diff mbox series

[v3] scsi: scsi_debug: Make the READ CAPACITY response compliant with ZBC

Message ID 20221102193248.3177608-1-bvanassche@acm.org (mailing list archive)
State Accepted
Headers show
Series [v3] scsi: scsi_debug: Make the READ CAPACITY response compliant with ZBC | expand

Commit Message

Bart Van Assche Nov. 2, 2022, 7:32 p.m. UTC
From ZBC-1:
* RC BASIS = 0: The RETURNED LOGICAL BLOCK ADDRESS field indicates the
  highest LBA of a contiguous range of zones that are not sequential write
  required zones starting with the first zone.
* RC BASIS = 1: The RETURNED LOGICAL BLOCK ADDRESS field indicates the LBA
  of the last logical block on the logical unit.

The current scsi_debug READ CAPACITY response does not comply with the above
if there are one or more sequential write required zones. SCSI initiators
need a way to retrieve the largest valid LBA from SCSI devices. Reporting
the largest valid LBA if there are one or more sequential zones requires to
set the RC BASIS field in the READ CAPACITY response to one. Hence this
patch.

Cc: Douglas Gilbert <dgilbert@interlog.com>
Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Suggested-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
Changes between v2 and v3: elaborated the comment added by this patch.

Changes between v1 and v2: simplified this patch as suggested by Damien.

 drivers/scsi/scsi_debug.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Damien Le Moal Nov. 2, 2022, 10:31 p.m. UTC | #1
On 11/3/22 04:32, Bart Van Assche wrote:
> From ZBC-1:
> * RC BASIS = 0: The RETURNED LOGICAL BLOCK ADDRESS field indicates the
>   highest LBA of a contiguous range of zones that are not sequential write
>   required zones starting with the first zone.
> * RC BASIS = 1: The RETURNED LOGICAL BLOCK ADDRESS field indicates the LBA
>   of the last logical block on the logical unit.
> 
> The current scsi_debug READ CAPACITY response does not comply with the above
> if there are one or more sequential write required zones. SCSI initiators
> need a way to retrieve the largest valid LBA from SCSI devices. Reporting
> the largest valid LBA if there are one or more sequential zones requires to
> set the RC BASIS field in the READ CAPACITY response to one. Hence this
> patch.
> 
> Cc: Douglas Gilbert <dgilbert@interlog.com>
> Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> Suggested-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> Changes between v2 and v3: elaborated the comment added by this patch.
> 
> Changes between v1 and v2: simplified this patch as suggested by Damien.
> 
>  drivers/scsi/scsi_debug.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index 697fc57bc711..629853662b82 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -1899,6 +1899,13 @@ static int resp_readcap16(struct scsi_cmnd *scp,
>  			arr[14] |= 0x40;
>  	}
>  
> +	/*
> +	 * Since the scsi_debug READ CAPACITY implementation always reports the
> +	 * total disk capacity, set RC BASIS = 1 for host-managed ZBC devices.
> +	 */
> +	if (devip->zmodel == BLK_ZONED_HM)
> +		arr[12] |= 1 << 4;
> +
>  	arr[15] = sdebug_lowest_aligned & 0xff;
>  
>  	if (have_dif_prot) {

Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Douglas Gilbert Nov. 2, 2022, 10:47 p.m. UTC | #2
On 2022-11-02 15:32, Bart Van Assche wrote:
>>From ZBC-1:
> * RC BASIS = 0: The RETURNED LOGICAL BLOCK ADDRESS field indicates the
>    highest LBA of a contiguous range of zones that are not sequential write
>    required zones starting with the first zone.
> * RC BASIS = 1: The RETURNED LOGICAL BLOCK ADDRESS field indicates the LBA
>    of the last logical block on the logical unit.
> 
> The current scsi_debug READ CAPACITY response does not comply with the above
> if there are one or more sequential write required zones. SCSI initiators
> need a way to retrieve the largest valid LBA from SCSI devices. Reporting
> the largest valid LBA if there are one or more sequential zones requires to
> set the RC BASIS field in the READ CAPACITY response to one. Hence this
> patch.
> 
> Cc: Douglas Gilbert <dgilbert@interlog.com>
> Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> Suggested-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>

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

> ---
> Changes between v2 and v3: elaborated the comment added by this patch.
> 
> Changes between v1 and v2: simplified this patch as suggested by Damien.
> 
>   drivers/scsi/scsi_debug.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index 697fc57bc711..629853662b82 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -1899,6 +1899,13 @@ static int resp_readcap16(struct scsi_cmnd *scp,
>   			arr[14] |= 0x40;
>   	}
>   
> +	/*
> +	 * Since the scsi_debug READ CAPACITY implementation always reports the
> +	 * total disk capacity, set RC BASIS = 1 for host-managed ZBC devices.
> +	 */
> +	if (devip->zmodel == BLK_ZONED_HM)
> +		arr[12] |= 1 << 4;
> +
>   	arr[15] = sdebug_lowest_aligned & 0xff;
>   
>   	if (have_dif_prot) {
Martin K. Petersen Nov. 8, 2022, 4:01 a.m. UTC | #3
On Wed, 2 Nov 2022 12:32:48 -0700, Bart Van Assche wrote:

> From ZBC-1:
> * RC BASIS = 0: The RETURNED LOGICAL BLOCK ADDRESS field indicates the
>   highest LBA of a contiguous range of zones that are not sequential write
>   required zones starting with the first zone.
> * RC BASIS = 1: The RETURNED LOGICAL BLOCK ADDRESS field indicates the LBA
>   of the last logical block on the logical unit.
> 
> [...]

Applied to 6.1/scsi-fixes, thanks!

[1/1] scsi: scsi_debug: Make the READ CAPACITY response compliant with ZBC
      https://git.kernel.org/mkp/scsi/c/ecb8c2580d37
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 697fc57bc711..629853662b82 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -1899,6 +1899,13 @@  static int resp_readcap16(struct scsi_cmnd *scp,
 			arr[14] |= 0x40;
 	}
 
+	/*
+	 * Since the scsi_debug READ CAPACITY implementation always reports the
+	 * total disk capacity, set RC BASIS = 1 for host-managed ZBC devices.
+	 */
+	if (devip->zmodel == BLK_ZONED_HM)
+		arr[12] |= 1 << 4;
+
 	arr[15] = sdebug_lowest_aligned & 0xff;
 
 	if (have_dif_prot) {