block: Find bio sector offset given idx and offset
Subsystems (2)
PATCH 1/1 block: Find bio sector offset given idx and offset
Helper function to find the sector offset in a bio given bvec index and page offset.
Signed-off-by Martin K. Petersen <[email protected]>
--- fs/bio.c | 24 ++++++++++++++++++++++++ include/linux/bio.h | 2 ++ 2 files changed, 26 insertions(+), 0 deletions(-)
fs/bio.c +24 -0
@@ -1300,6 +1300,30 @@ struct bio_pair *bio_split(struct bio *bi, mempool_t *pool, int first_sectors)return bp; } +sector_t bio_sector_offset (struct bio *bio,unsigned short index,unsigned int offset) +{ +struct bio_vec *bv; +unsigned int sector_sz = bio->bi_bdev->bd_disk->queue->hardsect_size; +sector_t sectors; +int i; + + sectors =0 ; + +BUG_ON (index >= bio->bi_vcnt); + +bio_for_each_segment (bv, bio, i) { +if (i == index) { +if (offset > bv->bv_offset) + sectors += (offset - bv->bv_offset) / sector_sz; +return sectors; + } + + sectors += bv->bv_len / sector_sz; + } + +BUG (); +} +EXPORT_SYMBOL (bio_sector_offset);/* * create memory pools for biovec's in a bio_set.
include/linux/bio.h +2 -0
@@ -327,6 +327,8 @@ 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 ;
Signature · 1 line
1.5.5.1
Quoted 18 lines · On Sat, 20 Sep 2008 20:13:29 -0400 "Martin K. Petersen"…
fs/bio.c +14
-0@@ -1300,6 +1300,30 @@ struct bio_pair *bio_split(struct bio *bi, mempool_t *pool, int first_sectors)return bp; } +sector_t bio_sector_offset (struct bio *bio,unsigned short index,unsigned int offset) +{ +struct bio_vec *bv; +unsigned int sector_sz = bio->bi_bdev->bd_disk->queue->hardsect_size; +sector_t sectors; +int i; + + sectors =0 ; + +BUG_ON (index >= bio->bi_vcnt); + +bio_for_each_segment (bv, bio, i) { +if (i == index) { +if (offset > bv->bv_offset)
fs/bio.c struct bio_pair *bio_split(struct bio *bi, mempool_t *pool, int first_sectors) · line 1326
Quoted 10 lines
fs/bio.c +10
-0+ sectors += (offset - bv->bv_offset) / sector_sz; +return sectors; + } + + sectors += bv->bv_len / sector_sz; + } + +BUG (); +} +EXPORT_SYMBOL (bio_sector_offset);
Please avoid sending out kenrel-wide exported-to-modules utility functions which have no documentation.
Not only is it a bad thing from a maintainability and reliability point of view - it also makes code review significantly less effective.