Hi Song Please ignore this patch. After thinking, it should be better to call md_update_sb directly here. So it doesn't need to consider if mddev->pers is NULL or not. I'll send V2 later Regards Xiao On Wed, Oct 13, 2021 at 10:21 PM Xiao Ni <xni@xxxxxxxxxx> wrote: > > It doesn't update rdev superblock flags to disk after changing these flags. > This patch does this job. In the process of creating a raid, it creates per > device sysfs files and then sets value to mddev->pers. There is a interval > between the two events. If someone changes rdev flags in this interval, it > needs to record this. So it sets MD_SB_CHANGE_DEVS first. If mddev->pers is > NULL, it can update superblock after creating mddev->thread. > > Signed-off-by: Xiao Ni <xni@xxxxxxxxxx> > --- > drivers/md/md.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 6c0c3d0..40d0f50 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -2976,7 +2976,11 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len) > * -write_error - clears WriteErrorSeen > * {,-}failfast - set/clear FailFast > */ > + > + struct mddev *mddev = rdev->mddev; > int err = -EINVAL; > + bool need_update_sb = false; > + > if (cmd_match(buf, "faulty") && rdev->mddev->pers) { > md_error(rdev->mddev, rdev); > if (test_bit(Faulty, &rdev->flags)) > @@ -2991,7 +2995,6 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len) > if (rdev->raid_disk >= 0) > err = -EBUSY; > else { > - struct mddev *mddev = rdev->mddev; > err = 0; > if (mddev_is_clustered(mddev)) > err = md_cluster_ops->remove_disk(mddev, rdev); > @@ -3008,10 +3011,12 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len) > } else if (cmd_match(buf, "writemostly")) { > set_bit(WriteMostly, &rdev->flags); > mddev_create_serial_pool(rdev->mddev, rdev, false); > + need_update_sb = true; > err = 0; > } else if (cmd_match(buf, "-writemostly")) { > mddev_destroy_serial_pool(rdev->mddev, rdev, false); > clear_bit(WriteMostly, &rdev->flags); > + need_update_sb = true; > err = 0; > } else if (cmd_match(buf, "blocked")) { > set_bit(Blocked, &rdev->flags); > @@ -3037,9 +3042,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 = true; > err = 0; > } else if (cmd_match(buf, "-failfast")) { > clear_bit(FailFast, &rdev->flags); > + need_update_sb = true; > err = 0; > } else if (cmd_match(buf, "-insync") && rdev->raid_disk >= 0 && > !test_bit(Journal, &rdev->flags)) { > @@ -3118,6 +3125,11 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len) > clear_bit(ExternalBbl, &rdev->flags); > err = 0; > } > + if (need_update_sb) { > + set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags); > + if (mddev->pers) > + md_wakeup_thread(mddev->thread); > + } > if (!err) > sysfs_notify_dirent_safe(rdev->sysfs_state); > return err ? err : len; > -- > 2.7.5 >