Skip to content

Commit 650b2e6

Browse files
Li Nanliu-song-6
authored andcommitted
md: clean up openers check in do_md_stop() and md_set_readonly()
Before stopping or setting readonly, mddev_set_closing_and_sync_blockdev() is always called to check the openers. So no longer need to check it again in do_md_stop() and md_set_readonly(). Clean it up. Signed-off-by: Li Nan <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 99b902a commit 650b2e6

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

drivers/md/md.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4482,8 +4482,8 @@ array_state_show(struct mddev *mddev, char *page)
44824482
return sprintf(page, "%s\n", array_states[st]);
44834483
}
44844484

4485-
static int do_md_stop(struct mddev *mddev, int ro, struct block_device *bdev);
4486-
static int md_set_readonly(struct mddev *mddev, struct block_device *bdev);
4485+
static int do_md_stop(struct mddev *mddev, int ro);
4486+
static int md_set_readonly(struct mddev *mddev);
44874487
static int restart_array(struct mddev *mddev);
44884488

44894489
static ssize_t
@@ -4544,14 +4544,14 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len)
45444544
case inactive:
45454545
/* stop an active array, return 0 otherwise */
45464546
if (mddev->pers)
4547-
err = do_md_stop(mddev, 2, NULL);
4547+
err = do_md_stop(mddev, 2);
45484548
break;
45494549
case clear:
4550-
err = do_md_stop(mddev, 0, NULL);
4550+
err = do_md_stop(mddev, 0);
45514551
break;
45524552
case readonly:
45534553
if (mddev->pers)
4554-
err = md_set_readonly(mddev, NULL);
4554+
err = md_set_readonly(mddev);
45554555
else {
45564556
mddev->ro = MD_RDONLY;
45574557
set_disk_ro(mddev->gendisk, 1);
@@ -4561,7 +4561,7 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len)
45614561
case read_auto:
45624562
if (mddev->pers) {
45634563
if (md_is_rdwr(mddev))
4564-
err = md_set_readonly(mddev, NULL);
4564+
err = md_set_readonly(mddev);
45654565
else if (mddev->ro == MD_RDONLY)
45664566
err = restart_array(mddev);
45674567
if (err == 0) {
@@ -6420,7 +6420,7 @@ void md_stop(struct mddev *mddev)
64206420

64216421
EXPORT_SYMBOL_GPL(md_stop);
64226422

6423-
static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
6423+
static int md_set_readonly(struct mddev *mddev)
64246424
{
64256425
int err = 0;
64266426
int did_freeze = 0;
@@ -6438,9 +6438,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
64386438
!test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags));
64396439
mddev_lock_nointr(mddev);
64406440

6441-
mutex_lock(&mddev->open_mutex);
6442-
if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
6443-
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
6441+
if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
64446442
pr_warn("md: %s still in use.\n",mdname(mddev));
64456443
err = -EBUSY;
64466444
goto out;
@@ -6465,16 +6463,14 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
64656463
sysfs_notify_dirent_safe(mddev->sysfs_state);
64666464
}
64676465

6468-
mutex_unlock(&mddev->open_mutex);
64696466
return err;
64706467
}
64716468

64726469
/* mode:
64736470
* 0 - completely stop and dis-assemble array
64746471
* 2 - stop but do not disassemble array
64756472
*/
6476-
static int do_md_stop(struct mddev *mddev, int mode,
6477-
struct block_device *bdev)
6473+
static int do_md_stop(struct mddev *mddev, int mode)
64786474
{
64796475
struct gendisk *disk = mddev->gendisk;
64806476
struct md_rdev *rdev;
@@ -6487,12 +6483,9 @@ static int do_md_stop(struct mddev *mddev, int mode,
64876483

64886484
stop_sync_thread(mddev, true, false);
64896485

6490-
mutex_lock(&mddev->open_mutex);
6491-
if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
6492-
mddev->sysfs_active ||
6486+
if (mddev->sysfs_active ||
64936487
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
64946488
pr_warn("md: %s still in use.\n",mdname(mddev));
6495-
mutex_unlock(&mddev->open_mutex);
64966489
if (did_freeze) {
64976490
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
64986491
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
@@ -6514,13 +6507,11 @@ static int do_md_stop(struct mddev *mddev, int mode,
65146507
sysfs_unlink_rdev(mddev, rdev);
65156508

65166509
set_capacity_and_notify(disk, 0);
6517-
mutex_unlock(&mddev->open_mutex);
65186510
mddev->changed = 1;
65196511

65206512
if (!md_is_rdwr(mddev))
65216513
mddev->ro = MD_RDWR;
6522-
} else
6523-
mutex_unlock(&mddev->open_mutex);
6514+
}
65246515
/*
65256516
* Free resources if final stop
65266517
*/
@@ -6566,7 +6557,7 @@ static void autorun_array(struct mddev *mddev)
65666557
err = do_md_run(mddev);
65676558
if (err) {
65686559
pr_warn("md: do_md_run() returned %d\n", err);
6569-
do_md_stop(mddev, 0, NULL);
6560+
do_md_stop(mddev, 0);
65706561
}
65716562
}
65726563

@@ -7735,11 +7726,11 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
77357726
goto unlock;
77367727

77377728
case STOP_ARRAY:
7738-
err = do_md_stop(mddev, 0, bdev);
7729+
err = do_md_stop(mddev, 0);
77397730
goto unlock;
77407731

77417732
case STOP_ARRAY_RO:
7742-
err = md_set_readonly(mddev, bdev);
7733+
err = md_set_readonly(mddev);
77437734
goto unlock;
77447735

77457736
case HOT_REMOVE_DISK:

0 commit comments

Comments
 (0)