diff options
author | trasz <trasz@FreeBSD.org> | 2014-05-07 07:32:45 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2014-05-07 07:32:45 +0000 |
commit | f2085cbf68170b0ebbd85e5433c6ce5d1597123c (patch) | |
tree | c08f5aa92cff17cc13d9c093c00feebe14f4fd2c | |
parent | f86dc9fb87f300d9fa5fc14c7723812853a5fc98 (diff) | |
download | FreeBSD-src-f2085cbf68170b0ebbd85e5433c6ce5d1597123c.zip FreeBSD-src-f2085cbf68170b0ebbd85e5433c6ce5d1597123c.tar.gz |
MFC r264526:
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
-rw-r--r-- | sys/cam/ctl/ctl_frontend_iscsi.c | 17 | ||||
-rw-r--r-- | sys/cam/ctl/ctl_frontend_iscsi.h | 1 | ||||
-rw-r--r-- | sys/cam/ctl/ctl_ioctl.h | 9 | ||||
-rw-r--r-- | sys/dev/iscsi/icl.h | 18 | ||||
-rw-r--r-- | sys/dev/iscsi/icl_proxy.c | 19 | ||||
-rw-r--r-- | usr.sbin/ctld/ctld.c | 33 | ||||
-rw-r--r-- | usr.sbin/ctld/ctld.h | 11 | ||||
-rw-r--r-- | usr.sbin/ctld/kernel.c | 29 |
8 files changed, 74 insertions, 63 deletions
diff --git a/sys/cam/ctl/ctl_frontend_iscsi.c b/sys/cam/ctl/ctl_frontend_iscsi.c index 3b3da91..2d07e1b 100644 --- a/sys/cam/ctl/ctl_frontend_iscsi.c +++ b/sys/cam/ctl/ctl_frontend_iscsi.c @@ -1350,7 +1350,7 @@ cfiscsi_module_event_handler(module_t mod, int what, void *arg) #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 *ci) } 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 *ci) 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) 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", diff --git a/sys/cam/ctl/ctl_frontend_iscsi.h b/sys/cam/ctl/ctl_frontend_iscsi.h index 1642944..759c739 100644 --- a/sys/cam/ctl/ctl_frontend_iscsi.h +++ b/sys/cam/ctl/ctl_frontend_iscsi.h @@ -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; diff --git a/sys/cam/ctl/ctl_ioctl.h b/sys/cam/ctl/ctl_ioctl.h index acd6bfe..c81a525 100644 --- a/sys/cam/ctl/ctl_ioctl.h +++ b/sys/cam/ctl/ctl_ioctl.h @@ -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 }; diff --git a/sys/dev/iscsi/icl.h b/sys/dev/iscsi/icl.h index d5f5aa2..e30c3d1 100644 --- a/sys/dev/iscsi/icl.h +++ b/sys/dev/iscsi/icl.h @@ -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 *ic, bool rdma, /* * 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); /* diff --git a/sys/dev/iscsi/icl_proxy.c b/sys/dev/iscsi/icl_proxy.c index 41e64c3..18c9d20 100644 --- a/sys/dev/iscsi/icl_proxy.c +++ b/sys/dev/iscsi/icl_proxy.c @@ -182,7 +182,7 @@ icl_conn_connect(struct icl_conn *ic, bool rdma, int domain, int socktype, } 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, int domain, int socktype, int protocol 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 domain, int socktype, int protocol } 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, bool rdma, int domain, int socktype, int p 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 diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c index 354d0ed..a884cf8 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -1408,9 +1408,13 @@ conf_apply(struct conf *oldconf, struct conf *newconf) #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_fork) 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_fork) #ifdef ICL_KERNEL_PROXY if (proxy_mode) { - connection_id = kernel_accept(); - if (connection_id == 0) - continue; + kernel_accept(&connection_id, &portal_id); - /* - * XXX: This is obviously temporary. - */ - pg = TAILQ_FIRST(&conf->conf_portal_groups); - portal = TAILQ_FIRST(&pg->pg_portals); + 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; + } + } + } + + log_errx(1, "kernel returned invalid portal_id %d", + portal_id); +found: handle_connection(portal, connection_id, dont_fork); } else { #endif diff --git a/usr.sbin/ctld/ctld.h b/usr.sbin/ctld/ctld.h index ce161b6..be7be13 100644 --- a/usr.sbin/ctld/ctld.h +++ b/usr.sbin/ctld/ctld.h @@ -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); diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.c index a0e68ba..6907868 100644 --- a/usr.sbin/ctld/kernel.c +++ b/usr.sbin/ctld/kernel.c @@ -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 iser) 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 iser) } } -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 |