From: "Daniel P. Berrange" <berrange(a)redhat.com>
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(a)redhat.com>
---
src/qemu/qemu_monitor.c | 20 +---------------
src/qemu/qemu_monitor_json.c | 56 +++++++++++++++-----------------------------
src/qemu/qemu_monitor_json.h | 3 +--
3 files changed, 21 insertions(+), 58 deletions(-)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 543b6cd..e04af72 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,
virBitmapPtr qemuCaps)
{
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, qemuCaps, &json_hmp);
+ ret = qemuMonitorJSONCheckCommands(mon, qemuCaps);
if (ret < 0)
goto cleanup;
- mon->json_hmp = json_hmp > 0;
ret = qemuMonitorJSONCheckEvents(mon, qemuCaps);
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 bab6ca2..10a68c6 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_INTERNAL_ERROR,
+ _("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,
- virBitmapPtr qemuCaps,
- int *json_hmp)
+ virBitmapPtr qemuCaps)
{
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(qemuCaps, QEMU_CAPS_WAKEUP);
else if (STREQ(name, "transaction"))
qemuCapsSet(qemuCaps, 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,14 +3114,8 @@ 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");
+ ret = qemuMonitorTextDriveDel(mon, drivestr);
} else if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
/* NB: device not found errors mean the drive was
* auto-deleted and we ignore the error */
@@ -3181,8 +3177,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 +3206,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 +3235,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 +3280,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 +3333,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 +3367,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 +3389,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 3255007..f6e34f4 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,
- virBitmapPtr qemuCaps,
- int *json_hmp);
+ virBitmapPtr qemuCaps);
int qemuMonitorJSONCheckEvents(qemuMonitorPtr mon,
virBitmapPtr qemuCaps);
--
1.7.11.4