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 01/16] block: remove disk_free_zone_resources()
Date: Tue, 8 Sep 2026 17:57:30 +0900 [thread overview]
Message-ID: <20260908085745.1082697-2-dlemoal@kernel.org> (raw)
In-Reply-To: <20260908085745.1082697-1-dlemoal@kernel.org>
In the rare event when revalidating the zones of a zoned block device
fails, the device capacity will be dropped to 0. In such case, the zoned
block device will either be rescanned and restored or will be dropped
entirely and its gendisk will be destroyed. So calling
disk_free_zone_resources() from blk_revalidate_disk_zones() in case of
an error does not make much sense. We can keep the zone resources in case
the device is rescanned and restored and simply free all resources in
disk_release_zone_resources() when the gendisk is destroyed.
Remove the call to disk_free_zone_resources() from
blk_revalidate_disk_zones() and squash disk_free_zone_resources() inside
disk_release_zone_resources(). With this change, the conditional creation
of the zone write plugs work queue is not necessary anymore as the
workqueue will keep existing together with all other resources until the
disk is released. This simplifies disk_alloc_zone_resources().
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
block/blk-zoned.c | 58 +++++++++++++++++------------------------------
1 file changed, 21 insertions(+), 37 deletions(-)
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index a5afb842bf35..c7d8c767bb31 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -1893,21 +1893,6 @@ static int disk_alloc_zone_resources(struct gendisk *disk,
if (!disk->zone_wplugs_pool)
goto free_hash;
- /*
- * We may already have a zone write plug workqueue as this function may
- * be called after disk_free_zone_resources(), which does not destroy
- * the workqueue (the zone write plugs workqueue is destroyed at
- * disk_release() time).
- */
- if (!disk->zone_wplugs_wq) {
- disk->zone_wplugs_wq =
- alloc_workqueue("%s_zwplugs",
- WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_PERCPU,
- pool_size, disk->disk_name);
- if (!disk->zone_wplugs_wq)
- goto destroy_pool;
- }
-
disk->zone_wplugs_worker =
kthread_create(disk_zone_wplugs_worker, disk,
"%s_zwplugs_worker", disk->disk_name);
@@ -1918,8 +1903,18 @@ static int disk_alloc_zone_resources(struct gendisk *disk,
}
wake_up_process(disk->zone_wplugs_worker);
+ disk->zone_wplugs_wq =
+ alloc_workqueue("%s_zwplugs",
+ WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_PERCPU,
+ pool_size, disk->disk_name);
+ if (!disk->zone_wplugs_wq)
+ goto stop_worker;
+
return 0;
+stop_worker:
+ kthread_stop(disk->zone_wplugs_worker);
+ disk->zone_wplugs_worker = NULL;
destroy_pool:
mempool_destroy(disk->zone_wplugs_pool);
disk->zone_wplugs_pool = NULL;
@@ -1975,7 +1970,7 @@ static void disk_set_zones_cond_array(struct gendisk *disk, u8 *zones_cond)
kfree_rcu_mightsleep(zones_cond);
}
-static void disk_free_zone_resources(struct gendisk *disk)
+void disk_release_zone_resources(struct gendisk *disk)
{
if (disk->zone_wplugs_worker) {
kthread_stop(disk->zone_wplugs_worker);
@@ -1983,8 +1978,10 @@ static void disk_free_zone_resources(struct gendisk *disk)
}
WARN_ON_ONCE(!list_empty(&disk->zone_wplugs_list));
- if (disk->zone_wplugs_wq)
- drain_workqueue(disk->zone_wplugs_wq);
+ if (disk->zone_wplugs_wq) {
+ destroy_workqueue(disk->zone_wplugs_wq);
+ disk->zone_wplugs_wq = NULL;
+ }
disk_destroy_zone_wplugs_hash_table(disk);
@@ -1994,16 +1991,6 @@ static void disk_free_zone_resources(struct gendisk *disk)
disk->nr_zones = 0;
}
-void disk_release_zone_resources(struct gendisk *disk)
-{
- if (disk->zone_wplugs_wq) {
- destroy_workqueue(disk->zone_wplugs_wq);
- disk->zone_wplugs_wq = NULL;
- }
-
- disk_free_zone_resources(disk);
-}
-
struct blk_revalidate_zone_args {
struct gendisk *disk;
u8 *zones_cond;
@@ -2317,11 +2304,11 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
sector_t zone_sectors = q->limits.chunk_sectors;
sector_t capacity = get_capacity(disk);
struct blk_revalidate_zone_args args = { };
- unsigned int memflags, noio_flag;
struct blk_report_zones_args rep_args = {
.cb = blk_revalidate_zone_cb,
.data = &args,
};
+ unsigned int noio_flag;
int ret = -ENOMEM;
if (WARN_ON_ONCE(!blk_queue_is_zoned(q)))
@@ -2358,8 +2345,8 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
}
memalloc_noio_restore(noio_flag);
- if (ret <= 0)
- goto free_resources;
+ if (ret < 0)
+ goto free_args;
/*
* If zones where reported, make sure that the entire disk capacity
@@ -2369,22 +2356,19 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
pr_warn("%s: Missing zones from sector %llu\n",
disk->disk_name, args.sector);
ret = -ENODEV;
- goto free_resources;
+ goto free_args;
}
ret = disk_update_zone_resources(disk, &args);
if (ret)
- goto free_resources;
+ goto free_args;
return 0;
-free_resources:
+free_args:
pr_warn("%s: failed to revalidate zones\n", disk->disk_name);
kfree(args.zones_cond);
- memflags = blk_mq_freeze_queue(q);
- disk_free_zone_resources(disk);
- blk_mq_unfreeze_queue(q, memflags);
return ret;
}
--
2.55.0
next prev parent reply other threads:[~2026-09-08 8:57 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 ` Damien Le Moal [this message]
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 ` [PATCH v7 10/16] block: drop all zone write plugs on capacity changes Damien Le Moal
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-2-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