diff mbox series

[02/13] scsi: add scsi_host_complete_all_commands() helper

Message ID 20200213140422.128382-3-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 a helper scsi_host_complete_all_commands() to terminate all outstanding
commands on a scsi host.

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

Comments

Christoph Hellwig Feb. 26, 2020, 5:39 p.m. UTC | #1
On Thu, Feb 13, 2020 at 03:04:11PM +0100, Hannes Reinecke wrote:
>  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);

This adds an > 80 char line.  And externs on function declarations in
headers are never needed anyway.
Hannes Reinecke Feb. 26, 2020, 10:26 p.m. UTC | #2
On 2/26/20 6:39 PM, Christoph Hellwig wrote:
> On Thu, Feb 13, 2020 at 03:04:11PM +0100, Hannes Reinecke wrote:
>>   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);
> 
> This adds an > 80 char line.  And externs on function declarations in
> headers are never needed anyway.
> 
Ok, will be cleaning it up.

Cheers,

Hannes
Hannes Reinecke Feb. 26, 2020, 10:58 p.m. UTC | #3
On 2/26/20 6:39 PM, Christoph Hellwig wrote:
> On Thu, Feb 13, 2020 at 03:04:11PM +0100, Hannes Reinecke wrote:
>>   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);
> 
> This adds an > 80 char line.  And externs on function declarations in
> headers are never needed anyway.
> 
As for the "extern": I'm just following what all the other function 
declarations in the header file do.

If your argument is valid it would apply to all declarations in this 
file, not just this one.
And that would be a separate patch.

Cheers,

Hannes
diff mbox series

Patch

diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 1d669e47b692..00ae9d43ce9f 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -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);
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 7a97fb8104cf..d11a0a030dd3 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -732,6 +732,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)