Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Feb 2025 15:15:52 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: b797cc839a12 - main - ctld: Support anonymous LUN entries in UCL
Message-ID:  <202502261515.51QFFq8D034055@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=b797cc839a12fc358e99635ca3adf3cf80e0825b

commit b797cc839a12fc358e99635ca3adf3cf80e0825b
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-02-26 15:13:10 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-02-26 15:13:48 +0000

    ctld: Support anonymous LUN entries in UCL
    
    If a target LUN entry doesn't have a name property, assume it is an
    anonymous LUN and parse other properties from the entry to define the
    LUN.
    
    This removes the odd support for target LUNs only named by an integer.
    My guess is this was meant to implement support for anonymous LUNs
    based on how the syntax for this works in the non-UCL case, but the
    prior implementation was useless (it just created unconfigured LUNs).
    
    Sponsored by:   Chelsio Communications
    Differential Revision:  https://reviews.freebsd.org/D48937
---
 usr.sbin/ctld/ctl.conf.5 |  30 +++++++-------
 usr.sbin/ctld/uclparse.c | 106 ++++++++++++++++++++++++++++-------------------
 2 files changed, 77 insertions(+), 59 deletions(-)

diff --git a/usr.sbin/ctld/ctl.conf.5 b/usr.sbin/ctld/ctl.conf.5
index 0be873fe512c..015fc1e12e36 100644
--- a/usr.sbin/ctld/ctl.conf.5
+++ b/usr.sbin/ctld/ctl.conf.5
@@ -26,7 +26,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd October 13, 2020
+.Dd February 26, 2025
 .Dt CTL.CONF 5
 .Os
 .Sh NAME
@@ -543,25 +543,12 @@ portal-group {
 }
 
 lun {
-	example_0 {
-		path = /dev/zvol/tank/example_0
-		blocksize = 4096
-		size = 4GB
-	}
-
 	example_1 {
 		path = /dev/zvol/tank/example_1
 		options {
 			naa = "0x50015178f369f093"
 		}
 	}
-
-	example_2 {
-		path = /dev/zvol/tank/example_2
-		options {
-			vendor = "FreeBSD"
-		}
-	}
 }
 
 target {
@@ -569,7 +556,12 @@ target {
 		alias = "Example target"
 		auth-group = no-authentication
 		lun = [
-			{ number = 0, name = example_0 },
+			{
+				number = 0
+				path = /dev/zvol/tank/example_0
+				blocksize = 4096
+				size = 4GB
+			}
 		]
 	}
 
@@ -578,7 +570,13 @@ target {
 		portal-group { name = pg0 }
 		lun = [
 			{ number = 0, name = example_1 },
-			{ number = 1, name = example_2 }
+			{
+				number = 1
+				path = /dev/zvol/tank/example_2
+				options {
+					vendor = "FreeBSD"
+				}
+			}
 		]
 	}
 
diff --git a/usr.sbin/ctld/uclparse.c b/usr.sbin/ctld/uclparse.c
index 7c786afb1e93..b9d88a1d45d2 100644
--- a/usr.sbin/ctld/uclparse.c
+++ b/usr.sbin/ctld/uclparse.c
@@ -48,6 +48,7 @@ static bool uclparse_toplevel(const ucl_object_t *);
 static bool uclparse_chap(const char *, const ucl_object_t *);
 static bool uclparse_chap_mutual(const char *, const ucl_object_t *);
 static bool uclparse_lun(const char *, const ucl_object_t *);
+static bool uclparse_lun_entries(const char *, const ucl_object_t *);
 static bool uclparse_auth_group(const char *, const ucl_object_t *);
 static bool uclparse_portal_group(const char *, const ucl_object_t *);
 static bool uclparse_target(const char *, const ucl_object_t *);
@@ -216,35 +217,44 @@ uclparse_target_portal_group(const char *t_name, const ucl_object_t *obj)
 static bool
 uclparse_target_lun(const char *t_name, const ucl_object_t *obj)
 {
-	if (obj->type == UCL_INT) {
-		if (!target_start_lun(ucl_object_toint(obj)))
-			return (false);
-		lun_finish();
-		return (true);
+	const ucl_object_t *num;
+	const ucl_object_t *name;
+	char *lun_name;
+	u_int id;
+	bool ok;
+
+	if (obj->type != UCL_OBJECT) {
+		log_warnx("lun section entries in target \"%s\" must be objects",
+		    t_name);
+		return (false);
 	}
 
-	if (obj->type == UCL_OBJECT) {
-		const ucl_object_t *num = ucl_object_find_key(obj, "number");
-		const ucl_object_t *name = ucl_object_find_key(obj, "name");
+	num = ucl_object_find_key(obj, "number");
+	if (num == NULL || num->type != UCL_INT) {
+		log_warnx("lun section in target \"%s\" is missing "
+		    "\"number\" integer property", t_name);
+		return (false);
+	}
+	id = ucl_object_toint(num);
 
-		if (num == NULL || num->type != UCL_INT) {
-			log_warnx("lun section in target \"%s\" is missing "
-			    "\"number\" integer property", t_name);
+	name = ucl_object_find_key(obj, "name");
+	if (name == NULL) {
+		if (!target_start_lun(id))
 			return (false);
-		}
 
-		if (name == NULL || name->type != UCL_STRING) {
-			log_warnx("lun section in target \"%s\" is missing "
-			    "\"name\" string property", t_name);
-			return (false);
-		}
+		asprintf(&lun_name, "lun %u for target \"%s\"", id, t_name);
+		ok = uclparse_lun_entries(lun_name, obj);
+		free(lun_name);
+		return (ok);
+	}
 
-		if (!target_add_lun(ucl_object_toint(num),
-		    ucl_object_tostring(name)))
-			return (false);
+	if (name->type != UCL_STRING) {
+		log_warnx("\"name\" property for lun %u for target "
+		    "\"%s\" is not a string", id, t_name);
+		return (false);
 	}
 
-	return (true);
+	return (target_add_lun(id, ucl_object_tostring(name)));
 }
 
 static bool
@@ -929,21 +939,31 @@ fail:
 static bool
 uclparse_lun(const char *name, const ucl_object_t *top)
 {
-	ucl_object_iter_t it = NULL, child_it = NULL;
-	const ucl_object_t *obj = NULL, *child = NULL;
-	const char *key;
+	char *lun_name;
+	bool ok;
 
 	if (!lun_start(name))
 		return (false);
+	asprintf(&lun_name, "lun \"%s\"", name);
+	ok = uclparse_lun_entries(lun_name, top);
+	free(lun_name);
+	return (ok);
+}
+
+static bool
+uclparse_lun_entries(const char *name, const ucl_object_t *top)
+{
+	ucl_object_iter_t it = NULL, child_it = NULL;
+	const ucl_object_t *obj = NULL, *child = NULL;
+	const char *key;
 
 	while ((obj = ucl_iterate_object(top, &it, true))) {
 		key = ucl_object_key(obj);
 
 		if (strcmp(key, "backend") == 0) {
 			if (obj->type != UCL_STRING) {
-				log_warnx("\"backend\" property of lun "
-				    "\"%s\" is not a string",
-				    name);
+				log_warnx("\"backend\" property of %s "
+				    "is not a string", name);
 				goto fail;
 			}
 
@@ -953,8 +973,8 @@ uclparse_lun(const char *name, const ucl_object_t *top)
 
 		if (strcmp(key, "blocksize") == 0) {
 			if (obj->type != UCL_INT) {
-				log_warnx("\"blocksize\" property of lun "
-				    "\"%s\" is not an integer", name);
+				log_warnx("\"blocksize\" property of %s "
+				    "is not an integer", name);
 				goto fail;
 			}
 
@@ -964,8 +984,8 @@ uclparse_lun(const char *name, const ucl_object_t *top)
 
 		if (strcmp(key, "device-id") == 0) {
 			if (obj->type != UCL_STRING) {
-				log_warnx("\"device-id\" property of lun "
-				    "\"%s\" is not an integer", name);
+				log_warnx("\"device-id\" property of %s "
+				    "is not an integer", name);
 				goto fail;
 			}
 
@@ -975,8 +995,8 @@ uclparse_lun(const char *name, const ucl_object_t *top)
 
 		if (strcmp(key, "device-type") == 0) {
 			if (obj->type != UCL_STRING) {
-				log_warnx("\"device-type\" property of lun "
-				    "\"%s\" is not an integer", name);
+				log_warnx("\"device-type\" property of %s "
+				    "is not an integer", name);
 				goto fail;
 			}
 
@@ -986,8 +1006,8 @@ uclparse_lun(const char *name, const ucl_object_t *top)
 
 		if (strcmp(key, "ctl-lun") == 0) {
 			if (obj->type != UCL_INT) {
-				log_warnx("\"ctl-lun\" property of lun "
-				    "\"%s\" is not an integer", name);
+				log_warnx("\"ctl-lun\" property of %s "
+				    "is not an integer", name);
 				goto fail;
 			}
 
@@ -997,8 +1017,8 @@ uclparse_lun(const char *name, const ucl_object_t *top)
 
 		if (strcmp(key, "options") == 0) {
 			if (obj->type != UCL_OBJECT) {
-				log_warnx("\"options\" property of lun "
-				    "\"%s\" is not an object", name);
+				log_warnx("\"options\" property of %s "
+				    "is not an object", name);
 				goto fail;
 			}
 
@@ -1012,8 +1032,8 @@ uclparse_lun(const char *name, const ucl_object_t *top)
 
 		if (strcmp(key, "path") == 0) {
 			if (obj->type != UCL_STRING) {
-				log_warnx("\"path\" property of lun "
-				    "\"%s\" is not a string", name);
+				log_warnx("\"path\" property of %s "
+				    "is not a string", name);
 				goto fail;
 			}
 
@@ -1023,8 +1043,8 @@ uclparse_lun(const char *name, const ucl_object_t *top)
 
 		if (strcmp(key, "serial") == 0) {
 			if (obj->type != UCL_STRING) {
-				log_warnx("\"serial\" property of lun "
-				    "\"%s\" is not a string", name);
+				log_warnx("\"serial\" property of %s "
+				    "is not a string", name);
 				goto fail;
 			}
 
@@ -1034,8 +1054,8 @@ uclparse_lun(const char *name, const ucl_object_t *top)
 
 		if (strcmp(key, "size") == 0) {
 			if (obj->type != UCL_INT) {
-				log_warnx("\"size\" property of lun "
-				    "\"%s\" is not an integer", name);
+				log_warnx("\"size\" property of %s "
+				    "is not an integer", name);
 				goto fail;
 			}
 



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