Message ID | 20220427160255.300418-3-p.raghav@samsung.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/16] block: make blkdev_nr_zones and blk_queue_zone_no generic for npo2 zsze | expand |
On 4/27/22 09:02, Pankaj Raghav wrote: > +static inline bool bdev_zone_aligned(struct block_device *bdev, sector_t sec) > +{ > + struct request_queue *q = bdev_get_queue(bdev); > + > + if (q) > + return blk_queue_zone_aligned(q, sec); > + return false; > +} Which patch uses this function? I can't find any patch in this series that introduces a call to this function. Thanks, Bart.
On 4/27/22 09:02, Pankaj Raghav wrote: > Checking if a given sector is aligned to a zone is a very common > operation that is performed for zoned devices. Add > blk_queue_zone_aligned helper to check for this instead of opencoding it > everywhere. > > The helper is made to be generic so that it can also check for alignment > for non non-power-of-2 zone size devices. > > As the existing deployments of zoned devices had power-of-2 > assumption, power-of-2 optimized calculation is done for devices with > power-of-2 zone size > > Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> > Signed-off-by: Pankaj Raghav <p.raghav@samsung.com> > --- > include/linux/blkdev.h | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > Reviewed-by: Hannes Reinecke <hare@suse.de> Cheers, Hannes
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index c4e4c7071b7b..f8f2d2998afb 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -676,6 +676,22 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, return div64_u64(sector, zone_sectors); } +static inline bool blk_queue_zone_aligned(struct request_queue *q, sector_t sec) +{ + sector_t zone_sectors = blk_queue_zone_sectors(q); + u64 remainder = 0; + + if (!blk_queue_is_zoned(q)) + return false; + + if (is_power_of_2(zone_sectors)) + return IS_ALIGNED(sec, zone_sectors); + + div64_u64_rem(sec, zone_sectors, &remainder); + /* if there is a remainder, then the sector is not aligned */ + return remainder == 0; +} + static inline bool blk_queue_zone_is_seq(struct request_queue *q, sector_t sector) { @@ -722,6 +738,12 @@ static inline unsigned int blk_queue_zone_no(struct request_queue *q, { return 0; } + +static inline bool blk_queue_zone_aligned(struct request_queue *q, sector_t sec) +{ + return false; +} + static inline unsigned int queue_max_open_zones(const struct request_queue *q) { return 0; @@ -1361,6 +1383,15 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev) return 0; } +static inline bool bdev_zone_aligned(struct block_device *bdev, sector_t sec) +{ + struct request_queue *q = bdev_get_queue(bdev); + + if (q) + return blk_queue_zone_aligned(q, sec); + return false; +} + static inline unsigned int bdev_max_open_zones(struct block_device *bdev) { struct request_queue *q = bdev_get_queue(bdev);