Commit 7d680f3b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Nicholas Bellinger

target: replace various cmd flags with a transport state

Replace various atomic_ts used as flags in struct se_cmd with a single
transport_state bitmap that requires t_state_lock to be held for modifications.

In the target core that assumption generally is true, but some recently added
code in the SRP target had to grow new lock calls.  I can't say I like the way
how it messes with the command state directly, but let's leave that for later.

(Re-add missing ib_srpt.c changes that nab dropped..)
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent b01543df
...@@ -1378,7 +1378,9 @@ static int srpt_abort_cmd(struct srpt_send_ioctx *ioctx) ...@@ -1378,7 +1378,9 @@ static int srpt_abort_cmd(struct srpt_send_ioctx *ioctx)
break; break;
case SRPT_STATE_NEED_DATA: case SRPT_STATE_NEED_DATA:
/* DMA_TO_DEVICE (write) - RDMA read error. */ /* DMA_TO_DEVICE (write) - RDMA read error. */
atomic_set(&ioctx->cmd.transport_lun_stop, 1); spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags);
ioctx->cmd.transport_state |= CMD_T_LUN_STOP;
spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags);
transport_generic_handle_data(&ioctx->cmd); transport_generic_handle_data(&ioctx->cmd);
break; break;
case SRPT_STATE_CMD_RSP_SENT: case SRPT_STATE_CMD_RSP_SENT:
...@@ -1387,7 +1389,9 @@ static int srpt_abort_cmd(struct srpt_send_ioctx *ioctx) ...@@ -1387,7 +1389,9 @@ static int srpt_abort_cmd(struct srpt_send_ioctx *ioctx)
* not been received in time. * not been received in time.
*/ */
srpt_unmap_sg_to_ib_sge(ioctx->ch, ioctx); srpt_unmap_sg_to_ib_sge(ioctx->ch, ioctx);
atomic_set(&ioctx->cmd.transport_lun_stop, 1); spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags);
ioctx->cmd.transport_state |= CMD_T_LUN_STOP;
spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags);
kref_put(&ioctx->kref, srpt_put_send_ioctx_kref); kref_put(&ioctx->kref, srpt_put_send_ioctx_kref);
break; break;
case SRPT_STATE_MGMT_RSP_SENT: case SRPT_STATE_MGMT_RSP_SENT:
...@@ -1494,6 +1498,7 @@ static void srpt_handle_rdma_err_comp(struct srpt_rdma_ch *ch, ...@@ -1494,6 +1498,7 @@ static void srpt_handle_rdma_err_comp(struct srpt_rdma_ch *ch,
{ {
struct se_cmd *cmd; struct se_cmd *cmd;
enum srpt_command_state state; enum srpt_command_state state;
unsigned long flags;
cmd = &ioctx->cmd; cmd = &ioctx->cmd;
state = srpt_get_cmd_state(ioctx); state = srpt_get_cmd_state(ioctx);
...@@ -1513,7 +1518,9 @@ static void srpt_handle_rdma_err_comp(struct srpt_rdma_ch *ch, ...@@ -1513,7 +1518,9 @@ static void srpt_handle_rdma_err_comp(struct srpt_rdma_ch *ch,
__func__, __LINE__, state); __func__, __LINE__, state);
break; break;
case SRPT_RDMA_WRITE_LAST: case SRPT_RDMA_WRITE_LAST:
atomic_set(&ioctx->cmd.transport_lun_stop, 1); spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags);
ioctx->cmd.transport_state |= CMD_T_LUN_STOP;
spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags);
break; break;
default: default:
printk(KERN_ERR "%s[%d]: opcode = %u\n", __func__, printk(KERN_ERR "%s[%d]: opcode = %u\n", __func__,
......
...@@ -1363,7 +1363,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf) ...@@ -1363,7 +1363,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
* outstanding_r2ts reaches zero, go ahead and send the delayed * outstanding_r2ts reaches zero, go ahead and send the delayed
* TASK_ABORTED status. * TASK_ABORTED status.
*/ */
if (atomic_read(&se_cmd->t_transport_aborted) != 0) { if (se_cmd->transport_state & CMD_T_ABORTED) {
if (hdr->flags & ISCSI_FLAG_CMD_FINAL) if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
if (--cmd->outstanding_r2ts < 1) { if (--cmd->outstanding_r2ts < 1) {
iscsit_stop_dataout_timer(cmd); iscsit_stop_dataout_timer(cmd);
......
...@@ -416,7 +416,7 @@ static int iscsit_handle_recovery_datain( ...@@ -416,7 +416,7 @@ static int iscsit_handle_recovery_datain(
struct iscsi_datain_req *dr; struct iscsi_datain_req *dr;
struct se_cmd *se_cmd = &cmd->se_cmd; struct se_cmd *se_cmd = &cmd->se_cmd;
if (!atomic_read(&se_cmd->t_transport_complete)) { if (!(se_cmd->transport_state & CMD_T_COMPLETE)) {
pr_err("Ignoring ITT: 0x%08x Data SNACK\n", pr_err("Ignoring ITT: 0x%08x Data SNACK\n",
cmd->init_task_tag); cmd->init_task_tag);
return 0; return 0;
......
...@@ -250,7 +250,7 @@ static int iscsit_task_reassign_complete_write( ...@@ -250,7 +250,7 @@ static int iscsit_task_reassign_complete_write(
* so if we have received all DataOUT we can safety ignore Initiator. * so if we have received all DataOUT we can safety ignore Initiator.
*/ */
if (cmd->cmd_flags & ICF_GOT_LAST_DATAOUT) { if (cmd->cmd_flags & ICF_GOT_LAST_DATAOUT) {
if (!atomic_read(&cmd->se_cmd.t_transport_sent)) { if (!(cmd->se_cmd.transport_state & CMD_T_SENT)) {
pr_debug("WRITE ITT: 0x%08x: t_state: %d" pr_debug("WRITE ITT: 0x%08x: t_state: %d"
" never sent to transport\n", " never sent to transport\n",
cmd->init_task_tag, cmd->se_cmd.t_state); cmd->init_task_tag, cmd->se_cmd.t_state);
...@@ -314,7 +314,7 @@ static int iscsit_task_reassign_complete_read( ...@@ -314,7 +314,7 @@ static int iscsit_task_reassign_complete_read(
cmd->acked_data_sn = (tmr_req->exp_data_sn - 1); cmd->acked_data_sn = (tmr_req->exp_data_sn - 1);
} }
if (!atomic_read(&cmd->se_cmd.t_transport_sent)) { if (!(cmd->se_cmd.transport_state & CMD_T_SENT)) {
pr_debug("READ ITT: 0x%08x: t_state: %d never sent to" pr_debug("READ ITT: 0x%08x: t_state: %d never sent to"
" transport\n", cmd->init_task_tag, " transport\n", cmd->init_task_tag,
cmd->se_cmd.t_state); cmd->se_cmd.t_state);
...@@ -322,7 +322,7 @@ static int iscsit_task_reassign_complete_read( ...@@ -322,7 +322,7 @@ static int iscsit_task_reassign_complete_read(
return 0; return 0;
} }
if (!atomic_read(&se_cmd->t_transport_complete)) { if (!(se_cmd->transport_state & CMD_T_COMPLETE)) {
pr_err("READ ITT: 0x%08x: t_state: %d, never returned" pr_err("READ ITT: 0x%08x: t_state: %d, never returned"
" from transport\n", cmd->init_task_tag, " from transport\n", cmd->init_task_tag,
cmd->se_cmd.t_state); cmd->se_cmd.t_state);
......
...@@ -150,7 +150,7 @@ static void core_tmr_drain_tmr_list( ...@@ -150,7 +150,7 @@ static void core_tmr_drain_tmr_list(
continue; continue;
spin_lock(&cmd->t_state_lock); spin_lock(&cmd->t_state_lock);
if (!atomic_read(&cmd->t_transport_active)) { if (!(cmd->transport_state & CMD_T_ACTIVE)) {
spin_unlock(&cmd->t_state_lock); spin_unlock(&cmd->t_state_lock);
continue; continue;
} }
...@@ -255,15 +255,15 @@ static void core_tmr_drain_task_list( ...@@ -255,15 +255,15 @@ static void core_tmr_drain_task_list(
cmd->t_task_cdb[0]); cmd->t_task_cdb[0]);
pr_debug("LUN_RESET: ITT[0x%08x] - pr_res_key: 0x%016Lx" pr_debug("LUN_RESET: ITT[0x%08x] - pr_res_key: 0x%016Lx"
" t_task_cdbs: %d t_task_cdbs_left: %d" " t_task_cdbs: %d t_task_cdbs_left: %d"
" t_task_cdbs_sent: %d -- t_transport_active: %d" " t_task_cdbs_sent: %d -- CMD_T_ACTIVE: %d"
" t_transport_stop: %d t_transport_sent: %d\n", " CMD_T_STOP: %d CMD_T_SENT: %d\n",
cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key, cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
cmd->t_task_list_num, cmd->t_task_list_num,
atomic_read(&cmd->t_task_cdbs_left), atomic_read(&cmd->t_task_cdbs_left),
atomic_read(&cmd->t_task_cdbs_sent), atomic_read(&cmd->t_task_cdbs_sent),
atomic_read(&cmd->t_transport_active), (cmd->transport_state & CMD_T_ACTIVE) != 0,
atomic_read(&cmd->t_transport_stop), (cmd->transport_state & CMD_T_STOP) != 0,
atomic_read(&cmd->t_transport_sent)); (cmd->transport_state & CMD_T_SENT) != 0);
/* /*
* If the command may be queued onto a workqueue cancel it now. * If the command may be queued onto a workqueue cancel it now.
...@@ -287,19 +287,19 @@ static void core_tmr_drain_task_list( ...@@ -287,19 +287,19 @@ static void core_tmr_drain_task_list(
} }
fe_count = atomic_read(&cmd->t_fe_count); fe_count = atomic_read(&cmd->t_fe_count);
if (atomic_read(&cmd->t_transport_active)) { if (!(cmd->transport_state & CMD_T_ACTIVE)) {
pr_debug("LUN_RESET: got t_transport_active = 1 for" pr_debug("LUN_RESET: got CMD_T_ACTIVE for"
" task: %p, t_fe_count: %d dev: %p\n", task, " task: %p, t_fe_count: %d dev: %p\n", task,
fe_count, dev); fe_count, dev);
atomic_set(&cmd->t_transport_aborted, 1); cmd->transport_state |= CMD_T_ABORTED;
spin_unlock_irqrestore(&cmd->t_state_lock, flags); spin_unlock_irqrestore(&cmd->t_state_lock, flags);
core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count); core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
continue; continue;
} }
pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p," pr_debug("LUN_RESET: Got !CMD_T_ACTIVE for task: %p,"
" t_fe_count: %d dev: %p\n", task, fe_count, dev); " t_fe_count: %d dev: %p\n", task, fe_count, dev);
atomic_set(&cmd->t_transport_aborted, 1); cmd->transport_state |= CMD_T_ABORTED;
spin_unlock_irqrestore(&cmd->t_state_lock, flags); spin_unlock_irqrestore(&cmd->t_state_lock, flags);
core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count); core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
...@@ -339,7 +339,7 @@ static void core_tmr_drain_cmd_list( ...@@ -339,7 +339,7 @@ static void core_tmr_drain_cmd_list(
if (prout_cmd == cmd) if (prout_cmd == cmd)
continue; continue;
atomic_set(&cmd->t_transport_queue_active, 0); cmd->transport_state &= ~CMD_T_QUEUED;
atomic_dec(&qobj->queue_cnt); atomic_dec(&qobj->queue_cnt);
list_move_tail(&cmd->se_queue_node, &drain_cmd_list); list_move_tail(&cmd->se_queue_node, &drain_cmd_list);
} }
......
This diff is collapsed.
...@@ -555,23 +555,24 @@ struct se_cmd { ...@@ -555,23 +555,24 @@ struct se_cmd {
unsigned char *t_task_cdb; unsigned char *t_task_cdb;
unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE]; unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE];
unsigned long long t_task_lba; unsigned long long t_task_lba;
int t_tasks_failed;
u32 t_tasks_sg_chained_no; u32 t_tasks_sg_chained_no;
atomic_t t_fe_count; atomic_t t_fe_count;
atomic_t t_se_count; atomic_t t_se_count;
atomic_t t_task_cdbs_left; atomic_t t_task_cdbs_left;
atomic_t t_task_cdbs_ex_left; atomic_t t_task_cdbs_ex_left;
atomic_t t_task_cdbs_sent; atomic_t t_task_cdbs_sent;
atomic_t t_transport_aborted; unsigned int transport_state;
atomic_t t_transport_active; #define CMD_T_ABORTED (1 << 0)
atomic_t t_transport_complete; #define CMD_T_ACTIVE (1 << 1)
atomic_t t_transport_queue_active; #define CMD_T_COMPLETE (1 << 2)
atomic_t t_transport_sent; #define CMD_T_QUEUED (1 << 3)
atomic_t t_transport_stop; #define CMD_T_SENT (1 << 4)
atomic_t transport_dev_active; #define CMD_T_STOP (1 << 5)
#define CMD_T_FAILED (1 << 6)
#define CMD_T_LUN_STOP (1 << 7)
#define CMD_T_LUN_FE_STOP (1 << 8)
#define CMD_T_DEV_ACTIVE (1 << 9)
atomic_t transport_lun_active; atomic_t transport_lun_active;
atomic_t transport_lun_fe_stop;
atomic_t transport_lun_stop;
spinlock_t t_state_lock; spinlock_t t_state_lock;
struct completion t_transport_stop_comp; struct completion t_transport_stop_comp;
struct completion transport_lun_fe_stop_comp; struct completion transport_lun_fe_stop_comp;
......
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