Commit 08f78436 authored by Bart Van Assche's avatar Bart Van Assche Committed by Martin K. Petersen

scsi: Make scsi_mq_prep_fn() call scsi_init_command()

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 1bad6c4a ("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().

[mkp: applied by hand]
Signed-off-by: default avatarBart Van Assche <bart.vanassche@sandisk.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent be4c186c
...@@ -1871,36 +1871,21 @@ static int scsi_mq_prep_fn(struct request *req) ...@@ -1871,36 +1871,21 @@ static int scsi_mq_prep_fn(struct request *req)
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req);
struct scsi_device *sdev = req->q->queuedata; struct scsi_device *sdev = req->q->queuedata;
struct Scsi_Host *shost = sdev->host; 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; struct scatterlist *sg;
/* zero out the cmd, except for the embedded scsi_request */ scsi_init_command(sdev, cmd);
memset((char *)cmd + sizeof(cmd->req), 0,
sizeof(*cmd) - sizeof(cmd->req) + shost->hostt->cmd_size);
req->special = cmd; req->special = cmd;
cmd->request = req; cmd->request = req;
cmd->device = sdev;
cmd->sense_buffer = sense_buf;
cmd->flags = unchecked_isa_dma;
cmd->tag = req->tag; cmd->tag = req->tag;
cmd->prot_op = SCSI_PROT_NORMAL; 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; sg = (void *)cmd + sizeof(struct scsi_cmnd) + shost->hostt->cmd_size;
cmd->sdb.table.sgl = sg; cmd->sdb.table.sgl = sg;
if (scsi_host_get_prot(shost)) { 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)); memset(cmd->prot_sdb, 0, sizeof(struct scsi_data_buffer));
cmd->prot_sdb->table.sgl = cmd->prot_sdb->table.sgl =
...@@ -2026,6 +2011,7 @@ static int scsi_init_request(struct blk_mq_tag_set *set, struct request *rq, ...@@ -2026,6 +2011,7 @@ static int scsi_init_request(struct blk_mq_tag_set *set, struct request *rq,
struct Scsi_Host *shost = set->driver_data; struct Scsi_Host *shost = set->driver_data;
const bool unchecked_isa_dma = shost->unchecked_isa_dma; const bool unchecked_isa_dma = shost->unchecked_isa_dma;
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
struct scatterlist *sg;
if (unchecked_isa_dma) if (unchecked_isa_dma)
cmd->flags |= SCMD_UNCHECKED_ISA_DMA; cmd->flags |= SCMD_UNCHECKED_ISA_DMA;
...@@ -2034,6 +2020,13 @@ static int scsi_init_request(struct blk_mq_tag_set *set, struct request *rq, ...@@ -2034,6 +2020,13 @@ static int scsi_init_request(struct blk_mq_tag_set *set, struct request *rq,
if (!cmd->sense_buffer) if (!cmd->sense_buffer)
return -ENOMEM; return -ENOMEM;
cmd->req.sense = cmd->sense_buffer; 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; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment