just support setting these params for Migrate3Full protocal.
Signed-off-by: Eli Qiao <liyong.qiao(a)intel.com>
Signed-off-by: ShaoHe Feng <shaohe.feng(a)intel.com>
---
include/libvirt/libvirt-domain.h | 24 ++++++++++++++++++++
src/qemu/qemu_domain.h | 3 +++
src/qemu/qemu_driver.c | 28 +++++++++++++++++++++++
src/qemu/qemu_migration.c | 49 ++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_migration.h | 23 +++++++++++++------
5 files changed, 120 insertions(+), 7 deletions(-)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index e8202cf..8d1d93e 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -2800,6 +2800,30 @@ int virDomainAbortJob(virDomainPtr dom);
/**
+ * VIR_DOMAIN_MIRGRATE_COMPRESSION_LEVEL:
+ *
+ * .domainMigrateGetParameters field: level of compression when live migration,
+ * as VIR_TYPED_PARAM_UINT.
+ */
+# define VIR_DOMAIN_MIRGRATE_COMPRESSION_LEVEL "migrate.compress-level"
+
+/**
+ * VIR_DOMAIN_MIRGRATE_COMPRESSION_THREADS:
+ *
+ * .domainMigrateGetParameters field: numbers of compression threads when live
+ * migration, as VIR_TYPED_PARAM_UINT.
+ */
+# define VIR_DOMAIN_MIRGRATE_COMPRESSION_THREADS "migrate.compress-threads"
+
+/**
+ * VIR_DOMAIN_MIRGRATE_DECOMPRESSION_THREADS:
+ *
+ * .domainMigrateGetParameters field: numbers of decompression threads when
+ * live migration, as VIR_TYPED_PARAM_UINT.
+ */
+# define VIR_DOMAIN_MIRGRATE_DECOMPRESSION_THREADS
"migrate.decompress-threads"
+
+/**
* virConnectDomainEventGenericCallback:
* @conn: the connection pointer
* @dom: the domain pointer
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 2af7c59..12b1624 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -48,6 +48,9 @@
# define QEMU_DOMAIN_MIG_BANDWIDTH_MAX (INT64_MAX / (1024 * 1024))
# endif
+# define QEMU_DOMAIN_MIG_PARAMETERS_LEVEL_MAX 9
+# define QEMU_DOMAIN_MIG_PARAMETERS_THREADS_MAX 255
+
# define JOB_MASK(job) (1 << (job - 1))
# define QEMU_JOB_DEFAULT_MASK \
(JOB_MASK(QEMU_JOB_QUERY) | \
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c4b3979..2bbf37b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12180,6 +12180,7 @@ qemuDomainMigrateBegin3Params(virDomainPtr domain,
const char **migrate_disks = NULL;
int nmigrate_disks;
char *ret = NULL;
+ virQEMUDriverPtr driver = domain->conn->privateData;
virDomainObjPtr vm;
virCheckFlags(QEMU_MIGRATION_FLAGS, NULL);
@@ -12208,6 +12209,10 @@ qemuDomainMigrateBegin3Params(virDomainPtr domain,
virDomainObjEndAPI(&vm);
goto cleanup;
}
+ if (qemuMigrationPrepareExtraParams(driver, vm, params, nparams) < 0) {
+ virDomainObjEndAPI(&vm);
+ return NULL;
+ }
ret = qemuMigrationBegin(domain->conn, vm, xmlin, dname,
cookieout, cookieoutlen,
@@ -12281,6 +12286,7 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
virQEMUDriverPtr driver = dconn->privateData;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virDomainDefPtr def = NULL;
+ virDomainObjPtr vm = NULL;
const char *dom_xml = NULL;
const char *dname = NULL;
const char *uri_in = NULL;
@@ -12288,6 +12294,8 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
int nmigrate_disks;
const char **migrate_disks = NULL;
char *origname = NULL;
+ unsigned char uuid[VIR_UUID_BUFLEN];
+ char *uuidstr = NULL;
int ret = -1;
virCheckFlagsGoto(QEMU_MIGRATION_FLAGS, cleanup);
@@ -12328,6 +12336,8 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname, &origname)))
goto cleanup;
+ memcpy(uuid, def->uuid, VIR_UUID_BUFLEN);
+
if (virDomainMigratePrepare3ParamsEnsureACL(dconn, def) < 0)
goto cleanup;
@@ -12337,6 +12347,24 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
uri_in, uri_out,
&def, origname, listenAddress,
nmigrate_disks, migrate_disks, flags);
+ if (ret < 0)
+ goto cleanup;
+
+ if (!(vm = virDomainObjListFindByUUID(driver->domains, uuid))) {
+ virUUIDFormat(uuid, uuidstr);
+ virReportError(VIR_ERR_NO_DOMAIN,
+ _("no domain with matching uuid '%s'"),
uuidstr);
+ goto cleanup;
+ }
+ /* only domain start, we can set these prarams for it. */
+ ret = qemuMigrationPrepareExtraParams(driver, vm, params, nparams);
+ if (ret < 0){
+ /* we need to stop the vm and realse the resource. */
+ virDomainAuditStart(vm, "migrated", false);
+ qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, 0);
+ qemuMigrationJobFinish(driver, vm);
+ }
+ virObjectUnlock(vm);
cleanup:
VIR_FREE(migrate_disks);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 891ddb6..fd39e79 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3523,6 +3523,55 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
/*
+ * First version just prepare the multi-thread compress params.
+ * we can extend more params here for live migration
+ */
+int
+qemuMigrationPrepareExtraParams(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virTypedParameterPtr params,
+ int nparams)
+{
+ qemuDomainObjPrivatePtr priv = NULL;
+ int level = -1;
+ int threads = -1;
+ int dthreads = -1;
+ int ret = -1;
+
+ if (virTypedParamsGetInt(params, nparams,
+ VIR_DOMAIN_MIRGRATE_COMPRESSION_LEVEL, &level) < 0)
+ return -1;
+ if (virTypedParamsGetInt(params, nparams,
+ VIR_DOMAIN_MIRGRATE_COMPRESSION_THREADS, &threads) <
0)
+ return -1;
+ if (virTypedParamsGetInt(params, nparams,
+ VIR_DOMAIN_MIRGRATE_DECOMPRESSION_THREADS, &dthreads)
< 0)
+ return -1;
+
+ 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);
+ return -1;
+ }
+ 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);
+ return -1;
+ }
+
+ priv = vm->privateData;
+ qemuDomainObjEnterMonitor(driver, vm);
+ ret = qemuMonitorSetMigrationParameters(priv->mon, level, threads, dthreads);
+ if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ return -1;
+ return ret;
+}
+
+
+/*
* This version starts an empty VM listening on a localhost TCP port, and
* sets up the corresponding virStream to handle the incoming data.
*/
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 1092e5f..4a4c848 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -45,15 +45,18 @@
VIR_MIGRATE_MT_COMPRESSED)
/* All supported migration parameters and their types. */
-# define QEMU_MIGRATION_PARAMETERS \
- VIR_MIGRATE_PARAM_URI, VIR_TYPED_PARAM_STRING, \
- VIR_MIGRATE_PARAM_DEST_NAME, VIR_TYPED_PARAM_STRING, \
- VIR_MIGRATE_PARAM_DEST_XML, VIR_TYPED_PARAM_STRING, \
- VIR_MIGRATE_PARAM_BANDWIDTH, VIR_TYPED_PARAM_ULLONG, \
- VIR_MIGRATE_PARAM_GRAPHICS_URI, VIR_TYPED_PARAM_STRING, \
- VIR_MIGRATE_PARAM_LISTEN_ADDRESS, VIR_TYPED_PARAM_STRING, \
+# define QEMU_MIGRATION_PARAMETERS \
+ VIR_MIGRATE_PARAM_URI, VIR_TYPED_PARAM_STRING, \
+ VIR_MIGRATE_PARAM_DEST_NAME, VIR_TYPED_PARAM_STRING, \
+ VIR_MIGRATE_PARAM_DEST_XML, VIR_TYPED_PARAM_STRING, \
+ VIR_MIGRATE_PARAM_BANDWIDTH, VIR_TYPED_PARAM_ULLONG, \
+ VIR_MIGRATE_PARAM_GRAPHICS_URI, VIR_TYPED_PARAM_STRING, \
+ VIR_MIGRATE_PARAM_LISTEN_ADDRESS, VIR_TYPED_PARAM_STRING, \
VIR_MIGRATE_PARAM_MIGRATE_DISKS, VIR_TYPED_PARAM_STRING | \
VIR_TYPED_PARAM_MULTIPLE, \
+ 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
@@ -137,6 +140,12 @@ int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
const char **migrate_disks,
unsigned long flags);
+int
+qemuMigrationPrepareExtraParams(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virTypedParameterPtr params,
+ int nparams);
+
int qemuMigrationPerform(virQEMUDriverPtr driver,
virConnectPtr conn,
virDomainObjPtr vm,
--
2.1.4