3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
17 ALWAYS_EXCEPT="$SANITY_SEC_EXCEPT "
18 # bug number for skipped test:
20 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
22 [ "$SLOW" = "no" ] && EXCEPT_SLOW="26"
24 NODEMAP_TESTS=$(seq 7 26)
26 if ! check_versions; then
27 echo "It is NOT necessary to test nodemap under interoperation mode"
28 EXCEPT="$EXCEPT $NODEMAP_TESTS"
33 RUNAS_CMD=${RUNAS_CMD:-runas}
35 WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
38 PERM_CONF=$CONFDIR/perm.conf
40 HOSTNAME_CHECKSUM=$(hostname | sum | awk '{ print $1 }')
41 SUBNET_CHECKSUM=$(expr $HOSTNAME_CHECKSUM % 250 + 1)
43 require_dsh_mds || exit 0
44 require_dsh_ost || exit 0
46 clients=${CLIENTS//,/ }
47 num_clients=$(get_node_count ${clients})
48 clients_arr=($clients)
52 USER0=$(getent passwd | grep :$ID0:$ID0: | cut -d: -f1)
53 USER1=$(getent passwd | grep :$ID1:$ID1: | cut -d: -f1)
55 if [ "$SLOW" == "yes" ]; then
58 NODEMAP_IPADDR_LIST="1 10 64 128 200 250"
63 NODEMAP_IPADDR_LIST="1 250"
66 NODEMAP_MAX_ID=$((ID0 + NODEMAP_ID_COUNT))
69 skip "need to add user0 ($ID0:$ID0)" && exit 0
72 skip "need to add user1 ($ID1:$ID1)" && exit 0
74 IDBASE=${IDBASE:-60000}
76 # changes to mappings must be reflected in test 23
78 [0]="$((IDBASE+3)):$((IDBASE+0)) $((IDBASE+4)):$((IDBASE+2))"
79 [1]="$((IDBASE+5)):$((IDBASE+1)) $((IDBASE+6)):$((IDBASE+2))"
82 check_and_setup_lustre
87 GSS_REF=$(lsmod | grep ^ptlrpc_gss | awk '{print $3}')
88 if [ ! -z "$GSS_REF" -a "$GSS_REF" != "0" ]; then
90 echo "with GSS support"
93 echo "without GSS support"
96 MDT=$(do_facet $SINGLEMDS lctl get_param -N "mdt.\*MDT0000" |
98 [ -z "$MDT" ] && error "fail to get MDT device" && exit 1
99 do_facet $SINGLEMDS "mkdir -p $CONFDIR"
100 IDENTITY_FLUSH=mdt.$MDT.identity_flush
101 IDENTITY_UPCALL=mdt.$MDT.identity_upcall
110 if ! $RUNAS_CMD -u $user krb5_login.sh; then
111 error "$user login kerberos failed."
115 if ! $RUNAS_CMD -u $user -g $group ls $DIR > /dev/null 2>&1; then
116 $RUNAS_CMD -u $user lfs flushctx -k
117 $RUNAS_CMD -u $user krb5_login.sh
118 if ! $RUNAS_CMD -u$user -g$group ls $DIR > /dev/null 2>&1; then
119 error "init $user $group failed."
125 declare -a identity_old
128 for num in $(seq $MDSCOUNT); do
129 switch_identity $num true || identity_old[$num]=$?
132 if ! $RUNAS_CMD -u $ID0 ls $DIR > /dev/null 2>&1; then
133 sec_login $USER0 $USER0
136 if ! $RUNAS_CMD -u $ID1 ls $DIR > /dev/null 2>&1; then
137 sec_login $USER1 $USER1
142 # run as different user
146 chmod 0755 $DIR || error "chmod (1)"
147 rm -rf $DIR/$tdir || error "rm (1)"
148 mkdir -p $DIR/$tdir || error "mkdir (1)"
149 chown $USER0 $DIR/$tdir || error "chown (2)"
150 $RUNAS_CMD -u $ID0 ls $DIR || error "ls (1)"
151 rm -f $DIR/f0 || error "rm (2)"
152 $RUNAS_CMD -u $ID0 touch $DIR/f0 && error "touch (1)"
153 $RUNAS_CMD -u $ID0 touch $DIR/$tdir/f1 || error "touch (2)"
154 $RUNAS_CMD -u $ID1 touch $DIR/$tdir/f2 && error "touch (3)"
155 touch $DIR/$tdir/f3 || error "touch (4)"
156 chown root $DIR/$tdir || error "chown (3)"
157 chgrp $USER0 $DIR/$tdir || error "chgrp (1)"
158 chmod 0775 $DIR/$tdir || error "chmod (2)"
159 $RUNAS_CMD -u $ID0 touch $DIR/$tdir/f4 || error "touch (5)"
160 $RUNAS_CMD -u $ID1 touch $DIR/$tdir/f5 && error "touch (6)"
161 touch $DIR/$tdir/f6 || error "touch (7)"
162 rm -rf $DIR/$tdir || error "rm (3)"
164 run_test 0 "uid permission ============================="
168 [ $GSS_SUP = 0 ] && skip "without GSS support." && return
171 mkdir_on_mdt0 $DIR/$tdir
173 chown $USER0 $DIR/$tdir || error "chown (1)"
174 $RUNAS_CMD -u $ID1 -v $ID0 touch $DIR/$tdir/f0 && error "touch (2)"
175 echo "enable uid $ID1 setuid"
176 do_facet $SINGLEMDS "echo '* $ID1 setuid' >> $PERM_CONF"
177 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
178 $RUNAS_CMD -u $ID1 -v $ID0 touch $DIR/$tdir/f1 || error "touch (3)"
180 chown root $DIR/$tdir || error "chown (4)"
181 chgrp $USER0 $DIR/$tdir || error "chgrp (5)"
182 chmod 0770 $DIR/$tdir || error "chmod (6)"
183 $RUNAS_CMD -u $ID1 -g $ID1 touch $DIR/$tdir/f2 && error "touch (7)"
184 $RUNAS_CMD -u$ID1 -g$ID1 -j$ID0 touch $DIR/$tdir/f3 && error "touch (8)"
185 echo "enable uid $ID1 setuid,setgid"
186 do_facet $SINGLEMDS "echo '* $ID1 setuid,setgid' > $PERM_CONF"
187 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
188 $RUNAS_CMD -u $ID1 -g $ID1 -j $ID0 touch $DIR/$tdir/f4 ||
190 $RUNAS_CMD -u $ID1 -v $ID0 -g $ID1 -j $ID0 touch $DIR/$tdir/f5 ||
195 do_facet $SINGLEMDS "rm -f $PERM_CONF"
196 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
198 run_test 1 "setuid/gid ============================="
200 # bug 3285 - supplementary group should always succeed.
201 # NB: the supplementary groups are set for local client only,
202 # as for remote client, the groups of the specified uid on MDT
203 # will be obtained by upcall /sbin/l_getidentity and used.
205 [[ "$MDS1_VERSION" -ge $(version_code 2.6.93) ]] ||
206 [[ "$MDS1_VERSION" -ge $(version_code 2.5.35) &&
207 "$MDS1_VERSION" -lt $(version_code 2.5.50) ]] ||
208 skip "Need MDS version at least 2.6.93 or 2.5.35"
212 chmod 0771 $DIR/$tdir
213 chgrp $ID0 $DIR/$tdir
214 $RUNAS_CMD -u $ID0 ls $DIR/$tdir || error "setgroups (1)"
215 do_facet $SINGLEMDS "echo '* $ID1 setgrp' > $PERM_CONF"
216 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
217 $RUNAS_CMD -u $ID1 -G1,2,$ID0 ls $DIR/$tdir ||
218 error "setgroups (2)"
219 $RUNAS_CMD -u $ID1 -G1,2 ls $DIR/$tdir && error "setgroups (3)"
222 do_facet $SINGLEMDS "rm -f $PERM_CONF"
223 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
225 run_test 4 "set supplementary group ==============="
231 squash_id default 99 0
232 wait_nm_sync default squash_uid '' inactive
233 squash_id default 99 1
234 wait_nm_sync default squash_gid '' inactive
235 for (( i = 0; i < NODEMAP_COUNT; i++ )); do
236 local csum=${HOSTNAME_CHECKSUM}_${i}
238 do_facet mgs $LCTL nodemap_add $csum
240 if [ $rc -ne 0 ]; then
241 echo "nodemap_add $csum failed with $rc"
245 wait_update_facet --verbose mgs \
246 "$LCTL get_param nodemap.$csum.id 2>/dev/null | \
247 grep -c $csum || true" 1 30 ||
250 for (( i = 0; i < NODEMAP_COUNT; i++ )); do
251 local csum=${HOSTNAME_CHECKSUM}_${i}
253 wait_nm_sync $csum id '' inactive
261 for ((i = 0; i < NODEMAP_COUNT; i++)); do
262 local csum=${HOSTNAME_CHECKSUM}_${i}
264 if ! do_facet mgs $LCTL nodemap_del $csum; then
265 error "nodemap_del $csum failed with $?"
269 wait_update_facet --verbose mgs \
270 "$LCTL get_param nodemap.$csum.id 2>/dev/null | \
271 grep -c $csum || true" 0 30 ||
274 for (( i = 0; i < NODEMAP_COUNT; i++ )); do
275 local csum=${HOSTNAME_CHECKSUM}_${i}
277 wait_nm_sync $csum id '' inactive
284 local cmd="$LCTL nodemap_add_range"
288 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
289 range="$SUBNET_CHECKSUM.${2}.${j}.[1-253]@tcp"
290 if ! do_facet mgs $cmd --name $1 --range $range; then
299 local cmd="$LCTL nodemap_del_range"
303 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
304 range="$SUBNET_CHECKSUM.${2}.${j}.[1-253]@tcp"
305 if ! do_facet mgs $cmd --name $1 --range $range; then
315 local cmd="$LCTL nodemap_add_idmap"
319 (( $MDS1_VERSION >= $(version_code 2.14.52) )) || do_proj=false
321 echo "Start to add idmaps ..."
322 for ((i = 0; i < NODEMAP_COUNT; i++)); do
325 for ((j = $ID0; j < NODEMAP_MAX_ID; j++)); do
326 local csum=${HOSTNAME_CHECKSUM}_${i}
328 local fs_id=$((j + 1))
330 if ! do_facet mgs $cmd --name $csum --idtype uid \
331 --idmap $client_id:$fs_id; then
334 if ! do_facet mgs $cmd --name $csum --idtype gid \
335 --idmap $client_id:$fs_id; then
339 if ! do_facet mgs $cmd --name $csum \
340 --idtype projid --idmap \
341 $client_id:$fs_id; then
351 update_idmaps() { #LU-10040
352 [ "$MGS_VERSION" -lt $(version_code 2.10.55) ] &&
353 skip "Need MGS >= 2.10.55"
355 local csum=${HOSTNAME_CHECKSUM}_0
356 local old_id_client=$ID0
357 local old_id_fs=$((ID0 + 1))
358 local new_id=$((ID0 + 100))
365 echo "Start to update idmaps ..."
367 #Inserting an existed idmap should return error
368 cmd="$LCTL nodemap_add_idmap --name $csum --idtype uid"
370 $cmd --idmap $old_id_client:$old_id_fs 2>/dev/null; then
371 error "insert idmap {$old_id_client:$old_id_fs} " \
372 "should return error"
377 #Update id_fs and check it
378 if ! do_facet mgs $cmd --idmap $old_id_client:$new_id; then
379 error "$cmd --idmap $old_id_client:$new_id failed"
383 tmp_id=$(do_facet mgs $LCTL get_param -n nodemap.$csum.idmap |
384 awk '{ print $7 }' | sed -n '2p')
385 [ $tmp_id != $new_id ] && { error "new id_fs $tmp_id != $new_id"; \
386 rc=$((rc + 1)); return $rc; }
388 #Update id_client and check it
389 if ! do_facet mgs $cmd --idmap $new_id:$new_id; then
390 error "$cmd --idmap $new_id:$new_id failed"
394 tmp_id=$(do_facet mgs $LCTL get_param -n nodemap.$csum.idmap |
395 awk '{ print $5 }' | sed -n "$((NODEMAP_ID_COUNT + 1)) p")
396 tmp_id=$(echo ${tmp_id%,*}) #e.g. "501,"->"501"
397 [ $tmp_id != $new_id ] && { error "new id_client $tmp_id != $new_id"; \
398 rc=$((rc + 1)); return $rc; }
400 #Delete above updated idmap
401 cmd="$LCTL nodemap_del_idmap --name $csum --idtype uid"
402 if ! do_facet mgs $cmd --idmap $new_id:$new_id; then
403 error "$cmd --idmap $new_id:$new_id failed"
408 #restore the idmaps to make delete_idmaps work well
409 cmd="$LCTL nodemap_add_idmap --name $csum --idtype uid"
410 if ! do_facet mgs $cmd --idmap $old_id_client:$old_id_fs; then
411 error "$cmd --idmap $old_id_client:$old_id_fs failed"
421 local cmd="$LCTL nodemap_del_idmap"
425 (( $MDS1_VERSION >= $(version_code 2.14.52) )) || do_proj=false
427 echo "Start to delete idmaps ..."
428 for ((i = 0; i < NODEMAP_COUNT; i++)); do
431 for ((j = $ID0; j < NODEMAP_MAX_ID; j++)); do
432 local csum=${HOSTNAME_CHECKSUM}_${i}
434 local fs_id=$((j + 1))
436 if ! do_facet mgs $cmd --name $csum --idtype uid \
437 --idmap $client_id:$fs_id; then
440 if ! do_facet mgs $cmd --name $csum --idtype gid \
441 --idmap $client_id:$fs_id; then
445 if ! do_facet mgs $cmd --name $csum \
446 --idtype projid --idmap \
447 $client_id:$fs_id; then
461 local cmd="$LCTL nodemap_modify"
464 proc[0]="admin_nodemap"
465 proc[1]="trusted_nodemap"
469 for ((idx = 0; idx < 2; idx++)); do
470 if ! do_facet mgs $cmd --name $1 --property ${option[$idx]} \
475 if ! do_facet mgs $cmd --name $1 --property ${option[$idx]} \
485 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
486 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
490 cmd[0]="$LCTL nodemap_modify --property squash_uid"
491 cmd[1]="$LCTL nodemap_modify --property squash_gid"
492 cmd[2]="$LCTL nodemap_modify --property squash_projid"
494 if ! do_facet mgs ${cmd[$3]} --name $1 --value $2; then
499 # ensure that the squash defaults are the expected defaults
500 squash_id default 99 0
501 wait_nm_sync default squash_uid '' inactive
502 squash_id default 99 1
503 wait_nm_sync default squash_gid '' inactive
504 if [ "$MDS1_VERSION" -ge $(version_code 2.14.50) ]; then
505 squash_id default 99 2
506 wait_nm_sync default squash_projid '' inactive
512 cmd="$LCTL nodemap_test_nid"
514 nid=$(do_facet mgs $cmd $1)
516 if [ $nid == $2 ]; then
524 # restore activation state
525 do_facet mgs $LCTL nodemap_activate 0
531 local cmd="$LCTL nodemap_test_id"
534 echo "Start to test idmaps ..."
535 ## nodemap deactivated
536 if ! do_facet mgs $LCTL nodemap_activate 0; then
539 for ((id = $ID0; id < NODEMAP_MAX_ID; id++)); do
542 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
543 local nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
544 local fs_id=$(do_facet mgs $cmd --nid $nid \
545 --idtype uid --id $id)
546 if [ $fs_id != $id ]; then
547 echo "expected $id, got $fs_id"
554 if ! do_facet mgs $LCTL nodemap_activate 1; then
558 for ((id = $ID0; id < NODEMAP_MAX_ID; id++)); do
559 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
560 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
561 fs_id=$(do_facet mgs $cmd --nid $nid \
562 --idtype uid --id $id)
563 expected_id=$((id + 1))
564 if [ $fs_id != $expected_id ]; then
565 echo "expected $expected_id, got $fs_id"
572 for ((i = 0; i < NODEMAP_COUNT; i++)); do
573 local csum=${HOSTNAME_CHECKSUM}_${i}
575 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
576 --property trusted --value 1; then
577 error "nodemap_modify $csum failed with $?"
582 for ((id = $ID0; id < NODEMAP_MAX_ID; id++)); do
583 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
584 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
585 fs_id=$(do_facet mgs $cmd --nid $nid \
586 --idtype uid --id $id)
587 if [ $fs_id != $id ]; then
588 echo "expected $id, got $fs_id"
594 ## ensure allow_root_access is enabled
595 for ((i = 0; i < NODEMAP_COUNT; i++)); do
596 local csum=${HOSTNAME_CHECKSUM}_${i}
598 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
599 --property admin --value 1; then
600 error "nodemap_modify $csum failed with $?"
605 ## check that root allowed
606 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
607 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
608 fs_id=$(do_facet mgs $cmd --nid $nid --idtype uid --id 0)
609 if [ $fs_id != 0 ]; then
610 echo "root allowed expected 0, got $fs_id"
615 ## ensure allow_root_access is disabled
616 for ((i = 0; i < NODEMAP_COUNT; i++)); do
617 local csum=${HOSTNAME_CHECKSUM}_${i}
619 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
620 --property admin --value 0; then
621 error "nodemap_modify ${HOSTNAME_CHECKSUM}_${i} "
627 ## check that root is mapped to 99
628 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
629 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
630 fs_id=$(do_facet mgs $cmd --nid $nid --idtype uid --id 0)
631 if [ $fs_id != 99 ]; then
632 error "root squash expected 99, got $fs_id"
637 ## reset client trust to 0
638 for ((i = 0; i < NODEMAP_COUNT; i++)); do
639 if ! do_facet mgs $LCTL nodemap_modify \
640 --name ${HOSTNAME_CHECKSUM}_${i} \
641 --property trusted --value 0; then
642 error "nodemap_modify ${HOSTNAME_CHECKSUM}_${i} "
654 remote_mgs_nodsh && skip "remote MGS with nodsh"
655 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
656 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
660 [[ $rc != 0 ]] && error "nodemap_add failed with $rc"
664 [[ $rc != 0 ]] && error "nodemap_del failed with $rc"
668 run_test 7 "nodemap create and delete"
673 remote_mgs_nodsh && skip "remote MGS with nodsh"
674 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
675 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
681 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
687 [[ $rc == 0 ]] && error "duplicate nodemap_add allowed with $rc" &&
693 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 3
697 run_test 8 "nodemap reject duplicates"
703 remote_mgs_nodsh && skip "remote MGS with nodsh"
704 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
705 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
710 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
713 for ((i = 0; i < NODEMAP_COUNT; i++)); do
714 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
718 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
721 for ((i = 0; i < NODEMAP_COUNT; i++)); do
722 if ! delete_range ${HOSTNAME_CHECKSUM}_${i} $i; then
726 [[ $rc != 0 ]] && error "nodemap_del_range failed with $rc" && return 4
731 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
735 run_test 9 "nodemap range add"
740 remote_mgs_nodsh && skip "remote MGS with nodsh"
741 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
742 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
747 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
750 for ((i = 0; i < NODEMAP_COUNT; i++)); do
751 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
755 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
758 for ((i = 0; i < NODEMAP_COUNT; i++)); do
759 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
763 [[ $rc == 0 ]] && error "nodemap_add_range duplicate add with $rc" &&
768 for ((i = 0; i < NODEMAP_COUNT; i++)); do
769 if ! delete_range ${HOSTNAME_CHECKSUM}_${i} $i; then
773 [[ $rc != 0 ]] && error "nodemap_del_range failed with $rc" && return 4
777 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 5
781 run_test 10a "nodemap reject duplicate ranges"
784 [ "$MGS_VERSION" -lt $(version_code 2.10.53) ] &&
785 skip "Need MGS >= 2.10.53"
789 local nids="192.168.19.[0-255]@o2ib20"
791 do_facet mgs $LCTL nodemap_del $nm1 2>/dev/null
792 do_facet mgs $LCTL nodemap_del $nm2 2>/dev/null
794 do_facet mgs $LCTL nodemap_add $nm1 || error "Add $nm1 failed"
795 do_facet mgs $LCTL nodemap_add $nm2 || error "Add $nm2 failed"
796 do_facet mgs $LCTL nodemap_add_range --name $nm1 --range $nids ||
797 error "Add range $nids to $nm1 failed"
798 [ -n "$(do_facet mgs $LCTL get_param nodemap.$nm1.* |
799 grep start_nid)" ] || error "No range was found"
800 do_facet mgs $LCTL nodemap_del_range --name $nm2 --range $nids &&
801 error "Deleting range $nids from $nm2 should fail"
802 [ -n "$(do_facet mgs $LCTL get_param nodemap.$nm1.* |
803 grep start_nid)" ] || error "Range $nids should be there"
805 do_facet mgs $LCTL nodemap_del $nm1 || error "Delete $nm1 failed"
806 do_facet mgs $LCTL nodemap_del $nm2 || error "Delete $nm2 failed"
809 run_test 10b "delete range from the correct nodemap"
811 test_10c() { #LU-8912
812 [ "$MGS_VERSION" -lt $(version_code 2.10.57) ] &&
813 skip "Need MGS >= 2.10.57"
815 local nm="nodemap_lu8912"
816 local nid_range="10.210.[32-47].[0-255]@o2ib3"
817 local start_nid="10.210.32.0@o2ib3"
818 local end_nid="10.210.47.255@o2ib3"
819 local start_nid_found
822 do_facet mgs $LCTL nodemap_del $nm 2>/dev/null
823 do_facet mgs $LCTL nodemap_add $nm || error "Add $nm failed"
824 do_facet mgs $LCTL nodemap_add_range --name $nm --range $nid_range ||
825 error "Add range $nid_range to $nm failed"
827 start_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
828 awk -F '[,: ]' /start_nid/'{ print $9 }')
829 [ "$start_nid" == "$start_nid_found" ] ||
830 error "start_nid: $start_nid_found != $start_nid"
831 end_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
832 awk -F '[,: ]' /end_nid/'{ print $13 }')
833 [ "$end_nid" == "$end_nid_found" ] ||
834 error "end_nid: $end_nid_found != $end_nid"
836 do_facet mgs $LCTL nodemap_del $nm || error "Delete $nm failed"
839 run_test 10c "verfify contiguous range support"
841 test_10d() { #LU-8913
842 [ "$MGS_VERSION" -lt $(version_code 2.10.59) ] &&
843 skip "Need MGS >= 2.10.59"
845 local nm="nodemap_lu8913"
846 local nid_range="*@o2ib3"
847 local start_nid="0.0.0.0@o2ib3"
848 local end_nid="255.255.255.255@o2ib3"
849 local start_nid_found
852 do_facet mgs $LCTL nodemap_del $nm 2>/dev/null
853 do_facet mgs $LCTL nodemap_add $nm || error "Add $nm failed"
854 do_facet mgs $LCTL nodemap_add_range --name $nm --range $nid_range ||
855 error "Add range $nid_range to $nm failed"
857 start_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
858 awk -F '[,: ]' /start_nid/'{ print $9 }')
859 [ "$start_nid" == "$start_nid_found" ] ||
860 error "start_nid: $start_nid_found != $start_nid"
861 end_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
862 awk -F '[,: ]' /end_nid/'{ print $13 }')
863 [ "$end_nid" == "$end_nid_found" ] ||
864 error "end_nid: $end_nid_found != $end_nid"
866 do_facet mgs $LCTL nodemap_del $nm || error "Delete $nm failed"
869 run_test 10d "verfify nodemap range format '*@<net>' support"
874 remote_mgs_nodsh && skip "remote MGS with nodsh"
875 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
876 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
881 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
884 for ((i = 0; i < NODEMAP_COUNT; i++)); do
885 if ! modify_flags ${HOSTNAME_CHECKSUM}_${i}; then
889 [[ $rc != 0 ]] && error "nodemap_modify with $rc" && return 2
894 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 3
898 run_test 11 "nodemap modify"
903 remote_mgs_nodsh && skip "remote MGS with nodsh"
904 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
905 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
910 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
913 for ((i = 0; i < NODEMAP_COUNT; i++)); do
914 if ! squash_id ${HOSTNAME_CHECKSUM}_${i} 88 0; then
918 [[ $rc != 0 ]] && error "nodemap squash_uid with $rc" && return 2
921 for ((i = 0; i < NODEMAP_COUNT; i++)); do
922 if ! squash_id ${HOSTNAME_CHECKSUM}_${i} 88 1; then
926 [[ $rc != 0 ]] && error "nodemap squash_gid with $rc" && return 3
929 if (( $MDS1_VERSION >= $(version_code 2.14.52) )); then
930 for ((i = 0; i < NODEMAP_COUNT; i++)); do
931 if ! squash_id ${HOSTNAME_CHECKSUM}_${i} 88 2; then
936 [[ $rc != 0 ]] && error "nodemap squash_projid with $rc" && return 5
941 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
945 run_test 12 "nodemap set squash ids"
950 remote_mgs_nodsh && skip "remote MGS with nodsh"
951 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
952 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
957 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
960 for ((i = 0; i < NODEMAP_COUNT; i++)); do
961 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
965 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
968 for ((i = 0; i < NODEMAP_COUNT; i++)); do
969 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
970 for k in $NODEMAP_IPADDR_LIST; do
971 if ! test_nid $SUBNET_CHECKSUM.$i.$j.$k \
972 ${HOSTNAME_CHECKSUM}_${i}; then
978 [[ $rc != 0 ]] && error "nodemap_test_nid failed with $rc" && return 3
983 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
987 run_test 13 "test nids"
992 remote_mgs_nodsh && skip "remote MGS with nodsh"
993 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
994 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
999 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
1002 for ((i = 0; i < NODEMAP_COUNT; i++)); do
1003 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
1004 for k in $NODEMAP_IPADDR_LIST; do
1005 if ! test_nid $SUBNET_CHECKSUM.$i.$j.$k \
1012 [[ $rc != 0 ]] && error "nodemap_test_nid failed with $rc" && return 3
1017 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
1021 run_test 14 "test default nodemap nid lookup"
1026 remote_mgs_nodsh && skip "remote MGS with nodsh"
1027 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
1028 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
1033 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
1036 for ((i = 0; i < NODEMAP_COUNT; i++)); do
1037 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
1041 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
1046 [[ $rc != 0 ]] && error "nodemap_add_idmap failed with $rc" && return 3
1048 activedefault=$(do_facet mgs $LCTL get_param -n nodemap.active)
1049 if [[ "$activedefault" != "1" ]]; then
1050 stack_trap cleanup_active EXIT
1056 [[ $rc != 0 ]] && error "nodemap_test_id failed with $rc" && return 4
1061 [[ $rc != 0 ]] && error "update_idmaps failed with $rc" && return 5
1066 [[ $rc != 0 ]] && error "nodemap_del_idmap failed with $rc" && return 6
1071 [[ $rc != 0 ]] && error "nodemap_delete failed with $rc" && return 7
1075 run_test 15 "test id mapping"
1077 create_fops_nodemaps() {
1080 for client in $clients; do
1081 local client_ip=$(host_nids_address $client $NETTYPE)
1082 local client_nid=$(h2nettype $client_ip)
1083 do_facet mgs $LCTL nodemap_add c${i} || return 1
1084 do_facet mgs $LCTL nodemap_add_range \
1085 --name c${i} --range $client_nid || return 1
1086 for map in ${FOPS_IDMAPS[i]}; do
1087 do_facet mgs $LCTL nodemap_add_idmap --name c${i} \
1088 --idtype uid --idmap ${map} || return 1
1089 do_facet mgs $LCTL nodemap_add_idmap --name c${i} \
1090 --idtype gid --idmap ${map} || return 1
1093 wait_nm_sync c$i idmap
1100 delete_fops_nodemaps() {
1103 for client in $clients; do
1104 do_facet mgs $LCTL nodemap_del c${i} || return 1
1112 if [ $MDSCOUNT -le 1 ]; then
1113 do_node ${clients_arr[0]} mkdir -p $DIR/$tdir
1115 # round-robin MDTs to test DNE nodemap support
1116 [ ! -d $DIR ] && do_node ${clients_arr[0]} mkdir -p $DIR
1117 do_node ${clients_arr[0]} $LFS setdirstripe -c 1 -i \
1118 $((fops_mds_index % MDSCOUNT)) $DIR/$tdir
1119 ((fops_mds_index++))
1123 # acl test directory needs to be initialized on a privileged client
1125 local admin=$(do_facet mgs $LCTL get_param -n nodemap.c0.admin_nodemap)
1126 local trust=$(do_facet mgs $LCTL get_param -n \
1127 nodemap.c0.trusted_nodemap)
1129 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1130 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
1132 wait_nm_sync c0 admin_nodemap
1133 wait_nm_sync c0 trusted_nodemap
1135 do_node ${clients_arr[0]} rm -rf $DIR/$tdir
1137 do_node ${clients_arr[0]} chown $user $DIR/$tdir
1139 do_facet mgs $LCTL nodemap_modify --name c0 \
1140 --property admin --value $admin
1141 do_facet mgs $LCTL nodemap_modify --name c0 \
1142 --property trusted --value $trust
1144 # flush MDT locks to make sure they are reacquired before test
1145 do_node ${clients_arr[0]} $LCTL set_param \
1146 ldlm.namespaces.$FSNAME-MDT*.lru_size=clear
1148 wait_nm_sync c0 admin_nodemap
1149 wait_nm_sync c0 trusted_nodemap
1152 # fileset test directory needs to be initialized on a privileged client
1153 fileset_test_setup() {
1156 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
1157 cleanup_mount $MOUNT
1158 FILESET="" zconf_mount_clients $CLIENTS $MOUNT
1161 local admin=$(do_facet mgs $LCTL get_param -n \
1162 nodemap.${nm}.admin_nodemap)
1163 local trust=$(do_facet mgs $LCTL get_param -n \
1164 nodemap.${nm}.trusted_nodemap)
1166 do_facet mgs $LCTL nodemap_modify --name $nm --property admin --value 1
1167 do_facet mgs $LCTL nodemap_modify --name $nm --property trusted \
1170 wait_nm_sync $nm admin_nodemap
1171 wait_nm_sync $nm trusted_nodemap
1173 # create directory and populate it for subdir mount
1174 do_node ${clients_arr[0]} mkdir $MOUNT/$subdir ||
1175 error "unable to create dir $MOUNT/$subdir"
1176 do_node ${clients_arr[0]} touch $MOUNT/$subdir/this_is_$subdir ||
1177 error "unable to create file $MOUNT/$subdir/this_is_$subdir"
1178 do_node ${clients_arr[0]} mkdir $MOUNT/$subdir/$subsubdir ||
1179 error "unable to create dir $MOUNT/$subdir/$subsubdir"
1180 do_node ${clients_arr[0]} touch \
1181 $MOUNT/$subdir/$subsubdir/this_is_$subsubdir ||
1182 error "unable to create file \
1183 $MOUNT/$subdir/$subsubdir/this_is_$subsubdir"
1185 do_facet mgs $LCTL nodemap_modify --name $nm \
1186 --property admin --value $admin
1187 do_facet mgs $LCTL nodemap_modify --name $nm \
1188 --property trusted --value $trust
1190 # flush MDT locks to make sure they are reacquired before test
1191 do_node ${clients_arr[0]} $LCTL set_param \
1192 ldlm.namespaces.$FSNAME-MDT*.lru_size=clear
1194 wait_nm_sync $nm admin_nodemap
1195 wait_nm_sync $nm trusted_nodemap
1198 # fileset test directory needs to be initialized on a privileged client
1199 fileset_test_cleanup() {
1201 local admin=$(do_facet mgs $LCTL get_param -n \
1202 nodemap.${nm}.admin_nodemap)
1203 local trust=$(do_facet mgs $LCTL get_param -n \
1204 nodemap.${nm}.trusted_nodemap)
1206 do_facet mgs $LCTL nodemap_modify --name $nm --property admin --value 1
1207 do_facet mgs $LCTL nodemap_modify --name $nm --property trusted \
1210 wait_nm_sync $nm admin_nodemap
1211 wait_nm_sync $nm trusted_nodemap
1213 # cleanup directory created for subdir mount
1214 do_node ${clients_arr[0]} rm -rf $MOUNT/$subdir ||
1215 error "unable to remove dir $MOUNT/$subdir"
1217 do_facet mgs $LCTL nodemap_modify --name $nm \
1218 --property admin --value $admin
1219 do_facet mgs $LCTL nodemap_modify --name $nm \
1220 --property trusted --value $trust
1222 # flush MDT locks to make sure they are reacquired before test
1223 do_node ${clients_arr[0]} $LCTL set_param \
1224 ldlm.namespaces.$FSNAME-MDT*.lru_size=clear
1226 wait_nm_sync $nm admin_nodemap
1227 wait_nm_sync $nm trusted_nodemap
1228 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
1229 cleanup_mount $MOUNT
1230 zconf_mount_clients $CLIENTS $MOUNT
1234 do_create_delete() {
1237 local testfile=$DIR/$tdir/$tfile
1241 if $run_u touch $testfile >& /dev/null; then
1243 $run_u rm $testfile && d=1
1247 local expected=$(get_cr_del_expected $key)
1248 [ "$res" != "$expected" ] &&
1249 error "test $key, wanted $expected, got $res" && rc=$((rc + 1))
1253 nodemap_check_quota() {
1255 $run_u lfs quota -q $DIR | awk '{ print $2; exit; }'
1258 do_fops_quota_test() {
1260 # fuzz quota used to account for possible indirect blocks, etc
1261 local quota_fuzz=$(fs_log_size)
1262 local qused_orig=$(nodemap_check_quota "$run_u")
1263 local qused_high=$((qused_orig + quota_fuzz))
1264 local qused_low=$((qused_orig - quota_fuzz))
1265 local testfile=$DIR/$tdir/$tfile
1266 $run_u dd if=/dev/zero of=$testfile oflag=sync bs=1M count=1 \
1267 >& /dev/null || error "unable to write quota test file"
1268 sync; sync_all_data || true
1270 local qused_new=$(nodemap_check_quota "$run_u")
1271 [ $((qused_new)) -lt $((qused_low + 1024)) -o \
1272 $((qused_new)) -gt $((qused_high + 1024)) ] &&
1273 error "$qused_new != $qused_orig + 1M after write, " \
1274 "fuzz is $quota_fuzz"
1275 $run_u rm $testfile || error "unable to remove quota test file"
1276 wait_delete_completed_mds
1278 qused_new=$(nodemap_check_quota "$run_u")
1279 [ $((qused_new)) -lt $((qused_low)) \
1280 -o $((qused_new)) -gt $((qused_high)) ] &&
1281 error "quota not reclaimed, expect $qused_orig, " \
1282 "got $qused_new, fuzz $quota_fuzz"
1285 get_fops_mapped_user() {
1288 for ((i=0; i < ${#FOPS_IDMAPS[@]}; i++)); do
1289 for map in ${FOPS_IDMAPS[i]}; do
1290 if [ $(cut -d: -f1 <<< "$map") == $cli_user ]; then
1291 cut -d: -f2 <<< "$map"
1299 get_cr_del_expected() {
1301 IFS=":" read -a key <<< "$1"
1302 local mapmode="${key[0]}"
1303 local mds_user="${key[1]}"
1304 local cluster="${key[2]}"
1305 local cli_user="${key[3]}"
1306 local mode="0${key[4]}"
1313 [[ $mapmode == *mapped* ]] && mapped=1
1314 # only c1 is mapped in these test cases
1315 [[ $mapmode == mapped_trusted* ]] && [ "$cluster" == "c0" ] && mapped=0
1316 [[ $mapmode == *noadmin* ]] && noadmin=1
1318 # o+wx works as long as the user isn't mapped
1319 if [ $((mode & 3)) -eq 3 ]; then
1323 # if client user is root, check if root is squashed
1324 if [ "$cli_user" == "0" ]; then
1325 # squash root succeed, if other bit is on
1328 1) [ "$other" == "1" ] && echo $SUCCESS
1329 [ "$other" == "0" ] && echo $FAILURE;;
1333 if [ "$mapped" == "0" ]; then
1334 [ "$other" == "1" ] && echo $SUCCESS
1335 [ "$other" == "0" ] && echo $FAILURE
1339 # if mapped user is mds user, check for u+wx
1340 mapped_user=$(get_fops_mapped_user $cli_user)
1341 [ "$mapped_user" == "-1" ] &&
1342 error "unable to find mapping for client user $cli_user"
1344 if [ "$mapped_user" == "$mds_user" -a \
1345 $(((mode & 0300) == 0300)) -eq 1 ]; then
1349 if [ "$mapped_user" != "$mds_user" -a "$other" == "1" ]; then
1356 test_fops_admin_cli_i=""
1357 test_fops_chmod_dir() {
1358 local current_cli_i=$1
1360 local dir_to_chmod=$3
1361 local new_admin_cli_i=""
1363 # do we need to set up a new admin client?
1364 [ "$current_cli_i" == "0" ] && [ "$test_fops_admin_cli_i" != "1" ] &&
1366 [ "$current_cli_i" != "0" ] && [ "$test_fops_admin_cli_i" != "0" ] &&
1369 # if only one client, and non-admin, need to flip admin everytime
1370 if [ "$num_clients" == "1" ]; then
1371 test_fops_admin_client=$clients
1372 test_fops_admin_val=$(do_facet mgs $LCTL get_param -n \
1373 nodemap.c0.admin_nodemap)
1374 if [ "$test_fops_admin_val" != "1" ]; then
1375 do_facet mgs $LCTL nodemap_modify \
1379 wait_nm_sync c0 admin_nodemap
1381 elif [ "$new_admin_cli_i" != "" ]; then
1382 # restore admin val to old admin client
1383 if [ "$test_fops_admin_cli_i" != "" ] &&
1384 [ "$test_fops_admin_val" != "1" ]; then
1385 do_facet mgs $LCTL nodemap_modify \
1386 --name c${test_fops_admin_cli_i} \
1388 --value $test_fops_admin_val
1389 wait_nm_sync c${test_fops_admin_cli_i} admin_nodemap
1392 test_fops_admin_cli_i=$new_admin_cli_i
1393 test_fops_admin_client=${clients_arr[$new_admin_cli_i]}
1394 test_fops_admin_val=$(do_facet mgs $LCTL get_param -n \
1395 nodemap.c${new_admin_cli_i}.admin_nodemap)
1397 if [ "$test_fops_admin_val" != "1" ]; then
1398 do_facet mgs $LCTL nodemap_modify \
1399 --name c${new_admin_cli_i} \
1402 wait_nm_sync c${new_admin_cli_i} admin_nodemap
1406 do_node $test_fops_admin_client chmod $perm_bits $DIR/$tdir || return 1
1408 # remove admin for single client if originally non-admin
1409 if [ "$num_clients" == "1" ] && [ "$test_fops_admin_val" != "1" ]; then
1410 do_facet mgs $LCTL nodemap_modify --name c0 --property admin \
1412 wait_nm_sync c0 admin_nodemap
1420 local single_client="$2"
1421 local client_user_list=([0]="0 $((IDBASE+3))"
1422 [1]="0 $((IDBASE+5))")
1423 local mds_users="-1 0"
1426 local perm_bit_list="3 $((0300))"
1427 # SLOW tests 000-007, 010-070, 100-700 (octal modes)
1428 if [ "$SLOW" == "yes" ]; then
1429 perm_bit_list="0 $(seq 1 7) $(seq 8 8 63) $(seq 64 64 511) \
1431 client_user_list=([0]="0 $((IDBASE+3)) $((IDBASE+4))"
1432 [1]="0 $((IDBASE+5)) $((IDBASE+6))")
1433 mds_users="-1 0 1 2"
1436 # force single_client to speed up test
1437 [ "$SLOW" == "yes" ] ||
1439 # step through mds users. -1 means root
1440 for mds_i in $mds_users; do
1441 local user=$((mds_i + IDBASE))
1445 [ "$mds_i" == "-1" ] && user=0
1447 echo mkdir -p $DIR/$tdir
1450 for client in $clients; do
1452 for u in ${client_user_list[$cli_i]}; do
1453 local run_u="do_node $client \
1454 $RUNAS_CMD -u$u -g$u -G$u"
1455 for perm_bits in $perm_bit_list; do
1456 local mode=$(printf %03o $perm_bits)
1458 key="$mapmode:$user:c$cli_i:$u:$mode"
1459 test_fops_chmod_dir $cli_i $mode \
1461 error cannot chmod $key
1462 do_create_delete "$run_u" "$key"
1466 test_fops_chmod_dir $cli_i 777 $DIR/$tdir ||
1467 error cannot chmod $key
1468 do_fops_quota_test "$run_u"
1471 cli_i=$((cli_i + 1))
1472 [ "$single_client" == "1" ] && break
1479 nodemap_version_check () {
1480 remote_mgs_nodsh && skip "remote MGS with nodsh" && return 1
1481 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
1482 skip "No nodemap on $MGS_VERSION MGS < 2.5.53" &&
1487 nodemap_test_setup() {
1489 local active_nodemap=1
1491 [ "$1" == "0" ] && active_nodemap=0
1493 do_nodes $(comma_list $(all_mdts_nodes)) \
1494 $LCTL set_param mdt.*.identity_upcall=NONE
1497 create_fops_nodemaps
1499 [[ $rc != 0 ]] && error "adding fops nodemaps failed $rc"
1501 do_facet mgs $LCTL nodemap_activate $active_nodemap
1504 do_facet mgs $LCTL nodemap_modify --name default \
1505 --property admin --value 1
1506 wait_nm_sync default admin_nodemap
1507 do_facet mgs $LCTL nodemap_modify --name default \
1508 --property trusted --value 1
1509 wait_nm_sync default trusted_nodemap
1512 nodemap_test_cleanup() {
1514 delete_fops_nodemaps
1516 [[ $rc != 0 ]] && error "removing fops nodemaps failed $rc"
1518 do_facet mgs $LCTL nodemap_modify --name default \
1519 --property admin --value 0
1520 wait_nm_sync default admin_nodemap
1521 do_facet mgs $LCTL nodemap_modify --name default \
1522 --property trusted --value 0
1523 wait_nm_sync default trusted_nodemap
1525 do_facet mgs $LCTL nodemap_activate 0
1526 wait_nm_sync active 0
1528 export SK_UNIQUE_NM=false
1532 nodemap_clients_admin_trusted() {
1536 for client in $clients; do
1537 do_facet mgs $LCTL nodemap_modify --name c0 \
1538 --property admin --value $admin
1539 do_facet mgs $LCTL nodemap_modify --name c0 \
1540 --property trusted --value $tr
1543 wait_nm_sync c$((i - 1)) admin_nodemap
1544 wait_nm_sync c$((i - 1)) trusted_nodemap
1548 nodemap_version_check || return 0
1549 nodemap_test_setup 0
1551 trap nodemap_test_cleanup EXIT
1553 nodemap_test_cleanup
1555 run_test 16 "test nodemap all_off fileops"
1559 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1560 skip "Need MDS >= 2.11.55"
1563 nodemap_version_check || return 0
1566 trap nodemap_test_cleanup EXIT
1567 nodemap_clients_admin_trusted 0 1
1568 test_fops trusted_noadmin 1
1569 nodemap_test_cleanup
1571 run_test 17 "test nodemap trusted_noadmin fileops"
1575 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1576 skip "Need MDS >= 2.11.55"
1579 nodemap_version_check || return 0
1582 trap nodemap_test_cleanup EXIT
1583 nodemap_clients_admin_trusted 0 0
1584 test_fops mapped_noadmin 1
1585 nodemap_test_cleanup
1587 run_test 18 "test nodemap mapped_noadmin fileops"
1591 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1592 skip "Need MDS >= 2.11.55"
1595 nodemap_version_check || return 0
1598 trap nodemap_test_cleanup EXIT
1599 nodemap_clients_admin_trusted 1 1
1600 test_fops trusted_admin 1
1601 nodemap_test_cleanup
1603 run_test 19 "test nodemap trusted_admin fileops"
1607 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1608 skip "Need MDS >= 2.11.55"
1611 nodemap_version_check || return 0
1614 trap nodemap_test_cleanup EXIT
1615 nodemap_clients_admin_trusted 1 0
1616 test_fops mapped_admin 1
1617 nodemap_test_cleanup
1619 run_test 20 "test nodemap mapped_admin fileops"
1623 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1624 skip "Need MDS >= 2.11.55"
1627 nodemap_version_check || return 0
1630 trap nodemap_test_cleanup EXIT
1633 for client in $clients; do
1634 do_facet mgs $LCTL nodemap_modify --name c${i} \
1635 --property admin --value 0
1636 do_facet mgs $LCTL nodemap_modify --name c${i} \
1637 --property trusted --value $x
1641 wait_nm_sync c$((i - 1)) trusted_nodemap
1643 test_fops mapped_trusted_noadmin
1644 nodemap_test_cleanup
1646 run_test 21 "test nodemap mapped_trusted_noadmin fileops"
1650 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1651 skip "Need MDS >= 2.11.55"
1654 nodemap_version_check || return 0
1657 trap nodemap_test_cleanup EXIT
1660 for client in $clients; do
1661 do_facet mgs $LCTL nodemap_modify --name c${i} \
1662 --property admin --value 1
1663 do_facet mgs $LCTL nodemap_modify --name c${i} \
1664 --property trusted --value $x
1668 wait_nm_sync c$((i - 1)) trusted_nodemap
1670 test_fops mapped_trusted_admin
1671 nodemap_test_cleanup
1673 run_test 22 "test nodemap mapped_trusted_admin fileops"
1675 # acl test directory needs to be initialized on a privileged client
1676 nodemap_acl_test_setup() {
1677 local admin=$(do_facet mgs $LCTL get_param -n \
1678 nodemap.c0.admin_nodemap)
1679 local trust=$(do_facet mgs $LCTL get_param -n \
1680 nodemap.c0.trusted_nodemap)
1682 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1683 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
1685 wait_nm_sync c0 admin_nodemap
1686 wait_nm_sync c0 trusted_nodemap
1688 do_node ${clients_arr[0]} rm -rf $DIR/$tdir
1690 do_node ${clients_arr[0]} chmod a+rwx $DIR/$tdir ||
1691 error unable to chmod a+rwx test dir $DIR/$tdir
1693 do_facet mgs $LCTL nodemap_modify --name c0 \
1694 --property admin --value $admin
1695 do_facet mgs $LCTL nodemap_modify --name c0 \
1696 --property trusted --value $trust
1698 wait_nm_sync c0 trusted_nodemap
1701 # returns 0 if the number of ACLs does not change on the second (mapped) client
1702 # after being set on the first client
1703 nodemap_acl_test() {
1705 local set_client="$2"
1706 local get_client="$3"
1707 local check_setfacl="$4"
1708 local setfacl_error=0
1709 local testfile=$DIR/$tdir/$tfile
1710 local RUNAS_USER="$RUNAS_CMD -u $user"
1712 local acl_count_post=0
1714 nodemap_acl_test_setup
1717 do_node $set_client $RUNAS_USER touch $testfile
1719 # ACL masks aren't filtered by nodemap code, so we ignore them
1720 acl_count=$(do_node $get_client getfacl $testfile | grep -v mask |
1722 do_node $set_client $RUNAS_USER setfacl -m $user:rwx $testfile ||
1725 # if check setfacl is set to 1, then it's supposed to error
1726 if [ "$check_setfacl" == "1" ]; then
1727 [ "$setfacl_error" != "1" ] && return 1
1730 [ "$setfacl_error" == "1" ] && echo "WARNING: unable to setfacl"
1732 acl_count_post=$(do_node $get_client getfacl $testfile | grep -v mask |
1734 [ $acl_count -eq $acl_count_post ] && return 0
1739 [ $num_clients -lt 2 ] && skip "Need 2 clients at least" && return
1740 nodemap_version_check || return 0
1743 trap nodemap_test_cleanup EXIT
1744 # 1 trusted cluster, 1 mapped cluster
1745 local unmapped_fs=$((IDBASE+0))
1746 local unmapped_c1=$((IDBASE+5))
1747 local mapped_fs=$((IDBASE+2))
1748 local mapped_c0=$((IDBASE+4))
1749 local mapped_c1=$((IDBASE+6))
1751 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1752 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
1754 do_facet mgs $LCTL nodemap_modify --name c1 --property admin --value 0
1755 do_facet mgs $LCTL nodemap_modify --name c1 --property trusted --value 0
1757 wait_nm_sync c1 trusted_nodemap
1759 # setfacl on trusted cluster to unmapped user, verify it's not seen
1760 nodemap_acl_test $unmapped_fs ${clients_arr[0]} ${clients_arr[1]} ||
1761 error "acl count (1)"
1763 # setfacl on trusted cluster to mapped user, verify it's seen
1764 nodemap_acl_test $mapped_fs ${clients_arr[0]} ${clients_arr[1]} &&
1765 error "acl count (2)"
1767 # setfacl on mapped cluster to mapped user, verify it's seen
1768 nodemap_acl_test $mapped_c1 ${clients_arr[1]} ${clients_arr[0]} &&
1769 error "acl count (3)"
1771 # setfacl on mapped cluster to unmapped user, verify error
1772 nodemap_acl_test $unmapped_fs ${clients_arr[1]} ${clients_arr[0]} 1 ||
1773 error "acl count (4)"
1776 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 0
1777 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 0
1779 wait_nm_sync c0 trusted_nodemap
1781 # setfacl to mapped user on c1, also mapped to c0, verify it's seen
1782 nodemap_acl_test $mapped_c1 ${clients_arr[1]} ${clients_arr[0]} &&
1783 error "acl count (5)"
1785 # setfacl to mapped user on c1, not mapped to c0, verify not seen
1786 nodemap_acl_test $unmapped_c1 ${clients_arr[1]} ${clients_arr[0]} ||
1787 error "acl count (6)"
1789 nodemap_test_cleanup
1791 run_test 23a "test mapped regular ACLs"
1793 test_23b() { #LU-9929
1794 [ $num_clients -lt 2 ] && skip "Need 2 clients at least"
1795 [ "$MGS_VERSION" -lt $(version_code 2.10.53) ] &&
1796 skip "Need MGS >= 2.10.53"
1798 export SK_UNIQUE_NM=true
1800 trap nodemap_test_cleanup EXIT
1802 local testdir=$DIR/$tdir
1803 local fs_id=$((IDBASE+10))
1808 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1809 wait_nm_sync c0 admin_nodemap
1810 do_facet mgs $LCTL nodemap_modify --name c1 --property admin --value 1
1811 wait_nm_sync c1 admin_nodemap
1812 do_facet mgs $LCTL nodemap_modify --name c1 --property trusted --value 1
1813 wait_nm_sync c1 trusted_nodemap
1815 # Add idmap $ID0:$fs_id (500:60010)
1816 do_facet mgs $LCTL nodemap_add_idmap --name c0 --idtype gid \
1817 --idmap $ID0:$fs_id ||
1818 error "add idmap $ID0:$fs_id to nodemap c0 failed"
1819 wait_nm_sync c0 idmap
1821 # set/getfacl default acl on client 1 (unmapped gid=500)
1822 do_node ${clients_arr[0]} rm -rf $testdir
1823 do_node ${clients_arr[0]} mkdir -p $testdir
1824 # Here, USER0=$(getent passwd | grep :$ID0:$ID0: | cut -d: -f1)
1825 do_node ${clients_arr[0]} setfacl -R -d -m group:$USER0:rwx $testdir ||
1826 error "setfacl $testdir on ${clients_arr[0]} failed"
1827 unmapped_id=$(do_node ${clients_arr[0]} getfacl $testdir |
1828 grep -E "default:group:.*:rwx" | awk -F: '{print $3}')
1829 [ "$unmapped_id" = "$USER0" ] ||
1830 error "gid=$ID0 was not unmapped correctly on ${clients_arr[0]}"
1832 # getfacl default acl on client 2 (mapped gid=60010)
1833 mapped_id=$(do_node ${clients_arr[1]} getfacl $testdir |
1834 grep -E "default:group:.*:rwx" | awk -F: '{print $3}')
1835 fs_user=$(do_node ${clients_arr[1]} getent passwd |
1836 grep :$fs_id:$fs_id: | cut -d: -f1)
1837 [ -z "$fs_user" ] && fs_user=$fs_id
1838 [ $mapped_id -eq $fs_id -o "$mapped_id" = "$fs_user" ] ||
1839 error "Should return gid=$fs_id or $fs_user on client2"
1842 nodemap_test_cleanup
1843 export SK_UNIQUE_NM=false
1845 run_test 23b "test mapped default ACLs"
1850 trap nodemap_test_cleanup EXIT
1851 do_nodes $(comma_list $(all_server_nodes)) $LCTL get_param -R nodemap
1853 nodemap_test_cleanup
1855 run_test 24 "check nodemap proc files for LBUGs and Oopses"
1858 local tmpfile=$(mktemp)
1859 local tmpfile2=$(mktemp)
1860 local tmpfile3=$(mktemp)
1861 local tmpfile4=$(mktemp)
1865 nodemap_version_check || return 0
1867 # stop clients for this test
1868 zconf_umount_clients $CLIENTS $MOUNT ||
1869 error "unable to umount clients $CLIENTS"
1871 export SK_UNIQUE_NM=true
1874 # enable trusted/admin for setquota call in cleanup_and_setup_lustre()
1876 for client in $clients; do
1877 do_facet mgs $LCTL nodemap_modify --name c${i} \
1878 --property admin --value 1
1879 do_facet mgs $LCTL nodemap_modify --name c${i} \
1880 --property trusted --value 1
1883 wait_nm_sync c$((i - 1)) trusted_nodemap
1885 trap nodemap_test_cleanup EXIT
1887 # create a new, empty nodemap, and add fileset info to it
1888 do_facet mgs $LCTL nodemap_add test25 ||
1889 error "unable to create nodemap $testname"
1890 do_facet mgs $LCTL set_param -P nodemap.$testname.fileset=/$subdir ||
1891 error "unable to add fileset info to nodemap test25"
1893 wait_nm_sync test25 id
1895 do_facet mgs $LCTL nodemap_info > $tmpfile
1896 do_facet mds $LCTL nodemap_info > $tmpfile2
1898 if ! $SHARED_KEY; then
1899 # will conflict with SK's nodemaps
1900 cleanup_and_setup_lustre
1902 # stop clients for this test
1903 zconf_umount_clients $CLIENTS $MOUNT ||
1904 error "unable to umount clients $CLIENTS"
1906 do_facet mgs $LCTL nodemap_info > $tmpfile3
1907 diff -q $tmpfile3 $tmpfile >& /dev/null ||
1908 error "nodemap_info diff on MGS after remount"
1910 do_facet mds $LCTL nodemap_info > $tmpfile4
1911 diff -q $tmpfile4 $tmpfile2 >& /dev/null ||
1912 error "nodemap_info diff on MDS after remount"
1915 do_facet mgs $LCTL nodemap_del test25 ||
1916 error "cannot delete nodemap test25 from config"
1917 nodemap_test_cleanup
1918 # restart clients previously stopped
1919 zconf_mount_clients $CLIENTS $MOUNT ||
1920 error "unable to mount clients $CLIENTS"
1922 rm -f $tmpfile $tmpfile2
1923 export SK_UNIQUE_NM=false
1925 run_test 25 "test save and reload nodemap config"
1928 nodemap_version_check || return 0
1932 do_facet mgs "seq -f 'c%g' $large_i | xargs -n1 $LCTL nodemap_add"
1933 wait_nm_sync c$large_i admin_nodemap
1935 do_facet mgs "seq -f 'c%g' $large_i | xargs -n1 $LCTL nodemap_del"
1936 wait_nm_sync c$large_i admin_nodemap
1938 run_test 26 "test transferring very large nodemap"
1940 nodemap_exercise_fileset() {
1945 if [ "$nm" == "default" ]; then
1946 do_facet mgs $LCTL nodemap_activate 1
1951 if $SHARED_KEY; then
1952 export SK_UNIQUE_NM=true
1954 # will conflict with SK's nodemaps
1955 trap "fileset_test_cleanup $nm" EXIT
1957 fileset_test_setup "$nm"
1959 # add fileset info to $nm nodemap
1960 if ! combined_mgs_mds; then
1961 do_facet mgs $LCTL set_param nodemap.${nm}.fileset=/$subdir ||
1962 error "unable to add fileset info to $nm nodemap on MGS"
1964 do_facet mgs $LCTL set_param -P nodemap.${nm}.fileset=/$subdir ||
1965 error "unable to add fileset info to $nm nodemap for servers"
1966 wait_nm_sync $nm fileset "nodemap.${nm}.fileset=/$subdir"
1969 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
1970 error "unable to umount client ${clients_arr[0]}"
1971 # set some generic fileset to trigger SSK code
1973 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
1974 error "unable to remount client ${clients_arr[0]}"
1977 # test mount point content
1978 do_node ${clients_arr[0]} test -f $MOUNT/this_is_$subdir ||
1979 error "fileset not taken into account"
1981 # re-mount client with sub-subdir
1982 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
1983 error "unable to umount client ${clients_arr[0]}"
1984 export FILESET=/$subsubdir
1985 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
1986 error "unable to remount client ${clients_arr[0]}"
1989 # test mount point content
1990 do_node ${clients_arr[0]} test -f $MOUNT/this_is_$subsubdir ||
1991 error "subdir of fileset not taken into account"
1993 # remove fileset info from nodemap
1994 do_facet mgs $LCTL nodemap_set_fileset --name $nm --fileset clear ||
1995 error "unable to delete fileset info on $nm nodemap"
1996 wait_update_facet mgs "$LCTL get_param nodemap.${nm}.fileset" \
1997 "nodemap.${nm}.fileset=" ||
1998 error "fileset info still not cleared on $nm nodemap"
1999 do_facet mgs $LCTL set_param -P nodemap.${nm}.fileset=clear ||
2000 error "unable to reset fileset info on $nm nodemap"
2001 wait_nm_sync $nm fileset "nodemap.${nm}.fileset="
2004 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2005 error "unable to umount client ${clients_arr[0]}"
2006 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2007 error "unable to remount client ${clients_arr[0]}"
2009 # test mount point content
2010 if ! $(do_node ${clients_arr[0]} test -d $MOUNT/$subdir); then
2012 error "fileset not cleared on $nm nodemap"
2015 # back to non-nodemap setup
2016 if $SHARED_KEY; then
2017 export SK_UNIQUE_NM=false
2018 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2019 error "unable to umount client ${clients_arr[0]}"
2021 fileset_test_cleanup "$nm"
2022 if [ "$nm" == "default" ]; then
2023 do_facet mgs $LCTL nodemap_activate 0
2024 wait_nm_sync active 0
2026 export SK_UNIQUE_NM=false
2028 nodemap_test_cleanup
2030 if $SHARED_KEY; then
2031 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2032 error "unable to remount client ${clients_arr[0]}"
2037 [ "$MDS1_VERSION" -lt $(version_code 2.11.50) ] &&
2038 skip "Need MDS >= 2.11.50"
2040 for nm in "default" "c0"; do
2041 local subdir="subdir_${nm}"
2042 local subsubdir="subsubdir_${nm}"
2044 if [ "$nm" == "default" ] && [ "$SHARED_KEY" == "true" ]; then
2045 echo "Skipping nodemap $nm with SHARED_KEY";
2049 echo "Exercising fileset for nodemap $nm"
2050 nodemap_exercise_fileset "$nm"
2053 run_test 27a "test fileset in various nodemaps"
2055 test_27b() { #LU-10703
2056 [ "$MDS1_VERSION" -lt $(version_code 2.11.50) ] &&
2057 skip "Need MDS >= 2.11.50"
2058 [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs"
2061 trap nodemap_test_cleanup EXIT
2063 # Add the nodemaps and set their filesets
2064 for i in $(seq 1 $MDSCOUNT); do
2065 do_facet mgs $LCTL nodemap_del nm$i 2>/dev/null
2066 do_facet mgs $LCTL nodemap_add nm$i ||
2067 error "add nodemap nm$i failed"
2068 wait_nm_sync nm$i "" "" "-N"
2070 if ! combined_mgs_mds; then
2072 $LCTL set_param nodemap.nm$i.fileset=/dir$i ||
2073 error "set nm$i.fileset=/dir$i failed on MGS"
2075 do_facet mgs $LCTL set_param -P nodemap.nm$i.fileset=/dir$i ||
2076 error "set nm$i.fileset=/dir$i failed on servers"
2077 wait_nm_sync nm$i fileset "nodemap.nm$i.fileset=/dir$i"
2080 # Check if all the filesets are correct
2081 for i in $(seq 1 $MDSCOUNT); do
2082 fileset=$(do_facet mds$i \
2083 $LCTL get_param -n nodemap.nm$i.fileset)
2084 [ "$fileset" = "/dir$i" ] ||
2085 error "nm$i.fileset $fileset != /dir$i on mds$i"
2086 do_facet mgs $LCTL nodemap_del nm$i ||
2087 error "delete nodemap nm$i failed"
2090 nodemap_test_cleanup
2092 run_test 27b "The new nodemap won't clear the old nodemap's fileset"
2095 if ! $SHARED_KEY; then
2096 skip "need shared key feature for this test" && return
2098 mkdir -p $DIR/$tdir || error "mkdir failed"
2099 touch $DIR/$tdir/$tdir.out || error "touch failed"
2100 if [ ! -f $DIR/$tdir/$tdir.out ]; then
2101 error "read before rotation failed"
2103 # store top key identity to ensure rotation has occurred
2104 SK_IDENTITY_OLD=$(lctl get_param *.*.*srpc* | grep "expire" |
2105 head -1 | awk '{print $15}' | cut -c1-8)
2106 do_facet $SINGLEMDS lfs flushctx ||
2107 error "could not run flushctx on $SINGLEMDS"
2109 lfs flushctx || error "could not run flushctx on client"
2111 # verify new key is in place
2112 SK_IDENTITY_NEW=$(lctl get_param *.*.*srpc* | grep "expire" |
2113 head -1 | awk '{print $15}' | cut -c1-8)
2114 if [ $SK_IDENTITY_OLD == $SK_IDENTITY_NEW ]; then
2115 error "key did not rotate correctly"
2117 if [ ! -f $DIR/$tdir/$tdir.out ]; then
2118 error "read after rotation failed"
2121 run_test 28 "check shared key rotation method"
2124 if ! $SHARED_KEY; then
2125 skip "need shared key feature for this test" && return
2127 if [ $SK_FLAVOR != "ski" ] && [ $SK_FLAVOR != "skpi" ]; then
2128 skip "test only valid if integrity is active"
2131 mkdir $DIR/$tdir || error "mkdir"
2132 touch $DIR/$tdir/$tfile || error "touch"
2133 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2134 error "unable to umount clients"
2135 do_node ${clients_arr[0]} "keyctl show |
2136 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
2137 OLD_SK_PATH=$SK_PATH
2138 export SK_PATH=/dev/null
2139 if zconf_mount_clients ${clients_arr[0]} $MOUNT; then
2140 export SK_PATH=$OLD_SK_PATH
2141 do_node ${clients_arr[0]} "ls $DIR/$tdir/$tfile"
2142 if [ $? -eq 0 ]; then
2143 error "able to mount and read without key"
2145 error "able to mount without key"
2148 export SK_PATH=$OLD_SK_PATH
2149 do_node ${clients_arr[0]} "keyctl show |
2150 awk '/lustre/ { print \\\$1 }' |
2151 xargs -IX keyctl unlink X"
2153 zconf_mount_clients ${clients_arr[0]} $MOUNT ||
2154 error "unable to mount clients"
2156 run_test 29 "check for missing shared key"
2159 if ! $SHARED_KEY; then
2160 skip "need shared key feature for this test" && return
2162 if [ $SK_FLAVOR != "ski" ] && [ $SK_FLAVOR != "skpi" ]; then
2163 skip "test only valid if integrity is active"
2165 mkdir -p $DIR/$tdir || error "mkdir failed"
2166 touch $DIR/$tdir/$tdir.out || error "touch failed"
2167 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2168 error "unable to umount clients"
2169 # unload keys from ring
2170 do_node ${clients_arr[0]} "keyctl show |
2171 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
2172 # generate key with bogus filesystem name
2173 do_node ${clients_arr[0]} "lgss_sk -w $SK_PATH/$FSNAME-bogus.key \
2174 -f $FSNAME.bogus -t client -d /dev/urandom" ||
2175 error "lgss_sk failed (1)"
2176 do_facet $SINGLEMDS lfs flushctx || error "could not run flushctx"
2177 OLD_SK_PATH=$SK_PATH
2178 export SK_PATH=$SK_PATH/$FSNAME-bogus.key
2179 if zconf_mount_clients ${clients_arr[0]} $MOUNT; then
2180 SK_PATH=$OLD_SK_PATH
2181 do_node ${clients_arr[0]} "ls $DIR/$tdir/$tdir.out"
2182 if [ $? -eq 0 ]; then
2183 error "mount and read file with invalid key"
2185 error "mount with invalid key"
2188 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2189 error "unable to umount clients"
2190 # unload keys from ring
2191 do_node ${clients_arr[0]} "keyctl show |
2192 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
2194 SK_PATH=$OLD_SK_PATH
2195 zconf_mount_clients ${clients_arr[0]} $MOUNT ||
2196 error "unable to mount clients"
2198 run_test 30 "check for invalid shared key"
2203 mkdir -p $DIR/$tdir || error "mkdir $flvr"
2204 touch $DIR/$tdir/f0 || error "touch $flvr"
2205 ls $DIR/$tdir || error "ls $flvr"
2206 dd if=/dev/zero of=$DIR/$tdir/f0 conv=fsync bs=1M count=10 \
2207 >& /dev/null || error "dd $flvr"
2208 rm -f $DIR/$tdir/f0 || error "rm $flvr"
2209 rmdir $DIR/$tdir || error "rmdir $flvr"
2212 echo 3 > /proc/sys/vm/drop_caches
2216 local save_flvr=$SK_FLAVOR
2218 if ! $SHARED_KEY; then
2219 skip "need shared key feature for this test"
2222 stack_trap restore_to_default_flavor EXIT
2224 for flvr in skn ska ski skpi; do
2227 restore_to_default_flavor || error "cannot set $flvr flavor"
2228 SK_FLAVOR=$save_flvr
2233 run_test 30b "basic test of all different SSK flavors"
2237 zconf_umount $HOSTNAME $MOUNT || error "unable to umount client"
2239 # remove ${NETTYPE}999 network on all nodes
2240 do_nodes $(comma_list $(all_nodes)) \
2241 "$LNETCTL net del --net ${NETTYPE}999 && \
2242 $LNETCTL lnet unconfigure 2>/dev/null || true"
2244 # necessary to do writeconf in order to de-register
2245 # @${NETTYPE}999 nid for targets
2247 export KEEP_ZPOOL="true"
2249 export SK_MOUNTED=false
2252 export KEEP_ZPOOL="$KZPOOL"
2256 local nid=$(lctl list_nids | grep ${NETTYPE} | head -n1)
2257 local addr=${nid%@*}
2260 export LNETCTL=$(which lnetctl 2> /dev/null)
2262 [ -z "$LNETCTL" ] && skip "without lnetctl support." && return
2263 local_mode && skip "in local mode."
2265 stack_trap cleanup_31 EXIT
2268 if [ "$MOUNT_2" ] && $(grep -q $MOUNT2' ' /proc/mounts); then
2269 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2271 if $(grep -q $MOUNT' ' /proc/mounts); then
2272 umount_client $MOUNT || error "umount $MOUNT failed"
2275 # check exports on servers are empty for client
2276 do_facet mgs "lctl get_param -n *.MGS*.exports.'$nid'.uuid 2>/dev/null |
2277 grep -q -" && error "export on MGS should be empty"
2278 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
2279 "lctl get_param -n *.${FSNAME}*.exports.'$nid'.uuid \
2280 2>/dev/null | grep -q -" &&
2281 error "export on servers should be empty"
2283 # add network ${NETTYPE}999 on all nodes
2284 do_nodes $(comma_list $(all_nodes)) \
2285 "$LNETCTL lnet configure && $LNETCTL net add --if \
2286 \$($LNETCTL net show --net $net | awk 'BEGIN{inf=0} \
2287 {if (inf==1) print \$2; fi; inf=0} /interfaces/{inf=1}') \
2288 --net ${NETTYPE}999" ||
2289 error "unable to configure NID ${NETTYPE}999"
2291 # necessary to do writeconf in order to register
2292 # new @${NETTYPE}999 nid for targets
2294 export KEEP_ZPOOL="true"
2296 export SK_MOUNTED=false
2298 setupall server_only || echo 1
2299 export KEEP_ZPOOL="$KZPOOL"
2302 local mgsnid_orig=$MGSNID
2303 # compute new MGSNID
2304 MGSNID=$(do_facet mgs "$LCTL list_nids | grep ${NETTYPE}999")
2306 # on client, turn LNet Dynamic Discovery on
2307 lnetctl set discovery 1
2309 # mount client with -o network=${NETTYPE}999 option:
2310 # should fail because of LNet Dynamic Discovery
2311 mount_client $MOUNT ${MOUNT_OPTS},network=${NETTYPE}999 &&
2312 error "client mount with '-o network' option should be refused"
2314 # on client, reconfigure LNet and turn LNet Dynamic Discovery off
2315 $LNETCTL net del --net ${NETTYPE}999 && lnetctl lnet unconfigure
2318 lnetctl set discovery 0
2320 $LNETCTL lnet configure && $LNETCTL net add --if \
2321 $($LNETCTL net show --net $net | awk 'BEGIN{inf=0} \
2322 {if (inf==1) print $2; fi; inf=0} /interfaces/{inf=1}') \
2323 --net ${NETTYPE}999 ||
2324 error "unable to configure NID ${NETTYPE}999 on client"
2326 # mount client with -o network=${NETTYPE}999 option
2327 mount_client $MOUNT ${MOUNT_OPTS},network=${NETTYPE}999 ||
2328 error "unable to remount client"
2333 # check export on MGS
2334 do_facet mgs "lctl get_param -n *.MGS*.exports.'$nid'.uuid 2>/dev/null |
2336 [ $? -ne 0 ] || error "export for $nid on MGS should not exist"
2339 "lctl get_param -n *.MGS*.exports.'${addr}@${NETTYPE}999'.uuid \
2340 2>/dev/null | grep -q -"
2342 error "export for ${addr}@${NETTYPE}999 on MGS should exist"
2344 # check {mdc,osc} imports
2345 lctl get_param mdc.${FSNAME}-*.import | grep current_connection |
2346 grep -q ${NETTYPE}999
2348 error "import for mdc should use ${addr}@${NETTYPE}999"
2349 lctl get_param osc.${FSNAME}-*.import | grep current_connection |
2350 grep -q ${NETTYPE}999
2352 error "import for osc should use ${addr}@${NETTYPE}999"
2354 run_test 31 "client mount option '-o network'"
2358 zconf_umount_clients ${clients_arr[0]} $MOUNT
2360 # disable sk flavor enforcement on MGS
2361 set_rule _mgs any any null
2363 # stop gss daemon on MGS
2364 if ! combined_mgs_mds ; then
2365 send_sigint $mgs_HOST lsvcgssd
2369 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
2372 restore_to_default_flavor
2376 if ! $SHARED_KEY; then
2377 skip "need shared key feature for this test"
2380 stack_trap cleanup_32 EXIT
2382 # restore to default null flavor
2383 save_flvr=$SK_FLAVOR
2385 restore_to_default_flavor || error "cannot set null flavor"
2386 SK_FLAVOR=$save_flvr
2389 if [ "$MOUNT_2" ] && $(grep -q $MOUNT2' ' /proc/mounts); then
2390 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2392 if $(grep -q $MOUNT' ' /proc/mounts); then
2393 umount_client $MOUNT || error "umount $MOUNT failed"
2396 # start gss daemon on MGS
2397 if combined_mgs_mds ; then
2398 send_sigint $mds_HOST lsvcgssd
2400 start_gss_daemons $mgs_HOST "$LSVCGSSD -vvv -s -g"
2402 # add mgs key type and MGS NIDs in key on MGS
2403 do_nodes $mgs_HOST "lgss_sk -t mgs,server -g $MGSNID -m \
2404 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2405 error "could not modify keyfile on MGS"
2407 # load modified key file on MGS
2408 do_nodes $mgs_HOST "lgss_sk -l $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2409 error "could not load keyfile on MGS"
2411 # add MGS NIDs in key on client
2412 do_nodes ${clients_arr[0]} "lgss_sk -g $MGSNID -m \
2413 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2414 error "could not modify keyfile on MGS"
2416 # set perms for per-nodemap keys else permission denied
2417 do_nodes $(comma_list $(all_nodes)) \
2418 "keyctl show | grep lustre | cut -c1-11 |
2420 xargs -IX keyctl setperm X 0x3f3f3f3f"
2422 # re-mount client with mgssec=skn
2423 save_opts=$MOUNT_OPTS
2424 if [ -z "$MOUNT_OPTS" ]; then
2425 MOUNT_OPTS="-o mgssec=skn"
2427 MOUNT_OPTS="$MOUNT_OPTS,mgssec=skn"
2429 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2430 error "mount ${clients_arr[0]} with mgssec=skn failed"
2431 MOUNT_OPTS=$save_opts
2434 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2435 error "umount ${clients_arr[0]} failed"
2437 # enforce ska flavor on MGS
2438 set_rule _mgs any any ska
2440 # re-mount client without mgssec
2441 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS &&
2442 error "mount ${clients_arr[0]} without mgssec should fail"
2444 # re-mount client with mgssec=skn
2445 save_opts=$MOUNT_OPTS
2446 if [ -z "$MOUNT_OPTS" ]; then
2447 MOUNT_OPTS="-o mgssec=skn"
2449 MOUNT_OPTS="$MOUNT_OPTS,mgssec=skn"
2451 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS &&
2452 error "mount ${clients_arr[0]} with mgssec=skn should fail"
2453 MOUNT_OPTS=$save_opts
2455 # re-mount client with mgssec=ska
2456 save_opts=$MOUNT_OPTS
2457 if [ -z "$MOUNT_OPTS" ]; then
2458 MOUNT_OPTS="-o mgssec=ska"
2460 MOUNT_OPTS="$MOUNT_OPTS,mgssec=ska"
2462 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2463 error "mount ${clients_arr[0]} with mgssec=ska failed"
2464 MOUNT_OPTS=$save_opts
2468 run_test 32 "check for mgssec"
2471 # disable sk flavor enforcement
2472 set_rule $FSNAME any cli2mdt null
2473 wait_flavor cli2mdt null
2476 zconf_umount_clients ${clients_arr[0]} $MOUNT
2478 # stop gss daemon on MGS
2479 if ! combined_mgs_mds ; then
2480 send_sigint $mgs_HOST lsvcgssd
2484 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
2487 restore_to_default_flavor
2491 if ! $SHARED_KEY; then
2492 skip "need shared key feature for this test"
2495 stack_trap cleanup_33 EXIT
2497 # restore to default null flavor
2498 save_flvr=$SK_FLAVOR
2500 restore_to_default_flavor || error "cannot set null flavor"
2501 SK_FLAVOR=$save_flvr
2504 if [ "$MOUNT_2" ] && $(grep -q $MOUNT2' ' /proc/mounts); then
2505 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2507 if $(grep -q $MOUNT' ' /proc/mounts); then
2508 umount_client $MOUNT || error "umount $MOUNT failed"
2511 # start gss daemon on MGS
2512 if combined_mgs_mds ; then
2513 send_sigint $mds_HOST lsvcgssd
2515 start_gss_daemons $mgs_HOST "$LSVCGSSD -vvv -s -g"
2517 # add mgs key type and MGS NIDs in key on MGS
2518 do_nodes $mgs_HOST "lgss_sk -t mgs,server -g $MGSNID -m \
2519 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2520 error "could not modify keyfile on MGS"
2522 # load modified key file on MGS
2523 do_nodes $mgs_HOST "lgss_sk -l $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2524 error "could not load keyfile on MGS"
2526 # add MGS NIDs in key on client
2527 do_nodes ${clients_arr[0]} "lgss_sk -g $MGSNID -m \
2528 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2529 error "could not modify keyfile on MGS"
2531 # set perms for per-nodemap keys else permission denied
2532 do_nodes $(comma_list $(all_nodes)) \
2533 "keyctl show | grep lustre | cut -c1-11 |
2535 xargs -IX keyctl setperm X 0x3f3f3f3f"
2537 # re-mount client with mgssec=skn
2538 save_opts=$MOUNT_OPTS
2539 if [ -z "$MOUNT_OPTS" ]; then
2540 MOUNT_OPTS="-o mgssec=skn"
2542 MOUNT_OPTS="$MOUNT_OPTS,mgssec=skn"
2544 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2545 error "mount ${clients_arr[0]} with mgssec=skn failed"
2546 MOUNT_OPTS=$save_opts
2548 # enforce ska flavor for cli2mdt
2549 set_rule $FSNAME any cli2mdt ska
2550 wait_flavor cli2mdt ska
2552 # check error message
2553 $LCTL dk | grep "faked source" &&
2554 error "MGS connection srpc flags incorrect"
2558 run_test 33 "correct srpc flags for MGS connection"
2561 # restore deny_unknown
2562 do_facet mgs $LCTL nodemap_modify --name default \
2563 --property deny_unknown --value $denydefault
2564 if [ $? -ne 0 ]; then
2565 error_noexit "cannot reset deny_unknown on default nodemap"
2569 wait_nm_sync default deny_unknown
2576 [ $MGS_VERSION -lt $(version_code 2.12.51) ] &&
2577 skip "deny_unknown on default nm not supported before 2.12.51"
2579 activedefault=$(do_facet mgs $LCTL get_param -n nodemap.active)
2581 if [[ "$activedefault" != "1" ]]; then
2582 do_facet mgs $LCTL nodemap_activate 1
2584 stack_trap cleanup_active EXIT
2587 denydefault=$(do_facet mgs $LCTL get_param -n \
2588 nodemap.default.deny_unknown)
2589 [ -z "$denydefault" ] &&
2590 error "cannot get deny_unknown on default nodemap"
2591 if [ "$denydefault" -eq 0 ]; then
2597 do_facet mgs $LCTL nodemap_modify --name default \
2598 --property deny_unknown --value $denynew ||
2599 error "cannot set deny_unknown on default nodemap"
2601 [ "$(do_facet mgs $LCTL get_param -n nodemap.default.deny_unknown)" \
2603 error "setting deny_unknown on default nodemap did not work"
2605 stack_trap cleanup_34_deny EXIT
2607 wait_nm_sync default deny_unknown
2609 run_test 34 "deny_unknown on default nodemap"
2612 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.13.50) ] ||
2613 skip "Need MDS >= 2.13.50"
2615 # activate changelogs
2616 changelog_register || error "changelog_register failed"
2617 local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
2618 changelog_users $SINGLEMDS | grep -q $cl_user ||
2619 error "User $cl_user not found in changelog_users"
2620 changelog_chmask ALL
2623 mkdir $DIR/$tdir || error "failed to mkdir $tdir"
2624 touch $DIR/$tdir/$tfile || error "failed to touch $tfile"
2626 # access changelogs with root
2627 changelog_dump || error "failed to dump changelogs"
2628 changelog_clear 0 || error "failed to clear changelogs"
2630 # put clients in non-admin nodemap
2632 stack_trap nodemap_test_cleanup EXIT
2633 for i in $(seq 0 $((num_clients-1))); do
2634 do_facet mgs $LCTL nodemap_modify --name c${i} \
2635 --property admin --value 0
2637 for i in $(seq 0 $((num_clients-1))); do
2638 wait_nm_sync c${i} admin_nodemap
2641 # access with mapped root
2642 changelog_dump && error "dump changelogs should have failed"
2643 changelog_clear 0 && error "clear changelogs should have failed"
2647 run_test 35 "Check permissions when accessing changelogs"
2649 setup_for_enc_tests() {
2650 # remount client with test_dummy_encryption option
2651 if is_mounted $MOUNT; then
2652 umount_client $MOUNT || error "umount $MOUNT failed"
2654 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption ||
2655 error "mount with '-o test_dummy_encryption' failed"
2657 # this directory will be encrypted, because of dummy mode
2661 cleanup_for_enc_tests() {
2664 # remount client normally
2665 if is_mounted $MOUNT; then
2666 umount_client $MOUNT || error "umount $MOUNT failed"
2668 mount_client $MOUNT ${MOUNT_OPTS} ||
2669 error "remount failed"
2671 if is_mounted $MOUNT2; then
2672 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2674 if [ "$MOUNT_2" ]; then
2675 mount_client $MOUNT2 ${MOUNT_OPTS} ||
2676 error "remount failed"
2680 cleanup_nodemap_after_enc_tests() {
2681 do_facet mgs $LCTL nodemap_modify --name default \
2682 --property forbid_encryption --value 0
2683 wait_nm_sync default forbid_encryption
2684 do_facet mgs $LCTL nodemap_activate 0
2689 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2690 skip "client encryption not supported"
2692 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2693 skip "need dummy encryption support"
2695 stack_trap cleanup_for_enc_tests EXIT
2697 # first make sure it is possible to enable encryption
2698 # when nodemap is not active
2701 umount_client $MOUNT || error "umount $MOUNT failed (1)"
2703 # then activate nodemap, and retry
2704 # should succeed as encryption is not forbidden on default nodemap
2706 stack_trap cleanup_nodemap_after_enc_tests EXIT
2707 do_facet mgs $LCTL nodemap_activate 1
2709 forbid=$(do_facet mgs lctl get_param -n nodemap.default.forbid_encryption)
2710 [ $forbid -eq 0 ] || error "wrong default value for forbid_encryption"
2711 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption ||
2712 error "mount '-o test_dummy_encryption' failed with default"
2713 umount_client $MOUNT || error "umount $MOUNT failed (2)"
2715 # then forbid encryption, and retry
2716 do_facet mgs $LCTL nodemap_modify --name default \
2717 --property forbid_encryption --value 1
2718 wait_nm_sync default forbid_encryption
2719 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption &&
2720 error "mount '-o test_dummy_encryption' should have failed"
2723 run_test 36 "control if clients can use encryption"
2726 local testfile=$DIR/$tdir/$tfile
2727 local tmpfile=$TMP/abc
2728 local objdump=$TMP/objdump
2731 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2732 skip "client encryption not supported"
2734 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2735 skip "need dummy encryption support"
2737 [ "$ost1_FSTYPE" = ldiskfs ] || skip "ldiskfs only test (using debugfs)"
2739 stack_trap cleanup_for_enc_tests EXIT
2742 # write a few bytes in file
2743 echo "abc" > $tmpfile
2744 $LFS setstripe -c1 -i0 $testfile
2745 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2746 do_facet ost1 "sync; sync"
2748 # check that content on ost is encrypted
2749 objid=$($LFS getstripe $testfile | awk '/obdidx/{getline; print $2}')
2750 do_facet ost1 "$DEBUGFS -c -R 'cat O/0/d$(($objid % 32))/$objid' \
2751 $(ostdevname 1)" > $objdump
2752 cmp -s $objdump $tmpfile &&
2753 error "file $testfile is not encrypted on ost"
2755 # check that in-memory representation of file is correct
2756 cmp -bl ${tmpfile} ${testfile} ||
2757 error "file $testfile is corrupted in memory"
2759 cancel_lru_locks osc ; cancel_lru_locks mdc
2761 # check that file read from server is correct
2762 cmp -bl ${tmpfile} ${testfile} ||
2763 error "file $testfile is corrupted on server"
2765 rm -f $tmpfile $objdump
2767 run_test 37 "simple encrypted file"
2770 local testfile=$DIR/$tdir/$tfile
2771 local tmpfile=$TMP/abc
2777 local pagesz=$(getconf PAGE_SIZE)
2779 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2780 skip "client encryption not supported"
2782 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2783 skip "need dummy encryption support"
2785 stack_trap cleanup_for_enc_tests EXIT
2788 # get block size on ost
2789 blksz=$($LCTL get_param osc.$FSNAME*.import |
2790 awk '/grant_block_size:/ { print $2; exit; }')
2791 # write a few bytes in file at offset $blksz
2792 echo "abc" > $tmpfile
2793 $LFS setstripe -c1 -i0 $testfile
2794 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$blksz \
2795 oflag=seek_bytes conv=fsync
2797 blksz=$(($blksz > $pagesz ? $blksz : $pagesz))
2798 # check that in-memory representation of file is correct
2799 bsize=$(stat --format=%B $testfile)
2800 filesz=$(stat --format=%b $testfile)
2801 filesz=$((filesz*bsize))
2802 [ $filesz -le $blksz ] ||
2803 error "file $testfile is $filesz long in memory"
2805 cancel_lru_locks osc ; cancel_lru_locks mdc
2807 # check that file read from server is correct
2808 bsize=$(stat --format=%B $testfile)
2809 filesz=$(stat --format=%b $testfile)
2810 filesz=$((filesz*bsize))
2811 [ $filesz -le $blksz ] ||
2812 error "file $testfile is $filesz long on server"
2816 run_test 38 "encrypted file with hole"
2819 local testfile=$DIR/$tdir/$tfile
2820 local tmpfile=$TMP/abc
2822 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2823 skip "client encryption not supported"
2825 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2826 skip "need dummy encryption support"
2828 stack_trap cleanup_for_enc_tests EXIT
2831 # write a few bytes in file
2832 echo "abc" > $tmpfile
2833 $LFS setstripe -c1 -i0 $testfile
2834 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2836 # write a few more bytes in the same page
2837 dd if=$tmpfile of=$testfile bs=4 count=1 seek=1024 oflag=seek_bytes \
2840 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=1024 oflag=seek_bytes \
2843 # check that in-memory representation of file is correct
2844 cmp -bl $tmpfile $testfile ||
2845 error "file $testfile is corrupted in memory"
2847 cancel_lru_locks osc ; cancel_lru_locks mdc
2849 # check that file read from server is correct
2850 cmp -bl $tmpfile $testfile ||
2851 error "file $testfile is corrupted on server"
2855 run_test 39 "rewrite data in already encrypted page"
2858 local testfile=$DIR/$tdir/$tfile
2859 local tmpfile=$TMP/abc
2860 local tmpfile2=$TMP/abc2
2863 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2864 skip "client encryption not supported"
2866 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2867 skip "need dummy encryption support"
2869 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2871 stack_trap cleanup_for_enc_tests EXIT
2874 # write a few bytes in file
2875 echo "abc" > $tmpfile
2876 $LFS setstripe -c1 -i0 $testfile
2877 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2879 # check that in-memory representation of file is correct
2880 cmp -bl $tmpfile $testfile ||
2881 error "file $testfile is corrupted in memory (1)"
2883 cancel_lru_locks osc ; cancel_lru_locks mdc
2885 # check that file read from server is correct
2886 cmp -bl $tmpfile $testfile ||
2887 error "file $testfile is corrupted on server (1)"
2889 # write a few other bytes in same page
2890 dd if=$tmpfile of=$testfile bs=4 count=1 seek=256 oflag=seek_bytes \
2893 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=256 oflag=seek_bytes \
2896 # check that in-memory representation of file is correct
2897 cmp -bl $tmpfile $testfile ||
2898 error "file $testfile is corrupted in memory (2)"
2900 cancel_lru_locks osc ; cancel_lru_locks mdc
2902 # check that file read from server is correct
2903 cmp -bl $tmpfile $testfile ||
2904 error "file $testfile is corrupted on server (2)"
2906 rm -f $testfile $tmpfile
2907 cancel_lru_locks osc ; cancel_lru_locks mdc
2909 # write a few bytes in file, at end of first page
2910 echo "abc" > $tmpfile
2911 $LFS setstripe -c1 -i0 $testfile
2912 seek=$(getconf PAGESIZE)
2914 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2917 # write a few other bytes at beginning of first page
2918 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync,notrunc
2920 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2923 # check that in-memory representation of file is correct
2924 cmp -bl $tmpfile $testfile ||
2925 error "file $testfile is corrupted in memory (3)"
2927 cancel_lru_locks osc ; cancel_lru_locks mdc
2929 # check that file read from server is correct
2930 cmp -bl $tmpfile $testfile ||
2931 error "file $testfile is corrupted on server (3)"
2933 rm -f $testfile $tmpfile
2934 cancel_lru_locks osc ; cancel_lru_locks mdc
2936 # write a few bytes in file, at beginning of second page
2937 echo "abc" > $tmpfile
2938 $LFS setstripe -c1 -i0 $testfile
2939 seek=$(getconf PAGESIZE)
2940 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2942 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
2945 # write a few other bytes at end of first page
2947 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2949 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
2952 # check that in-memory representation of file is correct
2953 cmp -bl $tmpfile2 $testfile ||
2954 error "file $testfile is corrupted in memory (4)"
2956 cancel_lru_locks osc ; cancel_lru_locks mdc
2958 # check that file read from server is correct
2959 cmp -bl $tmpfile2 $testfile ||
2960 error "file $testfile is corrupted on server (4)"
2962 rm -f $testfile $tmpfile $tmpfile2
2963 cancel_lru_locks osc ; cancel_lru_locks mdc
2965 # write a few bytes in file, at beginning of first stripe
2966 echo "abc" > $tmpfile
2967 $LFS setstripe -S 256k -c2 $testfile
2968 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync,notrunc
2970 # write a few other bytes, at beginning of second stripe
2971 dd if=$tmpfile of=$testfile bs=4 count=1 seek=262144 oflag=seek_bytes \
2973 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=262144 oflag=seek_bytes \
2976 # check that in-memory representation of file is correct
2977 cmp -bl $tmpfile $testfile ||
2978 error "file $testfile is corrupted in memory (5)"
2980 cancel_lru_locks osc ; cancel_lru_locks mdc
2982 # check that file read from server is correct
2983 cmp -bl $tmpfile $testfile ||
2984 error "file $testfile is corrupted on server (5)"
2988 run_test 40 "exercise size of encrypted file"
2991 local testfile=$DIR/$tdir/$tfile
2992 local tmpfile=$TMP/abc
2993 local tmpfile2=$TMP/abc2
2996 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2997 skip "client encryption not supported"
2999 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3000 skip "need dummy encryption support"
3002 stack_trap cleanup_for_enc_tests EXIT
3005 echo "abc" > $tmpfile
3006 seek=$(getconf PAGESIZE)
3007 seek=$((seek - 204))
3008 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3010 seek=$(getconf PAGESIZE)
3011 seek=$((seek + 1092))
3012 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3015 # write a few bytes in file
3016 $LFS setstripe -c1 -i0 -S 256k $testfile
3017 seek=$(getconf PAGESIZE)
3018 seek=$((seek - 204))
3019 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
3020 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
3021 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3025 # write a few other bytes, at a different offset
3026 seek=$(getconf PAGESIZE)
3027 seek=$((seek + 1092))
3028 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3029 conv=fsync,notrunc &
3031 do_facet ost1 "$LCTL set_param fail_loc=0x0"
3033 # check that in-memory representation of file is correct
3034 cmp -bl $tmpfile2 $testfile ||
3035 error "file $testfile is corrupted in memory (1)"
3037 cancel_lru_locks osc ; cancel_lru_locks mdc
3039 # check that file read from server is correct
3040 cmp -bl $tmpfile2 $testfile ||
3041 error "file $testfile is corrupted on server (1)"
3043 rm -f $tmpfile $tmpfile2
3045 run_test 41 "test race on encrypted file size (1)"
3048 local testfile=$DIR/$tdir/$tfile
3049 local testfile2=$DIR2/$tdir/$tfile
3050 local tmpfile=$TMP/abc
3051 local tmpfile2=$TMP/abc2
3052 local pagesz=$(getconf PAGESIZE)
3055 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3056 skip "client encryption not supported"
3058 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3059 skip "need dummy encryption support"
3061 stack_trap cleanup_for_enc_tests EXIT
3064 if is_mounted $MOUNT2; then
3065 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
3067 mount_client $MOUNT2 ${MOUNT_OPTS},test_dummy_encryption ||
3068 error "mount2 with '-o test_dummy_encryption' failed"
3070 # create file by writting one whole page
3071 $LFS setstripe -c1 -i0 -S 256k $testfile
3072 dd if=/dev/zero of=$testfile bs=$pagesz count=1 conv=fsync
3074 # read file from 2nd mount point
3075 cat $testfile2 > /dev/null
3077 echo "abc" > $tmpfile
3078 dd if=/dev/zero of=$tmpfile2 bs=$pagesz count=1 conv=fsync
3079 seek=$((2*pagesz - 204))
3080 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3082 seek=$((2*pagesz + 1092))
3083 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3086 # write a few bytes in file from 1st mount point
3087 seek=$((2*pagesz - 204))
3088 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
3089 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
3090 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3091 conv=fsync,notrunc &
3094 # write a few other bytes, at a different offset from 2nd mount point
3095 seek=$((2*pagesz + 1092))
3096 dd if=$tmpfile of=$testfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3097 conv=fsync,notrunc &
3099 do_facet ost1 "$LCTL set_param fail_loc=0x0"
3101 # check that in-memory representation of file is correct
3102 cmp -bl $tmpfile2 $testfile ||
3103 error "file $testfile is corrupted in memory (1)"
3105 # check that in-memory representation of file is correct
3106 cmp -bl $tmpfile2 $testfile2 ||
3107 error "file $testfile is corrupted in memory (2)"
3109 cancel_lru_locks osc ; cancel_lru_locks mdc
3111 # check that file read from server is correct
3112 cmp -bl $tmpfile2 $testfile ||
3113 error "file $testfile is corrupted on server (1)"
3115 rm -f $tmpfile $tmpfile2
3117 run_test 42 "test race on encrypted file size (2)"
3120 local testfile=$DIR/$tdir/$tfile
3121 local testfile2=$DIR2/$tdir/$tfile
3122 local tmpfile=$TMP/abc
3123 local tmpfile2=$TMP/abc2
3124 local resfile=$TMP/res
3125 local pagesz=$(getconf PAGESIZE)
3128 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3129 skip "client encryption not supported"
3131 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3132 skip "need dummy encryption support"
3134 stack_trap cleanup_for_enc_tests EXIT
3137 if is_mounted $MOUNT2; then
3138 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
3140 mount_client $MOUNT2 ${MOUNT_OPTS},test_dummy_encryption ||
3141 error "mount2 with '-o test_dummy_encryption' failed"
3144 tr '\0' '1' < /dev/zero |
3145 dd of=$tmpfile bs=1 count=$pagesz conv=fsync
3146 $LFS setstripe -c1 -i0 -S 256k $testfile
3147 cp $tmpfile $testfile
3149 # read file from 2nd mount point
3150 cat $testfile2 > /dev/null
3152 # write a few bytes in file from 1st mount point
3153 echo "abc" > $tmpfile2
3154 seek=$((2*pagesz - 204))
3155 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
3156 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
3157 dd if=$tmpfile2 of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3158 conv=fsync,notrunc &
3161 # read file from 2nd mount point
3162 dd if=$testfile2 of=$resfile bs=$pagesz count=1 conv=fsync,notrunc
3163 cmp -bl $tmpfile $resfile ||
3164 error "file $testfile is corrupted in memory (1)"
3167 do_facet ost1 "$LCTL set_param fail_loc=0x0"
3169 # check that in-memory representation of file is correct
3170 dd if=$tmpfile2 of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3172 cmp -bl $tmpfile $testfile2 ||
3173 error "file $testfile is corrupted in memory (2)"
3175 cancel_lru_locks osc ; cancel_lru_locks mdc
3177 # check that file read from server is correct
3178 cmp -bl $tmpfile $testfile ||
3179 error "file $testfile is corrupted on server (1)"
3181 rm -f $tmpfile $tmpfile2
3183 run_test 43 "test race on encrypted file size (3)"
3186 local testfile=$DIR/$tdir/$tfile
3187 local tmpfile=$TMP/abc
3188 local resfile=$TMP/resfile
3189 local pagesz=$(getconf PAGESIZE)
3192 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3193 skip "client encryption not supported"
3195 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3196 skip "need dummy encryption support"
3198 which vmtouch || skip "This test needs vmtouch utility"
3200 # Direct I/O is now supported on encrypted files.
3202 stack_trap cleanup_for_enc_tests EXIT
3205 $LFS setstripe -c1 -i0 $testfile
3206 dd if=/dev/urandom of=$tmpfile bs=$pagesz count=2 conv=fsync
3207 dd if=$tmpfile of=$testfile bs=$pagesz count=2 oflag=direct ||
3208 error "could not write to file with O_DIRECT (1)"
3210 respage=$(vmtouch $testfile | awk '/Resident Pages:/ {print $3}')
3211 [ "$respage" == "0/2" ] ||
3212 error "write to enc file fell back to buffered IO"
3216 dd if=$testfile of=$resfile bs=$pagesz count=2 iflag=direct ||
3217 error "could not read from file with O_DIRECT (1)"
3219 respage=$(vmtouch $testfile | awk '/Resident Pages:/ {print $3}')
3220 [ "$respage" == "0/2" ] ||
3221 error "read from enc file fell back to buffered IO"
3223 cmp -bl $tmpfile $resfile ||
3224 error "file $testfile is corrupted (1)"
3228 $TRUNCATE $tmpfile $pagesz
3229 dd if=$tmpfile of=$testfile bs=$pagesz count=1 seek=13 oflag=direct ||
3230 error "could not write to file with O_DIRECT (2)"
3234 dd if=$testfile of=$resfile bs=$pagesz count=1 skip=13 iflag=direct ||
3235 error "could not read from file with O_DIRECT (2)"
3236 cmp -bl $tmpfile $resfile ||
3237 error "file $testfile is corrupted (2)"
3239 rm -f $testfile $resfile
3240 $LFS setstripe -c1 -i0 $testfile
3242 $TRUNCATE $tmpfile $((pagesz/2 - 5))
3243 cp $tmpfile $testfile
3247 dd if=$testfile of=$resfile bs=$pagesz count=1 iflag=direct ||
3248 error "could not read from file with O_DIRECT (3)"
3249 cmp -bl $tmpfile $resfile ||
3250 error "file $testfile is corrupted (3)"
3252 rm -f $tmpfile $resfile
3254 run_test 44 "encrypted file access semantics: direct IO"
3257 local testfile=$DIR/$tdir/$tfile
3258 local tmpfile=$TMP/junk
3260 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3261 skip "client encryption not supported"
3263 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3264 skip "need dummy encryption support"
3266 stack_trap cleanup_for_enc_tests EXIT
3269 $LFS setstripe -c1 -i0 $testfile
3270 dd if=/dev/zero of=$testfile bs=512K count=1
3271 $MULTIOP $testfile OSMRUc || error "$MULTIOP $testfile failed (1)"
3272 $MULTIOP $testfile OSMWUc || error "$MULTIOP $testfile failed (2)"
3274 dd if=/dev/zero of=$tmpfile bs=512K count=1
3275 $MULTIOP $tmpfile OSMWUc || error "$MULTIOP $tmpfile failed"
3276 $MMAP_CAT $tmpfile > ${tmpfile}2
3280 $MULTIOP $testfile OSMRUc
3281 $MMAP_CAT $testfile > ${testfile}2
3282 cmp -bl ${tmpfile}2 ${testfile}2 ||
3283 error "file $testfile is corrupted"
3285 rm -f $tmpfile ${tmpfile}2
3287 run_test 45 "encrypted file access semantics: MMAP"
3290 local testdir=$DIR/$tdir/mydir
3291 local testfile=$testdir/myfile
3292 local testdir2=$DIR/$tdir/mydirwithaveryverylongnametotestcodebehaviour0
3293 local testfile2=$testdir/myfilewithaveryverylongnametotestcodebehaviour0
3294 local lsfile=$TMP/lsfile
3298 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3299 skip "client encryption not supported"
3301 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3302 skip "need dummy encryption support"
3304 stack_trap cleanup_for_enc_tests EXIT
3307 touch $DIR/$tdir/$tfile
3309 echo test > $testfile
3310 echo othertest > $testfile2
3311 if [[ $MDSCOUNT -gt 1 ]]; then
3312 $LFS setdirstripe -c1 -i1 $testdir2
3316 sync ; echo 3 > /proc/sys/vm/drop_caches
3318 # remove fscrypt key from keyring
3319 keyctl revoke $(keyctl show | awk '$7 ~ "^fscrypt:" {print $1}')
3324 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d| grep _)
3325 stat $scrambleddir || error "stat $scrambleddir failed"
3326 rmdir $scrambleddir || error "rmdir $scrambleddir failed"
3328 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d)
3329 ls -1 $scrambleddir > $lsfile || error "ls $testdir failed (1)"
3331 scrambledfile=$scrambleddir/$(head -n 1 $lsfile)
3332 stat $scrambledfile || error "stat $scrambledfile failed (1)"
3335 cat $scrambledfile && error "cat $scrambledfile should have failed (1)"
3336 rm -f $scrambledfile || error "rm $scrambledfile failed (1)"
3338 ls -1 $scrambleddir > $lsfile || error "ls $testdir failed (2)"
3339 scrambledfile=$scrambleddir/$(head -n 1 $lsfile)
3340 stat $scrambledfile || error "stat $scrambledfile failed (2)"
3342 cat $scrambledfile && error "cat $scrambledfile should have failed (2)"
3344 touch $scrambleddir/otherfile &&
3345 error "touch otherfile should have failed"
3346 ls $scrambleddir/otherfile && error "otherfile should not exist"
3347 mkdir $scrambleddir/otherdir &&
3348 error "mkdir otherdir should have failed"
3349 ls -d $scrambleddir/otherdir && error "otherdir should not exist"
3352 rm -f $scrambledfile || error "rm $scrambledfile failed (2)"
3353 rmdir $scrambleddir || error "rmdir $scrambleddir failed"
3356 run_test 46 "encrypted file access semantics without key"
3359 local testfile=$DIR/$tdir/$tfile
3360 local testfile2=$DIR/$tdir/${tfile}.2
3361 local tmpfile=$DIR/junk
3365 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3366 skip "client encryption not supported"
3368 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3369 skip "need dummy encryption support"
3371 stack_trap cleanup_for_enc_tests EXIT
3374 dd if=/dev/urandom of=$tmpfile bs=512K count=1
3375 mrename $tmpfile $testfile &&
3376 error "rename from unencrypted to encrypted dir should fail"
3378 ln $tmpfile $testfile &&
3379 error "link from encrypted to unencrypted dir should fail"
3381 cp $tmpfile $testfile ||
3382 error "cp from unencrypted to encrypted dir should succeed"
3385 mrename $testfile $testfile2 ||
3386 error "rename from within encrypted dir should succeed"
3388 ln $testfile2 $testfile ||
3389 error "link from within encrypted dir should succeed"
3390 cmp -bl $testfile2 $testfile ||
3391 error "cannot read from hard link (1.1)"
3392 echo a >> $testfile || error "cannot write to hard link (1)"
3394 cmp -bl $testfile2 $testfile ||
3395 error "cannot read from hard link (1.2)"
3398 ln $testfile2 $tmpfile ||
3399 error "link from unencrypted to encrypted dir should succeed"
3401 cmp -bl $testfile2 $tmpfile ||
3402 error "cannot read from hard link (2.1)"
3403 echo a >> $tmpfile || error "cannot write to hard link (2)"
3405 cmp -bl $testfile2 $tmpfile ||
3406 error "cannot read from hard link (2.2)"
3409 # check we are limited in the number of hard links
3410 # we can create for encrypted files, to what can fit into LinkEA
3411 for i in $(seq 1 160); do
3412 ln $testfile2 ${testfile}_$i || break
3414 [ $i -lt 160 ] || error "hard link $i should fail"
3417 mrename $testfile2 $tmpfile &&
3418 error "rename from encrypted to unencrypted dir should fail"
3420 dd if=/dev/urandom of=$tmpfile bs=512K count=1
3422 dd if=/dev/urandom of=$testfile bs=512K count=1
3423 mkdir $DIR/$tdir/mydir
3425 ln -s $testfile ${testfile}.sym ||
3426 error "symlink from within encrypted dir should succeed"
3428 cmp -bl $testfile ${testfile}.sym ||
3429 error "cannot read from sym link (1.1)"
3430 echo a >> ${testfile}.sym || error "cannot write to sym link (1)"
3432 cmp -bl $testfile ${testfile}.sym ||
3433 error "cannot read from sym link (1.2)"
3434 [ $(stat -c %s ${testfile}.sym) -eq ${#testfile} ] ||
3435 error "wrong symlink size (1)"
3437 ln -s $tmpfile ${testfile}.sl ||
3438 error "symlink from encrypted to unencrypted dir should succeed"
3440 cmp -bl $tmpfile ${testfile}.sl ||
3441 error "cannot read from sym link (2.1)"
3442 echo a >> ${testfile}.sl || error "cannot write to sym link (2)"
3444 cmp -bl $tmpfile ${testfile}.sl ||
3445 error "cannot read from sym link (2.2)"
3446 [ $(stat -c %s ${testfile}.sl) -eq ${#tmpfile} ] ||
3447 error "wrong symlink size (2)"
3448 rm -f ${testfile}.sl
3450 sync ; echo 3 > /proc/sys/vm/drop_caches
3452 # remove fscrypt key from keyring
3453 keyctl revoke $(keyctl show | awk '$7 ~ "^fscrypt:" {print $1}')
3457 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d)
3458 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -type f)
3459 scrambledlink=$(find $DIR/$tdir/ -maxdepth 1 -type l)
3460 ln $scrambledfile $scrambleddir/linkfile &&
3461 error "ln linkfile should have failed"
3462 mrename $scrambledfile $DIR/onefile2 &&
3463 error "mrename from $scrambledfile should have failed"
3465 mrename $DIR/onefile $scrambleddir/otherfile &&
3466 error "mrename to $scrambleddir should have failed"
3467 readlink $scrambledlink ||
3468 error "link should be read without key"
3469 [ $(stat -c %s $scrambledlink) -eq \
3470 $(expr length "$(readlink $scrambledlink)") ] ||
3471 error "wrong symlink size without key"
3472 readlink -e $scrambledlink &&
3473 error "link should not point to anywhere useful"
3474 ln -s $scrambledfile ${scrambledfile}.sym &&
3475 error "symlink without key should fail (1)"
3476 ln -s $tmpfile ${scrambledfile}.sl &&
3477 error "symlink without key should fail (2)"
3479 rm -f $tmpfile $DIR/onefile
3481 run_test 47 "encrypted file access semantics: rename/link"
3484 local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
3485 local testfile=$DIR/$tdir/$tfile
3486 local tmpfile=$TMP/111
3487 local tmpfile2=$TMP/abc
3488 local pagesz=$(getconf PAGESIZE)
3493 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3494 skip "client encryption not supported"
3496 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3497 skip "need dummy encryption support"
3499 stack_trap cleanup_for_enc_tests EXIT
3502 # create file, 4 x PAGE_SIZE long
3503 tr '\0' '1' < /dev/zero |
3504 dd of=$tmpfile bs=1 count=4x$pagesz conv=fsync
3505 $LFS setstripe -c1 -i0 $testfile
3506 cp $tmpfile $testfile
3507 echo "abc" > $tmpfile2
3509 # decrease size: truncate to PAGE_SIZE
3510 $TRUNCATE $tmpfile $pagesz
3511 $TRUNCATE $testfile $pagesz
3512 cancel_lru_locks osc ; cancel_lru_locks mdc
3513 cmp -bl $tmpfile $testfile ||
3514 error "file $testfile is corrupted (1)"
3516 # increase size: truncate to 2 x PAGE_SIZE
3518 $TRUNCATE $tmpfile $sz
3519 $TRUNCATE $testfile $sz
3520 cancel_lru_locks osc ; cancel_lru_locks mdc
3521 cmp -bl $tmpfile $testfile ||
3522 error "file $testfile is corrupted (2)"
3525 seek=$((pagesz+100))
3526 dd if=$tmpfile2 of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3528 dd if=$tmpfile2 of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3530 cancel_lru_locks osc ; cancel_lru_locks mdc
3531 cmp -bl $tmpfile $testfile ||
3532 error "file $testfile is corrupted (3)"
3534 # truncate to PAGE_SIZE / 2
3536 $TRUNCATE $tmpfile $sz
3537 $TRUNCATE $testfile $sz
3538 cancel_lru_locks osc ; cancel_lru_locks mdc
3539 cmp -bl $tmpfile $testfile ||
3540 error "file $testfile is corrupted (4)"
3542 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16
3544 $TRUNCATE $tmpfile $sz
3545 $TRUNCATE $testfile $sz
3546 cancel_lru_locks osc ; cancel_lru_locks mdc
3547 cmp -bl $tmpfile $testfile ||
3548 error "file $testfile is corrupted (5)"
3550 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16
3552 $TRUNCATE $tmpfile $sz
3553 $TRUNCATE $testfile $sz
3554 cancel_lru_locks osc ; cancel_lru_locks mdc
3555 cmp -bl $tmpfile $testfile ||
3556 error "file $testfile is corrupted (6)"
3558 # truncate to a larger, non-multiple of PAGE_SIZE, in a different page
3559 sz=$((sz+pagesz+30))
3560 $TRUNCATE $tmpfile $sz
3561 $TRUNCATE $testfile $sz
3562 cancel_lru_locks osc ; cancel_lru_locks mdc
3563 cmp -bl $tmpfile $testfile ||
3564 error "file $testfile is corrupted (7)"
3566 sync ; echo 3 > /proc/sys/vm/drop_caches
3568 # remove fscrypt key from keyring
3569 keyctl revoke $(keyctl show | awk '$7 ~ "^fscrypt:" {print $1}')
3572 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -type f)
3573 $TRUNCATE $scrambledfile 0 &&
3574 error "truncate $scrambledfile should have failed without key"
3576 rm -f $tmpfile $tmpfile2
3578 run_test 48a "encrypted file access semantics: truncate"
3580 cleanup_for_enc_tests_othercli() {
3583 # remount othercli normally
3584 zconf_umount $othercli $MOUNT ||
3585 error "umount $othercli $MOUNT failed"
3586 zconf_mount $othercli $MOUNT ||
3587 error "remount $othercli $MOUNT failed"
3593 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3594 skip "client encryption not supported"
3596 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3597 skip "need dummy encryption support"
3599 [ "$num_clients" -ge 2 ] || skip "Need at least 2 clients"
3601 if [ "$HOSTNAME" == ${clients_arr[0]} ]; then
3602 othercli=${clients_arr[1]}
3604 othercli=${clients_arr[0]}
3607 stack_trap cleanup_for_enc_tests EXIT
3608 stack_trap "cleanup_for_enc_tests_othercli $othercli" EXIT
3610 zconf_umount $othercli $MOUNT ||
3611 error "umount $othercli $MOUNT failed"
3613 cp /bin/sleep $DIR/$tdir/
3614 cancel_lru_locks osc ; cancel_lru_locks mdc
3615 $DIR/$tdir/sleep 30 &
3616 # mount and IOs must be done in the same shell session, otherwise
3617 # encryption key in session keyring is missing
3618 do_node $othercli "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
3619 $MGSNID:/$FSNAME $MOUNT && \
3620 $TRUNCATE $DIR/$tdir/sleep 7"
3621 wait || error "wait error"
3622 cmp --silent /bin/sleep $DIR/$tdir/sleep ||
3623 error "/bin/sleep and $DIR/$tdir/sleep differ"
3625 run_test 48b "encrypted file: concurrent truncate"
3631 $LCTL set_param debug=+info
3636 [ $? -eq 0 ] || error "$cmd failed"
3638 if [ -z "$MATCHING_STRING" ]; then
3639 $LCTL dk | grep -E "get xattr 'security.c'|get xattrs"
3641 $LCTL dk | grep -E "$MATCHING_STRING"
3643 [ $? -ne 0 ] || error "get xattr event was triggered"
3647 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3648 skip "client encryption not supported"
3650 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3651 skip "need dummy encryption support"
3653 stack_trap cleanup_for_enc_tests EXIT
3656 local dirname=$DIR/$tdir/subdir
3660 trace_cmd stat $dirname
3661 trace_cmd touch $dirname/f1
3662 trace_cmd stat $dirname/f1
3663 trace_cmd cat $dirname/f1
3664 dd if=/dev/zero of=$dirname/f1 bs=1M count=10 conv=fsync
3665 MATCHING_STRING="get xattr 'security.c'" \
3666 trace_cmd $TRUNCATE $dirname/f1 10240
3667 trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
3668 trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
3670 if [[ $MDSCOUNT -gt 1 ]]; then
3671 trace_cmd $LFS setdirstripe -i 1 $dirname/d2
3672 trace_cmd $LFS migrate -m 0 $dirname/d2
3673 touch $dirname/d2/subf
3674 # migrate a non-empty encrypted dir
3675 trace_cmd $LFS migrate -m 1 $dirname/d2
3677 $LFS setdirstripe -i 1 -c 1 $dirname/d3
3678 dirname=$dirname/d3/subdir
3681 trace_cmd stat $dirname
3682 trace_cmd touch $dirname/f1
3683 trace_cmd stat $dirname/f1
3684 trace_cmd cat $dirname/f1
3685 dd if=/dev/zero of=$dirname/f1 bs=1M count=10 conv=fsync
3686 MATCHING_STRING="get xattr 'security.c'" \
3687 trace_cmd $TRUNCATE $dirname/f1 10240
3688 trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
3689 trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
3691 skip_noexit "2nd part needs >= 2 MDTs"
3694 run_test 49 "Avoid getxattr for encryption context"
3697 local testfile=$DIR/$tdir/$tfile
3698 local tmpfile=$TMP/abc
3699 local pagesz=$(getconf PAGESIZE)
3702 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3703 skip "client encryption not supported"
3705 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3706 skip "need dummy encryption support"
3708 stack_trap cleanup_for_enc_tests EXIT
3711 # write small file, data on MDT only
3712 tr '\0' '1' < /dev/zero |
3713 dd of=$tmpfile bs=1 count=5000 conv=fsync
3714 $LFS setstripe -E 1M -L mdt -E EOF $testfile
3715 cp $tmpfile $testfile
3717 # check that in-memory representation of file is correct
3718 cmp -bl $tmpfile $testfile ||
3719 error "file $testfile is corrupted in memory"
3721 cancel_lru_locks osc ; cancel_lru_locks mdc
3723 # check that file read from server is correct
3724 cmp -bl $tmpfile $testfile ||
3725 error "file $testfile is corrupted on server"
3727 # decrease size: truncate to PAGE_SIZE
3728 $TRUNCATE $tmpfile $pagesz
3729 $TRUNCATE $testfile $pagesz
3730 cancel_lru_locks osc ; cancel_lru_locks mdc
3731 cmp -bl $tmpfile $testfile ||
3732 error "file $testfile is corrupted (1)"
3734 # increase size: truncate to 2 x PAGE_SIZE
3736 $TRUNCATE $tmpfile $sz
3737 $TRUNCATE $testfile $sz
3738 cancel_lru_locks osc ; cancel_lru_locks mdc
3739 cmp -bl $tmpfile $testfile ||
3740 error "file $testfile is corrupted (2)"
3742 # truncate to PAGE_SIZE / 2
3744 $TRUNCATE $tmpfile $sz
3745 $TRUNCATE $testfile $sz
3746 cancel_lru_locks osc ; cancel_lru_locks mdc
3747 cmp -bl $tmpfile $testfile ||
3748 error "file $testfile is corrupted (3)"
3750 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16
3752 $TRUNCATE $tmpfile $sz
3753 $TRUNCATE $testfile $sz
3754 cancel_lru_locks osc ; cancel_lru_locks mdc
3755 cmp -bl $tmpfile $testfile ||
3756 error "file $testfile is corrupted (4)"
3758 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16
3760 $TRUNCATE $tmpfile $sz
3761 $TRUNCATE $testfile $sz
3762 cancel_lru_locks osc ; cancel_lru_locks mdc
3763 cmp -bl $tmpfile $testfile ||
3764 error "file $testfile is corrupted (5)"
3766 # truncate to a larger, non-multiple of PAGE_SIZE, in a different page
3767 sz=$((sz+pagesz+30))
3768 $TRUNCATE $tmpfile $sz
3769 $TRUNCATE $testfile $sz
3770 cancel_lru_locks osc ; cancel_lru_locks mdc
3771 cmp -bl $tmpfile $testfile ||
3772 error "file $testfile is corrupted (6)"
3775 cancel_lru_locks osc ; cancel_lru_locks mdc
3777 # write hole in file, data spread on MDT and OST
3778 tr '\0' '2' < /dev/zero |
3779 dd of=$tmpfile bs=1 count=1539 seek=1539074 conv=fsync,notrunc
3780 $LFS setstripe -E 1M -L mdt -E EOF $testfile
3781 cp --sparse=always $tmpfile $testfile
3783 # check that in-memory representation of file is correct
3784 cmp -bl $tmpfile $testfile ||
3785 error "file $testfile is corrupted in memory"
3787 cancel_lru_locks osc ; cancel_lru_locks mdc
3789 # check that file read from server is correct
3790 cmp -bl $tmpfile $testfile ||
3791 error "file $testfile is corrupted on server"
3793 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16,
3794 # inside OST part of data
3795 sz=$((1024*1024+13))
3796 $TRUNCATE $tmpfile $sz
3797 $TRUNCATE $testfile $sz
3798 cancel_lru_locks osc ; cancel_lru_locks mdc
3799 cmp -bl $tmpfile $testfile ||
3800 error "file $testfile is corrupted (7)"
3802 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16,
3803 # inside MDT part of data
3805 $TRUNCATE $tmpfile $sz
3806 $TRUNCATE $testfile $sz
3807 cancel_lru_locks osc ; cancel_lru_locks mdc
3808 cmp -bl $tmpfile $testfile ||
3809 error "file $testfile is corrupted (8)"
3811 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16,
3812 # inside MDT part of data
3813 sz=$((1024*1024-13))
3814 $TRUNCATE $tmpfile $sz
3815 $TRUNCATE $testfile $sz
3816 cancel_lru_locks osc ; cancel_lru_locks mdc
3817 cmp -bl $tmpfile $testfile ||
3818 error "file $testfile is corrupted (9)"
3820 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16,
3821 # inside OST part of data
3823 $TRUNCATE $tmpfile $sz
3824 $TRUNCATE $testfile $sz
3825 cancel_lru_locks osc ; cancel_lru_locks mdc
3826 cmp -bl $tmpfile $testfile ||
3827 error "file $testfile is corrupted (10)"
3831 run_test 50 "DoM encrypted file"
3834 [ "$MDS1_VERSION" -gt $(version_code 2.13.53) ] ||
3835 skip "Need MDS version at least 2.13.53"
3837 mkdir $DIR/$tdir || error "mkdir $tdir"
3839 touch $DIR/$tdir/$tfile || error "touch $tfile"
3840 cp $(which chown) $DIR/$tdir || error "cp chown"
3841 $RUNAS_CMD -u $ID0 $DIR/$tdir/chown $ID0 $DIR/$tdir/$tfile &&
3842 error "chown $tfile should fail"
3843 setcap 'CAP_CHOWN=ep' $DIR/$tdir/chown || error "setcap CAP_CHOWN"
3844 $RUNAS_CMD -u $ID0 $DIR/$tdir/chown $ID0 $DIR/$tdir/$tfile ||
3845 error "chown $tfile"
3846 rm $DIR/$tdir/$tfile || error "rm $tfile"
3848 touch $DIR/$tdir/$tfile || error "touch $tfile"
3849 cp $(which touch) $DIR/$tdir || error "cp touch"
3850 $RUNAS_CMD -u $ID0 $DIR/$tdir/touch $DIR/$tdir/$tfile &&
3851 error "touch should fail"
3852 setcap 'CAP_FOWNER=ep' $DIR/$tdir/touch || error "setcap CAP_FOWNER"
3853 $RUNAS_CMD -u $ID0 $DIR/$tdir/touch $DIR/$tdir/$tfile ||
3854 error "touch $tfile"
3855 rm $DIR/$tdir/$tfile || error "rm $tfile"
3858 for cap in "CAP_DAC_OVERRIDE" "CAP_DAC_READ_SEARCH"; do
3859 touch $DIR/$tdir/$tfile || error "touch $tfile"
3860 chmod 600 $DIR/$tdir/$tfile || error "chmod $tfile"
3861 cp $(which cat) $DIR/$tdir || error "cp cat"
3862 $RUNAS_CMD -u $ID0 $DIR/$tdir/cat $DIR/$tdir/$tfile &&
3863 error "cat should fail"
3864 setcap $cap=ep $DIR/$tdir/cat || error "setcap $cap"
3865 $RUNAS_CMD -u $ID0 $DIR/$tdir/cat $DIR/$tdir/$tfile ||
3867 rm $DIR/$tdir/$tfile || error "rm $tfile"
3870 run_test 51 "FS capabilities ==============="
3873 local testfile=$DIR/$tdir/$tfile
3874 local tmpfile=$TMP/$tfile
3875 local mirror1=$TMP/$tfile.mirror1
3876 local mirror2=$TMP/$tfile.mirror2
3878 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3879 skip "client encryption not supported"
3881 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3882 skip "need dummy encryption support"
3884 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
3886 stack_trap cleanup_for_enc_tests EXIT
3889 dd if=/dev/urandom of=$tmpfile bs=5000 count=1 conv=fsync
3891 $LFS mirror create -N -i0 -N -i1 $testfile ||
3892 error "could not create mirror"
3894 dd if=$tmpfile of=$testfile bs=5000 count=1 conv=fsync ||
3895 error "could not write to $testfile"
3897 $LFS mirror resync $testfile ||
3898 error "could not resync mirror"
3900 $LFS mirror verify -v $testfile ||
3901 error "verify mirror failed"
3903 $LFS mirror read -N 1 -o $mirror1 $testfile ||
3904 error "could not read from mirror 1"
3906 cmp -bl $tmpfile $mirror1 ||
3907 error "mirror 1 is corrupted"
3909 $LFS mirror read -N 2 -o $mirror2 $testfile ||
3910 error "could not read from mirror 2"
3912 cmp -bl $tmpfile $mirror2 ||
3913 error "mirror 2 is corrupted"
3915 tr '\0' '2' < /dev/zero |
3916 dd of=$tmpfile bs=1 count=9000 conv=fsync
3918 $LFS mirror write -N 1 -i $tmpfile $testfile ||
3919 error "could not write to mirror 1"
3921 $LFS mirror verify -v $testfile &&
3922 error "mirrors should be different"
3924 rm -f $testfile $mirror1 $mirror2
3926 $LFS setstripe -c1 -i0 $testfile
3927 dd if=$tmpfile of=$testfile bs=9000 count=1 conv=fsync ||
3928 error "write to $testfile failed"
3929 $LFS getstripe $testfile
3932 $LFS migrate -i1 $testfile ||
3933 error "migrate $testfile failed"
3934 $LFS getstripe $testfile
3935 stripe=$($LFS getstripe -i $testfile)
3936 [ $stripe -eq 1 ] || error "migrate file $testfile failed"
3939 cmp -bl $tmpfile $testfile ||
3940 error "migrated file is corrupted"
3942 $LFS mirror extend -N -i0 $testfile ||
3943 error "mirror extend $testfile failed"
3944 $LFS getstripe $testfile
3945 mirror_count=$($LFS getstripe -N $testfile)
3946 [ $mirror_count -eq 2 ] ||
3947 error "mirror extend file $testfile failed (1)"
3948 stripe=$($LFS getstripe --mirror-id=1 -i $testfile)
3949 [ $stripe -eq 1 ] || error "mirror extend file $testfile failed (2)"
3950 stripe=$($LFS getstripe --mirror-id=2 -i $testfile)
3951 [ $stripe -eq 0 ] || error "mirror extend file $testfile failed (3)"
3954 $LFS mirror verify -v $testfile ||
3955 error "mirror verify failed"
3956 $LFS mirror read -N 1 -o $mirror1 $testfile ||
3957 error "read from mirror 1 failed"
3958 cmp -bl $tmpfile $mirror1 ||
3959 error "corruption of mirror 1"
3960 $LFS mirror read -N 2 -o $mirror2 $testfile ||
3961 error "read from mirror 2 failed"
3962 cmp -bl $tmpfile $mirror2 ||
3963 error "corruption of mirror 2"
3965 $LFS mirror split --mirror-id 1 -f ${testfile}.mirror $testfile &&
3966 error "mirror split -f should fail"
3968 $LFS mirror split --mirror-id 1 $testfile &&
3969 error "mirror split without -d should fail"
3971 $LFS mirror split --mirror-id 1 -d $testfile ||
3972 error "mirror split failed"
3973 $LFS getstripe $testfile
3974 mirror_count=$($LFS getstripe -N $testfile)
3975 [ $mirror_count -eq 1 ] ||
3976 error "mirror split file $testfile failed (1)"
3977 stripe=$($LFS getstripe --mirror-id=1 -i $testfile)
3978 [ -z "$stripe" ] || error "mirror extend file $testfile failed (2)"
3979 stripe=$($LFS getstripe --mirror-id=2 -i $testfile)
3980 [ $stripe -eq 0 ] || error "mirror extend file $testfile failed (3)"
3983 cmp -bl $tmpfile $testfile ||
3984 error "extended/split file is corrupted"
3986 rm -f $tmpfile $mirror1 $mirror2
3988 run_test 52 "Mirrored encrypted file"
3991 local testfile=$DIR/$tdir/$tfile
3992 local testfile2=$DIR2/$tdir/$tfile
3993 local tmpfile=$TMP/$tfile.tmp
3994 local resfile=$TMP/$tfile.res
3998 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3999 skip "client encryption not supported"
4001 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4002 skip "need dummy encryption support"
4004 pagesz=$(getconf PAGESIZE)
4005 [[ $pagesz == 65536 ]] || skip "Need 64K PAGE_SIZE client"
4007 do_node $mds1_HOST \
4008 "mount.lustre --help |& grep -q 'test_dummy_encryption:'" ||
4009 skip "need dummy encryption support on MDS client mount"
4011 # this test is probably useless now, but may turn out to be useful when
4012 # Lustre supports servers with PAGE_SIZE != 4KB
4013 pagesz=$(do_node $mds1_HOST getconf PAGESIZE)
4014 [[ $pagesz == 4096 ]] || skip "Need 4K PAGE_SIZE MDS client"
4016 stack_trap cleanup_for_enc_tests EXIT
4017 stack_trap "zconf_umount $mds1_HOST $MOUNT2" EXIT
4020 $LFS setstripe -c1 -i0 $testfile
4022 # write from 1st client
4023 cat /dev/urandom | tr -dc 'a-zA-Z0-9' |
4024 dd of=$tmpfile bs=$((pagesz+3)) count=2 conv=fsync
4025 dd if=$tmpfile of=$testfile bs=$((pagesz+3)) count=2 conv=fsync ||
4026 error "could not write to $testfile (1)"
4028 # read from 2nd client
4029 # mount and IOs must be done in the same shell session, otherwise
4030 # encryption key in session keyring is missing
4031 do_node $mds1_HOST "mkdir -p $MOUNT2"
4032 do_node $mds1_HOST \
4033 "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4034 $MGSNID:/$FSNAME $MOUNT2 && \
4035 dd if=$testfile2 of=$resfile bs=$((pagesz+3)) count=2" ||
4036 error "could not read from $testfile2 (1)"
4039 filemd5=$(do_node $mds1_HOST md5sum $resfile | awk '{print $1}')
4040 [ $filemd5 = $(md5sum $tmpfile | awk '{print $1}') ] ||
4041 error "file is corrupted (1)"
4042 do_node $mds1_HOST rm -f $resfile
4045 # truncate from 2nd client
4046 $TRUNCATE $tmpfile $((pagesz+3))
4047 zconf_umount $mds1_HOST $MOUNT2 ||
4048 error "umount $mds1_HOST $MOUNT2 failed (1)"
4049 do_node $mds1_HOST "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4050 $MGSNID:/$FSNAME $MOUNT2 && \
4051 $TRUNCATE $testfile2 $((pagesz+3))" ||
4052 error "could not truncate $testfile2 (1)"
4055 cmp -bl $tmpfile $testfile ||
4056 error "file is corrupted (2)"
4057 rm -f $tmpfile $testfile
4059 zconf_umount $mds1_HOST $MOUNT2 ||
4060 error "umount $mds1_HOST $MOUNT2 failed (2)"
4063 do_node $mds1_HOST \
4064 dd if=/dev/urandom of=$tmpfile bs=$((pagesz+3)) count=2 conv=fsync
4065 # write from 2nd client
4066 do_node $mds1_HOST \
4067 "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4068 $MGSNID:/$FSNAME $MOUNT2 && \
4069 dd if=$tmpfile of=$testfile2 bs=$((pagesz+3)) count=2 conv=fsync" ||
4070 error "could not write to $testfile2 (2)"
4072 # read from 1st client
4073 dd if=$testfile of=$resfile bs=$((pagesz+3)) count=2 ||
4074 error "could not read from $testfile (2)"
4077 filemd5=$(do_node $mds1_HOST md5sum -b $tmpfile | awk '{print $1}')
4078 [ $filemd5 = $(md5sum -b $resfile | awk '{print $1}') ] ||
4079 error "file is corrupted (3)"
4083 # truncate from 1st client
4084 do_node $mds1_HOST "$TRUNCATE $tmpfile $((pagesz+3))"
4085 $TRUNCATE $testfile $((pagesz+3)) ||
4086 error "could not truncate $testfile (2)"
4089 zconf_umount $mds1_HOST $MOUNT2 ||
4090 error "umount $mds1_HOST $MOUNT2 failed (3)"
4091 do_node $mds1_HOST "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4092 $MGSNID:/$FSNAME $MOUNT2 && \
4093 cmp -bl $tmpfile $testfile2" ||
4094 error "file is corrupted (4)"
4096 do_node $mds1_HOST rm -f $tmpfile
4099 run_test 53 "Mixed PAGE_SIZE clients"
4102 local testdir=$DIR/$tdir/$ID0
4103 local testfile=$testdir/$tfile
4104 local testfile2=$testdir/${tfile}withveryverylongnametoexercisecode
4105 local tmpfile=$TMP/${tfile}.tmp
4106 local resfile=$TMP/${tfile}.res
4108 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4109 skip "client encryption not supported"
4111 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4112 skip "need dummy encryption support"
4114 which fscrypt || skip "This test needs fscrypt userspace tool"
4116 fscrypt setup --force --verbose || error "fscrypt global setup failed"
4117 sed -i 's/\(.*\)policy_version\(.*\):\(.*\)\"[0-9]*\"\(.*\)/\1policy_version\2:\3"2"\4/' \
4119 fscrypt setup --verbose $MOUNT || error "fscrypt setup $MOUNT failed"
4121 chown -R $ID0:$ID0 $testdir
4123 echo -e 'mypass\nmypass' | su - $USER0 -c "fscrypt encrypt --verbose \
4124 --source=custom_passphrase --name=protector $testdir" ||
4125 error "fscrypt encrypt failed"
4127 echo -e 'mypass\nmypass' | su - $USER0 -c "fscrypt encrypt --verbose \
4128 --source=custom_passphrase --name=protector2 $testdir" &&
4129 error "second fscrypt encrypt should have failed"
4131 mkdir -p ${testdir}2 || error "mkdir ${testdir}2 failed"
4132 touch ${testdir}2/f || error "mkdir ${testdir}2/f failed"
4135 echo -e 'mypass\nmypass' | fscrypt encrypt --verbose \
4136 --source=custom_passphrase --name=protector3 ${testdir}2 &&
4137 error "fscrypt encrypt on non-empty dir should have failed"
4139 $RUNAS dd if=/dev/urandom of=$testfile bs=127 count=1 conv=fsync ||
4140 error "write to encrypted file $testfile failed"
4141 cp $testfile $tmpfile
4142 $RUNAS dd if=/dev/urandom of=$testfile2 bs=127 count=1 conv=fsync ||
4143 error "write to encrypted file $testfile2 failed"
4144 $RUNAS mkdir $testdir/subdir || error "mkdir subdir failed"
4145 $RUNAS touch $testdir/subdir/subfile || error "mkdir subdir failed"
4147 $RUNAS fscrypt lock --verbose $testdir ||
4148 error "fscrypt lock $testdir failed (1)"
4150 $RUNAS ls -R $testdir || error "ls -R $testdir failed"
4151 local filecount=$($RUNAS find $testdir -type f | wc -l)
4152 [ $filecount -eq 3 ] || error "found $filecount files"
4154 scrambledfiles=( $(find $testdir/ -maxdepth 1 -type f) )
4155 $RUNAS hexdump -C ${scrambledfiles[0]} &&
4156 error "reading ${scrambledfiles[0]} should fail without key"
4158 $RUNAS touch ${testfile}.nokey &&
4159 error "touch ${testfile}.nokey should have failed without key"
4161 echo mypass | $RUNAS fscrypt unlock --verbose $testdir ||
4162 error "fscrypt unlock $testdir failed (1)"
4164 $RUNAS cat $testfile > $resfile ||
4165 error "reading $testfile failed"
4167 cmp -bl $tmpfile $resfile || error "file read differs from file written"
4169 $RUNAS fscrypt lock --verbose $testdir ||
4170 error "fscrypt lock $testdir failed (2)"
4172 $RUNAS hexdump -C ${scrambledfiles[1]} &&
4173 error "reading ${scrambledfiles[1]} should fail without key"
4175 echo mypass | $RUNAS fscrypt unlock --verbose $testdir ||
4176 error "fscrypt unlock $testdir failed (2)"
4179 $RUNAS fscrypt lock --verbose $testdir ||
4180 error "fscrypt lock $testdir failed (3)"
4182 rm -f $tmpfile $resfile
4184 run_test 54 "Encryption policies with fscrypt"
4188 if is_mounted $MOUNT; then
4189 umount_client $MOUNT || error "umount $MOUNT failed"
4192 do_facet mgs $LCTL nodemap_del c0
4193 do_facet mgs $LCTL nodemap_modify --name default \
4194 --property admin --value 0
4195 do_facet mgs $LCTL nodemap_modify --name default \
4196 --property trusted --value 0
4197 wait_nm_sync default admin_nodemap
4198 wait_nm_sync default trusted_nodemap
4200 do_facet mgs $LCTL nodemap_activate 0
4201 wait_nm_sync active 0
4203 if $SHARED_KEY; then
4204 export SK_UNIQUE_NM=false
4208 mount_client $MOUNT ${MOUNT_OPTS} || error "remount failed"
4209 if [ "$MOUNT_2" ]; then
4210 mount_client $MOUNT2 ${MOUNT_OPTS} || error "remount failed"
4215 (( $MDS1_VERSION > $(version_code 2.12.6.2) )) ||
4216 skip "Need MDS version at least 2.12.6.3"
4221 mkdir -p $DIR/$tdir/$USER0/testdir_groups
4222 chown root:$ID0 $DIR/$tdir/$USER0
4223 chmod 770 $DIR/$tdir/$USER0
4224 chmod g+s $DIR/$tdir/$USER0
4225 chown $ID0:$ID0 $DIR/$tdir/$USER0/testdir_groups
4226 chmod 770 $DIR/$tdir/$USER0/testdir_groups
4227 chmod g+s $DIR/$tdir/$USER0/testdir_groups
4229 # unmount client completely
4230 umount_client $MOUNT || error "umount $MOUNT failed"
4231 if is_mounted $MOUNT2; then
4232 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
4235 do_nodes $(comma_list $(all_mdts_nodes)) \
4236 $LCTL set_param mdt.*.identity_upcall=NONE
4238 stack_trap cleanup_55 EXIT
4240 do_facet mgs $LCTL nodemap_activate 1
4243 do_facet mgs $LCTL nodemap_del c0 || true
4244 wait_nm_sync c0 id ''
4246 do_facet mgs $LCTL nodemap_modify --name default \
4247 --property admin --value 1
4248 do_facet mgs $LCTL nodemap_modify --name default \
4249 --property trusted --value 1
4250 wait_nm_sync default admin_nodemap
4251 wait_nm_sync default trusted_nodemap
4253 client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
4254 client_nid=$(h2nettype $client_ip)
4255 do_facet mgs $LCTL nodemap_add c0
4256 do_facet mgs $LCTL nodemap_add_range \
4257 --name c0 --range $client_nid
4258 do_facet mgs $LCTL nodemap_modify --name c0 \
4259 --property admin --value 0
4260 do_facet mgs $LCTL nodemap_modify --name c0 \
4261 --property trusted --value 1
4262 wait_nm_sync c0 admin_nodemap
4263 wait_nm_sync c0 trusted_nodemap
4265 if $SHARED_KEY; then
4266 export SK_UNIQUE_NM=true
4267 # set some generic fileset to trigger SSK code
4271 # remount client to take nodemap into account
4272 zconf_mount_clients $HOSTNAME $MOUNT $MOUNT_OPTS ||
4273 error "remount failed"
4276 euid_access $USER0 $DIR/$tdir/$USER0/testdir_groups/file
4278 run_test 55 "access with seteuid"
4281 local testfile=$DIR/$tdir/$tfile
4283 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4285 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4286 skip "client encryption not supported"
4288 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4289 skip "need dummy encryption support"
4291 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4293 stack_trap cleanup_for_enc_tests EXIT
4296 $LFS setstripe -c1 $testfile
4297 dd if=/dev/urandom of=$testfile bs=1M count=3 conv=fsync
4298 filefrag -v $testfile || error "filefrag $testfile failed"
4299 (( $(filefrag -v $testfile | grep -c encrypted) >= 1 )) ||
4300 error "filefrag $testfile does not show encrypted flag"
4301 (( $(filefrag -v $testfile | grep -c encoded) >= 1 )) ||
4302 error "filefrag $testfile does not show encoded flag"
4304 run_test 56 "FIEMAP on encrypted file"
4307 local testdir=$DIR/$tdir/mytestdir
4308 local testfile=$DIR/$tdir/$tfile
4310 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4312 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4313 skip "client encryption not supported"
4315 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4316 skip "need dummy encryption support"
4320 setfattr -n security.c -v myval $testdir &&
4321 error "setting xattr on $testdir should have failed (1)"
4323 setfattr -n security.c -v myval $testfile &&
4324 error "setting xattr on $testfile should have failed (1)"
4328 stack_trap cleanup_for_enc_tests EXIT
4332 if [ $(getfattr -n security.c $testdir 2>&1 |
4333 grep -ci "Operation not permitted") -eq 0 ]; then
4334 error "getting xattr on $testdir should have failed"
4336 getfattr -d -m - $testdir 2>&1 | grep security\.c &&
4337 error "listing xattrs on $testdir should not expose security.c"
4338 if [ $(setfattr -n security.c -v myval $testdir 2>&1 |
4339 grep -ci "Operation not permitted") -eq 0 ]; then
4340 error "setting xattr on $testdir should have failed (2)"
4343 if [ $(getfattr -n security.c $testfile 2>&1 |
4344 grep -ci "Operation not permitted") -eq 0 ]; then
4345 error "getting xattr on $testfile should have failed"
4347 getfattr -d -m - $testfile 2>&1 | grep security\.c &&
4348 error "listing xattrs on $testfile should not expose security.c"
4349 if [ $(setfattr -n security.c -v myval $testfile 2>&1 |
4350 grep -ci "Operation not permitted") -eq 0 ]; then
4351 error "setting xattr on $testfile should have failed (2)"
4355 run_test 57 "security.c xattr protection"
4358 local testdir=$DIR/$tdir/mytestdir
4359 local testfile=$DIR/$tdir/$tfile
4361 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4363 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4364 skip "client encryption not supported"
4366 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4367 skip "need dummy encryption support"
4369 stack_trap cleanup_for_enc_tests EXIT
4372 touch $DIR/$tdir/$tfile
4373 mkdir $DIR/$tdir/subdir
4377 echo 3 > /proc/sys/vm/drop_caches
4379 ll_decode_linkea $DIR/$tdir/$tfile || error "cannot read $tfile linkea"
4380 ll_decode_linkea $DIR/$tdir/subdir || error "cannot read subdir linkea"
4382 for ((i = 0; i < 1000; i = $((i+1)))); do
4383 mkdir -p $DIR/$tdir/d${i}
4384 touch $DIR/$tdir/f${i}
4385 createmany -m $DIR/$tdir/d${i}/f 5 > /dev/null
4390 echo 3 > /proc/sys/vm/drop_caches
4393 ls -ailR $MOUNT > /dev/null || error "fail to ls"
4395 run_test 58 "access to enc file's xattrs"
4397 log "cleanup: ======================================================"
4400 for num in $(seq $MDSCOUNT); do
4401 if [ "${identity_old[$num]}" = 1 ]; then
4402 switch_identity $num false || identity_old[$num]=$?
4406 $RUNAS_CMD -u $ID0 ls $DIR
4407 $RUNAS_CMD -u $ID1 ls $DIR
4412 check_and_cleanup_lustre