diff mbox series

scsi: scsi_debug: Zero clear zones at reset write pointer

Message ID 20211119102204.259762-1-shinichiro.kawasaki@wdc.com (mailing list archive)
State Superseded
Headers show
Series scsi: scsi_debug: Zero clear zones at reset write pointer | expand

Commit Message

Shin'ichiro Kawasaki Nov. 19, 2021, 10:22 a.m. UTC
When reset write pointer is requested to scsi_debug devices with zoned
model, positions of write pointers are reset, but the data in the target
zones are not cleared. Read to the zones returns data written before the
reset write pointer. This unexpected left data is confusing and does not
allow using scsi_debug for stale page cache test of the BLKRESETZONE
ioctl. Hence, zero clear the target zones at reset write pointer.

Fixes: f0d1cf9378bd ("scsi: scsi_debug: Add ZBC zone commands")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 drivers/scsi/scsi_debug.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Damien Le Moal Nov. 19, 2021, 10:34 p.m. UTC | #1
On 11/19/21 19:22, Shin'ichiro Kawasaki wrote:
> When reset write pointer is requested to scsi_debug devices with zoned
> model, positions of write pointers are reset, but the data in the target
> zones are not cleared. Read to the zones returns data written before the
> reset write pointer. This unexpected left data is confusing and does not
> allow using scsi_debug for stale page cache test of the BLKRESETZONE
> ioctl. Hence, zero clear the target zones at reset write pointer.
> 
> Fixes: f0d1cf9378bd ("scsi: scsi_debug: Add ZBC zone commands")
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> ---
>  drivers/scsi/scsi_debug.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index 1d0278da9041..6d1f1a4a6724 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -4653,6 +4653,7 @@ static void zbc_rwp_zone(struct sdebug_dev_info *devip,
>  			 struct sdeb_zone_state *zsp)
>  {
>  	enum sdebug_z_cond zc;
> +	struct sdeb_store_info *sip = devip2sip(devip, false);
>  
>  	if (zbc_zone_is_conv(zsp))
>  		return;
> @@ -4667,6 +4668,9 @@ static void zbc_rwp_zone(struct sdebug_dev_info *devip,
>  	zsp->z_non_seq_resource = false;
>  	zsp->z_wp = zsp->z_start;
>  	zsp->z_cond = ZC1_EMPTY;
> +
> +	memset(sip->storep + zsp->z_start * sdebug_sector_size, 0,
> +	       devip->zsize * sdebug_sector_size);

May be do this only if the zone is *not* already empty ? Resetting an
empty zone is not an error, and in that case there will be no need for
the memset(). This will avoid a lot of memset() when this function is
called from zbc_rwp_all() to handle an all zone reset operation.

>  }
>  
>  static void zbc_rwp_all(struct sdebug_dev_info *devip)
>
Shin'ichiro Kawasaki Nov. 22, 2021, 5:22 a.m. UTC | #2
On Nov 20, 2021 / 07:34, Damien Le Moal wrote:
> On 11/19/21 19:22, Shin'ichiro Kawasaki wrote:
> > When reset write pointer is requested to scsi_debug devices with zoned
> > model, positions of write pointers are reset, but the data in the target
> > zones are not cleared. Read to the zones returns data written before the
> > reset write pointer. This unexpected left data is confusing and does not
> > allow using scsi_debug for stale page cache test of the BLKRESETZONE
> > ioctl. Hence, zero clear the target zones at reset write pointer.
> > 
> > Fixes: f0d1cf9378bd ("scsi: scsi_debug: Add ZBC zone commands")
> > Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> > ---
> >  drivers/scsi/scsi_debug.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> > index 1d0278da9041..6d1f1a4a6724 100644
> > --- a/drivers/scsi/scsi_debug.c
> > +++ b/drivers/scsi/scsi_debug.c
> > @@ -4653,6 +4653,7 @@ static void zbc_rwp_zone(struct sdebug_dev_info *devip,
> >  			 struct sdeb_zone_state *zsp)
> >  {
> >  	enum sdebug_z_cond zc;
> > +	struct sdeb_store_info *sip = devip2sip(devip, false);
> >  
> >  	if (zbc_zone_is_conv(zsp))
> >  		return;
> > @@ -4667,6 +4668,9 @@ static void zbc_rwp_zone(struct sdebug_dev_info *devip,
> >  	zsp->z_non_seq_resource = false;
> >  	zsp->z_wp = zsp->z_start;
> >  	zsp->z_cond = ZC1_EMPTY;
> > +
> > +	memset(sip->storep + zsp->z_start * sdebug_sector_size, 0,
> > +	       devip->zsize * sdebug_sector_size);
> 
> May be do this only if the zone is *not* already empty ? Resetting an
> empty zone is not an error, and in that case there will be no need for
> the memset(). This will avoid a lot of memset() when this function is
> called from zbc_rwp_all() to handle an all zone reset operation.

That sounds a good idea. Also, we can reduce the number of bytes to zero clear
by limiting the clear target between z->start and z->wp. Will post v2 with that
change.

> 
> >  }
> >  
> >  static void zbc_rwp_all(struct sdebug_dev_info *devip)
> > 
> 
> 
> -- 
> Damien Le Moal
> Western Digital Research
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 1d0278da9041..6d1f1a4a6724 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -4653,6 +4653,7 @@  static void zbc_rwp_zone(struct sdebug_dev_info *devip,
 			 struct sdeb_zone_state *zsp)
 {
 	enum sdebug_z_cond zc;
+	struct sdeb_store_info *sip = devip2sip(devip, false);
 
 	if (zbc_zone_is_conv(zsp))
 		return;
@@ -4667,6 +4668,9 @@  static void zbc_rwp_zone(struct sdebug_dev_info *devip,
 	zsp->z_non_seq_resource = false;
 	zsp->z_wp = zsp->z_start;
 	zsp->z_cond = ZC1_EMPTY;
+
+	memset(sip->storep + zsp->z_start * sdebug_sector_size, 0,
+	       devip->zsize * sdebug_sector_size);
 }
 
 static void zbc_rwp_all(struct sdebug_dev_info *devip)