All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@sandisk.com>
To: "Martin K . Petersen" <martin.petersen@oracle.com>,
	James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: linux-scsi@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bart.vanassche@sandisk.com>,
	Hannes Reinecke <hare@suse.com>,
	Johannes Thumshirn <jthumshirn@suse.de>
Subject: [PATCH v3 09/12] Make scsi_mq_prep_fn() call scsi_init_command()
Date: Fri, 2 Jun 2017 14:22:00 -0700	[thread overview]
Message-ID: <20170602212203.30401-10-bart.vanassche@sandisk.com> (raw)
In-Reply-To: <20170602212203.30401-1-bart.vanassche@sandisk.com>

This patch reduces code duplication. There are two functional changes
in this patch:
- It causes scsi_mq_prep_fn() to clear driver-private
  command data, just like the already upstream commit 1bad6c4a57ef
  ("scsi: zero per-cmd private driver data for each MQ I/O").
- The initialization of .prot_sdb is moved from scsi_mq_prep_fn()
  into scsi_init_request().

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/scsi/scsi_lib.c | 25 +++++++++----------------
 1 file changed, 9 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 6b4fb48033fb..ef4e33319407 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1870,36 +1870,21 @@ static int scsi_mq_prep_fn(struct request *req)
 	struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req);
 	struct scsi_device *sdev = req->q->queuedata;
 	struct Scsi_Host *shost = sdev->host;
-	unsigned char *sense_buf = cmd->sense_buffer;
-	unsigned int unchecked_isa_dma = cmd->flags & SCMD_UNCHECKED_ISA_DMA;
 	struct scatterlist *sg;
 
-	/* zero out the cmd, except for the embedded scsi_request */
-	memset((char *)cmd + sizeof(cmd->req), 0,
-		sizeof(*cmd) - sizeof(cmd->req));
+	scsi_init_command(sdev, cmd);
 
 	req->special = cmd;
 
 	cmd->request = req;
-	cmd->device = sdev;
-	cmd->sense_buffer = sense_buf;
-	cmd->flags = unchecked_isa_dma;
 
 	cmd->tag = req->tag;
-
 	cmd->prot_op = SCSI_PROT_NORMAL;
 
-	INIT_LIST_HEAD(&cmd->list);
-	INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler);
-	cmd->jiffies_at_alloc = jiffies;
-
-	scsi_add_cmd_to_list(cmd);
-
 	sg = (void *)cmd + sizeof(struct scsi_cmnd) + shost->hostt->cmd_size;
 	cmd->sdb.table.sgl = sg;
 
 	if (scsi_host_get_prot(shost)) {
-		cmd->prot_sdb = (void *)sg + scsi_mq_sgl_size(shost);
 		memset(cmd->prot_sdb, 0, sizeof(struct scsi_data_buffer));
 
 		cmd->prot_sdb->table.sgl =
@@ -2025,6 +2010,7 @@ static int scsi_init_request(struct blk_mq_tag_set *set, struct request *rq,
 	struct Scsi_Host *shost = set->driver_data;
 	const bool unchecked_isa_dma = shost->unchecked_isa_dma;
 	struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
+	struct scatterlist *sg;
 
 	if (unchecked_isa_dma)
 		cmd->flags |= SCMD_UNCHECKED_ISA_DMA;
@@ -2033,6 +2019,13 @@ static int scsi_init_request(struct blk_mq_tag_set *set, struct request *rq,
 	if (!cmd->sense_buffer)
 		return -ENOMEM;
 	cmd->req.sense = cmd->sense_buffer;
+
+	if (scsi_host_get_prot(shost)) {
+		sg = (void *)cmd + sizeof(struct scsi_cmnd) +
+			shost->hostt->cmd_size;
+		cmd->prot_sdb = (void *)sg + scsi_mq_sgl_size(shost);
+	}
+
 	return 0;
 }
 
-- 
2.12.2

  parent reply	other threads:[~2017-06-02 21:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-02 21:21 [PATCH v3 00/12] SCSI patches for kernel v4.13 Bart Van Assche
2017-06-02 21:21 ` [PATCH v3 01/12] Avoid that scsi_exit_rq() triggers a use-after-free Bart Van Assche
2017-06-02 21:21   ` Bart Van Assche
2017-06-02 21:21 ` [PATCH v3 02/12] Split scsi_internal_device_block() Bart Van Assche
2017-06-02 21:21 ` [PATCH v3 03/12] Create two versions of scsi_internal_device_unblock() Bart Van Assche
2017-06-02 21:21 ` [PATCH v3 04/12] Protect SCSI device state changes with a mutex Bart Van Assche
2017-06-05  8:09   ` Christoph Hellwig
2017-06-05 15:18     ` Bart Van Assche
2017-06-05 18:36       ` Bart Van Assche
2017-06-08 15:53         ` hch
2017-06-02 21:21 ` [PATCH v3 05/12] Introduce scsi_start_queue() Bart Van Assche
2017-06-02 21:21 ` [PATCH v3 06/12] Make __scsi_remove_device go straight from BLOCKED to DEL Bart Van Assche
2017-06-02 21:21 ` [PATCH v3 07/12] Only add commands to the device command list if required by the LLD Bart Van Assche
2017-06-02 21:21 ` [PATCH v3 08/12] Introduce scsi_mq_sgl_size() Bart Van Assche
2017-06-02 21:22 ` Bart Van Assche [this message]
2017-06-05  8:10   ` [PATCH v3 09/12] Make scsi_mq_prep_fn() call scsi_init_command() Christoph Hellwig
2017-06-02 21:22 ` [PATCH v3 10/12] snic: Remove code that zeroes driver-private command data Bart Van Assche
2017-06-02 21:22 ` [PATCH v3 11/12] virtio_scsi: " Bart Van Assche
2017-06-02 21:22 ` [PATCH v3 12/12] xen/scsifront: " Bart Van Assche
2017-06-02 21:22 ` Bart Van Assche
2017-06-13  1:04 ` [PATCH v3 00/12] SCSI patches for kernel v4.13 Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170602212203.30401-10-bart.vanassche@sandisk.com \
    --to=bart.vanassche@sandisk.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=jthumshirn@suse.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.