[PATCH v2 2/3] nodedev: Add capability bit to detect 'cdrom' devices

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

 



Add the capability to detect and list any/all cdrom devices

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 include/libvirt/libvirt-nodedev.h    |  1 +
 src/conf/node_device_conf.c          |  6 +++++-
 src/conf/node_device_conf.h          |  5 ++++-
 src/conf/virnodedeviceobj.c          | 21 ++++++++++++++++++---
 src/node_device/node_device_driver.c |  1 +
 src/node_device/node_device_udev.c   |  2 ++
 tools/virsh-nodedev.c                |  3 +++
 tools/virsh.pod                      |  2 +-
 8 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-nodedev.h
index 25e8724..140c8f2 100644
--- a/include/libvirt/libvirt-nodedev.h
+++ b/include/libvirt/libvirt-nodedev.h
@@ -82,6 +82,7 @@ typedef enum {
     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 */
     VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV       = 1 << 15, /* CCW device */
+    VIR_CONNECT_LIST_NODE_DEVICES_CAP_CDROM         = 1 << 16, /* CDROM capable device */
 } virConnectListAllNodeDeviceFlags;
 
 int                     virConnectListAllNodeDevices (virConnectPtr conn,
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index bf84fd2..54f36a3 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -63,7 +63,8 @@ VIR_ENUM_IMPL(virNodeDevCap, VIR_NODE_DEV_CAP_LAST,
               "drm",
               "mdev_types",
               "mdev",
-              "ccw")
+              "ccw",
+              "cdrom")
 
 VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST,
               "80203",
@@ -603,6 +604,7 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def)
         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_CDROM:
         case VIR_NODE_DEV_CAP_LAST:
             break;
         }
@@ -1895,6 +1897,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_CDROM:
     case VIR_NODE_DEV_CAP_LAST:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unknown capability type '%d' for '%s'"),
@@ -2223,6 +2226,7 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
     case VIR_NODE_DEV_CAP_FC_HOST:
     case VIR_NODE_DEV_CAP_VPORTS:
     case VIR_NODE_DEV_CAP_CCW_DEV:
+    case VIR_NODE_DEV_CAP_CDROM:
     case VIR_NODE_DEV_CAP_LAST:
         /* This case is here to shutup the compiler */
         break;
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index da56eaf..b5e1f16 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -67,6 +67,7 @@ typedef enum {
     VIR_NODE_DEV_CAP_MDEV_TYPES,        /* Device capable of mediated devices */
     VIR_NODE_DEV_CAP_MDEV,              /* Mediated device */
     VIR_NODE_DEV_CAP_CCW_DEV,           /* s390 CCW device */
+    VIR_NODE_DEV_CAP_CDROM,             /* CDROM capable device */
 
     VIR_NODE_DEV_CAP_LAST
 } virNodeDevCapType;
@@ -85,6 +86,7 @@ typedef enum {
     VIR_NODE_DEV_CAP_STORAGE_REMOVABLE			= (1 << 0),
     VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE	= (1 << 1),
     VIR_NODE_DEV_CAP_STORAGE_HOTPLUGGABLE		= (1 << 2),
+    VIR_NODE_DEV_CAP_STORAGE_CDROM                      = (1 << 3),
 } virNodeDevStorageCapFlags;
 
 typedef enum {
@@ -377,7 +379,8 @@ virNodeDevCapMdevTypeFree(virNodeDevCapMdevTypePtr type);
                  VIR_CONNECT_LIST_NODE_DEVICES_CAP_DRM           | \
                  VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV_TYPES    | \
                  VIR_CONNECT_LIST_NODE_DEVICES_CAP_MDEV          | \
-                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV)
+                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV       | \
+                 VIR_CONNECT_LIST_NODE_DEVICES_CAP_CDROM)
 
 char *
 virNodeDeviceGetParentName(virConnectPtr conn,
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index b0dcee1..e3e2078 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -131,6 +131,8 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj *obj,
         virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS);
     const char *mdev_types =
         virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_MDEV_TYPES);
+    const char *cdrom_types =
+        virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_CDROM);
 
     while (caps) {
         if (STREQ(cap, virNodeDevCapTypeToString(caps->data.type))) {
@@ -151,13 +153,18 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj *obj,
                     return 1;
                 break;
 
+            case VIR_NODE_DEV_CAP_STORAGE:
+                if ((STREQ(cap, cdrom_types) &&
+                     (caps->data.storage.flags & VIR_NODE_DEV_CAP_STORAGE_CDROM)))
+                    return 1;
+                break;
+
             case VIR_NODE_DEV_CAP_SYSTEM:
             case VIR_NODE_DEV_CAP_USB_DEV:
             case VIR_NODE_DEV_CAP_USB_INTERFACE:
             case VIR_NODE_DEV_CAP_NET:
             case VIR_NODE_DEV_CAP_SCSI_TARGET:
             case VIR_NODE_DEV_CAP_SCSI:
-            case VIR_NODE_DEV_CAP_STORAGE:
             case VIR_NODE_DEV_CAP_FC_HOST:
             case VIR_NODE_DEV_CAP_VPORTS:
             case VIR_NODE_DEV_CAP_SCSI_GENERIC:
@@ -165,6 +172,7 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj *obj,
             case VIR_NODE_DEV_CAP_MDEV_TYPES:
             case VIR_NODE_DEV_CAP_MDEV:
             case VIR_NODE_DEV_CAP_CCW_DEV:
+            case VIR_NODE_DEV_CAP_CDROM:
             case VIR_NODE_DEV_CAP_LAST:
                 break;
             }
@@ -707,13 +715,18 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr obj,
                 return true;
             break;
 
+        case VIR_NODE_DEV_CAP_STORAGE:
+            if (type == VIR_NODE_DEV_CAP_CDROM &&
+                (cap->data.storage.flags & VIR_NODE_DEV_CAP_STORAGE_CDROM))
+                return true;
+            break;
+
         case VIR_NODE_DEV_CAP_SYSTEM:
         case VIR_NODE_DEV_CAP_USB_DEV:
         case VIR_NODE_DEV_CAP_USB_INTERFACE:
         case VIR_NODE_DEV_CAP_NET:
         case VIR_NODE_DEV_CAP_SCSI_TARGET:
         case VIR_NODE_DEV_CAP_SCSI:
-        case VIR_NODE_DEV_CAP_STORAGE:
         case VIR_NODE_DEV_CAP_FC_HOST:
         case VIR_NODE_DEV_CAP_VPORTS:
         case VIR_NODE_DEV_CAP_SCSI_GENERIC:
@@ -721,6 +734,7 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr obj,
         case VIR_NODE_DEV_CAP_MDEV_TYPES:
         case VIR_NODE_DEV_CAP_MDEV:
         case VIR_NODE_DEV_CAP_CCW_DEV:
+        case VIR_NODE_DEV_CAP_CDROM:
         case VIR_NODE_DEV_CAP_LAST:
             break;
         }
@@ -867,7 +881,8 @@ virNodeDeviceMatch(virNodeDeviceObjPtr obj,
               MATCH(DRM)           ||
               MATCH(MDEV_TYPES)    ||
               MATCH(MDEV)          ||
-              MATCH(CCW_DEV)))
+              MATCH(CCW_DEV)       ||
+              MATCH(CDROM)))
             return false;
     }
 
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index facfeb6..adae917 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -90,6 +90,7 @@ nodeDeviceUpdateCaps(virNodeDeviceDefPtr def)
         case VIR_NODE_DEV_CAP_MDEV_TYPES:
         case VIR_NODE_DEV_CAP_MDEV:
         case VIR_NODE_DEV_CAP_CCW_DEV:
+        case VIR_NODE_DEV_CAP_CDROM:
         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 f417745..bebfec4 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -920,6 +920,7 @@ udevProcessCDROM(struct udev_device *device,
     VIR_FREE(def->caps->data.storage.drive_type);
     if (VIR_STRDUP(def->caps->data.storage.drive_type, "cdrom") < 0)
         return -1;
+    def->caps->data.storage.flags |= VIR_NODE_DEV_CAP_STORAGE_CDROM;
 
     if (udevHasDeviceProperty(device, "ID_CDROM_MEDIA") &&
         udevGetIntProperty(device, "ID_CDROM_MEDIA", &has_media, 0) < 0)
@@ -1303,6 +1304,7 @@ udevGetDeviceDetails(struct udev_device *device,
     case VIR_NODE_DEV_CAP_SYSTEM:
     case VIR_NODE_DEV_CAP_FC_HOST:
     case VIR_NODE_DEV_CAP_VPORTS:
+    case VIR_NODE_DEV_CAP_CDROM:
     case VIR_NODE_DEV_CAP_LAST:
         break;
     }
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index c7ef6bf..ba1592b 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -463,6 +463,9 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
         case VIR_NODE_DEV_CAP_CCW_DEV:
             flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_CCW_DEV;
             break;
+        case VIR_NODE_DEV_CAP_CDROM:
+            flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_CDROM;
+            break;
         case VIR_NODE_DEV_CAP_LAST:
             break;
         }
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 01453be..2ba7762 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -3243,7 +3243,7 @@ I<cap> is used to filter the list by capability types, the types must be
 separated by comma, e.g. --cap pci,scsi. Valid capability types include
 'system', 'pci', 'usb_device', 'usb', 'net', 'scsi_host', 'scsi_target',
 'scsi', 'storage', 'fc_host', 'vports', 'scsi_generic', 'drm', 'mdev',
-'mdev_types', 'ccw'.
+'mdev_types', 'ccw', 'cdrom'.
 If I<--tree> is used, the output is formatted in a tree representing parents of each
 node.  I<cap> and I<--tree> are mutually exclusive.
 
-- 
2.9.5

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