Skip to contentSkip to conversation

md: fix deadlock error in recent patch.

PATCH In review NeilBrown 2 participants 2 messages Oct 5, 2017 MD RAID

lore
Share & tools
lore

NeilBrown

author
#0 lore raw

PATCH 1/1 md: fix deadlock error in recent patch.

A recent patch aimed to cause md_write_start() to fail (rather than block) when the mddev was suspending, so as to avoid deadlocks. Unfortunately the test in wait_event() was wrong, and it didn't change behaviour at all.

We wait_event() must wait until the metadata is written OR the array is suspending.

Fixes cc27b0c78c79 ("md: fix deadlock between mddev_suspend() and md_write_start()")
---
 drivers/md/md.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +2 -1
index 0ff1bbf6c90e..8b2eb0f4122f 100644
@@ -8039,7 +8039,8 @@ bool md_write_start(struct mddev *mddev, struct bio *bi)
 	if (did_change)
 		sysfs_notify_dirent_safe(mddev->sysfs_state);
 	wait_event(mddev->sb_wait,
-		   !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags) && !mddev->suspended);
+		   !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags) ||
+		   mddev->suspended);
 	if (test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) {
 		percpu_ref_put(&mddev->writes_pending);
 		return false;
Signature · 1 line
2.14.0.rc0.dirty
#1 lore raw
Quoted 8 lines · Neil Brown

A recent patch aimed to cause md_write_start() to fail (rather than block) when the mddev was suspending, so as to avoid deadlocks. Unfortunately the test in wait_event() was wrong, and it didn't change behaviour at all.

We wait_event() must wait until the metadata is written OR the array is suspending.

Ouch, probably suspended isn't set normally, so it doesn't get caught. Applied, thanks Neil and Xiao!

Quoted 25 lines
Fixes cc27b0c78c79 ("md: fix deadlock between mddev_suspend() and md_write_start()")
---
 drivers/md/md.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/md.c +2 -1
index 0ff1bbf6c90e..8b2eb0f4122f 100644
@@ -8039,7 +8039,8 @@ bool md_write_start(struct mddev *mddev, struct bio *bi)
 	if (did_change)
 		sysfs_notify_dirent_safe(mddev->sysfs_state);
 	wait_event(mddev->sb_wait,
-		   !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags) && !mddev->suspended);
+		   !test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags) ||
+		   mddev->suspended);
 	if (test_bit(MD_SB_CHANGE_PENDING, &mddev->sb_flags)) {
 		percpu_ref_put(&mddev->writes_pending);
 		return false;
Signature · 1 line
2.14.0.rc0.dirty