[stgt] Limiting the number of ISCSI-Sessions per target

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Wed Oct 22 02:53:03 CEST 2008


On Tue, 21 Oct 2008 20:33:52 +0200
<volker.jaenisch at inqbus.de> wrote:

> Hi Tomonori!
> 
> (Is this the right salutation? Mike Christy called you tomo ..)
> 
> Thanks a lot for the patch! My colleague (I'm on vacation) has tried the
> patch - it compiles, tgtd works.
> But if a second sessions is negotiating to the target the tgtd dies.
> 
> It may not be the intention of the patch but this prevents deadly sure that
> never two sessions aquire the same target :-)). 
> 
> My colleague will join the list asap to report the issue. He did the patch
> by hand into
> version tgt-20080805, which we choose to run our production environment.
> 
> Is the patch version dependend? Which version do you recommend to work on? 
> I learned today that the 0.91-Version is going to get released soon.

Oops, can you try this patch (please ignore the previous patch)?

This can be applied to tgt-20080805 (0.90, and the latest git tree
too).

diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index cb2ba0b..c22a6f6 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -498,6 +498,7 @@ static void login_finish(struct iscsi_connection *conn)
 {
 	struct iscsi_login_rsp *rsp = (struct iscsi_login_rsp *) &conn->rsp.bhs;
 	int ret;
+	uint8_t class, detail;
 
 	switch (conn->session_type) {
 	case SESSION_NORMAL:
@@ -513,25 +514,25 @@ static void login_finish(struct iscsi_connection *conn)
 		 */
 		ret = conn->tp->ep_login_complete(conn);
 		if (ret) {
-			rsp->flags = 0;
-			rsp->status_class = ISCSI_STATUS_CLS_TARGET_ERR;
-			rsp->status_detail = ISCSI_LOGIN_STATUS_NO_RESOURCES;
-			conn->state = STATE_EXIT;
-			break;
+			class = ISCSI_STATUS_CLS_TARGET_ERR;
+			detail = ISCSI_LOGIN_STATUS_NO_RESOURCES;
+			goto fail;
 		}
 		if (!conn->session) {
-			session_create(conn);
+			ret = session_create(conn);
+			if (ret) {
+				class = ISCSI_STATUS_CLS_TARGET_ERR;
+				detail = ISCSI_LOGIN_STATUS_TARGET_ERROR;
+				goto fail;
+			}
 		} else {
 			if (conn->tp->rdma ^ conn->session->rdma) {
 				eprintf("new conn rdma %d, but session %d\n",
 					conn->tp->rdma, conn->session->rdma);
-				rsp->flags = 0;
-				rsp->status_class =
-					ISCSI_STATUS_CLS_INITIATOR_ERR;
-				rsp->status_detail =
-					ISCSI_LOGIN_STATUS_INVALID_REQUEST;
-				conn->state = STATE_EXIT;
-				break;
+
+				class = ISCSI_STATUS_CLS_INITIATOR_ERR;
+				detail =ISCSI_LOGIN_STATUS_INVALID_REQUEST;
+				goto fail;
 			}
 		}
 		memcpy(conn->isid, conn->session->isid, sizeof(conn->isid));
@@ -542,6 +543,14 @@ static void login_finish(struct iscsi_connection *conn)
 		conn->tsih = 1;
 		break;
 	}
+
+	return;
+fail:
+	rsp->flags = 0;
+	rsp->status_class = class;
+	rsp->status_detail = detail;
+	conn->state = STATE_EXIT;
+	return;
 }
 
 static int cmnd_exec_auth(struct iscsi_connection *conn)
diff --git a/usr/target.c b/usr/target.c
index dc30c87..91085dc 100644
--- a/usr/target.c
+++ b/usr/target.c
@@ -248,6 +248,9 @@ int it_nexus_create(int tid, uint64_t itn_id, int host_no, char *info)
 
 	target = target_lookup(tid);
 
+	if (!list_empty(&target->it_nexus_list))
+		return -EEXIST;
+
 	itn = zalloc(sizeof(*itn));
 	if (!itn)
 		return -ENOMEM;


--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list