diff options
author | Nate Dailey <nate.dailey@stratus.com> | 2019-02-07 14:19:01 -0500 |
---|---|---|
committer | Song Liu <songliubraving@fb.com> | 2019-02-12 17:06:58 -0500 |
commit | dfcc34c99f3ebc16b787b118763bf9cb6b1efc7a (patch) | |
tree | 1019fd0794fb6db7465d218b0a7444d8e68ed223 /drivers/md/raid1.c | |
parent | 96d7cb932e826219ec41ac02e5af037ffae6098c (diff) |
md/raid1: don't clear bitmap bits on interrupted recovery.
sync_request_write no longer submits writes to a Faulty device. This has
the unfortunate side effect that bitmap bits can be incorrectly cleared
if a recovery is interrupted (previously, end_sync_write would have
prevented this). This means the next recovery may not copy everything
it should, potentially corrupting data.
Add a function for doing the proper md_bitmap_end_sync, called from
end_sync_write and the Faulty case in sync_request_write.
backport note to 4.14: s/md_bitmap_end_sync/bitmap_end_sync
Cc: stable@vger.kernel.org 4.14+
Fixes: 0c9d5b127f69 ("md/raid1: avoid reusing a resync bio after error handling.")
Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Tested-by: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Nate Dailey <nate.dailey@stratus.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
Diffstat (limited to 'drivers/md/raid1.c')
-rw-r--r-- | drivers/md/raid1.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 1d54109071cc..fa47249fa3e4 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c | |||
@@ -1863,6 +1863,20 @@ static void end_sync_read(struct bio *bio) | |||
1863 | reschedule_retry(r1_bio); | 1863 | reschedule_retry(r1_bio); |
1864 | } | 1864 | } |
1865 | 1865 | ||
1866 | static void abort_sync_write(struct mddev *mddev, struct r1bio *r1_bio) | ||
1867 | { | ||
1868 | sector_t sync_blocks = 0; | ||
1869 | sector_t s = r1_bio->sector; | ||
1870 | long sectors_to_go = r1_bio->sectors; | ||
1871 | |||
1872 | /* make sure these bits don't get cleared. */ | ||
1873 | do { | ||
1874 | md_bitmap_end_sync(mddev->bitmap, s, &sync_blocks, 1); | ||
1875 | s += sync_blocks; | ||
1876 | sectors_to_go -= sync_blocks; | ||
1877 | } while (sectors_to_go > 0); | ||
1878 | } | ||
1879 | |||
1866 | static void end_sync_write(struct bio *bio) | 1880 | static void end_sync_write(struct bio *bio) |
1867 | { | 1881 | { |
1868 | int uptodate = !bio->bi_status; | 1882 | int uptodate = !bio->bi_status; |
@@ -1874,15 +1888,7 @@ static void end_sync_write(struct bio *bio) | |||
1874 | struct md_rdev *rdev = conf->mirrors[find_bio_disk(r1_bio, bio)].rdev; | 1888 | struct md_rdev *rdev = conf->mirrors[find_bio_disk(r1_bio, bio)].rdev; |
1875 | 1889 | ||
1876 | if (!uptodate) { | 1890 | if (!uptodate) { |
1877 | sector_t sync_blocks = 0; | 1891 | abort_sync_write(mddev, r1_bio); |
1878 | sector_t s = r1_bio->sector; | ||
1879 | long sectors_to_go = r1_bio->sectors; | ||
1880 | /* make sure these bits doesn't get cleared. */ | ||
1881 | do { | ||
1882 | md_bitmap_end_sync(mddev->bitmap, s, &sync_blocks, 1); | ||
1883 | s += sync_blocks; | ||
1884 | sectors_to_go -= sync_blocks; | ||
1885 | } while (sectors_to_go > 0); | ||
1886 | set_bit(WriteErrorSeen, &rdev->flags); | 1892 | set_bit(WriteErrorSeen, &rdev->flags); |
1887 | if (!test_and_set_bit(WantReplacement, &rdev->flags)) | 1893 | if (!test_and_set_bit(WantReplacement, &rdev->flags)) |
1888 | set_bit(MD_RECOVERY_NEEDED, & | 1894 | set_bit(MD_RECOVERY_NEEDED, & |
@@ -2172,8 +2178,10 @@ static void sync_request_write(struct mddev *mddev, struct r1bio *r1_bio) | |||
2172 | (i == r1_bio->read_disk || | 2178 | (i == r1_bio->read_disk || |
2173 | !test_bit(MD_RECOVERY_SYNC, &mddev->recovery)))) | 2179 | !test_bit(MD_RECOVERY_SYNC, &mddev->recovery)))) |
2174 | continue; | 2180 | continue; |
2175 | if (test_bit(Faulty, &conf->mirrors[i].rdev->flags)) | 2181 | if (test_bit(Faulty, &conf->mirrors[i].rdev->flags)) { |
2182 | abort_sync_write(mddev, r1_bio); | ||
2176 | continue; | 2183 | continue; |
2184 | } | ||
2177 | 2185 | ||
2178 | bio_set_op_attrs(wbio, REQ_OP_WRITE, 0); | 2186 | bio_set_op_attrs(wbio, REQ_OP_WRITE, 0); |
2179 | if (test_bit(FailFast, &conf->mirrors[i].rdev->flags)) | 2187 | if (test_bit(FailFast, &conf->mirrors[i].rdev->flags)) |