Skip to content

Commit 2dd6fb5

Browse files
Bart Van Asschemartinkpetersen
authored andcommitted
scsi: Only add commands to the device command list if required by the LLD
Just like for the scsi-mq code path, in the single queue SCSI code path only add commands to the per-device command list if required by the SCSI LLD. This patch will make it easier to merge the single-queue and multiqueue command initialization code. Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.com> Cc: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 255ee93 commit 2dd6fb5

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

drivers/scsi/scsi.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,7 @@ EXPORT_SYMBOL(scsi_sd_pm_domain);
108108
*/
109109
void scsi_put_command(struct scsi_cmnd *cmd)
110110
{
111-
unsigned long flags;
112-
113-
/* serious error if the command hasn't come from a device list */
114-
spin_lock_irqsave(&cmd->device->list_lock, flags);
115-
BUG_ON(list_empty(&cmd->list));
116-
list_del_init(&cmd->list);
117-
spin_unlock_irqrestore(&cmd->device->list_lock, flags);
118-
111+
scsi_del_cmd_from_list(cmd);
119112
BUG_ON(delayed_work_pending(&cmd->abort_work));
120113
}
121114

drivers/scsi/scsi_lib.c

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -584,19 +584,9 @@ static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd)
584584

585585
static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd)
586586
{
587-
struct scsi_device *sdev = cmd->device;
588-
struct Scsi_Host *shost = sdev->host;
589-
unsigned long flags;
590-
591587
scsi_mq_free_sgtables(cmd);
592588
scsi_uninit_cmd(cmd);
593-
594-
if (shost->use_cmd_list) {
595-
BUG_ON(list_empty(&cmd->list));
596-
spin_lock_irqsave(&sdev->list_lock, flags);
597-
list_del_init(&cmd->list);
598-
spin_unlock_irqrestore(&sdev->list_lock, flags);
599-
}
589+
scsi_del_cmd_from_list(cmd);
600590
}
601591

602592
/*
@@ -1134,12 +1124,40 @@ int scsi_init_io(struct scsi_cmnd *cmd)
11341124
}
11351125
EXPORT_SYMBOL(scsi_init_io);
11361126

1127+
/* Add a command to the list used by the aacraid and dpt_i2o drivers */
1128+
void scsi_add_cmd_to_list(struct scsi_cmnd *cmd)
1129+
{
1130+
struct scsi_device *sdev = cmd->device;
1131+
struct Scsi_Host *shost = sdev->host;
1132+
unsigned long flags;
1133+
1134+
if (shost->use_cmd_list) {
1135+
spin_lock_irqsave(&sdev->list_lock, flags);
1136+
list_add_tail(&cmd->list, &sdev->cmd_list);
1137+
spin_unlock_irqrestore(&sdev->list_lock, flags);
1138+
}
1139+
}
1140+
1141+
/* Remove a command from the list used by the aacraid and dpt_i2o drivers */
1142+
void scsi_del_cmd_from_list(struct scsi_cmnd *cmd)
1143+
{
1144+
struct scsi_device *sdev = cmd->device;
1145+
struct Scsi_Host *shost = sdev->host;
1146+
unsigned long flags;
1147+
1148+
if (shost->use_cmd_list) {
1149+
spin_lock_irqsave(&sdev->list_lock, flags);
1150+
BUG_ON(list_empty(&cmd->list));
1151+
list_del_init(&cmd->list);
1152+
spin_unlock_irqrestore(&sdev->list_lock, flags);
1153+
}
1154+
}
1155+
11371156
void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
11381157
{
11391158
void *buf = cmd->sense_buffer;
11401159
void *prot = cmd->prot_sdb;
11411160
unsigned int unchecked_isa_dma = cmd->flags & SCMD_UNCHECKED_ISA_DMA;
1142-
unsigned long flags;
11431161

11441162
/* zero out the cmd, except for the embedded scsi_request */
11451163
memset((char *)cmd + sizeof(cmd->req), 0,
@@ -1152,9 +1170,7 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
11521170
INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler);
11531171
cmd->jiffies_at_alloc = jiffies;
11541172

1155-
spin_lock_irqsave(&dev->list_lock, flags);
1156-
list_add_tail(&cmd->list, &dev->cmd_list);
1157-
spin_unlock_irqrestore(&dev->list_lock, flags);
1173+
scsi_add_cmd_to_list(cmd);
11581174
}
11591175

11601176
static int scsi_setup_scsi_cmnd(struct scsi_device *sdev, struct request *req)
@@ -1871,11 +1887,7 @@ static int scsi_mq_prep_fn(struct request *req)
18711887
INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler);
18721888
cmd->jiffies_at_alloc = jiffies;
18731889

1874-
if (shost->use_cmd_list) {
1875-
spin_lock_irq(&sdev->list_lock);
1876-
list_add_tail(&cmd->list, &sdev->cmd_list);
1877-
spin_unlock_irq(&sdev->list_lock);
1878-
}
1890+
scsi_add_cmd_to_list(cmd);
18791891

18801892
sg = (void *)cmd + sizeof(struct scsi_cmnd) + shost->hostt->cmd_size;
18811893
cmd->sdb.table.sgl = sg;

drivers/scsi/scsi_priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ int scsi_eh_get_sense(struct list_head *work_q,
8080
int scsi_noretry_cmd(struct scsi_cmnd *scmd);
8181

8282
/* scsi_lib.c */
83+
extern void scsi_add_cmd_to_list(struct scsi_cmnd *cmd);
84+
extern void scsi_del_cmd_from_list(struct scsi_cmnd *cmd);
8385
extern int scsi_maybe_unblock_host(struct scsi_device *sdev);
8486
extern void scsi_device_unbusy(struct scsi_device *sdev);
8587
extern void scsi_queue_insert(struct scsi_cmnd *cmd, int reason);

0 commit comments

Comments
 (0)