From: "Daniel P. Berrange" <berrange@xxxxxxxxxx> Don't bother checking for the existance of the HMP passthrough command. Just try to execute it, and propagate the failure. Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx> --- src/qemu/qemu_monitor.c | 20 +------------- src/qemu/qemu_monitor_json.c | 63 +++++++++++++++++++------------------------- src/qemu/qemu_monitor_json.h | 3 +-- 3 files changed, 29 insertions(+), 57 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index b43b15e..f8d717f 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -78,7 +78,6 @@ struct _qemuMonitor { int nextSerial; unsigned json: 1; - unsigned json_hmp: 1; unsigned wait_greeting: 1; }; @@ -1131,7 +1130,6 @@ int qemuMonitorSetCapabilities(qemuMonitorPtr mon, qemuCapsPtr caps) { int ret; - int json_hmp; VIR_DEBUG("mon=%p", mon); if (!mon) { @@ -1145,10 +1143,9 @@ int qemuMonitorSetCapabilities(qemuMonitorPtr mon, if (ret < 0) goto cleanup; - ret = qemuMonitorJSONCheckCommands(mon, caps, &json_hmp); + ret = qemuMonitorJSONCheckCommands(mon, caps); if (ret < 0) goto cleanup; - mon->json_hmp = json_hmp > 0; ret = qemuMonitorJSONCheckEvents(mon, caps); if (ret < 0) @@ -1163,21 +1160,6 @@ cleanup: int -qemuMonitorCheckHMP(qemuMonitorPtr mon, const char *cmd) -{ - if (!mon->json || mon->json_hmp) - return 1; - - if (cmd) { - VIR_DEBUG("HMP passthrough not supported by qemu process;" - " not trying HMP for command %s", cmd); - } - - return 0; -} - - -int qemuMonitorStartCPUs(qemuMonitorPtr mon, virConnectPtr conn) { diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 8842817..ed18a64 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -909,6 +909,13 @@ qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon, if (!cmd || qemuMonitorJSONCommandWithFd(mon, cmd, scm_fd, &reply) < 0) goto cleanup; + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("Human monitor command is not available to run %s"), + cmd_str); + goto cleanup; + } + if (qemuMonitorJSONCheckError(cmd, reply)) goto cleanup; @@ -967,8 +974,7 @@ qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon) */ int qemuMonitorJSONCheckCommands(qemuMonitorPtr mon, - qemuCapsPtr caps, - int *json_hmp) + qemuCapsPtr caps) { int ret = -1; virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-commands", NULL); @@ -996,9 +1002,7 @@ qemuMonitorJSONCheckCommands(qemuMonitorPtr mon, !(name = virJSONValueObjectGetString(entry, "name"))) goto cleanup; - if (STREQ(name, "human-monitor-command")) - *json_hmp = 1; - else if (STREQ(name, "system_wakeup")) + if (STREQ(name, "system_wakeup")) qemuCapsSet(caps, QEMU_CAPS_WAKEUP); else if (STREQ(name, "transaction")) qemuCapsSet(caps, QEMU_CAPS_TRANSACTION); @@ -2183,8 +2187,7 @@ int qemuMonitorJSONSetCPU(qemuMonitorPtr mon, if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) goto cleanup; - if (qemuMonitorJSONHasError(reply, "CommandNotFound") && - qemuMonitorCheckHMP(mon, "cpu_set")) { + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { VIR_DEBUG("cpu_set command not found, trying HMP"); ret = qemuMonitorTextSetCPU(mon, cpu, online); goto cleanup; @@ -3078,8 +3081,7 @@ int qemuMonitorJSONAddDrive(qemuMonitorPtr mon, if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply) < 0)) goto cleanup; - if (qemuMonitorJSONHasError(reply, "CommandNotFound") && - qemuMonitorCheckHMP(mon, "drive_add")) { + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { VIR_DEBUG("drive_add command not found, trying HMP"); ret = qemuMonitorTextAddDrive(mon, drivestr); goto cleanup; @@ -3112,13 +3114,16 @@ int qemuMonitorJSONDriveDel(qemuMonitorPtr mon, goto cleanup; if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { - if (qemuMonitorCheckHMP(mon, "drive_del")) { - VIR_DEBUG("drive_del command not found, trying HMP"); - ret = qemuMonitorTextDriveDel(mon, drivestr); - } else { - VIR_ERROR(_("deleting disk is not supported. " - "This may leak data if disk is reassigned")); - ret = 1; + VIR_DEBUG("drive_del command not found, trying HMP"); + if ((ret = qemuMonitorTextDriveDel(mon, drivestr)) < 0) { + virErrorPtr err = virGetLastError(); + if (err && err->code == VIR_ERR_OPERATION_UNSUPPORTED) { + VIR_ERROR("%s", + _("deleting disk is not supported. " + "This may leak data if disk is reassigned")); + ret = 1; + virResetLastError();; + } } } else if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) { /* NB: device not found errors mean the drive was @@ -3181,8 +3186,7 @@ int qemuMonitorJSONCreateSnapshot(qemuMonitorPtr mon, const char *name) if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) goto cleanup; - if (qemuMonitorJSONHasError(reply, "CommandNotFound") && - qemuMonitorCheckHMP(mon, "savevm")) { + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { VIR_DEBUG("savevm command not found, trying HMP"); ret = qemuMonitorTextCreateSnapshot(mon, name); goto cleanup; @@ -3211,8 +3215,7 @@ int qemuMonitorJSONLoadSnapshot(qemuMonitorPtr mon, const char *name) if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) goto cleanup; - if (qemuMonitorJSONHasError(reply, "CommandNotFound") && - qemuMonitorCheckHMP(mon, "loadvm")) { + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { VIR_DEBUG("loadvm command not found, trying HMP"); ret = qemuMonitorTextLoadSnapshot(mon, name); goto cleanup; @@ -3241,8 +3244,7 @@ int qemuMonitorJSONDeleteSnapshot(qemuMonitorPtr mon, const char *name) if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) goto cleanup; - if (qemuMonitorJSONHasError(reply, "CommandNotFound") && - qemuMonitorCheckHMP(mon, "delvm")) { + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { VIR_DEBUG("delvm command not found, trying HMP"); ret = qemuMonitorTextDeleteSnapshot(mon, name); goto cleanup; @@ -3287,8 +3289,7 @@ qemuMonitorJSONDiskSnapshot(qemuMonitorPtr mon, virJSONValuePtr actions, if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) goto cleanup; - if (qemuMonitorJSONHasError(reply, "CommandNotFound") && - qemuMonitorCheckHMP(mon, "snapshot_blkdev")) { + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { VIR_DEBUG("blockdev-snapshot-sync command not found, trying HMP"); ret = qemuMonitorTextDiskSnapshot(mon, device, file); goto cleanup; @@ -3341,12 +3342,6 @@ int qemuMonitorJSONArbitraryCommand(qemuMonitorPtr mon, int ret = -1; if (hmp) { - if (!qemuMonitorCheckHMP(mon, NULL)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("HMP passthrough is not supported by qemu" - " process; only QMP commands can be used")); - return -1; - } return qemuMonitorJSONHumanCommandWithFd(mon, cmd_str, -1, reply_str); } else { if (!(cmd = virJSONValueFromString(cmd_str))) @@ -3381,8 +3376,7 @@ int qemuMonitorJSONInjectNMI(qemuMonitorPtr mon) if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) goto cleanup; - if (qemuMonitorJSONHasError(reply, "CommandNotFound") && - qemuMonitorCheckHMP(mon, "inject-nmi")) { + if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { VIR_DEBUG("inject-nmi command not found, trying HMP"); ret = qemuMonitorTextInjectNMI(mon); } else { @@ -3404,10 +3398,7 @@ int qemuMonitorJSONSendKey(qemuMonitorPtr mon, * FIXME: qmp sendkey has not been implemented yet, * and qmp API of it cannot be anticipated, so we use hmp temporary. */ - if (qemuMonitorCheckHMP(mon, "sendkey")) { - return qemuMonitorTextSendKey(mon, holdtime, keycodes, nkeycodes); - } else - return -1; + return qemuMonitorTextSendKey(mon, holdtime, keycodes, nkeycodes); } int qemuMonitorJSONScreendump(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index f5d515f..d092b88 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -43,8 +43,7 @@ int qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon, int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon); int qemuMonitorJSONCheckCommands(qemuMonitorPtr mon, - qemuCapsPtr caps, - int *json_hmp); + qemuCapsPtr caps); int qemuMonitorJSONCheckEvents(qemuMonitorPtr mon, qemuCapsPtr caps); -- 1.7.11.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list