Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Damien Le Moal" <dlemoal@kernel.org>, linux-scsi@vger.kernel.org
Subject: Re: [PATCH v10 08/13] zloop: add storage element emulation
Date: Sun, 15 Nov 2026 23:58:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-215934@kernel.org> (raw)
In-Reply-To: <20261115233327.941586-9-dlemoal@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] zloop: stale zone state on partial failure in
  zloop_execute_restore_elements()
- [Medium] zloop: zloop_rdwr_is_ok() blocks ZLOOP_ZONE_SEQ_ERROR
  recovery on full zones
- [Medium] zloop: race between storage element ops and
  zloop_ctl_remove()
--

commit 8e8c9e4aeea297b926b2b865b9d40a12a001bcbe
Author: Damien Le Moal <dlemoal@kernel.org>

zloop: add storage element emulation

This commit adds storage element depopulation emulation to the zloop
driver, controlled via the new stor_elements option and implemented
through zloop_se_ops.

> diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
> index eb51c8e1cc189..26018e9e567c6 100644
> --- a/drivers/block/zloop.c
> +++ b/drivers/block/zloop.c

[ ... ]

> @@ -876,6 +988,43 @@ static void zloop_complete_rq(struct request *rq)
>  	blk_mq_end_request(rq, sts);
>  }
>  
> +static bool zloop_rdwr_is_ok(struct zloop_device *zlo, struct request *rq)
> +{
> +	struct zloop_zone *zone = &zlo->zones[rq_zone_no(rq)];
> +	bool is_write = op_is_write(req_op(rq));
> +	enum blk_se_status sts = zloop_zone_element_status(zlo, zone, is_write);
> +	bool ret;
> +
> +	/*
> +	 * Fail read and write operations if the storage element serving the
> +	 * target zone is not healthy.
> +	 */
> +	if (sts >= BLK_SE_STS_DEGRADED)
> +		return false;
> +
> +	/*
> +	 * Check the zone condition: do not allow any read and write operations
> +	 * to offline zones, and allow only read operations to full and
> +	 * read-only zones.
> +	 */
> +	spin_lock(&zone->wp_lock);
> +	switch (zone->cond) {
> +	case BLK_ZONE_COND_OFFLINE:
> +		ret = false;
> +		break;
> +	case BLK_ZONE_COND_FULL:
> +	case BLK_ZONE_COND_READONLY:
> +		ret = !is_write;
> +		break;
> +	default:
> +		ret = true;
> +		break;
> +	}
> +	spin_unlock(&zone->wp_lock);
> +
> +	return ret;
> +}
> +
>  static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,
>  				   const struct blk_mq_queue_data *bd)
>  {
> @@ -889,6 +1038,30 @@ static blk_status_t zloop_queue_rq(struct blk_mq_hw_ctx *hctx,
>  		return BLK_STS_IOERR;
>  	}
>  
> +	if (zlo->nr_elements) {
> +		/*
> +		 * Do not allow commands while the restoration of storage
> +		 * elements is in progress.
> +		 */
> +		if (READ_ONCE(zlo->restore_in_progress))
> +			return BLK_STS_IOERR;
> +
> +		/*
> +		 * Check if we can accept data access commands based on the
> +		 * health state of the storage element serving the target zone.
> +		 */
> +		switch (req_op(rq)) {
> +		case REQ_OP_READ:
> +		case REQ_OP_WRITE:
> +		case REQ_OP_ZONE_APPEND:
> +			if (!zloop_rdwr_is_ok(zlo, rq))
> +				return BLK_STS_IOERR;
> +			break;
> +		default:
> +			break;
> +		}
> +	}

[Severity: Medium]
Does rejecting writes to BLK_ZONE_COND_FULL zones in zloop_rdwr_is_ok()
prevent ZLOOP_ZONE_SEQ_ERROR recovery?

zloop_seq_write_prep() advances zone->wp and calls zloop_set_zone_full()
when zone->wp reaches zone_end before zloop_do_rw() writes to the backing
file.  If that write fails, zloop_complete_rq() sets ZLOOP_ZONE_SEQ_ERROR
so the next I/O will resynchronize zone->wp and zone->cond from the file
size in zloop_rw() -> zloop_update_seq_zone().  When zlo->nr_elements is
non-zero, however, zloop_queue_rq() calls zloop_rdwr_is_ok() before
queueing cmd->work, so subsequent writes or zone appends to that zone fail
immediately with BLK_STS_IOERR and never reach zloop_rw().

[ ... ]

> +static int zloop_execute_restore_elements(struct zloop_device *zlo)
> +{
> +	struct gendisk *disk = zlo->disk;
> +	struct zloop_zone *zone;
> +	struct blk_se *se;
> +	enum blk_se_status sts;
> +	unsigned int memflags, i;
> +	int ret = 0;
> +
> +	/* Wait for all IOs to complete. */
> +	memflags = blk_mq_freeze_queue(disk->queue);
> +	blk_mq_unfreeze_queue(disk->queue, memflags);
> +
> +	/* First, truncate all files for sequential zones. */
> +	for (i = 0, zone = zlo->zones; i < zlo->nr_zones; i++, zone++) {
> +		ret = zloop_restore_zone_file(zlo, zone);
> +		if (ret) {
> +			pr_err("zloop%d: restore zone %u file failed %d\n",
> +			       zlo->id, i, ret);
> +			break;
> +		}
> +	}
> +
> +	/*
> +	 * Now, resetore the condition of all zones, unless we failed to
> +	 * truncate all files, in which case we report a restoration error
> +	 * without changing the zone conditions.
> +	 */
> +	if (!ret) {
> +		for (i = 0, zone = zlo->zones; i < zlo->nr_zones; i++, zone++)
> +			zloop_restore_zone_cond(zlo, zone);
> +		sts = BLK_SE_STS_OK;
> +	} else {
> +		sts = BLK_SE_STS_RESTORE_ERROR;
> +	}

[Severity: Medium]
If zloop_restore_zone_file() fails on zone i, do sequential zones before i
keep stale in-memory zone conditions and write pointers?

Those earlier sequential zones have already had their backing files
truncated to 0 bytes by vfs_truncate(), but zloop_restore_zone_cond() is
skipped when ret is non-zero and ZLOOP_ZONE_SEQ_ERROR is only set on the
zone that failed.  Earlier non-empty zones are left with 0-byte backing
files while retaining their old zone->cond, non-zero zone->wp, and
open_zones_lru_list accounting, which zloop_report_zones() will then
report as-is.

> +
> +	/*
> +	 * Update the status of all elements being restored based on the zone
> +	 * restoration result.
> +	 */
> +	for (i = 0, se = zlo->elements; i < zlo->nr_elements; i++, se++) {
> +		if (READ_ONCE(se->status) == BLK_SE_STS_RESTORE_IN_PROGRESS)
> +			WRITE_ONCE(se->status, sts);
> +	}
> +
> +	return ret;
> +}
> +
> +static int zloop_restore_elements(struct gendisk *disk)
> +{

[ ... ]

> +	msleep(5000);
> +
> +	mutex_lock(&zlo->stor_elements_lock);
> +
> +	/*
> +	 * Re-check the device as its removal may have been initiated
> +	 * while we were sleeping.
> +	 */
> +	if (test_bit(GD_DEAD, &disk->state) ||
> +	    data_race(READ_ONCE(zlo->state)) == Zlo_deleting) {
> +		ret = -ENODEV;
> +		goto clear_restore;
> +	}
> +
> +	/* Restore the elements. */
> +	ret = zloop_execute_restore_elements(zlo);

[Severity: Medium]
Can zloop_restore_elements() and zloop_remove_element() race with
zloop_ctl_remove() right after the post-sleep check?

zloop_ctl_remove() sets zlo->state to Zlo_deleting under zloop_ctl_mutex
without synchronizing with zlo->stor_elements_lock:

CPU0                                  CPU1
zloop_restore_elements()
  mutex_lock(&zlo->stor_elements_lock)
  /* checks GD_DEAD and zlo->state */
                                      zloop_ctl_remove()
                                        mutex_lock_killable(&zloop_ctl_mutex)
                                        WRITE_ONCE(zlo->state, Zlo_deleting)
                                        mutex_unlock(&zloop_ctl_mutex)
                                        del_gendisk(zlo->disk)
  zloop_execute_restore_elements()
    zloop_restore_zone_file()
      vfs_truncate(..., 0)
                                        zloop_forget_cache()
                                          /* sees active zone->cond / wp */
                                          vfs_truncate(..., old_wp - start)
    zloop_restore_zone_cond()

Because zloop_execute_restore_elements() truncates all sequential zone
files to 0 in a first pass before resetting zone->cond and zone->wp in a
second pass, a concurrent zloop_forget_cache() still sees active zone
conditions and extends the truncated zone files back to old_wp.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115233327.941586-1-dlemoal@kernel.org?part=8

  reply	other threads:[~2026-11-15 23:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15 23:33 [PATCH v10 00/13] Add support for storage element depopulation Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 01/13] block: introduce disk_zone_is_offline() Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 02/13] block: refactor blk_revalidate_disk_zones() Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 03/13] block: allow dropping all zone write plugs on revalidation Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 04/13] block: introduce storage element management Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 05/13] block: add storage element management ioctls Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 06/13] zloop: fix ordered zone append handling Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 07/13] zloop: fix zone reporting consistency Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 08/13] zloop: add storage element emulation Damien Le Moal
2026-11-15 23:58   ` sashiko-bot [this message]
2026-11-15 23:33 ` [PATCH v10 09/13] zloop: add degrade_element control command Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 10/13] scsi: scsi_proto: refine the definition of storage element health Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 11/13] scsi: sd_zbc: always revalidate zones for disks supporting head depopulation Damien Le Moal
2026-11-15 23:33 ` [PATCH v10 12/13] scsi: sd_zbc: define storage element management operations Damien Le Moal
2026-11-16  0:04   ` sashiko-bot
2026-11-15 23:33 ` [PATCH v10 13/13] scsi: sd: fail read commands to offline zones early 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=sashiko-outbox-215934@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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