From: "Kusiak, Mateusz" <mateusz.kusiak@linux.intel.com>
To: Coly Li <colyli@suse.de>, Mateusz Kusiak <mateusz.kusiak@intel.com>
Cc: linux-raid@vger.kernel.org, jes@trained-monkey.org
Subject: Re: [PATCH 06/10] super1: refactor the code for enum
Date: Thu, 22 Sep 2022 13:21:58 +0200 [thread overview]
Message-ID: <0d8322fc-f457-ed65-811e-adc90b6a4970@linux.intel.com> (raw)
In-Reply-To: <79C06B27-C8DD-4E87-9C40-72160D26C641@suse.de>
On 14/09/2022 17:03, Coly Li wrote:
>
>
>> 2022年8月18日 22:56,Mateusz Kusiak <mateusz.kusiak@intel.com> 写道:
>>
>> It prepares update_super1 for change context->update to enum.
>> Change if else statements into switch.
>>
>> Signed-off-by: Mateusz Kusiak <mateusz.kusiak@intel.com>
>> ---
>> super1.c | 149 ++++++++++++++++++++++++++++++++-----------------------
>> 1 file changed, 87 insertions(+), 62 deletions(-)
>>
>> diff --git a/super1.c b/super1.c
>> index 71af860c..6c81c1b9 100644
>> --- a/super1.c
>> +++ b/super1.c
>> @@ -1212,30 +1212,53 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
>> int rv = 0;
>> struct mdp_superblock_1 *sb = st->sb;
>> bitmap_super_t *bms = (bitmap_super_t*)(((char*)sb) + MAX_SB_SIZE);
>> + enum update_opt update_enum = map_name(update_options, update);
>>
>> - if (strcmp(update, "homehost") == 0 &&
>> - homehost) {
>> - /* Note that 'homehost' is special as it is really
>> + if (update_enum == UOPT_HOMEHOST && homehost) {
>> + /*
>> + * Note that 'homehost' is special as it is really
>> * a "name" update.
>> */
>> char *c;
>> - update = "name";
>> + update_enum = UOPT_NAME;
>> c = strchr(sb->set_name, ':');
>> if (c)
>> - strncpy(info->name, c+1, 31 - (c-sb->set_name));
>> + snprintf(info->name, sizeof(info->name), "%s", c+1);
>> else
>> - strncpy(info->name, sb->set_name, 32);
>> - info->name[32] = 0;
>> + snprintf(info->name, sizeof(info->name), "%s", sb->set_name);
>> }
>>
>> - if (strcmp(update, "force-one")==0) {
>> + switch (update_enum) {
>> + case UOPT_NAME:
>> + if (!info->name[0])
>> + snprintf(info->name, sizeof(info->name), "%d", info->array.md_minor);
>> + memset(sb->set_name, 0, sizeof(sb->set_name));
>> + int namelen;
>> +
>
> The above variable ’namelen’ might be declared at beginning of this code block.
I'll fix this in v2.
>
>> + namelen = strnlen(homehost, MD_NAME_MAX) + 1 + strnlen(info->name, MD_NAME_MAX);
>> + if (homehost &&
>> + strchr(info->name, ':') == NULL &&
>> + namelen < MD_NAME_MAX) {
>> + strcpy(sb->set_name, homehost);
>> + strcat(sb->set_name, ":");
>> + strcat(sb->set_name, info->name);
>> + } else {
>> + namelen = min((int)strnlen(info->name, MD_NAME_MAX),
>> + (int)sizeof(sb->set_name) - 1);
>> + memcpy(sb->set_name, info->name, namelen);
>> + memset(&sb->set_name[namelen], '\0',
>> + sizeof(sb->set_name) - namelen);
>> + }
>> + break;
>>
> [snipped]
>> @@ -1569,32 +1589,37 @@ static int update_super1(struct supertype *st, struct mdinfo *info,
>> }
>> done:;
>> }
>> - } else if (strcmp(update, "_reshape_progress") == 0)
>> + break;
>> + case UOPT_SPEC__RESHAPE_PROGRESS:
>> sb->reshape_position = __cpu_to_le64(info->reshape_progress);
>> - else if (strcmp(update, "writemostly") == 0)
>> - sb->devflags |= WriteMostly1;
>> - else if (strcmp(update, "readwrite") == 0)
>> + break;
>> + case UOPT_SPEC_READWRITE:
>> sb->devflags &= ~WriteMostly1;
>> - else if (strcmp(update, "failfast") == 0)
>
> Writemostly-setting is removed here, is it on purpose ?
No, thanks for noticing! I'll add this in v2.
>
> [snip]
>
> Thanks.
>
> Coly Li
next prev parent reply other threads:[~2022-09-22 11:22 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-18 14:56 [PATCH 00/10] Block update-subarray and refactor context update Mateusz Kusiak
2022-08-18 14:56 ` [PATCH 01/10] mdadm: Add option validation for --update-subarray Mateusz Kusiak
2022-09-13 15:12 ` Coly Li
2022-09-22 11:21 ` Kusiak, Mateusz
2022-08-18 14:56 ` [PATCH 02/10] Fix --update-subarray on active volume Mateusz Kusiak
2022-09-14 15:02 ` Coly Li
2022-08-18 14:56 ` [PATCH 03/10] Add code specific update options to enum Mateusz Kusiak
2022-09-14 15:02 ` Coly Li
2022-08-18 14:56 ` [PATCH 04/10] super-ddf: Remove update_super_ddf Mateusz Kusiak
2022-09-14 15:03 ` Coly Li
2022-08-18 14:56 ` [PATCH 05/10] super0: refactor the code for enum Mateusz Kusiak
2022-09-14 15:03 ` Coly Li
2022-09-22 11:21 ` Kusiak, Mateusz
2022-09-22 18:20 ` Jes Sorensen
2022-08-18 14:56 ` [PATCH 06/10] super1: " Mateusz Kusiak
2022-09-14 15:03 ` Coly Li
2022-09-22 11:21 ` Kusiak, Mateusz [this message]
2022-12-28 14:29 ` Jes Sorensen
2022-08-18 14:56 ` [PATCH 07/10] super-intel: " Mateusz Kusiak
2022-09-14 15:03 ` Coly Li
2022-09-22 11:22 ` Kusiak, Mateusz
2022-08-18 14:56 ` [PATCH 08/10] Change update to enum in update_super and update_subarray Mateusz Kusiak
2022-09-03 5:57 ` Coly Li
2022-09-14 15:03 ` Coly Li
2022-09-22 11:22 ` Kusiak, Mateusz
2022-08-18 14:56 ` [PATCH 09/10] Manage&Incremental: code refactor, string to enum Mateusz Kusiak
2022-09-14 15:03 ` Coly Li
2022-08-18 14:56 ` [PATCH 10/10] Change char* to enum in context->update & refactor code Mateusz Kusiak
2022-09-14 15:03 ` Coly Li
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=0d8322fc-f457-ed65-811e-adc90b6a4970@linux.intel.com \
--to=mateusz.kusiak@linux.intel.com \
--cc=colyli@suse.de \
--cc=jes@trained-monkey.org \
--cc=linux-raid@vger.kernel.org \
--cc=mateusz.kusiak@intel.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).