Skip to content

Commit 9674f54

Browse files
Li Nanliu-song-6
authored andcommitted
md: Don't clear MD_CLOSING when the raid is about to stop
The raid should not be opened anymore when it is about to be stopped. However, other processes can open it again if the flag MD_CLOSING is cleared before exiting. From now on, this flag will not be cleared when the raid will be stopped. Fixes: 065e519 ("md: MD_CLOSING needs to be cleared after called md_set_readonly or do_md_stop") Signed-off-by: Li Nan <[email protected]> Reviewed-by: Yu Kuai <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 91b26a3 commit 9674f54

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/md/md.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6265,7 +6265,15 @@ static void md_clean(struct mddev *mddev)
62656265
mddev->persistent = 0;
62666266
mddev->level = LEVEL_NONE;
62676267
mddev->clevel[0] = 0;
6268-
mddev->flags = 0;
6268+
/*
6269+
* Don't clear MD_CLOSING, or mddev can be opened again.
6270+
* 'hold_active != 0' means mddev is still in the creation
6271+
* process and will be used later.
6272+
*/
6273+
if (mddev->hold_active)
6274+
mddev->flags = 0;
6275+
else
6276+
mddev->flags &= BIT_ULL_MASK(MD_CLOSING);
62696277
mddev->sb_flags = 0;
62706278
mddev->ro = MD_RDWR;
62716279
mddev->metadata_type[0] = 0;
@@ -7603,7 +7611,6 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
76037611
int err = 0;
76047612
void __user *argp = (void __user *)arg;
76057613
struct mddev *mddev = NULL;
7606-
bool did_set_md_closing = false;
76077614

76087615
err = md_ioctl_valid(cmd);
76097616
if (err)
@@ -7660,7 +7667,6 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
76607667
mutex_unlock(&mddev->open_mutex);
76617668
return -EBUSY;
76627669
}
7663-
did_set_md_closing = true;
76647670
mutex_unlock(&mddev->open_mutex);
76657671
sync_blockdev(bdev);
76667672
}
@@ -7802,7 +7808,7 @@ static int md_ioctl(struct block_device *bdev, blk_mode_t mode,
78027808
mddev_unlock(mddev);
78037809

78047810
out:
7805-
if(did_set_md_closing)
7811+
if (cmd == STOP_ARRAY_RO || (err && cmd == STOP_ARRAY))
78067812
clear_bit(MD_CLOSING, &mddev->flags);
78077813
return err;
78087814
}

0 commit comments

Comments
 (0)