Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Apr 2014 10:29:35 +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: r264526 - in head: sys/cam/ctl sys/dev/iscsi usr.sbin/ctld
Message-ID:  <201404161029.s3GATZOR061477@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Wed Apr 16 10:29:34 2014
New Revision: 264526
URL: http://svnweb.freebsd.org/changeset/base/264526

Log:
  Properly identify target portal when running in proxy mode.  While here,
  remove CTL_ISCSI_CLOSE, it wasn't used or implemented anyway.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/cam/ctl/ctl_frontend_iscsi.c
  head/sys/cam/ctl/ctl_frontend_iscsi.h
  head/sys/cam/ctl/ctl_ioctl.h
  head/sys/dev/iscsi/icl.h
  head/sys/dev/iscsi/icl_proxy.c
  head/usr.sbin/ctld/ctld.c
  head/usr.sbin/ctld/ctld.h
  head/usr.sbin/ctld/kernel.c

Modified: head/sys/cam/ctl/ctl_frontend_iscsi.c
==============================================================================
--- head/sys/cam/ctl/ctl_frontend_iscsi.c	Wed Apr 16 10:18:44 2014	(r264525)
+++ head/sys/cam/ctl/ctl_frontend_iscsi.c	Wed Apr 16 10:29:34 2014	(r264526)
@@ -1350,7 +1350,7 @@ cfiscsi_module_event_handler(module_t mo
 
 #ifdef ICL_KERNEL_PROXY
 static void
-cfiscsi_accept(struct socket *so)
+cfiscsi_accept(struct socket *so, int portal_id)
 {
 	struct cfiscsi_session *cs;
 
@@ -1361,6 +1361,7 @@ cfiscsi_accept(struct socket *so)
 	}
 
 	icl_conn_handoff_sock(cs->cs_conn, so);
+	cs->cs_portal_id = portal_id;
 	cs->cs_waiting_for_ctld = true;
 	cv_signal(&cfiscsi_softc.accept_cv);
 }
@@ -1739,7 +1740,7 @@ cfiscsi_ioctl_listen(struct ctl_iscsi *c
 	}
 
 	error = icl_listen_add(cfiscsi_softc.listener, cilp->iser, cilp->domain,
-	    cilp->socktype, cilp->protocol, sa);
+	    cilp->socktype, cilp->protocol, sa, cilp->portal_id);
 	if (error != 0) {
 		free(sa, M_SONAME);
 		CFISCSI_DEBUG("icl_listen_add, error %d", error);
@@ -1783,6 +1784,7 @@ cfiscsi_ioctl_accept(struct ctl_iscsi *c
 	cs->cs_login_phase = true;
 
 	ciap->connection_id = cs->cs_id;
+	ciap->portal_id = cs->cs_portal_id;
 	ci->status = CTL_ISCSI_OK;
 }
 
@@ -1916,13 +1918,6 @@ cfiscsi_ioctl_receive(struct ctl_iscsi *
 	ci->status = CTL_ISCSI_OK;
 }
 
-static void
-cfiscsi_ioctl_close(struct ctl_iscsi *ci)
-{
-	/*
-	 * XXX
-	 */
-}
 #endif /* !ICL_KERNEL_PROXY */
 
 static int
@@ -1961,15 +1956,11 @@ cfiscsi_ioctl(struct cdev *dev,
 	case CTL_ISCSI_RECEIVE:
 		cfiscsi_ioctl_receive(ci);
 		break;
-	case CTL_ISCSI_CLOSE:
-		cfiscsi_ioctl_close(ci);
-		break;
 #else
 	case CTL_ISCSI_LISTEN:
 	case CTL_ISCSI_ACCEPT:
 	case CTL_ISCSI_SEND:
 	case CTL_ISCSI_RECEIVE:
-	case CTL_ISCSI_CLOSE:
 		ci->status = CTL_ISCSI_ERROR;
 		snprintf(ci->error_str, sizeof(ci->error_str),
 		    "%s: CTL compiled without ICL_KERNEL_PROXY",

Modified: head/sys/cam/ctl/ctl_frontend_iscsi.h
==============================================================================
--- head/sys/cam/ctl/ctl_frontend_iscsi.h	Wed Apr 16 10:18:44 2014	(r264525)
+++ head/sys/cam/ctl/ctl_frontend_iscsi.h	Wed Apr 16 10:29:34 2014	(r264526)
@@ -82,6 +82,7 @@ struct cfiscsi_session {
 	unsigned int			cs_id;
 	int				cs_ctl_initid;
 #ifdef ICL_KERNEL_PROXY
+	int				cs_portal_id;
 	bool				cs_login_phase;
 	bool				cs_waiting_for_ctld;
 	struct cv			cs_login_cv;

Modified: head/sys/cam/ctl/ctl_ioctl.h
==============================================================================
--- head/sys/cam/ctl/ctl_ioctl.h	Wed Apr 16 10:18:44 2014	(r264525)
+++ head/sys/cam/ctl/ctl_ioctl.h	Wed Apr 16 10:29:34 2014	(r264526)
@@ -626,7 +626,6 @@ typedef enum {
 	CTL_ISCSI_ACCEPT,
 	CTL_ISCSI_SEND,
 	CTL_ISCSI_RECEIVE,
-	CTL_ISCSI_CLOSE,
 #endif
 } ctl_iscsi_type;
 
@@ -701,11 +700,14 @@ struct ctl_iscsi_listen_params {
 	int				protocol;
 	struct sockaddr			*addr;
 	socklen_t			addrlen;
+	int				portal_id;
 	int				spare[4];
 };
 
 struct ctl_iscsi_accept_params {
 	int				connection_id;
+	struct sockaddr			*initiator_addr;
+	int				portal_id;
 	int				spare[4];
 };
 
@@ -729,10 +731,6 @@ struct ctl_iscsi_receive_params {
 	int				spare3[4];
 };
 
-struct ctl_iscsi_close_params {
-	int				connection_id;
-	int				spare[4];
-};
 #endif /* ICL_KERNEL_PROXY */
 
 union ctl_iscsi_data {
@@ -745,7 +743,6 @@ union ctl_iscsi_data {
 	struct ctl_iscsi_accept_params		accept;
 	struct ctl_iscsi_send_params		send;
 	struct ctl_iscsi_receive_params		receive;
-	struct ctl_iscsi_close_params		close;
 #endif
 };
 

Modified: head/sys/dev/iscsi/icl.h
==============================================================================
--- head/sys/dev/iscsi/icl.h	Wed Apr 16 10:18:44 2014	(r264525)
+++ head/sys/dev/iscsi/icl.h	Wed Apr 16 10:29:34 2014	(r264526)
@@ -118,16 +118,17 @@ struct icl_listen;
 
 struct icl_listen_sock {
 	TAILQ_ENTRY(icl_listen_sock)	ils_next;
-	struct icl_listen	*ils_listen;
-	struct socket		*ils_socket;
-	bool			ils_running;
-	bool			ils_disconnecting;
+	struct icl_listen		*ils_listen;
+	struct socket			*ils_socket;
+	bool				ils_running;
+	bool				ils_disconnecting;
+	int				ils_id;
 };
 
 struct icl_listen	{
 	TAILQ_HEAD(, icl_listen_sock)	il_sockets;
 	struct sx			il_lock;
-	void				(*il_accept)(struct socket *);
+	void				(*il_accept)(struct socket *, int);
 };
 
 /*
@@ -139,10 +140,11 @@ int			icl_conn_connect(struct icl_conn *
 /*
  * Target part.
  */
-struct icl_listen	*icl_listen_new(void (*accept_cb)(struct socket *));
+struct icl_listen	*icl_listen_new(void (*accept_cb)(struct socket *, int));
 void			icl_listen_free(struct icl_listen *il);
-int			icl_listen_add(struct icl_listen *il, bool rdma, int domain,
-    int socktype, int protocol, struct sockaddr *sa);
+int			icl_listen_add(struct icl_listen *il, bool rdma,
+			    int domain, int socktype, int protocol,
+			    struct sockaddr *sa, int portal_id);
 int			icl_listen_remove(struct icl_listen *il, struct sockaddr *sa);
 
 /*

Modified: head/sys/dev/iscsi/icl_proxy.c
==============================================================================
--- head/sys/dev/iscsi/icl_proxy.c	Wed Apr 16 10:18:44 2014	(r264525)
+++ head/sys/dev/iscsi/icl_proxy.c	Wed Apr 16 10:29:34 2014	(r264526)
@@ -182,7 +182,7 @@ icl_conn_connect(struct icl_conn *ic, bo
 }
 
 struct icl_listen *
-icl_listen_new(void (*accept_cb)(struct socket *))
+icl_listen_new(void (*accept_cb)(struct socket *, int))
 {
 	struct icl_listen *il;
 
@@ -298,13 +298,13 @@ icl_accept_thread(void *arg)
 			soclose(so);
 		}
 
-		(ils->ils_listen->il_accept)(so);
+		(ils->ils_listen->il_accept)(so, ils->ils_id);
 	}
 }
 
 static int
-icl_listen_add_tcp(struct icl_listen *il, int domain, int socktype, int protocol,
-    struct sockaddr *sa)
+icl_listen_add_tcp(struct icl_listen *il, int domain, int socktype,
+    int protocol, struct sockaddr *sa, int portal_id)
 {
 	struct icl_listen_sock *ils;
 	struct socket *so;
@@ -348,6 +348,7 @@ icl_listen_add_tcp(struct icl_listen *il
 	ils = malloc(sizeof(*ils), M_ICL_PROXY, M_ZERO | M_WAITOK);
 	ils->ils_listen = il;
 	ils->ils_socket = so;
+	ils->ils_id = portal_id;
 
 	error = kthread_add(icl_accept_thread, ils, NULL, NULL, 0, 0, "iclacc");
 	if (error != 0) {
@@ -366,8 +367,8 @@ icl_listen_add_tcp(struct icl_listen *il
 }
 
 int
-icl_listen_add(struct icl_listen *il, bool rdma, int domain, int socktype, int protocol,
-    struct sockaddr *sa)
+icl_listen_add(struct icl_listen *il, bool rdma, int domain, int socktype,
+    int protocol, struct sockaddr *sa, int portal_id)
 {
 
 	if (rdma) {
@@ -375,12 +376,14 @@ icl_listen_add(struct icl_listen *il, bo
 		ICL_DEBUG("RDMA not supported");
 		return (EOPNOTSUPP);
 #else
-		return (icl_listen_add_rdma(il, domain, socktype, protocol, sa));
+		return (icl_listen_add_rdma(il, domain, socktype, protocol,
+		    sa, portal_id));
 #endif
 	}
 
 
-	return (icl_listen_add_tcp(il, domain, socktype, protocol, sa));
+	return (icl_listen_add_tcp(il, domain, socktype, protocol, sa,
+	    portal_id));
 }
 
 int

Modified: head/usr.sbin/ctld/ctld.c
==============================================================================
--- head/usr.sbin/ctld/ctld.c	Wed Apr 16 10:18:44 2014	(r264525)
+++ head/usr.sbin/ctld/ctld.c	Wed Apr 16 10:29:34 2014	(r264526)
@@ -1408,9 +1408,13 @@ conf_apply(struct conf *oldconf, struct 
 
 #ifdef ICL_KERNEL_PROXY
 			if (proxy_mode) {
-				log_debugx("listening on %s, portal-group \"%s\" using ICL proxy",
-				    newp->p_listen, newpg->pg_name);
-				kernel_listen(newp->p_ai, newp->p_iser);
+				newpg->pg_conf->conf_portal_id++;
+				newp->p_id = newpg->pg_conf->conf_portal_id;
+				log_debugx("listening on %s, portal-group "
+				    "\"%s\", portal id %d, using ICL proxy",
+				    newp->p_listen, newpg->pg_name, newp->p_id);
+				kernel_listen(newp->p_ai, newp->p_iser,
+				    newp->p_id);
 				continue;
 			}
 #endif
@@ -1671,6 +1675,7 @@ main_loop(struct conf *conf, bool dont_f
 	struct portal *portal;
 #ifdef ICL_KERNEL_PROXY
 	int connection_id;
+	int portal_id;
 #endif
 	fd_set fdset;
 	int error, nfds, client_fd;
@@ -1683,16 +1688,22 @@ main_loop(struct conf *conf, bool dont_f
 
 #ifdef ICL_KERNEL_PROXY
 		if (proxy_mode) {
-			connection_id = kernel_accept();
-			if (connection_id == 0)
-				continue;
+			kernel_accept(&connection_id, &portal_id);
+
+			log_debugx("incoming connection, id %d, portal id %d",
+			    connection_id, portal_id);
+			TAILQ_FOREACH(pg, &conf->conf_portal_groups, pg_next) {
+				TAILQ_FOREACH(portal, &pg->pg_portals, p_next) {
+					if (portal->p_id == portal_id) {
+						goto found;
+					}
+				}
+			}
 
-			/*
-			 * XXX: This is obviously temporary.
-			 */
-			pg = TAILQ_FIRST(&conf->conf_portal_groups);
-			portal = TAILQ_FIRST(&pg->pg_portals);
+			log_errx(1, "kernel returned invalid portal_id %d",
+			    portal_id);
 
+found:
 			handle_connection(portal, connection_id, dont_fork);
 		} else {
 #endif

Modified: head/usr.sbin/ctld/ctld.h
==============================================================================
--- head/usr.sbin/ctld/ctld.h	Wed Apr 16 10:18:44 2014	(r264525)
+++ head/usr.sbin/ctld/ctld.h	Wed Apr 16 10:29:34 2014	(r264526)
@@ -88,6 +88,9 @@ struct portal {
 	bool				p_iser;
 	char				*p_listen;
 	struct addrinfo			*p_ai;
+#ifdef ICL_KERNEL_PROXY
+	int				p_id;
+#endif
 
 	TAILQ_HEAD(, target)		p_targets;
 	int				p_socket;
@@ -146,6 +149,9 @@ struct conf {
 	int				conf_maxproc;
 
 	uint16_t			conf_last_portal_group_tag;
+#ifdef ICL_KERNEL_PROXY
+	int				conf_portal_id;
+#endif
 	struct pidfh			*conf_pidfh;
 
 	bool				conf_default_pg_defined;
@@ -265,8 +271,9 @@ void			kernel_capsicate(void);
 /*
  * ICL_KERNEL_PROXY
  */
-void			kernel_listen(struct addrinfo *ai, bool iser);
-int			kernel_accept(void);
+void			kernel_listen(struct addrinfo *ai, bool iser,
+			    int portal_id);
+void			kernel_accept(int *connection_id, int *portal_id);
 void			kernel_send(struct pdu *pdu);
 void			kernel_receive(struct pdu *pdu);
 

Modified: head/usr.sbin/ctld/kernel.c
==============================================================================
--- head/usr.sbin/ctld/kernel.c	Wed Apr 16 10:18:44 2014	(r264525)
+++ head/usr.sbin/ctld/kernel.c	Wed Apr 16 10:29:34 2014	(r264526)
@@ -622,13 +622,15 @@ kernel_handoff(struct connection *conn)
 	req.data.handoff.max_burst_length = conn->conn_max_burst_length;
 	req.data.handoff.immediate_data = conn->conn_immediate_data;
 
-	if (ioctl(ctl_fd, CTL_ISCSI, &req) == -1)
+	if (ioctl(ctl_fd, CTL_ISCSI, &req) == -1) {
 		log_err(1, "error issuing CTL_ISCSI ioctl; "
 		    "dropping connection");
+	}
 
-	if (req.status != CTL_ISCSI_OK)
+	if (req.status != CTL_ISCSI_OK) {
 		log_errx(1, "error returned from CTL iSCSI handoff request: "
 		    "%s; dropping connection", req.error_str);
+	}
 }
 
 int
@@ -673,7 +675,7 @@ kernel_port_off(void)
 
 #ifdef ICL_KERNEL_PROXY
 void
-kernel_listen(struct addrinfo *ai, bool iser)
+kernel_listen(struct addrinfo *ai, bool iser, int portal_id)
 {
 	struct ctl_iscsi req;
 
@@ -686,11 +688,10 @@ kernel_listen(struct addrinfo *ai, bool 
 	req.data.listen.protocol = ai->ai_protocol;
 	req.data.listen.addr = ai->ai_addr;
 	req.data.listen.addrlen = ai->ai_addrlen;
+	req.data.listen.portal_id = portal_id;
 
-	if (ioctl(ctl_fd, CTL_ISCSI, &req) == -1) {
+	if (ioctl(ctl_fd, CTL_ISCSI, &req) == -1)
 		log_err(1, "error issuing CTL_ISCSI ioctl");
-		return;
-	}
 
 	if (req.status != CTL_ISCSI_OK) {
 		log_errx(1, "error returned from CTL iSCSI listen: %s",
@@ -698,8 +699,8 @@ kernel_listen(struct addrinfo *ai, bool 
 	}
 }
 
-int
-kernel_accept(void)
+void
+kernel_accept(int *connection_id, int *portal_id)
 {
 	struct ctl_iscsi req;
 
@@ -707,18 +708,16 @@ kernel_accept(void)
 
 	req.type = CTL_ISCSI_ACCEPT;
 
-	if (ioctl(ctl_fd, CTL_ISCSI, &req) == -1) {
-		log_warn("error issuing CTL_ISCSI ioctl");
-		return (0);
-	}
+	if (ioctl(ctl_fd, CTL_ISCSI, &req) == -1)
+		log_err(1, "error issuing CTL_ISCSI ioctl");
 
 	if (req.status != CTL_ISCSI_OK) {
-		log_warnx("error returned from CTL iSCSI accept: %s",
+		log_errx(1, "error returned from CTL iSCSI accept: %s",
 		    req.error_str);
-		return (0);
 	}
 
-	return (req.data.accept.connection_id);
+	*connection_id = req.data.accept.connection_id;
+	*portal_id = req.data.accept.portal_id;
 }
 
 void



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