This is to list the node device objects, supports to filter the results
by capability types.

include/libvirt/libvirt.h.in: Declare enum virConnectListAllNodeDeviceFlags
                              and virConnectListAllNodeDevices.
python/generator.py: Skip auto-generating
src/driver.h: (virDrvConnectListAllNodeDevices)
src/libvirt.c: Implement the public API
src/libvirt_public.syms: Export the symbol to public
---
 include/libvirt/libvirt.h.in |   25 +++++++++++++++++
 python/generator.py          |    1 +
 src/driver.h                 |    4 +++
 src/libvirt.c                |   59 ++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |    1 +
 5 files changed, 90 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 2b8106e..ee186c0 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2767,6 +2767,31 @@ int                     virNodeListDevices      
(virConnectPtr conn,
                                                  char **const names,
                                                  int maxnames,
                                                  unsigned int flags);
+/*
+ * virConnectListAllNodeDevices:
+ *
+ * Flags used to filter the returned node devices. Flags in each group
+ * are exclusive.
+ */
+typedef enum {
+    /* Reserved the first 6 bits for the possibility of persistent
+     * node device support in future.
+     */
+
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_SYSTEM        = 1 << 6,
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_PCI_DEV       = 1 << 7,
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_DEV       = 1 << 8,
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_USB_INTERFACE = 1 << 9,
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET           = 1 << 10,
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_HOST     = 1 << 11,
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_TARGET   = 1 << 12,
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI          = 1 << 13,
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_STORAGE       = 1 << 14,
+} virConnectListAllNodeDeviceFlags;
+
+int                     virConnectListAllNodeDevices (virConnectPtr conn,
+                                                      virNodeDevicePtr 
**devices,
+                                                      unsigned int flags);
 
 virNodeDevicePtr        virNodeDeviceLookupByName (virConnectPtr conn,
                                                    const char *name);
diff --git a/python/generator.py b/python/generator.py
index 51c3fce..6f50fa0 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -460,6 +460,7 @@ skip_function = (
     'virStoragePoolListAllVolumes', # overridden in virStoragePool.py
     'virConnectListAllNetworks', # overridden in virConnect.py
     'virConnectListAllInterfaces', # overridden in virConnect.py
+    'virConnectListAllNodeDevices', # overridden in virConnect.py
 
     'virStreamRecvAll', # Pure python libvirt-override-virStream.py
     'virStreamSendAll', # Pure python libvirt-override-virStream.py
diff --git a/src/driver.h b/src/driver.h
index 335ee86..102684c 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1456,6 +1456,9 @@ typedef int (*virDevMonListDevices)(virConnectPtr conn,
                                     char **const names,
                                     int maxnames,
                                     unsigned int flags);
+typedef int (*virDevMonListAllNodeDevices)(virConnectPtr conn,
+                                           virNodeDevicePtr **devices,
+                                           unsigned int flags);
 
 typedef virNodeDevicePtr (*virDevMonDeviceLookupByName)(virConnectPtr conn,
                                                         const char *name);
@@ -1489,6 +1492,7 @@ struct _virDeviceMonitor {
     virDrvClose                 close;
     virDevMonNumOfDevices       numOfDevices;
     virDevMonListDevices        listDevices;
+    virDevMonListAllNodeDevices listAllNodeDevices;
     virDevMonDeviceLookupByName deviceLookupByName;
     virDevMonDeviceGetXMLDesc   deviceGetXMLDesc;
     virDevMonDeviceGetParent    deviceGetParent;
diff --git a/src/libvirt.c b/src/libvirt.c
index c50bb3d..6d4cd76 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -13559,6 +13559,65 @@ error:
     return -1;
 }
 
+/**
+ * virConnectListAllNodeDevices:
+ * @conn: Pointer to the hypervisor connection.
+ * @devices: Pointer to a variable to store the array containing the node
+ *           device objects or NULL if the list is not required (just returns
+ *           number of node devices).
+ * @flags: bitwise-OR of virConnectListAllNodeDevices.
+ *
+ * Collect the list of node devices, and allocate an array to store those
+ * objects.
+ *
+ * By default, this API covers all node devices; it is also possible to return
+ * the filtered objects with flags. Filters are provided in groups, where each
+ * group contains bits that describe mutually exclusive attributes of a node
+ * device.
+ *
+ * Only one group of the @flags is supported. It supports to filter the node
+ * devices by capability type.
+ *
+ * Returns the number of node devices found or -1 and sets @devices to NULL in
+ * case of error.  On success, the array stored into @devices is guaranteed to
+ * have an extra allocated element set to NULL but not included in the return
+ * count, to make iteration easier.  The caller is responsible for calling
+ * virNodeDeviceFree() on each array element, then calling free() on
+ * @devices.
+ */
+int
+virConnectListAllNodeDevices(virConnectPtr conn,
+                             virNodeDevicePtr **devices,
+                             unsigned int flags)
+{
+    VIR_DEBUG("conn=%p, devices=%p, flags=%x", conn, devices, flags);
+
+    virResetLastError();
+
+    if (devices)
+        *devices = NULL;
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (conn->deviceMonitor &&
+        conn->deviceMonitor->listAllNodeDevices) {
+        int ret;
+        ret = conn->deviceMonitor->listAllNodeDevices(conn, devices, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
 
 /**
  * virNodeListDevices:
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 298eaac..d45e38f 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -550,6 +550,7 @@ LIBVIRT_0.9.14 {
         virStoragePoolListAllVolumes;
         virConnectListAllNetworks;
         virConnectListAllInterfaces;
+        virConnectListAllNodeDevices;
 } LIBVIRT_0.9.13;
 
 # .... define new API here using predicted next version number ....
-- 
1.7.7.3

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

Reply via email to