This is going to be squashed into previous commit. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_monitor_json.c | 162 +++++++++++++++++++++++++------------------ 1 file changed, 94 insertions(+), 68 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index dfb31a2..e9e1c51 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2424,7 +2424,7 @@ int qemuMonitorJSONSavePhysicalMemory(qemuMonitorPtr mon, int qemuMonitorJSONSetMigrationSpeed(qemuMonitorPtr mon, unsigned long bandwidth) { - int ret; + int ret = -1; virJSONValuePtr cmd; virJSONValuePtr reply = NULL; cmd = qemuMonitorJSONMakeCommand("migrate_set_speed", @@ -2433,11 +2433,14 @@ int qemuMonitorJSONSetMigrationSpeed(qemuMonitorPtr mon, if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + ret = 0; + cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; @@ -2447,7 +2450,7 @@ int qemuMonitorJSONSetMigrationSpeed(qemuMonitorPtr mon, int qemuMonitorJSONSetMigrationDowntime(qemuMonitorPtr mon, unsigned long long downtime) { - int ret; + int ret = -1; virJSONValuePtr cmd; virJSONValuePtr reply = NULL; @@ -2457,11 +2460,14 @@ int qemuMonitorJSONSetMigrationDowntime(qemuMonitorPtr mon, if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + ret = 0; + cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; @@ -2472,7 +2478,7 @@ int qemuMonitorJSONGetMigrationCacheSize(qemuMonitorPtr mon, unsigned long long *cacheSize) { - int ret; + int ret = -1; virJSONValuePtr cmd; virJSONValuePtr reply = NULL; @@ -2482,16 +2488,13 @@ qemuMonitorJSONGetMigrationCacheSize(qemuMonitorPtr mon, if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); - - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret < 0) + if (qemuMonitorJSONCheckError(cmd, reply) < 0) goto cleanup; - ret = virJSONValueObjectGetNumberUlong(reply, "return", cacheSize); - if (ret < 0) { + if (virJSONValueObjectGetNumberUlong(reply, "return", cacheSize) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-migrate-cache-size reply was missing " "'return' data")); @@ -2510,7 +2513,7 @@ int qemuMonitorJSONSetMigrationCacheSize(qemuMonitorPtr mon, unsigned long long cacheSize) { - int ret; + int ret = -1; virJSONValuePtr cmd; virJSONValuePtr reply = NULL; @@ -2520,11 +2523,14 @@ qemuMonitorJSONSetMigrationCacheSize(qemuMonitorPtr mon, if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + ret = 0; + cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; @@ -2543,10 +2549,10 @@ qemuMonitorJSONGetMigrationCompression(qemuMonitorPtr mon, if (!(cmd = qemuMonitorJSONMakeCommand("query-migrate-parameters", NULL))) return -1; - if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; - if ((ret = qemuMonitorJSONCheckError(cmd, reply)) < 0) + if (qemuMonitorJSONCheckError(cmd, reply) < 0) goto cleanup; result = virJSONValueObjectGet(reply, "return"); @@ -2623,7 +2629,7 @@ qemuMonitorJSONSetMigrationCompression(qemuMonitorPtr mon, goto cleanup; args = NULL; - if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) goto cleanup; ret = qemuMonitorJSONCheckError(cmd, reply); @@ -2836,7 +2842,7 @@ qemuMonitorJSONGetMigrationStatsReply(virJSONValuePtr reply, int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr mon, qemuMonitorMigrationStatsPtr stats) { - int ret; + int ret = -1; virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-migrate", NULL); virJSONValuePtr reply = NULL; @@ -2846,15 +2852,17 @@ int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr mon, if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; - if (ret == 0 && - qemuMonitorJSONGetMigrationStatsReply(reply, stats) < 0) - ret = -1; + if (qemuMonitorJSONGetMigrationStatsReply(reply, stats) < 0) + goto cleanup; + ret = 0; + cleanup: if (ret < 0) memset(stats, 0, sizeof(*stats)); virJSONValueFree(cmd); @@ -2867,7 +2875,7 @@ int qemuMonitorJSONMigrate(qemuMonitorPtr mon, unsigned int flags, const char *uri) { - int ret; + int ret = -1; virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("migrate", "b:detach", flags & QEMU_MONITOR_MIGRATE_BACKGROUND ? 1 : 0, @@ -2880,11 +2888,14 @@ int qemuMonitorJSONMigrate(qemuMonitorPtr mon, if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + ret = 0; + cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; @@ -2892,17 +2903,20 @@ int qemuMonitorJSONMigrate(qemuMonitorPtr mon, int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon) { - int ret; + int ret = -1; virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("migrate_cancel", NULL); virJSONValuePtr reply = NULL; if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + ret = 0; + cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; @@ -2912,7 +2926,7 @@ int qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon, const char *capability) { - int ret; + int ret = -1; virJSONValuePtr cmd; virJSONValuePtr reply = NULL; virJSONValuePtr caps; @@ -2923,19 +2937,17 @@ qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon, NULL))) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) { - if (qemuMonitorJSONHasError(reply, "CommandNotFound")) - goto cleanup; - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { + ret = 0; + goto cleanup; } - if (ret < 0) + if (qemuMonitorJSONCheckError(cmd, reply) < 0) goto cleanup; - ret = -1; - if (!(caps = virJSONValueObjectGetObject(reply, "return"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing dump guest memory capabilities")); @@ -2961,10 +2973,9 @@ qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon, ret = 1; goto cleanup; } - - ret = 0; } + ret = 0; cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); @@ -2976,7 +2987,7 @@ qemuMonitorJSONDump(qemuMonitorPtr mon, const char *protocol, const char *dumpformat) { - int ret; + int ret = -1; virJSONValuePtr cmd = NULL; virJSONValuePtr reply = NULL; @@ -2996,11 +3007,14 @@ qemuMonitorJSONDump(qemuMonitorPtr mon, if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + ret = 0; + cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; @@ -3026,11 +3040,14 @@ int qemuMonitorJSONGraphicsRelocate(qemuMonitorPtr mon, if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + ret = 0; + cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; @@ -3041,7 +3058,7 @@ int qemuMonitorJSONSendFileHandle(qemuMonitorPtr mon, const char *fdname, int fd) { - int ret; + int ret = -1; virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("getfd", "s:fdname", fdname, NULL); @@ -3049,11 +3066,14 @@ int qemuMonitorJSONSendFileHandle(qemuMonitorPtr mon, if (!cmd) return -1; - ret = qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply); + if (qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + ret = 0; + cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; @@ -3063,7 +3083,7 @@ int qemuMonitorJSONSendFileHandle(qemuMonitorPtr mon, int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon, const char *fdname) { - int ret; + int ret = -1; virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("closefd", "s:fdname", fdname, NULL); @@ -3071,11 +3091,14 @@ int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon, if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + ret = 0; + cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; @@ -3139,7 +3162,7 @@ qemuMonitorJSONAddFd(qemuMonitorPtr mon, int fdset, int fd, const char *name) int qemuMonitorJSONRemoveFd(qemuMonitorPtr mon, int fdset, int fd) { - int ret; + int ret = -1; virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("remove-fd", "i:fdset-id", fdset, fd < 0 ? NULL : "i:fd", @@ -3148,11 +3171,14 @@ qemuMonitorJSONRemoveFd(qemuMonitorPtr mon, int fdset, int fd) if (!cmd) return -1; - ret = qemuMonitorJSONCommand(mon, cmd, &reply); + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; - if (ret == 0) - ret = qemuMonitorJSONCheckError(cmd, reply); + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + ret = 0; + cleanup: virJSONValueFree(cmd); virJSONValueFree(reply); return ret; -- 2.8.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list