From b216ed51914986087ea7dee57bc29904fda001a0 Mon Sep 17 00:00:00 2001 From: Rafi Khardalian Date: Wed, 30 Jan 2013 02:39:18 +0000 Subject: Add support for compressing qcow2 snapshots Fixes bug 1109923 Adds a new configuration option: libvirt_snapshot_compression=False (Default) When set to True and the snapshot output format is qcow2, we pass the -c option into qemu-img, which enables compression. This patch also refactors the extract_image function to make construction of the whole qemu-img command more dynamic. Change-Id: I7a7ebcf41a91a8a9cb14be79e9bb79c22acb136e Flags: DocImpact --- nova/virt/libvirt/utils.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) mode change 100644 => 100755 nova/virt/libvirt/utils.py (limited to 'nova') diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py old mode 100644 new mode 100755 index bd4ec685c..7bcc82f2b --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -29,7 +29,15 @@ from nova.openstack.common import log as logging from nova import utils from nova.virt import images +libvirt_opts = [ + cfg.BoolOpt('libvirt_snapshot_compression', + default=False, + help='Compress snapshot images when possible. This ' + 'currently applies exclusively to qcow2 images'), + ] + CONF = cfg.CONF +CONF.register_opts(libvirt_opts) CONF.import_opt('instances_path', 'nova.compute.manager') LOG = logging.getLogger(__name__) @@ -406,15 +414,18 @@ def extract_snapshot(disk_path, source_fmt, snapshot_name, out_path, dest_fmt): if dest_fmt == 'iso': dest_fmt = 'raw' - qemu_img_cmd = ('qemu-img', 'convert', '-f', source_fmt, '-O', - dest_fmt, '-s', snapshot_name, disk_path, out_path) + qemu_img_cmd = ('qemu-img', 'convert', '-f', source_fmt, '-O', dest_fmt) + + # Conditionally enable compression of snapshots. + if CONF.libvirt_snapshot_compression and dest_fmt == "qcow2": + qemu_img_cmd += ('-c',) # When snapshot name is omitted we do a basic convert, which # is used by live snapshots. - if snapshot_name is None: - qemu_img_cmd = ('qemu-img', 'convert', '-f', source_fmt, '-O', - dest_fmt, disk_path, out_path) + if snapshot_name is not None: + qemu_img_cmd += ('-s', snapshot_name) + qemu_img_cmd += (disk_path, out_path) execute(*qemu_img_cmd) -- cgit