From: Zhilong Liu <zlliu@suse.com>
To: Jes.Sorensen@gmail.com
Cc: linux-raid@vger.kernel.org, Zhilong Liu <zlliu@suse.com>
Subject: [PATCH] mdadm/mdopen: create new function create_named_array for writing to new_array
Date: Mon, 16 Oct 2017 15:54:18 +0800 [thread overview]
Message-ID: <1508140458-16435-1-git-send-email-zlliu@suse.com> (raw)
Split 'write to new_array' out into a function named create_named_array.
And fixed a trivial compiling warning 'warn_unused_result' against commit:
fdbf7aaa1956 (mdopen: call "modprobe md_mod" if it might be needed.)
Suggested-by: NeilBrown <neilb@suse.com>
Signed-off-by: Zhilong Liu <zlliu@suse.com>
---
Discussed this issue with mail:
[mdadm PATCH] mdopen: call "modprobe md_mod" if it might be needed.
mdopen.c | 47 +++++++++++++++++++++++++++--------------------
1 file changed, 27 insertions(+), 20 deletions(-)
diff --git a/mdopen.c b/mdopen.c
index dcdc6f2..4ec13f5 100644
--- a/mdopen.c
+++ b/mdopen.c
@@ -100,6 +100,31 @@ void make_parts(char *dev, int cnt)
free(name);
}
+int create_named_array(char *devnm)
+{
+ int fd;
+ int n = -1;
+ static const char new_array_file[] = {
+ "/sys/module/md_mod/parameters/new_array"
+ };
+
+ fd = open(new_array_file, O_WRONLY);
+ if (fd < 0 && errno == ENOENT) {
+ if (system("modprobe md_mod") == 0)
+ fd = open(new_array_file, O_WRONLY);
+ }
+ if (fd >= 0) {
+ n = write(fd, devnm, strlen(devnm));
+ close(fd);
+ }
+ if (fd < 0 || n != (int)strlen(devnm)) {
+ pr_err("Fail create %s when using %s\n", devnm, new_array_file);
+ return 0;
+ }
+
+ return 1;
+}
+
/*
* We need a new md device to assemble/build/create an array.
* 'dev' is a name given us by the user (command line or mdadm.conf)
@@ -306,37 +331,19 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy,
devnm[0] = 0;
if (num < 0 && cname && ci->names) {
- int fd;
- int n = -1;
sprintf(devnm, "md_%s", cname);
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);
- }
- if (n < 0) {
+ if (!create_named_array(devnm)) {
devnm[0] = 0;
udev_unblock();
}
}
if (num >= 0) {
- int fd;
- int n = -1;
sprintf(devnm, "md%d", num);
if (block_udev)
udev_block(devnm);
- fd = open("/sys/module/md_mod/parameters/new_array", O_WRONLY);
- if (fd >= 0) {
- n = write(fd, devnm, strlen(devnm));
- close(fd);
- }
- if (n < 0) {
+ if (!create_named_array(devnm)) {
devnm[0] = 0;
udev_unblock();
}
--
2.6.6
next reply other threads:[~2017-10-16 7:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-16 7:54 Zhilong Liu [this message]
2017-11-01 21:23 ` [PATCH] mdadm/mdopen: create new function create_named_array for writing to new_array Jes Sorensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1508140458-16435-1-git-send-email-zlliu@suse.com \
--to=zlliu@suse.com \
--cc=Jes.Sorensen@gmail.com \
--cc=linux-raid@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).