From nobody Wed Feb 26 15:15:52 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Z2yj52gcCz5qHF2; Wed, 26 Feb 2025 15:15:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z2yj46qXWz3Nsd; Wed, 26 Feb 2025 15:15:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740582953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bfSaRDkpSTjtImzQCtnq2vkAPUXzvcohG1XOiZxNCpc=; b=acIyLnIY0aumFGJLIR6rNBzFHGSlVPp5bfg3s+JmgViRwkJ8/8z77wkvVjE4ouI9sW+sKJ xx8O7YlETS5ckhVK0+n43hHT/vhEee91bS1ayW+tlTaDFJLTn0QAHrhE1pNwBeo2bwEEWY FOFUHXjw3NHFORyY+Ij0X96+9E28pz2Z0/AgOPFuKiwlWTFI2BWBB7XX+nk4bLpIQNk368 NDMJTWVMLO5OQjw6CzxQeY6Burz5PbReMRccFUxFgx8vQXSVzv+zfRD57WClgl3fO9Q3cg WDvHgIE1YiP6TozkM9Dc6I61l4WeXk05jDTjyVEE+Ogf51xihc/S6dQOueW6nA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740582953; a=rsa-sha256; cv=none; b=f42Kkp0UJG6ipGEXp339CUlP04/W7G/FsL3klKZlyCK0diyQkAGHJIkhnYX12UzpPJCfe8 jtAGor3FwTGAJQOkN1grANCBSuACLIEfP6GKV7dmPqok7j6EIv+5z3/dqhbRhQ4bETo/Na asf5enp8aCtzjy2H69521Ukx0aM9uOpicI/TSYDoeWOPpF0ly1UVmv9LbYfEfK8eUA3Ugw LOtNhrEIajhztvLowMmU+1nnjulrcstbM5J8Debyc1xWowyPmeEqjxkodmFc2t7aKHaj/y CyBVz9f5ZfBKunghgS9gViZ5Z8WGwKV6QLnijbChuzcqYkuaF3vf17GyCHTI0g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740582953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bfSaRDkpSTjtImzQCtnq2vkAPUXzvcohG1XOiZxNCpc=; b=FTbIf73R3OszmrJS0QC/8hW6AvwUBn2Im+N21UHHut7WMIw6Ouj8BQwoC5LGaoV09hKWG1 i4eHWSXE4CGJfpgEUkPQLbSWf4PONMBvyBsflMpaI6Zpjv2s5IdTaZ+D/JlwDHsaT/D684 buor0C64pnEemfYUDNS/ZqeEOYnp8lzwVv0dovfa56aOyTUmp1SVkIsrqn/2jKRJIul5X/ b5JPgVc/6mURi/dfi7iA1PaIOSwG9kOgUyGimiCZSXJZhSXErcinAG9D0R/QquegCTXMhl R48suIFmbvkpjrt5Y/gbg+qyD2tDk1gJeRfCYVN6nrXmQf9HCvDAk6/FB5bWDw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Z2yj46RFXz1HDB; Wed, 26 Feb 2025 15:15:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 51QFFq8c034058; Wed, 26 Feb 2025 15:15:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51QFFq8D034055; Wed, 26 Feb 2025 15:15:52 GMT (envelope-from git) Date: Wed, 26 Feb 2025 15:15:52 GMT Message-Id: <202502261515.51QFFq8D034055@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: b797cc839a12 - main - ctld: Support anonymous LUN entries in UCL List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b797cc839a12fc358e99635ca3adf3cf80e0825b Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=b797cc839a12fc358e99635ca3adf3cf80e0825b commit b797cc839a12fc358e99635ca3adf3cf80e0825b Author: John Baldwin AuthorDate: 2025-02-26 15:13:10 +0000 Commit: John Baldwin 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; }