[v4,06/10] scsi: export scsi_mq_uninit_cmnd
diff mbox series

Message ID 20200403101250.33245-7-johannes.thumshirn@wdc.com
State New
Headers show
Series
  • Introduce Zone Append for writing to zoned block devices
Related show

Commit Message

Johannes Thumshirn April 3, 2020, 10:12 a.m. UTC
scsi_mq_uninit_cmnd is used to free the sg_tables, uninitialize the
command and delete it from the command list.

Export this function so it can be used from modular code to free the
memory allocated by scsi_init_io() if the caller of scsi_init_io() needs
to do error recovery.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
 drivers/scsi/scsi_lib.c  | 9 ++++++---
 include/scsi/scsi_cmnd.h | 1 +
 2 files changed, 7 insertions(+), 3 deletions(-)

Comments

Christoph Hellwig April 7, 2020, 5 p.m. UTC | #1
On Fri, Apr 03, 2020 at 07:12:46PM +0900, Johannes Thumshirn wrote:
> scsi_mq_uninit_cmnd is used to free the sg_tables, uninitialize the
> command and delete it from the command list.
> 
> Export this function so it can be used from modular code to free the
> memory allocated by scsi_init_io() if the caller of scsi_init_io() needs
> to do error recovery.

Hmm.  scsi_mq_uninit_cmnd does three things:

 - calls ->uninit_command, but that is something the driver can
   trivially do itself.
 - scsi_mq_free_sgtables - yes, this would need to be done by the driver
   and actually is what undoes scsi_init_io.  I think you want to export
   this instead (and remove the _mq in the name while you are at it)
 - scsi_del_cmd_from_list - this undoes scsi_add_cmd_to_list, which
   is not related to what the upper level driver does
Johannes Thumshirn April 8, 2020, 11:32 a.m. UTC | #2
On 07/04/2020 19:00, Christoph Hellwig wrote:
>   - scsi_mq_free_sgtables - yes, this would need to be done by the driver
>     and actually is what undoes scsi_init_io.  I think you want to export
>     this instead (and remove the _mq in the name while you are at it)

OK, I was afraid to expose too much internals if I export 
scsi_mq_free_sgtables() but, sure that's a trivial change.
Christoph Hellwig April 8, 2020, 3:59 p.m. UTC | #3
On Wed, Apr 08, 2020 at 11:32:30AM +0000, Johannes Thumshirn wrote:
> On 07/04/2020 19:00, Christoph Hellwig wrote:
> >   - scsi_mq_free_sgtables - yes, this would need to be done by the driver
> >     and actually is what undoes scsi_init_io.  I think you want to export
> >     this instead (and remove the _mq in the name while you are at it)
> 
> OK, I was afraid to expose too much internals if I export 
> scsi_mq_free_sgtables() but, sure that's a trivial change.

Well, it mirrors scsi_init_io, so if we want to undo scsi_init_io
it seems to be the right export.

Patch
diff mbox series

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index ea327f320b7f..4646575a89d6 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -57,8 +57,6 @@  static struct kmem_cache *scsi_sense_cache;
 static struct kmem_cache *scsi_sense_isadma_cache;
 static DEFINE_MUTEX(scsi_sense_cache_mutex);
 
-static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd);
-
 static inline struct kmem_cache *
 scsi_select_sense_cache(bool unchecked_isa_dma)
 {
@@ -558,12 +556,17 @@  static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd)
 				SCSI_INLINE_PROT_SG_CNT);
 }
 
-static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd)
+/**
+ * scsi_mq_uninit_cmd - uninitialize a SCSI command
+ * @cmd: the command to free
+ */
+void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd)
 {
 	scsi_mq_free_sgtables(cmd);
 	scsi_uninit_cmd(cmd);
 	scsi_del_cmd_from_list(cmd);
 }
+EXPORT_SYMBOL_GPL(scsi_mq_uninit_cmd);
 
 /* Returns false when no more bytes to process, true if there are more */
 static bool scsi_end_request(struct request *req, blk_status_t error,
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index a2849bb9cd19..65ff625db38b 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -167,6 +167,7 @@  extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
 extern void scsi_kunmap_atomic_sg(void *virt);
 
 extern blk_status_t scsi_init_io(struct scsi_cmnd *cmd);
+extern void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd);
 
 #ifdef CONFIG_SCSI_DMA
 extern int scsi_dma_map(struct scsi_cmnd *cmd);