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

scsi: core: add scsi_host_busy_iter()

Add 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.

Link: https://lore.kernel.org/r/20200228075318.91255-11-hare@suse.de
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
dcece99e 3d3ca53b

+40
+37
drivers/scsi/hosts.c
··· 678 678 &status); 679 679 } 680 680 EXPORT_SYMBOL_GPL(scsi_host_complete_all_commands); 681 + 682 + struct scsi_host_busy_iter_data { 683 + bool (*fn)(struct scsi_cmnd *, void *, bool); 684 + void *priv; 685 + }; 686 + 687 + static bool __scsi_host_busy_iter_fn(struct request *req, void *priv, 688 + bool reserved) 689 + { 690 + struct scsi_host_busy_iter_data *iter_data = priv; 691 + struct scsi_cmnd *sc = blk_mq_rq_to_pdu(req); 692 + 693 + return iter_data->fn(sc, iter_data->priv, reserved); 694 + } 695 + 696 + /** 697 + * scsi_host_busy_iter - Iterate over all busy commands 698 + * @shost: Pointer to Scsi_Host. 699 + * @fn: Function to call on each busy command 700 + * @priv: Data pointer passed to @fn 701 + * 702 + * If locking against concurrent command completions is required 703 + * ithas to be provided by the caller 704 + **/ 705 + void scsi_host_busy_iter(struct Scsi_Host *shost, 706 + bool (*fn)(struct scsi_cmnd *, void *, bool), 707 + void *priv) 708 + { 709 + struct scsi_host_busy_iter_data iter_data = { 710 + .fn = fn, 711 + .priv = priv, 712 + }; 713 + 714 + blk_mq_tagset_busy_iter(&shost->tag_set, __scsi_host_busy_iter_fn, 715 + &iter_data); 716 + } 717 + EXPORT_SYMBOL_GPL(scsi_host_busy_iter);
+3
include/scsi/scsi_host.h
··· 761 761 extern int scsi_host_block(struct Scsi_Host *shost); 762 762 extern int scsi_host_unblock(struct Scsi_Host *shost, int new_state); 763 763 764 + void scsi_host_busy_iter(struct Scsi_Host *, 765 + bool (*fn)(struct scsi_cmnd *, void *, bool), void *priv); 766 + 764 767 struct class_container; 765 768 766 769 /*