qemuMigrationParamsForSave: Don't take opaque 'flags'

Similarly to previous commit, 'flags' is really opaque. The function
lives in migration code and similar functions there expect migration
flags. Here we get virDomainSaveRestoreFlags. Here at least the dump
code handles it properly and passes VIR_DOMAIN_SAVE_BYPASS_CACHE rather
than VIR_DUMP_BYPASS_CACHE.

Note: We, in many cases, encourage use of 'flags' instead of a bunch of
boolean parameters. Since C doesn't do proper type checks on enums and
in fact with 'flags' we pass a binary or of some flags rather than pure
options from the enum there isn't really an elegant solution that would
be enforced by the compiler and easy on eyes. With a bunch of booleans
at least anyone reading the code will need to look up the function
definition to see the header rather than assume that passing in 'flags'
is fine without properly checking *which* flags are accepted by the
function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa committed 2025-12-10 11:07:34 +01:00
1 parent 61ae36fa0b
commit 5ca7d3227d
3 files changed
+7 -6

No files matched your search

+4 -3
View File
@@ -2679,7 +2679,7 @@ qemuDomainSaveInternal(virQEMUDriver *driver,
if (!(saveParams = qemuMigrationParamsForSave(params, nparams,
format == QEMU_SAVE_FORMAT_SPARSE,
flags)))
(flags & VIR_DOMAIN_SAVE_BYPASS_CACHE))))
goto endjob;
ret = qemuSaveImageCreate(driver, vm, path, data, compressor,
@@ -5798,7 +5798,8 @@ qemuDomainRestoreInternal(virConnectPtr conn,
goto cleanup;
sparse = data->header.format == QEMU_SAVE_FORMAT_SPARSE;
if (!(restoreParams = qemuMigrationParamsForSave(params, nparams, sparse, flags)))
if (!(restoreParams = qemuMigrationParamsForSave(params, nparams, sparse,
(flags & VIR_DOMAIN_SAVE_BYPASS_CACHE))))
goto cleanup;
fd = qemuSaveImageOpen(driver, path,
@@ -6130,7 +6131,7 @@ qemuDomainObjRestore(virConnectPtr conn,
sparse = data->header.format == QEMU_SAVE_FORMAT_SPARSE;
if (!(restoreParams = qemuMigrationParamsForSave(NULL, 0, sparse,
bypass_cache ? VIR_DOMAIN_SAVE_BYPASS_CACHE : 0)))
bypass_cache)))
return -1;
fd = qemuSaveImageOpen(driver, path, bypass_cache, sparse, &wrapperFd, false);
+2 -2
View File
@@ -800,7 +800,7 @@ qemuMigrationParams *
qemuMigrationParamsForSave(virTypedParameterPtr params,
int nparams,
bool sparse,
unsigned int flags)
bool bypassCache)
{
g_autoptr(qemuMigrationParams) saveParams = NULL;
int nchannels = 0;
@@ -837,7 +837,7 @@ qemuMigrationParamsForSave(virTypedParameterPtr params,
saveParams->params[QEMU_MIGRATION_PARAM_MULTIFD_CHANNELS].value.i = nchannels;
saveParams->params[QEMU_MIGRATION_PARAM_MULTIFD_CHANNELS].set = true;
if (flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) {
if (bypassCache) {
saveParams->params[QEMU_MIGRATION_PARAM_DIRECT_IO].value.b = true;
saveParams->params[QEMU_MIGRATION_PARAM_DIRECT_IO].set = true;
}
+1 -1
View File
@@ -92,7 +92,7 @@ qemuMigrationParams *
qemuMigrationParamsForSave(virTypedParameterPtr params,
int nparams,
bool sparse,
unsigned int flags);
bool bypassCache);
int
qemuMigrationParamsDump(qemuMigrationParams *migParams,