[stgt] [PATCH 3/5] Encapsulate Redirect details to be within target_redirected()

Chandra Seetharaman sekharan at us.ibm.com
Tue Sep 21 03:41:09 CEST 2010


Encapsulate the RedirectAddress and reason to the function
target_redirected(), so that it is easier to contain the dynamic target
redirection code in target_redirected itself.

Signed-Off-By: Chandra Seetharaman <sekharan at us.ibm.com>
---
 usr/iscsi/iscsid.c |    9 ++++-----
 usr/iscsi/iscsid.h |    3 ++-
 usr/iscsi/target.c |   21 +++++++++++++++------
 3 files changed, 21 insertions(+), 12 deletions(-)

Index: tgt-1.0.8/usr/iscsi/iscsid.c
===================================================================
--- tgt-1.0.8.orig/usr/iscsi/iscsid.c
+++ tgt-1.0.8/usr/iscsi/iscsid.c
@@ -430,6 +430,8 @@ static void login_start(struct iscsi_con
 	struct iscsi_login_rsp *rsp = (struct iscsi_login_rsp *)&conn->rsp.bhs;
 	char *name, *alias, *session_type, *target_name;
 	struct iscsi_target *target;
+	char buf[NI_MAXHOST + NI_MAXSERV + 4];
+	int reason;
 
 	conn->cid = be16_to_cpu(req->cid);
 	memcpy(conn->isid, req->isid, sizeof(req->isid));
@@ -489,13 +491,10 @@ static void login_start(struct iscsi_con
 
 		conn->tid = target->tid;
 
-		if (target_redirected(target, conn)) {
-			char buf[NI_MAXHOST + NI_MAXSERV + 4];
-			snprintf(buf, sizeof(buf), "%s:%s", target->redirect_info.addr,
-				 target->redirect_info.port);
+		if (target_redirected(target, conn, buf, &reason)) {
 			text_key_add(conn, "TargetAddress", buf);
 			rsp->status_class = ISCSI_STATUS_CLS_REDIRECT;
-			rsp->status_detail = target->redirect_info.reason;
+			rsp->status_detail = reason;
 			conn->state = STATE_EXIT;
 			return;
 		}
Index: tgt-1.0.8/usr/iscsi/target.c
===================================================================
--- tgt-1.0.8.orig/usr/iscsi/target.c
+++ tgt-1.0.8/usr/iscsi/target.c
@@ -189,19 +189,24 @@ int ip_acl(int tid, struct iscsi_connect
 	return -EPERM;
 }
 
-int target_redirected(struct iscsi_target *target, struct iscsi_connection *conn)
+int target_redirected(struct iscsi_target *target,
+	struct iscsi_connection *conn, char *buf, int *reason)
 {
 	struct sockaddr_storage from;
 	struct addrinfo hints, *res;
 	socklen_t len;
-	int ret;
-	char *p, *q, *str;
+	int ret, rsn;
+	char *p, *q, *str, *port, *addr;
 
 	if (!strlen(target->redirect_info.addr))
 		return 0;
 
-	if (target->redirect_info.reason != ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP &&
-	    target->redirect_info.reason != ISCSI_LOGIN_STATUS_TGT_MOVED_PERM)
+	addr = target->redirect_info.addr;
+	port = target->redirect_info.port;
+	rsn = target->redirect_info.reason;
+
+	if (rsn != ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP &&
+	    rsn != ISCSI_LOGIN_STATUS_TGT_MOVED_PERM)
 		return 0;
 
 	len = sizeof(from);
@@ -209,7 +214,7 @@ int target_redirected(struct iscsi_targe
 	if (ret < 0)
 		return 0;
 
-	p = strdup(target->redirect_info.addr);
+	p = strdup(addr);
 	if (!p)
 		return 0;
 	str = p;
@@ -237,6 +242,10 @@ int target_redirected(struct iscsi_targe
 	freeaddrinfo(res);
 	free(str);
 
+	if (!ret) {
+		sprintf(buf, "%s:%s", addr, port);
+		*reason = rsn;
+	}
 	return !ret;
 }
 
Index: tgt-1.0.8/usr/iscsi/iscsid.h
===================================================================
--- tgt-1.0.8.orig/usr/iscsi/iscsid.h
+++ tgt-1.0.8/usr/iscsi/iscsid.h
@@ -317,7 +317,8 @@ extern int iscsi_target_show(int mode, i
 			     uint64_t lun, char *buf, int rest);
 int iscsi_target_update(int mode, int op, int tid, uint64_t sid, uint64_t lun,
 			uint32_t cid, char *name);
-int target_redirected(struct iscsi_target *target, struct iscsi_connection *conn);
+int target_redirected(struct iscsi_target *target,
+	struct iscsi_connection *conn, char *buf, int *reason);
 
 /* param.c */
 int param_index_by_name(char *name, struct iscsi_key *keys);
--
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