diff options
author | Christoph Hellwig <hch@lst.de> | 2011-09-13 17:08:32 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2011-10-23 23:20:33 -0400 |
commit | d3df7825aed2e69e12732f9e32ef9093b01302d8 (patch) | |
tree | 582bb19c5eb961945beeae347000c6c4a8d7b896 /drivers | |
parent | 2dbc43d256c5371ebc294e3534620663eb80a5ce (diff) |
target: simplify transport_generic_remove
Instead of duplicating the code from transport_release_fe_cmd re-use it by
allowing transport_release_fe_cmd to return wether it actually freed the
command or not. Also rename transport_release_fe_cmd to transport_put_cmd
and add a kerneldoc comment for it to make the use case more obvious.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/target/target_core_transport.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 49df0971a37f..bee923fd5750 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c | |||
@@ -88,7 +88,7 @@ static u32 transport_allocate_tasks(struct se_cmd *cmd, | |||
88 | static int transport_generic_get_mem(struct se_cmd *cmd); | 88 | static int transport_generic_get_mem(struct se_cmd *cmd); |
89 | static int transport_generic_remove(struct se_cmd *cmd, | 89 | static int transport_generic_remove(struct se_cmd *cmd, |
90 | int session_reinstatement); | 90 | int session_reinstatement); |
91 | static void transport_release_fe_cmd(struct se_cmd *cmd); | 91 | static bool transport_put_cmd(struct se_cmd *cmd); |
92 | static void transport_remove_cmd_from_queue(struct se_cmd *cmd, | 92 | static void transport_remove_cmd_from_queue(struct se_cmd *cmd, |
93 | struct se_queue_obj *qobj); | 93 | struct se_queue_obj *qobj); |
94 | static int transport_set_sense_codes(struct se_cmd *cmd, u8 asc, u8 ascq); | 94 | static int transport_set_sense_codes(struct se_cmd *cmd, u8 asc, u8 ascq); |
@@ -1074,7 +1074,7 @@ static void transport_release_all_cmds(struct se_device *dev) | |||
1074 | cmd->se_tfo->get_task_tag(cmd), | 1074 | cmd->se_tfo->get_task_tag(cmd), |
1075 | cmd->se_tfo->get_cmd_state(cmd), t_state); | 1075 | cmd->se_tfo->get_cmd_state(cmd), t_state); |
1076 | 1076 | ||
1077 | transport_release_fe_cmd(cmd); | 1077 | transport_put_cmd(cmd); |
1078 | bug_out = 1; | 1078 | bug_out = 1; |
1079 | 1079 | ||
1080 | spin_lock_irqsave(&dev->dev_queue_obj.cmd_queue_lock, flags); | 1080 | spin_lock_irqsave(&dev->dev_queue_obj.cmd_queue_lock, flags); |
@@ -3762,12 +3762,18 @@ static inline int transport_dec_and_check(struct se_cmd *cmd) | |||
3762 | return 0; | 3762 | return 0; |
3763 | } | 3763 | } |
3764 | 3764 | ||
3765 | static void transport_release_fe_cmd(struct se_cmd *cmd) | 3765 | /** |
3766 | * transport_put_cmd - release a reference to a command | ||
3767 | * @cmd: command to release | ||
3768 | * | ||
3769 | * This routine releases our reference to the command and frees it if possible. | ||
3770 | */ | ||
3771 | static bool transport_put_cmd(struct se_cmd *cmd) | ||
3766 | { | 3772 | { |
3767 | unsigned long flags; | 3773 | unsigned long flags; |
3768 | 3774 | ||
3769 | if (transport_dec_and_check(cmd)) | 3775 | if (transport_dec_and_check(cmd)) |
3770 | return; | 3776 | return false; |
3771 | 3777 | ||
3772 | spin_lock_irqsave(&cmd->t_state_lock, flags); | 3778 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
3773 | if (!atomic_read(&cmd->transport_dev_active)) { | 3779 | if (!atomic_read(&cmd->transport_dev_active)) { |
@@ -3779,9 +3785,12 @@ static void transport_release_fe_cmd(struct se_cmd *cmd) | |||
3779 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); | 3785 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
3780 | 3786 | ||
3781 | transport_release_tasks(cmd); | 3787 | transport_release_tasks(cmd); |
3788 | return true; | ||
3789 | |||
3782 | free_pages: | 3790 | free_pages: |
3783 | transport_free_pages(cmd); | 3791 | transport_free_pages(cmd); |
3784 | transport_release_cmd(cmd); | 3792 | transport_release_cmd(cmd); |
3793 | return true; | ||
3785 | } | 3794 | } |
3786 | 3795 | ||
3787 | static int | 3796 | static int |
@@ -3789,7 +3798,7 @@ transport_generic_remove(struct se_cmd *cmd, int session_reinstatement) | |||
3789 | { | 3798 | { |
3790 | unsigned long flags; | 3799 | unsigned long flags; |
3791 | 3800 | ||
3792 | if (transport_dec_and_check(cmd)) { | 3801 | if (!transport_put_cmd(cmd)) { |
3793 | if (session_reinstatement) { | 3802 | if (session_reinstatement) { |
3794 | spin_lock_irqsave(&cmd->t_state_lock, flags); | 3803 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
3795 | transport_all_task_dev_remove_state(cmd); | 3804 | transport_all_task_dev_remove_state(cmd); |
@@ -3799,20 +3808,6 @@ transport_generic_remove(struct se_cmd *cmd, int session_reinstatement) | |||
3799 | return 1; | 3808 | return 1; |
3800 | } | 3809 | } |
3801 | 3810 | ||
3802 | spin_lock_irqsave(&cmd->t_state_lock, flags); | ||
3803 | if (!atomic_read(&cmd->transport_dev_active)) { | ||
3804 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); | ||
3805 | goto free_pages; | ||
3806 | } | ||
3807 | atomic_set(&cmd->transport_dev_active, 0); | ||
3808 | transport_all_task_dev_remove_state(cmd); | ||
3809 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); | ||
3810 | |||
3811 | transport_release_tasks(cmd); | ||
3812 | |||
3813 | free_pages: | ||
3814 | transport_free_pages(cmd); | ||
3815 | transport_release_cmd(cmd); | ||
3816 | return 0; | 3811 | return 0; |
3817 | } | 3812 | } |
3818 | 3813 | ||