Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mdadm.h
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ extern int restore_stripes(int *dest, unsigned long long *offsets,
unsigned long long start, unsigned long long length,
char *src_buf);
extern bool sysfs_is_libata_allow_tpm_enabled(const int verbose);
extern bool init_md_mod_param(void);
extern bool init_md_mod(void);

#ifndef Sendmail
#define Sendmail "/usr/lib/sendmail -t"
Expand Down
30 changes: 6 additions & 24 deletions mdopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,15 @@ int create_named_array(char *devnm)
};

fd = open(new_array_file, O_WRONLY);
if (fd < 0 && errno == ENOENT) {
char buf[PATH_MAX] = {0};
char *env_ptr;

env_ptr = getenv("PATH");
/*
* When called by udev worker context, path of modprobe
* might not be in env PATH. Set sbin paths into PATH
* env to avoid potential failure when run modprobe here.
*/
if (env_ptr)
snprintf(buf, PATH_MAX - 1, "%s:%s", env_ptr,
"/sbin:/usr/sbin:/usr/local/sbin");
else
snprintf(buf, PATH_MAX - 1, "%s",
"/sbin:/usr/sbin:/usr/local/sbin");

setenv("PATH", buf, 1);

if (system("modprobe md_mod") == 0)
fd = open(new_array_file, O_WRONLY);
}
if (fd >= 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!is_fd_valid(fd)){
	pr_err("Fail to open %s\n", new_array_file);
	return 0;
}

n = write(fd, devnm, strlen(devnm));
close(fd);

if (n != (int)strlen(devnm)) {

Looks like simpler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!is_fd_valid(fd)){
	pr_err("Fail to open %s\n", new_array_file);
	return 0;
}

n = write(fd, devnm, strlen(devnm));
close(fd);

if (n != (int)strlen(devnm)) {

Looks like simpler.

Hi Mariusz

The codes mentioned above don't have relationship with this problem, right? You mean this part can be improved in this way, right?

n = write(fd, devnm, strlen(devnm));
close(fd);
} else {
pr_err("Fail to open %s\n", new_array_file);
return 0;
}
if (fd < 0 || n != (int)strlen(devnm)) {

if (n != (int)strlen(devnm)) {
pr_err("Fail to create %s when using %s, fallback to creation via node\n",
devnm, new_array_file);
return 0;
Expand Down Expand Up @@ -148,7 +130,7 @@ int create_mddev(char *dev, char *name, int trustworthy,
char devnm[32];
char cbuf[400];

if (!init_md_mod_param()) {
if (!init_md_mod()) {
pr_err("init md module parameters fail\n");
return -1;
}
Expand Down
35 changes: 33 additions & 2 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2583,10 +2583,41 @@ bool set_md_mod_parameter(const char *name, const char *value)
return ret;
}

/* Init kernel md_mod parameters here if needed */
bool init_md_mod_param(void)
/* Init kernel md_mod and parameters here if needed */
bool init_md_mod(void)
{
bool ret = true;
char module_path[32];
FILE *fp;

snprintf(module_path, sizeof(module_path), "/sys/module/md_mod");
fp = fopen(module_path, "r");
if (fp == NULL) {

char buf[PATH_MAX] = {0};
char *env_ptr;

env_ptr = getenv("PATH");
/*
* When called by udev worker context, path of modprobe
* might not be in env PATH. Set sbin paths into PATH
* env to avoid potential failure when run modprobe here.
*/
if (env_ptr)
snprintf(buf, PATH_MAX - 1, "%s:%s", env_ptr,
"/sbin:/usr/sbin:/usr/local/sbin");
else
snprintf(buf, PATH_MAX - 1, "%s",
"/sbin:/usr/sbin:/usr/local/sbin");

setenv("PATH", buf, 1);

if (system("modprobe md_mod") != 0) {
pr_err("Can't load kernel module md_mod\n");
return false;
}
} else
fclose(fp);

/*
* In kernel 9e59d609763f calls del_gendisk in sync way. So device
Expand Down