Whamcloud - gitweb
LU-7812 tests: address race condition for sanity:120{e,f}
[fs/lustre-release.git] / lustre / tests / sanity.sh
index 320c39a..1654625 100755 (executable)
@@ -264,6 +264,21 @@ test_6g() {
        test_mkdir $DIR/$tdir/d/subdir || error "mkdir $tdir/d/subdir failed"
        $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir/d/subdir ||
                error "$tdir/d/subdir should be GID $RUNAS_GID"
+       if [[ $MDSCOUNT -gt 1 ]]; then
+               # check remote dir sgid inherite
+               $LFS mkdir -i 0 $DIR/$tdir.local ||
+                       error "mkdir $tdir.local failed"
+               chmod g+s $DIR/$tdir.local ||
+                       error "chmod $tdir.local failed"
+               chgrp $RUNAS_GID $DIR/$tdir.local ||
+                       error "chgrp $tdir.local failed"
+               $LFS mkdir -i 1 $DIR/$tdir.local/$tdir.remote ||
+                       error "mkdir $tdir.remote failed"
+               $CHECKSTAT -g \#$RUNAS_GID $DIR/$tdir.local/$tdir.remote ||
+                       error "$tdir.remote should be owned by $UID.$RUNAS_ID"
+               $CHECKSTAT -p 02755 $DIR/$tdir.local/$tdir.remote ||
+                       error "$tdir.remote should be mode 02755"
+       fi
 }
 run_test 6g "Is new dir in sgid dir inheriting group?"
 
@@ -1650,7 +1665,7 @@ test_27u() { # bug 4900
        createmany -o $DIR/$tdir/t- 1000
        do_nodes $list $LCTL set_param fail_loc=0
 
-       TLOG=$DIR/$tfile.getstripe
+       TLOG=$TMP/$tfile.getstripe
        $GETSTRIPE $DIR/$tdir > $TLOG
        OBJS=$(awk -vobj=0 '($1 == 0) { obj += 1 } END { print obj; }' $TLOG)
        unlinkmany $DIR/$tdir/t- 1000
@@ -3112,7 +3127,7 @@ test_38() {
 }
 run_test 38 "open a regular file with O_DIRECTORY should return -ENOTDIR ==="
 
-test_39() {
+test_39a() { # was test_39
        touch $DIR/$tfile
        touch $DIR/${tfile}2
 #      ls -l  $DIR/$tfile $DIR/${tfile}2
@@ -3130,7 +3145,7 @@ test_39() {
                error "O_TRUNC didn't change timestamps"
        fi
 }
-run_test 39 "mtime changed on create ==========================="
+run_test 39a "mtime changed on create ==========================="
 
 test_39b() {
        test_mkdir -p -c1 $DIR/$tdir
@@ -3792,7 +3807,7 @@ test_42e() { # bug22074
 }
 run_test 42e "verify sub-RPC writes are not done synchronously"
 
-test_43() {
+test_43A() { # was test_43
        test_mkdir -p $DIR/$tdir
        cp -p /bin/ls $DIR/$tdir/$tfile
        $MULTIOP $DIR/$tdir/$tfile Ow_c &
@@ -3803,7 +3818,7 @@ test_43() {
        $DIR/$tdir/$tfile && error || true
        kill -USR1 $pid
 }
-run_test 43 "execution of file opened for write should return -ETXTBSY"
+run_test 43A "execution of file opened for write should return -ETXTBSY"
 
 test_43a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
@@ -3844,12 +3859,12 @@ test_43c() {
 }
 run_test 43c "md5sum of copy into lustre========================"
 
-test_44() {
+test_44A() { # was test_44
        [[ $OSTCOUNT -lt 2 ]] && skip_env "skipping 2-stripe test" && return
        dd if=/dev/zero of=$DIR/f1 bs=4k count=1 seek=1023
        dd if=$DIR/f1 bs=4k count=1 > /dev/null
 }
-run_test 44 "zero length read from a sparse stripe ============="
+run_test 44A "zero length read from a sparse stripe ============="
 
 test_44a() {
        local nstripe=$($LCTL lov_getconfig $DIR | grep default_stripe_count: |
@@ -5731,10 +5746,6 @@ cleanup_68() {
                rm -f $LLOOP
                unset LLOOP
        fi
-       if [ ! -z "$LLITELOOPLOAD" ]; then
-               rmmod llite_lloop
-               unset LLITELOOPLOAD
-       fi
        rm -f $DIR/f68*
 }
 
@@ -5746,74 +5757,6 @@ swap_used() {
        swapon -s | awk '($1 == "'$1'") { print $4 }'
 }
 
-# test case for lloop driver, basic function
-test_68a() {
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       [ "$UID" != 0 ] && skip_env "must run as root" && return
-       llite_lloop_enabled || \
-               { skip_env "llite_lloop module disabled" && return; }
-
-       trap cleanup_68 EXIT
-
-       if ! module_loaded llite_lloop; then
-               if load_module llite/llite_lloop; then
-                       LLITELOOPLOAD=yes
-               else
-                       skip_env "can't find module llite_lloop"
-                       return
-               fi
-       fi
-
-       LLOOP=$TMP/lloop.`date +%s`.`date +%N`
-       dd if=/dev/zero of=$DIR/f68a bs=4k count=1024
-       $LCTL blockdev_attach $DIR/f68a $LLOOP || error "attach failed"
-
-       directio rdwr $LLOOP 0 1024 4096 || error "direct write failed"
-       directio rdwr $LLOOP 0 1025 4096 && error "direct write should fail"
-
-       cleanup_68
-}
-run_test 68a "lloop driver - basic test ========================"
-
-# excercise swapping to lustre by adding a high priority swapfile entry
-# and then consuming memory until it is used.
-test_68b() {  # was test_68
-       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
-       [ "$UID" != 0 ] && skip_env "must run as root" && return
-       lctl get_param -n devices | grep -q obdfilter && \
-               skip "local OST" && return
-
-       grep -q llite_lloop /proc/modules
-       [ $? -ne 0 ] && skip "can't find module llite_lloop" && return
-
-       [ -z "`$LCTL list_nids | grep -v tcp`" ] && \
-               skip "can't reliably test swap with TCP" && return
-
-       MEMTOTAL=`meminfo MemTotal`
-       NR_BLOCKS=$((MEMTOTAL>>8))
-       [[ $NR_BLOCKS -le 2048 ]] && NR_BLOCKS=2048
-
-       LLOOP=$TMP/lloop.`date +%s`.`date +%N`
-       dd if=/dev/zero of=$DIR/f68b bs=64k seek=$NR_BLOCKS count=1
-       mkswap $DIR/f68b
-
-       $LCTL blockdev_attach $DIR/f68b $LLOOP || error "attach failed"
-
-       trap cleanup_68 EXIT
-
-       swapon -p 32767 $LLOOP || error "swapon $LLOOP failed"
-
-       echo "before: `swapon -s | grep $LLOOP`"
-       $MEMHOG $MEMTOTAL || error "error allocating $MEMTOTAL kB"
-       echo "after: `swapon -s | grep $LLOOP`"
-       SWAPUSED=`swap_used $LLOOP`
-
-       cleanup_68
-
-       [ $SWAPUSED -eq 0 ] && echo "no swap used???" || true
-}
-run_test 68b "support swapping to Lustre ========================"
-
 # bug5265, obdfilter oa2dentry return -ENOENT
 # #define OBD_FAIL_SRV_ENOENT 0x217
 test_69() {
@@ -6725,6 +6668,7 @@ test_101f() {
        which iozone || { skip "no iozone installed" && return; }
 
        local old_debug=$($LCTL get_param debug)
+       old_debug=${old_debug#*=}
        $LCTL set_param debug="reada mmap"
 
        # create a test file
@@ -6737,14 +6681,15 @@ test_101f() {
        $LCTL set_param -n llite.*.read_ahead_stats 0
 
        echo mmap read the file with small block size
-       iozone -i 1 -+n -r 32k -s 128m -B -f $DIR/$tfile > /dev/null 2>&1
+       iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
+               > /dev/null 2>&1
 
        echo checking missing pages
        $LCTL get_param llite.*.read_ahead_stats
        local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
                        get_named_value 'misses' | cut -d" " -f1 | calc_total)
 
-       $LCTL set_param debug=$old_debug
+       $LCTL set_param debug="$old_debug"
        [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
        rm -f $DIR/$tfile
 }
@@ -7178,29 +7123,31 @@ getxattr() { # getxattr path name
 }
 
 test_102n() { # LU-4101 mdt: protect internal xattrs
-       local file0=$DIR/$tfile.0
-       local file1=$DIR/$tfile.1
-       local xattr0=$TMP/$tfile.0
-       local xattr1=$TMP/$tfile.1
-       local name
-       local value
-
        [ -z "$(which setfattr 2>/dev/null)" ] &&
                skip "could not find setfattr" && return
-
        if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.50) ]
        then
                skip "MDT < 2.5.50 allows setxattr on internal trusted xattrs"
                return
        fi
 
+       local file0=$DIR/$tfile.0
+       local file1=$DIR/$tfile.1
+       local xattr0=$TMP/$tfile.0
+       local xattr1=$TMP/$tfile.1
+       local namelist="lov lma lmv link fid version som hsm"
+       local name
+       local value
+
        rm -rf $file0 $file1 $xattr0 $xattr1
        touch $file0 $file1
 
        # Get 'before' xattrs of $file1.
        getfattr --absolute-names --dump --match=- $file1 > $xattr0
 
-       for name in lov lma lmv link fid version som hsm; do
+       [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.53) ] &&
+               namelist+=" lfsck_namespace"
+       for name in $namelist; do
                # Try to copy xattr from $file0 to $file1.
                value=$(getxattr $file0 trusted.$name 2> /dev/null)
 
@@ -7337,7 +7284,8 @@ test_103a() {
 
        SAVE_UMASK=$(umask)
        umask 0022
-       cd $DIR
+       mkdir -p $DIR/$tdir
+       cd $DIR/$tdir
 
        echo "performing cp ..."
        run_acl_subtest cp || error "run_acl_subtest cp failed"
@@ -8391,6 +8339,7 @@ test_120e() {
        stat $DIR/$tdir $DIR/$tdir/f1 > /dev/null
        # XXX client can not do early lock cancel of OST lock
        # during unlink (LU-4206), so cancel osc lock now.
+       sleep 2
        cancel_lru_locks osc
        can1=$(do_facet $SINGLEMDS \
               "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
@@ -8433,6 +8382,7 @@ test_120f() {
        stat $DIR/$tdir/d1 $DIR/$tdir/d2 $DIR/$tdir/d1/f1 $DIR/$tdir/d2/f2 > /dev/null
        # XXX client can not do early lock cancel of OST lock
        # during rename (LU-4206), so cancel osc lock now.
+       sleep 2
        cancel_lru_locks osc
        can1=$(do_facet $SINGLEMDS \
               "$LCTL get_param -n ldlm.services.ldlm_canceld.stats" |
@@ -8727,11 +8677,18 @@ test_124b() {
 
        NR=$(($(default_lru_size)*20))
        if [[ $NR -gt $LIMIT ]]; then
-                log "Limit lock number by $LIMIT locks"
-                NR=$LIMIT
-        fi
-        lru_resize_disable mdc
-        test_mkdir -p $DIR/$tdir/disable_lru_resize ||
+               log "Limit lock number by $LIMIT locks"
+               NR=$LIMIT
+       fi
+
+       IFree=$(mdsrate_inodes_available)
+       if [ $IFree -lt $NR ]; then
+               log "Limit lock number by $IFree inodes"
+               NR=$IFree
+       fi
+
+       lru_resize_disable mdc
+       test_mkdir -p $DIR/$tdir/disable_lru_resize ||
                error "failed to create $DIR/$tdir/disable_lru_resize"
 
         createmany -o $DIR/$tdir/disable_lru_resize/f $NR
@@ -10202,6 +10159,29 @@ test_154A() {
 }
 run_test 154A "lfs path2fid and fid2path basic checks"
 
+test_154B() {
+       [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
+               skip "Need MDS version at least 2.4.1" && return
+
+       mkdir -p $DIR/$tdir || error "mkdir $tdir failed"
+       touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
+       local linkea=$($LL_DECODE_LINKEA $DIR/$tdir/$tfile | grep 'pfid')
+       [ -z "$linkea" ] && error "decode linkea $DIR/$tdir/$tfile failed"
+
+       local name=$(echo $linkea | awk '/pfid/ {print $5}' | sed -e "s/'//g")
+       local PFID=$(echo $linkea | awk '/pfid/ {print $3}' | sed -e "s/,//g")
+
+       # check that we get the same pathname
+       echo "PFID: $PFID, name: $name"
+       local FOUND=$($LFS fid2path $MOUNT "$PFID")
+       [ -z "$FOUND" ] && error "fid2path unable to get $PFID path"
+       [ "$FOUND/$name" != "$DIR/$tdir/$tfile" ] &&
+               error "ll_decode_linkea has $FOUND/$name != $DIR/$tdir/$tfile"
+
+       rm -rf $DIR/$tdir || error "Can not delete directory $DIR/$tdir"
+}
+run_test 154B "verify the ll_decode_linkea tool"
+
 test_154a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
@@ -12134,8 +12114,10 @@ test_205() { # Job stats
        cmd="mv -f $DIR/$tfile $DIR/$tdir.rename"
        verify_jobstats "$cmd" "$SINGLEMDS"
        # jobstats expiry - sleep until old stats should be expired
-       local left=$((interval_new + 2 - (SECONDS - start)))
-       [ $left -ge 0 ] && echo "sleep $left for expiry" && sleep $((left + 1))
+       local left=$((interval_new + 5 - (SECONDS - start)))
+       [ $left -ge 0 ] && wait_update_facet $SINGLEMDS \
+               "lctl get_param *.*.job_stats | grep -c 'job_id.*mkdir'" \
+                       "0" $left
        cmd="mkdir $DIR/$tdir.expire"
        verify_jobstats "$cmd" "$SINGLEMDS"
        [ $(do_facet $SINGLEMDS lctl get_param *.*.job_stats |
@@ -13737,7 +13719,7 @@ test_241_dio() {
        done
 }
 
-test_241() {
+test_241a() { # was test_241
        dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
        ls -la $DIR/$tfile
        cancel_lru_locks osc
@@ -13746,7 +13728,7 @@ test_241() {
        test_241_dio 1000
        wait $PID
 }
-run_test 241 "bio vs dio"
+run_test 241a "bio vs dio"
 
 test_241b() {
        dd if=/dev/zero of=$DIR/$tfile count=1 bs=40960
@@ -14401,8 +14383,6 @@ facet_meminfo() {
 }
 
 test_255b() {
-       lfs setstripe -c -1 -i 0 $DIR/$tfile
-
        ladvise_no_type dontneed $DIR/$tfile &&
                skip "dontneed ladvise is not supported" && return
 
@@ -14415,6 +14395,8 @@ test_255b() {
        [ "$(facet_fstype ost1)" = "zfs" ] &&
                skip "zfs-osd does not support dontneed advice" && return
 
+       lfs setstripe -c 1 -i 0 $DIR/$tfile
+
        local size_mb=100
        local size=$((size_mb * 1048576))
        # In order to prevent disturbance of other processes, only check 3/4
@@ -15790,6 +15772,26 @@ test_407() {
 }
 run_test 407 "transaction fail should cause operation fail"
 
+test_408() {
+       dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=direct
+
+       #define OBD_FAIL_OSC_BRW_PREP_REQ2        0x40a
+       lctl set_param fail_loc=0x8000040a
+       # let ll_prepare_partial_page() fail
+       dd if=/dev/zero of=$DIR/$tfile bs=2048 count=1 conv=notrunc || true
+
+       rm -f $DIR/$tfile
+
+       # create at least 100 unused inodes so that
+       # shrink_icache_memory(0) should not return 0
+       touch $DIR/$tfile-{0..100}
+       rm -f $DIR/$tfile-{0..100}
+       sync
+
+       echo 2 > /proc/sys/vm/drop_caches
+}
+run_test 408 "drop_caches should not hang due to page leaks"
+
 #
 # tests that do cleanup/setup should be run at the end
 #