From: Eli Qiao <liyong.qiao@xxxxxxxxx> Add qemuDomainMigrateGetParameters and qemuDomainMigrateSetParameters in order to set or get multi-thread compress parameters. Signed-off-by: ShaoHe Feng <shaohe.feng@xxxxxxxxx> Signed-off-by: Eli Qiao <liyong.qiao@xxxxxxxxx> --- src/qemu/qemu_driver.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 498bcac..16a8b44 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -110,6 +110,8 @@ VIR_LOG_INIT("qemu.qemu_driver"); #define QEMU_NB_BLOCK_IO_TUNE_PARAM 6 #define QEMU_NB_BLOCK_IO_TUNE_PARAM_MAX 13 +#define QEMU_NB_MIGRATE_COMPRESS_PARAM 3 + #define QEMU_NB_NUMA_PARAM 2 #define QEMU_SCHED_MIN_PERIOD 1000LL @@ -13745,6 +13747,160 @@ qemuDomainMigrateGetMaxSpeed(virDomainPtr dom, return ret; } +static int +qemuDomainMigrateSetParameters(virDomainPtr dom, + virTypedParameterPtr params, + int nparams, + unsigned int flags) +{ + size_t i; + virQEMUDriverPtr driver = dom->conn->privateData; + virDomainObjPtr vm; + qemuDomainObjPrivatePtr priv; + int ret = -1; + int level = -1; + int threads = -1; + int dthreads = -1; + + virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1); + + if (!(vm = qemuDomObjFromDomain(dom))) + goto cleanup; + + if (virTypedParamsValidate(params, nparams, + VIR_DOMAIN_MIRGRATE_COMPRESSION_LEVEL, + VIR_TYPED_PARAM_INT, + VIR_DOMAIN_MIRGRATE_COMPRESSION_THREADS, + VIR_TYPED_PARAM_INT, + VIR_DOMAIN_MIRGRATE_DECOMPRESSION_THREADS, + VIR_TYPED_PARAM_INT, + NULL) < 0) + goto cleanup; + + if (virDomainMigrateSetParametersEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + priv = vm->privateData; + + for (i = 0; i < nparams; i++) { + virTypedParameterPtr param = ¶ms[i]; + + if (STREQ(param->field, VIR_DOMAIN_MIRGRATE_COMPRESSION_LEVEL)) { + level = params[i].value.i; + } else if (STREQ(param->field, VIR_DOMAIN_MIRGRATE_COMPRESSION_THREADS)) { + threads = params[i].value.i; + } else if (STREQ(param->field, VIR_DOMAIN_MIRGRATE_DECOMPRESSION_THREADS)) { + dthreads = params[i].value.i; + } + } + + if (level > QEMU_DOMAIN_MIG_PARAMETERS_LEVEL_MAX) { + virReportError(VIR_ERR_OVERFLOW, + _("level must be less than %d"), + QEMU_DOMAIN_MIG_PARAMETERS_LEVEL_MAX + 1); + goto cleanup; + } else if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_IN) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("compress level is invalid for destination " + "hypervisor during live migration")); + goto cleanup; + } + + if ((threads > QEMU_DOMAIN_MIG_PARAMETERS_THREADS_MAX) || + (dthreads > QEMU_DOMAIN_MIG_PARAMETERS_THREADS_MAX)) { + virReportError(VIR_ERR_OVERFLOW, _("both compress and decompress " + "threads number must be less than %d"), + QEMU_DOMAIN_MIG_PARAMETERS_THREADS_MAX + 1); + goto cleanup; + } else if ((priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_IN) || + (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("neither compress nor decompress threads number " + "setting is valid during live migration")); + goto cleanup; + } + + VIR_DEBUG("Setting migration multi-thread compress parameters: " + "level is %d, compress threads is %d, " + "decompress threads is %d", level, threads, dthreads); + + qemuDomainObjEnterMonitor(driver, vm); + ret = qemuMonitorSetMigrationParameters(priv->mon, level, threads, dthreads); + + if (qemuDomainObjExitMonitor(driver, vm) < 0) + ret = -1; + ret = 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + +static int +qemuDomainMigrateGetParameters(virDomainPtr dom, + virTypedParameterPtr params, + int *nparams, + unsigned int flags) +{ + virDomainObjPtr vm; + virQEMUDriverPtr driver = dom->conn->privateData; + qemuDomainObjPrivatePtr priv; + int ret = -1; + unsigned int level = 0; + unsigned int threads = 0; + unsigned int dthreads = 0; + + + virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1); + + if (!(vm = qemuDomObjFromDomain(dom))) + goto cleanup; + + priv = vm->privateData; + + if (virDomainMigrateGetParametersEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if ((*nparams) == 0) { + *nparams = QEMU_NB_MIGRATE_COMPRESS_PARAM; + ret = 0; + goto cleanup; + } + + qemuDomainObjEnterMonitor(driver, vm); + /* now qemu only support 3 compression parameters, + and compession method such as zlib will support in later version. */ + ret = qemuMonitorGetMigrationParameters(priv->mon, &level, &threads, &dthreads) < 0; + if (qemuDomainObjExitMonitor(driver, vm) < 0) + ret = -1; + if (ret < 0) + goto cleanup; + + if (virTypedParameterAssign(params, + VIR_DOMAIN_MIRGRATE_COMPRESSION_LEVEL, + VIR_TYPED_PARAM_UINT, + level) < 0) + goto cleanup; + + if (virTypedParameterAssign(params + 1, + VIR_DOMAIN_MIRGRATE_COMPRESSION_THREADS, + VIR_TYPED_PARAM_UINT, + threads) < 0) + goto cleanup; + + if (virTypedParameterAssign(params + 2, + VIR_DOMAIN_MIRGRATE_DECOMPRESSION_THREADS, + VIR_TYPED_PARAM_UINT, + dthreads) < 0) + goto cleanup; + + ret = 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} typedef enum { VIR_DISK_CHAIN_NO_ACCESS, @@ -20315,6 +20471,8 @@ static virHypervisorDriver qemuHypervisorDriver = { .domainMigrateSetCompressionCache = qemuDomainMigrateSetCompressionCache, /* 1.0.3 */ .domainMigrateSetMaxSpeed = qemuDomainMigrateSetMaxSpeed, /* 0.9.0 */ .domainMigrateGetMaxSpeed = qemuDomainMigrateGetMaxSpeed, /* 0.9.5 */ + .domainMigrateGetParameters = qemuDomainMigrateGetParameters, /* 1.2.17 */ + .domainMigrateSetParameters = qemuDomainMigrateSetParameters, /* 1.2.17 */ .connectDomainEventRegisterAny = qemuConnectDomainEventRegisterAny, /* 0.8.0 */ .connectDomainEventDeregisterAny = qemuConnectDomainEventDeregisterAny, /* 0.8.0 */ .domainManagedSave = qemuDomainManagedSave, /* 0.8.0 */ -- 2.1.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list