scsi: Call scsi_initialize_rq() for filesystem requests

If a pass-through request is submitted then blk_get_request()
initializes that request by calling scsi_initialize_rq(). Also call this
function for filesystem requests. Introduce CMD_INITIALIZED to keep
track of whether or not a request has already been initialized.

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>

authored by

Bart Van Assche and committed by
Martin K. Petersen
64104f70 3515832c

+25 -4
+22 -4
drivers/scsi/scsi_lib.c
··· 642 if (blk_queue_add_random(q)) 643 add_disk_randomness(req->rq_disk); 644 645 if (req->mq_ctx) { 646 /* 647 * In the MQ case the command gets freed by __blk_mq_end_request, ··· 1115 * scsi_initialize_rq - initialize struct scsi_cmnd.req 1116 * @rq: Request associated with the SCSI command to be initialized. 1117 * 1118 - * Called from inside blk_get_request(). 1119 */ 1120 void scsi_initialize_rq(struct request *rq) 1121 { ··· 1160 { 1161 void *buf = cmd->sense_buffer; 1162 void *prot = cmd->prot_sdb; 1163 - unsigned int unchecked_isa_dma = cmd->flags & SCMD_UNCHECKED_ISA_DMA; 1164 1165 /* zero out the cmd, except for the embedded scsi_request */ 1166 memset((char *)cmd + sizeof(cmd->req), 0, ··· 1175 cmd->device = dev; 1176 cmd->sense_buffer = buf; 1177 cmd->prot_sdb = prot; 1178 - cmd->flags = unchecked_isa_dma; 1179 INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler); 1180 cmd->jiffies_at_alloc = jiffies; 1181 ··· 1362 1363 ret = scsi_setup_cmnd(sdev, req); 1364 out: 1365 return scsi_prep_return(q, req, ret); 1366 } 1367 ··· 1883 struct scsi_device *sdev = req->q->queuedata; 1884 struct Scsi_Host *shost = sdev->host; 1885 struct scatterlist *sg; 1886 1887 scsi_init_command(sdev, cmd); 1888 ··· 1917 1918 blk_mq_start_request(req); 1919 1920 - return scsi_setup_cmnd(sdev, req); 1921 } 1922 1923 static void scsi_mq_done(struct scsi_cmnd *cmd)
··· 642 if (blk_queue_add_random(q)) 643 add_disk_randomness(req->rq_disk); 644 645 + if (!blk_rq_is_scsi(req)) { 646 + WARN_ON_ONCE(!(cmd->flags & SCMD_INITIALIZED)); 647 + cmd->flags &= ~SCMD_INITIALIZED; 648 + } 649 + 650 if (req->mq_ctx) { 651 /* 652 * In the MQ case the command gets freed by __blk_mq_end_request, ··· 1110 * scsi_initialize_rq - initialize struct scsi_cmnd.req 1111 * @rq: Request associated with the SCSI command to be initialized. 1112 * 1113 + * Called from inside blk_get_request() for pass-through requests and from 1114 + * inside scsi_init_command() for filesystem requests. 1115 */ 1116 void scsi_initialize_rq(struct request *rq) 1117 { ··· 1154 { 1155 void *buf = cmd->sense_buffer; 1156 void *prot = cmd->prot_sdb; 1157 + struct request *rq = blk_mq_rq_from_pdu(cmd); 1158 + unsigned int flags = cmd->flags & SCMD_PRESERVED_FLAGS; 1159 + 1160 + if (!blk_rq_is_scsi(rq) && !(flags & SCMD_INITIALIZED)) { 1161 + flags |= SCMD_INITIALIZED; 1162 + scsi_initialize_rq(rq); 1163 + } 1164 1165 /* zero out the cmd, except for the embedded scsi_request */ 1166 memset((char *)cmd + sizeof(cmd->req), 0, ··· 1163 cmd->device = dev; 1164 cmd->sense_buffer = buf; 1165 cmd->prot_sdb = prot; 1166 + cmd->flags = flags; 1167 INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler); 1168 cmd->jiffies_at_alloc = jiffies; 1169 ··· 1350 1351 ret = scsi_setup_cmnd(sdev, req); 1352 out: 1353 + if (ret != BLKPREP_OK) 1354 + cmd->flags &= ~SCMD_INITIALIZED; 1355 return scsi_prep_return(q, req, ret); 1356 } 1357 ··· 1869 struct scsi_device *sdev = req->q->queuedata; 1870 struct Scsi_Host *shost = sdev->host; 1871 struct scatterlist *sg; 1872 + int ret; 1873 1874 scsi_init_command(sdev, cmd); 1875 ··· 1902 1903 blk_mq_start_request(req); 1904 1905 + ret = scsi_setup_cmnd(sdev, req); 1906 + if (ret != BLK_STS_OK) 1907 + cmd->flags &= ~SCMD_INITIALIZED; 1908 + return ret; 1909 } 1910 1911 static void scsi_mq_done(struct scsi_cmnd *cmd)
+3
include/scsi/scsi_cmnd.h
··· 57 /* for scmd->flags */ 58 #define SCMD_TAGGED (1 << 0) 59 #define SCMD_UNCHECKED_ISA_DMA (1 << 1) 60 61 struct scsi_cmnd { 62 struct scsi_request req;
··· 57 /* for scmd->flags */ 58 #define SCMD_TAGGED (1 << 0) 59 #define SCMD_UNCHECKED_ISA_DMA (1 << 1) 60 + #define SCMD_INITIALIZED (1 << 3) 61 + /* flags preserved across unprep / reprep */ 62 + #define SCMD_PRESERVED_FLAGS (SCMD_UNCHECKED_ISA_DMA | SCMD_INITIALIZED) 63 64 struct scsi_cmnd { 65 struct scsi_request req;