[openib-general] [PATCH] iser: move from the iscsi connection fields directly related to the rdma conn

Or Gerlitz ogerlitz at voltaire.com
Mon Feb 13 06:56:17 PST 2006


moved from struct iscsi_iser_conn to iser_conn all the fields related to the 
rdma connection and simplified a flow related to its establishment/teardown

Signed-off-by: Or Gerlitz <ogerlitz at voltaire.com>

Index: iscsi_iser.h
===================================================================
--- iscsi_iser.h	(revision 5382)
+++ iscsi_iser.h	(revision 5383)
@@ -260,10 +260,12 @@ struct iser_conn
 	struct ib_qp	             *qp;
 	struct ib_fmr_pool           *fmr_pool;
 	int                          disc_evt_flag;/* may a state reflect it? */
-	wait_queue_head_t	     connect_wait_q;
+	wait_queue_head_t	     wait;
 	struct iscsi_iser_conn       *p_iscsi_conn;
-	u32                          dst_addr;
-	u16                          dst_port;
+	atomic_t                     post_recv_buf_count;
+	atomic_t                     post_send_buf_count;
+	struct work_struct           comperror_work;     /* conn term sleepabl*/
+	char 			     name[ISER_OBJECT_NAME_SIZE];
 };
 
 struct iscsi_iser_queue {
@@ -314,11 +316,6 @@ struct iscsi_iser_conn {
 
 	struct iser_conn             *ib_conn;           /* iSER IB conn      */
 	int                          ff_mode_enabled;    /* To be removed ??? */
-	atomic_t                     post_recv_buf_count;
-	atomic_t                     post_send_buf_count;
-	wait_queue_head_t            disconnect_wait_q;  /* used by sync term */
-	struct work_struct           comperror_work;     /* conn term sleepabl*/
-	char 			     name[ISER_OBJECT_NAME_SIZE];
 };
 
 struct iscsi_iser_session {
@@ -503,6 +500,4 @@ void iser_unreg_mem(struct iser_mem_reg 
 
 int  iser_post_recv(struct iser_desc *p_rx_desc);
 int  iser_start_send(struct iser_desc *p_tx_desc);
-
-void iser_comp_error_worker(void *data);
 #endif
Index: iser_verbs.c
===================================================================
--- iser_verbs.c	(revision 5382)
+++ iser_verbs.c	(revision 5383)
@@ -49,6 +49,7 @@
 
 static void iser_cq_tasklet_fn(unsigned long data);
 static void iser_cq_callback(struct ib_cq *cq, void *cq_context);
+static void iser_comp_error_worker(void *data);
 
 static void iser_cq_event_callback(struct ib_event *cause, void *context)
 {
@@ -321,7 +322,7 @@ int iser_conn_sync_terminate(struct iscs
 		if (err)
 			iser_bug("Failed to disc.gracefully, conn: 0x%p\n",
 				 p_iser_conn);
-		wait_event_interruptible(p_iser_conn->disconnect_wait_q,
+		wait_event_interruptible(ib_conn->wait,
 					 (atomic_read(&ib_conn->state) ==
 					  ISER_CONN_DOWN));
 		break;
@@ -330,7 +331,7 @@ int iser_conn_sync_terminate(struct iscs
 	 * conn stop, in that case the state is aligned to SYNC              */
 	case ISER_CONN_ASYNC_TERM:
 		atomic_set(&ib_conn->state, ISER_CONN_SYNC_TERM);
-		wait_event_interruptible(p_iser_conn->disconnect_wait_q,
+		wait_event_interruptible(ib_conn->wait,
 					 (atomic_read(&ib_conn->state) ==
 					  ISER_CONN_DOWN));
 		break;
@@ -367,7 +368,7 @@ void iser_conn_async_terminate(struct is
 
 /* iser_complete_conn_termination - Checks if the conn may be terminated *
  * and terminates if possible                                            */
-static void iser_complete_conn_termination(struct iscsi_iser_conn *p_iser_conn)
+static void iser_complete_conn_termination(struct iser_conn *p_iser_conn)
 {
 	int rcv_buf_count;
 	int send_buf_count;
@@ -377,16 +378,16 @@ static void iser_complete_conn_terminati
 
 	/* Check if this conn may be terminated now */
 	if (rcv_buf_count == 0 &&
-	    send_buf_count == 0 && p_iser_conn->ib_conn->disc_evt_flag) {
+	    send_buf_count == 0 && p_iser_conn->disc_evt_flag) {
 		unsigned int cur_conn_state;
 
-		cur_conn_state = atomic_read(&p_iser_conn->ib_conn->state);
+		cur_conn_state = atomic_read(&p_iser_conn->state);
 		if (cur_conn_state != ISER_CONN_ASYNC_TERM &&
 		    cur_conn_state != ISER_CONN_SYNC_TERM) {
 			iser_bug("Illegal state (%s)",
-				 iser_conn_get_state_name(p_iser_conn->ib_conn));
+				 iser_conn_get_state_name(p_iser_conn));
 		}
-		atomic_set(&p_iser_conn->ib_conn->state, ISER_CONN_DOWN);
+		atomic_set(&p_iser_conn->state, ISER_CONN_DOWN);
 
 		iser_dbg("Conn:0x%p, may be terminated:%s\n", p_iser_conn,
 			 (cur_conn_state == ISER_CONN_ASYNC_TERM ?
@@ -394,19 +395,20 @@ static void iser_complete_conn_terminati
 
 		/* Notify the upper layer about asynch terminations */
 		if (cur_conn_state == ISER_CONN_ASYNC_TERM)
-			iscsi_iser_conn_failure(p_iser_conn,
+			iscsi_iser_conn_failure(p_iser_conn->p_iscsi_conn,
 						ISCSI_ERR_CONN_FAILED);
 
 		if (cur_conn_state == ISER_CONN_SYNC_TERM)
-			wake_up_interruptible(&p_iser_conn->disconnect_wait_q);
+			wake_up_interruptible(
+				      &p_iser_conn->wait);
 		else
-			iser_conn_release(p_iser_conn->ib_conn);
+			iser_conn_release(p_iser_conn);
 	} else {
 		iser_dbg("Conn:0x%p not terminated now, disc_event:%d,"
 			 " post_recv_cnt:%d, post_send_cnt:%d, state:%s)\n",
-			 p_iser_conn, p_iser_conn->ib_conn->disc_evt_flag,
+			 p_iser_conn, p_iser_conn->disc_evt_flag,
 			 rcv_buf_count, send_buf_count,
-			 iser_conn_get_state_name(p_iser_conn->ib_conn));
+			 iser_conn_get_state_name(p_iser_conn));
 	}
 }
 
@@ -417,7 +419,7 @@ static void iser_connect_error(struct rd
 
 	if (atomic_read(&p_iser_conn->state) == ISER_CONN_PENDING) {
 		atomic_set(&p_iser_conn->state, ISER_CONN_DOWN);
-		wake_up_interruptible(&p_iser_conn->connect_wait_q);
+		wake_up_interruptible(&p_iser_conn->wait);
 	} else
 		iser_err("Unexpected evt for conn.state: %s\n",
 			 iser_conn_get_state_name(p_iser_conn));
@@ -480,7 +482,7 @@ static void iser_connected_handler(struc
 
 	p_iser_conn = (struct iser_conn *)cma_id->context;
 	atomic_set(&p_iser_conn->state, ISER_CONN_UP);
-	wake_up_interruptible(&p_iser_conn->connect_wait_q);
+	wake_up_interruptible(&p_iser_conn->wait);
 }
 
 static void iser_disconnected_handler(struct rdma_cm_id *cma_id)
@@ -496,7 +498,7 @@ static void iser_disconnected_handler(st
 	/* terminated asynchronously from the iSCSI layer's perspective.  */
 	if (atomic_read(&p_iser_conn->state) == ISER_CONN_PENDING) {
 		atomic_set(&p_iser_conn->state, ISER_CONN_DOWN);
-		wake_up_interruptible(&p_iser_conn->connect_wait_q);
+		wake_up_interruptible(&p_iser_conn->wait);
 	} else {
 		if (atomic_read(&p_iser_conn->state) == ISER_CONN_UP) {
 			atomic_set(&p_iser_conn->state, ISER_CONN_ASYNC_TERM);
@@ -505,7 +507,7 @@ static void iser_disconnected_handler(st
 		}
 		/* Complete the termination process if possible	 */
 		/* (no events pending)				 */
-		iser_complete_conn_termination(p_iser_conn->p_iscsi_conn);
+		iser_complete_conn_termination(p_iser_conn);
 	}
 }
 
@@ -553,7 +555,11 @@ void iser_conn_init(struct iser_conn *p_
 {
 	memset(p_iser_conn, 0, sizeof(struct iser_conn));
 	atomic_set(&p_iser_conn->state, ISER_CONN_INIT);
-	init_waitqueue_head(&p_iser_conn->connect_wait_q);
+	init_waitqueue_head(&p_iser_conn->wait);
+	atomic_set(&p_iser_conn->post_recv_buf_count, 0);
+	atomic_set(&p_iser_conn->post_send_buf_count, 0);
+	INIT_WORK(&p_iser_conn->comperror_work, iser_comp_error_worker,
+		  p_iser_conn);
 }
 
  /**
@@ -567,8 +573,8 @@ int iser_connect(struct iser_conn   *p_i
 	struct sockaddr *src, *dst;
 	int err = 0;
 
-	p_iser_conn->dst_addr = dst_addr->sin_addr.s_addr;
-	p_iser_conn->dst_port = dst_addr->sin_port;
+	sprintf(p_iser_conn->name,"%d.%d.%d.%d:%d",
+		NIPQUAD(dst_addr->sin_addr.s_addr), dst_addr->sin_port);
 
 	/* the adaptor is known only --after-- address resolution */
 	p_iser_conn->p_adaptor = NULL;
@@ -596,7 +602,7 @@ int iser_connect(struct iser_conn   *p_i
 		goto connect_failure;
 	}
 
-	wait_event_interruptible(p_iser_conn->connect_wait_q,
+	wait_event_interruptible(p_iser_conn->wait,
 			 atomic_read(&p_iser_conn->state) != ISER_CONN_PENDING);
 
 	if (atomic_read(&p_iser_conn->state) != ISER_CONN_UP) {
@@ -762,9 +768,11 @@ int iser_post_recv(struct iser_desc *p_r
 	recv_wr.num_sge = p_recv_dto->regd_vector_len;
 	recv_wr.wr_id	= (unsigned long)p_rx_desc;
 
+	atomic_inc(&p_iser_conn->ib_conn->post_recv_buf_count);
 	ib_ret	= ib_post_recv (p_iser_conn->ib_conn->qp, &recv_wr, &recv_wr_failed);
 	if (ib_ret) {
 		iser_err("ib_post_recv failed ret=%d\n", ib_ret);
+		atomic_dec(&p_iser_conn->ib_conn->post_recv_buf_count);
 		ret_val = -1;
 	}
 
@@ -800,37 +808,37 @@ int iser_start_send(struct iser_desc *p_
 	send_wr.opcode	   = IB_WR_SEND;
 	send_wr.send_flags = p_dto->notify_enable ? IB_SEND_SIGNALED : 0;
 
-	atomic_inc(&p_iser_conn->post_send_buf_count);
+	atomic_inc(&p_iser_conn->ib_conn->post_send_buf_count);
 
 	ib_ret = ib_post_send(p_iser_conn->ib_conn->qp, &send_wr, &send_wr_failed);
 	if (ib_ret) {
 		iser_err("Failed to start SEND DTO, p_dto: 0x%p, IOV len: %d\n",
 			 p_dto, p_dto->regd_vector_len);
 		iser_err("ib_post_send failed, ret:%d\n", ib_ret);
-		atomic_dec(&p_iser_conn->post_send_buf_count);
+		atomic_dec(&p_iser_conn->ib_conn->post_send_buf_count);
 		ret_val = -1;
 	}
 
 	return ret_val;
 }
 
-void iser_comp_error_worker(void *data)
+static void iser_comp_error_worker(void *data)
 {
-	struct iscsi_iser_conn *p_iser_conn = data;
+	struct iser_conn *p_iser_conn = data;
 
 	if (p_iser_conn == NULL)
 		iser_bug("NULL p_desc->p_conn \n");
 
-	if (atomic_read(&p_iser_conn->ib_conn->state) == ISER_CONN_UP)
-		iser_conn_async_terminate(p_iser_conn->ib_conn);
+	if (atomic_read(&p_iser_conn->state) == ISER_CONN_UP)
+		iser_conn_async_terminate(p_iser_conn);
 
 	iser_complete_conn_termination(p_iser_conn);
 }
 
 static void iser_handle_comp_error(struct iser_desc *p_desc)
 {
-	struct iser_dto        *p_dto       = &p_desc->dto;
-	struct iscsi_iser_conn *p_iser_conn = p_dto->p_conn;
+	struct iser_dto  *p_dto       = &p_desc->dto;
+	struct iser_conn *p_iser_conn = p_dto->p_conn->ib_conn;
 
 	iser_dto_buffs_release(p_dto);
 
@@ -857,6 +865,7 @@ static void iser_cq_tasklet_fn(unsigned 
 	 struct iser_desc	*p_desc;
 	 unsigned long	    	xfer_len;
 
+
 	while (ib_poll_cq(cq, 1, &wc) == 1) {
 		p_desc	 = (struct iser_desc *) (unsigned long) wc.wr_id;
 
Index: iser_initiator.c
===================================================================
--- iser_initiator.c	(revision 5382)
+++ iser_initiator.c	(revision 5383)
@@ -304,7 +304,6 @@ static int iser_post_receive_control(str
 	iser_dto_add_regd_buff(p_recv_dto, p_regd_data,
 			       USE_NO_OFFSET, USE_ENTIRE_SIZE);
 
-	atomic_inc(&p_iser_conn->post_recv_buf_count);
 	err = iser_post_recv(rx_desc);
 
 post_receive_control_exit:
@@ -313,7 +312,6 @@ post_receive_control_exit:
 		if (rx_desc->data != NULL)
 			kfree(rx_desc->data);
 		kmem_cache_free(ig.desc_cache, rx_desc);
-		atomic_dec(&p_iser_conn->post_recv_buf_count);
 	}
 	return err;
 }
@@ -355,9 +353,9 @@ int iser_conn_set_full_featured_mode(str
 
 	/* Check that there is no posted recv or send buffers left - */
 	/* they must be consumed during the login phase */
-	if (atomic_read(&p_iser_conn->post_recv_buf_count) != 0)
+	if (atomic_read(&p_iser_conn->ib_conn->post_recv_buf_count) != 0)
 		iser_bug("Number of currently posted recv bufs non-zero\n");
-	if (atomic_read(&p_iser_conn->post_send_buf_count) != 0)
+	if (atomic_read(&p_iser_conn->ib_conn->post_send_buf_count) != 0)
 		iser_bug("Number of currently posted send bufs non-zero\n");
 
 	/* Initial post receive buffers */
@@ -384,7 +382,8 @@ iser_check_xmit(struct iscsi_iser_conn  
 	int rc = 0;
 
 	spin_lock_bh(&conn->lock);
-	if (atomic_read(&conn->post_send_buf_count) == ISER_QP_MAX_REQ_DTOS) {
+	if (atomic_read(&conn->ib_conn->post_send_buf_count) ==
+	    ISER_QP_MAX_REQ_DTOS) {
 		iser_dbg("%ld can't xmit task %p, suspending tx\n",jiffies,task);
 		set_bit(SUSPEND_BIT, &conn->suspend_tx);
 		rc = -EAGAIN;
@@ -462,7 +461,7 @@ int iser_send_command(struct iscsi_iser_
 		return 0;
 
 send_command_error:
-	if (p_send_dto != NULL) 
+	if (p_send_dto != NULL)
 		iser_dto_buffs_release(p_send_dto);
 	if (p_iser_conn != NULL) {
 		/* drop the conn, open tasks are deleted during shutdown */
@@ -684,7 +683,7 @@ void iser_rcv_completion(struct iser_des
 	 * task eliminates the need to worry on tasks which are completed in   *
 	 * parallel to the execution of iser_conn_term. So the code that waits *
          * for the posted rx bufs refcount to become zero handles everything   */
-	atomic_dec(&p_iser_conn->post_recv_buf_count);
+	atomic_dec(&p_iser_conn->ib_conn->post_recv_buf_count);
 }
 
 void iser_snd_completion(struct iser_desc *p_tx_desc)
@@ -699,7 +698,7 @@ void iser_snd_completion(struct iser_des
 	if (p_tx_desc->type == ISCSI_TX_DATAOUT)
 		kmem_cache_free(ig.desc_cache, p_tx_desc);
 
-	atomic_dec(&p_iser_conn->post_send_buf_count);
+	atomic_dec(&p_iser_conn->ib_conn->post_send_buf_count);
 
 	spin_lock(&p_iser_conn->lock);
 	if (p_iser_conn->suspend_tx) {
Index: iscsi_iser.c
===================================================================
--- iscsi_iser.c	(revision 5382)
+++ iscsi_iser.c	(revision 5383)
@@ -921,12 +921,7 @@ iscsi_iser_conn_create(iscsi_sessionh_t 
 	init_timer(&conn->tmabort_timer);
 	init_MUTEX(&conn->xmitsema);
 	init_waitqueue_head(&conn->ehwait);
-
-	atomic_set(&conn->post_recv_buf_count, 0);
-	atomic_set(&conn->post_send_buf_count, 0);
-	init_waitqueue_head(&conn->disconnect_wait_q);
 	spin_lock_init(&conn->lock);
-	INIT_WORK(&conn->comperror_work, iser_comp_error_worker, conn);
 
 	return iscsi_handle(conn);
 
@@ -1069,8 +1064,6 @@ iscsi_iser_conn_bind(iscsi_sessionh_t se
 	p_iser_conn = iser_conn_from_sock(sock);
 	p_iser_conn->p_iscsi_conn = conn;
 	conn->ib_conn             = p_iser_conn;
-	sprintf(conn->name,"%d.%d.%d.%d:%d",
-		NIPQUAD(p_iser_conn->dst_addr),p_iser_conn->dst_port);
 
 	if (is_leading)
 		session->leadconn = conn;




More information about the general mailing list