[PATCH V4 07/18] qemu_saveimage: add "sparse" to supported save image formats

Jim Fehlig via Devel posted 18 patches 6 days, 13 hours ago
[PATCH V4 07/18] qemu_saveimage: add "sparse" to supported save image formats
Posted by Jim Fehlig via Devel 6 days, 13 hours ago
Extend the list of formats to include "sparse", which uses QEMU's mapped-ram
stream format [1] to write guest memory blocks at fixed offsets in the save
image file.

[1] https://gitlab.com/qemu-project/qemu/-/blob/master/docs/devel/migration/mapped-ram.rst?ref_type=heads

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 src/qemu/qemu.conf.in     | 9 ++++++++-
 src/qemu/qemu_saveimage.c | 1 +
 src/qemu/qemu_saveimage.h | 1 +
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu.conf.in b/src/qemu/qemu.conf.in
index 31172303dc..44ff658ad6 100644
--- a/src/qemu/qemu.conf.in
+++ b/src/qemu/qemu.conf.in
@@ -588,11 +588,18 @@
 # disk space when saving large memory guests. Various compression formats are
 # available for specifying a save image compressed by the named algorithm.
 # Supported compression formats are "zstd", "lzop", "gzip", "bzip2", and "xz".
+# The "sparse" format uses QEMU's mapped-ram stream format to write guest memory
+# blocks at fixed offsets in the save image file.
 
 # save_image_format can be used to select the desired save format. "raw" is
 # the traditional format used by libvirt and is also the default. The
 # compression formats can be used to save disk space, although this typically
-# results in longer save and restore times.
+# results in longer save and restore times. The "sparse" format results in a
+# save image file that is roughly the logical size of the guest's memory,
+# although on-disk size is a function of guest memory usage. The "sparse"
+# format is useful when a predictable maximum save image file size is
+# needed. The other formats can result in a save image file much larger
+# than guest memory if the guest runs a memory intensive workload.
 #
 # save_image_format is used with 'virsh save' or 'virsh managedsave'. It is
 # an error if the specified save_image_format is not valid, or cannot be
diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c
index d940bfb5c3..29b4e39879 100644
--- a/src/qemu/qemu_saveimage.c
+++ b/src/qemu/qemu_saveimage.c
@@ -45,6 +45,7 @@ VIR_ENUM_IMPL(qemuSaveFormat,
               "xz",
               "lzop",
               "zstd",
+              "sparse",
 );
 
 static inline void
diff --git a/src/qemu/qemu_saveimage.h b/src/qemu/qemu_saveimage.h
index 58f8252c8a..0411f3140a 100644
--- a/src/qemu/qemu_saveimage.h
+++ b/src/qemu/qemu_saveimage.h
@@ -42,6 +42,7 @@ typedef enum {
     QEMU_SAVE_FORMAT_XZ = 3,
     QEMU_SAVE_FORMAT_LZOP = 4,
     QEMU_SAVE_FORMAT_ZSTD = 5,
+    QEMU_SAVE_FORMAT_SPARSE = 6,
     /* Note: add new members only at the end.
        These values are used in the on-disk format.
        Do not change or re-use numbers. */
-- 
2.43.0