dm init: add dm-mod.waitfor to wait for asynchronously probed block devices
[platform/kernel/linux-rpi.git] / drivers / md / dm-init.c
index b0c45c6..dc4381d 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <linux/ctype.h>
+#include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/device-mapper.h>
 #include <linux/init.h>
 #define DM_MAX_DEVICES 256
 #define DM_MAX_TARGETS 256
 #define DM_MAX_STR_SIZE 4096
+#define DM_MAX_WAITFOR 256
 
 static char *create;
 
+static char *waitfor[DM_MAX_WAITFOR];
+
 /*
  * Format: dm-mod.create=<name>,<uuid>,<minor>,<flags>,<table>[,<table>+][;<name>,<uuid>,<minor>,<flags>,<table>[,<table>+]+]
  * Table format: <start_sector> <num_sectors> <target_type> <target_args>
+ * Block devices to wait for to become available before setting up tables:
+ * dm-mod.waitfor=<device1>[,..,<deviceN>]
  *
  * See Documentation/admin-guide/device-mapper/dm-init.rst for dm-mod.create="..." format
  * details.
@@ -266,7 +272,7 @@ static int __init dm_init_init(void)
        struct dm_device *dev;
        LIST_HEAD(devices);
        char *str;
-       int r;
+       int i, r;
 
        if (!create)
                return 0;
@@ -286,6 +292,17 @@ static int __init dm_init_init(void)
        DMINFO("waiting for all devices to be available before creating mapped devices");
        wait_for_device_probe();
 
+       for (i = 0; i < ARRAY_SIZE(waitfor); i++) {
+               if (waitfor[i]) {
+                       DMINFO("waiting for device %s ...", waitfor[i]);
+                       while (!dm_get_dev_t(waitfor[i]))
+                               msleep(5);
+               }
+       }
+
+       if (waitfor[0])
+               DMINFO("all devices available");
+
        list_for_each_entry(dev, &devices, list) {
                if (dm_early_create(&dev->dmi, dev->table,
                                    dev->target_args_array))
@@ -301,3 +318,6 @@ late_initcall(dm_init_init);
 
 module_param(create, charp, 0);
 MODULE_PARM_DESC(create, "Create a mapped device in early boot");
+
+module_param_array(waitfor, charp, NULL, 0);
+MODULE_PARM_DESC(waitfor, "Devices to wait for before setting up tables");