Recognise storage devices on USB bus
authorSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Fri, 21 Aug 2015 05:18:48 +0000 (15:18 +1000)
committerSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Mon, 31 Aug 2015 04:58:14 +0000 (14:58 +1000)
Users may want to prioritise USB-attached storage devices differently to
other devices. Detect if a device is USB-attached and add a new device
type to identify it.

Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
discover/device-handler.c
discover/udev.c
lib/types/types.c
lib/types/types.h
ui/ncurses/nc-config.c
ui/ncurses/nc-menu.c
ui/test/discover-test.c

index 4f7a7b7500c4fee446747df10861095d30b2ce33..9246f0dd865ea3218f6bb5d6869553a64295e1ba 100644 (file)
@@ -457,6 +457,7 @@ struct {
 } device_type_map[] = {
        { IPMI_BOOTDEV_NETWORK, DEVICE_TYPE_NETWORK },
        { IPMI_BOOTDEV_DISK, DEVICE_TYPE_DISK },
+       { IPMI_BOOTDEV_DISK, DEVICE_TYPE_USB },
        { IPMI_BOOTDEV_CDROM, DEVICE_TYPE_OPTICAL },
 };
 
index 87a3748fe2f622749e3b65151d25d89b679db293..6cc718ea4614f9da6e7110fd9901144c5f37fb7c 100644 (file)
@@ -88,7 +88,7 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
                "LVM2_member",
                NULL,
        };
-       bool cdrom;
+       bool cdrom, usb;
 
        typestr = udev_device_get_devtype(dev);
        if (!typestr) {
@@ -167,12 +167,18 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
        prop = udev_device_get_property_value(dev, "ID_FS_LABEL");
        if (prop)
                ddev->label = talloc_strdup(ddev, prop);
-       ddev->device->type = cdrom ? DEVICE_TYPE_OPTICAL : DEVICE_TYPE_DISK;
+
+       usb = !!udev_device_get_property_value(dev, "ID_USB_DRIVER");
+       if (cdrom)
+               ddev->device->type = DEVICE_TYPE_OPTICAL;
+       else
+               ddev->device->type = usb ? DEVICE_TYPE_USB : DEVICE_TYPE_DISK;
 
        udev_setup_device_params(dev, ddev);
 
        /* Create a snapshot for all disks, unless it is an assembled RAID array */
-       if (ddev->device->type == DEVICE_TYPE_DISK &&
+       if ((ddev->device->type == DEVICE_TYPE_DISK ||
+            ddev->device->type == DEVICE_TYPE_USB) &&
            !udev_device_get_property_value(dev, "MD_LEVEL"))
                devmapper_init_snapshot(udev->handler, ddev);
 
index 95a3a48cb4fca9571fa9a6eac54449b9c2378c2e..611f2a1018dba2f772b90ad245508339aa07dc53 100644 (file)
@@ -27,6 +27,8 @@ const char *device_type_display_name(enum device_type type)
        switch (type) {
        case DEVICE_TYPE_DISK:
                return _("Disk");
+       case DEVICE_TYPE_USB:
+               return _("USB");
        case DEVICE_TYPE_OPTICAL:
                return _("Optical");
        case DEVICE_TYPE_NETWORK:
@@ -44,6 +46,8 @@ const char *device_type_name(enum device_type type)
        switch (type) {
        case DEVICE_TYPE_DISK:
                return "disk";
+       case DEVICE_TYPE_USB:
+               return "usb";
        case DEVICE_TYPE_OPTICAL:
                return "optical";
        case DEVICE_TYPE_NETWORK:
@@ -60,6 +64,8 @@ enum device_type find_device_type(const char *str)
 {
        if (!strncmp(str, "disk", strlen("disk")))
                return DEVICE_TYPE_DISK;
+       if (!strncmp(str, "usb", strlen("usb")))
+               return DEVICE_TYPE_USB;
        if (!strncmp(str, "optical", strlen("optical")))
                return DEVICE_TYPE_OPTICAL;
        if (!strncmp(str, "network", strlen("network")))
index 0415206bcb95a657cda3cb6476799ccee6b61baa..6a2c25810fff5c80a07ad2f11af44924b225f469 100644 (file)
@@ -8,6 +8,7 @@
 enum device_type {
        DEVICE_TYPE_NETWORK,
        DEVICE_TYPE_DISK,
+       DEVICE_TYPE_USB,
        DEVICE_TYPE_OPTICAL,
        DEVICE_TYPE_ANY,
        DEVICE_TYPE_UNKNOWN,
index 6363bb9a0f7785b5a470573a356ce0a19e9ccc0e..f7c6b8c4b1cc11cfee9d975590906b4e55edeb19 100644 (file)
@@ -762,7 +762,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                widget_subset_add_option(screen->widgets.boot_order_f, label);
        }
 
-       for (i = DEVICE_TYPE_NETWORK; i < DEVICE_TYPE_NETWORK + 4; i++) {
+       for (i = DEVICE_TYPE_NETWORK; i < DEVICE_TYPE_UNKNOWN; i++) {
                char *label;
 
                if (i == DEVICE_TYPE_ANY)
index b8f9a35e0cddcd7ac16bbd330e73104ee8a0a3e4..b42dc23e556c5f2dc85081a2a1dcfb718671e8ab 100644 (file)
@@ -253,6 +253,7 @@ struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
        switch (dev->type) {
        case DEVICE_TYPE_OPTICAL:
        case DEVICE_TYPE_DISK:
+       case DEVICE_TYPE_USB:
                /* Find block info */
                for (i = 0; sys && i < sys->n_blockdevs; i++) {
                        bd = sys->blockdevs[i];
@@ -263,8 +264,9 @@ struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
                }
                if (matched) {
                        snprintf(buf,sizeof(buf),"[%s: %s / %s]",
-                               dev->type == DEVICE_TYPE_DISK ?
-                                       _("Disk") : _("CD/DVD"),
+                               dev->type == DEVICE_TYPE_OPTICAL ?
+                               _("CD/DVD") :
+                               device_type_display_name(dev->type),
                                bd->name, bd->uuid);
                }
                break;
index 363a28978f810561ddd00991c96683ce9edd9f9a..b099b59128b7bbec99f34845a708d89dc45ea9a7 100644 (file)
@@ -8,6 +8,8 @@ static const char *device_type_string(enum device_type type)
        switch (type) {
        case DEVICE_TYPE_DISK:
                return "disk";
+       case DEVICE_TYPE_USB:
+               return "usb";
        case DEVICE_TYPE_NETWORK:
                return "network";
        case DEVICE_TYPE_OPTICAL: