block: Make most scsi_req_init() calls implicit
authorBart Van Assche <bart.vanassche@sandisk.com>
Tue, 20 Jun 2017 18:15:41 +0000 (11:15 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 21 Jun 2017 01:27:14 +0000 (19:27 -0600)
Instead of explicitly calling scsi_req_init() after blk_get_request(),
call that function from inside blk_get_request(). Add an
.initialize_rq_fn() callback function to the block drivers that need
it. Merge the IDE .init_rq_fn() function into .initialize_rq_fn()
because it is too small to keep it as a separate function. Keep the
scsi_req_init() call in ide_prep_sense() because it follows a
blk_rq_init() call.

References: commit 82ed4db499b8 ("block: split scsi_request out of struct request")
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Omar Sandoval <osandov@fb.com>
Cc: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
25 files changed:
block/bsg.c
block/scsi_ioctl.c
drivers/block/pktcdvd.c
drivers/cdrom/cdrom.c
drivers/ide/ide-atapi.c
drivers/ide/ide-cd.c
drivers/ide/ide-cd_ioctl.c
drivers/ide/ide-devsets.c
drivers/ide/ide-disk.c
drivers/ide/ide-ioctls.c
drivers/ide/ide-park.c
drivers/ide/ide-pm.c
drivers/ide/ide-probe.c
drivers/ide/ide-tape.c
drivers/ide/ide-taskfile.c
drivers/scsi/osd/osd_initiator.c
drivers/scsi/osst.c
drivers/scsi/scsi_error.c
drivers/scsi/scsi_lib.c
drivers/scsi/scsi_transport_sas.c
drivers/scsi/sg.c
drivers/scsi/st.c
drivers/target/target_core_pscsi.c
fs/nfsd/blocklayout.c
include/scsi/scsi_cmnd.h

index 59d02dd31b0cf29fa0f8b94fdc34614fc1335113..37663b664666fbeeeeac6ffd048231b3a8cac918 100644 (file)
@@ -236,7 +236,6 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm)
        rq = blk_get_request(q, op, GFP_KERNEL);
        if (IS_ERR(rq))
                return rq;
-       scsi_req_init(rq);
 
        ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd, has_write_perm);
        if (ret)
index 4a294a5f7fab2002e105a6b2ca475ad0e9738b83..f96c51f5df401a8e2eb8aa66e2a69d604879d21c 100644 (file)
@@ -326,7 +326,6 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
        if (IS_ERR(rq))
                return PTR_ERR(rq);
        req = scsi_req(rq);
-       scsi_req_init(rq);
 
        if (hdr->cmd_len > BLK_MAX_CDB) {
                req->cmd = kzalloc(hdr->cmd_len, GFP_KERNEL);
@@ -456,7 +455,6 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
                goto error_free_buffer;
        }
        req = scsi_req(rq);
-       scsi_req_init(rq);
 
        cmdlen = COMMAND_SIZE(opcode);
 
@@ -542,7 +540,6 @@ static int __blk_send_generic(struct request_queue *q, struct gendisk *bd_disk,
        rq = blk_get_request(q, REQ_OP_SCSI_OUT, __GFP_RECLAIM);
        if (IS_ERR(rq))
                return PTR_ERR(rq);
-       scsi_req_init(rq);
        rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
        scsi_req(rq)->cmd[0] = cmd;
        scsi_req(rq)->cmd[4] = data;
index 26c04baae967169b74b6181d3dc8b12a9fa8ecac..8ef703ccc4b658a2a58aa7ebfb9e1a7d754eaf66 100644 (file)
@@ -708,7 +708,6 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *
                             REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, __GFP_RECLAIM);
        if (IS_ERR(rq))
                return PTR_ERR(rq);
-       scsi_req_init(rq);
 
        if (cgc->buflen) {
                ret = blk_rq_map_kern(q, rq, cgc->buffer, cgc->buflen,
index ff19cfc587f04a99191d937b3adeb6f7a6d880cc..e36d160c458fdb334556129b9559d147aefb2472 100644 (file)
@@ -2201,7 +2201,6 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
                        break;
                }
                req = scsi_req(rq);
-               scsi_req_init(rq);
 
                ret = blk_rq_map_user(q, rq, NULL, ubuf, len, GFP_KERNEL);
                if (ret) {
index d7a49dcfa85eef64231e77213196916c15edcaa7..37f61acf5a3564c17f09dff872cb4ea1ca5ae9e3 100644 (file)
@@ -93,7 +93,6 @@ int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
        int error;
 
        rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM);
-       scsi_req_init(rq);
        ide_req(rq)->type = ATA_PRIV_MISC;
        rq->special = (char *)pc;
 
index d55e44ed82b549d67718d4302e7d3973b922e5fd..81e18f9628d068e54cd5fca5f80b06594ee5d29f 100644 (file)
@@ -438,7 +438,6 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
 
                rq = blk_get_request(drive->queue,
                        write ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN,  __GFP_RECLAIM);
-               scsi_req_init(rq);
                memcpy(scsi_req(rq)->cmd, cmd, BLK_MAX_CDB);
                ide_req(rq)->type = ATA_PRIV_PC;
                rq->rq_flags |= rq_flags;
index 55cd736c39c6795c80c1c9ed96a03c24c17bd700..9d26c9737e2127066e80af152f61584a59b98b41 100644 (file)
@@ -304,7 +304,6 @@ int ide_cdrom_reset(struct cdrom_device_info *cdi)
        int ret;
 
        rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM);
-       scsi_req_init(rq);
        ide_req(rq)->type = ATA_PRIV_MISC;
        rq->rq_flags = RQF_QUIET;
        blk_execute_rq(drive->queue, cd->disk, rq, 0);
index 9b69c32ee560119bd3c74efe09ff0b48a139063a..ef7c8c43a380956ecfd00f066d1d504d0ffbb9ee 100644 (file)
@@ -166,7 +166,6 @@ int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
                return setting->set(drive, arg);
 
        rq = blk_get_request(q, REQ_OP_DRV_IN, __GFP_RECLAIM);
-       scsi_req_init(rq);
        ide_req(rq)->type = ATA_PRIV_MISC;
        scsi_req(rq)->cmd_len = 5;
        scsi_req(rq)->cmd[0] = REQ_DEVSET_EXEC;
index 7c06237f3479521e083b76469392c8a489ff2dcc..241983da5fc400e68cc045e9696f2370c22f8271 100644 (file)
@@ -478,7 +478,6 @@ static int set_multcount(ide_drive_t *drive, int arg)
                return -EBUSY;
 
        rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM);
-       scsi_req_init(rq);
        ide_req(rq)->type = ATA_PRIV_TASKFILE;
 
        drive->mult_req = arg;
index 8c0d17297a7a0ab0950edf4aa06321e85fd65098..3661abb16a5fc98acaa59eecb3ac7c810c35a7b7 100644 (file)
@@ -126,7 +126,6 @@ static int ide_cmd_ioctl(ide_drive_t *drive, unsigned long arg)
                struct request *rq;
 
                rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM);
-               scsi_req_init(rq);
                ide_req(rq)->type = ATA_PRIV_TASKFILE;
                blk_execute_rq(drive->queue, NULL, rq, 0);
                err = scsi_req(rq)->result ? -EIO : 0;
@@ -224,7 +223,6 @@ static int generic_drive_reset(ide_drive_t *drive)
        int ret = 0;
 
        rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM);
-       scsi_req_init(rq);
        ide_req(rq)->type = ATA_PRIV_MISC;
        scsi_req(rq)->cmd_len = 1;
        scsi_req(rq)->cmd[0] = REQ_DRIVE_RESET;
index 94e3107f59b933fc3618f906dc8b1b4554027dd5..1f264d5d3f3fa5c3f4eb71cc2838b60b6fd5d2ee 100644 (file)
@@ -32,7 +32,6 @@ static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
        spin_unlock_irq(&hwif->lock);
 
        rq = blk_get_request(q, REQ_OP_DRV_IN, __GFP_RECLAIM);
-       scsi_req_init(rq);
        scsi_req(rq)->cmd[0] = REQ_PARK_HEADS;
        scsi_req(rq)->cmd_len = 1;
        ide_req(rq)->type = ATA_PRIV_MISC;
@@ -48,7 +47,6 @@ static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
         * timeout has expired, so power management will be reenabled.
         */
        rq = blk_get_request(q, REQ_OP_DRV_IN, GFP_NOWAIT);
-       scsi_req_init(rq);
        if (IS_ERR(rq))
                goto out;
 
index 08b54bb3b7058ba5cafd05acbbb2c05b488cb038..544f02d673ca2717224f643742d00dc00a7e828e 100644 (file)
@@ -19,7 +19,6 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
 
        memset(&rqpm, 0, sizeof(rqpm));
        rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM);
-       scsi_req_init(rq);
        ide_req(rq)->type = ATA_PRIV_PM_SUSPEND;
        rq->special = &rqpm;
        rqpm.pm_step = IDE_PM_START_SUSPEND;
@@ -91,7 +90,6 @@ int generic_ide_resume(struct device *dev)
 
        memset(&rqpm, 0, sizeof(rqpm));
        rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM);
-       scsi_req_init(rq);
        ide_req(rq)->type = ATA_PRIV_PM_RESUME;
        rq->rq_flags |= RQF_PREEMPT;
        rq->special = &rqpm;
index b3f85250dea9c66caf8debae0285f709b4871118..c60e5ffc92319760900c307ce44f26673776a7c2 100644 (file)
@@ -741,12 +741,12 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
        }
 }
 
-static int ide_init_rq(struct request_queue *q, struct request *rq, gfp_t gfp)
+static void ide_initialize_rq(struct request *rq)
 {
        struct ide_request *req = blk_mq_rq_to_pdu(rq);
 
+       scsi_req_init(rq);
        req->sreq.sense = req->sense;
-       return 0;
 }
 
 /*
@@ -771,7 +771,7 @@ static int ide_init_queue(ide_drive_t *drive)
                return 1;
 
        q->request_fn = do_ide_request;
-       q->init_rq_fn = ide_init_rq;
+       q->initialize_rq_fn = ide_initialize_rq;
        q->cmd_size = sizeof(struct ide_request);
        queue_flag_set_unlocked(QUEUE_FLAG_SCSI_PASSTHROUGH, q);
        if (blk_init_allocated_queue(q) < 0) {
index 4d062c56877740509eec2d33d99c206ea170ec96..fd57e8ccc47ab9a22a6a377d5545713b333c01e1 100644 (file)
@@ -855,7 +855,6 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
        BUG_ON(size < 0 || size % tape->blk_size);
 
        rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, __GFP_RECLAIM);
-       scsi_req_init(rq);
        ide_req(rq)->type = ATA_PRIV_MISC;
        scsi_req(rq)->cmd[13] = cmd;
        rq->rq_disk = tape->disk;
index ab1a32cdcb0ad95f3e3a98f0ee9ad80ce24a9343..4efe4c6e956cdd330025e57bc5bc2dfe60eeae7b 100644 (file)
@@ -433,7 +433,6 @@ int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
        rq = blk_get_request(drive->queue,
                (cmd->tf_flags & IDE_TFLAG_WRITE) ?
                        REQ_OP_DRV_OUT : REQ_OP_DRV_IN, __GFP_RECLAIM);
-       scsi_req_init(rq);
        ide_req(rq)->type = ATA_PRIV_TASKFILE;
 
        /*
index 1e69a43b279d335867210ff828098632389e21be..ca45bf6d2bdb1af49ef03e1d21fd1bd49a82b235 100644 (file)
@@ -1574,7 +1574,6 @@ static struct request *_make_request(struct request_queue *q, bool has_write,
                        flags);
        if (IS_ERR(req))
                return req;
-       scsi_req_init(req);
 
        for_each_bio(bio) {
                struct bio *bounce_bio = bio;
@@ -1619,7 +1618,6 @@ static int _init_blk_request(struct osd_request *or,
                                ret = PTR_ERR(req);
                                goto out;
                        }
-                       scsi_req_init(req);
                        or->in.req = or->request->next_rq = req;
                }
        } else if (has_in)
index d54689c9216ee29ee0d023d57334ad56b4a2f1ef..929ee7e88120b2372468b7f58905d44fe7a0b7a2 100644 (file)
@@ -373,7 +373,6 @@ static int osst_execute(struct osst_request *SRpnt, const unsigned char *cmd,
                return DRIVER_ERROR << 24;
 
        rq = scsi_req(req);
-       scsi_req_init(req);
        req->rq_flags |= RQF_QUIET;
 
        SRpnt->bio = NULL;
index 44904f41924cdb579f090014962b530bf3580efd..304a7158540f05550ccecb560459ee849162e366 100644 (file)
@@ -1903,7 +1903,6 @@ static void scsi_eh_lock_door(struct scsi_device *sdev)
        if (IS_ERR(req))
                return;
        rq = scsi_req(req);
-       scsi_req_init(req);
 
        rq->cmd[0] = ALLOW_MEDIUM_REMOVAL;
        rq->cmd[1] = 0;
index fb18ed284e55ae34b4ad7143b8fdd895b611e517..301a7f706c9a2a416ba3383299ab8622dc1ce8bf 100644 (file)
@@ -250,7 +250,6 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
        if (IS_ERR(req))
                return ret;
        rq = scsi_req(req);
-       scsi_req_init(req);
 
        if (bufflen &&  blk_rq_map_kern(sdev->request_queue, req,
                                        buffer, bufflen, __GFP_RECLAIM))
@@ -1117,6 +1116,18 @@ err_exit:
 }
 EXPORT_SYMBOL(scsi_init_io);
 
+/**
+ * scsi_initialize_rq - initialize struct scsi_cmnd.req
+ *
+ * Called from inside blk_get_request().
+ */
+void scsi_initialize_rq(struct request *rq)
+{
+       scsi_req_init(rq);
+}
+EXPORT_SYMBOL(scsi_initialize_rq);
+
+/* Called after a request has been started. */
 void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
 {
        void *buf = cmd->sense_buffer;
@@ -2124,6 +2135,7 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
        q->request_fn = scsi_request_fn;
        q->init_rq_fn = scsi_init_rq;
        q->exit_rq_fn = scsi_exit_rq;
+       q->initialize_rq_fn = scsi_initialize_rq;
 
        if (blk_init_allocated_queue(q) < 0) {
                blk_cleanup_queue(q);
@@ -2148,6 +2160,7 @@ static const struct blk_mq_ops scsi_mq_ops = {
 #endif
        .init_request   = scsi_init_request,
        .exit_request   = scsi_exit_request,
+       .initialize_rq_fn = scsi_initialize_rq,
        .map_queues     = scsi_map_queues,
 };
 
index cc970c811bcbc207cc6f366faf0bad85e7e160ab..a190c052cd9399f15561f06267d8ffb533aaba69 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/bsg.h>
 
 #include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_request.h>
 #include <scsi/scsi_device.h>
 #include <scsi/scsi_host.h>
@@ -230,6 +231,7 @@ static int sas_bsg_initialize(struct Scsi_Host *shost, struct sas_rphy *rphy)
        q = blk_alloc_queue(GFP_KERNEL);
        if (!q)
                return -ENOMEM;
+       q->initialize_rq_fn = scsi_initialize_rq;
        q->cmd_size = sizeof(struct scsi_request);
 
        if (rphy) {
index f3387c6089c51c99668455a040458aefd8265b20..21225d62b0c1f4424bc72f57f8daf109cabffb7e 100644 (file)
@@ -1732,8 +1732,6 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)
        }
        req = scsi_req(rq);
 
-       scsi_req_init(rq);
-
        if (hp->cmd_len > BLK_MAX_CDB)
                req->cmd = long_cmdp;
        memcpy(req->cmd, cmd, hp->cmd_len);
index 6b1c4ac54e662b77751cfad349545aeddb31ddbb..8e5013d9cad445178a0461edd8eaf9abe4e84c38 100644 (file)
@@ -549,7 +549,6 @@ static int st_scsi_execute(struct st_request *SRpnt, const unsigned char *cmd,
        if (IS_ERR(req))
                return DRIVER_ERROR << 24;
        rq = scsi_req(req);
-       scsi_req_init(req);
        req->rq_flags |= RQF_QUIET;
 
        mdata->null_mapped = 1;
index 323ab47645d01f3dd153253beb1dad0c672ae325..ceec0211e84e11960d9e2bee1946fbd16ddf1e9b 100644 (file)
@@ -992,8 +992,6 @@ pscsi_execute_cmd(struct se_cmd *cmd)
                goto fail;
        }
 
-       scsi_req_init(req);
-
        if (sgl) {
                ret = pscsi_map_sg(cmd, sgl, sgl_nents, req);
                if (ret)
index 47ed19c53f2e37bb3e3c8f4cc37d4e2aed1545c7..c862c2489df0eba4ece4e8878b9bb8da447472d5 100644 (file)
@@ -232,7 +232,6 @@ static int nfsd4_scsi_identify_device(struct block_device *bdev,
                goto out_free_buf;
        }
        req = scsi_req(rq);
-       scsi_req_init(rq);
 
        error = blk_rq_map_kern(q, rq, buf, bufflen, GFP_KERNEL);
        if (error)
index b379f93a2c482ce223cce3c0673df34d1ba82068..da9bf2bcdf1a86f07ceca70e4e9c820246a19c98 100644 (file)
@@ -166,6 +166,7 @@ extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
 extern void scsi_kunmap_atomic_sg(void *virt);
 
 extern int scsi_init_io(struct scsi_cmnd *cmd);
+extern void scsi_initialize_rq(struct request *rq);
 
 extern int scsi_dma_map(struct scsi_cmnd *cmd);
 extern void scsi_dma_unmap(struct scsi_cmnd *cmd);