Re: [PATCH 5/7] block: Find bio sector offset given idx and offset

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jens Axboe
Date: Wednesday, October 1, 2008 - 1:10 am

On Wed, Oct 01 2008, Martin K. Petersen wrote:

Too may BUG's there, me thinks, and the interface looks fragile. What if
the bio is alreday done (bi_idx == bi_vcnt)? I'd prefer something ala:

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;

        /* total start of bio current start? */
#if 0
        if (index >= bio->bi_vcnt)
                index = bio->bi_vcnt - 1;

        __bio_for_each_segment(bv, bio, i, 0) {
#else
        if (index > bio->bi_idx)
                return 0;

	bio_for_each_segment(bv, bio, i) {
#endif
		if (i == index) {
			if (offset > bv->bv_offset)
				sectors += (offset - bv->bv_offset) / sector_sz;
                        break;
		}

		sectors += bv->bv_len / sector_sz;
	}

        return sectors;
}

Depending on which interface you want, pick one of the if/else parts :-)

-- 
Jens Axboe

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Block integrity patches for 2.6.28, Martin K. Petersen, (Wed Oct 1, 12:38 am)
[PATCH 1/7] block: Introduce integrity data ownership flag, Martin K. Petersen, (Wed Oct 1, 12:38 am)
[PATCH 2/7] block: Fix double put in blk_integrity_unregister, Martin K. Petersen, (Wed Oct 1, 12:38 am)
[PATCH 3/7] block: Switch blk_integrity_compare from bdev ..., Martin K. Petersen, (Wed Oct 1, 12:38 am)
[PATCH 4/7] block: gendisk integrity wrapper, Martin K. Petersen, (Wed Oct 1, 12:38 am)
[PATCH 5/7] block: Find bio sector offset given idx and offset, Martin K. Petersen, (Wed Oct 1, 12:38 am)
[PATCH 6/7] dm: Add support for data integrity to DM, Martin K. Petersen, (Wed Oct 1, 12:38 am)
[PATCH 7/7] md: Add support for data integrity to MD, Martin K. Petersen, (Wed Oct 1, 12:38 am)
Re: [PATCH 5/7] block: Find bio sector offset given idx an ..., Jens Axboe, (Wed Oct 1, 1:10 am)
Re: [PATCH 5/7] block: Find bio sector offset given idx an ..., Martin K. Petersen, (Wed Oct 1, 7:42 pm)
Re: Block integrity patches for 2.6.28, Jens Axboe, (Thu Oct 2, 3:56 am)
Re: Block integrity patches for 2.6.28, Martin K. Petersen, (Thu Oct 2, 6:54 am)
Re: Block integrity patches for 2.6.28, Jens Axboe, (Thu Oct 2, 9:29 am)