[PATCH v1 3/7] qemu_capabilities: Separate out device props fetching

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

 



The code is written generic enough to be reused. Move it into a
separate function.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 62 ++++++++++++++++++++++++++++++--------------
 1 file changed, 42 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 1d2110eef3..2d36aeaa54 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1250,14 +1250,19 @@ static struct virQEMUCapsStringFlags virQEMUCapsQMPSchemaQueries[] = {
     { "blockdev-add/arg-type/+qcow2/encrypt/+luks/key-secret", QEMU_CAPS_QCOW2_LUKS },
 };
 
-struct virQEMUCapsObjectTypeProps {
+typedef struct _virQEMUCapsObjectTypeProps virQEMUCapsObjectTypeProps;
+struct _virQEMUCapsObjectTypeProps {
     const char *type;
     struct virQEMUCapsStringFlags *props;
     size_t nprops;
     int capsCondition;
 };
 
-static struct virQEMUCapsObjectTypeProps virQEMUCapsDeviceProps[] = {
+typedef int (*virQEMUCapsObjectTypePropsCB)(qemuMonitorPtr mon,
+                                            const char *type,
+                                            char ***props);
+
+static virQEMUCapsObjectTypeProps virQEMUCapsDeviceProps[] = {
     { "virtio-blk-pci", virQEMUCapsDevicePropsVirtioBlk,
       ARRAY_CARDINALITY(virQEMUCapsDevicePropsVirtioBlk),
       -1 },
@@ -2067,6 +2072,35 @@ virQEMUCapsProbeQMPEvents(virQEMUCapsPtr qemuCaps,
     return 0;
 }
 
+static int
+virQEMUCapsProbeQMPGenericProps(virQEMUCapsPtr qemuCaps,
+                                qemuMonitorPtr mon,
+                                virQEMUCapsObjectTypeProps *props,
+                                size_t nprops,
+                                virQEMUCapsObjectTypePropsCB propsGetCB)
+{
+    int nvalues;
+    char **values;
+    size_t i;
+
+    for (i = 0; i < nprops; i++) {
+        const char *type = props[i].type;
+        int cap = props[i].capsCondition;
+
+        if (cap >= 0 && !virQEMUCapsGet(qemuCaps, cap))
+            continue;
+
+        if ((nvalues = propsGetCB(mon, type, &values)) < 0)
+            return -1;
+        virQEMUCapsProcessStringFlags(qemuCaps,
+                                      props[i].nprops,
+                                      props[i].props,
+                                      nvalues, values);
+        virStringListFreeCount(values, nvalues);
+    }
+
+    return 0;
+}
 
 static int
 virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps,
@@ -2074,7 +2108,6 @@ virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps,
 {
     int nvalues;
     char **values;
-    size_t i;
 
     if ((nvalues = qemuMonitorGetObjectTypes(mon, &values)) < 0)
         return -1;
@@ -2084,23 +2117,12 @@ virQEMUCapsProbeQMPDevices(virQEMUCapsPtr qemuCaps,
                                   nvalues, values);
     virStringListFreeCount(values, nvalues);
 
-    for (i = 0; i < ARRAY_CARDINALITY(virQEMUCapsDeviceProps); i++) {
-        const char *device = virQEMUCapsDeviceProps[i].type;
-        int cap = virQEMUCapsDeviceProps[i].capsCondition;
-
-        if (cap >= 0 && !virQEMUCapsGet(qemuCaps, cap))
-            continue;
-
-        if ((nvalues = qemuMonitorGetDeviceProps(mon,
-                                                 device,
-                                                 &values)) < 0)
-            return -1;
-        virQEMUCapsProcessStringFlags(qemuCaps,
-                                      virQEMUCapsDeviceProps[i].nprops,
-                                      virQEMUCapsDeviceProps[i].props,
-                                      nvalues, values);
-        virStringListFreeCount(values, nvalues);
-    }
+    if (virQEMUCapsProbeQMPGenericProps(qemuCaps,
+                                        mon,
+                                        virQEMUCapsDeviceProps,
+                                        ARRAY_CARDINALITY(virQEMUCapsDeviceProps),
+                                        qemuMonitorGetDeviceProps) < 0)
+        return -1;
 
     /* Prefer -chardev spicevmc (detected earlier) over -device spicevmc */
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_CHARDEV_SPICEVMC))
-- 
2.16.1

--
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]

  Powered by Linux