]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: monitor: Extract the top level format node when querying disks
authorPeter Krempa <pkrempa@redhat.com>
Thu, 23 Feb 2017 18:36:52 +0000 (19:36 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Mar 2017 08:35:19 +0000 (10:35 +0200)
To allow matching the node names gathered via 'query-named-block-nodes'
we need to query and then use the top level nodes from 'query-block'.
Add the data to the structure returned by qemuMonitorGetBlockInfo.

src/qemu/qemu_domain.h
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor_json.c

index 7a9cfad52cf750c58a525e565aeaf4ba08aef15c..36e3a85d36e558d592b036def20d51f05d26ef0f 100644 (file)
@@ -364,6 +364,7 @@ struct qemuDomainDiskInfo {
     bool tray_open;
     bool empty;
     int io_status;
+    char *nodename;
 };
 
 typedef struct _qemuDomainHostdevPrivate qemuDomainHostdevPrivate;
index ee125de2a72bcae75198c6a13f079dc8aeaca877..3b4f7cdb4390a55bf1807ebc609975bef0071e4d 100644 (file)
@@ -2173,6 +2173,16 @@ qemuMonitorBlockIOStatusToError(const char *status)
 }
 
 
+static void
+qemuDomainDiskInfoFree(void *value, const void *name ATTRIBUTE_UNUSED)
+{
+    struct qemuDomainDiskInfo *info = value;
+
+    VIR_FREE(info->nodename);
+    VIR_FREE(info);
+}
+
+
 virHashTablePtr
 qemuMonitorGetBlockInfo(qemuMonitorPtr mon)
 {
@@ -2181,7 +2191,7 @@ qemuMonitorGetBlockInfo(qemuMonitorPtr mon)
 
     QEMU_CHECK_MONITOR_NULL(mon);
 
-    if (!(table = virHashCreate(32, virHashValueFree)))
+    if (!(table = virHashCreate(32, qemuDomainDiskInfoFree)))
         return NULL;
 
     if (mon->json)
index 6c01fad4dd72c7328547decdf0bfb251c7e79bc1..35ee72cf18d3a64e10eacaf3e0bcf9f37261106e 100644 (file)
@@ -1868,9 +1868,11 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
 
     for (i = 0; i < virJSONValueArraySize(devices); i++) {
         virJSONValuePtr dev;
+        virJSONValuePtr image;
         struct qemuDomainDiskInfo *info;
         const char *thisdev;
         const char *status;
+        const char *nodename;
 
         if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
             goto cleanup;
@@ -1907,8 +1909,12 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
             info->tray = true;
 
         /* presence of 'inserted' notifies that a medium is in the device */
-        if (!virJSONValueObjectGetObject(dev, "inserted"))
+        if ((image = virJSONValueObjectGetObject(dev, "inserted"))) {
+            if ((nodename = virJSONValueObjectGetString(image, "node-name")))
+                ignore_value(VIR_STRDUP(info->nodename, nodename));
+        } else {
             info->empty = true;
+        }
 
         /* Missing io-status indicates no error */
         if ((status = virJSONValueObjectGetString(dev, "io-status"))) {