libiscsi: lock clean ups
Subsystems (10)
Mike Christie
maintainercover libiscsi: lock clean ups
The following patches made over Linus's current tree cleanup the locking in libiscsi so we again, for the main IO path, have the frwd lock only used in the xmit/queue path and the back lock used in the completion path and no taskqueuelock. The EH paths still use both the frwd/back lock though.
These patches are not ready for merging. I have only tested iscsi_tcp. Also, even though the changes to the offload drivers look like minimal API use changes, I wanted to try and get some tests done as the changes affect the main IO and error paths.
Also, I wanted to try and track down any offload maintainers that are still doing development on their drivers. After this batch of patches is merged we can go one step further and remove the frwd lock from queuecommand for at least the iscsi xmit wq based drivers by switching to some per task locking or lllists. And if we can figure out if the offload cards manage their own cmdsn window then we could drop the frwd lock for them too and we could do some optimizatons with the back lock for them.
Mike Christie
maintainerPATCH 1/15 libiscsi: fix iscsi_prep_scsi_cmd_pdu error handling
If iscsi_prep_scsi_cmd_pdu fails we try to add it back to the cmdqueue, but we leave it partially setup. We don't have functions that can undo the pdu and init task setup. We only have cleanup_task which can cleanup both parts. So this has us just fail the cmd and go through the standard cleanup routine and then have scsi-ml retry it like is done when it fails in the queuecommand path.
--- drivers/scsi/libiscsi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/scsi/libiscsi.c +3 -8
@@ -1532,14 +1532,9 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) } rc =iscsi_prep_scsi_cmd_pdu (conn->task);if (rc) { -if (rc == -ENOMEM || rc == -EACCES ) { -spin_lock_bh (&conn->taskqueuelock); -list_add_tail (&conn->task->running, - &conn->cmdqueue); - conn->task =NULL ; -spin_unlock_bh (&conn->taskqueuelock); - goto done; - }else +if (rc == -ENOMEM || rc == -EACCES ) +fail_scsi_task (conn->task,DID_IMM_RETRY ); +else fail_scsi_task (conn->task,DID_ABORT );spin_lock_bh (&conn->taskqueuelock);continue ;
Signature · 1 line
1.8.3.1
Re: [PATCH 01/15] libiscsi: fix iscsi_prep_scsi_cmd_pdu error handling
Quoted 25 lines · Mike Christie
If
iscsi_prep_scsi_cmd_pdufails we try to add it back to the cmdqueue, but we leave it partially setup. We don't have functions that can undo the pdu and init task setup. We only havecleanup_taskwhich can cleanup both parts. So this has us just fail the cmd and go through the standard cleanup routine and then have scsi-ml retry it like is done when it fails in the queuecommand path.Signed-off-by Mike Christie <[email protected]>--- drivers/scsi/libiscsi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)drivers/scsi/libiscsi.c +0
-4@@ -1532,14 +1532,9 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) } rc =iscsi_prep_scsi_cmd_pdu (conn->task);if (rc) { -if (rc == -ENOMEM || rc == -EACCES ) { -spin_lock_bh (&conn->taskqueuelock); -list_add_tail (&conn->task->running, - &conn->cmdqueue);
drivers/scsi/libiscsi.c static int iscsi_data_xmit(struct iscsi_conn *conn) · line 1540
Quoted 10 lines
drivers/scsi/libiscsi.c +3
-4- conn->task =NULL ; -spin_unlock_bh (&conn->taskqueuelock); - goto done; - }else +if (rc == -ENOMEM || rc == -EACCES ) +fail_scsi_task (conn->task,DID_IMM_RETRY ); +else fail_scsi_task (conn->task,DID_ABORT );spin_lock_bh (&conn->taskqueuelock);continue ;
Mike Christie
maintainerPATCH 2/15 libiscsi: drop taskqueuelock
In reply to Mike ChristieThe purpose of the taskqueuelock was to handle the issue where a bad target decides to send a R2T and before it's data has been sent decides to send a cmd response to complete the cmd. The following patches fix up the frwd/back locks so they are taken from the queue/xmit (frwd) and completion (back) paths again. To get there this patch removes the taskqueuelock which for iscsi xmit wq based drivers was taken in the queue, xmit and completion paths.
Instead of the lock, we just make sure we have a ref to the task when we queue a R2T, and then we always remove the task from the requeue list in the xmit path or the forced cleanup paths.
--- drivers/scsi/libiscsi.c | 170 +++++++++++++++++++++++++++----------------- drivers/scsi/libiscsi_tcp.c | 84 ++++++++++++++-------- include/scsi/libiscsi.h | 4 +- 3 files changed, 163 insertions(+), 95 deletions(-)
drivers/scsi/libiscsi.c +105 -65
@@ -523,16 +523,6 @@ static void iscsi_complete_task(struct iscsi_task *task, int state)WARN_ON_ONCE (task->state ==ISCSI_TASK_FREE ); task->state = state; -spin_lock_bh (&conn->taskqueuelock); -if (!list_empty (&task->running)) { -pr_debug_once ("%s while task on list" , __func__); -list_del_init (&task->running); - } -spin_unlock_bh (&conn->taskqueuelock); - -if (conn->task == task) - conn->task =NULL ; -if (READ_ONCE (conn->ping_task) == task)WRITE_ONCE (conn->ping_task,NULL );
@@ -564,9 +554,39 @@ void iscsi_complete_scsi_task(struct iscsi_task *task, }EXPORT_SYMBOL_GPL (iscsi_complete_scsi_task); +/* +* Must be called with back and frwd lock +*/ +static bool cleanup_queued_task (struct iscsi_task *task) +{ +struct iscsi_conn *conn = task->conn; +bool early_complete = false; + +/* Bad target might have completed task while it was still running */ +if (task->state ==ISCSI_TASK_COMPLETED ) + early_complete = true; + +if (!list_empty (&task->running)) { +list_del_init (&task->running); + +/* +* If it's on a list and running then it must be on the requeue +* list +*/ +if (task->state ==ISCSI_TASK_RUNNING ) +__iscsi_put_task (task); + } + +if (conn->task == task) { + conn->task =NULL ; +__iscsi_put_task (task); + } + +return early_complete; +}/* -* session back_lock must be held and if not called for a task that is +* session frwd_lock must be held and if not called for a task that is * still pending or from the xmit thread, then xmit thread must * be suspended. */
@@ -585,6 +605,13 @@ static void fail_scsi_task(struct iscsi_task *task, int err)if (!sc)return ; +/* regular RX path uses back_lock */ +spin_lock_bh (&conn->session->back_lock); +if (cleanup_queued_task (task)) { +spin_unlock_bh (&conn->session->back_lock); +return ; + } +if (task->state ==ISCSI_TASK_PENDING ) {/* * cmd never made it to the xmit thread, so we should not count
@@ -600,9 +627,6 @@ static void fail_scsi_task(struct iscsi_task *task, int err) sc->result = err <<16 ;scsi_set_resid (sc,scsi_bufflen (sc)); - -/* regular RX path uses back_lock */ -spin_lock_bh (&conn->session->back_lock);iscsi_complete_task (task, state);spin_unlock_bh (&conn->session->back_lock); }
@@ -748,9 +772,7 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn,if (session->tt->xmit_task (task)) goto free_task; }else { -spin_lock_bh (&conn->taskqueuelock);list_add_tail (&task->running, &conn->mgmtqueue); -spin_unlock_bh (&conn->taskqueuelock);iscsi_conn_queue_work (conn); }
@@ -1411,31 +1433,51 @@ static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn)return 0 ; } -static int iscsi_xmit_task (struct iscsi_conn *conn) +static int iscsi_xmit_task (struct iscsi_conn *conn,bool has_extra_ref) {struct iscsi_task *task = conn->task;int rc; -if (test_bit (ISCSI_SUSPEND_BIT , &conn->suspend_tx)) -return -ENODATA ; - +/* Take a ref so we can access it after xmit_task() */ +__iscsi_get_task (task); + conn->task =NULL ;spin_lock_bh (&conn->session->back_lock); -if (conn->task ==NULL ) { -spin_unlock_bh (&conn->session->back_lock); -return -ENODATA ; +/* +* If this was a requeue for a R2T or we were in the middle of sending +* the task, we have an extra ref on the task in case a bad target +* sends a cmd rsp before we have handled the task. +*/ +if (has_extra_ref) +__iscsi_put_task (task); + +/* +* Do this after dropping the extra ref because the forced dequeue +* helper will miss the ref taken during requeue list check. +*/ +if (test_bit (ISCSI_SUSPEND_BIT , &conn->suspend_tx)) { + rc = -ENODATA ; + goto put_task; } -__iscsi_get_task (task);spin_unlock_bh (&conn->session->back_lock); +spin_unlock_bh (&conn->session->frwd_lock); rc = conn->session->tt->xmit_task (task);spin_lock_bh (&conn->session->frwd_lock);if (!rc) {/* done with this task */ task->last_xfer = jiffies; - conn->task =NULL ; }/* regular RX path uses back_lock */ spin_lock (&conn->session->back_lock); +if (rc && task->state ==ISCSI_TASK_RUNNING ) { +/* +* get an extra ref that is released next time we access it +* as conn->task above. +*/ +__iscsi_get_task (task); + conn->task = task; + } +put_task:__iscsi_put_task (task);spin_unlock (&conn->session->back_lock);return rc;
@@ -1445,9 +1487,7 @@ static int iscsi_xmit_task(struct iscsi_conn *conn)* iscsi_requeue_task - requeue task to run from session workqueue * @task: task to requeue * -* LLDs that need to run a task from the session workqueue should call -* this. The session frwd_lock must be held. This should only be called -* by software drivers. +* Callers must have taken a ref to the task that is going to be requeued. */ void iscsi_requeue_task (struct iscsi_task *task) {
@@ -1457,11 +1497,18 @@ void iscsi_requeue_task(struct iscsi_task *task)* this may be on the requeue list already if the xmit_task callout * is handling the r2ts while we are adding new ones */ -spin_lock_bh (&conn->taskqueuelock); -if (list_empty (&task->running)) +spin_lock_bh (&conn->session->frwd_lock); +if (list_empty (&task->running)) {list_add_tail (&task->running, &conn->requeue); -spin_unlock_bh (&conn->taskqueuelock); + }else { +/* +* Don't need the extra ref since it's already requeued and +* has a ref. +*/ +iscsi_put_task (task); + }iscsi_conn_queue_work (conn); +spin_unlock_bh (&conn->session->frwd_lock); }EXPORT_SYMBOL_GPL (iscsi_requeue_task);
@@ -1487,7 +1534,7 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) }if (conn->task) { - rc =iscsi_xmit_task (conn); + rc =iscsi_xmit_task (conn, true);if (rc) goto done; }
@@ -1497,49 +1544,43 @@ static int iscsi_data_xmit(struct iscsi_conn *conn)* only have one nop-out as a ping from us and targets should not * overflow us with nop-ins */ -spin_lock_bh (&conn->taskqueuelock); check_mgmt:while (!list_empty (&conn->mgmtqueue)) { - conn->task =list_entry (conn->mgmtqueue.next, - struct iscsi_task, running); -list_del_init (&conn->task->running); -spin_unlock_bh (&conn->taskqueuelock); -if (iscsi_prep_mgmt_task (conn, conn->task)) { + task = list_entry(conn->mgmtqueue.next, struct iscsi_task, + running); +list_del_init (&task->running); +if (iscsi_prep_mgmt_task (conn, task)) {/* regular RX path uses back_lock */ spin_lock_bh (&conn->session->back_lock); -__iscsi_put_task (conn->task); +__iscsi_put_task (task);spin_unlock_bh (&conn->session->back_lock); - conn->task =NULL ; -spin_lock_bh (&conn->taskqueuelock);continue ; } - rc =iscsi_xmit_task (conn); + conn->task = task; + rc =iscsi_xmit_task (conn, false);if (rc) goto done; -spin_lock_bh (&conn->taskqueuelock); }/* process pending command queue */ while (!list_empty (&conn->cmdqueue)) { - conn->task = list_entry(conn->cmdqueue.next, struct iscsi_task, - running); -list_del_init (&conn->task->running); -spin_unlock_bh (&conn->taskqueuelock); + task = list_entry(conn->cmdqueue.next, struct iscsi_task, + running); +list_del_init (&task->running);if (conn->session->state ==ISCSI_STATE_LOGGING_OUT ) { -fail_scsi_task (conn->task,DID_IMM_RETRY ); -spin_lock_bh (&conn->taskqueuelock); +fail_scsi_task (task,DID_IMM_RETRY );continue ; } - rc =iscsi_prep_scsi_cmd_pdu (conn->task); + rc =iscsi_prep_scsi_cmd_pdu (task);if (rc) {if (rc == -ENOMEM || rc == -EACCES ) -fail_scsi_task (conn->task,DID_IMM_RETRY ); +fail_scsi_task (task,DID_IMM_RETRY );else -fail_scsi_task (conn->task,DID_ABORT ); -spin_lock_bh (&conn->taskqueuelock); +fail_scsi_task (task,DID_ABORT );continue ; } - rc =iscsi_xmit_task (conn); + conn->task = task; + rc =iscsi_xmit_task (conn, false);if (rc) goto done;/*
@@ -1547,7 +1588,6 @@ static int iscsi_data_xmit(struct iscsi_conn *conn)* we need to check the mgmt queue for nops that need to * be sent to aviod starvation */ -spin_lock_bh (&conn->taskqueuelock);if (!list_empty (&conn->mgmtqueue)) goto check_mgmt; }
@@ -1561,21 +1601,18 @@ static int iscsi_data_xmit(struct iscsi_conn *conn) task = list_entry(conn->requeue.next, struct iscsi_task, running); +if (iscsi_check_tmf_restrictions (task,ISCSI_OP_SCSI_DATA_OUT ))break ; +list_del_init (&task->running); conn->task = task; -list_del_init (&conn->task->running); - conn->task->state =ISCSI_TASK_RUNNING ; -spin_unlock_bh (&conn->taskqueuelock); - rc =iscsi_xmit_task (conn); + rc =iscsi_xmit_task (conn, true);if (rc) goto done; -spin_lock_bh (&conn->taskqueuelock);if (!list_empty (&conn->mgmtqueue)) goto check_mgmt; } -spin_unlock_bh (&conn->taskqueuelock);spin_unlock_bh (&conn->session->frwd_lock);return -ENODATA ;
@@ -1741,9 +1778,7 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) goto prepd_reject; } }else { -spin_lock_bh (&conn->taskqueuelock);list_add_tail (&task->running, &conn->cmdqueue); -spin_unlock_bh (&conn->taskqueuelock);iscsi_conn_queue_work (conn); }
@@ -2914,7 +2949,6 @@ struct iscsi_cls_conn *INIT_LIST_HEAD (&conn->mgmtqueue);INIT_LIST_HEAD (&conn->cmdqueue);INIT_LIST_HEAD (&conn->requeue); -spin_lock_init (&conn->taskqueuelock);INIT_WORK (&conn->xmitwork, iscsi_xmitworker);/* allocate login_task used for the login/text sequences */
@@ -3080,10 +3114,16 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)ISCSI_DBG_SESSION (conn->session,"failing mgmt itt 0x%x state %d\n" , task->itt, task->state); + +spin_lock_bh (&session->back_lock); +if (cleanup_queued_task (task)) { +spin_unlock_bh (&session->back_lock); +continue ; + } + state =ISCSI_TASK_ABRT_SESS_RECOV ;if (task->state ==ISCSI_TASK_PENDING ) state =ISCSI_TASK_COMPLETED ; -spin_lock_bh (&session->back_lock);iscsi_complete_task (task, state);spin_unlock_bh (&session->back_lock); }
drivers/scsi/libiscsi_tcp.c +56 -28
144 lines not on this page · raw message
include/scsi/libiscsi.h +2 -2
@@ -187,7 +187,7 @@ struct iscsi_conn {struct iscsi_task *task;/* xmit task in progress */ /* xmit */ -spinlock_t taskqueuelock;/* protects the next three lists */ +/* items must be added/deleted under frwd lock */ struct list_head mgmtqueue;/* mgmt (control) xmit queue */ struct list_head cmdqueue;/* data-path cmd queue */ struct list_head requeue;/* tasks needing another run */
@@ -332,7 +332,7 @@ struct iscsi_session {* cmdsn, queued_cmdsn * * session resources: * * - cmdpool kfifo_out , * -* - mgmtpool, */ +* - mgmtpool, queues */ spinlock_t back_lock;/* protects cmdsn_exp * * cmdsn_max, * * cmdpool kfifo_in */
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 3/15 qla4xxx: use iscsi_is_session_online
In reply to Mike Christie__qla4xxx_is_chap_active just wants to know if a session is online and does not care about why it's not, so this has it use iscsi_is_session_online.
This is not a bug now, but the next patch changes the behavior of iscsi_session_chkready so this patch just prepares the driver for that change.
--- drivers/scsi/qla4xxx/ql4_os.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qla4xxx/ql4_os.c +1 -1
@@ -844,7 +844,7 @@ static int __qla4xxx_is_chap_active(struct device *dev, void *data) sess = cls_session->dd_data; ddb_entry = sess->dd_data; -if (iscsi_session_chkready (cls_session)) +if (iscsi_is_session_online (cls_session)) goto exit_is_chap_active;if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
Signature · 1 line
1.8.3.1
Re: [PATCH 03/15] qla4xxx: use iscsi_is_session_online
Quoted 19 lines · Mike Christie
__qla4xxx_is_chap_activejust wants to know if a session is online and does not care about why it's not, so this has it useiscsi_is_session_online.This is not a bug now, but the next patch changes the behavior of
iscsi_session_chkreadyso this patch just prepares the driver for that change.Signed-off-by Mike Christie <[email protected]>--- drivers/scsi/qla4xxx/ql4_os.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/qla4xxx/ql4_os.c +0
-0
drivers/scsi/qla4xxx/ql4_os.c static int __qla4xxx_is_chap_active(struct device *dev, void *data) · line 850
Quoted 8 lines
drivers/scsi/qla4xxx/ql4_os.c +1
-1@@ -844,7 +844,7 @@ static int __qla4xxx_is_chap_active(struct device *dev, void *data) sess = cls_session->dd_data; ddb_entry = sess->dd_data; -if (iscsi_session_chkready (cls_session)) +if (iscsi_is_session_online (cls_session)) goto exit_is_chap_active;if (ddb_entry->chap_tbl_idx == *chap_tbl_idx)
Mike Christie
maintainerPATCH 4/15 iscsi class: drop session lock in iscsi_session_chkready
In reply to Mike ChristieThe session lock in iscsi_session_chkready is not needed because when we transition from logged into to another state we will blocked and/or remove the devices under the session, so no new IO will be sent the drivers after the block/remove. IO that races with the block/removal is cleaned up by the drivers when it handles all outstanding IO, so this just added an extra lock in the main IO path. This patch removes the lock like other transport classes.
--- drivers/scsi/scsi_transport_iscsi.c | 3 --- 1 file changed, 3 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +0 -3
@@ -1701,10 +1701,8 @@ static const char *iscsi_session_state_name(int state)int iscsi_session_chkready (struct iscsi_cls_session *session) { -unsigned long flags;int err; -spin_lock_irqsave (&session->lock, flags);switch (session->state) {case ISCSI_SESSION_LOGGED_IN : err =0 ;
@@ -1719,7 +1717,6 @@ int iscsi_session_chkready(struct iscsi_cls_session *session) err =DID_NO_CONNECT <<16 ;break ; } -spin_unlock_irqrestore (&session->lock, flags);return err; }EXPORT_SYMBOL_GPL (iscsi_session_chkready);
Signature · 1 line
1.8.3.1
Re: [PATCH 04/15] iscsi class: drop session lock in iscsi_session_chkready
Quoted 30 lines · Mike Christie
The session lock in
iscsi_session_chkreadyis not needed because when we transition from logged into to another state we will blocked and/or remove the devices under the session, so no new IO will be sent the drivers after the block/remove. IO that races with the block/removal is cleaned up by the drivers when it handles all outstanding IO, so this just added an extra lock in the main IO path. This patch removes the lock like other transport classes.Signed-off-by Mike Christie <[email protected]>--- drivers/scsi/scsi_transport_iscsi.c | 3 --- 1 file changed, 3 deletions(-)drivers/scsi/scsi_transport_iscsi.c +0
-2@@ -1701,10 +1701,8 @@ static const char *iscsi_session_state_name(int state)int iscsi_session_chkready (struct iscsi_cls_session *session) { -unsigned long flags;int err; -spin_lock_irqsave (&session->lock, flags);switch (session->state) {case ISCSI_SESSION_LOGGED_IN : err =0 ;
drivers/scsi/scsi_transport_iscsi.c int iscsi_session_chkready(struct iscsi_cls_session *session) · line 1722
Quoted 7 lines
drivers/scsi/scsi_transport_iscsi.c +0
-1@@ -1719,7 +1717,6 @@ int iscsi_session_chkready(struct iscsi_cls_session *session) err =DID_NO_CONNECT <<16 ;break ; } -spin_unlock_irqrestore (&session->lock, flags);return err; }EXPORT_SYMBOL_GPL (iscsi_session_chkready);
Mike Christie
maintainerPATCH 5/15 libiscsi: remove queued_cmdsn
In reply to Mike Christiequeue_cmdsn was meant to prevent cmds from sitting in the cmdqueue too long, but iscsi_eh_cmd_timed_out already handles this. By dropping it and moving the window check to iscsi_data_xmit we will no longer need the frwd lock for the cmdsn for the iscsi xmit wq based drivers. This will be more useful for future patches where we drop the frwd lock from queuecommand for these drivers, but today it only has the benefit that we can now detect when a nop carries the cmdsn info that opens a window.
--- drivers/scsi/libiscsi.c | 111 +++++++++++++++++++++++++------------------- drivers/scsi/libiscsi_tcp.c | 4 +- include/scsi/libiscsi.h | 10 ++-- 3 files changed, 69 insertions(+), 56 deletions(-)
drivers/scsi/libiscsi.c +63 -48
@@ -93,9 +93,31 @@ inline void iscsi_conn_queue_work(struct iscsi_conn *conn) }EXPORT_SYMBOL_GPL (iscsi_conn_queue_work); -static void __iscsi_update_cmdsn (struct iscsi_session *session, -uint32_t exp_cmdsn,uint32_t max_cmdsn) +static int iscsi_check_cmdsn_window_closed (struct iscsi_conn *conn) +{ +struct iscsi_session *session = conn->session; + +/* make sure we see the updated SNs */ +smp_rmb (); +/* +* Check for iSCSI window and take care of CmdSN wrap-around +*/ +if (!iscsi_sna_lte (session->cmdsn, session->max_cmdsn)) { +ISCSI_DBG_SESSION (session,"iSCSI CmdSN closed. ExpCmdSn " +"%u MaxCmdSN %u CmdSN %u\n" , + session->exp_cmdsn, session->max_cmdsn, + session->cmdsn); +return -ENOSPC ; + } +return 0 ; +} + +static void __iscsi_update_cmdsn (struct iscsi_conn *conn,uint32_t exp_cmdsn, +uint32_t max_cmdsn) { +struct iscsi_session *session = conn->session; +bool win_closed = false; +/* * standard specifies this check for when to update expected and * max sequence numbers
@@ -108,13 +130,22 @@ static void __iscsi_update_cmdsn(struct iscsi_session *session, session->exp_cmdsn = exp_cmdsn;if (max_cmdsn != session->max_cmdsn && - !iscsi_sna_lt (max_cmdsn, session->max_cmdsn)) + !iscsi_sna_lt (max_cmdsn, session->max_cmdsn)) { + +if (iscsi_check_cmdsn_window_closed (conn)) + win_closed = true; + session->max_cmdsn = max_cmdsn; +/* make sure we see the open window from the xmit/queue path */ +smp_wmb (); +if (win_closed) + session->win_opened = true; + } } -void iscsi_update_cmdsn (struct iscsi_session *session,struct iscsi_nopin *hdr) +void iscsi_update_cmdsn (struct iscsi_conn *conn,struct iscsi_nopin *hdr) { -__iscsi_update_cmdsn (session,be32_to_cpu (hdr->exp_cmdsn), +__iscsi_update_cmdsn (conn,be32_to_cpu (hdr->exp_cmdsn),be32_to_cpu (hdr->max_cmdsn)); }EXPORT_SYMBOL_GPL (iscsi_update_cmdsn);
@@ -424,14 +455,15 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) task->state =ISCSI_TASK_RUNNING ; session->cmdsn++; +/* make sure window checkers see the update */ +smp_wmb (); conn->scsicmd_pdus_cnt++;ISCSI_DBG_SESSION (session,"iscsi prep [%s cid %d sc %p cdb 0x%x " "itt 0x%x len %d cmdsn %d win %d]\n" , sc->sc_data_direction ==DMA_TO_DEVICE ?"write" :"read" , conn->id, sc, sc->cmnd[0 ], - task->itt, transfer_length, - session->cmdsn, + task->itt, transfer_length, session->cmdsn, session->max_cmdsn - session->exp_cmdsn +1 );return 0 ; }
@@ -465,6 +497,11 @@ static void iscsi_free_task(struct iscsi_task *task)kfifo_in (&session->cmdpool.queue, (void *)&task,sizeof (void *)); +if (session->win_opened && !work_pending (&conn->xmitwork)) { + session->win_opened = false; +iscsi_conn_queue_work (conn); + } +if (sc) {/* SCSI eh reuses commands to verify us */ sc->SCp.ptr =NULL ;
@@ -549,7 +586,7 @@ void iscsi_complete_scsi_task(struct iscsi_task *task,ISCSI_DBG_SESSION (conn->session,"[itt 0x%x]\n" , task->itt); conn->last_recv = jiffies; -__iscsi_update_cmdsn (conn->session, exp_cmdsn, max_cmdsn); +__iscsi_update_cmdsn (conn, exp_cmdsn, max_cmdsn);iscsi_complete_task (task,ISCSI_TASK_COMPLETED ); }EXPORT_SYMBOL_GPL (iscsi_complete_scsi_task);
@@ -613,11 +650,6 @@ static void fail_scsi_task(struct iscsi_task *task, int err) }if (task->state ==ISCSI_TASK_PENDING ) { -/* -* cmd never made it to the xmit thread, so we should not count -* the cmd in the sequencing -*/ - conn->session->queued_cmdsn--;/* it was never sent so just complete like normal */ state =ISCSI_TASK_COMPLETED ; }else if (err ==DID_TRANSPORT_DISRUPTED )
@@ -658,10 +690,8 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn,* but we always only send one PDU at a time. */ if (conn->c_stage ==ISCSI_CONN_STARTED && - !(hdr->opcode &ISCSI_OP_IMMEDIATE )) { - session->queued_cmdsn++; + !(hdr->opcode &ISCSI_OP_IMMEDIATE )) session->cmdsn++; - } }if (session->tt->init_task && session->tt->init_task (task))
@@ -820,7 +850,7 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,struct iscsi_session *session = conn->session;struct scsi_cmnd *sc = task->sc; -iscsi_update_cmdsn (session, (struct iscsi_nopin *)rhdr); +iscsi_update_cmdsn (conn, (struct iscsi_nopin *)rhdr); conn->exp_statsn =be32_to_cpu (rhdr->statsn) +1 ; sc->result = (DID_OK <<16 ) | rhdr->cmd_status;
@@ -920,7 +950,7 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,if (!(rhdr->flags &ISCSI_FLAG_DATA_STATUS ))return ; -iscsi_update_cmdsn (conn->session, (struct iscsi_nopin *)hdr); +iscsi_update_cmdsn (conn, (struct iscsi_nopin *)hdr); sc->result = (DID_OK <<16 ) | rhdr->cmd_status; conn->exp_statsn =be32_to_cpu (rhdr->statsn) +1 ; if (rhdr->flags & (ISCSI_FLAG_DATA_UNDERFLOW |
@@ -1172,7 +1202,7 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, opcode, conn->id, itt, datalen);if (itt == ~0U ) { -iscsi_update_cmdsn (session, (struct iscsi_nopin *)hdr); +iscsi_update_cmdsn (conn, (struct iscsi_nopin *)hdr);switch (opcode) {case ISCSI_OP_NOOP_IN :
@@ -1240,7 +1270,7 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,iscsi_data_in_rsp (conn, hdr, task);break ;case ISCSI_OP_LOGOUT_RSP : -iscsi_update_cmdsn (session, (struct iscsi_nopin *)hdr); +iscsi_update_cmdsn (conn, (struct iscsi_nopin *)hdr);if (datalen) { rc =ISCSI_ERR_PROTO ;break ;
@@ -1249,14 +1279,14 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr, goto recv_pdu;case ISCSI_OP_LOGIN_RSP :case ISCSI_OP_TEXT_RSP : -iscsi_update_cmdsn (session, (struct iscsi_nopin *)hdr); +iscsi_update_cmdsn (conn, (struct iscsi_nopin *)hdr);/* * login related PDU's exp_statsn is handled in * userspace */ goto recv_pdu;case ISCSI_OP_SCSI_TMFUNC_RSP : -iscsi_update_cmdsn (session, (struct iscsi_nopin *)hdr); +iscsi_update_cmdsn (conn, (struct iscsi_nopin *)hdr);if (datalen) { rc =ISCSI_ERR_PROTO ;break ;
@@ -1266,7 +1296,7 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,iscsi_complete_task (task,ISCSI_TASK_COMPLETED );break ;case ISCSI_OP_NOOP_IN : -iscsi_update_cmdsn (session, (struct iscsi_nopin *)hdr); +iscsi_update_cmdsn (conn, (struct iscsi_nopin *)hdr);if (hdr->ttt !=cpu_to_be32 (ISCSI_RESERVED_TAG ) || datalen) { rc =ISCSI_ERR_PROTO ;break ;
@@ -1416,23 +1446,6 @@ void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err) }EXPORT_SYMBOL_GPL (iscsi_conn_failure); -static int iscsi_check_cmdsn_window_closed (struct iscsi_conn *conn) -{ -struct iscsi_session *session = conn->session; - -/* -* Check for iSCSI window and take care of CmdSN wrap-around -*/ -if (!iscsi_sna_lte (session->queued_cmdsn, session->max_cmdsn)) { -ISCSI_DBG_SESSION (session,"iSCSI CmdSN closed. ExpCmdSn " -"%u MaxCmdSN %u CmdSN %u/%u\n" , - session->exp_cmdsn, session->max_cmdsn, - session->cmdsn, session->queued_cmdsn); -return -ENOSPC ; - } -return 0 ; -} -static int iscsi_xmit_task (struct iscsi_conn *conn,bool has_extra_ref) {struct iscsi_task *task = conn->task;
@@ -1564,6 +1577,10 @@ static int iscsi_data_xmit(struct iscsi_conn *conn)/* process pending command queue */ while (!list_empty (&conn->cmdqueue)) { + rc =iscsi_check_cmdsn_window_closed (conn); +if (rc) + goto done; + task = list_entry(conn->cmdqueue.next, struct iscsi_task, running);list_del_init (&task->running);
@@ -1750,11 +1767,6 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) goto fault; } -if (iscsi_check_cmdsn_window_closed (conn)) { - reason =FAILURE_WINDOW_CLOSED ; - goto reject; - } - task =iscsi_alloc_task (conn, sc);if (!task) { reason =FAILURE_OOM ;
@@ -1762,6 +1774,11 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) }if (!ihost->workq) { +if (iscsi_check_cmdsn_window_closed (conn)) { + reason =FAILURE_WINDOW_CLOSED ; + goto prepd_reject; + } + reason =iscsi_prep_scsi_cmd_pdu (task);if (reason) {if (reason == -ENOMEM || reason == -EACCES ) {
@@ -1782,7 +1799,6 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc)iscsi_conn_queue_work (conn); } - session->queued_cmdsn++;spin_unlock_bh (&session->frwd_lock);return 0 ;
@@ -2831,7 +2847,7 @@ struct iscsi_cls_session * session->abort_timeout =10 ; session->scsi_cmds_max = scsi_cmds; session->cmds_max = total_cmds; - session->queued_cmdsn = session->cmdsn = initial_cmdsn; + session->cmdsn = initial_cmdsn; session->exp_cmdsn = initial_cmdsn +1 ; session->max_cmdsn = initial_cmdsn +1 ; session->max_r2t =1 ;
@@ -3063,7 +3079,6 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)spin_lock_bh (&session->frwd_lock); conn->c_stage =ISCSI_CONN_STARTED ; session->state =ISCSI_STATE_LOGGED_IN ; - session->queued_cmdsn = session->cmdsn; conn->last_recv = jiffies; conn->last_ping = jiffies;
drivers/scsi/libiscsi_tcp.c +2 -2
@@ -496,7 +496,7 @@ static int iscsi_tcp_data_in(struct iscsi_conn *conn, struct iscsi_task *task)* is status. */ if (!(rhdr->flags &ISCSI_FLAG_DATA_STATUS )) -iscsi_update_cmdsn (conn->session, (struct iscsi_nopin *)rhdr); +iscsi_update_cmdsn (conn, (struct iscsi_nopin *)rhdr);if (tcp_conn->in.datalen ==0 )return 0 ;
@@ -563,7 +563,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr) tcp_conn = conn->dd_data; rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr;/* fill-in new R2T associated with the task */ -iscsi_update_cmdsn (session, (struct iscsi_nopin *)rhdr); +iscsi_update_cmdsn (conn, (struct iscsi_nopin *)rhdr);spin_unlock (&session->back_lock);if (tcp_conn->in.datalen) {
include/scsi/libiscsi.h +4 -6
@@ -275,9 +275,7 @@ struct iscsi_session {uint32_t cmdsn;uint32_t exp_cmdsn;uint32_t max_cmdsn; - -/* This tracks the reqs queued into the initiator */ -uint32_t queued_cmdsn; +bool win_opened;/* configuration */ int abort_timeout;
@@ -329,8 +327,8 @@ struct iscsi_session {* but not vice versa. */ spinlock_t frwd_lock;/* protects session state, * -* cmdsn, queued_cmdsn * -* session resources: * +* cmdsn and session * +* resources: * * - cmdpool kfifo_out , * * - mgmtpool, queues */ spinlock_t back_lock;/* protects cmdsn_exp *
@@ -440,7 +438,7 @@ extern int iscsi_conn_get_addr_param(struct sockaddr_storage *addr,/* * pdu and task processing */ -extern void iscsi_update_cmdsn (struct iscsi_session *,struct iscsi_nopin *); +extern void iscsi_update_cmdsn (struct iscsi_conn *,struct iscsi_nopin *);extern void iscsi_prep_data_out_pdu (struct iscsi_task *task,struct iscsi_r2t_info *r2t,struct iscsi_data *hdr);
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 6/15 libiscsi: drop frwd lock for session state
In reply to Mike ChristieThis drops the frwd lock for the session state checks in queuecommand. Like with the transport class case, we only need it as a hint since when the session is cleaned up we will block the session which flushes the queues, and then we clean up all running IO. So the locking just prevents cleaning up extra cmds.
It is still needed:
1. when accessing suspend_tx in queuecomand because drivers that implement ep_disconnect will set that bit from disconnect (called before stop) and expect that no new commands will be queued to it. Note that the comment for this was wrong and that is fixed in this patch.
2. the list addition for the drivers that use the iscsi xmit wq.
--- drivers/scsi/libiscsi.c | 10 +++++++--- include/scsi/libiscsi.h | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-)
drivers/scsi/libiscsi.c +7 -3
@@ -1704,7 +1704,6 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) cls_session =starget_to_session (scsi_target (sc->device)); session = cls_session->dd_data; -spin_lock_bh (&session->frwd_lock); reason =iscsi_session_chkready (cls_session);if (reason) {
@@ -1761,7 +1760,9 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) goto fault; } +spin_lock_bh (&session->frwd_lock);if (test_bit (ISCSI_SUSPEND_BIT , &conn->suspend_tx)) { +spin_unlock_bh (&session->frwd_lock); reason =FAILURE_SESSION_IN_RECOVERY ; sc->result =DID_REQUEUE <<16 ; goto fault;
@@ -1769,6 +1770,7 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) task =iscsi_alloc_task (conn, sc);if (!task) { +spin_unlock_bh (&session->frwd_lock); reason =FAILURE_OOM ; goto reject; }
@@ -1803,21 +1805,23 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc)return 0 ; prepd_reject: +spin_unlock_bh (&session->frwd_lock); +spin_lock_bh (&session->back_lock);iscsi_complete_task (task,ISCSI_TASK_REQUEUE_SCSIQ );spin_unlock_bh (&session->back_lock); reject: -spin_unlock_bh (&session->frwd_lock);ISCSI_DBG_SESSION (session,"cmd 0x%x rejected (%d)\n" , sc->cmnd[0 ], reason);return SCSI_MLQUEUE_TARGET_BUSY ; prepd_fault: +spin_unlock_bh (&session->frwd_lock); +spin_lock_bh (&session->back_lock);iscsi_complete_task (task,ISCSI_TASK_REQUEUE_SCSIQ );spin_unlock_bh (&session->back_lock); fault: -spin_unlock_bh (&session->frwd_lock);ISCSI_DBG_SESSION (session,"iscsi: cmd 0x%x is not queued (%d)\n" , sc->cmnd[0 ], reason);scsi_set_resid (sc,scsi_bufflen (sc));
include/scsi/libiscsi.h +3 -2
@@ -326,8 +326,9 @@ struct iscsi_session {* can enclose the mutual exclusion zone protected by the backward lock * but not vice versa. */ -spinlock_t frwd_lock;/* protects session state, * -* cmdsn and session * +spinlock_t frwd_lock;/* protects session state * +* in the eh paths, cmdsn * +* suspend bit and session * * resources: * * - cmdpool kfifo_out , * * - mgmtpool, queues */
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 7/15 libiscsi: separate itt from task allocation
In reply to Mike ChristieThe next patches has libiscsi use the blk/scsi mq scsi cmd preallocation callouts to allocate the iscsi_task and the LLD's per task data so libiscsi does not have to add extra locking to manage it's cmd pool for scsi cmds. This means we need to separate the itt allocation and lookup from the task allocation. In this patch we just use a sbitmap.
--- drivers/scsi/be2iscsi/be_main.c | 2 +- drivers/scsi/libiscsi.c | 131 ++++++++++++++++++++++++++++++++++------ include/scsi/libiscsi.h | 2 + 3 files changed, 115 insertions(+), 20 deletions(-)
drivers/scsi/be2iscsi/be_main.c +1 -1
@@ -306,7 +306,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc)spin_lock (&session->back_lock);for (i =0 ; i < conn->session->cmds_max; i++) { task = conn->session->cmds[i]; -if (!task->sc) +if (!task || !task->sc)continue ;if (sc->device->lun != task->sc->device->lun)
drivers/scsi/libiscsi.c +112 -19
267 lines not on this page · raw message
include/scsi/libiscsi.h +2 -0
@@ -17,6 +17,7 @@#include <linux/workqueue.h> #include <linux/kfifo.h> #include <linux/refcount.h> +#include <linux/sbitmap.h> #include <scsi/iscsi_proto.h> #include <scsi/iscsi_if.h> #include <scsi/scsi_transport_iscsi.h>
@@ -342,6 +343,7 @@ struct iscsi_session {int cmds_max;/* size of cmds array */ struct iscsi_task **cmds;/* Original Cmds arr */ struct iscsi_pool cmdpool;/* PDU's pool */ +struct sbitmap itts;void *dd_data;/* LLD private data */ };
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 8/15 iser, be2iscsi, qla4xxx: set scsi_host_template cmd_size
In reply to Mike ChristieUse scsi_host_template cmd_size so the block/scsi-ml layers allocate the iscsi structs for the driver. This patch includes the easy drivers that just needed to set the size and a helper to init the iscsi task.
--- drivers/infiniband/ulp/iser/iscsi_iser.c | 3 +++ drivers/scsi/be2iscsi/be_main.c | 2 ++ drivers/scsi/libiscsi.c | 17 +++++++++++++++++ drivers/scsi/qla4xxx/ql4_os.c | 3 +++ include/scsi/libiscsi.h | 1 + 5 files changed, 26 insertions(+)
drivers/infiniband/ulp/iser/iscsi_iser.c +3 -0
@@ -976,6 +976,9 @@ static umode_t iser_attr_is_visible(int param_type, int param) .proc_name = "iscsi_iser", .this_id = -1, .track_queue_depth = 1, + .cmd_size = sizeof(struct iscsi_iser_task) + + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_init_cmd_priv, };static struct iscsi_transport iscsi_iser_transport = {
drivers/scsi/be2iscsi/be_main.c +2 -0
@@ -401,6 +401,8 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) .cmd_per_lun = BEISCSI_CMD_PER_LUN, .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, .track_queue_depth = 1, + .cmd_size = sizeof(struct beiscsi_io_task) + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_init_cmd_priv, };static struct scsi_transport_template *beiscsi_scsi_transport;
drivers/scsi/libiscsi.c +17 -0
@@ -2830,6 +2830,23 @@ static void iscsi_host_dec_session_cnt(struct Scsi_Host *shost)scsi_host_put (shost); } +static void iscsi_init_task (struct iscsi_task *task) +{ + task->dd_data = &task[1 ]; + task->itt =ISCSI_RESERVED_TAG ; + task->state =ISCSI_TASK_FREE ; +INIT_LIST_HEAD (&task->running); +} + +int iscsi_init_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *sc) +{ +struct iscsi_task *task =scsi_cmd_priv (sc); + +iscsi_init_task (task); +return 0 ; +} +EXPORT_SYMBOL_GPL (iscsi_init_cmd_priv); +/** * iscsi_session_setup - create iscsi cls session and host and session * @iscsit: iscsi transport template
drivers/scsi/qla4xxx/ql4_os.c +3 -0
@@ -239,6 +239,9 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, .this_id = -1, .cmd_per_lun = 3, .sg_tablesize = SG_ALL, + .cmd_size =sizeof (struct ql4_task_data ) + + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_init_cmd_priv, .max_sectors = 0xFFFF, .shost_attrs = qla4xxx_host_attrs,
include/scsi/libiscsi.h +1 -0
@@ -460,6 +460,7 @@ extern int __iscsi_complete_pdu(struct iscsi_conn *, struct iscsi_hdr *,extern void __iscsi_get_task (struct iscsi_task *task);extern void iscsi_complete_scsi_task (struct iscsi_task *task,uint32_t exp_cmdsn,uint32_t max_cmdsn); +extern int iscsi_init_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *cmd);/* * generic helpers
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 9/15 bnx2i: set scsi_host_template cmd_size
In reply to Mike ChristieUse scsi_host_template cmd_size so the block/scsi-ml layers allocate the iscsi structs for the driver.
--- drivers/scsi/bnx2i/bnx2i_iscsi.c | 112 +++++++++++---------------------------- 1 file changed, 30 insertions(+), 82 deletions(-)
drivers/scsi/bnx2i/bnx2i_iscsi.c +30 -82
@@ -438,11 +438,9 @@ static void bnx2i_free_ep(struct iscsi_endpoint *ep)/** * bnx2i_alloc_bdt - allocates buffer descriptor (BD) table for the command * @hba: adapter instance pointer -* @session: iscsi session pointer * @cmd: iscsi command structure */ -static int bnx2i_alloc_bdt (struct bnx2i_hba *hba,struct iscsi_session *session, -struct bnx2i_cmd *cmd) +static int bnx2i_alloc_bdt (struct bnx2i_hba *hba,struct bnx2i_cmd *cmd) {struct io_bdt *io = &cmd->io_tbl;struct iscsi_bd *bd;
@@ -451,68 +449,44 @@ static int bnx2i_alloc_bdt(struct bnx2i_hba *hba, struct iscsi_session *session,ISCSI_MAX_BDS_PER_CMD *sizeof (*bd), &io->bd_tbl_dma, GFP_KERNEL);if (!io->bd_tbl) { -iscsi_session_printk (KERN_ERR , session,"Could not " -"allocate bdt.\n" ); +shost_printk (KERN_ERR , hba->shost,"Could not allocate bdt.\n" );return -ENOMEM ; } io->bd_valid =0 ;return 0 ; } -/** -* bnx2i_destroy_cmd_pool - destroys iscsi command pool and release BD table -* @hba: adapter instance pointer -* @session: iscsi session pointer -*/ -static void bnx2i_destroy_cmd_pool (struct bnx2i_hba *hba, -struct iscsi_session *session) +static int bnx2i_exit_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *sc) { -int i; - -for (i =0 ; i < session->cmds_max; i++) { -struct iscsi_task *task = session->cmds[i]; -struct bnx2i_cmd *cmd = task->dd_data; +struct bnx2i_hba *hba =iscsi_host_priv (shost); +struct iscsi_task *task =scsi_cmd_priv (sc); +struct bnx2i_cmd *cmd = task->dd_data; -if (cmd->io_tbl.bd_tbl) -dma_free_coherent (&hba->pcidev->dev, -ISCSI_MAX_BDS_PER_CMD * -sizeof (struct iscsi_bd ), - cmd->io_tbl.bd_tbl, - cmd->io_tbl.bd_tbl_dma); - } +if (!cmd->io_tbl.bd_tbl) +return 0 ; +dma_free_coherent (&hba->pcidev->dev, +ISCSI_MAX_BDS_PER_CMD *sizeof (struct iscsi_bd ), + cmd->io_tbl.bd_tbl, cmd->io_tbl.bd_tbl_dma); +return 0 ; } - -/** -* bnx2i_setup_cmd_pool - sets up iscsi command pool for the session -* @hba: adapter instance pointer -* @session: iscsi session pointer -*/ -static int bnx2i_setup_cmd_pool (struct bnx2i_hba *hba, -struct iscsi_session *session) +static int bnx2i_init_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *sc) { -int i; - -for (i =0 ; i < session->cmds_max; i++) { -struct iscsi_task *task = session->cmds[i]; -struct bnx2i_cmd *cmd = task->dd_data; - - task->hdr = &cmd->hdr; - task->hdr_max =sizeof (struct iscsi_hdr ); +struct bnx2i_hba *hba =iscsi_host_priv (shost); +struct iscsi_task *task; +struct bnx2i_cmd *cmd; -if (bnx2i_alloc_bdt (hba, session, cmd)) - goto free_bdts; - } +iscsi_init_cmd_priv (shost, sc); -return 0 ; + task =scsi_cmd_priv (sc); + cmd = task->dd_data; + task->hdr = &cmd->hdr; + task->hdr_max =sizeof (struct iscsi_hdr ); -free_bdts: -bnx2i_destroy_cmd_pool (hba, session); -return -ENOMEM ; +return bnx2i_alloc_bdt (hba, cmd); } -/** * bnx2i_setup_mp_bdt - allocate BD table resources * @hba: pointer to adapter structure
@@ -1288,7 +1262,6 @@ static int bnx2i_task_xmit(struct iscsi_task *task) uint32_t initial_cmdsn) {struct Scsi_Host *shost; -struct iscsi_cls_session *cls_session;struct bnx2i_hba *hba;struct bnx2i_endpoint *bnx2i_ep;
@@ -1312,40 +1285,11 @@ static int bnx2i_task_xmit(struct iscsi_task *task)else if (cmds_max <BNX2I_SQ_WQES_MIN ) cmds_max =BNX2I_SQ_WQES_MIN ; - cls_session =iscsi_session_setup (&bnx2i_iscsi_transport, shost, - cmds_max,0 ,sizeof (struct bnx2i_cmd ), - initial_cmdsn,ISCSI_MAX_TARGET ); -if (!cls_session) -return NULL ; - -if (bnx2i_setup_cmd_pool (hba, cls_session->dd_data)) - goto session_teardown; -return cls_session; - -session_teardown: -iscsi_session_teardown (cls_session); -return NULL ; +return iscsi_session_setup (&bnx2i_iscsi_transport, shost, + cmds_max,0 ,sizeof (struct bnx2i_cmd ), + initial_cmdsn,ISCSI_MAX_TARGET ); } - -/** -* bnx2i_session_destroy - destroys iscsi session -* @cls_session: pointer to iscsi cls session -* -* Destroys previously created iSCSI session instance and releases -* all resources held by it -*/ -static void bnx2i_session_destroy (struct iscsi_cls_session *cls_session) -{ -struct iscsi_session *session = cls_session->dd_data; -struct Scsi_Host *shost =iscsi_session_to_shost (cls_session); -struct bnx2i_hba *hba =iscsi_host_priv (shost); - -bnx2i_destroy_cmd_pool (hba, session); -iscsi_session_teardown (cls_session); -} - -/** * bnx2i_conn_create - create iscsi connection instance * @cls_session: pointer to iscsi cls session
@@ -2265,6 +2209,10 @@ static umode_t bnx2i_attr_is_visible(int param_type, int param) .sg_tablesize = ISCSI_MAX_BDS_PER_CMD, .shost_attrs = bnx2i_dev_attributes, .track_queue_depth = 1, + .cmd_size = sizeof(struct bnx2i_cmd) + + sizeof(struct iscsi_task), + .init_cmd_priv = bnx2i_init_cmd_priv, + .exit_cmd_priv = bnx2i_exit_cmd_priv, };struct iscsi_transport bnx2i_iscsi_transport = {
@@ -2275,7 +2223,7 @@ struct iscsi_transport bnx2i_iscsi_transport = {CAP_DATA_PATH_OFFLOAD | CAP_TEXT_NEGO, .create_session = bnx2i_session_create, - .destroy_session = bnx2i_session_destroy, + .destroy_session = iscsi_session_teardown, .create_conn = bnx2i_conn_create, .bind_conn = bnx2i_conn_bind, .destroy_conn = bnx2i_conn_destroy,
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 10/15 qedi: set scsi_host_template cmd_size
In reply to Mike ChristieUse scsi_host_template cmd_size so the block/scsi-ml layers allocate the iscsi structs for the driver.
--- drivers/scsi/qedi/qedi_iscsi.c | 113 ++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 64 deletions(-)
drivers/scsi/qedi/qedi_iscsi.c +49 -64
@@ -14,6 +14,9 @@#include "qedi_iscsi.h" #include "qedi_gbl.h" +static int qedi_exit_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *sc); +static int qedi_init_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *sc); +int qedi_recover_all_conns (struct qedi_ctx *qedi) {struct qedi_conn *qedi_conn;
@@ -59,6 +62,9 @@ struct scsi_host_template qedi_host_template = { .dma_boundary = QEDI_HW_DMA_BOUNDARY, .cmd_per_lun = 128, .shost_attrs = qedi_shost_attrs, + .cmd_size = sizeof(struct qedi_cmd) + sizeof(struct iscsi_task), + .init_cmd_priv = qedi_init_cmd_priv, + .exit_cmd_priv = qedi_exit_cmd_priv, }; static void qedi_conn_free_login_resources(struct qedi_ctx *qedi,
@@ -160,32 +166,17 @@ static int qedi_conn_alloc_login_resources(struct qedi_ctx *qedi,return -ENOMEM ; } -static void qedi_destroy_cmd_pool (struct qedi_ctx *qedi, -struct iscsi_session *session) +static void qedi_free_sget (struct qedi_ctx *qedi,struct qedi_cmd *cmd) { -int i; +if (!cmd->io_tbl.sge_tbl) +return ; -for (i =0 ; i < session->cmds_max; i++) { -struct iscsi_task *task = session->cmds[i]; -struct qedi_cmd *cmd = task->dd_data; - -if (cmd->io_tbl.sge_tbl) -dma_free_coherent (&qedi->pdev->dev, -QEDI_ISCSI_MAX_BDS_PER_CMD * -sizeof (struct scsi_sge ), - cmd->io_tbl.sge_tbl, - cmd->io_tbl.sge_tbl_dma); - -if (cmd->sense_buffer) -dma_free_coherent (&qedi->pdev->dev, -SCSI_SENSE_BUFFERSIZE , - cmd->sense_buffer, - cmd->sense_buffer_dma); - } +dma_free_coherent (&qedi->pdev->dev, +QEDI_ISCSI_MAX_BDS_PER_CMD *sizeof (struct scsi_sge ), + cmd->io_tbl.sge_tbl, cmd->io_tbl.sge_tbl_dma); } -static int qedi_alloc_sget (struct qedi_ctx *qedi,struct iscsi_session *session, -struct qedi_cmd *cmd) +static int qedi_alloc_sget (struct qedi_ctx *qedi,struct qedi_cmd *cmd) {struct qedi_io_bdt *io = &cmd->io_tbl;struct scsi_sge *sge;
@@ -195,8 +186,8 @@ static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session,sizeof (*sge), &io->sge_tbl_dma, GFP_KERNEL);if (!io->sge_tbl) { -iscsi_session_printk (KERN_ERR , session, -"Could not allocate BD table.\n" ); +shost_printk (KERN_ERR , qedi->shost, +"Could not allocate BD table.\n" );return -ENOMEM ; }
@@ -204,33 +195,47 @@ static int qedi_alloc_sget(struct qedi_ctx *qedi, struct iscsi_session *session,return 0 ; } -static int qedi_setup_cmd_pool (struct qedi_ctx *qedi, -struct iscsi_session *session) +static int qedi_exit_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *sc) { -int i; +struct qedi_ctx *qedi =iscsi_host_priv (shost); +struct iscsi_task *task =scsi_cmd_priv (sc); +struct qedi_cmd *cmd = task->dd_data; -for (i =0 ; i < session->cmds_max; i++) { -struct iscsi_task *task = session->cmds[i]; -struct qedi_cmd *cmd = task->dd_data; +qedi_free_sget (qedi, cmd); - task->hdr = &cmd->hdr; - task->hdr_max =sizeof (struct iscsi_hdr ); +if (cmd->sense_buffer) +dma_free_coherent (&qedi->pdev->dev,SCSI_SENSE_BUFFERSIZE , + cmd->sense_buffer, cmd->sense_buffer_dma); +return 0 ; +} + +static int qedi_init_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *sc) +{ +struct qedi_ctx *qedi =iscsi_host_priv (shost); +struct iscsi_task *task; +struct qedi_cmd *cmd; -if (qedi_alloc_sget (qedi, session, cmd)) - goto free_sgets; +iscsi_init_cmd_priv (shost, sc); - cmd->sense_buffer =dma_alloc_coherent (&qedi->pdev->dev, -SCSI_SENSE_BUFFERSIZE , - &cmd->sense_buffer_dma, -GFP_KERNEL ); -if (!cmd->sense_buffer) - goto free_sgets; - } + task =scsi_cmd_priv (sc); + cmd = task->dd_data; + task->hdr = &cmd->hdr; + task->hdr_max =sizeof (struct iscsi_hdr ); + +if (qedi_alloc_sget (qedi, cmd)) + goto free_sgets; + + cmd->sense_buffer =dma_alloc_coherent (&qedi->pdev->dev, +SCSI_SENSE_BUFFERSIZE , + &cmd->sense_buffer_dma, +GFP_KERNEL ); +if (!cmd->sense_buffer) + goto free_sgets;return 0 ; free_sgets: -qedi_destroy_cmd_pool (qedi, session); +qedi_free_sget (qedi, cmd);return -ENOMEM ; }
@@ -264,27 +269,7 @@ static int qedi_setup_cmd_pool(struct qedi_ctx *qedi,return NULL ; } -if (qedi_setup_cmd_pool (qedi, cls_session->dd_data)) { -QEDI_ERR (&qedi->dbg_ctx, -"Failed to setup cmd pool for ep=%p\n" , qedi_ep); - goto session_teardown; - } -return cls_session; - -session_teardown: -iscsi_session_teardown (cls_session); -return NULL ; -} - -static void qedi_session_destroy (struct iscsi_cls_session *cls_session) -{ -struct iscsi_session *session = cls_session->dd_data; -struct Scsi_Host *shost =iscsi_session_to_shost (cls_session); -struct qedi_ctx *qedi =iscsi_host_priv (shost); - -qedi_destroy_cmd_pool (qedi, session); -iscsi_session_teardown (cls_session); } static struct iscsi_cls_conn *
@@ -1398,7 +1383,7 @@ struct iscsi_transport qedi_iscsi_transport = { .caps = CAP_RECOVERY_L0 | CAP_HDRDGST | CAP_MULTI_R2T | CAP_DATADGST | CAP_DATA_PATH_OFFLOAD | CAP_TEXT_NEGO, .create_session = qedi_session_create, - .destroy_session = qedi_session_destroy, + .destroy_session = iscsi_session_teardown, .create_conn = qedi_conn_create, .bind_conn = qedi_conn_bind, .start_conn = qedi_conn_start,
@@ -1625,7 +1610,7 @@ void qedi_clear_session_ctx(struct iscsi_cls_session *cls_sess)qedi_conn_destroy (qedi_conn->cls_conn); -qedi_session_destroy (cls_sess); +iscsi_session_teardown (cls_sess); } void qedi_process_tcp_error(struct qedi_endpoint *ep,
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 11/15 iscsi_tcp, libcxgbi: set scsi_host_template cmd_size
In reply to Mike ChristieUse scsi_host_template cmd_size so the block/scsi-ml layers allocate the iscsi structs for the driver.
Note: Because for cxgbi we do not have access to the specific session we are creating cmds for, all sessions get the max of what is on the host but this is normally going to one so it should not be any different.
--- drivers/scsi/cxgbi/cxgb3i/cxgb3i.c | 5 ++ drivers/scsi/cxgbi/cxgb4i/cxgb4i.c | 5 ++ drivers/scsi/cxgbi/libcxgbi.c | 10 ---- drivers/scsi/iscsi_tcp.c | 10 ++-- drivers/scsi/libiscsi_tcp.c | 102 ++++++++++++++++++++----------------- include/scsi/libiscsi_tcp.h | 5 +- 6 files changed, 72 insertions(+), 65 deletions(-)
drivers/scsi/cxgbi/cxgb3i/cxgb3i.c +5 -0
@@ -98,6 +98,11 @@ .dma_boundary = PAGE_SIZE - 1, .this_id = -1, .track_queue_depth = 1, + .cmd_size =sizeof (struct iscsi_tcp_task ) + +sizeof (struct cxgbi_task_data ) + + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_tcp_init_cmd_priv, + .exit_cmd_priv = iscsi_tcp_exit_cmd_priv, };static struct iscsi_transport cxgb3i_iscsi_transport = {
drivers/scsi/cxgbi/cxgb4i/cxgb4i.c +5 -0
@@ -116,6 +116,11 @@ .dma_boundary = PAGE_SIZE - 1, .this_id = -1, .track_queue_depth = 1, + .cmd_size =sizeof (struct iscsi_tcp_task ) + +sizeof (struct cxgbi_task_data ) + + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_tcp_init_cmd_priv, + .exit_cmd_priv = iscsi_tcp_exit_cmd_priv, };static struct iscsi_transport cxgb4i_iscsi_transport = {
drivers/scsi/cxgbi/libcxgbi.c +0 -10
@@ -2727,7 +2727,6 @@ struct iscsi_cls_session *cxgbi_create_session(struct iscsi_endpoint *ep,struct cxgbi_hba *chba;struct Scsi_Host *shost;struct iscsi_cls_session *cls_session; -struct iscsi_session *session;if (!ep) {pr_err ("missing endpoint.\n" );
@@ -2748,17 +2747,9 @@ struct iscsi_cls_session *cxgbi_create_session(struct iscsi_endpoint *ep,if (!cls_session)return NULL ; - session = cls_session->dd_data; -if (iscsi_tcp_r2tpool_alloc (session)) - goto remove_session; -log_debug (1 <<CXGBI_DBG_ISCSI ,"ep 0x%p, cls sess 0x%p.\n" , ep, cls_session);return cls_session; - -remove_session: -iscsi_session_teardown (cls_session); -return NULL ; }EXPORT_SYMBOL_GPL (cxgbi_create_session);
@@ -2767,7 +2758,6 @@ void cxgbi_destroy_session(struct iscsi_cls_session *cls_session)log_debug (1 <<CXGBI_DBG_ISCSI ,"cls sess 0x%p.\n" , cls_session); -iscsi_tcp_r2tpool_free (cls_session->dd_data);iscsi_session_teardown (cls_session); }EXPORT_SYMBOL_GPL (cxgbi_destroy_session);
drivers/scsi/iscsi_tcp.c +5 -5
@@ -879,12 +879,8 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost, tcp_sw_host->session = session; shost->can_queue = session->scsi_cmds_max; -if (iscsi_tcp_r2tpool_alloc (session)) - goto remove_session;return cls_session; -remove_session: -iscsi_session_teardown (cls_session); remove_host:iscsi_host_remove (shost); free_host:
@@ -900,7 +896,6 @@ static void iscsi_sw_tcp_session_destroy(struct iscsi_cls_session *cls_session)if (WARN_ON_ONCE (session->leadconn))return ; -iscsi_tcp_r2tpool_free (cls_session->dd_data);iscsi_session_teardown (cls_session);iscsi_host_remove (shost);
@@ -995,6 +990,11 @@ static int iscsi_sw_tcp_slave_configure(struct scsi_device *sdev) .proc_name = "iscsi_tcp", .this_id = -1, .track_queue_depth = 1, + .cmd_size =sizeof (struct iscsi_tcp_task ) + +sizeof (struct iscsi_sw_tcp_hdrbuf ) + + sizeof(struct iscsi_task), + .init_cmd_priv = iscsi_tcp_init_cmd_priv, + .exit_cmd_priv = iscsi_tcp_exit_cmd_priv, };static struct iscsi_transport iscsi_sw_tcp_transport = {
drivers/scsi/libiscsi_tcp.c +54 -48
130 lines not on this page · raw message
include/scsi/libiscsi_tcp.h +3 -2
@@ -89,6 +89,9 @@ extern int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb,extern void iscsi_tcp_cleanup_task (struct iscsi_task *task);extern int iscsi_tcp_task_init (struct iscsi_task *task);extern int iscsi_tcp_task_xmit (struct iscsi_task *task); +extern int iscsi_tcp_init_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *sc); +extern int iscsi_tcp_exit_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *sc); +/* segment helpers */ extern int iscsi_tcp_recv_segment_is_hdr (struct iscsi_tcp_conn *tcp_conn);
@@ -118,8 +121,6 @@ extern void iscsi_tcp_dgst_header(struct ahash_request *hash, const void *hdr,extern void iscsi_tcp_conn_teardown (struct iscsi_cls_conn *cls_conn);/* misc helpers */ -extern int iscsi_tcp_r2tpool_alloc (struct iscsi_session *session); -extern void iscsi_tcp_r2tpool_free (struct iscsi_session *session);extern int iscsi_tcp_set_max_r2t (struct iscsi_conn *conn,char *buf);extern void iscsi_tcp_conn_get_stats (struct iscsi_cls_conn *cls_conn,struct iscsi_stats *stats);
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 12/15 libiscsi: use blk/scsi-ml mq cmd pre-allocator
In reply to Mike ChristieThis has us use the blk/scsi-ml mq cmd pre-allocator for scsi tasks. We now do not need the back/frwd locks for scsi task allocation. We still need it for mgmt tasks, but that will be fixed in the next patch.
--- drivers/scsi/libiscsi.c | 84 ++++++++++++++++++------------------------------- include/scsi/libiscsi.h | 13 +++++--- 2 files changed, 38 insertions(+), 59 deletions(-)
drivers/scsi/libiscsi.c +30 -54
@@ -547,14 +547,15 @@ static void iscsi_free_task(struct iscsi_task *task)return ;iscsi_free_itt (session, task); -kfifo_in (&session->cmdpool.queue, (void *)&task,sizeof (void *));if (session->win_opened && !work_pending (&conn->xmitwork)) { session->win_opened = false;iscsi_conn_queue_work (conn); } -if (sc) { +if (!sc) { +kfifo_in (&session->mgmt_pool.queue, (void *)&task,sizeof (void *)); + }else {/* SCSI eh reuses commands to verify us */ sc->SCp.ptr =NULL ;/*
@@ -803,13 +804,13 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn,BUG_ON (conn->c_stage ==ISCSI_CONN_INITIAL_STAGE );BUG_ON (conn->c_stage ==ISCSI_CONN_STOPPED ); -if (!kfifo_out (&session->cmdpool.queue, +if (!kfifo_out (&session->mgmt_pool.queue, (void *)&task,sizeof (void *)))return NULL ;if (iscsi_alloc_itt (session, task)) {spin_lock (&session->back_lock); -kfifo_in (&session->cmdpool.queue, (void *)&task, +kfifo_in (&session->mgmt_pool.queue, (void *)&task,sizeof (void *));spin_unlock (&session->back_lock);return NULL ;
@@ -1712,14 +1713,10 @@ static void iscsi_xmitworker(struct work_struct *work) }while (rc >=0 || rc == -EAGAIN ); } -static inline struct iscsi_task *iscsi_alloc_task (struct iscsi_conn *conn, -struct scsi_cmnd *sc) +static struct iscsi_task *iscsi_init_scsi_task (struct iscsi_conn *conn, +struct scsi_cmnd *sc) { -struct iscsi_task *task; - -if (!kfifo_out (&conn->session->cmdpool.queue, - (void *) &task,sizeof (void *))) -return NULL ; +struct iscsi_task *task =scsi_cmd_priv (sc); sc->SCp.phase = conn->session->age; sc->SCp.ptr = (char *) task;
@@ -1822,22 +1819,16 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) goto fault; } -spin_lock_bh (&session->frwd_lock); -if (test_bit (ISCSI_SUSPEND_BIT , &conn->suspend_tx)) { -spin_unlock_bh (&session->frwd_lock); - reason =FAILURE_SESSION_IN_RECOVERY ; - sc->result =DID_REQUEUE <<16 ; - goto fault; - } - - task =iscsi_alloc_task (conn, sc); -if (!task) { -spin_unlock_bh (&session->frwd_lock); - reason =FAILURE_OOM ; - goto reject; - } + task =iscsi_init_scsi_task (conn, sc); +spin_lock_bh (&session->frwd_lock);if (!ihost->workq) { +if (test_bit (ISCSI_SUSPEND_BIT , &conn->suspend_tx)) { + reason =FAILURE_SESSION_IN_RECOVERY ; + sc->result =DID_REQUEUE <<16 ; + goto prepd_fault; + } +if (iscsi_check_cmdsn_window_closed (conn)) { reason =FAILURE_WINDOW_CLOSED ; goto prepd_reject;
@@ -1872,7 +1863,7 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc)spin_lock_bh (&session->back_lock);iscsi_complete_task (task,ISCSI_TASK_REQUEUE_SCSIQ );spin_unlock_bh (&session->back_lock); -reject: +ISCSI_DBG_SESSION (session,"cmd 0x%x rejected (%d)\n" , sc->cmnd[0 ], reason);return SCSI_MLQUEUE_TARGET_BUSY ;
@@ -2873,7 +2864,6 @@ struct iscsi_cls_session *struct iscsi_session *session;struct iscsi_cls_session *cls_session;int cmd_i, scsi_cmds, total_cmds = cmds_max; -struct iscsi_task *task;unsigned long flags;spin_lock_irqsave (&ihost->lock, flags);
@@ -2951,30 +2941,16 @@ struct iscsi_cls_session *if (!session->cmds) goto cmds_alloc_fail; -/* initialize SCSI PDU commands pool */ -if (iscsi_pool_init (&session->cmdpool, session->cmds_max,NULL , +/* initialize mgmt PDU pool */ +if (iscsi_pool_init (&session->mgmt_pool,ISCSI_MGMT_CMDS_MAX , + (void ***)&session->mgmt_cmds, cmd_task_size +sizeof (struct iscsi_task ))) - goto cmdpool_alloc_fail; - -/* -* This is a temp change to allow drivers that prealloc task resources -* during session setup to continue to work. The next patches convert -* the drivers to use the blk/scsi-ml init/exit callouts then this -* will be removed. -*/ -while (kfifo_out (&session->cmdpool.queue, (void *) &task, -sizeof (void *))) { - session->cmds[cmd_i++] = task; + goto mgmt_pool_alloc_fail; -if (cmd_task_size) - task->dd_data = &task[1 ]; - task->state =ISCSI_TASK_FREE ; -INIT_LIST_HEAD (&task->running); - } +for (cmd_i =0 ; cmd_i <ISCSI_MGMT_CMDS_MAX ; cmd_i++) { +struct iscsi_task *task = session->mgmt_cmds[cmd_i]; -for (cmd_i =0 ; cmd_i < session->cmds_max; cmd_i++) { - task = session->cmds[cmd_i]; -kfifo_in (&session->cmdpool.queue, (void *)&task,sizeof (void *)); +iscsi_init_task (task); }if (!try_module_get (iscsit->owner))
@@ -2988,8 +2964,8 @@ struct iscsi_cls_session * cls_session_fail:module_put (iscsit->owner); module_get_fail: -iscsi_pool_free (&session->cmdpool); -cmdpool_alloc_fail: +iscsi_pool_free (&session->mgmt_pool); +mgmt_pool_alloc_fail:kfree (session->cmds); cmds_alloc_fail:sbitmap_free (&session->itts);
@@ -3011,7 +2987,7 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)struct module *owner = cls_session->transport->owner;struct Scsi_Host *shost = session->host; -iscsi_pool_free (&session->cmdpool); +iscsi_pool_free (&session->mgmt_pool);iscsi_remove_session (cls_session);
@@ -3078,7 +3054,7 @@ struct iscsi_cls_conn */* allocate login_task used for the login/text sequences */ spin_lock_bh (&session->frwd_lock); -if (!kfifo_out (&session->cmdpool.queue, +if (!kfifo_out (&session->mgmt_pool.queue, (void *)&conn->login_task,sizeof (void *))) {spin_unlock_bh (&session->frwd_lock);
@@ -3104,7 +3080,7 @@ struct iscsi_cls_conn *iscsi_free_itt (session, conn->login_task); login_itt_fail:spin_lock_bh (&session->frwd_lock); -kfifo_in (&session->cmdpool.queue, (void *)&conn->login_task, +kfifo_in (&session->mgmt_pool.queue, (void *)&conn->login_task,sizeof (void *));spin_unlock_bh (&session->frwd_lock); login_task_alloc_fail:
@@ -3149,7 +3125,7 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)kfree (conn->local_ipaddr);/* regular RX path uses back_lock */ spin_lock_bh (&session->back_lock); -kfifo_in (&session->cmdpool.queue, (void *)&conn->login_task, +kfifo_in (&session->mgmt_pool.queue, (void *)&conn->login_task,sizeof (void *));spin_unlock_bh (&session->back_lock);iscsi_free_itt (session, conn->login_task);
include/scsi/libiscsi.h +8 -5
@@ -331,19 +331,22 @@ struct iscsi_session {* in the eh paths, cmdsn * * suspend bit and session * * resources: * -* - cmdpool kfifo_out , * -* - mgmtpool, queues */ +* - kfifo_out mgmt_pool, * +* - queues */ spinlock_t back_lock;/* protects cmdsn_exp * * cmdsn_max, * -* cmdpool kfifo_in */ +* mgmt_pool kfifo_in */ int state;/* session state */ int age;/* counts session re-opens */ int scsi_cmds_max;/* max scsi commands */ int cmds_max;/* size of cmds array */ -struct iscsi_task **cmds;/* Original Cmds arr */ -struct iscsi_pool cmdpool;/* PDU's pool */ +struct iscsi_task **cmds;/* Lookup map of all tasks */ struct sbitmap itts; + +struct iscsi_task **mgmt_cmds; +struct iscsi_pool mgmt_pool; +void *dd_data;/* LLD private data */ };
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 13/15 libiscsi: drop back_lock requirement for iscsi_put_task
In reply to Mike ChristieThis patch adds a new lock around the mgmt pool, so we no longer need the back lock when calling iscsi_put_task. This helps in the xmit path where we are taking it to drop the refcount. The next patch will allow us to completely remove the back lock from the xmit path.
--- drivers/scsi/be2iscsi/be_main.c | 6 +-- drivers/scsi/bnx2i/bnx2i_hwi.c | 2 +- drivers/scsi/libiscsi.c | 84 +++++++++++++++++------------------------ drivers/scsi/libiscsi_tcp.c | 2 +- drivers/scsi/qedi/qedi_fw.c | 11 ++---- include/scsi/libiscsi.h | 4 +- 6 files changed, 45 insertions(+), 64 deletions(-)
drivers/scsi/be2iscsi/be_main.c +3 -3
@@ -236,7 +236,7 @@ static int beiscsi_eh_abort(struct scsi_cmnd *sc)return SUCCESS ; }/* get a task ref till FW processes the req for the ICD used */ -__iscsi_get_task (abrt_task); +iscsi_get_task (abrt_task); abrt_io_task = abrt_task->dd_data; conn = abrt_task->conn; beiscsi_conn = conn->dd_data;
@@ -321,7 +321,7 @@ static int beiscsi_eh_device_reset(struct scsi_cmnd *sc) }/* get a task ref till FW processes the req for the ICD used */ -__iscsi_get_task (task); +iscsi_get_task (task); io_task = task->dd_data;/* mark WRB invalid which have been not processed by FW yet */ if (is_chip_be2_be3r (phba)) {
@@ -1245,7 +1245,7 @@ static struct sgl_handle *alloc_mgmt_sgl_handle(struct beiscsi_hba *phba)spin_lock_bh (&session->back_lock); task = pwrb_handle->pio_handle;if (task) -__iscsi_put_task (task); +iscsi_put_task (task);spin_unlock_bh (&session->back_lock); }
drivers/scsi/bnx2i/bnx2i_hwi.c +1 -1
@@ -1657,7 +1657,7 @@ static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session, task =iscsi_itt_to_task (conn, nop_in->itt &ISCSI_NOP_IN_MSG_INDEX );if (task) -__iscsi_put_task (task); +iscsi_put_task (task);spin_unlock (&session->back_lock); }
drivers/scsi/libiscsi.c +35 -49
211 lines not on this page · raw message
drivers/scsi/libiscsi_tcp.c +1 -1
@@ -558,7 +558,7 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr)return 0 ; } task->last_xfer = jiffies; -__iscsi_get_task (task); +iscsi_get_task (task); tcp_conn = conn->dd_data; rhdr = (struct iscsi_r2t_rsp *)tcp_conn->in.hdr;
drivers/scsi/qedi/qedi_fw.c +3 -8
@@ -718,11 +718,8 @@ static void qedi_mtask_completion(struct qedi_ctx *qedi,static void qedi_process_nopin_local_cmpl (struct qedi_ctx *qedi,struct iscsi_cqe_solicited *cqe, -struct iscsi_task *task, -struct qedi_conn *qedi_conn) +struct iscsi_task *task) { -struct iscsi_conn *conn = qedi_conn->cls_conn->dd_data; -struct iscsi_session *session = conn->session;struct qedi_cmd *cmd = task->dd_data; QEDI_INFO(&qedi->dbg_ctx, QEDI_LOG_UNSOL,
@@ -732,9 +729,7 @@ static void qedi_process_nopin_local_cmpl(struct qedi_ctx *qedi, cmd->state =RESPONSE_RECEIVED ;qedi_clear_task_idx (qedi, cmd->task_id); -spin_lock_bh (&session->back_lock); -__iscsi_put_task (task); -spin_unlock_bh (&session->back_lock); +iscsi_put_task (task); } static void qedi_process_cmd_cleanup_resp(struct qedi_ctx *qedi,
@@ -930,7 +925,7 @@ void qedi_fp_process_cqes(struct qedi_work *work)if ((nopout_hdr->itt ==RESERVED_ITT ) && (cqe->cqe_solicited.itid != (u16 )RESERVED_ITT )) {qedi_process_nopin_local_cmpl (qedi, &cqe->cqe_solicited, - task, q_conn); + task); }else { cqe->cqe_solicited.itid =qedi_get_itt (cqe->cqe_solicited);
include/scsi/libiscsi.h +2 -2
@@ -336,6 +336,7 @@ struct iscsi_session {spinlock_t back_lock;/* protects cmdsn_exp * * cmdsn_max, * * mgmt_pool kfifo_in */ +spinlock_t mgmt_lock;/* mgmt pool/cmds lock */ int state;/* session state */ int age;/* counts session re-opens */
@@ -459,8 +460,7 @@ extern int __iscsi_complete_pdu(struct iscsi_conn *, struct iscsi_hdr *,extern struct iscsi_task *iscsi_itt_to_task (struct iscsi_conn *,itt_t );extern void iscsi_requeue_task (struct iscsi_task *task);extern void iscsi_put_task (struct iscsi_task *task); -extern void __iscsi_put_task (struct iscsi_task *task); -extern void __iscsi_get_task (struct iscsi_task *task); +extern void iscsi_get_task (struct iscsi_task *task);extern void iscsi_complete_scsi_task (struct iscsi_task *task,uint32_t exp_cmdsn,uint32_t max_cmdsn);extern int iscsi_init_cmd_priv (struct Scsi_Host *shost,struct scsi_cmnd *cmd);
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 14/15 libiscsi: drop back_lock from xmit path
In reply to Mike ChristieWe have a proper refcount on the task so if we get a rsp while R2Ts are queued then we will not crash. We only need to check if a rsp has been processed and if we race it's ok since with a bad target we could get this rsp at any time like after dropping the lock and starting to send data so the lock use doesn't matter.
This patch just drops the lock since we will eventually either see the updated state or we will send all the data and free the task. I'm not 100% sure though and am thinking we might want to use READ/ WRITE_ONCE or use a barrier?
--- drivers/scsi/libiscsi.c | 3 --- 1 file changed, 3 deletions(-)
drivers/scsi/libiscsi.c +0 -3
@@ -1529,8 +1529,6 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, bool has_extra_ref)/* done with this task */ task->last_xfer = jiffies; } -/* regular RX path uses back_lock */ -spin_lock (&conn->session->back_lock);if (rc && task->state ==ISCSI_TASK_RUNNING ) {/* * get an extra ref that is released next time we access it
@@ -1539,7 +1537,6 @@ static int iscsi_xmit_task(struct iscsi_conn *conn, bool has_extra_ref)iscsi_get_task (task); conn->task = task; } -spin_unlock (&conn->session->back_lock); put_task:iscsi_put_task (task);
Signature · 1 line
1.8.3.1
Mike Christie
maintainerPATCH 15/15 libiscsi: convert ping_task to refcount handler
In reply to Mike ChristieThe conn_send_pdu API is evil in that it returns a pointer to a iscsi_task, but that task might have been freed already. This would happen with the ping_task code. To fix up the API so the caller can access the task if it needs to like in the ping_task case, this has conn_send_pdu grab a ref to the task for the caller. We then move the ping_task clearing to when all the refcounts are dropped, so we know the caller and a completion do not race.
--- drivers/scsi/libiscsi.c | 39 +++++++++++++++++++++------------------ include/scsi/libiscsi.h | 3 --- 2 files changed, 21 insertions(+), 21 deletions(-)
drivers/scsi/libiscsi.c +21 -18
@@ -546,13 +546,16 @@ static void iscsi_free_task(struct iscsi_task *task)return ;iscsi_free_itt (session, task); - +if (session->win_opened && !work_pending (&conn->xmitwork)) { session->win_opened = false;iscsi_conn_queue_work (conn); }if (!sc) { +if (READ_ONCE (conn->ping_task) == task) +WRITE_ONCE (conn->ping_task,NULL ); +spin_lock_bh (&session->mgmt_lock);kfifo_in (&session->mgmt_pool.queue, (void *)&task,sizeof (void *));spin_unlock_bh (&session->mgmt_lock);
@@ -603,9 +606,6 @@ static void iscsi_complete_task(struct iscsi_task *task, int state)WARN_ON_ONCE (task->state ==ISCSI_TASK_FREE ); task->state = state; -if (READ_ONCE (conn->ping_task) == task) -WRITE_ONCE (conn->ping_task,NULL ); -/* release get from queueing */ iscsi_put_task (task); }
@@ -819,6 +819,8 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, task->sc =NULL ;INIT_LIST_HEAD (&task->running); task->state =ISCSI_TASK_PENDING ; +/* Take an extra ref so the caller can access the task */ +iscsi_get_task (task);if (data_size) {memcpy (task->data, data, data_size);
@@ -846,9 +848,6 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn, task->conn->session->age); } -if (unlikely (READ_ONCE (conn->ping_task) ==INVALID_SCSI_TASK )) -WRITE_ONCE (conn->ping_task, task); -if (!ihost->workq) {if (iscsi_prep_mgmt_task (conn, task)) goto free_task;
@@ -863,6 +862,8 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn,return task; free_task: +/* drop extra count taken for caller and count from allocation */ +iscsi_put_task (task);iscsi_put_task (task);return NULL ; }
@@ -872,11 +873,15 @@ int iscsi_conn_send_pdu(struct iscsi_cls_conn *cls_conn, struct iscsi_hdr *hdr, {struct iscsi_conn *conn = cls_conn->dd_data;struct iscsi_session *session = conn->session; +struct iscsi_task *task;int err =0 ;spin_lock_bh (&session->frwd_lock); -if (!__iscsi_conn_send_pdu (conn, hdr, data, data_size)) + task =__iscsi_conn_send_pdu (conn, hdr, data, data_size); +if (!task) err = -EPERM ; +else +iscsi_put_task (task);spin_unlock_bh (&session->frwd_lock);return err; }
@@ -1047,12 +1052,6 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr)struct iscsi_nopout hdr;struct iscsi_task *task; -if (!rhdr) { -if (READ_ONCE (conn->ping_task)) -return -EINVAL ; -WRITE_ONCE (conn->ping_task,INVALID_SCSI_TASK ); - } -memset (&hdr,0 ,sizeof (struct iscsi_nopout )); hdr.opcode =ISCSI_OP_NOOP_OUT |ISCSI_OP_IMMEDIATE ; hdr.flags =ISCSI_FLAG_CMD_FINAL ;
@@ -1061,20 +1060,23 @@ static int iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr) hdr.lun = rhdr->lun; hdr.ttt = rhdr->ttt; hdr.itt =RESERVED_ITT ; - }else + }else { +if (READ_ONCE (conn->ping_task)) +return -EINVAL ; + hdr.ttt =RESERVED_ITT ; + } task =__iscsi_conn_send_pdu (conn, (struct iscsi_hdr *)&hdr,NULL ,0 );if (!task) { -if (!rhdr) -WRITE_ONCE (conn->ping_task,NULL );iscsi_conn_printk (KERN_ERR , conn,"Could not send nopout\n" );return -EIO ; }else if (!rhdr) {/* only track our nops */ conn->last_ping = jiffies; +WRITE_ONCE (conn->ping_task, task); } - +iscsi_put_task (task);return 0 ; }
@@ -1907,6 +1909,7 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,spin_lock_bh (&session->frwd_lock);return -EPERM ; } +iscsi_put_task (task); conn->tmfcmd_pdus_cnt++; conn->tmf_timer.expires = timeout *HZ + jiffies;add_timer (&conn->tmf_timer);
include/scsi/libiscsi.h +0 -3
@@ -133,9 +133,6 @@ struct iscsi_task {void *dd_data;/* driver/transport data */ }; -/* invalid scsi_task pointer */ -#define INVALID_SCSI_TASK (struct iscsi_task *)-1l -static inline int iscsi_task_has_unsol_data (struct iscsi_task *task) {return task->unsol_r2t.data_length > task->unsol_r2t.sent;
Signature · 1 line
1.8.3.1
Mike Christie
maintainerRe: [PATCH 15/15] libiscsi: convert ping_task to refcount handler
Quoted 9 lines · Mike Christie
The
conn_send_pduAPI is evil in that it returns a pointer to aiscsi_task, but that task might have been freed already. This would happen with theping_taskcode. To fix up the API so the caller can access the task if it needs to like in theping_taskcase, this hasconn_send_pdugrab a ref to the task for the caller. We then move theping_taskclearing to when all the refcounts are dropped, so we know the caller and a completion do not race.
Ignore this patch. It's wrong, because it doesn't handle the check for if the nop is from userspace or kernel.
Manish Rangankar
maintainerQuoted 22 lines
-----Original Message-----
From: Mike Christie <[email protected]>
Sent: Wednesday, December 2, 2020 3:00 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Nilesh Javali <[email protected]>; Manish Rangankar <[email protected]>; GR-QLogic-Storage-Upstream <GR-QLogic-Storage- [email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [EXT] [RFC PATCH 00/15] libiscsi: lock clean upsExternal Email
----------------------------------------------------------------------
The following patches made over Linus's current tree cleanup the locking in libiscsi so we again, for the main IO path, have the frwd lock only used in the xmit/queue path and the back lock used in the completion path and no taskqueuelock. The EH paths still use both the frwd/back lock though.
Quoted 5 lines
These patches are not ready for merging. I have only tested
iscsi_tcp. Also, even though the changes to the offload drivers look like minimal API use changes, I wanted to try and get some tests done as the changes affect the main IO and error paths.
Mike,
We will run the sanity test for qedi and bnx2i.
Thanks,
Manish