]> git.ozlabs.org Git - petitboot/commitdiff
discover: Use ID_FS_TYPE property for filesystem type detection
authorJeremy Kerr <jk@ozlabs.org>
Thu, 13 Mar 2014 02:07:12 +0000 (10:07 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Fri, 14 Mar 2014 07:14:47 +0000 (15:14 +0800)
Currently, we don't hand any -t option to mount, as we expect the mount
binary to do autodetection of the filesystem type for us.

Turns out this isn't great with busybox mount, (which we're likely to be
using in petitboot builds), which implements "autodetection" by trying
the mount() syscall with every fs type in /proc/filesystems, until one
succeeds.

We expect a lot of the mount calls to fail, as we currently try to mount
everything (and abort discovery on devices that don't mount), including
non-filesystem partitions. On a test machine with 560 block devices, and
37 entries in /proc/partitions, this results in around 20,000 calls to
mount().

A better way would be to pass a -t option to mount. It turns out that
udev uses libblkid to probe the filesystem type, which is available in
the ID_FS_TYPE property. This change only attempts to mount filesystems
with this property, and passes an explicit fstype to the mount binary.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/device-handler.c
discover/udev.c

index 80187ff49474a186cfb5b7e5bb7bceb0f4209404..9c8dea8f47a1bc55293f807c5ba6cfae52652e7e 100644 (file)
@@ -806,6 +806,7 @@ static bool check_existing_mount(struct discover_device *dev)
 
 static int mount_device(struct discover_device *dev)
 {
+       const char *fstype;
        int rc;
 
        if (!dev->device_path)
@@ -817,6 +818,10 @@ static int mount_device(struct discover_device *dev)
        if (check_existing_mount(dev))
                return 0;
 
+       fstype = discover_device_get_param(dev, "ID_FS_TYPE");
+       if (!fstype)
+               return 0;
+
        dev->mount_path = join_paths(dev, mount_base(),
                                        dev->device_path);
 
@@ -828,7 +833,7 @@ static int mount_device(struct discover_device *dev)
 
        rc = process_run_simple(dev, pb_system_apps.mount,
                        dev->device_path, dev->mount_path,
-                       "-o", "ro", NULL);
+                       "-t", fstype, "-o", "ro", NULL);
        if (!rc) {
                dev->mounted = true;
                dev->mounted_rw = false;
index 0b2ec2fd905d3da2bad341a26653c738f68da2a8..7a99eeaf9d772433c4e7f507a4be2f5e7f5dfa06 100644 (file)
@@ -69,6 +69,7 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
        const char *path;
        const char *node;
        const char *prop;
+       const char *type;
        bool cdrom;
 
        typestr = udev_device_get_devtype(dev);
@@ -101,6 +102,11 @@ static int udev_handle_block_add(struct pb_udev *udev, struct udev_device *dev,
                }
        }
 
+       type = udev_device_get_property_value(dev, "ID_FS_TYPE");
+       if (!type) {
+               pb_debug("SKIP: %s: no ID_FS_TYPE property\n", name);
+               return 0;
+       }
 
        /* We may see multipath devices; they'll have the same uuid as an
         * existing device, so only parse the first. */