Skip to content

Commit af8d8e6

Browse files
GuoqingJiangshligit
authored andcommitted
md: changes for MD_STILL_CLOSED flag
When stop clustered raid while it is pending on resync, MD_STILL_CLOSED flag could be cleared since udev rule is triggered to open the mddev. So obviously array can't be stopped soon and returns EBUSY. mdadm -Ss md-raid-arrays.rules set MD_STILL_CLOSED md_open() ... ... ... clear MD_STILL_CLOSED do_md_stop We make below changes to resolve this issue: 1. rename MD_STILL_CLOSED to MD_CLOSING since it is set when stop array and it means we are stopping array. 2. let md_open returns early if CLOSING is set, so no other threads will open array if one thread is trying to close it. 3. no need to clear CLOSING bit in md_open because 1 has ensure the bit is cleared, then we also don't need to test CLOSING bit in do_md_stop. Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: Guoqing Jiang <gqjiang@suse.com> Signed-off-by: Shaohua Li <shli@fb.com>
1 parent e3f924d commit af8d8e6

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

drivers/md/md.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5573,8 +5573,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
55735573
mutex_lock(&mddev->open_mutex);
55745574
if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
55755575
mddev->sync_thread ||
5576-
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
5577-
(bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
5576+
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
55785577
printk("md: %s still in use.\n",mdname(mddev));
55795578
if (did_freeze) {
55805579
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
@@ -5636,8 +5635,7 @@ static int do_md_stop(struct mddev *mddev, int mode,
56365635
if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
56375636
mddev->sysfs_active ||
56385637
mddev->sync_thread ||
5639-
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
5640-
(bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
5638+
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
56415639
printk("md: %s still in use.\n",mdname(mddev));
56425640
mutex_unlock(&mddev->open_mutex);
56435641
if (did_freeze) {
@@ -6826,7 +6824,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
68266824
err = -EBUSY;
68276825
goto out;
68286826
}
6829-
set_bit(MD_STILL_CLOSED, &mddev->flags);
6827+
set_bit(MD_CLOSING, &mddev->flags);
68306828
mutex_unlock(&mddev->open_mutex);
68316829
sync_blockdev(bdev);
68326830
}
@@ -7075,9 +7073,13 @@ static int md_open(struct block_device *bdev, fmode_t mode)
70757073
if ((err = mutex_lock_interruptible(&mddev->open_mutex)))
70767074
goto out;
70777075

7076+
if (test_bit(MD_CLOSING, &mddev->flags)) {
7077+
mutex_unlock(&mddev->open_mutex);
7078+
return -ENODEV;
7079+
}
7080+
70787081
err = 0;
70797082
atomic_inc(&mddev->openers);
7080-
clear_bit(MD_STILL_CLOSED, &mddev->flags);
70817083
mutex_unlock(&mddev->open_mutex);
70827084

70837085
check_disk_change(bdev);

drivers/md/md.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,8 @@ struct mddev {
201201
#define MD_CHANGE_PENDING 2 /* switch from 'clean' to 'active' in progress */
202202
#define MD_UPDATE_SB_FLAGS (1 | 2 | 4) /* If these are set, md_update_sb needed */
203203
#define MD_ARRAY_FIRST_USE 3 /* First use of array, needs initialization */
204-
#define MD_STILL_CLOSED 4 /* If set, then array has not been opened since
205-
* md_ioctl checked on it.
206-
*/
204+
#define MD_CLOSING 4 /* If set, we are closing the array, do not open
205+
* it then */
207206
#define MD_JOURNAL_CLEAN 5 /* A raid with journal is already clean */
208207
#define MD_HAS_JOURNAL 6 /* The raid array has journal feature set */
209208
#define MD_RELOAD_SB 7 /* Reload the superblock because another node

0 commit comments

Comments
 (0)