Linux block layer
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Christoph Hellwig <hch@lst.de>
Subject: [PATCH v7 10/16] block: drop all zone write plugs on capacity changes
Date: Tue,  8 Sep 2026 17:57:39 +0900	[thread overview]
Message-ID: <20260908085745.1082697-11-dlemoal@kernel.org> (raw)
In-Reply-To: <20260908085745.1082697-1-dlemoal@kernel.org>

If during revalidation, we detect a capacity change for a zoned block
device, e.g. due to a storage element removal on an HDD, we can assume
that the device was reformatted, which implies that all sequential zones
are empty. For such case, we can remove and free all zone write plugs in
the gendisk hash table by marking them as dead, thus avoiding also to
leave zone write plugs for zones that are beyond the new device capacity
in the disk hash table.

Introduce the function disk_revalidate_capacity() to do this and call this
new function at the beginning of blk_revalidate_disk_zones(), so that the
zone revalidation process can re-create, if needed, any zone write plug
for sequential zones that are not empty.

The checks on the capacity and zone size that were in
blk_revalidate_disk_zones() are moved to disk_revalidate_capacity() and
if true, also trigger dropping all zone write plugs.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-zoned.c | 77 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 57 insertions(+), 20 deletions(-)

diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 676620ed93de..e7f20b5262c7 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -2246,6 +2246,56 @@ static int disk_revalidate_zone_resources(struct gendisk *disk,
 	return ret;
 }
 
+static void disk_drop_zone_wplug(struct blk_zone_wplug *zwplug, void *data)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&zwplug->lock, flags);
+	disk_zone_wplug_abort(zwplug);
+	disk_mark_zone_wplug_dead(zwplug);
+	spin_unlock_irqrestore(&zwplug->lock, flags);
+}
+
+static int disk_revalidate_capacity(struct gendisk *disk,
+				    struct blk_revalidate_zone_args *args)
+{
+	struct queue_limits *lim = &disk->queue->limits;
+	sector_t zone_sectors = lim->chunk_sectors;
+	unsigned int nr_zones;
+	int ret = -ENODEV;
+
+	/* Checks that the device driver indicated a valid zone size. */
+	if (!zone_sectors || !is_power_of_2(zone_sectors)) {
+		pr_warn("%s: Invalid non power of two zone size (%llu)\n",
+			disk->disk_name, zone_sectors);
+		goto drop_all_zwplugs;
+	}
+
+	args->capacity = get_capacity(disk);
+	nr_zones = disk_get_nr_zones(disk, args->capacity);
+	if (!args->capacity || !nr_zones)
+		goto drop_all_zwplugs;
+
+	/*
+	 * Check if the capacity has changed. If it did, assume that the device
+	 * was reformatted and that all sequential zones are now empty. So drop
+	 * all zone write plug.
+	 */
+	if (disk->nr_zones && disk->nr_zones != nr_zones) {
+		pr_warn("%s: Number of zones changed (%u -> %u)\n",
+			disk->disk_name, disk->nr_zones, nr_zones);
+		ret = 0;
+		goto drop_all_zwplugs;
+	}
+
+	return 0;
+
+drop_all_zwplugs:
+	disk_for_all_zone_wplugs(disk, disk_drop_zone_wplug, NULL);
+
+	return ret;
+}
+
 static int blk_revalidate_zone_cond(struct blk_zone *zone, unsigned int idx,
 				    struct blk_revalidate_zone_args *args)
 {
@@ -2435,40 +2485,27 @@ static int blk_revalidate_zone_cb(struct blk_zone *zone, unsigned int idx,
  */
 int blk_revalidate_disk_zones(struct gendisk *disk)
 {
-	struct request_queue *q = disk->queue;
-	sector_t zone_sectors = q->limits.chunk_sectors;
-	struct blk_revalidate_zone_args args = {
-		.capacity = get_capacity(disk),
-	};
+	struct blk_revalidate_zone_args args = { };
 	struct blk_report_zones_args rep_args = {
 		.cb = blk_revalidate_zone_cb,
 		.data = &args,
 	};
 	unsigned int noio_flag;
-	int ret = -ENOMEM;
+	int ret;
 
-	if (WARN_ON_ONCE(!blk_queue_is_zoned(q)))
+	if (WARN_ON_ONCE(!blk_queue_is_zoned(disk->queue)))
 		return -EIO;
 
-	if (!args.capacity)
-		return -ENODEV;
-
-	/*
-	 * Checks that the device driver indicated a valid zone size and that
-	 * the max zone append limit is set.
-	 */
-	if (!zone_sectors || !is_power_of_2(zone_sectors)) {
-		pr_warn("%s: Invalid non power of two zone size (%llu)\n",
-			disk->disk_name, zone_sectors);
-		return -ENODEV;
-	}
-
 	/*
 	 * Serialize calls to this function so that we can safely look at and
 	 * eventually change the disk zone information.
 	 */
 	mutex_lock(&disk->zone_revalidate_mutex);
 
+	ret = disk_revalidate_capacity(disk, &args);
+	if (ret)
+		goto unlock;
+
 	/*
 	 * Allocate zone resources if they are needed and we have not done
 	 * so yet, and initialize the revalidation arguments passed to report
-- 
2.55.0


  parent reply	other threads:[~2026-09-08  8:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08  8:57 [PATCH v7 00/16] Improve handling of offline and read-only zones Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 01/16] block: remove disk_free_zone_resources() Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 02/16] block: improve capacity handling during zone revalidation Damien Le Moal
2026-09-09  8:51   ` Hannes Reinecke
2026-09-10  5:20   ` Christoph Hellwig
2026-09-08  8:57 ` [PATCH v7 03/16] block: refactor disk_revalidate_zone_resources() Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 04/16] block: refactor disk_update_zone_resources() Damien Le Moal
2026-09-09  9:09   ` Hannes Reinecke
2026-09-10  5:20   ` Christoph Hellwig
2026-09-08  8:57 ` [PATCH v7 05/16] block: remember a zone type regardless of its condition Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 06/16] block: refactor bdev_zone_is_seq() Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 07/16] block: improve blkdev_get_zone_info() Damien Le Moal
2026-09-09  9:11   ` Hannes Reinecke
2026-09-10  5:21   ` Christoph Hellwig
2026-09-08  8:57 ` [PATCH v7 08/16] block: introduce disk_for_all_zone_wplugs() Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 09/16] block: serialize zone revalidation Damien Le Moal
2026-09-09  9:20   ` Hannes Reinecke
2026-09-10  5:21   ` Christoph Hellwig
2026-09-08  8:57 ` Damien Le Moal [this message]
2026-09-08  8:57 ` [PATCH v7 11/16] block: retry zone revalidation on capacity change Damien Le Moal
2026-09-09  9:26   ` Hannes Reinecke
2026-09-10  5:24   ` Christoph Hellwig
2026-09-10  5:26     ` Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 12/16] block: propagate readonly and offline conditions to zone write plugs Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 13/16] block: always treat offline and read-only zones as dead Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 14/16] block: fail zone management operations to read-only and offline zones Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 15/16] block: allow read-only and offline conventional zones Damien Le Moal
2026-09-08  8:57 ` [PATCH v7 16/16] block: simplify disk_zone_set_cond() 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=20260908085745.1082697-11-dlemoal@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    /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