]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Set capabilities based on supported monitor commands
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 13 Feb 2012 11:19:24 +0000 (12:19 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 15 Feb 2012 10:37:39 +0000 (11:37 +0100)
In the future (my next patch in fact) we may want to make
decisions depending on qemu having a monitor command or not.
Therefore, we want to set qemuCaps flag instead of querying
on the monitor each time we are about to make that decision.

src/qemu/qemu_capabilities.c
src/qemu/qemu_capabilities.h
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
src/qemu/qemu_process.c

index 426637ce48dd78ce9bdf277e2259abf5c0f534df..6d35676b0bf1848ae7a8dc7f6b0445f938a0b336 100644 (file)
@@ -152,6 +152,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST,
               "fsdev-writeout",
 
               "drive-iotune", /* 85 */
+              "system_wakeup",
     );
 
 struct qemu_feature_flags {
index 18d6bc853b9d69d2fb14275ea6e2405a263b271d..b9666e12fe5f9e7551a2e51caa04a17842baf671 100644 (file)
@@ -120,6 +120,7 @@ enum qemuCapsFlags {
     QEMU_CAPS_CPU_HOST           = 83, /* support for -cpu host */
     QEMU_CAPS_FSDEV_WRITEOUT     = 84, /* -fsdev writeout supported */
     QEMU_CAPS_DRIVE_IOTUNE       = 85, /* -drive bps= and friends */
+    QEMU_CAPS_WAKEUP             = 86, /* system_wakeup monitor command */
 
     QEMU_CAPS_LAST,                   /* this must always be the last item */
 };
index 7872e3d64943cea43f8614fc78dccde6dd8f7b48..93f35055bdd9df0d942612cb25dc0a8a8711fca2 100644 (file)
@@ -996,9 +996,11 @@ int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
 
 
 
-int qemuMonitorSetCapabilities(qemuMonitorPtr mon)
+int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
+                               virBitmapPtr qemuCaps)
 {
     int ret;
+    int json_hmp;
     VIR_DEBUG("mon=%p", mon);
 
     if (!mon) {
@@ -1009,19 +1011,16 @@ int qemuMonitorSetCapabilities(qemuMonitorPtr mon)
 
     if (mon->json) {
         ret = qemuMonitorJSONSetCapabilities(mon);
-        if (ret == 0) {
-            int hmp = qemuMonitorJSONCheckHMP(mon);
-            if (hmp < 0) {
-                /* qemu may quited unexpectedly when we call
-                 * qemuMonitorJSONCheckHMP() */
-                ret = -1;
-            } else {
-                mon->json_hmp = hmp > 0;
-            }
-        }
+        if (ret)
+            goto cleanup;
+
+        ret = qemuMonitorJSONCheckCommands(mon, qemuCaps, &json_hmp);
+        mon->json_hmp = json_hmp > 0;
     } else {
         ret = 0;
     }
+
+cleanup:
     return ret;
 }
 
index 5945d3e462af6f1b6e88600129f7cd89354682b8..7c6c52bbe47a44ab8aa06aebd01349d9b29af3c0 100644 (file)
@@ -29,6 +29,7 @@
 
 # include "domain_conf.h"
 # include "qemu_conf.h"
+# include "bitmap.h"
 # include "virhash.h"
 
 typedef struct _qemuMonitor qemuMonitor;
@@ -135,7 +136,8 @@ qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
 
 void qemuMonitorClose(qemuMonitorPtr mon);
 
-int qemuMonitorSetCapabilities(qemuMonitorPtr mon);
+int qemuMonitorSetCapabilities(qemuMonitorPtr mon,
+                               virBitmapPtr qemuCaps);
 
 int qemuMonitorCheckHMP(qemuMonitorPtr mon, const char *cmd);
 
index b0ae57002599160c98f88f380ca8a57f7532b563..513788a1f9a7c177d3e645614ab7e9acaa68f1b1 100644 (file)
@@ -34,6 +34,7 @@
 #include "qemu_monitor_text.h"
 #include "qemu_monitor_json.h"
 #include "qemu_command.h"
+#include "qemu_capabilities.h"
 #include "memory.h"
 #include "logging.h"
 #include "driver.h"
@@ -800,7 +801,9 @@ qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon)
  * human-monitor-command worked or -1 on failure
  */
 int
-qemuMonitorJSONCheckHMP(qemuMonitorPtr mon)
+qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
+                             virBitmapPtr qemuCaps,
+                             int *json_hmp)
 {
     int ret = -1;
     virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-commands", NULL);
@@ -828,13 +831,13 @@ qemuMonitorJSONCheckHMP(qemuMonitorPtr mon)
             !(name = virJSONValueObjectGetString(entry, "name")))
             goto cleanup;
 
-        if (STREQ(name, "human-monitor-command")) {
-            ret = 1;
-            goto cleanup;
-        }
+        if (STREQ(name, "human-monitor-command"))
+            *json_hmp = 1;
+
+        if (STREQ(name, "system_wakeup"))
+            qemuCapsSet(qemuCaps, QEMU_CAPS_WAKEUP);
     }
 
-    /* human-monitor-command is not supported */
     ret = 0;
 
 cleanup:
index d221e59661bce17e1ccf24164d9b155f7ff5db1a..d0b3000578441e2326294b43872f05472c34d77a 100644 (file)
@@ -28,6 +28,7 @@
 # include "internal.h"
 
 # include "qemu_monitor.h"
+# include "bitmap.h"
 
 int qemuMonitorJSONIOProcess(qemuMonitorPtr mon,
                              const char *data,
@@ -41,7 +42,9 @@ int qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
 
 int qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon);
 
-int qemuMonitorJSONCheckHMP(qemuMonitorPtr mon);
+int qemuMonitorJSONCheckCommands(qemuMonitorPtr mon,
+                                 virBitmapPtr qemuCaps,
+                                 int *json_hmp);
 
 int qemuMonitorJSONStartCPUs(qemuMonitorPtr mon,
                              virConnectPtr conn);
index 2d92d66a0e122562f952b71d7d653c247a2179e3..7afb58561a6b1c1c0a08165e1930859bb3ab3d83 100644 (file)
@@ -1086,7 +1086,7 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm)
 
 
     qemuDomainObjEnterMonitorWithDriver(driver, vm);
-    ret = qemuMonitorSetCapabilities(priv->mon);
+    ret = qemuMonitorSetCapabilities(priv->mon, priv->qemuCaps);
     qemuDomainObjExitMonitorWithDriver(driver, vm);
 
 error: