Skip to content

Commit 035641b

Browse files
jacmetMike Snitzer
authored andcommitted
dm init: add dm-mod.waitfor to wait for asynchronously probed block devices
Just calling wait_for_device_probe() is not enough to ensure that asynchronously probed block devices are available (E.G. mmc, usb), so add a "dm-mod.waitfor=<device1>[,..,<deviceN>]" parameter to get dm-init to explicitly wait for specific block devices before initializing the tables with logic similar to the rootwait logic that was introduced with commit cc1ed75 ("init: wait for asynchronously scanned block devices"). E.G. with dm-verity on mmc using: dm-mod.waitfor="PARTLABEL=hash-a,PARTLABEL=root-a" [ 0.671671] device-mapper: init: waiting for all devices to be available before creating mapped devices [ 0.671679] device-mapper: init: waiting for device PARTLABEL=hash-a ... [ 0.710695] mmc0: new HS200 MMC card at address 0001 [ 0.711158] mmcblk0: mmc0:0001 004GA0 3.69 GiB [ 0.715954] mmcblk0boot0: mmc0:0001 004GA0 partition 1 2.00 MiB [ 0.722085] mmcblk0boot1: mmc0:0001 004GA0 partition 2 2.00 MiB [ 0.728093] mmcblk0rpmb: mmc0:0001 004GA0 partition 3 512 KiB, chardev (249:0) [ 0.738274] mmcblk0: p1 p2 p3 p4 p5 p6 p7 [ 0.751282] device-mapper: init: waiting for device PARTLABEL=root-a ... [ 0.751306] device-mapper: init: all devices available [ 0.751683] device-mapper: verity: sha256 using implementation "sha256-generic" [ 0.759344] device-mapper: ioctl: dm-0 (vroot) is ready [ 0.766540] VFS: Mounted root (squashfs filesystem) readonly on device 254:0. Signed-off-by: Peter Korsgaard <[email protected]> Signed-off-by: Mike Snitzer <[email protected]>
1 parent b52c3de commit 035641b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Documentation/admin-guide/device-mapper/dm-init.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,11 @@ Other examples (per target):
123123
0 1638400 verity 1 8:1 8:2 4096 4096 204800 1 sha256
124124
fb1a5a0f00deb908d8b53cb270858975e76cf64105d412ce764225d53b8f3cfd
125125
51934789604d1b92399c52e7cb149d1b3a1b74bbbcb103b2a0aaacbed5c08584
126+
127+
For setups using device-mapper on top of asynchronously probed block
128+
devices (MMC, USB, ..), it may be necessary to tell dm-init to
129+
explicitly wait for them to become available before setting up the
130+
device-mapper tables. This can be done with the "dm-mod.waitfor="
131+
module parameter, which takes a list of devices to wait for::
132+
133+
dm-mod.waitfor=<device1>[,..,<deviceN>]

drivers/md/dm-init.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include <linux/ctype.h>
11+
#include <linux/delay.h>
1112
#include <linux/device.h>
1213
#include <linux/device-mapper.h>
1314
#include <linux/init.h>
@@ -18,12 +19,17 @@
1819
#define DM_MAX_DEVICES 256
1920
#define DM_MAX_TARGETS 256
2021
#define DM_MAX_STR_SIZE 4096
22+
#define DM_MAX_WAITFOR 256
2123

2224
static char *create;
2325

26+
static char *waitfor[DM_MAX_WAITFOR];
27+
2428
/*
2529
* Format: dm-mod.create=<name>,<uuid>,<minor>,<flags>,<table>[,<table>+][;<name>,<uuid>,<minor>,<flags>,<table>[,<table>+]+]
2630
* Table format: <start_sector> <num_sectors> <target_type> <target_args>
31+
* Block devices to wait for to become available before setting up tables:
32+
* dm-mod.waitfor=<device1>[,..,<deviceN>]
2733
*
2834
* See Documentation/admin-guide/device-mapper/dm-init.rst for dm-mod.create="..." format
2935
* details.
@@ -266,7 +272,7 @@ static int __init dm_init_init(void)
266272
struct dm_device *dev;
267273
LIST_HEAD(devices);
268274
char *str;
269-
int r;
275+
int i, r;
270276

271277
if (!create)
272278
return 0;
@@ -286,6 +292,17 @@ static int __init dm_init_init(void)
286292
DMINFO("waiting for all devices to be available before creating mapped devices");
287293
wait_for_device_probe();
288294

295+
for (i = 0; i < ARRAY_SIZE(waitfor); i++) {
296+
if (waitfor[i]) {
297+
DMINFO("waiting for device %s ...", waitfor[i]);
298+
while (!dm_get_dev_t(waitfor[i]))
299+
msleep(5);
300+
}
301+
}
302+
303+
if (waitfor[0])
304+
DMINFO("all devices available");
305+
289306
list_for_each_entry(dev, &devices, list) {
290307
if (dm_early_create(&dev->dmi, dev->table,
291308
dev->target_args_array))
@@ -301,3 +318,6 @@ late_initcall(dm_init_init);
301318

302319
module_param(create, charp, 0);
303320
MODULE_PARM_DESC(create, "Create a mapped device in early boot");
321+
322+
module_param_array(waitfor, charp, NULL, 0);
323+
MODULE_PARM_DESC(waitfor, "Devices to wait for before setting up tables");

0 commit comments

Comments
 (0)