md: add new_level sysfs interface
PATCH 1/1 md: add new_level sysfs interface
This interface is used to updating new level during reshape progress. Now it doesn't update new level during reshape. So it can't know the new level when systemd service mdadm-grow-continue runs. And it can't finally change to new level.
--- drivers/md/md.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/md/md.c +29 -0
@@ -4141,6 +4141,34 @@ level_store(struct mddev *mddev, const char *buf, size_t len)static struct md_sysfs_entry md_level =__ATTR (level,S_IRUGO |S_IWUSR , level_show, level_store); +static ssize_t +new_level_show (struct mddev *mddev,char *page) +{ +return sprintf (page,"%d\n" , mddev->new_level); +} + +static ssize_t +new_level_store (struct mddev *mddev,const char *buf,size_t len) +{ +unsigned int n; +int err; + + err =kstrtouint (buf,10 , &n); +if (err <0 ) +return err; + err =mddev_lock (mddev); +if (err) +return err; + + mddev->new_level = n; +md_update_sb (mddev,1 ); + +mddev_unlock (mddev); +return err ?: len; +} +static struct md_sysfs_entry md_new_level = +__ATTR (new_level,0664 , new_level_show, new_level_store); +static ssize_t layout_show (struct mddev *mddev,char *page) {
@@ -5666,6 +5694,7 @@ __ATTR(serialize_policy, S_IRUGO | S_IWUSR, serialize_policy_show,static struct attribute *md_default_attrs[] = { &md_level.attr, + &md_new_level.attr, &md_layout.attr, &md_raid_disks.attr, &md_uuid.attr,
Signature · 1 line
2.32.0 (Apple Git-132)
Dear Xiao,
Thank you for your patch.
Am 28.08.24 um 04:18 schrieb Xiao Ni:
Quoted 1 line
This interface is used to updating new level during reshape progress.
to update
Quoted 3 lines
Now it doesn't update new level during reshape. So it can't know the new level when systemd service mdadm-grow-continue runs. And it can't finally change to new level.
How can this be tested?
Quoted 27 lines
Signed-off-by Xiao Ni <[email protected]>--- drivers/md/md.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)drivers/md/md.c +14
-0@@ -4141,6 +4141,34 @@ level_store(struct mddev *mddev, const char *buf, size_t len)static struct md_sysfs_entry md_level =__ATTR (level,S_IRUGO |S_IWUSR , level_show, level_store); +static ssize_t +new_level_show (struct mddev *mddev,char *page) +{ +return sprintf (page,"%d\n" , mddev->new_level); +} + +static ssize_t +new_level_store (struct mddev *mddev,const char *buf,size_t len) +{ +unsigned int n; +int err; + + err =kstrtouint (buf,10 , &n); +if (err <0 )
drivers/md/md.c level_store(struct mddev *mddev, const char *buf, size_t len) · line 4167
Quoted 10 lines
drivers/md/md.c +10
-0+return err; + err =mddev_lock (mddev); +if (err) +return err; + + mddev->new_level = n; +md_update_sb (mddev,1 ); + +mddev_unlock (mddev); +return err ?: len;
Can err be set? Why return len if it’s not modified?
Quoted 8 lines
drivers/md/md.c +4
-0+} +static struct md_sysfs_entry md_new_level = +__ATTR (new_level,0664 , new_level_show, new_level_store); +static ssize_t layout_show (struct mddev *mddev,char *page) {
drivers/md/md.c __ATTR(serialize_policy, S_IRUGO | S_IWUSR, serialize_policy_show, · line 5700
Quoted 7 lines
drivers/md/md.c +1
-0@@ -5666,6 +5694,7 @@ __ATTR(serialize_policy, S_IRUGO | S_IWUSR, serialize_policy_show,static struct attribute *md_default_attrs[] = { &md_level.attr, + &md_new_level.attr, &md_layout.attr, &md_raid_disks.attr, &md_uuid.attr,
Kind regards,
Paul
Quoted 6 lines · Paul Menzel
Dear Xiao,
Thank you for your reply. Was it intentional, that you only replied to me off-list?
Hi Paul
I made a mistake. Thanks for reminding me.
Quoted 20 lines
Am 28.08.24 um 10:44 schrieb Xiao Ni:
Quoted 3 lines · Paul Menzel
Quoted 2 lines
Am 28.08.24 um 04:18 schrieb Xiao Ni:
[…]
Quoted 12 lines
Quoted 1 line
How can this be tested?
mdadm -CR
/dev/md0-l6 -n4 /dev/loop[0-3]
mdadm --wait/dev/md0
mdadm/dev/md0--grow -l5 --backup=backup
cat/proc/mdstat
Personalities : [raid6] [raid5] [raid4] [raid0] [raid1] [raid10] md0 : active raid6 loop3[3] loop2[2] loop1[1] loop0[0]98304 blocks super 1.2 level 6, 512k chunk, algorithm 18 [4/4] [UUUU]unused devices: <none>
Quoted 7 lines
Quoted 2 lines
There is a tests directory in mdadm. The case 07changelevels have this test. Now it can't run successfully. This patch is used to fix this.
It’d be great if you mentioned this in the commit message. That this test fails, and now it works. Please also mention, if this was a regression. (I guess it is, as the test should have been passed, when it was added?)
Ok, I'll add them to the commit message. The test cases was created in 2009. So yes, it must be a regression, but it's hard to see what changes cause the regression.
Quoted 41 lines
Quoted 41 lines
Quoted 40 lines
Quoted 28 lines
Signed-off-by Xiao Ni <[email protected]>--- drivers/md/md.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)drivers/md/md.c +14
-0@@ -4141,6 +4141,34 @@ level_store(struct mddev *mddev, const char *buf, size_t len)static struct md_sysfs_entry md_level =__ATTR (level,S_IRUGO |S_IWUSR , level_show, level_store); +static ssize_t +new_level_show (struct mddev *mddev,char *page) +{ +return sprintf (page,"%d\n" , mddev->new_level); +} + +static ssize_t +new_level_store (struct mddev *mddev,const char *buf,size_t len) +{ +unsigned int n; +int err; + + err =kstrtouint (buf,10 , &n); +if (err <0 )drivers/md/md.c level_store(struct mddev *mddev, const char *buf, size_t len) · line 4167
Quoted 10 lines
drivers/md/md.c +10
-0+return err; + err =mddev_lock (mddev); +if (err) +return err; + + mddev->new_level = n; +md_update_sb (mddev,1 ); + +mddev_unlock (mddev); +return err ?: len;Can
errbe set? Why returnlenif it’s not modified?
Quoted 7 lines
Quoted 4 lines
err is the return value from kstrtouint and
mddev_lock. And len is the input value of the buf length. If it can be set successfully, it returns len. It's same with other sysfs functions. For example,raid_disks_store,layout_storeand so on.At least
layout_storemodifieserrlater on. In your new function, if there is an error the function returns, so there is no need to check it.
Ah I know what you mean. I'll fix this.
Quoted 3 lines
Where is
lenused in your new function? It’s only in the function signature. A colleague also didn’t spot it.
Hmm, functions raid_disks_store, layout_store, chunk_size_sotre don't use len too. So what's your suggestion here?
Best Regards
Xiao
Quoted 23 lines
Kind regards,
Paul
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/md/md.c +5
-0+} +static struct md_sysfs_entry md_new_level = +__ATTR (new_level,0664 , new_level_show, new_level_store); +static ssize_t layout_show (struct mddev *mddev,char *page) {@@ -5666,6 +5694,7 @@ __ATTR(serialize_policy, S_IRUGO | S_IWUSR, serialize_policy_show,static struct attribute *md_default_attrs[] = { &md_level.attr, + &md_new_level.attr, &md_layout.attr, &md_raid_disks.attr, &md_uuid.attr,
Quoted 29 lines · On Wed, 28 Aug 2024 10:18:28 +0800 Xiao Ni <[email protected]> wrote:
This interface is used to updating new level during reshape progress. Now it doesn't update new level during reshape. So it can't know the new level when systemd service mdadm-grow-continue runs. And it can't finally change to new level.
Signed-off-by Xiao Ni <[email protected]>--- drivers/md/md.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)drivers/md/md.c +0
-0@@ -4141,6 +4141,34 @@ level_store(struct mddev *mddev, const char *buf,
size_tlen) static structmd_sysfs_entrymd_level=
__ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store);drivers/md/md.c +11
-0+static ssize_t +new_level_show (struct mddev *mddev,char *page) +{ +return sprintf (page,"%d\n" , mddev->new_level); +} + +static ssize_t +new_level_store (struct mddev *mddev,const char *buf,size_t len) +{ +unsigned int n; +int err;
drivers/md/md.c level_store(struct mddev *mddev, const char *buf, size_t len) · line 4164
Quoted 10 lines
drivers/md/md.c +10
-0+ + err =kstrtouint (buf,10 , &n); +if (err <0 ) +return err; + err =mddev_lock (mddev); +if (err) +return err; + + mddev->new_level = n; +md_update_sb (mddev,1 );
I don't see any code behind mddev->new_level handling so I suspect that md_update_sb() does nothing in this case. Is there something I'm missing?
Thanks,
Mariusz
Quoted 18 lines
drivers/md/md.c +8
-0+ +mddev_unlock (mddev); +return err ?: len; +} +static struct md_sysfs_entry md_new_level = +__ATTR (new_level,0664 , new_level_show, new_level_store); +static ssize_t layout_show (struct mddev *mddev,char *page) {@@ -5666,6 +5694,7 @@ __ATTR(serialize_policy, S_IRUGO | S_IWUSR, serialize_policy_show, static struct attribute *md_default_attrs[] = { &md_level.attr, + &md_new_level.attr, &md_layout.attr, &md_raid_disks.attr, &md_uuid.attr,
Quoted 38 lines · Mariusz Tkaczyk
Quoted 34 lines · On Wed, 28 Aug 2024 10:18:28 +0800 Xiao Ni <[email protected]> wrote:
This interface is used to updating new level during reshape progress. Now it doesn't update new level during reshape. So it can't know the new level when systemd service mdadm-grow-continue runs. And it can't finally change to new level.
Signed-off-by Xiao Ni <[email protected]>--- drivers/md/md.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)drivers/md/md.c +0
-0@@ -4141,6 +4141,34 @@ level_store(struct mddev *mddev, const char *buf,
size_tlen) static structmd_sysfs_entrymd_level=
__ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store);drivers/md/md.c +16
-0+static ssize_t +new_level_show (struct mddev *mddev,char *page) +{ +return sprintf (page,"%d\n" , mddev->new_level); +} + +static ssize_t +new_level_store (struct mddev *mddev,const char *buf,size_t len) +{ +unsigned int n; +int err; + + err =kstrtouint (buf,10 , &n); +if (err <0 ) +return err; + err =mddev_lock (mddev);
Quoted 8 lines
drivers/md/md.c level_store(struct mddev *mddev, const char *buf, size_t len) · line 4164
Quoted 5 lines
drivers/md/md.c +5
-0+if (err) +return err; + + mddev->new_level = n; +md_update_sb (mddev,1 );I don't see any code behind
mddev->new_levelhandling so I suspect thatmd_update_sb()does nothing in this case. Is there something I'm missing?
You mean the calling path md_update_sb->sync_sbs->super_1_sync?
Best Regards
Xiao
Quoted 24 lines
Thanks,
MariuszQuoted 18 lines
drivers/md/md.c +8
-0+ +mddev_unlock (mddev); +return err ?: len; +} +static struct md_sysfs_entry md_new_level = +__ATTR (new_level,0664 , new_level_show, new_level_store); +static ssize_t layout_show (struct mddev *mddev,char *page) {@@ -5666,6 +5694,7 @@ __ATTR(serialize_policy, S_IRUGO | S_IWUSR, serialize_policy_show, static struct attribute *md_default_attrs[] = { &md_level.attr, + &md_new_level.attr, &md_layout.attr, &md_raid_disks.attr, &md_uuid.attr,
Quoted 49 lines · On Tue, 3 Sep 2024 08:18:19 +0800 Xiao Ni <[email protected]> wrote:
Quoted 38 lines · Mariusz Tkaczyk
Quoted 34 lines · On Wed, 28 Aug 2024 10:18:28 +0800 Xiao Ni <[email protected]> wrote:
This interface is used to updating new level during reshape progress. Now it doesn't update new level during reshape. So it can't know the new level when systemd service mdadm-grow-continue runs. And it can't finally change to new level.
Signed-off-by Xiao Ni <[email protected]>--- drivers/md/md.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)drivers/md/md.c +0
-0@@ -4141,6 +4141,34 @@ level_store(struct mddev *mddev, const char *buf,
size_tlen) static structmd_sysfs_entrymd_level=
__ATTR(level, S_IRUGO|S_IWUSR, level_show, level_store);drivers/md/md.c +16
-0+static ssize_t +new_level_show (struct mddev *mddev,char *page) +{ +return sprintf (page,"%d\n" , mddev->new_level); +} + +static ssize_t +new_level_store (struct mddev *mddev,const char *buf,size_t len) +{ +unsigned int n; +int err; + + err =kstrtouint (buf,10 , &n); +if (err <0 ) +return err; + err =mddev_lock (mddev);Quoted 8 lines
drivers/md/md.c level_store(struct mddev *mddev, const char *buf, size_t len) · line 4164
Quoted 5 lines
drivers/md/md.c +5
-0+if (err) +return err; + + mddev->new_level = n; +md_update_sb (mddev,1 );I don't see any code behind
mddev->new_levelhandling so I suspect thatmd_update_sb()does nothing in this case. Is there something I'm missing?
Quoted 2 lines
You mean the calling path
md_update_sb->sync_sbs->super_1_sync?
No, I missed that mddev->new_level is a exiting property and it is already implemented in kernel. Now, I understand that it is super0 metadata property and you just presented it. This is fine.
What I can see is that calling md_update_super() in case of external might be unnecessary but it is fine anyway I think.
maybe: if (!mddev->external)
md_update_sb(mddev, 1);
but I don't see it used in the code anywhere. metadata update path is still black box to me. Maybe Kuai can comment?
Thanks,
Mariusz