From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EA154C8FFD for ; Tue, 8 Sep 2026 08:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788857899; cv=none; b=eFvGcHdS97QUxiCByx1TmEK4MFh3lWjKjVocutQfO9AAgc6E9R6NYR4EA407fzVt5kjapkhOl+HC9BT22Ez+rF6Ca4ddhAQJ1Fwkayx4vuExEoobxJDxRlr7Syi1qbc18HPx8GL9A3k0CYCU3yFFkKMeZGaTGz9AyIM22Of5sgY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788857899; c=relaxed/simple; bh=JHPbmji4daYXQ5OoVaOpCb/LvzsTVpBs6xZ6KXnZ6YY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F4n13avlJ8CBzGOxBI8rfVhOIomtrPPu3cQ0xXpsvkhgupS/SkwczHE74MnkNjJoqkjgyoXBdOOd9VGbHYB65OtkuiOTm3ZRH4MnmEAIiG/wZjnvMmOOya7pTHAhNvcXDygeRTrMxN6WqwqP3/aK3Ke9Y4dbYRl0cm01Jqes5as= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YQnkpggZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YQnkpggZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70ECB1F00ADE; Tue, 8 Sep 2026 08:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788857882; bh=zE6HQ6FRIt3sp3/T+iFpB54i+8V9SeSFMmuis+U3Eto=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YQnkpggZolnk04Mw1AiXF9Fqd8SunLgRNQLOjETfsO6vuvMfUOzb3cNnzy86pLcDM 76ApDfpj/LlZeSl3+udOqAOJ3FctnzkBXF/zyb0RGkzS6TKTlAEUsscBL/C2/txVba 0w6y4zefgjHLpjWGp02s9tZDkfasQhw8gyO2G5Ve0ZgOxfCpMHuED97Wh8kabVvr3B 8MfYD1YepuqQGBR995VY3a7d9ctFo3+CFVAOtWnLUj8CzBVhmH+Q8RVxvsIC4D92zd Xc0ngBa/ba/HrLZkBjytpRv6V78WiwIHdiainkUaRZ8RHY638z7s9RUBNhwK7yOs1p lSpod75niiKpg== From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org Cc: Christoph Hellwig Subject: [PATCH v7 08/16] block: introduce disk_for_all_zone_wplugs() Date: Tue, 8 Sep 2026 17:57:37 +0900 Message-ID: <20260908085745.1082697-9-dlemoal@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260908085745.1082697-1-dlemoal@kernel.org> References: <20260908085745.1082697-1-dlemoal@kernel.org> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Introduce the helper function disk_for_all_zone_wplugs() to allow executing an actor function on all hashed zone write plugs. This helper is used to simplify the implementation of blk_zone_reset_all_bio_endio() and queue_zone_wplugs_show(). Signed-off-by: Damien Le Moal Reviewed-by: Bart Van Assche Reviewed-by: Hannes Reinecke Reviewed-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig --- block/blk-zoned.c | 68 +++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 93d862d44e7c..70a687bb371f 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -661,6 +661,26 @@ static inline struct blk_zone_wplug *disk_get_zone_wplug(struct gendisk *disk, return disk_get_hashed_zone_wplug(disk, sector); } +static void disk_for_all_zone_wplugs(struct gendisk *disk, + void (*actor)(struct blk_zone_wplug *, + void *), + void *data) +{ + struct blk_zone_wplug *zwplug; + unsigned int i; + + if (!disk->zone_wplugs_hash) + return; + + rcu_read_lock(); + for (i = 0; i < disk_zone_wplugs_hash_size(disk); i++) { + hlist_for_each_entry_rcu(zwplug, &disk->zone_wplugs_hash[i], + node) + actor(zwplug, data); + } + rcu_read_unlock(); +} + static void disk_free_zone_wplug_rcu(struct rcu_head *rcu_head) { struct blk_zone_wplug *zwplug = @@ -1203,32 +1223,26 @@ static void blk_zone_reset_bio_endio(struct bio *bio) } } +static void disk_zone_wplug_reset_wp(struct blk_zone_wplug *zwplug, void *data) +{ + unsigned long flags; + + spin_lock_irqsave(&zwplug->lock, flags); + disk_zone_wplug_set_wp_offset(zwplug->disk, zwplug, 0); + spin_unlock_irqrestore(&zwplug->lock, flags); +} + static void blk_zone_reset_all_bio_endio(struct bio *bio) { struct gendisk *disk = bio->bi_bdev->bd_disk; - sector_t capacity = get_capacity(disk); - struct blk_zone_wplug *zwplug; - unsigned long flags; sector_t sector; - unsigned int i; - if (atomic_read(&disk->nr_zone_wplugs)) { - /* Update the condition of all zone write plugs. */ - rcu_read_lock(); - for (i = 0; i < disk_zone_wplugs_hash_size(disk); i++) { - hlist_for_each_entry_rcu(zwplug, - &disk->zone_wplugs_hash[i], - node) { - spin_lock_irqsave(&zwplug->lock, flags); - disk_zone_wplug_set_wp_offset(disk, zwplug, 0); - spin_unlock_irqrestore(&zwplug->lock, flags); - } - } - rcu_read_unlock(); - } + /* Update the condition of all zone write plugs. */ + if (atomic_read(&disk->nr_zone_wplugs)) + disk_for_all_zone_wplugs(disk, disk_zone_wplug_reset_wp, NULL); /* Update the cached zone conditions. */ - for (sector = 0; sector < capacity; + for (sector = 0; sector < get_capacity(disk); sector += bdev_zone_sectors(bio->bi_bdev)) disk_zone_set_cond(disk, sector, BLK_ZONE_COND_EMPTY); clear_bit(GD_ZONE_APPEND_USED, &disk->state); @@ -2538,8 +2552,9 @@ EXPORT_SYMBOL_GPL(blk_zone_issue_zeroout); #ifdef CONFIG_BLK_DEBUG_FS static void queue_zone_wplug_show(struct blk_zone_wplug *zwplug, - struct seq_file *m) + void *data) { + struct seq_file *m = data; unsigned int zwp_wp_offset, zwp_flags; unsigned int zwp_zone_no, zwp_ref; unsigned int zwp_bio_list_size; @@ -2564,19 +2579,8 @@ static void queue_zone_wplug_show(struct blk_zone_wplug *zwplug, int queue_zone_wplugs_show(void *data, struct seq_file *m) { struct request_queue *q = data; - struct gendisk *disk = q->disk; - struct blk_zone_wplug *zwplug; - unsigned int i; - - if (!disk->zone_wplugs_hash) - return 0; - rcu_read_lock(); - for (i = 0; i < disk_zone_wplugs_hash_size(disk); i++) - hlist_for_each_entry_rcu(zwplug, &disk->zone_wplugs_hash[i], - node) - queue_zone_wplug_show(zwplug, m); - rcu_read_unlock(); + disk_for_all_zone_wplugs(q->disk, queue_zone_wplug_show, m); return 0; } -- 2.55.0