block: add queue_logical_block_mask() and bdev_logical_block_mask()

Message ID 20230310082413.58141-1-frank.li@vivo.com
State New
Headers
Series block: add queue_logical_block_mask() and bdev_logical_block_mask() |

Commit Message

李扬韬 March 10, 2023, 8:24 a.m. UTC
  Introduce queue_logical_block_mask() and bdev_logical_block_mask()
to simplify code, which replace (queue_logical_block_size(q) - 1)
and (bdev_logical_block_size(bdev) - 1).

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
Like wo done for fs.
This round we add helpers and start converting in the next cycle.
https://lore.kernel.org/lkml/20230309124035.15820-1-frank.li@vivo.com/
 include/linux/blkdev.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
  

Comments

Christoph Hellwig March 20, 2023, 1:34 p.m. UTC | #1
On Fri, Mar 10, 2023 at 04:24:13PM +0800, Yangtao Li wrote:
> Introduce queue_logical_block_mask() and bdev_logical_block_mask()
> to simplify code, which replace (queue_logical_block_size(q) - 1)
> and (bdev_logical_block_size(bdev) - 1).
> 
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> Like wo done for fs.
> This round we add helpers and start converting in the next cycle.
> https://lore.kernel.org/lkml/20230309124035.15820-1-frank.li@vivo.com/

Please always send the helper with the actual users.

And for use in file systems the request_queue is very much the
wrong object to work on.  All the block layer APIs for consumers like
file systems are based on struct block_device.
  

Patch

diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index d1aee08f8c18..a68a704e5ea5 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1173,11 +1173,21 @@  static inline unsigned queue_logical_block_size(const struct request_queue *q)
 	return retval;
 }
 
+static inline unsigned int queue_logical_block_mask(const struct request_queue *q)
+{
+	return queue_logical_block_size(q) - 1;
+}
+
 static inline unsigned int bdev_logical_block_size(struct block_device *bdev)
 {
 	return queue_logical_block_size(bdev_get_queue(bdev));
 }
 
+static inline unsigned int bdev_logical_block_mask(struct block_device *bdev)
+{
+	return bdev_logical_block_size(bdev) - 1;
+}
+
 static inline unsigned int queue_physical_block_size(const struct request_queue *q)
 {
 	return q->limits.physical_block_size;