diff options
author | Nicholas Bellinger <nab@linux-iscsi.org> | 2011-11-03 00:52:08 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2011-11-04 03:50:26 -0400 |
commit | a17f091d1a7c570804cfc2c77701634da88f8ecf (patch) | |
tree | 50884063148c31cb5ee7b9a3f13bcc41f585cb92 /drivers | |
parent | 2235007c4d3245c0eca5e49497aafe5a111c00fb (diff) |
target: Add generic active I/O shutdown logic
This patch adds the initial pieces of generic active I/O shutdown logic.
This is intended to be a 'opt-in' feature for fabric modules that
includes the following functions to provide a mechinism for fabric
modules to track se_cmd via se_session->sess_cmd_list:
*) target_get_sess_cmd() - Add se_cmd to sess->sess_cmd_list, called
from fabric module incoming I/O path.
*) target_put_sess_cmd() - Check for completion or drop se_cmd from
->sess_cmd_list
*) target_splice_sess_cmd_list() - Splice active I/O list from
->sess_cmd_list to ->sess_wait_list, can called with HW fabric
lock held.
*) target_wait_for_sess_cmds() - Walk ->sess_wait_list waiting on
individual ->cmd_wait_comp. Optional transport_wait_for_tasks()
call.
target_splice_sess_cmd_list() is allowed to be called under HW fabric
lock, and performs the splice into se_sess->sess_wait_list and set
se_cmd->cmd_wait_set. Then target_wait_for_sess_cmds() walks the list
waiting for individual target_put_sess_cmd() fabric callbacks to
complete.
It also adds TFO->check_release_cmd() to split the completion and memory
release calls, where a fabric module uses target_put_sess_cmd() to check
for I/O completion during session shutdown. This is currently pushed out
into fabric modules as current fabric code may sleep here waiting for
TFO->check_stop_free() to complete in main response path, and because
target_wait_for_sess_cmds() calling TFO->release_cmd() to free fabric
descriptor memory directly.
Cc: Christoph Hellwig <hch@lst.de>
Cc: Roland Dreier <roland@purestorage.com>
Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/target/target_core_transport.c | 132 |
1 files changed, 127 insertions, 5 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 81bc355be317..e84b26ffb17b 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c | |||
@@ -268,6 +268,9 @@ struct se_session *transport_init_session(void) | |||
268 | } | 268 | } |
269 | INIT_LIST_HEAD(&se_sess->sess_list); | 269 | INIT_LIST_HEAD(&se_sess->sess_list); |
270 | INIT_LIST_HEAD(&se_sess->sess_acl_list); | 270 | INIT_LIST_HEAD(&se_sess->sess_acl_list); |
271 | INIT_LIST_HEAD(&se_sess->sess_cmd_list); | ||
272 | INIT_LIST_HEAD(&se_sess->sess_wait_list); | ||
273 | spin_lock_init(&se_sess->sess_cmd_lock); | ||
271 | 274 | ||
272 | return se_sess; | 275 | return se_sess; |
273 | } | 276 | } |
@@ -1505,11 +1508,12 @@ void transport_init_se_cmd( | |||
1505 | INIT_LIST_HEAD(&cmd->se_ordered_node); | 1508 | INIT_LIST_HEAD(&cmd->se_ordered_node); |
1506 | INIT_LIST_HEAD(&cmd->se_qf_node); | 1509 | INIT_LIST_HEAD(&cmd->se_qf_node); |
1507 | INIT_LIST_HEAD(&cmd->se_queue_node); | 1510 | INIT_LIST_HEAD(&cmd->se_queue_node); |
1508 | 1511 | INIT_LIST_HEAD(&cmd->se_cmd_list); | |
1509 | INIT_LIST_HEAD(&cmd->t_task_list); | 1512 | INIT_LIST_HEAD(&cmd->t_task_list); |
1510 | init_completion(&cmd->transport_lun_fe_stop_comp); | 1513 | init_completion(&cmd->transport_lun_fe_stop_comp); |
1511 | init_completion(&cmd->transport_lun_stop_comp); | 1514 | init_completion(&cmd->transport_lun_stop_comp); |
1512 | init_completion(&cmd->t_transport_stop_comp); | 1515 | init_completion(&cmd->t_transport_stop_comp); |
1516 | init_completion(&cmd->cmd_wait_comp); | ||
1513 | spin_lock_init(&cmd->t_state_lock); | 1517 | spin_lock_init(&cmd->t_state_lock); |
1514 | atomic_set(&cmd->transport_dev_active, 1); | 1518 | atomic_set(&cmd->transport_dev_active, 1); |
1515 | 1519 | ||
@@ -3950,6 +3954,14 @@ void transport_release_cmd(struct se_cmd *cmd) | |||
3950 | core_tmr_release_req(cmd->se_tmr_req); | 3954 | core_tmr_release_req(cmd->se_tmr_req); |
3951 | if (cmd->t_task_cdb != cmd->__t_task_cdb) | 3955 | if (cmd->t_task_cdb != cmd->__t_task_cdb) |
3952 | kfree(cmd->t_task_cdb); | 3956 | kfree(cmd->t_task_cdb); |
3957 | /* | ||
3958 | * Check if target_wait_for_sess_cmds() is expecting to | ||
3959 | * release se_cmd directly here.. | ||
3960 | */ | ||
3961 | if (cmd->check_release != 0 && cmd->se_tfo->check_release_cmd) | ||
3962 | if (cmd->se_tfo->check_release_cmd(cmd) != 0) | ||
3963 | return; | ||
3964 | |||
3953 | cmd->se_tfo->release_cmd(cmd); | 3965 | cmd->se_tfo->release_cmd(cmd); |
3954 | } | 3966 | } |
3955 | EXPORT_SYMBOL(transport_release_cmd); | 3967 | EXPORT_SYMBOL(transport_release_cmd); |
@@ -3977,6 +3989,114 @@ void transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) | |||
3977 | } | 3989 | } |
3978 | EXPORT_SYMBOL(transport_generic_free_cmd); | 3990 | EXPORT_SYMBOL(transport_generic_free_cmd); |
3979 | 3991 | ||
3992 | /* target_get_sess_cmd - Add command to active ->sess_cmd_list | ||
3993 | * @se_sess: session to reference | ||
3994 | * @se_cmd: command descriptor to add | ||
3995 | */ | ||
3996 | void target_get_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd) | ||
3997 | { | ||
3998 | unsigned long flags; | ||
3999 | |||
4000 | spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); | ||
4001 | list_add_tail(&se_cmd->se_cmd_list, &se_sess->sess_cmd_list); | ||
4002 | se_cmd->check_release = 1; | ||
4003 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); | ||
4004 | } | ||
4005 | EXPORT_SYMBOL(target_get_sess_cmd); | ||
4006 | |||
4007 | /* target_put_sess_cmd - Check for active I/O shutdown or list delete | ||
4008 | * @se_sess: session to reference | ||
4009 | * @se_cmd: command descriptor to drop | ||
4010 | */ | ||
4011 | int target_put_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd) | ||
4012 | { | ||
4013 | unsigned long flags; | ||
4014 | |||
4015 | spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); | ||
4016 | if (list_empty(&se_cmd->se_cmd_list)) { | ||
4017 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); | ||
4018 | WARN_ON(1); | ||
4019 | return 0; | ||
4020 | } | ||
4021 | |||
4022 | if (se_sess->sess_tearing_down && se_cmd->cmd_wait_set) { | ||
4023 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); | ||
4024 | complete(&se_cmd->cmd_wait_comp); | ||
4025 | return 1; | ||
4026 | } | ||
4027 | list_del(&se_cmd->se_cmd_list); | ||
4028 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); | ||
4029 | |||
4030 | return 0; | ||
4031 | } | ||
4032 | EXPORT_SYMBOL(target_put_sess_cmd); | ||
4033 | |||
4034 | /* target_splice_sess_cmd_list - Split active cmds into sess_wait_list | ||
4035 | * @se_sess: session to split | ||
4036 | */ | ||
4037 | void target_splice_sess_cmd_list(struct se_session *se_sess) | ||
4038 | { | ||
4039 | struct se_cmd *se_cmd; | ||
4040 | unsigned long flags; | ||
4041 | |||
4042 | WARN_ON(!list_empty(&se_sess->sess_wait_list)); | ||
4043 | INIT_LIST_HEAD(&se_sess->sess_wait_list); | ||
4044 | |||
4045 | spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); | ||
4046 | se_sess->sess_tearing_down = 1; | ||
4047 | |||
4048 | list_splice_init(&se_sess->sess_cmd_list, &se_sess->sess_wait_list); | ||
4049 | |||
4050 | list_for_each_entry(se_cmd, &se_sess->sess_wait_list, se_cmd_list) | ||
4051 | se_cmd->cmd_wait_set = 1; | ||
4052 | |||
4053 | spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); | ||
4054 | } | ||
4055 | EXPORT_SYMBOL(target_splice_sess_cmd_list); | ||
4056 | |||
4057 | /* target_wait_for_sess_cmds - Wait for outstanding descriptors | ||
4058 | * @se_sess: session to wait for active I/O | ||
4059 | * @wait_for_tasks: Make extra transport_wait_for_tasks call | ||
4060 | */ | ||
4061 | void target_wait_for_sess_cmds( | ||
4062 | struct se_session *se_sess, | ||
4063 | int wait_for_tasks) | ||
4064 | { | ||
4065 | struct se_cmd *se_cmd, *tmp_cmd; | ||
4066 | bool rc = false; | ||
4067 | |||
4068 | list_for_each_entry_safe(se_cmd, tmp_cmd, | ||
4069 | &se_sess->sess_wait_list, se_cmd_list) { | ||
4070 | list_del(&se_cmd->se_cmd_list); | ||
4071 | |||
4072 | pr_debug("Waiting for se_cmd: %p t_state: %d, fabric state:" | ||
4073 | " %d\n", se_cmd, se_cmd->t_state, | ||
4074 | se_cmd->se_tfo->get_cmd_state(se_cmd)); | ||
4075 | |||
4076 | if (wait_for_tasks) { | ||
4077 | pr_debug("Calling transport_wait_for_tasks se_cmd: %p t_state: %d," | ||
4078 | " fabric state: %d\n", se_cmd, se_cmd->t_state, | ||
4079 | se_cmd->se_tfo->get_cmd_state(se_cmd)); | ||
4080 | |||
4081 | rc = transport_wait_for_tasks(se_cmd); | ||
4082 | |||
4083 | pr_debug("After transport_wait_for_tasks se_cmd: %p t_state: %d," | ||
4084 | " fabric state: %d\n", se_cmd, se_cmd->t_state, | ||
4085 | se_cmd->se_tfo->get_cmd_state(se_cmd)); | ||
4086 | } | ||
4087 | |||
4088 | if (!rc) { | ||
4089 | wait_for_completion(&se_cmd->cmd_wait_comp); | ||
4090 | pr_debug("After cmd_wait_comp: se_cmd: %p t_state: %d" | ||
4091 | " fabric state: %d\n", se_cmd, se_cmd->t_state, | ||
4092 | se_cmd->se_tfo->get_cmd_state(se_cmd)); | ||
4093 | } | ||
4094 | |||
4095 | se_cmd->se_tfo->release_cmd(se_cmd); | ||
4096 | } | ||
4097 | } | ||
4098 | EXPORT_SYMBOL(target_wait_for_sess_cmds); | ||
4099 | |||
3980 | /* transport_lun_wait_for_tasks(): | 4100 | /* transport_lun_wait_for_tasks(): |
3981 | * | 4101 | * |
3982 | * Called from ConfigFS context to stop the passed struct se_cmd to allow | 4102 | * Called from ConfigFS context to stop the passed struct se_cmd to allow |
@@ -4153,14 +4273,14 @@ int transport_clear_lun_from_sessions(struct se_lun *lun) | |||
4153 | * Called from frontend fabric context to wait for storage engine | 4273 | * Called from frontend fabric context to wait for storage engine |
4154 | * to pause and/or release frontend generated struct se_cmd. | 4274 | * to pause and/or release frontend generated struct se_cmd. |
4155 | */ | 4275 | */ |
4156 | void transport_wait_for_tasks(struct se_cmd *cmd) | 4276 | bool transport_wait_for_tasks(struct se_cmd *cmd) |
4157 | { | 4277 | { |
4158 | unsigned long flags; | 4278 | unsigned long flags; |
4159 | 4279 | ||
4160 | spin_lock_irqsave(&cmd->t_state_lock, flags); | 4280 | spin_lock_irqsave(&cmd->t_state_lock, flags); |
4161 | if (!(cmd->se_cmd_flags & SCF_SE_LUN_CMD) && !(cmd->se_tmr_req)) { | 4281 | if (!(cmd->se_cmd_flags & SCF_SE_LUN_CMD) && !(cmd->se_tmr_req)) { |
4162 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); | 4282 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
4163 | return; | 4283 | return false; |
4164 | } | 4284 | } |
4165 | /* | 4285 | /* |
4166 | * Only perform a possible wait_for_tasks if SCF_SUPPORTED_SAM_OPCODE | 4286 | * Only perform a possible wait_for_tasks if SCF_SUPPORTED_SAM_OPCODE |
@@ -4168,7 +4288,7 @@ void transport_wait_for_tasks(struct se_cmd *cmd) | |||
4168 | */ | 4288 | */ |
4169 | if (!(cmd->se_cmd_flags & SCF_SUPPORTED_SAM_OPCODE) && !cmd->se_tmr_req) { | 4289 | if (!(cmd->se_cmd_flags & SCF_SUPPORTED_SAM_OPCODE) && !cmd->se_tmr_req) { |
4170 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); | 4290 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
4171 | return; | 4291 | return false; |
4172 | } | 4292 | } |
4173 | /* | 4293 | /* |
4174 | * If we are already stopped due to an external event (ie: LUN shutdown) | 4294 | * If we are already stopped due to an external event (ie: LUN shutdown) |
@@ -4211,7 +4331,7 @@ void transport_wait_for_tasks(struct se_cmd *cmd) | |||
4211 | if (!atomic_read(&cmd->t_transport_active) || | 4331 | if (!atomic_read(&cmd->t_transport_active) || |
4212 | atomic_read(&cmd->t_transport_aborted)) { | 4332 | atomic_read(&cmd->t_transport_aborted)) { |
4213 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); | 4333 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
4214 | return; | 4334 | return false; |
4215 | } | 4335 | } |
4216 | 4336 | ||
4217 | atomic_set(&cmd->t_transport_stop, 1); | 4337 | atomic_set(&cmd->t_transport_stop, 1); |
@@ -4236,6 +4356,8 @@ void transport_wait_for_tasks(struct se_cmd *cmd) | |||
4236 | cmd->se_tfo->get_task_tag(cmd)); | 4356 | cmd->se_tfo->get_task_tag(cmd)); |
4237 | 4357 | ||
4238 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); | 4358 | spin_unlock_irqrestore(&cmd->t_state_lock, flags); |
4359 | |||
4360 | return true; | ||
4239 | } | 4361 | } |
4240 | EXPORT_SYMBOL(transport_wait_for_tasks); | 4362 | EXPORT_SYMBOL(transport_wait_for_tasks); |
4241 | 4363 | ||