[libvirt] [PATCH] Add support for SD cards in nodedev driver

2013-04-03 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@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
  nameblock_mmcblk0_0xb1c7c08b/name
  parentcomputer/parent
  capability type='storage'
block/dev/mmcblk0/block
drive_typesd/drive_type
serial0xb1c7c08b/serial
size15758000128/size
logical_block_size512/logical_block_size
num_blocks30777344/num_blocks
  /capability
/device

Signed-off-by: Daniel P. Berrange berra...@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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Add support for SD cards in nodedev driver

2013-04-03 Thread Eric Blake
On 04/03/2013 11:24 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@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
   nameblock_mmcblk0_0xb1c7c08b/name
   parentcomputer/parent
   capability type='storage'
 block/dev/mmcblk0/block
 drive_typesd/drive_type
 serial0xb1c7c08b/serial
 size15758000128/size
 logical_block_size512/logical_block_size
 num_blocks30777344/num_blocks
   /capability
 /device
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---
  src/node_device/node_device_udev.c | 41 
 ++
  1 file changed, 41 insertions(+)

ACK.  Potential nits below are not showstoppers, but you may want to
clean them up anyway...

 +
 +static int udevProcessSD(struct udev_device *device,
 + virNodeDeviceDefPtr def)

Is it worth formatting this:

static int
udevProcessSD(...)

 +
  /* 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)) {

Spurious (), but it is copying existing style in this file.

 +
 +data-storage.drive_type = strdup(sd);

Another merge conflict with the VIR_STRDUP series :)

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list