Re: [PATCH 2/3] nodedev: Introduce virNodeDeviceObjGetNames

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

 



On 04/06/2017 01:31 PM, John Ferlan wrote:
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@xxxxxxxxxx>
---
 src/conf/virnodedeviceobj.c          | 36 +++++++++++++++++++++++++++++++++++-
 src/conf/virnodedeviceobj.h          | 12 ++++++++----
 src/libvirt_private.syms             |  2 +-
 src/node_device/node_device_driver.c | 34 ++++++++++------------------------
 src/test/test_driver.c               | 27 ++++++---------------------
 5 files changed, 60 insertions(+), 51 deletions(-)

diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index f0c20c2..5a8dfe7 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -33,7 +33,7 @@
 VIR_LOG_INIT("conf.virnodedeviceobj");


-int
+static int
 virNodeDeviceObjHasCap(const virNodeDeviceObj *dev,
                        const char *cap)
 {
@@ -496,6 +496,40 @@ 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]);
+    memset(names, 0, maxnames * sizeof(*names));

Like you've said in our discussion to early series, this is no longer here.

+    return -1;
+}
+
+
 #define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && \
                      virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FLAG))
 static bool
diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h
index 7d303a0..0acd8ce 100644
--- a/src/conf/virnodedeviceobj.h
+++ b/src/conf/virnodedeviceobj.h
@@ -40,10 +40,6 @@ struct _virNodeDeviceDriverState {
 };


-int
-virNodeDeviceObjHasCap(const virNodeDeviceObj *dev,
-                       const char *cap);
-
 virNodeDeviceObjPtr
 virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs,
                            const char *name);
@@ -89,6 +85,14 @@ virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr devs,
                              virNodeDeviceObjListFilter aclfilter);

 int
+virNodeDeviceObjGetNames(virNodeDeviceObjListPtr devs,
+                         virConnectPtr conn,
+                         virNodeDeviceObjListFilter aclfilter,
+                         const char *cap,
+                         char **const names,
+                         int maxnames);
+
+int
 virNodeDeviceObjListExport(virConnectPtr conn,
                            virNodeDeviceObjList devobjs,
                            virNodeDevicePtr **devices,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 104ed88..5df6a5d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -946,8 +946,8 @@ virInterfaceObjUnlock;
 virNodeDeviceObjAssignDef;
 virNodeDeviceObjFindByName;
 virNodeDeviceObjFindBySysfsPath;
+virNodeDeviceObjGetNames;
 virNodeDeviceObjGetParentHost;
-virNodeDeviceObjHasCap;
 virNodeDeviceObjListExport;
 virNodeDeviceObjListFree;
 virNodeDeviceObjLock;
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index f90b168..e850a22 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -174,14 +174,17 @@ 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;
+
+    memset(names, 0, maxnames * sizeof(*names));

Nor this.


     if (virNodeListDevicesEnsureACL(conn) < 0)
         return -1;

Michal

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