md:array cannot be opened again after 'md_set_readonly'
PATCH 1/1 md:array cannot be opened again after 'md_set_readonly'
This is a bug about array cannot be opened again after 'md_set_readonly', because the MD_CLOSING bit is still waiting for clear. MD_CLOSING should only be set for a short period or time to avoid certain races. After the operation that set it completes, it should be cleared.
--- drivers/md/md.c | 1 + 1 file changed, 1 insertion(+)
drivers/md/md.c +1 -0
@@ -5588,6 +5588,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)int err =0 ;int did_freeze =0 ; +test_and_clear_bit (MD_CLOSING , &mddev->flags);if (!test_bit (MD_RECOVERY_FROZEN , &mddev->recovery)) { did_freeze =1 ;set_bit (MD_RECOVERY_FROZEN , &mddev->recovery);
Signature · 1 line
2.6.6
Quoted 4 lines · Zhilong Liu
This is a bug about array cannot be opened again after '
md_set_readonly', because theMD_CLOSINGbit is still waiting for clear.MD_CLOSINGshould only be set for a short period or time to avoid certain races. After the operation that set it completes, it should be cleared.
where is the bit set? Why don't clear it after the operation but clear it in set_readonly?
Quoted 12 lines
Reviewed-by NeilBrown <[email protected]>Cc Guoqing Jiang <[email protected]>Signed-off-by Zhilong Liu <[email protected]>--- drivers/md/md.c | 1 + 1 file changed, 1 insertion(+)drivers/md/md.c +0
-0
drivers/md/md.c static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) · line 5591
Quoted 4 lines
drivers/md/md.c +1
-0@@ -5588,6 +5588,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)int err =0 ;int did_freeze =0 ; +test_and_clear_bit (MD_CLOSING , &mddev->flags);
I don't understand why this must be a test_and_clear.
Thanks,
Shaohua
Quoted 8 lines · Shaohua Li
Quoted 4 lines · Zhilong Liu
This is a bug about array cannot be opened again after '
md_set_readonly', because theMD_CLOSINGbit is still waiting for clear.MD_CLOSINGshould only be set for a short period or time to avoid certain races. After the operation that set it completes, it should be cleared.where is the bit set? Why don't clear it after the operation but clear it in
set_readonly?
it goes two paths after set MD_CLOSING bit, do_md_stop and md_set_readonly, the do_md_stop has done the md_clean to clear the mddev->flags, thus I put it in md_set_readonly.
Thanks for your suggestion, is the following changing good for you? here it has finished what it needs to do, so clear the MD_CLOSING bit in time. if looks good, I would send this in new revision patch.
drivers/md/md.c +1 -0
@@ -6868,6 +6868,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,set_bit (MD_CLOSING , &mddev->flags);mutex_unlock (&mddev->open_mutex);sync_blockdev (bdev); +clear_bit (MD_CLOSING , &mddev->flags); } err =mddev_lock (mddev);if (err) {
Thanks,
-Zhilong
Quoted 25 lines
Quoted 12 lines
Reviewed-by NeilBrown <[email protected]>Cc Guoqing Jiang <[email protected]>Signed-off-by Zhilong Liu <[email protected]>--- drivers/md/md.c | 1 + 1 file changed, 1 insertion(+)drivers/md/md.c +0
-0drivers/md/md.c static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) · line 5591
Quoted 4 lines
drivers/md/md.c +1
-0@@ -5588,6 +5588,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)int err =0 ;int did_freeze =0 ; +test_and_clear_bit (MD_CLOSING , &mddev->flags);I don't understand why this must be a
test_and_clear.Thanks,
Shaohua
--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 31 lines · Zhilong Liu
Quoted 7 lines · Shaohua Li
Quoted 4 lines · Zhilong Liu
This is a bug about array cannot be opened again after '
md_set_readonly', because theMD_CLOSINGbit is still waiting for clear.MD_CLOSINGshould only be set for a short period or time to avoid certain races. After the operation that set it completes, it should be cleared.where is the bit set? Why don't clear it after the operation but clear it in
set_readonly?it goes two paths after set
MD_CLOSINGbit,do_md_stopandmd_set_readonly, thedo_md_stophas done themd_cleanto clear themddev->flags, thus I put it inmd_set_readonly.
Thanks for your suggestion, is the following changing good for you? here it has
finished what it needs to do, so clear theMD_CLOSINGbit in time. if looks good, I would send this in new revision patch.drivers/md/md.c +1
-0@@ -6868,6 +6868,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,set_bit (MD_CLOSING , &mddev->flags);mutex_unlock (&mddev->open_mutex);sync_blockdev (bdev); +clear_bit (MD_CLOSING , &mddev->flags); } err =mddev_lock (mddev);
Quoted 1 line
if (err) {It would be better done at the end of set_readonly to guarantee set ro done.
Thanks,
Shaohua
Quoted 27 lines
Thanks,
-ZhilongQuoted 24 lines
Quoted 12 lines
Reviewed-by NeilBrown <[email protected]>Cc Guoqing Jiang <[email protected]>Signed-off-by Zhilong Liu <[email protected]>--- drivers/md/md.c | 1 + 1 file changed, 1 insertion(+)drivers/md/md.c +0
-0drivers/md/md.c static int md_set_readonly(struct mddev *mddev, struct block_device *bdev) · line 5590
Quoted 3 lines
drivers/md/md.c +1
-0@@ -5588,6 +5588,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)int err =0 ;int did_freeze =0 ; +test_and_clear_bit (MD_CLOSING , &mddev->flags);I don't understand why this must be a
test_and_clear.Thanks,
Shaohua
--
To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 24 lines · Zhilong Liu
Quoted 8 lines · Shaohua Li
Quoted 4 lines · Zhilong Liu
This is a bug about array cannot be opened again after '
md_set_readonly', because theMD_CLOSINGbit is still waiting for clear.MD_CLOSINGshould only be set for a short period or time to avoid certain races. After the operation that set it completes, it should be cleared.where is the bit set? Why don't clear it after the operation but clear it in
set_readonly?it goes two paths after set
MD_CLOSINGbit,do_md_stopandmd_set_readonly, thedo_md_stophas done themd_cleanto clear themddev->flags, thus I put it inmd_set_readonly.
Thanks for your suggestion, is the following changing good for you? here it has
finished what it needs to do, so clear theMD_CLOSINGbit in time. if looks good, I would send this in new revision patch.drivers/md/md.c +0
-0
drivers/md/md.c static int md_ioctl(struct block_device *bdev, · line 6872
Quoted 5 lines
drivers/md/md.c +1
-0@@ -6868,6 +6868,7 @@ static int md_ioctl(struct block_device *bdev,fmode_t mode, set_bit(MD_CLOSING, &mddev->flags);mutex_unlock (&mddev->open_mutex);sync_blockdev (bdev); +clear_bit (MD_CLOSING , &mddev->flags);
No.
MD_CLOSING is used to prevent a race with md_open(). md_open() blocks on open_mutex(), but we cannot hold that here for complicated reasons.
So we set MD_CLOSING and need to keep it set at least until md_set_readonly() or do_md_stop() take that lock again.
Clearing it here just opens up the race again.
It needs to be cleared in md_ioctl, after any call to md_set_readonly() or do_md_stop().
I've already posted a sample patch which has been tested. Please don't do something completely different.
NeilBrown
Quoted 6 lines · Zhilong Liu
This is a bug about array cannot be opened again after '
md_set_readonly', because theMD_CLOSINGbit is still waiting for clear.MD_CLOSINGshould only be set for a short period or time to avoid certain races. After the operation that set it completes, it should be cleared.Reviewed-by NeilBrown <[email protected]>
No I didn't. I never reviewed this patch. I don't agree with this patch. This patch is wrong.
The flag is set in md_ioctl(), and it should be cleared in md_ioctl().
NeilBrown
Quoted 20 lines
Cc Guoqing Jiang <[email protected]>Signed-off-by Zhilong Liu <[email protected]>--- drivers/md/md.c | 1 + 1 file changed, 1 insertion(+)drivers/md/md.c +1
-0@@ -5588,6 +5588,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)int err =0 ;int did_freeze =0 ; +test_and_clear_bit (MD_CLOSING , &mddev->flags);if (!test_bit (MD_RECOVERY_FROZEN , &mddev->recovery)) { did_freeze =1 ;set_bit (MD_RECOVERY_FROZEN , &mddev->recovery);Signature · 1 line
2.6.6