Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Jul 2014 15:31:46 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r269065 - in stable/10: sys/dev/iscsi usr.sbin/iscsid
Message-ID:  <201407241531.s6OFVkgi000258@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Thu Jul 24 15:31:45 2014
New Revision: 269065
URL: http://svnweb.freebsd.org/changeset/base/269065

Log:
  MFC r267613 (by trasz):
  Implement redirection handling in initiator.

Modified:
  stable/10/sys/dev/iscsi/iscsi.c
  stable/10/sys/dev/iscsi/iscsi_ioctl.h
  stable/10/usr.sbin/iscsid/iscsid.c
  stable/10/usr.sbin/iscsid/login.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/iscsi/iscsi.c
==============================================================================
--- stable/10/sys/dev/iscsi/iscsi.c	Thu Jul 24 15:18:19 2014	(r269064)
+++ stable/10/sys/dev/iscsi/iscsi.c	Thu Jul 24 15:31:45 2014	(r269065)
@@ -1635,6 +1635,33 @@ iscsi_sanitize_session_conf(struct iscsi
 	isc->isc_mutual_secret[ISCSI_SECRET_LEN - 1] = '\0';
 }
 
+static bool
+iscsi_valid_session_conf(const struct iscsi_session_conf *isc)
+{
+
+	if (isc->isc_initiator[0] == '\0') {
+		ISCSI_DEBUG("empty isc_initiator");
+		return (false);
+	}
+
+	if (isc->isc_target_addr[0] == '\0') {
+		ISCSI_DEBUG("empty isc_target_addr");
+		return (false);
+	}
+
+	if (isc->isc_discovery != 0 && isc->isc_target[0] != 0) {
+		ISCSI_DEBUG("non-empty isc_target for discovery session");
+		return (false);
+	}
+
+	if (isc->isc_discovery == 0 && isc->isc_target[0] == 0) {
+		ISCSI_DEBUG("empty isc_target for non-discovery session");
+		return (false);
+	}
+
+	return (true);
+}
+
 static int
 iscsi_ioctl_session_add(struct iscsi_softc *sc, struct iscsi_session_add *isa)
 {
@@ -1643,22 +1670,12 @@ iscsi_ioctl_session_add(struct iscsi_sof
 	int error;
 
 	iscsi_sanitize_session_conf(&isa->isa_conf);
+	if (iscsi_valid_session_conf(&isa->isa_conf) == false)
+		return (EINVAL);
 
 	is = malloc(sizeof(*is), M_ISCSI, M_ZERO | M_WAITOK);
 	memcpy(&is->is_conf, &isa->isa_conf, sizeof(is->is_conf));
 
-	if (is->is_conf.isc_initiator[0] == '\0' ||
-	    is->is_conf.isc_target_addr[0] == '\0') {
-		free(is, M_ISCSI);
-		return (EINVAL);
-	}
-
-	if ((is->is_conf.isc_discovery != 0 && is->is_conf.isc_target[0] != 0) ||
-	    (is->is_conf.isc_discovery == 0 && is->is_conf.isc_target[0] == 0)) {
-		free(is, M_ISCSI);
-		return (EINVAL);
-	}
-
 	sx_xlock(&sc->sc_lock);
 
 	/*
@@ -1818,7 +1835,38 @@ iscsi_ioctl_session_list(struct iscsi_so
 
 	return (0);
 }
-	
+
+static int
+iscsi_ioctl_session_modify(struct iscsi_softc *sc,
+    struct iscsi_session_modify *ism)
+{
+	struct iscsi_session *is;
+
+	iscsi_sanitize_session_conf(&ism->ism_conf);
+	if (iscsi_valid_session_conf(&ism->ism_conf) == false)
+		return (EINVAL);
+
+	sx_xlock(&sc->sc_lock);
+	TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
+		ISCSI_SESSION_LOCK(is);
+		if (is->is_id == ism->ism_session_id)
+			break;
+		ISCSI_SESSION_UNLOCK(is);
+	}
+	if (is == NULL) {
+		sx_xunlock(&sc->sc_lock);
+		return (ESRCH);
+	}
+	sx_xunlock(&sc->sc_lock);
+
+	memcpy(&is->is_conf, &ism->ism_conf, sizeof(is->is_conf));
+	ISCSI_SESSION_UNLOCK(is);
+
+	iscsi_session_reconnect(is);
+
+	return (0);
+}
+
 static int
 iscsi_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode,
     struct thread *td)
@@ -1857,6 +1905,9 @@ iscsi_ioctl(struct cdev *dev, u_long cmd
 	case ISCSISLIST:
 		return (iscsi_ioctl_session_list(sc,
 		    (struct iscsi_session_list *)arg));
+	case ISCSISMODIFY:
+		return (iscsi_ioctl_session_modify(sc,
+		    (struct iscsi_session_modify *)arg));
 	default:
 		return (EINVAL);
 	}

Modified: stable/10/sys/dev/iscsi/iscsi_ioctl.h
==============================================================================
--- stable/10/sys/dev/iscsi/iscsi_ioctl.h	Thu Jul 24 15:18:19 2014	(r269064)
+++ stable/10/sys/dev/iscsi/iscsi_ioctl.h	Thu Jul 24 15:31:45 2014	(r269065)
@@ -202,8 +202,15 @@ struct iscsi_session_list {
 	int				isl_spare[4];
 };
 
+struct iscsi_session_modify {
+	unsigned int			ism_session_id;
+	struct iscsi_session_conf	ism_conf;
+	int				ism_spare[4];
+};
+
 #define	ISCSISADD	_IOW('I', 0x11, struct iscsi_session_add)
 #define	ISCSISREMOVE	_IOW('I', 0x12, struct iscsi_session_remove)
 #define	ISCSISLIST	_IOWR('I', 0x13, struct iscsi_session_list)
+#define	ISCSISMODIFY	_IOWR('I', 0x14, struct iscsi_session_modify)
 
 #endif /* !ISCSI_IOCTL_H */

Modified: stable/10/usr.sbin/iscsid/iscsid.c
==============================================================================
--- stable/10/usr.sbin/iscsid/iscsid.c	Thu Jul 24 15:18:19 2014	(r269064)
+++ stable/10/usr.sbin/iscsid/iscsid.c	Thu Jul 24 15:31:45 2014	(r269065)
@@ -306,10 +306,10 @@ capsicate(struct connection *conn)
 	cap_rights_t rights;
 #ifdef ICL_KERNEL_PROXY
 	const unsigned long cmds[] = { ISCSIDCONNECT, ISCSIDSEND, ISCSIDRECEIVE,
-	    ISCSIDHANDOFF, ISCSIDFAIL, ISCSISADD, ISCSISREMOVE };
+	    ISCSIDHANDOFF, ISCSIDFAIL, ISCSISADD, ISCSISREMOVE, ISCSISMODIFY };
 #else
 	const unsigned long cmds[] = { ISCSIDHANDOFF, ISCSIDFAIL, ISCSISADD,
-	    ISCSISREMOVE };
+	    ISCSISREMOVE, ISCSISMODIFY };
 #endif
 
 	cap_rights_init(&rights, CAP_IOCTL);

Modified: stable/10/usr.sbin/iscsid/login.c
==============================================================================
--- stable/10/usr.sbin/iscsid/login.c	Thu Jul 24 15:18:19 2014	(r269064)
+++ stable/10/usr.sbin/iscsid/login.c	Thu Jul 24 15:31:45 2014	(r269065)
@@ -30,6 +30,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/ioctl.h>
 #include <assert.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -158,6 +159,60 @@ login_target_error_str(int class, int de
 	}
 }
 
+static void
+kernel_modify(const struct connection *conn, const char *target_address)
+{
+	struct iscsi_session_modify ism;
+	int error;
+
+	memset(&ism, 0, sizeof(ism));
+	ism.ism_session_id = conn->conn_session_id;
+	memcpy(&ism.ism_conf, &conn->conn_conf, sizeof(ism.ism_conf));
+	strlcpy(ism.ism_conf.isc_target_addr, target_address,
+	    sizeof(ism.ism_conf.isc_target));
+	error = ioctl(conn->conn_iscsi_fd, ISCSISMODIFY, &ism);
+	if (error != 0) {
+		log_err(1, "failed to redirect to %s: ISCSISMODIFY",
+		    target_address);
+	}
+}
+
+/*
+ * XXX:	The way it works is suboptimal; what should happen is described
+ *	in draft-gilligan-iscsi-fault-tolerance-00.  That, however, would
+ *	be much more complicated: we would need to keep "dependencies"
+ *	for sessions, so that, in case described in draft and using draft
+ *	terminology, we would have three sessions: one for discovery,
+ *	one for initial target portal, and one for redirect portal.  
+ *	This would allow us to "backtrack" on connection failure,
+ *	as described in draft.
+ */
+static void
+login_handle_redirection(struct connection *conn, struct pdu *response)
+{
+	struct iscsi_bhs_login_response *bhslr;
+	struct keys *response_keys;
+	const char *target_address;
+
+	bhslr = (struct iscsi_bhs_login_response *)response->pdu_bhs;
+	assert (bhslr->bhslr_status_class == 1);
+
+	response_keys = keys_new();
+	keys_load(response_keys, response);
+
+	target_address = keys_find(response_keys, "TargetAddress");
+	if (target_address == NULL)
+		log_errx(1, "received redirection without TargetAddress");
+	if (target_address[0] == '\0')
+		log_errx(1, "received redirection with empty TargetAddress");
+	if (strlen(target_address) >=
+	    sizeof(conn->conn_conf.isc_target_addr) - 1)
+		log_errx(1, "received TargetAddress is too long");
+
+	log_debugx("received redirection to \"%s\"", target_address);
+	kernel_modify(conn, target_address);
+}
+
 static struct pdu *
 login_receive(struct connection *conn, bool initial)
 {
@@ -183,6 +238,11 @@ login_receive(struct connection *conn, b
 	if (bhslr->bhslr_version_active != 0x00)
 		log_errx(1, "received Login PDU with unsupported "
 		    "Version-active 0x%x", bhslr->bhslr_version_active);
+	if (bhslr->bhslr_status_class == 1) {
+		login_handle_redirection(conn, response);
+		log_debugx("redirection handled; exiting");
+		exit(0);
+	}
 	if (bhslr->bhslr_status_class != 0) {
 		errorstr = login_target_error_str(bhslr->bhslr_status_class,
 		    bhslr->bhslr_status_detail);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407241531.s6OFVkgi000258>