[PATCH V2 0/2] qemu: Support specifying save image format

V2 of https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/message/ISSW... Changes in V2: * Adjusted patch2 after moving verification of save image formats to driver startup in the series this one is based on https://lists.libvirt.org/archives/list/devel@lists.libvirt.org/thread/NZFXR... Jim Fehlig (2): include: Define constant for save image format qemu: Add support for 'image_format' typed parameter include/libvirt/libvirt-domain.h | 13 +++++++++++++ src/libvirt-domain.c | 3 +++ src/qemu/qemu_driver.c | 20 ++++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) -- 2.43.0

Add a new VIR_DOMAIN_SAVE_PARAM_IMAGE_FORMAT typed parameter for specifying the save image format. A format specified via the virDomainSaveParams API overrides the save_image_format setting in qemu.conf. The 'raw' format remains the default. Signed-off-by: Jim Fehlig <jfehlig@suse.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> --- include/libvirt/libvirt-domain.h | 13 +++++++++++++ src/libvirt-domain.c | 3 +++ 2 files changed, 16 insertions(+) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index f5420bca6e..b5f2f8a31c 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1700,6 +1700,19 @@ int virDomainRestoreParams (virConnectPtr conn, */ # define VIR_DOMAIN_SAVE_PARAM_DXML "dxml" +/** + * VIR_DOMAIN_SAVE_PARAM_IMAGE_FORMAT: + * + * an optional parameter used to specify the format of the save image. + * Valid formats are raw, zstd, lzop, gzip, bzip2, and xz. If not + * specified, the save_image_format setting in qemu.conf is used, which + * defaults to raw. As VIR_TYPED_PARAM_STRING. + * + * Since: 11.1.0 + */ +# define VIR_DOMAIN_SAVE_PARAM_IMAGE_FORMAT "image_format" + + /* See below for virDomainSaveImageXMLFlags */ char * virDomainSaveImageGetXMLDesc (virConnectPtr conn, const char *file, diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 072cc32255..4e38d4c868 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -1010,6 +1010,9 @@ virDomainSaveFlags(virDomainPtr domain, const char *to, * If VIR_DOMAIN_SAVE_PARAM_FILE is not provided then a managed save is * performed (see virDomainManagedSave). * + * See VIR_DOMAIN_SAVE_PARAM_* for detailed description of accepted save + * parameters. + * * Returns 0 in case of success and -1 in case of failure. * * Since: 8.4.0 -- 2.43.0

Add support for the 'image_format' typed parameter in virDomainSaveParams. The parameter overrides the 'save_image_format' setting in qemu.conf. Signed-off-by: Jim Fehlig <jfehlig@suse.com> --- src/qemu/qemu_driver.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 76b808b98f..6db7a30658 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2806,11 +2806,13 @@ qemuDomainSaveParams(virDomainPtr dom, unsigned int flags) { virQEMUDriver *driver = dom->conn->privateData; - g_autoptr(virQEMUDriverConfig) cfg = NULL; + g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); virDomainObj *vm = NULL; g_autoptr(virCommand) compressor = NULL; const char *to = NULL; const char *dxml = NULL; + const char *formatstr = NULL; + int format = cfg->saveImageFormat; int ret = -1; virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE | @@ -2822,6 +2824,8 @@ qemuDomainSaveParams(virDomainPtr dom, VIR_TYPED_PARAM_STRING, VIR_DOMAIN_SAVE_PARAM_DXML, VIR_TYPED_PARAM_STRING, + VIR_DOMAIN_SAVE_PARAM_IMAGE_FORMAT, + VIR_TYPED_PARAM_STRING, NULL) < 0) return -1; @@ -2831,6 +2835,9 @@ qemuDomainSaveParams(virDomainPtr dom, if (virTypedParamsGetString(params, nparams, VIR_DOMAIN_SAVE_PARAM_DXML, &dxml) < 0) return -1; + if (virTypedParamsGetString(params, nparams, + VIR_DOMAIN_SAVE_PARAM_IMAGE_FORMAT, &formatstr) < 0) + return -1; if (!(vm = qemuDomainObjFromDomain(dom))) goto cleanup; @@ -2843,14 +2850,19 @@ qemuDomainSaveParams(virDomainPtr dom, return qemuDomainManagedSaveHelper(driver, vm, dxml, flags); } - cfg = virQEMUDriverGetConfig(driver); - if (qemuSaveImageGetCompressionProgram(cfg->saveImageFormat, &compressor, "save") < 0) + if (formatstr && (format = qemuSaveFormatTypeFromString(formatstr)) < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Invalid image_format '%1$s'"), formatstr); + goto cleanup; + } + + if (qemuSaveImageGetCompressionProgram(format, &compressor, "save") < 0) goto cleanup; if (virDomainObjCheckActive(vm) < 0) goto cleanup; - ret = qemuDomainSaveInternal(driver, vm, to, cfg->saveImageFormat, + ret = qemuDomainSaveInternal(driver, vm, to, format, compressor, dxml, flags); cleanup: -- 2.43.0

On Thu, Feb 20, 2025 at 05:23:54PM -0700, Jim Fehlig via Devel wrote:
Add support for the 'image_format' typed parameter in virDomainSaveParams. The parameter overrides the 'save_image_format' setting in qemu.conf.
Signed-off-by: Jim Fehlig <jfehlig@suse.com> --- src/qemu/qemu_driver.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On 2/25/25 07:43, Daniel P. Berrangé wrote:
On Thu, Feb 20, 2025 at 05:23:54PM -0700, Jim Fehlig via Devel wrote:
Add support for the 'image_format' typed parameter in virDomainSaveParams. The parameter overrides the 'save_image_format' setting in qemu.conf.
Signed-off-by: Jim Fehlig <jfehlig@suse.com> --- src/qemu/qemu_driver.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Hi Daniel, Thanks for reviewing this and the related series! I suppose it's too late to push these for 11.1.0? If so, I'll change the 'Since:' to 11.2.0 in patch1 and push after the release. Regards, Jim

On Tue, Feb 25, 2025 at 11:34:24AM -0700, Jim Fehlig wrote:
On 2/25/25 07:43, Daniel P. Berrangé wrote:
On Thu, Feb 20, 2025 at 05:23:54PM -0700, Jim Fehlig via Devel wrote:
Add support for the 'image_format' typed parameter in virDomainSaveParams. The parameter overrides the 'save_image_format' setting in qemu.conf.
Signed-off-by: Jim Fehlig <jfehlig@suse.com> --- src/qemu/qemu_driver.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Hi Daniel,
Thanks for reviewing this and the related series! I suppose it's too late to push these for 11.1.0? If so, I'll change the 'Since:' to 11.2.0 in patch1 and push after the release.
I could kinda argue for the other series being a bugfix, but since its motivation is mostly to assist this series, we might as well merge both together after the release. With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (2)
-
Daniel P. Berrangé
-
Jim Fehlig