Skip to content

Instantly share code, notes, and snippets.

@rmk40
Last active December 17, 2015 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmk40/ab2c6f518a7a40a261af to your computer and use it in GitHub Desktop.
Save rmk40/ab2c6f518a7a40a261af to your computer and use it in GitHub Desktop.
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py
index 9b8ced7..59b088f 100755
--- a/nova/virt/libvirt/driver.py
+++ b/nova/virt/libvirt/driver.py
@@ -3473,8 +3473,8 @@ class LibvirtDriver(driver.ComputeDriver):
return shared_storage
def migrate_disk_and_power_off(self, context, instance, dest,
- instance_type, network_info,
- block_device_info=None):
+ instance_type, network_info,
+ block_device_info=None):
LOG.debug(_("Starting migrate_disk_and_power_off"),
instance=instance)
disk_info_text = self.get_instance_disk_info(instance['name'])
@@ -3512,9 +3512,11 @@ class LibvirtDriver(driver.ComputeDriver):
from_path = os.path.join(inst_base_resize, fname)
if info['type'] == 'qcow2' and info['backing_file']:
tmp_path = from_path + "_rbase"
- # merge backing file
- utils.execute('qemu-img', 'convert', '-f', 'qcow2',
- '-O', 'qcow2', from_path, tmp_path)
+ # NOTE(rmk): Simply copy the existing backing-file
+ # based qcow2 file and rely on the remote server to
+ # properly grab the necessary backing files from
+ # Glance.
+ utils.execute('cp', '-a', from_path, tmp_path)
if shared_storage:
utils.execute('mv', tmp_path, img_path)
@@ -3529,7 +3531,6 @@ class LibvirtDriver(driver.ComputeDriver):
self._cleanup_remote_migration(dest, inst_base,
inst_base_resize,
shared_storage)
-
return disk_info_text
def _wait_for_running(self, instance):
@@ -3544,44 +3545,12 @@ class LibvirtDriver(driver.ComputeDriver):
block_device_info=None):
LOG.debug(_("Starting finish_migration"), instance=instance)
- # resize disks. only "disk" and "disk.local" are necessary.
- disk_info = jsonutils.loads(disk_info)
- for info in disk_info:
- fname = os.path.basename(info['path'])
- if fname == 'disk':
- size = instance['root_gb']
- elif fname == 'disk.local':
- size = instance['ephemeral_gb']
- else:
- size = 0
- size *= 1024 * 1024 * 1024
-
- # If we have a non partitioned image that we can extend
- # then ensure we're in 'raw' format so we can extend file system.
- fmt = info['type']
- if (size and fmt == 'qcow2' and
- disk.can_resize_fs(info['path'], size, use_cow=True)):
- path_raw = info['path'] + '_raw'
- utils.execute('qemu-img', 'convert', '-f', 'qcow2',
- '-O', 'raw', info['path'], path_raw)
- utils.execute('mv', path_raw, info['path'])
- fmt = 'raw'
-
- if size:
- disk.extend(info['path'], size)
-
- if fmt == 'raw' and CONF.use_cow_images:
- # back to qcow2 (no backing_file though) so that snapshot
- # will be available
- path_qcow = info['path'] + '_qcow'
- utils.execute('qemu-img', 'convert', '-f', 'raw',
- '-O', 'qcow2', info['path'], path_qcow)
- utils.execute('mv', path_qcow, info['path'])
-
+ disk_info_json = jsonutils.loads(disk_info)
disk_info = blockinfo.get_disk_info(CONF.libvirt_type,
instance,
block_device_info,
image_meta)
+
# assume _create_image do nothing if a target file exists.
# TODO(oda): injecting files is not necessary
self._create_image(context, instance,
@@ -3591,6 +3560,21 @@ class LibvirtDriver(driver.ComputeDriver):
xml = self.to_xml(instance, network_info, disk_info,
block_device_info=block_device_info,
write_to_disk=True)
+
+ # resize disks. only "disk" and "disk.local" are necessary.
+ for info in disk_info_json:
+ fname = os.path.basename(info['path'])
+ if fname == 'disk':
+ size = instance['root_gb']
+ elif fname == 'disk.local':
+ size = instance['ephemeral_gb']
+ else:
+ size = 0
+ size *= 1024 * 1024 * 1024
+
+ if size:
+ disk.extend(info['path'], size)
+
self._create_domain_and_network(xml, instance, network_info,
block_device_info)
timer = utils.FixedIntervalLoopingCall(self._wait_for_running,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment