diff mbox series

[10/13] scsi: add scsi_host_busy_iter()

Message ID 20200213140422.128382-11-hare@suse.de (mailing list archive)
State Superseded
Headers show
Series scsi: remove legacy cmd_list implementation | expand

Commit Message

Hannes Reinecke Feb. 13, 2020, 2:04 p.m. UTC
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.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/hosts.c     | 33 +++++++++++++++++++++++++++++++++
 include/scsi/scsi_host.h |  5 +++++
 2 files changed, 38 insertions(+)

Comments

Christoph Hellwig Feb. 26, 2020, 5:45 p.m. UTC | #1
> +/**
> + * 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
> + **/

Can you add the context information from the commit log to the kerneldoc
comment her?

> +typedef bool (scsi_host_busy_iter_fn)(struct scsi_cmnd *, void *, bool);

Is there much of a point in having this typedef?

> +
> +void scsi_host_busy_iter(struct Scsi_Host *,
> +			 scsi_host_busy_iter_fn *fn, void *priv);

Any reason to spell out to argument names, but not the third one?
Hannes Reinecke Feb. 26, 2020, 10:28 p.m. UTC | #2
On 2/26/20 6:45 PM, Christoph Hellwig wrote:
>> +/**
>> + * 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
>> + **/
> 
> Can you add the context information from the commit log to the kerneldoc
> comment her?
> 
Yes.

>> +typedef bool (scsi_host_busy_iter_fn)(struct scsi_cmnd *, void *, bool);
> 
> Is there much of a point in having this typedef?
> 
Hmm. Idea was to save typing, but as it's being used only once I'll drop
it for the next round.

>> +
>> +void scsi_host_busy_iter(struct Scsi_Host *,
>> +			 scsi_host_busy_iter_fn *fn, void *priv);
> 
> Any reason to spell out to argument names, but not the third one?
> 
Probably not. Will be fixing it up.

Cheers,

Hannes
diff mbox series

Patch

diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 00ae9d43ce9f..91987b9fb45f 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -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);
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index a230e2c0e11f..f5300ad887c4 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -760,6 +760,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;
 
 /*