[openib-general] [PATCH] iser updates for 2.6.16

Or Gerlitz ogerlitz at voltaire.com
Sun Mar 5 07:28:43 PST 2006


The patch below would be commited to the opeinib trunk following the 
release of 2.6.16, it is needs for having iser compiles and working 
under this kernel.

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

Index: iscsi_iser.h
===================================================================
--- iscsi_iser.h	(revision 226)
+++ iscsi_iser.h	(working copy)
@@ -298,7 +298,10 @@ struct iscsi_iser_queue {
 	int			     max;	 /* Max number of elements */
 };
 
+struct iscsi_cls_conn;
+
 struct iscsi_iser_conn {
+	struct iscsi_cls_conn	     *cls_conn;	 /* ptr to class connection */
 	struct socket                *sock;      /* iSER socket       */
 	struct iser_conn             *ib_conn;   /* iSER IB conn      */
 	int			     stop_stage; /* conn_stop() flag: *
Index: iscsi_iser.c
===================================================================
--- iscsi_iser.c	(revision 226)
+++ iscsi_iser.c	(working copy)
@@ -120,7 +120,7 @@ iscsi_iser_conn_failure(struct iscsi_ise
 		session->state = ISCSI_STATE_FAILED;
 	spin_unlock_irqrestore(&session->lock, flags);
 	set_bit(SUSPEND_BIT, &conn->suspend_tx);
-	iscsi_conn_error(iscsi_handle(conn), err);
+	iscsi_conn_error(conn->cls_conn, err);
 }
 
 static inline int
@@ -320,7 +320,7 @@ iscsi_iser_recv(struct iscsi_iser_conn *
 			if (rc)
 				break;
 
-			rc = iscsi_recv_pdu(iscsi_handle(conn), hdr,
+			rc = iscsi_recv_pdu(conn->cls_conn, hdr,
 					    rx_data, rx_data_len);
 			if (conn->login_mtask != mtask) {
 				spin_lock(&session->lock);
@@ -364,7 +364,7 @@ iscsi_iser_recv(struct iscsi_iser_conn *
 				break;
 			conn->exp_statsn = be32_to_cpu(hdr->statsn) + 1;
 
-			rc = iscsi_recv_pdu(iscsi_handle(conn), hdr,
+			rc = iscsi_recv_pdu(conn->cls_conn, hdr,
 					    NULL, 0);
 			mtask = (struct iscsi_iser_mgmt_task *)
 				session->mgmt_cmds[itt -
@@ -386,7 +386,7 @@ iscsi_iser_recv(struct iscsi_iser_conn *
 			rc = iscsi_iser_check_assign_cmdsn(session,
 					 (struct iscsi_nopin*)hdr);
 			if (!rc && hdr->ttt != ISCSI_RESERVED_TAG)
-				rc = iscsi_recv_pdu(iscsi_handle(conn),
+				rc = iscsi_recv_pdu(conn->cls_conn,
 						    hdr, NULL, 0);
 			break;
 		case ISCSI_OP_REJECT:
@@ -721,7 +721,7 @@ iscsi_iser_xmitworker(void *data)
 	 */
 	mutex_lock(&conn->xmitmutex);
 	if (iscsi_iser_data_xmit(conn))
-		schedule_work(&conn->xmitwork);
+		scsi_queue_work(conn->session->host, &conn->xmitwork);
 	mutex_unlock(&conn->xmitmutex);
 }
 
@@ -796,15 +796,7 @@ iscsi_iser_queuecommand(struct scsi_cmnd
 		  session->cmdsn, session->max_cmdsn - session->exp_cmdsn + 1);
 	spin_unlock(&session->lock);
 
-	if (!in_interrupt() && mutex_trylock(&conn->xmitmutex)) {
-		spin_unlock_irq(host->host_lock);
-		if (iscsi_iser_data_xmit(conn))
-			schedule_work(&conn->xmitwork);
-		mutex_unlock(&conn->xmitmutex);
-		spin_lock_irq(host->host_lock);
-	} else
-		schedule_work(&conn->xmitwork);
-
+	scsi_queue_work(host, &conn->xmitwork);
 	return 0;
 
 reject:
@@ -882,27 +874,25 @@ iscsi_iser_pool_free(struct iscsi_iser_q
 	kfree(items);
 }
 
-static iscsi_connh_t
-iscsi_iser_conn_create(iscsi_sessionh_t sessionh,
-		       uint32_t conn_idx)
+static struct iscsi_cls_conn *
+iscsi_iser_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
 {
-	struct iscsi_iser_session *session = iscsi_ptr(sessionh);
-	struct iscsi_iser_conn *conn = NULL;
+	struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
+	struct iscsi_iser_session *session = iscsi_hostdata(shost->hostdata);
+	struct iscsi_iser_conn *conn;
+	struct iscsi_cls_conn *cls_conn;
 
-	conn = kzalloc(sizeof *conn, GFP_KERNEL);
-	if (conn == NULL) {
-		goto conn_alloc_fail;
-	}
+	cls_conn = iscsi_create_conn(cls_session, conn_idx);
+	if (!cls_conn)
+		return NULL;
+	conn = cls_conn->dd_data;
+	memset(conn, 0, sizeof(*conn));
 
-	/* Init the connection */
+	conn->cls_conn = cls_conn;
 	conn->c_stage = ISCSI_CONN_INITIAL_STAGE;
-
-	conn->tmabort_state = TMABORT_INITIAL;
-
-	conn->session = session;
 	conn->id = conn_idx;
-
 	conn->exp_statsn = 0;
+	conn->tmabort_state = TMABORT_INITIAL;
 
 	/* initialize general xmit PDU commands queue */
 	conn->xmitqueue = kfifo_alloc(session->cmds_max * sizeof(void*),
@@ -938,7 +928,7 @@ iscsi_iser_conn_create(iscsi_sessionh_t 
 	init_waitqueue_head(&conn->ehwait);
 	spin_lock_init(&conn->lock);
 
-	return iscsi_handle(conn);
+	return cls_conn;
 
 login_mtask_alloc_fail:
 	kfifo_free(conn->mgmtqueue);
@@ -947,15 +937,14 @@ mgmtqueue_alloc_fail:
 immqueue_alloc_fail:
 	kfifo_free(conn->xmitqueue);
 xmitqueue_alloc_fail:
-	kfree(conn);
-conn_alloc_fail:
-	return iscsi_handle(NULL);
+	iscsi_destroy_conn(cls_conn);
+	return NULL;
 }
 
 static void
-iscsi_iser_conn_destroy(iscsi_connh_t connh)
+iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
 {
-	struct iscsi_iser_conn *conn = iscsi_ptr(connh);
+	struct iscsi_iser_conn *conn = cls_conn->dd_data;
 	struct iscsi_iser_session *session = conn->session;
 	unsigned long flags;
 
@@ -1019,16 +1008,18 @@ iscsi_iser_conn_destroy(iscsi_connh_t co
 	kfifo_free(conn->xmitqueue);
 	kfifo_free(conn->immqueue);
 	kfifo_free(conn->mgmtqueue);
-	kfree(conn);
+
+	iscsi_destroy_conn(cls_conn);
 }
 
 static int
-iscsi_iser_conn_bind(iscsi_sessionh_t sessionh,
-		     iscsi_connh_t connh, uint32_t transport_fd,
+iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
+		     struct iscsi_cls_conn *cls_conn, uint32_t transport_fd,
 		     int is_leading)
 {
-	struct iscsi_iser_session *session = iscsi_ptr(sessionh);
-	struct iscsi_iser_conn *tmp = ERR_PTR(-EEXIST), *conn = iscsi_ptr(connh);
+	struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
+	struct iscsi_iser_session *session = iscsi_hostdata(shost->hostdata);
+	struct iscsi_iser_conn *tmp = ERR_PTR(-EEXIST), *conn = cls_conn->dd_data;
 	struct socket *sock;
 	struct iser_conn *ib_conn;
 	int error = 0;
@@ -1084,9 +1075,9 @@ iscsi_iser_conn_bind(iscsi_sessionh_t se
 }
 
 static int
-iscsi_iser_conn_start(iscsi_connh_t connh)
+iscsi_iser_conn_start(struct iscsi_cls_conn *cls_conn)
 {
-	struct iscsi_iser_conn *conn = iscsi_ptr(connh);
+	struct iscsi_iser_conn *conn = cls_conn->dd_data;
 	struct iscsi_iser_session *session = conn->session;
 	int error = 0;
 
@@ -1130,9 +1121,9 @@ iscsi_iser_conn_start(iscsi_connh_t conn
 }
 
 static void
-iscsi_iser_conn_stop(iscsi_connh_t connh, int flag)
+iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
 {
-	struct iscsi_iser_conn *conn = iscsi_ptr(connh);
+	struct iscsi_iser_conn *conn = cls_conn->dd_data;
 	struct iscsi_iser_session *session = conn->session;
 	struct iscsi_iser_cmd_task *ctask;
 	struct iscsi_iser_mgmt_task *mtask;
@@ -1142,7 +1133,7 @@ iscsi_iser_conn_stop(iscsi_connh_t connh
 
 	mutex_lock(&conn->xmitmutex);
 
-       spin_lock_irqsave(session->host->host_lock, flags);
+	spin_lock_irqsave(session->host->host_lock, flags);
 	spin_lock(&session->lock);
 	conn->stop_stage = flag;
 	conn->c_stage = ISCSI_CONN_STOPPED;
@@ -1198,10 +1189,9 @@ iscsi_iser_conn_stop(iscsi_connh_t connh
 
 
 static int
-iscsi_iser_conn_send_generic(iscsi_connh_t connh, struct iscsi_hdr *hdr,
+iscsi_iser_conn_send_generic(struct iscsi_iser_conn *conn, struct iscsi_hdr *hdr,
 			     char *data, uint32_t data_size)
 {
-	struct iscsi_iser_conn *conn = iscsi_ptr(connh);
 	struct iscsi_iser_session *session = conn->session;
 	struct iscsi_iser_mgmt_task *mtask = NULL;
 	struct iscsi_nopout *nop = (struct iscsi_nopout *)hdr;
@@ -1269,8 +1259,7 @@ iscsi_iser_conn_send_generic(iscsi_connh
 	else
 		__kfifo_put(conn->mgmtqueue, (void*)&mtask, sizeof(void*));
 
-	schedule_work(&conn->xmitwork);
-
+	scsi_queue_work(conn->session->host, &conn->xmitwork);
 	return 0;
 }
 
@@ -1392,7 +1381,7 @@ iscsi_iser_eh_abort(struct scsi_cmnd *sc
 		iser_err("op 0x%x aborting rtt 0x%x itt 0x%x dlength %d]\n",
 		         hdr->opcode, hdr->rtt, hdr->itt, ntoh24(hdr->dlength));
 
-		rc = iscsi_iser_conn_send_generic(iscsi_handle(conn), (struct iscsi_hdr *)hdr,
+		rc = iscsi_iser_conn_send_generic(conn, (struct iscsi_hdr *)hdr,
 						  NULL, 0);
 
 		if (rc) {
@@ -1524,23 +1513,30 @@ static struct scsi_host_template iscsi_i
 	.this_id                = -1,
 };
 
-static iscsi_sessionh_t
-iscsi_iser_session_create(uint32_t initial_cmdsn,
-			  struct Scsi_Host *host)
+static struct iscsi_transport iscsi_iser_transport;
+
+static struct iscsi_cls_session *
+iscsi_iser_session_create(struct scsi_transport_template *scsit,
+			  uint32_t initial_cmdsn, uint32_t *sid)
 {
+	struct Scsi_Host *shost;
 	struct iscsi_iser_session *session = NULL;
 	int cmd_i, mgmt_i, j;
 
-	session = iscsi_hostdata(host->hostdata);
-	memset(session, 0, sizeof(struct iscsi_iser_session));
+	shost = iscsi_transport_create_session(scsit, &iscsi_iser_transport);
+	if (!shost)
+		return NULL;
 
-	session->host = host;
-	session->id = host->host_no;
+	session = iscsi_hostdata(shost->hostdata);
+	memset(session, 0, sizeof(struct iscsi_iser_session));
+	session->host = shost;
+	session->state = ISCSI_STATE_FREE;
 	session->mgmtpool_max = ISCSI_ISER_MGMT_CMDS_MAX;
 	session->cmds_max = ISCSI_ISER_XMIT_CMDS_MAX;
 	session->cmdsn = initial_cmdsn;
 	session->exp_cmdsn = initial_cmdsn + 1;
 	session->max_cmdsn = initial_cmdsn + 1;
+	*sid = shost->host_no;
 
 	if (iscsi_iser_pool_init(&session->cmdpool, session->cmds_max,
 				 (void***)&session->cmds,
@@ -1582,7 +1578,7 @@ iscsi_iser_session_create(uint32_t initi
 			session->mgmt_cmds[mgmt_i]->desc.data;
 	}
 
-	return iscsi_handle(session);
+	return hostdata_session(shost->hostdata);
 
 immdata_alloc_fail:
 	for (j = 0; j < mgmt_i; j++)
@@ -1591,28 +1587,31 @@ immdata_alloc_fail:
 mgmtpool_alloc_fail:
 	iscsi_iser_pool_free(&session->cmdpool, (void**)session->cmds);
 cmdpool_alloc_fail:
-	return iscsi_handle(NULL);
+	iscsi_transport_destroy_session(shost);
+	return NULL;
 }
 
 static void
-iscsi_iser_session_destroy(iscsi_sessionh_t sessionh)
+iscsi_iser_session_destroy(struct iscsi_cls_session *cls_session)
 {
 	int mgmt_i;
-	struct iscsi_iser_session *session = iscsi_ptr(sessionh);
+	struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
+	struct iscsi_iser_session *session = iscsi_hostdata(shost->hostdata);
 
 	for (mgmt_i = 0; mgmt_i < session->mgmtpool_max; mgmt_i++)
 		kfree(session->mgmt_cmds[mgmt_i]->desc.data);
 
 	iscsi_iser_pool_free(&session->mgmtpool, (void**)session->mgmt_cmds);
 	iscsi_iser_pool_free(&session->cmdpool, (void**)session->cmds);
+
+	iscsi_transport_destroy_session(shost);
 }
 
 static int
-iscsi_iser_conn_set_param(iscsi_connh_t connh,
-			  enum iscsi_param param,
-			  uint32_t value)
+iscsi_iser_conn_set_param(struct iscsi_cls_conn *cls_conn,
+			  enum iscsi_param param, uint32_t value)
 {
-	struct iscsi_iser_conn *conn = iscsi_ptr(connh);
+	struct iscsi_iser_conn *conn = cls_conn->dd_data;
 	struct iscsi_iser_session *session = conn->session;
 
 	spin_lock_bh(&session->lock);
@@ -1691,23 +1690,13 @@ iscsi_iser_conn_set_param(iscsi_connh_t 
 }
 
 static int
-iscsi_iser_conn_get_param(iscsi_connh_t connh,
-			  enum iscsi_param param,
-			  uint32_t *value)
+iscsi_iser_session_get_param(struct iscsi_cls_session *cls_session,
+			     enum iscsi_param param, uint32_t *value)
 {
-	struct iscsi_iser_conn *conn = iscsi_ptr(connh);
-	struct iscsi_iser_session *session = conn->session;
+	struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
+	struct iscsi_iser_session *session = iscsi_hostdata(shost->hostdata);
 
 	switch (param) {
-	case ISCSI_PARAM_MAX_XMIT_DLENGTH:
-		*value = conn->max_xmit_dlength;
-		break;
-	case ISCSI_PARAM_HDRDGST_EN:
-		*value = 0;
-		break;
-	case ISCSI_PARAM_DATADGST_EN:
-		*value = 0;
-		break;
 	case ISCSI_PARAM_INITIAL_R2T_EN:
 		*value = session->initial_r2t_en;
 		break;
@@ -1741,6 +1730,32 @@ iscsi_iser_conn_get_param(iscsi_connh_t 
 	case ISCSI_PARAM_RDMAEXTENSIONS:
 		*value = 1;
 		break;
+	default:
+		return ISCSI_ERR_PARAM_NOT_FOUND;
+	}
+
+	return 0;
+}
+
+static int
+iscsi_iser_conn_get_param(struct iscsi_cls_conn *cls_conn,
+			  enum iscsi_param param, uint32_t *value)
+{
+	struct iscsi_iser_conn *conn = cls_conn->dd_data;
+
+	switch(param) {
+	case ISCSI_PARAM_MAX_RECV_DLENGTH:
+		*value = conn->max_recv_dlength;
+		break;
+	case ISCSI_PARAM_MAX_XMIT_DLENGTH:
+		*value = conn->max_xmit_dlength;
+		break;
+	case ISCSI_PARAM_HDRDGST_EN:
+		*value = 0;
+		break;
+	case ISCSI_PARAM_DATADGST_EN:
+		*value = 0;
+		break;
 	/*case ISCSI_PARAM_TARGET_RECV_DLENGTH:
 		*value = conn->target_recv_dlength;
 		break;
@@ -1754,15 +1769,16 @@ iscsi_iser_conn_get_param(iscsi_connh_t 
 	return 0;
 }
 
+
 static int
-iscsi_iser_conn_send_pdu(iscsi_connh_t connh, struct iscsi_hdr *hdr, char *data,
-			  uint32_t data_size)
+iscsi_iser_conn_send_pdu(struct iscsi_cls_conn *cls_conn, struct iscsi_hdr *hdr,
+			 char *data, uint32_t data_size)
 {
-	struct iscsi_iser_conn *conn = iscsi_ptr(connh);
+	struct iscsi_iser_conn *conn = cls_conn->dd_data;
 	int rc;
 
 	mutex_lock(&conn->xmitmutex);
-	rc = iscsi_iser_conn_send_generic(connh, hdr, data, data_size);
+	rc = iscsi_iser_conn_send_generic(conn, hdr, data, data_size);
 	mutex_unlock(&conn->xmitmutex);
 
 	return rc;
@@ -1776,6 +1792,7 @@ static struct iscsi_transport iscsi_iser
 	.rdma                   = 1,
 	.host_template          = &iscsi_iser_sht,
 	.hostdata_size          = sizeof(struct iscsi_iser_session),
+	.conndata_size		= sizeof(struct iscsi_iser_conn),
 	.max_lun                = ISCSI_ISER_MAX_LUN,
 	.max_cmd_len            = ISCSI_ISER_MAX_CMD_LEN,
 	.create_session         = iscsi_iser_session_create,
@@ -1784,7 +1801,8 @@ static struct iscsi_transport iscsi_iser
 	.bind_conn              = iscsi_iser_conn_bind,
 	.destroy_conn           = iscsi_iser_conn_destroy,
 	.set_param              = iscsi_iser_conn_set_param,
-	.get_param              = iscsi_iser_conn_get_param,
+	.get_conn_param		= iscsi_iser_conn_get_param,
+	.get_session_param	= iscsi_iser_session_get_param,
 	.start_conn             = iscsi_iser_conn_start,
 	.stop_conn              = iscsi_iser_conn_stop,
 	.send_pdu               = iscsi_iser_conn_send_pdu,
@@ -1822,8 +1840,7 @@ static int __init iser_init(void)
 		goto register_socket_failure;
 	}
 
-	err = iscsi_register_transport(&iscsi_iser_transport);
-	if (err) {
+	if (!iscsi_register_transport(&iscsi_iser_transport)) {
 		iser_err("iscsi_register_transport failed\n");
 		goto register_transport_failure;
 	}




More information about the general mailing list