]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Remove upfront check for hmp - just try it cope with failure
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 6 Sep 2012 15:28:53 +0000 (16:28 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 14 Sep 2012 11:59:25 +0000 (12:59 +0100)
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>
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index b43b15e889ca905fcdb85d3061ec8bf31532da22..f8d717f13f0847cc6ad1dc9a38c42811bd955ad8 100644 (file)
@@ -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)
@@ -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
 qemuMonitorStartCPUs(qemuMonitorPtr mon,
                      virConnectPtr conn)
index f206d49c2a51ba11f9ffe764d028165343a8e21d..d44e93cb183301307cd52b99552b8f282c52d923 100644 (file)
@@ -159,8 +159,6 @@ void qemuMonitorClose(qemuMonitorPtr mon);
 int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
                                qemuCapsPtr caps);
 
-int qemuMonitorCheckHMP(qemuMonitorPtr mon, const char *cmd);
-
 void qemuMonitorLock(qemuMonitorPtr mon);
 void qemuMonitorUnlock(qemuMonitorPtr mon);
 
index 8842817b2459a613aadbf0f8b79e73d308d56fb2..ed18a64fae9c3ad39b74a05b9e1a38ba51459f1e 100644 (file)
@@ -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,
index f5d515f52842d771b562fa4849681e735a9f30eb..d092b880f1e2b6984aa01ab00bbf855c640f48de 100644 (file)
@@ -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);