mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
lib: Repurpose virDomainSaveParams() with no VIR_DOMAIN_SAVE_PARAM_FILE
When no VIR_DOMAIN_SAVE_PARAM_FILE typed param is set when calling virDomainSaveParams() then in turn virQEMUFileOpenAs() tries to open a NULL path. We have two options now: 1) require the typed param, which in turn may be promoted to a regular argument, or 2) use this opportunity to make the API behave like virDomainManagedSave() and use typed params to pass extra arguments, instead of having to invent new managed save API with typed params. Let's go with option 2, as it is more future proof. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
parent
25b2f75c7a
commit
f4e2910552
@ -1007,6 +1007,8 @@ virDomainSaveFlags(virDomainPtr domain, const char *to,
|
||||
* @flags: bitwise-OR of virDomainSaveRestoreFlags
|
||||
*
|
||||
* This method extends virDomainSaveFlags by adding parameters.
|
||||
* If VIR_DOMAIN_SAVE_PARAM_FILE is not provided then a managed save is
|
||||
* performed (see virDomainManagedSave).
|
||||
*
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*
|
||||
|
@ -2772,6 +2772,7 @@ qemuDomainManagedSavePath(virQEMUDriver *driver, virDomainObj *vm)
|
||||
static int
|
||||
qemuDomainManagedSaveHelper(virQEMUDriver *driver,
|
||||
virDomainObj *vm,
|
||||
const char *dxml,
|
||||
unsigned int flags)
|
||||
{
|
||||
g_autoptr(virQEMUDriverConfig) cfg = NULL;
|
||||
@ -2799,7 +2800,7 @@ qemuDomainManagedSaveHelper(virQEMUDriver *driver,
|
||||
VIR_INFO("Saving state of domain '%s' to '%s'", vm->def->name, path);
|
||||
|
||||
if (qemuDomainSaveInternal(driver, vm, path, compressed,
|
||||
compressor, NULL, flags) < 0)
|
||||
compressor, dxml, flags) < 0)
|
||||
return -1;
|
||||
|
||||
vm->hasManagedSave = true;
|
||||
@ -2853,17 +2854,18 @@ qemuDomainSave(virDomainPtr dom, const char *path)
|
||||
|
||||
static int
|
||||
qemuDomainSaveParams(virDomainPtr dom,
|
||||
virTypedParameterPtr params, int nparams,
|
||||
virTypedParameterPtr params,
|
||||
int nparams,
|
||||
unsigned int flags)
|
||||
{
|
||||
virQEMUDriver *driver = dom->conn->privateData;
|
||||
g_autoptr(virQEMUDriverConfig) cfg = NULL;
|
||||
virDomainObj *vm = NULL;
|
||||
g_autoptr(virCommand) compressor = NULL;
|
||||
const char *to = NULL;
|
||||
const char *dxml = NULL;
|
||||
virQEMUDriver *driver = dom->conn->privateData;
|
||||
int compressed;
|
||||
g_autoptr(virCommand) compressor = NULL;
|
||||
int ret = -1;
|
||||
virDomainObj *vm = NULL;
|
||||
g_autoptr(virQEMUDriverConfig) cfg = NULL;
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE |
|
||||
VIR_DOMAIN_SAVE_RUNNING |
|
||||
@ -2884,18 +2886,23 @@ qemuDomainSaveParams(virDomainPtr dom,
|
||||
VIR_DOMAIN_SAVE_PARAM_DXML, &dxml) < 0)
|
||||
return -1;
|
||||
|
||||
cfg = virQEMUDriverGetConfig(driver);
|
||||
if ((compressed = qemuSaveImageGetCompressionProgram(cfg->saveImageFormat,
|
||||
&compressor,
|
||||
"save", false)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(vm = qemuDomainObjFromDomain(dom)))
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainSaveParamsEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!to) {
|
||||
/* If no save path was provided then this behaves as managed save. */
|
||||
return qemuDomainManagedSaveHelper(driver, vm, dxml, flags);
|
||||
}
|
||||
|
||||
cfg = virQEMUDriverGetConfig(driver);
|
||||
if ((compressed = qemuSaveImageGetCompressionProgram(cfg->saveImageFormat,
|
||||
&compressor,
|
||||
"save", false)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -2925,7 +2932,7 @@ qemuDomainManagedSave(virDomainPtr dom, unsigned int flags)
|
||||
if (virDomainManagedSaveEnsureACL(dom->conn, vm->def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = qemuDomainManagedSaveHelper(driver, vm, flags);
|
||||
ret = qemuDomainManagedSaveHelper(driver, vm, NULL, flags);
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&vm);
|
||||
|
Loading…
Reference in New Issue
Block a user