Message ID | e0fa06613d4f39f85a64c75e5b4413ccfd725c4b.1742259006.git.naohiro.aota@wdc.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | btrfs: zoned: skip reporting zone for new block group | expand |
On 3/18/25 9:59 AM, Naohiro Aota wrote: > {bdev,disk}_zone_capacity() takes block_device or gendisk and sector position > and returns the zone capacity of the corresponding zone. > > With that, move disk_nr_zones() and blk_zone_plug_bio() to consolidate them in > the same #ifdef block. > > Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> > --- > include/linux/blkdev.h | 67 ++++++++++++++++++++++++++++-------------- > 1 file changed, 45 insertions(+), 22 deletions(-) > > diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h > index d37751789bf5..6f1bdec27ac7 100644 > --- a/include/linux/blkdev.h > +++ b/include/linux/blkdev.h > @@ -691,23 +691,6 @@ static inline bool blk_queue_is_zoned(struct request_queue *q) > (q->limits.features & BLK_FEAT_ZONED); > } > > -#ifdef CONFIG_BLK_DEV_ZONED > -static inline unsigned int disk_nr_zones(struct gendisk *disk) > -{ > - return disk->nr_zones; > -} > -bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs); > -#else /* CONFIG_BLK_DEV_ZONED */ > -static inline unsigned int disk_nr_zones(struct gendisk *disk) > -{ > - return 0; > -} > -static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs) > -{ > - return false; > -} > -#endif /* CONFIG_BLK_DEV_ZONED */ > - > static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector) > { > if (!blk_queue_is_zoned(disk->queue)) > @@ -715,11 +698,6 @@ static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector) > return sector >> ilog2(disk->queue->limits.chunk_sectors); > } > > -static inline unsigned int bdev_nr_zones(struct block_device *bdev) > -{ > - return disk_nr_zones(bdev->bd_disk); > -} > - > static inline unsigned int bdev_max_open_zones(struct block_device *bdev) > { > return bdev->bd_disk->queue->limits.max_open_zones; > @@ -826,6 +804,51 @@ static inline u64 sb_bdev_nr_blocks(struct super_block *sb) > (sb->s_blocksize_bits - SECTOR_SHIFT); > } > > +#ifdef CONFIG_BLK_DEV_ZONED > +static inline unsigned int disk_nr_zones(struct gendisk *disk) > +{ > + return disk->nr_zones; > +} > +bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs); > + > +/** > + * disk_zone_capacity - returns the zone capacity of zone at @pos @pos is not the start of the zone, so this should be: * disk_zone_capacity - returns the capacity of the zone containing @sect And rename pos to sect. With that, this looks good to me, so feel free to add: Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
On Tue, Mar 18, 2025 at 02:14:29PM +0900, Damien Le Moal wrote: > @pos is not the start of the zone, so this should be: > > * disk_zone_capacity - returns the capacity of the zone containing @sect > > And rename pos to sect. While we're nitpicking: sect is a bit weird, the block layer usually spells it out as sectors (sect sounds too close to the german word for sparkling wine anyway :))
Minus the nitpicks from Damien and Christoph,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
On 3/18/25 2:54 PM, Christoph Hellwig wrote: > On Tue, Mar 18, 2025 at 02:14:29PM +0900, Damien Le Moal wrote: >> @pos is not the start of the zone, so this should be: >> >> * disk_zone_capacity - returns the capacity of the zone containing @sect >> >> And rename pos to sect. > > While we're nitpicking: sect is a bit weird, the block layer usually > spells it out as sectors (sect sounds too close to the german word for > sparkling wine anyway :)) Given that this is not a number of sectors, "sector" would be the right name then :)
On Tue, Mar 18, 2025 at 04:57:45PM +0900, Damien Le Moal wrote: > Given that this is not a number of sectors, "sector" would be the right name > then :) Yes. That's what I meant, but I obviously can't type before the first three coffees of the day.
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index d37751789bf5..6f1bdec27ac7 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -691,23 +691,6 @@ static inline bool blk_queue_is_zoned(struct request_queue *q) (q->limits.features & BLK_FEAT_ZONED); } -#ifdef CONFIG_BLK_DEV_ZONED -static inline unsigned int disk_nr_zones(struct gendisk *disk) -{ - return disk->nr_zones; -} -bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs); -#else /* CONFIG_BLK_DEV_ZONED */ -static inline unsigned int disk_nr_zones(struct gendisk *disk) -{ - return 0; -} -static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs) -{ - return false; -} -#endif /* CONFIG_BLK_DEV_ZONED */ - static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector) { if (!blk_queue_is_zoned(disk->queue)) @@ -715,11 +698,6 @@ static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector) return sector >> ilog2(disk->queue->limits.chunk_sectors); } -static inline unsigned int bdev_nr_zones(struct block_device *bdev) -{ - return disk_nr_zones(bdev->bd_disk); -} - static inline unsigned int bdev_max_open_zones(struct block_device *bdev) { return bdev->bd_disk->queue->limits.max_open_zones; @@ -826,6 +804,51 @@ static inline u64 sb_bdev_nr_blocks(struct super_block *sb) (sb->s_blocksize_bits - SECTOR_SHIFT); } +#ifdef CONFIG_BLK_DEV_ZONED +static inline unsigned int disk_nr_zones(struct gendisk *disk) +{ + return disk->nr_zones; +} +bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs); + +/** + * disk_zone_capacity - returns the zone capacity of zone at @pos + * @disk: disk to work with + * @pos: sector number within the querying zone + * + * Returns the zone capacity of a zone at @pos. @pos can be any sector contained + * in the zone. + */ +static inline unsigned int disk_zone_capacity(struct gendisk *disk, + sector_t pos) +{ + sector_t zone_sectors = disk->queue->limits.chunk_sectors; + + if (pos + zone_sectors >= get_capacity(disk)) + return disk->last_zone_capacity; + return disk->zone_capacity; +} +static inline unsigned int bdev_zone_capacity(struct block_device *bdev, + sector_t pos) +{ + return disk_zone_capacity(bdev->bd_disk, pos); +} +#else /* CONFIG_BLK_DEV_ZONED */ +static inline unsigned int disk_nr_zones(struct gendisk *disk) +{ + return 0; +} +static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs) +{ + return false; +} +#endif /* CONFIG_BLK_DEV_ZONED */ + +static inline unsigned int bdev_nr_zones(struct block_device *bdev) +{ + return disk_nr_zones(bdev->bd_disk); +} + int bdev_disk_changed(struct gendisk *disk, bool invalidate); void put_disk(struct gendisk *disk);
{bdev,disk}_zone_capacity() takes block_device or gendisk and sector position and returns the zone capacity of the corresponding zone. With that, move disk_nr_zones() and blk_zone_plug_bio() to consolidate them in the same #ifdef block. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> --- include/linux/blkdev.h | 67 ++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 22 deletions(-)