From: "Daniel P. Berrange" <berrange(a)redhat.com>
The nodedev driver currently only detects harddisk, cdrom
and floppy devices. This adds support for SD cards, which
are common storage for ARM devices, eg the Google ChromeBook
<device>
<name>block_mmcblk0_0xb1c7c08b</name>
<parent>computer</parent>
<capability type='storage'>
<block>/dev/mmcblk0</block>
<drive_type>sd</drive_type>
<serial>0xb1c7c08b</serial>
<size>15758000128</size>
<logical_block_size>512</logical_block_size>
<num_blocks>30777344</num_blocks>
</capability>
</device>
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/node_device/node_device_udev.c | 41 ++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index cb11e5f..362a47f 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -952,6 +952,35 @@ static int udevProcessFloppy(struct udev_device *device,
return udevProcessRemoveableMedia(device, def, has_media);
}
+
+static int udevProcessSD(struct udev_device *device,
+ virNodeDeviceDefPtr def)
+{
+ union _virNodeDevCapData *data = &def->caps->data;
+ int ret = 0;
+
+ if (udevGetUint64SysfsAttr(device,
+ "size",
+ &data->storage.num_blocks) == PROPERTY_ERROR) {
+ goto out;
+ }
+
+ if (udevGetUint64SysfsAttr(device,
+ "queue/logical_block_size",
+ &data->storage.logical_block_size)
+ == PROPERTY_ERROR) {
+ goto out;
+ }
+
+ data->storage.size = data->storage.num_blocks *
+ data->storage.logical_block_size;
+
+out:
+ return ret;
+}
+
+
+
/* This function exists to deal with the case in which a driver does
* not provide a device type in the usual place, but udev told us it's
* a storage device, and we can make a good guess at what kind of
@@ -1056,6 +1085,13 @@ static int udevProcessStorage(struct udev_device *device,
data->storage.drive_type = strdup("floppy");
if (!data->storage.drive_type)
goto out;
+ } else if ((udevGetIntProperty(device, "ID_DRIVE_FLASH_SD",
+ &tmp_int, 0) == PROPERTY_FOUND) &&
+ (tmp_int == 1)) {
+
+ data->storage.drive_type = strdup("sd");
+ if (!data->storage.drive_type)
+ goto out;
} else {
/* If udev doesn't have it, perhaps we can guess it. */
@@ -1071,6 +1107,8 @@ static int udevProcessStorage(struct udev_device *device,
ret = udevProcessDisk(device, def);
} else if (STREQ(def->caps->data.storage.drive_type, "floppy")) {
ret = udevProcessFloppy(device, def);
+ } else if (STREQ(def->caps->data.storage.drive_type, "sd")) {
+ ret = udevProcessSD(device, def);
} else {
VIR_DEBUG("Unsupported storage type '%s'",
def->caps->data.storage.drive_type);
@@ -1082,6 +1120,7 @@ static int udevProcessStorage(struct udev_device *device,
}
out:
+ VIR_DEBUG("Storage ret=%d", ret);
return ret;
}
@@ -1338,6 +1377,8 @@ static int udevAddOneDevice(struct udev_device *device)
out:
if (ret != 0) {
+ VIR_DEBUG("Discarding device %d %p %s", ret, def,
+ def ? def->sysfs_path : "");
virNodeDeviceDefFree(def);
}
--
1.8.1.4