diff mbox

[11/18] scsi: Move most of scsi_init_command() into scsi_initialize_rq()

Message ID 20170519183016.12646-12-bart.vanassche@sandisk.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Bart Van Assche May 19, 2017, 6:30 p.m. UTC
Move the initializations that only have to be performed once and
not every time a request is prepared from scsi_init_command()
into scsi_initialize_rq(). This patch also moves the
jiffies_at_alloc assignment such that it gets back the meaning it
had before commit e9c787e65c0c, namely the value of the jiffies
counter at request allocation time.

Fixes: commit e9c787e65c0c ("scsi: allocate scsi_cmnd structures as part of struct request")
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/scsi_lib.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Christoph Hellwig May 21, 2017, 6:45 a.m. UTC | #1
On Fri, May 19, 2017 at 11:30:09AM -0700, Bart Van Assche wrote:
> Move the initializations that only have to be performed once and
> not every time a request is prepared from scsi_init_command()
> into scsi_initialize_rq(). This patch also moves the
> jiffies_at_alloc assignment such that it gets back the meaning it
> had before commit e9c787e65c0c, namely the value of the jiffies
> counter at request allocation time.

How does this account for the kmalloced request in scsi_ioctl_reset()?
Christoph Hellwig May 21, 2017, 6:46 a.m. UTC | #2
On Sun, May 21, 2017 at 08:45:23AM +0200, Christoph Hellwig wrote:
> On Fri, May 19, 2017 at 11:30:09AM -0700, Bart Van Assche wrote:
> > Move the initializations that only have to be performed once and
> > not every time a request is prepared from scsi_init_command()
> > into scsi_initialize_rq(). This patch also moves the
> > jiffies_at_alloc assignment such that it gets back the meaning it
> > had before commit e9c787e65c0c, namely the value of the jiffies
> > counter at request allocation time.
> 
> How does this account for the kmalloced request in scsi_ioctl_reset()?

Oh, because that currently manually calls blk_rq_init..
Christoph Hellwig May 21, 2017, 6:47 a.m. UTC | #3
On Fri, May 19, 2017 at 11:30:09AM -0700, Bart Van Assche wrote:
> Move the initializations that only have to be performed once and
> not every time a request is prepared from scsi_init_command()
> into scsi_initialize_rq(). This patch also moves the
> jiffies_at_alloc assignment such that it gets back the meaning it
> had before commit e9c787e65c0c, namely the value of the jiffies
> counter at request allocation time.

Looks fine,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox

Patch

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index a8d4f17ad5aa..68ce053b184b 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1156,26 +1156,24 @@  void scsi_del_cmd_from_list(struct scsi_cmnd *cmd)
 static void scsi_initialize_rq(struct request *rq)
 {
 	struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
-
-	scsi_req_init(&cmd->req);
-}
-
-/* Called after a request has been started. */
-void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
-{
+	struct scsi_device *dev = rq->q->queuedata;
 	void *buf = cmd->sense_buffer;
 	void *prot = cmd->prot_sdb;
 
 	/* zero out the cmd, except for the embedded scsi_request */
 	memset((char *)cmd + sizeof(cmd->req), 0,
 		sizeof(*cmd) - sizeof(cmd->req) + dev->host->hostt->cmd_size);
-
+	scsi_req_init(&cmd->req);
 	cmd->device = dev;
 	cmd->sense_buffer = buf;
 	cmd->prot_sdb = prot;
 	INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler);
 	cmd->jiffies_at_alloc = jiffies;
+}
 
+/* Called after a request has been started. */
+void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
+{
 	scsi_add_cmd_to_list(cmd);
 }