From: Damien Le Moal <damien.lemoal@opensource.wdc.com>
To: linux-scsi@vger.kernel.org,
"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: Douglas Gilbert <dgilbert@interlog.com>
Subject: [PATCH] scsi: scsi_debug: fix zone transition to full condition
Date: Tue, 7 Jun 2022 10:49:42 +0900 [thread overview]
Message-ID: <20220607014942.38384-1-damien.lemoal@opensource.wdc.com> (raw)
When a write command to a sequential write required or sequential write
preferred zone result in the zone write pointer reaching the end of the
zone, the zone condition must be set to full AND the number of
implicitly or explicitly open zones updated to have a correct accounting
for zone resources. However, the function zbc_inc_wp() only sets the
zone condition to full without updating the open zone counters,
resulting in a zone state machine breakage.
Factor out the correct code from zbc_finish_zone() to transition a zone
to the full condition and introduce the helper zbc_set_zone_full(). Use
this helper in zbc_finish_zone() and zbc_inc_wp() to correctly
transition zones to the full condition.
Fixes: 0d1cf9378bd4 ("scsi: scsi_debug: Add ZBC zone commands")
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
drivers/scsi/scsi_debug.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 1f423f723d06..6c2bb02a42d8 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2826,6 +2826,19 @@ static void zbc_open_zone(struct sdebug_dev_info *devip,
}
}
+static inline void zbc_set_zone_full(struct sdebug_dev_info *devip,
+ struct sdeb_zone_state *zsp)
+{
+ enum sdebug_z_cond zc = zsp->z_cond;
+
+ if (zc == ZC2_IMPLICIT_OPEN || zc == ZC3_EXPLICIT_OPEN)
+ zbc_close_zone(devip, zsp);
+ if (zsp->z_cond == ZC4_CLOSED)
+ devip->nr_closed--;
+ zsp->z_wp = zsp->z_start + zsp->z_size;
+ zsp->z_cond = ZC5_FULL;
+}
+
static void zbc_inc_wp(struct sdebug_dev_info *devip,
unsigned long long lba, unsigned int num)
{
@@ -2838,7 +2851,7 @@ static void zbc_inc_wp(struct sdebug_dev_info *devip,
if (zsp->z_type == ZBC_ZTYPE_SWR) {
zsp->z_wp += num;
if (zsp->z_wp >= zend)
- zsp->z_cond = ZC5_FULL;
+ zbc_set_zone_full(devip, zsp);
return;
}
@@ -2857,7 +2870,7 @@ static void zbc_inc_wp(struct sdebug_dev_info *devip,
n = num;
}
if (zsp->z_wp >= zend)
- zsp->z_cond = ZC5_FULL;
+ zbc_set_zone_full(devip, zsp);
num -= n;
lba += n;
@@ -4731,14 +4744,8 @@ static void zbc_finish_zone(struct sdebug_dev_info *devip,
enum sdebug_z_cond zc = zsp->z_cond;
if (zc == ZC4_CLOSED || zc == ZC2_IMPLICIT_OPEN ||
- zc == ZC3_EXPLICIT_OPEN || (empty && zc == ZC1_EMPTY)) {
- if (zc == ZC2_IMPLICIT_OPEN || zc == ZC3_EXPLICIT_OPEN)
- zbc_close_zone(devip, zsp);
- if (zsp->z_cond == ZC4_CLOSED)
- devip->nr_closed--;
- zsp->z_wp = zsp->z_start + zsp->z_size;
- zsp->z_cond = ZC5_FULL;
- }
+ zc == ZC3_EXPLICIT_OPEN || (empty && zc == ZC1_EMPTY))
+ zbc_set_zone_full(devip, zsp);
}
static void zbc_finish_all(struct sdebug_dev_info *devip)
--
2.36.1
next reply other threads:[~2022-06-07 1:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-07 1:49 Damien Le Moal [this message]
2022-06-07 9:16 ` [PATCH] scsi: scsi_debug: fix zone transition to full condition Niklas Cassel
2022-06-07 9:25 ` Damien Le Moal
2022-06-07 9:37 ` Niklas Cassel
2022-06-07 9:40 ` Damien Le Moal
2022-06-07 10:05 ` Niklas Cassel
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=20220607014942.38384-1-damien.lemoal@opensource.wdc.com \
--to=damien.lemoal@opensource.wdc.com \
--cc=dgilbert@interlog.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
/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