Skip to content

Commit 99b902a

Browse files
Li Nanliu-song-6
authored andcommitted
md: sync blockdev before stopping raid or setting readonly
Commit a05b7ea ("md: avoid crash when stopping md array races with closing other open fds.") added sync_block before stopping raid and setting readonly. Later in commit 260fa03 ("md: avoid deadlock when dirty buffers during md_stop.") it is moved to ioctl. array_state_store() was ignored. Add sync blockdev to array_state_store() now. Signed-off-by: Li Nan <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f74aaf6 commit 99b902a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/md/md.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4500,6 +4500,17 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len)
45004500
case broken: /* cannot be set */
45014501
case bad_word:
45024502
return -EINVAL;
4503+
case clear:
4504+
case readonly:
4505+
case inactive:
4506+
case read_auto:
4507+
if (!mddev->pers || !md_is_rdwr(mddev))
4508+
break;
4509+
/* write sysfs will not open mddev and opener should be 0 */
4510+
err = mddev_set_closing_and_sync_blockdev(mddev, 0);
4511+
if (err)
4512+
return err;
4513+
break;
45034514
default:
45044515
break;
45054516
}
@@ -4599,6 +4610,11 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len)
45994610
sysfs_notify_dirent_safe(mddev->sysfs_state);
46004611
}
46014612
mddev_unlock(mddev);
4613+
4614+
if (st == readonly || st == read_auto || st == inactive ||
4615+
(err && st == clear))
4616+
clear_bit(MD_CLOSING, &mddev->flags);
4617+
46024618
return err ?: len;
46034619
}
46044620
static struct md_sysfs_entry md_array_state =

0 commit comments

Comments
 (0)