diff mbox series

[v2,6/7] scsi: scsi_debug: Reset tape setting at device reset

Message ID 20250213092636.2510-7-Kai.Makisara@kolumbus.fi
State Superseded
Headers show
Series scsi: scsi_debug: Add more tape support | expand

Commit Message

Kai Mäkisara Feb. 13, 2025, 9:26 a.m. UTC
Set tape block size, density and compression to default values when the
device is reset (either directly or via target, bus or host reset).

Signed-off-by: Kai Mäkisara <Kai.Makisara@kolumbus.fi>
---
 drivers/scsi/scsi_debug.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

Comments

John Meneghini Feb. 19, 2025, 9:58 p.m. UTC | #1
Reviewed-by: John Meneghini <jmeneghi@redhat.com>
Tested-by: John Meneghini <jmeneghi@redhat.com>


On 2/13/25 4:26 AM, Kai Mäkisara wrote:
> Set tape block size, density and compression to default values when the
> device is reset (either directly or via target, bus or host reset).
> 
> Signed-off-by: Kai Mäkisara <Kai.Makisara@kolumbus.fi>
> ---
>   drivers/scsi/scsi_debug.c | 21 ++++++++++++++++++++-
>   1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index 0a5cd35c41de..7da1758da3f5 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -6772,6 +6772,20 @@ static int sdebug_fail_lun_reset(struct scsi_cmnd *cmnd)
>   	return 0;
>   }
>   
> +static void scsi_tape_reset_clear(struct sdebug_dev_info *devip)
> +{
> +	if (sdebug_ptype == TYPE_TAPE) {
> +		int i;
> +
> +		devip->tape_blksize = TAPE_DEF_BLKSIZE;
> +		devip->tape_density = TAPE_DEF_DENSITY;
> +		devip->tape_partition = 0;
> +		devip->tape_dce = 0;
> +		for (i = 0; i < TAPE_MAX_PARTITIONS; i++)
> +			devip->tape_location[i] = 0;
> +	}
> +}
> +
>   static int scsi_debug_device_reset(struct scsi_cmnd *SCpnt)
>   {
>   	struct scsi_device *sdp = SCpnt->device;
> @@ -6785,8 +6799,10 @@ static int scsi_debug_device_reset(struct scsi_cmnd *SCpnt)
>   		sdev_printk(KERN_INFO, sdp, "%s\n", __func__);
>   
>   	scsi_debug_stop_all_queued(sdp);
> -	if (devip)
> +	if (devip) {
>   		set_bit(SDEBUG_UA_POR, devip->uas_bm);
> +		scsi_tape_reset_clear(devip);
> +	}
>   
>   	if (sdebug_fail_lun_reset(SCpnt)) {
>   		scmd_printk(KERN_INFO, SCpnt, "fail lun reset 0x%x\n", opcode);
> @@ -6824,6 +6840,7 @@ static int scsi_debug_target_reset(struct scsi_cmnd *SCpnt)
>   	list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) {
>   		if (devip->target == sdp->id) {
>   			set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm);
> +			scsi_tape_reset_clear(devip);
>   			++k;
>   		}
>   	}
> @@ -6855,6 +6872,7 @@ static int scsi_debug_bus_reset(struct scsi_cmnd *SCpnt)
>   
>   	list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) {
>   		set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm);
> +		scsi_tape_reset_clear(devip);
>   		++k;
>   	}
>   
> @@ -6878,6 +6896,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd *SCpnt)
>   		list_for_each_entry(devip, &sdbg_host->dev_info_list,
>   				    dev_list) {
>   			set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm);
> +			scsi_tape_reset_clear(devip);
>   			++k;
>   		}
>   	}
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 0a5cd35c41de..7da1758da3f5 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -6772,6 +6772,20 @@  static int sdebug_fail_lun_reset(struct scsi_cmnd *cmnd)
 	return 0;
 }
 
+static void scsi_tape_reset_clear(struct sdebug_dev_info *devip)
+{
+	if (sdebug_ptype == TYPE_TAPE) {
+		int i;
+
+		devip->tape_blksize = TAPE_DEF_BLKSIZE;
+		devip->tape_density = TAPE_DEF_DENSITY;
+		devip->tape_partition = 0;
+		devip->tape_dce = 0;
+		for (i = 0; i < TAPE_MAX_PARTITIONS; i++)
+			devip->tape_location[i] = 0;
+	}
+}
+
 static int scsi_debug_device_reset(struct scsi_cmnd *SCpnt)
 {
 	struct scsi_device *sdp = SCpnt->device;
@@ -6785,8 +6799,10 @@  static int scsi_debug_device_reset(struct scsi_cmnd *SCpnt)
 		sdev_printk(KERN_INFO, sdp, "%s\n", __func__);
 
 	scsi_debug_stop_all_queued(sdp);
-	if (devip)
+	if (devip) {
 		set_bit(SDEBUG_UA_POR, devip->uas_bm);
+		scsi_tape_reset_clear(devip);
+	}
 
 	if (sdebug_fail_lun_reset(SCpnt)) {
 		scmd_printk(KERN_INFO, SCpnt, "fail lun reset 0x%x\n", opcode);
@@ -6824,6 +6840,7 @@  static int scsi_debug_target_reset(struct scsi_cmnd *SCpnt)
 	list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) {
 		if (devip->target == sdp->id) {
 			set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm);
+			scsi_tape_reset_clear(devip);
 			++k;
 		}
 	}
@@ -6855,6 +6872,7 @@  static int scsi_debug_bus_reset(struct scsi_cmnd *SCpnt)
 
 	list_for_each_entry(devip, &sdbg_host->dev_info_list, dev_list) {
 		set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm);
+		scsi_tape_reset_clear(devip);
 		++k;
 	}
 
@@ -6878,6 +6896,7 @@  static int scsi_debug_host_reset(struct scsi_cmnd *SCpnt)
 		list_for_each_entry(devip, &sdbg_host->dev_info_list,
 				    dev_list) {
 			set_bit(SDEBUG_UA_BUS_RESET, devip->uas_bm);
+			scsi_tape_reset_clear(devip);
 			++k;
 		}
 	}