]> xenbits.xensource.com Git - libvirt.git/commitdiff
nodedev: Introduce virNodeDeviceObjGetNames
authorJohn Ferlan <jferlan@redhat.com>
Sun, 19 Mar 2017 19:51:03 +0000 (15:51 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 10 Apr 2017 11:36:23 +0000 (07:36 -0400)
Unify the *ListDevice API into virnodedeviceobj.c from node_device_driver
and test_driver.  The only real difference between the two is that the test
driver doesn't call the aclfilter API. The name of the new API follows that
of other drivers to "GetNames".

NB: Change some variable names to match what they really are - consistency
with other drivers. Also added a clear of the input names.

This also allows virNodeDeviceObjHasCap to be static to virnodedeviceobj

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/conf/virnodedeviceobj.c
src/conf/virnodedeviceobj.h
src/libvirt_private.syms
src/node_device/node_device_driver.c
src/test/test_driver.c

index f0c20c28b185238cd25ce20a836a6fb056a55d6a..5b15363d8de7f978ffc49ede09baeb7dd9be7529 100644 (file)
@@ -33,7 +33,7 @@
 VIR_LOG_INIT("conf.virnodedeviceobj");
 
 
-int
+static int
 virNodeDeviceObjHasCap(const virNodeDeviceObj *dev,
                        const char *cap)
 {
@@ -496,6 +496,39 @@ virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr devs,
 }
 
 
+int
+virNodeDeviceObjGetNames(virNodeDeviceObjListPtr devs,
+                         virConnectPtr conn,
+                         virNodeDeviceObjListFilter aclfilter,
+                         const char *cap,
+                         char **const names,
+                         int maxnames)
+{
+    int nnames = 0;
+    size_t i;
+
+    for (i = 0; i < devs->count && nnames < maxnames; i++) {
+        virNodeDeviceObjPtr obj = devs->objs[i];
+        virNodeDeviceObjLock(obj);
+        if (aclfilter && aclfilter(conn, obj->def) &&
+            (!cap || virNodeDeviceObjHasCap(obj, cap))) {
+            if (VIR_STRDUP(names[nnames++], obj->def->name) < 0) {
+                virNodeDeviceObjUnlock(obj);
+                goto failure;
+            }
+        }
+        virNodeDeviceObjUnlock(obj);
+    }
+
+    return nnames;
+
+ failure:
+    while (--nnames >= 0)
+        VIR_FREE(names[nnames]);
+    return -1;
+}
+
+
 #define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \
                      virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG))
 static bool
index 7d303a060ae4316523dd3e04a8e6b325f44135b8..0acd8cedad56023c1044a848c13ae2193a8d51e6 100644 (file)
@@ -40,10 +40,6 @@ struct _virNodeDeviceDriverState {
 };
 
 
-int
-virNodeDeviceObjHasCap(const virNodeDeviceObj *dev,
-                       const char *cap);
-
 virNodeDeviceObjPtr
 virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs,
                            const char *name);
@@ -88,6 +84,14 @@ virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr devs,
                              const char *cap,
                              virNodeDeviceObjListFilter aclfilter);
 
+int
+virNodeDeviceObjGetNames(virNodeDeviceObjListPtr devs,
+                         virConnectPtr conn,
+                         virNodeDeviceObjListFilter aclfilter,
+                         const char *cap,
+                         char **const names,
+                         int maxnames);
+
 int
 virNodeDeviceObjListExport(virConnectPtr conn,
                            virNodeDeviceObjList devobjs,
index bd5a0c3b7817fcd18e7593e683950b9d124e6706..62bc36ac58d88f1a3895992f790122c165a575eb 100644 (file)
@@ -948,8 +948,8 @@ virInterfaceObjUnlock;
 virNodeDeviceObjAssignDef;
 virNodeDeviceObjFindByName;
 virNodeDeviceObjFindBySysfsPath;
+virNodeDeviceObjGetNames;
 virNodeDeviceObjGetParentHost;
-virNodeDeviceObjHasCap;
 virNodeDeviceObjListExport;
 virNodeDeviceObjListFree;
 virNodeDeviceObjLock;
index f90b168749de3ab648c2a192e947da8b501fa950..7e705e2b182c3f6fc434f12274931e6376cb8775 100644 (file)
@@ -174,14 +174,15 @@ nodeNumOfDevices(virConnectPtr conn,
     return ndevs;
 }
 
+
 int
 nodeListDevices(virConnectPtr conn,
                 const char *cap,
-                char **const names, int maxnames,
+                char **const names,
+                int maxnames,
                 unsigned int flags)
 {
-    int ndevs = 0;
-    size_t i;
+    int nnames;
 
     if (virNodeListDevicesEnsureACL(conn) < 0)
         return -1;
@@ -189,29 +190,12 @@ nodeListDevices(virConnectPtr conn,
     virCheckFlags(0, -1);
 
     nodeDeviceLock();
-    for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) {
-        virNodeDeviceObjPtr obj = driver->devs.objs[i];
-        virNodeDeviceObjLock(obj);
-        if (virNodeListDevicesCheckACL(conn, obj->def) &&
-            (cap == NULL ||
-             virNodeDeviceObjHasCap(obj, cap))) {
-            if (VIR_STRDUP(names[ndevs++], obj->def->name) < 0) {
-                virNodeDeviceObjUnlock(obj);
-                goto failure;
-            }
-        }
-        virNodeDeviceObjUnlock(obj);
-    }
+    nnames = virNodeDeviceObjGetNames(&driver->devs, conn,
+                                      virNodeListDevicesCheckACL,
+                                      cap, names, maxnames);
     nodeDeviceUnlock();
 
-    return ndevs;
-
- failure:
-    nodeDeviceUnlock();
-    --ndevs;
-    while (--ndevs >= 0)
-        VIR_FREE(names[ndevs]);
-    return -1;
+    return nnames;
 }
 
 int
index cf6ccd98a4ce2b8b671ca2a61b90cc99c1e8dd55..f9d9512032de81da7eb2fac2ffe3b84035cca80d 100644 (file)
@@ -5382,6 +5382,7 @@ testNodeNumOfDevices(virConnectPtr conn,
     return ndevs;
 }
 
+
 static int
 testNodeListDevices(virConnectPtr conn,
                     const char *cap,
@@ -5390,35 +5391,19 @@ testNodeListDevices(virConnectPtr conn,
                     unsigned int flags)
 {
     testDriverPtr driver = conn->privateData;
-    int ndevs = 0;
-    size_t i;
+    int nnames = 0;
 
     virCheckFlags(0, -1);
 
     testDriverLock(driver);
-    for (i = 0; i < driver->devs.count && ndevs < maxnames; i++) {
-        virNodeDeviceObjLock(driver->devs.objs[i]);
-        if (cap == NULL ||
-            virNodeDeviceObjHasCap(driver->devs.objs[i], cap)) {
-            if (VIR_STRDUP(names[ndevs++], driver->devs.objs[i]->def->name) < 0) {
-                virNodeDeviceObjUnlock(driver->devs.objs[i]);
-                goto failure;
-            }
-        }
-        virNodeDeviceObjUnlock(driver->devs.objs[i]);
-    }
+    nnames = virNodeDeviceObjGetNames(&driver->devs, conn, NULL,
+                                     cap, names, maxnames);
     testDriverUnlock(driver);
 
-    return ndevs;
-
- failure:
-    testDriverUnlock(driver);
-    --ndevs;
-    while (--ndevs >= 0)
-        VIR_FREE(names[ndevs]);
-    return -1;
+    return nnames;
 }
 
+
 static virNodeDevicePtr
 testNodeDeviceLookupByName(virConnectPtr conn, const char *name)
 {