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 6CB6A47DD4B for ; Thu, 6 Aug 2026 16:05:03 +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=1786032304; cv=none; b=EuSKqJIV/suzZY4O3QoLDQnzTnd02mCNL6i+A5qXymwzOlZFToRyXMWEmAiGY18IyJRfqBzOCHUG9sZ2cgyq5KZ3St2nf4qx44GUSW9HAjW56bbIdmfXo13/iMlTbusfeegtA4CV3DmikVZ6j4X7wVpQbcbmWLGrPI1QCKgZkJY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786032304; c=relaxed/simple; bh=EZBxnKpzmoOE64p3A1lN7wGrKM/MNhkKHuBPZk6m+hk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BeLOxr0gBLUrcb4gsCD5VZpsD4b16iEtCGYy83OuThuYlMyazCWxkV5lhURdRArs1gV7OoHcPeMOHiUEUfG5vsxbstD864T1+2ktSiYW+RHdEO3Z9+6yHNmzml8CgYoPPO7s7bkU2OdNG58BC2OU0lPxQLs7Zi1V0m36auu9lA4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LbWJcrE0; 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="LbWJcrE0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFA3B1F00A3D; Thu, 6 Aug 2026 16:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786032303; bh=TCptdxFcuCaQkQuEyDq3Vx5ZGKWcnsvbV2Y26l6vIdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LbWJcrE0h+3jOWD02+1laMxxjR3/usIBi5ekh7bRD4dBLiIJFTc+GcNSWdWQyym+R CArS9FHcxqOId8HsEDzW/cTHU3+7EBaaQoH+eJIqPylYK6Z5Z/AtIAaf11BolgTRQp sPRNEErhpw4b2hQO57lUPRypmS5a0amf/KEfHAhn3WDql28z0odyI9GfyW23kqsZSF UMr8Vh2vVxhm8xfCY54hThMnS9ksyElTM35zcG34vyE/yUgL8HUGykTYIFBi7bKH2R 4zgye/4NlKNNtsNZbSSTCi8vceClpupbqYhzceQ6cZhwGiR49op2qQ5gp5srGGAVeX yNueVDG4lI/4A== From: Damien Le Moal To: Jens Axboe , linux-block@vger.kernel.org Cc: Christoph Hellwig Subject: [PATCH v2 08/13] block: propagate readonly and offline conditions to zone write plugs Date: Fri, 7 Aug 2026 01:04:40 +0900 Message-ID: <20260806160445.848337-9-dlemoal@kernel.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260806160445.848337-1-dlemoal@kernel.org> References: <20260806160445.848337-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 When revalidating the zones of a zoned block device, or when handling a zone which has a zone write plug flagged with BLK_ZONE_WPLUG_NEED_WP_UPDATE, the function disk_zone_wplug_sync_wp_offset() is used to update the write pointer offset of a zone write plug. However, this does not take into account the condition of the zone, which may have changed to readonly or offline, which in itself will always cause errors. In order to catch such errors, rename disk_zone_wplug_sync_wp_offset() to disk_zone_wplug_sync_state() and in addition to the zone write pointer, also update the zone write plug condition if the zone is readonly or offline. This change also requires changes to how a reset all zones operation (REQ_OP_ZONE_RESET_ALL) is handled so that the offline or read-only condition of zone write plugs is not overwritten with an erroneous empty condition. To do so, introduce the helper function disk_zone_is_offline_or_readonly() to skip updating the condition of zones that are read-only or offline and that do not have a zone write plug. For zones that have a zone write plug, the helper function disk_zone_wplug_is_offline_or_readonly() is used in disk_zone_wplug_set_wp_offset() to not update a zone write plug write pointer and condition for read-only and offline zones. Signed-off-by: Damien Le Moal --- block/blk-zoned.c | 52 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index e2cbeecb5f03..cb34d0beaf43 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -277,6 +277,29 @@ static inline u8 disk_zone_get_state(struct gendisk *disk, sector_t sector) return zs; } +static enum blk_zone_cond disk_zone_get_cond(struct gendisk *disk, + sector_t sector) +{ + u8 zs = disk_zone_get_state(disk, sector); + + return blk_zstate_to_zone_cond(zs); +} + +static inline bool +disk_zone_cond_is_offline_or_readonly(enum blk_zone_cond cond) +{ + return cond == BLK_ZONE_COND_READONLY || + cond == BLK_ZONE_COND_OFFLINE; +} + +static inline bool disk_zone_is_offline_or_readonly(struct gendisk *disk, + sector_t sector) +{ + enum blk_zone_cond cond = disk_zone_get_cond(disk, sector); + + return disk_zone_cond_is_offline_or_readonly(cond); +} + static bool disk_zone_is_seq(struct gendisk *disk, sector_t sector) { u8 zs = disk_zone_get_state(disk, sector); @@ -587,6 +610,11 @@ static bool disk_zone_wplug_is_full(struct gendisk *disk, return zwplug->wp_offset >= disk->last_zone_capacity; } +static bool disk_zone_wplug_is_offline_or_readonly(struct blk_zone_wplug *zwplug) +{ + return disk_zone_cond_is_offline_or_readonly(zwplug->cond); +} + static bool disk_insert_zone_wplug(struct gendisk *disk, struct blk_zone_wplug *zwplug) { @@ -893,8 +921,10 @@ static void disk_zone_wplug_set_wp_offset(struct gendisk *disk, /* Update the zone write pointer and abort all plugged BIOs. */ zwplug->flags &= ~BLK_ZONE_WPLUG_NEED_WP_UPDATE; - zwplug->wp_offset = wp_offset; - disk_zone_wplug_update_cond(disk, zwplug); + if (!disk_zone_wplug_is_offline_or_readonly(zwplug)) { + zwplug->wp_offset = wp_offset; + disk_zone_wplug_update_cond(disk, zwplug); + } disk_zone_wplug_abort(zwplug); if (!zwplug->wp_offset || disk_zone_wplug_is_full(disk, zwplug)) @@ -924,8 +954,8 @@ static unsigned int blk_zone_wp_offset(struct blk_zone *zone) } } -static unsigned int disk_zone_wplug_sync_wp_offset(struct gendisk *disk, - struct blk_zone *zone) +static unsigned int disk_zone_wplug_sync_state(struct gendisk *disk, + struct blk_zone *zone) { struct blk_zone_wplug *zwplug; unsigned int wp_offset = blk_zone_wp_offset(zone); @@ -937,6 +967,8 @@ static unsigned int disk_zone_wplug_sync_wp_offset(struct gendisk *disk, spin_lock_irqsave(&zwplug->lock, flags); if (zwplug->flags & BLK_ZONE_WPLUG_NEED_WP_UPDATE) disk_zone_wplug_set_wp_offset(disk, zwplug, wp_offset); + if (disk_zone_cond_is_offline_or_readonly(zone->cond)) + zwplug->cond = zone->cond; spin_unlock_irqrestore(&zwplug->lock, flags); disk_put_zone_wplug(zwplug); } @@ -979,7 +1011,7 @@ int disk_report_zone(struct gendisk *disk, struct blk_zone *zone, } if (disk->zone_wplugs_hash) - disk_zone_wplug_sync_wp_offset(disk, zone); + disk_zone_wplug_sync_state(disk, zone); if (args && args->cb) return args->cb(zone, idx, args->data); @@ -1100,8 +1132,7 @@ int blkdev_get_zone_info(struct block_device *bdev, sector_t sector, else zone->capacity = disk->zone_capacity; - if (zone->cond == BLK_ZONE_COND_READONLY || - zone->cond == BLK_ZONE_COND_OFFLINE) { + if (disk_zone_cond_is_offline_or_readonly(zone->cond)) { zone->wp = ULLONG_MAX; return 0; } @@ -1240,8 +1271,11 @@ static void blk_zone_reset_all_bio_endio(struct bio *bio) /* Update the cached zone conditions. */ for (sector = 0; sector < get_capacity(disk); - sector += bdev_zone_sectors(bio->bi_bdev)) + sector += bdev_zone_sectors(bio->bi_bdev)) { + if (disk_zone_is_offline_or_readonly(disk, sector)) + continue; disk_zone_set_cond(disk, sector, BLK_ZONE_COND_EMPTY); + } clear_bit(GD_ZONE_APPEND_USED, &disk->state); } @@ -2356,7 +2390,7 @@ static int blk_revalidate_seq_zone(struct blk_zone *zone, unsigned int idx, if (!disk->zone_wplugs_hash) return 0; - wp_offset = disk_zone_wplug_sync_wp_offset(disk, zone); + wp_offset = disk_zone_wplug_sync_state(disk, zone); if (!wp_offset || wp_offset >= zone->capacity) return 0; -- 2.55.0