diff options
author | NeilBrown <neilb@suse.com> | 2017-06-05 02:49:39 -0400 |
---|---|---|
committer | Shaohua Li <shli@fb.com> | 2017-06-13 13:18:01 -0400 |
commit | cc27b0c78c79680d128dbac79de0d40556d041bb (patch) | |
tree | 1f32d4acd29d825eecc1aef90d423cdacea8121c /drivers/md/raid1.c | |
parent | 63f700aab4c11d46626de3cd051dae56cf7e9056 (diff) |
md: fix deadlock between mddev_suspend() and md_write_start()
If mddev_suspend() races with md_write_start() we can deadlock
with mddev_suspend() waiting for the request that is currently
in md_write_start() to complete the ->make_request() call,
and md_write_start() waiting for the metadata to be updated
to mark the array as 'dirty'.
As metadata updates done by md_check_recovery() only happen then
the mddev_lock() can be claimed, and as mddev_suspend() is often
called with the lock held, these threads wait indefinitely for each
other.
We fix this by having md_write_start() abort if mddev_suspend()
is happening, and ->make_request() aborts if md_write_start()
aborted.
md_make_request() can detect this abort, decrease the ->active_io
count, and wait for mddev_suspend().
Reported-by: Nix <nix@esperi.org.uk>
Fix: 68866e425be2(MD: no sync IO while suspended)
Cc: stable@vger.kernel.org
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
Diffstat (limited to 'drivers/md/raid1.c')
-rw-r--r-- | drivers/md/raid1.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index e1a7e3d4c5e4..c71739b87ab7 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c | |||
@@ -1321,7 +1321,6 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, | |||
1321 | * Continue immediately if no resync is active currently. | 1321 | * Continue immediately if no resync is active currently. |
1322 | */ | 1322 | */ |
1323 | 1323 | ||
1324 | md_write_start(mddev, bio); /* wait on superblock update early */ | ||
1325 | 1324 | ||
1326 | if ((bio_end_sector(bio) > mddev->suspend_lo && | 1325 | if ((bio_end_sector(bio) > mddev->suspend_lo && |
1327 | bio->bi_iter.bi_sector < mddev->suspend_hi) || | 1326 | bio->bi_iter.bi_sector < mddev->suspend_hi) || |
@@ -1550,13 +1549,13 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, | |||
1550 | wake_up(&conf->wait_barrier); | 1549 | wake_up(&conf->wait_barrier); |
1551 | } | 1550 | } |
1552 | 1551 | ||
1553 | static void raid1_make_request(struct mddev *mddev, struct bio *bio) | 1552 | static bool raid1_make_request(struct mddev *mddev, struct bio *bio) |
1554 | { | 1553 | { |
1555 | sector_t sectors; | 1554 | sector_t sectors; |
1556 | 1555 | ||
1557 | if (unlikely(bio->bi_opf & REQ_PREFLUSH)) { | 1556 | if (unlikely(bio->bi_opf & REQ_PREFLUSH)) { |
1558 | md_flush_request(mddev, bio); | 1557 | md_flush_request(mddev, bio); |
1559 | return; | 1558 | return true; |
1560 | } | 1559 | } |
1561 | 1560 | ||
1562 | /* | 1561 | /* |
@@ -1571,8 +1570,12 @@ static void raid1_make_request(struct mddev *mddev, struct bio *bio) | |||
1571 | 1570 | ||
1572 | if (bio_data_dir(bio) == READ) | 1571 | if (bio_data_dir(bio) == READ) |
1573 | raid1_read_request(mddev, bio, sectors, NULL); | 1572 | raid1_read_request(mddev, bio, sectors, NULL); |
1574 | else | 1573 | else { |
1574 | if (!md_write_start(mddev,bio)) | ||
1575 | return false; | ||
1575 | raid1_write_request(mddev, bio, sectors); | 1576 | raid1_write_request(mddev, bio, sectors); |
1577 | } | ||
1578 | return true; | ||
1576 | } | 1579 | } |
1577 | 1580 | ||
1578 | static void raid1_status(struct seq_file *seq, struct mddev *mddev) | 1581 | static void raid1_status(struct seq_file *seq, struct mddev *mddev) |