From 703828a3387215ad880edf0f632b6a1528efe95c Mon Sep 17 00:00:00 2001 From: "Martin K. Petersen" Date: Wed, 1 Oct 2008 22:42:53 -0400 Subject: [PATCH] --- yaml --- r: 110568 b: refs/heads/master c: ad3316bf4eeb53c89164f759767f911072b56203 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/fs/bio.c | 36 ++++++++++++++++++++++++++++++++++++ trunk/include/linux/bio.h | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 1368c39d3e8c..2d0959ecd793 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: b02739b01c5309d74a59859f2ce92c931d1f1955 +refs/heads/master: ad3316bf4eeb53c89164f759767f911072b56203 diff --git a/trunk/fs/bio.c b/trunk/fs/bio.c index e56e7685af9c..a5af5809f566 100644 --- a/trunk/fs/bio.c +++ b/trunk/fs/bio.c @@ -1300,6 +1300,42 @@ struct bio_pair *bio_split(struct bio *bi, mempool_t *pool, int first_sectors) return bp; } +/** + * bio_sector_offset - Find hardware sector offset in bio + * @bio: bio to inspect + * @index: bio_vec index + * @offset: offset in bv_page + * + * Return the number of hardware sectors between beginning of bio + * and an end point indicated by a bio_vec index and an offset + * within that vector's page. + */ +sector_t bio_sector_offset(struct bio *bio, unsigned short index, + unsigned int offset) +{ + unsigned int sector_sz = queue_hardsect_size(bio->bi_bdev->bd_disk->queue); + struct bio_vec *bv; + sector_t sectors; + int i; + + sectors = 0; + + if (index >= bio->bi_idx) + index = bio->bi_vcnt - 1; + + __bio_for_each_segment(bv, bio, i, 0) { + if (i == index) { + if (offset > bv->bv_offset) + sectors += (offset - bv->bv_offset) / sector_sz; + break; + } + + sectors += bv->bv_len / sector_sz; + } + + return sectors; +} +EXPORT_SYMBOL(bio_sector_offset); /* * create memory pools for biovec's in a bio_set. diff --git a/trunk/include/linux/bio.h b/trunk/include/linux/bio.h index d86d39d490e6..fe12d0f9ebaa 100644 --- a/trunk/include/linux/bio.h +++ b/trunk/include/linux/bio.h @@ -327,6 +327,7 @@ extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int); extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *, unsigned int, unsigned int); extern int bio_get_nr_vecs(struct block_device *); +extern sector_t bio_sector_offset(struct bio *, unsigned short, unsigned int); extern struct bio *bio_map_user(struct request_queue *, struct block_device *, unsigned long, unsigned int, int, gfp_t); struct sg_iovec;