3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
17 ALWAYS_EXCEPT="$SANITY_SEC_EXCEPT "
18 # bug number for skipped test:
20 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
22 [ "$SLOW" = "no" ] && EXCEPT_SLOW="26"
24 NODEMAP_TESTS=$(seq 7 26)
26 if ! check_versions; then
27 echo "It is NOT necessary to test nodemap under interoperation mode"
28 EXCEPT="$EXCEPT $NODEMAP_TESTS"
33 RUNAS_CMD=${RUNAS_CMD:-runas}
35 WTL=${WTL:-"$LUSTRE/tests/write_time_limit"}
38 PERM_CONF=$CONFDIR/perm.conf
40 HOSTNAME_CHECKSUM=$(hostname | sum | awk '{ print $1 }')
41 SUBNET_CHECKSUM=$(expr $HOSTNAME_CHECKSUM % 250 + 1)
43 require_dsh_mds || exit 0
44 require_dsh_ost || exit 0
46 clients=${CLIENTS//,/ }
47 num_clients=$(get_node_count ${clients})
48 clients_arr=($clients)
52 USER0=$(getent passwd | grep :$ID0:$ID0: | cut -d: -f1)
53 USER1=$(getent passwd | grep :$ID1:$ID1: | cut -d: -f1)
55 if [ "$SLOW" == "yes" ]; then
58 NODEMAP_IPADDR_LIST="1 10 64 128 200 250"
63 NODEMAP_IPADDR_LIST="1 250"
66 NODEMAP_MAX_ID=$((ID0 + NODEMAP_ID_COUNT))
69 skip "need to add user0 ($ID0:$ID0)" && exit 0
72 skip "need to add user1 ($ID1:$ID1)" && exit 0
74 IDBASE=${IDBASE:-60000}
76 # changes to mappings must be reflected in test 23
78 [0]="$((IDBASE+3)):$((IDBASE+0)) $((IDBASE+4)):$((IDBASE+2))"
79 [1]="$((IDBASE+5)):$((IDBASE+1)) $((IDBASE+6)):$((IDBASE+2))"
82 check_and_setup_lustre
87 GSS_REF=$(lsmod | grep ^ptlrpc_gss | awk '{print $3}')
88 if [ ! -z "$GSS_REF" -a "$GSS_REF" != "0" ]; then
90 echo "with GSS support"
93 echo "without GSS support"
96 MDT=$(do_facet $SINGLEMDS lctl get_param -N "mdt.\*MDT0000" |
98 [ -z "$MDT" ] && error "fail to get MDT device" && exit 1
99 do_facet $SINGLEMDS "mkdir -p $CONFDIR"
100 IDENTITY_FLUSH=mdt.$MDT.identity_flush
101 IDENTITY_UPCALL=mdt.$MDT.identity_upcall
110 if ! $RUNAS_CMD -u $user krb5_login.sh; then
111 error "$user login kerberos failed."
115 if ! $RUNAS_CMD -u $user -g $group ls $DIR > /dev/null 2>&1; then
116 $RUNAS_CMD -u $user lfs flushctx -k
117 $RUNAS_CMD -u $user krb5_login.sh
118 if ! $RUNAS_CMD -u$user -g$group ls $DIR > /dev/null 2>&1; then
119 error "init $user $group failed."
125 declare -a identity_old
128 for num in $(seq $MDSCOUNT); do
129 switch_identity $num true || identity_old[$num]=$?
132 if ! $RUNAS_CMD -u $ID0 ls $DIR > /dev/null 2>&1; then
133 sec_login $USER0 $USER0
136 if ! $RUNAS_CMD -u $ID1 ls $DIR > /dev/null 2>&1; then
137 sec_login $USER1 $USER1
142 # run as different user
146 chmod 0755 $DIR || error "chmod (1)"
147 rm -rf $DIR/$tdir || error "rm (1)"
148 mkdir -p $DIR/$tdir || error "mkdir (1)"
149 chown $USER0 $DIR/$tdir || error "chown (2)"
150 $RUNAS_CMD -u $ID0 ls $DIR || error "ls (1)"
151 rm -f $DIR/f0 || error "rm (2)"
152 $RUNAS_CMD -u $ID0 touch $DIR/f0 && error "touch (1)"
153 $RUNAS_CMD -u $ID0 touch $DIR/$tdir/f1 || error "touch (2)"
154 $RUNAS_CMD -u $ID1 touch $DIR/$tdir/f2 && error "touch (3)"
155 touch $DIR/$tdir/f3 || error "touch (4)"
156 chown root $DIR/$tdir || error "chown (3)"
157 chgrp $USER0 $DIR/$tdir || error "chgrp (1)"
158 chmod 0775 $DIR/$tdir || error "chmod (2)"
159 $RUNAS_CMD -u $ID0 touch $DIR/$tdir/f4 || error "touch (5)"
160 $RUNAS_CMD -u $ID1 touch $DIR/$tdir/f5 && error "touch (6)"
161 touch $DIR/$tdir/f6 || error "touch (7)"
162 rm -rf $DIR/$tdir || error "rm (3)"
164 run_test 0 "uid permission ============================="
168 [ $GSS_SUP = 0 ] && skip "without GSS support." && return
171 mkdir_on_mdt0 $DIR/$tdir
173 chown $USER0 $DIR/$tdir || error "chown (1)"
174 $RUNAS_CMD -u $ID1 -v $ID0 touch $DIR/$tdir/f0 && error "touch (2)"
175 echo "enable uid $ID1 setuid"
176 do_facet $SINGLEMDS "echo '* $ID1 setuid' >> $PERM_CONF"
177 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
178 $RUNAS_CMD -u $ID1 -v $ID0 touch $DIR/$tdir/f1 || error "touch (3)"
180 chown root $DIR/$tdir || error "chown (4)"
181 chgrp $USER0 $DIR/$tdir || error "chgrp (5)"
182 chmod 0770 $DIR/$tdir || error "chmod (6)"
183 $RUNAS_CMD -u $ID1 -g $ID1 touch $DIR/$tdir/f2 && error "touch (7)"
184 $RUNAS_CMD -u$ID1 -g$ID1 -j$ID0 touch $DIR/$tdir/f3 && error "touch (8)"
185 echo "enable uid $ID1 setuid,setgid"
186 do_facet $SINGLEMDS "echo '* $ID1 setuid,setgid' > $PERM_CONF"
187 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
188 $RUNAS_CMD -u $ID1 -g $ID1 -j $ID0 touch $DIR/$tdir/f4 ||
190 $RUNAS_CMD -u $ID1 -v $ID0 -g $ID1 -j $ID0 touch $DIR/$tdir/f5 ||
195 do_facet $SINGLEMDS "rm -f $PERM_CONF"
196 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
198 run_test 1 "setuid/gid ============================="
200 # bug 3285 - supplementary group should always succeed.
201 # NB: the supplementary groups are set for local client only,
202 # as for remote client, the groups of the specified uid on MDT
203 # will be obtained by upcall /sbin/l_getidentity and used.
205 [[ "$MDS1_VERSION" -ge $(version_code 2.6.93) ]] ||
206 [[ "$MDS1_VERSION" -ge $(version_code 2.5.35) &&
207 "$MDS1_VERSION" -lt $(version_code 2.5.50) ]] ||
208 skip "Need MDS version at least 2.6.93 or 2.5.35"
212 chmod 0771 $DIR/$tdir
213 chgrp $ID0 $DIR/$tdir
214 $RUNAS_CMD -u $ID0 ls $DIR/$tdir || error "setgroups (1)"
215 do_facet $SINGLEMDS "echo '* $ID1 setgrp' > $PERM_CONF"
216 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
217 $RUNAS_CMD -u $ID1 -G1,2,$ID0 ls $DIR/$tdir ||
218 error "setgroups (2)"
219 $RUNAS_CMD -u $ID1 -G1,2 ls $DIR/$tdir && error "setgroups (3)"
222 do_facet $SINGLEMDS "rm -f $PERM_CONF"
223 do_facet $SINGLEMDS "lctl set_param -n $IDENTITY_FLUSH=-1"
225 run_test 4 "set supplementary group ==============="
231 squash_id default 99 0
232 wait_nm_sync default squash_uid '' inactive
233 squash_id default 99 1
234 wait_nm_sync default squash_gid '' inactive
235 for (( i = 0; i < NODEMAP_COUNT; i++ )); do
236 local csum=${HOSTNAME_CHECKSUM}_${i}
238 do_facet mgs $LCTL nodemap_add $csum
240 if [ $rc -ne 0 ]; then
241 echo "nodemap_add $csum failed with $rc"
245 wait_update_facet --verbose mgs \
246 "$LCTL get_param nodemap.$csum.id 2>/dev/null | \
247 grep -c $csum || true" 1 30 ||
250 for (( i = 0; i < NODEMAP_COUNT; i++ )); do
251 local csum=${HOSTNAME_CHECKSUM}_${i}
253 wait_nm_sync $csum id '' inactive
261 for ((i = 0; i < NODEMAP_COUNT; i++)); do
262 local csum=${HOSTNAME_CHECKSUM}_${i}
264 if ! do_facet mgs $LCTL nodemap_del $csum; then
265 error "nodemap_del $csum failed with $?"
269 wait_update_facet --verbose mgs \
270 "$LCTL get_param nodemap.$csum.id 2>/dev/null | \
271 grep -c $csum || true" 0 30 ||
274 for (( i = 0; i < NODEMAP_COUNT; i++ )); do
275 local csum=${HOSTNAME_CHECKSUM}_${i}
277 wait_nm_sync $csum id '' inactive
284 local cmd="$LCTL nodemap_add_range"
288 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
289 range="$SUBNET_CHECKSUM.${2}.${j}.[1-253]@tcp"
290 if ! do_facet mgs $cmd --name $1 --range $range; then
299 local cmd="$LCTL nodemap_del_range"
303 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
304 range="$SUBNET_CHECKSUM.${2}.${j}.[1-253]@tcp"
305 if ! do_facet mgs $cmd --name $1 --range $range; then
315 local cmd="$LCTL nodemap_add_idmap"
319 (( $MDS1_VERSION >= $(version_code 2.14.52) )) || do_proj=false
321 echo "Start to add idmaps ..."
322 for ((i = 0; i < NODEMAP_COUNT; i++)); do
325 for ((j = $ID0; j < NODEMAP_MAX_ID; j++)); do
326 local csum=${HOSTNAME_CHECKSUM}_${i}
328 local fs_id=$((j + 1))
330 if ! do_facet mgs $cmd --name $csum --idtype uid \
331 --idmap $client_id:$fs_id; then
334 if ! do_facet mgs $cmd --name $csum --idtype gid \
335 --idmap $client_id:$fs_id; then
339 if ! do_facet mgs $cmd --name $csum \
340 --idtype projid --idmap \
341 $client_id:$fs_id; then
351 update_idmaps() { #LU-10040
352 [ "$MGS_VERSION" -lt $(version_code 2.10.55) ] &&
353 skip "Need MGS >= 2.10.55"
355 local csum=${HOSTNAME_CHECKSUM}_0
356 local old_id_client=$ID0
357 local old_id_fs=$((ID0 + 1))
358 local new_id=$((ID0 + 100))
365 echo "Start to update idmaps ..."
367 #Inserting an existed idmap should return error
368 cmd="$LCTL nodemap_add_idmap --name $csum --idtype uid"
370 $cmd --idmap $old_id_client:$old_id_fs 2>/dev/null; then
371 error "insert idmap {$old_id_client:$old_id_fs} " \
372 "should return error"
377 #Update id_fs and check it
378 if ! do_facet mgs $cmd --idmap $old_id_client:$new_id; then
379 error "$cmd --idmap $old_id_client:$new_id failed"
383 tmp_id=$(do_facet mgs $LCTL get_param -n nodemap.$csum.idmap |
384 awk '{ print $7 }' | sed -n '2p')
385 [ $tmp_id != $new_id ] && { error "new id_fs $tmp_id != $new_id"; \
386 rc=$((rc + 1)); return $rc; }
388 #Update id_client and check it
389 if ! do_facet mgs $cmd --idmap $new_id:$new_id; then
390 error "$cmd --idmap $new_id:$new_id failed"
394 tmp_id=$(do_facet mgs $LCTL get_param -n nodemap.$csum.idmap |
395 awk '{ print $5 }' | sed -n "$((NODEMAP_ID_COUNT + 1)) p")
396 tmp_id=$(echo ${tmp_id%,*}) #e.g. "501,"->"501"
397 [ $tmp_id != $new_id ] && { error "new id_client $tmp_id != $new_id"; \
398 rc=$((rc + 1)); return $rc; }
400 #Delete above updated idmap
401 cmd="$LCTL nodemap_del_idmap --name $csum --idtype uid"
402 if ! do_facet mgs $cmd --idmap $new_id:$new_id; then
403 error "$cmd --idmap $new_id:$new_id failed"
408 #restore the idmaps to make delete_idmaps work well
409 cmd="$LCTL nodemap_add_idmap --name $csum --idtype uid"
410 if ! do_facet mgs $cmd --idmap $old_id_client:$old_id_fs; then
411 error "$cmd --idmap $old_id_client:$old_id_fs failed"
421 local cmd="$LCTL nodemap_del_idmap"
425 (( $MDS1_VERSION >= $(version_code 2.14.52) )) || do_proj=false
427 echo "Start to delete idmaps ..."
428 for ((i = 0; i < NODEMAP_COUNT; i++)); do
431 for ((j = $ID0; j < NODEMAP_MAX_ID; j++)); do
432 local csum=${HOSTNAME_CHECKSUM}_${i}
434 local fs_id=$((j + 1))
436 if ! do_facet mgs $cmd --name $csum --idtype uid \
437 --idmap $client_id:$fs_id; then
440 if ! do_facet mgs $cmd --name $csum --idtype gid \
441 --idmap $client_id:$fs_id; then
445 if ! do_facet mgs $cmd --name $csum \
446 --idtype projid --idmap \
447 $client_id:$fs_id; then
461 local cmd="$LCTL nodemap_modify"
464 proc[0]="admin_nodemap"
465 proc[1]="trusted_nodemap"
469 for ((idx = 0; idx < 2; idx++)); do
470 if ! do_facet mgs $cmd --name $1 --property ${option[$idx]} \
475 if ! do_facet mgs $cmd --name $1 --property ${option[$idx]} \
485 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
486 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
490 cmd[0]="$LCTL nodemap_modify --property squash_uid"
491 cmd[1]="$LCTL nodemap_modify --property squash_gid"
492 cmd[2]="$LCTL nodemap_modify --property squash_projid"
494 if ! do_facet mgs ${cmd[$3]} --name $1 --value $2; then
499 # ensure that the squash defaults are the expected defaults
500 squash_id default 99 0
501 wait_nm_sync default squash_uid '' inactive
502 squash_id default 99 1
503 wait_nm_sync default squash_gid '' inactive
504 if [ "$MDS1_VERSION" -ge $(version_code 2.14.50) ]; then
505 squash_id default 99 2
506 wait_nm_sync default squash_projid '' inactive
512 cmd="$LCTL nodemap_test_nid"
514 nid=$(do_facet mgs $cmd $1)
516 if [ $nid == $2 ]; then
524 # restore activation state
525 do_facet mgs $LCTL nodemap_activate 0
531 local cmd="$LCTL nodemap_test_id"
534 echo "Start to test idmaps ..."
535 ## nodemap deactivated
536 if ! do_facet mgs $LCTL nodemap_activate 0; then
539 for ((id = $ID0; id < NODEMAP_MAX_ID; id++)); do
542 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
543 local nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
544 local fs_id=$(do_facet mgs $cmd --nid $nid \
545 --idtype uid --id $id)
546 if [ $fs_id != $id ]; then
547 echo "expected $id, got $fs_id"
554 if ! do_facet mgs $LCTL nodemap_activate 1; then
558 for ((id = $ID0; id < NODEMAP_MAX_ID; id++)); do
559 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
560 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
561 fs_id=$(do_facet mgs $cmd --nid $nid \
562 --idtype uid --id $id)
563 expected_id=$((id + 1))
564 if [ $fs_id != $expected_id ]; then
565 echo "expected $expected_id, got $fs_id"
572 for ((i = 0; i < NODEMAP_COUNT; i++)); do
573 local csum=${HOSTNAME_CHECKSUM}_${i}
575 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
576 --property trusted --value 1; then
577 error "nodemap_modify $csum failed with $?"
582 for ((id = $ID0; id < NODEMAP_MAX_ID; id++)); do
583 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
584 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
585 fs_id=$(do_facet mgs $cmd --nid $nid \
586 --idtype uid --id $id)
587 if [ $fs_id != $id ]; then
588 echo "expected $id, got $fs_id"
594 ## ensure allow_root_access is enabled
595 for ((i = 0; i < NODEMAP_COUNT; i++)); do
596 local csum=${HOSTNAME_CHECKSUM}_${i}
598 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
599 --property admin --value 1; then
600 error "nodemap_modify $csum failed with $?"
605 ## check that root allowed
606 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
607 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
608 fs_id=$(do_facet mgs $cmd --nid $nid --idtype uid --id 0)
609 if [ $fs_id != 0 ]; then
610 echo "root allowed expected 0, got $fs_id"
615 ## ensure allow_root_access is disabled
616 for ((i = 0; i < NODEMAP_COUNT; i++)); do
617 local csum=${HOSTNAME_CHECKSUM}_${i}
619 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
620 --property admin --value 0; then
621 error "nodemap_modify ${HOSTNAME_CHECKSUM}_${i} "
627 ## check that root is mapped to 99
628 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
629 nid="$SUBNET_CHECKSUM.0.${j}.100@tcp"
630 fs_id=$(do_facet mgs $cmd --nid $nid --idtype uid --id 0)
631 if [ $fs_id != 99 ]; then
632 error "root squash expected 99, got $fs_id"
637 ## reset client trust to 0
638 for ((i = 0; i < NODEMAP_COUNT; i++)); do
639 if ! do_facet mgs $LCTL nodemap_modify \
640 --name ${HOSTNAME_CHECKSUM}_${i} \
641 --property trusted --value 0; then
642 error "nodemap_modify ${HOSTNAME_CHECKSUM}_${i} "
654 remote_mgs_nodsh && skip "remote MGS with nodsh"
655 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
656 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
660 [[ $rc != 0 ]] && error "nodemap_add failed with $rc"
664 [[ $rc != 0 ]] && error "nodemap_del failed with $rc"
668 run_test 7 "nodemap create and delete"
673 remote_mgs_nodsh && skip "remote MGS with nodsh"
674 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
675 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
681 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
687 [[ $rc == 0 ]] && error "duplicate nodemap_add allowed with $rc" &&
693 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 3
697 run_test 8 "nodemap reject duplicates"
703 remote_mgs_nodsh && skip "remote MGS with nodsh"
704 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
705 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
710 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
713 for ((i = 0; i < NODEMAP_COUNT; i++)); do
714 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
718 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
721 for ((i = 0; i < NODEMAP_COUNT; i++)); do
722 if ! delete_range ${HOSTNAME_CHECKSUM}_${i} $i; then
726 [[ $rc != 0 ]] && error "nodemap_del_range failed with $rc" && return 4
731 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
735 run_test 9 "nodemap range add"
740 remote_mgs_nodsh && skip "remote MGS with nodsh"
741 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
742 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
747 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
750 for ((i = 0; i < NODEMAP_COUNT; i++)); do
751 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
755 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
758 for ((i = 0; i < NODEMAP_COUNT; i++)); do
759 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
763 [[ $rc == 0 ]] && error "nodemap_add_range duplicate add with $rc" &&
768 for ((i = 0; i < NODEMAP_COUNT; i++)); do
769 if ! delete_range ${HOSTNAME_CHECKSUM}_${i} $i; then
773 [[ $rc != 0 ]] && error "nodemap_del_range failed with $rc" && return 4
777 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 5
781 run_test 10a "nodemap reject duplicate ranges"
784 [ "$MGS_VERSION" -lt $(version_code 2.10.53) ] &&
785 skip "Need MGS >= 2.10.53"
789 local nids="192.168.19.[0-255]@o2ib20"
791 do_facet mgs $LCTL nodemap_del $nm1 2>/dev/null
792 do_facet mgs $LCTL nodemap_del $nm2 2>/dev/null
794 do_facet mgs $LCTL nodemap_add $nm1 || error "Add $nm1 failed"
795 do_facet mgs $LCTL nodemap_add $nm2 || error "Add $nm2 failed"
796 do_facet mgs $LCTL nodemap_add_range --name $nm1 --range $nids ||
797 error "Add range $nids to $nm1 failed"
798 [ -n "$(do_facet mgs $LCTL get_param nodemap.$nm1.* |
799 grep start_nid)" ] || error "No range was found"
800 do_facet mgs $LCTL nodemap_del_range --name $nm2 --range $nids &&
801 error "Deleting range $nids from $nm2 should fail"
802 [ -n "$(do_facet mgs $LCTL get_param nodemap.$nm1.* |
803 grep start_nid)" ] || error "Range $nids should be there"
805 do_facet mgs $LCTL nodemap_del $nm1 || error "Delete $nm1 failed"
806 do_facet mgs $LCTL nodemap_del $nm2 || error "Delete $nm2 failed"
809 run_test 10b "delete range from the correct nodemap"
811 test_10c() { #LU-8912
812 [ "$MGS_VERSION" -lt $(version_code 2.10.57) ] &&
813 skip "Need MGS >= 2.10.57"
815 local nm="nodemap_lu8912"
816 local nid_range="10.210.[32-47].[0-255]@o2ib3"
817 local start_nid="10.210.32.0@o2ib3"
818 local end_nid="10.210.47.255@o2ib3"
819 local start_nid_found
822 do_facet mgs $LCTL nodemap_del $nm 2>/dev/null
823 do_facet mgs $LCTL nodemap_add $nm || error "Add $nm failed"
824 do_facet mgs $LCTL nodemap_add_range --name $nm --range $nid_range ||
825 error "Add range $nid_range to $nm failed"
827 start_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
828 awk -F '[,: ]' /start_nid/'{ print $9 }')
829 [ "$start_nid" == "$start_nid_found" ] ||
830 error "start_nid: $start_nid_found != $start_nid"
831 end_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
832 awk -F '[,: ]' /end_nid/'{ print $13 }')
833 [ "$end_nid" == "$end_nid_found" ] ||
834 error "end_nid: $end_nid_found != $end_nid"
836 do_facet mgs $LCTL nodemap_del $nm || error "Delete $nm failed"
839 run_test 10c "verfify contiguous range support"
841 test_10d() { #LU-8913
842 [ "$MGS_VERSION" -lt $(version_code 2.10.59) ] &&
843 skip "Need MGS >= 2.10.59"
845 local nm="nodemap_lu8913"
846 local nid_range="*@o2ib3"
847 local start_nid="0.0.0.0@o2ib3"
848 local end_nid="255.255.255.255@o2ib3"
849 local start_nid_found
852 do_facet mgs $LCTL nodemap_del $nm 2>/dev/null
853 do_facet mgs $LCTL nodemap_add $nm || error "Add $nm failed"
854 do_facet mgs $LCTL nodemap_add_range --name $nm --range $nid_range ||
855 error "Add range $nid_range to $nm failed"
857 start_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
858 awk -F '[,: ]' /start_nid/'{ print $9 }')
859 [ "$start_nid" == "$start_nid_found" ] ||
860 error "start_nid: $start_nid_found != $start_nid"
861 end_nid_found=$(do_facet mgs $LCTL get_param nodemap.$nm.* |
862 awk -F '[,: ]' /end_nid/'{ print $13 }')
863 [ "$end_nid" == "$end_nid_found" ] ||
864 error "end_nid: $end_nid_found != $end_nid"
866 do_facet mgs $LCTL nodemap_del $nm || error "Delete $nm failed"
869 run_test 10d "verfify nodemap range format '*@<net>' support"
874 remote_mgs_nodsh && skip "remote MGS with nodsh"
875 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
876 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
881 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
884 for ((i = 0; i < NODEMAP_COUNT; i++)); do
885 if ! modify_flags ${HOSTNAME_CHECKSUM}_${i}; then
889 [[ $rc != 0 ]] && error "nodemap_modify with $rc" && return 2
894 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 3
898 run_test 11 "nodemap modify"
903 remote_mgs_nodsh && skip "remote MGS with nodsh"
904 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
905 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
910 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
913 for ((i = 0; i < NODEMAP_COUNT; i++)); do
914 if ! squash_id ${HOSTNAME_CHECKSUM}_${i} 88 0; then
918 [[ $rc != 0 ]] && error "nodemap squash_uid with $rc" && return 2
921 for ((i = 0; i < NODEMAP_COUNT; i++)); do
922 if ! squash_id ${HOSTNAME_CHECKSUM}_${i} 88 1; then
926 [[ $rc != 0 ]] && error "nodemap squash_gid with $rc" && return 3
929 if (( $MDS1_VERSION >= $(version_code 2.14.52) )); then
930 for ((i = 0; i < NODEMAP_COUNT; i++)); do
931 if ! squash_id ${HOSTNAME_CHECKSUM}_${i} 88 2; then
936 [[ $rc != 0 ]] && error "nodemap squash_projid with $rc" && return 5
941 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
945 run_test 12 "nodemap set squash ids"
950 remote_mgs_nodsh && skip "remote MGS with nodsh"
951 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
952 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
957 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
960 for ((i = 0; i < NODEMAP_COUNT; i++)); do
961 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
965 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
968 for ((i = 0; i < NODEMAP_COUNT; i++)); do
969 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
970 for k in $NODEMAP_IPADDR_LIST; do
971 if ! test_nid $SUBNET_CHECKSUM.$i.$j.$k \
972 ${HOSTNAME_CHECKSUM}_${i}; then
978 [[ $rc != 0 ]] && error "nodemap_test_nid failed with $rc" && return 3
983 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
987 run_test 13 "test nids"
992 remote_mgs_nodsh && skip "remote MGS with nodsh"
993 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
994 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
999 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
1002 for ((i = 0; i < NODEMAP_COUNT; i++)); do
1003 for ((j = 0; j < NODEMAP_RANGE_COUNT; j++)); do
1004 for k in $NODEMAP_IPADDR_LIST; do
1005 if ! test_nid $SUBNET_CHECKSUM.$i.$j.$k \
1012 [[ $rc != 0 ]] && error "nodemap_test_nid failed with $rc" && return 3
1017 [[ $rc != 0 ]] && error "nodemap_del failed with $rc" && return 4
1021 run_test 14 "test default nodemap nid lookup"
1026 remote_mgs_nodsh && skip "remote MGS with nodsh"
1027 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
1028 skip "No nodemap on $MGS_VERSION MGS < 2.5.53"
1033 [[ $rc != 0 ]] && error "nodemap_add failed with $rc" && return 1
1035 for (( i = 0; i < NODEMAP_COUNT; i++ )); do
1036 local csum=${HOSTNAME_CHECKSUM}_${i}
1038 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
1039 --property admin --value 0; then
1042 if ! do_facet mgs $LCTL nodemap_modify --name $csum \
1043 --property trusted --value 0; then
1047 [[ $rc != 0 ]] && error "nodemap_modify failed with $rc" && return 1
1050 for ((i = 0; i < NODEMAP_COUNT; i++)); do
1051 if ! add_range ${HOSTNAME_CHECKSUM}_${i} $i; then
1055 [[ $rc != 0 ]] && error "nodemap_add_range failed with $rc" && return 2
1060 [[ $rc != 0 ]] && error "nodemap_add_idmap failed with $rc" && return 3
1062 activedefault=$(do_facet mgs $LCTL get_param -n nodemap.active)
1063 if [[ "$activedefault" != "1" ]]; then
1064 stack_trap cleanup_active EXIT
1070 [[ $rc != 0 ]] && error "nodemap_test_id failed with $rc" && return 4
1075 [[ $rc != 0 ]] && error "update_idmaps failed with $rc" && return 5
1080 [[ $rc != 0 ]] && error "nodemap_del_idmap failed with $rc" && return 6
1085 [[ $rc != 0 ]] && error "nodemap_delete failed with $rc" && return 7
1089 run_test 15 "test id mapping"
1091 create_fops_nodemaps() {
1094 for client in $clients; do
1095 local client_ip=$(host_nids_address $client $NETTYPE)
1096 local client_nid=$(h2nettype $client_ip)
1097 do_facet mgs $LCTL nodemap_add c${i} || return 1
1098 do_facet mgs $LCTL nodemap_add_range \
1099 --name c${i} --range $client_nid || return 1
1100 for map in ${FOPS_IDMAPS[i]}; do
1101 do_facet mgs $LCTL nodemap_add_idmap --name c${i} \
1102 --idtype uid --idmap ${map} || return 1
1103 do_facet mgs $LCTL nodemap_add_idmap --name c${i} \
1104 --idtype gid --idmap ${map} || return 1
1107 wait_nm_sync c$i idmap
1114 delete_fops_nodemaps() {
1117 for client in $clients; do
1118 do_facet mgs $LCTL nodemap_del c${i} || return 1
1126 if [ $MDSCOUNT -le 1 ]; then
1127 do_node ${clients_arr[0]} mkdir -p $DIR/$tdir
1129 # round-robin MDTs to test DNE nodemap support
1130 [ ! -d $DIR ] && do_node ${clients_arr[0]} mkdir -p $DIR
1131 do_node ${clients_arr[0]} $LFS setdirstripe -c 1 -i \
1132 $((fops_mds_index % MDSCOUNT)) $DIR/$tdir
1133 ((fops_mds_index++))
1137 # acl test directory needs to be initialized on a privileged client
1139 local admin=$(do_facet mgs $LCTL get_param -n nodemap.c0.admin_nodemap)
1140 local trust=$(do_facet mgs $LCTL get_param -n \
1141 nodemap.c0.trusted_nodemap)
1143 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1144 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
1146 wait_nm_sync c0 admin_nodemap
1147 wait_nm_sync c0 trusted_nodemap
1149 do_node ${clients_arr[0]} rm -rf $DIR/$tdir
1151 do_node ${clients_arr[0]} chown $user $DIR/$tdir
1153 do_facet mgs $LCTL nodemap_modify --name c0 \
1154 --property admin --value $admin
1155 do_facet mgs $LCTL nodemap_modify --name c0 \
1156 --property trusted --value $trust
1158 # flush MDT locks to make sure they are reacquired before test
1159 do_node ${clients_arr[0]} $LCTL set_param \
1160 ldlm.namespaces.$FSNAME-MDT*.lru_size=clear
1162 wait_nm_sync c0 admin_nodemap
1163 wait_nm_sync c0 trusted_nodemap
1166 # fileset test directory needs to be initialized on a privileged client
1167 fileset_test_setup() {
1170 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
1171 cleanup_mount $MOUNT
1172 FILESET="" zconf_mount_clients $CLIENTS $MOUNT
1175 local admin=$(do_facet mgs $LCTL get_param -n \
1176 nodemap.${nm}.admin_nodemap)
1177 local trust=$(do_facet mgs $LCTL get_param -n \
1178 nodemap.${nm}.trusted_nodemap)
1180 do_facet mgs $LCTL nodemap_modify --name $nm --property admin --value 1
1181 do_facet mgs $LCTL nodemap_modify --name $nm --property trusted \
1184 wait_nm_sync $nm admin_nodemap
1185 wait_nm_sync $nm trusted_nodemap
1187 # create directory and populate it for subdir mount
1188 do_node ${clients_arr[0]} mkdir $MOUNT/$subdir ||
1189 error "unable to create dir $MOUNT/$subdir"
1190 do_node ${clients_arr[0]} touch $MOUNT/$subdir/this_is_$subdir ||
1191 error "unable to create file $MOUNT/$subdir/this_is_$subdir"
1192 do_node ${clients_arr[0]} mkdir $MOUNT/$subdir/$subsubdir ||
1193 error "unable to create dir $MOUNT/$subdir/$subsubdir"
1194 do_node ${clients_arr[0]} touch \
1195 $MOUNT/$subdir/$subsubdir/this_is_$subsubdir ||
1196 error "unable to create file \
1197 $MOUNT/$subdir/$subsubdir/this_is_$subsubdir"
1199 do_facet mgs $LCTL nodemap_modify --name $nm \
1200 --property admin --value $admin
1201 do_facet mgs $LCTL nodemap_modify --name $nm \
1202 --property trusted --value $trust
1204 # flush MDT locks to make sure they are reacquired before test
1205 do_node ${clients_arr[0]} $LCTL set_param \
1206 ldlm.namespaces.$FSNAME-MDT*.lru_size=clear
1208 wait_nm_sync $nm admin_nodemap
1209 wait_nm_sync $nm trusted_nodemap
1212 # fileset test directory needs to be initialized on a privileged client
1213 fileset_test_cleanup() {
1215 local admin=$(do_facet mgs $LCTL get_param -n \
1216 nodemap.${nm}.admin_nodemap)
1217 local trust=$(do_facet mgs $LCTL get_param -n \
1218 nodemap.${nm}.trusted_nodemap)
1220 do_facet mgs $LCTL nodemap_modify --name $nm --property admin --value 1
1221 do_facet mgs $LCTL nodemap_modify --name $nm --property trusted \
1224 wait_nm_sync $nm admin_nodemap
1225 wait_nm_sync $nm trusted_nodemap
1227 # cleanup directory created for subdir mount
1228 do_node ${clients_arr[0]} rm -rf $MOUNT/$subdir ||
1229 error "unable to remove dir $MOUNT/$subdir"
1231 do_facet mgs $LCTL nodemap_modify --name $nm \
1232 --property admin --value $admin
1233 do_facet mgs $LCTL nodemap_modify --name $nm \
1234 --property trusted --value $trust
1236 # flush MDT locks to make sure they are reacquired before test
1237 do_node ${clients_arr[0]} $LCTL set_param \
1238 ldlm.namespaces.$FSNAME-MDT*.lru_size=clear
1240 wait_nm_sync $nm admin_nodemap
1241 wait_nm_sync $nm trusted_nodemap
1242 if [ -n "$FILESET" -a -z "$SKIP_FILESET" ]; then
1243 cleanup_mount $MOUNT
1244 zconf_mount_clients $CLIENTS $MOUNT
1248 do_create_delete() {
1251 local testfile=$DIR/$tdir/$tfile
1255 if $run_u touch $testfile >& /dev/null; then
1257 $run_u rm $testfile && d=1
1261 local expected=$(get_cr_del_expected $key)
1262 [ "$res" != "$expected" ] &&
1263 error "test $key, wanted $expected, got $res" && rc=$((rc + 1))
1267 nodemap_check_quota() {
1269 $run_u lfs quota -q $DIR | awk '{ print $2; exit; }'
1272 do_fops_quota_test() {
1274 # fuzz quota used to account for possible indirect blocks, etc
1275 local quota_fuzz=$(fs_log_size)
1276 local qused_orig=$(nodemap_check_quota "$run_u")
1277 local qused_high=$((qused_orig + quota_fuzz))
1278 local qused_low=$((qused_orig - quota_fuzz))
1279 local testfile=$DIR/$tdir/$tfile
1280 $run_u dd if=/dev/zero of=$testfile oflag=sync bs=1M count=1 \
1281 >& /dev/null || error "unable to write quota test file"
1282 sync; sync_all_data || true
1284 local qused_new=$(nodemap_check_quota "$run_u")
1285 [ $((qused_new)) -lt $((qused_low + 1024)) -o \
1286 $((qused_new)) -gt $((qused_high + 1024)) ] &&
1287 error "$qused_new != $qused_orig + 1M after write, " \
1288 "fuzz is $quota_fuzz"
1289 $run_u rm $testfile || error "unable to remove quota test file"
1290 wait_delete_completed_mds
1292 qused_new=$(nodemap_check_quota "$run_u")
1293 [ $((qused_new)) -lt $((qused_low)) \
1294 -o $((qused_new)) -gt $((qused_high)) ] &&
1295 error "quota not reclaimed, expect $qused_orig, " \
1296 "got $qused_new, fuzz $quota_fuzz"
1299 get_fops_mapped_user() {
1302 for ((i=0; i < ${#FOPS_IDMAPS[@]}; i++)); do
1303 for map in ${FOPS_IDMAPS[i]}; do
1304 if [ $(cut -d: -f1 <<< "$map") == $cli_user ]; then
1305 cut -d: -f2 <<< "$map"
1313 get_cr_del_expected() {
1315 IFS=":" read -a key <<< "$1"
1316 local mapmode="${key[0]}"
1317 local mds_user="${key[1]}"
1318 local cluster="${key[2]}"
1319 local cli_user="${key[3]}"
1320 local mode="0${key[4]}"
1327 [[ $mapmode == *mapped* ]] && mapped=1
1328 # only c1 is mapped in these test cases
1329 [[ $mapmode == mapped_trusted* ]] && [ "$cluster" == "c0" ] && mapped=0
1330 [[ $mapmode == *noadmin* ]] && noadmin=1
1332 # o+wx works as long as the user isn't mapped
1333 if [ $((mode & 3)) -eq 3 ]; then
1337 # if client user is root, check if root is squashed
1338 if [ "$cli_user" == "0" ]; then
1339 # squash root succeed, if other bit is on
1342 1) [ "$other" == "1" ] && echo $SUCCESS
1343 [ "$other" == "0" ] && echo $FAILURE;;
1347 if [ "$mapped" == "0" ]; then
1348 [ "$other" == "1" ] && echo $SUCCESS
1349 [ "$other" == "0" ] && echo $FAILURE
1353 # if mapped user is mds user, check for u+wx
1354 mapped_user=$(get_fops_mapped_user $cli_user)
1355 [ "$mapped_user" == "-1" ] &&
1356 error "unable to find mapping for client user $cli_user"
1358 if [ "$mapped_user" == "$mds_user" -a \
1359 $(((mode & 0300) == 0300)) -eq 1 ]; then
1363 if [ "$mapped_user" != "$mds_user" -a "$other" == "1" ]; then
1370 test_fops_admin_cli_i=""
1371 test_fops_chmod_dir() {
1372 local current_cli_i=$1
1374 local dir_to_chmod=$3
1375 local new_admin_cli_i=""
1377 # do we need to set up a new admin client?
1378 [ "$current_cli_i" == "0" ] && [ "$test_fops_admin_cli_i" != "1" ] &&
1380 [ "$current_cli_i" != "0" ] && [ "$test_fops_admin_cli_i" != "0" ] &&
1383 # if only one client, and non-admin, need to flip admin everytime
1384 if [ "$num_clients" == "1" ]; then
1385 test_fops_admin_client=$clients
1386 test_fops_admin_val=$(do_facet mgs $LCTL get_param -n \
1387 nodemap.c0.admin_nodemap)
1388 if [ "$test_fops_admin_val" != "1" ]; then
1389 do_facet mgs $LCTL nodemap_modify \
1393 wait_nm_sync c0 admin_nodemap
1395 elif [ "$new_admin_cli_i" != "" ]; then
1396 # restore admin val to old admin client
1397 if [ "$test_fops_admin_cli_i" != "" ] &&
1398 [ "$test_fops_admin_val" != "1" ]; then
1399 do_facet mgs $LCTL nodemap_modify \
1400 --name c${test_fops_admin_cli_i} \
1402 --value $test_fops_admin_val
1403 wait_nm_sync c${test_fops_admin_cli_i} admin_nodemap
1406 test_fops_admin_cli_i=$new_admin_cli_i
1407 test_fops_admin_client=${clients_arr[$new_admin_cli_i]}
1408 test_fops_admin_val=$(do_facet mgs $LCTL get_param -n \
1409 nodemap.c${new_admin_cli_i}.admin_nodemap)
1411 if [ "$test_fops_admin_val" != "1" ]; then
1412 do_facet mgs $LCTL nodemap_modify \
1413 --name c${new_admin_cli_i} \
1416 wait_nm_sync c${new_admin_cli_i} admin_nodemap
1420 do_node $test_fops_admin_client chmod $perm_bits $DIR/$tdir || return 1
1422 # remove admin for single client if originally non-admin
1423 if [ "$num_clients" == "1" ] && [ "$test_fops_admin_val" != "1" ]; then
1424 do_facet mgs $LCTL nodemap_modify --name c0 --property admin \
1426 wait_nm_sync c0 admin_nodemap
1434 local single_client="$2"
1435 local client_user_list=([0]="0 $((IDBASE+3))"
1436 [1]="0 $((IDBASE+5))")
1437 local mds_users="-1 0"
1440 local perm_bit_list="3 $((0300))"
1441 # SLOW tests 000-007, 010-070, 100-700 (octal modes)
1442 if [ "$SLOW" == "yes" ]; then
1443 perm_bit_list="0 $(seq 1 7) $(seq 8 8 63) $(seq 64 64 511) \
1445 client_user_list=([0]="0 $((IDBASE+3)) $((IDBASE+4))"
1446 [1]="0 $((IDBASE+5)) $((IDBASE+6))")
1447 mds_users="-1 0 1 2"
1450 # force single_client to speed up test
1451 [ "$SLOW" == "yes" ] ||
1453 # step through mds users. -1 means root
1454 for mds_i in $mds_users; do
1455 local user=$((mds_i + IDBASE))
1459 [ "$mds_i" == "-1" ] && user=0
1461 echo mkdir -p $DIR/$tdir
1464 for client in $clients; do
1466 for u in ${client_user_list[$cli_i]}; do
1467 local run_u="do_node $client \
1468 $RUNAS_CMD -u$u -g$u -G$u"
1469 for perm_bits in $perm_bit_list; do
1470 local mode=$(printf %03o $perm_bits)
1472 key="$mapmode:$user:c$cli_i:$u:$mode"
1473 test_fops_chmod_dir $cli_i $mode \
1475 error cannot chmod $key
1476 do_create_delete "$run_u" "$key"
1480 test_fops_chmod_dir $cli_i 777 $DIR/$tdir ||
1481 error cannot chmod $key
1482 do_fops_quota_test "$run_u"
1485 cli_i=$((cli_i + 1))
1486 [ "$single_client" == "1" ] && break
1493 nodemap_version_check () {
1494 remote_mgs_nodsh && skip "remote MGS with nodsh" && return 1
1495 [ "$MGS_VERSION" -lt $(version_code 2.5.53) ] &&
1496 skip "No nodemap on $MGS_VERSION MGS < 2.5.53" &&
1501 nodemap_test_setup() {
1503 local active_nodemap=1
1505 [ "$1" == "0" ] && active_nodemap=0
1507 do_nodes $(comma_list $(all_mdts_nodes)) \
1508 $LCTL set_param mdt.*.identity_upcall=NONE
1511 create_fops_nodemaps
1513 [[ $rc != 0 ]] && error "adding fops nodemaps failed $rc"
1515 do_facet mgs $LCTL nodemap_activate $active_nodemap
1518 do_facet mgs $LCTL nodemap_modify --name default \
1519 --property admin --value 1
1520 wait_nm_sync default admin_nodemap
1521 do_facet mgs $LCTL nodemap_modify --name default \
1522 --property trusted --value 1
1523 wait_nm_sync default trusted_nodemap
1526 nodemap_test_cleanup() {
1528 delete_fops_nodemaps
1530 [[ $rc != 0 ]] && error "removing fops nodemaps failed $rc"
1532 do_facet mgs $LCTL nodemap_modify --name default \
1533 --property admin --value 0
1534 wait_nm_sync default admin_nodemap
1535 do_facet mgs $LCTL nodemap_modify --name default \
1536 --property trusted --value 0
1537 wait_nm_sync default trusted_nodemap
1539 do_facet mgs $LCTL nodemap_activate 0
1540 wait_nm_sync active 0
1542 export SK_UNIQUE_NM=false
1546 nodemap_clients_admin_trusted() {
1550 for client in $clients; do
1551 do_facet mgs $LCTL nodemap_modify --name c0 \
1552 --property admin --value $admin
1553 do_facet mgs $LCTL nodemap_modify --name c0 \
1554 --property trusted --value $tr
1557 wait_nm_sync c$((i - 1)) admin_nodemap
1558 wait_nm_sync c$((i - 1)) trusted_nodemap
1562 nodemap_version_check || return 0
1563 nodemap_test_setup 0
1565 trap nodemap_test_cleanup EXIT
1567 nodemap_test_cleanup
1569 run_test 16 "test nodemap all_off fileops"
1573 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1574 skip "Need MDS >= 2.11.55"
1577 nodemap_version_check || return 0
1580 trap nodemap_test_cleanup EXIT
1581 nodemap_clients_admin_trusted 0 1
1582 test_fops trusted_noadmin 1
1583 nodemap_test_cleanup
1585 run_test 17 "test nodemap trusted_noadmin fileops"
1589 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1590 skip "Need MDS >= 2.11.55"
1593 nodemap_version_check || return 0
1596 trap nodemap_test_cleanup EXIT
1597 nodemap_clients_admin_trusted 0 0
1598 test_fops mapped_noadmin 1
1599 nodemap_test_cleanup
1601 run_test 18 "test nodemap mapped_noadmin fileops"
1605 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1606 skip "Need MDS >= 2.11.55"
1609 nodemap_version_check || return 0
1612 trap nodemap_test_cleanup EXIT
1613 nodemap_clients_admin_trusted 1 1
1614 test_fops trusted_admin 1
1615 nodemap_test_cleanup
1617 run_test 19 "test nodemap trusted_admin fileops"
1621 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1622 skip "Need MDS >= 2.11.55"
1625 nodemap_version_check || return 0
1628 trap nodemap_test_cleanup EXIT
1629 nodemap_clients_admin_trusted 1 0
1630 test_fops mapped_admin 1
1631 nodemap_test_cleanup
1633 run_test 20 "test nodemap mapped_admin fileops"
1637 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1638 skip "Need MDS >= 2.11.55"
1641 nodemap_version_check || return 0
1644 trap nodemap_test_cleanup EXIT
1647 for client in $clients; do
1648 do_facet mgs $LCTL nodemap_modify --name c${i} \
1649 --property admin --value 0
1650 do_facet mgs $LCTL nodemap_modify --name c${i} \
1651 --property trusted --value $x
1655 wait_nm_sync c$((i - 1)) trusted_nodemap
1657 test_fops mapped_trusted_noadmin
1658 nodemap_test_cleanup
1660 run_test 21 "test nodemap mapped_trusted_noadmin fileops"
1664 [ "$MDS1_VERSION" -lt $(version_code 2.11.55) ]; then
1665 skip "Need MDS >= 2.11.55"
1668 nodemap_version_check || return 0
1671 trap nodemap_test_cleanup EXIT
1674 for client in $clients; do
1675 do_facet mgs $LCTL nodemap_modify --name c${i} \
1676 --property admin --value 1
1677 do_facet mgs $LCTL nodemap_modify --name c${i} \
1678 --property trusted --value $x
1682 wait_nm_sync c$((i - 1)) trusted_nodemap
1684 test_fops mapped_trusted_admin
1685 nodemap_test_cleanup
1687 run_test 22 "test nodemap mapped_trusted_admin fileops"
1689 # acl test directory needs to be initialized on a privileged client
1690 nodemap_acl_test_setup() {
1691 local admin=$(do_facet mgs $LCTL get_param -n \
1692 nodemap.c0.admin_nodemap)
1693 local trust=$(do_facet mgs $LCTL get_param -n \
1694 nodemap.c0.trusted_nodemap)
1696 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1697 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
1699 wait_nm_sync c0 admin_nodemap
1700 wait_nm_sync c0 trusted_nodemap
1702 do_node ${clients_arr[0]} rm -rf $DIR/$tdir
1704 do_node ${clients_arr[0]} chmod a+rwx $DIR/$tdir ||
1705 error unable to chmod a+rwx test dir $DIR/$tdir
1707 do_facet mgs $LCTL nodemap_modify --name c0 \
1708 --property admin --value $admin
1709 do_facet mgs $LCTL nodemap_modify --name c0 \
1710 --property trusted --value $trust
1712 wait_nm_sync c0 trusted_nodemap
1715 # returns 0 if the number of ACLs does not change on the second (mapped) client
1716 # after being set on the first client
1717 nodemap_acl_test() {
1719 local set_client="$2"
1720 local get_client="$3"
1721 local check_setfacl="$4"
1722 local setfacl_error=0
1723 local testfile=$DIR/$tdir/$tfile
1724 local RUNAS_USER="$RUNAS_CMD -u $user"
1726 local acl_count_post=0
1728 nodemap_acl_test_setup
1731 do_node $set_client $RUNAS_USER touch $testfile
1733 # ACL masks aren't filtered by nodemap code, so we ignore them
1734 acl_count=$(do_node $get_client getfacl $testfile | grep -v mask |
1736 do_node $set_client $RUNAS_USER setfacl -m $user:rwx $testfile ||
1739 # if check setfacl is set to 1, then it's supposed to error
1740 if [ "$check_setfacl" == "1" ]; then
1741 [ "$setfacl_error" != "1" ] && return 1
1744 [ "$setfacl_error" == "1" ] && echo "WARNING: unable to setfacl"
1746 acl_count_post=$(do_node $get_client getfacl $testfile | grep -v mask |
1748 [ $acl_count -eq $acl_count_post ] && return 0
1753 [ $num_clients -lt 2 ] && skip "Need 2 clients at least" && return
1754 nodemap_version_check || return 0
1757 trap nodemap_test_cleanup EXIT
1758 # 1 trusted cluster, 1 mapped cluster
1759 local unmapped_fs=$((IDBASE+0))
1760 local unmapped_c1=$((IDBASE+5))
1761 local mapped_fs=$((IDBASE+2))
1762 local mapped_c0=$((IDBASE+4))
1763 local mapped_c1=$((IDBASE+6))
1765 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1766 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 1
1768 do_facet mgs $LCTL nodemap_modify --name c1 --property admin --value 0
1769 do_facet mgs $LCTL nodemap_modify --name c1 --property trusted --value 0
1771 wait_nm_sync c1 trusted_nodemap
1773 # setfacl on trusted cluster to unmapped user, verify it's not seen
1774 nodemap_acl_test $unmapped_fs ${clients_arr[0]} ${clients_arr[1]} ||
1775 error "acl count (1)"
1777 # setfacl on trusted cluster to mapped user, verify it's seen
1778 nodemap_acl_test $mapped_fs ${clients_arr[0]} ${clients_arr[1]} &&
1779 error "acl count (2)"
1781 # setfacl on mapped cluster to mapped user, verify it's seen
1782 nodemap_acl_test $mapped_c1 ${clients_arr[1]} ${clients_arr[0]} &&
1783 error "acl count (3)"
1785 # setfacl on mapped cluster to unmapped user, verify error
1786 nodemap_acl_test $unmapped_fs ${clients_arr[1]} ${clients_arr[0]} 1 ||
1787 error "acl count (4)"
1790 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 0
1791 do_facet mgs $LCTL nodemap_modify --name c0 --property trusted --value 0
1793 wait_nm_sync c0 trusted_nodemap
1795 # setfacl to mapped user on c1, also mapped to c0, verify it's seen
1796 nodemap_acl_test $mapped_c1 ${clients_arr[1]} ${clients_arr[0]} &&
1797 error "acl count (5)"
1799 # setfacl to mapped user on c1, not mapped to c0, verify not seen
1800 nodemap_acl_test $unmapped_c1 ${clients_arr[1]} ${clients_arr[0]} ||
1801 error "acl count (6)"
1803 nodemap_test_cleanup
1805 run_test 23a "test mapped regular ACLs"
1807 test_23b() { #LU-9929
1808 [ $num_clients -lt 2 ] && skip "Need 2 clients at least"
1809 [ "$MGS_VERSION" -lt $(version_code 2.10.53) ] &&
1810 skip "Need MGS >= 2.10.53"
1812 export SK_UNIQUE_NM=true
1814 trap nodemap_test_cleanup EXIT
1816 local testdir=$DIR/$tdir
1817 local fs_id=$((IDBASE+10))
1822 do_facet mgs $LCTL nodemap_modify --name c0 --property admin --value 1
1823 wait_nm_sync c0 admin_nodemap
1824 do_facet mgs $LCTL nodemap_modify --name c1 --property admin --value 1
1825 wait_nm_sync c1 admin_nodemap
1826 do_facet mgs $LCTL nodemap_modify --name c1 --property trusted --value 1
1827 wait_nm_sync c1 trusted_nodemap
1829 # Add idmap $ID0:$fs_id (500:60010)
1830 do_facet mgs $LCTL nodemap_add_idmap --name c0 --idtype gid \
1831 --idmap $ID0:$fs_id ||
1832 error "add idmap $ID0:$fs_id to nodemap c0 failed"
1833 wait_nm_sync c0 idmap
1835 # set/getfacl default acl on client 1 (unmapped gid=500)
1836 do_node ${clients_arr[0]} rm -rf $testdir
1837 do_node ${clients_arr[0]} mkdir -p $testdir
1838 # Here, USER0=$(getent passwd | grep :$ID0:$ID0: | cut -d: -f1)
1839 do_node ${clients_arr[0]} setfacl -R -d -m group:$USER0:rwx $testdir ||
1840 error "setfacl $testdir on ${clients_arr[0]} failed"
1841 unmapped_id=$(do_node ${clients_arr[0]} getfacl $testdir |
1842 grep -E "default:group:.*:rwx" | awk -F: '{print $3}')
1843 [ "$unmapped_id" = "$USER0" ] ||
1844 error "gid=$ID0 was not unmapped correctly on ${clients_arr[0]}"
1846 # getfacl default acl on client 2 (mapped gid=60010)
1847 mapped_id=$(do_node ${clients_arr[1]} getfacl $testdir |
1848 grep -E "default:group:.*:rwx" | awk -F: '{print $3}')
1849 fs_user=$(do_node ${clients_arr[1]} getent passwd |
1850 grep :$fs_id:$fs_id: | cut -d: -f1)
1851 [ -z "$fs_user" ] && fs_user=$fs_id
1852 [ $mapped_id -eq $fs_id -o "$mapped_id" = "$fs_user" ] ||
1853 error "Should return gid=$fs_id or $fs_user on client2"
1856 nodemap_test_cleanup
1857 export SK_UNIQUE_NM=false
1859 run_test 23b "test mapped default ACLs"
1864 trap nodemap_test_cleanup EXIT
1865 do_nodes $(comma_list $(all_server_nodes)) $LCTL get_param -R nodemap
1867 nodemap_test_cleanup
1869 run_test 24 "check nodemap proc files for LBUGs and Oopses"
1872 local tmpfile=$(mktemp)
1873 local tmpfile2=$(mktemp)
1874 local tmpfile3=$(mktemp)
1875 local tmpfile4=$(mktemp)
1879 nodemap_version_check || return 0
1881 # stop clients for this test
1882 zconf_umount_clients $CLIENTS $MOUNT ||
1883 error "unable to umount clients $CLIENTS"
1885 export SK_UNIQUE_NM=true
1888 # enable trusted/admin for setquota call in cleanup_and_setup_lustre()
1890 for client in $clients; do
1891 do_facet mgs $LCTL nodemap_modify --name c${i} \
1892 --property admin --value 1
1893 do_facet mgs $LCTL nodemap_modify --name c${i} \
1894 --property trusted --value 1
1897 wait_nm_sync c$((i - 1)) trusted_nodemap
1899 trap nodemap_test_cleanup EXIT
1901 # create a new, empty nodemap, and add fileset info to it
1902 do_facet mgs $LCTL nodemap_add test25 ||
1903 error "unable to create nodemap $testname"
1904 do_facet mgs $LCTL set_param -P nodemap.$testname.fileset=/$subdir ||
1905 error "unable to add fileset info to nodemap test25"
1907 wait_nm_sync test25 id
1909 do_facet mgs $LCTL nodemap_info > $tmpfile
1910 do_facet mds $LCTL nodemap_info > $tmpfile2
1912 if ! $SHARED_KEY; then
1913 # will conflict with SK's nodemaps
1914 cleanup_and_setup_lustre
1916 # stop clients for this test
1917 zconf_umount_clients $CLIENTS $MOUNT ||
1918 error "unable to umount clients $CLIENTS"
1920 do_facet mgs $LCTL nodemap_info > $tmpfile3
1921 diff -q $tmpfile3 $tmpfile >& /dev/null ||
1922 error "nodemap_info diff on MGS after remount"
1924 do_facet mds $LCTL nodemap_info > $tmpfile4
1925 diff -q $tmpfile4 $tmpfile2 >& /dev/null ||
1926 error "nodemap_info diff on MDS after remount"
1929 do_facet mgs $LCTL nodemap_del test25 ||
1930 error "cannot delete nodemap test25 from config"
1931 nodemap_test_cleanup
1932 # restart clients previously stopped
1933 zconf_mount_clients $CLIENTS $MOUNT ||
1934 error "unable to mount clients $CLIENTS"
1936 rm -f $tmpfile $tmpfile2
1937 export SK_UNIQUE_NM=false
1939 run_test 25 "test save and reload nodemap config"
1942 nodemap_version_check || return 0
1946 do_facet mgs "seq -f 'c%g' $large_i | xargs -n1 $LCTL nodemap_add"
1947 wait_nm_sync c$large_i admin_nodemap
1949 do_facet mgs "seq -f 'c%g' $large_i | xargs -n1 $LCTL nodemap_del"
1950 wait_nm_sync c$large_i admin_nodemap
1952 run_test 26 "test transferring very large nodemap"
1954 nodemap_exercise_fileset() {
1957 local check_proj=true
1959 (( $MDS1_VERSION >= $(version_code 2.14.52) )) || check_proj=false
1962 if [ "$nm" == "default" ]; then
1963 do_facet mgs $LCTL nodemap_activate 1
1965 do_facet mgs $LCTL nodemap_modify --name default \
1966 --property admin --value 1
1967 do_facet mgs $LCTL nodemap_modify --name default \
1968 --property trusted --value 1
1969 wait_nm_sync default admin_nodemap
1970 wait_nm_sync default trusted_nodemap
1975 if $SHARED_KEY; then
1976 export SK_UNIQUE_NM=true
1978 # will conflict with SK's nodemaps
1979 trap "fileset_test_cleanup $nm" EXIT
1981 fileset_test_setup "$nm"
1983 # add fileset info to $nm nodemap
1984 if ! combined_mgs_mds; then
1985 do_facet mgs $LCTL set_param nodemap.${nm}.fileset=/$subdir ||
1986 error "unable to add fileset info to $nm nodemap on MGS"
1988 do_facet mgs $LCTL set_param -P nodemap.${nm}.fileset=/$subdir ||
1989 error "unable to add fileset info to $nm nodemap for servers"
1990 wait_nm_sync $nm fileset "nodemap.${nm}.fileset=/$subdir"
1992 if $check_proj; then
1993 do_facet mgs $LCTL nodemap_modify --name $nm \
1994 --property admin --value 1
1995 wait_nm_sync $nm admin_nodemap
1996 do_facet mgs $LCTL nodemap_modify --name $nm \
1997 --property trusted --value 0
1998 wait_nm_sync $nm trusted_nodemap
1999 do_facet mgs $LCTL nodemap_modify --name $nm \
2000 --property map_mode --value projid
2001 wait_nm_sync $nm map_mode
2002 do_facet mgs $LCTL nodemap_add_idmap --name $nm \
2003 --idtype projid --idmap 1:1
2004 do_facet mgs $LCTL nodemap_modify --name $nm \
2005 --property deny_unknown --value 1
2006 wait_nm_sync $nm deny_unknown
2010 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2011 error "unable to umount client ${clients_arr[0]}"
2012 # set some generic fileset to trigger SSK code
2014 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2015 error "unable to remount client ${clients_arr[0]}"
2018 # test mount point content
2019 do_node ${clients_arr[0]} test -f $MOUNT/this_is_$subdir ||
2020 error "fileset not taken into account"
2022 if $check_proj; then
2023 do_node ${clients_arr[0]} $LFS setquota -p 1 -b 10000 -B 11000 \
2024 -i 0 -I 0 $MOUNT || error "setquota -p 1 failed"
2025 do_node ${clients_arr[0]} $LFS setquota -p 2 -b 10000 -B 11000 \
2026 -i 0 -I 0 $MOUNT && error "setquota -p 2 should fail"
2029 # re-mount client with sub-subdir
2030 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2031 error "unable to umount client ${clients_arr[0]}"
2032 export FILESET=/$subsubdir
2033 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2034 error "unable to remount client ${clients_arr[0]}"
2037 # test mount point content
2038 do_node ${clients_arr[0]} test -f $MOUNT/this_is_$subsubdir ||
2039 error "subdir of fileset not taken into account"
2041 # remove fileset info from nodemap
2042 do_facet mgs $LCTL nodemap_set_fileset --name $nm --fileset clear ||
2043 error "unable to delete fileset info on $nm nodemap"
2044 wait_update_facet mgs "$LCTL get_param nodemap.${nm}.fileset" \
2045 "nodemap.${nm}.fileset=" ||
2046 error "fileset info still not cleared on $nm nodemap"
2047 do_facet mgs $LCTL set_param -P nodemap.${nm}.fileset=clear ||
2048 error "unable to reset fileset info on $nm nodemap"
2049 wait_nm_sync $nm fileset "nodemap.${nm}.fileset="
2052 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2053 error "unable to umount client ${clients_arr[0]}"
2054 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2055 error "unable to remount client ${clients_arr[0]}"
2057 # test mount point content
2058 if ! $(do_node ${clients_arr[0]} test -d $MOUNT/$subdir); then
2060 error "fileset not cleared on $nm nodemap"
2063 # back to non-nodemap setup
2064 if $SHARED_KEY; then
2065 export SK_UNIQUE_NM=false
2066 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2067 error "unable to umount client ${clients_arr[0]}"
2069 fileset_test_cleanup "$nm"
2070 if [ "$nm" == "default" ]; then
2071 do_facet mgs $LCTL nodemap_modify --name default \
2072 --property admin --value 0
2073 do_facet mgs $LCTL nodemap_modify --name default \
2074 --property trusted --value 0
2075 wait_nm_sync default admin_nodemap
2076 wait_nm_sync default trusted_nodemap
2077 do_facet mgs $LCTL nodemap_activate 0
2078 wait_nm_sync active 0
2080 export SK_UNIQUE_NM=false
2082 nodemap_test_cleanup
2084 if $SHARED_KEY; then
2085 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2086 error "unable to remount client ${clients_arr[0]}"
2091 [ "$MDS1_VERSION" -lt $(version_code 2.11.50) ] &&
2092 skip "Need MDS >= 2.11.50"
2094 for nm in "default" "c0"; do
2095 local subdir="subdir_${nm}"
2096 local subsubdir="subsubdir_${nm}"
2098 if [ "$nm" == "default" ] && [ "$SHARED_KEY" == "true" ]; then
2099 echo "Skipping nodemap $nm with SHARED_KEY";
2103 echo "Exercising fileset for nodemap $nm"
2104 nodemap_exercise_fileset "$nm"
2107 run_test 27a "test fileset in various nodemaps"
2109 test_27b() { #LU-10703
2110 [ "$MDS1_VERSION" -lt $(version_code 2.11.50) ] &&
2111 skip "Need MDS >= 2.11.50"
2112 [[ $MDSCOUNT -lt 2 ]] && skip "needs >= 2 MDTs"
2115 trap nodemap_test_cleanup EXIT
2117 # Add the nodemaps and set their filesets
2118 for i in $(seq 1 $MDSCOUNT); do
2119 do_facet mgs $LCTL nodemap_del nm$i 2>/dev/null
2120 do_facet mgs $LCTL nodemap_add nm$i ||
2121 error "add nodemap nm$i failed"
2122 wait_nm_sync nm$i "" "" "-N"
2124 if ! combined_mgs_mds; then
2126 $LCTL set_param nodemap.nm$i.fileset=/dir$i ||
2127 error "set nm$i.fileset=/dir$i failed on MGS"
2129 do_facet mgs $LCTL set_param -P nodemap.nm$i.fileset=/dir$i ||
2130 error "set nm$i.fileset=/dir$i failed on servers"
2131 wait_nm_sync nm$i fileset "nodemap.nm$i.fileset=/dir$i"
2134 # Check if all the filesets are correct
2135 for i in $(seq 1 $MDSCOUNT); do
2136 fileset=$(do_facet mds$i \
2137 $LCTL get_param -n nodemap.nm$i.fileset)
2138 [ "$fileset" = "/dir$i" ] ||
2139 error "nm$i.fileset $fileset != /dir$i on mds$i"
2140 do_facet mgs $LCTL nodemap_del nm$i ||
2141 error "delete nodemap nm$i failed"
2144 nodemap_test_cleanup
2146 run_test 27b "The new nodemap won't clear the old nodemap's fileset"
2149 if ! $SHARED_KEY; then
2150 skip "need shared key feature for this test" && return
2152 mkdir -p $DIR/$tdir || error "mkdir failed"
2153 touch $DIR/$tdir/$tdir.out || error "touch failed"
2154 if [ ! -f $DIR/$tdir/$tdir.out ]; then
2155 error "read before rotation failed"
2157 # store top key identity to ensure rotation has occurred
2158 SK_IDENTITY_OLD=$(lctl get_param *.*.*srpc* | grep "expire" |
2159 head -1 | awk '{print $15}' | cut -c1-8)
2160 do_facet $SINGLEMDS lfs flushctx ||
2161 error "could not run flushctx on $SINGLEMDS"
2163 lfs flushctx || error "could not run flushctx on client"
2165 # verify new key is in place
2166 SK_IDENTITY_NEW=$(lctl get_param *.*.*srpc* | grep "expire" |
2167 head -1 | awk '{print $15}' | cut -c1-8)
2168 if [ $SK_IDENTITY_OLD == $SK_IDENTITY_NEW ]; then
2169 error "key did not rotate correctly"
2171 if [ ! -f $DIR/$tdir/$tdir.out ]; then
2172 error "read after rotation failed"
2175 run_test 28 "check shared key rotation method"
2178 if ! $SHARED_KEY; then
2179 skip "need shared key feature for this test" && return
2181 if [ $SK_FLAVOR != "ski" ] && [ $SK_FLAVOR != "skpi" ]; then
2182 skip "test only valid if integrity is active"
2185 mkdir $DIR/$tdir || error "mkdir"
2186 touch $DIR/$tdir/$tfile || error "touch"
2187 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2188 error "unable to umount clients"
2189 do_node ${clients_arr[0]} "keyctl show |
2190 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
2191 OLD_SK_PATH=$SK_PATH
2192 export SK_PATH=/dev/null
2193 if zconf_mount_clients ${clients_arr[0]} $MOUNT; then
2194 export SK_PATH=$OLD_SK_PATH
2195 do_node ${clients_arr[0]} "ls $DIR/$tdir/$tfile"
2196 if [ $? -eq 0 ]; then
2197 error "able to mount and read without key"
2199 error "able to mount without key"
2202 export SK_PATH=$OLD_SK_PATH
2203 do_node ${clients_arr[0]} "keyctl show |
2204 awk '/lustre/ { print \\\$1 }' |
2205 xargs -IX keyctl unlink X"
2207 zconf_mount_clients ${clients_arr[0]} $MOUNT ||
2208 error "unable to mount clients"
2210 run_test 29 "check for missing shared key"
2213 if ! $SHARED_KEY; then
2214 skip "need shared key feature for this test" && return
2216 if [ $SK_FLAVOR != "ski" ] && [ $SK_FLAVOR != "skpi" ]; then
2217 skip "test only valid if integrity is active"
2219 mkdir -p $DIR/$tdir || error "mkdir failed"
2220 touch $DIR/$tdir/$tdir.out || error "touch failed"
2221 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2222 error "unable to umount clients"
2223 # unload keys from ring
2224 do_node ${clients_arr[0]} "keyctl show |
2225 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
2226 # generate key with bogus filesystem name
2227 do_node ${clients_arr[0]} "lgss_sk -w $SK_PATH/$FSNAME-bogus.key \
2228 -f $FSNAME.bogus -t client -d /dev/urandom" ||
2229 error "lgss_sk failed (1)"
2230 do_facet $SINGLEMDS lfs flushctx || error "could not run flushctx"
2231 OLD_SK_PATH=$SK_PATH
2232 export SK_PATH=$SK_PATH/$FSNAME-bogus.key
2233 if zconf_mount_clients ${clients_arr[0]} $MOUNT; then
2234 SK_PATH=$OLD_SK_PATH
2235 do_node ${clients_arr[0]} "ls $DIR/$tdir/$tdir.out"
2236 if [ $? -eq 0 ]; then
2237 error "mount and read file with invalid key"
2239 error "mount with invalid key"
2242 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2243 error "unable to umount clients"
2244 # unload keys from ring
2245 do_node ${clients_arr[0]} "keyctl show |
2246 awk '/lustre/ { print \\\$1 }' | xargs -IX keyctl unlink X"
2248 SK_PATH=$OLD_SK_PATH
2249 zconf_mount_clients ${clients_arr[0]} $MOUNT ||
2250 error "unable to mount clients"
2252 run_test 30 "check for invalid shared key"
2257 mkdir -p $DIR/$tdir || error "mkdir $flvr"
2258 touch $DIR/$tdir/f0 || error "touch $flvr"
2259 ls $DIR/$tdir || error "ls $flvr"
2260 dd if=/dev/zero of=$DIR/$tdir/f0 conv=fsync bs=1M count=10 \
2261 >& /dev/null || error "dd $flvr"
2262 rm -f $DIR/$tdir/f0 || error "rm $flvr"
2263 rmdir $DIR/$tdir || error "rmdir $flvr"
2266 echo 3 > /proc/sys/vm/drop_caches
2270 local save_flvr=$SK_FLAVOR
2272 if ! $SHARED_KEY; then
2273 skip "need shared key feature for this test"
2276 stack_trap restore_to_default_flavor EXIT
2278 for flvr in skn ska ski skpi; do
2281 restore_to_default_flavor || error "cannot set $flvr flavor"
2282 SK_FLAVOR=$save_flvr
2287 run_test 30b "basic test of all different SSK flavors"
2291 zconf_umount $HOSTNAME $MOUNT || error "unable to umount client"
2293 # remove ${NETTYPE}999 network on all nodes
2294 do_nodes $(comma_list $(all_nodes)) \
2295 "$LNETCTL net del --net ${NETTYPE}999 && \
2296 $LNETCTL lnet unconfigure 2>/dev/null || true"
2298 # necessary to do writeconf in order to de-register
2299 # @${NETTYPE}999 nid for targets
2301 export KEEP_ZPOOL="true"
2303 export SK_MOUNTED=false
2306 export KEEP_ZPOOL="$KZPOOL"
2310 local nid=$(lctl list_nids | grep ${NETTYPE} | head -n1)
2311 local addr=${nid%@*}
2314 export LNETCTL=$(which lnetctl 2> /dev/null)
2316 [ -z "$LNETCTL" ] && skip "without lnetctl support." && return
2317 local_mode && skip "in local mode."
2319 stack_trap cleanup_31 EXIT
2322 if [ "$MOUNT_2" ] && $(grep -q $MOUNT2' ' /proc/mounts); then
2323 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2325 if $(grep -q $MOUNT' ' /proc/mounts); then
2326 umount_client $MOUNT || error "umount $MOUNT failed"
2329 # check exports on servers are empty for client
2330 do_facet mgs "lctl get_param -n *.MGS*.exports.'$nid'.uuid 2>/dev/null |
2331 grep -q -" && error "export on MGS should be empty"
2332 do_nodes $(comma_list $(mdts_nodes) $(osts_nodes)) \
2333 "lctl get_param -n *.${FSNAME}*.exports.'$nid'.uuid \
2334 2>/dev/null | grep -q -" &&
2335 error "export on servers should be empty"
2337 # add network ${NETTYPE}999 on all nodes
2338 do_nodes $(comma_list $(all_nodes)) \
2339 "$LNETCTL lnet configure && $LNETCTL net add --if \
2340 \$($LNETCTL net show --net $net | awk 'BEGIN{inf=0} \
2341 {if (inf==1) print \$2; fi; inf=0} /interfaces/{inf=1}') \
2342 --net ${NETTYPE}999" ||
2343 error "unable to configure NID ${NETTYPE}999"
2345 # necessary to do writeconf in order to register
2346 # new @${NETTYPE}999 nid for targets
2348 export KEEP_ZPOOL="true"
2350 export SK_MOUNTED=false
2352 setupall server_only || echo 1
2353 export KEEP_ZPOOL="$KZPOOL"
2356 local mgsnid_orig=$MGSNID
2357 # compute new MGSNID
2358 MGSNID=$(do_facet mgs "$LCTL list_nids | grep ${NETTYPE}999")
2360 # on client, turn LNet Dynamic Discovery on
2361 lnetctl set discovery 1
2363 # mount client with -o network=${NETTYPE}999 option:
2364 # should fail because of LNet Dynamic Discovery
2365 mount_client $MOUNT ${MOUNT_OPTS},network=${NETTYPE}999 &&
2366 error "client mount with '-o network' option should be refused"
2368 # on client, reconfigure LNet and turn LNet Dynamic Discovery off
2369 $LNETCTL net del --net ${NETTYPE}999 && lnetctl lnet unconfigure
2372 lnetctl set discovery 0
2374 $LNETCTL lnet configure && $LNETCTL net add --if \
2375 $($LNETCTL net show --net $net | awk 'BEGIN{inf=0} \
2376 {if (inf==1) print $2; fi; inf=0} /interfaces/{inf=1}') \
2377 --net ${NETTYPE}999 ||
2378 error "unable to configure NID ${NETTYPE}999 on client"
2380 # mount client with -o network=${NETTYPE}999 option
2381 mount_client $MOUNT ${MOUNT_OPTS},network=${NETTYPE}999 ||
2382 error "unable to remount client"
2387 # check export on MGS
2388 do_facet mgs "lctl get_param -n *.MGS*.exports.'$nid'.uuid 2>/dev/null |
2390 [ $? -ne 0 ] || error "export for $nid on MGS should not exist"
2393 "lctl get_param -n *.MGS*.exports.'${addr}@${NETTYPE}999'.uuid \
2394 2>/dev/null | grep -q -"
2396 error "export for ${addr}@${NETTYPE}999 on MGS should exist"
2398 # check {mdc,osc} imports
2399 lctl get_param mdc.${FSNAME}-*.import | grep current_connection |
2400 grep -q ${NETTYPE}999
2402 error "import for mdc should use ${addr}@${NETTYPE}999"
2403 lctl get_param osc.${FSNAME}-*.import | grep current_connection |
2404 grep -q ${NETTYPE}999
2406 error "import for osc should use ${addr}@${NETTYPE}999"
2408 run_test 31 "client mount option '-o network'"
2412 zconf_umount_clients ${clients_arr[0]} $MOUNT
2414 # disable sk flavor enforcement on MGS
2415 set_rule _mgs any any null
2417 # stop gss daemon on MGS
2418 if ! combined_mgs_mds ; then
2419 send_sigint $mgs_HOST lsvcgssd
2423 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
2426 restore_to_default_flavor
2430 if ! $SHARED_KEY; then
2431 skip "need shared key feature for this test"
2434 stack_trap cleanup_32 EXIT
2436 # restore to default null flavor
2437 save_flvr=$SK_FLAVOR
2439 restore_to_default_flavor || error "cannot set null flavor"
2440 SK_FLAVOR=$save_flvr
2443 if [ "$MOUNT_2" ] && $(grep -q $MOUNT2' ' /proc/mounts); then
2444 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2446 if $(grep -q $MOUNT' ' /proc/mounts); then
2447 umount_client $MOUNT || error "umount $MOUNT failed"
2450 # start gss daemon on MGS
2451 if combined_mgs_mds ; then
2452 send_sigint $mds_HOST lsvcgssd
2454 start_gss_daemons $mgs_HOST "$LSVCGSSD -vvv -s -g"
2456 # add mgs key type and MGS NIDs in key on MGS
2457 do_nodes $mgs_HOST "lgss_sk -t mgs,server -g $MGSNID -m \
2458 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2459 error "could not modify keyfile on MGS"
2461 # load modified key file on MGS
2462 do_nodes $mgs_HOST "lgss_sk -l $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2463 error "could not load keyfile on MGS"
2465 # add MGS NIDs in key on client
2466 do_nodes ${clients_arr[0]} "lgss_sk -g $MGSNID -m \
2467 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2468 error "could not modify keyfile on MGS"
2470 # set perms for per-nodemap keys else permission denied
2471 do_nodes $(comma_list $(all_nodes)) \
2472 "keyctl show | grep lustre | cut -c1-11 |
2474 xargs -IX keyctl setperm X 0x3f3f3f3f"
2476 # re-mount client with mgssec=skn
2477 save_opts=$MOUNT_OPTS
2478 if [ -z "$MOUNT_OPTS" ]; then
2479 MOUNT_OPTS="-o mgssec=skn"
2481 MOUNT_OPTS="$MOUNT_OPTS,mgssec=skn"
2483 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2484 error "mount ${clients_arr[0]} with mgssec=skn failed"
2485 MOUNT_OPTS=$save_opts
2488 zconf_umount_clients ${clients_arr[0]} $MOUNT ||
2489 error "umount ${clients_arr[0]} failed"
2491 # enforce ska flavor on MGS
2492 set_rule _mgs any any ska
2494 # re-mount client without mgssec
2495 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS &&
2496 error "mount ${clients_arr[0]} without mgssec should fail"
2498 # re-mount client with mgssec=skn
2499 save_opts=$MOUNT_OPTS
2500 if [ -z "$MOUNT_OPTS" ]; then
2501 MOUNT_OPTS="-o mgssec=skn"
2503 MOUNT_OPTS="$MOUNT_OPTS,mgssec=skn"
2505 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS &&
2506 error "mount ${clients_arr[0]} with mgssec=skn should fail"
2507 MOUNT_OPTS=$save_opts
2509 # re-mount client with mgssec=ska
2510 save_opts=$MOUNT_OPTS
2511 if [ -z "$MOUNT_OPTS" ]; then
2512 MOUNT_OPTS="-o mgssec=ska"
2514 MOUNT_OPTS="$MOUNT_OPTS,mgssec=ska"
2516 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2517 error "mount ${clients_arr[0]} with mgssec=ska failed"
2518 MOUNT_OPTS=$save_opts
2522 run_test 32 "check for mgssec"
2525 # disable sk flavor enforcement
2526 set_rule $FSNAME any cli2mdt null
2527 wait_flavor cli2mdt null
2530 zconf_umount_clients ${clients_arr[0]} $MOUNT
2532 # stop gss daemon on MGS
2533 if ! combined_mgs_mds ; then
2534 send_sigint $mgs_HOST lsvcgssd
2538 MOUNT_OPTS=$(add_sk_mntflag $MOUNT_OPTS)
2541 restore_to_default_flavor
2545 if ! $SHARED_KEY; then
2546 skip "need shared key feature for this test"
2549 stack_trap cleanup_33 EXIT
2551 # restore to default null flavor
2552 save_flvr=$SK_FLAVOR
2554 restore_to_default_flavor || error "cannot set null flavor"
2555 SK_FLAVOR=$save_flvr
2558 if [ "$MOUNT_2" ] && $(grep -q $MOUNT2' ' /proc/mounts); then
2559 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2561 if $(grep -q $MOUNT' ' /proc/mounts); then
2562 umount_client $MOUNT || error "umount $MOUNT failed"
2565 # start gss daemon on MGS
2566 if combined_mgs_mds ; then
2567 send_sigint $mds_HOST lsvcgssd
2569 start_gss_daemons $mgs_HOST "$LSVCGSSD -vvv -s -g"
2571 # add mgs key type and MGS NIDs in key on MGS
2572 do_nodes $mgs_HOST "lgss_sk -t mgs,server -g $MGSNID -m \
2573 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2574 error "could not modify keyfile on MGS"
2576 # load modified key file on MGS
2577 do_nodes $mgs_HOST "lgss_sk -l $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2578 error "could not load keyfile on MGS"
2580 # add MGS NIDs in key on client
2581 do_nodes ${clients_arr[0]} "lgss_sk -g $MGSNID -m \
2582 $SK_PATH/$FSNAME.key >/dev/null 2>&1" ||
2583 error "could not modify keyfile on MGS"
2585 # set perms for per-nodemap keys else permission denied
2586 do_nodes $(comma_list $(all_nodes)) \
2587 "keyctl show | grep lustre | cut -c1-11 |
2589 xargs -IX keyctl setperm X 0x3f3f3f3f"
2591 # re-mount client with mgssec=skn
2592 save_opts=$MOUNT_OPTS
2593 if [ -z "$MOUNT_OPTS" ]; then
2594 MOUNT_OPTS="-o mgssec=skn"
2596 MOUNT_OPTS="$MOUNT_OPTS,mgssec=skn"
2598 zconf_mount_clients ${clients_arr[0]} $MOUNT $MOUNT_OPTS ||
2599 error "mount ${clients_arr[0]} with mgssec=skn failed"
2600 MOUNT_OPTS=$save_opts
2602 # enforce ska flavor for cli2mdt
2603 set_rule $FSNAME any cli2mdt ska
2604 wait_flavor cli2mdt ska
2606 # check error message
2607 $LCTL dk | grep "faked source" &&
2608 error "MGS connection srpc flags incorrect"
2612 run_test 33 "correct srpc flags for MGS connection"
2615 # restore deny_unknown
2616 do_facet mgs $LCTL nodemap_modify --name default \
2617 --property deny_unknown --value $denydefault
2618 if [ $? -ne 0 ]; then
2619 error_noexit "cannot reset deny_unknown on default nodemap"
2623 wait_nm_sync default deny_unknown
2630 [ $MGS_VERSION -lt $(version_code 2.12.51) ] &&
2631 skip "deny_unknown on default nm not supported before 2.12.51"
2633 activedefault=$(do_facet mgs $LCTL get_param -n nodemap.active)
2635 if [[ "$activedefault" != "1" ]]; then
2636 do_facet mgs $LCTL nodemap_activate 1
2638 stack_trap cleanup_active EXIT
2641 denydefault=$(do_facet mgs $LCTL get_param -n \
2642 nodemap.default.deny_unknown)
2643 [ -z "$denydefault" ] &&
2644 error "cannot get deny_unknown on default nodemap"
2645 if [ "$denydefault" -eq 0 ]; then
2651 do_facet mgs $LCTL nodemap_modify --name default \
2652 --property deny_unknown --value $denynew ||
2653 error "cannot set deny_unknown on default nodemap"
2655 [ "$(do_facet mgs $LCTL get_param -n nodemap.default.deny_unknown)" \
2657 error "setting deny_unknown on default nodemap did not work"
2659 stack_trap cleanup_34_deny EXIT
2661 wait_nm_sync default deny_unknown
2663 run_test 34 "deny_unknown on default nodemap"
2666 [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.13.50) ] ||
2667 skip "Need MDS >= 2.13.50"
2669 # activate changelogs
2670 changelog_register || error "changelog_register failed"
2671 local cl_user="${CL_USERS[$SINGLEMDS]%% *}"
2672 changelog_users $SINGLEMDS | grep -q $cl_user ||
2673 error "User $cl_user not found in changelog_users"
2674 changelog_chmask ALL
2677 mkdir $DIR/$tdir || error "failed to mkdir $tdir"
2678 touch $DIR/$tdir/$tfile || error "failed to touch $tfile"
2680 # access changelogs with root
2681 changelog_dump || error "failed to dump changelogs"
2682 changelog_clear 0 || error "failed to clear changelogs"
2684 # put clients in non-admin nodemap
2686 stack_trap nodemap_test_cleanup EXIT
2687 for i in $(seq 0 $((num_clients-1))); do
2688 do_facet mgs $LCTL nodemap_modify --name c${i} \
2689 --property admin --value 0
2691 for i in $(seq 0 $((num_clients-1))); do
2692 wait_nm_sync c${i} admin_nodemap
2695 # access with mapped root
2696 changelog_dump && error "dump changelogs should have failed"
2697 changelog_clear 0 && error "clear changelogs should have failed"
2701 run_test 35 "Check permissions when accessing changelogs"
2704 local mode='\x00\x00\x00\x00'
2705 local raw="$(printf ""\\\\x%02x"" {0..63})"
2709 [[ $(lscpu) =~ Byte\ Order.*Little ]] && size='\x40\x00\x00\x00' ||
2710 size='\x00\x00\x00\x40'
2711 key="${mode}${raw}${size}"
2712 echo -n -e "${key}" | keyctl padd logon fscrypt:4242424242424242 @s
2717 sync ; echo 3 > /proc/sys/vm/drop_caches
2724 $LCTL set_param -n ldlm.namespaces.*.lru_size=clear
2725 sync ; echo 3 > /proc/sys/vm/drop_caches
2726 dummy_key=$(keyctl show | awk '$7 ~ "^fscrypt:" {print $1}')
2727 if [ -n "$dummy_key" ]; then
2728 keyctl revoke $dummy_key
2733 remount_client_normally() {
2734 # remount client without dummy encryption key
2735 if is_mounted $MOUNT; then
2736 umount_client $MOUNT || error "umount $MOUNT failed"
2738 mount_client $MOUNT ${MOUNT_OPTS} ||
2739 error "remount failed"
2741 if is_mounted $MOUNT2; then
2742 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
2744 if [ "$MOUNT_2" ]; then
2745 mount_client $MOUNT2 ${MOUNT_OPTS} ||
2746 error "remount failed"
2752 remount_client_dummykey() {
2755 # remount client with dummy encryption key
2756 if is_mounted $MOUNT; then
2757 umount_client $MOUNT || error "umount $MOUNT failed"
2759 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption ||
2760 error "remount failed"
2763 setup_for_enc_tests() {
2764 # remount client with test_dummy_encryption option
2765 if is_mounted $MOUNT; then
2766 umount_client $MOUNT || error "umount $MOUNT failed"
2768 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption ||
2769 error "mount with '-o test_dummy_encryption' failed"
2771 # this directory will be encrypted, because of dummy mode
2775 cleanup_for_enc_tests() {
2776 rm -rf $DIR/$tdir $*
2778 remount_client_normally
2781 cleanup_nodemap_after_enc_tests() {
2782 umount_client $MOUNT || true
2784 do_facet mgs $LCTL nodemap_modify --name default \
2785 --property forbid_encryption --value 0
2786 do_facet mgs $LCTL nodemap_modify --name default \
2787 --property readonly_mount --value 0 || true
2788 do_facet mgs $LCTL nodemap_modify --name default \
2789 --property trusted --value 0
2790 do_facet mgs $LCTL nodemap_modify --name default \
2791 --property admin --value 0
2792 do_facet mgs $LCTL nodemap_activate 0
2794 wait_nm_sync default forbid_encryption '' inactive
2795 [ -z "$(do_facet mgs \
2796 lctl get_param -n nodemap.default.readonly_mount)" ] ||
2797 wait_nm_sync default readonly_mount '' inactive
2798 wait_nm_sync default trusted_nodemap '' inactive
2799 wait_nm_sync default admin_nodemap '' inactive
2802 mount_client $MOUNT ${MOUNT_OPTS} || error "re-mount failed"
2806 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2807 skip "client encryption not supported"
2809 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2810 skip "need dummy encryption support"
2812 stack_trap cleanup_for_enc_tests EXIT
2814 # first make sure it is possible to enable encryption
2815 # when nodemap is not active
2818 umount_client $MOUNT || error "umount $MOUNT failed (1)"
2820 # then activate nodemap, and retry
2821 # should succeed as encryption is not forbidden on default nodemap
2823 stack_trap cleanup_nodemap_after_enc_tests EXIT
2824 do_facet mgs $LCTL nodemap_activate 1
2826 forbid=$(do_facet mgs lctl get_param -n nodemap.default.forbid_encryption)
2827 [ $forbid -eq 0 ] || error "wrong default value for forbid_encryption"
2828 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption ||
2829 error "mount '-o test_dummy_encryption' failed with default"
2830 umount_client $MOUNT || error "umount $MOUNT failed (2)"
2832 # then forbid encryption, and retry
2833 do_facet mgs $LCTL nodemap_modify --name default \
2834 --property forbid_encryption --value 1
2835 wait_nm_sync default forbid_encryption
2836 mount_client $MOUNT ${MOUNT_OPTS},test_dummy_encryption &&
2837 error "mount '-o test_dummy_encryption' should have failed"
2840 run_test 36 "control if clients can use encryption"
2843 local testfile=$DIR/$tdir/$tfile
2844 local tmpfile=$TMP/abc
2845 local objdump=$TMP/objdump
2848 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2849 skip "client encryption not supported"
2851 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2852 skip "need dummy encryption support"
2854 [ "$ost1_FSTYPE" = ldiskfs ] || skip "ldiskfs only test (using debugfs)"
2856 stack_trap cleanup_for_enc_tests EXIT
2859 # write a few bytes in file
2860 echo "abc" > $tmpfile
2861 $LFS setstripe -c1 -i0 $testfile
2862 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2863 do_facet ost1 "sync; sync"
2865 # check that content on ost is encrypted
2866 objid=$($LFS getstripe $testfile | awk '/obdidx/{getline; print $2}')
2867 do_facet ost1 "$DEBUGFS -c -R 'cat O/0/d$(($objid % 32))/$objid' \
2868 $(ostdevname 1)" > $objdump
2869 cmp -s $objdump $tmpfile &&
2870 error "file $testfile is not encrypted on ost"
2872 # check that in-memory representation of file is correct
2873 cmp -bl ${tmpfile} ${testfile} ||
2874 error "file $testfile is corrupted in memory"
2876 cancel_lru_locks osc ; cancel_lru_locks mdc
2878 # check that file read from server is correct
2879 cmp -bl ${tmpfile} ${testfile} ||
2880 error "file $testfile is corrupted on server"
2882 rm -f $tmpfile $objdump
2884 run_test 37 "simple encrypted file"
2887 local testfile=$DIR/$tdir/$tfile
2888 local tmpfile=$TMP/abc
2894 local pagesz=$(getconf PAGE_SIZE)
2896 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2897 skip "client encryption not supported"
2899 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2900 skip "need dummy encryption support"
2902 stack_trap cleanup_for_enc_tests EXIT
2905 # get block size on ost
2906 blksz=$($LCTL get_param osc.$FSNAME*.import |
2907 awk '/grant_block_size:/ { print $2; exit; }')
2908 # write a few bytes in file at offset $blksz
2909 echo "abc" > $tmpfile
2910 $LFS setstripe -c1 -i0 $testfile
2911 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$blksz \
2912 oflag=seek_bytes conv=fsync
2914 blksz=$(($blksz > $pagesz ? $blksz : $pagesz))
2915 # check that in-memory representation of file is correct
2916 bsize=$(stat --format=%B $testfile)
2917 filesz=$(stat --format=%b $testfile)
2918 filesz=$((filesz*bsize))
2919 [ $filesz -le $blksz ] ||
2920 error "file $testfile is $filesz long in memory"
2922 cancel_lru_locks osc ; cancel_lru_locks mdc
2924 # check that file read from server is correct
2925 bsize=$(stat --format=%B $testfile)
2926 filesz=$(stat --format=%b $testfile)
2927 filesz=$((filesz*bsize))
2928 [ $filesz -le $blksz ] ||
2929 error "file $testfile is $filesz long on server"
2933 run_test 38 "encrypted file with hole"
2936 local testfile=$DIR/$tdir/$tfile
2937 local tmpfile=$TMP/abc
2939 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2940 skip "client encryption not supported"
2942 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2943 skip "need dummy encryption support"
2945 stack_trap cleanup_for_enc_tests EXIT
2948 # write a few bytes in file
2949 echo "abc" > $tmpfile
2950 $LFS setstripe -c1 -i0 $testfile
2951 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
2953 # write a few more bytes in the same page
2954 dd if=$tmpfile of=$testfile bs=4 count=1 seek=1024 oflag=seek_bytes \
2957 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=1024 oflag=seek_bytes \
2960 # check that in-memory representation of file is correct
2961 cmp -bl $tmpfile $testfile ||
2962 error "file $testfile is corrupted in memory"
2964 cancel_lru_locks osc ; cancel_lru_locks mdc
2966 # check that file read from server is correct
2967 cmp -bl $tmpfile $testfile ||
2968 error "file $testfile is corrupted on server"
2972 run_test 39 "rewrite data in already encrypted page"
2975 local testfile=$DIR/$tdir/$tfile
2976 local tmpfile=$TMP/abc
2977 local tmpfile2=$TMP/abc2
2980 #define LUSTRE_ENCRYPTION_UNIT_SIZE (1 << 12)
2981 local UNIT_SIZE=$((1 << 12))
2984 $LCTL get_param mdc.*.import | grep -q client_encryption ||
2985 skip "client encryption not supported"
2987 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
2988 skip "need dummy encryption support"
2990 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
2992 stack_trap cleanup_for_enc_tests EXIT
2995 # write a few bytes in file
2996 echo "abc" > $tmpfile
2997 $LFS setstripe -c1 -i0 $testfile
2998 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync
3000 # check that in-memory representation of file is correct
3001 cmp -bl $tmpfile $testfile ||
3002 error "file $testfile is corrupted in memory (1)"
3004 cancel_lru_locks osc ; cancel_lru_locks mdc
3006 # check that file read from server is correct
3007 cmp -bl $tmpfile $testfile ||
3008 error "file $testfile is corrupted on server (1)"
3010 # write a few other bytes in same page
3011 dd if=$tmpfile of=$testfile bs=4 count=1 seek=256 oflag=seek_bytes \
3014 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=256 oflag=seek_bytes \
3017 # check that in-memory representation of file is correct
3018 cmp -bl $tmpfile $testfile ||
3019 error "file $testfile is corrupted in memory (2)"
3021 cancel_lru_locks osc ; cancel_lru_locks mdc
3023 # check that file read from server is correct
3024 cmp -bl $tmpfile $testfile ||
3025 error "file $testfile is corrupted on server (2)"
3027 rm -f $testfile $tmpfile
3028 cancel_lru_locks osc ; cancel_lru_locks mdc
3030 # write a few bytes in file, at end of first page
3031 echo "abc" > $tmpfile
3032 $LFS setstripe -c1 -i0 $testfile
3033 seek=$(getconf PAGESIZE)
3035 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3038 # write a few other bytes at beginning of first page
3039 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync,notrunc
3041 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3044 # check that in-memory representation of file is correct
3045 cmp -bl $tmpfile $testfile ||
3046 error "file $testfile is corrupted in memory (3)"
3048 cancel_lru_locks osc ; cancel_lru_locks mdc
3050 # check that file read from server is correct
3051 cmp -bl $tmpfile $testfile ||
3052 error "file $testfile is corrupted on server (3)"
3054 rm -f $testfile $tmpfile
3055 cancel_lru_locks osc ; cancel_lru_locks mdc
3057 # write a few bytes in file, at beginning of second page
3058 echo "abc" > $tmpfile
3059 $LFS setstripe -c1 -i0 $testfile
3060 seek=$(getconf PAGESIZE)
3061 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3063 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3066 # write a few other bytes at end of first page
3068 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3070 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3073 # check that in-memory representation of file is correct
3074 cmp -bl $tmpfile2 $testfile ||
3075 error "file $testfile is corrupted in memory (4)"
3077 cancel_lru_locks osc ; cancel_lru_locks mdc
3079 # check that file read from server is correct
3080 cmp -bl $tmpfile2 $testfile ||
3081 error "file $testfile is corrupted on server (4)"
3083 rm -f $testfile $tmpfile $tmpfile2
3084 cancel_lru_locks osc ; cancel_lru_locks mdc
3086 # write a few bytes in file, at beginning of first stripe
3087 echo "abc" > $tmpfile
3088 $LFS setstripe -S 256k -c2 $testfile
3089 dd if=$tmpfile of=$testfile bs=4 count=1 conv=fsync,notrunc
3091 # write a few other bytes, at beginning of second stripe
3092 dd if=$tmpfile of=$testfile bs=4 count=1 seek=262144 oflag=seek_bytes \
3094 dd if=$tmpfile of=$tmpfile bs=4 count=1 seek=262144 oflag=seek_bytes \
3097 # check that in-memory representation of file is correct
3098 cmp -bl $tmpfile $testfile ||
3099 error "file $testfile is corrupted in memory (5)"
3101 cancel_lru_locks osc ; cancel_lru_locks mdc
3103 # check that file read from server is correct
3104 cmp -bl $tmpfile $testfile ||
3105 error "file $testfile is corrupted on server (5)"
3107 filesz=$(stat --format=%s $testfile)
3108 filesz=$(((filesz+UNIT_SIZE-1)/UNIT_SIZE * UNIT_SIZE))
3110 # remount without dummy encryption key
3111 remount_client_normally
3113 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type f)
3114 [ $(stat --format=%s $scrambledfile) -eq $filesz ] ||
3115 error "file size without key should be rounded up"
3119 run_test 40 "exercise size of encrypted file"
3122 local testfile=$DIR/$tdir/$tfile
3123 local tmpfile=$TMP/abc
3124 local tmpfile2=$TMP/abc2
3127 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3128 skip "client encryption not supported"
3130 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3131 skip "need dummy encryption support"
3133 stack_trap cleanup_for_enc_tests EXIT
3136 echo "abc" > $tmpfile
3137 seek=$(getconf PAGESIZE)
3138 seek=$((seek - 204))
3139 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3141 seek=$(getconf PAGESIZE)
3142 seek=$((seek + 1092))
3143 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3146 # write a few bytes in file
3147 $LFS setstripe -c1 -i0 -S 256k $testfile
3148 seek=$(getconf PAGESIZE)
3149 seek=$((seek - 204))
3150 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
3151 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
3152 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3156 # write a few other bytes, at a different offset
3157 seek=$(getconf PAGESIZE)
3158 seek=$((seek + 1092))
3159 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3160 conv=fsync,notrunc &
3162 do_facet ost1 "$LCTL set_param fail_loc=0x0"
3164 # check that in-memory representation of file is correct
3165 cmp -bl $tmpfile2 $testfile ||
3166 error "file $testfile is corrupted in memory (1)"
3168 cancel_lru_locks osc ; cancel_lru_locks mdc
3170 # check that file read from server is correct
3171 cmp -bl $tmpfile2 $testfile ||
3172 error "file $testfile is corrupted on server (1)"
3174 rm -f $tmpfile $tmpfile2
3176 run_test 41 "test race on encrypted file size (1)"
3179 local testfile=$DIR/$tdir/$tfile
3180 local testfile2=$DIR2/$tdir/$tfile
3181 local tmpfile=$TMP/abc
3182 local tmpfile2=$TMP/abc2
3183 local pagesz=$(getconf PAGESIZE)
3186 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3187 skip "client encryption not supported"
3189 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3190 skip "need dummy encryption support"
3192 stack_trap cleanup_for_enc_tests EXIT
3195 if is_mounted $MOUNT2; then
3196 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
3198 mount_client $MOUNT2 ${MOUNT_OPTS},test_dummy_encryption ||
3199 error "mount2 with '-o test_dummy_encryption' failed"
3201 # create file by writting one whole page
3202 $LFS setstripe -c1 -i0 -S 256k $testfile
3203 dd if=/dev/zero of=$testfile bs=$pagesz count=1 conv=fsync
3205 # read file from 2nd mount point
3206 cat $testfile2 > /dev/null
3208 echo "abc" > $tmpfile
3209 dd if=/dev/zero of=$tmpfile2 bs=$pagesz count=1 conv=fsync
3210 seek=$((2*pagesz - 204))
3211 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3213 seek=$((2*pagesz + 1092))
3214 dd if=$tmpfile of=$tmpfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3217 # write a few bytes in file from 1st mount point
3218 seek=$((2*pagesz - 204))
3219 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
3220 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
3221 dd if=$tmpfile of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3222 conv=fsync,notrunc &
3225 # write a few other bytes, at a different offset from 2nd mount point
3226 seek=$((2*pagesz + 1092))
3227 dd if=$tmpfile of=$testfile2 bs=4 count=1 seek=$seek oflag=seek_bytes \
3228 conv=fsync,notrunc &
3230 do_facet ost1 "$LCTL set_param fail_loc=0x0"
3232 # check that in-memory representation of file is correct
3233 cmp -bl $tmpfile2 $testfile ||
3234 error "file $testfile is corrupted in memory (1)"
3236 # check that in-memory representation of file is correct
3237 cmp -bl $tmpfile2 $testfile2 ||
3238 error "file $testfile is corrupted in memory (2)"
3240 cancel_lru_locks osc ; cancel_lru_locks mdc
3242 # check that file read from server is correct
3243 cmp -bl $tmpfile2 $testfile ||
3244 error "file $testfile is corrupted on server (1)"
3246 rm -f $tmpfile $tmpfile2
3248 run_test 42 "test race on encrypted file size (2)"
3251 local testfile=$DIR/$tdir/$tfile
3252 local testfile2=$DIR2/$tdir/$tfile
3253 local tmpfile=$TMP/abc
3254 local tmpfile2=$TMP/abc2
3255 local resfile=$TMP/res
3256 local pagesz=$(getconf PAGESIZE)
3259 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3260 skip "client encryption not supported"
3262 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3263 skip "need dummy encryption support"
3265 stack_trap cleanup_for_enc_tests EXIT
3268 if is_mounted $MOUNT2; then
3269 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
3271 mount_client $MOUNT2 ${MOUNT_OPTS},test_dummy_encryption ||
3272 error "mount2 with '-o test_dummy_encryption' failed"
3275 tr '\0' '1' < /dev/zero |
3276 dd of=$tmpfile bs=1 count=$pagesz conv=fsync
3277 $LFS setstripe -c1 -i0 -S 256k $testfile
3278 cp $tmpfile $testfile
3280 # read file from 2nd mount point
3281 cat $testfile2 > /dev/null
3283 # write a few bytes in file from 1st mount point
3284 echo "abc" > $tmpfile2
3285 seek=$((2*pagesz - 204))
3286 #define OBD_FAIL_OST_WR_ATTR_DELAY 0x250
3287 do_facet ost1 "$LCTL set_param fail_loc=0x250 fail_val=15"
3288 dd if=$tmpfile2 of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3289 conv=fsync,notrunc &
3292 # read file from 2nd mount point
3293 dd if=$testfile2 of=$resfile bs=$pagesz count=1 conv=fsync,notrunc
3294 cmp -bl $tmpfile $resfile ||
3295 error "file $testfile is corrupted in memory (1)"
3298 do_facet ost1 "$LCTL set_param fail_loc=0x0"
3300 # check that in-memory representation of file is correct
3301 dd if=$tmpfile2 of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3303 cmp -bl $tmpfile $testfile2 ||
3304 error "file $testfile is corrupted in memory (2)"
3306 cancel_lru_locks osc ; cancel_lru_locks mdc
3308 # check that file read from server is correct
3309 cmp -bl $tmpfile $testfile ||
3310 error "file $testfile is corrupted on server (1)"
3312 rm -f $tmpfile $tmpfile2
3314 run_test 43 "test race on encrypted file size (3)"
3317 local testfile=$DIR/$tdir/$tfile
3318 local tmpfile=$TMP/abc
3319 local resfile=$TMP/resfile
3320 local pagesz=$(getconf PAGESIZE)
3323 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3324 skip "client encryption not supported"
3326 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3327 skip "need dummy encryption support"
3329 which vmtouch || skip "This test needs vmtouch utility"
3331 # Direct I/O is now supported on encrypted files.
3333 stack_trap cleanup_for_enc_tests EXIT
3336 $LFS setstripe -c1 -i0 $testfile
3337 dd if=/dev/urandom of=$tmpfile bs=$pagesz count=2 conv=fsync
3338 dd if=$tmpfile of=$testfile bs=$pagesz count=2 oflag=direct ||
3339 error "could not write to file with O_DIRECT (1)"
3341 respage=$(vmtouch $testfile | awk '/Resident Pages:/ {print $3}')
3342 [ "$respage" == "0/2" ] ||
3343 error "write to enc file fell back to buffered IO"
3347 dd if=$testfile of=$resfile bs=$pagesz count=2 iflag=direct ||
3348 error "could not read from file with O_DIRECT (1)"
3350 respage=$(vmtouch $testfile | awk '/Resident Pages:/ {print $3}')
3351 [ "$respage" == "0/2" ] ||
3352 error "read from enc file fell back to buffered IO"
3354 cmp -bl $tmpfile $resfile ||
3355 error "file $testfile is corrupted (1)"
3359 $TRUNCATE $tmpfile $pagesz
3360 dd if=$tmpfile of=$testfile bs=$pagesz count=1 seek=13 oflag=direct ||
3361 error "could not write to file with O_DIRECT (2)"
3365 dd if=$testfile of=$resfile bs=$pagesz count=1 skip=13 iflag=direct ||
3366 error "could not read from file with O_DIRECT (2)"
3367 cmp -bl $tmpfile $resfile ||
3368 error "file $testfile is corrupted (2)"
3370 rm -f $testfile $resfile
3371 $LFS setstripe -c1 -i0 $testfile
3373 $TRUNCATE $tmpfile $((pagesz/2 - 5))
3374 cp $tmpfile $testfile
3378 dd if=$testfile of=$resfile bs=$pagesz count=1 iflag=direct ||
3379 error "could not read from file with O_DIRECT (3)"
3380 cmp -bl $tmpfile $resfile ||
3381 error "file $testfile is corrupted (3)"
3383 rm -f $tmpfile $resfile $testfile
3385 if [ $OSTCOUNT -ge 2 ]; then
3386 dd if=/dev/urandom of=$tmpfile bs=$pagesz count=1 conv=fsync
3387 $LFS setstripe -S 256k -c2 $testfile
3389 # write in file, at beginning of first stripe, buffered IO
3390 dd if=$tmpfile of=$testfile bs=$pagesz count=1 \
3393 # write at beginning of second stripe, direct IO
3394 dd if=$tmpfile of=$testfile bs=$pagesz count=1 seek=256k \
3395 oflag=seek_bytes,direct conv=fsync,notrunc
3399 # read at beginning of first stripe, direct IO
3400 dd if=$testfile of=$resfile bs=$pagesz count=1 \
3401 iflag=direct conv=fsync
3403 cmp -bl $tmpfile $resfile ||
3404 error "file $testfile is corrupted (4)"
3406 # read at beginning of second stripe, buffered IO
3407 dd if=$testfile of=$resfile bs=$pagesz count=1 skip=256k \
3408 iflag=skip_bytes conv=fsync
3410 cmp -bl $tmpfile $resfile ||
3411 error "file $testfile is corrupted (5)"
3413 rm -f $tmpfile $resfile
3416 run_test 44 "encrypted file access semantics: direct IO"
3419 local testfile=$DIR/$tdir/$tfile
3420 local tmpfile=$TMP/junk
3422 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3423 skip "client encryption not supported"
3425 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3426 skip "need dummy encryption support"
3428 stack_trap cleanup_for_enc_tests EXIT
3431 $LFS setstripe -c1 -i0 $testfile
3432 dd if=/dev/zero of=$testfile bs=512K count=1
3433 $MULTIOP $testfile OSMRUc || error "$MULTIOP $testfile failed (1)"
3434 $MULTIOP $testfile OSMWUc || error "$MULTIOP $testfile failed (2)"
3436 dd if=/dev/zero of=$tmpfile bs=512K count=1
3437 $MULTIOP $tmpfile OSMWUc || error "$MULTIOP $tmpfile failed"
3438 $MMAP_CAT $tmpfile > ${tmpfile}2
3442 $MULTIOP $testfile OSMRUc
3443 $MMAP_CAT $testfile > ${testfile}2
3444 cmp -bl ${tmpfile}2 ${testfile}2 ||
3445 error "file $testfile is corrupted"
3447 rm -f $tmpfile ${tmpfile}2
3449 run_test 45 "encrypted file access semantics: MMAP"
3452 local testdir=$DIR/$tdir/mydir
3453 local testfile=$testdir/myfile
3454 local testdir2=$DIR/$tdir/mydirwithaveryverylongnametotestcodebehaviour0
3455 local testfile2=$testdir/myfilewithaveryverylongnametotestcodebehaviour0
3456 # testdir3, testfile3, testhl3 and testsl3 names are 255 bytes long
3457 local testdir3=$testdir2/dir_abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz012345678
3458 local testfile3=$testdir2/file_abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01234567
3459 local testhl3=$testdir2/hl_abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
3460 local testsl3=$testdir2/sl_abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
3461 local lsfile=$TMP/lsfile
3466 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3467 skip "client encryption not supported"
3469 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3470 skip "need dummy encryption support"
3472 stack_trap cleanup_for_enc_tests EXIT
3475 touch $DIR/$tdir/$tfile
3477 echo test > $testfile
3478 echo othertest > $testfile2
3479 if [[ $MDSCOUNT -gt 1 ]]; then
3480 $LFS setdirstripe -c1 -i1 $testdir2
3484 inum=$(stat -c %i $testdir2)
3485 if [ "$mds1_FSTYPE" = ldiskfs ]; then
3486 # For now, restrict this part of the test to ldiskfs backend,
3487 # as osd-zfs does not support 255 byte-long encrypted names.
3488 mkdir $testdir3 || error "cannot mkdir $testdir3"
3489 touch $testfile3 || error "cannot touch $testfile3"
3490 ln $testfile3 $testhl3 || error "cannot ln $testhl3"
3491 ln -s $testfile3 $testsl3 || error "cannot ln $testsl3"
3493 sync ; echo 3 > /proc/sys/vm/drop_caches
3495 # remount without dummy encryption key
3496 remount_client_normally
3499 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -inum $inum)
3500 stat $scrambleddir || error "stat $scrambleddir failed"
3501 if [ "$mds1_FSTYPE" = ldiskfs ]; then
3502 stat $scrambleddir/* || error "cannot stat in $scrambleddir"
3503 rm -rf $scrambleddir/* || error "cannot clean in $scrambleddir"
3505 rmdir $scrambleddir || error "rmdir $scrambleddir failed"
3507 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d)
3508 ls -1 $scrambleddir > $lsfile || error "ls $testdir failed (1)"
3510 scrambledfile=$scrambleddir/$(head -n 1 $lsfile)
3511 stat $scrambledfile || error "stat $scrambledfile failed (1)"
3514 cat $scrambledfile && error "cat $scrambledfile should have failed (1)"
3515 rm -f $scrambledfile || error "rm $scrambledfile failed (1)"
3517 ls -1 $scrambleddir > $lsfile || error "ls $testdir failed (2)"
3518 scrambledfile=$scrambleddir/$(head -n 1 $lsfile)
3519 stat $scrambledfile || error "stat $scrambledfile failed (2)"
3521 cat $scrambledfile && error "cat $scrambledfile should have failed (2)"
3523 touch $scrambleddir/otherfile &&
3524 error "touch otherfile should have failed"
3525 ls $scrambleddir/otherfile && error "otherfile should not exist"
3526 mkdir $scrambleddir/otherdir &&
3527 error "mkdir otherdir should have failed"
3528 ls -d $scrambleddir/otherdir && error "otherdir should not exist"
3531 rm -f $scrambledfile || error "rm $scrambledfile failed (2)"
3532 rmdir $scrambleddir || error "rmdir $scrambleddir failed"
3535 run_test 46 "encrypted file access semantics without key"
3538 local testfile=$DIR/$tdir/$tfile
3539 local testfile2=$DIR/$tdir/${tfile}.2
3540 local tmpfile=$DIR/junk
3545 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3546 skip "client encryption not supported"
3548 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3549 skip "need dummy encryption support"
3551 $LCTL get_param mdc.*.connect_flags | grep -q name_encryption ||
3554 stack_trap cleanup_for_enc_tests EXIT
3557 dd if=/dev/urandom of=$tmpfile bs=512K count=1
3558 mrename $tmpfile $testfile &&
3559 error "rename from unencrypted to encrypted dir should fail"
3561 ln $tmpfile $testfile &&
3562 error "link from encrypted to unencrypted dir should fail"
3564 cp $tmpfile $testfile ||
3565 error "cp from unencrypted to encrypted dir should succeed"
3568 mrename $testfile $testfile2 ||
3569 error "rename from within encrypted dir should succeed"
3571 ln $testfile2 $testfile ||
3572 error "link from within encrypted dir should succeed"
3573 cmp -bl $testfile2 $testfile ||
3574 error "cannot read from hard link (1.1)"
3575 echo a >> $testfile || error "cannot write to hard link (1)"
3577 cmp -bl $testfile2 $testfile ||
3578 error "cannot read from hard link (1.2)"
3581 ln $testfile2 $tmpfile ||
3582 error "link from unencrypted to encrypted dir should succeed"
3584 cmp -bl $testfile2 $tmpfile ||
3585 error "cannot read from hard link (2.1)"
3586 echo a >> $tmpfile || error "cannot write to hard link (2)"
3588 cmp -bl $testfile2 $tmpfile ||
3589 error "cannot read from hard link (2.2)"
3592 if [ $name_enc -eq 1 ]; then
3593 # check we are limited in the number of hard links
3594 # we can create for encrypted files, to what can fit into LinkEA
3595 for i in $(seq 1 160); do
3596 ln $testfile2 ${testfile}_$i || break
3598 [ $i -lt 160 ] || error "hard link $i should fail"
3602 mrename $testfile2 $tmpfile &&
3603 error "rename from encrypted to unencrypted dir should fail"
3605 dd if=/dev/urandom of=$tmpfile bs=512K count=1
3607 dd if=/dev/urandom of=$testfile bs=512K count=1
3608 mkdir $DIR/$tdir/mydir
3610 ln -s $testfile ${testfile}.sym ||
3611 error "symlink from within encrypted dir should succeed"
3613 cmp -bl $testfile ${testfile}.sym ||
3614 error "cannot read from sym link (1.1)"
3615 echo a >> ${testfile}.sym || error "cannot write to sym link (1)"
3617 cmp -bl $testfile ${testfile}.sym ||
3618 error "cannot read from sym link (1.2)"
3619 [ $(stat -c %s ${testfile}.sym) -eq ${#testfile} ] ||
3620 error "wrong symlink size (1)"
3622 ln -s $tmpfile ${testfile}.sl ||
3623 error "symlink from encrypted to unencrypted dir should succeed"
3625 cmp -bl $tmpfile ${testfile}.sl ||
3626 error "cannot read from sym link (2.1)"
3627 echo a >> ${testfile}.sl || error "cannot write to sym link (2)"
3629 cmp -bl $tmpfile ${testfile}.sl ||
3630 error "cannot read from sym link (2.2)"
3631 [ $(stat -c %s ${testfile}.sl) -eq ${#tmpfile} ] ||
3632 error "wrong symlink size (2)"
3633 rm -f ${testfile}.sl
3635 sync ; echo 3 > /proc/sys/vm/drop_caches
3637 # remount without dummy encryption key
3638 remount_client_normally
3640 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d)
3641 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -type f)
3642 scrambledlink=$(find $DIR/$tdir/ -maxdepth 1 -type l)
3643 ln $scrambledfile $scrambleddir/linkfile &&
3644 error "ln linkfile should have failed"
3645 mrename $scrambledfile $DIR/onefile2 &&
3646 error "mrename from $scrambledfile should have failed"
3648 mrename $DIR/onefile $scrambleddir/otherfile &&
3649 error "mrename to $scrambleddir should have failed"
3650 readlink $scrambledlink ||
3651 error "link should be read without key"
3652 [ $(stat -c %s $scrambledlink) -eq \
3653 $(expr length "$(readlink $scrambledlink)") ] ||
3654 error "wrong symlink size without key"
3655 if [ $name_enc -eq 1 ]; then
3656 readlink -e $scrambledlink &&
3657 error "link should not point to anywhere useful"
3659 ln -s $scrambledfile ${scrambledfile}.sym &&
3660 error "symlink without key should fail (1)"
3661 ln -s $tmpfile ${scrambledfile}.sl &&
3662 error "symlink without key should fail (2)"
3664 rm -f $tmpfile $DIR/onefile
3666 run_test 47 "encrypted file access semantics: rename/link"
3669 local save="$TMP/$TESTSUITE-$TESTNAME.parameters"
3670 local testfile=$DIR/$tdir/$tfile
3671 local tmpfile=$TMP/111
3672 local tmpfile2=$TMP/abc
3673 local pagesz=$(getconf PAGESIZE)
3678 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3679 skip "client encryption not supported"
3681 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3682 skip "need dummy encryption support"
3684 stack_trap cleanup_for_enc_tests EXIT
3687 # create file, 4 x PAGE_SIZE long
3688 tr '\0' '1' < /dev/zero |
3689 dd of=$tmpfile bs=1 count=4x$pagesz conv=fsync
3690 $LFS setstripe -c1 -i0 $testfile
3691 cp $tmpfile $testfile
3692 echo "abc" > $tmpfile2
3694 # decrease size: truncate to PAGE_SIZE
3695 $TRUNCATE $tmpfile $pagesz
3696 $TRUNCATE $testfile $pagesz
3697 cancel_lru_locks osc ; cancel_lru_locks mdc
3698 cmp -bl $tmpfile $testfile ||
3699 error "file $testfile is corrupted (1)"
3701 # increase size: truncate to 2 x PAGE_SIZE
3703 $TRUNCATE $tmpfile $sz
3704 $TRUNCATE $testfile $sz
3705 cancel_lru_locks osc ; cancel_lru_locks mdc
3706 cmp -bl $tmpfile $testfile ||
3707 error "file $testfile is corrupted (2)"
3710 seek=$((pagesz+100))
3711 dd if=$tmpfile2 of=$tmpfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3713 dd if=$tmpfile2 of=$testfile bs=4 count=1 seek=$seek oflag=seek_bytes \
3715 cancel_lru_locks osc ; cancel_lru_locks mdc
3716 cmp -bl $tmpfile $testfile ||
3717 error "file $testfile is corrupted (3)"
3719 # truncate to PAGE_SIZE / 2
3721 $TRUNCATE $tmpfile $sz
3722 $TRUNCATE $testfile $sz
3723 cancel_lru_locks osc ; cancel_lru_locks mdc
3724 cmp -bl $tmpfile $testfile ||
3725 error "file $testfile is corrupted (4)"
3727 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16
3729 $TRUNCATE $tmpfile $sz
3730 $TRUNCATE $testfile $sz
3731 cancel_lru_locks osc ; cancel_lru_locks mdc
3732 cmp -bl $tmpfile $testfile ||
3733 error "file $testfile is corrupted (5)"
3735 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16
3737 $TRUNCATE $tmpfile $sz
3738 $TRUNCATE $testfile $sz
3739 cancel_lru_locks osc ; cancel_lru_locks mdc
3740 cmp -bl $tmpfile $testfile ||
3741 error "file $testfile is corrupted (6)"
3743 # truncate to a larger, non-multiple of PAGE_SIZE, in a different page
3744 sz=$((sz+pagesz+30))
3745 $TRUNCATE $tmpfile $sz
3746 $TRUNCATE $testfile $sz
3747 cancel_lru_locks osc ; cancel_lru_locks mdc
3748 cmp -bl $tmpfile $testfile ||
3749 error "file $testfile is corrupted (7)"
3751 sync ; echo 3 > /proc/sys/vm/drop_caches
3753 # remount without dummy encryption key
3754 remount_client_normally
3756 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -type f)
3757 $TRUNCATE $scrambledfile 0 &&
3758 error "truncate $scrambledfile should have failed without key"
3760 rm -f $tmpfile $tmpfile2
3762 run_test 48a "encrypted file access semantics: truncate"
3764 cleanup_for_enc_tests_othercli() {
3767 # remount othercli normally
3768 zconf_umount $othercli $MOUNT ||
3769 error "umount $othercli $MOUNT failed"
3770 zconf_mount $othercli $MOUNT ||
3771 error "remount $othercli $MOUNT failed"
3777 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3778 skip "client encryption not supported"
3780 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3781 skip "need dummy encryption support"
3783 [ "$num_clients" -ge 2 ] || skip "Need at least 2 clients"
3785 if [ "$HOSTNAME" == ${clients_arr[0]} ]; then
3786 othercli=${clients_arr[1]}
3788 othercli=${clients_arr[0]}
3791 stack_trap cleanup_for_enc_tests EXIT
3792 stack_trap "cleanup_for_enc_tests_othercli $othercli" EXIT
3794 zconf_umount $othercli $MOUNT ||
3795 error "umount $othercli $MOUNT failed"
3797 cp /bin/sleep $DIR/$tdir/
3798 cancel_lru_locks osc ; cancel_lru_locks mdc
3799 $DIR/$tdir/sleep 30 &
3800 # mount and IOs must be done in the same shell session, otherwise
3801 # encryption key in session keyring is missing
3802 do_node $othercli "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
3803 $MGSNID:/$FSNAME $MOUNT && \
3804 $TRUNCATE $DIR/$tdir/sleep 7"
3805 wait || error "wait error"
3806 cmp --silent /bin/sleep $DIR/$tdir/sleep ||
3807 error "/bin/sleep and $DIR/$tdir/sleep differ"
3809 run_test 48b "encrypted file: concurrent truncate"
3815 $LCTL set_param debug=+info
3820 [ $? -eq 0 ] || error "$cmd failed"
3822 if [ -z "$MATCHING_STRING" ]; then
3823 $LCTL dk | grep -E "get xattr 'encryption.c'|get xattrs"
3825 $LCTL dk | grep -E "$MATCHING_STRING"
3827 [ $? -ne 0 ] || error "get xattr event was triggered"
3831 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3832 skip "client encryption not supported"
3834 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3835 skip "need dummy encryption support"
3837 stack_trap cleanup_for_enc_tests EXIT
3840 local dirname=$DIR/$tdir/subdir
3844 trace_cmd stat $dirname
3845 trace_cmd echo a > $dirname/f1
3846 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3847 trace_cmd stat $dirname/f1
3848 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3849 trace_cmd cat $dirname/f1
3850 dd if=/dev/zero of=$dirname/f1 bs=1M count=10 conv=fsync
3851 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3852 MATCHING_STRING="get xattr 'encryption.c'" \
3853 trace_cmd $TRUNCATE $dirname/f1 10240
3854 trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
3855 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3856 trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
3858 if [[ $MDSCOUNT -gt 1 ]]; then
3859 trace_cmd $LFS setdirstripe -i 1 $dirname/d2
3860 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3861 trace_cmd $LFS migrate -m 0 $dirname/d2
3862 echo b > $dirname/d2/subf
3863 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3864 if (( "$MDS1_VERSION" > $(version_code 2.14.54.54) )); then
3865 # migrate a non-empty encrypted dir
3866 trace_cmd $LFS migrate -m 1 $dirname/d2
3867 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3868 [ -f $dirname/d2/subf ] || error "migrate failed (1)"
3869 [ $(cat $dirname/d2/subf) == "b" ] ||
3870 error "migrate failed (2)"
3873 $LFS setdirstripe -i 1 -c 1 $dirname/d3
3874 dirname=$dirname/d3/subdir
3876 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3877 trace_cmd stat $dirname
3878 trace_cmd echo c > $dirname/f1
3879 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3880 trace_cmd stat $dirname/f1
3881 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3882 trace_cmd cat $dirname/f1
3883 dd if=/dev/zero of=$dirname/f1 bs=1M count=10 conv=fsync
3884 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3885 MATCHING_STRING="get xattr 'encryption.c'" \
3886 trace_cmd $TRUNCATE $dirname/f1 10240
3887 trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
3888 sync ; sync ; echo 3 > /proc/sys/vm/drop_caches
3889 trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
3891 skip_noexit "2nd part needs >= 2 MDTs"
3894 run_test 49 "Avoid getxattr for encryption context"
3897 local testfile=$DIR/$tdir/$tfile
3898 local tmpfile=$TMP/abc
3899 local pagesz=$(getconf PAGESIZE)
3902 $LCTL get_param mdc.*.import | grep -q client_encryption ||
3903 skip "client encryption not supported"
3905 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
3906 skip "need dummy encryption support"
3908 stack_trap cleanup_for_enc_tests EXIT
3911 # write small file, data on MDT only
3912 tr '\0' '1' < /dev/zero |
3913 dd of=$tmpfile bs=1 count=5000 conv=fsync
3914 $LFS setstripe -E 1M -L mdt -E EOF $testfile
3915 cp $tmpfile $testfile
3917 # check that in-memory representation of file is correct
3918 cmp -bl $tmpfile $testfile ||
3919 error "file $testfile is corrupted in memory"
3921 cancel_lru_locks osc ; cancel_lru_locks mdc
3923 # check that file read from server is correct
3924 cmp -bl $tmpfile $testfile ||
3925 error "file $testfile is corrupted on server"
3927 # decrease size: truncate to PAGE_SIZE
3928 $TRUNCATE $tmpfile $pagesz
3929 $TRUNCATE $testfile $pagesz
3930 cancel_lru_locks osc ; cancel_lru_locks mdc
3931 cmp -bl $tmpfile $testfile ||
3932 error "file $testfile is corrupted (1)"
3934 # increase size: truncate to 2 x PAGE_SIZE
3936 $TRUNCATE $tmpfile $sz
3937 $TRUNCATE $testfile $sz
3938 cancel_lru_locks osc ; cancel_lru_locks mdc
3939 cmp -bl $tmpfile $testfile ||
3940 error "file $testfile is corrupted (2)"
3942 # truncate to PAGE_SIZE / 2
3944 $TRUNCATE $tmpfile $sz
3945 $TRUNCATE $testfile $sz
3946 cancel_lru_locks osc ; cancel_lru_locks mdc
3947 cmp -bl $tmpfile $testfile ||
3948 error "file $testfile is corrupted (3)"
3950 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16
3952 $TRUNCATE $tmpfile $sz
3953 $TRUNCATE $testfile $sz
3954 cancel_lru_locks osc ; cancel_lru_locks mdc
3955 cmp -bl $tmpfile $testfile ||
3956 error "file $testfile is corrupted (4)"
3958 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16
3960 $TRUNCATE $tmpfile $sz
3961 $TRUNCATE $testfile $sz
3962 cancel_lru_locks osc ; cancel_lru_locks mdc
3963 cmp -bl $tmpfile $testfile ||
3964 error "file $testfile is corrupted (5)"
3966 # truncate to a larger, non-multiple of PAGE_SIZE, in a different page
3967 sz=$((sz+pagesz+30))
3968 $TRUNCATE $tmpfile $sz
3969 $TRUNCATE $testfile $sz
3970 cancel_lru_locks osc ; cancel_lru_locks mdc
3971 cmp -bl $tmpfile $testfile ||
3972 error "file $testfile is corrupted (6)"
3975 cancel_lru_locks osc ; cancel_lru_locks mdc
3977 # write hole in file, data spread on MDT and OST
3978 tr '\0' '2' < /dev/zero |
3979 dd of=$tmpfile bs=1 count=1539 seek=1539074 conv=fsync,notrunc
3980 $LFS setstripe -E 1M -L mdt -E EOF $testfile
3981 cp --sparse=always $tmpfile $testfile
3983 # check that in-memory representation of file is correct
3984 cmp -bl $tmpfile $testfile ||
3985 error "file $testfile is corrupted in memory"
3987 cancel_lru_locks osc ; cancel_lru_locks mdc
3989 # check that file read from server is correct
3990 cmp -bl $tmpfile $testfile ||
3991 error "file $testfile is corrupted on server"
3993 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16,
3994 # inside OST part of data
3995 sz=$((1024*1024+13))
3996 $TRUNCATE $tmpfile $sz
3997 $TRUNCATE $testfile $sz
3998 cancel_lru_locks osc ; cancel_lru_locks mdc
3999 cmp -bl $tmpfile $testfile ||
4000 error "file $testfile is corrupted (7)"
4002 # truncate to a smaller, non-multiple of PAGE_SIZE, non-multiple of 16,
4003 # inside MDT part of data
4005 $TRUNCATE $tmpfile $sz
4006 $TRUNCATE $testfile $sz
4007 cancel_lru_locks osc ; cancel_lru_locks mdc
4008 cmp -bl $tmpfile $testfile ||
4009 error "file $testfile is corrupted (8)"
4011 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16,
4012 # inside MDT part of data
4013 sz=$((1024*1024-13))
4014 $TRUNCATE $tmpfile $sz
4015 $TRUNCATE $testfile $sz
4016 cancel_lru_locks osc ; cancel_lru_locks mdc
4017 cmp -bl $tmpfile $testfile ||
4018 error "file $testfile is corrupted (9)"
4020 # truncate to a larger, non-multiple of PAGE_SIZE, non-multiple of 16,
4021 # inside OST part of data
4023 $TRUNCATE $tmpfile $sz
4024 $TRUNCATE $testfile $sz
4025 cancel_lru_locks osc ; cancel_lru_locks mdc
4026 cmp -bl $tmpfile $testfile ||
4027 error "file $testfile is corrupted (10)"
4031 run_test 50 "DoM encrypted file"
4034 [ "$MDS1_VERSION" -gt $(version_code 2.13.53) ] ||
4035 skip "Need MDS version at least 2.13.53"
4037 mkdir $DIR/$tdir || error "mkdir $tdir"
4039 touch $DIR/$tdir/$tfile || error "touch $tfile"
4040 cp $(which chown) $DIR/$tdir || error "cp chown"
4041 $RUNAS_CMD -u $ID0 $DIR/$tdir/chown $ID0 $DIR/$tdir/$tfile &&
4042 error "chown $tfile should fail"
4043 setcap 'CAP_CHOWN=ep' $DIR/$tdir/chown || error "setcap CAP_CHOWN"
4044 $RUNAS_CMD -u $ID0 $DIR/$tdir/chown $ID0 $DIR/$tdir/$tfile ||
4045 error "chown $tfile"
4046 rm $DIR/$tdir/$tfile || error "rm $tfile"
4048 touch $DIR/$tdir/$tfile || error "touch $tfile"
4049 cp $(which touch) $DIR/$tdir || error "cp touch"
4050 $RUNAS_CMD -u $ID0 $DIR/$tdir/touch $DIR/$tdir/$tfile &&
4051 error "touch should fail"
4052 setcap 'CAP_FOWNER=ep' $DIR/$tdir/touch || error "setcap CAP_FOWNER"
4053 $RUNAS_CMD -u $ID0 $DIR/$tdir/touch $DIR/$tdir/$tfile ||
4054 error "touch $tfile"
4055 rm $DIR/$tdir/$tfile || error "rm $tfile"
4058 for cap in "CAP_DAC_OVERRIDE" "CAP_DAC_READ_SEARCH"; do
4059 touch $DIR/$tdir/$tfile || error "touch $tfile"
4060 chmod 600 $DIR/$tdir/$tfile || error "chmod $tfile"
4061 cp $(which cat) $DIR/$tdir || error "cp cat"
4062 $RUNAS_CMD -u $ID0 $DIR/$tdir/cat $DIR/$tdir/$tfile &&
4063 error "cat should fail"
4064 setcap $cap=ep $DIR/$tdir/cat || error "setcap $cap"
4065 $RUNAS_CMD -u $ID0 $DIR/$tdir/cat $DIR/$tdir/$tfile ||
4067 rm $DIR/$tdir/$tfile || error "rm $tfile"
4070 run_test 51 "FS capabilities ==============="
4073 local testfile=$DIR/$tdir/$tfile
4074 local tmpfile=$TMP/$tfile
4075 local mirror1=$TMP/$tfile.mirror1
4076 local mirror2=$TMP/$tfile.mirror2
4078 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4079 skip "client encryption not supported"
4081 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4082 skip "need dummy encryption support"
4084 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4086 stack_trap "cleanup_for_enc_tests $tmpfile $mirror1 $mirror2" EXIT
4089 dd if=/dev/urandom of=$tmpfile bs=5000 count=1 conv=fsync
4091 $LFS mirror create -N -i0 -N -i1 $testfile ||
4092 error "could not create mirror"
4094 dd if=$tmpfile of=$testfile bs=5000 count=1 conv=fsync ||
4095 error "could not write to $testfile"
4097 $LFS mirror resync $testfile ||
4098 error "could not resync mirror"
4100 $LFS mirror verify -v $testfile ||
4101 error "verify mirror failed"
4103 $LFS mirror read -N 1 -o $mirror1 $testfile ||
4104 error "could not read from mirror 1"
4106 cmp -bl $tmpfile $mirror1 ||
4107 error "mirror 1 is corrupted"
4109 $LFS mirror read -N 2 -o $mirror2 $testfile ||
4110 error "could not read from mirror 2"
4112 cmp -bl $tmpfile $mirror2 ||
4113 error "mirror 2 is corrupted"
4115 tr '\0' '2' < /dev/zero |
4116 dd of=$tmpfile bs=1 count=9000 conv=fsync
4118 $LFS mirror write -N 1 -i $tmpfile $testfile ||
4119 error "could not write to mirror 1"
4121 $LFS mirror verify -v $testfile &&
4122 error "mirrors should be different"
4124 rm -f $testfile $mirror1 $mirror2
4126 $LFS setstripe -c1 -i0 $testfile
4127 dd if=$tmpfile of=$testfile bs=9000 count=1 conv=fsync ||
4128 error "write to $testfile failed"
4129 $LFS getstripe $testfile
4132 $LFS migrate -i1 $testfile ||
4133 error "migrate $testfile failed"
4134 $LFS getstripe $testfile
4135 stripe=$($LFS getstripe -i $testfile)
4136 [ $stripe -eq 1 ] || error "migrate file $testfile failed"
4139 cmp -bl $tmpfile $testfile ||
4140 error "migrated file is corrupted"
4142 $LFS mirror extend -N -i0 $testfile ||
4143 error "mirror extend $testfile failed"
4144 $LFS getstripe $testfile
4145 mirror_count=$($LFS getstripe -N $testfile)
4146 [ $mirror_count -eq 2 ] ||
4147 error "mirror extend file $testfile failed (1)"
4148 stripe=$($LFS getstripe --mirror-id=1 -i $testfile)
4149 [ $stripe -eq 1 ] || error "mirror extend file $testfile failed (2)"
4150 stripe=$($LFS getstripe --mirror-id=2 -i $testfile)
4151 [ $stripe -eq 0 ] || error "mirror extend file $testfile failed (3)"
4154 $LFS mirror verify -v $testfile ||
4155 error "mirror verify failed"
4156 $LFS mirror read -N 1 -o $mirror1 $testfile ||
4157 error "read from mirror 1 failed"
4158 cmp -bl $tmpfile $mirror1 ||
4159 error "corruption of mirror 1"
4160 $LFS mirror read -N 2 -o $mirror2 $testfile ||
4161 error "read from mirror 2 failed"
4162 cmp -bl $tmpfile $mirror2 ||
4163 error "corruption of mirror 2"
4165 $LFS mirror split --mirror-id 1 -f ${testfile}.mirror $testfile &&
4166 error "mirror split -f should fail"
4168 $LFS mirror split --mirror-id 1 $testfile &&
4169 error "mirror split without -d should fail"
4171 $LFS mirror split --mirror-id 1 -d $testfile ||
4172 error "mirror split failed"
4173 $LFS getstripe $testfile
4174 mirror_count=$($LFS getstripe -N $testfile)
4175 [ $mirror_count -eq 1 ] ||
4176 error "mirror split file $testfile failed (1)"
4177 stripe=$($LFS getstripe --mirror-id=1 -i $testfile)
4178 [ -z "$stripe" ] || error "mirror extend file $testfile failed (2)"
4179 stripe=$($LFS getstripe --mirror-id=2 -i $testfile)
4180 [ $stripe -eq 0 ] || error "mirror extend file $testfile failed (3)"
4183 cmp -bl $tmpfile $testfile ||
4184 error "extended/split file is corrupted"
4186 run_test 52 "Mirrored encrypted file"
4189 local testfile=$DIR/$tdir/$tfile
4190 local testfile2=$DIR2/$tdir/$tfile
4191 local tmpfile=$TMP/$tfile.tmp
4192 local resfile=$TMP/$tfile.res
4196 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4197 skip "client encryption not supported"
4199 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4200 skip "need dummy encryption support"
4202 pagesz=$(getconf PAGESIZE)
4203 [[ $pagesz == 65536 ]] || skip "Need 64K PAGE_SIZE client"
4205 do_node $mds1_HOST \
4206 "mount.lustre --help |& grep -q 'test_dummy_encryption:'" ||
4207 skip "need dummy encryption support on MDS client mount"
4209 # this test is probably useless now, but may turn out to be useful when
4210 # Lustre supports servers with PAGE_SIZE != 4KB
4211 pagesz=$(do_node $mds1_HOST getconf PAGESIZE)
4212 [[ $pagesz == 4096 ]] || skip "Need 4K PAGE_SIZE MDS client"
4214 stack_trap cleanup_for_enc_tests EXIT
4215 stack_trap "zconf_umount $mds1_HOST $MOUNT2" EXIT
4218 $LFS setstripe -c1 -i0 $testfile
4220 # write from 1st client
4221 cat /dev/urandom | tr -dc 'a-zA-Z0-9' |
4222 dd of=$tmpfile bs=$((pagesz+3)) count=2 conv=fsync
4223 dd if=$tmpfile of=$testfile bs=$((pagesz+3)) count=2 conv=fsync ||
4224 error "could not write to $testfile (1)"
4226 # read from 2nd client
4227 # mount and IOs must be done in the same shell session, otherwise
4228 # encryption key in session keyring is missing
4229 do_node $mds1_HOST "mkdir -p $MOUNT2"
4230 do_node $mds1_HOST \
4231 "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4232 $MGSNID:/$FSNAME $MOUNT2 && \
4233 dd if=$testfile2 of=$resfile bs=$((pagesz+3)) count=2" ||
4234 error "could not read from $testfile2 (1)"
4237 filemd5=$(do_node $mds1_HOST md5sum $resfile | awk '{print $1}')
4238 [ $filemd5 = $(md5sum $tmpfile | awk '{print $1}') ] ||
4239 error "file is corrupted (1)"
4240 do_node $mds1_HOST rm -f $resfile
4243 # truncate from 2nd client
4244 $TRUNCATE $tmpfile $((pagesz+3))
4245 zconf_umount $mds1_HOST $MOUNT2 ||
4246 error "umount $mds1_HOST $MOUNT2 failed (1)"
4247 do_node $mds1_HOST "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4248 $MGSNID:/$FSNAME $MOUNT2 && \
4249 $TRUNCATE $testfile2 $((pagesz+3))" ||
4250 error "could not truncate $testfile2 (1)"
4253 cmp -bl $tmpfile $testfile ||
4254 error "file is corrupted (2)"
4255 rm -f $tmpfile $testfile
4257 zconf_umount $mds1_HOST $MOUNT2 ||
4258 error "umount $mds1_HOST $MOUNT2 failed (2)"
4261 do_node $mds1_HOST \
4262 dd if=/dev/urandom of=$tmpfile bs=$((pagesz+3)) count=2 conv=fsync
4263 # write from 2nd client
4264 do_node $mds1_HOST \
4265 "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4266 $MGSNID:/$FSNAME $MOUNT2 && \
4267 dd if=$tmpfile of=$testfile2 bs=$((pagesz+3)) count=2 conv=fsync" ||
4268 error "could not write to $testfile2 (2)"
4270 # read from 1st client
4271 dd if=$testfile of=$resfile bs=$((pagesz+3)) count=2 ||
4272 error "could not read from $testfile (2)"
4275 filemd5=$(do_node $mds1_HOST md5sum -b $tmpfile | awk '{print $1}')
4276 [ $filemd5 = $(md5sum -b $resfile | awk '{print $1}') ] ||
4277 error "file is corrupted (3)"
4281 # truncate from 1st client
4282 do_node $mds1_HOST "$TRUNCATE $tmpfile $((pagesz+3))"
4283 $TRUNCATE $testfile $((pagesz+3)) ||
4284 error "could not truncate $testfile (2)"
4287 zconf_umount $mds1_HOST $MOUNT2 ||
4288 error "umount $mds1_HOST $MOUNT2 failed (3)"
4289 do_node $mds1_HOST "$MOUNT_CMD -o ${MOUNT_OPTS},test_dummy_encryption \
4290 $MGSNID:/$FSNAME $MOUNT2 && \
4291 cmp -bl $tmpfile $testfile2" ||
4292 error "file is corrupted (4)"
4294 do_node $mds1_HOST rm -f $tmpfile
4297 run_test 53 "Mixed PAGE_SIZE clients"
4300 local testdir=$DIR/$tdir/$ID0
4301 local testdir2=$DIR2/$tdir/$ID0
4302 local testfile=$testdir/$tfile
4303 local testfile2=$testdir/${tfile}withveryverylongnametoexercisecode
4304 local tmpfile=$TMP/${tfile}.tmp
4305 local resfile=$TMP/${tfile}.res
4310 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4311 skip "client encryption not supported"
4313 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4314 skip "need dummy encryption support"
4316 which fscrypt || skip "This test needs fscrypt userspace tool"
4318 fscrypt setup --force --verbose || error "fscrypt global setup failed"
4319 sed -i 's/\(.*\)policy_version\(.*\):\(.*\)\"[0-9]*\"\(.*\)/\1policy_version\2:\3"2"\4/' \
4321 fscrypt setup --verbose $MOUNT || error "fscrypt setup $MOUNT failed"
4323 chown -R $ID0:$ID0 $testdir
4325 echo -e 'mypass\nmypass' | su - $USER0 -c "fscrypt encrypt --verbose \
4326 --source=custom_passphrase --name=protector $testdir" ||
4327 error "fscrypt encrypt failed"
4329 echo -e 'mypass\nmypass' | su - $USER0 -c "fscrypt encrypt --verbose \
4330 --source=custom_passphrase --name=protector2 $testdir" &&
4331 error "second fscrypt encrypt should have failed"
4333 mkdir -p ${testdir}2 || error "mkdir ${testdir}2 failed"
4334 touch ${testdir}2/f || error "mkdir ${testdir}2/f failed"
4337 echo -e 'mypass\nmypass' | fscrypt encrypt --verbose \
4338 --source=custom_passphrase --name=protector3 ${testdir}2 &&
4339 error "fscrypt encrypt on non-empty dir should have failed"
4341 $RUNAS dd if=/dev/urandom of=$testfile bs=127 count=1 conv=fsync ||
4342 error "write to encrypted file $testfile failed"
4343 cp $testfile $tmpfile
4344 $RUNAS dd if=/dev/urandom of=$testfile2 bs=127 count=1 conv=fsync ||
4345 error "write to encrypted file $testfile2 failed"
4346 $RUNAS mkdir $testdir/subdir || error "mkdir subdir failed"
4347 $RUNAS touch $testdir/subdir/subfile || error "mkdir subdir failed"
4349 $RUNAS fscrypt lock --verbose $testdir ||
4350 error "fscrypt lock $testdir failed (1)"
4352 $RUNAS ls -R $testdir || error "ls -R $testdir failed"
4353 local filecount=$($RUNAS find $testdir -type f | wc -l)
4354 [ $filecount -eq 3 ] || error "found $filecount files"
4356 # check enable_filename_encryption default value
4357 $LCTL get_param mdc.*.connect_flags | grep -q name_encryption &&
4358 nameenc=$(lctl get_param -n llite.*.enable_filename_encryption |
4360 if [ -n "$nameenc" ]; then
4361 [ $nameenc -eq 0 ] ||
4362 error "enable_filename_encryption should be 0 by default"
4364 # $testfile and $testfile2 should exist because
4365 # names are not encrypted
4367 error "$testfile should exist because name not encrypted"
4368 [ -f $testfile2 ] ||
4369 error "$testfile2 should exist because name not encrypted"
4372 scrambledfiles=( $(find $testdir/ -maxdepth 1 -type f) )
4373 $RUNAS hexdump -C ${scrambledfiles[0]} &&
4374 error "reading ${scrambledfiles[0]} should fail without key"
4376 $RUNAS touch ${testfile}.nokey &&
4377 error "touch ${testfile}.nokey should have failed without key"
4379 echo mypass | $RUNAS fscrypt unlock --verbose $testdir ||
4380 error "fscrypt unlock $testdir failed (1)"
4382 $RUNAS cat $testfile > $resfile ||
4383 error "reading $testfile failed"
4385 cmp -bl $tmpfile $resfile || error "file read differs from file written"
4387 $RUNAS fscrypt lock --verbose $testdir ||
4388 error "fscrypt lock $testdir failed (2)"
4390 $RUNAS hexdump -C ${scrambledfiles[1]} &&
4391 error "reading ${scrambledfiles[1]} should fail without key"
4393 # server local client incompatible with SSK keys installed
4394 if [ "$SHARED_KEY" != true ]; then
4396 stack_trap umount_mds_client EXIT
4397 do_facet $SINGLEMDS touch $DIR2/$tdir/newfile
4398 mdsscrambledfile=$(do_facet $SINGLEMDS find $testdir2/ \
4399 -maxdepth 1 -type f | head -n1)
4400 [ -n "$mdsscrambledfile" ] || error "could not find file"
4401 do_facet $SINGLEMDS cat "$mdsscrambledfile" &&
4402 error "reading $mdsscrambledfile should fail on MDS"
4403 do_facet $SINGLEMDS "echo aaa >> \"$mdsscrambledfile\"" &&
4404 error "writing $mdsscrambledfile should fail on MDS"
4405 do_facet $SINGLEMDS $MULTIOP $testdir2/fileA m &&
4406 error "creating $testdir2/fileA should fail on MDS"
4407 do_facet $SINGLEMDS mkdir $testdir2/dirA &&
4408 error "mkdir $testdir2/dirA should fail on MDS"
4409 do_facet $SINGLEMDS ln -s $DIR2/$tdir/newfile $testdir2/sl1 &&
4410 error "ln -s $testdir2/sl1 should fail on MDS"
4411 do_facet $SINGLEMDS ln $DIR2/$tdir/newfile $testdir2/hl1 &&
4412 error "ln $testdir2/hl1 should fail on MDS"
4413 do_facet $SINGLEMDS mv "$mdsscrambledfile" $testdir2/fB &&
4414 error "mv $mdsscrambledfile should fail on MDS"
4415 do_facet $SINGLEMDS mrename "$mdsscrambledfile" $testdir2/fB &&
4416 error "mrename $mdsscrambledfile should fail on MDS"
4417 do_facet $SINGLEMDS rm -f $DIR2/$tdir/newfile
4420 echo mypass | $RUNAS fscrypt unlock --verbose $testdir ||
4421 error "fscrypt unlock $testdir failed (2)"
4424 $RUNAS fscrypt lock --verbose $testdir ||
4425 error "fscrypt lock $testdir failed (3)"
4427 rm -rf $tmpfile $resfile $testdir ${testdir}2 $MOUNT/.fscrypt
4429 # remount client with subdirectory mount
4430 umount_client $MOUNT || error "umount $MOUNT failed (1)"
4431 export FILESET=/$tdir
4432 mount_client $MOUNT ${MOUNT_OPTS} || error "remount failed (1)"
4435 # setup encryption from inside this subdir mount
4436 # the .fscrypt directory is going to be created at the real fs root
4437 fscrypt setup --verbose $MOUNT ||
4438 error "fscrypt setup $MOUNT failed (2)"
4439 testdir=$MOUNT/vault
4441 chown -R $ID0:$ID0 $testdir
4442 fid1=$(path2fid $MOUNT/.fscrypt)
4443 echo "With FILESET $tdir, .fscrypt FID is $fid1"
4445 # enable name encryption
4446 if [ -n "$nameenc" ]; then
4447 do_facet mgs $LCTL set_param -P \
4448 llite.*.enable_filename_encryption=1
4450 error "set_param -P \
4451 llite.*.enable_filename_encryption failed"
4453 wait_update_facet --verbose client \
4454 "$LCTL get_param -n llite.*.enable_filename_encryption \
4456 error "enable_filename_encryption not set on client"
4459 # encrypt 'vault' dir inside the subdir mount
4460 echo -e 'mypass\nmypass' | su - $USER0 -c "fscrypt encrypt --verbose \
4461 --source=custom_passphrase --name=protector $testdir" ||
4462 error "fscrypt encrypt failed"
4466 $RUNAS cp $tmpfile $testdir/encfile
4468 $RUNAS fscrypt lock --verbose $testdir ||
4469 error "fscrypt lock $testdir failed (4)"
4471 # encfile should actually have its name encrypted
4472 if [ -n "$nameenc" ]; then
4473 [ -f $testdir/encfile ] &&
4474 error "encfile name should be encrypted"
4476 filecount=$(find $testdir -type f | wc -l)
4477 [ $filecount -eq 1 ] || error "found $filecount files instead of 1"
4479 # remount client with encrypted dir as subdirectory mount
4480 umount_client $MOUNT || error "umount $MOUNT failed (2)"
4481 export FILESET=/$tdir/vault
4482 mount_client $MOUNT ${MOUNT_OPTS} || error "remount failed (2)"
4485 fid2=$(path2fid $MOUNT/.fscrypt)
4486 echo "With FILESET $tdir/vault, .fscrypt FID is $fid2"
4487 [ "$fid1" == "$fid2" ] || error "fid1 $fid1 != fid2 $fid2 (1)"
4489 # all content seen by this mount is encrypted, but .fscrypt is virtually
4490 # presented, letting us call fscrypt lock/unlock
4491 echo mypass | $RUNAS fscrypt unlock --verbose $MOUNT ||
4492 error "fscrypt unlock $MOUNT failed (3)"
4495 [ $(cat $MOUNT/encfile) == "abc" ] || error "cat encfile failed"
4497 # remount client without subdir mount
4498 umount_client $MOUNT || error "umount $MOUNT failed (3)"
4499 mount_client $MOUNT ${MOUNT_OPTS} || error "remount failed (3)"
4501 fid2=$(path2fid $MOUNT/.fscrypt)
4502 echo "Without FILESET, .fscrypt FID is $fid2"
4503 [ "$fid1" == "$fid2" ] || error "fid1 $fid1 != fid2 $fid2 (2)"
4505 # because .fscrypt was actually created at the real root of the fs,
4506 # we can call fscrypt lock/unlock on the encrypted dir
4507 echo mypass | $RUNAS fscrypt unlock --verbose $DIR/$tdir/vault ||
4508 error "fscrypt unlock $$DIR/$tdir/vault failed (4)"
4511 echo c >> $DIR/$tdir/vault/encfile || error "write to encfile failed"
4513 rm -rf $DIR/$tdir/vault/*
4514 $RUNAS fscrypt lock --verbose $DIR/$tdir/vault ||
4515 error "fscrypt lock $DIR/$tdir/vault failed (5)"
4517 # disable name encryption
4518 if [ -n "$nameenc" ]; then
4519 do_facet mgs $LCTL set_param -P \
4520 llite.*.enable_filename_encryption=0
4522 error "set_param -P \
4523 llite.*.enable_filename_encryption failed"
4525 wait_update_facet --verbose client \
4526 "$LCTL get_param -n llite.*.enable_filename_encryption \
4528 error "enable_filename_encryption not set back to default"
4531 rm -rf $tmpfile $MOUNT/.fscrypt
4533 run_test 54 "Encryption policies with fscrypt"
4537 if is_mounted $MOUNT; then
4538 umount_client $MOUNT || error "umount $MOUNT failed"
4541 do_facet mgs $LCTL nodemap_del c0
4542 do_facet mgs $LCTL nodemap_modify --name default \
4543 --property admin --value 0
4544 do_facet mgs $LCTL nodemap_modify --name default \
4545 --property trusted --value 0
4546 wait_nm_sync default admin_nodemap
4547 wait_nm_sync default trusted_nodemap
4549 do_facet mgs $LCTL nodemap_activate 0
4550 wait_nm_sync active 0
4552 if $SHARED_KEY; then
4553 export SK_UNIQUE_NM=false
4557 mount_client $MOUNT ${MOUNT_OPTS} || error "remount failed"
4558 if [ "$MOUNT_2" ]; then
4559 mount_client $MOUNT2 ${MOUNT_OPTS} || error "remount failed"
4564 (( $MDS1_VERSION > $(version_code 2.12.6.2) )) ||
4565 skip "Need MDS version at least 2.12.6.3"
4570 mkdir -p $DIR/$tdir/$USER0/testdir_groups
4571 chown root:$ID0 $DIR/$tdir/$USER0
4572 chmod 770 $DIR/$tdir/$USER0
4573 chmod g+s $DIR/$tdir/$USER0
4574 chown $ID0:$ID0 $DIR/$tdir/$USER0/testdir_groups
4575 chmod 770 $DIR/$tdir/$USER0/testdir_groups
4576 chmod g+s $DIR/$tdir/$USER0/testdir_groups
4578 # unmount client completely
4579 umount_client $MOUNT || error "umount $MOUNT failed"
4580 if is_mounted $MOUNT2; then
4581 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
4584 do_nodes $(comma_list $(all_mdts_nodes)) \
4585 $LCTL set_param mdt.*.identity_upcall=NONE
4587 stack_trap cleanup_55 EXIT
4589 do_facet mgs $LCTL nodemap_activate 1
4592 do_facet mgs $LCTL nodemap_del c0 || true
4593 wait_nm_sync c0 id ''
4595 do_facet mgs $LCTL nodemap_modify --name default \
4596 --property admin --value 1
4597 do_facet mgs $LCTL nodemap_modify --name default \
4598 --property trusted --value 1
4599 wait_nm_sync default admin_nodemap
4600 wait_nm_sync default trusted_nodemap
4602 client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
4603 client_nid=$(h2nettype $client_ip)
4604 do_facet mgs $LCTL nodemap_add c0
4605 do_facet mgs $LCTL nodemap_add_range \
4606 --name c0 --range $client_nid
4607 do_facet mgs $LCTL nodemap_modify --name c0 \
4608 --property admin --value 0
4609 do_facet mgs $LCTL nodemap_modify --name c0 \
4610 --property trusted --value 1
4611 wait_nm_sync c0 admin_nodemap
4612 wait_nm_sync c0 trusted_nodemap
4614 if $SHARED_KEY; then
4615 export SK_UNIQUE_NM=true
4616 # set some generic fileset to trigger SSK code
4620 # remount client to take nodemap into account
4621 zconf_mount_clients $HOSTNAME $MOUNT $MOUNT_OPTS ||
4622 error "remount failed"
4625 euid_access $USER0 $DIR/$tdir/$USER0/testdir_groups/file
4627 run_test 55 "access with seteuid"
4630 local testfile=$DIR/$tdir/$tfile
4632 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4634 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4635 skip "client encryption not supported"
4637 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4638 skip "need dummy encryption support"
4640 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4642 stack_trap cleanup_for_enc_tests EXIT
4645 $LFS setstripe -c1 $testfile
4646 dd if=/dev/urandom of=$testfile bs=1M count=3 conv=fsync
4647 filefrag -v $testfile || error "filefrag $testfile failed"
4648 (( $(filefrag -v $testfile | grep -c encrypted) >= 1 )) ||
4649 error "filefrag $testfile does not show encrypted flag"
4650 (( $(filefrag -v $testfile | grep -c encoded) >= 1 )) ||
4651 error "filefrag $testfile does not show encoded flag"
4653 run_test 56 "FIEMAP on encrypted file"
4656 local testdir=$DIR/$tdir/mytestdir
4657 local testfile=$DIR/$tdir/$tfile
4659 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4661 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4662 skip "client encryption not supported"
4664 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4665 skip "need dummy encryption support"
4669 setfattr -n security.c -v myval $testdir &&
4670 error "setting xattr on $testdir should have failed (1.1)"
4671 setfattr -n encryption.c -v myval $testdir &&
4672 error "setting xattr on $testdir should have failed (1.2)"
4674 setfattr -n security.c -v myval $testfile &&
4675 error "setting xattr on $testfile should have failed (1.1)"
4676 setfattr -n encryption.c -v myval $testfile &&
4677 error "setting xattr on $testfile should have failed (1.2)"
4681 stack_trap cleanup_for_enc_tests EXIT
4685 if [ $(getfattr -n security.c $testdir 2>&1 |
4686 grep -ci "Operation not permitted") -eq 0 ]; then
4687 error "getting xattr on $testdir should have failed (1.1)"
4689 if [ $(getfattr -n encryption.c $testdir 2>&1 |
4690 grep -ci "Operation not supported") -eq 0 ]; then
4691 error "getting xattr on $testdir should have failed (1.2)"
4693 getfattr -d -m - $testdir 2>&1 | grep security\.c &&
4694 error "listing xattrs on $testdir should not expose security.c"
4695 getfattr -d -m - $testdir 2>&1 | grep encryption\.c &&
4696 error "listing xattrs on $testdir should not expose encryption.c"
4697 if [ $(setfattr -n security.c -v myval $testdir 2>&1 |
4698 grep -ci "Operation not permitted") -eq 0 ]; then
4699 error "setting xattr on $testdir should have failed (2.1)"
4701 if [ $(setfattr -n encryption.c -v myval $testdir 2>&1 |
4702 grep -ci "Operation not supported") -eq 0 ]; then
4703 error "setting xattr on $testdir should have failed (2.2)"
4706 if [ $(getfattr -n security.c $testfile 2>&1 |
4707 grep -ci "Operation not permitted") -eq 0 ]; then
4708 error "getting xattr on $testfile should have failed (1.1)"
4710 if [ $(getfattr -n encryption.c $testfile 2>&1 |
4711 grep -ci "Operation not supported") -eq 0 ]; then
4712 error "getting xattr on $testfile should have failed (1.2)"
4714 getfattr -d -m - $testfile 2>&1 | grep security\.c &&
4715 error "listing xattrs on $testfile should not expose security.c"
4716 getfattr -d -m - $testfile 2>&1 | grep encryption\.c &&
4717 error "listing xattrs on $testfile should not expose encryption.c"
4718 if [ $(setfattr -n security.c -v myval $testfile 2>&1 |
4719 grep -ci "Operation not permitted") -eq 0 ]; then
4720 error "setting xattr on $testfile should have failed (2.1)"
4722 if [ $(setfattr -n encryption.c -v myval $testfile 2>&1 |
4723 grep -ci "Operation not supported") -eq 0 ]; then
4724 error "setting xattr on $testfile should have failed (2.2)"
4728 run_test 57 "security.c/encryption.c xattr protection"
4731 local testdir=$DIR/$tdir/mytestdir
4732 local testfile=$DIR/$tdir/$tfile
4734 [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
4736 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4737 skip "client encryption not supported"
4739 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4740 skip "need dummy encryption support"
4742 stack_trap cleanup_for_enc_tests EXIT
4745 touch $DIR/$tdir/$tfile
4746 mkdir $DIR/$tdir/subdir
4750 echo 3 > /proc/sys/vm/drop_caches
4752 ll_decode_linkea $DIR/$tdir/$tfile || error "cannot read $tfile linkea"
4753 ll_decode_linkea $DIR/$tdir/subdir || error "cannot read subdir linkea"
4755 for ((i = 0; i < 1000; i = $((i+1)))); do
4756 mkdir -p $DIR/$tdir/d${i}
4757 touch $DIR/$tdir/f${i}
4758 createmany -m $DIR/$tdir/d${i}/f 5 > /dev/null
4763 echo 3 > /proc/sys/vm/drop_caches
4766 ls -ailR $DIR/$tdir > /dev/null || error "fail to ls"
4768 run_test 58 "access to enc file's xattrs"
4771 local mirror1=$TMP/$tfile.mirror1
4772 local mirror2=$TMP/$tfile.mirror2
4776 $LFS mirror verify -vvv $testfile ||
4777 error "verifying mirror failed (1)"
4778 if [ $($LFS mirror verify -v $testfile 2>&1 |
4779 grep -ci "only valid") -ne 0 ]; then
4780 error "verifying mirror failed (2)"
4783 $LFS mirror read -N 1 -o $mirror1 $testfile ||
4784 error "read from mirror 1 failed"
4785 cmp -bl $reffile $mirror1 ||
4786 error "corruption of mirror 1"
4787 $LFS mirror read -N 2 -o $mirror2 $testfile ||
4788 error "read from mirror 2 failed"
4789 cmp -bl $reffile $mirror2 ||
4790 error "corruption of mirror 2"
4794 local testfile=$DIR/$tdir/$tfile
4795 local tmpfile=$TMP/$tfile
4796 local mirror1=$TMP/$tfile.mirror1
4797 local mirror2=$TMP/$tfile.mirror2
4800 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4801 skip "client encryption not supported"
4803 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4804 skip "need dummy encryption support"
4806 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4808 stack_trap "cleanup_for_enc_tests $tmpfile $mirror1 $mirror2" EXIT
4811 dd if=/dev/urandom of=$tmpfile bs=5000 count=1 conv=fsync
4813 $LFS mirror create -N -i0 -N -i1 $testfile ||
4814 error "could not create mirror"
4815 dd if=$tmpfile of=$testfile bs=5000 count=1 conv=fsync ||
4816 error "could not write to $testfile"
4817 $LFS getstripe $testfile
4819 # remount without dummy encryption key
4820 remount_client_normally
4822 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type f)
4823 $LFS mirror resync $scrambledfile ||
4824 error "could not resync mirror"
4826 $LFS mirror verify -vvv $scrambledfile ||
4827 error "mirror verify failed (1)"
4828 if [ $($LFS mirror verify -v $scrambledfile 2>&1 |
4829 grep -ci "only valid") -ne 0 ]; then
4830 error "mirror verify failed (2)"
4833 $LFS mirror read -N 1 -o $mirror1 $scrambledfile &&
4834 error "read from mirror should fail"
4837 remount_client_dummykey
4838 verify_mirror $testfile $tmpfile
4840 run_test 59a "mirror resync of encrypted files without key"
4843 local testfile=$DIR/$tdir/$tfile
4844 local tmpfile=$TMP/$tfile
4845 local mirror1=$TMP/$tfile.mirror1
4846 local mirror2=$TMP/$tfile.mirror2
4849 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4850 skip "client encryption not supported"
4852 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4853 skip "need dummy encryption support"
4855 [[ $OSTCOUNT -lt 2 ]] && skip_env "needs >= 2 OSTs"
4857 stack_trap "cleanup_for_enc_tests $tmpfile $mirror1 $mirror2" EXIT
4860 tr '\0' '2' < /dev/zero |
4861 dd of=$tmpfile bs=1 count=9000 conv=fsync
4863 $LFS setstripe -c1 -i0 $testfile
4864 dd if=$tmpfile of=$testfile bs=9000 count=1 conv=fsync ||
4865 error "write to $testfile failed"
4866 $LFS getstripe $testfile
4868 # remount without dummy encryption key
4869 remount_client_normally
4871 scrambledfile=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type f)
4872 $LFS migrate -i1 $scrambledfile ||
4873 error "migrate $scrambledfile failed"
4874 $LFS getstripe $scrambledfile
4875 stripe=$($LFS getstripe -i $scrambledfile)
4876 [ $stripe -eq 1 ] || error "migrate file $scrambledfile failed"
4880 remount_client_dummykey
4881 cmp -bl $tmpfile $testfile ||
4882 error "migrated file is corrupted"
4884 # remount without dummy encryption key
4885 remount_client_normally
4887 $LFS mirror extend -N -i0 $scrambledfile ||
4888 error "mirror extend $scrambledfile failed (1)"
4889 $LFS getstripe $scrambledfile
4890 mirror_count=$($LFS getstripe -N $scrambledfile)
4891 [ $mirror_count -eq 2 ] ||
4892 error "mirror extend file $scrambledfile failed (2)"
4893 stripe=$($LFS getstripe --mirror-id=1 -i $scrambledfile)
4894 [ $stripe -eq 1 ] ||
4895 error "mirror extend file $scrambledfile failed (3)"
4896 stripe=$($LFS getstripe --mirror-id=2 -i $scrambledfile)
4897 [ $stripe -eq 0 ] ||
4898 error "mirror extend file $scrambledfile failed (4)"
4900 $LFS mirror verify -vvv $scrambledfile ||
4901 error "mirror verify failed (1)"
4902 if [ $($LFS mirror verify -v $scrambledfile 2>&1 |
4903 grep -ci "only valid") -ne 0 ]; then
4904 error "mirror verify failed (2)"
4908 remount_client_dummykey
4909 verify_mirror $testfile $tmpfile
4911 # remount without dummy encryption key
4912 remount_client_normally
4914 $LFS mirror split --mirror-id 1 -d $scrambledfile ||
4915 error "mirror split file $scrambledfile failed (1)"
4916 $LFS getstripe $scrambledfile
4917 mirror_count=$($LFS getstripe -N $scrambledfile)
4918 [ $mirror_count -eq 1 ] ||
4919 error "mirror split file $scrambledfile failed (2)"
4920 stripe=$($LFS getstripe --mirror-id=1 -i $scrambledfile)
4921 [ -z "$stripe" ] || error "mirror split file $scrambledfile failed (3)"
4922 stripe=$($LFS getstripe --mirror-id=2 -i $scrambledfile)
4923 [ $stripe -eq 0 ] || error "mirror split file $scrambledfile failed (4)"
4926 remount_client_dummykey
4928 cmp -bl $tmpfile $testfile ||
4929 error "extended/split file is corrupted"
4931 run_test 59b "migrate/extend/split of encrypted files without key"
4934 local dirname=$DIR/$tdir/subdir
4937 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4938 skip "client encryption not supported"
4940 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4941 skip "need dummy encryption support"
4943 [[ $MDSCOUNT -ge 2 ]] || skip_env "needs >= 2 MDTs"
4945 (( "$MDS1_VERSION" > $(version_code 2.14.54.54) )) ||
4946 skip "MDT migration not supported with older server"
4948 stack_trap cleanup_for_enc_tests EXIT
4951 $LFS setdirstripe -i 0 $dirname
4952 echo b > $dirname/subf
4954 # remount without dummy encryption key
4955 remount_client_normally
4957 scrambleddir=$(find $DIR/$tdir/ -maxdepth 1 -mindepth 1 -type d)
4959 # migrate a non-empty encrypted dir
4960 $LFS migrate -m 1 $scrambleddir ||
4961 error "migrate $scrambleddir between MDTs failed (1)"
4963 stripe=$($LFS getdirstripe -i $scrambleddir)
4964 [ $stripe -eq 1 ] ||
4965 error "migrate $scrambleddir between MDTs failed (2)"
4969 [ -f $dirname/subf ] ||
4970 error "migrate $scrambleddir between MDTs failed (3)"
4971 [ $(cat $dirname/subf) == "b" ] ||
4972 error "migrate $scrambleddir between MDTs failed (4)"
4974 run_test 59c "MDT migrate of encrypted files without key"
4977 local testdir=$DIR/$tdir/mytestdir
4978 local testfile=$DIR/$tdir/$tfile
4980 (( $MDS1_VERSION > $(version_code 2.14.53) )) ||
4981 skip "Need MDS version at least 2.14.53"
4983 $LCTL get_param mdc.*.import | grep -q client_encryption ||
4984 skip "client encryption not supported"
4986 mount.lustre --help |& grep -q "test_dummy_encryption:" ||
4987 skip "need dummy encryption support"
4989 stack_trap cleanup_for_enc_tests EXIT
4992 echo a > $DIR/$tdir/file1
4993 mkdir $DIR/$tdir/subdir
4994 echo b > $DIR/$tdir/subdir/subfile1
4997 # unmount client completely
4998 umount_client $MOUNT || error "umount $MOUNT failed"
4999 if is_mounted $MOUNT2; then
5000 umount_client $MOUNT2 || error "umount $MOUNT2 failed"
5003 # remount client with subdirectory mount
5004 export FILESET=/$tdir
5005 mount_client $MOUNT ${MOUNT_OPTS} || error "remount failed"
5006 if [ "$MOUNT_2" ]; then
5007 mount_client $MOUNT2 ${MOUNT_OPTS} || error "remount failed"
5010 ls -Rl $DIR || error "ls -Rl $DIR failed (1)"
5013 remount_client_dummykey
5016 ls -Rl $DIR || error "ls -Rl $DIR failed (2)"
5017 cat $DIR/file1 || error "cat $DIR/$tdir/file1 failed"
5018 cat $DIR/subdir/subfile1 ||
5019 error "cat $DIR/$tdir/subdir/subfile1 failed"
5021 run_test 60 "Subdirmount of encrypted dir"
5024 local testfile=$DIR/$tdir/$tfile
5027 readonly=$(do_facet mgs \
5028 lctl get_param -n nodemap.default.readonly_mount)
5029 [ -n "$readonly" ] ||
5030 skip "Server does not have readonly_mount nodemap flag"
5032 stack_trap cleanup_nodemap_after_enc_tests EXIT
5033 umount_client $MOUNT || error "umount $MOUNT failed (1)"
5035 # Activate nodemap, and mount rw.
5036 # Should succeed as rw mount is not forbidden on default nodemap
5038 do_facet mgs $LCTL nodemap_activate 1
5040 do_facet mgs $LCTL nodemap_modify --name default \
5041 --property admin --value 1
5042 do_facet mgs $LCTL nodemap_modify --name default \
5043 --property trusted --value 1
5044 wait_nm_sync default admin_nodemap
5045 wait_nm_sync default trusted_nodemap
5046 readonly=$(do_facet mgs \
5047 lctl get_param -n nodemap.default.readonly_mount)
5048 [ $readonly -eq 0 ] || error "wrong default value for readonly_mount"
5050 mount_client $MOUNT ${MOUNT_OPTS},rw ||
5051 error "mount '-o rw' failed with default"
5052 findmnt $MOUNT --output=options -n -f | grep -q "rw," ||
5053 error "should be rw mount"
5054 mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5055 echo a > $testfile || error "write $testfile failed"
5056 umount_client $MOUNT || error "umount $MOUNT failed (2)"
5058 # Now enforce read-only, and retry.
5059 do_facet mgs $LCTL nodemap_modify --name default \
5060 --property readonly_mount --value 1
5061 wait_nm_sync default readonly_mount
5062 mount_client $MOUNT ${MOUNT_OPTS},rw &&
5063 error "mount '-o rw' should have failed"
5064 mount_client $MOUNT ${MOUNT_OPTS},ro ||
5065 error "mount '-o ro' failed"
5066 cat $testfile || error "read $testfile failed"
5067 echo b > $testfile && error "write $testfile should fail"
5068 umount_client $MOUNT || error "umount $MOUNT failed (3)"
5070 run_test 61 "Nodemap enforces read-only mount"
5072 log "cleanup: ======================================================"
5075 for num in $(seq $MDSCOUNT); do
5076 if [ "${identity_old[$num]}" = 1 ]; then
5077 switch_identity $num false || identity_old[$num]=$?
5081 $RUNAS_CMD -u $ID0 ls $DIR
5082 $RUNAS_CMD -u $ID1 ls $DIR
5087 check_and_cleanup_lustre