Blame SOURCES/libvirt-qemu-snapshot-Add-support-for-compressing-external-snapshot-memory.patch

43fe83
From 28c7179c49ed6b21301c9bbf9adb896422816e7c Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <28c7179c49ed6b21301c9bbf9adb896422816e7c.1382534061.git.jdenemar@redhat.com>
43fe83
From: Peter Krempa <pkrempa@redhat.com>
43fe83
Date: Mon, 14 Oct 2013 16:38:48 +0200
43fe83
Subject: [PATCH] qemu: snapshot: Add support for compressing external snapshot
43fe83
 memory
43fe83
43fe83
The regular save image code has the support to compress images using a
43fe83
specified algorithm. This was not implemented for external checkpoints
43fe83
although it shares most of the backend code.
43fe83
43fe83
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1017227
43fe83
(cherry picked from commit 7df5093f67f0560d0440807b4363746e032ad942)
43fe83
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/qemu/libvirtd_qemu.aug         |  1 +
43fe83
 src/qemu/qemu.conf                 |  6 ++++++
43fe83
 src/qemu/qemu_conf.c               |  2 ++
43fe83
 src/qemu/qemu_conf.h               |  1 +
43fe83
 src/qemu/qemu_driver.c             | 23 +++++++++++++++++++++--
43fe83
 src/qemu/test_libvirtd_qemu.aug.in |  1 +
43fe83
 6 files changed, 32 insertions(+), 2 deletions(-)
43fe83
43fe83
diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
43fe83
index 5344125..3a874ca 100644
43fe83
--- a/src/qemu/libvirtd_qemu.aug
43fe83
+++ b/src/qemu/libvirtd_qemu.aug
43fe83
@@ -56,6 +56,7 @@ module Libvirtd_qemu =
43fe83
 
43fe83
    let save_entry =  str_entry "save_image_format"
43fe83
                  | str_entry "dump_image_format"
43fe83
+                 | str_entry "snapshot_image_format"
43fe83
                  | str_entry "auto_dump_path"
43fe83
                  | bool_entry "auto_dump_bypass_cache"
43fe83
                  | bool_entry "auto_start_bypass_cache"
43fe83
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
43fe83
index a2735cb..be6ab2a 100644
43fe83
--- a/src/qemu/qemu.conf
43fe83
+++ b/src/qemu/qemu.conf
43fe83
@@ -269,8 +269,14 @@
43fe83
 # the requested compression program can't be found, this falls
43fe83
 # back to "raw" compression.
43fe83
 #
43fe83
+# snapshot_image_format specifies the compression algorithm of the memory save
43fe83
+# image when an external snapshot of a domain is taken. This does not apply
43fe83
+# on disk image format. It is an error if the specified format isn't valid,
43fe83
+# or the requested compression program can't be found.
43fe83
+#
43fe83
 #save_image_format = "raw"
43fe83
 #dump_image_format = "raw"
43fe83
+#snapshot_image_format = "raw"
43fe83
 
43fe83
 # When a domain is configured to be auto-dumped when libvirtd receives a
43fe83
 # watchdog event from qemu guest, libvirtd will save dump files in directory
43fe83
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
43fe83
index 86ed9ed..c9d90db 100644
43fe83
--- a/src/qemu/qemu_conf.c
43fe83
+++ b/src/qemu/qemu_conf.c
43fe83
@@ -502,6 +502,8 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
43fe83
 
43fe83
     GET_VALUE_STR("save_image_format", cfg->saveImageFormat);
43fe83
     GET_VALUE_STR("dump_image_format", cfg->dumpImageFormat);
43fe83
+    GET_VALUE_STR("snapshot_image_format", cfg->snapshotImageFormat);
43fe83
+
43fe83
     GET_VALUE_STR("auto_dump_path", cfg->autoDumpPath);
43fe83
     GET_VALUE_BOOL("auto_dump_bypass_cache", cfg->autoDumpBypassCache);
43fe83
     GET_VALUE_BOOL("auto_start_bypass_cache", cfg->autoStartBypassCache);
43fe83
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
43fe83
index 8229cfc..dc5f8db 100644
43fe83
--- a/src/qemu/qemu_conf.h
43fe83
+++ b/src/qemu/qemu_conf.h
43fe83
@@ -143,6 +143,7 @@ struct _virQEMUDriverConfig {
43fe83
 
43fe83
     char *saveImageFormat;
43fe83
     char *dumpImageFormat;
43fe83
+    char *snapshotImageFormat;
43fe83
 
43fe83
     char *autoDumpPath;
43fe83
     bool autoDumpBypassCache;
43fe83
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
43fe83
index 14b0d57..3d0b56e 100644
43fe83
--- a/src/qemu/qemu_driver.c
43fe83
+++ b/src/qemu/qemu_driver.c
43fe83
@@ -12391,6 +12391,8 @@ qemuDomainSnapshotCreateActiveExternal(virConnectPtr conn,
43fe83
     bool transaction = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_TRANSACTION);
43fe83
     int thaw = 0; /* 1 if freeze succeeded, -1 if freeze failed */
43fe83
     bool pmsuspended = false;
43fe83
+    virQEMUDriverConfigPtr cfg = NULL;
43fe83
+    int compressed = QEMU_SAVE_FORMAT_RAW;
43fe83
 
43fe83
     if (qemuDomainObjBeginAsyncJob(driver, vm, QEMU_ASYNC_JOB_SNAPSHOT) < 0)
43fe83
         goto cleanup;
43fe83
@@ -12452,12 +12454,28 @@ qemuDomainSnapshotCreateActiveExternal(virConnectPtr conn,
43fe83
                                      JOB_MASK(QEMU_JOB_SUSPEND) |
43fe83
                                      JOB_MASK(QEMU_JOB_MIGRATION_OP));
43fe83
 
43fe83
+        cfg = virQEMUDriverGetConfig(driver);
43fe83
+        if (cfg->snapshotImageFormat) {
43fe83
+            compressed = qemuSaveCompressionTypeFromString(cfg->snapshotImageFormat);
43fe83
+            if (compressed < 0) {
43fe83
+                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
43fe83
+                               _("Invalid snapshot image format specified "
43fe83
+                                 "in configuration file"));
43fe83
+                goto cleanup;
43fe83
+            }
43fe83
+            if (!qemuCompressProgramAvailable(compressed)) {
43fe83
+                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
43fe83
+                               _("Compression program for image format "
43fe83
+                                 "in configuration file isn't available"));
43fe83
+                goto cleanup;
43fe83
+            }
43fe83
+        }
43fe83
+
43fe83
         if (!(xml = qemuDomainDefFormatLive(driver, vm->def, true, true)))
43fe83
             goto endjob;
43fe83
 
43fe83
         if ((ret = qemuDomainSaveMemory(driver, vm, snap->def->file,
43fe83
-                                        xml, QEMU_SAVE_FORMAT_RAW,
43fe83
-                                        resume, 0,
43fe83
+                                        xml, compressed, resume, 0,
43fe83
                                         QEMU_ASYNC_JOB_SNAPSHOT)) < 0)
43fe83
             goto endjob;
43fe83
 
43fe83
@@ -12546,6 +12564,7 @@ endjob:
43fe83
 
43fe83
 cleanup:
43fe83
     VIR_FREE(xml);
43fe83
+    virObjectUnref(cfg);
43fe83
     if (memory_unlink && ret < 0)
43fe83
         unlink(snap->def->file);
43fe83
 
43fe83
diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in
43fe83
index d4e4fae..d5df46c 100644
43fe83
--- a/src/qemu/test_libvirtd_qemu.aug.in
43fe83
+++ b/src/qemu/test_libvirtd_qemu.aug.in
43fe83
@@ -48,6 +48,7 @@ module Test_libvirtd_qemu =
43fe83
 }
43fe83
 { "save_image_format" = "raw" }
43fe83
 { "dump_image_format" = "raw" }
43fe83
+{ "snapshot_image_format" = "raw" }
43fe83
 { "auto_dump_path" = "/var/lib/libvirt/qemu/dump" }
43fe83
 { "auto_dump_bypass_cache" = "0" }
43fe83
 { "auto_start_bypass_cache" = "0" }
43fe83
-- 
43fe83
1.8.4
43fe83