Skip to content

Commit 2691277

Browse files
author
Ewan D. Milne
committed
scsi: core: Clear driver private data when retrying request
JIRA: https://issues.redhat.com/browse/RHEL-86156 Upstream Status: From upstream linux mainline Conflicts: Merge differences due to various commits not present in RHEL 9 which only affected the portion of this patch that removed the memset() of the per-cmd private drivate data from the function scsi_init_command() -- RHEL 9 still avoids zeroing the scsi_req but this does not affect the memset() added to scsi_queue_rq(). After commit 1bad6c4 ("scsi: zero per-cmd private driver data for each MQ I/O"), the xen-scsifront/virtio_scsi/snic drivers all removed code that explicitly zeroed driver-private command data. In combination with commit 464a00c ("scsi: core: Kill DRIVER_SENSE"), after virtio_scsi performs a capacity expansion, the first request will return a unit attention to indicate that the capacity has changed. And then the original command is retried. As driver-private command data was not cleared, the request would return UA again and eventually time out and fail. Zero driver-private command data when a request is retried. Fixes: f7de50d ("scsi: xen-scsifront: Remove code that zeroes driver-private command data") Fixes: c2bb873 ("scsi: virtio_scsi: Remove code that zeroes driver-private command data") Fixes: c3006a9 ("scsi: snic: Remove code that zeroes driver-private command data") Signed-off-by: Ye Bin <yebin10@huawei.com> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Link: https://lore.kernel.org/r/20250217021628.2929248-1-yebin@huaweicloud.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> (cherry picked from commit dce5c4a) Signed-off-by: Ewan D. Milne <emilne@redhat.com>
1 parent 8c8174d commit 2691277

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,13 +1295,9 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
12951295
retries = cmd->retries;
12961296
in_flight = test_bit(SCMD_STATE_INFLIGHT, &cmd->state);
12971297
/*
1298-
* Zero out the cmd, except for the embedded scsi_request. Only clear
1299-
* the driver-private command data if the LLD does not supply a
1300-
* function to initialize that data.
1298+
* Zero out the cmd, except for the embedded scsi_request.
13011299
*/
13021300
to_clear = sizeof(*cmd) - sizeof(cmd->req);
1303-
if (!dev->host->hostt->init_cmd_priv)
1304-
to_clear += dev->host->hostt->cmd_size;
13051301
memset((char *)cmd + sizeof(cmd->req), 0, to_clear);
13061302

13071303
cmd->device = dev;
@@ -1867,6 +1863,13 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
18671863
if (!scsi_host_queue_ready(q, shost, sdev, cmd))
18681864
goto out_dec_target_busy;
18691865

1866+
/*
1867+
* Only clear the driver-private command data if the LLD does not supply
1868+
* a function to initialize that data.
1869+
*/
1870+
if (shost->hostt->cmd_size && !shost->hostt->init_cmd_priv)
1871+
memset(cmd + 1, 0, shost->hostt->cmd_size);
1872+
18701873
if (!(req->rq_flags & RQF_DONTPREP)) {
18711874
ret = scsi_prepare_cmd(req);
18721875
if (ret != BLK_STS_OK)

0 commit comments

Comments
 (0)