Skip to content

Commit c1a79b1

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 f1ab017 commit c1a79b1

File tree

1 file changed

+45
-22
lines changed

1 file changed

+45
-22
lines changed

include/linux/blkdev.h

+45-22
Original file line numberDiff line numberDiff line change
@@ -691,35 +691,13 @@ static inline bool blk_queue_is_zoned(struct request_queue *q)
691691
(q->limits.features & BLK_FEAT_ZONED);
692692
}
693693

694-
#ifdef CONFIG_BLK_DEV_ZONED
695-
static inline unsigned int disk_nr_zones(struct gendisk *disk)
696-
{
697-
return disk->nr_zones;
698-
}
699-
bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs);
700-
#else /* CONFIG_BLK_DEV_ZONED */
701-
static inline unsigned int disk_nr_zones(struct gendisk *disk)
702-
{
703-
return 0;
704-
}
705-
static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
706-
{
707-
return false;
708-
}
709-
#endif /* CONFIG_BLK_DEV_ZONED */
710-
711694
static inline unsigned int disk_zone_no(struct gendisk *disk, sector_t sector)
712695
{
713696
if (!blk_queue_is_zoned(disk->queue))
714697
return 0;
715698
return sector >> ilog2(disk->queue->limits.chunk_sectors);
716699
}
717700

718-
static inline unsigned int bdev_nr_zones(struct block_device *bdev)
719-
{
720-
return disk_nr_zones(bdev->bd_disk);
721-
}
722-
723701
static inline unsigned int bdev_max_open_zones(struct block_device *bdev)
724702
{
725703
return bdev->bd_disk->queue->limits.max_open_zones;
@@ -826,6 +804,51 @@ static inline u64 sb_bdev_nr_blocks(struct super_block *sb)
826804
(sb->s_blocksize_bits - SECTOR_SHIFT);
827805
}
828806

807+
#ifdef CONFIG_BLK_DEV_ZONED
808+
static inline unsigned int disk_nr_zones(struct gendisk *disk)
809+
{
810+
return disk->nr_zones;
811+
}
812+
bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs);
813+
814+
/**
815+
* disk_zone_capacity - returns the zone capacity of zone containing @sector
816+
* @disk: disk to work with
817+
* @sector: sector number within the querying zone
818+
*
819+
* Returns the zone capacity of a zone containing @sector. @sector can be any
820+
* sector in the zone.
821+
*/
822+
static inline unsigned int disk_zone_capacity(struct gendisk *disk,
823+
sector_t sector)
824+
{
825+
sector_t zone_sectors = disk->queue->limits.chunk_sectors;
826+
827+
if (sector + zone_sectors >= get_capacity(disk))
828+
return disk->last_zone_capacity;
829+
return disk->zone_capacity;
830+
}
831+
static inline unsigned int bdev_zone_capacity(struct block_device *bdev,
832+
sector_t pos)
833+
{
834+
return disk_zone_capacity(bdev->bd_disk, pos);
835+
}
836+
#else /* CONFIG_BLK_DEV_ZONED */
837+
static inline unsigned int disk_nr_zones(struct gendisk *disk)
838+
{
839+
return 0;
840+
}
841+
static inline bool blk_zone_plug_bio(struct bio *bio, unsigned int nr_segs)
842+
{
843+
return false;
844+
}
845+
#endif /* CONFIG_BLK_DEV_ZONED */
846+
847+
static inline unsigned int bdev_nr_zones(struct block_device *bdev)
848+
{
849+
return disk_nr_zones(bdev->bd_disk);
850+
}
851+
829852
int bdev_disk_changed(struct gendisk *disk, bool invalidate);
830853

831854
void put_disk(struct gendisk *disk);

0 commit comments

Comments
 (0)