Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Apr 2014 18:23:36 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r264549 - in head: sys/dev/iscsi usr.sbin/iscsid
Message-ID:  <201404161823.s3GINaN2059268@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Wed Apr 16 18:23:36 2014
New Revision: 264549
URL: http://svnweb.freebsd.org/changeset/base/264549

Log:
  Make it possible for the initiator side to operate in both proxy
  and normal mode; this makes it possible to compile with the former
  by default, but use it only when neccessary.  That's especially
  important for the userland part.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/dev/iscsi/iscsi.c
  head/sys/dev/iscsi/iscsi_ioctl.h
  head/usr.sbin/iscsid/iscsid.c
  head/usr.sbin/iscsid/iscsid.h
  head/usr.sbin/iscsid/pdu.c

Modified: head/sys/dev/iscsi/iscsi.c
==============================================================================
--- head/sys/dev/iscsi/iscsi.c	Wed Apr 16 18:09:39 2014	(r264548)
+++ head/sys/dev/iscsi/iscsi.c	Wed Apr 16 18:23:36 2014	(r264549)
@@ -1304,12 +1304,19 @@ iscsi_ioctl_daemon_handoff(struct iscsi_
 
 	ISCSI_SESSION_UNLOCK(is);
 
-#ifndef ICL_KERNEL_PROXY
-	error = icl_conn_handoff(is->is_conn, handoff->idh_socket);
-	if (error != 0) {
-		sx_sunlock(&sc->sc_lock);
-		iscsi_session_terminate(is);
-		return (error);
+#ifdef ICL_KERNEL_PROXY
+	if (handoff->idh_socket != 0) {
+#endif
+		/*
+		 * Handoff without using ICL proxy.
+		 */
+		error = icl_conn_handoff(is->is_conn, handoff->idh_socket);
+		if (error != 0) {
+			sx_sunlock(&sc->sc_lock);
+			iscsi_session_terminate(is);
+			return (error);
+		}
+#ifdef ICL_KERNEL_PROXY
 	}
 #endif
 
@@ -1420,13 +1427,18 @@ iscsi_ioctl_daemon_connect(struct iscsi_
 
 	if (idc->idc_from_addrlen > 0) {
 		error = getsockaddr(&from_sa, (void *)idc->idc_from_addr, idc->idc_from_addrlen);
-		if (error != 0)
+		if (error != 0) {
+			ISCSI_SESSION_WARN(is,
+			    "getsockaddr failed with error %d", error);
 			return (error);
+		}
 	} else {
 		from_sa = NULL;
 	}
 	error = getsockaddr(&to_sa, (void *)idc->idc_to_addr, idc->idc_to_addrlen);
 	if (error != 0) {
+		ISCSI_SESSION_WARN(is, "getsockaddr failed with error %d",
+		    error);
 		free(from_sa, M_SONAME);
 		return (error);
 	}

Modified: head/sys/dev/iscsi/iscsi_ioctl.h
==============================================================================
--- head/sys/dev/iscsi/iscsi_ioctl.h	Wed Apr 16 18:09:39 2014	(r264548)
+++ head/sys/dev/iscsi/iscsi_ioctl.h	Wed Apr 16 18:23:36 2014	(r264549)
@@ -129,9 +129,9 @@ struct iscsi_daemon_fail {
 
 /*
  * When ICL_KERNEL_PROXY is not defined, the iscsid(8) is responsible
- * for creating the socket, connecting, performing Login Phase using
- * socked in the usual userspace way, and then passing the socket file
- * descriptor to the kernel part using ISCSIDHANDOFF.
+ * for creating the socket, connecting, and performing Login Phase using
+ * the socket in the usual userspace way, and then passing the socket
+ * file descriptor to the kernel part using ISCSIDHANDOFF.
  *
  * When ICL_KERNEL_PROXY is defined, the iscsid(8) creates the session
  * using ISCSICONNECT, performs Login Phase using ISCSISEND/ISCSIRECEIVE
@@ -162,7 +162,7 @@ struct iscsi_daemon_send {
 	void				*ids_spare2;
 	size_t				ids_data_segment_len;
 	void				*ids_data_segment;
-	int				ids_spare[4];
+	int				ids_spare3[4];
 };
 
 struct iscsi_daemon_receive {
@@ -172,7 +172,7 @@ struct iscsi_daemon_receive {
 	void				*idr_spare2;
 	size_t				idr_data_segment_len;
 	void				*idr_data_segment;
-	int				idr_spare[4];
+	int				idr_spare3[4];
 };
 
 #define	ISCSIDCONNECT	_IOWR('I', 0x04, struct iscsi_daemon_connect)

Modified: head/usr.sbin/iscsid/iscsid.c
==============================================================================
--- head/usr.sbin/iscsid/iscsid.c	Wed Apr 16 18:09:39 2014	(r264548)
+++ head/usr.sbin/iscsid/iscsid.c	Wed Apr 16 18:23:36 2014	(r264549)
@@ -194,30 +194,32 @@ connection_new(unsigned int session_id, 
 	resolve_addr(conn, to_addr, &to_ai, false);
 
 #ifdef ICL_KERNEL_PROXY
+	if (conn->conn_conf.isc_iser) {
+		memset(&idc, 0, sizeof(idc));
+		idc.idc_session_id = conn->conn_session_id;
+		if (conn->conn_conf.isc_iser)
+			idc.idc_iser = 1;
+		idc.idc_domain = to_ai->ai_family;
+		idc.idc_socktype = to_ai->ai_socktype;
+		idc.idc_protocol = to_ai->ai_protocol;
+		if (from_ai != NULL) {
+			idc.idc_from_addr = from_ai->ai_addr;
+			idc.idc_from_addrlen = from_ai->ai_addrlen;
+		}
+		idc.idc_to_addr = to_ai->ai_addr;
+		idc.idc_to_addrlen = to_ai->ai_addrlen;
 
-	memset(&idc, 0, sizeof(idc));
-	idc.idc_session_id = conn->conn_session_id;
-	if (conn->conn_conf.isc_iser)
-		idc.idc_iser = 1;
-	idc.idc_domain = to_ai->ai_family;
-	idc.idc_socktype = to_ai->ai_socktype;
-	idc.idc_protocol = to_ai->ai_protocol;
-	if (from_ai != NULL) {
-		idc.idc_from_addr = from_ai->ai_addr;
-		idc.idc_from_addrlen = from_ai->ai_addrlen;
-	}
-	idc.idc_to_addr = to_ai->ai_addr;
-	idc.idc_to_addrlen = to_ai->ai_addrlen;
+		log_debugx("connecting to %s using ICL kernel proxy", to_addr);
+		error = ioctl(iscsi_fd, ISCSIDCONNECT, &idc);
+		if (error != 0) {
+			fail(conn, strerror(errno));
+			log_err(1, "failed to connect to %s "
+			    "using ICL kernel proxy: ISCSIDCONNECT", to_addr);
+		}
 
-	log_debugx("connecting to %s using ICL kernel proxy", to_addr);
-	error = ioctl(iscsi_fd, ISCSIDCONNECT, &idc);
-	if (error != 0) {
-		fail(conn, strerror(errno));
-		log_err(1, "failed to connect to %s using ICL kernel proxy",
-		    to_addr);
+		return (conn);
 	}
-
-#else /* !ICL_KERNEL_PROXY */
+#endif /* ICL_KERNEL_PROXY */
 
 	if (conn->conn_conf.isc_iser) {
 		fail(conn, "iSER not supported");
@@ -246,8 +248,6 @@ connection_new(unsigned int session_id, 
 		log_err(1, "failed to connect to %s", to_addr);
 	}
 
-#endif /* !ICL_KERNEL_PROXY */
-
 	return (conn);
 }
 
@@ -261,9 +261,7 @@ handoff(struct connection *conn)
 
 	memset(&idh, 0, sizeof(idh));
 	idh.idh_session_id = conn->conn_session_id;
-#ifndef ICL_KERNEL_PROXY
 	idh.idh_socket = conn->conn_socket;
-#endif
 	strlcpy(idh.idh_target_alias, conn->conn_target_alias,
 	    sizeof(idh.idh_target_alias));
 	memcpy(idh.idh_isid, conn->conn_isid, sizeof(idh.idh_isid));

Modified: head/usr.sbin/iscsid/iscsid.h
==============================================================================
--- head/usr.sbin/iscsid/iscsid.h	Wed Apr 16 18:09:39 2014	(r264548)
+++ head/usr.sbin/iscsid/iscsid.h	Wed Apr 16 18:23:36 2014	(r264549)
@@ -46,9 +46,7 @@
 
 struct connection {
 	int			conn_iscsi_fd;
-#ifndef ICL_KERNEL_PROXY
 	int			conn_socket;
-#endif
 	unsigned int		conn_session_id;
 	struct iscsi_session_conf	conn_conf;
 	char			conn_target_alias[ISCSI_ADDR_LEN];

Modified: head/usr.sbin/iscsid/pdu.c
==============================================================================
--- head/usr.sbin/iscsid/pdu.c	Wed Apr 16 18:09:39 2014	(r264548)
+++ head/usr.sbin/iscsid/pdu.c	Wed Apr 16 18:23:36 2014	(r264549)
@@ -101,13 +101,15 @@ pdu_new_response(struct pdu *request)
 
 #ifdef ICL_KERNEL_PROXY
 
-void
-pdu_receive(struct pdu *pdu)
+static void
+pdu_receive_proxy(struct pdu *pdu)
 {
 	struct iscsi_daemon_receive *idr;
 	size_t len;
 	int error;
 
+	assert(pdu->pdu_connection->conn_conf.isc_iser != 0);
+
 	pdu->pdu_data = malloc(ISCSI_MAX_DATA_SEGMENT_LENGTH);
 	if (pdu->pdu_data == NULL)
 		log_err(1, "malloc");
@@ -136,12 +138,14 @@ pdu_receive(struct pdu *pdu)
 	free(idr);
 }
 
-void
-pdu_send(struct pdu *pdu)
+static void
+pdu_send_proxy(struct pdu *pdu)
 {
 	struct iscsi_daemon_send *ids;
 	int error;
 
+	assert(pdu->pdu_connection->conn_conf.isc_iser != 0);
+
 	pdu_set_data_segment_length(pdu, pdu->pdu_data_len);
 
 	ids = calloc(1, sizeof(*ids));
@@ -160,7 +164,7 @@ pdu_send(struct pdu *pdu)
 	free(ids);
 }
 
-#else /* !ICL_KERNEL_PROXY */
+#endif /* ICL_KERNEL_PROXY */
 
 static size_t
 pdu_padding(const struct pdu *pdu)
@@ -196,6 +200,13 @@ pdu_receive(struct pdu *pdu)
 	size_t len, padding;
 	char dummy[4];
 
+#ifdef ICL_KERNEL_PROXY
+	if (pdu->pdu_connection->conn_conf.isc_iser != 0)
+		return (pdu_receive_proxy(pdu));
+#endif
+
+	assert(pdu->pdu_connection->conn_conf.isc_iser == 0);
+
 	pdu_read(pdu->pdu_connection->conn_socket,
 	    (char *)pdu->pdu_bhs, sizeof(*pdu->pdu_bhs));
 
@@ -237,6 +248,13 @@ pdu_send(struct pdu *pdu)
 	struct iovec iov[3];
 	int iovcnt;
 
+#ifdef ICL_KERNEL_PROXY
+	if (pdu->pdu_connection->conn_conf.isc_iser != 0)
+		return (pdu_send_proxy(pdu));
+#endif
+
+	assert(pdu->pdu_connection->conn_conf.isc_iser == 0);
+
 	pdu_set_data_segment_length(pdu, pdu->pdu_data_len);
 	iov[0].iov_base = pdu->pdu_bhs;
 	iov[0].iov_len = sizeof(*pdu->pdu_bhs);
@@ -269,8 +287,6 @@ pdu_send(struct pdu *pdu)
 		log_errx(1, "short write");
 }
 
-#endif /* !ICL_KERNEL_PROXY */
-
 void
 pdu_delete(struct pdu *pdu)
 {



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