From deae2bb57f1038d019124dca9c0101f839cd4a50 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 14 Dec 2009 14:58:23 +0100 Subject: [PATCH] nodedev: Add removable storage 'media_label' prop Provides the CDROM label for current media. Only implemented for the udev backend. --- 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(+) create mode 100644 tests/nodedevschemadata/DVD_with_media.xml diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 7060274295..797b1aff67 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -314,6 +314,11 @@ + + + + + diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 2a722744f9..4e8a492c8c 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -446,6 +446,11 @@ char *virNodeDeviceDefFormat(virConnectPtr conn, "\n", avl ? 1 : 0); virBufferVSprintf(&buf, " %llu\n", data->storage.removable_media_size); + if (data->storage.media_label) + virBufferEscapeString(&buf, + " %s\n", + data->storage.media_label); + if (data->storage.logical_block_size > 0) virBufferVSprintf(&buf, " %llu" "\n", @@ -598,6 +603,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'"), @@ -1459,6 +1466,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 4bfac90775..318fa3e03d 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -170,6 +170,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 cf23be11d5..422a713435 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -868,6 +868,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 0000000000..673e88fd0a --- /dev/null +++ b/tests/nodedevschemadata/DVD_with_media.xml @@ -0,0 +1,16 @@ + + DVD_GCC_4247N + pci_8086_27df_scsi_host_scsi_device_lun0 + + /dev/sr0 + scsi + cdrom + RW/DVD GCC-4247N + HL-DT-ST + + 1 + 12345678 + Windows_XP_Label + + + diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index 7621212791..bf8be7e5ca 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");