From: NeilBrown <neilb@suse.com>
To: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"Shaohua Li" <shli@kernel.org>
Cc: linux-raid@vger.kernel.org
Subject: Re: [PATCH] md: allow changing set_name of running array
Date: Fri, 01 Sep 2017 10:07:29 +1000 [thread overview]
Message-ID: <87tw0ne0xq.fsf@notabene.neil.brown.name> (raw)
In-Reply-To: <429c2b1c84c44b0c09ea7aa8dfa86846885441f7.1504044125.git.mirq-linux@rere.qmqm.pl>
[-- Attachment #1: Type: text/plain, Size: 3606 bytes --]
On Wed, Aug 30 2017, Michał Mirosław wrote:
> Allow changing active array's set_name. This is the only way to
> safely update superblock on an array which carries a mounted fs.
Do you really need to change the set_name of an active array?
The name is only used when the array is actived, so wait until the next
time the array is stopped, and change the name then.
You can boot with a rescue CD or similar and use "--assemble
--update=name", or with a bit of effort you could get the normal boot
sequence to change the name.
I wouldn't object to adding something to mdadm so that it would read
something from mdadm.conf, and update the set name at boot time.
What is the underlying problem that you are trying to solve here?
Thanks,
NeilBrown
>
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
> drivers/md/md.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 79 insertions(+)
>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index caca5d689cdc..59aa10669bef 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -5051,6 +5051,84 @@ static struct md_sysfs_entry md_consistency_policy =
> __ATTR(consistency_policy, S_IRUGO | S_IWUSR, consistency_policy_show,
> consistency_policy_store);
>
> +static ssize_t
> +set_name_show(struct mddev *mddev, char *page)
> +{
> + struct mdp_superblock_1 *sb;
> + struct md_rdev *rdev;
> + int err;
> +
> + err = mddev_lock(mddev);
> + if (err)
> + return err;
> +
> + /* only version-1 superblocks carry a MD set's name */
> + err = -ENXIO;
> + if (mddev->major_version != 1)
> + goto out_unlock;
> +
> + err = -EINVAL;
> + rdev_for_each(rdev, mddev) {
> + if (WARN_ON(!rdev->sb_loaded))
> + continue;
> +
> + sb = page_address(rdev->sb_page);
> + err = sprintf(page, "%.32s\n", sb->set_name);
> + break;
> + }
> +
> +out_unlock:
> + mddev_unlock(mddev);
> + return err;
> +}
> +
> +static ssize_t
> +set_name_store(struct mddev *mddev, const char *buf, size_t buflen)
> +{
> + struct mdp_superblock_1 *sb;
> + struct md_rdev *rdev;
> + size_t len = buflen;
> + int err;
> +
> + if (len && buf[len - 1] == '\n')
> + --len;
> +
> + if (len > sizeof(sb->set_name))
> + return -ENOSPC;
> +
> + err = mddev_lock(mddev);
> + if (err)
> + return err;
> +
> + /* only version-1 superblocks carry a MD set's name */
> + err = -ENXIO;
> + if (mddev->major_version != 1)
> + goto out_unlock;
> +
> + err = -EROFS;
> + if (mddev->ro)
> + goto out_unlock;
> +
> + rdev_for_each(rdev, mddev) {
> + if (WARN_ON(!rdev->sb_loaded))
> + continue;
> +
> + sb = page_address(rdev->sb_page);
> + memcpy(sb->set_name, buf, len);
> + memset(&sb->set_name[len], 0, sizeof(sb->set_name) - len);
> + }
> +
> + md_update_sb(mddev, 1);
> + err = buflen;
> +
> +out_unlock:
> + mddev_unlock(mddev);
> + return err;
> +}
> +
> +static struct md_sysfs_entry md_set_name =
> +__ATTR(set_name, S_IRUGO | S_IWUSR, set_name_show, set_name_store);
> +
> static struct attribute *md_default_attrs[] = {
> &md_level.attr,
> &md_layout.attr,
> @@ -5067,6 +5145,7 @@ static struct attribute *md_default_attrs[] = {
> &md_array_size.attr,
> &max_corr_read_errors.attr,
> &md_consistency_policy.attr,
> + &md_set_name.attr,
> NULL,
> };
>
> --
> 2.11.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-raid" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
next prev parent reply other threads:[~2017-09-01 0:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-29 22:02 [PATCH] md: allow changing set_name of running array Michał Mirosław
2017-09-01 0:07 ` NeilBrown [this message]
2017-09-01 16:41 ` Michał Mirosław
2017-09-04 2:22 ` NeilBrown
2017-09-04 19:36 ` Michał Mirosław
2017-09-05 1:00 ` NeilBrown
2017-09-05 3:06 ` Phil Turmel
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=87tw0ne0xq.fsf@notabene.neil.brown.name \
--to=neilb@suse.com \
--cc=linux-raid@vger.kernel.org \
--cc=mirq-linux@rere.qmqm.pl \
--cc=shli@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