From b9aac1181581b9036c98f5aa493731fdc74be7e1 Mon Sep 17 00:00:00 2001 From: Kei Masumoto Date: Wed, 28 Sep 2011 15:05:54 -0400 Subject: Fixed bug lp850602. Adding backing file copy operation on kvm block migration. Change-Id: I165b0f8778e712c8932260c0110e159b2e9a6cfb --- nova/virt/libvirt/connection.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 064c2688f..6ab28a3f7 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -1726,9 +1726,31 @@ class LibvirtConnection(driver.ComputeDriver): for info in disk_info: base = os.path.basename(info['path']) - # Get image type and create empty disk image. + # Get image type and create empty disk image, and + # create backing file in case of qcow2. instance_disk = os.path.join(instance_dir, base) - utils.execute('qemu-img', 'create', '-f', info['type'], + if not info['backing_file']: + utils.execute('qemu-img', 'create', '-f', info['type'], + instance_disk, info['local_gb']) + + else: + # Creating backing file follows same way as spawning instances. + backing_file = os.path.join(FLAGS.instances_path, + '_base', info['backing_file']) + + if not os.path.exists(backing_file): + self._cache_image(fn=self._fetch_image, + context=ctxt, + target=info['path'], + fname=info['backing_file'], + cow=FLAGS.use_cow_images, + image_id=instance_ref['image_ref'], + user_id=instance_ref['user_id'], + project_id=instance_ref['project_id'], + size=instance_ref['local_gb']) + + utils.execute('qemu-img', 'create', '-f', info['type'], + '-o', 'backing_file=%s' % backing_file, instance_disk, info['local_gb']) # if image has kernel and ramdisk, just download @@ -1819,12 +1841,17 @@ class LibvirtConnection(driver.ComputeDriver): driver_nodes[cnt].get_properties().get_next().getContent() if disk_type == 'raw': size = int(os.path.getsize(path)) + backing_file = "" else: out, err = utils.execute('qemu-img', 'info', path) size = [i.split('(')[1].split()[0] for i in out.split('\n') if i.strip().find('virtual size') >= 0] size = int(size[0]) + backing_file = [i.split('actual path:')[1].strip()[:-1] + for i in out.split('\n') if 0 <= i.find('backing file')] + backing_file = os.path.basename(backing_file[0]) + # block migration needs same/larger size of empty image on the # destination host. since qemu-img creates bit smaller size image # depending on original image size, fixed value is necessary. @@ -1840,7 +1867,7 @@ class LibvirtConnection(driver.ComputeDriver): break disk_info.append({'type': disk_type, 'path': path, - 'local_gb': size}) + 'local_gb': size, 'backing_file': backing_file}) return utils.dumps(disk_info) -- cgit