[PATCH v2 06/10] nodedev: Introduce the mdev capability to the nodedev driver structure

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

 



Besides updating the capability enum, this patch introduces
'virNodeDevCapMdev' structure which will store everything libvirt can
gather from sysfs about a mediated device. Since we need to report the
info for both the mediated child device and its parent mdev capabilities
(merely the mdev types' attributes), this structure serves in both of
these cases with the difference being that the amount of data it holds
depends on the specific scenario (child vs parent).

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

diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-nodedev.h
index 85003903d..59edf4db0 100644
--- a/include/libvirt/libvirt-nodedev.h
+++ b/include/libvirt/libvirt-nodedev.h
@@ -79,6 +79,7 @@ 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          = 1 << 13, /* Mediated device */
 } virConnectListAllNodeDeviceFlags;
 
 int                     virConnectListAllNodeDevices (virConnectPtr conn,
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index de346597a..fdddc97eb 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -60,7 +60,8 @@ VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST,
               "fc_host",
               "vports",
               "scsi_generic",
-              "drm")
+              "drm",
+              "mdev")
 
 VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST,
               "80203",
@@ -542,6 +543,7 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def)
             break;
         case VIR_NODE_DEV_CAP_FC_HOST:
         case VIR_NODE_DEV_CAP_VPORTS:
+        case VIR_NODE_DEV_CAP_MDEV:
         case VIR_NODE_DEV_CAP_LAST:
             break;
         }
@@ -1613,6 +1615,7 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt,
     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:
     case VIR_NODE_DEV_CAP_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unknown capability type '%d' for '%s'"),
@@ -1928,6 +1931,7 @@ 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_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..375f97256 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -64,6 +64,7 @@ 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,              /* Mediated device */
 
     VIR_NODE_DEV_CAP_LAST
 } virNodeDevCapType;
@@ -351,7 +352,8 @@ 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)
 
 char *
 virNodeDeviceGetParentName(virConnectPtr conn,
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 4f47b4e41..442914b27 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -550,7 +550,8 @@ virNodeDeviceMatch(virNodeDeviceObjPtr devobj,
               MATCH(FC_HOST)       ||
               MATCH(VPORTS)        ||
               MATCH(SCSI_GENERIC)  ||
-              MATCH(DRM)))
+              MATCH(DRM)           ||
+              MATCH(MDEV)))
             return false;
     }
 
diff --git a/src/libvirt-nodedev.c b/src/libvirt-nodedev.c
index 83376b0d9..f9d8edf7e 100644
--- a/src/libvirt-nodedev.c
+++ b/src/libvirt-nodedev.c
@@ -98,6 +98,7 @@ 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
  *
  * 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..fa1993e43 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -82,6 +82,7 @@ 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:
         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..95c1aee29 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
 
@@ -1016,12 +1017,16 @@ udevGetDeviceType(struct udev_device *device,
         if (udevHasDeviceProperty(device, "INTERFACE"))
             *type = VIR_NODE_DEV_CAP_NET;
 
-        /* SCSI generic device doesn't set DEVTYPE property */
+        /* Neither SCSI generic devices nor mediated devices set DEVTYPE
+         * property, therefore we need to rely on the SUBSYSTEM property */
         if (udevGetStringProperty(device, "SUBSYSTEM", &subsystem) < 0)
             return -1;
 
         if (STREQ_NULLABLE(subsystem, "scsi_generic"))
             *type = VIR_NODE_DEV_CAP_SCSI_GENERIC;
+        else if (STREQ_NULLABLE(subsystem, "mdev"))
+            *type = VIR_NODE_DEV_CAP_MDEV;
+
         VIR_FREE(subsystem);
     }
 
@@ -1060,6 +1065,7 @@ 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_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..19dcfafa6 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -454,6 +454,8 @@ 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:
+            flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV;
         case VIR_NODE_DEV_CAP_LAST:
             break;
         }
-- 
2.12.2

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