Commit 88dd9e26 authored by Nicholas Bellinger's avatar Nicholas Bellinger

target: Make TFO->check_stop_free return free status

This patch converts target_core_fabric_ops->check_stop_free() usage in
transport_cmd_check_stop() and associated fabric module usage to
return '1' when the passed se_cmd has been released directly within
->check_stop_free(), or return '0' when the passed se_cmd has not
been released.

This addresses an issue where transport_cmd_finish_abort() ->
transport_cmd_check_stop_to_fabric() was leaking descriptors during
LUN_RESET for modules using ->check_stop_free(), but not directly
releasing se_cmd in all cases.

Cc: stable@kernel.org
Signed-off-by: default avatarNicholas Bellinger <nab@risingtidesystems.com>
parent 5a4c8666
...@@ -205,7 +205,7 @@ static int tcm_loop_new_cmd_map(struct se_cmd *se_cmd) ...@@ -205,7 +205,7 @@ static int tcm_loop_new_cmd_map(struct se_cmd *se_cmd)
/* /*
* Called from struct target_core_fabric_ops->check_stop_free() * Called from struct target_core_fabric_ops->check_stop_free()
*/ */
static void tcm_loop_check_stop_free(struct se_cmd *se_cmd) static int tcm_loop_check_stop_free(struct se_cmd *se_cmd)
{ {
/* /*
* Do not release struct se_cmd's containing a valid TMR * Do not release struct se_cmd's containing a valid TMR
...@@ -213,12 +213,13 @@ static void tcm_loop_check_stop_free(struct se_cmd *se_cmd) ...@@ -213,12 +213,13 @@ static void tcm_loop_check_stop_free(struct se_cmd *se_cmd)
* with transport_generic_free_cmd(). * with transport_generic_free_cmd().
*/ */
if (se_cmd->se_tmr_req) if (se_cmd->se_tmr_req)
return; return 0;
/* /*
* Release the struct se_cmd, which will make a callback to release * Release the struct se_cmd, which will make a callback to release
* struct tcm_loop_cmd * in tcm_loop_deallocate_core_cmd() * struct tcm_loop_cmd * in tcm_loop_deallocate_core_cmd()
*/ */
transport_generic_free_cmd(se_cmd, 0); transport_generic_free_cmd(se_cmd, 0);
return 1;
} }
static void tcm_loop_release_cmd(struct se_cmd *se_cmd) static void tcm_loop_release_cmd(struct se_cmd *se_cmd)
......
...@@ -514,13 +514,16 @@ static int transport_cmd_check_stop( ...@@ -514,13 +514,16 @@ static int transport_cmd_check_stop(
* Some fabric modules like tcm_loop can release * Some fabric modules like tcm_loop can release
* their internally allocated I/O reference now and * their internally allocated I/O reference now and
* struct se_cmd now. * struct se_cmd now.
*
* Fabric modules are expected to return '1' here if the
* se_cmd being passed is released at this point,
* or zero if not being released.
*/ */
if (cmd->se_tfo->check_stop_free != NULL) { if (cmd->se_tfo->check_stop_free != NULL) {
spin_unlock_irqrestore( spin_unlock_irqrestore(
&cmd->t_state_lock, flags); &cmd->t_state_lock, flags);
cmd->se_tfo->check_stop_free(cmd); return cmd->se_tfo->check_stop_free(cmd);
return 1;
} }
} }
spin_unlock_irqrestore(&cmd->t_state_lock, flags); spin_unlock_irqrestore(&cmd->t_state_lock, flags);
......
...@@ -156,7 +156,7 @@ int ft_lport_notify(struct notifier_block *, unsigned long, void *); ...@@ -156,7 +156,7 @@ int ft_lport_notify(struct notifier_block *, unsigned long, void *);
/* /*
* IO methods. * IO methods.
*/ */
void ft_check_stop_free(struct se_cmd *); int ft_check_stop_free(struct se_cmd *);
void ft_release_cmd(struct se_cmd *); void ft_release_cmd(struct se_cmd *);
int ft_queue_status(struct se_cmd *); int ft_queue_status(struct se_cmd *);
int ft_queue_data_in(struct se_cmd *); int ft_queue_data_in(struct se_cmd *);
......
...@@ -112,9 +112,10 @@ void ft_release_cmd(struct se_cmd *se_cmd) ...@@ -112,9 +112,10 @@ void ft_release_cmd(struct se_cmd *se_cmd)
ft_free_cmd(cmd); ft_free_cmd(cmd);
} }
void ft_check_stop_free(struct se_cmd *se_cmd) int ft_check_stop_free(struct se_cmd *se_cmd)
{ {
transport_generic_free_cmd(se_cmd, 0); transport_generic_free_cmd(se_cmd, 0);
return 1;
} }
/* /*
......
...@@ -46,9 +46,12 @@ struct target_core_fabric_ops { ...@@ -46,9 +46,12 @@ struct target_core_fabric_ops {
int (*new_cmd_map)(struct se_cmd *); int (*new_cmd_map)(struct se_cmd *);
/* /*
* Optional to release struct se_cmd and fabric dependent allocated * Optional to release struct se_cmd and fabric dependent allocated
* I/O descriptor in transport_cmd_check_stop() * I/O descriptor in transport_cmd_check_stop().
*
* Returning 1 will signal a descriptor has been released.
* Returning 0 will signal a descriptor has not been released.
*/ */
void (*check_stop_free)(struct se_cmd *); int (*check_stop_free)(struct se_cmd *);
void (*release_cmd)(struct se_cmd *); void (*release_cmd)(struct se_cmd *);
/* /*
* Called with spin_lock_bh(struct se_portal_group->session_lock held. * Called with spin_lock_bh(struct se_portal_group->session_lock held.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment