From 8a83181c90a1a945c0de2e27f71bc9a5cdb48cda Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Fri, 9 Mar 2018 17:30:16 +0100 Subject: [PATCH] qemu: Drop qemuMigrationCompression structure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- src/qemu/qemu_driver.c | 63 ++--------- src/qemu/qemu_migration_params.c | 173 +++++++++++++------------------ src/qemu/qemu_migration_params.h | 26 +---- 3 files changed, 81 insertions(+), 181 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e0f519bfa0..bd7970066f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12104,7 +12104,6 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn, virQEMUDriverPtr driver = dconn->privateData; virDomainDefPtr def = NULL; char *origname = NULL; - qemuMigrationCompressionPtr compression = NULL; qemuMigrationParamsPtr migParams = NULL; int ret = -1; @@ -12116,11 +12115,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)) { @@ -12141,7 +12137,6 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn, st, &def, origname, migParams, flags); cleanup: - VIR_FREE(compression); qemuMigrationParamsFree(migParams); VIR_FREE(origname); virDomainDefFree(def); @@ -12166,7 +12161,6 @@ qemuDomainMigratePrepare2(virConnectPtr dconn, virQEMUDriverPtr driver = dconn->privateData; virDomainDefPtr def = NULL; char *origname = NULL; - qemuMigrationCompressionPtr compression = NULL; qemuMigrationParamsPtr migParams = NULL; int ret = -1; @@ -12182,11 +12176,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)) { @@ -12214,7 +12205,6 @@ qemuDomainMigratePrepare2(virConnectPtr dconn, cleanup: qemuMigrationParamsFree(migParams); - VIR_FREE(compression); VIR_FREE(origname); virDomainDefFree(def); return ret; @@ -12235,7 +12225,6 @@ qemuDomainMigratePerform(virDomainPtr dom, virDomainObjPtr vm; int ret = -1; const char *dconnuri = NULL; - qemuMigrationCompressionPtr compression = NULL; qemuMigrationParamsPtr migParams = NULL; virCheckFlags(QEMU_MIGRATION_FLAGS, -1); @@ -12247,11 +12236,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))) @@ -12281,7 +12267,6 @@ qemuDomainMigratePerform(virDomainPtr dom, cleanup: qemuMigrationParamsFree(migParams); - VIR_FREE(compression); return ret; } @@ -12425,7 +12410,6 @@ qemuDomainMigratePrepare3(virConnectPtr dconn, virQEMUDriverPtr driver = dconn->privateData; virDomainDefPtr def = NULL; char *origname = NULL; - qemuMigrationCompressionPtr compression = NULL; qemuMigrationParamsPtr migParams = NULL; int ret = -1; @@ -12441,11 +12425,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))) @@ -12463,7 +12444,6 @@ qemuDomainMigratePrepare3(virConnectPtr dconn, cleanup: qemuMigrationParamsFree(migParams); - VIR_FREE(compression); VIR_FREE(origname); virDomainDefFree(def); return ret; @@ -12491,7 +12471,6 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn, int nmigrate_disks; const char **migrate_disks = NULL; char *origname = NULL; - qemuMigrationCompressionPtr compression = NULL; qemuMigrationParamsPtr migParams = NULL; int ret = -1; @@ -12523,11 +12502,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) { @@ -12556,7 +12532,6 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn, cleanup: qemuMigrationParamsFree(migParams); - VIR_FREE(compression); VIR_FREE(migrate_disks); VIR_FREE(origname); virDomainDefFree(def); @@ -12580,7 +12555,6 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn, virQEMUDriverPtr driver = dconn->privateData; virDomainDefPtr def = NULL; char *origname = NULL; - qemuMigrationCompressionPtr compression = NULL; qemuMigrationParamsPtr migParams = NULL; int ret = -1; @@ -12592,11 +12566,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))) @@ -12611,7 +12582,6 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn, st, &def, origname, migParams, flags); cleanup: - VIR_FREE(compression); qemuMigrationParamsFree(migParams); VIR_FREE(origname); virDomainDefFree(def); @@ -12634,7 +12604,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; @@ -12656,11 +12625,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))) @@ -12675,7 +12641,6 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr dconn, st, &def, origname, migParams, flags); cleanup: - VIR_FREE(compression); qemuMigrationParamsFree(migParams); VIR_FREE(origname); virDomainDefFree(def); @@ -12698,17 +12663,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))) @@ -12728,7 +12689,6 @@ qemuDomainMigratePerform3(virDomainPtr dom, cleanup: qemuMigrationParamsFree(migParams); - VIR_FREE(compression); return ret; } @@ -12755,7 +12715,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; @@ -12796,11 +12755,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))) @@ -12818,7 +12774,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)) - ignore_value(virBitmapSetBit(migParams->caps, - QEMU_MONITOR_MIGRATION_CAPS_XBZRLE)); + size_t i; + int method; + qemuMonitorMigrationCaps cap; - if (compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_MT)) - ignore_value(virBitmapSetBit(migParams->caps, - QEMU_MONITOR_MIGRATION_CAPS_COMPRESS)); + for (i = 0; i < nparams; i++) { + if (STRNEQ(params[i].field, VIR_MIGRATE_PARAM_COMPRESSION)) + continue; - migParams->compMethods = compression->methods; + 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->params.compressLevel_set = compression->level_set; - migParams->params.compressLevel = compression->level; + migParams->compMethods |= 1ULL << method; - migParams->params.compressThreads_set = compression->threads_set; - migParams->params.compressThreads = compression->threads; + switch ((qemuMigrationCompressMethod) method) { + case QEMU_MIGRATION_COMPRESS_XBZRLE: + cap = QEMU_MONITOR_MIGRATION_CAPS_XBZRLE; + break; - migParams->params.decompressThreads_set = compression->dthreads_set; - migParams->params.decompressThreads = compression->dthreads; + case QEMU_MIGRATION_COMPRESS_MT: + cap = QEMU_MONITOR_MIGRATION_CAPS_COMPRESS; + break; - migParams->params.xbzrleCacheSize_set = compression->xbzrle_cache_set; - migParams->params.xbzrleCacheSize = compression->xbzrle_cache; + 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)); + } 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, -- GitLab