Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Sep 2015 13:43:05 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r287534 - head/usr.sbin/ctld
Message-ID:  <201509071343.t87Dh5S0059921@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Mon Sep  7 13:43:05 2015
New Revision: 287534
URL: https://svnweb.freebsd.org/changeset/base/287534

Log:
  Add two new portal group options "tag" and "foreign".
  
  They are going to be useful in clustered setups.

Modified:
  head/usr.sbin/ctld/ctl.conf.5
  head/usr.sbin/ctld/ctld.c
  head/usr.sbin/ctld/ctld.h
  head/usr.sbin/ctld/parse.y
  head/usr.sbin/ctld/token.l

Modified: head/usr.sbin/ctld/ctl.conf.5
==============================================================================
--- head/usr.sbin/ctld/ctl.conf.5	Mon Sep  7 13:02:25 2015	(r287533)
+++ head/usr.sbin/ctld/ctl.conf.5	Mon Sep  7 13:43:05 2015	(r287534)
@@ -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 authenticatio
 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

Modified: head/usr.sbin/ctld/ctld.c
==============================================================================
--- head/usr.sbin/ctld/ctld.c	Mon Sep  7 13:02:25 2015	(r287533)
+++ head/usr.sbin/ctld/ctld.c	Mon Sep  7 13:43:05 2015	(r287534)
@@ -59,7 +59,7 @@ static volatile bool sigterm_received = 
 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 targe
 	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 
 	 * 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 
 	 * 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 
 	 * 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 
 	 * 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",

Modified: head/usr.sbin/ctld/ctld.h
==============================================================================
--- head/usr.sbin/ctld/ctld.h	Mon Sep  7 13:02:25 2015	(r287533)
+++ head/usr.sbin/ctld/ctld.h	Mon Sep  7 13:43:05 2015	(r287534)
@@ -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;
 };

Modified: head/usr.sbin/ctld/parse.y
==============================================================================
--- head/usr.sbin/ctld/parse.y	Mon Sep  7 13:02:25 2015	(r287533)
+++ head/usr.sbin/ctld/parse.y	Mon Sep  7 13:43:05 2015	(r287534)
@@ -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
 	}
 	;
 
+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
 	{

Modified: head/usr.sbin/ctld/token.l
==============================================================================
--- head/usr.sbin/ctld/token.l	Mon Sep  7 13:02:25 2015	(r287533)
+++ head/usr.sbin/ctld/token.l	Mon Sep  7 13:43:05 2015	(r287534)
@@ -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,



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