Commit d73f9907 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Mike Snitzer

dm io: fix I/O to multiple destinations

Commit 003b5c57 ("block: Convert drivers
to immutable biovecs") broke dm-mirror due to dm-io breakage.

dm-io had three possible iterators (DM_IO_PAGE_LIST, DM_IO_BVEC,
DM_IO_VMA) that iterate over pages where the I/O should be performed.

The switch to immutable biovecs changed the DM_IO_BVEC iterator to
DM_IO_BIO.  Before this change the iterator stored the pointer to a bio
vector in the dpages structure.  The iterator incremented the pointer in
the dpages structure as it advanced over the pages.  After the immutable
biovecs change, the DM_IO_BIO iterator stores a pointer to the bio in
the dpages structure and uses bio_advance to change the bio as it
advances.

The problem is that the function dispatch_io stores the content of the
dpages structure into the variable old_pages and restores it before
issuing I/O to each of the devices.  Before the change, the statement
"*dp = old_pages;" restored the iterator to its starting position.
After the change, struct dpages holds a pointer to the bio, thus the
statement "*dp = old_pages;" doesn't restore the iterator.

Consequently, in the context of dm-mirror: only the first mirror leg is
written correctly, the kernel locks up when trying to write the other
mirror legs because the number of sectors to write in the where->count
variable doesn't match the number of sectors returned by the iterator.

This patch fixes the bug by partially reverting the original patch - it
changes the code so that struct dpages holds a pointer to the bio vector,
so that the statement "*dp = old_pages;" restores the iterator correctly.

The field "context_u" holds the offset from the beginning of the current
bio vector entry, just like the "bio->bi_iter.bi_bvec_done" field.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent 4d1662a3
...@@ -201,29 +201,28 @@ static void list_dp_init(struct dpages *dp, struct page_list *pl, unsigned offse ...@@ -201,29 +201,28 @@ static void list_dp_init(struct dpages *dp, struct page_list *pl, unsigned offse
/* /*
* Functions for getting the pages from a bvec. * Functions for getting the pages from a bvec.
*/ */
static void bio_get_page(struct dpages *dp, static void bio_get_page(struct dpages *dp, struct page **p,
struct page **p, unsigned long *len, unsigned *offset) unsigned long *len, unsigned *offset)
{ {
struct bio *bio = dp->context_ptr; struct bio_vec *bvec = dp->context_ptr;
struct bio_vec bvec = bio_iovec(bio); *p = bvec->bv_page;
*p = bvec.bv_page; *len = bvec->bv_len - dp->context_u;
*len = bvec.bv_len; *offset = bvec->bv_offset + dp->context_u;
*offset = bvec.bv_offset;
} }
static void bio_next_page(struct dpages *dp) static void bio_next_page(struct dpages *dp)
{ {
struct bio *bio = dp->context_ptr; struct bio_vec *bvec = dp->context_ptr;
struct bio_vec bvec = bio_iovec(bio); dp->context_ptr = bvec + 1;
dp->context_u = 0;
bio_advance(bio, bvec.bv_len);
} }
static void bio_dp_init(struct dpages *dp, struct bio *bio) static void bio_dp_init(struct dpages *dp, struct bio *bio)
{ {
dp->get_page = bio_get_page; dp->get_page = bio_get_page;
dp->next_page = bio_next_page; dp->next_page = bio_next_page;
dp->context_ptr = bio; dp->context_ptr = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
dp->context_u = bio->bi_iter.bi_bvec_done;
} }
/* /*
......
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