Commit 270c1bc3 authored by Shaohua Li's avatar Shaohua Li Committed by Greg Kroah-Hartman

md/raid1: fix writebehind bio clone

commit 16d56e2f upstream.

After bio is submitted, we should not clone it as its bi_iter might be
invalid by driver. This is the case of behind_master_bio. In certain
situration, we could dispatch behind_master_bio immediately for the
first disk and then clone it for other disks.

https://bugzilla.kernel.org/show_bug.cgi?id=196383Reported-and-tested-by: default avatarMarkus <m4rkusxxl@web.de>
Reviewed-by: default avatarMing Lei <ming.lei@redhat.com>
Fix: 841c1316(md: raid1: improve write behind)
Signed-off-by: default avatarShaohua Li <shli@fb.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b70f86ce
...@@ -491,10 +491,6 @@ static void raid1_end_write_request(struct bio *bio) ...@@ -491,10 +491,6 @@ static void raid1_end_write_request(struct bio *bio)
} }
if (behind) { if (behind) {
/* we release behind master bio when all write are done */
if (r1_bio->behind_master_bio == bio)
to_put = NULL;
if (test_bit(WriteMostly, &rdev->flags)) if (test_bit(WriteMostly, &rdev->flags))
atomic_dec(&r1_bio->behind_remaining); atomic_dec(&r1_bio->behind_remaining);
...@@ -1087,7 +1083,7 @@ static void unfreeze_array(struct r1conf *conf) ...@@ -1087,7 +1083,7 @@ static void unfreeze_array(struct r1conf *conf)
wake_up(&conf->wait_barrier); wake_up(&conf->wait_barrier);
} }
static struct bio *alloc_behind_master_bio(struct r1bio *r1_bio, static void alloc_behind_master_bio(struct r1bio *r1_bio,
struct bio *bio) struct bio *bio)
{ {
int size = bio->bi_iter.bi_size; int size = bio->bi_iter.bi_size;
...@@ -1097,11 +1093,13 @@ static struct bio *alloc_behind_master_bio(struct r1bio *r1_bio, ...@@ -1097,11 +1093,13 @@ static struct bio *alloc_behind_master_bio(struct r1bio *r1_bio,
behind_bio = bio_alloc_mddev(GFP_NOIO, vcnt, r1_bio->mddev); behind_bio = bio_alloc_mddev(GFP_NOIO, vcnt, r1_bio->mddev);
if (!behind_bio) if (!behind_bio)
goto fail; return;
/* discard op, we don't support writezero/writesame yet */ /* discard op, we don't support writezero/writesame yet */
if (!bio_has_data(bio)) if (!bio_has_data(bio)) {
behind_bio->bi_iter.bi_size = size;
goto skip_copy; goto skip_copy;
}
while (i < vcnt && size) { while (i < vcnt && size) {
struct page *page; struct page *page;
...@@ -1122,14 +1120,13 @@ static struct bio *alloc_behind_master_bio(struct r1bio *r1_bio, ...@@ -1122,14 +1120,13 @@ static struct bio *alloc_behind_master_bio(struct r1bio *r1_bio,
r1_bio->behind_master_bio = behind_bio;; r1_bio->behind_master_bio = behind_bio;;
set_bit(R1BIO_BehindIO, &r1_bio->state); set_bit(R1BIO_BehindIO, &r1_bio->state);
return behind_bio; return;
free_pages: free_pages:
pr_debug("%dB behind alloc failed, doing sync I/O\n", pr_debug("%dB behind alloc failed, doing sync I/O\n",
bio->bi_iter.bi_size); bio->bi_iter.bi_size);
bio_free_pages(behind_bio); bio_free_pages(behind_bio);
fail: bio_put(behind_bio);
return behind_bio;
} }
struct raid1_plug_cb { struct raid1_plug_cb {
...@@ -1482,7 +1479,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, ...@@ -1482,7 +1479,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
(atomic_read(&bitmap->behind_writes) (atomic_read(&bitmap->behind_writes)
< mddev->bitmap_info.max_write_behind) && < mddev->bitmap_info.max_write_behind) &&
!waitqueue_active(&bitmap->behind_wait)) { !waitqueue_active(&bitmap->behind_wait)) {
mbio = alloc_behind_master_bio(r1_bio, bio); alloc_behind_master_bio(r1_bio, bio);
} }
bitmap_startwrite(bitmap, r1_bio->sector, bitmap_startwrite(bitmap, r1_bio->sector,
...@@ -1492,14 +1489,11 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, ...@@ -1492,14 +1489,11 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
first_clone = 0; first_clone = 0;
} }
if (!mbio) { if (r1_bio->behind_master_bio)
if (r1_bio->behind_master_bio) mbio = bio_clone_fast(r1_bio->behind_master_bio,
mbio = bio_clone_fast(r1_bio->behind_master_bio, GFP_NOIO, mddev->bio_set);
GFP_NOIO, else
mddev->bio_set); mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
else
mbio = bio_clone_fast(bio, GFP_NOIO, mddev->bio_set);
}
if (r1_bio->behind_master_bio) { if (r1_bio->behind_master_bio) {
if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags)) if (test_bit(WriteMostly, &conf->mirrors[i].rdev->flags))
...@@ -2367,8 +2361,6 @@ static int narrow_write_error(struct r1bio *r1_bio, int i) ...@@ -2367,8 +2361,6 @@ static int narrow_write_error(struct r1bio *r1_bio, int i)
wbio = bio_clone_fast(r1_bio->behind_master_bio, wbio = bio_clone_fast(r1_bio->behind_master_bio,
GFP_NOIO, GFP_NOIO,
mddev->bio_set); mddev->bio_set);
/* We really need a _all clone */
wbio->bi_iter = (struct bvec_iter){ 0 };
} else { } else {
wbio = bio_clone_fast(r1_bio->master_bio, GFP_NOIO, wbio = bio_clone_fast(r1_bio->master_bio, GFP_NOIO,
mddev->bio_set); mddev->bio_set);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment