[libvirt] [PATCH v4 3/6] nodedev: Introduce new mdev_types and mdev nodedev capabilities

Erik Skultety eskultet at redhat.com
Mon May 15 12:10:19 UTC 2017


The reason for introducing two capabilities, one for the device itself
(cap 'mdev') and one for the parent device listing the available types
('mdev_types'), is that we should be able to do
'virsh nodedev-list --cap' not only for existing mdev devices but also
for devices that support creation of mdev devices, since one day libvirt
might be actually able to create the mdev devices in an automated way
(just like we do for NPIV/vHBA).

Signed-off-by: Erik Skultety <eskultet at redhat.com>
---
 include/libvirt/libvirt-nodedev.h    |  2 ++
 src/conf/node_device_conf.c          | 10 +++++++++-
 src/conf/node_device_conf.h          |  6 +++++-
 src/conf/virnodedeviceobj.c          |  4 +++-
 src/libvirt-nodedev.c                |  2 ++
 src/node_device/node_device_driver.c |  2 ++
 src/node_device/node_device_udev.c   |  3 +++
 tools/virsh-nodedev.c                |  6 ++++++
 8 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-nodedev.h
index 85003903d..1e3043787 100644
--- a/include/libvirt/libvirt-nodedev.h
+++ b/include/libvirt/libvirt-nodedev.h
@@ -79,6 +79,8 @@ typedef enum {
     VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS        = 1 << 10, /* Capable of vport */
     VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC  = 1 << 11, /* Capable of scsi_generic */
     VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM           = 1 << 12, /* DRM device */
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES    = 1 << 13, /* Capable of mediated devices */
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV          = 1 << 14, /* Mediated device */
 } virConnectListAllNodeDeviceFlags;
 
 int                     virConnectListAllNodeDevices (virConnectPtr conn,
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 7aab2e03c..40d71f277 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -60,7 +60,9 @@ VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST,
               "fc_host",
               "vports",
               "scsi_generic",
-              "drm")
+              "drm",
+              "mdev_types",
+              "mdev")
 
 VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST,
               "80203",
@@ -540,6 +542,8 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def)
         case VIR_NODE_DEV_CAP_DRM:
             virBufferEscapeString(&buf, "<type>%s</type>\n", virNodeDevDRMTypeToString(data->drm.type));
             break;
+        case VIR_NODE_DEV_CAP_MDEV:
+        case VIR_NODE_DEV_CAP_MDEV_TYPES:
         case VIR_NODE_DEV_CAP_FC_HOST:
         case VIR_NODE_DEV_CAP_VPORTS:
         case VIR_NODE_DEV_CAP_LAST:
@@ -1612,6 +1616,8 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt,
     case VIR_NODE_DEV_CAP_DRM:
         ret = virNodeDevCapDRMParseXML(ctxt, def, node, &caps->data.drm);
         break;
+    case VIR_NODE_DEV_CAP_MDEV:
+    case VIR_NODE_DEV_CAP_MDEV_TYPES:
     case VIR_NODE_DEV_CAP_FC_HOST:
     case VIR_NODE_DEV_CAP_VPORTS:
     case VIR_NODE_DEV_CAP_SCSI_GENERIC:
@@ -1930,6 +1936,8 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
     case VIR_NODE_DEV_CAP_SCSI_GENERIC:
         VIR_FREE(data->sg.path);
         break;
+    case VIR_NODE_DEV_CAP_MDEV:
+    case VIR_NODE_DEV_CAP_MDEV_TYPES:
     case VIR_NODE_DEV_CAP_DRM:
     case VIR_NODE_DEV_CAP_FC_HOST:
     case VIR_NODE_DEV_CAP_VPORTS:
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index a5d5cdd2a..273d49f76 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -64,6 +64,8 @@ typedef enum {
     VIR_NODE_DEV_CAP_VPORTS,		/* HBA which is capable of vports */
     VIR_NODE_DEV_CAP_SCSI_GENERIC,      /* SCSI generic device */
     VIR_NODE_DEV_CAP_DRM,               /* DRM device */
+    VIR_NODE_DEV_CAP_MDEV_TYPES,      /* Device capable of mediated devices */
+    VIR_NODE_DEV_CAP_MDEV,            /* Mediated device */
 
     VIR_NODE_DEV_CAP_LAST
 } virNodeDevCapType;
@@ -351,7 +353,9 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps);
                  VIR_CONNECT_LIST_NODE_DEVICES_CAP_FC_HOST       | \
                  VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS        | \
                  VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC  | \
-                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM)
+                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM           | \
+                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES    | \
+                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV)
 
 char *
 virNodeDeviceGetParentName(virConnectPtr conn,
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 4f47b4e41..181d2efe1 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -550,7 +550,9 @@ virNodeDeviceMatch(virNodeDeviceObjPtr devobj,
               MATCH(FC_HOST)       ||
               MATCH(VPORTS)        ||
               MATCH(SCSI_GENERIC)  ||
-              MATCH(DRM)))
+              MATCH(DRM)           ||
+              MATCH(MDEV_TYPES)    ||
+              MATCH(MDEV)))
             return false;
     }
 
diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c
index 83376b0d9..44e2b4efd 100644
--- a/src/libvirt-nodedev.c
+++ b/src/libvirt-nodedev.c
@@ -98,6 +98,8 @@ virNodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags)
  *   VIR_CONNECT_LIST_NODE_DEVICES_CAP_VPORTS
  *   VIR_CONNECT_LIST_NODE_DEVICES_CAP_SCSI_GENERIC
  *   VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM
+ *   VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES
+ *   VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV
  *
  * 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
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index c3997c922..ba3da6288 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -82,6 +82,8 @@ static int update_caps(virNodeDeviceObjPtr dev)
         case VIR_NODE_DEV_CAP_FC_HOST:
         case VIR_NODE_DEV_CAP_VPORTS:
         case VIR_NODE_DEV_CAP_SCSI_GENERIC:
+        case VIR_NODE_DEV_CAP_MDEV_TYPES:
+        case VIR_NODE_DEV_CAP_MDEV:
         case VIR_NODE_DEV_CAP_LAST:
             break;
         }
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 6e706a10b..1ddb55c80 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -43,6 +43,7 @@
 #include "virpci.h"
 #include "virstring.h"
 #include "virnetdev.h"
+#include "virmdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_NODEDEV
 
@@ -1060,6 +1061,8 @@ static int udevGetDeviceDetails(struct udev_device *device,
         return udevProcessSCSIGeneric(device, def);
     case VIR_NODE_DEV_CAP_DRM:
         return udevProcessDRMDevice(device, def);
+    case VIR_NODE_DEV_CAP_MDEV:
+    case VIR_NODE_DEV_CAP_MDEV_TYPES:
     case VIR_NODE_DEV_CAP_SYSTEM:
     case VIR_NODE_DEV_CAP_FC_HOST:
     case VIR_NODE_DEV_CAP_VPORTS:
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index c69144021..ad96dda1f 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -454,6 +454,12 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         case VIR_NODE_DEV_CAP_DRM:
             flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM;
             break;
+        case VIR_NODE_DEV_CAP_MDEV_TYPES:
+            flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES;
+            break;
+        case VIR_NODE_DEV_CAP_MDEV:
+            flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV;
+            break;
         case VIR_NODE_DEV_CAP_LAST:
             break;
         }
-- 
2.13.0




More information about the libvir-list mailing list