Skip to content

Commit 6b93b02

Browse files
committed
mdadm: load md_mod first
Load md_mod first before setting module parameter legacy_async_del_gendisk Everything works well if md_mod is built in kernel. If not, create and assemble will fail. Signed-off-by: Xiao Ni <xni@redhat.com>
1 parent 8f0c769 commit 6b93b02

3 files changed

Lines changed: 40 additions & 27 deletions

File tree

mdadm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ extern int restore_stripes(int *dest, unsigned long long *offsets,
860860
unsigned long long start, unsigned long long length,
861861
char *src_buf);
862862
extern bool sysfs_is_libata_allow_tpm_enabled(const int verbose);
863-
extern bool init_md_mod_param(void);
863+
extern bool init_md_mod(void);
864864

865865
#ifndef Sendmail
866866
#define Sendmail "/usr/lib/sendmail -t"

mdopen.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,15 @@ int create_named_array(char *devnm)
3838
};
3939

4040
fd = open(new_array_file, O_WRONLY);
41-
if (fd < 0 && errno == ENOENT) {
42-
char buf[PATH_MAX] = {0};
43-
char *env_ptr;
44-
45-
env_ptr = getenv("PATH");
46-
/*
47-
* When called by udev worker context, path of modprobe
48-
* might not be in env PATH. Set sbin paths into PATH
49-
* env to avoid potential failure when run modprobe here.
50-
*/
51-
if (env_ptr)
52-
snprintf(buf, PATH_MAX - 1, "%s:%s", env_ptr,
53-
"/sbin:/usr/sbin:/usr/local/sbin");
54-
else
55-
snprintf(buf, PATH_MAX - 1, "%s",
56-
"/sbin:/usr/sbin:/usr/local/sbin");
57-
58-
setenv("PATH", buf, 1);
59-
60-
if (system("modprobe md_mod") == 0)
61-
fd = open(new_array_file, O_WRONLY);
62-
}
6341
if (fd >= 0) {
6442
n = write(fd, devnm, strlen(devnm));
6543
close(fd);
44+
} else {
45+
pr_err("Fail to open %s\n", new_array_file);
46+
return 0;
6647
}
67-
if (fd < 0 || n != (int)strlen(devnm)) {
48+
49+
if (n != (int)strlen(devnm)) {
6850
pr_err("Fail to create %s when using %s, fallback to creation via node\n",
6951
devnm, new_array_file);
7052
return 0;
@@ -148,7 +130,7 @@ int create_mddev(char *dev, char *name, int trustworthy,
148130
char devnm[32];
149131
char cbuf[400];
150132

151-
if (!init_md_mod_param()) {
133+
if (!init_md_mod()) {
152134
pr_err("init md module parameters fail\n");
153135
return -1;
154136
}

util.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,10 +2583,41 @@ bool set_md_mod_parameter(const char *name, const char *value)
25832583
return ret;
25842584
}
25852585

2586-
/* Init kernel md_mod parameters here if needed */
2587-
bool init_md_mod_param(void)
2586+
/* Init kernel md_mod and parameters here if needed */
2587+
bool init_md_mod(void)
25882588
{
25892589
bool ret = true;
2590+
char module_path[32];
2591+
FILE *fp;
2592+
2593+
snprintf(module_path, sizeof(module_path), "/sys/module/md_mod");
2594+
fp = fopen(module_path, "r");
2595+
if (fp == NULL) {
2596+
2597+
char buf[PATH_MAX] = {0};
2598+
char *env_ptr;
2599+
2600+
env_ptr = getenv("PATH");
2601+
/*
2602+
* When called by udev worker context, path of modprobe
2603+
* might not be in env PATH. Set sbin paths into PATH
2604+
* env to avoid potential failure when run modprobe here.
2605+
*/
2606+
if (env_ptr)
2607+
snprintf(buf, PATH_MAX - 1, "%s:%s", env_ptr,
2608+
"/sbin:/usr/sbin:/usr/local/sbin");
2609+
else
2610+
snprintf(buf, PATH_MAX - 1, "%s",
2611+
"/sbin:/usr/sbin:/usr/local/sbin");
2612+
2613+
setenv("PATH", buf, 1);
2614+
2615+
if (system("modprobe md_mod") != 0) {
2616+
pr_err("Can't load kernel module md_mod\n");
2617+
return false;
2618+
}
2619+
} else
2620+
fclose(fp);
25902621

25912622
/*
25922623
* In kernel 9e59d609763f calls del_gendisk in sync way. So device

0 commit comments

Comments
 (0)