From d5e405d1168dc48504d031facd5a43b036e8776e Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Wed, 30 Jun 2021 18:30:57 +0200 Subject: [PATCH] LU-14797 nodemap: map project id Add calls to nodemap_map_id() in order to map project IDs from client ID to server ID and conversely. Also extend nodemap_can_setquota() to allow setquota on project only if ID is not squashed or deny_unknown is not set. Update sanity-sec test_27a to exercise the feature. Lustre-change: https://review.whamcloud.com/44119 Lustre-commit: 0daeebcbdc4e89d59221299f2687cfd3c4f00b5b --- lustre/include/lustre_nodemap.h | 2 +- lustre/tests/sanity-sec.sh | 42 +++++++++++++++++++++++++++++++++ lustre/utils/lfs.c | 6 ++++- 10 files changed, 105 insertions(+), 19 deletions(-) diff --git a/lustre/include/lustre_nodemap.h b/lustre/include/lustre_nodemap.h index 15ed2700fa..17306a586b 100644 --- a/lustre/include/lustre_nodemap.h +++ b/lustre/include/lustre_nodemap.h @@ -155,7 +155,7 @@ int nodemap_set_squash_gid(const char *name, gid_t gid); int nodemap_set_squash_projid(const char *name, projid_t projid); int nodemap_set_audit_mode(const char *name, bool enable_audit); int nodemap_set_forbid_encryption(const char *name, bool forbid_encryption); -bool nodemap_can_setquota(const struct lu_nodemap *nodemap); +bool nodemap_can_setquota(struct lu_nodemap *nodemap, __u32 qc_type, __u32 id); int nodemap_add_idmap(const char *name, enum nodemap_id_type id_type, const __u32 map[2]); int nodemap_del_idmap(const char *name, enum nodemap_id_type id_type, diff --git a/lustre/tests/sanity-sec.sh b/lustre/tests/sanity-sec.sh index 5213d02d8b..3c233701f7 100755 --- a/lustre/tests/sanity-sec.sh +++ b/lustre/tests/sanity-sec.sh @@ -949,6 +949,20 @@ test_13() { rc=$? [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1 + for (( i = 0; i < NODEMAP_COUNT; i++ )); do + local csum=${HOSTNAME_CHECKSUM}_${i} + + if ! do_facet mgs $LCTL nodemap_modify --name $csum \ + --property admin --value 0; then + rc=$((rc + 1)) + fi + if ! do_facet mgs $LCTL nodemap_modify --name $csum \ + --property trusted --value 0; then + rc=$((rc + 1)) + fi + done + [[ $rc != 0 ]] && error "nodemap_modify failed with $rc" && return 1 + rc=0 for ((i = 0; i < NODEMAP_COUNT; i++)); do if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then @@ -1939,11 +1953,15 @@ run_test 26 "test transferring very large nodemap" nodemap_exercise_fileset() { local nm="$1" local loop=0 + local check_proj=true + + (( $MDS1_VERSION >= $(version_code 2.14.0) )) || check_proj=false # setup if [ "$nm" == "default" ]; then do_facet mgs $LCTL nodemap_activate 1 wait_nm_sync active + check_proj=false else nodemap_test_setup fi @@ -1964,6 +1982,23 @@ nodemap_exercise_fileset() { error "unable to add fileset info to $nm nodemap for servers" wait_nm_sync $nm fileset "nodemap.${nm}.fileset=/$subdir" + if $check_proj; then + do_facet mgs $LCTL nodemap_modify --name $nm \ + --property admin --value 1 + wait_nm_sync $nm admin_nodemap + do_facet mgs $LCTL nodemap_modify --name $nm \ + --property trusted --value 0 + wait_nm_sync $nm trusted_nodemap + do_facet mgs $LCTL nodemap_modify --name $nm \ + --property map_mode --value projid + wait_nm_sync $nm map_mode + do_facet mgs $LCTL nodemap_add_idmap --name $nm \ + --idtype projid --idmap 1:1 + do_facet mgs $LCTL nodemap_modify --name $nm \ + --property deny_unknown --value 1 + wait_nm_sync $nm deny_unknown + fi + # re-mount client zconf_umount_clients ${clients_arr[0]} $MOUNT || error "unable to umount client ${clients_arr[0]}" @@ -1977,6 +2012,13 @@ nodemap_exercise_fileset() { do_node ${clients_arr[0]} test -f $MOUNT/this_is_$subdir || error "fileset not taken into account" + if $check_proj; then + $LFS setquota -p 1 -b 10000 -B 11000 -i 0 -I 0 $MOUNT || + error "setquota -p 1 failed" + $LFS setquota -p 2 -b 10000 -B 11000 -i 0 -I 0 $MOUNT && + error "setquota -p 2 should have failed" + fi + # re-mount client with sub-subdir zconf_umount_clients ${clients_arr[0]} $MOUNT || error "unable to umount client ${clients_arr[0]}" diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 19d2b0db1b..1369c71d23 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -7471,9 +7471,13 @@ quota_type_def: if (rc) { if (*obd_type) fprintf(stderr, - "%s setquota: cannot quotactl '%s' '%s': %s", + "%s setquota: cannot quotactl '%s' '%s': %s\n", progname, obd_type, obd_uuid2str(&qctl->obd_uuid), strerror(-rc)); + else + fprintf(stderr, + "%s setquota: quotactl failed: %s\n", + progname, strerror(-rc)); } out: free(qctl); -- 2.28.0