From: ShaoHe Feng Date: Thu, 14 Apr 2016 10:33:49 +0000 (+0300) Subject: qemu: monitor: add migration parameters accessors X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=8979c5ddb99323daf0cf728dd224294f4269b82a;p=libvirt.git qemu: monitor: add migration parameters accessors Signed-off-by: ShaoHe Feng Signed-off-by: Nikolay Shirokovskiy --- diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index ac9befa4e5..83551a83f2 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2176,6 +2176,28 @@ qemuMonitorSetMigrationCacheSize(qemuMonitorPtr mon, } +int +qemuMonitorGetMigrationCompression(qemuMonitorPtr mon, + qemuMonitorMigrationCompressionPtr compress) +{ + QEMU_CHECK_MONITOR_JSON(mon); + + return qemuMonitorJSONGetMigrationCompression(mon, compress); +} + +int +qemuMonitorSetMigrationCompression(qemuMonitorPtr mon, + qemuMonitorMigrationCompressionPtr compress) +{ + VIR_DEBUG("level=%d threads=%d dthreads=%d", + compress->level, compress->threads, compress->dthreads); + + QEMU_CHECK_MONITOR_JSON(mon); + + return qemuMonitorJSONSetMigrationCompression(mon, compress); +} + + int qemuMonitorGetMigrationStats(qemuMonitorPtr mon, qemuMonitorMigrationStatsPtr stats) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 78efcd7e4e..bd5d006750 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -487,6 +487,23 @@ int qemuMonitorGetMigrationCacheSize(qemuMonitorPtr mon, int qemuMonitorSetMigrationCacheSize(qemuMonitorPtr mon, unsigned long long cacheSize); +typedef struct _qemuMonitorMigrationCompression qemuMonitorMigrationCompression; +typedef qemuMonitorMigrationCompression *qemuMonitorMigrationCompressionPtr; +struct _qemuMonitorMigrationCompression { + bool level_set; + bool threads_set; + bool dthreads_set; + + int level; + int threads; + int dthreads; +}; + +int qemuMonitorGetMigrationCompression(qemuMonitorPtr mon, + qemuMonitorMigrationCompressionPtr compress); +int qemuMonitorSetMigrationCompression(qemuMonitorPtr mon, + qemuMonitorMigrationCompressionPtr compress); + typedef enum { QEMU_MONITOR_MIGRATION_STATUS_INACTIVE, QEMU_MONITOR_MIGRATION_STATUS_SETUP, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 78af83e0c6..29d6c8c5b8 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2521,6 +2521,116 @@ qemuMonitorJSONSetMigrationCacheSize(qemuMonitorPtr mon, } +int +qemuMonitorJSONGetMigrationCompression(qemuMonitorPtr mon, + qemuMonitorMigrationCompressionPtr compress) +{ + int ret = -1; + virJSONValuePtr result; + virJSONValuePtr cmd = NULL; + virJSONValuePtr reply = NULL; + + if (!(cmd = qemuMonitorJSONMakeCommand("query-migrate-parameters", NULL))) + return -1; + + if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) + goto cleanup; + + if ((ret = qemuMonitorJSONCheckError(cmd, reply)) < 0) + goto cleanup; + + if (!(result = virJSONValueObjectGet(reply, "return"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-migrate-parameters reply was missing " + "'return' data")); + goto cleanup; + } + + if (virJSONValueObjectGetNumberInt(result, "compress-level", + &compress->level) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed/missing compress-level " + "in migrate parameters")); + goto cleanup; + } + compress->level_set = true; + + if (virJSONValueObjectGetNumberInt(result, "compress-threads", + &compress->threads) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed/missing compress-threads " + "in migrate parameters")); + goto cleanup; + } + compress->threads_set = true; + + if (virJSONValueObjectGetNumberInt(result, "decompress-threads", + &compress->dthreads) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed/missing decompress-threads " + "in migrate parameters")); + goto cleanup; + } + compress->dthreads_set = true; + + ret = 0; + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + +int +qemuMonitorJSONSetMigrationCompression(qemuMonitorPtr mon, + qemuMonitorMigrationCompressionPtr compress) +{ + int ret = -1; + virJSONValuePtr cmd = NULL; + virJSONValuePtr args = NULL; + virJSONValuePtr reply = NULL; + + if (!(cmd = virJSONValueNewObject())) + goto cleanup; + + if (virJSONValueObjectAppendString(cmd, "execute", + "migrate-set-parameters") < 0) + goto cleanup; + + if (!(args = virJSONValueNewObject())) + goto cleanup; + + if (compress->level_set && + virJSONValueObjectAppendNumberInt(args, "compress-level", + compress->level) < 0) + goto cleanup; + + if (compress->threads_set && + virJSONValueObjectAppendNumberInt(args, "compress-threads", + compress->threads) < 0) + goto cleanup; + + if (compress->dthreads_set && + virJSONValueObjectAppendNumberInt(args, "decompress-threads", + compress->dthreads) < 0) + goto cleanup; + + if (virJSONValueObjectAppend(cmd, "arguments", args) < 0) + goto cleanup; + args = NULL; + + if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) + goto cleanup; + + ret = qemuMonitorJSONCheckError(cmd, reply); + + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(args); + virJSONValueFree(reply); + return ret; +} + + static int qemuMonitorJSONGetMigrationStatsReply(virJSONValuePtr reply, qemuMonitorMigrationStatsPtr stats) diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index d155f52e5a..5cbee1a439 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -126,6 +126,11 @@ int qemuMonitorJSONGetMigrationCacheSize(qemuMonitorPtr mon, int qemuMonitorJSONSetMigrationCacheSize(qemuMonitorPtr mon, unsigned long long cacheSize); +int qemuMonitorJSONGetMigrationCompression(qemuMonitorPtr mon, + qemuMonitorMigrationCompressionPtr compress); +int qemuMonitorJSONSetMigrationCompression(qemuMonitorPtr mon, + qemuMonitorMigrationCompressionPtr compress); + int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr mon, qemuMonitorMigrationStatsPtr stats);