summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2015-10-05 08:54:02 +0000
committermav <mav@FreeBSD.org>2015-10-05 08:54:02 +0000
commitf1a03e38c50a7d5bc9185fe40d17d80197e1b575 (patch)
tree1a08e553d4971f77bb63d59918a7859e615123fa
parent3f61db5756a866fb4ec6b09cacd0ccbce7410361 (diff)
downloadFreeBSD-src-f1a03e38c50a7d5bc9185fe40d17d80197e1b575.zip
FreeBSD-src-f1a03e38c50a7d5bc9185fe40d17d80197e1b575.tar.gz
MFC r287534: Add two new portal group options "tag" and "foreign".
They are going to be useful in clustered setups.
-rw-r--r--usr.sbin/ctld/ctl.conf.512
-rw-r--r--usr.sbin/ctld/ctld.c21
-rw-r--r--usr.sbin/ctld/ctld.h2
-rw-r--r--usr.sbin/ctld/parse.y28
-rw-r--r--usr.sbin/ctld/token.l2
5 files changed, 58 insertions, 7 deletions
diff --git a/usr.sbin/ctld/ctl.conf.5 b/usr.sbin/ctld/ctl.conf.5
index af50c0a..9e8ac67 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 June 24, 2015
+.Dd September 7, 2015
.Dt CTL.CONF 5
.Os
.Sh NAME
@@ -239,6 +240,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 85f1133..90b74bf 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)
@@ -1212,6 +1212,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);
}
@@ -1717,14 +1718,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 "
@@ -1818,6 +1821,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;
@@ -1847,8 +1852,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);
@@ -1968,9 +1975,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 {
@@ -1994,6 +2003,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 a4e260b..9d2465c 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;
@@ -144,6 +145,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 8ef20fa..dda130b 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 OPENING_BRACKET OPTION
%token PATH PIDFILE PORT PORTAL_GROUP REDIRECT SEMICOLON SERIAL SIZE STR
-%token TARGET TIMEOUT
+%token TAG TARGET TIMEOUT
%union
{
@@ -337,11 +338,15 @@ portal_group_entry:
|
portal_group_discovery_filter
|
+ portal_group_foreign
+ |
portal_group_listen
|
portal_group_listen_iser
|
portal_group_redirect
+ |
+ portal_group_tag
;
portal_group_discovery_auth_group: DISCOVERY_AUTH_GROUP STR
@@ -375,6 +380,13 @@ portal_group_discovery_filter: DISCOVERY_FILTER STR
}
;
+portal_group_foreign: FOREIGN
+ {
+
+ portal_group->pg_foreign = 1;
+ }
+ ;
+
portal_group_listen: LISTEN STR
{
int error;
@@ -408,6 +420,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 6db3297..979949c 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; }
@@ -75,6 +76,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,
OpenPOWER on IntegriCloud