[libvirt] [PATCH] nodedev: Add removable storage 'media_label' prop

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

 



Provides the CDROM label for current media. Only implemented for the udev
backend.

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 docs/schemas/nodedev.rng                   |    5 +++++
 src/conf/node_device_conf.c                |    8 ++++++++
 src/conf/node_device_conf.h                |    1 +
 src/node_device/node_device_udev.c         |    5 +++++
 tests/nodedevschemadata/DVD_with_media.xml |   16 ++++++++++++++++
 tests/nodedevxml2xmltest.c                 |    1 +
 6 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 tests/nodedevschemadata/DVD_with_media.xml

diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng
index 7060274..797b1af 100644
--- a/docs/schemas/nodedev.rng
+++ b/docs/schemas/nodedev.rng
@@ -314,6 +314,11 @@
       <element name='media_size'>
 	<ref name='uint'/>
       </element>
+      <optional>
+        <element name='media_label'>
+          <text/>
+        </element>
+      </optional>
     </element>
   </define>
 
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 6003ab1..a0d256c 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -422,6 +422,11 @@ char *virNodeDeviceDefFormat(virConnectPtr conn,
                                   "</media_available>\n", avl ? 1 : 0);
                 virBufferVSprintf(&buf, "      <media_size>%llu</media_size>\n",
                                   data->storage.removable_media_size);
+                if (data->storage.media_label)
+                    virBufferVSprintf(&buf,
+                                      "      <media_label>%s</media_label>\n",
+                                      data->storage.media_label);
+
                 if (data->storage.logical_block_size > 0)
                     virBufferVSprintf(&buf, "      <logical_block_size>%llu"
                                       "</logical_block_size>\n",
@@ -575,6 +580,8 @@ virNodeDevCapStorageParseXML(virConnectPtr conn,
             if (virXPathBoolean(conn, "count(./media_available[. = '1']) > 0", ctxt))
                 data->storage.flags |= VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE;
 
+            data->storage.media_label = virXPathString(conn, "string(./media_label[1])", ctxt);
+
             val = 0;
             if (virNodeDevCapsDefParseULongLong(conn, "number(./media_size[1])", ctxt, &val, def,
                                                 _("no removable media size supplied for '%s'"),
@@ -1431,6 +1438,7 @@ void virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
         VIR_FREE(data->storage.model);
         VIR_FREE(data->storage.vendor);
         VIR_FREE(data->storage.serial);
+        VIR_FREE(data->storage.media_label);
         break;
     case VIR_NODE_DEV_CAP_LAST:
         /* This case is here to shutup the compiler */
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index 7a20bd6..e409a76 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -154,6 +154,7 @@ struct _virNodeDevCapsDef {
             char *model;
             char *vendor;
             char *serial;
+            char *media_label;
             unsigned flags;	/* virNodeDevStorageCapFlags bits */
         } storage;
     } data;
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 9b48052..c78643e 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -867,6 +867,11 @@ static int udevProcessCDROM(struct udev_device *device,
         def->caps->data.storage.flags |=
             VIR_NODE_DEV_CAP_STORAGE_REMOVABLE_MEDIA_AVAILABLE;
 
+        if (udevGetStringProperty(device, "ID_FS_LABEL",
+                                  &data->storage.media_label) == PROPERTY_ERROR) {
+            goto out;
+        }
+
         if (udevGetUint64SysfsAttr(device,
                                    "size",
                                    &data->storage.num_blocks) == PROPERTY_ERROR) {
diff --git a/tests/nodedevschemadata/DVD_with_media.xml b/tests/nodedevschemadata/DVD_with_media.xml
new file mode 100644
index 0000000..673e88f
--- /dev/null
+++ b/tests/nodedevschemadata/DVD_with_media.xml
@@ -0,0 +1,16 @@
+<device>
+  <name>DVD_GCC_4247N</name>
+  <parent>pci_8086_27df_scsi_host_scsi_device_lun0</parent>
+  <capability type='storage'>
+    <block>/dev/sr0</block>
+    <bus>scsi</bus>
+    <drive_type>cdrom</drive_type>
+    <model>RW/DVD GCC-4247N</model>
+    <vendor>HL-DT-ST</vendor>
+    <capability type='removable'>
+      <media_available>1</media_available>
+      <media_size>12345678</media_size>
+      <media_label>Windows_XP_Label</media_label>
+    </capability>
+  </capability>
+</device>
diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c
index 7621212..bf8be7e 100644
--- a/tests/nodedevxml2xmltest.c
+++ b/tests/nodedevxml2xmltest.c
@@ -80,6 +80,7 @@ mymain(int argc, char **argv)
 
     DO_TEST("computer");
     DO_TEST("DVD_GCC_4247N");
+    DO_TEST("DVD_with_media");
     DO_TEST("net_00_13_02_b9_f9_d3");
     DO_TEST("net_00_15_58_2f_e9_55");
     DO_TEST("pci_1002_71c4");
-- 
1.6.5.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]