+
+test_fops_admin_cli_i=""
+test_fops_chmod_dir() {
+ local current_cli_i=$1
+ local perm_bits=$2
+ local dir_to_chmod=$3
+ local new_admin_cli_i=""
+
+ # do we need to set up a new admin client?
+ [ "$current_cli_i" == "0" ] && [ "$test_fops_admin_cli_i" != "1" ] &&
+ new_admin_cli_i=1
+ [ "$current_cli_i" != "0" ] && [ "$test_fops_admin_cli_i" != "0" ] &&
+ new_admin_cli_i=0
+
+ # if only one client, and non-admin, need to flip admin everytime
+ if [ "$num_clients" == "1" ]; then
+ test_fops_admin_client=$clients
+ test_fops_admin_val=$(do_facet mgs $LCTL get_param -n \
+ nodemap.c0.admin_nodemap)
+ if [ "$test_fops_admin_val" != "1" ]; then
+ do_facet mgs $LCTL nodemap_modify \
+ --name c0 \
+ --property admin \
+ --value 1
+ wait_nm_sync c0 admin_nodemap
+ fi
+ elif [ "$new_admin_cli_i" != "" ]; then
+ # restore admin val to old admin client
+ if [ "$test_fops_admin_cli_i" != "" ] &&
+ [ "$test_fops_admin_val" != "1" ]; then
+ do_facet mgs $LCTL nodemap_modify \
+ --name c${test_fops_admin_cli_i} \
+ --property admin \
+ --value $test_fops_admin_val
+ wait_nm_sync c${test_fops_admin_cli_i} admin_nodemap
+ fi
+
+ test_fops_admin_cli_i=$new_admin_cli_i
+ test_fops_admin_client=${clients_arr[$new_admin_cli_i]}
+ test_fops_admin_val=$(do_facet mgs $LCTL get_param -n \
+ nodemap.c${new_admin_cli_i}.admin_nodemap)
+
+ if [ "$test_fops_admin_val" != "1" ]; then
+ do_facet mgs $LCTL nodemap_modify \
+ --name c${new_admin_cli_i} \
+ --property admin \
+ --value 1
+ wait_nm_sync c${new_admin_cli_i} admin_nodemap
+ fi
+ fi
+
+ do_node $test_fops_admin_client chmod $perm_bits $DIR/$tdir || return 1
+
+ # remove admin for single client if originally non-admin
+ if [ "$num_clients" == "1" ] && [ "$test_fops_admin_val" != "1" ]; then
+ do_facet mgs $LCTL nodemap_modify --name c0 --property admin \
+ --value 0
+ wait_nm_sync c0 admin_nodemap
+ fi
+
+ return 0
+}
+
+test_fops() {
+ local mapmode="$1"
+ local single_client="$2"
+ local client_user_list=([0]="0 $((IDBASE+3)) $((IDBASE+4))"
+ [1]="0 $((IDBASE+5)) $((IDBASE+6))")
+ local mds_i
+ local rc=0
+ local perm_bit_list="0 3 $((0300)) $((0303))"
+ # SLOW tests 000-007, 010-070, 100-700 (octal modes)
+ [ "$SLOW" == "yes" ] &&
+ perm_bit_list="0 $(seq 1 7) $(seq 8 8 63) $(seq 64 64 511) \
+ $((0303))"
+
+ # step through mds users. -1 means root
+ for mds_i in -1 0 1 2; do
+ local user=$((mds_i + IDBASE))
+ local client
+ local x
+
+ [ "$mds_i" == "-1" ] && user=0
+
+ echo mkdir -p $DIR/$tdir
+ fops_test_setup
+ local cli_i=0
+ for client in $clients; do
+ local u
+ for u in ${client_user_list[$cli_i]}; do
+ local run_u="do_node $client \
+ $RUNAS_CMD -u$u -g$u -G$u"
+ for perm_bits in $perm_bit_list; do
+ local mode=$(printf %03o $perm_bits)
+ local key
+ key="$mapmode:$user:c$cli_i:$u:$mode"
+ test_fops_chmod_dir $cli_i $mode \
+ $DIR/$tdir ||
+ error cannot chmod $key
+ do_create_delete "$run_u" "$key"
+ done
+
+ # check quota
+ test_fops_chmod_dir $cli_i 777 $DIR/$tdir ||
+ error cannot chmod $key
+ do_fops_quota_test "$run_u"
+ done
+
+ cli_i=$((cli_i + 1))
+ [ "$single_client" == "1" ] && break
+ done
+ rm -rf $DIR/$tdir
+ done
+ return $rc
+}
+
+nodemap_version_check () {
+ remote_mgs_nodsh && skip "remote MGS with nodsh" && return 1
+ [ $(lustre_version_code mgs) -lt $(version_code 2.5.53) ] &&
+ skip "No nodemap on $(lustre_build_version mgs) MGS < 2.5.53" &&
+ return 1
+ return 0
+}
+
+nodemap_test_setup() {
+ local rc
+ local active_nodemap=1
+
+ [ "$1" == "0" ] && active_nodemap=0
+
+ do_nodes $(comma_list $(all_mdts_nodes)) \
+ $LCTL set_param mdt.*.identity_upcall=NONE
+
+ rc=0
+ create_fops_nodemaps
+ rc=$?
+ [[ $rc != 0 ]] && error "adding fops nodemaps failed $rc"
+
+ do_facet mgs $LCTL nodemap_activate $active_nodemap
+ wait_nm_sync active
+
+ do_facet mgs $LCTL nodemap_modify --name default \
+ --property admin --value 1
+ do_facet mgs $LCTL nodemap_modify --name default \
+ --property trusted --value 1
+ wait_nm_sync default trusted_nodemap
+}
+
+nodemap_test_cleanup() {
+ trap 0
+ delete_fops_nodemaps
+ rc=$?
+ [[ $rc != 0 ]] && error "removing fops nodemaps failed $rc"
+
+ do_facet mgs $LCTL nodemap_modify --name default \
+ --property admin --value 0
+ do_facet mgs $LCTL nodemap_modify --name default \
+ --property trusted --value 0
+ wait_nm_sync default trusted_nodemap
+
+ do_facet mgs $LCTL nodemap_activate 0
+ wait_nm_sync active 0
+
+ return 0
+}
+
+nodemap_clients_admin_trusted() {
+ local admin=$1
+ local tr=$2
+ local i=0
+ for client in $clients; do
+ do_facet mgs $LCTL nodemap_modify --name c0 \
+ --property admin --value $admin
+ do_facet mgs $LCTL nodemap_modify --name c0 \
+ --property trusted --value $tr
+ i=$((i + 1))
+ done
+ wait_nm_sync c$((i - 1)) admin_nodemap
+ wait_nm_sync c$((i - 1)) trusted_nodemap
+}
+
+test_16() {
+ nodemap_version_check || return 0
+ nodemap_test_setup 0
+
+ trap nodemap_test_cleanup EXIT
+ test_fops all_off
+ nodemap_test_cleanup
+}
+run_test 16 "test nodemap all_off fileops"
+
+test_17() {
+ nodemap_version_check || return 0
+ nodemap_test_setup
+
+ trap nodemap_test_cleanup EXIT
+ nodemap_clients_admin_trusted 0 1
+ test_fops trusted_noadmin 1
+ nodemap_test_cleanup
+}
+run_test 17 "test nodemap trusted_noadmin fileops"
+
+test_18() {
+ nodemap_version_check || return 0
+ nodemap_test_setup
+
+ trap nodemap_test_cleanup EXIT
+ nodemap_clients_admin_trusted 0 0
+ test_fops mapped_noadmin 1
+ nodemap_test_cleanup
+}
+run_test 18 "test nodemap mapped_noadmin fileops"
+
+test_19() {
+ nodemap_version_check || return 0
+ nodemap_test_setup
+
+ trap nodemap_test_cleanup EXIT
+ nodemap_clients_admin_trusted 1 1
+ test_fops trusted_admin 1
+ nodemap_test_cleanup
+}
+run_test 19 "test nodemap trusted_admin fileops"
+
+test_20() {
+ nodemap_version_check || return 0
+ nodemap_test_setup
+
+ trap nodemap_test_cleanup EXIT
+ nodemap_clients_admin_trusted 1 0
+ test_fops mapped_admin 1
+ nodemap_test_cleanup
+}
+run_test 20 "test nodemap mapped_admin fileops"
+
+test_21() {
+ nodemap_version_check || return 0
+ nodemap_test_setup
+
+ trap nodemap_test_cleanup EXIT
+ local x=1
+ local i=0
+ for client in $clients; do
+ do_facet mgs $LCTL nodemap_modify --name c${i} \
+ --property admin --value 0
+ do_facet mgs $LCTL nodemap_modify --name c${i} \
+ --property trusted --value $x
+ x=0
+ i=$((i + 1))
+ done
+ wait_nm_sync c$((i - 1)) trusted_nodemap
+
+ test_fops mapped_trusted_noadmin
+ nodemap_test_cleanup
+}
+run_test 21 "test nodemap mapped_trusted_noadmin fileops"
+
+test_22() {
+ nodemap_version_check || return 0
+ nodemap_test_setup
+
+ trap nodemap_test_cleanup EXIT
+ local x=1
+ local i=0
+ for client in $clients; do
+ do_facet mgs $LCTL nodemap_modify --name c${i} \
+ --property admin --value 1
+ do_facet mgs $LCTL nodemap_modify --name c${i} \
+ --property trusted --value $x
+ x=0
+ i=$((i + 1))
+ done
+ wait_nm_sync c$((i - 1)) trusted_nodemap
+
+ test_fops mapped_trusted_admin
+ nodemap_test_cleanup
+}
+run_test 22 "test nodemap mapped_trusted_admin fileops"
+
+# acl test directory needs to be initialized on a privileged client
+nodemap_acl_test_setup() {
+ local admin=$(do_facet mgs $LCTL get_param -n nodemap.c0.admin_nodemap)
+ local trust=$(do_facet mgs $LCTL get_param -n \
+ nodemap.c0.trusted_nodemap)
+
+ do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
+ do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
+
+ wait_nm_sync c0 admin_nodemap
+ wait_nm_sync c0 trusted_nodemap
+
+ do_node ${clients_arr[0]} rm -rf $DIR/$tdir
+ nm_test_mkdir
+ do_node ${clients_arr[0]} chmod a+rwx $DIR/$tdir ||
+ error unable to chmod a+rwx test dir $DIR/$tdir
+
+ do_facet mgs $LCTL nodemap_modify --name c0 \
+ --property admin --value $admin
+ do_facet mgs $LCTL nodemap_modify --name c0 \
+ --property trusted --value $trust
+
+ wait_nm_sync c0 trusted_nodemap
+}
+
+# returns 0 if the number of ACLs does not change on the second (mapped) client
+# after being set on the first client
+nodemap_acl_test() {
+ local user="$1"
+ local set_client="$2"
+ local get_client="$3"
+ local check_setfacl="$4"
+ local setfacl_error=0
+ local testfile=$DIR/$tdir/$tfile
+ local RUNAS_USER="$RUNAS_CMD -u $user"
+ local acl_count=0
+ local acl_count_post=0
+
+ nodemap_acl_test_setup
+ sleep 5
+
+ do_node $set_client $RUNAS_USER touch $testfile
+
+ # ACL masks aren't filtered by nodemap code, so we ignore them
+ acl_count=$(do_node $get_client getfacl $testfile | grep -v mask |
+ wc -l)
+ do_node $set_client $RUNAS_USER setfacl -m $user:rwx $testfile ||
+ setfacl_error=1
+
+ # if check setfacl is set to 1, then it's supposed to error
+ if [ "$check_setfacl" == "1" ]; then
+ [ "$setfacl_error" != "1" ] && return 1
+ return 0
+ fi
+ [ "$setfacl_error" == "1" ] && echo "WARNING: unable to setfacl"
+
+ acl_count_post=$(do_node $get_client getfacl $testfile | grep -v mask |
+ wc -l)
+ [ $acl_count -eq $acl_count_post ] && return 0
+ return 1
+}
+
+test_23() {
+ nodemap_version_check || return 0
+ nodemap_test_setup
+
+ trap nodemap_test_cleanup EXIT
+ # 1 trusted cluster, 1 mapped cluster
+ local unmapped_fs=$((IDBASE+0))
+ local unmapped_c1=$((IDBASE+5))
+ local mapped_fs=$((IDBASE+2))
+ local mapped_c0=$((IDBASE+4))
+ local mapped_c1=$((IDBASE+6))
+
+ do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
+ do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
+
+ do_facet mgs $LCTL nodemap_modify --name c1 --property admin --value 0
+ do_facet mgs $LCTL nodemap_modify --name c1 --property trusted --value 0
+
+ wait_nm_sync c1 trusted_nodemap
+
+ # setfacl on trusted cluster to unmapped user, verify it's not seen
+ nodemap_acl_test $unmapped_fs ${clients_arr[0]} ${clients_arr[1]} ||
+ error "acl count (1)"
+
+ # setfacl on trusted cluster to mapped user, verify it's seen
+ nodemap_acl_test $mapped_fs ${clients_arr[0]} ${clients_arr[1]} &&
+ error "acl count (2)"
+
+ # setfacl on mapped cluster to mapped user, verify it's seen
+ nodemap_acl_test $mapped_c1 ${clients_arr[1]} ${clients_arr[0]} &&
+ error "acl count (3)"
+
+ # setfacl on mapped cluster to unmapped user, verify error
+ nodemap_acl_test $unmapped_fs ${clients_arr[1]} ${clients_arr[0]} 1 ||
+ error "acl count (4)"
+
+ # 2 mapped clusters
+ do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 0
+ do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 0
+
+ wait_nm_sync c0 trusted_nodemap
+
+ # setfacl to mapped user on c1, also mapped to c0, verify it's seen
+ nodemap_acl_test $mapped_c1 ${clients_arr[1]} ${clients_arr[0]} &&
+ error "acl count (5)"
+
+ # setfacl to mapped user on c1, not mapped to c0, verify not seen
+ nodemap_acl_test $unmapped_c1 ${clients_arr[1]} ${clients_arr[0]} ||
+ error "acl count (6)"
+
+ nodemap_test_cleanup
+}
+run_test 23 "test mapped ACLs"
+
+test_24() {
+ nodemap_test_setup
+
+ trap nodemap_test_cleanup EXIT
+ do_nodes $(comma_list $(all_server_nodes)) $LCTL get_param -R nodemap ||
+ error "proc readable file read failed"
+
+ nodemap_test_cleanup
+}
+run_test 24 "check nodemap proc files for LBUGs and Oopses"
+
+test_25() {
+ local tmpfile=$(mktemp)
+ local tmpfile2=$(mktemp)
+ local subdir=c0dir
+
+ nodemap_version_check || return 0
+
+ # stop clients for this test
+ zconf_umount_clients $CLIENTS $MOUNT ||
+ error "unable to umount clients $CLIENTS"
+
+ nodemap_test_setup
+
+ trap nodemap_test_cleanup EXIT
+
+ # create a new, empty nodemap, and add fileset info to it
+ do_facet mgs $LCTL nodemap_add test26 ||
+ error "unable to create nodemap test26"
+ do_facet mgs $LCTL set_param -P nodemap.test26.fileset=/$subdir ||
+ error "unable to add fileset info to nodemap test26"
+
+ wait_nm_sync test26 id
+
+ do_facet mgs $LCTL nodemap_info > $tmpfile
+ do_facet mds $LCTL nodemap_info > $tmpfile2
+
+ cleanup_and_setup_lustre
+ # stop clients for this test
+ zconf_umount_clients $CLIENTS $MOUNT ||
+ error "unable to umount clients $CLIENTS"
+
+ diff -q <(do_facet mgs $LCTL nodemap_info) $tmpfile >& /dev/null ||
+ error "nodemap_info diff on MGS after remount"
+
+ diff -q <(do_facet mds $LCTL nodemap_info) $tmpfile2 >& /dev/null ||
+ error "nodemap_info diff on MDS after remount"
+
+ # cleanup nodemap
+ do_facet mgs $LCTL nodemap_del test26 ||
+ error "cannot delete nodemap test26 from config"
+ nodemap_test_cleanup
+ # restart clients previously stopped
+ zconf_mount_clients $CLIENTS $MOUNT ||
+ error "unable to mount clients $CLIENTS"
+
+ rm -f $tmpfile $tmpfile2
+}
+run_test 25 "test save and reload nodemap config"
+
+test_26() {
+ nodemap_version_check || return 0
+
+ local large_i=32000
+
+ do_facet mgs "seq -f 'c%g' $large_i | xargs -n1 $LCTL nodemap_add"
+ wait_nm_sync c$large_i admin_nodemap
+
+ do_facet mgs "seq -f 'c%g' $large_i | xargs -n1 $LCTL nodemap_del"
+ wait_nm_sync c$large_i admin_nodemap
+}
+run_test 26 "test transferring very large nodemap"
+
+test_27() {
+ local subdir=c0dir
+ local subsubdir=c0subdir
+
+ nodemap_test_setup
+ trap nodemap_test_cleanup EXIT
+
+ fileset_test_setup
+
+ # add fileset info to nodemap
+ do_facet mgs $LCTL set_param nodemap.c0.fileset=/$subdir ||
+ error "unable to set fileset info on nodemap c0"
+ do_facet mgs $LCTL set_param -P nodemap.c0.fileset=/$subdir ||
+ error "unable to add fileset info to nodemap c0"
+ wait_nm_sync c0 fileset
+
+ # re-mount client
+ zconf_umount_clients ${clients_arr[0]} $MOUNT ||
+ error "unable to umount client ${clients_arr[0]}"
+ zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
+ error "unable to remount client ${clients_arr[0]}"
+
+ # test mount point content
+ do_node ${clients_arr[0]} test -f $MOUNT/this_is_$subdir ||
+ error "fileset not taken into account"
+
+ # re-mount client with sub-subdir
+ zconf_umount_clients ${clients_arr[0]} $MOUNT ||
+ error "unable to umount client ${clients_arr[0]}"
+ export FILESET=/$subsubdir
+ zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
+ error "unable to remount client ${clients_arr[0]}"
+ unset FILESET
+
+ # test mount point content
+ do_node ${clients_arr[0]} test -f $MOUNT/this_is_$subsubdir ||
+ error "subdir of fileset not taken into account"
+
+ # remove fileset info from nodemap
+ do_facet mgs $LCTL nodemap_set_fileset --name c0 --fileset \'\' ||
+ error "unable to delete fileset info on nodemap c0"
+ do_facet mgs $LCTL set_param -P nodemap.c0.fileset=\'\' ||
+ error "unable to reset fileset info on nodemap c0"
+ wait_nm_sync c0 fileset
+
+ # re-mount client
+ zconf_umount_clients ${clients_arr[0]} $MOUNT ||
+ error "unable to umount client ${clients_arr[0]}"
+ zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
+ error "unable to remount client ${clients_arr[0]}"
+
+ # test mount point content
+ do_node ${clients_arr[0]} test -d $MOUNT/$subdir ||
+ error "fileset not cleared on nodemap c0"
+
+ fileset_test_cleanup
+ nodemap_test_cleanup
+}
+run_test 27 "test fileset in nodemap"
+
+log "cleanup: ======================================================"
+
+sec_unsetup() {
+ ## nodemap deactivated
+ do_facet mgs $LCTL nodemap_activate 0
+
+ for num in $(seq $MDSCOUNT); do
+ if [ "${identity_old[$num]}" = 1 ]; then
+ switch_identity $num false || identity_old[$num]=$?
+ fi
+ done
+
+ $RUNAS_CMD -u $ID0 ls $DIR
+ $RUNAS_CMD -u $ID1 ls $DIR
+}
+sec_unsetup
+