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

[libvirt] [PATCH v4 4/5] qemu: migration: add compression options



Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy virtuozzo com>
---
 include/libvirt/libvirt-domain.h | 33 ++++++++++++++++
 src/qemu/qemu_migration.c        | 85 +++++++++++++++++++++++++++++++++++++++-
 src/qemu/qemu_migration.h        |  7 ++++
 3 files changed, 124 insertions(+), 1 deletion(-)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index b3a176f..59df373 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -784,6 +784,39 @@ typedef enum {
 
 # define VIR_MIGRATE_PARAM_COMPRESSION    "compression"
 
+/**
+ * VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL:
+ *
+ * virDomainMigrate* params field: the level of compression for multithread
+ * compression as VIR_TYPED_PARAM_INT. Accepted values * are in range 0-9.
+ * 0 is no compression, 1 is maximum speed and 9 is maximum compression.
+ */
+# define VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL    "compression.mt.level"
+
+/**
+ * VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS:
+ *
+ * virDomainMigrate* params field: the number of compression threads for
+ * multithread compression as VIR_TYPED_PARAM_INT.
+ */
+# define VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS "compression.mt.threads"
+
+/**
+ * VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS:
+ *
+ * virDomainMigrate* params field: the number of decompression threads for
+ * multithread compression as VIR_TYPED_PARAM_INT.
+ */
+# define VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS "compression.mt.dthreads"
+
+/**
+ * VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE:
+ *
+ * virDomainMigrate* params field: the size of page cache for xbzrle
+ * compression as VIR_TYPED_PARAM_ULLONG.
+ */
+# define VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE "compression.xbzrle.cache"
+
 /* Domain migration. */
 virDomainPtr virDomainMigrate (virDomainPtr domain, virConnectPtr dconn,
                                unsigned long flags, const char *dname,
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 5fcf132..88d62a9 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3305,6 +3305,9 @@ qemuMigrationSetCompression(virQEMUDriverPtr driver,
                             qemuMigrationCompressionPtr compression,
                             unsigned int flags)
 {
+    int ret = -1;
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+
     /*
      * if compression methods are not set explicitly use flags to
      * set default compression methods
@@ -3328,7 +3331,24 @@ qemuMigrationSetCompression(virQEMUDriverPtr driver,
                                job) < 0)
         return -1;
 
-    return 0;
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, job) < 0)
+        return -1;
+
+    if (qemuMonitorSetMigrationParameters(priv->mon, &compression->params) < 0)
+        goto cleanup;
+
+    if (compression->xbzrle_cache_set &&
+        qemuMonitorSetMigrationCacheSize(priv->mon,
+                                         compression->xbzrle_cache) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        ret = -1;
+
+    return ret;
 }
 
 static int
@@ -6359,6 +6379,8 @@ qemuMigrationCompressionParseParams(qemuMigrationCompressionPtr compression,
                                     virTypedParameterPtr params, int nparams)
 {
     size_t i;
+    qemuMonitorMigrationParametersPtr cparams = &compression->params;
+    int rc;
 
     for (i = 0; i < nparams; i++) {
         if (STRNEQ(params[i].field, VIR_MIGRATE_PARAM_COMPRESSION))
@@ -6379,6 +6401,41 @@ qemuMigrationCompressionParseParams(qemuMigrationCompressionPtr compression,
         }
     }
 
+#define VIR_GET_PARAMETER_OPT(PARAM, TYPE, PARENT, VALUE)               \
+    if ((rc = virTypedParamsGet ## TYPE(params, nparams,                \
+                                         PARAM, &PARENT->VALUE)) < 0)   \
+        return -1;                                                      \
+                                                                        \
+    if (rc == 1)                                                        \
+        PARENT->VALUE ## _set = 1;
+
+    VIR_GET_PARAMETER_OPT(VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL,
+                          Int, cparams, level)
+    VIR_GET_PARAMETER_OPT(VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS,
+                          Int, cparams, threads)
+    VIR_GET_PARAMETER_OPT(VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS,
+                          Int, cparams, dthreads)
+    VIR_GET_PARAMETER_OPT(VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE,
+                          ULLong, compression, xbzrle_cache)
+
+#undef VIR_GET_PARAMETER_OPT
+
+    if ((cparams->level_set || cparams->threads_set || cparams->dthreads_set) &&
+        !(compression->methods & QEMU_MIGRATION_COMPESS_MULTITHREAD)) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("You cannot specify multithread compression "
+                         "parameters without turning it on."));
+        return -1;
+    }
+
+    if (compression->xbzrle_cache_set &&
+        !(compression->methods & QEMU_MIGRATION_COMPESS_XBZRLE)) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("You cannot specify xbzrle compression "
+                         "parameters without turning it on."));
+        return -1;
+    }
+
     return 0;
 }
 
@@ -6388,6 +6445,8 @@ qemuMigrationCompressionDumpParams(qemuMigrationCompressionPtr compression,
                                    int *nparams,
                                    int *maxparams)
 {
+    qemuMonitorMigrationParametersPtr cparams = &compression->params;
+
     if ((compression->methods & QEMU_MIGRATION_COMPESS_XBZRLE) &&
         virTypedParamsAddString(params, nparams, maxparams,
                                 VIR_MIGRATE_PARAM_COMPRESSION,
@@ -6400,5 +6459,29 @@ qemuMigrationCompressionDumpParams(qemuMigrationCompressionPtr compression,
                                 "multithread") < 0)
         return -1;
 
+    if (cparams->level_set &&
+        virTypedParamsAddInt(params, nparams, maxparams,
+                             VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL,
+                             cparams->level) < 0)
+        return -1;
+
+    if (cparams->threads_set &&
+        virTypedParamsAddInt(params, nparams, maxparams,
+                             VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS,
+                             cparams->threads) < 0)
+        return -1;
+
+    if (cparams->dthreads_set &&
+        virTypedParamsAddInt(params, nparams, maxparams,
+                             VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS,
+                             cparams->dthreads) < 0)
+        return -1;
+
+    if (compression->xbzrle_cache_set &&
+        virTypedParamsAddULLong(params, nparams, maxparams,
+                                VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE,
+                                compression->xbzrle_cache) < 0)
+        return -1;
+
     return 0;
 }
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 3cbe944..3758a9c 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -58,6 +58,10 @@ typedef qemuMigrationCompression *qemuMigrationCompressionPtr;
                                         VIR_TYPED_PARAM_MULTIPLE, \
     VIR_MIGRATE_PARAM_COMPRESSION,      VIR_TYPED_PARAM_STRING |  \
                                         VIR_TYPED_PARAM_MULTIPLE, \
+    VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL,         VIR_TYPED_PARAM_INT,    \
+    VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS,       VIR_TYPED_PARAM_INT,    \
+    VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS,      VIR_TYPED_PARAM_INT,    \
+    VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE,     VIR_TYPED_PARAM_ULLONG, \
     NULL
 
 
@@ -84,6 +88,9 @@ typedef enum {
 
 struct _qemuMigrationCompression {
     qemuMigrationCompressMethods methods;
+    qemuMonitorMigrationParameters params;
+    unsigned int xbzrle_cache_set : 1;
+    unsigned long long xbzrle_cache;
 };
 
 int qemuMigrationCompressionParseParams(qemuMigrationCompressionPtr compression,
-- 
1.8.3.1


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