Skip to content

Commit 982446a

Browse files
naotakdave
authored andcommitted
block: introduce zone capacity helper
{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 <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 41108cf commit 982446a

File tree

1 file changed

+45
-22
lines changed

1 file changed

+45
-22
lines changed

include/linux/blkdev.h

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -712,35 +712,13 @@ static inline bool blk_queue_is_zoned(struct request_queue *q)
712712
(q->limits.features & BLK_FEAT_ZONED);
713713
}
714714

715-
#ifdef CONFIG_BLK_DEV_ZONED
716-
static inline unsigned int disk_nr_zones(struct gendisk *disk)
717-
{
718-
return disk->nr_zones;
719-
}
720-
bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs);
721-
#else /* CONFIG_BLK_DEV_ZONED */
722-
static inline unsigned int disk_nr_zones(struct gendisk *disk)
723-
{
724-
return 0;
725-
}
726-
static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
727-
{
728-
return false;
729-
}
730-
#endif /* CONFIG_BLK_DEV_ZONED */
731-
732715
static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
733716
{
734717
if (!blk_queue_is_zoned(disk->queue))
735718
return 0;
736719
return sector >> ilog2(disk->queue->limits.chunk_sectors);
737720
}
738721

739-
static inline unsigned int bdev_nr_zones(struct block_device *bdev)
740-
{
741-
return disk_nr_zones(bdev->bd_disk);
742-
}
743-
744722
static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
745723
{
746724
return bdev->bd_disk->queue->limits.max_open_zones;
@@ -847,6 +825,51 @@ static inline u64 sb_bdev_nr_blocks(struct super_block *sb)
847825
(sb->s_blocksize_bits - SECTOR_SHIFT);
848826
}
849827

828+
#ifdef CONFIG_BLK_DEV_ZONED
829+
static inline unsigned int disk_nr_zones(struct gendisk *disk)
830+
{
831+
return disk->nr_zones;
832+
}
833+
bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs);
834+
835+
/**
836+
* disk_zone_capacity - returns the zone capacity of zone containing @sector
837+
* @disk: disk to work with
838+
* @sector: sector number within the querying zone
839+
*
840+
* Returns the zone capacity of a zone containing @sector. @sector can be any
841+
* sector in the zone.
842+
*/
843+
static inline unsigned int disk_zone_capacity(struct gendisk *disk,
844+
sector_t sector)
845+
{
846+
sector_t zone_sectors = disk->queue->limits.chunk_sectors;
847+
848+
if (sector + zone_sectors >= get_capacity(disk))
849+
return disk->last_zone_capacity;
850+
return disk->zone_capacity;
851+
}
852+
static inline unsigned int bdev_zone_capacity(struct block_device *bdev,
853+
sector_t pos)
854+
{
855+
return disk_zone_capacity(bdev->bd_disk, pos);
856+
}
857+
#else /* CONFIG_BLK_DEV_ZONED */
858+
static inline unsigned int disk_nr_zones(struct gendisk *disk)
859+
{
860+
return 0;
861+
}
862+
static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
863+
{
864+
return false;
865+
}
866+
#endif /* CONFIG_BLK_DEV_ZONED */
867+
868+
static inline unsigned int bdev_nr_zones(struct block_device *bdev)
869+
{
870+
return disk_nr_zones(bdev->bd_disk);
871+
}
872+
850873
int bdev_disk_changed(struct gendisk *disk, bool invalidate);
851874

852875
void put_disk(struct gendisk *disk);

0 commit comments

Comments
 (0)