diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 0b1f08efee277d9a2817fe121f988f01cd33e276..895843b86731142a329c8df7b61b7b87424fa138 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -435,15 +435,9 @@ qemuMonitorIOProcess(qemuMonitorPtr mon) PROBE_QUIET(QEMU_MONITOR_IO_PROCESS, "mon=%p buf=%s len=%zu", mon, mon->buffer, mon->bufferOffset); - if (mon->json) - len = qemuMonitorJSONIOProcess(mon, - mon->buffer, mon->bufferOffset, - msg); - else - len = qemuMonitorTextIOProcess(mon, - mon->buffer, mon->bufferOffset, - msg); - + len = qemuMonitorJSONIOProcess(mon, + mon->buffer, mon->bufferOffset, + msg); if (len < 0) return -1; @@ -1269,19 +1263,15 @@ qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) { - /* hack to avoid complicating each call to text monitor functions */ - json_cmd = qemuMonitorUnescapeArg(cmd); - if (!json_cmd) { - VIR_DEBUG("Could not unescape command: %s", cmd); - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to unescape command")); - goto cleanup; - } - ret = qemuMonitorJSONHumanCommandWithFd(mon, json_cmd, scm_fd, reply); - } else { - ret = qemuMonitorTextCommandWithFd(mon, cmd, scm_fd, reply); + /* hack to avoid complicating each call to text monitor functions */ + json_cmd = qemuMonitorUnescapeArg(cmd); + if (!json_cmd) { + VIR_DEBUG("Could not unescape command: %s", cmd); + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Unable to unescape command")); + goto cleanup; } + ret = qemuMonitorJSONHumanCommandWithFd(mon, json_cmd, scm_fd, reply); cleanup: VIR_FREE(json_cmd); @@ -1688,10 +1678,7 @@ qemuMonitorStartCPUs(qemuMonitorPtr mon) { QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONStartCPUs(mon); - else - return qemuMonitorTextStartCPUs(mon); + return qemuMonitorJSONStartCPUs(mon); } @@ -1700,10 +1687,7 @@ qemuMonitorStopCPUs(qemuMonitorPtr mon) { QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONStopCPUs(mon); - else - return qemuMonitorTextStopCPUs(mon); + return qemuMonitorJSONStopCPUs(mon); } @@ -1724,10 +1708,7 @@ qemuMonitorGetStatus(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONGetStatus(mon, running, reason); - else - return qemuMonitorTextGetStatus(mon, running, reason); + return qemuMonitorJSONGetStatus(mon, running, reason); } @@ -1736,10 +1717,7 @@ qemuMonitorSystemPowerdown(qemuMonitorPtr mon) { QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSystemPowerdown(mon); - else - return qemuMonitorTextSystemPowerdown(mon); + return qemuMonitorJSONSystemPowerdown(mon); } @@ -1748,10 +1726,7 @@ qemuMonitorSystemReset(qemuMonitorPtr mon) { QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSystemReset(mon); - else - return qemuMonitorTextSystemReset(mon); + return qemuMonitorJSONSystemReset(mon); } @@ -2016,11 +1991,8 @@ qemuMonitorGetCPUInfo(qemuMonitorPtr mon, (qemuMonitorJSONGetHotpluggableCPUs(mon, &hotplugcpus, &nhotplugcpus)) < 0) goto cleanup; - if (mon->json) - rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, hotplug, - fast); - else - rc = qemuMonitorTextQueryCPUs(mon, &cpuentries, &ncpuentries); + rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, hotplug, + fast); if (rc < 0) { if (!hotplug && rc == -2) { @@ -2071,11 +2043,8 @@ qemuMonitorGetCpuHalted(qemuMonitorPtr mon, QEMU_CHECK_MONITOR_NULL(mon); - if (mon->json) - rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, false, - fast); - else - rc = qemuMonitorTextQueryCPUs(mon, &cpuentries, &ncpuentries); + rc = qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, false, + fast); if (rc < 0) goto cleanup; @@ -2103,10 +2072,7 @@ qemuMonitorSetLink(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSetLink(mon, name, state); - else - return qemuMonitorTextSetLink(mon, name, state); + return qemuMonitorJSONSetLink(mon, name, state); } @@ -2116,10 +2082,7 @@ qemuMonitorGetVirtType(qemuMonitorPtr mon, { QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONGetVirtType(mon, virtType); - else - return qemuMonitorTextGetVirtType(mon, virtType); + return qemuMonitorJSONGetVirtType(mon, virtType); } @@ -2133,10 +2096,7 @@ qemuMonitorGetBalloonInfo(qemuMonitorPtr mon, { QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONGetBalloonInfo(mon, currmem); - else - return qemuMonitorTextGetBalloonInfo(mon, currmem); + return qemuMonitorJSONGetBalloonInfo(mon, currmem); } @@ -2150,13 +2110,9 @@ qemuMonitorGetMemoryStats(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) { - qemuMonitorInitBalloonObjectPath(mon, balloon); - return qemuMonitorJSONGetMemoryStats(mon, mon->balloonpath, - stats, nr_stats); - } else { - return qemuMonitorTextGetMemoryStats(mon, stats, nr_stats); - } + qemuMonitorInitBalloonObjectPath(mon, balloon); + return qemuMonitorJSONGetMemoryStats(mon, mon->balloonpath, + stats, nr_stats); } @@ -2250,10 +2206,7 @@ qemuMonitorGetBlockInfo(qemuMonitorPtr mon) if (!(table = virHashCreate(32, qemuDomainDiskInfoFree))) return NULL; - if (mon->json) - ret = qemuMonitorJSONGetBlockInfo(mon, table); - else - ret = qemuMonitorTextGetBlockInfo(mon, table); + ret = qemuMonitorJSONGetBlockInfo(mon, table); if (ret < 0) { virHashFree(table); @@ -2304,19 +2257,8 @@ qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon, if (!(*ret_stats = virHashCreate(10, virHashValueFree))) goto error; - if (mon->json) { - ret = qemuMonitorJSONGetAllBlockStatsInfo(mon, *ret_stats, - backingChain); - } else { - if (backingChain) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("text monitor doesn't support block stats for " - "backing chain members")); - goto error; - } - - ret = qemuMonitorTextGetAllBlockStatsInfo(mon, *ret_stats); - } + ret = qemuMonitorJSONGetAllBlockStatsInfo(mon, *ret_stats, + backingChain); if (ret < 0) goto error; @@ -2353,10 +2295,7 @@ qemuMonitorBlockResize(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONBlockResize(mon, device, size); - else - return qemuMonitorTextBlockResize(mon, device, size); + return qemuMonitorJSONBlockResize(mon, device, size); } @@ -2371,10 +2310,7 @@ qemuMonitorSetVNCPassword(qemuMonitorPtr mon, if (!password) password = ""; - if (mon->json) - return qemuMonitorJSONSetVNCPassword(mon, password); - else - return qemuMonitorTextSetVNCPassword(mon, password); + return qemuMonitorJSONSetVNCPassword(mon, password); } @@ -2418,10 +2354,7 @@ qemuMonitorSetPassword(qemuMonitorPtr mon, if (!action_if_connected) action_if_connected = "keep"; - if (mon->json) - return qemuMonitorJSONSetPassword(mon, protocol, password, action_if_connected); - else - return qemuMonitorTextSetPassword(mon, protocol, password, action_if_connected); + return qemuMonitorJSONSetPassword(mon, protocol, password, action_if_connected); } @@ -2442,10 +2375,7 @@ qemuMonitorExpirePassword(qemuMonitorPtr mon, if (!expire_time) expire_time = "now"; - if (mon->json) - return qemuMonitorJSONExpirePassword(mon, protocol, expire_time); - else - return qemuMonitorTextExpirePassword(mon, protocol, expire_time); + return qemuMonitorJSONExpirePassword(mon, protocol, expire_time); } @@ -2461,10 +2391,7 @@ qemuMonitorSetBalloon(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSetBalloon(mon, newmem); - else - return qemuMonitorTextSetBalloon(mon, newmem); + return qemuMonitorJSONSetBalloon(mon, newmem); } @@ -2478,10 +2405,7 @@ qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online) QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSetCPU(mon, cpu, online); - else - return qemuMonitorTextSetCPU(mon, cpu, online); + return qemuMonitorJSONSetCPU(mon, cpu, online); } @@ -2494,10 +2418,7 @@ qemuMonitorEjectMedia(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONEjectMedia(mon, dev_name, force); - else - return qemuMonitorTextEjectMedia(mon, dev_name, force); + return qemuMonitorJSONEjectMedia(mon, dev_name, force); } @@ -2511,10 +2432,7 @@ qemuMonitorChangeMedia(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONChangeMedia(mon, dev_name, newmedia, format); - else - return qemuMonitorTextChangeMedia(mon, dev_name, newmedia, format); + return qemuMonitorJSONChangeMedia(mon, dev_name, newmedia, format); } @@ -2528,10 +2446,7 @@ qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSaveVirtualMemory(mon, offset, length, path); - else - return qemuMonitorTextSaveVirtualMemory(mon, offset, length, path); + return qemuMonitorJSONSaveVirtualMemory(mon, offset, length, path); } @@ -2545,10 +2460,7 @@ qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSavePhysicalMemory(mon, offset, length, path); - else - return qemuMonitorTextSavePhysicalMemory(mon, offset, length, path); + return qemuMonitorJSONSavePhysicalMemory(mon, offset, length, path); } @@ -2567,10 +2479,7 @@ qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon, return -1; } - if (mon->json) - return qemuMonitorJSONSetMigrationSpeed(mon, bandwidth); - else - return qemuMonitorTextSetMigrationSpeed(mon, bandwidth); + return qemuMonitorJSONSetMigrationSpeed(mon, bandwidth); } @@ -2582,10 +2491,7 @@ qemuMonitorSetMigrationDowntime(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSetMigrationDowntime(mon, downtime); - else - return qemuMonitorTextSetMigrationDowntime(mon, downtime); + return qemuMonitorJSONSetMigrationDowntime(mon, downtime); } @@ -2668,10 +2574,7 @@ qemuMonitorGetMigrationStats(qemuMonitorPtr mon, if (error) *error = NULL; - if (mon->json) - return qemuMonitorJSONGetMigrationStats(mon, stats, error); - else - return qemuMonitorTextGetMigrationStats(mon, stats); + return qemuMonitorJSONGetMigrationStats(mon, stats, error); } @@ -2688,10 +2591,7 @@ qemuMonitorMigrateToFd(qemuMonitorPtr mon, if (qemuMonitorSendFileHandle(mon, "migrate", fd) < 0) return -1; - if (mon->json) - ret = qemuMonitorJSONMigrate(mon, flags, "fd:migrate"); - else - ret = qemuMonitorTextMigrate(mon, flags, "fd:migrate"); + ret = qemuMonitorJSONMigrate(mon, flags, "fd:migrate"); if (ret < 0) { if (qemuMonitorCloseFileHandle(mon, "migrate") < 0) @@ -2722,10 +2622,7 @@ qemuMonitorMigrateToHost(qemuMonitorPtr mon, return -1; } - if (mon->json) - ret = qemuMonitorJSONMigrate(mon, flags, uri); - else - ret = qemuMonitorTextMigrate(mon, flags, uri); + ret = qemuMonitorJSONMigrate(mon, flags, uri); VIR_FREE(uri); return ret; @@ -2737,10 +2634,7 @@ qemuMonitorMigrateCancel(qemuMonitorPtr mon) { QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONMigrateCancel(mon); - else - return qemuMonitorTextMigrateCancel(mon); + return qemuMonitorJSONMigrateCancel(mon); } @@ -2811,20 +2705,12 @@ qemuMonitorGraphicsRelocate(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONGraphicsRelocate(mon, - type, - hostname, - port, - tlsPort, - tlsSubject); - else - return qemuMonitorTextGraphicsRelocate(mon, - type, - hostname, - port, - tlsPort, - tlsSubject); + return qemuMonitorJSONGraphicsRelocate(mon, + type, + hostname, + port, + tlsPort, + tlsSubject); } @@ -2850,10 +2736,7 @@ qemuMonitorSendFileHandle(qemuMonitorPtr mon, return -1; } - if (mon->json) - return qemuMonitorJSONSendFileHandle(mon, fdname, fd); - else - return qemuMonitorTextSendFileHandle(mon, fdname, fd); + return qemuMonitorJSONSendFileHandle(mon, fdname, fd); } @@ -2870,10 +2753,7 @@ qemuMonitorCloseFileHandle(qemuMonitorPtr mon, QEMU_CHECK_MONITOR_GOTO(mon, cleanup); - if (mon->json) - ret = qemuMonitorJSONCloseFileHandle(mon, fdname); - else - ret = qemuMonitorTextCloseFileHandle(mon, fdname); + ret = qemuMonitorJSONCloseFileHandle(mon, fdname); cleanup: if (error) { @@ -2962,10 +2842,7 @@ qemuMonitorAddNetdev(qemuMonitorPtr mon, goto cleanup; } - if (mon->json) - ret = qemuMonitorJSONAddNetdev(mon, netdevstr); - else - ret = qemuMonitorTextAddNetdev(mon, netdevstr); + ret = qemuMonitorJSONAddNetdev(mon, netdevstr); cleanup: if (ret < 0) { @@ -2991,10 +2868,7 @@ qemuMonitorRemoveNetdev(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONRemoveNetdev(mon, alias); - else - return qemuMonitorTextRemoveNetdev(mon, alias); + return qemuMonitorJSONRemoveNetdev(mon, alias); } @@ -3035,10 +2909,7 @@ qemuMonitorGetChardevInfo(qemuMonitorPtr mon, if (!(info = virHashCreate(10, qemuMonitorChardevInfoFree))) goto error; - if (mon->json) - ret = qemuMonitorJSONGetChardevInfo(mon, info); - else - ret = qemuMonitorTextGetChardevInfo(mon, info); + ret = qemuMonitorJSONGetChardevInfo(mon, info); if (ret < 0) goto error; @@ -3081,10 +2952,7 @@ qemuMonitorDelDevice(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONDelDevice(mon, devalias); - else - return qemuMonitorTextDelDevice(mon, devalias); + return qemuMonitorJSONDelDevice(mon, devalias); } @@ -3102,10 +2970,7 @@ qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon, if (fd >= 0 && qemuMonitorSendFileHandle(mon, fdname, fd) < 0) return -1; - if (mon->json) - ret = qemuMonitorJSONAddDevice(mon, devicestr); - else - ret = qemuMonitorTextAddDevice(mon, devicestr); + ret = qemuMonitorJSONAddDevice(mon, devicestr); if (ret < 0 && fd >= 0) { if (qemuMonitorCloseFileHandle(mon, fdname) < 0) @@ -3204,10 +3069,7 @@ qemuMonitorSetDrivePassphrase(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSetDrivePassphrase(mon, alias, passphrase); - else - return qemuMonitorTextSetDrivePassphrase(mon, alias, passphrase); + return qemuMonitorJSONSetDrivePassphrase(mon, alias, passphrase); } @@ -3382,10 +3244,7 @@ qemuMonitorArbitraryCommand(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONArbitraryCommand(mon, cmd, reply, hmp); - else - return qemuMonitorTextArbitraryCommand(mon, cmd, reply); + return qemuMonitorJSONArbitraryCommand(mon, cmd, reply, hmp); } @@ -3394,10 +3253,7 @@ qemuMonitorInjectNMI(qemuMonitorPtr mon) { QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONInjectNMI(mon); - else - return qemuMonitorTextInjectNMI(mon); + return qemuMonitorJSONInjectNMI(mon); } @@ -3411,10 +3267,7 @@ qemuMonitorSendKey(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSendKey(mon, holdtime, keycodes, nkeycodes); - else - return qemuMonitorTextSendKey(mon, holdtime, keycodes, nkeycodes); + return qemuMonitorJSONSendKey(mon, holdtime, keycodes, nkeycodes); } @@ -3428,10 +3281,7 @@ qemuMonitorScreendump(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONScreendump(mon, device, head, file); - else - return qemuMonitorTextScreendump(mon, file); + return qemuMonitorJSONScreendump(mon, device, head, file); } @@ -3526,13 +3376,10 @@ qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONSetBlockIoThrottle(mon, device, info, - supportMaxOptions, - supportGroupNameOption, - supportMaxLengthOptions); - else - return qemuMonitorTextSetBlockIoThrottle(mon, device, info); + return qemuMonitorJSONSetBlockIoThrottle(mon, device, info, + supportMaxOptions, + supportGroupNameOption, + supportMaxLengthOptions); } @@ -3545,10 +3392,7 @@ qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon, QEMU_CHECK_MONITOR(mon); - if (mon->json) - return qemuMonitorJSONGetBlockIoThrottle(mon, device, reply); - else - return qemuMonitorTextGetBlockIoThrottle(mon, device, reply); + return qemuMonitorJSONGetBlockIoThrottle(mon, device, reply); } @@ -3623,10 +3467,7 @@ qemuMonitorOpenGraphics(qemuMonitorPtr mon, if (qemuMonitorSendFileHandle(mon, fdname, fd) < 0) return -1; - if (mon->json) - ret = qemuMonitorJSONOpenGraphics(mon, protocol, fdname, skipauth); - else - ret = qemuMonitorTextOpenGraphics(mon, protocol, fdname, skipauth); + ret = qemuMonitorJSONOpenGraphics(mon, protocol, fdname, skipauth); if (ret < 0) { if (qemuMonitorCloseFileHandle(mon, fdname) < 0)