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