diff options
author | mav <mav@FreeBSD.org> | 2015-09-07 13:43:05 +0000 |
---|---|---|
committer | mav <mav@FreeBSD.org> | 2015-09-07 13:43:05 +0000 |
commit | 0bc1e39132872349f177743f9f4d6e6586d7ebf3 (patch) | |
tree | 2845ff1c1273e232d57e42e2ccd4ffee98c51849 /usr.sbin/ctld | |
parent | 59e96ee17c1361bf63bc08572706e00ba1288649 (diff) | |
download | FreeBSD-src-0bc1e39132872349f177743f9f4d6e6586d7ebf3.zip FreeBSD-src-0bc1e39132872349f177743f9f4d6e6586d7ebf3.tar.gz |
Add two new portal group options "tag" and "foreign".
They are going to be useful in clustered setups.
Diffstat (limited to 'usr.sbin/ctld')
-rw-r--r-- | usr.sbin/ctld/ctl.conf.5 | 12 | ||||
-rw-r--r-- | usr.sbin/ctld/ctld.c | 21 | ||||
-rw-r--r-- | usr.sbin/ctld/ctld.h | 2 | ||||
-rw-r--r-- | usr.sbin/ctld/parse.y | 28 | ||||
-rw-r--r-- | usr.sbin/ctld/token.l | 2 |
5 files changed, 58 insertions, 7 deletions
diff --git a/usr.sbin/ctld/ctl.conf.5 b/usr.sbin/ctld/ctl.conf.5 index 16b2aa2..121daa7 100644 --- a/usr.sbin/ctld/ctl.conf.5 +++ b/usr.sbin/ctld/ctl.conf.5 @@ -1,4 +1,5 @@ .\" Copyright (c) 2012 The FreeBSD Foundation +.\" Copyright (c) 2015 Alexander Motin <mav@FreeBSD.org> .\" All rights reserved. .\" .\" This software was developed by Edward Tomasz Napierala under sponsorship @@ -27,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 24, 2015 +.Dd September 7, 2015 .Dt CTL.CONF 5 .Os .Sh NAME @@ -236,6 +237,15 @@ Redirection happens before authentication and any or .Sy initiator-portal checks are skipped. +.It Ic tag Ar value +Unique 16-bit tag value of this +.Sy portal-group . +If not specified, the value is generated automatically. +.It Ic foreign +Specifies that this +.Sy portal-group +is listened by some other host. +This host will announce it on discovery stage, but won't listen. .El .Ss target Context .Bl -tag -width indent diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c index f146ee6..9803a5d 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -59,7 +59,7 @@ static volatile bool sigterm_received = false; static volatile bool sigalrm_received = false; static int nchildren = 0; -static uint16_t last_portal_group_tag = 0; +static uint16_t last_portal_group_tag = 0xff; static void usage(void) @@ -1229,6 +1229,7 @@ port_new(struct conf *conf, struct target *target, struct portal_group *pg) port->p_target = target; TAILQ_INSERT_TAIL(&pg->pg_ports, port, p_pgs); port->p_portal_group = pg; + port->p_foreign = pg->pg_foreign; return (port); } @@ -1734,14 +1735,16 @@ conf_verify(struct conf *conf) if (pg->pg_discovery_filter == PG_FILTER_UNKNOWN) pg->pg_discovery_filter = PG_FILTER_NONE; - if (!TAILQ_EMPTY(&pg->pg_ports)) { - if (pg->pg_redirection != NULL) { + if (pg->pg_redirection != NULL) { + if (!TAILQ_EMPTY(&pg->pg_ports)) { log_debugx("portal-group \"%s\" assigned " "to target, but configured " "for redirection", pg->pg_name); } pg->pg_unassigned = false; + } else if (!TAILQ_EMPTY(&pg->pg_ports)) { + pg->pg_unassigned = false; } else { if (strcmp(pg->pg_name, "default") != 0) log_warnx("portal-group \"%s\" not assigned " @@ -1835,6 +1838,8 @@ conf_apply(struct conf *oldconf, struct conf *newconf) * Go through the new portal groups, assigning tags or preserving old. */ TAILQ_FOREACH(newpg, &newconf->conf_portal_groups, pg_next) { + if (newpg->pg_tag != 0) + continue; oldpg = portal_group_find(oldconf, newpg->pg_name); if (oldpg != NULL) newpg->pg_tag = oldpg->pg_tag; @@ -1864,8 +1869,10 @@ conf_apply(struct conf *oldconf, struct conf *newconf) * and missing in the new one. */ TAILQ_FOREACH_SAFE(oldport, &oldconf->conf_ports, p_next, tmpport) { + if (oldport->p_foreign) + continue; newport = port_find(newconf, oldport->p_name); - if (newport != NULL) + if (newport != NULL && !newport->p_foreign) continue; log_debugx("removing port \"%s\"", oldport->p_name); error = kernel_port_remove(oldport); @@ -1985,9 +1992,11 @@ conf_apply(struct conf *oldconf, struct conf *newconf) * Now add new ports or modify existing ones. */ TAILQ_FOREACH(newport, &newconf->conf_ports, p_next) { + if (newport->p_foreign) + continue; oldport = port_find(oldconf, newport->p_name); - if (oldport == NULL) { + if (oldport == NULL || oldport->p_foreign) { log_debugx("adding port \"%s\"", newport->p_name); error = kernel_port_add(newport); } else { @@ -2011,6 +2020,8 @@ conf_apply(struct conf *oldconf, struct conf *newconf) * Go through the new portals, opening the sockets as neccessary. */ TAILQ_FOREACH(newpg, &newconf->conf_portal_groups, pg_next) { + if (newpg->pg_foreign) + continue; if (newpg->pg_unassigned) { log_debugx("not listening on portal-group \"%s\", " "not assigned to any target", diff --git a/usr.sbin/ctld/ctld.h b/usr.sbin/ctld/ctld.h index 8ac8de7..4f43c4e 100644 --- a/usr.sbin/ctld/ctld.h +++ b/usr.sbin/ctld/ctld.h @@ -116,6 +116,7 @@ struct portal_group { char *pg_name; struct auth_group *pg_discovery_auth_group; int pg_discovery_filter; + int pg_foreign; bool pg_unassigned; TAILQ_HEAD(, portal) pg_portals; TAILQ_HEAD(, port) pg_ports; @@ -145,6 +146,7 @@ struct port { struct portal_group *p_portal_group; struct pport *p_pport; struct target *p_target; + int p_foreign; uint32_t p_ctl_port; }; diff --git a/usr.sbin/ctld/parse.y b/usr.sbin/ctld/parse.y index cfc202c..677b5d5 100644 --- a/usr.sbin/ctld/parse.y +++ b/usr.sbin/ctld/parse.y @@ -58,10 +58,11 @@ extern void yyrestart(FILE *); %token ALIAS AUTH_GROUP AUTH_TYPE BACKEND BLOCKSIZE CHAP CHAP_MUTUAL %token CLOSING_BRACKET DEBUG DEVICE_ID DISCOVERY_AUTH_GROUP DISCOVERY_FILTER +%token FOREIGN %token INITIATOR_NAME INITIATOR_PORTAL ISNS_SERVER ISNS_PERIOD ISNS_TIMEOUT %token LISTEN LISTEN_ISER LUN MAXPROC OFFLOAD OPENING_BRACKET OPTION %token PATH PIDFILE PORT PORTAL_GROUP REDIRECT SEMICOLON SERIAL SIZE STR -%token TARGET TIMEOUT +%token TAG TARGET TIMEOUT %union { @@ -337,6 +338,8 @@ portal_group_entry: | portal_group_discovery_filter | + portal_group_foreign + | portal_group_listen | portal_group_listen_iser @@ -344,6 +347,8 @@ portal_group_entry: portal_group_offload | portal_group_redirect + | + portal_group_tag ; portal_group_discovery_auth_group: DISCOVERY_AUTH_GROUP STR @@ -377,6 +382,13 @@ portal_group_discovery_filter: DISCOVERY_FILTER STR } ; +portal_group_foreign: FOREIGN + { + + portal_group->pg_foreign = 1; + } + ; + portal_group_listen: LISTEN STR { int error; @@ -421,6 +433,20 @@ portal_group_redirect: REDIRECT STR } ; +portal_group_tag: TAG STR + { + uint64_t tmp; + + if (expand_number($2, &tmp) != 0) { + yyerror("invalid numeric value"); + free($2); + return (1); + } + + portal_group->pg_tag = tmp; + } + ; + lun: LUN lun_name OPENING_BRACKET lun_entries CLOSING_BRACKET { diff --git a/usr.sbin/ctld/token.l b/usr.sbin/ctld/token.l index caf59cc..19535f7 100644 --- a/usr.sbin/ctld/token.l +++ b/usr.sbin/ctld/token.l @@ -58,6 +58,7 @@ debug { return DEBUG; } device-id { return DEVICE_ID; } discovery-auth-group { return DISCOVERY_AUTH_GROUP; } discovery-filter { return DISCOVERY_FILTER; } +foreign { return FOREIGN; } initiator-name { return INITIATOR_NAME; } initiator-portal { return INITIATOR_PORTAL; } listen { return LISTEN; } @@ -76,6 +77,7 @@ portal-group { return PORTAL_GROUP; } redirect { return REDIRECT; } serial { return SERIAL; } size { return SIZE; } +tag { return TAG; } target { return TARGET; } timeout { return TIMEOUT; } \"[^"]+\" { yylval.str = strndup(yytext + 1, |