[PATCH v3 4/4] qemu: Create helper qemuMonitorJSONGetBlockDevDevice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This will fetch "this device" from the recently returned 'dev' and perform
common error checking for the paths that call it.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/qemu/qemu_monitor_json.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 8cb3891..458b112 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1822,6 +1822,21 @@ qemuMonitorJSONGetBlockDev(virJSONValuePtr devices,
 }
 
 
+static const char *
+qemuMonitorJSONGetBlockDevDevice(virJSONValuePtr dev)
+{
+    const char *thisdev;
+
+    if (!(thisdev = virJSONValueObjectGetString(dev, "device"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-block device entry was not in expected format"));
+        return NULL;
+    }
+
+    return thisdev;
+}
+
+
 int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
                                 virHashTablePtr table)
 {
@@ -1842,11 +1857,8 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
         if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
             goto cleanup;
 
-        if ((thisdev = virJSONValueObjectGetString(dev, "device")) == NULL) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("block info device entry was not in expected format"));
+        if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev)))
             goto cleanup;
-        }
 
         thisdev = qemuAliasDiskDriveSkipPrefix(thisdev);
 
@@ -2102,12 +2114,8 @@ qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon,
         if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
             goto cleanup;
 
-        if (!(dev_name = virJSONValueObjectGetString(dev, "device"))) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("query-block device entry was not "
-                             "in expected format"));
+        if (!(dev_name = qemuMonitorJSONGetBlockDevDevice(dev)))
             goto cleanup;
-        }
 
         /* drive may be empty */
         if (!(inserted = virJSONValueObjectGetObject(dev, "inserted")) ||
@@ -4013,11 +4021,8 @@ qemuMonitorJSONDiskNameLookup(qemuMonitorPtr mon,
         if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
             goto cleanup;
 
-        if (!(thisdev = virJSONValueObjectGetString(dev, "device"))) {
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("block info device entry was not in expected format"));
+        if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev)))
             goto cleanup;
-        }
 
         if (STREQ(thisdev, device)) {
             if ((inserted = virJSONValueObjectGetObject(dev, "inserted")) &&
-- 
2.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]