Skip to content

Commit

Permalink
dm io: use bvec iterator helpers to implement .get_page and .next_page
Browse files Browse the repository at this point in the history
Firstly we have mature bvec/bio iterator helper for iterate each
page in one bio, not necessary to reinvent a wheel to do that.

Secondly the coming multipage bvecs requires this patch.

Also add comments about the direct access to bvec table.

Signed-off-by: Ming Lei <[email protected]>
Signed-off-by: Mike Snitzer <[email protected]>
  • Loading branch information
ming1 authored and snitm committed Nov 21, 2016
1 parent 4f9c74c commit cacc7b0
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions drivers/md/dm-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ struct dpages {
struct page **p, unsigned long *len, unsigned *offset);
void (*next_page)(struct dpages *dp);

unsigned context_u;
union {
unsigned context_u;
struct bvec_iter context_bi;
};
void *context_ptr;

void *vma_invalidate_address;
Expand Down Expand Up @@ -204,25 +207,36 @@ static void list_dp_init(struct dpages *dp, struct page_list *pl, unsigned offse
static void bio_get_page(struct dpages *dp, struct page **p,
unsigned long *len, unsigned *offset)
{
struct bio_vec *bvec = dp->context_ptr;
*p = bvec->bv_page;
*len = bvec->bv_len - dp->context_u;
*offset = bvec->bv_offset + dp->context_u;
struct bio_vec bvec = bvec_iter_bvec((struct bio_vec *)dp->context_ptr,
dp->context_bi);

*p = bvec.bv_page;
*len = bvec.bv_len;
*offset = bvec.bv_offset;

/* avoid figuring it out again in bio_next_page() */
dp->context_bi.bi_sector = (sector_t)bvec.bv_len;
}

static void bio_next_page(struct dpages *dp)
{
struct bio_vec *bvec = dp->context_ptr;
dp->context_ptr = bvec + 1;
dp->context_u = 0;
unsigned int len = (unsigned int)dp->context_bi.bi_sector;

bvec_iter_advance((struct bio_vec *)dp->context_ptr,
&dp->context_bi, len);
}

static void bio_dp_init(struct dpages *dp, struct bio *bio)
{
dp->get_page = bio_get_page;
dp->next_page = bio_next_page;
dp->context_ptr = __bvec_iter_bvec(bio->bi_io_vec, bio->bi_iter);
dp->context_u = bio->bi_iter.bi_bvec_done;

/*
* We just use bvec iterator to retrieve pages, so it is ok to
* access the bvec table directly here
*/
dp->context_ptr = bio->bi_io_vec;
dp->context_bi = bio->bi_iter;
}

/*
Expand Down

0 comments on commit cacc7b0

Please sign in to comment.