Skip to content

Commit 566d3c5

Browse files
Damien Le Moalmartinkpetersen
authored andcommitted
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. Link: https://lore.kernel.org/r/20220608011302.92061-1-damien.lemoal@opensource.wdc.com Fixes: f0d1cf9 ("scsi: scsi_debug: Add ZBC zone commands") Reviewed-by: Niklas Cassel <niklas.cassel@wdc.com> Acked-by: Douglas Gilbert <dgilbert@interlog.com> Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent ec1e8ad commit 566d3c5

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

drivers/scsi/scsi_debug.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,24 @@ static void zbc_open_zone(struct sdebug_dev_info *devip,
28262826
}
28272827
}
28282828

2829+
static inline void zbc_set_zone_full(struct sdebug_dev_info *devip,
2830+
struct sdeb_zone_state *zsp)
2831+
{
2832+
switch (zsp->z_cond) {
2833+
case ZC2_IMPLICIT_OPEN:
2834+
devip->nr_imp_open--;
2835+
break;
2836+
case ZC3_EXPLICIT_OPEN:
2837+
devip->nr_exp_open--;
2838+
break;
2839+
default:
2840+
WARN_ONCE(true, "Invalid zone %llu condition %x\n",
2841+
zsp->z_start, zsp->z_cond);
2842+
break;
2843+
}
2844+
zsp->z_cond = ZC5_FULL;
2845+
}
2846+
28292847
static void zbc_inc_wp(struct sdebug_dev_info *devip,
28302848
unsigned long long lba, unsigned int num)
28312849
{
@@ -2838,7 +2856,7 @@ static void zbc_inc_wp(struct sdebug_dev_info *devip,
28382856
if (zsp->z_type == ZBC_ZTYPE_SWR) {
28392857
zsp->z_wp += num;
28402858
if (zsp->z_wp >= zend)
2841-
zsp->z_cond = ZC5_FULL;
2859+
zbc_set_zone_full(devip, zsp);
28422860
return;
28432861
}
28442862

@@ -2857,7 +2875,7 @@ static void zbc_inc_wp(struct sdebug_dev_info *devip,
28572875
n = num;
28582876
}
28592877
if (zsp->z_wp >= zend)
2860-
zsp->z_cond = ZC5_FULL;
2878+
zbc_set_zone_full(devip, zsp);
28612879

28622880
num -= n;
28632881
lba += n;

0 commit comments

Comments
 (0)