scsi: remove legacy cmd_list implementation
Subsystems (2)
v6 cover scsi: remove legacy cmd_list implementation
Hi all,
with the switch to blk-mq we have an efficient way of looking up outstanding commands via blk_mq_rq_busy_iter().
In this patchset the dpt_i2o and aacraid drivers are switched over to using that function, and the now obsolete cmd_list implemantation in the SCSI midlayer is removed.
As usual, comments and reviews are welcome.
Changes to v1:
- Fixup kbuild warning
Changes to v2:
- Add scsi_host_busy_iter()
- Include reviews from Christoph
Changes to v3:
- Include reviews from Christoph
- Add midlayer helper to terminate outstanding commands
- Split off aacraid modifcations into several patches
Changes to v4:
- Include reviews from Bart
- Add new midlayer helper scsi_host_quiesce()/scsi_host_resume()
- Improve comments
Changes to v5:
- Add reviews from Balsundar P.
- Rename scsi_host_flush_commands()
- Replace patch using scsi_host_quiesce() by using busy iterator
Hannes Reinecke (13):
dpt_i2o: rename adpt_i2o_to_scsi() to adpt_i2o_scsi_complete()
scsi: add scsi_host_complete_all_commands() helper
dpt_i2o: use scsi_host_complete_all_commands() to abort outstanding
commands
aacraid: Do not wait for outstanding write commands on
synchronize_cache
aacraid: use scsi_host_complete_all_commands() to terminate
outstanding commands
aacraid: replace aac_flush_ios() with midlayer helper
aacraid: move scsi_(block,unblock)_requests out of
_aac_reset_adapter()
scsi: add scsi_host_(block,unblock) helper function
aacraid: use scsi_host_(block,unblock) to block I/O
scsi: add scsi_host_busy_iter()
aacraid: use scsi_host_busy_iter() to wait for outstanding commands
aacraid: use scsi_host_busy_iter() in get_num_of_incomplete_fibs()
scsi: Remove cmd_list functionality
drivers/scsi/aacraid/aachba.c | 76 +------------------------ drivers/scsi/aacraid/comminit.c | 35 ++++++------ drivers/scsi/aacraid/commsup.c | 46 +++------------ drivers/scsi/aacraid/linit.c | 120 ++++++++++++++++------------------------ drivers/scsi/dpt_i2o.c | 25 +-------- drivers/scsi/dpti.h | 3 +- drivers/scsi/hosts.c | 61 ++++++++++++++++++++ drivers/scsi/scsi.c | 14 ----- drivers/scsi/scsi_error.c | 1 - drivers/scsi/scsi_lib.c | 61 ++++++++++---------- drivers/scsi/scsi_priv.h | 2 - drivers/scsi/scsi_scan.c | 1 - include/scsi/scsi_cmnd.h | 1 - include/scsi/scsi_device.h | 1 - include/scsi/scsi_host.h | 10 +++- 15 files changed, 178 insertions(+), 279 deletions(-)
Signature · 1 line
2.16.4
PATCH v6 1/13 dpt_i2o: rename adpt_i2o_to_scsi() to adpt_i2o_scsi_complete()
Rename the badly named function into adpt_i2o_scsi_complete(), and make it a void function as the return value is never used. This also fixes a potential use-after free as the return value might be evaluated from the command result after the command has been freed.
--- drivers/scsi/dpt_i2o.c | 5 ++--- drivers/scsi/dpti.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/scsi/dpt_i2o.c +2 -3
@@ -2173,7 +2173,7 @@ static irqreturn_t adpt_isr(int irq, void *dev_id) readl(reply + 12) - 1);if (cmd !=NULL ){scsi_dma_unmap (cmd); -adpt_i2o_to_scsi (reply, cmd); +adpt_i2o_scsi_complete (reply, cmd); } }writel (m, pHba->reply_port);
@@ -2341,7 +2341,7 @@ static s32 adpt_scsi_host_alloc(adpt_hba* pHba, struct scsi_host_template *sht) } -static s32 adpt_i2o_to_scsi (void __iomem *reply,struct scsi_cmnd * cmd) +static void adpt_i2o_scsi_complete (void __iomem *reply,struct scsi_cmnd *cmd) {adpt_hba * pHba;u32 hba_status;
@@ -2459,7 +2459,6 @@ static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd)if (cmd->scsi_done !=NULL ){ cmd->scsi_done (cmd); } -return cmd->result; }
drivers/scsi/dpti.h +1 -1
@@ -286,7 +286,7 @@ static s32 adpt_i2o_status_get(adpt_hba* pHba);static s32 adpt_i2o_init_outbound_q (adpt_hba * pHba);static s32 adpt_i2o_hrt_get (adpt_hba * pHba);static s32 adpt_scsi_to_i2o (adpt_hba * pHba,struct scsi_cmnd * cmd,struct adpt_device * dptdevice); -static s32 adpt_i2o_to_scsi (void __iomem *reply,struct scsi_cmnd * cmd); +static void adpt_i2o_scsi_complete (void __iomem *reply,struct scsi_cmnd *cmd);static s32 adpt_scsi_host_alloc (adpt_hba * pHba,struct scsi_host_template * sht);static s32 adpt_hba_reset (adpt_hba * pHba);static s32 adpt_i2o_reset_hba (adpt_hba * pHba);
Signature · 1 line
2.16.4
PATCH v6 2/13 scsi: add scsi_host_complete_all_commands() helper
In reply to Hannes ReineckeAdd a helper scsi_host_complete_all_commands() to terminate all outstanding commands on a scsi host.
--- drivers/scsi/hosts.c | 28 ++++++++++++++++++++++++++++ include/scsi/scsi_host.h | 1 + 2 files changed, 29 insertions(+)
drivers/scsi/hosts.c +28 -0
@@ -650,3 +650,31 @@ void scsi_flush_work(struct Scsi_Host *shost)flush_workqueue (shost->work_q); }EXPORT_SYMBOL_GPL (scsi_flush_work); + +static bool complete_all_cmds_iter (struct request *rq,void *data,bool rsvd) +{ +struct scsi_cmnd *scmd =blk_mq_rq_to_pdu (rq); +int status = *(int *)data; + +scsi_dma_unmap (scmd); + scmd->result = status <<16 ; + scmd->scsi_done (scmd); +return true; +} + +/** +* scsi_host_complete_all_commands - Terminate all running commands +* @shost: Scsi Host on which commands should be terminated +* @status: Status to be set for the terminated commands +* +* There is no protection against modification of the number +* of outstanding commands. It is the responsibility of the +* caller to ensure that concurrent I/O submission and/or +* completion is stopped when calling this function. +*/ +void scsi_host_complete_all_commands (struct Scsi_Host *shost,int status) +{ +blk_mq_tagset_busy_iter (&shost->tag_set, complete_all_cmds_iter, + &status); +} +EXPORT_SYMBOL_GPL (scsi_host_complete_all_commands);
include/scsi/scsi_host.h +1 -0
@@ -735,6 +735,7 @@ extern int scsi_host_busy(struct Scsi_Host *shost);extern void scsi_host_put (struct Scsi_Host *t);extern struct Scsi_Host *scsi_host_lookup (unsigned short );extern const char *scsi_host_state_name (enum scsi_host_state ); +extern void scsi_host_complete_all_commands (struct Scsi_Host *shost,int status);static inline int __must_check scsi_add_host (struct Scsi_Host *host,struct device *dev)
Signature · 1 line
2.16.4
PATCH v6 3/13 dpt_i2o: use scsi_host_complete_all_commands() to abort outstanding commands
In reply to Hannes ReineckeRather than traversing all outstanding commands manually use the scsi_host_complete_all_commands() helper to terminate all commands during reset.
With that we can drop the cmd_list usage from the midlayer.
--- drivers/scsi/dpt_i2o.c | 20 +------------------- drivers/scsi/dpti.h | 1 - 2 files changed, 1 insertion(+), 20 deletions(-)
drivers/scsi/dpt_i2o.c +1 -19
@@ -817,7 +817,7 @@ static int adpt_hba_reset(adpt_hba* pHba) } pHba->state &= ~DPTI_STATE_RESET ; -adpt_fail_posted_scbs (pHba); +scsi_host_complete_all_commands (pHba->host,DID_RESET );return 0 ;/* return success */ }
@@ -2335,7 +2335,6 @@ static s32 adpt_scsi_host_alloc(adpt_hba* pHba, struct scsi_host_template *sht) host->unique_id = (u32 )sys_tbl_pa + pHba->unit; host->sg_tablesize = pHba->sg_tablesize; host->can_queue = pHba->post_fifo_size; - host->use_cmd_list =1 ;return 0 ; }
@@ -2646,23 +2645,6 @@ static s32 adpt_i2o_reparse_lct(adpt_hba* pHba)return 0 ; } -static void adpt_fail_posted_scbs (adpt_hba * pHba) -{ -struct scsi_cmnd * cmd =NULL ; -struct scsi_device * d =NULL ; - -shost_for_each_device (d, pHba->host) { -unsigned long flags; -spin_lock_irqsave (&d->list_lock, flags); -list_for_each_entry (cmd, &d->cmd_list, list) { - cmd->result = (DID_OK <<16 ) | (QUEUE_FULL <<1 ); - cmd->scsi_done (cmd); - } -spin_unlock_irqrestore (&d->list_lock, flags); - } -} - -/*============================================================================ * Routines from i2o subsystem *============================================================================
drivers/scsi/dpti.h +0 -1
@@ -295,7 +295,6 @@ static s32 adpt_i2o_reparse_lct(adpt_hba* pHba);static s32 adpt_send_nop (adpt_hba *pHba,u32 m);static void adpt_i2o_delete_hba (adpt_hba * pHba);static void adpt_inquiry (adpt_hba * pHba); -static void adpt_fail_posted_scbs (adpt_hba * pHba);static struct adpt_device *adpt_find_device (adpt_hba * pHba,u32 chan,u32 id,u64 lun);static int adpt_install_hba (struct scsi_host_template * sht,struct pci_dev * pDev) ;static int adpt_i2o_online_hba (adpt_hba * pHba);
Signature · 1 line
2.16.4
PATCH v6 4/13 aacraid: Do not wait for outstanding write commands on synchronize_cache
In reply to Hannes ReineckeThere is no need to wait for outstanding write commands on synchronize cache; the block layer is responsible for I/O scheduling, no need to out-guess it on the driver layer.
--- drivers/scsi/aacraid/aachba.c | 76 ++----------------------------------------- 1 file changed, 2 insertions(+), 74 deletions(-)
drivers/scsi/aacraid/aachba.c +2 -74
@@ -2601,9 +2601,7 @@ static int aac_write(struct scsi_cmnd * scsicmd)static void synchronize_callback (void *context,struct fib *fibptr) {struct aac_synchronize_reply *synchronizereply; -struct scsi_cmnd *cmd; - - cmd = context; +struct scsi_cmnd *cmd = context;if (!aac_valid_context (cmd, fibptr))return ;
@@ -2644,77 +2642,8 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd)int status;struct fib *cmd_fibcontext;struct aac_synchronize *synchronizecmd; -struct scsi_cmnd *cmd;struct scsi_device *sdev = scsicmd->device; -int active =0 ;struct aac_dev *aac; -u64 lba = ((u64 )scsicmd->cmnd[2 ] <<24 ) | (scsicmd->cmnd[3 ] <<16 ) | - (scsicmd->cmnd[4 ] <<8 ) | scsicmd->cmnd[5 ]; -u32 count = (scsicmd->cmnd[7 ] <<8 ) | scsicmd->cmnd[8 ]; -unsigned long flags; - -/* -* Wait for all outstanding queued commands to complete to this -* specific target (block). -*/ -spin_lock_irqsave (&sdev->list_lock, flags); -list_for_each_entry (cmd, &sdev->cmd_list, list) -if (cmd->SCp.phase ==AAC_OWNER_FIRMWARE ) { -u64 cmnd_lba; -u32 cmnd_count; - -if (cmd->cmnd[0 ] ==WRITE_6 ) { - cmnd_lba = ((cmd->cmnd[1 ] &0x1F ) <<16 ) | - (cmd->cmnd[2 ] <<8 ) | - cmd->cmnd[3 ]; - cmnd_count = cmd->cmnd[4 ]; -if (cmnd_count ==0 ) - cmnd_count =256 ; - }else if (cmd->cmnd[0 ] ==WRITE_16 ) { - cmnd_lba = ((u64 )cmd->cmnd[2 ] <<56 ) | - ((u64 )cmd->cmnd[3 ] <<48 ) | - ((u64 )cmd->cmnd[4 ] <<40 ) | - ((u64 )cmd->cmnd[5 ] <<32 ) | - ((u64 )cmd->cmnd[6 ] <<24 ) | - (cmd->cmnd[7 ] <<16 ) | - (cmd->cmnd[8 ] <<8 ) | - cmd->cmnd[9 ]; - cmnd_count = (cmd->cmnd[10 ] <<24 ) | - (cmd->cmnd[11 ] <<16 ) | - (cmd->cmnd[12 ] <<8 ) | - cmd->cmnd[13 ]; - }else if (cmd->cmnd[0 ] ==WRITE_12 ) { - cmnd_lba = ((u64 )cmd->cmnd[2 ] <<24 ) | - (cmd->cmnd[3 ] <<16 ) | - (cmd->cmnd[4 ] <<8 ) | - cmd->cmnd[5 ]; - cmnd_count = (cmd->cmnd[6 ] <<24 ) | - (cmd->cmnd[7 ] <<16 ) | - (cmd->cmnd[8 ] <<8 ) | - cmd->cmnd[9 ]; - }else if (cmd->cmnd[0 ] ==WRITE_10 ) { - cmnd_lba = ((u64 )cmd->cmnd[2 ] <<24 ) | - (cmd->cmnd[3 ] <<16 ) | - (cmd->cmnd[4 ] <<8 ) | - cmd->cmnd[5 ]; - cmnd_count = (cmd->cmnd[7 ] <<8 ) | - cmd->cmnd[8 ]; - }else -continue ; -if (((cmnd_lba + cmnd_count) < lba) || - (count && ((lba + count) < cmnd_lba))) -continue ; - ++active; -break ; - } - -spin_unlock_irqrestore (&sdev->list_lock, flags); - -/* -* Yield the processor (requeue for later) -*/ -if (active) -return SCSI_MLQUEUE_DEVICE_BUSY ; aac = (struct aac_dev *)sdev->host->hostdata;if (aac->in_reset)
@@ -2723,8 +2652,7 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd)/* * Allocate and initialize a Fib */ -if (!(cmd_fibcontext =aac_fib_alloc (aac))) -return SCSI_MLQUEUE_HOST_BUSY ; + cmd_fibcontext =aac_fib_alloc_tag (aac, scsicmd);aac_fib_init (cmd_fibcontext);
Signature · 1 line
2.16.4
RE: [PATCH 04/13] aacraid: Do not wait for outstanding write commands on synchronize_cache
-----Original Message-----
From: Hannes Reinecke <[email protected]>
Sent: Wednesday, December 4, 2019 20:29
To: Martin K. Petersen <[email protected]>
Cc: Christoph Hellwig <[email protected]>; Bart van Assche <[email protected]>; Balsundar P - I31211 <[email protected]>; James Bottomley <[email protected]>; [email protected]; Hannes Reinecke <[email protected]>; Adaptec OEM Raid Solutions <[email protected]>
Subject: [PATCH 04/13] aacraid: Do not wait for outstanding write commands on synchronize_cache
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
There is no need to wait for outstanding write commands on synchronize cache; the block layer is responsible for I/O scheduling, no need to out-guess it on the driver layer.
--- drivers/scsi/aacraid/aachba.c | 76 ++----------------------------------------- 1 file changed, 2 insertions(+), 74 deletions(-)
drivers/scsi/aacraid/aachba.c +2 -74
@@ -2601,9 +2601,7 @@ static int aac_write(struct scsi_cmnd * scsicmd) static void synchronize_callback(void *context, struct fib *fibptr) {struct aac_synchronize_reply *synchronizereply; -struct scsi_cmnd *cmd; - - cmd = context; +struct scsi_cmnd *cmd = context;if (!aac_valid_context (cmd, fibptr))return ;
@@ -2644,77 +2642,8 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd)int status;struct fib *cmd_fibcontext;struct aac_synchronize *synchronizecmd; -struct scsi_cmnd *cmd;struct scsi_device *sdev = scsicmd->device; -int active =0 ;struct aac_dev *aac; -u64 lba = ((u64 )scsicmd->cmnd[2 ] <<24 ) | (scsicmd->cmnd[3 ] <<16 ) | - (scsicmd->cmnd[4 ] <<8 ) | scsicmd->cmnd[5 ]; -u32 count = (scsicmd->cmnd[7 ] <<8 ) | scsicmd->cmnd[8 ]; -unsigned long flags; - -/* -* Wait for all outstanding queued commands to complete to this -* specific target (block). -*/ -spin_lock_irqsave (&sdev->list_lock, flags); -list_for_each_entry (cmd, &sdev->cmd_list, list) -if (cmd->SCp.phase ==AAC_OWNER_FIRMWARE ) { -u64 cmnd_lba; -u32 cmnd_count; - -if (cmd->cmnd[0 ] ==WRITE_6 ) { - cmnd_lba = ((cmd->cmnd[1 ] &0x1F ) <<16 ) | - (cmd->cmnd[2 ] <<8 ) | - cmd->cmnd[3 ]; - cmnd_count = cmd->cmnd[4 ]; -if (cmnd_count ==0 ) - cmnd_count =256 ; - }else if (cmd->cmnd[0 ] ==WRITE_16 ) { - cmnd_lba = ((u64 )cmd->cmnd[2 ] <<56 ) | - ((u64 )cmd->cmnd[3 ] <<48 ) | - ((u64 )cmd->cmnd[4 ] <<40 ) | - ((u64 )cmd->cmnd[5 ] <<32 ) | - ((u64 )cmd->cmnd[6 ] <<24 ) | - (cmd->cmnd[7 ] <<16 ) | - (cmd->cmnd[8 ] <<8 ) | - cmd->cmnd[9 ]; - cmnd_count = (cmd->cmnd[10 ] <<24 ) | - (cmd->cmnd[11 ] <<16 ) | - (cmd->cmnd[12 ] <<8 ) | - cmd->cmnd[13 ]; - }else if (cmd->cmnd[0 ] ==WRITE_12 ) { - cmnd_lba = ((u64 )cmd->cmnd[2 ] <<24 ) | - (cmd->cmnd[3 ] <<16 ) | - (cmd->cmnd[4 ] <<8 ) | - cmd->cmnd[5 ]; - cmnd_count = (cmd->cmnd[6 ] <<24 ) | - (cmd->cmnd[7 ] <<16 ) | - (cmd->cmnd[8 ] <<8 ) | - cmd->cmnd[9 ]; - }else if (cmd->cmnd[0 ] ==WRITE_10 ) { - cmnd_lba = ((u64 )cmd->cmnd[2 ] <<24 ) | - (cmd->cmnd[3 ] <<16 ) | - (cmd->cmnd[4 ] <<8 ) | - cmd->cmnd[5 ]; - cmnd_count = (cmd->cmnd[7 ] <<8 ) | - cmd->cmnd[8 ]; - }else -continue ; -if (((cmnd_lba + cmnd_count) < lba) || - (count && ((lba + count) < cmnd_lba))) -continue ; - ++active; -break ; - } - -spin_unlock_irqrestore (&sdev->list_lock, flags); - -/* -* Yield the processor (requeue for later) -*/ -if (active) -return SCSI_MLQUEUE_DEVICE_BUSY ; aac = (struct aac_dev *)sdev->host->hostdata;if (aac->in_reset)
@@ -2723,8 +2652,7 @@ static int aac_synchronize(struct scsi_cmnd *scsicmd)/* * Allocate and initialize a Fib */ -if (!(cmd_fibcontext =aac_fib_alloc (aac))) -return SCSI_MLQUEUE_HOST_BUSY ; + cmd_fibcontext =aac_fib_alloc_tag (aac, scsicmd);aac_fib_init (cmd_fibcontext);
--
2.16.4
PATCH v6 5/13 aacraid: use scsi_host_complete_all_commands() to terminate outstanding commands
In reply to Hannes ReineckeUse scsi_host_complete_all_commands() to terminate all outstanding commands instead, and change the command result for terminated commands to the more common 'DID_RESET' instead of 'QUEUE_FULL'.
--- drivers/scsi/aacraid/commsup.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
drivers/scsi/aacraid/commsup.c +2 -22
@@ -1478,8 +1478,6 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)int retval;struct Scsi_Host *host;struct scsi_device *dev; -struct scsi_cmnd *command; -struct scsi_cmnd *command_list;int jafo =0 ;int bled;u64 dmamask;
@@ -1607,26 +1605,8 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)* This is where the assumption that the Adapter is quiesced * is important. */ - command_list =NULL ; -__shost_for_each_device (dev, host) { -unsigned long flags; -spin_lock_irqsave (&dev->list_lock, flags); -list_for_each_entry (command, &dev->cmd_list, list) -if (command->SCp.phase ==AAC_OWNER_FIRMWARE ) { - command->SCp.buffer = (struct scatterlist *)command_list; - command_list = command; - } -spin_unlock_irqrestore (&dev->list_lock, flags); - } -while ((command = command_list)) { - command_list = (struct scsi_cmnd *)command->SCp.buffer; - command->SCp.buffer =NULL ; - command->result =DID_OK <<16 - |COMMAND_COMPLETE <<8 - |SAM_STAT_TASK_SET_FULL ; - command->SCp.phase =AAC_OWNER_ERROR_HANDLER ; - command->scsi_done (command); - } +scsi_host_complete_all_commands (host,DID_RESET ); +/* * Any Device that was already marked offline needs to be marked * running
Signature · 1 line
2.16.4
[email protected]
Acked-by Reviewed-by Bart Van Assche Reviewed-by Christoph Hellwig Acked-by on v6 5/13RE: [PATCH 05/13] aacraid: use scsi_host_complete_all_commands() to terminate outstanding commands
-----Original Message-----
From: Hannes Reinecke <[email protected]>
Sent: Wednesday, December 4, 2019 20:29
To: Martin K. Petersen <[email protected]>
Cc: Christoph Hellwig <[email protected]>; Bart van Assche <[email protected]>; Balsundar P - I31211 <[email protected]>; James Bottomley <[email protected]>; [email protected]; Hannes Reinecke <[email protected]>; Adaptec OEM Raid Solutions <[email protected]>
Subject: [PATCH 05/13] aacraid: use scsi_host_complete_all_commands() to terminate outstanding commands
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Use scsi_host_complete_all_commands() to terminate all outstanding commands instead, and change the command result for terminated commands to the more common 'DID_RESET' instead of 'QUEUE_FULL'.
--- drivers/scsi/aacraid/commsup.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
drivers/scsi/aacraid/commsup.c +2 -22
@@ -1478,8 +1478,6 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)int retval;struct Scsi_Host *host;struct scsi_device *dev; -struct scsi_cmnd *command; -struct scsi_cmnd *command_list;int jafo =0 ;int bled;u64 dmamask;
@@ -1607,26 +1605,8 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)* This is where the assumption that the Adapter is quiesced * is important. */ - command_list =NULL ; -__shost_for_each_device (dev, host) { -unsigned long flags; -spin_lock_irqsave (&dev->list_lock, flags); -list_for_each_entry (command, &dev->cmd_list, list) -if (command->SCp.phase ==AAC_OWNER_FIRMWARE ) { - command->SCp.buffer = (struct scatterlist *)command_list; - command_list = command; - } -spin_unlock_irqrestore (&dev->list_lock, flags); - } -while ((command = command_list)) { - command_list = (struct scsi_cmnd *)command->SCp.buffer; - command->SCp.buffer =NULL ; - command->result =DID_OK <<16 - |COMMAND_COMPLETE <<8 - |SAM_STAT_TASK_SET_FULL ; - command->SCp.phase =AAC_OWNER_ERROR_HANDLER ; - command->scsi_done (command); - } +scsi_host_complete_all_commands (host,DID_RESET ); +/* * Any Device that was already marked offline needs to be marked * running
--
2.16.4
PATCH v6 6/13 aacraid: replace aac_flush_ios() with midlayer helper
In reply to Hannes ReineckeUse the midlayer helper scsi_host_complete_all_commands() to flush all outstanding commands.
--- drivers/scsi/aacraid/linit.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
drivers/scsi/aacraid/linit.c +2 -22
@@ -1977,26 +1977,6 @@ static void aac_remove_one(struct pci_dev *pdev) } } -static void aac_flush_ios (struct aac_dev *aac) -{ -int i; -struct scsi_cmnd *cmd; - -for (i =0 ; i < aac->scsi_host_ptr->can_queue; i++) { - cmd = (struct scsi_cmnd *)aac->fibs[i].callback_data; -if (cmd && (cmd->SCp.phase ==AAC_OWNER_FIRMWARE )) { -scsi_dma_unmap (cmd); - -if (aac->handle_pci_error) - cmd->result =DID_NO_CONNECT <<16 ; -else - cmd->result =DID_RESET <<16 ; - - cmd->scsi_done (cmd); - } - } -} -static pci_ers_result_t aac_pci_error_detected (struct pci_dev *pdev,enum pci_channel_state error) {
@@ -2013,7 +1993,7 @@ static pci_ers_result_t aac_pci_error_detected(struct pci_dev *pdev,scsi_block_requests (aac->scsi_host_ptr);aac_cancel_rescan_worker (aac); -aac_flush_ios (aac); +scsi_host_complete_all_commands (shost,DID_NO_CONNECT );aac_release_resources (aac);pci_disable_pcie_error_reporting (pdev);
@@ -2023,7 +2003,7 @@ static pci_ers_result_t aac_pci_error_detected(struct pci_dev *pdev,case pci_channel_io_perm_failure: aac->handle_pci_error =1 ; -aac_flush_ios (aac); +scsi_host_complete_all_commands (shost,DID_NO_CONNECT );return PCI_ERS_RESULT_DISCONNECT ; }
Signature · 1 line
2.16.4
RE: [PATCH 06/13] aacraid: replace aac_flush_ios() with midlayer helper
-----Original Message-----
From: Hannes Reinecke <[email protected]>
Sent: Wednesday, December 4, 2019 20:29
To: Martin K. Petersen <[email protected]>
Cc: Christoph Hellwig <[email protected]>; Bart van Assche <[email protected]>; Balsundar P - I31211 <[email protected]>; James Bottomley <[email protected]>; [email protected]; Hannes Reinecke <[email protected]>; Adaptec OEM Raid Solutions <[email protected]>
Subject: [PATCH 06/13] aacraid: replace aac_flush_ios() with midlayer helper
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Use the midlayer helper scsi_host_complete_all_commands() to flush all outstanding commands.
--- drivers/scsi/aacraid/linit.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
drivers/scsi/aacraid/linit.c +0 -19
@@ -1977,26 +1977,6 @@ static void aac_remove_one(struct pci_dev *pdev) } } -static void aac_flush_ios(struct aac_dev *aac) -{ -int i; -struct scsi_cmnd *cmd; - -for (i =0 ; i < aac->scsi_host_ptr->can_queue; i++) { - cmd = (struct scsi_cmnd *)aac->fibs[i].callback_data; -if (cmd && (cmd->SCp.phase ==AAC_OWNER_FIRMWARE )) { -scsi_dma_unmap (cmd); - -if (aac->handle_pci_error) - cmd->result =DID_NO_CONNECT <<16 ; -else - cmd->result =DID_RESET <<16 ; - - cmd->scsi_done (cmd); - } - } -} -static pci_ers_result_t aac_pci_error_detected (struct pci_dev *pdev, enum pci_channel_state error) { @@ -2013,7 +1993,7 @@ static pci_ers_result_t aac_pci_error_detected(struct pci_dev *pdev,
scsi_block_requests(aac->scsi_host_ptr);
aac_cancel_rescan_worker(aac);
- aac_flush_ios(aac);
+ scsi_host_complete_all_commands(shost, DID_NO_CONNECT);
aac_release_resources(aac);
pci_disable_pcie_error_reporting(pdev);
@@ -2023,7 +2003,7 @@ static pci_ers_result_t aac_pci_error_detected(struct pci_dev *pdev,
case pci_channel_io_perm_failure:
aac->handle_pci_error = 1;- aac_flush_ios(aac);
+ scsi_host_complete_all_commands(shost, DID_NO_CONNECT);
return PCI_ERS_RESULT_DISCONNECT;
}--
2.16.4
PATCH v6 7/13 aacraid: move scsi_(block,unblock)_requests out of _aac_reset_adapter()
In reply to Hannes Reinecke_aac_reset_adapter() only has one caller, and that one already calls scsi_block_requests(). So move the calls out of _aac_reset_adapter() to avoid calling scsi_block_requests() twice.
--- drivers/scsi/aacraid/commsup.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/scsi/aacraid/commsup.c +4 -6
@@ -1476,7 +1476,7 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type) {int index, quirks;int retval; -struct Scsi_Host *host; +struct Scsi_Host *host = aac->scsi_host_ptr;struct scsi_device *dev;int jafo =0 ;int bled;
@@ -1493,8 +1493,6 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)* - The card is dead, or will be very shortly ;-/ so no new * commands are completing in the interrupt service. */ - host = aac->scsi_host_ptr; -scsi_block_requests (host);aac_adapter_disable_int (aac);if (aac->thread && aac->thread->pid != current->pid) {spin_unlock_irq (host->host_lock);
@@ -1619,7 +1617,6 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type) out: aac->in_reset =0 ; -scsi_unblock_requests (host);/* * Issue bus rescan to catch any configuration that might have
@@ -1640,7 +1637,7 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type) {unsigned long flagv =0 ;int retval; -struct Scsi_Host * host; +struct Scsi_Host * host = aac->scsi_host_ptr;int bled;if (spin_trylock_irqsave (&aac->fib_lock, flagv) ==0 )
@@ -1658,7 +1655,6 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)* target (block maximum 60 seconds). Although not necessary, * it does make us a good storage citizen. */ - host = aac->scsi_host_ptr;scsi_block_requests (host);/* Quiesce build, flush cache, write through mode */
@@ -1670,6 +1666,8 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type) retval =_aac_reset_adapter (aac, bled, reset_type);spin_unlock_irqrestore (host->host_lock, flagv); +scsi_unblock_requests (host); +if ((forced <2 ) && (retval == -ENODEV )) {/* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */ struct fib * fibctx =aac_fib_alloc (aac);
Signature · 1 line
2.16.4
RE: [PATCH 07/13] aacraid: move scsi_(block,unblock)_requests out of _aac_reset_adapter()
-----Original Message-----
From: Hannes Reinecke <[email protected]>
Sent: Wednesday, December 4, 2019 20:29
To: Martin K. Petersen <[email protected]>
Cc: Christoph Hellwig <[email protected]>; Bart van Assche <[email protected]>; Balsundar P - I31211 <[email protected]>; James Bottomley <[email protected]>; [email protected]; Hannes Reinecke <[email protected]>; Balsundar P <[email protected]>; Adaptec OEM Raid Solutions <[email protected]>
Subject: [PATCH 07/13] aacraid: move scsi_(block,unblock)_requests out of _aac_reset_adapter()
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
_aac_reset_adapter() only has one caller, and that one already calls scsi_block_requests(). So move the calls out of _aac_reset_adapter() to avoid calling scsi_block_requests() twice.
--- drivers/scsi/aacraid/commsup.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/scsi/aacraid/commsup.c +1 -3
@@ -1476,7 +1476,7 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type) {int index, quirks;int retval; -struct Scsi_Host *host; +struct Scsi_Host *host = aac->scsi_host_ptr;struct scsi_device *dev;int jafo =0 ;int bled;
@@ -1493,8 +1493,6 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)* - The card is dead, or will be very shortly ;-/ so no new * commands are completing in the interrupt service. */ - host = aac->scsi_host_ptr; -scsi_block_requests (host);aac_adapter_disable_int (aac);if (aac->thread && aac->thread->pid != current->pid) { spin_unlock_irq(host->host_lock); @@ -1619,7 +1617,6 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
out:
aac->in_reset = 0;
- scsi_unblock_requests(host);
/*
* Issue bus rescan to catch any configuration that might have @@ -1640,7 +1637,7 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type) {
unsigned long flagv = 0;
int retval;
- struct Scsi_Host * host;
+ struct Scsi_Host * host = aac->scsi_host_ptr;
int bled;
if (spin_trylock_irqsave(&aac->fib_lock, flagv) == 0) @@ -1658,7 +1655,6 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
* target (block maximum 60 seconds). Although not necessary,
* it does make us a good storage citizen.
*/
- host = aac->scsi_host_ptr;
scsi_block_requests(host);
/* Quiesce build, flush cache, write through mode */ @@ -1670,6 +1666,8 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
retval = _aac_reset_adapter(aac, bled, reset_type);
spin_unlock_irqrestore(host->host_lock, flagv);+ scsi_unblock_requests(host);
+
if ((forced < 2) && (retval == -ENODEV)) {
/* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */
struct fib * fibctx = aac_fib_alloc(aac);--
2.16.4
PATCH v6 8/13 scsi: add scsi_host_(block,unblock) helper function
In reply to Hannes ReineckeAdd helper functions to call scsi_internal_device_block()/ scsi_internal_device_unblock() for all attached devices on a scsi host.
--- drivers/scsi/scsi_lib.c | 30 ++++++++++++++++++++++++++++++ include/scsi/scsi_host.h | 2 ++ 2 files changed, 32 insertions(+)
drivers/scsi/scsi_lib.c +30 -0
@@ -2840,6 +2840,36 @@ scsi_target_unblock(struct device *dev, enum scsi_device_state new_state) }EXPORT_SYMBOL_GPL (scsi_target_unblock); +int +scsi_host_block (struct Scsi_Host *shost) +{ +struct scsi_device *sdev; +int ret =0 ; + +shost_for_each_device (sdev, shost) { + ret =scsi_internal_device_block (sdev); +if (ret) +break ; + } +return ret; +} +EXPORT_SYMBOL_GPL (scsi_host_block); + +int +scsi_host_unblock (struct Scsi_Host *shost,int new_state) +{ +struct scsi_device *sdev; +int ret =0 ; + +shost_for_each_device (sdev, shost) { + ret =scsi_internal_device_unblock (sdev, new_state); +if (ret) +break ; + } +return ret; +} +EXPORT_SYMBOL_GPL (scsi_host_unblock); +/** * scsi_kmap_atomic_sg - find and atomically map an sg-elemnt * @sgl: scatter-gather list
include/scsi/scsi_host.h +2 -0
@@ -760,6 +760,8 @@ static inline int scsi_host_scan_allowed(struct Scsi_Host *shost)extern void scsi_unblock_requests (struct Scsi_Host *);extern void scsi_block_requests (struct Scsi_Host *); +extern int scsi_host_block (struct Scsi_Host *shost); +extern int scsi_host_unblock (struct Scsi_Host *shost,int new_state);struct class_container ;
Signature · 1 line
2.16.4
PATCH v6 9/13 aacraid: use scsi_host_(block,unblock) to block I/O
In reply to Hannes ReineckeUse scsi_host_block() and scsi_host_unblock() instead of scsi_block_requests()/scsi_unblock_requests() to block and unblock I/O. This has the advantage that the block layer will stop sending I/O to the adapter instead of having the SCSI midlayer requeueing I/O internally.
--- drivers/scsi/aacraid/commsup.c | 14 ++------------ drivers/scsi/aacraid/linit.c | 15 ++++++--------- 2 files changed, 8 insertions(+), 21 deletions(-)
drivers/scsi/aacraid/commsup.c +2 -12
@@ -1477,7 +1477,6 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)int index, quirks;int retval;struct Scsi_Host *host = aac->scsi_host_ptr; -struct scsi_device *dev;int jafo =0 ;int bled;u64 dmamask;
@@ -1605,16 +1604,7 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)*/ scsi_host_complete_all_commands (host,DID_RESET ); -/* -* Any Device that was already marked offline needs to be marked -* running -*/ -__shost_for_each_device (dev, host) { -if (!scsi_device_online (dev)) -scsi_device_set_state (dev,SDEV_RUNNING ); - } retval =0 ; - out: aac->in_reset =0 ;
@@ -1655,7 +1645,7 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)* target (block maximum 60 seconds). Although not necessary, * it does make us a good storage citizen. */ -scsi_block_requests (host); +scsi_host_block (host);/* Quiesce build, flush cache, write through mode */ if (forced <2 )
@@ -1666,7 +1656,7 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type) retval =_aac_reset_adapter (aac, bled, reset_type);spin_unlock_irqrestore (host->host_lock, flagv); -scsi_unblock_requests (host); + retval =scsi_host_unblock (host,SDEV_RUNNING );if ((forced <2 ) && (retval == -ENODEV )) {/* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */
drivers/scsi/aacraid/linit.c +6 -9
@@ -1894,7 +1894,7 @@ static int aac_suspend(struct pci_dev *pdev, pm_message_t state)struct Scsi_Host *shost =pci_get_drvdata (pdev);struct aac_dev *aac = (struct aac_dev *)shost->hostdata; -scsi_block_requests (shost); +scsi_host_block (shost);aac_cancel_rescan_worker (aac);aac_send_shutdown (aac);
@@ -1930,7 +1930,7 @@ static int aac_resume(struct pci_dev *pdev)* aac_send_shutdown() to block ioctls from upperlayer */ aac->adapter_shutdown =0 ; -scsi_unblock_requests (shost); +scsi_host_unblock (shost,SDEV_RUNNING );return 0 ;
@@ -1945,7 +1945,8 @@ static int aac_resume(struct pci_dev *pdev)static void aac_shutdown (struct pci_dev *dev) {struct Scsi_Host *shost =pci_get_drvdata (dev); -scsi_block_requests (shost); + +scsi_host_block (shost);__aac_shutdown ((struct aac_dev *)shost->hostdata); }
@@ -1991,7 +1992,7 @@ static pci_ers_result_t aac_pci_error_detected(struct pci_dev *pdev,case pci_channel_io_frozen: aac->handle_pci_error =1 ; -scsi_block_requests (aac->scsi_host_ptr); +scsi_host_block (shost);aac_cancel_rescan_worker (aac);scsi_host_complete_all_commands (shost,DID_NO_CONNECT );aac_release_resources (aac);
@@ -2044,7 +2045,6 @@ static pci_ers_result_t aac_pci_slot_reset(struct pci_dev *pdev)static void aac_pci_resume (struct pci_dev *pdev) {struct Scsi_Host *shost =pci_get_drvdata (pdev); -struct scsi_device *sdev =NULL ;struct aac_dev *aac = (struct aac_dev *)shost_priv (shost);if (aac_adapter_ioremap (aac, aac->base_size)) {
@@ -2071,10 +2071,7 @@ static void aac_pci_resume(struct pci_dev *pdev) aac->adapter_shutdown =0 ; aac->handle_pci_error =0 ; -shost_for_each_device (sdev, shost) -if (sdev->sdev_state ==SDEV_OFFLINE ) - sdev->sdev_state =SDEV_RUNNING ; -scsi_unblock_requests (aac->scsi_host_ptr); +scsi_host_unblock (shost,SDEV_RUNNING );aac_scan_host (aac);pci_save_state (pdev);
Signature · 1 line
2.16.4
RE: [PATCH 09/13] aacraid: use scsi_host_(block,unblock) to block I/O
-----Original Message-----
From: Hannes Reinecke <[email protected]>
Sent: Wednesday, December 4, 2019 20:29
To: Martin K. Petersen <[email protected]>
Cc: Christoph Hellwig <[email protected]>; Bart van Assche <[email protected]>; Balsundar P - I31211 <[email protected]>; James Bottomley <[email protected]>; [email protected]; Hannes Reinecke <[email protected]>; Balsundar P <[email protected]>; Adaptec OEM Raid Solutions <[email protected]>
Subject: [PATCH 09/13] aacraid: use scsi_host_(block,unblock) to block I/O
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Use scsi_host_block() and scsi_host_unblock() instead of
scsi_block_requests()/scsi_unblock_requests() to block and unblock I/O.
This has the advantage that the block layer will stop sending I/O to the adapter instead of having the SCSI midlayer requeueing I/O internally.
--- drivers/scsi/aacraid/commsup.c | 14 ++------------ drivers/scsi/aacraid/linit.c | 15 ++++++--------- 2 files changed, 8 insertions(+), 21 deletions(-)
drivers/scsi/aacraid/commsup.c +2 -12
@@ -1477,7 +1477,6 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)int index, quirks;int retval;struct Scsi_Host *host = aac->scsi_host_ptr; -struct scsi_device *dev;int jafo =0 ;int bled;u64 dmamask;
@@ -1605,16 +1604,7 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)*/ scsi_host_complete_all_commands (host,DID_RESET ); -/* -* Any Device that was already marked offline needs to be marked -* running -*/ -__shost_for_each_device (dev, host) { -if (!scsi_device_online (dev)) -scsi_device_set_state (dev,SDEV_RUNNING ); - } retval =0 ; - out: aac->in_reset =0 ;
@@ -1655,7 +1645,7 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)* target (block maximum 60 seconds). Although not necessary, * it does make us a good storage citizen. */ -scsi_block_requests (host); +scsi_host_block (host);/* Quiesce build, flush cache, write through mode */ if (forced <2 )
@@ -1666,7 +1656,7 @@ int aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type) retval =_aac_reset_adapter (aac, bled, reset_type);spin_unlock_irqrestore (host->host_lock, flagv); -scsi_unblock_requests (host); + retval =scsi_host_unblock (host,SDEV_RUNNING );if ((forced <2 ) && (retval == -ENODEV )) { /* Unwind aac_send_shutdown() IOP_RESET unsupported/disabled */ diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c index 4d5b34e0d3a9..877464e9d520 100644
drivers/scsi/aacraid/linit.c +5 -4
@@ -1894,7 +1894,7 @@ static int aac_suspend(struct pci_dev *pdev, pm_message_t state)struct Scsi_Host *shost =pci_get_drvdata (pdev);struct aac_dev *aac = (struct aac_dev *)shost->hostdata; -scsi_block_requests (shost); +scsi_host_block (shost);aac_cancel_rescan_worker (aac);aac_send_shutdown (aac);
@@ -1930,7 +1930,7 @@ static int aac_resume(struct pci_dev *pdev)* aac_send_shutdown() to block ioctls from upperlayer */ aac->adapter_shutdown =0 ; -scsi_unblock_requests (shost); +scsi_host_unblock (shost,SDEV_RUNNING );return 0 ;
@@ -1945,7 +1945,8 @@ static int aac_resume(struct pci_dev *pdev) static void aac_shutdown(struct pci_dev *dev) {struct Scsi_Host *shost =pci_get_drvdata (dev); -scsi_block_requests (shost); + +scsi_host_block (shost);__aac_shutdown ((struct aac_dev *)shost->hostdata); }
@@ -1991,7 +1992,7 @@ static pci_ers_result_t aac_pci_error_detected(struct pci_dev *pdev,case pci_channel_io_frozen: aac->handle_pci_error =1 ; -scsi_block_requests (aac->scsi_host_ptr); +scsi_host_block (shost);aac_cancel_rescan_worker (aac);scsi_host_complete_all_commands (shost,DID_NO_CONNECT ); aac_release_resources(aac); @@ -2044,7 +2045,6 @@ static pci_ers_result_t aac_pci_slot_reset(struct pci_dev *pdev) static void aac_pci_resume(struct pci_dev *pdev) {
struct Scsi_Host *shost = pci_get_drvdata(pdev);
- struct scsi_device *sdev = NULL;
struct aac_dev *aac = (struct aac_dev *)shost_priv(shost);
if (aac_adapter_ioremap(aac, aac->base_size)) { @@ -2071,10 +2071,7 @@ static void aac_pci_resume(struct pci_dev *pdev)
aac->adapter_shutdown = 0;
aac->handle_pci_error = 0;- shost_for_each_device(sdev, shost)
- if (sdev->sdev_state == SDEV_OFFLINE)
- sdev->sdev_state = SDEV_RUNNING;
- scsi_unblock_requests(aac->scsi_host_ptr);
+ scsi_host_unblock(shost, SDEV_RUNNING);
aac_scan_host(aac);
pci_save_state(pdev);--
2.16.4
PATCH v6 10/13 scsi: add scsi_host_busy_iter()
In reply to Hannes ReineckeAdd an iterator scsi_host_busy_iter() to traverse all busy commands. If locking against concurrent command completions is required it has to be provided by the caller.
--- drivers/scsi/hosts.c | 33 +++++++++++++++++++++++++++++++++ include/scsi/scsi_host.h | 5 +++++ 2 files changed, 38 insertions(+)
drivers/scsi/hosts.c +33 -0
@@ -678,3 +678,36 @@ void scsi_host_complete_all_commands(struct Scsi_Host *shost, int status) &status); }EXPORT_SYMBOL_GPL (scsi_host_complete_all_commands); + +struct scsi_host_busy_iter_data { +scsi_host_busy_iter_fn *fn; +void *priv; +}; + +static bool __scsi_host_busy_iter_fn (struct request *req,void *priv, +bool reserved) +{ +struct scsi_host_busy_iter_data *iter_data = priv; +struct scsi_cmnd *sc =blk_mq_rq_to_pdu (req); + +return iter_data->fn (sc, iter_data->priv, reserved); +} + +/** +* scsi_host_busy_iter - Iterate over all busy commands +* @shost: Pointer to Scsi_Host. +* @fn: Function to call on each busy command +* @priv: Data pointer passed to @fn +**/ +void scsi_host_busy_iter (struct Scsi_Host *shost, +scsi_host_busy_iter_fn *fn,void *priv) +{ +struct scsi_host_busy_iter_data iter_data = { + .fn = fn, + .priv = priv, + }; + +blk_mq_tagset_busy_iter (&shost->tag_set, __scsi_host_busy_iter_fn, + &iter_data); +} +EXPORT_SYMBOL_GPL (scsi_host_busy_iter);
include/scsi/scsi_host.h +5 -0
@@ -763,6 +763,11 @@ extern void scsi_block_requests(struct Scsi_Host *);extern int scsi_host_block (struct Scsi_Host *shost);extern int scsi_host_unblock (struct Scsi_Host *shost,int new_state); +typedef bool (scsi_host_busy_iter_fn )(struct scsi_cmnd *,void *,bool ); + +void scsi_host_busy_iter (struct Scsi_Host *, +scsi_host_busy_iter_fn *fn,void *priv); +struct class_container ;/*
Signature · 1 line
2.16.4
PATCH v6 11/13 aacraid: use scsi_host_busy_iter() to wait for outstanding commands
In reply to Hannes ReineckeInstead of traversing the list of possible commands by hands we should be using scsi_host_busy_iter() to figure out if there are outstanding commands.
--- drivers/scsi/aacraid/comminit.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
drivers/scsi/aacraid/comminit.c +17 -18
@@ -272,36 +272,35 @@ static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, q->entries = qsize; } +static bool wait_for_io_iter (struct scsi_cmnd *cmd,void *data,bool rsvd) +{ +int *active = data; + +if (cmd->SCp.phase ==AAC_OWNER_FIRMWARE ) + *active = *active +1 ; +return true; +}static void aac_wait_for_io_completion (struct aac_dev *aac) { -unsigned long flagv =0 ; -int i =0 ; +int i =0 , active;for (i =60 ; i; --i) { -struct scsi_device *dev; -struct scsi_cmnd *command; -int active =0 ; - -__shost_for_each_device (dev, aac->scsi_host_ptr) { -spin_lock_irqsave (&dev->list_lock, flagv); -list_for_each_entry (command, &dev->cmd_list, list) { -if (command->SCp.phase ==AAC_OWNER_FIRMWARE ) { - active++; -break ; - } - } -spin_unlock_irqrestore (&dev->list_lock, flagv); -if (active) -break ; - } + active =0 ; +scsi_host_busy_iter (aac->scsi_host_ptr, + wait_for_io_iter, &active);/* * We can exit If all the commands are complete */ if (active ==0 )break ; +dev_info (&aac->pdev->dev, +"Wait for %d commands to complete\n" , active);ssleep (1 ); } +if (active) +dev_err (&aac->pdev->dev, +"%d outstanding commands during shutdown\n" , active); }/**
Signature · 1 line
2.16.4
RE: [PATCH 11/13] aacraid: use scsi_host_busy_iter() to wait for outstanding commands
-----Original Message-----
From: Hannes Reinecke <[email protected]>
Sent: Wednesday, December 4, 2019 20:29
To: Martin K. Petersen <[email protected]>
Cc: Christoph Hellwig <[email protected]>; Bart van Assche <[email protected]>; Balsundar P - I31211 <[email protected]>; James Bottomley <[email protected]>; [email protected]; Hannes Reinecke <[email protected]>
Subject: [PATCH 11/13] aacraid: use scsi_host_busy_iter() to wait for outstanding commands
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Instead of traversing the list of possible commands by hands we should be using scsi_host_busy_iter() to figure out if there are outstanding commands.
--- drivers/scsi/aacraid/comminit.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
drivers/scsi/aacraid/comminit.c +18 -19
@@ -272,36 +272,35 @@ static void aac_queue_init(struct aac_dev * dev, struct aac_queue * q, u32 *mem, q->entries = qsize; } +static bool wait_for_io_iter (struct scsi_cmnd *cmd,void *data,bool +rsvd) { +int *active = data; + +if (cmd->SCp.phase ==AAC_OWNER_FIRMWARE ) + *active = *active +1 ; +return true; +}static void aac_wait_for_io_completion (struct aac_dev *aac) { -unsigned long flagv =0 ; -int i =0 ; +int i =0 , active;for (i =60 ; i; --i) { -struct scsi_device *dev; -struct scsi_cmnd *command; -int active =0 ; - -__shost_for_each_device (dev, aac->scsi_host_ptr) { -spin_lock_irqsave (&dev->list_lock, flagv); -list_for_each_entry (command, &dev->cmd_list, list) { -if (command->SCp.phase ==AAC_OWNER_FIRMWARE ) { - active++; -break ; - } - } -spin_unlock_irqrestore (&dev->list_lock, flagv); -if (active) -break ; - } + active =0 ; +scsi_host_busy_iter (aac->scsi_host_ptr, + wait_for_io_iter, &active);/* * We can exit If all the commands are complete */ if (active ==0 )break ; +dev_info (&aac->pdev->dev, +"Wait for %d commands to complete\n" , active);ssleep (1 ); } +if (active) +dev_err (&aac->pdev->dev, +"%d outstanding commands during shutdown\n" , + active); }/** --
2.16.4
PATCH v6 12/13 aacraid: use scsi_host_busy_iter() in get_num_of_incomplete_fibs()
In reply to Hannes ReineckeUse the scsi midlayer helper to traverse the number of outstanding commands. This also eliminates the last usage for the cmd_list functionality so we can drop it.
--- drivers/scsi/aacraid/linit.c | 81 ++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 40 deletions(-)
drivers/scsi/aacraid/linit.c +41 -40
@@ -622,54 +622,56 @@ static int aac_ioctl(struct scsi_device *sdev, unsigned int cmd,return aac_do_ioctl (dev, cmd, arg); } -static int get_num_of_incomplete_fibs (struct aac_dev *aac) +struct fib_count_data { +int mlcnt; +int llcnt; +int ehcnt; +int fwcnt; +int krlcnt; +}; + +static bool fib_count_iter (struct scsi_cmnd *scmnd,void *data,bool reserved) { +struct fib_count_data *fib_count = data; + +switch (scmnd->SCp.phase) { +case AAC_OWNER_FIRMWARE : + fib_count->fwcnt++; +break ; +case AAC_OWNER_ERROR_HANDLER : + fib_count->ehcnt++; +break ; +case AAC_OWNER_LOWLEVEL : + fib_count->llcnt++; +break ; +case AAC_OWNER_MIDLEVEL : + fib_count->mlcnt++; +break ; +default : + fib_count->krlcnt++; +break ; + } +return true; +} -unsigned long flags; -struct scsi_device *sdev =NULL ; +/* Called during SCSI EH, so we don't need to block requests */ +static int get_num_of_incomplete_fibs (struct aac_dev *aac) +{struct Scsi_Host *shost = aac->scsi_host_ptr; -struct scsi_cmnd *scmnd =NULL ;struct device *ctrl_dev; +struct fib_count_data fcnt = { }; -int mlcnt =0 ; -int llcnt =0 ; -int ehcnt =0 ; -int fwcnt =0 ; -int krlcnt =0 ; - -__shost_for_each_device (sdev, shost) { -spin_lock_irqsave (&sdev->list_lock, flags); -list_for_each_entry (scmnd, &sdev->cmd_list, list) { -switch (scmnd->SCp.phase) { -case AAC_OWNER_FIRMWARE : - fwcnt++; -break ; -case AAC_OWNER_ERROR_HANDLER : - ehcnt++; -break ; -case AAC_OWNER_LOWLEVEL : - llcnt++; -break ; -case AAC_OWNER_MIDLEVEL : - mlcnt++; -break ; -default : - krlcnt++; -break ; - } - } -spin_unlock_irqrestore (&sdev->list_lock, flags); - } +scsi_host_busy_iter (shost, fib_count_iter, &fcnt); ctrl_dev = &aac->pdev->dev; -dev_info (ctrl_dev,"outstanding cmd: midlevel-%d\n" , mlcnt); -dev_info (ctrl_dev,"outstanding cmd: lowlevel-%d\n" , llcnt); -dev_info (ctrl_dev,"outstanding cmd: error handler-%d\n" , ehcnt); -dev_info (ctrl_dev,"outstanding cmd: firmware-%d\n" , fwcnt); -dev_info (ctrl_dev,"outstanding cmd: kernel-%d\n" , krlcnt); +dev_info (ctrl_dev,"outstanding cmd: midlevel-%d\n" , fcnt.mlcnt); +dev_info (ctrl_dev,"outstanding cmd: lowlevel-%d\n" , fcnt.llcnt); +dev_info (ctrl_dev,"outstanding cmd: error handler-%d\n" , fcnt.ehcnt); +dev_info (ctrl_dev,"outstanding cmd: firmware-%d\n" , fcnt.fwcnt); +dev_info (ctrl_dev,"outstanding cmd: kernel-%d\n" , fcnt.krlcnt); -return mlcnt + llcnt + ehcnt + fwcnt; +return fcnt.mlcnt + fcnt.llcnt + fcnt.ehcnt + fcnt.fwcnt; }static int aac_eh_abort (struct scsi_cmnd * cmd)
@@ -1675,7 +1677,6 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) shost->irq = pdev->irq; shost->unique_id = unique_id; shost->max_cmd_len =16 ; - shost->use_cmd_list =1 ;if (aac_cfg_major ==AAC_CHARDEV_NEEDS_REINIT )aac_init_char ();
Signature · 1 line
2.16.4
RE: [PATCH 12/13] aacraid: use scsi_host_busy_iter() in get_num_of_incomplete_fibs()
-----Original Message-----
From: Hannes Reinecke <[email protected]>
Sent: Wednesday, December 4, 2019 20:29
To: Martin K. Petersen <[email protected]>
Cc: Christoph Hellwig <[email protected]>; Bart van Assche <[email protected]>; Balsundar P - I31211 <[email protected]>; James Bottomley <[email protected]>; [email protected]; Hannes Reinecke <[email protected]>; Adaptec OEM Raid Solutions <[email protected]>
Subject: [PATCH 12/13] aacraid: use scsi_host_busy_iter() in get_num_of_incomplete_fibs()
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Use the scsi midlayer helper to traverse the number of outstanding commands. This also eliminates the last usage for the cmd_list functionality so we can drop it.
--- drivers/scsi/aacraid/linit.c | 81 ++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 40 deletions(-)
drivers/scsi/aacraid/linit.c +41 -39
@@ -622,54 +622,56 @@ static int aac_ioctl(struct scsi_device *sdev, unsigned int cmd,return aac_do_ioctl (dev, cmd, arg); } -static int get_num_of_incomplete_fibs (struct aac_dev *aac) +struct fib_count_data { +int mlcnt; +int llcnt; +int ehcnt; +int fwcnt; +int krlcnt; +}; + +static bool fib_count_iter (struct scsi_cmnd *scmnd,void *data,bool +reserved) { +struct fib_count_data *fib_count = data; + +switch (scmnd->SCp.phase) { +case AAC_OWNER_FIRMWARE : + fib_count->fwcnt++; +break ; +case AAC_OWNER_ERROR_HANDLER : + fib_count->ehcnt++; +break ; +case AAC_OWNER_LOWLEVEL : + fib_count->llcnt++; +break ; +case AAC_OWNER_MIDLEVEL : + fib_count->mlcnt++; +break ; +default : + fib_count->krlcnt++; +break ; + } +return true; +} -unsigned long flags; -struct scsi_device *sdev =NULL ; +/* Called during SCSI EH, so we don't need to block requests */ static +int get_num_of_incomplete_fibs (struct aac_dev *aac) {struct Scsi_Host *shost = aac->scsi_host_ptr; -struct scsi_cmnd *scmnd =NULL ;struct device *ctrl_dev; +struct fib_count_data fcnt = { }; -int mlcnt =0 ; -int llcnt =0 ; -int ehcnt =0 ; -int fwcnt =0 ; -int krlcnt =0 ; - -__shost_for_each_device (sdev, shost) { -spin_lock_irqsave (&sdev->list_lock, flags); -list_for_each_entry (scmnd, &sdev->cmd_list, list) { -switch (scmnd->SCp.phase) { -case AAC_OWNER_FIRMWARE : - fwcnt++; -break ; -case AAC_OWNER_ERROR_HANDLER : - ehcnt++; -break ; -case AAC_OWNER_LOWLEVEL : - llcnt++; -break ; -case AAC_OWNER_MIDLEVEL : - mlcnt++; -break ; -default : - krlcnt++; -break ; - } - } -spin_unlock_irqrestore (&sdev->list_lock, flags); - } +scsi_host_busy_iter (shost, fib_count_iter, &fcnt); ctrl_dev = &aac->pdev->dev; -dev_info (ctrl_dev,"outstanding cmd: midlevel-%d\n" , mlcnt); -dev_info (ctrl_dev,"outstanding cmd: lowlevel-%d\n" , llcnt); -dev_info (ctrl_dev,"outstanding cmd: error handler-%d\n" , ehcnt); -dev_info (ctrl_dev,"outstanding cmd: firmware-%d\n" , fwcnt); -dev_info (ctrl_dev,"outstanding cmd: kernel-%d\n" , krlcnt); +dev_info (ctrl_dev,"outstanding cmd: midlevel-%d\n" , fcnt.mlcnt); +dev_info (ctrl_dev,"outstanding cmd: lowlevel-%d\n" , fcnt.llcnt); +dev_info (ctrl_dev,"outstanding cmd: error handler-%d\n" , fcnt.ehcnt); +dev_info (ctrl_dev,"outstanding cmd: firmware-%d\n" , fcnt.fwcnt); +dev_info (ctrl_dev,"outstanding cmd: kernel-%d\n" , fcnt.krlcnt); -return mlcnt + llcnt + ehcnt + fwcnt; +return fcnt.mlcnt + fcnt.llcnt + fcnt.ehcnt + fcnt.fwcnt; } static int aac_eh_abort(struct scsi_cmnd* cmd) @@ -1675,7 +1677,6 @@ static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) shost->irq = pdev->irq;
shost->unique_id = unique_id;
shost->max_cmd_len = 16;- shost->use_cmd_list = 1;
if (aac_cfg_major == AAC_CHARDEV_NEEDS_REINIT)
aac_init_char();--
2.16.4
PATCH v6 13/13 scsi: Remove cmd_list functionality
In reply to Hannes ReineckeRemove cmd_list functionality; no users left. With that the scsi_put_command() becomes empty, so remove that one, too.
--- drivers/scsi/scsi.c | 14 -------------- drivers/scsi/scsi_error.c | 1 - drivers/scsi/scsi_lib.c | 31 ------------------------------- drivers/scsi/scsi_priv.h | 2 -- drivers/scsi/scsi_scan.c | 1 - include/scsi/scsi_cmnd.h | 1 - include/scsi/scsi_device.h | 1 - include/scsi/scsi_host.h | 2 -- 8 files changed, 53 deletions(-)
drivers/scsi/scsi.c +0 -14
@@ -94,20 +94,6 @@ EXPORT_SYMBOL(scsi_logging_level);ASYNC_DOMAIN_EXCLUSIVE (scsi_sd_pm_domain);EXPORT_SYMBOL (scsi_sd_pm_domain); -/** -* scsi_put_command - Free a scsi command block -* @cmd: command block to free -* -* Returns: Nothing. -* -* Notes: The command must not belong to any lists. -*/ -void scsi_put_command (struct scsi_cmnd *cmd) -{ -scsi_del_cmd_from_list (cmd); -BUG_ON (delayed_work_pending (&cmd->abort_work)); -} -#ifdef CONFIG_SCSI_LOGGING void scsi_log_send (struct scsi_cmnd *cmd) {
drivers/scsi/scsi_error.c +0 -1
@@ -2412,7 +2412,6 @@ scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)wake_up (&shost->host_wait);scsi_run_host_queues (shost); -scsi_put_command (scmd);kfree (rq); out_put_autopm_host:
drivers/scsi/scsi_lib.c +0 -31
@@ -562,7 +562,6 @@ static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd) {scsi_mq_free_sgtables (cmd);scsi_uninit_cmd (cmd); -scsi_del_cmd_from_list (cmd); }/* Returns false when no more bytes to process, true if there are more */
@@ -1098,35 +1097,6 @@ static void scsi_cleanup_rq(struct request *rq) } } -/* Add a command to the list used by the aacraid and dpt_i2o drivers */ -void scsi_add_cmd_to_list (struct scsi_cmnd *cmd) -{ -struct scsi_device *sdev = cmd->device; -struct Scsi_Host *shost = sdev->host; -unsigned long flags; - -if (shost->use_cmd_list) { -spin_lock_irqsave (&sdev->list_lock, flags); -list_add_tail (&cmd->list, &sdev->cmd_list); -spin_unlock_irqrestore (&sdev->list_lock, flags); - } -} - -/* Remove a command from the list used by the aacraid and dpt_i2o drivers */ -void scsi_del_cmd_from_list (struct scsi_cmnd *cmd) -{ -struct scsi_device *sdev = cmd->device; -struct Scsi_Host *shost = sdev->host; -unsigned long flags; - -if (shost->use_cmd_list) { -spin_lock_irqsave (&sdev->list_lock, flags); -BUG_ON (list_empty (&cmd->list)); -list_del_init (&cmd->list); -spin_unlock_irqrestore (&sdev->list_lock, flags); - } -} -/* Called after a request has been started. */ void scsi_init_command (struct scsi_device *dev,struct scsi_cmnd *cmd) {
@@ -1160,7 +1130,6 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)if (in_flight)__set_bit (SCMD_STATE_INFLIGHT , &cmd->state); -scsi_add_cmd_to_list (cmd); } static blk_status_t scsi_setup_scsi_cmnd(struct scsi_device *sdev,
drivers/scsi/scsi_priv.h +0 -2
@@ -84,8 +84,6 @@ int scsi_eh_get_sense(struct list_head *work_q,int scsi_noretry_cmd (struct scsi_cmnd *scmd);/* scsi_lib.c */ -extern void scsi_add_cmd_to_list (struct scsi_cmnd *cmd); -extern void scsi_del_cmd_from_list (struct scsi_cmnd *cmd);extern int scsi_maybe_unblock_host (struct scsi_device *sdev);extern void scsi_device_unbusy (struct scsi_device *sdev,struct scsi_cmnd *cmd);extern void scsi_queue_insert (struct scsi_cmnd *cmd,int reason);
drivers/scsi/scsi_scan.c +0 -1
@@ -236,7 +236,6 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget, sdev->sdev_state =SDEV_CREATED ;INIT_LIST_HEAD (&sdev->siblings);INIT_LIST_HEAD (&sdev->same_target_siblings); -INIT_LIST_HEAD (&sdev->cmd_list);INIT_LIST_HEAD (&sdev->starved_entry);INIT_LIST_HEAD (&sdev->event_list);spin_lock_init (&sdev->list_lock);
include/scsi/scsi_cmnd.h +0 -1
@@ -159,7 +159,6 @@ static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)return *(struct scsi_driver **)cmd->request->rq_disk->private_data; } -extern void scsi_put_command (struct scsi_cmnd *);extern void scsi_finish_command (struct scsi_cmnd *cmd); extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
include/scsi/scsi_device.h +0 -1
@@ -110,7 +110,6 @@ struct scsi_device {atomic_t device_blocked;/* Device returned QUEUE_FULL. */ spinlock_t list_lock; -struct list_head cmd_list;/* queue of in use SCSI Command structures */ struct list_head starved_entry;unsigned short queue_depth;/* How deep of a queue we want */ unsigned short max_queue_depth;/* max queue depth */
include/scsi/scsi_host.h +0 -2
@@ -627,8 +627,6 @@ struct Scsi_Host {/* The controller does not support WRITE SAME */ unsigned no_write_same:1; - unsigned use_cmd_list:1; -/* Host responded with short (<36 bytes) INQUIRY result */ unsigned short_inquiry:1;
Signature · 1 line
2.16.4