Skip to contentSkip to conversation

scsi: scsi_debug: fix zone transition to full condition

PATCH Applied Damien Le Moal 4 participants 6 messages Jun 8, 2022 – Jun 12, 2022 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi: scsi_debug: fix zone transition to full condition

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.

Introduce the helper function zbc_set_zone_full() and use it in zbc_inc_wp() to correctly transition zones to the full condition.

Fixes 0d1cf9378bd4 ("scsi: scsi_debug: Add ZBC zone commands")

---
Changes from v1:
* Simplify the patch to not modify the zbc_finish_zone() function and not use the CLOSED zone condition as an intermediate state in zbc_set_zone_full(). Cleanups to remove the use of the closed condition as an intermediate state will be sent later.

 drivers/scsi/scsi_debug.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/scsi/scsi_debug.c +20 -2
index 1f423f723d06..b8a76b89f85a 100644
@@ -2826,6 +2826,24 @@ 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)
+{
+	switch (zsp->z_cond) {
+	case ZC2_IMPLICIT_OPEN:
+		devip->nr_imp_open--;
+		break;
+	case ZC3_EXPLICIT_OPEN:
+		devip->nr_exp_open--;
+		break;
+	default:
+		WARN_ONCE(true, "Invalid zone %llu condition %x\n",
+			  zsp->z_start, zsp->z_cond);
+		break;
+	}
+	zsp->z_cond = ZC5_FULL;
+}
+
 static void zbc_inc_wp(struct sdebug_dev_info *devip,
 		       unsigned long long lba, unsigned int num)
 {
@@ -2838,7 +2856,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 +2875,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;
Signature · 1 line
2.36.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 20 lines · Damien Le Moal

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.

Introduce the helper function zbc_set_zone_full() and use it in zbc_inc_wp() to correctly transition zones to the full condition.

Fixes 0d1cf9378bd4 ("scsi: scsi_debug: Add ZBC zone commands")

---
Changes from v1:
* Simplify the patch to not modify the zbc_finish_zone() function and not use the CLOSED zone condition as an intermediate state in zbc_set_zone_full(). Cleanups to remove the use of the closed condition as an intermediate state will be sent later.

Quoted 2 lines
 drivers/scsi/scsi_debug.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
#2 lore raw
Quoted 21 lines · Niklas Cassel
Quoted 20 lines · Damien Le Moal

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.

Introduce the helper function zbc_set_zone_full() and use it in zbc_inc_wp() to correctly transition zones to the full condition.

Fixes 0d1cf9378bd4 ("scsi: scsi_debug: Add ZBC zone commands")

---
Changes from v1:
* Simplify the patch to not modify the zbc_finish_zone() function and not use the CLOSED zone condition as an intermediate state in zbc_set_zone_full(). Cleanups to remove the use of the closed condition as an intermediate state will be sent later.

Quoted 4 lines
Quoted 2 lines
  drivers/scsi/scsi_debug.c | 22 ++++++++++++++++++++--
  1 file changed, 20 insertions(+), 2 deletions(-)
#3 lore raw
In reply to Damien Le Moal

Damien,

Quoted 1 line
Fixes 0d1cf9378bd4 ("scsi: scsi_debug: Add ZBC zone commands")

Not sure where this SHA is from?

I fixed it up...

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#4 lore raw
Quoted 8 lines · Martin K. Petersen

Damien,

Quoted 1 line
Fixes 0d1cf9378bd4 ("scsi: scsi_debug: Add ZBC zone commands")

Not sure where this SHA is from?

I fixed it up...

Oops. Off by one character. Missing the leading "f". The sha is:

f0d1cf9378bd ("scsi: scsi_debug: Add ZBC zone commands")

Sorry about that.

Signature · 2 lines
Damien Le Moal
Western Digital Research
#5 lore raw
In reply to Damien Le Moal
Quoted 9 lines · Damien Le Moal

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.

[...]

Applied to 5.19/scsi-fixes, thanks!

[1/1] scsi: scsi_debug: fix zone transition to full condition

      https://git.kernel.org/mkp/scsi/c/566d3c57eb52
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering