Commit 832889f5ed45ec90c76f6eb97e64baf845929007

Authored by Bart Van Assche
Committed by Martin K. Petersen
1 parent 64104f7032

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 <brking@linux.vnet.ibm.com>
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 <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Brian King <brking@linux.vnet.ibm.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

Showing 1 changed file with 13 additions and 2 deletions Side-by-side Diff

drivers/scsi/scsi_lib.c
... ... @@ -1112,9 +1112,13 @@
1112 1112 EXPORT_SYMBOL(scsi_init_io);
1113 1113  
1114 1114 /**
1115   - * scsi_initialize_rq - initialize struct scsi_cmnd.req
  1115 + * scsi_initialize_rq - initialize struct scsi_cmnd partially
1116 1116 * @rq: Request associated with the SCSI command to be initialized.
1117 1117 *
  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 + *
1118 1122 * Called from inside blk_get_request() for pass-through requests and from
1119 1123 * inside scsi_init_command() for filesystem requests.
1120 1124 */
... ... @@ -1123,6 +1127,8 @@
1123 1127 struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
1124 1128  
1125 1129 scsi_req_init(&cmd->req);
  1130 + cmd->jiffies_at_alloc = jiffies;
  1131 + cmd->retries = 0;
1126 1132 }
1127 1133 EXPORT_SYMBOL(scsi_initialize_rq);
1128 1134  
1129 1135  
... ... @@ -1162,12 +1168,16 @@
1162 1168 void *prot = cmd->prot_sdb;
1163 1169 struct request *rq = blk_mq_rq_from_pdu(cmd);
1164 1170 unsigned int flags = cmd->flags & SCMD_PRESERVED_FLAGS;
  1171 + unsigned long jiffies_at_alloc;
  1172 + int retries;
1165 1173  
1166 1174 if (!blk_rq_is_scsi(rq) && !(flags & SCMD_INITIALIZED)) {
1167 1175 flags |= SCMD_INITIALIZED;
1168 1176 scsi_initialize_rq(rq);
1169 1177 }
1170 1178  
  1179 + jiffies_at_alloc = cmd->jiffies_at_alloc;
  1180 + retries = cmd->retries;
1171 1181 /* zero out the cmd, except for the embedded scsi_request */
1172 1182 memset((char *)cmd + sizeof(cmd->req), 0,
1173 1183 sizeof(*cmd) - sizeof(cmd->req) + dev->host->hostt->cmd_size);
... ... @@ -1177,7 +1187,8 @@
1177 1187 cmd->prot_sdb = prot;
1178 1188 cmd->flags = flags;
1179 1189 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;
1181 1192  
1182 1193 scsi_add_cmd_to_list(cmd);
1183 1194 }