Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: aacraid: use scsi_host_busy_iter() to wait for outstanding commands

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.

Link: https://lore.kernel.org/r/20200228075318.91255-12-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Balsundar P < Balsundar.P@microchip.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Hannes Reinecke and committed by
Martin K. Petersen
f4a0c9db dcece99e

+17 -18
+17 -18
drivers/scsi/aacraid/comminit.c
··· 272 272 q->entries = qsize; 273 273 } 274 274 275 + static bool wait_for_io_iter(struct scsi_cmnd *cmd, void *data, bool rsvd) 276 + { 277 + int *active = data; 278 + 279 + if (cmd->SCp.phase == AAC_OWNER_FIRMWARE) 280 + *active = *active + 1; 281 + return true; 282 + } 275 283 static void aac_wait_for_io_completion(struct aac_dev *aac) 276 284 { 277 - unsigned long flagv = 0; 278 - int i = 0; 285 + int i = 0, active; 279 286 280 287 for (i = 60; i; --i) { 281 - struct scsi_device *dev; 282 - struct scsi_cmnd *command; 283 - int active = 0; 284 288 285 - __shost_for_each_device(dev, aac->scsi_host_ptr) { 286 - spin_lock_irqsave(&dev->list_lock, flagv); 287 - list_for_each_entry(command, &dev->cmd_list, list) { 288 - if (command->SCp.phase == AAC_OWNER_FIRMWARE) { 289 - active++; 290 - break; 291 - } 292 - } 293 - spin_unlock_irqrestore(&dev->list_lock, flagv); 294 - if (active) 295 - break; 296 - 297 - } 289 + active = 0; 290 + scsi_host_busy_iter(aac->scsi_host_ptr, 291 + wait_for_io_iter, &active); 298 292 /* 299 293 * We can exit If all the commands are complete 300 294 */ 301 295 if (active == 0) 302 296 break; 297 + dev_info(&aac->pdev->dev, 298 + "Wait for %d commands to complete\n", active); 303 299 ssleep(1); 304 300 } 301 + if (active) 302 + dev_err(&aac->pdev->dev, 303 + "%d outstanding commands during shutdown\n", active); 305 304 } 306 305 307 306 /**