summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2014-04-16 10:29:34 +0000
committertrasz <trasz@FreeBSD.org>2014-04-16 10:29:34 +0000
commit9f88148032ca16625893bf074fd0f1edd458d878 (patch)
treeada15b3b38699ce211d0d7e29931a5b87f97c2e1 /usr.sbin
parentbc4e49eb8621bf764bdc8d39bef802a40fc85a8e (diff)
downloadFreeBSD-src-9f88148032ca16625893bf074fd0f1edd458d878.zip
FreeBSD-src-9f88148032ca16625893bf074fd0f1edd458d878.tar.gz
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
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ctld/ctld.c33
-rw-r--r--usr.sbin/ctld/ctld.h11
-rw-r--r--usr.sbin/ctld/kernel.c29
3 files changed, 45 insertions, 28 deletions
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 3c4a547..45c76c8 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
OpenPOWER on IntegriCloud