Skip to content

Commit 25976c3

Browse files
damien-lemoalaxboe
authored andcommitted
block: introduce bdev_zone_start()
Introduce the function bdev_zone_start() as a more explicit (and clear) replacement for ALIGN_DOWN() to get the start sector of a zone containing a particular sector of a zoned block device. Use this new helper in blkdev_get_zone_info() and blkdev_report_zones_cached(). Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent e2b0ec7 commit 25976c3

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

block/blk-zoned.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ int blkdev_get_zone_info(struct block_device *bdev, sector_t sector,
950950
return -EINVAL;
951951

952952
memset(zone, 0, sizeof(*zone));
953-
sector = ALIGN_DOWN(sector, zone_sectors);
953+
sector = bdev_zone_start(bdev, sector);
954954

955955
if (!blkdev_has_cached_report_zones(bdev))
956956
return blkdev_report_zone_fallback(bdev, sector, zone);
@@ -1068,7 +1068,7 @@ int blkdev_report_zones_cached(struct block_device *bdev, sector_t sector,
10681068
return blkdev_do_report_zones(bdev, sector, nr_zones, &args);
10691069
}
10701070

1071-
for (sector = ALIGN_DOWN(sector, zone_sectors);
1071+
for (sector = bdev_zone_start(bdev, sector);
10721072
sector < capacity && idx < nr_zones;
10731073
sector += zone_sectors, idx++) {
10741074
ret = blkdev_get_zone_info(bdev, sector, &zone);

include/linux/blkdev.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,12 @@ static inline sector_t bdev_zone_sectors(struct block_device *bdev)
15221522
return q->limits.chunk_sectors;
15231523
}
15241524

1525+
static inline sector_t bdev_zone_start(struct block_device *bdev,
1526+
sector_t sector)
1527+
{
1528+
return sector & ~(bdev_zone_sectors(bdev) - 1);
1529+
}
1530+
15251531
static inline sector_t bdev_offset_from_zone_start(struct block_device *bdev,
15261532
sector_t sector)
15271533
{

0 commit comments

Comments
 (0)