Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
include/libvirt/libvirt-domain.h | 13 +++++-
src/qemu/qemu_driver.c | 75 +++++++++++++++++++++++++++++---
src/qemu/qemu_migration.c | 94 ++++++++++++++++++++++++++++------------
src/qemu/qemu_migration.h | 16 +++++++
src/qemu/qemu_monitor.c | 2 +-
src/qemu/qemu_monitor.h | 1 +
6 files changed, 166 insertions(+), 35 deletions(-)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 65f1618..e868515 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -655,7 +655,7 @@ typedef enum {
* when supported */
VIR_MIGRATE_UNSAFE = (1 << 9), /* force migration even if it is
considered unsafe */
VIR_MIGRATE_OFFLINE = (1 << 10), /* offline migrate */
- VIR_MIGRATE_COMPRESSED = (1 << 11), /* compress data during migration
*/
+ VIR_MIGRATE_COMPRESSED = (1 << 11), /* use default compression method
*/
VIR_MIGRATE_ABORT_ON_ERROR = (1 << 12), /* abort migration on I/O errors
happened during migration */
VIR_MIGRATE_AUTO_CONVERGE = (1 << 13), /* force convergence */
VIR_MIGRATE_RDMA_PIN_ALL = (1 << 14), /* RDMA memory pinning */
@@ -757,6 +757,17 @@ typedef enum {
*/
# define VIR_MIGRATE_PARAM_MIGRATE_DISKS "migrate_disks"
+/**
+ * VIR_MIGRATE_PARAM_COMPRESSION:
+ *
+ * virDomainMigrate* params multiple field: string list of compression methods
+ * that are used to compress migration traffic. Note that this option cannot
+ * be used together with VIR_MIGRATE_COMPRESSED flag, use only one of them.
+ */
+
+# define VIR_MIGRATE_PARAM_COMPRESSION "compression"
+
+
/* Domain migration. */
virDomainPtr virDomainMigrate (virDomainPtr domain, virConnectPtr dconn,
unsigned long flags, const char *dname,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 351e529..129da6d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12163,7 +12163,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
ret = qemuMigrationPrepareDirect(driver, dconn,
NULL, 0, NULL, NULL, /* No cookies */
uri_in, uri_out,
- &def, origname, NULL, 0, NULL, flags);
+ &def, origname, NULL, 0, NULL, NULL, flags);
cleanup:
VIR_FREE(origname);
@@ -12216,7 +12216,7 @@ qemuDomainMigratePerform(virDomainPtr dom,
* Consume any cookie we were able to decode though
*/
ret = qemuMigrationPerform(driver, dom->conn, vm,
- NULL, dconnuri, uri, NULL, NULL, 0, NULL,
+ NULL, dconnuri, uri, NULL, NULL, 0, NULL, NULL,
cookie, cookielen,
NULL, NULL, /* No output cookies in v2 */
flags, dname, resource, false);
@@ -12389,7 +12389,7 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
cookiein, cookieinlen,
cookieout, cookieoutlen,
uri_in, uri_out,
- &def, origname, NULL, 0, NULL, flags);
+ &def, origname, NULL, 0, NULL, NULL, flags);
cleanup:
VIR_FREE(origname);
@@ -12398,6 +12398,60 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
}
static int
+qemuAddCompressionMethod(qemuMigrationCompressMethod value,
+ qemuMigrationCompressMethod *method)
+{
+ if (*method & value) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("Compression method is specified twice."));
+ return -1;
+ }
+
+ *method |= value;
+ return 0;
+}
+
+static int
+qemuGetCompression(virTypedParameterPtr params, int nparams,
+ unsigned int flags,
+ qemuMigrationCompressionPtr compression)
+{
+ size_t i;
+
+ memset(compression, 0, sizeof(*compression));
+
+ for (i = 0; i < nparams; i++) {
+ if (STRNEQ(params[i].field, VIR_MIGRATE_PARAM_COMPRESSION))
+ continue;
+
+ if (STREQ(params[i].value.s, "xbzrle")) {
+ if (qemuAddCompressionMethod(QEMU_MIGRATION_COMPESS_XBZRLE,
+ &compression->method) < 0)
+ return -1;
+ } else if (STREQ(params[i].value.s, "multithread")) {
+ if (qemuAddCompressionMethod(QEMU_MIGRATION_COMPESS_MULTITHREAD,
+ &compression->method) < 0)
+ return -1;
+ } else {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("Unsupported compression method"));
+ return -1;
+ }
+ }
+
+ if (flags & VIR_MIGRATE_COMPRESSED) {
+ if (compression->method) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("You cannot specify default compression with "
+ "other compression parameters"));
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+static int
qemuDomainMigratePrepare3Params(virConnectPtr dconn,
virTypedParameterPtr params,
int nparams,
@@ -12418,6 +12472,7 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
int nmigrate_disks;
const char **migrate_disks = NULL;
char *origname = NULL;
+ qemuMigrationCompression compression;
int ret = -1;
virCheckFlagsGoto(QEMU_MIGRATION_FLAGS, cleanup);
@@ -12445,6 +12500,9 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
if (nmigrate_disks < 0)
goto cleanup;
+ if (qemuGetCompression(params, nparams, flags, &compression) < 0)
+ goto cleanup;
+
if (flags & VIR_MIGRATE_TUNNELLED) {
/* this is a logical error; we never should have gotten here with
* VIR_MIGRATE_TUNNELLED set
@@ -12466,7 +12524,8 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
cookieout, cookieoutlen,
uri_in, uri_out,
&def, origname, listenAddress,
- nmigrate_disks, migrate_disks, flags);
+ nmigrate_disks, migrate_disks,
+ &compression, flags);
cleanup:
VIR_FREE(migrate_disks);
@@ -12600,7 +12659,7 @@ qemuDomainMigratePerform3(virDomainPtr dom,
}
return qemuMigrationPerform(driver, dom->conn, vm, xmlin,
- dconnuri, uri, NULL, NULL, 0, NULL,
+ dconnuri, uri, NULL, NULL, 0, NULL, NULL,
cookiein, cookieinlen,
cookieout, cookieoutlen,
flags, dname, resource, true);
@@ -12627,6 +12686,7 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
int nmigrate_disks;
const char **migrate_disks = NULL;
unsigned long long bandwidth = 0;
+ qemuMigrationCompression compression;
int ret = -1;
virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -12660,6 +12720,9 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
if (nmigrate_disks < 0)
goto cleanup;
+ if (qemuGetCompression(params, nparams, flags, &compression) < 0)
+ goto cleanup;
+
if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup;
@@ -12670,7 +12733,7 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
ret = qemuMigrationPerform(driver, dom->conn, vm, dom_xml,
dconnuri, uri, graphicsuri, listenAddress,
- nmigrate_disks, migrate_disks,
+ nmigrate_disks, migrate_disks, &compression,
cookiein, cookieinlen, cookieout, cookieoutlen,
flags, dname, bandwidth, true);
cleanup:
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index a6412ce..d37e416 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3300,6 +3300,37 @@ qemuMigrationPrepareIncoming(virDomainObjPtr vm,
}
static int
+qemuMigrationSetCompression(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ qemuDomainAsyncJob job,
+ qemuMigrationCompressionPtr compression,
+ unsigned int flags)
+{
+ qemuMigrationCompression deflt;
+
+ if (!compression) {
+ memset(&deflt, 0, sizeof(deflt));
+ if (flags & VIR_MIGRATE_COMPRESSED)
+ deflt.method = QEMU_MIGRATION_COMPESS_XBZRLE;
+ compression = &deflt;
+ }
+
+ if (qemuMigrationSetOption(driver, vm,
+ QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
+ compression->method &
QEMU_MIGRATION_COMPESS_XBZRLE,
+ job) < 0)
+ return -1;
+
+ if (qemuMigrationSetOption(driver, vm,
+ QEMU_MONITOR_MIGRATION_CAPS_COMPRESS,
+ compression->method &
QEMU_MIGRATION_COMPESS_MULTITHREAD,
+ job) < 0)
+ return -1;
+
+ return 0;
+}
+
+static int
qemuMigrationPrepareAny(virQEMUDriverPtr driver,
virConnectPtr dconn,
const char *cookiein,
@@ -3315,6 +3346,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
const char *listenAddress,
size_t nmigrate_disks,
const char **migrate_disks,
+ qemuMigrationCompressionPtr compression,
unsigned long flags)
{
virDomainObjPtr vm = NULL;
@@ -3495,10 +3527,8 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
dataFD[1] = -1; /* 'st' owns the FD now & will close it */
}
- if (qemuMigrationSetOption(driver, vm,
- QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
- flags & VIR_MIGRATE_COMPRESSED,
- QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
+ if (qemuMigrationSetCompression(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
+ compression, flags) < 0)
goto stopjob;
if (STREQ_NULLABLE(protocol, "rdma") &&
@@ -3636,7 +3666,7 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
cookieout, cookieoutlen, def, origname,
- st, NULL, 0, false, NULL, 0, NULL, flags);
+ st, NULL, 0, false, NULL, 0, NULL, NULL, flags);
return ret;
}
@@ -3678,6 +3708,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
const char *listenAddress,
size_t nmigrate_disks,
const char **migrate_disks,
+ qemuMigrationCompressionPtr compression,
unsigned long flags)
{
unsigned short port = 0;
@@ -3800,7 +3831,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
cookieout, cookieoutlen, def, origname,
NULL, uri ? uri->scheme : "tcp",
port, autoPort, listenAddress,
- nmigrate_disks, migrate_disks, flags);
+ nmigrate_disks, migrate_disks, compression,
+ flags);
cleanup:
virURIFree(uri);
VIR_FREE(hostname);
@@ -4280,7 +4312,8 @@ qemuMigrationRun(virQEMUDriverPtr driver,
virConnectPtr dconn,
const char *graphicsuri,
size_t nmigrate_disks,
- const char **migrate_disks)
+ const char **migrate_disks,
+ qemuMigrationCompressionPtr compression)
{
int ret = -1;
unsigned int migrate_flags = QEMU_MONITOR_MIGRATE_BACKGROUND;
@@ -4362,10 +4395,8 @@ qemuMigrationRun(virQEMUDriverPtr driver,
goto cleanup;
}
- if (qemuMigrationSetOption(driver, vm,
- QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
- flags & VIR_MIGRATE_COMPRESSED,
- QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+ if (qemuMigrationSetCompression(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+ compression, flags) < 0)
goto cleanup;
if (qemuMigrationSetOption(driver, vm,
@@ -4579,7 +4610,8 @@ static int doNativeMigrate(virQEMUDriverPtr driver,
virConnectPtr dconn,
const char *graphicsuri,
size_t nmigrate_disks,
- const char **migrate_disks)
+ const char **migrate_disks,
+ qemuMigrationCompressionPtr compression)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
virURIPtr uribits = NULL;
@@ -4629,7 +4661,8 @@ static int doNativeMigrate(virQEMUDriverPtr driver,
ret = qemuMigrationRun(driver, vm, cookiein, cookieinlen, cookieout,
cookieoutlen, flags, resource, &spec, dconn,
- graphicsuri, nmigrate_disks, migrate_disks);
+ graphicsuri, nmigrate_disks, migrate_disks,
+ compression);
if (spec.destType == MIGRATION_DEST_FD)
VIR_FORCE_CLOSE(spec.dest.fd.qemu);
@@ -4653,7 +4686,8 @@ static int doTunnelMigrate(virQEMUDriverPtr driver,
virConnectPtr dconn,
const char *graphicsuri,
size_t nmigrate_disks,
- const char **migrate_disks)
+ const char **migrate_disks,
+ qemuMigrationCompressionPtr compression)
{
virNetSocketPtr sock = NULL;
int ret = -1;
@@ -4690,7 +4724,8 @@ static int doTunnelMigrate(virQEMUDriverPtr driver,
ret = qemuMigrationRun(driver, vm, cookiein, cookieinlen, cookieout,
cookieoutlen, flags, resource, &spec, dconn,
- graphicsuri, nmigrate_disks, migrate_disks);
+ graphicsuri, nmigrate_disks, migrate_disks,
+ compression);
cleanup:
if (spec.destType == MIGRATION_DEST_FD) {
@@ -4801,12 +4836,12 @@ static int doPeer2PeerMigrate2(virQEMUDriverPtr driver,
ret = doTunnelMigrate(driver, vm, st,
NULL, 0, NULL, NULL,
flags, resource, dconn,
- NULL, 0, NULL);
+ NULL, 0, NULL, NULL);
else
ret = doNativeMigrate(driver, vm, uri_out,
cookie, cookielen,
NULL, NULL, /* No out cookie with v2 migration */
- flags, resource, dconn, NULL, 0, NULL);
+ flags, resource, dconn, NULL, 0, NULL, NULL);
/* Perform failed. Make sure Finish doesn't overwrite the error */
if (ret < 0)
@@ -4870,6 +4905,7 @@ doPeer2PeerMigrate3(virQEMUDriverPtr driver,
const char *listenAddress,
size_t nmigrate_disks,
const char **migrate_disks,
+ qemuMigrationCompressionPtr compression,
unsigned long long bandwidth,
bool useParams,
unsigned long flags)
@@ -5032,13 +5068,13 @@ doPeer2PeerMigrate3(virQEMUDriverPtr driver,
cookiein, cookieinlen,
&cookieout, &cookieoutlen,
flags, bandwidth, dconn, graphicsuri,
- nmigrate_disks, migrate_disks);
+ nmigrate_disks, migrate_disks, compression);
} else {
ret = doNativeMigrate(driver, vm, uri,
cookiein, cookieinlen,
&cookieout, &cookieoutlen,
flags, bandwidth, dconn, graphicsuri,
- nmigrate_disks, migrate_disks);
+ nmigrate_disks, migrate_disks, compression);
}
/* Perform failed. Make sure Finish doesn't overwrite the error */
@@ -5213,6 +5249,7 @@ static int doPeer2PeerMigrate(virQEMUDriverPtr driver,
const char *listenAddress,
size_t nmigrate_disks,
const char **migrate_disks,
+ qemuMigrationCompressionPtr compression,
unsigned long flags,
const char *dname,
unsigned long resource,
@@ -5326,8 +5363,8 @@ static int doPeer2PeerMigrate(virQEMUDriverPtr driver,
if (*v3proto) {
ret = doPeer2PeerMigrate3(driver, sconn, dconn, dconnuri, vm, xmlin,
dname, uri, graphicsuri, listenAddress,
- nmigrate_disks, migrate_disks, resource,
- useParams, flags);
+ nmigrate_disks, migrate_disks, compression,
+ resource, useParams, flags);
} else {
ret = doPeer2PeerMigrate2(driver, sconn, dconn, vm,
dconnuri, flags, dname, resource);
@@ -5364,6 +5401,7 @@ qemuMigrationPerformJob(virQEMUDriverPtr driver,
const char *listenAddress,
size_t nmigrate_disks,
const char **migrate_disks,
+ qemuMigrationCompressionPtr compression,
const char *cookiein,
int cookieinlen,
char **cookieout,
@@ -5399,13 +5437,13 @@ qemuMigrationPerformJob(virQEMUDriverPtr driver,
if ((flags & (VIR_MIGRATE_TUNNELLED | VIR_MIGRATE_PEER2PEER))) {
ret = doPeer2PeerMigrate(driver, conn, vm, xmlin,
dconnuri, uri, graphicsuri, listenAddress,
- nmigrate_disks, migrate_disks,
+ nmigrate_disks, migrate_disks, compression,
flags, dname, resource, &v3proto);
} else {
qemuMigrationJobSetPhase(driver, vm, QEMU_MIGRATION_PHASE_PERFORM2);
ret = doNativeMigrate(driver, vm, uri, cookiein, cookieinlen,
cookieout, cookieoutlen,
- flags, resource, NULL, NULL, 0, NULL);
+ flags, resource, NULL, NULL, 0, NULL, NULL);
}
if (ret < 0)
goto endjob;
@@ -5465,6 +5503,7 @@ qemuMigrationPerformPhase(virQEMUDriverPtr driver,
const char *graphicsuri,
size_t nmigrate_disks,
const char **migrate_disks,
+ qemuMigrationCompressionPtr compression,
const char *cookiein,
int cookieinlen,
char **cookieout,
@@ -5490,7 +5529,7 @@ qemuMigrationPerformPhase(virQEMUDriverPtr driver,
ret = doNativeMigrate(driver, vm, uri, cookiein, cookieinlen,
cookieout, cookieoutlen,
flags, resource, NULL, graphicsuri,
- nmigrate_disks, migrate_disks);
+ nmigrate_disks, migrate_disks, compression);
if (ret < 0) {
if (qemuMigrationRestoreDomainState(conn, vm)) {
@@ -5532,6 +5571,7 @@ qemuMigrationPerform(virQEMUDriverPtr driver,
const char *listenAddress,
size_t nmigrate_disks,
const char **migrate_disks,
+ qemuMigrationCompressionPtr compression,
const char *cookiein,
int cookieinlen,
char **cookieout,
@@ -5561,7 +5601,7 @@ qemuMigrationPerform(virQEMUDriverPtr driver,
return qemuMigrationPerformJob(driver, conn, vm, xmlin, dconnuri, uri,
graphicsuri, listenAddress,
nmigrate_disks, migrate_disks,
- cookiein, cookieinlen,
+ compression, cookiein, cookieinlen,
cookieout, cookieoutlen,
flags, dname, resource, v3proto);
} else {
@@ -5575,14 +5615,14 @@ qemuMigrationPerform(virQEMUDriverPtr driver,
return qemuMigrationPerformPhase(driver, conn, vm, uri,
graphicsuri,
nmigrate_disks, migrate_disks,
- cookiein, cookieinlen,
+ compression, cookiein, cookieinlen,
cookieout, cookieoutlen,
flags, resource);
} else {
return qemuMigrationPerformJob(driver, conn, vm, xmlin, NULL,
uri, graphicsuri, listenAddress,
nmigrate_disks, migrate_disks,
- cookiein, cookieinlen,
+ compression, cookiein, cookieinlen,
cookieout, cookieoutlen, flags,
dname, resource, v3proto);
}
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 2445e13..45de616 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -25,6 +25,9 @@
# include "qemu_conf.h"
# include "qemu_domain.h"
+typedef struct _qemuMigrationCompression qemuMigrationCompression;
+typedef qemuMigrationCompression *qemuMigrationCompressionPtr;
+
/* All supported qemu migration flags. */
# define QEMU_MIGRATION_FLAGS \
(VIR_MIGRATE_LIVE | \
@@ -53,6 +56,8 @@
VIR_MIGRATE_PARAM_LISTEN_ADDRESS, VIR_TYPED_PARAM_STRING, \
VIR_MIGRATE_PARAM_MIGRATE_DISKS, VIR_TYPED_PARAM_STRING | \
VIR_TYPED_PARAM_MULTIPLE, \
+ VIR_MIGRATE_PARAM_COMPRESSION, VIR_TYPED_PARAM_STRING | \
+ VIR_TYPED_PARAM_MULTIPLE, \
NULL
@@ -72,6 +77,15 @@ typedef enum {
} qemuMigrationJobPhase;
VIR_ENUM_DECL(qemuMigrationJobPhase)
+typedef enum {
+ QEMU_MIGRATION_COMPESS_XBZRLE = (1 << 0),
+ QEMU_MIGRATION_COMPESS_MULTITHREAD = (1 << 1),
+} qemuMigrationCompressMethod;
+
+struct _qemuMigrationCompression {
+ qemuMigrationCompressMethod method;
+};
+
int qemuMigrationJobStart(virQEMUDriverPtr driver,
virDomainObjPtr vm,
qemuDomainAsyncJob job)
@@ -134,6 +148,7 @@ int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
const char *listenAddress,
size_t nmigrate_disks,
const char **migrate_disks,
+ qemuMigrationCompressionPtr compression,
unsigned long flags);
int qemuMigrationPerform(virQEMUDriverPtr driver,
@@ -146,6 +161,7 @@ int qemuMigrationPerform(virQEMUDriverPtr driver,
const char *listenAddress,
size_t nmigrate_disks,
const char **migrate_disks,
+ qemuMigrationCompressionPtr compression,
const char *cookiein,
int cookieinlen,
char **cookieout,
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 6b23e88..cf1cdfb 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -167,7 +167,7 @@ VIR_ENUM_IMPL(qemuMonitorMigrationStatus,
VIR_ENUM_IMPL(qemuMonitorMigrationCaps,
QEMU_MONITOR_MIGRATION_CAPS_LAST,
- "xbzrle", "auto-converge", "rdma-pin-all",
"events")
+ "xbzrle", "auto-converge", "rdma-pin-all",
"events", "compress")
VIR_ENUM_IMPL(qemuMonitorVMStatus,
QEMU_MONITOR_VM_STATUS_LAST,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 9d7d5f3..c2a0ed6 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -525,6 +525,7 @@ typedef enum {
QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
QEMU_MONITOR_MIGRATION_CAPS_EVENTS,
+ QEMU_MONITOR_MIGRATION_CAPS_COMPRESS,
QEMU_MONITOR_MIGRATION_CAPS_LAST
} qemuMonitorMigrationCaps;
--
1.8.3.1