Linux SCSI subsystem development
 help / color / mirror / Atom feed
* [PATCH v3] scsi: core: Clear cmd->flags for terminal queuing error
@ 2026-11-29 18:55 John Garry
  0 siblings, 0 replies; only message in thread
From: John Garry @ 2026-11-29 18:55 UTC (permalink / raw)
  To: James.Bottomley, mkp; +Cc: linux-scsi, bvanassche, John Garry

If a request can't be queued in scsi_queue_rq(), then we error out with
a blk_status_t code. Such a scenario may be the scsi_device has its
transport offline.

For BLK_STS_RESOURCE or BLK_STS_DEV_RESOURCE, the request may be requeued
in the block layer. For other errors, the block layer ends the request and
so we won't see it again (until recycled).

Normally when a request completes scmd->flags is cleared in
scsi_end_request().

However for the error scenario mentioned above, scsi_end_request() is
not called and so scmd->flags is not cleared. As such, when the request
is recycled we see the old value in scmd->flags.

Fix this issue by clearing scmd->flags in the error scenario mentioned by
calling scsi_cleanup_rq().

Fixes: 64104f703212f ("scsi: Call scsi_initialize_rq() for filesystem requests")
Signed-off-by: John Garry <john.garry@linux.dev>
---
Differences to v2 (https://lore.kernel.org/linux-scsi/20261108204733.557995-2-john.garry@linux.dev/)
- Adding same handling for BLK_STS_AGAIN
- Add fixes tag

v1 was sent in https://lore.kernel.org/linux-scsi/20260911075415.634921-1-john.garry@linux.dev/

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ab39514cc0c6..3d9ef83d3d10 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1976,8 +1976,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
 		break;
 	case BLK_STS_AGAIN:
 		cmd->result = DID_BUS_BUSY << 16;
-		if (req->rq_flags & RQF_DONTPREP)
-			scsi_mq_uninit_cmd(cmd);
+		scsi_cleanup_rq(req);
 		break;
 	default:
 		if (unlikely(!scsi_device_online(sdev)))
@@ -1989,8 +1988,8 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
 		 * we hit an error, as we will never see this command
 		 * again.
 		 */
-		if (req->rq_flags & RQF_DONTPREP)
-			scsi_mq_uninit_cmd(cmd);
+		scsi_cleanup_rq(req);
+
 		scsi_run_queue_async(sdev);
 		break;
 	}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-29 18:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 18:55 [PATCH v3] scsi: core: Clear cmd->flags for terminal queuing error John Garry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox