Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx> --- include/libvirt/libvirt-domain.h | 33 +++++++++++++++ src/qemu/qemu_migration.c | 91 +++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_migration.h | 9 ++++ 3 files changed, 132 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h index cc8f7de..ccf0c3e 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -796,6 +796,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 8fe0f0d..099ff92 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3424,6 +3424,10 @@ qemuMigrationSetCompression(virQEMUDriverPtr driver, qemuDomainAsyncJob job, qemuMigrationCompressionPtr compression) { + int ret = -1; + qemuDomainObjPrivatePtr priv = vm->privateData; + qemuMonitorMigrationCompressionPtr params = &compression->params; + if (qemuMigrationSetOption(driver, vm, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE, compression->methods & @@ -3438,7 +3442,25 @@ qemuMigrationSetCompression(virQEMUDriverPtr driver, job) < 0) return -1; - return 0; + if (qemuDomainObjEnterMonitorAsync(driver, vm, job) < 0) + return -1; + + if ((params->level_set || params->threads_set || params->dthreads_set) && + qemuMonitorSetMigrationCompression(priv->mon, 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 @@ -6619,6 +6641,7 @@ qemuMigrationCompressionParse(virTypedParameterPtr params, int nparams, { size_t i; qemuMigrationCompressionPtr compression = NULL; + qemuMonitorMigrationCompressionPtr cparams; if (VIR_ALLOC(compression) < 0) return NULL; @@ -6646,6 +6669,47 @@ qemuMigrationCompressionParse(virTypedParameterPtr params, int nparams, compression->methods |= 1ULL << method; } +#define GET_PARAM(PARAM, TYPE, PARENT, VALUE) \ + do { \ + int rc; \ + \ + if ((rc = virTypedParamsGet ## TYPE(params, nparams, \ + PARAM, &PARENT->VALUE)) < 0) \ + goto error; \ + \ + if (rc == 1) \ + PARENT->VALUE ## _set = true; \ + } while (0) + + cparams = &compression->params; + + if (params) { + GET_PARAM(VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL, Int, + cparams, level); + GET_PARAM(VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS, Int, + cparams, threads); + GET_PARAM(VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS, Int, + cparams, dthreads); + GET_PARAM(VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE, ULLong, + compression, xbzrle_cache); + } + +#undef GET_PARAM + + if ((cparams->level_set || cparams->threads_set || cparams->dthreads_set) && + !(compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_MULTITHREAD))) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Turn multithread compression on to tune it")); + goto error; + } + + if (compression->xbzrle_cache_set && + !(compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE))) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Turn xbzrle compression on to tune it")); + goto error; + } + if (!compression->methods && (flags & VIR_MIGRATE_COMPRESSED)) compression->methods = 1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE; @@ -6663,6 +6727,7 @@ qemuMigrationCompressionDump(qemuMigrationCompressionPtr compression, unsigned long *flags) { size_t i; + qemuMonitorMigrationCompressionPtr cparams = &compression->params; if (compression->methods == 1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE) { *flags |= VIR_MIGRATE_COMPRESSED; @@ -6677,5 +6742,29 @@ qemuMigrationCompressionDump(qemuMigrationCompressionPtr compression, 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 cb51ca5..ea49928 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -60,6 +60,10 @@ typedef qemuMigrationCompression *qemuMigrationCompressionPtr; VIR_MIGRATE_PARAM_DISKS_PORT, VIR_TYPED_PARAM_INT, \ 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 @@ -89,6 +93,11 @@ VIR_ENUM_DECL(qemuMigrationCompressMethod) struct _qemuMigrationCompression { unsigned long long methods; + + qemuMonitorMigrationCompression params; + + bool xbzrle_cache_set; + unsigned long long xbzrle_cache; }; qemuMigrationCompressionPtr -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list