From: Niklas Cassel <cassel@kernel.org>
To: Jens Axboe <axboe@kernel.dk>
Cc: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>,
Damien Le Moal <dlemoal@kernel.org>,
linux-block@vger.kernel.org, Niklas Cassel <cassel@kernel.org>
Subject: [PATCH v2 3/3] null_blk: clean up setting zones read-only or offline
Date: Thu, 22 Oct 2026 11:22:02 +0200 [thread overview]
Message-ID: <20261022092158.2248831-8-cassel@kernel.org> (raw)
In-Reply-To: <20261022092158.2248831-5-cassel@kernel.org>
null_set_zone_cond() takes a zone condition, even though read-only and
offline are the only zone conditions that it can set. Because of this,
it needs a WARN_ON_ONCE() to reject any other zone condition, and its
name suggests a generic helper that can set any zone condition.
Rename null_set_zone_cond() to null_set_zone_readonly_or_offline(), and
replace its zone condition argument with a bool, set_offline, which
selects between the read-only and offline conditions. Also remove the
comment above the function, as it only repeats the new function name.
zone_cond_store() keeps taking a zone condition, as it, unlike
null_set_zone_readonly_or_offline(), contains generic code, and might
be extended to support additional zone conditions in the future.
No functional change, as zone_cond_store() is only called with the
read-only or offline condition.
Suggested-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
drivers/block/null_blk/zoned.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
index 015f5d304c7ce..b271d0a88ff21 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -770,15 +770,12 @@ static void null_release_zone_resources(struct nullb_device *dev,
spin_unlock(&dev->zone_res_lock);
}
-/*
- * Set a zone in the read-only or offline condition.
- */
-static void null_set_zone_cond(struct nullb_device *dev,
- struct nullb_zone *zone, enum blk_zone_cond cond)
+static void null_set_zone_readonly_or_offline(struct nullb_device *dev,
+ struct nullb_zone *zone,
+ bool set_offline)
{
- if (WARN_ON_ONCE(cond != BLK_ZONE_COND_READONLY &&
- cond != BLK_ZONE_COND_OFFLINE))
- return;
+ enum blk_zone_cond cond =
+ set_offline ? BLK_ZONE_COND_OFFLINE : BLK_ZONE_COND_READONLY;
null_lock_zone(dev, zone);
@@ -814,6 +811,11 @@ ssize_t zone_cond_store(struct nullb_device *dev, const char *page,
unsigned int zone_no;
int ret;
+ /* Read-only and offline are the only conditions supported for now */
+ if (WARN_ON_ONCE(cond != BLK_ZONE_COND_READONLY &&
+ cond != BLK_ZONE_COND_OFFLINE))
+ return -EINVAL;
+
if (!dev->zoned) {
pr_err("null_blk device is not zoned\n");
return -EINVAL;
@@ -839,7 +841,8 @@ ssize_t zone_cond_store(struct nullb_device *dev, const char *page,
return -EINVAL;
}
- null_set_zone_cond(dev, &dev->zones[zone_no], cond);
+ null_set_zone_readonly_or_offline(dev, &dev->zones[zone_no],
+ cond == BLK_ZONE_COND_OFFLINE);
return count;
}
--
2.56.0
next prev parent reply other threads:[~2026-10-22 9:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 9:21 [PATCH v2 0/3] null_blk: zone resource management fixes Niklas Cassel
2026-10-22 9:22 ` [PATCH v2 1/3] null_blk: fix opening closed zones at the active zone limit Niklas Cassel
2026-10-22 9:22 ` [PATCH v2 2/3] null_blk: don't finish zones to set them read-only or offline Niklas Cassel
2026-10-22 9:22 ` Niklas Cassel [this message]
2026-10-22 9:36 ` [PATCH v2 3/3] null_blk: clean up setting zones " Damien Le Moal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261022092158.2248831-8-cassel@kernel.org \
--to=cassel@kernel.org \
--cc=axboe@kernel.dk \
--cc=dlemoal@kernel.org \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-block@vger.kernel.org \
--cc=shinichiro.kawasaki@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox