Commit 8689461b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: factor out a chunk_size_left helper

Factor out a helper from blk_max_size_offset so that it can be reused
independently.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
Reviewed-by: default avatarPankaj Raghav <p.raghav@samsung.com>
Link: https://lore.kernel.org/r/20220614090934.570632-2-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 51ab80f0
......@@ -934,6 +934,17 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
return q->limits.max_sectors;
}
/*
* Return how much of the chunk is left to be used for I/O at a given offset.
*/
static inline unsigned int blk_chunk_sectors_left(sector_t offset,
unsigned int chunk_sectors)
{
if (unlikely(!is_power_of_2(chunk_sectors)))
return chunk_sectors - sector_div(offset, chunk_sectors);
return chunk_sectors - (offset & (chunk_sectors - 1));
}
/*
* Return maximum size of a request at given offset. Only valid for
* file system requests.
......@@ -949,12 +960,8 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q,
return q->limits.max_sectors;
}
if (likely(is_power_of_2(chunk_sectors)))
chunk_sectors -= offset & (chunk_sectors - 1);
else
chunk_sectors -= sector_div(offset, chunk_sectors);
return min(q->limits.max_sectors, chunk_sectors);
return min(q->limits.max_sectors,
blk_chunk_sectors_left(offset, chunk_sectors));
}
/*
......
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