Skip to content

Commit 832889f

Browse files
KAGA-KOKOmartinkpetersen
authored andcommitted
scsi: Improve requeuing behavior
Requests are unprepared and reprepared when being requeued. Avoid that requeuing resets .jiffies_at_alloc and .retries by initializing these two member variables from inside scsi_initialize_rq() and by preserving both member variables when preparing a request. This patch affects the requeuing behavior of both the legacy scsi and the scsi-mq code paths. Reported-by: Brian King <[email protected]> References: https://lkml.org/lkml/2017/8/18/923 ("Re: [BUG][bisected 270065e] linux-next fails to boot on powerpc") Signed-off-by: Bart Van Assche <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Brian King <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Johannes Thumshirn <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 64104f7 commit 832889f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,13 @@ int scsi_init_io(struct scsi_cmnd *cmd)
11121112
EXPORT_SYMBOL(scsi_init_io);
11131113

11141114
/**
1115-
* scsi_initialize_rq - initialize struct scsi_cmnd.req
1115+
* scsi_initialize_rq - initialize struct scsi_cmnd partially
11161116
* @rq: Request associated with the SCSI command to be initialized.
11171117
*
1118+
* This function initializes the members of struct scsi_cmnd that must be
1119+
* initialized before request processing starts and that won't be
1120+
* reinitialized if a SCSI command is requeued.
1121+
*
11181122
* Called from inside blk_get_request() for pass-through requests and from
11191123
* inside scsi_init_command() for filesystem requests.
11201124
*/
@@ -1123,6 +1127,8 @@ void scsi_initialize_rq(struct request *rq)
11231127
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
11241128

11251129
scsi_req_init(&cmd->req);
1130+
cmd->jiffies_at_alloc = jiffies;
1131+
cmd->retries = 0;
11261132
}
11271133
EXPORT_SYMBOL(scsi_initialize_rq);
11281134

@@ -1162,12 +1168,16 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
11621168
void *prot = cmd->prot_sdb;
11631169
struct request *rq = blk_mq_rq_from_pdu(cmd);
11641170
unsigned int flags = cmd->flags & SCMD_PRESERVED_FLAGS;
1171+
unsigned long jiffies_at_alloc;
1172+
int retries;
11651173

11661174
if (!blk_rq_is_scsi(rq) && !(flags & SCMD_INITIALIZED)) {
11671175
flags |= SCMD_INITIALIZED;
11681176
scsi_initialize_rq(rq);
11691177
}
11701178

1179+
jiffies_at_alloc = cmd->jiffies_at_alloc;
1180+
retries = cmd->retries;
11711181
/* zero out the cmd, except for the embedded scsi_request */
11721182
memset((char *)cmd + sizeof(cmd->req), 0,
11731183
sizeof(*cmd) - sizeof(cmd->req) + dev->host->hostt->cmd_size);
@@ -1177,7 +1187,8 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
11771187
cmd->prot_sdb = prot;
11781188
cmd->flags = flags;
11791189
INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler);
1180-
cmd->jiffies_at_alloc = jiffies;
1190+
cmd->jiffies_at_alloc = jiffies_at_alloc;
1191+
cmd->retries = retries;
11811192

11821193
scsi_add_cmd_to_list(cmd);
11831194
}

0 commit comments

Comments
 (0)