From 0468eeb5314fc3da444669353673935ec044e286 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 11 Aug 2020 21:46:12 -0400 Subject: [PATCH] Support live resizing of running disk volumes This wasn't happening automatically, nor does it happen with qemu-img commands, so we have to manually trigger a libvirt blockResize against the volume. This setup is a little roundabout but seems to work fine. --- daemon-common/ceph.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/daemon-common/ceph.py b/daemon-common/ceph.py index 1c22bdcd..a5d0f1a4 100644 --- a/daemon-common/ceph.py +++ b/daemon-common/ceph.py @@ -27,6 +27,7 @@ import json import time import math +import daemon_lib.vm as vm import daemon_lib.ansiprint as ansiprint import daemon_lib.zkhandler as zkhandler import daemon_lib.common as common @@ -940,6 +941,30 @@ def resize_volume(zk_conn, pool, name, size): if retcode: return False, 'ERROR: Failed to resize RBD volume "{}" to size "{}" in pool "{}": {}'.format(name, size, pool, stderr) + # 2a. Determine the node running this VM if applicable + active_node = None + volume_vm_name = name.split('_')[0] + retcode, vm_info = vm.get_info(zk_conn, volume_vm_name) + if retcode: + for disk in vm_info['disks']: + # This block device is present in this VM so we can continue + if disk['name'] == '{}/{}'.format(pool, name): + active_node = vm_info['node'] + volume_id = disk['dev'] + # 2b. Perform a live resize in libvirt if the VM is running + if vm_info['state'] == 'start' and active_node is not None: + import libvirt + # Run the libvirt command against the target host + try: + dest_lv = 'qemu+tcp://{}/system'.format(active_node) + target_lv_conn = libvirt.open(dest_lv) + target_vm_conn = target_lv_conn.lookupByName(vm_info['name']) + if target_vm_conn: + target_vm_conn.blockResize(volume_id, int(format_bytes_fromhuman(size)[:-1]), libvirt.VIR_DOMAIN_BLOCK_RESIZE_BYTES) + target_lv_conn.close() + except: + pass + # 2. Get volume stats retcode, stdout, stderr = common.run_os_command('rbd info --format json {}/{}'.format(pool, name)) volstats = stdout