Commit e5cfeed2 authored by Alex Elder's avatar Alex Elder

rbd: simplify rbd_merge_bvec()

The aim of this patch is to make what's going on rbd_merge_bvec() a
bit more obvious than it was before.  This was an issue when a
recent btrfs bug led us to question whether the merge function was
working correctly.

Use "obj" rather than "chunk" to indicate the units whose boundaries
we care about we call (rados) "objects".
Signed-off-by: default avatarAlex Elder <elder@inktank.com>
Reviewed-by: default avatarDan Mick <dan.mick@inktank.com>
parent d4b125e9
...@@ -1566,22 +1566,41 @@ static int rbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bmd, ...@@ -1566,22 +1566,41 @@ static int rbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bmd,
struct bio_vec *bvec) struct bio_vec *bvec)
{ {
struct rbd_device *rbd_dev = q->queuedata; struct rbd_device *rbd_dev = q->queuedata;
unsigned int chunk_sectors; sector_t sector_offset;
sector_t sector; sector_t sectors_per_obj;
unsigned int bio_sectors; sector_t obj_sector_offset;
int max; int ret;
chunk_sectors = 1 << (rbd_dev->header.obj_order - SECTOR_SHIFT); /*
sector = bmd->bi_sector + get_start_sect(bmd->bi_bdev); * Find how far into its rbd object the partition-relative
bio_sectors = bmd->bi_size >> SECTOR_SHIFT; * bio start sector is to offset relative to the enclosing
* device.
max = (chunk_sectors - ((sector & (chunk_sectors - 1)) */
+ bio_sectors)) << SECTOR_SHIFT; sector_offset = get_start_sect(bmd->bi_bdev) + bmd->bi_sector;
if (max < 0) sectors_per_obj = 1 << (rbd_dev->header.obj_order - SECTOR_SHIFT);
max = 0; /* bio_add cannot handle a negative return */ obj_sector_offset = sector_offset & (sectors_per_obj - 1);
if (max <= bvec->bv_len && bio_sectors == 0)
return bvec->bv_len; /*
return max; * Compute the number of bytes from that offset to the end
* of the object. Account for what's already used by the bio.
*/
ret = (int) (sectors_per_obj - obj_sector_offset) << SECTOR_SHIFT;
if (ret > bmd->bi_size)
ret -= bmd->bi_size;
else
ret = 0;
/*
* Don't send back more than was asked for. And if the bio
* was empty, let the whole thing through because: "Note
* that a block device *must* allow a single page to be
* added to an empty bio."
*/
rbd_assert(bvec->bv_len <= PAGE_SIZE);
if (ret > (int) bvec->bv_len || !bmd->bi_size)
ret = (int) bvec->bv_len;
return ret;
} }
static void rbd_free_disk(struct rbd_device *rbd_dev) static void rbd_free_disk(struct rbd_device *rbd_dev)
......
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