Whamcloud - gitweb
LU-18524 utils: Improve lctl nodemap_modify interface 48/57448/8
authorMarc Vef <mvef@whamcloud.com>
Sun, 15 Dec 2024 18:21:13 +0000 (19:21 +0100)
committerOleg Drokin <green@whamcloud.com>
Wed, 26 Mar 2025 04:00:12 +0000 (04:00 +0000)
"lctl nodemap_modify" uses two separate parameters for the property
name and the corresponding value. This patch slightly improves this
interface by allowing "=value" as part of --property similar to "lctl
set_param" commands:

lctl nodemap_modify --name nm_0 --property admin=1

instead of (which is still allowed):

lctl nodemap_modify --name nm_0 --property admin --value 1

sanity-sec fileset_test_setup() was modified to exercise this
interface.

Test-Parameters: trivial testlist=sanity-sec
Signed-off-by: Marc Vef <mvef@whamcloud.com>
Change-Id: I030e1602a67c066e6daf4187589a77c1b49ee855
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57448
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/doc/lctl-nodemap-modify.8
lustre/tests/sanity-sec.sh
lustre/utils/lctl.c
lustre/utils/obd.c

index 61b29af..2be825c 100644 (file)
@@ -6,8 +6,8 @@ lctl-nodemap_modify \- modify a nodemap property
 or
 .SY "lctl nodemap modify"
 .BI --name " NODEMAP_NAME"
-.BI --property " PROPERTY_NAME"
-.BI --value " VALUE"
+.B --property
+.IR PROPERTY_NAME {\fB= VALUE |\fB--value " VALUE" }
 .YS
 .SH DESCRIPTION
 .B nodemap_modify
@@ -17,7 +17,9 @@ modifies a property of the given nodemap.
 .BI --name " NODEMAP_NAME"
 The name of the nodemap to modify
 .TP
-.BI --property " PROPERTY_NAME"
+.B --property
+.IR PROPERTY_NAME {\fB= VALUE |\fB--value " VALUE" }
+.TP
 One of the following properties:
 .RS 8
 .TP 4
@@ -125,11 +127,17 @@ And to forbid all roles, use 'none' value.
 .TP
 .BI --value " VALUE"
 The value to set for the property. Should be 0 or 1 for admin and trusted.
+The use of both
+.BI --property " PROPERTY_NAME" = VALUE
+and
+.BI --value " VALUE"
+is invalid.
 .SH EXAMPLES
 .EX
 .B # lctl nodemap_modify --name remotesite --property trusted --value 1
 .B # lctl nodemap_modify --name remotesite --property admin --value 1
 .B # lctl nodemap_modify --name remotesite --property map_mode --value uid
+.B # lctl nodemap_modify --name remotesite --property rbac=all
 .B # lctl nodemap_modify --name othersite --property squash_uid --value 101
 .EE
 .SH AVAILABILITY
index fe730d7..78152db 100755 (executable)
@@ -1318,8 +1318,13 @@ fops_test_setup() {
 # fileset test directory needs to be initialized on a privileged client
 fileset_test_setup() {
        local nm=$1
+       local modify_val=""
 
-       if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
+       # exercise new nodemap_modify syntax if available
+       (( $MGS_VERSION >= $(version_code 2.16.51) )) ||
+               modify_val=" --value"
+
+       if [[ -n $FILESET && -z $SKIP_FILESET ]]; then
                cleanup_mount $MOUNT
                FILESET="" zconf_mount_clients $CLIENTS $MOUNT
        fi
@@ -1329,11 +1334,11 @@ fileset_test_setup() {
        local trust=$(do_facet mgs $LCTL get_param -n \
                nodemap.${nm}.trusted_nodemap)
 
-       do_facet mgs $LCTL nodemap_modify --name $nm --property admin --value 1
-       do_facet mgs $LCTL nodemap_modify --name $nm --property trusted \
-               --value 1
+       do_facet mgs $LCTL nodemap_modify --name $nm \
+               --property admin${modify_val}=1
+       do_facet mgs $LCTL nodemap_modify --name $nm \
+               --property trusted${modify_val}=1
 
-       wait_nm_sync $nm admin_nodemap
        wait_nm_sync $nm trusted_nodemap
 
        # create directory and populate it for subdir mount
@@ -1349,15 +1354,14 @@ fileset_test_setup() {
                        $MOUNT/$subdir/$subsubdir/this_is_$subsubdir"
 
        do_facet mgs $LCTL nodemap_modify --name $nm \
-               --property admin --value $admin
+               --property admin${modify_val}=$admin
        do_facet mgs $LCTL nodemap_modify --name $nm \
-               --property trusted --value $trust
+               --property trusted${modify_val}=$trust
 
        # flush MDT locks to make sure they are reacquired before test
        do_node ${clients_arr[0]} $LCTL set_param \
                ldlm.namespaces.$FSNAME-MDT*.lru_size=clear
 
-       wait_nm_sync $nm admin_nodemap
        wait_nm_sync $nm trusted_nodemap
 }
 
index a46694c..7551f77 100644 (file)
@@ -602,8 +602,9 @@ command_t cmdlist[] = {
         "delete a nid range from a nodemap\n"
         "usage: nodemap_del_range --name NODEMAP_NAME --range NID_RANGE"},
        {"nodemap_modify", jt_nodemap_modify, 0,
-        "modify a nodemap parameter\n"
-        "usage: nodemap_modify --name NODEMAP_NAME --property PROPERTY_NAME --value VALUE"},
+        "modify a nodemap property\n"
+        "usage: nodemap_modify --name NODEMAP_NAME --property PROPERTY_NAME{=VALUE| --value VALUE}\n"
+        "valid properties: admin trusted map_mode squash_uid squash_gid squash_projid deny_unknown audit_mode forbid_encryption readonly_mount rbac deny_mount"},
        {"nodemap_add_offset", jt_nodemap_add_offset, 0,
         "add an offset for UID/GID/PROJID mappings\n"
         "usage: nodemap_add_offset --name NODEMAP_NAME --offset OFFSET --limit LIMIT\n"},
index 3e4988d..f97ca3b 100644 (file)
@@ -4573,7 +4573,8 @@ set_sepol_usage:
  *
  * --name                      nodemap name
  * --property                  nodemap property to change
- *                             admin, trusted, squash_uid, squash_gid)
+ *                             admin, trusted, squash_uid, squash_gid.
+ *                             Can also be in the form of property=value
  * --value                     value to set property
  *
  * \retval                     0 on success
@@ -4584,6 +4585,8 @@ int jt_nodemap_modify(int argc, char **argv)
        char *nodemap_name = NULL;
        char *param = NULL;
        char *value = NULL;
+       char *delimiter = NULL;
+       bool double_value = false;
        int c, rc = 0;
 
        static struct option long_opts[] = {
@@ -4601,33 +4604,48 @@ int jt_nodemap_modify(int argc, char **argv)
                        break;
                case 'p':
                        param = optarg;
+                       /* check for property=value format */
+                       delimiter = strchr(param, '=');
+                       if (!value && delimiter) {
+                               *delimiter = '\0';
+                               value = delimiter + 1;
+                               /* reset if empty value */
+                               if (*value == '\0')
+                                       value = NULL;
+                       } else if (value && delimiter) {
+                               double_value = true;
+                       }
                        break;
                case 'v':
-                       value = optarg;
+                       if (value && delimiter)
+                               double_value = true;
+                       else
+                               value = optarg;
                        break;
                case 'h':
+               case '?':
                default:
-                       goto modify_usage;
+                       return CMD_HELP;
                }
        }
 
+       if (double_value) {
+               fprintf(stderr,
+                       "error: %s: use of both '--property=<value>' and '--value <value>' is invalid\n",
+                       jt_cmdname(argv[0]));
+               return CMD_HELP;
+       }
        if (!nodemap_name) {
                fprintf(stderr, "nodemap_modify: missing nodemap name\n");
-modify_usage:
-               fprintf(stderr,
-                       "usage: %s --name NODEMAP_NAME --property PROPERTY_NAME --value VALUE\n",
-                       argv[0]);
-               fprintf(stderr,
-                       "valid properties: admin trusted map_mode squash_uid squash_gid squash_projid deny_unknown audit_mode forbid_encryption readonly_mount rbac deny_mount\n");
-               return -EINVAL;
+               return CMD_HELP;
        }
        if (!param) {
                fprintf(stderr, "nodemap_modify: missing property name\n");
-               goto modify_usage;
+               return CMD_HELP;
        }
        if (!value) {
                fprintf(stderr, "nodemap_modify: missing value for property\n");
-               goto modify_usage;
+               return CMD_HELP;
        }
 
        if (strcmp("admin", param) == 0) {
@@ -4658,7 +4676,7 @@ modify_usage:
                fprintf(stderr,
                        "error: %s: nodemap_modify invalid property: %s\n",
                        jt_cmdname(argv[0]), param);
-               goto modify_usage;
+               return CMD_HELP;
        }
 
        rc = nodemap_cmd(cmd, false, NULL, 0, argv[0], nodemap_name, param,