mdopen: call "modprobe md_mod" if it might be needed.

Creating an array by opening a block-device with major number of 9
will transparently load the md module if needed.
Creating an array by opening
   /sys/module/md_mod/parameters/new_array
and writing to it won't, it will just fail if md_mod isn't loaded.

So when opening that file fails with ENOENT, run "modprobe md_mod" and
try again.

This fixes a bug whereby if you have "CREATE names=yes" in mdadm.conf,
and the md modules isn't loaded, then creating or assembling an
array will not honor the "names=yes" configuration.

Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
This commit is contained in:
NeilBrown 2017-09-25 15:52:19 +10:00 committed by Jes Sorensen
parent f12b31813e
commit fdbf7aaa19
1 changed files with 4 additions and 0 deletions

View File

@ -312,6 +312,10 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
if (block_udev)
udev_block(devnm);
fd = open("/sys/module/md_mod/parameters/new_array", O_WRONLY);
if (fd < 0 && errno == ENOENT) {
system("modprobe md_mod");
fd = open("/sys/module/md_mod/parameters/new_array", O_WRONLY);
}
if (fd >= 0) {
n = write(fd, devnm, strlen(devnm));
close(fd);