summaryrefslogtreecommitdiff
path: root/include/linux/blkdev.h
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2022-06-14 11:09:29 +0200
committerJens Axboe <axboe@kernel.dk>2022-06-27 06:29:11 -0600
commit8689461be3f1ce6686bc26f1f379790bb0fc7a8c (patch)
treec06cf2c3c78014e04481bbc84a72418a0ef41826 /include/linux/blkdev.h
parent51ab80f0aa861335eb80327af53e444a27e824b8 (diff)
downloadlwn-8689461be3f1ce6686bc26f1f379790bb0fc7a8c.tar.gz
lwn-8689461be3f1ce6686bc26f1f379790bb0fc7a8c.zip
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: Christoph Hellwig <hch@lst.de> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Pankaj Raghav <p.raghav@samsung.com> Link: https://lore.kernel.org/r/20220614090934.570632-2-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux/blkdev.h')
-rw-r--r--include/linux/blkdev.h19
1 files changed, 13 insertions, 6 deletions
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 886c44e97434..283961257cc9 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -935,6 +935,17 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
}
/*
+ * 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));
}
/*