Skip to content

Commit f74aaf6

Browse files
Li Nanliu-song-6
authored andcommitted
md: factor out a helper to sync mddev
There are no functional changes, prepare to sync mddev in array_state_store(). Signed-off-by: Li Nan <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9674f54 commit f74aaf6

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

drivers/md/md.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,24 @@ void mddev_resume(struct mddev *mddev)
529529
}
530530
EXPORT_SYMBOL_GPL(mddev_resume);
531531

532+
/* sync bdev before setting device to readonly or stopping raid*/
533+
static int mddev_set_closing_and_sync_blockdev(struct mddev *mddev, int opener_num)
534+
{
535+
mutex_lock(&mddev->open_mutex);
536+
if (mddev->pers && atomic_read(&mddev->openers) > opener_num) {
537+
mutex_unlock(&mddev->open_mutex);
538+
return -EBUSY;
539+
}
540+
if (test_and_set_bit(MD_CLOSING, &mddev->flags)) {
541+
mutex_unlock(&mddev->open_mutex);
542+
return -EBUSY;
543+
}
544+
mutex_unlock(&mddev->open_mutex);
545+
546+
sync_blockdev(mddev->gendisk->part0);
547+
return 0;
548+
}
549+
532550
/*
533551
* Generic flush handling for md
534552
*/
@@ -7658,17 +7676,9 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
76587676
/* Need to flush page cache, and ensure no-one else opens
76597677
* and writes
76607678
*/
7661-
mutex_lock(&mddev->open_mutex);
7662-
if (mddev->pers && atomic_read(&mddev->openers) > 1) {
7663-
mutex_unlock(&mddev->open_mutex);
7664-
return -EBUSY;
7665-
}
7666-
if (test_and_set_bit(MD_CLOSING, &mddev->flags)) {
7667-
mutex_unlock(&mddev->open_mutex);
7668-
return -EBUSY;
7669-
}
7670-
mutex_unlock(&mddev->open_mutex);
7671-
sync_blockdev(bdev);
7679+
err = mddev_set_closing_and_sync_blockdev(mddev, 1);
7680+
if (err)
7681+
return err;
76727682
}
76737683

76747684
if (!md_is_rdwr(mddev))

0 commit comments

Comments
 (0)