mirror of https://gitee.com/openkylin/libvirt.git
Remove upfront check for hmp - just try it cope with failure
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@redhat.com>
This commit is contained in:
parent
5505cf96b0
commit
97a1f07681
|
@ -78,7 +78,6 @@ struct _qemuMonitor {
|
||||||
int nextSerial;
|
int nextSerial;
|
||||||
|
|
||||||
unsigned json: 1;
|
unsigned json: 1;
|
||||||
unsigned json_hmp: 1;
|
|
||||||
unsigned wait_greeting: 1;
|
unsigned wait_greeting: 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1131,7 +1130,6 @@ int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
|
||||||
qemuCapsPtr caps)
|
qemuCapsPtr caps)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int json_hmp;
|
|
||||||
VIR_DEBUG("mon=%p", mon);
|
VIR_DEBUG("mon=%p", mon);
|
||||||
|
|
||||||
if (!mon) {
|
if (!mon) {
|
||||||
|
@ -1145,10 +1143,9 @@ int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = qemuMonitorJSONCheckCommands(mon, caps, &json_hmp);
|
ret = qemuMonitorJSONCheckCommands(mon, caps);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
mon->json_hmp = json_hmp > 0;
|
|
||||||
|
|
||||||
ret = qemuMonitorJSONCheckEvents(mon, caps);
|
ret = qemuMonitorJSONCheckEvents(mon, caps);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@ -1162,21 +1159,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
|
int
|
||||||
qemuMonitorStartCPUs(qemuMonitorPtr mon,
|
qemuMonitorStartCPUs(qemuMonitorPtr mon,
|
||||||
virConnectPtr conn)
|
virConnectPtr conn)
|
||||||
|
|
|
@ -159,8 +159,6 @@ void qemuMonitorClose(qemuMonitorPtr mon);
|
||||||
int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
|
int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
|
||||||
qemuCapsPtr caps);
|
qemuCapsPtr caps);
|
||||||
|
|
||||||
int qemuMonitorCheckHMP(qemuMonitorPtr mon, const char *cmd);
|
|
||||||
|
|
||||||
void qemuMonitorLock(qemuMonitorPtr mon);
|
void qemuMonitorLock(qemuMonitorPtr mon);
|
||||||
void qemuMonitorUnlock(qemuMonitorPtr mon);
|
void qemuMonitorUnlock(qemuMonitorPtr mon);
|
||||||
|
|
||||||
|
|
|
@ -909,6 +909,13 @@ qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
|
||||||
if (!cmd || qemuMonitorJSONCommandWithFd(mon, cmd, scm_fd, &reply) < 0)
|
if (!cmd || qemuMonitorJSONCommandWithFd(mon, cmd, scm_fd, &reply) < 0)
|
||||||
goto cleanup;
|
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))
|
if (qemuMonitorJSONCheckError(cmd, reply))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -967,8 +974,7 @@ qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon)
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
|
qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
|
||||||
qemuCapsPtr caps,
|
qemuCapsPtr caps)
|
||||||
int *json_hmp)
|
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-commands", NULL);
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-commands", NULL);
|
||||||
|
@ -996,9 +1002,7 @@ qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
|
||||||
!(name = virJSONValueObjectGetString(entry, "name")))
|
!(name = virJSONValueObjectGetString(entry, "name")))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (STREQ(name, "human-monitor-command"))
|
if (STREQ(name, "system_wakeup"))
|
||||||
*json_hmp = 1;
|
|
||||||
else if (STREQ(name, "system_wakeup"))
|
|
||||||
qemuCapsSet(caps, QEMU_CAPS_WAKEUP);
|
qemuCapsSet(caps, QEMU_CAPS_WAKEUP);
|
||||||
else if (STREQ(name, "transaction"))
|
else if (STREQ(name, "transaction"))
|
||||||
qemuCapsSet(caps, QEMU_CAPS_TRANSACTION);
|
qemuCapsSet(caps, QEMU_CAPS_TRANSACTION);
|
||||||
|
@ -2183,8 +2187,7 @@ int qemuMonitorJSONSetCPU(qemuMonitorPtr mon,
|
||||||
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "CommandNotFound") &&
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
||||||
qemuMonitorCheckHMP(mon, "cpu_set")) {
|
|
||||||
VIR_DEBUG("cpu_set command not found, trying HMP");
|
VIR_DEBUG("cpu_set command not found, trying HMP");
|
||||||
ret = qemuMonitorTextSetCPU(mon, cpu, online);
|
ret = qemuMonitorTextSetCPU(mon, cpu, online);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -3078,8 +3081,7 @@ int qemuMonitorJSONAddDrive(qemuMonitorPtr mon,
|
||||||
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply) < 0))
|
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply) < 0))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "CommandNotFound") &&
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
||||||
qemuMonitorCheckHMP(mon, "drive_add")) {
|
|
||||||
VIR_DEBUG("drive_add command not found, trying HMP");
|
VIR_DEBUG("drive_add command not found, trying HMP");
|
||||||
ret = qemuMonitorTextAddDrive(mon, drivestr);
|
ret = qemuMonitorTextAddDrive(mon, drivestr);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -3112,13 +3114,16 @@ int qemuMonitorJSONDriveDel(qemuMonitorPtr mon,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
||||||
if (qemuMonitorCheckHMP(mon, "drive_del")) {
|
VIR_DEBUG("drive_del command not found, trying HMP");
|
||||||
VIR_DEBUG("drive_del command not found, trying HMP");
|
if ((ret = qemuMonitorTextDriveDel(mon, drivestr)) < 0) {
|
||||||
ret = qemuMonitorTextDriveDel(mon, drivestr);
|
virErrorPtr err = virGetLastError();
|
||||||
} else {
|
if (err && err->code == VIR_ERR_OPERATION_UNSUPPORTED) {
|
||||||
VIR_ERROR(_("deleting disk is not supported. "
|
VIR_ERROR("%s",
|
||||||
"This may leak data if disk is reassigned"));
|
_("deleting disk is not supported. "
|
||||||
ret = 1;
|
"This may leak data if disk is reassigned"));
|
||||||
|
ret = 1;
|
||||||
|
virResetLastError();;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
|
} else if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
|
||||||
/* NB: device not found errors mean the drive was
|
/* 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)
|
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "CommandNotFound") &&
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
||||||
qemuMonitorCheckHMP(mon, "savevm")) {
|
|
||||||
VIR_DEBUG("savevm command not found, trying HMP");
|
VIR_DEBUG("savevm command not found, trying HMP");
|
||||||
ret = qemuMonitorTextCreateSnapshot(mon, name);
|
ret = qemuMonitorTextCreateSnapshot(mon, name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -3211,8 +3215,7 @@ int qemuMonitorJSONLoadSnapshot(qemuMonitorPtr mon, const char *name)
|
||||||
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "CommandNotFound") &&
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
||||||
qemuMonitorCheckHMP(mon, "loadvm")) {
|
|
||||||
VIR_DEBUG("loadvm command not found, trying HMP");
|
VIR_DEBUG("loadvm command not found, trying HMP");
|
||||||
ret = qemuMonitorTextLoadSnapshot(mon, name);
|
ret = qemuMonitorTextLoadSnapshot(mon, name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -3241,8 +3244,7 @@ int qemuMonitorJSONDeleteSnapshot(qemuMonitorPtr mon, const char *name)
|
||||||
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "CommandNotFound") &&
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
||||||
qemuMonitorCheckHMP(mon, "delvm")) {
|
|
||||||
VIR_DEBUG("delvm command not found, trying HMP");
|
VIR_DEBUG("delvm command not found, trying HMP");
|
||||||
ret = qemuMonitorTextDeleteSnapshot(mon, name);
|
ret = qemuMonitorTextDeleteSnapshot(mon, name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -3287,8 +3289,7 @@ qemuMonitorJSONDiskSnapshot(qemuMonitorPtr mon, virJSONValuePtr actions,
|
||||||
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "CommandNotFound") &&
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
||||||
qemuMonitorCheckHMP(mon, "snapshot_blkdev")) {
|
|
||||||
VIR_DEBUG("blockdev-snapshot-sync command not found, trying HMP");
|
VIR_DEBUG("blockdev-snapshot-sync command not found, trying HMP");
|
||||||
ret = qemuMonitorTextDiskSnapshot(mon, device, file);
|
ret = qemuMonitorTextDiskSnapshot(mon, device, file);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -3341,12 +3342,6 @@ int qemuMonitorJSONArbitraryCommand(qemuMonitorPtr mon,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (hmp) {
|
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);
|
return qemuMonitorJSONHumanCommandWithFd(mon, cmd_str, -1, reply_str);
|
||||||
} else {
|
} else {
|
||||||
if (!(cmd = virJSONValueFromString(cmd_str)))
|
if (!(cmd = virJSONValueFromString(cmd_str)))
|
||||||
|
@ -3381,8 +3376,7 @@ int qemuMonitorJSONInjectNMI(qemuMonitorPtr mon)
|
||||||
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuMonitorJSONHasError(reply, "CommandNotFound") &&
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
||||||
qemuMonitorCheckHMP(mon, "inject-nmi")) {
|
|
||||||
VIR_DEBUG("inject-nmi command not found, trying HMP");
|
VIR_DEBUG("inject-nmi command not found, trying HMP");
|
||||||
ret = qemuMonitorTextInjectNMI(mon);
|
ret = qemuMonitorTextInjectNMI(mon);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3404,10 +3398,7 @@ int qemuMonitorJSONSendKey(qemuMonitorPtr mon,
|
||||||
* FIXME: qmp sendkey has not been implemented yet,
|
* FIXME: qmp sendkey has not been implemented yet,
|
||||||
* and qmp API of it cannot be anticipated, so we use hmp temporary.
|
* and qmp API of it cannot be anticipated, so we use hmp temporary.
|
||||||
*/
|
*/
|
||||||
if (qemuMonitorCheckHMP(mon, "sendkey")) {
|
return qemuMonitorTextSendKey(mon, holdtime, keycodes, nkeycodes);
|
||||||
return qemuMonitorTextSendKey(mon, holdtime, keycodes, nkeycodes);
|
|
||||||
} else
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemuMonitorJSONScreendump(qemuMonitorPtr mon,
|
int qemuMonitorJSONScreendump(qemuMonitorPtr mon,
|
||||||
|
|
|
@ -43,8 +43,7 @@ int qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
|
||||||
int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon);
|
int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon);
|
||||||
|
|
||||||
int qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
|
int qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
|
||||||
qemuCapsPtr caps,
|
qemuCapsPtr caps);
|
||||||
int *json_hmp);
|
|
||||||
int qemuMonitorJSONCheckEvents(qemuMonitorPtr mon,
|
int qemuMonitorJSONCheckEvents(qemuMonitorPtr mon,
|
||||||
qemuCapsPtr caps);
|
qemuCapsPtr caps);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue