From 610058c9706eb4290febb107353db65857a67201 Mon Sep 17 00:00:00 2001
From: Pankaj Raghav
Date: Tue, 10 Jan 2023 15:36:34 +0100
Subject: [PATCH] BACKPORT: FROMLIST: block: add a new helper
bdev_{is_zone_start, offset_from_zone_start}
Instead of open coding to check for zone start, add a helper to improve
readability and store the logic in one place.
Reviewed-by: Chaitanya Kulkarni
Reviewed-by: Christoph Hellwig
Signed-off-by: Pankaj Raghav
Bug: 197782466
Bug: 269471019
Link: https://lore.kernel.org/linux-block/20230110143635.77300-3-p.raghav@samsung.com/
Change-Id: Ieb3ec909589fe087f49a61c48ba85f0e612b6d1d
Signed-off-by: Bart Van Assche
---
block/blk-zoned.c | 4 ++--
include/linux/blkdev.h | 12 ++++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index aba9f53853ee..a17f7f36af0d 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -274,10 +274,10 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
return -EINVAL;
/* Check alignment (handle eventual smaller last zone) */
- if (sector & (zone_sectors - 1))
+ if (!bdev_is_zone_start(bdev, sector))
return -EINVAL;
- if ((nr_sectors & (zone_sectors - 1)) && end_sector != capacity)
+ if (!bdev_is_zone_start(bdev, nr_sectors) && end_sector != capacity)
return -EINVAL;
/*
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 2ad9b1959e30..6d14ae718a30 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1665,6 +1665,18 @@ static inline unsigned int bdev_max_active_zones(struct block_device *bdev)
return 0;
}
+static inline sector_t bdev_offset_from_zone_start(struct block_device *bdev,
+ sector_t sector)
+{
+ return sector & (bdev_zone_sectors(bdev) - 1);
+}
+
+static inline bool bdev_is_zone_start(struct block_device *bdev,
+ sector_t sector)
+{
+ return bdev_offset_from_zone_start(bdev, sector) == 0;
+}
+
static inline int queue_dma_alignment(const struct request_queue *q)
{
return q ? q->dma_alignment : 511;