By merging qemuMigrationAnyCompressionParse into
qemuMigrationParamsSetCompression we can drop the useless intermediate
qemuMigrationCompression structure and parse compression related typed
parameters and flags directly into qemuMigrationParams.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_driver.c | 63 ++---------
src/qemu/qemu_migration_params.c | 181 +++++++++++++------------------
src/qemu/qemu_migration_params.h | 26 +----
3 files changed, 85 insertions(+), 185 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5e79e90609..8e880280ec 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12126,7 +12126,6 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
virQEMUDriverPtr driver = dconn->privateData;
virDomainDefPtr def = NULL;
char *origname = NULL;
- qemuMigrationCompressionPtr compression = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
@@ -12138,11 +12137,8 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
goto cleanup;
}
- if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
- goto cleanup;
-
if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
- QEMU_MIGRATION_DESTINATION,
compression)))
+ QEMU_MIGRATION_DESTINATION)))
goto cleanup;
if (virLockManagerPluginUsesState(driver->lockManager)) {
@@ -12163,7 +12159,6 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
st, &def, origname, migParams, flags);
cleanup:
- VIR_FREE(compression);
qemuMigrationParamsFree(migParams);
VIR_FREE(origname);
virDomainDefFree(def);
@@ -12188,7 +12183,6 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
virQEMUDriverPtr driver = dconn->privateData;
virDomainDefPtr def = NULL;
char *origname = NULL;
- qemuMigrationCompressionPtr compression = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
@@ -12204,11 +12198,8 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
goto cleanup;
}
- if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
- goto cleanup;
-
if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
- QEMU_MIGRATION_DESTINATION,
compression)))
+ QEMU_MIGRATION_DESTINATION)))
goto cleanup;
if (virLockManagerPluginUsesState(driver->lockManager)) {
@@ -12236,7 +12227,6 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
cleanup:
qemuMigrationParamsFree(migParams);
- VIR_FREE(compression);
VIR_FREE(origname);
virDomainDefFree(def);
return ret;
@@ -12257,7 +12247,6 @@ qemuDomainMigratePerform(virDomainPtr dom,
virDomainObjPtr vm;
int ret = -1;
const char *dconnuri = NULL;
- qemuMigrationCompressionPtr compression = NULL;
qemuMigrationParamsPtr migParams = NULL;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -12269,11 +12258,8 @@ qemuDomainMigratePerform(virDomainPtr dom,
goto cleanup;
}
- if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
- goto cleanup;
-
if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
- QEMU_MIGRATION_SOURCE, compression)))
+ QEMU_MIGRATION_SOURCE)))
goto cleanup;
if (!(vm = qemuDomObjFromDomain(dom)))
@@ -12303,7 +12289,6 @@ qemuDomainMigratePerform(virDomainPtr dom,
cleanup:
qemuMigrationParamsFree(migParams);
- VIR_FREE(compression);
return ret;
}
@@ -12447,7 +12432,6 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
virQEMUDriverPtr driver = dconn->privateData;
virDomainDefPtr def = NULL;
char *origname = NULL;
- qemuMigrationCompressionPtr compression = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
@@ -12463,11 +12447,8 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
goto cleanup;
}
- if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
- goto cleanup;
-
if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
- QEMU_MIGRATION_DESTINATION,
compression)))
+ QEMU_MIGRATION_DESTINATION)))
goto cleanup;
if (!(def = qemuMigrationAnyPrepareDef(driver, dom_xml, dname, &origname)))
@@ -12485,7 +12466,6 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
cleanup:
qemuMigrationParamsFree(migParams);
- VIR_FREE(compression);
VIR_FREE(origname);
virDomainDefFree(def);
return ret;
@@ -12513,7 +12493,6 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
int nmigrate_disks;
const char **migrate_disks = NULL;
char *origname = NULL;
- qemuMigrationCompressionPtr compression = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
@@ -12545,11 +12524,8 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
if (nmigrate_disks < 0)
goto cleanup;
- if (!(compression = qemuMigrationAnyCompressionParse(params, nparams, flags)))
- goto cleanup;
-
if (!(migParams = qemuMigrationParamsFromFlags(params, nparams, flags,
- QEMU_MIGRATION_DESTINATION,
compression)))
+ QEMU_MIGRATION_DESTINATION)))
goto cleanup;
if (flags & VIR_MIGRATE_TUNNELLED) {
@@ -12578,7 +12554,6 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
cleanup:
qemuMigrationParamsFree(migParams);
- VIR_FREE(compression);
VIR_FREE(migrate_disks);
VIR_FREE(origname);
virDomainDefFree(def);
@@ -12602,7 +12577,6 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
virQEMUDriverPtr driver = dconn->privateData;
virDomainDefPtr def = NULL;
char *origname = NULL;
- qemuMigrationCompressionPtr compression = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
@@ -12614,11 +12588,8 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
goto cleanup;
}
- if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
- goto cleanup;
-
if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
- QEMU_MIGRATION_DESTINATION,
compression)))
+ QEMU_MIGRATION_DESTINATION)))
goto cleanup;
if (!(def = qemuMigrationAnyPrepareDef(driver, dom_xml, dname, &origname)))
@@ -12633,7 +12604,6 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
st, &def, origname, migParams, flags);
cleanup:
- VIR_FREE(compression);
qemuMigrationParamsFree(migParams);
VIR_FREE(origname);
virDomainDefFree(def);
@@ -12656,7 +12626,6 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
const char *dom_xml = NULL;
const char *dname = NULL;
char *origname = NULL;
- qemuMigrationCompressionPtr compression = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
@@ -12678,11 +12647,8 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
goto cleanup;
}
- if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
- goto cleanup;
-
if (!(migParams = qemuMigrationParamsFromFlags(params, nparams, flags,
- QEMU_MIGRATION_DESTINATION,
compression)))
+ QEMU_MIGRATION_DESTINATION)))
goto cleanup;
if (!(def = qemuMigrationAnyPrepareDef(driver, dom_xml, dname, &origname)))
@@ -12697,7 +12663,6 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
st, &def, origname, migParams, flags);
cleanup:
- VIR_FREE(compression);
qemuMigrationParamsFree(migParams);
VIR_FREE(origname);
virDomainDefFree(def);
@@ -12720,17 +12685,13 @@ qemuDomainMigratePerform3(virDomainPtr dom,
{
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm;
- qemuMigrationCompressionPtr compression = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
- if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
- goto cleanup;
-
if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
- QEMU_MIGRATION_SOURCE, compression)))
+ QEMU_MIGRATION_SOURCE)))
goto cleanup;
if (!(vm = qemuDomObjFromDomain(dom)))
@@ -12750,7 +12711,6 @@ qemuDomainMigratePerform3(virDomainPtr dom,
cleanup:
qemuMigrationParamsFree(migParams);
- VIR_FREE(compression);
return ret;
}
@@ -12777,7 +12737,6 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
const char **migrate_disks = NULL;
unsigned long long bandwidth = 0;
int nbdPort = 0;
- qemuMigrationCompressionPtr compression = NULL;
qemuMigrationParamsPtr migParams = NULL;
int ret = -1;
@@ -12818,11 +12777,8 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
if (nmigrate_disks < 0)
goto cleanup;
- if (!(compression = qemuMigrationAnyCompressionParse(params, nparams, flags)))
- goto cleanup;
-
if (!(migParams = qemuMigrationParamsFromFlags(params, nparams, flags,
- QEMU_MIGRATION_SOURCE, compression)))
+ QEMU_MIGRATION_SOURCE)))
goto cleanup;
if (!(vm = qemuDomObjFromDomain(dom)))
@@ -12840,7 +12796,6 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
cookiein, cookieinlen, cookieout, cookieoutlen,
flags, dname, bandwidth, true);
cleanup:
- VIR_FREE(compression);
qemuMigrationParamsFree(migParams);
VIR_FREE(migrate_disks);
return ret;
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 33d91ccf38..388a1f5804 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -139,32 +139,85 @@ qemuMigrationParamsFree(qemuMigrationParamsPtr migParams)
static int
-qemuMigrationParamsSetCompression(qemuMigrationCompressionPtr compression,
+qemuMigrationParamsSetCompression(virTypedParameterPtr params,
+ int nparams,
+ unsigned long flags,
qemuMigrationParamsPtr migParams)
{
- if (compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE))
+ size_t i;
+ int method;
+ qemuMonitorMigrationCaps cap;
+
+ for (i = 0; i < nparams; i++) {
+ if (STRNEQ(params[i].field, VIR_MIGRATE_PARAM_COMPRESSION))
+ continue;
+
+ method = qemuMigrationCompressMethodTypeFromString(params[i].value.s);
+ if (method < 0) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("Unsupported compression method '%s'"),
+ params[i].value.s);
+ goto error;
+ }
+
+ if (migParams->compMethods & (1ULL << method)) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("Compression method '%s' is specified
twice"),
+ params[i].value.s);
+ goto error;
+ }
+
+ migParams->compMethods |= 1ULL << method;
+
+ switch ((qemuMigrationCompressMethod) method) {
+ case QEMU_MIGRATION_COMPRESS_XBZRLE:
+ cap = QEMU_MONITOR_MIGRATION_CAPS_XBZRLE;
+ break;
+
+ case QEMU_MIGRATION_COMPRESS_MT:
+ cap = QEMU_MONITOR_MIGRATION_CAPS_COMPRESS;
+ break;
+
+ case QEMU_MIGRATION_COMPRESS_LAST:
+ default:
+ continue;
+ }
+ ignore_value(virBitmapSetBit(migParams->caps, cap));
+ }
+
+ if (params) {
+ GET(virTypedParamsGetInt, COMPRESSION_MT_LEVEL, compressLevel);
+ GET(virTypedParamsGetInt, COMPRESSION_MT_THREADS, compressThreads);
+ GET(virTypedParamsGetInt, COMPRESSION_MT_DTHREADS, decompressThreads);
+ GET(virTypedParamsGetULLong, COMPRESSION_XBZRLE_CACHE, xbzrleCacheSize);
+ }
+
+ if ((migParams->params.compressLevel_set ||
+ migParams->params.compressThreads_set ||
+ migParams->params.decompressThreads_set) &&
+ !(migParams->compMethods & (1ULL << QEMU_MIGRATION_COMPRESS_MT))) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("Turn multithread compression on to tune it"));
+ goto error;
+ }
+
+ if (migParams->params.xbzrleCacheSize_set &&
+ !(migParams->compMethods & (1ULL <<
QEMU_MIGRATION_COMPRESS_XBZRLE))) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("Turn xbzrle compression on to tune it"));
+ goto error;
+ }
+
+ if (!migParams->compMethods && (flags & VIR_MIGRATE_COMPRESSED)) {
+ migParams->compMethods = 1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE;
ignore_value(virBitmapSetBit(migParams->caps,
QEMU_MONITOR_MIGRATION_CAPS_XBZRLE));
-
- if (compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_MT))
- ignore_value(virBitmapSetBit(migParams->caps,
- QEMU_MONITOR_MIGRATION_CAPS_COMPRESS));
-
- migParams->compMethods = compression->methods;
-
- migParams->params.compressLevel_set = compression->level_set;
- migParams->params.compressLevel = compression->level;
-
- migParams->params.compressThreads_set = compression->threads_set;
- migParams->params.compressThreads = compression->threads;
-
- migParams->params.decompressThreads_set = compression->dthreads_set;
- migParams->params.decompressThreads = compression->dthreads;
-
- migParams->params.xbzrleCacheSize_set = compression->xbzrle_cache_set;
- migParams->params.xbzrleCacheSize = compression->xbzrle_cache;
+ }
return 0;
+
+ error:
+ return -1;
}
@@ -172,8 +225,7 @@ qemuMigrationParamsPtr
qemuMigrationParamsFromFlags(virTypedParameterPtr params,
int nparams,
unsigned long flags,
- qemuMigrationParty party,
- qemuMigrationCompressionPtr compression)
+ qemuMigrationParty party)
{
qemuMigrationParamsPtr migParams;
size_t i;
@@ -207,7 +259,7 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
goto error;
}
- if (qemuMigrationParamsSetCompression(compression, migParams) < 0)
+ if (qemuMigrationParamsSetCompression(params, nparams, flags, migParams) < 0)
goto error;
return migParams;
@@ -220,89 +272,6 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
#undef GET
-qemuMigrationCompressionPtr
-qemuMigrationAnyCompressionParse(virTypedParameterPtr params,
- int nparams,
- unsigned long flags)
-{
- size_t i;
- qemuMigrationCompressionPtr compression = NULL;
-
- if (VIR_ALLOC(compression) < 0)
- return NULL;
-
- for (i = 0; i < nparams; i++) {
- int method;
-
- if (STRNEQ(params[i].field, VIR_MIGRATE_PARAM_COMPRESSION))
- continue;
-
- method = qemuMigrationCompressMethodTypeFromString(params[i].value.s);
- if (method < 0) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("Unsupported compression method '%s'"),
- params[i].value.s);
- goto error;
- }
-
- if (compression->methods & (1ULL << method)) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("Compression method '%s' is specified
twice"),
- params[i].value.s);
- goto error;
- }
-
- compression->methods |= 1ULL << method;
- }
-
-#define GET_PARAM(PARAM, TYPE, VALUE) \
- do { \
- int rc; \
- const char *par = VIR_MIGRATE_PARAM_COMPRESSION_ ## PARAM; \
- \
- if ((rc = virTypedParamsGet ## TYPE(params, nparams, \
- par, &compression->VALUE)) < 0) \
- goto error; \
- \
- if (rc == 1) \
- compression->VALUE ## _set = true; \
- } while (0)
-
- if (params) {
- GET_PARAM(MT_LEVEL, Int, level);
- GET_PARAM(MT_THREADS, Int, threads);
- GET_PARAM(MT_DTHREADS, Int, dthreads);
- GET_PARAM(XBZRLE_CACHE, ULLong, xbzrle_cache);
- }
-
-#undef GET_PARAM
-
- if ((compression->level_set ||
- compression->threads_set ||
- compression->dthreads_set) &&
- !(compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_MT))) {
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("Turn multithread compression on to tune it"));
- goto error;
- }
-
- if (compression->xbzrle_cache_set &&
- !(compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE)))
{
- virReportError(VIR_ERR_INVALID_ARG, "%s",
- _("Turn xbzrle compression on to tune it"));
- goto error;
- }
-
- if (!compression->methods && (flags & VIR_MIGRATE_COMPRESSED))
- compression->methods = 1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE;
-
- return compression;
-
- error:
- VIR_FREE(compression);
- return NULL;
-}
-
int
qemuMigrationParamsDump(qemuMigrationParamsPtr migParams,
virTypedParameterPtr *params,
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index d778a8e339..3d1ada1a61 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -28,25 +28,6 @@
# include "qemu_conf.h"
-typedef struct _qemuMigrationCompression qemuMigrationCompression;
-typedef qemuMigrationCompression *qemuMigrationCompressionPtr;
-struct _qemuMigrationCompression {
- unsigned long long methods;
-
- bool level_set;
- int level;
-
- bool threads_set;
- int threads;
-
- bool dthreads_set;
- int dthreads;
-
- bool xbzrle_cache_set;
- unsigned long long xbzrle_cache;
-};
-
-
typedef struct _qemuMigrationParams qemuMigrationParams;
typedef qemuMigrationParams *qemuMigrationParamsPtr;
@@ -60,13 +41,8 @@ qemuMigrationParamsPtr
qemuMigrationParamsFromFlags(virTypedParameterPtr params,
int nparams,
unsigned long flags,
- qemuMigrationParty party,
- qemuMigrationCompressionPtr compression);
+ qemuMigrationParty party);
-qemuMigrationCompressionPtr
-qemuMigrationAnyCompressionParse(virTypedParameterPtr params,
- int nparams,
- unsigned long flags);
int
qemuMigrationParamsDump(qemuMigrationParamsPtr migParams,
virTypedParameterPtr *params,
--
2.17.0