Module Name:    src
Committed By:   mlelstv
Date:           Wed Jun  1 05:13:07 UTC 2016

Modified Files:
        src/sys/dev/iscsi: iscsi_globals.h iscsi_ioctl.c iscsi_rcv.c
            iscsi_send.c iscsi_utils.c

Log Message:
refactor callouts
remove timed out ccbs and connections from cleanup queue when stopping timeout.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/iscsi/iscsi_globals.h \
    src/sys/dev/iscsi/iscsi_ioctl.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/iscsi/iscsi_rcv.c
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/iscsi/iscsi_send.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/iscsi/iscsi_utils.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/iscsi/iscsi_globals.h
diff -u src/sys/dev/iscsi/iscsi_globals.h:1.15 src/sys/dev/iscsi/iscsi_globals.h:1.16
--- src/sys/dev/iscsi/iscsi_globals.h:1.15	Wed Jun  1 04:19:08 2016
+++ src/sys/dev/iscsi/iscsi_globals.h	Wed Jun  1 05:13:07 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: iscsi_globals.h,v 1.15 2016/06/01 04:19:08 mlelstv Exp $	*/
+/*	$NetBSD: iscsi_globals.h,v 1.16 2016/06/01 05:13:07 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -253,6 +253,7 @@ struct ccb_s {
 
 	struct callout		timeout; /* To make sure it isn't lost */
 	TAILQ_ENTRY(ccb_s)	tchain;
+	bool			timedout;
 	int			num_timeouts;
 	/* How often we've sent out SNACK without answer */
 	int			total_tries;
@@ -373,6 +374,7 @@ struct connection_s {
 	struct callout			timeout;
 		/* Timeout for checking if connection is dead */
 	TAILQ_ENTRY(connection_s)	tchain;
+	bool				timedout;
 	int				num_timeouts;
 		/* How often we've sent out a NOP without answer */
 	uint32_t			idle_timeout_val;
@@ -698,7 +700,11 @@ void connection_timeout_co(void *);
 void ccb_timeout_co(void *);
 
 void connection_timeout(connection_t *);
+void connection_timeout_start(connection_t *, int);
+void connection_timeout_stop(connection_t *);
 void ccb_timeout(ccb_t *);
+void ccb_timeout_start(ccb_t *, int);
+void ccb_timeout_stop(ccb_t *);
 
 /* in iscsi_rcv.c */
 
Index: src/sys/dev/iscsi/iscsi_ioctl.c
diff -u src/sys/dev/iscsi/iscsi_ioctl.c:1.15 src/sys/dev/iscsi/iscsi_ioctl.c:1.16
--- src/sys/dev/iscsi/iscsi_ioctl.c:1.15	Wed Jun  1 04:07:03 2016
+++ src/sys/dev/iscsi/iscsi_ioctl.c	Wed Jun  1 05:13:07 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: iscsi_ioctl.c,v 1.15 2016/06/01 04:07:03 mlelstv Exp $	*/
+/*	$NetBSD: iscsi_ioctl.c,v 1.16 2016/06/01 05:13:07 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -497,7 +497,7 @@ kill_connection(connection_t *conn, uint
 		/* of logging in */
 		if (logout >= 0) {
 			conn->state = ST_WINDING_DOWN;
-			callout_schedule(&conn->timeout, CONNECTION_TIMEOUT);
+			connection_timeout_start(conn, CONNECTION_TIMEOUT);
 
 			if (sess->ErrorRecoveryLevel < 2 &&
 			    logout == RECOVER_CONNECTION) {
@@ -887,7 +887,7 @@ recreate_connection(iscsi_login_paramete
 			mutex_exit(&session->lock);
 			resend_pdu(ccb);
 		} else {
-			callout_schedule(&ccb->timeout, COMMAND_TIMEOUT);
+			ccb_timeout_start(ccb, COMMAND_TIMEOUT);
 		}
 	}
 
@@ -1576,22 +1576,60 @@ connection_timeout_co(void *par)
 	connection_t *conn = par;
 
 	mutex_enter(&iscsi_cleanup_mtx);
+	conn->timedout = true;
 	TAILQ_INSERT_TAIL(&iscsi_timeout_conn_list, conn, tchain);
 	mutex_exit(&iscsi_cleanup_mtx);
 	iscsi_notify_cleanup();
 }
 
+void            
+connection_timeout_start(connection_t *conn, int ticks)
+{
+	callout_schedule(&conn->timeout, ticks);
+}                           
+
+void                    
+connection_timeout_stop(connection_t *conn)
+{                                                
+	callout_halt(&conn->timeout, NULL);
+	mutex_enter(&iscsi_cleanup_mtx);
+	if (conn->timedout) {
+		TAILQ_REMOVE(&iscsi_timeout_conn_list, conn, tchain);
+		conn->timedout = false;
+	}               
+	mutex_exit(&iscsi_cleanup_mtx);
+}                        
+
 void
 ccb_timeout_co(void *par)
 {
 	ccb_t *ccb = par;
 
 	mutex_enter(&iscsi_cleanup_mtx);
+	ccb->timedout = true;
 	TAILQ_INSERT_TAIL(&iscsi_timeout_ccb_list, ccb, tchain);
 	mutex_exit(&iscsi_cleanup_mtx);
 	iscsi_notify_cleanup();
 }
 
+void    
+ccb_timeout_start(ccb_t *ccb, int ticks)
+{       
+	callout_schedule(&ccb->timeout, ticks);
+} 
+ 
+void
+ccb_timeout_stop(ccb_t *ccb)
+{
+	callout_halt(&ccb->timeout, NULL);
+	mutex_enter(&iscsi_cleanup_mtx);
+	if (ccb->timedout) {
+		TAILQ_REMOVE(&iscsi_timeout_ccb_list, ccb, tchain);
+		ccb->timedout = false;
+	} 
+	mutex_exit(&iscsi_cleanup_mtx);
+}
+
 /*
  * iscsi_cleanup_thread
  *    Global thread to handle connection and session cleanup after termination.

Index: src/sys/dev/iscsi/iscsi_rcv.c
diff -u src/sys/dev/iscsi/iscsi_rcv.c:1.11 src/sys/dev/iscsi/iscsi_rcv.c:1.12
--- src/sys/dev/iscsi/iscsi_rcv.c:1.11	Sun May 29 13:51:16 2016
+++ src/sys/dev/iscsi/iscsi_rcv.c	Wed Jun  1 05:13:07 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: iscsi_rcv.c,v 1.11 2016/05/29 13:51:16 mlelstv Exp $	*/
+/*	$NetBSD: iscsi_rcv.c,v 1.12 2016/06/01 05:13:07 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -471,7 +471,7 @@ receive_text_response_pdu(connection_t *
 	}
 
 	if (req_ccb->pdu_waiting != NULL) {
-		callout_schedule(&req_ccb->timeout, COMMAND_TIMEOUT);
+		ccb_timeout_start(req_ccb, COMMAND_TIMEOUT);
 		req_ccb->num_timeouts = 0;
 	}
 
@@ -542,7 +542,7 @@ receive_logout_pdu(connection_t *conn, p
 		conn->state = ST_SETTLING;
 		conn->loggedout = (response) ? LOGOUT_FAILED : LOGOUT_SUCCESS;
 
-		callout_stop(&conn->timeout);
+		connection_timeout_stop(conn);
 
 		/* let send thread take over next step of cleanup */
 		cv_broadcast(&conn->conn_cv);
@@ -578,7 +578,7 @@ receive_data_in_pdu(connection_t *conn, 
 	req_ccb->flags |= CCBF_GOT_RSP;
 
 	if (req_ccb->pdu_waiting != NULL) {
-		callout_schedule(&req_ccb->timeout, COMMAND_TIMEOUT);
+		ccb_timeout_start(req_ccb, COMMAND_TIMEOUT);
 		req_ccb->num_timeouts = 0;
 	}
 
@@ -659,7 +659,7 @@ receive_r2t_pdu(connection_t *conn, pdu_
 
 	if (req_ccb != NULL) {
 		if (req_ccb->pdu_waiting != NULL) {
-			callout_schedule(&req_ccb->timeout, COMMAND_TIMEOUT);
+			ccb_timeout_start(req_ccb, COMMAND_TIMEOUT);
 			req_ccb->num_timeouts = 0;
 		}
 		send_data_out(conn, pdu, req_ccb, CCBDISP_NOWAIT, TRUE);
@@ -702,7 +702,7 @@ receive_command_response_pdu(connection_
 	}
 
 	if (req_ccb->pdu_waiting != NULL) {
-		callout_schedule(&req_ccb->timeout, COMMAND_TIMEOUT);
+		ccb_timeout_start(req_ccb, COMMAND_TIMEOUT);
 		req_ccb->num_timeouts = 0;
 	}
 
@@ -1095,9 +1095,9 @@ receive_pdu(connection_t *conn, pdu_t *p
 	/* received a valid frame, reset timeout */
 	if ((pdu->pdu.Opcode & OPCODE_MASK) == TOP_NOP_In &&
 	    TAILQ_EMPTY(&conn->ccbs_waiting))
-		callout_schedule(&conn->timeout, conn->idle_timeout_val);
+		connection_timeout_start(conn, conn->idle_timeout_val);
 	else
-		callout_schedule(&conn->timeout, CONNECTION_TIMEOUT);
+		connection_timeout_start(conn, CONNECTION_TIMEOUT);
 	conn->num_timeouts = 0;
 
 	/*

Index: src/sys/dev/iscsi/iscsi_send.c
diff -u src/sys/dev/iscsi/iscsi_send.c:1.17 src/sys/dev/iscsi/iscsi_send.c:1.18
--- src/sys/dev/iscsi/iscsi_send.c:1.17	Wed Jun  1 04:19:08 2016
+++ src/sys/dev/iscsi/iscsi_send.c	Wed Jun  1 05:13:07 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: iscsi_send.c,v 1.17 2016/06/01 04:19:08 mlelstv Exp $	*/
+/*	$NetBSD: iscsi_send.c,v 1.18 2016/06/01 05:13:07 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2004,2005,2006,2011 The NetBSD Foundation, Inc.
@@ -267,7 +267,7 @@ reassign_tasks(connection_t *oldconn)
 			mutex_exit(&sess->lock);
 			resend_pdu(ccb);
 		} else {
-			callout_schedule(&ccb->timeout, COMMAND_TIMEOUT);
+			ccb_timeout_start(ccb, COMMAND_TIMEOUT);
 		}
 		DEBC(conn, 1, ("Reassign ccb %p, no_tm=%d, rc=%d\n",
 					   ccb, no_tm, rc));
@@ -333,7 +333,7 @@ iscsi_send_thread(void *par)
 		 *    Here this thread takes over cleanup of the terminating connection.
 		 * ------------------------------------------------------------------------
 		 */
-		callout_stop(&conn->timeout);
+		connection_timeout_stop(conn);
 		conn->idle_timeout_val = CONNECTION_IDLE_TIMEOUT;
 
 		fp = conn->sock;
@@ -354,7 +354,7 @@ iscsi_send_thread(void *par)
 					ccb,&ccb->timeout));
 				wake_ccb(ccb, conn->terminating);
 			} else {
-				callout_stop(&ccb->timeout);
+				ccb_timeout_stop(ccb);
 				ccb->num_timeouts = 0;
 			}
 		}
@@ -377,7 +377,7 @@ iscsi_send_thread(void *par)
 		/* If there's another connection available, transfer pending tasks */
 		if (sess->active_connections &&
 			TAILQ_FIRST(&conn->ccbs_waiting) != NULL) {
-			DEBC(conn, 1, ("Reassign Tasks\n"));
+			
 			reassign_tasks(conn);
 		} else if (!conn->destroy && conn->Time2Wait) {
 			DEBC(conn, 1, ("Time2Wait\n"));
@@ -478,7 +478,7 @@ send_pdu(ccb_t *ccb, pdu_t *pdu, ccb_dis
 	cv_broadcast(&conn->conn_cv);
 
 	if (cdisp != CCBDISP_NOWAIT) {
-		callout_schedule(&ccb->timeout, COMMAND_TIMEOUT);
+		ccb_timeout_start(ccb, COMMAND_TIMEOUT);
 
 		if (prev_cdisp <= CCBDISP_NOWAIT)
 			suspend_ccb(ccb, TRUE);
@@ -533,7 +533,7 @@ resend_pdu(ccb_t *ccb)
 	} else {
 		TAILQ_INSERT_TAIL(&conn->pdus_to_send, pdu, send_chain);
 	}
-	callout_schedule(&ccb->timeout, COMMAND_TIMEOUT);
+	ccb_timeout_start(ccb, COMMAND_TIMEOUT);
 	mutex_exit(&conn->lock);
 
 	cv_broadcast(&conn->conn_cv);
@@ -1594,7 +1594,7 @@ connection_timeout(connection_t *conn)
 		if (conn->state == ST_FULL_FEATURE)
 			send_nop_out(conn, NULL);
 
-		callout_schedule(&conn->timeout, CONNECTION_TIMEOUT);
+		connection_timeout_start(conn, CONNECTION_TIMEOUT);
 	}
 }
 
@@ -1631,7 +1631,7 @@ ccb_timeout(ccb_t *ccb)
 			/* request resend of all missing status */
 			snack_missing(conn, NULL, SNACK_STATUS_NAK, 0, 0);
 		}
-		callout_schedule(&ccb->timeout, COMMAND_TIMEOUT);
+		ccb_timeout_start(ccb, COMMAND_TIMEOUT);
 	}
 }
 

Index: src/sys/dev/iscsi/iscsi_utils.c
diff -u src/sys/dev/iscsi/iscsi_utils.c:1.10 src/sys/dev/iscsi/iscsi_utils.c:1.11
--- src/sys/dev/iscsi/iscsi_utils.c:1.10	Wed Jun  1 04:19:08 2016
+++ src/sys/dev/iscsi/iscsi_utils.c	Wed Jun  1 05:13:07 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: iscsi_utils.c,v 1.10 2016/06/01 04:19:08 mlelstv Exp $	*/
+/*	$NetBSD: iscsi_utils.c,v 1.11 2016/06/01 05:13:07 mlelstv Exp $	*/
 
 /*-
  * Copyright (c) 2004,2005,2006,2008 The NetBSD Foundation, Inc.
@@ -403,7 +403,7 @@ wake_ccb(ccb_t *ccb, uint32_t status)
 		ccb, ccb->disp));
 #endif
 
-	callout_stop(&ccb->timeout);
+	ccb_timeout_stop(ccb);
 
 	mutex_enter(&conn->lock);
 	disp = ccb->disp;

Reply via email to