discover: Fix dead code in udev_handle_cdrom_events()
[petitboot] / discover / udev.c
index 75393d51768cb9ab1782112a71c7c8d4f4cd4fdc..537ef10263fa11193f03057d0335de48910abc0a 100644 (file)
@@ -74,13 +74,21 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
                const char *name)
 {
        struct discover_device *ddev;
+       unsigned int i = 0;
        const char *typestr;
        const char *uuid;
        const char *path;
        const char *node;
        const char *prop;
        const char *type;
-       bool cdrom;
+       const char *devname;
+       const char *ignored_types[] = {
+               "linux_raid_member",
+               "swap",
+               "LVM2_member",
+               NULL,
+       };
+       bool cdrom, usb;
 
        typestr = udev_device_get_devtype(dev);
        if (!typestr) {
@@ -118,9 +126,9 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
 
        /* If our environment's udev can recognise them explictly skip any
         * device mapper devices we encounter */
-       const char *devname = udev_device_get_property_value(dev, "DM_NAME");
+       devname = udev_device_get_property_value(dev, "DM_NAME");
        if (devname) {
-               pb_log("SKIP: dm-device %s\n", devname);
+               pb_debug("SKIP: dm-device %s\n", devname);
                return 0;
        }
 
@@ -130,6 +138,14 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
                return 0;
        }
 
+       while (ignored_types[i]) {
+               if (!strncmp(type, ignored_types[i], strlen(ignored_types[i]))) {
+                       pb_log("SKIP: %s: ignore '%s' filesystem\n", name, type);
+                       return 0;
+               }
+               i++;
+       }
+
        /* We may see multipath devices; they'll have the same uuid as an
         * existing device, so only parse the first. */
        uuid = udev_device_get_property_value(dev, "ID_FS_UUID");
@@ -151,11 +167,19 @@ 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);
 
-       if (ddev->device->type == DEVICE_TYPE_DISK)
+       /* Create a snapshot for all disks, unless it is an assembled RAID array */
+       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);
 
        device_handler_discover(udev->handler, ddev);
@@ -221,13 +245,12 @@ static bool udev_handle_cdrom_events(struct pb_udev *udev,
                struct udev_device *dev, struct discover_device *ddev)
 {
        const char *node;
+       bool eject = false;
 
        node = udev_device_get_devnode(dev);
 
        /* handle CDROM eject requests */
        if (udev_device_get_property_value(dev, "DISK_EJECT_REQUEST")) {
-               bool eject = false;
-
                pb_debug("udev: eject request\n");
 
                /* If the device is mounted, cdrom_id's own eject request may
@@ -236,7 +259,6 @@ static bool udev_handle_cdrom_events(struct pb_udev *udev,
                if (ddev) {
                        eject = ddev->mounted;
                        udev_handle_dev_remove(udev, dev);
-                       return false;
                }
 
                if (eject)