+test_300_check_default_striped_dir()
+{
+ local dirname=$1
+ local default_count=$2
+ local default_index=$3
+ local stripe_count
+ local stripe_index
+ local dir_stripe_index
+ local dir
+
+ echo "checking $dirname $default_count $default_index"
+ $LFS setdirstripe -D -c $default_count -i $default_index \
+ -t all_char $DIR/$tdir/$dirname ||
+ error "set default stripe on striped dir error"
+ stripe_count=$($LFS getdirstripe -D -c $DIR/$tdir/$dirname)
+ [ $stripe_count -eq $default_count ] ||
+ error "expect $default_count get $stripe_count for $dirname"
+
+ stripe_index=$($LFS getdirstripe -D -i $DIR/$tdir/$dirname)
+ [ $stripe_index -eq $default_index ] ||
+ error "expect $default_index get $stripe_index for $dirname"
+
+ mkdir $DIR/$tdir/$dirname/{test1,test2,test3,test4} ||
+ error "create dirs failed"
+
+ createmany -o $DIR/$tdir/$dirname/f- 10 || error "create files failed"
+ unlinkmany $DIR/$tdir/$dirname/f- 10 || error "unlink files failed"
+ for dir in $(find $DIR/$tdir/$dirname/*); do
+ stripe_count=$($LFS getdirstripe -c $dir)
+ [ $stripe_count -eq $default_count ] ||
+ error "stripe count $default_count != $stripe_count for $dir"
+
+ stripe_index=$($LFS getdirstripe -i $dir)
+ [ $default_index -eq -1 -o $stripe_index -eq $default_index ] ||
+ error "$stripe_index != $default_index for $dir"
+
+ #check default stripe
+ stripe_count=$($LFS getdirstripe -D -c $dir)
+ [ $stripe_count -eq $default_count ] ||
+ error "default count $default_count != $stripe_count for $dir"
+
+ stripe_index=$($LFS getdirstripe -D -i $dir)
+ [ $stripe_index -eq $default_index ] ||
+ error "default index $default_index != $stripe_index for $dir"
+ done
+ rmdir $DIR/$tdir/$dirname/* || error "rmdir failed"
+}
+
+test_300g() {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+ local dir
+ local stripe_count
+ local stripe_index
+
+ mkdir $DIR/$tdir
+ mkdir $DIR/$tdir/normal_dir
+
+ test_300_check_default_striped_dir normal_dir $MDSCOUNT 1
+ test_300_check_default_striped_dir normal_dir 1 0
+ test_300_check_default_striped_dir normal_dir 2 1
+ test_300_check_default_striped_dir normal_dir 2 -1
+
+ #delete default stripe information
+ echo "delete default stripeEA"
+ $LFS setdirstripe -d $DIR/$tdir/normal_dir ||
+ error "set default stripe on striped dir error"
+
+ mkdir -p $DIR/$tdir/normal_dir/{test1,test2,test3,test4}
+ for dir in $(find $DIR/$tdir/normal_dir/*); do
+ stripe_count=$($LFS getdirstripe -c $dir)
+ [ $stripe_count -eq 0 ] ||
+ error "expect 1 get $stripe_count for $dir"
+ stripe_index=$($LFS getdirstripe -i $dir)
+ [ $stripe_index -eq 0 ] ||
+ error "expect 0 get $stripe_index for $dir"
+ done
+}
+run_test 300g "check default striped directory for normal directory"
+
+test_300h() {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+ local dir
+ local stripe_count
+
+ mkdir $DIR/$tdir
+ $LFS setdirstripe -i 0 -c $MDSCOUNT -t all_char \
+ $DIR/$tdir/striped_dir ||
+ error "set striped dir error"
+
+ test_300_check_default_striped_dir striped_dir $MDSCOUNT 1
+ test_300_check_default_striped_dir striped_dir 1 0
+ test_300_check_default_striped_dir striped_dir 2 1
+ test_300_check_default_striped_dir striped_dir 2 -1
+
+ #delete default stripe information
+ $LFS setdirstripe -d $DIR/$tdir/striped_dir ||
+ error "set default stripe on striped dir error"
+
+ mkdir -p $DIR/$tdir/striped_dir/{test1,test2,test3,test4}
+ for dir in $(find $DIR/$tdir/striped_dir/*); do
+ stripe_count=$($LFS getdirstripe -c $dir)
+ [ $stripe_count -eq 0 ] ||
+ error "expect 1 get $stripe_count for $dir"
+ done
+}
+run_test 300h "check default striped directory for striped directory"
+
+test_300i() {
+ [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+ local stripe_count
+ local file
+
+ mkdir $DIR/$tdir
+
+ $LFS setdirstripe -i 0 -c$MDSCOUNT -t all_char $DIR/$tdir/striped_dir ||
+ error "set striped dir error"
+
+ createmany -o $DIR/$tdir/striped_dir/f- 10 ||
+ error "create files under striped dir failed"
+
+ # unfortunately, we need to umount to clear dir layout cache for now
+ # once we fully implement dir layout, we can drop this
+ umount_client $MOUNT || error "umount failed"
+ mount_client $MOUNT || error "mount failed"
+
+ #set the stripe to be unknown hash type
+ #define OBD_FAIL_UNKNOWN_LMV_STRIPE 0x1901
+ $LCTL set_param fail_loc=0x1901
+ for ((i = 0; i < 10; i++)); do
+ $CHECKSTAT -t file $DIR/$tdir/striped_dir/f-$i ||
+ error "stat f-$i failed"
+ rm $DIR/$tdir/striped_dir/f-$i || error "unlink f-$i failed"
+ done
+
+ touch $DIR/$tdir/striped_dir/f0 &&
+ error "create under striped dir with unknown hash should fail"
+
+ $LCTL set_param fail_loc=0
+
+ umount_client $MOUNT || error "umount failed"
+ mount_client $MOUNT || error "mount failed"
+
+ return 0
+}
+run_test 300i "client handle unknown hash type striped directory"
+
+test_400a() { # LU-1606, was conf-sanity test_74
+ local extra_flags=''
+ local out=$TMP/$tfile
+ local prefix=/usr/include/lustre
+ local prog
+
+ if ! which $CC > /dev/null 2>&1; then
+ skip_env "$CC is not installed"
+ return 0
+ fi
+
+ if ! [[ -d $prefix ]]; then
+ # Assume we're running in tree and fixup the include path.
+ extra_flags+=" -I$LUSTRE/../libcfs/include"
+ extra_flags+=" -I$LUSTRE/include"
+ extra_flags+=" -L$LUSTRE/utils"
+ fi
+
+ for prog in $LUSTRE_TESTS_API_DIR/*.c; do
+ $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
+ error "client api broken"
+ done
+}
+run_test 400a "Lustre client api program can compile and link"
+
+test_400b() { # LU-1606, LU-5011
+ local header
+ local out=$TMP/$tfile
+ local prefix=/usr/include/lustre
+
+ # We use a hard coded prefix so that this test will not fail
+ # when run in tree. There are headers in lustre/include/lustre/
+ # that are not packaged (like lustre_idl.h) and have more
+ # complicated include dependencies (like config.h and lnet/types.h).
+ # Since this test about correct packaging we just skip them when
+ # they don't exist (see below) rather than try to fixup cppflags.
+
+ if ! which $CC > /dev/null 2>&1; then
+ skip_env "$CC is not installed"
+ return 0
+ fi
+
+ for header in $prefix/*.h; do
+ if ! [[ -f "$header" ]]; then
+ continue
+ fi
+
+ if [[ "$(basename $header)" == liblustreapi.h ]]; then
+ continue # liblustreapi.h is deprecated.
+ fi
+
+ $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
+ error "cannot compile '$header'"
+ done
+}
+run_test 400b "packaged headers can be compiled"
+