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"
318 echo "Start to add idmaps ..."
319 for ((i = 0; i < NODEMAP_COUNT; i++)); do
322 for ((j = $ID0; j < NODEMAP_MAX_ID; j++)); do
323 local csum=${HOSTNAME_CHECKSUM}_${i}
325 local fs_id=$((j + 1))
327 if ! do_facet mgs $cmd --name $csum --idtype uid \
328 --idmap $client_id:$fs_id; then
331 if ! do_facet mgs $cmd --name $csum --idtype gid \
332 --idmap $client_id:$fs_id; then
341 update_idmaps() { #LU-10040
342 [ "$MGS_VERSION" -lt $(version_code 2.10.55) ] &&
343 skip "Need MGS >= 2.10.55"
345 local csum=${HOSTNAME_CHECKSUM}_0
346 local old_id_client=$ID0
347 local old_id_fs=$((ID0 + 1))
348 local new_id=$((ID0 + 100))
355 echo "Start to update idmaps ..."
357 #Inserting an existed idmap should return error
358 cmd="$LCTL nodemap_add_idmap --name $csum --idtype uid"
360 $cmd --idmap $old_id_client:$old_id_fs 2>/dev/null; then
361 error "insert idmap {$old_id_client:$old_id_fs} " \
362 "should return error"
367 #Update id_fs and check it
368 if ! do_facet mgs $cmd --idmap $old_id_client:$new_id; then
369 error "$cmd --idmap $old_id_client:$new_id failed"
373 tmp_id=$(do_facet mgs $LCTL get_param -n nodemap.$csum.idmap |
374 awk '{ print $7 }' | sed -n '2p')
375 [ $tmp_id != $new_id ] && { error "new id_fs $tmp_id != $new_id"; \
376 rc=$((rc + 1)); return $rc; }
378 #Update id_client and check it
379 if ! do_facet mgs $cmd --idmap $new_id:$new_id; then
380 error "$cmd --idmap $new_id:$new_id failed"
384 tmp_id=$(do_facet mgs $LCTL get_param -n nodemap.$csum.idmap |
385 awk '{ print $5 }' | sed -n "$((NODEMAP_ID_COUNT + 1)) p")
386 tmp_id=$(echo ${tmp_id%,*}) #e.g. "501,"->"501"
387 [ $tmp_id != $new_id ] && { error "new id_client $tmp_id != $new_id"; \
388 rc=$((rc + 1)); return $rc; }
390 #Delete above updated idmap
391 cmd="$LCTL nodemap_del_idmap --name $csum --idtype uid"
392 if ! do_facet mgs $cmd --idmap $new_id:$new_id; then
393 error "$cmd --idmap $new_id:$new_id failed"
398 #restore the idmaps to make delete_idmaps work well
399 cmd="$LCTL nodemap_add_idmap --name $csum --idtype uid"
400 if ! do_facet mgs $cmd --idmap $old_id_client:$old_id_fs; then
401 error "$cmd --idmap $old_id_client:$old_id_fs failed"
411 local cmd="$LCTL nodemap_del_idmap"
414 echo "Start to delete idmaps ..."
415 for ((i = 0; i < NODEMAP_COUNT; i++)); do
418 for ((j = $ID0; j < NODEMAP_MAX_ID; j++)); do
419 local csum=${HOSTNAME_CHECKSUM}_${i}
421 local fs_id=$((j + 1))
423 if ! do_facet mgs $cmd --name $csum --idtype uid \
424 --idmap $client_id:$fs_id; then
427 if ! do_facet mgs $cmd --name $csum --idtype gid \
428 --idmap $client_id:$fs_id; then
441 local cmd="$LCTL nodemap_modify"
444 proc[0]="admin_nodemap"
445 proc[1]="trusted_nodemap"
449 for ((idx = 0; idx < 2; idx++)); do
450 if ! do_facet mgs $cmd --name $1 --property ${option[$idx]} \
455 if ! do_facet mgs $cmd --name $1 --property ${option[$idx]} \
465 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
466 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
470 cmd[0]="$LCTL nodemap_modify --property squash_uid"
471 cmd[1]="$LCTL nodemap_modify --property squash_gid"
473 if ! do_facet mgs ${cmd[$3]} --name $1 --value $2; then
478 # ensure that the squash defaults are the expected defaults
479 squash_id default 99 0
480 wait_nm_sync default squash_uid '' inactive
481 squash_id default 99 1
482 wait_nm_sync default squash_gid '' inactive
487 cmd="$LCTL nodemap_test_nid"
489 nid=$(do_facet mgs $cmd $1)
491 if [ $nid == $2 ]; then
499 # restore activation state
500 do_facet mgs $LCTL nodemap_activate 0
506 local cmd="$LCTL nodemap_test_id"
509 echo "Start to test idmaps ..."
510 ## nodemap deactivated
511 if ! do_facet mgs $LCTL nodemap_activate 0; then
514 for ((id = $ID0; id < NODEMAP_MAX_ID; id++)); do
517 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
518 local nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
519 local fs_id=$(do_facet mgs $cmd --nid $nid \
520 --idtype uid --id $id)
521 if [ $fs_id != $id ]; then
522 echo "expected $id, got $fs_id"
529 if ! do_facet mgs $LCTL nodemap_activate 1; then
533 for ((id = $ID0; id < NODEMAP_MAX_ID; id++)); do
534 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
535 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
536 fs_id=$(do_facet mgs $cmd --nid $nid \
537 --idtype uid --id $id)
538 expected_id=$((id + 1))
539 if [ $fs_id != $expected_id ]; then
540 echo "expected $expected_id, got $fs_id"
547 for ((i = 0; i < NODEMAP_COUNT; i++)); do
548 local csum=${HOSTNAME_CHECKSUM}_${i}
550 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
551 --property trusted --value 1; then
552 error "nodemap_modify $csum failed with $?"
557 for ((id = $ID0; id < NODEMAP_MAX_ID; id++)); do
558 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
559 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
560 fs_id=$(do_facet mgs $cmd --nid $nid \
561 --idtype uid --id $id)
562 if [ $fs_id != $id ]; then
563 echo "expected $id, got $fs_id"
569 ## ensure allow_root_access is enabled
570 for ((i = 0; i < NODEMAP_COUNT; i++)); do
571 local csum=${HOSTNAME_CHECKSUM}_${i}
573 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
574 --property admin --value 1; then
575 error "nodemap_modify $csum failed with $?"
580 ## check that root allowed
581 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
582 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
583 fs_id=$(do_facet mgs $cmd --nid $nid --idtype uid --id 0)
584 if [ $fs_id != 0 ]; then
585 echo "root allowed expected 0, got $fs_id"
590 ## ensure allow_root_access is disabled
591 for ((i = 0; i < NODEMAP_COUNT; i++)); do
592 local csum=${HOSTNAME_CHECKSUM}_${i}
594 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
595 --property admin --value 0; then
596 error "nodemap_modify ${HOSTNAME_CHECKSUM}_${i} "
602 ## check that root is mapped to 99
603 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
604 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
605 fs_id=$(do_facet mgs $cmd --nid $nid --idtype uid --id 0)
606 if [ $fs_id != 99 ]; then
607 error "root squash expected 99, got $fs_id"
612 ## reset client trust to 0
613 for ((i = 0; i < NODEMAP_COUNT; i++)); do
614 if ! do_facet mgs $LCTL nodemap_modify \
615 --name ${HOSTNAME_CHECKSUM}_${i} \
616 --property trusted --value 0; then
617 error "nodemap_modify ${HOSTNAME_CHECKSUM}_${i} "
629 remote_mgs_nodsh && skip "remote MGS with nodsh"
630 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
631 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
635 [[ $rc != 0 ]] && error "nodemap_add failed with $rc"
639 [[ $rc != 0 ]] && error "nodemap_del failed with $rc"
643 run_test 7 "nodemap create and delete"
648 remote_mgs_nodsh && skip "remote MGS with nodsh"
649 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
650 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
656 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
662 [[ $rc == 0 ]] && error "duplicate nodemap_add allowed with $rc" &&
668 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 3
672 run_test 8 "nodemap reject duplicates"
678 remote_mgs_nodsh && skip "remote MGS with nodsh"
679 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
680 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
685 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
688 for ((i = 0; i < NODEMAP_COUNT; i++)); do
689 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
693 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
696 for ((i = 0; i < NODEMAP_COUNT; i++)); do
697 if ! delete_range ${HOSTNAME_CHECKSUM}_${i} $i; then
701 [[ $rc != 0 ]] && error "nodemap_del_range failed with $rc" && return 4
706 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
710 run_test 9 "nodemap range add"
715 remote_mgs_nodsh && skip "remote MGS with nodsh"
716 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
717 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
722 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
725 for ((i = 0; i < NODEMAP_COUNT; i++)); do
726 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
730 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
733 for ((i = 0; i < NODEMAP_COUNT; i++)); do
734 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
738 [[ $rc == 0 ]] && error "nodemap_add_range duplicate add with $rc" &&
743 for ((i = 0; i < NODEMAP_COUNT; i++)); do
744 if ! delete_range ${HOSTNAME_CHECKSUM}_${i} $i; then
748 [[ $rc != 0 ]] && error "nodemap_del_range failed with $rc" && return 4
752 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 5
756 run_test 10a "nodemap reject duplicate ranges"
759 [ "$MGS_VERSION" -lt $(version_code 2.10.53) ] &&
760 skip "Need MGS >= 2.10.53"
764 local nids="192.168.19.[0-255]@o2ib20"
766 do_facet mgs $LCTL nodemap_del $nm1 2>/dev/null
767 do_facet mgs $LCTL nodemap_del $nm2 2>/dev/null
769 do_facet mgs $LCTL nodemap_add $nm1 || error "Add $nm1 failed"
770 do_facet mgs $LCTL nodemap_add $nm2 || error "Add $nm2 failed"
771 do_facet mgs $LCTL nodemap_add_range --name $nm1 --range $nids ||
772 error "Add range $nids to $nm1 failed"
773 [ -n "$(do_facet mgs $LCTL get_param nodemap.$nm1.* |
774 grep start_nid)" ] || error "No range was found"
775 do_facet mgs $LCTL nodemap_del_range --name $nm2 --range $nids &&
776 error "Deleting range $nids from $nm2 should fail"
777 [ -n "$(do_facet mgs $LCTL get_param nodemap.$nm1.* |
778 grep start_nid)" ] || error "Range $nids should be there"
780 do_facet mgs $LCTL nodemap_del $nm1 || error "Delete $nm1 failed"
781 do_facet mgs $LCTL nodemap_del $nm2 || error "Delete $nm2 failed"
784 run_test 10b "delete range from the correct nodemap"
786 test_10c() { #LU-8912
787 [ "$MGS_VERSION" -lt $(version_code 2.10.57) ] &&
788 skip "Need MGS >= 2.10.57"
790 local nm="nodemap_lu8912"
791 local nid_range="10.210.[32-47].[0-255]@o2ib3"
792 local start_nid="10.210.32.0@o2ib3"
793 local end_nid="10.210.47.255@o2ib3"
794 local start_nid_found
797 do_facet mgs $LCTL nodemap_del $nm 2>/dev/null
798 do_facet mgs $LCTL nodemap_add $nm || error "Add $nm failed"
799 do_facet mgs $LCTL nodemap_add_range --name $nm --range $nid_range ||
800 error "Add range $nid_range to $nm failed"
802 start_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
803 awk -F '[,: ]' /start_nid/'{ print $9 }')
804 [ "$start_nid" == "$start_nid_found" ] ||
805 error "start_nid: $start_nid_found != $start_nid"
806 end_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
807 awk -F '[,: ]' /end_nid/'{ print $13 }')
808 [ "$end_nid" == "$end_nid_found" ] ||
809 error "end_nid: $end_nid_found != $end_nid"
811 do_facet mgs $LCTL nodemap_del $nm || error "Delete $nm failed"
814 run_test 10c "verfify contiguous range support"
816 test_10d() { #LU-8913
817 [ "$MGS_VERSION" -lt $(version_code 2.10.59) ] &&
818 skip "Need MGS >= 2.10.59"
820 local nm="nodemap_lu8913"
821 local nid_range="*@o2ib3"
822 local start_nid="0.0.0.0@o2ib3"
823 local end_nid="255.255.255.255@o2ib3"
824 local start_nid_found
827 do_facet mgs $LCTL nodemap_del $nm 2>/dev/null
828 do_facet mgs $LCTL nodemap_add $nm || error "Add $nm failed"
829 do_facet mgs $LCTL nodemap_add_range --name $nm --range $nid_range ||
830 error "Add range $nid_range to $nm failed"
832 start_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
833 awk -F '[,: ]' /start_nid/'{ print $9 }')
834 [ "$start_nid" == "$start_nid_found" ] ||
835 error "start_nid: $start_nid_found != $start_nid"
836 end_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
837 awk -F '[,: ]' /end_nid/'{ print $13 }')
838 [ "$end_nid" == "$end_nid_found" ] ||
839 error "end_nid: $end_nid_found != $end_nid"
841 do_facet mgs $LCTL nodemap_del $nm || error "Delete $nm failed"
844 run_test 10d "verfify nodemap range format '*@<net>' support"
849 remote_mgs_nodsh && skip "remote MGS with nodsh"
850 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
851 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
856 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
859 for ((i = 0; i < NODEMAP_COUNT; i++)); do
860 if ! modify_flags ${HOSTNAME_CHECKSUM}_${i}; then
864 [[ $rc != 0 ]] && error "nodemap_modify with $rc" && return 2
869 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 3
873 run_test 11 "nodemap modify"
878 remote_mgs_nodsh && skip "remote MGS with nodsh"
879 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
880 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
885 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
888 for ((i = 0; i < NODEMAP_COUNT; i++)); do
889 if ! squash_id ${HOSTNAME_CHECKSUM}_${i} 88 0; then
893 [[ $rc != 0 ]] && error "nodemap squash_uid with $rc" && return 2
896 for ((i = 0; i < NODEMAP_COUNT; i++)); do
897 if ! squash_id ${HOSTNAME_CHECKSUM}_${i} 88 1; then
901 [[ $rc != 0 ]] && error "nodemap squash_gid with $rc" && return 3
906 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
910 run_test 12 "nodemap set squash ids"
915 remote_mgs_nodsh && skip "remote MGS with nodsh"
916 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
917 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
922 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
925 for ((i = 0; i < NODEMAP_COUNT; i++)); do
926 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
930 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
933 for ((i = 0; i < NODEMAP_COUNT; i++)); do
934 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
935 for k in $NODEMAP_IPADDR_LIST; do
936 if ! test_nid $SUBNET_CHECKSUM.$i.$j.$k \
937 ${HOSTNAME_CHECKSUM}_${i}; then
943 [[ $rc != 0 ]] && error "nodemap_test_nid failed with $rc" && return 3
948 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
952 run_test 13 "test nids"
957 remote_mgs_nodsh && skip "remote MGS with nodsh"
958 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
959 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
964 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
967 for ((i = 0; i < NODEMAP_COUNT; i++)); do
968 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
969 for k in $NODEMAP_IPADDR_LIST; do
970 if ! test_nid $SUBNET_CHECKSUM.$i.$j.$k \
977 [[ $rc != 0 ]] && error "nodemap_test_nid failed with $rc" && return 3
982 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
986 run_test 14 "test default nodemap nid lookup"
991 remote_mgs_nodsh && skip "remote MGS with nodsh"
992 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
993 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
998 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
1001 for ((i = 0; i < NODEMAP_COUNT; i++)); do
1002 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
1006 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
1011 [[ $rc != 0 ]] && error "nodemap_add_idmap failed with $rc" && return 3
1013 activedefault=$(do_facet mgs $LCTL get_param -n nodemap.active)
1014 if [[ "$activedefault" != "1" ]]; then
1015 stack_trap cleanup_active EXIT
1021 [[ $rc != 0 ]] && error "nodemap_test_id failed with $rc" && return 4
1026 [[ $rc != 0 ]] && error "update_idmaps failed with $rc" && return 5
1031 [[ $rc != 0 ]] && error "nodemap_del_idmap failed with $rc" && return 6
1036 [[ $rc != 0 ]] && error "nodemap_delete failed with $rc" && return 7
1040 run_test 15 "test id mapping"
1042 create_fops_nodemaps() {
1045 for client in $clients; do
1046 local client_ip=$(host_nids_address $client $NETTYPE)
1047 local client_nid=$(h2nettype $client_ip)
1048 do_facet mgs $LCTL nodemap_add c${i} || return 1
1049 do_facet mgs $LCTL nodemap_add_range \
1050 --name c${i} --range $client_nid || return 1
1051 for map in ${FOPS_IDMAPS[i]}; do
1052 do_facet mgs $LCTL nodemap_add_idmap --name c${i} \
1053 --idtype uid --idmap ${map} || return 1
1054 do_facet mgs $LCTL nodemap_add_idmap --name c${i} \
1055 --idtype gid --idmap ${map} || return 1
1058 wait_nm_sync c$i idmap
1065 delete_fops_nodemaps() {
1068 for client in $clients; do
1069 do_facet mgs $LCTL nodemap_del c${i} || return 1
1077 if [ $MDSCOUNT -le 1 ]; then
1078 do_node ${clients_arr[0]} mkdir -p $DIR/$tdir
1080 # round-robin MDTs to test DNE nodemap support
1081 [ ! -d $DIR ] && do_node ${clients_arr[0]} mkdir -p $DIR
1082 do_node ${clients_arr[0]} $LFS setdirstripe -c 1 -i \
1083 $((fops_mds_index % MDSCOUNT)) $DIR/$tdir
1084 ((fops_mds_index++))
1088 # acl test directory needs to be initialized on a privileged client
1090 local admin=$(do_facet mgs $LCTL get_param -n nodemap.c0.admin_nodemap)
1091 local trust=$(do_facet mgs $LCTL get_param -n \
1092 nodemap.c0.trusted_nodemap)
1094 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1095 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
1097 wait_nm_sync c0 admin_nodemap
1098 wait_nm_sync c0 trusted_nodemap
1100 do_node ${clients_arr[0]} rm -rf $DIR/$tdir
1102 do_node ${clients_arr[0]} chown $user $DIR/$tdir
1104 do_facet mgs $LCTL nodemap_modify --name c0 \
1105 --property admin --value $admin
1106 do_facet mgs $LCTL nodemap_modify --name c0 \
1107 --property trusted --value $trust
1109 # flush MDT locks to make sure they are reacquired before test
1110 do_node ${clients_arr[0]} $LCTL set_param \
1111 ldlm.namespaces.$FSNAME-MDT*.lru_size=clear
1113 wait_nm_sync c0 admin_nodemap
1114 wait_nm_sync c0 trusted_nodemap
1117 # fileset test directory needs to be initialized on a privileged client
1118 fileset_test_setup() {
1121 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
1122 cleanup_mount $MOUNT
1123 FILESET="" zconf_mount_clients $CLIENTS $MOUNT
1126 local admin=$(do_facet mgs $LCTL get_param -n \
1127 nodemap.${nm}.admin_nodemap)
1128 local trust=$(do_facet mgs $LCTL get_param -n \
1129 nodemap.${nm}.trusted_nodemap)
1131 do_facet mgs $LCTL nodemap_modify --name $nm --property admin --value 1
1132 do_facet mgs $LCTL nodemap_modify --name $nm --property trusted \
1135 wait_nm_sync $nm admin_nodemap
1136 wait_nm_sync $nm trusted_nodemap
1138 # create directory and populate it for subdir mount
1139 do_node ${clients_arr[0]} mkdir $MOUNT/$subdir ||
1140 error "unable to create dir $MOUNT/$subdir"
1141 do_node ${clients_arr[0]} touch $MOUNT/$subdir/this_is_$subdir ||
1142 error "unable to create file $MOUNT/$subdir/this_is_$subdir"
1143 do_node ${clients_arr[0]} mkdir $MOUNT/$subdir/$subsubdir ||
1144 error "unable to create dir $MOUNT/$subdir/$subsubdir"
1145 do_node ${clients_arr[0]} touch \
1146 $MOUNT/$subdir/$subsubdir/this_is_$subsubdir ||
1147 error "unable to create file \
1148 $MOUNT/$subdir/$subsubdir/this_is_$subsubdir"
1150 do_facet mgs $LCTL nodemap_modify --name $nm \
1151 --property admin --value $admin
1152 do_facet mgs $LCTL nodemap_modify --name $nm \
1153 --property trusted --value $trust
1155 # flush MDT locks to make sure they are reacquired before test
1156 do_node ${clients_arr[0]} $LCTL set_param \
1157 ldlm.namespaces.$FSNAME-MDT*.lru_size=clear
1159 wait_nm_sync $nm admin_nodemap
1160 wait_nm_sync $nm trusted_nodemap
1163 # fileset test directory needs to be initialized on a privileged client
1164 fileset_test_cleanup() {
1166 local admin=$(do_facet mgs $LCTL get_param -n \
1167 nodemap.${nm}.admin_nodemap)
1168 local trust=$(do_facet mgs $LCTL get_param -n \
1169 nodemap.${nm}.trusted_nodemap)
1171 do_facet mgs $LCTL nodemap_modify --name $nm --property admin --value 1
1172 do_facet mgs $LCTL nodemap_modify --name $nm --property trusted \
1175 wait_nm_sync $nm admin_nodemap
1176 wait_nm_sync $nm trusted_nodemap
1178 # cleanup directory created for subdir mount
1179 do_node ${clients_arr[0]} rm -rf $MOUNT/$subdir ||
1180 error "unable to remove dir $MOUNT/$subdir"
1182 do_facet mgs $LCTL nodemap_modify --name $nm \
1183 --property admin --value $admin
1184 do_facet mgs $LCTL nodemap_modify --name $nm \
1185 --property trusted --value $trust
1187 # flush MDT locks to make sure they are reacquired before test
1188 do_node ${clients_arr[0]} $LCTL set_param \
1189 ldlm.namespaces.$FSNAME-MDT*.lru_size=clear
1191 wait_nm_sync $nm admin_nodemap
1192 wait_nm_sync $nm trusted_nodemap
1193 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
1194 cleanup_mount $MOUNT
1195 zconf_mount_clients $CLIENTS $MOUNT
1199 do_create_delete() {
1202 local testfile=$DIR/$tdir/$tfile
1206 if $run_u touch $testfile >& /dev/null; then
1208 $run_u rm $testfile && d=1
1212 local expected=$(get_cr_del_expected $key)
1213 [ "$res" != "$expected" ] &&
1214 error "test $key, wanted $expected, got $res" && rc=$((rc + 1))
1218 nodemap_check_quota() {
1220 $run_u lfs quota -q $DIR | awk '{ print $2; exit; }'
1223 do_fops_quota_test() {
1225 # fuzz quota used to account for possible indirect blocks, etc
1226 local quota_fuzz=$(fs_log_size)
1227 local qused_orig=$(nodemap_check_quota "$run_u")
1228 local qused_high=$((qused_orig + quota_fuzz))
1229 local qused_low=$((qused_orig - quota_fuzz))
1230 local testfile=$DIR/$tdir/$tfile
1231 $run_u dd if=/dev/zero of=$testfile oflag=sync bs=1M count=1 \
1232 >& /dev/null || error "unable to write quota test file"
1233 sync; sync_all_data || true
1235 local qused_new=$(nodemap_check_quota "$run_u")
1236 [ $((qused_new)) -lt $((qused_low + 1024)) -o \
1237 $((qused_new)) -gt $((qused_high + 1024)) ] &&
1238 error "$qused_new != $qused_orig + 1M after write, " \
1239 "fuzz is $quota_fuzz"
1240 $run_u rm $testfile || error "unable to remove quota test file"
1241 wait_delete_completed_mds
1243 qused_new=$(nodemap_check_quota "$run_u")
1244 [ $((qused_new)) -lt $((qused_low)) \
1245 -o $((qused_new)) -gt $((qused_high)) ] &&
1246 error "quota not reclaimed, expect $qused_orig, " \
1247 "got $qused_new, fuzz $quota_fuzz"
1250 get_fops_mapped_user() {
1253 for ((i=0; i < ${#FOPS_IDMAPS[@]}; i++)); do
1254 for map in ${FOPS_IDMAPS[i]}; do
1255 if [ $(cut -d: -f1 <<< "$map") == $cli_user ]; then
1256 cut -d: -f2 <<< "$map"
1264 get_cr_del_expected() {
1266 IFS=":" read -a key <<< "$1"
1267 local mapmode="${key[0]}"
1268 local mds_user="${key[1]}"
1269 local cluster="${key[2]}"
1270 local cli_user="${key[3]}"
1271 local mode="0${key[4]}"
1278 [[ $mapmode == *mapped* ]] && mapped=1
1279 # only c1 is mapped in these test cases
1280 [[ $mapmode == mapped_trusted* ]] && [ "$cluster" == "c0" ] && mapped=0
1281 [[ $mapmode == *noadmin* ]] && noadmin=1
1283 # o+wx works as long as the user isn't mapped
1284 if [ $((mode & 3)) -eq 3 ]; then
1288 # if client user is root, check if root is squashed
1289 if [ "$cli_user" == "0" ]; then
1290 # squash root succeed, if other bit is on
1293 1) [ "$other" == "1" ] && echo $SUCCESS
1294 [ "$other" == "0" ] && echo $FAILURE;;
1298 if [ "$mapped" == "0" ]; then
1299 [ "$other" == "1" ] && echo $SUCCESS
1300 [ "$other" == "0" ] && echo $FAILURE
1304 # if mapped user is mds user, check for u+wx
1305 mapped_user=$(get_fops_mapped_user $cli_user)
1306 [ "$mapped_user" == "-1" ] &&
1307 error "unable to find mapping for client user $cli_user"
1309 if [ "$mapped_user" == "$mds_user" -a \
1310 $(((mode & 0300) == 0300)) -eq 1 ]; then
1314 if [ "$mapped_user" != "$mds_user" -a "$other" == "1" ]; then
1321 test_fops_admin_cli_i=""
1322 test_fops_chmod_dir() {
1323 local current_cli_i=$1
1325 local dir_to_chmod=$3
1326 local new_admin_cli_i=""
1328 # do we need to set up a new admin client?
1329 [ "$current_cli_i" == "0" ] && [ "$test_fops_admin_cli_i" != "1" ] &&
1331 [ "$current_cli_i" != "0" ] && [ "$test_fops_admin_cli_i" != "0" ] &&
1334 # if only one client, and non-admin, need to flip admin everytime
1335 if [ "$num_clients" == "1" ]; then
1336 test_fops_admin_client=$clients
1337 test_fops_admin_val=$(do_facet mgs $LCTL get_param -n \
1338 nodemap.c0.admin_nodemap)
1339 if [ "$test_fops_admin_val" != "1" ]; then
1340 do_facet mgs $LCTL nodemap_modify \
1344 wait_nm_sync c0 admin_nodemap
1346 elif [ "$new_admin_cli_i" != "" ]; then
1347 # restore admin val to old admin client
1348 if [ "$test_fops_admin_cli_i" != "" ] &&
1349 [ "$test_fops_admin_val" != "1" ]; then
1350 do_facet mgs $LCTL nodemap_modify \
1351 --name c${test_fops_admin_cli_i} \
1353 --value $test_fops_admin_val
1354 wait_nm_sync c${test_fops_admin_cli_i} admin_nodemap
1357 test_fops_admin_cli_i=$new_admin_cli_i
1358 test_fops_admin_client=${clients_arr[$new_admin_cli_i]}
1359 test_fops_admin_val=$(do_facet mgs $LCTL get_param -n \
1360 nodemap.c${new_admin_cli_i}.admin_nodemap)
1362 if [ "$test_fops_admin_val" != "1" ]; then
1363 do_facet mgs $LCTL nodemap_modify \
1364 --name c${new_admin_cli_i} \
1367 wait_nm_sync c${new_admin_cli_i} admin_nodemap
1371 do_node $test_fops_admin_client chmod $perm_bits $DIR/$tdir || return 1
1373 # remove admin for single client if originally non-admin
1374 if [ "$num_clients" == "1" ] && [ "$test_fops_admin_val" != "1" ]; then
1375 do_facet mgs $LCTL nodemap_modify --name c0 --property admin \
1377 wait_nm_sync c0 admin_nodemap
1385 local single_client="$2"
1386 local client_user_list=([0]="0 $((IDBASE+3))"
1387 [1]="0 $((IDBASE+5))")
1388 local mds_users="-1 0"
1391 local perm_bit_list="3 $((0300))"
1392 # SLOW tests 000-007, 010-070, 100-700 (octal modes)
1393 if [ "$SLOW" == "yes" ]; then
1394 perm_bit_list="0 $(seq 1 7) $(seq 8 8 63) $(seq 64 64 511) \
1396 client_user_list=([0]="0 $((IDBASE+3)) $((IDBASE+4))"
1397 [1]="0 $((IDBASE+5)) $((IDBASE+6))")
1398 mds_users="-1 0 1 2"
1401 # force single_client to speed up test
1402 [ "$SLOW" == "yes" ] ||
1404 # step through mds users. -1 means root
1405 for mds_i in $mds_users; do
1406 local user=$((mds_i + IDBASE))
1410 [ "$mds_i" == "-1" ] && user=0
1412 echo mkdir -p $DIR/$tdir
1415 for client in $clients; do
1417 for u in ${client_user_list[$cli_i]}; do
1418 local run_u="do_node $client \
1419 $RUNAS_CMD -u$u -g$u -G$u"
1420 for perm_bits in $perm_bit_list; do
1421 local mode=$(printf %03o $perm_bits)
1423 key="$mapmode:$user:c$cli_i:$u:$mode"
1424 test_fops_chmod_dir $cli_i $mode \
1426 error cannot chmod $key
1427 do_create_delete "$run_u" "$key"
1431 test_fops_chmod_dir $cli_i 777 $DIR/$tdir ||
1432 error cannot chmod $key
1433 do_fops_quota_test "$run_u"
1436 cli_i=$((cli_i + 1))
1437 [ "$single_client" == "1" ] && break
1444 nodemap_version_check () {
1445 remote_mgs_nodsh && skip "remote MGS with nodsh" && return 1
1446 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
1447 skip "No nodemap on $MGS_VERSION MGS < 2.5.53" &&
1452 nodemap_test_setup() {
1454 local active_nodemap=1
1456 [ "$1" == "0" ] && active_nodemap=0
1458 do_nodes $(comma_list $(all_mdts_nodes)) \
1459 $LCTL set_param mdt.*.identity_upcall=NONE
1462 create_fops_nodemaps
1464 [[ $rc != 0 ]] && error "adding fops nodemaps failed $rc"
1466 do_facet mgs $LCTL nodemap_activate $active_nodemap
1469 do_facet mgs $LCTL nodemap_modify --name default \
1470 --property admin --value 1
1471 wait_nm_sync default admin_nodemap
1472 do_facet mgs $LCTL nodemap_modify --name default \
1473 --property trusted --value 1
1474 wait_nm_sync default trusted_nodemap
1477 nodemap_test_cleanup() {
1479 delete_fops_nodemaps
1481 [[ $rc != 0 ]] && error "removing fops nodemaps failed $rc"
1483 do_facet mgs $LCTL nodemap_modify --name default \
1484 --property admin --value 0
1485 wait_nm_sync default admin_nodemap
1486 do_facet mgs $LCTL nodemap_modify --name default \
1487 --property trusted --value 0
1488 wait_nm_sync default trusted_nodemap
1490 do_facet mgs $LCTL nodemap_activate 0
1491 wait_nm_sync active 0
1493 export SK_UNIQUE_NM=false
1497 nodemap_clients_admin_trusted() {
1501 for client in $clients; do
1502 do_facet mgs $LCTL nodemap_modify --name c0 \
1503 --property admin --value $admin
1504 do_facet mgs $LCTL nodemap_modify --name c0 \
1505 --property trusted --value $tr
1508 wait_nm_sync c$((i - 1)) admin_nodemap
1509 wait_nm_sync c$((i - 1)) trusted_nodemap
1513 nodemap_version_check || return 0
1514 nodemap_test_setup 0
1516 trap nodemap_test_cleanup EXIT
1518 nodemap_test_cleanup
1520 run_test 16 "test nodemap all_off fileops"
1524 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1525 skip "Need MDS >= 2.11.55"
1528 nodemap_version_check || return 0
1531 trap nodemap_test_cleanup EXIT
1532 nodemap_clients_admin_trusted 0 1
1533 test_fops trusted_noadmin 1
1534 nodemap_test_cleanup
1536 run_test 17 "test nodemap trusted_noadmin fileops"
1540 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1541 skip "Need MDS >= 2.11.55"
1544 nodemap_version_check || return 0
1547 trap nodemap_test_cleanup EXIT
1548 nodemap_clients_admin_trusted 0 0
1549 test_fops mapped_noadmin 1
1550 nodemap_test_cleanup
1552 run_test 18 "test nodemap mapped_noadmin fileops"
1556 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1557 skip "Need MDS >= 2.11.55"
1560 nodemap_version_check || return 0
1563 trap nodemap_test_cleanup EXIT
1564 nodemap_clients_admin_trusted 1 1
1565 test_fops trusted_admin 1
1566 nodemap_test_cleanup
1568 run_test 19 "test nodemap trusted_admin fileops"
1572 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1573 skip "Need MDS >= 2.11.55"
1576 nodemap_version_check || return 0
1579 trap nodemap_test_cleanup EXIT
1580 nodemap_clients_admin_trusted 1 0
1581 test_fops mapped_admin 1
1582 nodemap_test_cleanup
1584 run_test 20 "test nodemap mapped_admin fileops"
1588 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1589 skip "Need MDS >= 2.11.55"
1592 nodemap_version_check || return 0
1595 trap nodemap_test_cleanup EXIT
1598 for client in $clients; do
1599 do_facet mgs $LCTL nodemap_modify --name c${i} \
1600 --property admin --value 0
1601 do_facet mgs $LCTL nodemap_modify --name c${i} \
1602 --property trusted --value $x
1606 wait_nm_sync c$((i - 1)) trusted_nodemap
1608 test_fops mapped_trusted_noadmin
1609 nodemap_test_cleanup
1611 run_test 21 "test nodemap mapped_trusted_noadmin fileops"
1615 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1616 skip "Need MDS >= 2.11.55"
1619 nodemap_version_check || return 0
1622 trap nodemap_test_cleanup EXIT
1625 for client in $clients; do
1626 do_facet mgs $LCTL nodemap_modify --name c${i} \
1627 --property admin --value 1
1628 do_facet mgs $LCTL nodemap_modify --name c${i} \
1629 --property trusted --value $x
1633 wait_nm_sync c$((i - 1)) trusted_nodemap
1635 test_fops mapped_trusted_admin
1636 nodemap_test_cleanup
1638 run_test 22 "test nodemap mapped_trusted_admin fileops"
1640 # acl test directory needs to be initialized on a privileged client
1641 nodemap_acl_test_setup() {
1642 local admin=$(do_facet mgs $LCTL get_param -n \
1643 nodemap.c0.admin_nodemap)
1644 local trust=$(do_facet mgs $LCTL get_param -n \
1645 nodemap.c0.trusted_nodemap)
1647 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1648 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
1650 wait_nm_sync c0 admin_nodemap
1651 wait_nm_sync c0 trusted_nodemap
1653 do_node ${clients_arr[0]} rm -rf $DIR/$tdir
1655 do_node ${clients_arr[0]} chmod a+rwx $DIR/$tdir ||
1656 error unable to chmod a+rwx test dir $DIR/$tdir
1658 do_facet mgs $LCTL nodemap_modify --name c0 \
1659 --property admin --value $admin
1660 do_facet mgs $LCTL nodemap_modify --name c0 \
1661 --property trusted --value $trust
1663 wait_nm_sync c0 trusted_nodemap
1666 # returns 0 if the number of ACLs does not change on the second (mapped) client
1667 # after being set on the first client
1668 nodemap_acl_test() {
1670 local set_client="$2"
1671 local get_client="$3"
1672 local check_setfacl="$4"
1673 local setfacl_error=0
1674 local testfile=$DIR/$tdir/$tfile
1675 local RUNAS_USER="$RUNAS_CMD -u $user"
1677 local acl_count_post=0
1679 nodemap_acl_test_setup
1682 do_node $set_client $RUNAS_USER touch $testfile
1684 # ACL masks aren't filtered by nodemap code, so we ignore them
1685 acl_count=$(do_node $get_client getfacl $testfile | grep -v mask |
1687 do_node $set_client $RUNAS_USER setfacl -m $user:rwx $testfile ||
1690 # if check setfacl is set to 1, then it's supposed to error
1691 if [ "$check_setfacl" == "1" ]; then
1692 [ "$setfacl_error" != "1" ] && return 1
1695 [ "$setfacl_error" == "1" ] && echo "WARNING: unable to setfacl"
1697 acl_count_post=$(do_node $get_client getfacl $testfile | grep -v mask |
1699 [ $acl_count -eq $acl_count_post ] && return 0
1704 [ $num_clients -lt 2 ] && skip "Need 2 clients at least" && return
1705 nodemap_version_check || return 0
1708 trap nodemap_test_cleanup EXIT
1709 # 1 trusted cluster, 1 mapped cluster
1710 local unmapped_fs=$((IDBASE+0))
1711 local unmapped_c1=$((IDBASE+5))
1712 local mapped_fs=$((IDBASE+2))
1713 local mapped_c0=$((IDBASE+4))
1714 local mapped_c1=$((IDBASE+6))
1716 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1717 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
1719 do_facet mgs $LCTL nodemap_modify --name c1 --property admin --value 0
1720 do_facet mgs $LCTL nodemap_modify --name c1 --property trusted --value 0
1722 wait_nm_sync c1 trusted_nodemap
1724 # setfacl on trusted cluster to unmapped user, verify it's not seen
1725 nodemap_acl_test $unmapped_fs ${clients_arr[0]} ${clients_arr[1]} ||
1726 error "acl count (1)"
1728 # setfacl on trusted cluster to mapped user, verify it's seen
1729 nodemap_acl_test $mapped_fs ${clients_arr[0]} ${clients_arr[1]} &&
1730 error "acl count (2)"
1732 # setfacl on mapped cluster to mapped user, verify it's seen
1733 nodemap_acl_test $mapped_c1 ${clients_arr[1]} ${clients_arr[0]} &&
1734 error "acl count (3)"
1736 # setfacl on mapped cluster to unmapped user, verify error
1737 nodemap_acl_test $unmapped_fs ${clients_arr[1]} ${clients_arr[0]} 1 ||
1738 error "acl count (4)"
1741 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 0
1742 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 0
1744 wait_nm_sync c0 trusted_nodemap
1746 # setfacl to mapped user on c1, also mapped to c0, verify it's seen
1747 nodemap_acl_test $mapped_c1 ${clients_arr[1]} ${clients_arr[0]} &&
1748 error "acl count (5)"
1750 # setfacl to mapped user on c1, not mapped to c0, verify not seen
1751 nodemap_acl_test $unmapped_c1 ${clients_arr[1]} ${clients_arr[0]} ||
1752 error "acl count (6)"
1754 nodemap_test_cleanup
1756 run_test 23a "test mapped regular ACLs"
1758 test_23b() { #LU-9929
1759 [ $num_clients -lt 2 ] && skip "Need 2 clients at least"
1760 [ "$MGS_VERSION" -lt $(version_code 2.10.53) ] &&
1761 skip "Need MGS >= 2.10.53"
1763 export SK_UNIQUE_NM=true
1765 trap nodemap_test_cleanup EXIT
1767 local testdir=$DIR/$tdir
1768 local fs_id=$((IDBASE+10))
1773 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1774 wait_nm_sync c0 admin_nodemap
1775 do_facet mgs $LCTL nodemap_modify --name c1 --property admin --value 1
1776 wait_nm_sync c1 admin_nodemap
1777 do_facet mgs $LCTL nodemap_modify --name c1 --property trusted --value 1
1778 wait_nm_sync c1 trusted_nodemap
1780 # Add idmap $ID0:$fs_id (500:60010)
1781 do_facet mgs $LCTL nodemap_add_idmap --name c0 --idtype gid \
1782 --idmap $ID0:$fs_id ||
1783 error "add idmap $ID0:$fs_id to nodemap c0 failed"
1784 wait_nm_sync c0 idmap
1786 # set/getfacl default acl on client 1 (unmapped gid=500)
1787 do_node ${clients_arr[0]} rm -rf $testdir
1788 do_node ${clients_arr[0]} mkdir -p $testdir
1789 # Here, USER0=$(getent passwd | grep :$ID0:$ID0: | cut -d: -f1)
1790 do_node ${clients_arr[0]} setfacl -R -d -m group:$USER0:rwx $testdir ||
1791 error "setfacl $testdir on ${clients_arr[0]} failed"
1792 unmapped_id=$(do_node ${clients_arr[0]} getfacl $testdir |
1793 grep -E "default:group:.*:rwx" | awk -F: '{print $3}')
1794 [ "$unmapped_id" = "$USER0" ] ||
1795 error "gid=$ID0 was not unmapped correctly on ${clients_arr[0]}"
1797 # getfacl default acl on client 2 (mapped gid=60010)
1798 mapped_id=$(do_node ${clients_arr[1]} getfacl $testdir |
1799 grep -E "default:group:.*:rwx" | awk -F: '{print $3}')
1800 fs_user=$(do_node ${clients_arr[1]} getent passwd |
1801 grep :$fs_id:$fs_id: | cut -d: -f1)
1802 [ -z "$fs_user" ] && fs_user=$fs_id
1803 [ $mapped_id -eq $fs_id -o "$mapped_id" = "$fs_user" ] ||
1804 error "Should return gid=$fs_id or $fs_user on client2"
1807 nodemap_test_cleanup
1808 export SK_UNIQUE_NM=false
1810 run_test 23b "test mapped default ACLs"
1815 trap nodemap_test_cleanup EXIT
1816 do_nodes $(comma_list $(all_server_nodes)) $LCTL get_param -R nodemap
1818 nodemap_test_cleanup
1820 run_test 24 "check nodemap proc files for LBUGs and Oopses"
1823 local tmpfile=$(mktemp)
1824 local tmpfile2=$(mktemp)
1825 local tmpfile3=$(mktemp)
1826 local tmpfile4=$(mktemp)
1830 nodemap_version_check || return 0
1832 # stop clients for this test
1833 zconf_umount_clients $CLIENTS $MOUNT ||
1834 error "unable to umount clients $CLIENTS"
1836 export SK_UNIQUE_NM=true
1839 # enable trusted/admin for setquota call in cleanup_and_setup_lustre()
1841 for client in $clients; do
1842 do_facet mgs $LCTL nodemap_modify --name c${i} \
1843 --property admin --value 1
1844 do_facet mgs $LCTL nodemap_modify --name c${i} \
1845 --property trusted --value 1
1848 wait_nm_sync c$((i - 1)) trusted_nodemap
1850 trap nodemap_test_cleanup EXIT
1852 # create a new, empty nodemap, and add fileset info to it
1853 do_facet mgs $LCTL nodemap_add test25 ||
1854 error "unable to create nodemap $testname"
1855 do_facet mgs $LCTL set_param -P nodemap.$testname.fileset=/$subdir ||
1856 error "unable to add fileset info to nodemap test25"
1858 wait_nm_sync test25 id
1860 do_facet mgs $LCTL nodemap_info > $tmpfile
1861 do_facet mds $LCTL nodemap_info > $tmpfile2
1863 if ! $SHARED_KEY; then
1864 # will conflict with SK's nodemaps
1865 cleanup_and_setup_lustre
1867 # stop clients for this test
1868 zconf_umount_clients $CLIENTS $MOUNT ||
1869 error "unable to umount clients $CLIENTS"
1871 do_facet mgs $LCTL nodemap_info > $tmpfile3
1872 diff -q $tmpfile3 $tmpfile >& /dev/null ||
1873 error "nodemap_info diff on MGS after remount"
1875 do_facet mds $LCTL nodemap_info > $tmpfile4
1876 diff -q $tmpfile4 $tmpfile2 >& /dev/null ||
1877 error "nodemap_info diff on MDS after remount"
1880 do_facet mgs $LCTL nodemap_del test25 ||
1881 error "cannot delete nodemap test25 from config"
1882 nodemap_test_cleanup
1883 # restart clients previously stopped
1884 zconf_mount_clients $CLIENTS $MOUNT ||
1885 error "unable to mount clients $CLIENTS"
1887 rm -f $tmpfile $tmpfile2
1888 export SK_UNIQUE_NM=false
1890 run_test 25 "test save and reload nodemap config"
1893 nodemap_version_check || return 0
1897 do_facet mgs "seq -f 'c%g' $large_i | xargs -n1 $LCTL nodemap_add"
1898 wait_nm_sync c$large_i admin_nodemap
1900 do_facet mgs "seq -f 'c%g' $large_i | xargs -n1 $LCTL nodemap_del"
1901 wait_nm_sync c$large_i admin_nodemap
1903 run_test 26 "test transferring very large nodemap"
1905 nodemap_exercise_fileset() {
1910 if [ "$nm" == "default" ]; then
1911 do_facet mgs $LCTL nodemap_activate 1
1916 if $SHARED_KEY; then
1917 export SK_UNIQUE_NM=true
1919 # will conflict with SK's nodemaps
1920 trap "fileset_test_cleanup $nm" EXIT
1922 fileset_test_setup "$nm"
1924 # add fileset info to $nm nodemap
1925 if ! combined_mgs_mds; then
1926 do_facet mgs $LCTL set_param nodemap.${nm}.fileset=/$subdir ||
1927 error "unable to add fileset info to $nm nodemap on MGS"
1929 do_facet mgs $LCTL set_param -P nodemap.${nm}.fileset=/$subdir ||
1930 error "unable to add fileset info to $nm nodemap for servers"
1931 wait_nm_sync $nm fileset "nodemap.${nm}.fileset=/$subdir"
1934 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
1935 error "unable to umount client ${clients_arr[0]}"
1936 # set some generic fileset to trigger SSK code
1938 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
1939 error "unable to remount client ${clients_arr[0]}"
1942 # test mount point content
1943 do_node ${clients_arr[0]} test -f $MOUNT/this_is_$subdir ||
1944 error "fileset not taken into account"
1946 # re-mount client with sub-subdir
1947 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
1948 error "unable to umount client ${clients_arr[0]}"
1949 export FILESET=/$subsubdir
1950 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
1951 error "unable to remount client ${clients_arr[0]}"
1954 # test mount point content
1955 do_node ${clients_arr[0]} test -f $MOUNT/this_is_$subsubdir ||
1956 error "subdir of fileset not taken into account"
1958 # remove fileset info from nodemap
1959 do_facet mgs $LCTL nodemap_set_fileset --name $nm --fileset clear ||
1960 error "unable to delete fileset info on $nm nodemap"
1961 wait_update_facet mgs "$LCTL get_param nodemap.${nm}.fileset" \
1962 "nodemap.${nm}.fileset=" ||
1963 error "fileset info still not cleared on $nm nodemap"
1964 do_facet mgs $LCTL set_param -P nodemap.${nm}.fileset=clear ||
1965 error "unable to reset fileset info on $nm nodemap"
1966 wait_nm_sync $nm fileset "nodemap.${nm}.fileset="
1969 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
1970 error "unable to umount client ${clients_arr[0]}"
1971 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
1972 error "unable to remount client ${clients_arr[0]}"
1974 # test mount point content
1975 if ! $(do_node ${clients_arr[0]} test -d $MOUNT/$subdir); then
1977 error "fileset not cleared on $nm nodemap"
1980 # back to non-nodemap setup
1981 if $SHARED_KEY; then
1982 export SK_UNIQUE_NM=false
1983 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
1984 error "unable to umount client ${clients_arr[0]}"
1986 fileset_test_cleanup "$nm"
1987 if [ "$nm" == "default" ]; then
1988 do_facet mgs $LCTL nodemap_activate 0
1989 wait_nm_sync active 0
1991 export SK_UNIQUE_NM=false
1993 nodemap_test_cleanup
1995 if $SHARED_KEY; then
1996 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
1997 error "unable to remount client ${clients_arr[0]}"
2002 [ "$MDS1_VERSION" -lt $(version_code 2.11.50) ] &&
2003 skip "Need MDS >= 2.11.50"
2005 for nm in "default" "c0"; do
2006 local subdir="subdir_${nm}"
2007 local subsubdir="subsubdir_${nm}"
2009 if [ "$nm" == "default" ] && [ "$SHARED_KEY" == "true" ]; then
2010 echo "Skipping nodemap $nm with SHARED_KEY";
2014 echo "Exercising fileset for nodemap $nm"
2015 nodemap_exercise_fileset "$nm"
2018 run_test 27a "test fileset in various nodemaps"
2020 test_27b() { #LU-10703
2021 [ "$MDS1_VERSION" -lt $(version_code 2.11.50) ] &&
2022 skip "Need MDS >= 2.11.50"
2023 [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs"
2026 trap nodemap_test_cleanup EXIT
2028 # Add the nodemaps and set their filesets
2029 for i in $(seq 1 $MDSCOUNT); do
2030 do_facet mgs $LCTL nodemap_del nm$i 2>/dev/null
2031 do_facet mgs $LCTL nodemap_add nm$i ||
2032 error "add nodemap nm$i failed"
2033 wait_nm_sync nm$i "" "" "-N"
2035 if ! combined_mgs_mds; then
2037 $LCTL set_param nodemap.nm$i.fileset=/dir$i ||
2038 error "set nm$i.fileset=/dir$i failed on MGS"
2040 do_facet mgs $LCTL set_param -P nodemap.nm$i.fileset=/dir$i ||
2041 error "set nm$i.fileset=/dir$i failed on servers"
2042 wait_nm_sync nm$i fileset "nodemap.nm$i.fileset=/dir$i"
2045 # Check if all the filesets are correct
2046 for i in $(seq 1 $MDSCOUNT); do
2047 fileset=$(do_facet mds$i \
2048 $LCTL get_param -n nodemap.nm$i.fileset)
2049 [ "$fileset" = "/dir$i" ] ||
2050 error "nm$i.fileset $fileset != /dir$i on mds$i"
2051 do_facet mgs $LCTL nodemap_del nm$i ||
2052 error "delete nodemap nm$i failed"
2055 nodemap_test_cleanup
2057 run_test 27b "The new nodemap won't clear the old nodemap's fileset"
2060 if ! $SHARED_KEY; then
2061 skip "need shared key feature for this test" && return
2063 mkdir -p $DIR/$tdir || error "mkdir failed"
2064 touch $DIR/$tdir/$tdir.out || error "touch failed"
2065 if [ ! -f $DIR/$tdir/$tdir.out ]; then
2066 error "read before rotation failed"
2068 # store top key identity to ensure rotation has occurred
2069 SK_IDENTITY_OLD=$(lctl get_param *.*.*srpc* | grep "expire" |
2070 head -1 | awk '{print $15}' | cut -c1-8)
2071 do_facet $SINGLEMDS lfs flushctx ||
2072 error "could not run flushctx on $SINGLEMDS"
2074 lfs flushctx || error "could not run flushctx on client"
2076 # verify new key is in place
2077 SK_IDENTITY_NEW=$(lctl get_param *.*.*srpc* | grep "expire" |
2078 head -1 | awk '{print $15}' | cut -c1-8)
2079 if [ $SK_IDENTITY_OLD == $SK_IDENTITY_NEW ]; then
2080 error "key did not rotate correctly"
2082 if [ ! -f $DIR/$tdir/$tdir.out ]; then
2083 error "read after rotation failed"
2086 run_test 28 "check shared key rotation method"
2089 if ! $SHARED_KEY; then
2090 skip "need shared key feature for this test" && return
2092 if [ $SK_FLAVOR != "ski" ] && [ $SK_FLAVOR != "skpi" ]; then
2093 skip "test only valid if integrity is active"
2096 mkdir $DIR/$tdir || error "mkdir"
2097 touch $DIR/$tdir/$tfile || error "touch"
2098 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2099 error "unable to umount clients"
2100 do_node ${clients_arr[0]} "keyctl show |
2101 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
2102 OLD_SK_PATH=$SK_PATH
2103 export SK_PATH=/dev/null
2104 if zconf_mount_clients ${clients_arr[0]} $MOUNT; then
2105 export SK_PATH=$OLD_SK_PATH
2106 do_node ${clients_arr[0]} "ls $DIR/$tdir/$tfile"
2107 if [ $? -eq 0 ]; then
2108 error "able to mount and read without key"
2110 error "able to mount without key"
2113 export SK_PATH=$OLD_SK_PATH
2114 do_node ${clients_arr[0]} "keyctl show |
2115 awk '/lustre/ { print \\\$1 }' |
2116 xargs -IX keyctl unlink X"
2118 zconf_mount_clients ${clients_arr[0]} $MOUNT ||
2119 error "unable to mount clients"
2121 run_test 29 "check for missing shared key"
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"
2130 mkdir -p $DIR/$tdir || error "mkdir failed"
2131 touch $DIR/$tdir/$tdir.out || error "touch failed"
2132 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2133 error "unable to umount clients"
2134 # unload keys from ring
2135 do_node ${clients_arr[0]} "keyctl show |
2136 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
2137 # generate key with bogus filesystem name
2138 do_node ${clients_arr[0]} "lgss_sk -w $SK_PATH/$FSNAME-bogus.key \
2139 -f $FSNAME.bogus -t client -d /dev/urandom" ||
2140 error "lgss_sk failed (1)"
2141 do_facet $SINGLEMDS lfs flushctx || error "could not run flushctx"
2142 OLD_SK_PATH=$SK_PATH
2143 export SK_PATH=$SK_PATH/$FSNAME-bogus.key
2144 if zconf_mount_clients ${clients_arr[0]} $MOUNT; then
2145 SK_PATH=$OLD_SK_PATH
2146 do_node ${clients_arr[0]} "ls $DIR/$tdir/$tdir.out"
2147 if [ $? -eq 0 ]; then
2148 error "mount and read file with invalid key"
2150 error "mount with invalid key"
2153 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2154 error "unable to umount clients"
2155 # unload keys from ring
2156 do_node ${clients_arr[0]} "keyctl show |
2157 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
2159 SK_PATH=$OLD_SK_PATH
2160 zconf_mount_clients ${clients_arr[0]} $MOUNT ||
2161 error "unable to mount clients"
2163 run_test 30 "check for invalid shared key"
2168 mkdir -p $DIR/$tdir || error "mkdir $flvr"
2169 touch $DIR/$tdir/f0 || error "touch $flvr"
2170 ls $DIR/$tdir || error "ls $flvr"
2171 dd if=/dev/zero of=$DIR/$tdir/f0 conv=fsync bs=1M count=10 \
2172 >& /dev/null || error "dd $flvr"
2173 rm -f $DIR/$tdir/f0 || error "rm $flvr"
2174 rmdir $DIR/$tdir || error "rmdir $flvr"
2177 echo 3 > /proc/sys/vm/drop_caches
2181 local save_flvr=$SK_FLAVOR
2183 if ! $SHARED_KEY; then
2184 skip "need shared key feature for this test"
2187 stack_trap restore_to_default_flavor EXIT
2189 for flvr in skn ska ski skpi; do
2192 restore_to_default_flavor || error "cannot set $flvr flavor"
2193 SK_FLAVOR=$save_flvr
2198 run_test 30b "basic test of all different SSK flavors"
2202 zconf_umount $HOSTNAME $MOUNT || error "unable to umount client"
2204 # remove ${NETTYPE}999 network on all nodes
2205 do_nodes $(comma_list $(all_nodes)) \
2206 "$LNETCTL net del --net ${NETTYPE}999 && \
2207 $LNETCTL lnet unconfigure 2>/dev/null || true"
2209 # necessary to do writeconf in order to de-register
2210 # @${NETTYPE}999 nid for targets
2212 export KEEP_ZPOOL="true"
2214 export SK_MOUNTED=false
2217 export KEEP_ZPOOL="$KZPOOL"
2221 local nid=$(lctl list_nids | grep ${NETTYPE} | head -n1)
2222 local addr=${nid%@*}
2225 export LNETCTL=$(which lnetctl 2> /dev/null)
2227 [ -z "$LNETCTL" ] && skip "without lnetctl support." && return
2228 local_mode && skip "in local mode."
2230 stack_trap cleanup_31 EXIT
2233 if [ "$MOUNT_2" ] && $(grep -q $MOUNT2' ' /proc/mounts); then
2234 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2236 if $(grep -q $MOUNT' ' /proc/mounts); then
2237 umount_client $MOUNT || error "umount $MOUNT failed"
2240 # check exports on servers are empty for client
2241 do_facet mgs "lctl get_param -n *.MGS*.exports.'$nid'.uuid 2>/dev/null |
2242 grep -q -" && error "export on MGS should be empty"
2243 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
2244 "lctl get_param -n *.${FSNAME}*.exports.'$nid'.uuid \
2245 2>/dev/null | grep -q -" &&
2246 error "export on servers should be empty"
2248 # add network ${NETTYPE}999 on all nodes
2249 do_nodes $(comma_list $(all_nodes)) \
2250 "$LNETCTL lnet configure && $LNETCTL net add --if \
2251 \$($LNETCTL net show --net $net | awk 'BEGIN{inf=0} \
2252 {if (inf==1) print \$2; fi; inf=0} /interfaces/{inf=1}') \
2253 --net ${NETTYPE}999" ||
2254 error "unable to configure NID ${NETTYPE}999"
2256 # necessary to do writeconf in order to register
2257 # new @${NETTYPE}999 nid for targets
2259 export KEEP_ZPOOL="true"
2261 export SK_MOUNTED=false
2263 setupall server_only || echo 1
2264 export KEEP_ZPOOL="$KZPOOL"
2267 local mgsnid_orig=$MGSNID
2268 # compute new MGSNID
2269 MGSNID=$(do_facet mgs "$LCTL list_nids | grep ${NETTYPE}999")
2271 # on client, turn LNet Dynamic Discovery on
2272 lnetctl set discovery 1
2274 # mount client with -o network=${NETTYPE}999 option:
2275 # should fail because of LNet Dynamic Discovery
2276 mount_client $MOUNT ${MOUNT_OPTS},network=${NETTYPE}999 &&
2277 error "client mount with '-o network' option should be refused"
2279 # on client, reconfigure LNet and turn LNet Dynamic Discovery off
2280 $LNETCTL net del --net ${NETTYPE}999 && lnetctl lnet unconfigure
2283 lnetctl set discovery 0
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 on client"
2291 # mount client with -o network=${NETTYPE}999 option
2292 mount_client $MOUNT ${MOUNT_OPTS},network=${NETTYPE}999 ||
2293 error "unable to remount client"
2298 # check export on MGS
2299 do_facet mgs "lctl get_param -n *.MGS*.exports.'$nid'.uuid 2>/dev/null |
2301 [ $? -ne 0 ] || error "export for $nid on MGS should not exist"
2304 "lctl get_param -n *.MGS*.exports.'${addr}@${NETTYPE}999'.uuid \
2305 2>/dev/null | grep -q -"
2307 error "export for ${addr}@${NETTYPE}999 on MGS should exist"
2309 # check {mdc,osc} imports
2310 lctl get_param mdc.${FSNAME}-*.import | grep current_connection |
2311 grep -q ${NETTYPE}999
2313 error "import for mdc should use ${addr}@${NETTYPE}999"
2314 lctl get_param osc.${FSNAME}-*.import | grep current_connection |
2315 grep -q ${NETTYPE}999
2317 error "import for osc should use ${addr}@${NETTYPE}999"
2319 run_test 31 "client mount option '-o network'"
2323 zconf_umount_clients ${clients_arr[0]} $MOUNT
2325 # disable sk flavor enforcement on MGS
2326 set_rule _mgs any any null
2328 # stop gss daemon on MGS
2329 if ! combined_mgs_mds ; then
2330 send_sigint $mgs_HOST lsvcgssd
2334 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
2337 restore_to_default_flavor
2341 if ! $SHARED_KEY; then
2342 skip "need shared key feature for this test"
2345 stack_trap cleanup_32 EXIT
2347 # restore to default null flavor
2348 save_flvr=$SK_FLAVOR
2350 restore_to_default_flavor || error "cannot set null flavor"
2351 SK_FLAVOR=$save_flvr
2354 if [ "$MOUNT_2" ] && $(grep -q $MOUNT2' ' /proc/mounts); then
2355 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2357 if $(grep -q $MOUNT' ' /proc/mounts); then
2358 umount_client $MOUNT || error "umount $MOUNT failed"
2361 # start gss daemon on MGS
2362 if combined_mgs_mds ; then
2363 send_sigint $mds_HOST lsvcgssd
2365 start_gss_daemons $mgs_HOST "$LSVCGSSD -vvv -s -g"
2367 # add mgs key type and MGS NIDs in key on MGS
2368 do_nodes $mgs_HOST "lgss_sk -t mgs,server -g $MGSNID -m \
2369 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2370 error "could not modify keyfile on MGS"
2372 # load modified key file on MGS
2373 do_nodes $mgs_HOST "lgss_sk -l $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2374 error "could not load keyfile on MGS"
2376 # add MGS NIDs in key on client
2377 do_nodes ${clients_arr[0]} "lgss_sk -g $MGSNID -m \
2378 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2379 error "could not modify keyfile on MGS"
2381 # set perms for per-nodemap keys else permission denied
2382 do_nodes $(comma_list $(all_nodes)) \
2383 "keyctl show | grep lustre | cut -c1-11 |
2385 xargs -IX keyctl setperm X 0x3f3f3f3f"
2387 # re-mount client with mgssec=skn
2388 save_opts=$MOUNT_OPTS
2389 if [ -z "$MOUNT_OPTS" ]; then
2390 MOUNT_OPTS="-o mgssec=skn"
2392 MOUNT_OPTS="$MOUNT_OPTS,mgssec=skn"
2394 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2395 error "mount ${clients_arr[0]} with mgssec=skn failed"
2396 MOUNT_OPTS=$save_opts
2399 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2400 error "umount ${clients_arr[0]} failed"
2402 # enforce ska flavor on MGS
2403 set_rule _mgs any any ska
2405 # re-mount client without mgssec
2406 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS &&
2407 error "mount ${clients_arr[0]} without mgssec should fail"
2409 # re-mount client with mgssec=skn
2410 save_opts=$MOUNT_OPTS
2411 if [ -z "$MOUNT_OPTS" ]; then
2412 MOUNT_OPTS="-o mgssec=skn"
2414 MOUNT_OPTS="$MOUNT_OPTS,mgssec=skn"
2416 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS &&
2417 error "mount ${clients_arr[0]} with mgssec=skn should fail"
2418 MOUNT_OPTS=$save_opts
2420 # re-mount client with mgssec=ska
2421 save_opts=$MOUNT_OPTS
2422 if [ -z "$MOUNT_OPTS" ]; then
2423 MOUNT_OPTS="-o mgssec=ska"
2425 MOUNT_OPTS="$MOUNT_OPTS,mgssec=ska"
2427 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2428 error "mount ${clients_arr[0]} with mgssec=ska failed"
2429 MOUNT_OPTS=$save_opts
2433 run_test 32 "check for mgssec"
2436 # disable sk flavor enforcement
2437 set_rule $FSNAME any cli2mdt null
2438 wait_flavor cli2mdt null
2441 zconf_umount_clients ${clients_arr[0]} $MOUNT
2443 # stop gss daemon on MGS
2444 if ! combined_mgs_mds ; then
2445 send_sigint $mgs_HOST lsvcgssd
2449 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
2452 restore_to_default_flavor
2456 if ! $SHARED_KEY; then
2457 skip "need shared key feature for this test"
2460 stack_trap cleanup_33 EXIT
2462 # restore to default null flavor
2463 save_flvr=$SK_FLAVOR
2465 restore_to_default_flavor || error "cannot set null flavor"
2466 SK_FLAVOR=$save_flvr
2469 if [ "$MOUNT_2" ] && $(grep -q $MOUNT2' ' /proc/mounts); then
2470 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2472 if $(grep -q $MOUNT' ' /proc/mounts); then
2473 umount_client $MOUNT || error "umount $MOUNT failed"
2476 # start gss daemon on MGS
2477 if combined_mgs_mds ; then
2478 send_sigint $mds_HOST lsvcgssd
2480 start_gss_daemons $mgs_HOST "$LSVCGSSD -vvv -s -g"
2482 # add mgs key type and MGS NIDs in key on MGS
2483 do_nodes $mgs_HOST "lgss_sk -t mgs,server -g $MGSNID -m \
2484 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2485 error "could not modify keyfile on MGS"
2487 # load modified key file on MGS
2488 do_nodes $mgs_HOST "lgss_sk -l $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2489 error "could not load keyfile on MGS"
2491 # add MGS NIDs in key on client
2492 do_nodes ${clients_arr[0]} "lgss_sk -g $MGSNID -m \
2493 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2494 error "could not modify keyfile on MGS"
2496 # set perms for per-nodemap keys else permission denied
2497 do_nodes $(comma_list $(all_nodes)) \
2498 "keyctl show | grep lustre | cut -c1-11 |
2500 xargs -IX keyctl setperm X 0x3f3f3f3f"
2502 # re-mount client with mgssec=skn
2503 save_opts=$MOUNT_OPTS
2504 if [ -z "$MOUNT_OPTS" ]; then
2505 MOUNT_OPTS="-o mgssec=skn"
2507 MOUNT_OPTS="$MOUNT_OPTS,mgssec=skn"
2509 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2510 error "mount ${clients_arr[0]} with mgssec=skn failed"
2511 MOUNT_OPTS=$save_opts
2513 # enforce ska flavor for cli2mdt
2514 set_rule $FSNAME any cli2mdt ska
2515 wait_flavor cli2mdt ska
2517 # check error message
2518 $LCTL dk | grep "faked source" &&
2519 error "MGS connection srpc flags incorrect"
2523 run_test 33 "correct srpc flags for MGS connection"
2526 # restore deny_unknown
2527 do_facet mgs $LCTL nodemap_modify --name default \
2528 --property deny_unknown --value $denydefault
2529 if [ $? -ne 0 ]; then
2530 error_noexit "cannot reset deny_unknown on default nodemap"
2534 wait_nm_sync default deny_unknown
2541 [ $MGS_VERSION -lt $(version_code 2.12.51) ] &&
2542 skip "deny_unknown on default nm not supported before 2.12.51"
2544 activedefault=$(do_facet mgs $LCTL get_param -n nodemap.active)
2546 if [[ "$activedefault" != "1" ]]; then
2547 do_facet mgs $LCTL nodemap_activate 1
2549 stack_trap cleanup_active EXIT
2552 denydefault=$(do_facet mgs $LCTL get_param -n \
2553 nodemap.default.deny_unknown)
2554 [ -z "$denydefault" ] &&
2555 error "cannot get deny_unknown on default nodemap"
2556 if [ "$denydefault" -eq 0 ]; then
2562 do_facet mgs $LCTL nodemap_modify --name default \
2563 --property deny_unknown --value $denynew ||
2564 error "cannot set deny_unknown on default nodemap"
2566 [ "$(do_facet mgs $LCTL get_param -n nodemap.default.deny_unknown)" \
2568 error "setting deny_unknown on default nodemap did not work"
2570 stack_trap cleanup_34_deny EXIT
2572 wait_nm_sync default deny_unknown
2574 run_test 34 "deny_unknown on default nodemap"
2577 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.13.50) ] ||
2578 skip "Need MDS >= 2.13.50"
2580 # activate changelogs
2581 changelog_register || error "changelog_register failed"
2582 local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
2583 changelog_users $SINGLEMDS | grep -q $cl_user ||
2584 error "User $cl_user not found in changelog_users"
2585 changelog_chmask ALL
2588 mkdir $DIR/$tdir || error "failed to mkdir $tdir"
2589 touch $DIR/$tdir/$tfile || error "failed to touch $tfile"
2591 # access changelogs with root
2592 changelog_dump || error "failed to dump changelogs"
2593 changelog_clear 0 || error "failed to clear changelogs"
2595 # put clients in non-admin nodemap
2597 stack_trap nodemap_test_cleanup EXIT
2598 for i in $(seq 0 $((num_clients-1))); do
2599 do_facet mgs $LCTL nodemap_modify --name c${i} \
2600 --property admin --value 0
2602 for i in $(seq 0 $((num_clients-1))); do
2603 wait_nm_sync c${i} admin_nodemap
2606 # access with mapped root
2607 changelog_dump && error "dump changelogs should have failed"
2608 changelog_clear 0 && error "clear changelogs should have failed"
2612 run_test 35 "Check permissions when accessing changelogs"
2614 setup_for_enc_tests() {
2615 # remount client with test_dummy_encryption option
2616 if is_mounted $MOUNT; then
2617 umount_client $MOUNT || error "umount $MOUNT failed"
2619 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption ||
2620 error "mount with '-o test_dummy_encryption' failed"
2622 # this directory will be encrypted, because of dummy mode
2626 cleanup_for_enc_tests() {
2627 # remount client normally
2628 if is_mounted $MOUNT; then
2629 umount_client $MOUNT || error "umount $MOUNT failed"
2631 mount_client $MOUNT ${MOUNT_OPTS} ||
2632 error "remount failed"
2634 if is_mounted $MOUNT2; then
2635 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2637 if [ "$MOUNT_2" ]; then
2638 mount_client $MOUNT2 ${MOUNT_OPTS} ||
2639 error "remount failed"
2643 cleanup_nodemap_after_enc_tests() {
2644 do_facet mgs $LCTL nodemap_modify --name default \
2645 --property forbid_encryption --value 0
2646 wait_nm_sync default forbid_encryption
2647 do_facet mgs $LCTL nodemap_activate 0
2652 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2653 skip "client encryption not supported"
2655 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2656 skip "need dummy encryption support"
2658 stack_trap cleanup_for_enc_tests EXIT
2660 # first make sure it is possible to enable encryption
2661 # when nodemap is not active
2664 umount_client $MOUNT || error "umount $MOUNT failed (1)"
2666 # then activate nodemap, and retry
2667 # should succeed as encryption is not forbidden on default nodemap
2669 stack_trap cleanup_nodemap_after_enc_tests EXIT
2670 do_facet mgs $LCTL nodemap_activate 1
2672 forbid=$(do_facet mgs lctl get_param -n nodemap.default.forbid_encryption)
2673 [ $forbid -eq 0 ] || error "wrong default value for forbid_encryption"
2674 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption ||
2675 error "mount '-o test_dummy_encryption' failed with default"
2676 umount_client $MOUNT || error "umount $MOUNT failed (2)"
2678 # then forbid encryption, and retry
2679 do_facet mgs $LCTL nodemap_modify --name default \
2680 --property forbid_encryption --value 1
2681 wait_nm_sync default forbid_encryption
2682 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption &&
2683 error "mount '-o test_dummy_encryption' should have failed"
2686 run_test 36 "control if clients can use encryption"
2689 local testfile=$DIR/$tdir/$tfile
2690 local tmpfile=$TMP/abc
2691 local objdump=$TMP/objdump
2694 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2695 skip "client encryption not supported"
2697 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2698 skip "need dummy encryption support"
2700 [ "$ost1_FSTYPE" = ldiskfs ] || skip "ldiskfs only test (using debugfs)"
2702 stack_trap cleanup_for_enc_tests EXIT
2705 # write a few bytes in file
2706 echo "abc" > $tmpfile
2707 $LFS setstripe -c1 -i0 $testfile
2708 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2709 do_facet ost1 "sync; sync"
2711 # check that content on ost is encrypted
2712 objid=$($LFS getstripe $testfile | awk '/obdidx/{getline; print $2}')
2713 do_facet ost1 "$DEBUGFS -c -R 'cat O/0/d$(($objid % 32))/$objid' \
2714 $(ostdevname 1)" > $objdump
2715 cmp -s $objdump $tmpfile &&
2716 error "file $testfile is not encrypted on ost"
2718 # check that in-memory representation of file is correct
2719 cmp -bl ${tmpfile} ${testfile} ||
2720 error "file $testfile is corrupted in memory"
2722 cancel_lru_locks osc ; cancel_lru_locks mdc
2724 # check that file read from server is correct
2725 cmp -bl ${tmpfile} ${testfile} ||
2726 error "file $testfile is corrupted on server"
2728 rm -f $tmpfile $objdump
2730 run_test 37 "simple encrypted file"
2733 local testfile=$DIR/$tdir/$tfile
2734 local tmpfile=$TMP/abc
2740 local pagesz=$(getconf PAGE_SIZE)
2742 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2743 skip "client encryption not supported"
2745 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2746 skip "need dummy encryption support"
2748 stack_trap cleanup_for_enc_tests EXIT
2751 # get block size on ost
2752 blksz=$($LCTL get_param osc.$FSNAME*.import |
2753 awk '/grant_block_size:/ { print $2; exit; }')
2754 # write a few bytes in file at offset $blksz
2755 echo "abc" > $tmpfile
2756 $LFS setstripe -c1 -i0 $testfile
2757 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$blksz \
2758 oflag=seek_bytes conv=fsync
2760 blksz=$(($blksz > $pagesz ? $blksz : $pagesz))
2761 # check that in-memory representation of file is correct
2762 bsize=$(stat --format=%B $testfile)
2763 filesz=$(stat --format=%b $testfile)
2764 filesz=$((filesz*bsize))
2765 [ $filesz -le $blksz ] ||
2766 error "file $testfile is $filesz long in memory"
2768 cancel_lru_locks osc ; cancel_lru_locks mdc
2770 # check that file read from server is correct
2771 bsize=$(stat --format=%B $testfile)
2772 filesz=$(stat --format=%b $testfile)
2773 filesz=$((filesz*bsize))
2774 [ $filesz -le $blksz ] ||
2775 error "file $testfile is $filesz long on server"
2779 run_test 38 "encrypted file with hole"
2782 local testfile=$DIR/$tdir/$tfile
2783 local tmpfile=$TMP/abc
2785 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2786 skip "client encryption not supported"
2788 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2789 skip "need dummy encryption support"
2791 stack_trap cleanup_for_enc_tests EXIT
2794 # write a few bytes in file
2795 echo "abc" > $tmpfile
2796 $LFS setstripe -c1 -i0 $testfile
2797 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2799 # write a few more bytes in the same page
2800 dd if=$tmpfile of=$testfile bs=4 count=1 seek=1024 oflag=seek_bytes \
2803 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=1024 oflag=seek_bytes \
2806 # check that in-memory representation of file is correct
2807 cmp -bl $tmpfile $testfile ||
2808 error "file $testfile is corrupted in memory"
2810 cancel_lru_locks osc ; cancel_lru_locks mdc
2812 # check that file read from server is correct
2813 cmp -bl $tmpfile $testfile ||
2814 error "file $testfile is corrupted on server"
2818 run_test 39 "rewrite data in already encrypted page"
2821 local testfile=$DIR/$tdir/$tfile
2822 local tmpfile=$TMP/abc
2823 local tmpfile2=$TMP/abc2
2826 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2827 skip "client encryption not supported"
2829 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2830 skip "need dummy encryption support"
2832 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2834 stack_trap cleanup_for_enc_tests EXIT
2837 # write a few bytes in file
2838 echo "abc" > $tmpfile
2839 $LFS setstripe -c1 -i0 $testfile
2840 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2842 # check that in-memory representation of file is correct
2843 cmp -bl $tmpfile $testfile ||
2844 error "file $testfile is corrupted in memory (1)"
2846 cancel_lru_locks osc ; cancel_lru_locks mdc
2848 # check that file read from server is correct
2849 cmp -bl $tmpfile $testfile ||
2850 error "file $testfile is corrupted on server (1)"
2852 # write a few other bytes in same page
2853 dd if=$tmpfile of=$testfile bs=4 count=1 seek=256 oflag=seek_bytes \
2856 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=256 oflag=seek_bytes \
2859 # check that in-memory representation of file is correct
2860 cmp -bl $tmpfile $testfile ||
2861 error "file $testfile is corrupted in memory (2)"
2863 cancel_lru_locks osc ; cancel_lru_locks mdc
2865 # check that file read from server is correct
2866 cmp -bl $tmpfile $testfile ||
2867 error "file $testfile is corrupted on server (2)"
2869 rm -f $testfile $tmpfile
2870 cancel_lru_locks osc ; cancel_lru_locks mdc
2872 # write a few bytes in file, at end of first page
2873 echo "abc" > $tmpfile
2874 $LFS setstripe -c1 -i0 $testfile
2875 seek=$(getconf PAGESIZE)
2877 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2880 # write a few other bytes at beginning of first page
2881 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync,notrunc
2883 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2886 # check that in-memory representation of file is correct
2887 cmp -bl $tmpfile $testfile ||
2888 error "file $testfile is corrupted in memory (3)"
2890 cancel_lru_locks osc ; cancel_lru_locks mdc
2892 # check that file read from server is correct
2893 cmp -bl $tmpfile $testfile ||
2894 error "file $testfile is corrupted on server (3)"
2896 rm -f $testfile $tmpfile
2897 cancel_lru_locks osc ; cancel_lru_locks mdc
2899 # write a few bytes in file, at beginning of second page
2900 echo "abc" > $tmpfile
2901 $LFS setstripe -c1 -i0 $testfile
2902 seek=$(getconf PAGESIZE)
2903 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2905 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
2908 # write a few other bytes at end of first page
2910 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2912 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
2915 # check that in-memory representation of file is correct
2916 cmp -bl $tmpfile2 $testfile ||
2917 error "file $testfile is corrupted in memory (4)"
2919 cancel_lru_locks osc ; cancel_lru_locks mdc
2921 # check that file read from server is correct
2922 cmp -bl $tmpfile2 $testfile ||
2923 error "file $testfile is corrupted on server (4)"
2925 rm -f $testfile $tmpfile $tmpfile2
2926 cancel_lru_locks osc ; cancel_lru_locks mdc
2928 # write a few bytes in file, at beginning of first stripe
2929 echo "abc" > $tmpfile
2930 $LFS setstripe -S 256k -c2 $testfile
2931 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync,notrunc
2933 # write a few other bytes, at beginning of second stripe
2934 dd if=$tmpfile of=$testfile bs=4 count=1 seek=262144 oflag=seek_bytes \
2936 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=262144 oflag=seek_bytes \
2939 # check that in-memory representation of file is correct
2940 cmp -bl $tmpfile $testfile ||
2941 error "file $testfile is corrupted in memory (5)"
2943 cancel_lru_locks osc ; cancel_lru_locks mdc
2945 # check that file read from server is correct
2946 cmp -bl $tmpfile $testfile ||
2947 error "file $testfile is corrupted on server (5)"
2951 run_test 40 "exercise size of encrypted file"
2954 local testfile=$DIR/$tdir/$tfile
2955 local tmpfile=$TMP/abc
2956 local tmpfile2=$TMP/abc2
2959 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2960 skip "client encryption not supported"
2962 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2963 skip "need dummy encryption support"
2965 stack_trap cleanup_for_enc_tests EXIT
2968 echo "abc" > $tmpfile
2969 seek=$(getconf PAGESIZE)
2970 seek=$((seek - 204))
2971 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
2973 seek=$(getconf PAGESIZE)
2974 seek=$((seek + 1092))
2975 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
2978 # write a few bytes in file
2979 $LFS setstripe -c1 -i0 -S 256k $testfile
2980 seek=$(getconf PAGESIZE)
2981 seek=$((seek - 204))
2982 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
2983 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
2984 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2988 # write a few other bytes, at a different offset
2989 seek=$(getconf PAGESIZE)
2990 seek=$((seek + 1092))
2991 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2992 conv=fsync,notrunc &
2994 do_facet ost1 "$LCTL set_param fail_loc=0x0"
2996 # check that in-memory representation of file is correct
2997 cmp -bl $tmpfile2 $testfile ||
2998 error "file $testfile is corrupted in memory (1)"
3000 cancel_lru_locks osc ; cancel_lru_locks mdc
3002 # check that file read from server is correct
3003 cmp -bl $tmpfile2 $testfile ||
3004 error "file $testfile is corrupted on server (1)"
3006 rm -f $tmpfile $tmpfile2
3008 run_test 41 "test race on encrypted file size (1)"
3011 local testfile=$DIR/$tdir/$tfile
3012 local testfile2=$DIR2/$tdir/$tfile
3013 local tmpfile=$TMP/abc
3014 local tmpfile2=$TMP/abc2
3015 local pagesz=$(getconf PAGESIZE)
3018 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3019 skip "client encryption not supported"
3021 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3022 skip "need dummy encryption support"
3024 stack_trap cleanup_for_enc_tests EXIT
3027 if is_mounted $MOUNT2; then
3028 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
3030 mount_client $MOUNT2 ${MOUNT_OPTS},test_dummy_encryption ||
3031 error "mount2 with '-o test_dummy_encryption' failed"
3033 # create file by writting one whole page
3034 $LFS setstripe -c1 -i0 -S 256k $testfile
3035 dd if=/dev/zero of=$testfile bs=$pagesz count=1 conv=fsync
3037 # read file from 2nd mount point
3038 cat $testfile2 > /dev/null
3040 echo "abc" > $tmpfile
3041 dd if=/dev/zero of=$tmpfile2 bs=$pagesz count=1 conv=fsync
3042 seek=$((2*pagesz - 204))
3043 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3045 seek=$((2*pagesz + 1092))
3046 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3049 # write a few bytes in file from 1st mount point
3050 seek=$((2*pagesz - 204))
3051 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
3052 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
3053 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3054 conv=fsync,notrunc &
3057 # write a few other bytes, at a different offset from 2nd mount point
3058 seek=$((2*pagesz + 1092))
3059 dd if=$tmpfile of=$testfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3060 conv=fsync,notrunc &
3062 do_facet ost1 "$LCTL set_param fail_loc=0x0"
3064 # check that in-memory representation of file is correct
3065 cmp -bl $tmpfile2 $testfile ||
3066 error "file $testfile is corrupted in memory (1)"
3068 # check that in-memory representation of file is correct
3069 cmp -bl $tmpfile2 $testfile2 ||
3070 error "file $testfile is corrupted in memory (2)"
3072 cancel_lru_locks osc ; cancel_lru_locks mdc
3074 # check that file read from server is correct
3075 cmp -bl $tmpfile2 $testfile ||
3076 error "file $testfile is corrupted on server (1)"
3078 rm -f $tmpfile $tmpfile2
3080 run_test 42 "test race on encrypted file size (2)"
3083 local testfile=$DIR/$tdir/$tfile
3084 local testfile2=$DIR2/$tdir/$tfile
3085 local tmpfile=$TMP/abc
3086 local tmpfile2=$TMP/abc2
3087 local resfile=$TMP/res
3088 local pagesz=$(getconf PAGESIZE)
3091 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3092 skip "client encryption not supported"
3094 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3095 skip "need dummy encryption support"
3097 stack_trap cleanup_for_enc_tests EXIT
3100 if is_mounted $MOUNT2; then
3101 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
3103 mount_client $MOUNT2 ${MOUNT_OPTS},test_dummy_encryption ||
3104 error "mount2 with '-o test_dummy_encryption' failed"
3107 tr '\0' '1' < /dev/zero |
3108 dd of=$tmpfile bs=1 count=$pagesz conv=fsync
3109 $LFS setstripe -c1 -i0 -S 256k $testfile
3110 cp $tmpfile $testfile
3112 # read file from 2nd mount point
3113 cat $testfile2 > /dev/null
3115 # write a few bytes in file from 1st mount point
3116 echo "abc" > $tmpfile2
3117 seek=$((2*pagesz - 204))
3118 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
3119 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
3120 dd if=$tmpfile2 of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3121 conv=fsync,notrunc &
3124 # read file from 2nd mount point
3125 dd if=$testfile2 of=$resfile bs=$pagesz count=1 conv=fsync,notrunc
3126 cmp -bl $tmpfile $resfile ||
3127 error "file $testfile is corrupted in memory (1)"
3130 do_facet ost1 "$LCTL set_param fail_loc=0x0"
3132 # check that in-memory representation of file is correct
3133 dd if=$tmpfile2 of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3135 cmp -bl $tmpfile $testfile2 ||
3136 error "file $testfile is corrupted in memory (2)"
3138 cancel_lru_locks osc ; cancel_lru_locks mdc
3140 # check that file read from server is correct
3141 cmp -bl $tmpfile $testfile ||
3142 error "file $testfile is corrupted on server (1)"
3144 rm -f $tmpfile $tmpfile2
3146 run_test 43 "test race on encrypted file size (3)"
3149 local testfile=$DIR/$tdir/$tfile
3150 local tmpfile=$TMP/abc
3151 local resfile=$TMP/resfile
3152 local pagesz=$(getconf PAGESIZE)
3155 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3156 skip "client encryption not supported"
3158 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3159 skip "need dummy encryption support"
3161 which vmtouch || skip "This test needs vmtouch utility"
3163 # Direct I/O is now supported on encrypted files.
3165 stack_trap cleanup_for_enc_tests EXIT
3168 $LFS setstripe -c1 -i0 $testfile
3169 dd if=/dev/urandom of=$tmpfile bs=$pagesz count=2 conv=fsync
3170 dd if=$tmpfile of=$testfile bs=$pagesz count=2 oflag=direct ||
3171 error "could not write to file with O_DIRECT (1)"
3173 respage=$(vmtouch $testfile | awk '/Resident Pages:/ {print $3}')
3174 [ "$respage" == "0/2" ] ||
3175 error "write to enc file fell back to buffered IO"
3179 dd if=$testfile of=$resfile bs=$pagesz count=2 iflag=direct ||
3180 error "could not read from file with O_DIRECT (1)"
3182 respage=$(vmtouch $testfile | awk '/Resident Pages:/ {print $3}')
3183 [ "$respage" == "0/2" ] ||
3184 error "read from enc file fell back to buffered IO"
3186 cmp -bl $tmpfile $resfile ||
3187 error "file $testfile is corrupted (1)"
3191 $TRUNCATE $tmpfile $pagesz
3192 dd if=$tmpfile of=$testfile bs=$pagesz count=1 seek=13 oflag=direct ||
3193 error "could not write to file with O_DIRECT (2)"
3197 dd if=$testfile of=$resfile bs=$pagesz count=1 skip=13 iflag=direct ||
3198 error "could not read from file with O_DIRECT (2)"
3199 cmp -bl $tmpfile $resfile ||
3200 error "file $testfile is corrupted (2)"
3202 rm -f $testfile $resfile
3203 $LFS setstripe -c1 -i0 $testfile
3205 $TRUNCATE $tmpfile $((pagesz/2 - 5))
3206 cp $tmpfile $testfile
3210 dd if=$testfile of=$resfile bs=$pagesz count=1 iflag=direct ||
3211 error "could not read from file with O_DIRECT (3)"
3212 cmp -bl $tmpfile $resfile ||
3213 error "file $testfile is corrupted (3)"
3215 rm -f $tmpfile $resfile
3217 run_test 44 "encrypted file access semantics: direct IO"
3220 local testfile=$DIR/$tdir/$tfile
3221 local tmpfile=$TMP/junk
3223 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3224 skip "client encryption not supported"
3226 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3227 skip "need dummy encryption support"
3229 stack_trap cleanup_for_enc_tests EXIT
3232 $LFS setstripe -c1 -i0 $testfile
3233 dd if=/dev/zero of=$testfile bs=512K count=1
3234 $MULTIOP $testfile OSMRUc || error "$MULTIOP $testfile failed (1)"
3235 $MULTIOP $testfile OSMWUc || error "$MULTIOP $testfile failed (2)"
3237 dd if=/dev/zero of=$tmpfile bs=512K count=1
3238 $MULTIOP $tmpfile OSMWUc || error "$MULTIOP $tmpfile failed"
3239 $MMAP_CAT $tmpfile > ${tmpfile}2
3243 $MULTIOP $testfile OSMRUc
3244 $MMAP_CAT $testfile > ${testfile}2
3245 cmp -bl ${tmpfile}2 ${testfile}2 ||
3246 error "file $testfile is corrupted"
3248 rm -f $tmpfile ${tmpfile}2
3250 run_test 45 "encrypted file access semantics: MMAP"
3253 local testdir=$DIR/$tdir/mydir
3254 local testfile=$testdir/myfile
3255 local testdir2=$DIR/$tdir/mydirwithaveryverylongnametotestcodebehaviour0
3256 local testfile2=$testdir/myfilewithaveryverylongnametotestcodebehaviour0
3257 local lsfile=$TMP/lsfile
3261 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3262 skip "client encryption not supported"
3264 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3265 skip "need dummy encryption support"
3267 stack_trap cleanup_for_enc_tests EXIT
3270 touch $DIR/$tdir/$tfile
3272 echo test > $testfile
3273 echo othertest > $testfile2
3274 if [[ $MDSCOUNT -gt 1 ]]; then
3275 $LFS setdirstripe -c1 -i1 $testdir2
3279 sync ; echo 3 > /proc/sys/vm/drop_caches
3281 # remove fscrypt key from keyring
3282 keyctl revoke $(keyctl show | awk '$7 ~ "^fscrypt:" {print $1}')
3287 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d| grep _)
3288 stat $scrambleddir || error "stat $scrambleddir failed"
3289 rmdir $scrambleddir || error "rmdir $scrambleddir failed"
3291 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d)
3292 ls -1 $scrambleddir > $lsfile || error "ls $testdir failed (1)"
3294 scrambledfile=$scrambleddir/$(head -n 1 $lsfile)
3295 stat $scrambledfile || error "stat $scrambledfile failed (1)"
3298 cat $scrambledfile && error "cat $scrambledfile should have failed (1)"
3299 rm -f $scrambledfile || error "rm $scrambledfile failed (1)"
3301 ls -1 $scrambleddir > $lsfile || error "ls $testdir failed (2)"
3302 scrambledfile=$scrambleddir/$(head -n 1 $lsfile)
3303 stat $scrambledfile || error "stat $scrambledfile failed (2)"
3305 cat $scrambledfile && error "cat $scrambledfile should have failed (2)"
3307 touch $scrambleddir/otherfile &&
3308 error "touch otherfile should have failed"
3309 ls $scrambleddir/otherfile && error "otherfile should not exist"
3310 mkdir $scrambleddir/otherdir &&
3311 error "mkdir otherdir should have failed"
3312 ls -d $scrambleddir/otherdir && error "otherdir should not exist"
3315 rm -f $scrambledfile || error "rm $scrambledfile failed (2)"
3316 rmdir $scrambleddir || error "rmdir $scrambleddir failed"
3319 run_test 46 "encrypted file access semantics without key"
3322 local testfile=$DIR/$tdir/$tfile
3323 local testfile2=$DIR/$tdir/${tfile}.2
3324 local tmpfile=$DIR/junk
3328 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3329 skip "client encryption not supported"
3331 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3332 skip "need dummy encryption support"
3334 stack_trap cleanup_for_enc_tests EXIT
3337 dd if=/dev/urandom of=$tmpfile bs=512K count=1
3338 mrename $tmpfile $testfile &&
3339 error "rename from unencrypted to encrypted dir should fail"
3341 ln $tmpfile $testfile &&
3342 error "link from encrypted to unencrypted dir should fail"
3344 cp $tmpfile $testfile ||
3345 error "cp from unencrypted to encrypted dir should succeed"
3348 mrename $testfile $testfile2 ||
3349 error "rename from within encrypted dir should succeed"
3351 ln $testfile2 $testfile ||
3352 error "link from within encrypted dir should succeed"
3353 cmp -bl $testfile2 $testfile ||
3354 error "cannot read from hard link (1.1)"
3355 echo a >> $testfile || error "cannot write to hard link (1)"
3357 cmp -bl $testfile2 $testfile ||
3358 error "cannot read from hard link (1.2)"
3361 ln $testfile2 $tmpfile ||
3362 error "link from unencrypted to encrypted dir should succeed"
3364 cmp -bl $testfile2 $tmpfile ||
3365 error "cannot read from hard link (2.1)"
3366 echo a >> $tmpfile || error "cannot write to hard link (2)"
3368 cmp -bl $testfile2 $tmpfile ||
3369 error "cannot read from hard link (2.2)"
3372 # check we are limited in the number of hard links
3373 # we can create for encrypted files, to what can fit into LinkEA
3374 for i in $(seq 1 160); do
3375 ln $testfile2 ${testfile}_$i || break
3377 [ $i -lt 160 ] || error "hard link $i should fail"
3380 mrename $testfile2 $tmpfile &&
3381 error "rename from encrypted to unencrypted dir should fail"
3383 dd if=/dev/urandom of=$tmpfile bs=512K count=1
3385 dd if=/dev/urandom of=$testfile bs=512K count=1
3386 mkdir $DIR/$tdir/mydir
3388 ln -s $testfile ${testfile}.sym ||
3389 error "symlink from within encrypted dir should succeed"
3391 cmp -bl $testfile ${testfile}.sym ||
3392 error "cannot read from sym link (1.1)"
3393 echo a >> ${testfile}.sym || error "cannot write to sym link (1)"
3395 cmp -bl $testfile ${testfile}.sym ||
3396 error "cannot read from sym link (1.2)"
3397 [ $(stat -c %s ${testfile}.sym) -eq ${#testfile} ] ||
3398 error "wrong symlink size (1)"
3400 ln -s $tmpfile ${testfile}.sl ||
3401 error "symlink from encrypted to unencrypted dir should succeed"
3403 cmp -bl $tmpfile ${testfile}.sl ||
3404 error "cannot read from sym link (2.1)"
3405 echo a >> ${testfile}.sl || error "cannot write to sym link (2)"
3407 cmp -bl $tmpfile ${testfile}.sl ||
3408 error "cannot read from sym link (2.2)"
3409 [ $(stat -c %s ${testfile}.sl) -eq ${#tmpfile} ] ||
3410 error "wrong symlink size (2)"
3411 rm -f ${testfile}.sl
3413 sync ; echo 3 > /proc/sys/vm/drop_caches
3415 # remove fscrypt key from keyring
3416 keyctl revoke $(keyctl show | awk '$7 ~ "^fscrypt:" {print $1}')
3420 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d)
3421 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -type f)
3422 scrambledlink=$(find $DIR/$tdir/ -maxdepth 1 -type l)
3423 ln $scrambledfile $scrambleddir/linkfile &&
3424 error "ln linkfile should have failed"
3425 mrename $scrambledfile $DIR/onefile2 &&
3426 error "mrename from $scrambledfile should have failed"
3428 mrename $DIR/onefile $scrambleddir/otherfile &&
3429 error "mrename to $scrambleddir should have failed"
3430 readlink $scrambledlink ||
3431 error "link should be read without key"
3432 [ $(stat -c %s $scrambledlink) -eq \
3433 $(expr length "$(readlink $scrambledlink)") ] ||
3434 error "wrong symlink size without key"
3435 readlink -e $scrambledlink &&
3436 error "link should not point to anywhere useful"
3437 ln -s $scrambledfile ${scrambledfile}.sym &&
3438 error "symlink without key should fail (1)"
3439 ln -s $tmpfile ${scrambledfile}.sl &&
3440 error "symlink without key should fail (2)"
3442 rm -f $tmpfile $DIR/onefile
3444 run_test 47 "encrypted file access semantics: rename/link"
3447 local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
3448 local testfile=$DIR/$tdir/$tfile
3449 local tmpfile=$TMP/111
3450 local tmpfile2=$TMP/abc
3451 local pagesz=$(getconf PAGESIZE)
3456 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3457 skip "client encryption not supported"
3459 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3460 skip "need dummy encryption support"
3462 stack_trap cleanup_for_enc_tests EXIT
3465 # create file, 4 x PAGE_SIZE long
3466 tr '\0' '1' < /dev/zero |
3467 dd of=$tmpfile bs=1 count=4x$pagesz conv=fsync
3468 $LFS setstripe -c1 -i0 $testfile
3469 cp $tmpfile $testfile
3470 echo "abc" > $tmpfile2
3472 # decrease size: truncate to PAGE_SIZE
3473 $TRUNCATE $tmpfile $pagesz
3474 $TRUNCATE $testfile $pagesz
3475 cancel_lru_locks osc ; cancel_lru_locks mdc
3476 cmp -bl $tmpfile $testfile ||
3477 error "file $testfile is corrupted (1)"
3479 # increase size: truncate to 2 x PAGE_SIZE
3481 $TRUNCATE $tmpfile $sz
3482 $TRUNCATE $testfile $sz
3483 cancel_lru_locks osc ; cancel_lru_locks mdc
3484 cmp -bl $tmpfile $testfile ||
3485 error "file $testfile is corrupted (2)"
3488 seek=$((pagesz+100))
3489 dd if=$tmpfile2 of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3491 dd if=$tmpfile2 of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3493 cancel_lru_locks osc ; cancel_lru_locks mdc
3494 cmp -bl $tmpfile $testfile ||
3495 error "file $testfile is corrupted (3)"
3497 # truncate to PAGE_SIZE / 2
3499 $TRUNCATE $tmpfile $sz
3500 $TRUNCATE $testfile $sz
3501 cancel_lru_locks osc ; cancel_lru_locks mdc
3502 cmp -bl $tmpfile $testfile ||
3503 error "file $testfile is corrupted (4)"
3505 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16
3507 $TRUNCATE $tmpfile $sz
3508 $TRUNCATE $testfile $sz
3509 cancel_lru_locks osc ; cancel_lru_locks mdc
3510 cmp -bl $tmpfile $testfile ||
3511 error "file $testfile is corrupted (5)"
3513 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16
3515 $TRUNCATE $tmpfile $sz
3516 $TRUNCATE $testfile $sz
3517 cancel_lru_locks osc ; cancel_lru_locks mdc
3518 cmp -bl $tmpfile $testfile ||
3519 error "file $testfile is corrupted (6)"
3521 # truncate to a larger, non-multiple of PAGE_SIZE, in a different page
3522 sz=$((sz+pagesz+30))
3523 $TRUNCATE $tmpfile $sz
3524 $TRUNCATE $testfile $sz
3525 cancel_lru_locks osc ; cancel_lru_locks mdc
3526 cmp -bl $tmpfile $testfile ||
3527 error "file $testfile is corrupted (7)"
3529 sync ; echo 3 > /proc/sys/vm/drop_caches
3531 # remove fscrypt key from keyring
3532 keyctl revoke $(keyctl show | awk '$7 ~ "^fscrypt:" {print $1}')
3535 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -type f)
3536 $TRUNCATE $scrambledfile 0 &&
3537 error "truncate $scrambledfile should have failed without key"
3539 rm -f $tmpfile $tmpfile2
3541 run_test 48a "encrypted file access semantics: truncate"
3543 cleanup_for_enc_tests_othercli() {
3546 # remount othercli normally
3547 zconf_umount $othercli $MOUNT ||
3548 error "umount $othercli $MOUNT failed"
3549 zconf_mount $othercli $MOUNT ||
3550 error "remount $othercli $MOUNT failed"
3556 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3557 skip "client encryption not supported"
3559 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3560 skip "need dummy encryption support"
3562 [ "$num_clients" -ge 2 ] || skip "Need at least 2 clients"
3564 if [ "$HOSTNAME" == ${clients_arr[0]} ]; then
3565 othercli=${clients_arr[1]}
3567 othercli=${clients_arr[0]}
3570 stack_trap cleanup_for_enc_tests EXIT
3571 stack_trap "cleanup_for_enc_tests_othercli $othercli" EXIT
3573 zconf_umount $othercli $MOUNT ||
3574 error "umount $othercli $MOUNT failed"
3576 cp /bin/sleep $DIR/$tdir/
3577 cancel_lru_locks osc ; cancel_lru_locks mdc
3578 $DIR/$tdir/sleep 30 &
3579 # mount and IOs must be done in the same shell session, otherwise
3580 # encryption key in session keyring is missing
3581 do_node $othercli "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
3582 $MGSNID:/$FSNAME $MOUNT && \
3583 $TRUNCATE $DIR/$tdir/sleep 7"
3584 wait || error "wait error"
3585 cmp --silent /bin/sleep $DIR/$tdir/sleep ||
3586 error "/bin/sleep and $DIR/$tdir/sleep differ"
3588 run_test 48b "encrypted file: concurrent truncate"
3592 local xattr_name="security.c"
3595 $LCTL set_param debug=+info
3600 [ $? -eq 0 ] || error "$cmd failed"
3602 $LCTL dk | grep -E "get xattr '${xattr_name}'|get xattrs"
3603 [ $? -ne 0 ] || error "get xattr event was triggered"
3607 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3608 skip "client encryption not supported"
3610 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3611 skip "need dummy encryption support"
3613 stack_trap cleanup_for_enc_tests EXIT
3616 local dirname=$DIR/$tdir/subdir
3620 trace_cmd stat $dirname
3621 trace_cmd touch $dirname/f1
3622 trace_cmd stat $dirname/f1
3623 trace_cmd cat $dirname/f1
3624 dd if=/dev/zero of=$dirname/f1 bs=1M count=10 conv=fsync
3625 trace_cmd $TRUNCATE $dirname/f1 10240
3626 trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
3627 trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
3629 if [[ $MDSCOUNT -gt 1 ]]; then
3630 trace_cmd $LFS setdirstripe -i 1 $dirname/d2
3631 trace_cmd $LFS migrate -m 0 $dirname/d2
3632 touch $dirname/d2/subf
3633 # migrate a non-empty encrypted dir
3634 trace_cmd $LFS migrate -m 1 $dirname/d2
3636 $LFS setdirstripe -i 1 -c 1 $dirname/d3
3637 dirname=$dirname/d3/subdir
3640 trace_cmd stat $dirname
3641 trace_cmd touch $dirname/f1
3642 trace_cmd stat $dirname/f1
3643 trace_cmd cat $dirname/f1
3644 dd if=/dev/zero of=$dirname/f1 bs=1M count=10 conv=fsync
3645 trace_cmd $TRUNCATE $dirname/f1 10240
3646 trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
3647 trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
3649 skip_noexit "2nd part needs >= 2 MDTs"
3652 run_test 49 "Avoid getxattr for encryption context"
3655 local testfile=$DIR/$tdir/$tfile
3656 local tmpfile=$TMP/abc
3657 local pagesz=$(getconf PAGESIZE)
3660 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3661 skip "client encryption not supported"
3663 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3664 skip "need dummy encryption support"
3666 stack_trap cleanup_for_enc_tests EXIT
3669 # write small file, data on MDT only
3670 tr '\0' '1' < /dev/zero |
3671 dd of=$tmpfile bs=1 count=5000 conv=fsync
3672 $LFS setstripe -E 1M -L mdt -E EOF $testfile
3673 cp $tmpfile $testfile
3675 # check that in-memory representation of file is correct
3676 cmp -bl $tmpfile $testfile ||
3677 error "file $testfile is corrupted in memory"
3679 cancel_lru_locks osc ; cancel_lru_locks mdc
3681 # check that file read from server is correct
3682 cmp -bl $tmpfile $testfile ||
3683 error "file $testfile is corrupted on server"
3685 # decrease size: truncate to PAGE_SIZE
3686 $TRUNCATE $tmpfile $pagesz
3687 $TRUNCATE $testfile $pagesz
3688 cancel_lru_locks osc ; cancel_lru_locks mdc
3689 cmp -bl $tmpfile $testfile ||
3690 error "file $testfile is corrupted (1)"
3692 # increase size: truncate to 2 x PAGE_SIZE
3694 $TRUNCATE $tmpfile $sz
3695 $TRUNCATE $testfile $sz
3696 cancel_lru_locks osc ; cancel_lru_locks mdc
3697 cmp -bl $tmpfile $testfile ||
3698 error "file $testfile is corrupted (2)"
3700 # truncate to PAGE_SIZE / 2
3702 $TRUNCATE $tmpfile $sz
3703 $TRUNCATE $testfile $sz
3704 cancel_lru_locks osc ; cancel_lru_locks mdc
3705 cmp -bl $tmpfile $testfile ||
3706 error "file $testfile is corrupted (3)"
3708 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16
3710 $TRUNCATE $tmpfile $sz
3711 $TRUNCATE $testfile $sz
3712 cancel_lru_locks osc ; cancel_lru_locks mdc
3713 cmp -bl $tmpfile $testfile ||
3714 error "file $testfile is corrupted (4)"
3716 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16
3718 $TRUNCATE $tmpfile $sz
3719 $TRUNCATE $testfile $sz
3720 cancel_lru_locks osc ; cancel_lru_locks mdc
3721 cmp -bl $tmpfile $testfile ||
3722 error "file $testfile is corrupted (5)"
3724 # truncate to a larger, non-multiple of PAGE_SIZE, in a different page
3725 sz=$((sz+pagesz+30))
3726 $TRUNCATE $tmpfile $sz
3727 $TRUNCATE $testfile $sz
3728 cancel_lru_locks osc ; cancel_lru_locks mdc
3729 cmp -bl $tmpfile $testfile ||
3730 error "file $testfile is corrupted (6)"
3733 cancel_lru_locks osc ; cancel_lru_locks mdc
3735 # write hole in file, data spread on MDT and OST
3736 tr '\0' '2' < /dev/zero |
3737 dd of=$tmpfile bs=1 count=1539 seek=1539074 conv=fsync,notrunc
3738 $LFS setstripe -E 1M -L mdt -E EOF $testfile
3739 cp --sparse=always $tmpfile $testfile
3741 # check that in-memory representation of file is correct
3742 cmp -bl $tmpfile $testfile ||
3743 error "file $testfile is corrupted in memory"
3745 cancel_lru_locks osc ; cancel_lru_locks mdc
3747 # check that file read from server is correct
3748 cmp -bl $tmpfile $testfile ||
3749 error "file $testfile is corrupted on server"
3751 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16,
3752 # inside OST part of data
3753 sz=$((1024*1024+13))
3754 $TRUNCATE $tmpfile $sz
3755 $TRUNCATE $testfile $sz
3756 cancel_lru_locks osc ; cancel_lru_locks mdc
3757 cmp -bl $tmpfile $testfile ||
3758 error "file $testfile is corrupted (7)"
3760 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16,
3761 # inside MDT part of data
3763 $TRUNCATE $tmpfile $sz
3764 $TRUNCATE $testfile $sz
3765 cancel_lru_locks osc ; cancel_lru_locks mdc
3766 cmp -bl $tmpfile $testfile ||
3767 error "file $testfile is corrupted (8)"
3769 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16,
3770 # inside MDT part of data
3771 sz=$((1024*1024-13))
3772 $TRUNCATE $tmpfile $sz
3773 $TRUNCATE $testfile $sz
3774 cancel_lru_locks osc ; cancel_lru_locks mdc
3775 cmp -bl $tmpfile $testfile ||
3776 error "file $testfile is corrupted (9)"
3778 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16,
3779 # inside OST part of data
3781 $TRUNCATE $tmpfile $sz
3782 $TRUNCATE $testfile $sz
3783 cancel_lru_locks osc ; cancel_lru_locks mdc
3784 cmp -bl $tmpfile $testfile ||
3785 error "file $testfile is corrupted (10)"
3789 run_test 50 "DoM encrypted file"
3792 [ "$MDS1_VERSION" -gt $(version_code 2.13.53) ] ||
3793 skip "Need MDS version at least 2.13.53"
3795 mkdir $DIR/$tdir || error "mkdir $tdir"
3797 touch $DIR/$tdir/$tfile || error "touch $tfile"
3798 cp $(which chown) $DIR/$tdir || error "cp chown"
3799 $RUNAS_CMD -u $ID0 $DIR/$tdir/chown $ID0 $DIR/$tdir/$tfile &&
3800 error "chown $tfile should fail"
3801 setcap 'CAP_CHOWN=ep' $DIR/$tdir/chown || error "setcap CAP_CHOWN"
3802 $RUNAS_CMD -u $ID0 $DIR/$tdir/chown $ID0 $DIR/$tdir/$tfile ||
3803 error "chown $tfile"
3804 rm $DIR/$tdir/$tfile || error "rm $tfile"
3806 touch $DIR/$tdir/$tfile || error "touch $tfile"
3807 cp $(which touch) $DIR/$tdir || error "cp touch"
3808 $RUNAS_CMD -u $ID0 $DIR/$tdir/touch $DIR/$tdir/$tfile &&
3809 error "touch should fail"
3810 setcap 'CAP_FOWNER=ep' $DIR/$tdir/touch || error "setcap CAP_FOWNER"
3811 $RUNAS_CMD -u $ID0 $DIR/$tdir/touch $DIR/$tdir/$tfile ||
3812 error "touch $tfile"
3813 rm $DIR/$tdir/$tfile || error "rm $tfile"
3816 for cap in "CAP_DAC_OVERRIDE" "CAP_DAC_READ_SEARCH"; do
3817 touch $DIR/$tdir/$tfile || error "touch $tfile"
3818 chmod 600 $DIR/$tdir/$tfile || error "chmod $tfile"
3819 cp $(which cat) $DIR/$tdir || error "cp cat"
3820 $RUNAS_CMD -u $ID0 $DIR/$tdir/cat $DIR/$tdir/$tfile &&
3821 error "cat should fail"
3822 setcap $cap=ep $DIR/$tdir/cat || error "setcap $cap"
3823 $RUNAS_CMD -u $ID0 $DIR/$tdir/cat $DIR/$tdir/$tfile ||
3825 rm $DIR/$tdir/$tfile || error "rm $tfile"
3828 run_test 51 "FS capabilities ==============="
3831 local testfile=$DIR/$tdir/$tfile
3832 local tmpfile=$TMP/$tfile
3833 local mirror1=$TMP/$tfile.mirror1
3834 local mirror2=$TMP/$tfile.mirror2
3836 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3837 skip "client encryption not supported"
3839 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3840 skip "need dummy encryption support"
3842 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
3844 stack_trap cleanup_for_enc_tests EXIT
3847 dd if=/dev/urandom of=$tmpfile bs=5000 count=1 conv=fsync
3849 $LFS mirror create -N -i0 -N -i1 $testfile ||
3850 error "could not create mirror"
3852 dd if=$tmpfile of=$testfile bs=5000 count=1 conv=fsync ||
3853 error "could not write to $testfile"
3855 $LFS mirror resync $testfile ||
3856 error "could not resync mirror"
3858 $LFS mirror verify -v $testfile ||
3859 error "verify mirror failed"
3861 $LFS mirror read -N 1 -o $mirror1 $testfile ||
3862 error "could not read from mirror 1"
3864 cmp -bl $tmpfile $mirror1 ||
3865 error "mirror 1 is corrupted"
3867 $LFS mirror read -N 2 -o $mirror2 $testfile ||
3868 error "could not read from mirror 2"
3870 cmp -bl $tmpfile $mirror2 ||
3871 error "mirror 2 is corrupted"
3873 tr '\0' '2' < /dev/zero |
3874 dd of=$tmpfile bs=1 count=9000 conv=fsync
3876 $LFS mirror write -N 1 -i $tmpfile $testfile ||
3877 error "could not write to mirror 1"
3879 $LFS mirror verify -v $testfile &&
3880 error "mirrors should be different"
3882 rm -f $testfile $mirror1 $mirror2
3884 $LFS setstripe -c1 -i0 $testfile
3885 dd if=$tmpfile of=$testfile bs=9000 count=1 conv=fsync ||
3886 error "write to $testfile failed"
3887 $LFS getstripe $testfile
3890 $LFS migrate -i1 $testfile ||
3891 error "migrate $testfile failed"
3892 $LFS getstripe $testfile
3893 stripe=$($LFS getstripe -i $testfile)
3894 [ $stripe -eq 1 ] || error "migrate file $testfile failed"
3897 cmp -bl $tmpfile $testfile ||
3898 error "migrated file is corrupted"
3900 $LFS mirror extend -N -i0 $testfile ||
3901 error "mirror extend $testfile failed"
3902 $LFS getstripe $testfile
3903 mirror_count=$($LFS getstripe -N $testfile)
3904 [ $mirror_count -eq 2 ] ||
3905 error "mirror extend file $testfile failed (1)"
3906 stripe=$($LFS getstripe --mirror-id=1 -i $testfile)
3907 [ $stripe -eq 1 ] || error "mirror extend file $testfile failed (2)"
3908 stripe=$($LFS getstripe --mirror-id=2 -i $testfile)
3909 [ $stripe -eq 0 ] || error "mirror extend file $testfile failed (3)"
3912 $LFS mirror verify -v $testfile ||
3913 error "mirror verify failed"
3914 $LFS mirror read -N 1 -o $mirror1 $testfile ||
3915 error "read from mirror 1 failed"
3916 cmp -bl $tmpfile $mirror1 ||
3917 error "corruption of mirror 1"
3918 $LFS mirror read -N 2 -o $mirror2 $testfile ||
3919 error "read from mirror 2 failed"
3920 cmp -bl $tmpfile $mirror2 ||
3921 error "corruption of mirror 2"
3923 $LFS mirror split --mirror-id 1 -f ${testfile}.mirror $testfile &&
3924 error "mirror split -f should fail"
3926 $LFS mirror split --mirror-id 1 $testfile &&
3927 error "mirror split without -d should fail"
3929 $LFS mirror split --mirror-id 1 -d $testfile ||
3930 error "mirror split failed"
3931 $LFS getstripe $testfile
3932 mirror_count=$($LFS getstripe -N $testfile)
3933 [ $mirror_count -eq 1 ] ||
3934 error "mirror split file $testfile failed (1)"
3935 stripe=$($LFS getstripe --mirror-id=1 -i $testfile)
3936 [ -z "$stripe" ] || error "mirror extend file $testfile failed (2)"
3937 stripe=$($LFS getstripe --mirror-id=2 -i $testfile)
3938 [ $stripe -eq 0 ] || error "mirror extend file $testfile failed (3)"
3941 cmp -bl $tmpfile $testfile ||
3942 error "extended/split file is corrupted"
3944 rm -f $tmpfile $mirror1 $mirror2
3946 run_test 52 "Mirrored encrypted file"
3949 local testfile=$DIR/$tdir/$tfile
3950 local testfile2=$DIR2/$tdir/$tfile
3951 local tmpfile=$TMP/$tfile.tmp
3952 local resfile=$TMP/$tfile.res
3956 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3957 skip "client encryption not supported"
3959 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3960 skip "need dummy encryption support"
3962 pagesz=$(getconf PAGESIZE)
3963 [[ $pagesz == 65536 ]] || skip "Need 64K PAGE_SIZE client"
3965 do_node $mds1_HOST \
3966 "mount.lustre --help |& grep -q 'test_dummy_encryption:'" ||
3967 skip "need dummy encryption support on MDS client mount"
3969 # this test is probably useless now, but may turn out to be useful when
3970 # Lustre supports servers with PAGE_SIZE != 4KB
3971 pagesz=$(do_node $mds1_HOST getconf PAGESIZE)
3972 [[ $pagesz == 4096 ]] || skip "Need 4K PAGE_SIZE MDS client"
3974 stack_trap cleanup_for_enc_tests EXIT
3975 stack_trap "zconf_umount $mds1_HOST $MOUNT2" EXIT
3978 $LFS setstripe -c1 -i0 $testfile
3980 # write from 1st client
3981 cat /dev/urandom | tr -dc 'a-zA-Z0-9' |
3982 dd of=$tmpfile bs=$((pagesz+3)) count=2 conv=fsync
3983 dd if=$tmpfile of=$testfile bs=$((pagesz+3)) count=2 conv=fsync ||
3984 error "could not write to $testfile (1)"
3986 # read from 2nd client
3987 # mount and IOs must be done in the same shell session, otherwise
3988 # encryption key in session keyring is missing
3989 do_node $mds1_HOST "mkdir -p $MOUNT2"
3990 do_node $mds1_HOST \
3991 "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
3992 $MGSNID:/$FSNAME $MOUNT2 && \
3993 dd if=$testfile2 of=$resfile bs=$((pagesz+3)) count=2" ||
3994 error "could not read from $testfile2 (1)"
3997 filemd5=$(do_node $mds1_HOST md5sum $resfile | awk '{print $1}')
3998 [ $filemd5 = $(md5sum $tmpfile | awk '{print $1}') ] ||
3999 error "file is corrupted (1)"
4000 do_node $mds1_HOST rm -f $resfile
4003 # truncate from 2nd client
4004 $TRUNCATE $tmpfile $((pagesz+3))
4005 zconf_umount $mds1_HOST $MOUNT2 ||
4006 error "umount $mds1_HOST $MOUNT2 failed (1)"
4007 do_node $mds1_HOST "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4008 $MGSNID:/$FSNAME $MOUNT2 && \
4009 $TRUNCATE $testfile2 $((pagesz+3))" ||
4010 error "could not truncate $testfile2 (1)"
4013 cmp -bl $tmpfile $testfile ||
4014 error "file is corrupted (2)"
4015 rm -f $tmpfile $testfile
4017 zconf_umount $mds1_HOST $MOUNT2 ||
4018 error "umount $mds1_HOST $MOUNT2 failed (2)"
4021 do_node $mds1_HOST \
4022 dd if=/dev/urandom of=$tmpfile bs=$((pagesz+3)) count=2 conv=fsync
4023 # write from 2nd client
4024 do_node $mds1_HOST \
4025 "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4026 $MGSNID:/$FSNAME $MOUNT2 && \
4027 dd if=$tmpfile of=$testfile2 bs=$((pagesz+3)) count=2 conv=fsync" ||
4028 error "could not write to $testfile2 (2)"
4030 # read from 1st client
4031 dd if=$testfile of=$resfile bs=$((pagesz+3)) count=2 ||
4032 error "could not read from $testfile (2)"
4035 filemd5=$(do_node $mds1_HOST md5sum -b $tmpfile | awk '{print $1}')
4036 [ $filemd5 = $(md5sum -b $resfile | awk '{print $1}') ] ||
4037 error "file is corrupted (3)"
4041 # truncate from 1st client
4042 do_node $mds1_HOST "$TRUNCATE $tmpfile $((pagesz+3))"
4043 $TRUNCATE $testfile $((pagesz+3)) ||
4044 error "could not truncate $testfile (2)"
4047 zconf_umount $mds1_HOST $MOUNT2 ||
4048 error "umount $mds1_HOST $MOUNT2 failed (3)"
4049 do_node $mds1_HOST "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4050 $MGSNID:/$FSNAME $MOUNT2 && \
4051 cmp -bl $tmpfile $testfile2" ||
4052 error "file is corrupted (4)"
4054 do_node $mds1_HOST rm -f $tmpfile
4057 run_test 53 "Mixed PAGE_SIZE clients"
4060 local testdir=$DIR/$tdir/$ID0
4061 local testfile=$testdir/$tfile
4062 local testfile2=$testdir/${tfile}withveryverylongnametoexercisecode
4063 local tmpfile=$TMP/${tfile}.tmp
4064 local resfile=$TMP/${tfile}.res
4066 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4067 skip "client encryption not supported"
4069 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4070 skip "need dummy encryption support"
4072 which fscrypt || skip "This test needs fscrypt userspace tool"
4074 fscrypt setup --force --verbose || error "fscrypt global setup failed"
4075 sed -i 's/\(.*\)policy_version\(.*\):\(.*\)\"[0-9]*\"\(.*\)/\1policy_version\2:\3"2"\4/' \
4077 fscrypt setup --verbose $MOUNT || error "fscrypt setup $MOUNT failed"
4079 chown -R $ID0:$ID0 $testdir
4081 echo -e 'mypass\nmypass' | su - $USER0 -c "fscrypt encrypt --verbose \
4082 --source=custom_passphrase --name=protector $testdir" ||
4083 error "fscrypt encrypt failed"
4085 echo -e 'mypass\nmypass' | su - $USER0 -c "fscrypt encrypt --verbose \
4086 --source=custom_passphrase --name=protector2 $testdir" &&
4087 error "second fscrypt encrypt should have failed"
4089 mkdir -p ${testdir}2 || error "mkdir ${testdir}2 failed"
4090 touch ${testdir}2/f || error "mkdir ${testdir}2/f failed"
4093 echo -e 'mypass\nmypass' | fscrypt encrypt --verbose \
4094 --source=custom_passphrase --name=protector3 ${testdir}2 &&
4095 error "fscrypt encrypt on non-empty dir should have failed"
4097 $RUNAS dd if=/dev/urandom of=$testfile bs=127 count=1 conv=fsync ||
4098 error "write to encrypted file $testfile failed"
4099 cp $testfile $tmpfile
4100 $RUNAS dd if=/dev/urandom of=$testfile2 bs=127 count=1 conv=fsync ||
4101 error "write to encrypted file $testfile2 failed"
4102 $RUNAS mkdir $testdir/subdir || error "mkdir subdir failed"
4103 $RUNAS touch $testdir/subdir/subfile || error "mkdir subdir failed"
4105 $RUNAS fscrypt lock --verbose $testdir ||
4106 error "fscrypt lock $testdir failed (1)"
4108 $RUNAS ls -R $testdir || error "ls -R $testdir failed"
4109 local filecount=$($RUNAS find $testdir -type f | wc -l)
4110 [ $filecount -eq 3 ] || error "found $filecount files"
4112 scrambledfiles=( $(find $testdir/ -maxdepth 1 -type f) )
4113 $RUNAS hexdump -C ${scrambledfiles[0]} &&
4114 error "reading ${scrambledfiles[0]} should fail without key"
4116 $RUNAS touch ${testfile}.nokey &&
4117 error "touch ${testfile}.nokey should have failed without key"
4119 echo mypass | $RUNAS fscrypt unlock --verbose $testdir ||
4120 error "fscrypt unlock $testdir failed (1)"
4122 $RUNAS cat $testfile > $resfile ||
4123 error "reading $testfile failed"
4125 cmp -bl $tmpfile $resfile || error "file read differs from file written"
4127 $RUNAS fscrypt lock --verbose $testdir ||
4128 error "fscrypt lock $testdir failed (2)"
4130 $RUNAS hexdump -C ${scrambledfiles[1]} &&
4131 error "reading ${scrambledfiles[1]} should fail without key"
4133 echo mypass | $RUNAS fscrypt unlock --verbose $testdir ||
4134 error "fscrypt unlock $testdir failed (2)"
4137 $RUNAS fscrypt lock --verbose $testdir ||
4138 error "fscrypt lock $testdir failed (3)"
4140 rm -f $tmpfile $resfile
4142 run_test 54 "Encryption policies with fscrypt"
4146 if is_mounted $MOUNT; then
4147 umount_client $MOUNT || error "umount $MOUNT failed"
4150 do_facet mgs $LCTL nodemap_del c0
4151 do_facet mgs $LCTL nodemap_modify --name default \
4152 --property admin --value 0
4153 do_facet mgs $LCTL nodemap_modify --name default \
4154 --property trusted --value 0
4155 wait_nm_sync default admin_nodemap
4156 wait_nm_sync default trusted_nodemap
4158 do_facet mgs $LCTL nodemap_activate 0
4159 wait_nm_sync active 0
4161 if $SHARED_KEY; then
4162 export SK_UNIQUE_NM=false
4166 mount_client $MOUNT ${MOUNT_OPTS} || error "remount failed"
4167 if [ "$MOUNT_2" ]; then
4168 mount_client $MOUNT2 ${MOUNT_OPTS} || error "remount failed"
4173 (( $MDS1_VERSION > $(version_code 2.12.6.2) )) ||
4174 skip "Need MDS version at least 2.12.6.3"
4179 mkdir -p $DIR/$tdir/$USER0/testdir_groups
4180 chown root:$ID0 $DIR/$tdir/$USER0
4181 chmod 770 $DIR/$tdir/$USER0
4182 chmod g+s $DIR/$tdir/$USER0
4183 chown $ID0:$ID0 $DIR/$tdir/$USER0/testdir_groups
4184 chmod 770 $DIR/$tdir/$USER0/testdir_groups
4185 chmod g+s $DIR/$tdir/$USER0/testdir_groups
4187 # unmount client completely
4188 umount_client $MOUNT || error "umount $MOUNT failed"
4189 if is_mounted $MOUNT2; then
4190 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
4193 do_nodes $(comma_list $(all_mdts_nodes)) \
4194 $LCTL set_param mdt.*.identity_upcall=NONE
4196 stack_trap cleanup_55 EXIT
4198 do_facet mgs $LCTL nodemap_activate 1
4201 do_facet mgs $LCTL nodemap_del c0 || true
4202 wait_nm_sync c0 id ''
4204 do_facet mgs $LCTL nodemap_modify --name default \
4205 --property admin --value 1
4206 do_facet mgs $LCTL nodemap_modify --name default \
4207 --property trusted --value 1
4208 wait_nm_sync default admin_nodemap
4209 wait_nm_sync default trusted_nodemap
4211 client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
4212 client_nid=$(h2nettype $client_ip)
4213 do_facet mgs $LCTL nodemap_add c0
4214 do_facet mgs $LCTL nodemap_add_range \
4215 --name c0 --range $client_nid
4216 do_facet mgs $LCTL nodemap_modify --name c0 \
4217 --property admin --value 0
4218 do_facet mgs $LCTL nodemap_modify --name c0 \
4219 --property trusted --value 1
4220 wait_nm_sync c0 admin_nodemap
4221 wait_nm_sync c0 trusted_nodemap
4223 if $SHARED_KEY; then
4224 export SK_UNIQUE_NM=true
4225 # set some generic fileset to trigger SSK code
4229 # remount client to take nodemap into account
4230 zconf_mount_clients $HOSTNAME $MOUNT $MOUNT_OPTS ||
4231 error "remount failed"
4234 euid_access $USER0 $DIR/$tdir/$USER0/testdir_groups/file
4236 run_test 55 "access with seteuid"
4239 local testfile=$DIR/$tdir/$tfile
4241 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4243 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4244 skip "client encryption not supported"
4246 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4247 skip "need dummy encryption support"
4249 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4251 stack_trap cleanup_for_enc_tests EXIT
4254 $LFS setstripe -c1 $testfile
4255 dd if=/dev/urandom of=$testfile bs=1M count=3 conv=fsync
4256 filefrag -v $testfile || error "filefrag $testfile failed"
4257 (( $(filefrag -v $testfile | grep -c encrypted) >= 1 )) ||
4258 error "filefrag $testfile does not show encrypted flag"
4259 (( $(filefrag -v $testfile | grep -c encoded) >= 1 )) ||
4260 error "filefrag $testfile does not show encoded flag"
4262 run_test 56 "FIEMAP on encrypted file"
4265 local testdir=$DIR/$tdir/mytestdir
4266 local testfile=$DIR/$tdir/$tfile
4268 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4270 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4271 skip "client encryption not supported"
4273 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4274 skip "need dummy encryption support"
4278 setfattr -n security.c -v myval $testdir &&
4279 error "setting xattr on $testdir should have failed (1)"
4281 setfattr -n security.c -v myval $testfile &&
4282 error "setting xattr on $testfile should have failed (1)"
4286 stack_trap cleanup_for_enc_tests EXIT
4290 setfattr -n security.c -v myval $testdir &&
4291 error "setting xattr on $testdir should have failed (2)"
4293 setfattr -n security.c -v myval $testfile &&
4294 error "setting xattr on $testfile should have failed (2)"
4297 run_test 57 "security.c xattr protection"
4299 log "cleanup: ======================================================"
4302 for num in $(seq $MDSCOUNT); do
4303 if [ "${identity_old[$num]}" = 1 ]; then
4304 switch_identity $num false || identity_old[$num]=$?
4308 $RUNAS_CMD -u $ID0 ls $DIR
4309 $RUNAS_CMD -u $ID1 ls $DIR
4314 check_and_cleanup_lustre