[PATCH 4/9] set multi-thread compress params for Migrate3 during live migration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



just support setting these params for Migrate3Full protocal.

Signed-off-by: Eli Qiao <liyong.qiao@xxxxxxxxx>
Signed-off-by: ShaoHe Feng <shaohe.feng@xxxxxxxxx>
---
 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        |  9 ++++++++
 5 files changed, 113 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index d851225..1c6ab16 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -2791,6 +2791,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 a6df199..53af176 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 d1b00a2..498bcac 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12599,6 +12599,7 @@ qemuDomainMigrateBegin3Params(virDomainPtr domain,
 {
     const char *xmlin = NULL;
     const char *dname = NULL;
+    virQEMUDriverPtr driver = domain->conn->privateData;
     virDomainObjPtr vm;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, NULL);
@@ -12620,6 +12621,10 @@ qemuDomainMigrateBegin3Params(virDomainPtr domain,
         virDomainObjEndAPI(&vm);
         return NULL;
     }
+    if (qemuMigrationPrepareExtraParams(driver, vm, params, nparams) < 0) {
+        virDomainObjEndAPI(&vm);
+        return NULL;
+    }
 
     return qemuMigrationBegin(domain->conn, vm, xmlin, dname,
                               cookieout, cookieoutlen, flags);
@@ -12688,11 +12693,14 @@ 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;
     const char *listenAddress = cfg->migrationAddress;
     char *origname = NULL;
+    unsigned char uuid[VIR_UUID_BUFLEN];
+    char *uuidstr = NULL;
     int ret = -1;
 
     virCheckFlagsGoto(QEMU_MIGRATION_FLAGS, cleanup);
@@ -12726,6 +12734,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;
 
@@ -12734,6 +12744,24 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
                                      cookieout, cookieoutlen,
                                      uri_in, uri_out,
                                      &def, origname, listenAddress, 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(origname);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 3322f72..4ca4db2 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3290,6 +3290,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 065623b..54b6a32 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -52,6 +52,9 @@
     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_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
 
 
@@ -131,6 +134,12 @@ int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
                                const char *listenAddress,
                                unsigned long flags);
 
+int
+qemuMigrationPrepareExtraParams(virQEMUDriverPtr driver,
+                                virDomainObjPtr vm,
+                                virTypedParameterPtr params,
+                                int nparams);
+
 int qemuMigrationPerform(virQEMUDriverPtr driver,
                          virConnectPtr conn,
                          virDomainObjPtr vm,
-- 
2.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]