public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] scsi: scsi_debug: fix zone transition to full condition
@ 2022-06-08  1:13 Damien Le Moal
  2022-06-08  1:52 ` Niklas Cassel
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Damien Le Moal @ 2022-06-08  1:13 UTC (permalink / raw)
  To: linux-scsi, Martin K . Petersen; +Cc: Douglas Gilbert, Niklas Cassel

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")
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
---
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(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 1f423f723d06..b8a76b89f85a 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -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;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] scsi: scsi_debug: fix zone transition to full condition
  2022-06-08  1:13 [PATCH v2] scsi: scsi_debug: fix zone transition to full condition Damien Le Moal
@ 2022-06-08  1:52 ` Niklas Cassel
  2022-06-08 17:52   ` Douglas Gilbert
  2022-06-10 16:51 ` Martin K. Petersen
  2022-06-10 17:44 ` Martin K. Petersen
  2 siblings, 1 reply; 6+ messages in thread
From: Niklas Cassel @ 2022-06-08  1:52 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: linux-scsi@vger.kernel.org, Martin K . Petersen, Douglas Gilbert

On Wed, Jun 08, 2022 at 10:13:02AM +0900, Damien Le Moal wrote:
> 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")
> Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> ---
> 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(-)

Reviewed-by: Niklas Cassel <niklas.cassel@wdc.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] scsi: scsi_debug: fix zone transition to full condition
  2022-06-08  1:52 ` Niklas Cassel
@ 2022-06-08 17:52   ` Douglas Gilbert
  0 siblings, 0 replies; 6+ messages in thread
From: Douglas Gilbert @ 2022-06-08 17:52 UTC (permalink / raw)
  To: Niklas Cassel, Damien Le Moal
  Cc: linux-scsi@vger.kernel.org, Martin K . Petersen

On 2022-06-08 03:52, Niklas Cassel wrote:
> On Wed, Jun 08, 2022 at 10:13:02AM +0900, Damien Le Moal wrote:
>> 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")
>> Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
>> ---
>> 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(-)
> 
> Reviewed-by: Niklas Cassel <niklas.cassel@wdc.com>

Acked-by: Douglas Gilbert <dgilbert@interlog.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] scsi: scsi_debug: fix zone transition to full condition
  2022-06-08  1:13 [PATCH v2] scsi: scsi_debug: fix zone transition to full condition Damien Le Moal
  2022-06-08  1:52 ` Niklas Cassel
@ 2022-06-10 16:51 ` Martin K. Petersen
  2022-06-12 22:51   ` Damien Le Moal
  2022-06-10 17:44 ` Martin K. Petersen
  2 siblings, 1 reply; 6+ messages in thread
From: Martin K. Petersen @ 2022-06-10 16:51 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: linux-scsi, Martin K . Petersen, Douglas Gilbert, Niklas Cassel


Damien,

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

Not sure where this SHA is from?

I fixed it up...

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] scsi: scsi_debug: fix zone transition to full condition
  2022-06-08  1:13 [PATCH v2] scsi: scsi_debug: fix zone transition to full condition Damien Le Moal
  2022-06-08  1:52 ` Niklas Cassel
  2022-06-10 16:51 ` Martin K. Petersen
@ 2022-06-10 17:44 ` Martin K. Petersen
  2 siblings, 0 replies; 6+ messages in thread
From: Martin K. Petersen @ 2022-06-10 17:44 UTC (permalink / raw)
  To: Damien Le Moal, linux-scsi
  Cc: Martin K . Petersen, Niklas Cassel, Douglas Gilbert

On Wed, 8 Jun 2022 10:13:02 +0900, Damien Le Moal wrote:

> 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

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] scsi: scsi_debug: fix zone transition to full condition
  2022-06-10 16:51 ` Martin K. Petersen
@ 2022-06-12 22:51   ` Damien Le Moal
  0 siblings, 0 replies; 6+ messages in thread
From: Damien Le Moal @ 2022-06-12 22:51 UTC (permalink / raw)
  To: Martin K. Petersen; +Cc: linux-scsi, Douglas Gilbert, Niklas Cassel

On 6/11/22 01:51, Martin K. Petersen wrote:
> 
> Damien,
> 
>> 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.


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-12 22:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-08  1:13 [PATCH v2] scsi: scsi_debug: fix zone transition to full condition Damien Le Moal
2022-06-08  1:52 ` Niklas Cassel
2022-06-08 17:52   ` Douglas Gilbert
2022-06-10 16:51 ` Martin K. Petersen
2022-06-12 22:51   ` Damien Le Moal
2022-06-10 17:44 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox