Skip to content

Commit

Permalink
scsi: core: add scsi_host_busy_iter()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Hannes Reinecke authored and Martin K. Petersen committed Feb 29, 2020
1 parent 3d3ca53 commit dcece99
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions drivers/scsi/hosts.c
Original file line number Diff line number Diff line change
@@ -678,3 +678,40 @@ 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 {
bool (*fn)(struct scsi_cmnd *, void *, bool);
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
*
* If locking against concurrent command completions is required
* ithas to be provided by the caller
**/
void scsi_host_busy_iter(struct Scsi_Host *shost,
bool (*fn)(struct scsi_cmnd *, void *, bool),
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);
3 changes: 3 additions & 0 deletions include/scsi/scsi_host.h
Original file line number Diff line number Diff line change
@@ -761,6 +761,9 @@ 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);

void scsi_host_busy_iter(struct Scsi_Host *,
bool (*fn)(struct scsi_cmnd *, void *, bool), void *priv);

struct class_container;

/*

0 comments on commit dcece99

Please sign in to comment.