From: NeilBrown <neilb@suse.com>
To: Zhilong Liu <zlliu@suse.com>,
"jes.sorensen@gmail.com" <jes.sorensen@gmail.com>
Cc: Linux Raid <linux-raid@vger.kernel.org>
Subject: Re: [mdadm PATCH] mdopen: call "modprobe md_mod" if it might be needed.
Date: Mon, 16 Oct 2017 09:41:28 +1100 [thread overview]
Message-ID: <87d15okp9j.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <4bfc741e-c9e6-1645-fc2b-f90da1c7cc20@suse.com>
[-- Attachment #1: Type: text/plain, Size: 4294 bytes --]
On Fri, Oct 13 2017, Zhilong Liu wrote:
> On 10/12/2017 04:48 PM, NeilBrown wrote:
>>> On 10/12/2017 08:06 AM, NeilBrown wrote:
>> I wouldn't worry too much about checkpatch.pl.
>> It is worth looking at what it reports, but if you don't agree or the
>> maintainer doesn't agree, then feel free to ignore it.
>>
>>
>>> Is this changing ok to you?
>>>
>>> diff --git a/mdopen.c b/mdopen.c
>>> index dcdc6f2..da8d9d1 100644
>>> --- a/mdopen.c
>>> +++ b/mdopen.c
>>> @@ -26,6 +26,8 @@
>>> #include "md_p.h"
>>> #include <ctype.h>
>>>
>>> +#define NEW_ARRAY_FILE "/sys/module/md_mod/parameters/new_array"
>>> +
>> Splitting this out into a separate string does make sense.
>> However I would use
>> static const char new_array_file[] = ....;
>> rather than #define.
>
> Maybe "const char *" is enough for this long string? Because this file
> only used when
> creating named array, not global using.
I would still suggest "const char new_array_file[] = " because you
don't need a variable to hold a pointer to the string, you just need the
string.
But if you want to make it static inside the function, rather then
static outside the function, I see no problem with that.
NeilBrown
>
>> I hadn't noticed that there are two places where we write to new_array.
>> Maybe that should be split out into a function.
>> Both should use modprobe if the open fails.
>
> how about this changing? Thanks for your patience to have a look at it.
>
>
> diff --git a/mdopen.c b/mdopen.c
> index dcdc6f2..6d8402d 100644
> --- a/mdopen.c
> +++ b/mdopen.c
> @@ -100,6 +100,29 @@ void make_parts(char *dev, int cnt)
> free(name);
> }
>
> +int create_named_array(char *devnm)
> +{
> + const char *file = "/sys/module/md_mod/parameters/new_array";
> + int fd;
> + int n = -1;
> +
> + fd = open(file, O_WRONLY);
> + if (fd < 0 && errno == ENOENT) {
> + if (system("modprobe md_mod") == 0)
> + fd = open(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, 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 +329,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();
> }
>
> Thanks,
> -Zhilong
>
>> Thanks,
>> NeilBrown
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
next prev parent reply other threads:[~2017-10-15 22:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-25 5:52 [mdadm PATCH] mdopen: call "modprobe md_mod" if it might be needed NeilBrown
2017-09-25 15:26 ` John Stoffel
2017-09-25 23:50 ` NeilBrown
2017-09-26 15:11 ` Jes Sorensen
2017-09-26 19:12 ` Wols Lists
2017-09-26 20:55 ` John Stoffel
2017-09-27 21:30 ` Jes Sorensen
[not found] ` <cba5f77f-d6de-7a6b-35b0-70b7c56eb3f7@suse.com>
2017-10-10 20:16 ` NeilBrown
2017-10-11 7:39 ` Zhilong Liu
2017-10-12 0:06 ` NeilBrown
2017-10-12 3:55 ` Zhilong Liu
2017-10-12 8:48 ` NeilBrown
2017-10-13 9:16 ` Zhilong Liu
2017-10-15 22:41 ` NeilBrown [this message]
2017-10-12 9:55 ` Wols Lists
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=87d15okp9j.fsf@notabene.neil.brown.name \
--to=neilb@suse.com \
--cc=jes.sorensen@gmail.com \
--cc=linux-raid@vger.kernel.org \
--cc=zlliu@suse.com \
/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).