Whamcloud - gitweb
LU-8150 mdt: Track open+create as mknod
[fs/lustre-release.git] / lustre / tests / sanity.sh
index 2da4365..87d9bad 100644 (file)
@@ -8,8 +8,8 @@
 set -e
 
 ONLY=${ONLY:-"$*"}
-# bug number for skipped test: 13297 2108 9789 3637 9789 3561 12622 5188
-ALWAYS_EXCEPT="                42a  42b  42c  42d  45   51d   68b   $SANITY_EXCEPT"
+# bug number for skipped test: 13297 2108 9789 3637 9789 3561 5188
+ALWAYS_EXCEPT="                42a  42b  42c  42d  45   68b   $SANITY_EXCEPT"
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
 # with LOD/OSP landing
@@ -75,11 +75,13 @@ init_test_env $@
 . ${CONFIG:=$LUSTRE/tests/cfg/${NAME}.sh}
 init_logging
 
-[ "$SLOW" = "no" ] && EXCEPT_SLOW="24o 24D 27m 64b 68 71 77f 78 115 124b 300o"
+#                                  5              12          (min)"
+[ "$SLOW" = "no" ] && EXCEPT_SLOW="24D 27m 64b 68 71 115 300o"
 
 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
        # bug number for skipped test: LU-4536 LU-1957 LU-2805
        ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180     184c"
+       #                                               4   13    (min)"
        [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b 51ba"
 fi
 
@@ -2067,6 +2069,46 @@ test_27E() {
 }
 run_test 27E "check that default extended attribute size properly increases"
 
+test_27F() { # LU-5346/LU-7975
+
+       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+
+       [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.51) ]] &&
+               skip "Need MDS version at least 2.8.51" && return
+
+       test_mkdir -p $DIR/$tdir
+       rm -f $DIR/$tdir/f0
+       $SETSTRIPE -c 2 $DIR/$tdir
+
+       # stop all OSTs to reproduce situation for LU-7975 ticket
+       for num in $(seq $OSTCOUNT); do
+               stop ost$num
+       done
+
+       # open/create f0 with O_LOV_DELAY_CREATE
+       # truncate f0 to a non-0 size
+       # close
+       multiop $DIR/$tdir/f0 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:T1050000c
+
+       $CHECKSTAT -s 1050000 $DIR/$tdir/f0 || error "checkstat failed"
+       # open/write it again to force delayed layout creation
+       cat /etc/hosts > $DIR/$tdir/f0 &
+       catpid=$!
+
+       # restart OSTs
+       for num in $(seq $OSTCOUNT); do
+               start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
+                       error "ost$num failed to start"
+       done
+
+       wait $catpid || error "cat failed"
+
+       cmp /etc/hosts $DIR/$tdir/f0 || error "cmp failed"
+       [[ $($GETSTRIPE -c $DIR/$tdir/f0) == 2 ]] || error "wrong stripecount"
+
+}
+run_test 27F "Client resend delayed layout creation with non-zero size"
+
 # createtest also checks that device nodes are created and
 # then visible correctly (#2091)
 test_28() { # bug 2091
@@ -2077,7 +2119,7 @@ run_test 28 "create/mknod/mkdir with bad file types ============"
 
 test_29() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return 0
-       cancel_lru_locks mdc
+       cancel_lru_locks
        test_mkdir $DIR/d29
        touch $DIR/d29/foo
        log 'first d29'
@@ -4033,87 +4075,62 @@ test_51a() {    # was test_51
 }
 run_test 51a "special situations: split htree with empty entry =="
 
-export NUMTEST=70000
 test_51b() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       local BASE=$DIR/d${base}.${TESTSUITE}
+       local dir=$DIR/$tdir
+
+       local nrdirs=$((65536 + 100))
 
        # cleanup the directory
-       rm -fr $BASE
+       rm -fr $dir
 
-       test_mkdir -p -c1 $BASE
+       test_mkdir -p -c1 $dir
 
        $LFS df
        $LFS df -i
-       local mdtidx=$(printf "%04x" $($LFS getstripe -M $BASE))
+       local mdtidx=$(printf "%04x" $($LFS getstripe -M $dir))
        local numfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.filesfree)
-       [[ $numfree -lt 21000 ]] &&
+       [[ $numfree -lt $nrdirs ]] &&
                skip "not enough free inodes ($numfree) on MDT$mdtidx" &&
                return
 
-       [[ $numfree -lt $NUMTEST ]] && NUMTEST=$(($numfree - 50)) &&
-               echo "reduced count to $NUMTEST due to inodes on MDT$mdtidx"
-
        # need to check free space for the directories as well
        local blkfree=$(lctl get_param -n mdc.$FSNAME-MDT$mdtidx*.kbytesavail)
        numfree=$((blkfree / 4))
-       [[ $numfree -lt $NUMTEST ]] && NUMTEST=$((numfree - 50)) &&
-               echo "reduced count to $NUMTEST due to blocks on MDT$mdtidx"
-
-       createmany -d $BASE/d $NUMTEST && echo $NUMTEST > $BASE/fnum ||
-       {
-               $LFS df
-               $LFS df -i
-               echo "failed" > $BASE/fnum
-               error "failed to create $NUMTEST subdirs in MDT$mdtidx:$BASE"
-       }
-}
-run_test 51b "exceed 64k subdirectory nlink limit"
+       [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)" &&
+               return
 
-test_51ba() { # LU-993
-       local BASE=$DIR/d${base}.${TESTSUITE}
-       # unlink all but 100 subdirectories, then check it still works
-       local LEFT=100
-       [ -f $BASE/fnum ] && local NUMPREV=$(cat $BASE/fnum) && rm $BASE/fnum
+       # create files
+       createmany -d $dir/d $nrdirs ||
+               error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
 
-       [ "$NUMPREV" != "failed" ] && NUMTEST=$NUMPREV
-       local DELETE=$((NUMTEST - LEFT))
+       # really created :
+       nrdirs=$(ls -U $dir | wc -l)
 
-       # continue on to run this test even if 51b didn't finish,
-       # just to delete the many subdirectories created.
-       [ ! -d "${BASE}/d1" ] && skip "test_51b() not run" && return 0
+       # unlink all but 100 subdirectories, then check it still works
+       local left=100
+       local delete=$((nrdirs - left))
 
        # for ldiskfs the nlink count should be 1, but this is OSD specific
        # and so this is listed for informational purposes only
-       echo "nlink before: $(stat -c %h $BASE), created before: $NUMTEST"
-       unlinkmany -d $BASE/d $DELETE
-       RC=$?
+       echo "nlink before: $(stat -c %h $dir), created before: $nrdirs"
+       unlinkmany -d $dir/d $delete ||
+               error "unlink of first $delete subdirs failed"
 
-       if [ $RC -ne 0 ]; then
-               if [ "$NUMPREV" == "failed" ]; then
-                       skip "previous setup failed"
-                       return 0
-               else
-                       error "unlink of first $DELETE subdirs failed"
-                       return $RC
-               fi
-       fi
+       echo "nlink between: $(stat -c %h $dir)"
+       local found=$(ls -U $dir | wc -l)
+       [ $found -ne $left ] &&
+               error "can't find subdirs: found only $found, expected $left"
 
-       echo "nlink between: $(stat -c %h $BASE)"
-       # trim the first line of ls output
-       local FOUND=$(($(ls -l ${BASE} | wc -l) - 1))
-       [ $FOUND -ne $LEFT ] &&
-               error "can't find subdirs: found only $FOUND/$LEFT"
-
-       unlinkmany -d $BASE/d $DELETE $LEFT ||
-               error "unlink of second $LEFT subdirs failed"
+       unlinkmany -d $dir/d $delete $left ||
+               error "unlink of second $left subdirs failed"
        # regardless of whether the backing filesystem tracks nlink accurately
        # or not, the nlink count shouldn't be more than "." and ".." here
-       local AFTER=$(stat -c %h $BASE)
-       [[ $AFTER -gt 2 ]] && error "nlink after: $AFTER > 2" ||
-               echo "nlink after: $AFTER"
+       local after=$(stat -c %h $dir)
+       [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
+               echo "nlink after: $after"
 }
-run_test 51ba "verify nlink for many subdirectory cleanup"
+run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
 
 test_51d() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
@@ -4121,11 +4138,11 @@ test_51d() {
                skip_env "skipping test with few OSTs" && return
        test_mkdir -p $DIR/$tdir
        createmany -o $DIR/$tdir/t- 1000
-       $GETSTRIPE $DIR/$tdir > $TMP/files
+       $GETSTRIPE $DIR/$tdir > $TMP/$tfile
        for N in $(seq 0 $((OSTCOUNT - 1))); do
                OBJS[$N]=$(awk -vobjs=0 '($1 == '$N') { objs += 1 } \
-                       END { printf("%0.0f", objs) }' $TMP/files)
-               OBJS0[$N]=$(grep -A 1 idx $TMP/files | awk -vobjs=0 \
+                       END { printf("%0.0f", objs) }' $TMP/$tfile)
+               OBJS0[$N]=$(grep -A 1 idx $TMP/$tfile | awk -vobjs=0 \
                        '($1 == '$N') { objs += 1 } \
                        END { printf("%0.0f", objs) }')
                log "OST$N has ${OBJS[$N]} objects, ${OBJS0[$N]} are index 0"
@@ -4149,8 +4166,9 @@ test_51d() {
                              " (${OBJS0[$N]} < ${OBJS0[$NLAST]}"
                NLAST=$N
        done
+       rm -f $TMP/$tfile
 }
-run_test 51d "check object distribution ===================="
+run_test 51d "check object distribution"
 
 test_51e() {
        if [ "$(facet_fstype $SINGLEMDS)" != ldiskfs ]; then
@@ -4184,10 +4202,10 @@ test_52a() {
        lsattr $DIR/$tdir/foo | egrep -q "^-+a[-e]+ $DIR/$tdir/foo" ||
                                                     error "lsattr"
        chattr -a $DIR/$tdir/foo || error "chattr -a failed"
-        cp -r $DIR/$tdir /tmp/
-       rm -fr $DIR/$tdir || error "cleanup rm failed"
+       cp -r $DIR/$tdir $TMP/
+       rm -fr $DIR/$tdir $TMP/$tdir || error "cleanup rm failed"
 }
-run_test 52a "append-only flag test (should return errors) ====="
+run_test 52a "append-only flag test (should return errors)"
 
 test_52b() {
        [ -f $DIR/$tdir/foo ] && chattr -i $DIR/$tdir/foo
@@ -5286,14 +5304,14 @@ test_60d() {
 
        # verify "lctl mark" is even working"
        MESSAGE="test message ID $RANDOM $$"
-       $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
+       $LCTL mark "$HOSTNAME $MESSAGE" || error "$LCTL mark failed"
        dmesg | grep -q "$MESSAGE" || error "didn't find debug marker in log"
 
        lctl set_param printk=0 || error "set lnet.printk failed"
        lctl get_param -n printk | grep emerg || error "lnet.printk dropped emerg"
        MESSAGE="new test message ID $RANDOM $$"
        # Assume here that libcfs_debug_mark_buffer() uses D_WARNING
-       $LCTL mark "$MESSAGE" || error "$LCTL mark failed"
+       $LCTL mark "$HOSTNAME $MESSAGE" || error "$LCTL mark failed"
        dmesg | grep -q "$MESSAGE" && error "D_WARNING wasn't masked" || true
 
        lctl set_param -n printk="$SAVEPRINTK"
@@ -7574,9 +7592,10 @@ test_116a() { # was previously test_116()
        echo "Wrote ${DIFF}KB to smaller OST $MINI1"
        DIFF2=$(($MAXV1 - ${AVAIL[$MAXI1]}))
        echo "Wrote ${DIFF2}KB to larger OST $MAXI1"
-       FILL=$(($DIFF2 * 100 / $DIFF - 100))
-       [ $DIFF -gt 0 ] &&
+       if [[ $DIFF -gt 0 ]]; then
+               FILL=$(($DIFF2 * 100 / $DIFF - 100))
                echo "Wrote ${FILL}% more data to larger OST $MAXI1"
+       fi
 
        # Figure out which files were written where
        UUID=$(lctl get_param -n lov.${FSNAME}-clilov-*.target_obd |
@@ -7589,9 +7608,10 @@ test_116a() { # was previously test_116()
        echo $UUID
        MAXC=$($GETSTRIPE --ost $UUID $DIR/$tdir | grep $DIR | wc -l)
        echo "$MAXC files created on larger OST $MAXI1"
-       FILL=$(($MAXC * 100 / $MINC - 100))
-       [[ $MINC -gt 0 ]] &&
+       if [[ $MINC -gt 0 ]]; then
+               FILL=$(($MAXC * 100 / $MINC - 100))
                echo "Wrote ${FILL}% more files to larger OST $MAXI1"
+       fi
        [[ $MAXC -gt $MINC ]] ||
                error_ignore LU-9 "stripe QOS didn't balance free space"
        simple_cleanup_common
@@ -8751,11 +8771,13 @@ test_127b() { # bug LU-333
                 esac
         done < $TMP/${tfile}.tmp
 
-        #check that we actually got some stats
-        [ "$read_bytes" ] || error "Missing read_bytes stats"
-        [ "$write_bytes" ] || error "Missing write_bytes stats"
-        [ "$read_bytes" != 0 ] || error "no read done"
-        [ "$write_bytes" != 0 ] || error "no write done"
+       #check that we actually got some stats
+       [ "$read_bytes" ] || error "Missing read_bytes stats"
+       [ "$write_bytes" ] || error "Missing write_bytes stats"
+       [ "$read_bytes" != 0 ] || error "no read done"
+       [ "$write_bytes" != 0 ] || error "no write done"
+
+       rm -f $TMP/${tfile}.tmp
 }
 run_test 127b "verify the llite client stats are sane"
 
@@ -8767,8 +8789,9 @@ test_128() { # bug 15212
        EOF
 
        result=$(grep error $TMP/$tfile.log)
-       rm -f $DIR/$tfile
-       [ -z "$result" ] || error "consecutive find's under interactive lfs failed"
+       rm -f $DIR/$tfile $TMP/$tfile.log
+       [ -z "$result" ] ||
+               error "consecutive find's under interactive lfs failed"
 }
 run_test 128 "interactive lfs for 2 consecutive find's"
 
@@ -9261,8 +9284,10 @@ test_133a() {
        touch ${testdir}/${tfile} || "touch failed"
        check_stats $SINGLEMDS "open" 1
        check_stats $SINGLEMDS "close" 1
-       mknod ${testdir}/${tfile}-pipe p || "mknod failed"
-       check_stats $SINGLEMDS "mknod" 1
+       [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.8.54) ] && {
+               mknod ${testdir}/${tfile}-pipe p || "mknod failed"
+               check_stats $SINGLEMDS "mknod" 2
+       }
        rm -f ${testdir}/${tfile}-pipe || "pipe remove failed"
        check_stats $SINGLEMDS "unlink" 1
        rm -f ${testdir}/${tfile} || error "file remove failed"
@@ -10231,6 +10256,7 @@ test_154f() {
 
        rm -f $DIR/f
        restore_lustre_params < $save
+       rm -f $save
 }
 run_test 154f "get parent fids by reading link ea"
 
@@ -13669,6 +13695,76 @@ test_247e() {
 }
 run_test 247e "mount .. as fileset"
 
+test_248() {
+       local my_error=error
+
+       # This test case is time sensitive and maloo uses kvm to run auto test.
+       # Therefore the complete time of I/O task is unreliable and depends on
+       # the work load on the host machine when the task is running.
+       which virt-what 2> /dev/null && [ "$(virt-what)" != "kvm" ] ||
+               { echo "no virt-what installed or running in kvm; ignore error";
+                 my_error="error_ignore env=kvm"; }
+
+       # create a large file for fast read verification
+       dd if=/dev/zero of=$DIR/$tfile bs=128M count=1 > /dev/null 2>&1
+
+       # make sure the file is created correctly
+       $CHECKSTAT -s $((128*1024*1024)) $DIR/$tfile ||
+               { rm -f $DIR/$tfile; skip "file creation error" && return; }
+
+       local saved_fast_read=$($LCTL get_param -n llite.*.fast_read)
+
+       echo "Test 1: verify that fast read is 4 times faster on cache read"
+
+       # small read with fast read enabled
+       $LCTL set_param -n llite.*.fast_read=1
+       local t_fast=$(eval time -p dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
+                  awk '/real/ { print $2 }')
+
+       # small read with fast read disabled
+       $LCTL set_param -n llite.*.fast_read=0
+       local t_slow=$(eval time -p dd if=$DIR/$tfile of=/dev/null bs=4k 2>&1 |
+                  awk '/real/ { print $2 }')
+
+       # verify that fast read is 4 times faster for cache read
+       [ $(bc <<< "4 * $t_fast < $t_slow") -eq 1 ] ||
+               $my_error "fast read was not 4 times faster: $t_fast vs $t_slow"
+
+       echo "Test 2: verify the performance between big and small read"
+       $LCTL set_param -n llite.*.fast_read=1
+
+       # 1k non-cache read
+       cancel_lru_locks osc
+       local t_1k=$(eval time -p dd if=$DIR/$tfile of=/dev/null bs=1k 2>&1 |
+            awk '/real/ { print $2 }')
+
+       # 1M non-cache read
+       cancel_lru_locks osc
+       local t_1m=$(eval time -p dd if=$DIR/$tfile of=/dev/null bs=1M 2>&1 |
+            awk '/real/ { print $2 }')
+
+       # verify that big IO is not 4 times faster than small IO
+       [ $(bc <<< "4 * $t_1k >= $t_1m") -eq 1 ] ||
+               $my_error "bigger IO is way too fast: $t_1k vs $t_1m"
+
+       $LCTL set_param -n llite.*.fast_read=$saved_fast_read
+       rm -f $DIR/$tfile
+}
+run_test 248 "fast read verification"
+
+test_249() { # LU-7890
+       rm -f $DIR/$tfile
+       $SETSTRIPE -c 1 $DIR/$tfile
+
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
+       skip "Need at least version 2.8.54"
+
+       # Offset 2T == 4k * 512M
+       dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 seek=512M ||
+               error "dd to 2T offset failed"
+}
+run_test 249 "Write above 2T file size"
+
 test_250() {
        [ "$(facet_fstype ost$(($($GETSTRIPE -i $DIR/$tfile) + 1)))" = "zfs" ] \
         && skip "no 16TB file size limit on ZFS" && return
@@ -14594,6 +14690,7 @@ test_400a() { # LU-1606, was conf-sanity test_74
                $CC -Wall -Werror $extra_flags -llustreapi -o $out $prog ||
                        error "client api broken"
        done
+       rm -f $out
 }
 run_test 400a "Lustre client api program can compile and link"
 
@@ -14626,6 +14723,7 @@ test_400b() { # LU-1606, LU-5011
                $CC -Wall -Werror -include $header -c -x c /dev/null -o $out ||
                        error "cannot compile '$header'"
        done
+       rm -f $out
 }
 run_test 400b "packaged headers can be compiled"
 
@@ -14782,6 +14880,18 @@ test_404() { # LU-6601
 }
 run_test 404 "validate manual {de}activated works properly for OSPs"
 
+test_405() {
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.92) ] &&
+               skip "Layout swap lock is not supported" && return
+
+       check_swap_layouts_support && return 0
+
+       test_mkdir -p $DIR/$tdir
+       swap_lock_test -d $DIR/$tdir ||
+               error "One layout swap locked test failed"
+}
+run_test 405 "Various layout swap lock tests"
+
 #
 # tests that do cleanup/setup should be run at the end
 #