md: allow to set the fail_fast on RAID1/RAID10
PATCH RESEND 1/1 md: allow to set the fail_fast on RAID1/RAID10
When the running RAID1/RAID10 need to be set with the fail_fast flag, we have to remove each device from RAID and re-add it again with the --fail_fast flag.
Export the fail_fast flag to the userspace to support the read and write.
--- drivers/md/md.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/md/md.c +30 -0
@@ -3583,6 +3583,35 @@ ppl_size_store(struct md_rdev *rdev, const char *buf, size_t len)static struct rdev_sysfs_entry rdev_ppl_size =__ATTR (ppl_size,S_IRUGO |S_IWUSR , ppl_size_show, ppl_size_store); +static ssize_t +fail_fast_show (struct md_rdev *rdev,char *page) +{ +return sprintf (page,"%d\n" ,test_bit (FailFast, &rdev->flags)); +} + +static ssize_t +fail_fast_store (struct md_rdev *rdev,const char *buf,size_t len) +{ +int ret; +bool bit; + + ret =kstrtobool (buf, &bit); +if (ret) +return ret; + +if (test_bit (FailFast, &rdev->flags) && !bit) { +clear_bit (FailFast, &rdev->flags); +md_update_sb (rdev->mddev,1 ); + }else if (!test_bit (FailFast, &rdev->flags) && bit) { +set_bit (FailFast, &rdev->flags); +md_update_sb (rdev->mddev,1 ); + } +return len; +} + +static struct rdev_sysfs_entry rdev_fail_fast = +__ATTR (fail_fast,0644 , fail_fast_show, fail_fast_store); +static struct attribute *rdev_default_attrs[] = { &rdev_state.attr, &rdev_errors.attr,
@@ -3595,6 +3624,7 @@ static struct attribute *rdev_default_attrs[] = { &rdev_unack_bad_blocks.attr, &rdev_ppl_sector.attr, &rdev_ppl_size.attr, + &rdev_fail_fast.attr, NULL, }; static ssize_t
Signature · 1 line
2.31.1
Song Liu
maintainerQuoted 9 lines · Li Feng
When the running RAID1/RAID10 need to be set with the
fail_fastflag, we have to remove each device from RAID and re-add it again with the --fail_fast flag.Export the
fail_fastflag to the userspace to support the read and write.Signed-off-by Li Feng <[email protected]>
Thanks for the patch! I applied it to md-next, with some changes in the commit log.
Thanks,
Song
Hi all
Now the per device sysfs interface file state can change failfast. Do we need a new file for failfast?
I did a test. The steps are:
mdadm -CR /dev/md0 -l1 -n2 /dev/sdb /dev/sdc --assume-clean cd /sys/block/md0/md/dev-sdb
echo failfast > state
cat state
in_sync,failfast
Best Regards
Xiao
Quoted 18 lines · Song Liu
Quoted 9 lines · Li Feng
When the running RAID1/RAID10 need to be set with the
fail_fastflag, we have to remove each device from RAID and re-add it again with the --fail_fast flag.Export the
fail_fastflag to the userspace to support the read and write.Signed-off-by Li Feng <[email protected]>Thanks for the patch! I applied it to md-next, with some changes in the commit log.
Thanks,
Song
Quoted 6 lines · Xiao Ni <[email protected]> 于2021年10月11日周一 下午3:49写道:
Hi all
Now the per device sysfs interface file state can change failfast. Do we need a new file for failfast?
Quoted 7 lines
I did a test. The steps are:
mdadm -CR
/dev/md0-l1 -n2/dev/sdb/dev/sdc--assume-clean cd/sys/block/md0/md/dev-sdb
echo failfast > state
cat state
in_sync,failfast
This works, will it be persisted to disk?
Quoted 24 lines
Best Regards
XiaoQuoted 18 lines · Song Liu
Quoted 9 lines · Li Feng
When the running RAID1/RAID10 need to be set with the
fail_fastflag, we have to remove each device from RAID and re-add it again with the --fail_fast flag.Export the
fail_fastflag to the userspace to support the read and write.Signed-off-by Li Feng <[email protected]>Thanks for the patch! I applied it to md-next, with some changes in the commit log.
Thanks,
Song
Quoted 10 lines · Li Feng
Quoted 8 lines · Xiao Ni <[email protected]> 于2021年10月11日周一 下午3:49写道:
Hi all
Now the per device sysfs interface file state can change failfast. Do we need a new file for failfast?
I did a test. The steps are:
Quoted 8 lines
Quoted 5 lines
mdadm -CR
/dev/md0-l1 -n2/dev/sdb/dev/sdc--assume-clean cd/sys/block/md0/md/dev-sdb
echo failfast > state
cat state
in_sync,failfastThis works, will it be persisted to disk?
mdadm --detail /dev/md0 can show the failfast information. So it should be written in superblock.
But I don't find how md does this. I'm looking at this.
Regards
Xiao
Quoted 18 lines · Xiao Ni <[email protected]> 于2021年10月12日周二 下午2:58写道:
Quoted 16 lines · Li Feng
Quoted 13 lines · Xiao Ni <[email protected]> 于2021年10月11日周一 下午3:49写道:
Hi all
Now the per device sysfs interface file state can change failfast. Do we need a new file for failfast?
I did a test. The steps are:
mdadm -CR
/dev/md0-l1 -n2/dev/sdb/dev/sdc--assume-clean cd/sys/block/md0/md/dev-sdb
echo failfast > state
cat state
in_sync,failfast
Quoted 7 lines
Quoted 2 lines
This works, will it be persisted to disk?
mdadm --detail
/dev/md0can show the failfast information. So it should be written in superblock.
But I don't find how md does this. I'm looking at this.
Yes, I have tested that it has been persisted, but don't understand who does it.
Quoted 3 lines
Regards
Xiao
Song Liu
maintainerQuoted 20 lines · Li Feng
Quoted 18 lines · Xiao Ni <[email protected]> 于2021年10月12日周二 下午2:58写道:
Quoted 16 lines · Li Feng
Quoted 13 lines · Xiao Ni <[email protected]> 于2021年10月11日周一 下午3:49写道:
Hi all
Now the per device sysfs interface file state can change failfast. Do we need a new file for failfast?
I did a test. The steps are:
mdadm -CR
/dev/md0-l1 -n2/dev/sdb/dev/sdc--assume-clean cd/sys/block/md0/md/dev-sdb
echo failfast > state
cat state
in_sync,failfast
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
This works, will it be persisted to disk?
mdadm --detail
/dev/md0can show the failfast information. So it should be written in superblock.
But I don't find how md does this. I'm looking at this.Yes, I have tested that it has been persisted, but don't understand who does it.
I think this is not guaranteed to be persistent:
[root@eth50-1 ~]# cat /sys/block/md127/md/rd1/state in_sync,failfast
[root@eth50-1 ~]# echo -failfast > /sys/block/md127/md/rd1/state [root@eth50-1 ~]# cat /sys/block/md127/md/rd1/state in_sync
[root@eth50-1 ~]# mdadm --stop /dev/md*
mdadm: /dev/md does not appear to be an md device
mdadm: stopped /dev/md127
[root@eth50-1 ~]# mdadm -As
mdadm: /dev/md/0_0 has been started with 4 drives. [root@eth50-1 ~]# cat /sys/block/md127/md/rd1/state in_sync,failfast
How about we fix state_store to make sure it is always persistent?
Thanks,
Song
Quoted 46 lines · Song Liu <[email protected]> 于2021年10月12日周二 下午4:17写道:
Quoted 20 lines · Li Feng
Quoted 18 lines · Xiao Ni <[email protected]> 于2021年10月12日周二 下午2:58写道:
Quoted 16 lines · Li Feng
Quoted 13 lines · Xiao Ni <[email protected]> 于2021年10月11日周一 下午3:49写道:
Hi all
Now the per device sysfs interface file state can change failfast. Do we need a new file for failfast?
I did a test. The steps are:
mdadm -CR
/dev/md0-l1 -n2/dev/sdb/dev/sdc--assume-clean cd/sys/block/md0/md/dev-sdb
echo failfast > state
cat state
in_sync,failfastQuoted 8 lines
Quoted 7 lines
Quoted 2 lines
This works, will it be persisted to disk?
mdadm --detail
/dev/md0can show the failfast information. So it should be written in superblock.
But I don't find how md does this. I'm looking at this.Yes, I have tested that it has been persisted, but don't understand who does it.
I think this is not guaranteed to be persistent:
[root@eth50-1 ~]# cat
/sys/block/md127/md/rd1/statein_sync,failfast
[root@eth50-1 ~]# echo -failfast >/sys/block/md127/md/rd1/state[root@eth50-1 ~]# cat/sys/block/md127/md/rd1/statein_sync
[root@eth50-1 ~]# mdadm --stop/dev/md*
mdadm:/dev/mddoes not appear to be an md device
mdadm: stopped/dev/md127
[root@eth50-1 ~]# mdadm -As
mdadm:/dev/md/0_0has been started with 4 drives. [root@eth50-1 ~]# cat/sys/block/md127/md/rd1/statein_sync,failfast
Quoted 2 lines
How about we fix
state_storeto make sure it is always persistent?
I agree with you.
Quoted 2 lines
Thanks,
Song
Hi all
How about this patch? Now writemostly flag doesn't be stored in superblock too. So this patch fix this problem too. If this patch is ok, I'll send the patch.
drivers/md/md.c +0 -0
@@ -2977,6 +2977,7 @@ state_store(struct md_rdev *rdev, const char
*buf, size_t len)
* {,-}failfast - set/clear FailFast
*/
int err = -EINVAL;
+ int need_update_sb = 0;
if (cmd_match(buf, "faulty") && rdev->mddev->pers) {
md_error(rdev->mddev, rdev);
if (test_bit(Faulty, &rdev->flags))@@ -2998,20 +2999,19 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
if (err == 0) {
md_kick_rdev_from_array(rdev);- if (mddev->pers) {
- set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
- md_wakeup_thread(mddev->thread);
- }
+ need_update_sb = 1;
md_new_event(mddev);
}
}
} else if (cmd_match(buf, "writemostly")) {
set_bit(WriteMostly, &rdev->flags);
mddev_create_serial_pool(rdev->mddev, rdev, false);
+ need_update_sb = 1;
err = 0;
} else if (cmd_match(buf, "-writemostly")) {
mddev_destroy_serial_pool(rdev->mddev, rdev, false);
clear_bit(WriteMostly, &rdev->flags);
+ need_update_sb = 1;
err = 0;
} else if (cmd_match(buf, "blocked")) {
set_bit(Blocked, &rdev->flags);
@@ -3037,9 +3037,11 @@ state_store(struct md_rdev *rdev, const char
*buf, size_t len)
err = 0;
} else if (cmd_match(buf, "failfast")) {
set_bit(FailFast, &rdev->flags);
+ need_update_sb = 1;
err = 0;
} else if (cmd_match(buf, "-failfast")) {
clear_bit(FailFast, &rdev->flags);
+ need_update_sb = 1;
err = 0;
} else if (cmd_match(buf, "-insync") && rdev->raid_disk >= 0 &&
!test_bit(Journal, &rdev->flags)) {
@@ -3120,6 +3122,11 @@ state_store(struct md_rdev *rdev, const char
*buf, size_t len)
}
if (!err)
sysfs_notify_dirent_safe(rdev->sysfs_state);+ if (need_update_sb)
+ if (mddev->pers) {
+ set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
+ md_wakeup_thread(mddev->thread);
+ }
return err ? err : len;
}
static struct rdev_sysfs_entry rdev_state =
Quoted 55 lines · Li Feng
Quoted 46 lines · Song Liu <[email protected]> 于2021年10月12日周二 下午4:17写道:
Quoted 20 lines · Li Feng
Quoted 18 lines · Xiao Ni <[email protected]> 于2021年10月12日周二 下午2:58写道:
Quoted 16 lines · Li Feng
Quoted 13 lines · Xiao Ni <[email protected]> 于2021年10月11日周一 下午3:49写道:
Hi all
Now the per device sysfs interface file state can change failfast. Do we need a new file for failfast?
I did a test. The steps are:
mdadm -CR
/dev/md0-l1 -n2/dev/sdb/dev/sdc--assume-clean cd/sys/block/md0/md/dev-sdb
echo failfast > state
cat state
in_sync,failfastQuoted 8 lines
Quoted 7 lines
Quoted 2 lines
This works, will it be persisted to disk?
mdadm --detail
/dev/md0can show the failfast information. So it should be written in superblock.
But I don't find how md does this. I'm looking at this.Yes, I have tested that it has been persisted, but don't understand who does it.
I think this is not guaranteed to be persistent:
[root@eth50-1 ~]# cat
/sys/block/md127/md/rd1/statein_sync,failfast
[root@eth50-1 ~]# echo -failfast >/sys/block/md127/md/rd1/state[root@eth50-1 ~]# cat/sys/block/md127/md/rd1/statein_sync
[root@eth50-1 ~]# mdadm --stop/dev/md*
mdadm:/dev/mddoes not appear to be an md device
mdadm: stopped/dev/md127
[root@eth50-1 ~]# mdadm -As
mdadm:/dev/md/0_0has been started with 4 drives. [root@eth50-1 ~]# cat/sys/block/md127/md/rd1/statein_sync,failfastQuoted 2 lines
How about we fix
state_storeto make sure it is always persistent?I agree with you.
Quoted 2 lines
Thanks,
Song
Thanks,
Feng Li
Quoted 59 lines · Xiao Ni <[email protected]> 于2021年10月12日周二 下午4:49写道:
Hi all
How about this patch? Now writemostly flag doesn't be stored in superblock too. So this patch fix this problem too. If this patch is ok, I'll send the patch.
drivers/md/md.c +1
-0@@ -2977,6 +2977,7 @@ state_store(struct md_rdev *rdev, const char*buf, size_t len) * {,-}failfast - set/clear FailFast */ int err = -EINVAL ; +int need_update_sb =0 ;if (cmd_match (buf,"faulty" ) && rdev->mddev->pers) {md_error (rdev->mddev, rdev);if (test_bit(Faulty, &rdev->flags))drivers/md/md.c +3
-4@@ -2998,20 +2999,19 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)if (err ==0 ) {md_kick_rdev_from_array (rdev); -if (mddev->pers) { -set_bit (MD_SB_CHANGE_DEVS , &mddev->sb_flags); -md_wakeup_thread (mddev->thread); - } + need_update_sb =1 ;md_new_event (mddev); } } }else if (cmd_match (buf,"writemostly" )) {set_bit (WriteMostly, &rdev->flags);mddev_create_serial_pool (rdev->mddev, rdev, false); + need_update_sb =1 ; err =0 ; }else if (cmd_match (buf,"-writemostly" )) {mddev_destroy_serial_pool (rdev->mddev, rdev, false);clear_bit (WriteMostly, &rdev->flags); + need_update_sb =1 ; err =0 ; }else if (cmd_match (buf,"blocked" )) {set_bit(Blocked, &rdev->flags);drivers/md/md.c +2
-0@@ -3037,9 +3037,11 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len) err =0 ; }else if (cmd_match (buf,"failfast" )) {set_bit (FailFast, &rdev->flags); + need_update_sb =1 ; err =0 ; }else if (cmd_match (buf,"-failfast" )) {clear_bit (FailFast, &rdev->flags); + need_update_sb =1 ; err =0 ; } else if (cmd_match(buf, "-insync") && rdev->raid_disk >= 0 &&!test_bit(Journal, &rdev->flags)) {
drivers/md/md.c state_store(struct md_rdev *rdev, const char · line 3130
Quoted 9 lines
drivers/md/md.c +5
-0@@ -3120,6 +3122,11 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len) }if (!err)sysfs_notify_dirent_safe (rdev->sysfs_state); +if (need_update_sb) +if (mddev->pers) { +set_bit (MD_SB_CHANGE_DEVS , &mddev->sb_flags); +md_wakeup_thread (mddev->thread); + }
When will mddev->pers is NULL?
If it is NULL, this change will not on disk.
Quoted 61 lines
drivers/md/md.c +0
-0return err ? err : len; }static struct
rdev_sysfs_entryrdev_state=Quoted 55 lines · Li Feng
Quoted 46 lines · Song Liu <[email protected]> 于2021年10月12日周二 下午4:17写道:
Quoted 20 lines · Li Feng
Quoted 18 lines · Xiao Ni <[email protected]> 于2021年10月12日周二 下午2:58写道:
Quoted 16 lines · Li Feng
Quoted 13 lines · Xiao Ni <[email protected]> 于2021年10月11日周一 下午3:49写道:
Hi all
Now the per device sysfs interface file state can change failfast. Do we need a new file for failfast?
I did a test. The steps are:
mdadm -CR
/dev/md0-l1 -n2/dev/sdb/dev/sdc--assume-clean cd/sys/block/md0/md/dev-sdb
echo failfast > state
cat state
in_sync,failfastQuoted 8 lines
Quoted 7 lines
Quoted 2 lines
This works, will it be persisted to disk?
mdadm --detail
/dev/md0can show the failfast information. So it should be written in superblock.
But I don't find how md does this. I'm looking at this.Yes, I have tested that it has been persisted, but don't understand who does it.
I think this is not guaranteed to be persistent:
[root@eth50-1 ~]# cat
/sys/block/md127/md/rd1/statein_sync,failfast
[root@eth50-1 ~]# echo -failfast >/sys/block/md127/md/rd1/state[root@eth50-1 ~]# cat/sys/block/md127/md/rd1/statein_sync
[root@eth50-1 ~]# mdadm --stop/dev/md*
mdadm:/dev/mddoes not appear to be an md device
mdadm: stopped/dev/md127
[root@eth50-1 ~]# mdadm -As
mdadm:/dev/md/0_0has been started with 4 drives. [root@eth50-1 ~]# cat/sys/block/md127/md/rd1/statein_sync,failfastQuoted 2 lines
How about we fix
state_storeto make sure it is always persistent?I agree with you.
Quoted 2 lines
Thanks,
Song
Quoted 7 lines · Li Feng
Review
Quoted 6 lines
sysfs_notify_dirent_safe(rdev->sysfs_state);(quoted diff) +5
-0+ if (need_update_sb) + if (mddev->pers) { + set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); + md_wakeup_thread(mddev->thread); + }When will
mddev->persis NULL?
The process of creating a raid device is:
1. md_ioctl->md_add_new_disk
2. md_ioctl->do_md_run->md_run->(pers->run)->(mddev->pers = pers) In md_add_new_disk it creates the per device sysfs files. It can read/write these
files before setting mddev->pers.
Quoted 1 line
If it is NULL, this change will not on disk.
I did a test. You are right. Someone can change the per device state before ADD_NEW_DISK
and RUN_ARRAY ioctl. Please note, the mdadm --create command doesn't return until RUN_ARRAY
ioctl finishes. Even though the are small, we can try to set MD_SB_CHANGE_DEVS.
Best regards
Xiao
Song Liu
maintainerQuoted 12 lines · Xiao Ni
Hi all
How about this patch? Now writemostly flag doesn't be stored in superblock too. So this patch fix this problem too. If this patch is ok, I'll send the patch.
drivers/md/md.c +0
-0
drivers/md/md.c state_store(struct md_rdev *rdev, const char · line 2981
Quoted 5 lines
drivers/md/md.c +1
-0@@ -2977,6 +2977,7 @@ state_store(struct md_rdev *rdev, const char*buf, size_t len) * {,-}failfast - set/clear FailFast */ int err = -EINVAL ; +int need_update_sb =0 ;
Please use bool for need_update_sb.
Quoted 3 lines
drivers/md/md.c +0
-0if (cmd_match (buf,"faulty" ) && rdev->mddev->pers) {md_error (rdev->mddev, rdev);if (test_bit(Faulty, &rdev->flags))
[...]
drivers/md/md.c state_store(struct md_rdev *rdev, const char · line 3127
Quoted 7 lines
drivers/md/md.c +2
-0@@ -3120,6 +3122,11 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len) }if (!err)sysfs_notify_dirent_safe (rdev->sysfs_state); +if (need_update_sb) +if (mddev->pers) {
We can merge the two conditions in in one line
if (need_update_sb && mddev->pers) {
...
}
Quoted 64 lines
drivers/md/md.c +3
-0+set_bit (MD_SB_CHANGE_DEVS , &mddev->sb_flags); +md_wakeup_thread (mddev->thread); + }return err ? err : len; }static struct
rdev_sysfs_entryrdev_state=Quoted 55 lines · Li Feng
Quoted 46 lines · Song Liu <[email protected]> 于2021年10月12日周二 下午4:17写道:
Quoted 20 lines · Li Feng
Quoted 18 lines · Xiao Ni <[email protected]> 于2021年10月12日周二 下午2:58写道:
Quoted 16 lines · Li Feng
Quoted 13 lines · Xiao Ni <[email protected]> 于2021年10月11日周一 下午3:49写道:
Hi all
Now the per device sysfs interface file state can change failfast. Do we need a new file for failfast?
I did a test. The steps are:
mdadm -CR
/dev/md0-l1 -n2/dev/sdb/dev/sdc--assume-clean cd/sys/block/md0/md/dev-sdb
echo failfast > state
cat state
in_sync,failfastQuoted 8 lines
Quoted 7 lines
Quoted 2 lines
This works, will it be persisted to disk?
mdadm --detail
/dev/md0can show the failfast information. So it should be written in superblock.
But I don't find how md does this. I'm looking at this.Yes, I have tested that it has been persisted, but don't understand who does it.
I think this is not guaranteed to be persistent:
[root@eth50-1 ~]# cat
/sys/block/md127/md/rd1/statein_sync,failfast
[root@eth50-1 ~]# echo -failfast >/sys/block/md127/md/rd1/state[root@eth50-1 ~]# cat/sys/block/md127/md/rd1/statein_sync
[root@eth50-1 ~]# mdadm --stop/dev/md*
mdadm:/dev/mddoes not appear to be an md device
mdadm: stopped/dev/md127
[root@eth50-1 ~]# mdadm -As
mdadm:/dev/md/0_0has been started with 4 drives. [root@eth50-1 ~]# cat/sys/block/md127/md/rd1/statein_sync,failfastQuoted 2 lines
How about we fix
state_storeto make sure it is always persistent?I agree with you.
Quoted 2 lines
Thanks,
Song