Skip to content

Commit f3d9bf0

Browse files
damien-lemoalaxboe
authored andcommitted
block: Add a public bdev_zone_is_seq() helper
Turn the private disk_zone_is_conv() function in blk-zoned.c into a public and documented bdev_zone_is_seq() helper with the inverse polarity of the original function, also adding a check for non-zoned devices so that all file systems can use the helper, even with a regular block device. Suggested-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Link: https://lore.kernel.org/r/20241107064300.227731-3-dlemoal@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent d7cb6d7 commit f3d9bf0

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

block/blk-zoned.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,6 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode,
348348
return ret;
349349
}
350350

351-
static inline bool disk_zone_is_conv(struct gendisk *disk, sector_t sector)
352-
{
353-
unsigned long *bitmap;
354-
bool is_conv;
355-
356-
rcu_read_lock();
357-
bitmap = rcu_dereference(disk->conv_zones_bitmap);
358-
is_conv = bitmap && test_bit(disk_zone_no(disk, sector), bitmap);
359-
rcu_read_unlock();
360-
361-
return is_conv;
362-
}
363-
364351
static bool disk_zone_is_last(struct gendisk *disk, struct blk_zone *zone)
365352
{
366353
return zone->start + zone->len >= get_capacity(disk);
@@ -715,7 +702,7 @@ static bool blk_zone_wplug_handle_reset_or_finish(struct bio *bio,
715702
struct blk_zone_wplug *zwplug;
716703

717704
/* Conventional zones cannot be reset nor finished. */
718-
if (disk_zone_is_conv(disk, sector)) {
705+
if (!bdev_zone_is_seq(bio->bi_bdev, sector)) {
719706
bio_io_error(bio);
720707
return true;
721708
}
@@ -969,7 +956,7 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs)
969956
}
970957

971958
/* Conventional zones do not need write plugging. */
972-
if (disk_zone_is_conv(disk, sector)) {
959+
if (!bdev_zone_is_seq(bio->bi_bdev, sector)) {
973960
/* Zone append to conventional zones is not allowed. */
974961
if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
975962
bio_io_error(bio);

include/linux/blkdev.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,33 @@ static inline bool bdev_is_zone_start(struct block_device *bdev,
13951395
return bdev_offset_from_zone_start(bdev, sector) == 0;
13961396
}
13971397

1398+
/**
1399+
* bdev_zone_is_seq - check if a sector belongs to a sequential write zone
1400+
* @bdev: block device to check
1401+
* @sector: sector number
1402+
*
1403+
* Check if @sector on @bdev is contained in a sequential write required zone.
1404+
*/
1405+
static inline bool bdev_zone_is_seq(struct block_device *bdev, sector_t sector)
1406+
{
1407+
bool is_seq = false;
1408+
1409+
#if IS_ENABLED(CONFIG_BLK_DEV_ZONED)
1410+
if (bdev_is_zoned(bdev)) {
1411+
struct gendisk *disk = bdev->bd_disk;
1412+
unsigned long *bitmap;
1413+
1414+
rcu_read_lock();
1415+
bitmap = rcu_dereference(disk->conv_zones_bitmap);
1416+
is_seq = !bitmap ||
1417+
!test_bit(disk_zone_no(disk, sector), bitmap);
1418+
rcu_read_unlock();
1419+
}
1420+
#endif
1421+
1422+
return is_seq;
1423+
}
1424+
13981425
static inline int queue_dma_alignment(const struct request_queue *q)
13991426
{
14001427
return q->limits.dma_alignment;

0 commit comments

Comments
 (0)