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() {
2629 # remount client normally
2630 if is_mounted $MOUNT; then
2631 umount_client $MOUNT || error "umount $MOUNT failed"
2633 mount_client $MOUNT ${MOUNT_OPTS} ||
2634 error "remount failed"
2636 if is_mounted $MOUNT2; then
2637 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2639 if [ "$MOUNT_2" ]; then
2640 mount_client $MOUNT2 ${MOUNT_OPTS} ||
2641 error "remount failed"
2645 cleanup_nodemap_after_enc_tests() {
2646 do_facet mgs $LCTL nodemap_modify --name default \
2647 --property forbid_encryption --value 0
2648 wait_nm_sync default forbid_encryption
2649 do_facet mgs $LCTL nodemap_activate 0
2654 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2655 skip "client encryption not supported"
2657 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2658 skip "need dummy encryption support"
2660 stack_trap cleanup_for_enc_tests EXIT
2662 # first make sure it is possible to enable encryption
2663 # when nodemap is not active
2666 umount_client $MOUNT || error "umount $MOUNT failed (1)"
2668 # then activate nodemap, and retry
2669 # should succeed as encryption is not forbidden on default nodemap
2671 stack_trap cleanup_nodemap_after_enc_tests EXIT
2672 do_facet mgs $LCTL nodemap_activate 1
2674 forbid=$(do_facet mgs lctl get_param -n nodemap.default.forbid_encryption)
2675 [ $forbid -eq 0 ] || error "wrong default value for forbid_encryption"
2676 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption ||
2677 error "mount '-o test_dummy_encryption' failed with default"
2678 umount_client $MOUNT || error "umount $MOUNT failed (2)"
2680 # then forbid encryption, and retry
2681 do_facet mgs $LCTL nodemap_modify --name default \
2682 --property forbid_encryption --value 1
2683 wait_nm_sync default forbid_encryption
2684 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption &&
2685 error "mount '-o test_dummy_encryption' should have failed"
2688 run_test 36 "control if clients can use encryption"
2691 local testfile=$DIR/$tdir/$tfile
2692 local tmpfile=$TMP/abc
2693 local objdump=$TMP/objdump
2696 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2697 skip "client encryption not supported"
2699 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2700 skip "need dummy encryption support"
2702 [ "$ost1_FSTYPE" = ldiskfs ] || skip "ldiskfs only test (using debugfs)"
2704 stack_trap cleanup_for_enc_tests EXIT
2707 # write a few bytes in file
2708 echo "abc" > $tmpfile
2709 $LFS setstripe -c1 -i0 $testfile
2710 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2711 do_facet ost1 "sync; sync"
2713 # check that content on ost is encrypted
2714 objid=$($LFS getstripe $testfile | awk '/obdidx/{getline; print $2}')
2715 do_facet ost1 "$DEBUGFS -c -R 'cat O/0/d$(($objid % 32))/$objid' \
2716 $(ostdevname 1)" > $objdump
2717 cmp -s $objdump $tmpfile &&
2718 error "file $testfile is not encrypted on ost"
2720 # check that in-memory representation of file is correct
2721 cmp -bl ${tmpfile} ${testfile} ||
2722 error "file $testfile is corrupted in memory"
2724 cancel_lru_locks osc ; cancel_lru_locks mdc
2726 # check that file read from server is correct
2727 cmp -bl ${tmpfile} ${testfile} ||
2728 error "file $testfile is corrupted on server"
2730 rm -f $tmpfile $objdump
2732 run_test 37 "simple encrypted file"
2735 local testfile=$DIR/$tdir/$tfile
2736 local tmpfile=$TMP/abc
2742 local pagesz=$(getconf PAGE_SIZE)
2744 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2745 skip "client encryption not supported"
2747 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2748 skip "need dummy encryption support"
2750 stack_trap cleanup_for_enc_tests EXIT
2753 # get block size on ost
2754 blksz=$($LCTL get_param osc.$FSNAME*.import |
2755 awk '/grant_block_size:/ { print $2; exit; }')
2756 # write a few bytes in file at offset $blksz
2757 echo "abc" > $tmpfile
2758 $LFS setstripe -c1 -i0 $testfile
2759 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$blksz \
2760 oflag=seek_bytes conv=fsync
2762 blksz=$(($blksz > $pagesz ? $blksz : $pagesz))
2763 # check that in-memory representation of file is correct
2764 bsize=$(stat --format=%B $testfile)
2765 filesz=$(stat --format=%b $testfile)
2766 filesz=$((filesz*bsize))
2767 [ $filesz -le $blksz ] ||
2768 error "file $testfile is $filesz long in memory"
2770 cancel_lru_locks osc ; cancel_lru_locks mdc
2772 # check that file read from server is correct
2773 bsize=$(stat --format=%B $testfile)
2774 filesz=$(stat --format=%b $testfile)
2775 filesz=$((filesz*bsize))
2776 [ $filesz -le $blksz ] ||
2777 error "file $testfile is $filesz long on server"
2781 run_test 38 "encrypted file with hole"
2784 local testfile=$DIR/$tdir/$tfile
2785 local tmpfile=$TMP/abc
2787 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2788 skip "client encryption not supported"
2790 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2791 skip "need dummy encryption support"
2793 stack_trap cleanup_for_enc_tests EXIT
2796 # write a few bytes in file
2797 echo "abc" > $tmpfile
2798 $LFS setstripe -c1 -i0 $testfile
2799 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2801 # write a few more bytes in the same page
2802 dd if=$tmpfile of=$testfile bs=4 count=1 seek=1024 oflag=seek_bytes \
2805 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=1024 oflag=seek_bytes \
2808 # check that in-memory representation of file is correct
2809 cmp -bl $tmpfile $testfile ||
2810 error "file $testfile is corrupted in memory"
2812 cancel_lru_locks osc ; cancel_lru_locks mdc
2814 # check that file read from server is correct
2815 cmp -bl $tmpfile $testfile ||
2816 error "file $testfile is corrupted on server"
2820 run_test 39 "rewrite data in already encrypted page"
2823 local testfile=$DIR/$tdir/$tfile
2824 local tmpfile=$TMP/abc
2825 local tmpfile2=$TMP/abc2
2828 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2829 skip "client encryption not supported"
2831 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2832 skip "need dummy encryption support"
2834 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2836 stack_trap cleanup_for_enc_tests EXIT
2839 # write a few bytes in file
2840 echo "abc" > $tmpfile
2841 $LFS setstripe -c1 -i0 $testfile
2842 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2844 # check that in-memory representation of file is correct
2845 cmp -bl $tmpfile $testfile ||
2846 error "file $testfile is corrupted in memory (1)"
2848 cancel_lru_locks osc ; cancel_lru_locks mdc
2850 # check that file read from server is correct
2851 cmp -bl $tmpfile $testfile ||
2852 error "file $testfile is corrupted on server (1)"
2854 # write a few other bytes in same page
2855 dd if=$tmpfile of=$testfile bs=4 count=1 seek=256 oflag=seek_bytes \
2858 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=256 oflag=seek_bytes \
2861 # check that in-memory representation of file is correct
2862 cmp -bl $tmpfile $testfile ||
2863 error "file $testfile is corrupted in memory (2)"
2865 cancel_lru_locks osc ; cancel_lru_locks mdc
2867 # check that file read from server is correct
2868 cmp -bl $tmpfile $testfile ||
2869 error "file $testfile is corrupted on server (2)"
2871 rm -f $testfile $tmpfile
2872 cancel_lru_locks osc ; cancel_lru_locks mdc
2874 # write a few bytes in file, at end of first page
2875 echo "abc" > $tmpfile
2876 $LFS setstripe -c1 -i0 $testfile
2877 seek=$(getconf PAGESIZE)
2879 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2882 # write a few other bytes at beginning of first page
2883 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync,notrunc
2885 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2888 # check that in-memory representation of file is correct
2889 cmp -bl $tmpfile $testfile ||
2890 error "file $testfile is corrupted in memory (3)"
2892 cancel_lru_locks osc ; cancel_lru_locks mdc
2894 # check that file read from server is correct
2895 cmp -bl $tmpfile $testfile ||
2896 error "file $testfile is corrupted on server (3)"
2898 rm -f $testfile $tmpfile
2899 cancel_lru_locks osc ; cancel_lru_locks mdc
2901 # write a few bytes in file, at beginning of second page
2902 echo "abc" > $tmpfile
2903 $LFS setstripe -c1 -i0 $testfile
2904 seek=$(getconf PAGESIZE)
2905 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2907 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
2910 # write a few other bytes at end of first page
2912 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2914 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
2917 # check that in-memory representation of file is correct
2918 cmp -bl $tmpfile2 $testfile ||
2919 error "file $testfile is corrupted in memory (4)"
2921 cancel_lru_locks osc ; cancel_lru_locks mdc
2923 # check that file read from server is correct
2924 cmp -bl $tmpfile2 $testfile ||
2925 error "file $testfile is corrupted on server (4)"
2927 rm -f $testfile $tmpfile $tmpfile2
2928 cancel_lru_locks osc ; cancel_lru_locks mdc
2930 # write a few bytes in file, at beginning of first stripe
2931 echo "abc" > $tmpfile
2932 $LFS setstripe -S 256k -c2 $testfile
2933 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync,notrunc
2935 # write a few other bytes, at beginning of second stripe
2936 dd if=$tmpfile of=$testfile bs=4 count=1 seek=262144 oflag=seek_bytes \
2938 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=262144 oflag=seek_bytes \
2941 # check that in-memory representation of file is correct
2942 cmp -bl $tmpfile $testfile ||
2943 error "file $testfile is corrupted in memory (5)"
2945 cancel_lru_locks osc ; cancel_lru_locks mdc
2947 # check that file read from server is correct
2948 cmp -bl $tmpfile $testfile ||
2949 error "file $testfile is corrupted on server (5)"
2953 run_test 40 "exercise size of encrypted file"
2956 local testfile=$DIR/$tdir/$tfile
2957 local tmpfile=$TMP/abc
2958 local tmpfile2=$TMP/abc2
2961 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2962 skip "client encryption not supported"
2964 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2965 skip "need dummy encryption support"
2967 stack_trap cleanup_for_enc_tests EXIT
2970 echo "abc" > $tmpfile
2971 seek=$(getconf PAGESIZE)
2972 seek=$((seek - 204))
2973 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
2975 seek=$(getconf PAGESIZE)
2976 seek=$((seek + 1092))
2977 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
2980 # write a few bytes in file
2981 $LFS setstripe -c1 -i0 -S 256k $testfile
2982 seek=$(getconf PAGESIZE)
2983 seek=$((seek - 204))
2984 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
2985 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
2986 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2990 # write a few other bytes, at a different offset
2991 seek=$(getconf PAGESIZE)
2992 seek=$((seek + 1092))
2993 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
2994 conv=fsync,notrunc &
2996 do_facet ost1 "$LCTL set_param fail_loc=0x0"
2998 # check that in-memory representation of file is correct
2999 cmp -bl $tmpfile2 $testfile ||
3000 error "file $testfile is corrupted in memory (1)"
3002 cancel_lru_locks osc ; cancel_lru_locks mdc
3004 # check that file read from server is correct
3005 cmp -bl $tmpfile2 $testfile ||
3006 error "file $testfile is corrupted on server (1)"
3008 rm -f $tmpfile $tmpfile2
3010 run_test 41 "test race on encrypted file size (1)"
3013 local testfile=$DIR/$tdir/$tfile
3014 local testfile2=$DIR2/$tdir/$tfile
3015 local tmpfile=$TMP/abc
3016 local tmpfile2=$TMP/abc2
3017 local pagesz=$(getconf PAGESIZE)
3020 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3021 skip "client encryption not supported"
3023 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3024 skip "need dummy encryption support"
3026 stack_trap cleanup_for_enc_tests EXIT
3029 if is_mounted $MOUNT2; then
3030 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
3032 mount_client $MOUNT2 ${MOUNT_OPTS},test_dummy_encryption ||
3033 error "mount2 with '-o test_dummy_encryption' failed"
3035 # create file by writting one whole page
3036 $LFS setstripe -c1 -i0 -S 256k $testfile
3037 dd if=/dev/zero of=$testfile bs=$pagesz count=1 conv=fsync
3039 # read file from 2nd mount point
3040 cat $testfile2 > /dev/null
3042 echo "abc" > $tmpfile
3043 dd if=/dev/zero of=$tmpfile2 bs=$pagesz count=1 conv=fsync
3044 seek=$((2*pagesz - 204))
3045 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3047 seek=$((2*pagesz + 1092))
3048 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3051 # write a few bytes in file from 1st mount point
3052 seek=$((2*pagesz - 204))
3053 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
3054 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
3055 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3056 conv=fsync,notrunc &
3059 # write a few other bytes, at a different offset from 2nd mount point
3060 seek=$((2*pagesz + 1092))
3061 dd if=$tmpfile of=$testfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3062 conv=fsync,notrunc &
3064 do_facet ost1 "$LCTL set_param fail_loc=0x0"
3066 # check that in-memory representation of file is correct
3067 cmp -bl $tmpfile2 $testfile ||
3068 error "file $testfile is corrupted in memory (1)"
3070 # check that in-memory representation of file is correct
3071 cmp -bl $tmpfile2 $testfile2 ||
3072 error "file $testfile is corrupted in memory (2)"
3074 cancel_lru_locks osc ; cancel_lru_locks mdc
3076 # check that file read from server is correct
3077 cmp -bl $tmpfile2 $testfile ||
3078 error "file $testfile is corrupted on server (1)"
3080 rm -f $tmpfile $tmpfile2
3082 run_test 42 "test race on encrypted file size (2)"
3085 local testfile=$DIR/$tdir/$tfile
3086 local testfile2=$DIR2/$tdir/$tfile
3087 local tmpfile=$TMP/abc
3088 local tmpfile2=$TMP/abc2
3089 local resfile=$TMP/res
3090 local pagesz=$(getconf PAGESIZE)
3093 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3094 skip "client encryption not supported"
3096 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3097 skip "need dummy encryption support"
3099 stack_trap cleanup_for_enc_tests EXIT
3102 if is_mounted $MOUNT2; then
3103 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
3105 mount_client $MOUNT2 ${MOUNT_OPTS},test_dummy_encryption ||
3106 error "mount2 with '-o test_dummy_encryption' failed"
3109 tr '\0' '1' < /dev/zero |
3110 dd of=$tmpfile bs=1 count=$pagesz conv=fsync
3111 $LFS setstripe -c1 -i0 -S 256k $testfile
3112 cp $tmpfile $testfile
3114 # read file from 2nd mount point
3115 cat $testfile2 > /dev/null
3117 # write a few bytes in file from 1st mount point
3118 echo "abc" > $tmpfile2
3119 seek=$((2*pagesz - 204))
3120 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
3121 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
3122 dd if=$tmpfile2 of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3123 conv=fsync,notrunc &
3126 # read file from 2nd mount point
3127 dd if=$testfile2 of=$resfile bs=$pagesz count=1 conv=fsync,notrunc
3128 cmp -bl $tmpfile $resfile ||
3129 error "file $testfile is corrupted in memory (1)"
3132 do_facet ost1 "$LCTL set_param fail_loc=0x0"
3134 # check that in-memory representation of file is correct
3135 dd if=$tmpfile2 of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3137 cmp -bl $tmpfile $testfile2 ||
3138 error "file $testfile is corrupted in memory (2)"
3140 cancel_lru_locks osc ; cancel_lru_locks mdc
3142 # check that file read from server is correct
3143 cmp -bl $tmpfile $testfile ||
3144 error "file $testfile is corrupted on server (1)"
3146 rm -f $tmpfile $tmpfile2
3148 run_test 43 "test race on encrypted file size (3)"
3151 local testfile=$DIR/$tdir/$tfile
3152 local tmpfile=$TMP/abc
3153 local resfile=$TMP/resfile
3154 local pagesz=$(getconf PAGESIZE)
3157 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3158 skip "client encryption not supported"
3160 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3161 skip "need dummy encryption support"
3163 which vmtouch || skip "This test needs vmtouch utility"
3165 # Direct I/O is now supported on encrypted files.
3167 stack_trap cleanup_for_enc_tests EXIT
3170 $LFS setstripe -c1 -i0 $testfile
3171 dd if=/dev/urandom of=$tmpfile bs=$pagesz count=2 conv=fsync
3172 dd if=$tmpfile of=$testfile bs=$pagesz count=2 oflag=direct ||
3173 error "could not write to file with O_DIRECT (1)"
3175 respage=$(vmtouch $testfile | awk '/Resident Pages:/ {print $3}')
3176 [ "$respage" == "0/2" ] ||
3177 error "write to enc file fell back to buffered IO"
3181 dd if=$testfile of=$resfile bs=$pagesz count=2 iflag=direct ||
3182 error "could not read from file with O_DIRECT (1)"
3184 respage=$(vmtouch $testfile | awk '/Resident Pages:/ {print $3}')
3185 [ "$respage" == "0/2" ] ||
3186 error "read from enc file fell back to buffered IO"
3188 cmp -bl $tmpfile $resfile ||
3189 error "file $testfile is corrupted (1)"
3193 $TRUNCATE $tmpfile $pagesz
3194 dd if=$tmpfile of=$testfile bs=$pagesz count=1 seek=13 oflag=direct ||
3195 error "could not write to file with O_DIRECT (2)"
3199 dd if=$testfile of=$resfile bs=$pagesz count=1 skip=13 iflag=direct ||
3200 error "could not read from file with O_DIRECT (2)"
3201 cmp -bl $tmpfile $resfile ||
3202 error "file $testfile is corrupted (2)"
3204 rm -f $testfile $resfile
3205 $LFS setstripe -c1 -i0 $testfile
3207 $TRUNCATE $tmpfile $((pagesz/2 - 5))
3208 cp $tmpfile $testfile
3212 dd if=$testfile of=$resfile bs=$pagesz count=1 iflag=direct ||
3213 error "could not read from file with O_DIRECT (3)"
3214 cmp -bl $tmpfile $resfile ||
3215 error "file $testfile is corrupted (3)"
3217 rm -f $tmpfile $resfile
3219 run_test 44 "encrypted file access semantics: direct IO"
3222 local testfile=$DIR/$tdir/$tfile
3223 local tmpfile=$TMP/junk
3225 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3226 skip "client encryption not supported"
3228 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3229 skip "need dummy encryption support"
3231 stack_trap cleanup_for_enc_tests EXIT
3234 $LFS setstripe -c1 -i0 $testfile
3235 dd if=/dev/zero of=$testfile bs=512K count=1
3236 $MULTIOP $testfile OSMRUc || error "$MULTIOP $testfile failed (1)"
3237 $MULTIOP $testfile OSMWUc || error "$MULTIOP $testfile failed (2)"
3239 dd if=/dev/zero of=$tmpfile bs=512K count=1
3240 $MULTIOP $tmpfile OSMWUc || error "$MULTIOP $tmpfile failed"
3241 $MMAP_CAT $tmpfile > ${tmpfile}2
3245 $MULTIOP $testfile OSMRUc
3246 $MMAP_CAT $testfile > ${testfile}2
3247 cmp -bl ${tmpfile}2 ${testfile}2 ||
3248 error "file $testfile is corrupted"
3250 rm -f $tmpfile ${tmpfile}2
3252 run_test 45 "encrypted file access semantics: MMAP"
3255 local testdir=$DIR/$tdir/mydir
3256 local testfile=$testdir/myfile
3257 local testdir2=$DIR/$tdir/mydirwithaveryverylongnametotestcodebehaviour0
3258 local testfile2=$testdir/myfilewithaveryverylongnametotestcodebehaviour0
3259 local lsfile=$TMP/lsfile
3263 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3264 skip "client encryption not supported"
3266 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3267 skip "need dummy encryption support"
3269 stack_trap cleanup_for_enc_tests EXIT
3272 touch $DIR/$tdir/$tfile
3274 echo test > $testfile
3275 echo othertest > $testfile2
3276 if [[ $MDSCOUNT -gt 1 ]]; then
3277 $LFS setdirstripe -c1 -i1 $testdir2
3281 sync ; echo 3 > /proc/sys/vm/drop_caches
3283 # remove fscrypt key from keyring
3284 keyctl revoke $(keyctl show | awk '$7 ~ "^fscrypt:" {print $1}')
3289 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d| grep _)
3290 stat $scrambleddir || error "stat $scrambleddir failed"
3291 rmdir $scrambleddir || error "rmdir $scrambleddir failed"
3293 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d)
3294 ls -1 $scrambleddir > $lsfile || error "ls $testdir failed (1)"
3296 scrambledfile=$scrambleddir/$(head -n 1 $lsfile)
3297 stat $scrambledfile || error "stat $scrambledfile failed (1)"
3300 cat $scrambledfile && error "cat $scrambledfile should have failed (1)"
3301 rm -f $scrambledfile || error "rm $scrambledfile failed (1)"
3303 ls -1 $scrambleddir > $lsfile || error "ls $testdir failed (2)"
3304 scrambledfile=$scrambleddir/$(head -n 1 $lsfile)
3305 stat $scrambledfile || error "stat $scrambledfile failed (2)"
3307 cat $scrambledfile && error "cat $scrambledfile should have failed (2)"
3309 touch $scrambleddir/otherfile &&
3310 error "touch otherfile should have failed"
3311 ls $scrambleddir/otherfile && error "otherfile should not exist"
3312 mkdir $scrambleddir/otherdir &&
3313 error "mkdir otherdir should have failed"
3314 ls -d $scrambleddir/otherdir && error "otherdir should not exist"
3317 rm -f $scrambledfile || error "rm $scrambledfile failed (2)"
3318 rmdir $scrambleddir || error "rmdir $scrambleddir failed"
3321 run_test 46 "encrypted file access semantics without key"
3324 local testfile=$DIR/$tdir/$tfile
3325 local testfile2=$DIR/$tdir/${tfile}.2
3326 local tmpfile=$DIR/junk
3330 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3331 skip "client encryption not supported"
3333 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3334 skip "need dummy encryption support"
3336 stack_trap cleanup_for_enc_tests EXIT
3339 dd if=/dev/urandom of=$tmpfile bs=512K count=1
3340 mrename $tmpfile $testfile &&
3341 error "rename from unencrypted to encrypted dir should fail"
3343 ln $tmpfile $testfile &&
3344 error "link from encrypted to unencrypted dir should fail"
3346 cp $tmpfile $testfile ||
3347 error "cp from unencrypted to encrypted dir should succeed"
3350 mrename $testfile $testfile2 ||
3351 error "rename from within encrypted dir should succeed"
3353 ln $testfile2 $testfile ||
3354 error "link from within encrypted dir should succeed"
3355 cmp -bl $testfile2 $testfile ||
3356 error "cannot read from hard link (1.1)"
3357 echo a >> $testfile || error "cannot write to hard link (1)"
3359 cmp -bl $testfile2 $testfile ||
3360 error "cannot read from hard link (1.2)"
3363 ln $testfile2 $tmpfile ||
3364 error "link from unencrypted to encrypted dir should succeed"
3366 cmp -bl $testfile2 $tmpfile ||
3367 error "cannot read from hard link (2.1)"
3368 echo a >> $tmpfile || error "cannot write to hard link (2)"
3370 cmp -bl $testfile2 $tmpfile ||
3371 error "cannot read from hard link (2.2)"
3374 # check we are limited in the number of hard links
3375 # we can create for encrypted files, to what can fit into LinkEA
3376 for i in $(seq 1 160); do
3377 ln $testfile2 ${testfile}_$i || break
3379 [ $i -lt 160 ] || error "hard link $i should fail"
3382 mrename $testfile2 $tmpfile &&
3383 error "rename from encrypted to unencrypted dir should fail"
3385 dd if=/dev/urandom of=$tmpfile bs=512K count=1
3387 dd if=/dev/urandom of=$testfile bs=512K count=1
3388 mkdir $DIR/$tdir/mydir
3390 ln -s $testfile ${testfile}.sym ||
3391 error "symlink from within encrypted dir should succeed"
3393 cmp -bl $testfile ${testfile}.sym ||
3394 error "cannot read from sym link (1.1)"
3395 echo a >> ${testfile}.sym || error "cannot write to sym link (1)"
3397 cmp -bl $testfile ${testfile}.sym ||
3398 error "cannot read from sym link (1.2)"
3399 [ $(stat -c %s ${testfile}.sym) -eq ${#testfile} ] ||
3400 error "wrong symlink size (1)"
3402 ln -s $tmpfile ${testfile}.sl ||
3403 error "symlink from encrypted to unencrypted dir should succeed"
3405 cmp -bl $tmpfile ${testfile}.sl ||
3406 error "cannot read from sym link (2.1)"
3407 echo a >> ${testfile}.sl || error "cannot write to sym link (2)"
3409 cmp -bl $tmpfile ${testfile}.sl ||
3410 error "cannot read from sym link (2.2)"
3411 [ $(stat -c %s ${testfile}.sl) -eq ${#tmpfile} ] ||
3412 error "wrong symlink size (2)"
3413 rm -f ${testfile}.sl
3415 sync ; echo 3 > /proc/sys/vm/drop_caches
3417 # remove fscrypt key from keyring
3418 keyctl revoke $(keyctl show | awk '$7 ~ "^fscrypt:" {print $1}')
3422 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d)
3423 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -type f)
3424 scrambledlink=$(find $DIR/$tdir/ -maxdepth 1 -type l)
3425 ln $scrambledfile $scrambleddir/linkfile &&
3426 error "ln linkfile should have failed"
3427 mrename $scrambledfile $DIR/onefile2 &&
3428 error "mrename from $scrambledfile should have failed"
3430 mrename $DIR/onefile $scrambleddir/otherfile &&
3431 error "mrename to $scrambleddir should have failed"
3432 readlink $scrambledlink ||
3433 error "link should be read without key"
3434 [ $(stat -c %s $scrambledlink) -eq \
3435 $(expr length "$(readlink $scrambledlink)") ] ||
3436 error "wrong symlink size without key"
3437 readlink -e $scrambledlink &&
3438 error "link should not point to anywhere useful"
3439 ln -s $scrambledfile ${scrambledfile}.sym &&
3440 error "symlink without key should fail (1)"
3441 ln -s $tmpfile ${scrambledfile}.sl &&
3442 error "symlink without key should fail (2)"
3444 rm -f $tmpfile $DIR/onefile
3446 run_test 47 "encrypted file access semantics: rename/link"
3449 local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
3450 local testfile=$DIR/$tdir/$tfile
3451 local tmpfile=$TMP/111
3452 local tmpfile2=$TMP/abc
3453 local pagesz=$(getconf PAGESIZE)
3458 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3459 skip "client encryption not supported"
3461 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3462 skip "need dummy encryption support"
3464 stack_trap cleanup_for_enc_tests EXIT
3467 # create file, 4 x PAGE_SIZE long
3468 tr '\0' '1' < /dev/zero |
3469 dd of=$tmpfile bs=1 count=4x$pagesz conv=fsync
3470 $LFS setstripe -c1 -i0 $testfile
3471 cp $tmpfile $testfile
3472 echo "abc" > $tmpfile2
3474 # decrease size: truncate to PAGE_SIZE
3475 $TRUNCATE $tmpfile $pagesz
3476 $TRUNCATE $testfile $pagesz
3477 cancel_lru_locks osc ; cancel_lru_locks mdc
3478 cmp -bl $tmpfile $testfile ||
3479 error "file $testfile is corrupted (1)"
3481 # increase size: truncate to 2 x PAGE_SIZE
3483 $TRUNCATE $tmpfile $sz
3484 $TRUNCATE $testfile $sz
3485 cancel_lru_locks osc ; cancel_lru_locks mdc
3486 cmp -bl $tmpfile $testfile ||
3487 error "file $testfile is corrupted (2)"
3490 seek=$((pagesz+100))
3491 dd if=$tmpfile2 of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3493 dd if=$tmpfile2 of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3495 cancel_lru_locks osc ; cancel_lru_locks mdc
3496 cmp -bl $tmpfile $testfile ||
3497 error "file $testfile is corrupted (3)"
3499 # truncate to PAGE_SIZE / 2
3501 $TRUNCATE $tmpfile $sz
3502 $TRUNCATE $testfile $sz
3503 cancel_lru_locks osc ; cancel_lru_locks mdc
3504 cmp -bl $tmpfile $testfile ||
3505 error "file $testfile is corrupted (4)"
3507 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16
3509 $TRUNCATE $tmpfile $sz
3510 $TRUNCATE $testfile $sz
3511 cancel_lru_locks osc ; cancel_lru_locks mdc
3512 cmp -bl $tmpfile $testfile ||
3513 error "file $testfile is corrupted (5)"
3515 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16
3517 $TRUNCATE $tmpfile $sz
3518 $TRUNCATE $testfile $sz
3519 cancel_lru_locks osc ; cancel_lru_locks mdc
3520 cmp -bl $tmpfile $testfile ||
3521 error "file $testfile is corrupted (6)"
3523 # truncate to a larger, non-multiple of PAGE_SIZE, in a different page
3524 sz=$((sz+pagesz+30))
3525 $TRUNCATE $tmpfile $sz
3526 $TRUNCATE $testfile $sz
3527 cancel_lru_locks osc ; cancel_lru_locks mdc
3528 cmp -bl $tmpfile $testfile ||
3529 error "file $testfile is corrupted (7)"
3531 sync ; echo 3 > /proc/sys/vm/drop_caches
3533 # remove fscrypt key from keyring
3534 keyctl revoke $(keyctl show | awk '$7 ~ "^fscrypt:" {print $1}')
3537 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -type f)
3538 $TRUNCATE $scrambledfile 0 &&
3539 error "truncate $scrambledfile should have failed without key"
3541 rm -f $tmpfile $tmpfile2
3543 run_test 48a "encrypted file access semantics: truncate"
3545 cleanup_for_enc_tests_othercli() {
3548 # remount othercli normally
3549 zconf_umount $othercli $MOUNT ||
3550 error "umount $othercli $MOUNT failed"
3551 zconf_mount $othercli $MOUNT ||
3552 error "remount $othercli $MOUNT failed"
3558 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3559 skip "client encryption not supported"
3561 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3562 skip "need dummy encryption support"
3564 [ "$num_clients" -ge 2 ] || skip "Need at least 2 clients"
3566 if [ "$HOSTNAME" == ${clients_arr[0]} ]; then
3567 othercli=${clients_arr[1]}
3569 othercli=${clients_arr[0]}
3572 stack_trap cleanup_for_enc_tests EXIT
3573 stack_trap "cleanup_for_enc_tests_othercli $othercli" EXIT
3575 zconf_umount $othercli $MOUNT ||
3576 error "umount $othercli $MOUNT failed"
3578 cp /bin/sleep $DIR/$tdir/
3579 cancel_lru_locks osc ; cancel_lru_locks mdc
3580 $DIR/$tdir/sleep 30 &
3581 # mount and IOs must be done in the same shell session, otherwise
3582 # encryption key in session keyring is missing
3583 do_node $othercli "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
3584 $MGSNID:/$FSNAME $MOUNT && \
3585 $TRUNCATE $DIR/$tdir/sleep 7"
3586 wait || error "wait error"
3587 cmp --silent /bin/sleep $DIR/$tdir/sleep ||
3588 error "/bin/sleep and $DIR/$tdir/sleep differ"
3590 run_test 48b "encrypted file: concurrent truncate"
3596 $LCTL set_param debug=+info
3601 [ $? -eq 0 ] || error "$cmd failed"
3603 if [ -z "$MATCHING_STRING" ]; then
3604 $LCTL dk | grep -E "get xattr 'security.c'|get xattrs"
3606 $LCTL dk | grep -E "$MATCHING_STRING"
3608 [ $? -ne 0 ] || error "get xattr event was triggered"
3612 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3613 skip "client encryption not supported"
3615 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3616 skip "need dummy encryption support"
3618 stack_trap cleanup_for_enc_tests EXIT
3621 local dirname=$DIR/$tdir/subdir
3625 trace_cmd stat $dirname
3626 trace_cmd touch $dirname/f1
3627 trace_cmd stat $dirname/f1
3628 trace_cmd cat $dirname/f1
3629 dd if=/dev/zero of=$dirname/f1 bs=1M count=10 conv=fsync
3630 MATCHING_STRING="get xattr 'security.c'" \
3631 trace_cmd $TRUNCATE $dirname/f1 10240
3632 trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
3633 trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
3635 if [[ $MDSCOUNT -gt 1 ]]; then
3636 trace_cmd $LFS setdirstripe -i 1 $dirname/d2
3637 trace_cmd $LFS migrate -m 0 $dirname/d2
3638 touch $dirname/d2/subf
3639 # migrate a non-empty encrypted dir
3640 trace_cmd $LFS migrate -m 1 $dirname/d2
3642 $LFS setdirstripe -i 1 -c 1 $dirname/d3
3643 dirname=$dirname/d3/subdir
3646 trace_cmd stat $dirname
3647 trace_cmd touch $dirname/f1
3648 trace_cmd stat $dirname/f1
3649 trace_cmd cat $dirname/f1
3650 dd if=/dev/zero of=$dirname/f1 bs=1M count=10 conv=fsync
3651 MATCHING_STRING="get xattr 'security.c'" \
3652 trace_cmd $TRUNCATE $dirname/f1 10240
3653 trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
3654 trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
3656 skip_noexit "2nd part needs >= 2 MDTs"
3659 run_test 49 "Avoid getxattr for encryption context"
3662 local testfile=$DIR/$tdir/$tfile
3663 local tmpfile=$TMP/abc
3664 local pagesz=$(getconf PAGESIZE)
3667 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3668 skip "client encryption not supported"
3670 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3671 skip "need dummy encryption support"
3673 stack_trap cleanup_for_enc_tests EXIT
3676 # write small file, data on MDT only
3677 tr '\0' '1' < /dev/zero |
3678 dd of=$tmpfile bs=1 count=5000 conv=fsync
3679 $LFS setstripe -E 1M -L mdt -E EOF $testfile
3680 cp $tmpfile $testfile
3682 # check that in-memory representation of file is correct
3683 cmp -bl $tmpfile $testfile ||
3684 error "file $testfile is corrupted in memory"
3686 cancel_lru_locks osc ; cancel_lru_locks mdc
3688 # check that file read from server is correct
3689 cmp -bl $tmpfile $testfile ||
3690 error "file $testfile is corrupted on server"
3692 # decrease size: truncate to PAGE_SIZE
3693 $TRUNCATE $tmpfile $pagesz
3694 $TRUNCATE $testfile $pagesz
3695 cancel_lru_locks osc ; cancel_lru_locks mdc
3696 cmp -bl $tmpfile $testfile ||
3697 error "file $testfile is corrupted (1)"
3699 # increase size: truncate to 2 x PAGE_SIZE
3701 $TRUNCATE $tmpfile $sz
3702 $TRUNCATE $testfile $sz
3703 cancel_lru_locks osc ; cancel_lru_locks mdc
3704 cmp -bl $tmpfile $testfile ||
3705 error "file $testfile is corrupted (2)"
3707 # truncate to PAGE_SIZE / 2
3709 $TRUNCATE $tmpfile $sz
3710 $TRUNCATE $testfile $sz
3711 cancel_lru_locks osc ; cancel_lru_locks mdc
3712 cmp -bl $tmpfile $testfile ||
3713 error "file $testfile is corrupted (3)"
3715 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16
3717 $TRUNCATE $tmpfile $sz
3718 $TRUNCATE $testfile $sz
3719 cancel_lru_locks osc ; cancel_lru_locks mdc
3720 cmp -bl $tmpfile $testfile ||
3721 error "file $testfile is corrupted (4)"
3723 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16
3725 $TRUNCATE $tmpfile $sz
3726 $TRUNCATE $testfile $sz
3727 cancel_lru_locks osc ; cancel_lru_locks mdc
3728 cmp -bl $tmpfile $testfile ||
3729 error "file $testfile is corrupted (5)"
3731 # truncate to a larger, non-multiple of PAGE_SIZE, in a different page
3732 sz=$((sz+pagesz+30))
3733 $TRUNCATE $tmpfile $sz
3734 $TRUNCATE $testfile $sz
3735 cancel_lru_locks osc ; cancel_lru_locks mdc
3736 cmp -bl $tmpfile $testfile ||
3737 error "file $testfile is corrupted (6)"
3740 cancel_lru_locks osc ; cancel_lru_locks mdc
3742 # write hole in file, data spread on MDT and OST
3743 tr '\0' '2' < /dev/zero |
3744 dd of=$tmpfile bs=1 count=1539 seek=1539074 conv=fsync,notrunc
3745 $LFS setstripe -E 1M -L mdt -E EOF $testfile
3746 cp --sparse=always $tmpfile $testfile
3748 # check that in-memory representation of file is correct
3749 cmp -bl $tmpfile $testfile ||
3750 error "file $testfile is corrupted in memory"
3752 cancel_lru_locks osc ; cancel_lru_locks mdc
3754 # check that file read from server is correct
3755 cmp -bl $tmpfile $testfile ||
3756 error "file $testfile is corrupted on server"
3758 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16,
3759 # inside OST part of data
3760 sz=$((1024*1024+13))
3761 $TRUNCATE $tmpfile $sz
3762 $TRUNCATE $testfile $sz
3763 cancel_lru_locks osc ; cancel_lru_locks mdc
3764 cmp -bl $tmpfile $testfile ||
3765 error "file $testfile is corrupted (7)"
3767 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16,
3768 # inside MDT part of data
3770 $TRUNCATE $tmpfile $sz
3771 $TRUNCATE $testfile $sz
3772 cancel_lru_locks osc ; cancel_lru_locks mdc
3773 cmp -bl $tmpfile $testfile ||
3774 error "file $testfile is corrupted (8)"
3776 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16,
3777 # inside MDT part of data
3778 sz=$((1024*1024-13))
3779 $TRUNCATE $tmpfile $sz
3780 $TRUNCATE $testfile $sz
3781 cancel_lru_locks osc ; cancel_lru_locks mdc
3782 cmp -bl $tmpfile $testfile ||
3783 error "file $testfile is corrupted (9)"
3785 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16,
3786 # inside OST part of data
3788 $TRUNCATE $tmpfile $sz
3789 $TRUNCATE $testfile $sz
3790 cancel_lru_locks osc ; cancel_lru_locks mdc
3791 cmp -bl $tmpfile $testfile ||
3792 error "file $testfile is corrupted (10)"
3796 run_test 50 "DoM encrypted file"
3799 [ "$MDS1_VERSION" -gt $(version_code 2.13.53) ] ||
3800 skip "Need MDS version at least 2.13.53"
3802 mkdir $DIR/$tdir || error "mkdir $tdir"
3804 touch $DIR/$tdir/$tfile || error "touch $tfile"
3805 cp $(which chown) $DIR/$tdir || error "cp chown"
3806 $RUNAS_CMD -u $ID0 $DIR/$tdir/chown $ID0 $DIR/$tdir/$tfile &&
3807 error "chown $tfile should fail"
3808 setcap 'CAP_CHOWN=ep' $DIR/$tdir/chown || error "setcap CAP_CHOWN"
3809 $RUNAS_CMD -u $ID0 $DIR/$tdir/chown $ID0 $DIR/$tdir/$tfile ||
3810 error "chown $tfile"
3811 rm $DIR/$tdir/$tfile || error "rm $tfile"
3813 touch $DIR/$tdir/$tfile || error "touch $tfile"
3814 cp $(which touch) $DIR/$tdir || error "cp touch"
3815 $RUNAS_CMD -u $ID0 $DIR/$tdir/touch $DIR/$tdir/$tfile &&
3816 error "touch should fail"
3817 setcap 'CAP_FOWNER=ep' $DIR/$tdir/touch || error "setcap CAP_FOWNER"
3818 $RUNAS_CMD -u $ID0 $DIR/$tdir/touch $DIR/$tdir/$tfile ||
3819 error "touch $tfile"
3820 rm $DIR/$tdir/$tfile || error "rm $tfile"
3823 for cap in "CAP_DAC_OVERRIDE" "CAP_DAC_READ_SEARCH"; do
3824 touch $DIR/$tdir/$tfile || error "touch $tfile"
3825 chmod 600 $DIR/$tdir/$tfile || error "chmod $tfile"
3826 cp $(which cat) $DIR/$tdir || error "cp cat"
3827 $RUNAS_CMD -u $ID0 $DIR/$tdir/cat $DIR/$tdir/$tfile &&
3828 error "cat should fail"
3829 setcap $cap=ep $DIR/$tdir/cat || error "setcap $cap"
3830 $RUNAS_CMD -u $ID0 $DIR/$tdir/cat $DIR/$tdir/$tfile ||
3832 rm $DIR/$tdir/$tfile || error "rm $tfile"
3835 run_test 51 "FS capabilities ==============="
3838 local testfile=$DIR/$tdir/$tfile
3839 local tmpfile=$TMP/$tfile
3840 local mirror1=$TMP/$tfile.mirror1
3841 local mirror2=$TMP/$tfile.mirror2
3843 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3844 skip "client encryption not supported"
3846 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3847 skip "need dummy encryption support"
3849 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
3851 stack_trap cleanup_for_enc_tests EXIT
3854 dd if=/dev/urandom of=$tmpfile bs=5000 count=1 conv=fsync
3856 $LFS mirror create -N -i0 -N -i1 $testfile ||
3857 error "could not create mirror"
3859 dd if=$tmpfile of=$testfile bs=5000 count=1 conv=fsync ||
3860 error "could not write to $testfile"
3862 $LFS mirror resync $testfile ||
3863 error "could not resync mirror"
3865 $LFS mirror verify -v $testfile ||
3866 error "verify mirror failed"
3868 $LFS mirror read -N 1 -o $mirror1 $testfile ||
3869 error "could not read from mirror 1"
3871 cmp -bl $tmpfile $mirror1 ||
3872 error "mirror 1 is corrupted"
3874 $LFS mirror read -N 2 -o $mirror2 $testfile ||
3875 error "could not read from mirror 2"
3877 cmp -bl $tmpfile $mirror2 ||
3878 error "mirror 2 is corrupted"
3880 tr '\0' '2' < /dev/zero |
3881 dd of=$tmpfile bs=1 count=9000 conv=fsync
3883 $LFS mirror write -N 1 -i $tmpfile $testfile ||
3884 error "could not write to mirror 1"
3886 $LFS mirror verify -v $testfile &&
3887 error "mirrors should be different"
3889 rm -f $testfile $mirror1 $mirror2
3891 $LFS setstripe -c1 -i0 $testfile
3892 dd if=$tmpfile of=$testfile bs=9000 count=1 conv=fsync ||
3893 error "write to $testfile failed"
3894 $LFS getstripe $testfile
3897 $LFS migrate -i1 $testfile ||
3898 error "migrate $testfile failed"
3899 $LFS getstripe $testfile
3900 stripe=$($LFS getstripe -i $testfile)
3901 [ $stripe -eq 1 ] || error "migrate file $testfile failed"
3904 cmp -bl $tmpfile $testfile ||
3905 error "migrated file is corrupted"
3907 $LFS mirror extend -N -i0 $testfile ||
3908 error "mirror extend $testfile failed"
3909 $LFS getstripe $testfile
3910 mirror_count=$($LFS getstripe -N $testfile)
3911 [ $mirror_count -eq 2 ] ||
3912 error "mirror extend file $testfile failed (1)"
3913 stripe=$($LFS getstripe --mirror-id=1 -i $testfile)
3914 [ $stripe -eq 1 ] || error "mirror extend file $testfile failed (2)"
3915 stripe=$($LFS getstripe --mirror-id=2 -i $testfile)
3916 [ $stripe -eq 0 ] || error "mirror extend file $testfile failed (3)"
3919 $LFS mirror verify -v $testfile ||
3920 error "mirror verify failed"
3921 $LFS mirror read -N 1 -o $mirror1 $testfile ||
3922 error "read from mirror 1 failed"
3923 cmp -bl $tmpfile $mirror1 ||
3924 error "corruption of mirror 1"
3925 $LFS mirror read -N 2 -o $mirror2 $testfile ||
3926 error "read from mirror 2 failed"
3927 cmp -bl $tmpfile $mirror2 ||
3928 error "corruption of mirror 2"
3930 $LFS mirror split --mirror-id 1 -f ${testfile}.mirror $testfile &&
3931 error "mirror split -f should fail"
3933 $LFS mirror split --mirror-id 1 $testfile &&
3934 error "mirror split without -d should fail"
3936 $LFS mirror split --mirror-id 1 -d $testfile ||
3937 error "mirror split failed"
3938 $LFS getstripe $testfile
3939 mirror_count=$($LFS getstripe -N $testfile)
3940 [ $mirror_count -eq 1 ] ||
3941 error "mirror split file $testfile failed (1)"
3942 stripe=$($LFS getstripe --mirror-id=1 -i $testfile)
3943 [ -z "$stripe" ] || error "mirror extend file $testfile failed (2)"
3944 stripe=$($LFS getstripe --mirror-id=2 -i $testfile)
3945 [ $stripe -eq 0 ] || error "mirror extend file $testfile failed (3)"
3948 cmp -bl $tmpfile $testfile ||
3949 error "extended/split file is corrupted"
3951 rm -f $tmpfile $mirror1 $mirror2
3953 run_test 52 "Mirrored encrypted file"
3956 local testfile=$DIR/$tdir/$tfile
3957 local testfile2=$DIR2/$tdir/$tfile
3958 local tmpfile=$TMP/$tfile.tmp
3959 local resfile=$TMP/$tfile.res
3963 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3964 skip "client encryption not supported"
3966 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3967 skip "need dummy encryption support"
3969 pagesz=$(getconf PAGESIZE)
3970 [[ $pagesz == 65536 ]] || skip "Need 64K PAGE_SIZE client"
3972 do_node $mds1_HOST \
3973 "mount.lustre --help |& grep -q 'test_dummy_encryption:'" ||
3974 skip "need dummy encryption support on MDS client mount"
3976 # this test is probably useless now, but may turn out to be useful when
3977 # Lustre supports servers with PAGE_SIZE != 4KB
3978 pagesz=$(do_node $mds1_HOST getconf PAGESIZE)
3979 [[ $pagesz == 4096 ]] || skip "Need 4K PAGE_SIZE MDS client"
3981 stack_trap cleanup_for_enc_tests EXIT
3982 stack_trap "zconf_umount $mds1_HOST $MOUNT2" EXIT
3985 $LFS setstripe -c1 -i0 $testfile
3987 # write from 1st client
3988 cat /dev/urandom | tr -dc 'a-zA-Z0-9' |
3989 dd of=$tmpfile bs=$((pagesz+3)) count=2 conv=fsync
3990 dd if=$tmpfile of=$testfile bs=$((pagesz+3)) count=2 conv=fsync ||
3991 error "could not write to $testfile (1)"
3993 # read from 2nd client
3994 # mount and IOs must be done in the same shell session, otherwise
3995 # encryption key in session keyring is missing
3996 do_node $mds1_HOST "mkdir -p $MOUNT2"
3997 do_node $mds1_HOST \
3998 "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
3999 $MGSNID:/$FSNAME $MOUNT2 && \
4000 dd if=$testfile2 of=$resfile bs=$((pagesz+3)) count=2" ||
4001 error "could not read from $testfile2 (1)"
4004 filemd5=$(do_node $mds1_HOST md5sum $resfile | awk '{print $1}')
4005 [ $filemd5 = $(md5sum $tmpfile | awk '{print $1}') ] ||
4006 error "file is corrupted (1)"
4007 do_node $mds1_HOST rm -f $resfile
4010 # truncate from 2nd client
4011 $TRUNCATE $tmpfile $((pagesz+3))
4012 zconf_umount $mds1_HOST $MOUNT2 ||
4013 error "umount $mds1_HOST $MOUNT2 failed (1)"
4014 do_node $mds1_HOST "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4015 $MGSNID:/$FSNAME $MOUNT2 && \
4016 $TRUNCATE $testfile2 $((pagesz+3))" ||
4017 error "could not truncate $testfile2 (1)"
4020 cmp -bl $tmpfile $testfile ||
4021 error "file is corrupted (2)"
4022 rm -f $tmpfile $testfile
4024 zconf_umount $mds1_HOST $MOUNT2 ||
4025 error "umount $mds1_HOST $MOUNT2 failed (2)"
4028 do_node $mds1_HOST \
4029 dd if=/dev/urandom of=$tmpfile bs=$((pagesz+3)) count=2 conv=fsync
4030 # write from 2nd client
4031 do_node $mds1_HOST \
4032 "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4033 $MGSNID:/$FSNAME $MOUNT2 && \
4034 dd if=$tmpfile of=$testfile2 bs=$((pagesz+3)) count=2 conv=fsync" ||
4035 error "could not write to $testfile2 (2)"
4037 # read from 1st client
4038 dd if=$testfile of=$resfile bs=$((pagesz+3)) count=2 ||
4039 error "could not read from $testfile (2)"
4042 filemd5=$(do_node $mds1_HOST md5sum -b $tmpfile | awk '{print $1}')
4043 [ $filemd5 = $(md5sum -b $resfile | awk '{print $1}') ] ||
4044 error "file is corrupted (3)"
4048 # truncate from 1st client
4049 do_node $mds1_HOST "$TRUNCATE $tmpfile $((pagesz+3))"
4050 $TRUNCATE $testfile $((pagesz+3)) ||
4051 error "could not truncate $testfile (2)"
4054 zconf_umount $mds1_HOST $MOUNT2 ||
4055 error "umount $mds1_HOST $MOUNT2 failed (3)"
4056 do_node $mds1_HOST "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4057 $MGSNID:/$FSNAME $MOUNT2 && \
4058 cmp -bl $tmpfile $testfile2" ||
4059 error "file is corrupted (4)"
4061 do_node $mds1_HOST rm -f $tmpfile
4064 run_test 53 "Mixed PAGE_SIZE clients"
4067 local testdir=$DIR/$tdir/$ID0
4068 local testfile=$testdir/$tfile
4069 local testfile2=$testdir/${tfile}withveryverylongnametoexercisecode
4070 local tmpfile=$TMP/${tfile}.tmp
4071 local resfile=$TMP/${tfile}.res
4073 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4074 skip "client encryption not supported"
4076 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4077 skip "need dummy encryption support"
4079 which fscrypt || skip "This test needs fscrypt userspace tool"
4081 fscrypt setup --force --verbose || error "fscrypt global setup failed"
4082 sed -i 's/\(.*\)policy_version\(.*\):\(.*\)\"[0-9]*\"\(.*\)/\1policy_version\2:\3"2"\4/' \
4084 fscrypt setup --verbose $MOUNT || error "fscrypt setup $MOUNT failed"
4086 chown -R $ID0:$ID0 $testdir
4088 echo -e 'mypass\nmypass' | su - $USER0 -c "fscrypt encrypt --verbose \
4089 --source=custom_passphrase --name=protector $testdir" ||
4090 error "fscrypt encrypt failed"
4092 echo -e 'mypass\nmypass' | su - $USER0 -c "fscrypt encrypt --verbose \
4093 --source=custom_passphrase --name=protector2 $testdir" &&
4094 error "second fscrypt encrypt should have failed"
4096 mkdir -p ${testdir}2 || error "mkdir ${testdir}2 failed"
4097 touch ${testdir}2/f || error "mkdir ${testdir}2/f failed"
4100 echo -e 'mypass\nmypass' | fscrypt encrypt --verbose \
4101 --source=custom_passphrase --name=protector3 ${testdir}2 &&
4102 error "fscrypt encrypt on non-empty dir should have failed"
4104 $RUNAS dd if=/dev/urandom of=$testfile bs=127 count=1 conv=fsync ||
4105 error "write to encrypted file $testfile failed"
4106 cp $testfile $tmpfile
4107 $RUNAS dd if=/dev/urandom of=$testfile2 bs=127 count=1 conv=fsync ||
4108 error "write to encrypted file $testfile2 failed"
4109 $RUNAS mkdir $testdir/subdir || error "mkdir subdir failed"
4110 $RUNAS touch $testdir/subdir/subfile || error "mkdir subdir failed"
4112 $RUNAS fscrypt lock --verbose $testdir ||
4113 error "fscrypt lock $testdir failed (1)"
4115 $RUNAS ls -R $testdir || error "ls -R $testdir failed"
4116 local filecount=$($RUNAS find $testdir -type f | wc -l)
4117 [ $filecount -eq 3 ] || error "found $filecount files"
4119 scrambledfiles=( $(find $testdir/ -maxdepth 1 -type f) )
4120 $RUNAS hexdump -C ${scrambledfiles[0]} &&
4121 error "reading ${scrambledfiles[0]} should fail without key"
4123 $RUNAS touch ${testfile}.nokey &&
4124 error "touch ${testfile}.nokey should have failed without key"
4126 echo mypass | $RUNAS fscrypt unlock --verbose $testdir ||
4127 error "fscrypt unlock $testdir failed (1)"
4129 $RUNAS cat $testfile > $resfile ||
4130 error "reading $testfile failed"
4132 cmp -bl $tmpfile $resfile || error "file read differs from file written"
4134 $RUNAS fscrypt lock --verbose $testdir ||
4135 error "fscrypt lock $testdir failed (2)"
4137 $RUNAS hexdump -C ${scrambledfiles[1]} &&
4138 error "reading ${scrambledfiles[1]} should fail without key"
4140 echo mypass | $RUNAS fscrypt unlock --verbose $testdir ||
4141 error "fscrypt unlock $testdir failed (2)"
4144 $RUNAS fscrypt lock --verbose $testdir ||
4145 error "fscrypt lock $testdir failed (3)"
4147 rm -f $tmpfile $resfile
4149 run_test 54 "Encryption policies with fscrypt"
4153 if is_mounted $MOUNT; then
4154 umount_client $MOUNT || error "umount $MOUNT failed"
4157 do_facet mgs $LCTL nodemap_del c0
4158 do_facet mgs $LCTL nodemap_modify --name default \
4159 --property admin --value 0
4160 do_facet mgs $LCTL nodemap_modify --name default \
4161 --property trusted --value 0
4162 wait_nm_sync default admin_nodemap
4163 wait_nm_sync default trusted_nodemap
4165 do_facet mgs $LCTL nodemap_activate 0
4166 wait_nm_sync active 0
4168 if $SHARED_KEY; then
4169 export SK_UNIQUE_NM=false
4173 mount_client $MOUNT ${MOUNT_OPTS} || error "remount failed"
4174 if [ "$MOUNT_2" ]; then
4175 mount_client $MOUNT2 ${MOUNT_OPTS} || error "remount failed"
4180 (( $MDS1_VERSION > $(version_code 2.12.6.2) )) ||
4181 skip "Need MDS version at least 2.12.6.3"
4186 mkdir -p $DIR/$tdir/$USER0/testdir_groups
4187 chown root:$ID0 $DIR/$tdir/$USER0
4188 chmod 770 $DIR/$tdir/$USER0
4189 chmod g+s $DIR/$tdir/$USER0
4190 chown $ID0:$ID0 $DIR/$tdir/$USER0/testdir_groups
4191 chmod 770 $DIR/$tdir/$USER0/testdir_groups
4192 chmod g+s $DIR/$tdir/$USER0/testdir_groups
4194 # unmount client completely
4195 umount_client $MOUNT || error "umount $MOUNT failed"
4196 if is_mounted $MOUNT2; then
4197 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
4200 do_nodes $(comma_list $(all_mdts_nodes)) \
4201 $LCTL set_param mdt.*.identity_upcall=NONE
4203 stack_trap cleanup_55 EXIT
4205 do_facet mgs $LCTL nodemap_activate 1
4208 do_facet mgs $LCTL nodemap_del c0 || true
4209 wait_nm_sync c0 id ''
4211 do_facet mgs $LCTL nodemap_modify --name default \
4212 --property admin --value 1
4213 do_facet mgs $LCTL nodemap_modify --name default \
4214 --property trusted --value 1
4215 wait_nm_sync default admin_nodemap
4216 wait_nm_sync default trusted_nodemap
4218 client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
4219 client_nid=$(h2nettype $client_ip)
4220 do_facet mgs $LCTL nodemap_add c0
4221 do_facet mgs $LCTL nodemap_add_range \
4222 --name c0 --range $client_nid
4223 do_facet mgs $LCTL nodemap_modify --name c0 \
4224 --property admin --value 0
4225 do_facet mgs $LCTL nodemap_modify --name c0 \
4226 --property trusted --value 1
4227 wait_nm_sync c0 admin_nodemap
4228 wait_nm_sync c0 trusted_nodemap
4230 if $SHARED_KEY; then
4231 export SK_UNIQUE_NM=true
4232 # set some generic fileset to trigger SSK code
4236 # remount client to take nodemap into account
4237 zconf_mount_clients $HOSTNAME $MOUNT $MOUNT_OPTS ||
4238 error "remount failed"
4241 euid_access $USER0 $DIR/$tdir/$USER0/testdir_groups/file
4243 run_test 55 "access with seteuid"
4246 local testfile=$DIR/$tdir/$tfile
4248 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4250 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4251 skip "client encryption not supported"
4253 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4254 skip "need dummy encryption support"
4256 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4258 stack_trap cleanup_for_enc_tests EXIT
4261 $LFS setstripe -c1 $testfile
4262 dd if=/dev/urandom of=$testfile bs=1M count=3 conv=fsync
4263 filefrag -v $testfile || error "filefrag $testfile failed"
4264 (( $(filefrag -v $testfile | grep -c encrypted) >= 1 )) ||
4265 error "filefrag $testfile does not show encrypted flag"
4266 (( $(filefrag -v $testfile | grep -c encoded) >= 1 )) ||
4267 error "filefrag $testfile does not show encoded flag"
4269 run_test 56 "FIEMAP on encrypted file"
4272 local testdir=$DIR/$tdir/mytestdir
4273 local testfile=$DIR/$tdir/$tfile
4275 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4277 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4278 skip "client encryption not supported"
4280 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4281 skip "need dummy encryption support"
4285 setfattr -n security.c -v myval $testdir &&
4286 error "setting xattr on $testdir should have failed (1)"
4288 setfattr -n security.c -v myval $testfile &&
4289 error "setting xattr on $testfile should have failed (1)"
4293 stack_trap cleanup_for_enc_tests EXIT
4297 if [ $(getfattr -n security.c $testdir 2>&1 |
4298 grep -ci "Operation not permitted") -eq 0 ]; then
4299 error "getting xattr on $testdir should have failed"
4301 getfattr -d -m - $testdir 2>&1 | grep security\.c &&
4302 error "listing xattrs on $testdir should not expose security.c"
4303 if [ $(setfattr -n security.c -v myval $testdir 2>&1 |
4304 grep -ci "Operation not permitted") -eq 0 ]; then
4305 error "setting xattr on $testdir should have failed (2)"
4308 if [ $(getfattr -n security.c $testfile 2>&1 |
4309 grep -ci "Operation not permitted") -eq 0 ]; then
4310 error "getting xattr on $testfile should have failed"
4312 getfattr -d -m - $testfile 2>&1 | grep security\.c &&
4313 error "listing xattrs on $testfile should not expose security.c"
4314 if [ $(setfattr -n security.c -v myval $testfile 2>&1 |
4315 grep -ci "Operation not permitted") -eq 0 ]; then
4316 error "setting xattr on $testfile should have failed (2)"
4320 run_test 57 "security.c xattr protection"
4323 local testdir=$DIR/$tdir/mytestdir
4324 local testfile=$DIR/$tdir/$tfile
4326 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4328 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4329 skip "client encryption not supported"
4331 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4332 skip "need dummy encryption support"
4334 stack_trap cleanup_for_enc_tests EXIT
4337 touch $DIR/$tdir/$tfile
4338 mkdir $DIR/$tdir/subdir
4342 echo 3 > /proc/sys/vm/drop_caches
4344 ll_decode_linkea $DIR/$tdir/$tfile || error "cannot read $tfile linkea"
4345 ll_decode_linkea $DIR/$tdir/subdir || error "cannot read subdir linkea"
4347 for ((i = 0; i < 1000; i = $((i+1)))); do
4348 mkdir -p $DIR/$tdir/d${i}
4349 touch $DIR/$tdir/f${i}
4350 createmany -m $DIR/$tdir/d${i}/f 5 > /dev/null
4355 echo 3 > /proc/sys/vm/drop_caches
4358 ls -ailR $MOUNT > /dev/null || error "fail to ls"
4360 run_test 58 "access to enc file's xattrs"
4362 log "cleanup: ======================================================"
4365 for num in $(seq $MDSCOUNT); do
4366 if [ "${identity_old[$num]}" = 1 ]; then
4367 switch_identity $num false || identity_old[$num]=$?
4371 $RUNAS_CMD -u $ID0 ls $DIR
4372 $RUNAS_CMD -u $ID1 ls $DIR
4377 check_and_cleanup_lustre