diff --git a/nova/tests/unit/virt/libvirt/fake_libvirt_utils.py b/nova/tests/unit/virt/libvirt/fake_libvirt_utils.py index ec9f0d19d87b..f0fae1886035 100644 --- a/nova/tests/unit/virt/libvirt/fake_libvirt_utils.py +++ b/nova/tests/unit/virt/libvirt/fake_libvirt_utils.py @@ -90,11 +90,11 @@ def create_cow_image(backing_file, path): pass -def get_disk_size(path): +def get_disk_size(path, format=None): return 0 -def get_disk_backing_file(path): +def get_disk_backing_file(path, format=None): return disk_backing_files.get(path, None) diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 5ab612b3621e..8930d9dea7b0 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -10957,7 +10957,7 @@ Active: 8381604 kB mock_backing.return_value = bckfile drvr._live_snapshot(self.context, self.test_instance, mock_dom, - srcfile, dstfile, "qcow2", {}) + srcfile, dstfile, "qcow2", "qcow2", {}) mock_dom.XMLDesc.assert_called_once_with( fakelibvirt.VIR_DOMAIN_XML_INACTIVE | @@ -10968,8 +10968,9 @@ Active: 8381604 kB fakelibvirt.VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT | fakelibvirt.VIR_DOMAIN_BLOCK_REBASE_SHALLOW) - mock_size.assert_called_once_with(srcfile) - mock_backing.assert_called_once_with(srcfile, basename=False) + mock_size.assert_called_once_with(srcfile, format="qcow2") + mock_backing.assert_called_once_with(srcfile, basename=False, + format="qcow2") mock_create_cow.assert_called_once_with(bckfile, dltfile, 1004009) mock_chown.assert_called_once_with(dltfile, os.getuid()) mock_snapshot.assert_called_once_with(dltfile, "qcow2", diff --git a/nova/virt/images.py b/nova/virt/images.py index ed869387034d..c0da0545f9e8 100644 --- a/nova/virt/images.py +++ b/nova/virt/images.py @@ -44,7 +44,7 @@ CONF.register_opts(image_opts) IMAGE_API = image.API() -def qemu_img_info(path): +def qemu_img_info(path, format=None): """Return an object containing the parsed output from qemu-img info.""" # TODO(mikal): this code should not be referring to a libvirt specific # flag. @@ -56,8 +56,10 @@ def qemu_img_info(path): msg = (_("Path does not exist %(path)s") % {'path': path}) raise exception.InvalidDiskInfo(reason=msg) - out, err = utils.execute('env', 'LC_ALL=C', 'LANG=C', - 'qemu-img', 'info', path) + cmd = ('env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info', path) + if format is not None: + cmd = cmd + ('-f', format) + out, err = utils.execute(*cmd) if not out: msg = (_("Failed to run qemu-img info on %(path)s : %(error)s") % {'path': path, 'error': err}) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 3c8697d181c2..1b5c4b9a9918 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -1429,7 +1429,8 @@ class LibvirtDriver(driver.ComputeDriver): # NOTE(xqueralt): libvirt needs o+x in the temp directory os.chmod(tmpdir, 0o701) self._live_snapshot(context, instance, virt_dom, disk_path, - out_path, image_format, base) + out_path, source_format, image_format, + base) else: snapshot_backend.snapshot_extract(out_path, image_format) finally: @@ -1539,7 +1540,7 @@ class LibvirtDriver(driver.ComputeDriver): self._set_quiesced(context, instance, image_meta, False) def _live_snapshot(self, context, instance, domain, disk_path, out_path, - image_format, image_meta): + source_format, image_format, image_meta): """Snapshot an instance without downtime.""" # Save a copy of the domain's persistent XML file xml = domain.XMLDesc( @@ -1557,9 +1558,11 @@ class LibvirtDriver(driver.ComputeDriver): # in QEMU 1.3. In order to do this, we need to create # a destination image with the original backing file # and matching size of the instance root disk. - src_disk_size = libvirt_utils.get_disk_size(disk_path) + src_disk_size = libvirt_utils.get_disk_size(disk_path, + format=source_format) src_back_path = libvirt_utils.get_disk_backing_file(disk_path, - basename=False) + format=source_format, + basename=False) disk_delta = out_path + '.delta' libvirt_utils.create_cow_image(src_back_path, disk_delta, src_disk_size) diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 52ca3ee671c9..6a0f7dd30f7b 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -270,24 +270,25 @@ def pick_disk_driver_name(hypervisor_version, is_block_dev=False): return None -def get_disk_size(path): +def get_disk_size(path, format=None): """Get the (virtual) size of a disk image :param path: Path to the disk image + :param format: the on-disk format of path :returns: Size (in bytes) of the given disk image as it would be seen by a virtual machine. """ - size = images.qemu_img_info(path).virtual_size + size = images.qemu_img_info(path, format).virtual_size return int(size) -def get_disk_backing_file(path, basename=True): +def get_disk_backing_file(path, basename=True, format=None): """Get the backing file of a disk image :param path: Path to the disk image :returns: a path to the image's backing store """ - backing_file = images.qemu_img_info(path).backing_file + backing_file = images.qemu_img_info(path, format).backing_file if backing_file and basename: backing_file = os.path.basename(backing_file)