ctld: Permit targets to use a string for portal-groups in UCL

In the case that a separate auth-group is not required, this permits
replacing:

	portal-group = { name = pg0 }

with:

	portal-group = pg0

Sponsored by:	Chelsio Communications
Differential Revision:	https://reviews.freebsd.org/D48938
This commit is contained in:
John Baldwin
2025-02-26 10:13:56 -05:00
parent b797cc839a
commit e49db000c4
2 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -567,7 +567,7 @@ target {
"iqn.2012-06.com.example:target1" {
auth-group = ag0
portal-group { name = pg0 }
portal-group = pg0
lun = [
{ number = 0, name = example_1 },
{
+17 -5
View File
@@ -191,6 +191,20 @@ uclparse_target_portal_group(const char *t_name, const ucl_object_t *obj)
const ucl_object_t *portal_group, *auth_group;
const char *ag_name;
/*
* If the value is a single string, assume it is a
* portal-group name.
*/
if (obj->type == UCL_STRING)
return (target_add_portal_group(ucl_object_tostring(obj),
NULL));
if (obj->type != UCL_OBJECT) {
log_warnx("portal-group section in target \"%s\" must be "
"an object or string", t_name);
return (false);
}
portal_group = ucl_object_find_key(obj, "name");
if (!portal_group || portal_group->type != UCL_STRING) {
log_warnx("portal-group section in target \"%s\" is missing "
@@ -884,11 +898,6 @@ uclparse_target(const char *name, const ucl_object_t *top)
}
if (strcmp(key, "portal-group") == 0) {
if (obj->type == UCL_OBJECT) {
if (!uclparse_target_portal_group(name, obj))
goto fail;
}
if (obj->type == UCL_ARRAY) {
while ((tmp = ucl_iterate_object(obj, &it2,
true))) {
@@ -896,6 +905,9 @@ uclparse_target(const char *name, const ucl_object_t *top)
tmp))
goto fail;
}
} else {
if (!uclparse_target_portal_group(name, obj))
goto fail;
}
}