@@ -392,8 +392,8 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
392392 isert_conn -> state = ISER_CONN_INIT ;
393393 INIT_LIST_HEAD (& isert_conn -> conn_accept_node );
394394 init_completion (& isert_conn -> conn_login_comp );
395- init_waitqueue_head (& isert_conn -> conn_wait );
396- init_waitqueue_head (& isert_conn -> conn_wait_comp_err );
395+ init_completion (& isert_conn -> conn_wait );
396+ init_completion (& isert_conn -> conn_wait_comp_err );
397397 kref_init (& isert_conn -> conn_kref );
398398 kref_get (& isert_conn -> conn_kref );
399399 mutex_init (& isert_conn -> conn_mutex );
@@ -550,11 +550,11 @@ isert_disconnect_work(struct work_struct *work)
550550
551551 pr_debug ("isert_disconnect_work(): >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" );
552552 mutex_lock (& isert_conn -> conn_mutex );
553- isert_conn -> state = ISER_CONN_DOWN ;
553+ if (isert_conn -> state == ISER_CONN_UP )
554+ isert_conn -> state = ISER_CONN_TERMINATING ;
554555
555556 if (isert_conn -> post_recv_buf_count == 0 &&
556557 atomic_read (& isert_conn -> post_send_buf_count ) == 0 ) {
557- pr_debug ("Calling wake_up(&isert_conn->conn_wait);\n" );
558558 mutex_unlock (& isert_conn -> conn_mutex );
559559 goto wake_up ;
560560 }
@@ -574,7 +574,7 @@ isert_disconnect_work(struct work_struct *work)
574574 mutex_unlock (& isert_conn -> conn_mutex );
575575
576576wake_up :
577- wake_up (& isert_conn -> conn_wait );
577+ complete (& isert_conn -> conn_wait );
578578 isert_put_conn (isert_conn );
579579}
580580
@@ -1348,7 +1348,7 @@ isert_do_control_comp(struct work_struct *work)
13481348 pr_debug ("Calling iscsit_logout_post_handler >>>>>>>>>>>>>>\n" );
13491349 /*
13501350 * Call atomic_dec(&isert_conn->post_send_buf_count)
1351- * from isert_free_conn ()
1351+ * from isert_wait_conn ()
13521352 */
13531353 isert_conn -> logout_posted = true;
13541354 iscsit_logout_post_handler (cmd , cmd -> conn );
@@ -1426,31 +1426,38 @@ isert_send_completion(struct iser_tx_desc *tx_desc,
14261426}
14271427
14281428static void
1429- isert_cq_comp_err (struct iser_tx_desc * tx_desc , struct isert_conn * isert_conn )
1429+ isert_cq_tx_comp_err (struct iser_tx_desc * tx_desc , struct isert_conn * isert_conn )
14301430{
14311431 struct ib_device * ib_dev = isert_conn -> conn_cm_id -> device ;
1432+ struct isert_cmd * isert_cmd = tx_desc -> isert_cmd ;
14321433
1433- if (tx_desc ) {
1434- struct isert_cmd * isert_cmd = tx_desc -> isert_cmd ;
1434+ if (!isert_cmd )
1435+ isert_unmap_tx_desc (tx_desc , ib_dev );
1436+ else
1437+ isert_completion_put (tx_desc , isert_cmd , ib_dev );
1438+ }
14351439
1436- if (!isert_cmd )
1437- isert_unmap_tx_desc (tx_desc , ib_dev );
1438- else
1439- isert_completion_put (tx_desc , isert_cmd , ib_dev );
1440+ static void
1441+ isert_cq_rx_comp_err (struct isert_conn * isert_conn )
1442+ {
1443+ struct iscsi_conn * conn = isert_conn -> conn ;
1444+
1445+ if (isert_conn -> post_recv_buf_count )
1446+ return ;
1447+
1448+ if (conn -> sess ) {
1449+ target_sess_cmd_list_set_waiting (conn -> sess -> se_sess );
1450+ target_wait_for_sess_cmds (conn -> sess -> se_sess );
14401451 }
14411452
1442- if (isert_conn -> post_recv_buf_count == 0 &&
1443- atomic_read (& isert_conn -> post_send_buf_count ) == 0 ) {
1444- pr_debug ("isert_cq_comp_err >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" );
1445- pr_debug ("Calling wake_up from isert_cq_comp_err\n" );
1453+ while (atomic_read (& isert_conn -> post_send_buf_count ))
1454+ msleep (3000 );
14461455
1447- mutex_lock (& isert_conn -> conn_mutex );
1448- if (isert_conn -> state != ISER_CONN_DOWN )
1449- isert_conn -> state = ISER_CONN_TERMINATING ;
1450- mutex_unlock (& isert_conn -> conn_mutex );
1456+ mutex_lock (& isert_conn -> conn_mutex );
1457+ isert_conn -> state = ISER_CONN_DOWN ;
1458+ mutex_unlock (& isert_conn -> conn_mutex );
14511459
1452- wake_up (& isert_conn -> conn_wait_comp_err );
1453- }
1460+ complete (& isert_conn -> conn_wait_comp_err );
14541461}
14551462
14561463static void
@@ -1475,7 +1482,7 @@ isert_cq_tx_work(struct work_struct *work)
14751482 pr_debug ("TX wc.status != IB_WC_SUCCESS >>>>>>>>>>>>>>\n" );
14761483 pr_debug ("TX wc.status: 0x%08x\n" , wc .status );
14771484 atomic_dec (& isert_conn -> post_send_buf_count );
1478- isert_cq_comp_err (tx_desc , isert_conn );
1485+ isert_cq_tx_comp_err (tx_desc , isert_conn );
14791486 }
14801487 }
14811488
@@ -1517,7 +1524,7 @@ isert_cq_rx_work(struct work_struct *work)
15171524 pr_debug ("RX wc.status: 0x%08x\n" , wc .status );
15181525
15191526 isert_conn -> post_recv_buf_count -- ;
1520- isert_cq_comp_err ( NULL , isert_conn );
1527+ isert_cq_rx_comp_err ( isert_conn );
15211528 }
15221529 }
15231530
@@ -2218,22 +2225,11 @@ isert_free_np(struct iscsi_np *np)
22182225 kfree (isert_np );
22192226}
22202227
2221- static int isert_check_state (struct isert_conn * isert_conn , int state )
2222- {
2223- int ret ;
2224-
2225- mutex_lock (& isert_conn -> conn_mutex );
2226- ret = (isert_conn -> state == state );
2227- mutex_unlock (& isert_conn -> conn_mutex );
2228-
2229- return ret ;
2230- }
2231-
2232- static void isert_free_conn (struct iscsi_conn * conn )
2228+ static void isert_wait_conn (struct iscsi_conn * conn )
22332229{
22342230 struct isert_conn * isert_conn = conn -> context ;
22352231
2236- pr_debug ("isert_free_conn : Starting \n" );
2232+ pr_debug ("isert_wait_conn : Starting \n" );
22372233 /*
22382234 * Decrement post_send_buf_count for special case when called
22392235 * from isert_do_control_comp() -> iscsit_logout_post_handler()
@@ -2243,38 +2239,29 @@ static void isert_free_conn(struct iscsi_conn *conn)
22432239 atomic_dec (& isert_conn -> post_send_buf_count );
22442240
22452241 if (isert_conn -> conn_cm_id && isert_conn -> state != ISER_CONN_DOWN ) {
2246- pr_debug ("Calling rdma_disconnect from isert_free_conn \n" );
2242+ pr_debug ("Calling rdma_disconnect from isert_wait_conn \n" );
22472243 rdma_disconnect (isert_conn -> conn_cm_id );
22482244 }
22492245 /*
22502246 * Only wait for conn_wait_comp_err if the isert_conn made it
22512247 * into full feature phase..
22522248 */
2253- if (isert_conn -> state == ISER_CONN_UP ) {
2254- pr_debug ("isert_free_conn: Before wait_event comp_err %d\n" ,
2255- isert_conn -> state );
2256- mutex_unlock (& isert_conn -> conn_mutex );
2257-
2258- wait_event (isert_conn -> conn_wait_comp_err ,
2259- (isert_check_state (isert_conn , ISER_CONN_TERMINATING )));
2260-
2261- wait_event (isert_conn -> conn_wait ,
2262- (isert_check_state (isert_conn , ISER_CONN_DOWN )));
2263-
2264- isert_put_conn (isert_conn );
2265- return ;
2266- }
22672249 if (isert_conn -> state == ISER_CONN_INIT ) {
22682250 mutex_unlock (& isert_conn -> conn_mutex );
2269- isert_put_conn (isert_conn );
22702251 return ;
22712252 }
2272- pr_debug ( "isert_free_conn: wait_event conn_wait %d\n" ,
2273- isert_conn -> state ) ;
2253+ if ( isert_conn -> state == ISER_CONN_UP )
2254+ isert_conn -> state = ISER_CONN_TERMINATING ;
22742255 mutex_unlock (& isert_conn -> conn_mutex );
22752256
2276- wait_event (isert_conn -> conn_wait ,
2277- (isert_check_state (isert_conn , ISER_CONN_DOWN )));
2257+ wait_for_completion (& isert_conn -> conn_wait_comp_err );
2258+
2259+ wait_for_completion (& isert_conn -> conn_wait );
2260+ }
2261+
2262+ static void isert_free_conn (struct iscsi_conn * conn )
2263+ {
2264+ struct isert_conn * isert_conn = conn -> context ;
22782265
22792266 isert_put_conn (isert_conn );
22802267}
@@ -2286,6 +2273,7 @@ static struct iscsit_transport iser_target_transport = {
22862273 .iscsit_setup_np = isert_setup_np ,
22872274 .iscsit_accept_np = isert_accept_np ,
22882275 .iscsit_free_np = isert_free_np ,
2276+ .iscsit_wait_conn = isert_wait_conn ,
22892277 .iscsit_free_conn = isert_free_conn ,
22902278 .iscsit_alloc_cmd = isert_alloc_cmd ,
22912279 .iscsit_get_login_rx = isert_get_login_rx ,
0 commit comments