On 02/19/13 13:35, Jiri Denemark wrote:
--- src/qemu/qemu_migration.c | 59 ++++++++++++++++++++-- src/qemu/qemu_migration.h | 3 +- src/qemu/qemu_monitor.c | 43 ++++++++++++++++ src/qemu/qemu_monitor.h | 13 +++++ src/qemu/qemu_monitor_json.c | 118 +++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 5 ++ 6 files changed, 237 insertions(+), 4 deletions(-)
...
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 7af571d..631ff92 100644
...
@@ -3383,3 +3387,42 @@ char *qemuMonitorGetTargetArch(qemuMonitorPtr mon) return qemuMonitorJSONGetTargetArch(mon); } + +
I think it would be worth briefly mentioning the meaning of return valiues in a comment.
+int qemuMonitorGetMigrationCapability(qemuMonitorPtr mon, + qemuMonitorMigrationCaps capability) +{ + VIR_DEBUG("mon=%p capability=%d", mon, capability); + + if (!mon) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("monitor must not be NULL")); + return -1; + } + + /* No capability is supported without JSON monitor */ + if (!mon->json) + return 0; + + return qemuMonitorJSONGetMigrationCapability(mon, capability); +} +
...
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index a86d90c..545d4d4 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c
...
+ +int +qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon, + qemuMonitorMigrationCaps capability) +{ + int ret = -1; + + virJSONValuePtr cmd = NULL; + virJSONValuePtr reply = NULL; + virJSONValuePtr cap = NULL; + virJSONValuePtr caps; + + if (!(caps = virJSONValueNewArray())) + goto cleanup; + + if (!(cap = virJSONValueNewObject())) + goto no_memory; + + if (virJSONValueObjectAppendString( + cap, "capability", + qemuMonitorMigrationCapsTypeToString(capability)) < 0) + goto no_memory; + + if (virJSONValueObjectAppendBoolean(cap, "state", 1) < 0) + goto no_memory; + + if (virJSONValueArrayAppend(caps, cap) < 0) + goto no_memory; + + cap = NULL; + + cmd = qemuMonitorJSONMakeCommand("migrate-set-capabilities", + "a:capabilities", caps, + NULL); + if (!cmd) + goto cleanup; + + if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) + goto cleanup; + + ret = qemuMonitorJSONCheckError(cmd, reply); + +cleanup: + virJSONValueFree(cap); + virJSONValueFree(cmd); + virJSONValueFree(reply);
You leak "caps" here, at least when hitting out of memory error.
+ return ret; + +no_memory: + virReportOOMError(); + goto cleanup; +}
ACK with comment added and memleak addressed. Peter -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list