Whamcloud - gitweb
LU-4185 llite: Revise create with no open optimization
[fs/lustre-release.git] / lustre / tests / sanity.sh
index 507812d..320c39a 100755 (executable)
@@ -81,8 +81,8 @@ init_logging
 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
        # bug number for skipped test: LU-4536 LU-1957
        ALWAYS_EXCEPT="$ALWAYS_EXCEPT  65ic    180"
-       #                                               4   13    (min)"
-       [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b 51ba"
+       #                                               13    (min)"
+       [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 51b"
 fi
 
 FAIL_ON_ERROR=false
@@ -2850,6 +2850,15 @@ test_33f() {
 }
 run_test 33f "nonroot user can create, access, and remove a striped directory"
 
+test_33g() {
+       mkdir -p $DIR/$tdir/dir2
+
+       local err=$($RUNAS mkdir $DIR/$tdir/dir2 2>&1)
+       echo $err
+       [[ $err =~ "exists" ]] || error "Not exists error"
+}
+run_test 33g "nonroot user create already existing root created file"
+
 TEST_34_SIZE=${TEST_34_SIZE:-2000000000000}
 test_34a() {
        rm -f $DIR/f34
@@ -4097,6 +4106,12 @@ test_51a() {     # was test_51
 }
 run_test 51a "special situations: split htree with empty entry =="
 
+cleanup_print_lfs_df () {
+       trap 0
+       $LFS df
+       $LFS df -i
+}
+
 test_51b() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
        local dir=$DIR/$tdir
@@ -4118,10 +4133,12 @@ test_51b() {
 
        # 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=$(( blkfree / $(fs_inode_ksize) ))
        [[ $numfree -lt $nrdirs ]] && skip "not enough blocks ($numfree)" &&
                return
 
+       trap cleanup_print_lfsdf EXIT
+
        # create files
        createmany -d $dir/d $nrdirs ||
                error "failed to create $nrdirs subdirs in MDT$mdtidx:$dir"
@@ -4133,6 +4150,9 @@ test_51b() {
        local left=100
        local delete=$((nrdirs - left))
 
+       $LFS df
+       $LFS df -i
+
        # 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 $dir), created before: $nrdirs"
@@ -4151,6 +4171,8 @@ test_51b() {
        local after=$(stat -c %h $dir)
        [[ $after -gt 2 ]] && error "nlink after: $after > 2" ||
                echo "nlink after: $after"
+
+       cleanup_print_lfs_df
 }
 run_test 51b "exceed 64k subdirectory nlink limit on create, verify unlink"
 
@@ -4423,30 +4445,47 @@ test_56a() {    # was test_56
                error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
        echo "$GETSTRIPE --recursive passed."
 
-        # test lfs getstripe with file instead of dir
+       # test lfs getstripe with file instead of dir
        FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
        [[ $FILENUM -eq 1 ]] ||
                error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
        echo "$GETSTRIPE file1 passed."
 
-        #test lfs getstripe with --verbose
+       #test lfs getstripe with --verbose
        [[ $($GETSTRIPE --verbose $DIR/$tdir |
                grep -c lmm_magic) -eq $NUMFILES ]] ||
                error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
        [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
-               rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
+               error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
+
+       #test lfs getstripe with -v prints lmm_fid
+       [[ $($GETSTRIPE -v $DIR/$tdir | grep -c lmm_fid) -eq $NUMFILES ]] ||
+               error "$GETSTRIPE -v $DIR/$tdir: want $NUMFILES lmm_fid: lines"
+       [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_fid) -eq 0 ]] ||
+               error "$GETSTRIPE $DIR/$tdir: showed lmm_fid"
        echo "$GETSTRIPE --verbose passed."
 
-        #test lfs getstripe with --obd
-        $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
+       #check for FID information
+       local fid1=$($GETSTRIPE --fid $DIR/$tdir/file1)
+       local fid2=$($GETSTRIPE --verbose $DIR/$tdir/file1 |
+                      awk '/lmm_fid: / { print $2 }')
+       local fid3=$($LFS path2fid $DIR/$tdir/file1)
+       [ "$fid1" != "$fid2" ] &&
+               error "getstripe --fid $fid1 != getstripe --verbose $fid2"
+       [ "$fid1" != "$fid3" ] &&
+               error "getstripe --fid $fid1 != lfs path2fid $fid3"
+       echo "$GETSTRIPE --fid passed."
+
+       #test lfs getstripe with --obd
+       $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
                grep -q "unknown obduuid" ||
                error "$GETSTRIPE --obd wrong_uuid should return error message"
 
        [[ $OSTCOUNT -lt 2 ]] &&
-                skip_env "skipping other $GETSTRIPE --obd test" && return
+               skip_env "skipping other $GETSTRIPE --obd test" && return
 
-        OSTIDX=1
-        OBDUUID=$(ostuuid_from_index $OSTIDX)
+       OSTIDX=1
+       OBDUUID=$(ostuuid_from_index $OSTIDX)
        FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
        FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
        [[ $FOUND -eq $FILENUM ]] ||
@@ -4792,7 +4831,7 @@ run_test 56s "check lfs find -stripe-count works"
 
 test_56t() { # LU-611
        TDIR=$DIR/${tdir}t
-       setup_56 $NUMFILES $NUMDIRS "-s 512k"
+       setup_56 $NUMFILES $NUMDIRS "--stripe-size 512k"
 
        $SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
 
@@ -6685,6 +6724,9 @@ run_test 101e "check read-ahead for small read(1k) for small files(500k)"
 test_101f() {
        which iozone || { skip "no iozone installed" && return; }
 
+       local old_debug=$($LCTL get_param debug)
+       $LCTL set_param debug="reada mmap"
+
        # create a test file
        iozone -i 0 -+n -r 1m -s 128m -w -f $DIR/$tfile > /dev/null 2>&1
 
@@ -6698,10 +6740,12 @@ test_101f() {
        iozone -i 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)
 
-       [ $miss -lt 3 ] || error "misses too much pages!"
+       $LCTL set_param debug=$old_debug
+       [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
        rm -f $DIR/$tfile
 }
 run_test 101f "check mmap read performance"
@@ -10144,17 +10188,17 @@ test_154A() {
        [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
                skip "Need MDS version at least 2.4.1" && return
 
-       touch $DIR/$tfile
-       local FID=$($LFS path2fid $DIR/$tfile)
-       [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
+       local tf=$DIR/$tfile
+       touch $tf
 
-       # check that we get the same pathname back
-       local FOUND=$($LFS fid2path $MOUNT "$FID")
-       [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
-       [ "$FOUND" != "$DIR/$tfile" ] &&
-               error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
+       local fid=$($LFS path2fid $tf)
+       [ -z "$fid" ] && error "path2fid unable to get $tf FID"
 
-       rm -rf $DIR/$tfile
+       # check that we get the same pathname back
+       local found=$($LFS fid2path $MOUNT "$fid")
+       [ -z "$found" ] && error "fid2path unable to get '$fid' path"
+       [ "$found" == "$tf" ] ||
+               error "fid2path($fid=path2fid($tf)) = $found != $tf"
 }
 run_test 154A "lfs path2fid and fid2path basic checks"
 
@@ -14015,6 +14059,129 @@ test_252() {
 }
 run_test 252 "check lr_reader tool"
 
+test_253_fill_ost() {
+       local size_mb #how many MB should we write to pass watermark
+       local lwm=$3  #low watermark
+       local free_10mb #10% of free space
+
+       free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
+       size_mb=$((free_kb / 1024 - lwm))
+       free_10mb=$((free_kb / 10240))
+       #If 10% of free space cross low watermark use it
+       if (( free_10mb > size_mb )); then
+               size_mb=$free_10mb
+       else
+               #At least we need to store 1.1 of difference between
+               #free space and low watermark
+               size_mb=$((size_mb + size_mb / 10))
+       fi
+       if (( lwm <= $((free_kb / 1024)) )) || [ ! -f $DIR/$tdir/1 ]; then
+               dd if=/dev/zero of=$DIR/$tdir/1 bs=1M count=$size_mb \
+                        oflag=append conv=notrunc
+       fi
+
+       sleep_maxage
+
+       free_kb=$($LFS df $MOUNT | grep $1 | awk '{ print $4 }')
+       echo "OST still has $((free_kb / 1024)) mbytes free"
+}
+
+test_253() {
+       local ostidx=0
+       local rc=0
+
+       [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return
+       remote_mgs_nodsh && skip "remote MGS with nodsh" && return
+
+       local ost_name=$($LFS osts | grep ${ostidx}": " | \
+               awk '{print $2}' | sed -e 's/_UUID$//')
+       # on the mdt's osc
+       local mdtosc_proc1=$(get_mdtosc_proc_path $SINGLEMDS $ost_name)
+       do_facet $SINGLEMDS $LCTL get_param -n \
+               osp.$mdtosc_proc1.reserved_mb_high ||
+               { skip  "remote MDS does not support reserved_mb_high" &&
+                 return; }
+
+       rm -rf $DIR/$tdir
+       wait_mds_ost_sync
+       wait_delete_completed
+       mkdir $DIR/$tdir
+
+       local last_wm_h=$(do_facet $SINGLEMDS $LCTL get_param -n \
+                       osp.$mdtosc_proc1.reserved_mb_high)
+       local last_wm_l=$(do_facet $SINGLEMDS $LCTL get_param -n \
+                       osp.$mdtosc_proc1.reserved_mb_low)
+       echo "prev high watermark $last_wm_h, prev low watermark $last_wm_l"
+
+       do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME ||
+               error "Pool creation failed"
+       do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $ost_name ||
+               error "Adding $ost_name to pool failed"
+
+       # Wait for client to see a OST at pool
+       wait_update $HOSTNAME "$LCTL get_param -n
+               lov.$FSNAME-*.pools.$TESTNAME | sort -u |
+               grep $ost_name" "$ost_name""_UUID" $((TIMEOUT/2)) ||
+               error "Client can not see the pool"
+       $SETSTRIPE $DIR/$tdir -i $ostidx -c 1 -p $FSNAME.$TESTNAME ||
+               error "Setstripe failed"
+
+       dd if=/dev/zero of=$DIR/$tdir/0 bs=1M count=10
+       local blocks=$($LFS df $MOUNT | grep $ost_name | awk '{ print $4 }')
+       echo "OST still has $((blocks/1024)) mbytes free"
+
+       local new_lwm=$((blocks/1024-10))
+       do_facet $SINGLEMDS $LCTL set_param \
+                       osp.$mdtosc_proc1.reserved_mb_high=$((new_lwm+5))
+       do_facet $SINGLEMDS $LCTL set_param \
+                       osp.$mdtosc_proc1.reserved_mb_low=$new_lwm
+
+       test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
+
+       #First enospc could execute orphan deletion so repeat.
+       test_253_fill_ost $ost_name $mdtosc_proc1 $new_lwm
+
+       local oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
+                       osp.$mdtosc_proc1.prealloc_status)
+       echo "prealloc_status $oa_status"
+
+       dd if=/dev/zero of=$DIR/$tdir/2 bs=1M count=1 &&
+               error "File creation should fail"
+       #object allocation was stopped, but we still able to append files
+       dd if=/dev/zero of=$DIR/$tdir/1 bs=1M seek=6 count=5 oflag=append ||
+               error "Append failed"
+       rm -f $DIR/$tdir/1 $DIR/$tdir/0 $DIR/$tdir/r*
+
+       wait_delete_completed
+
+       sleep_maxage
+
+       for i in $(seq 10 12); do
+               dd if=/dev/zero of=$DIR/$tdir/$i bs=1M count=1 2>/dev/null ||
+                       error "File creation failed after rm";
+       done
+
+       oa_status=$(do_facet $SINGLEMDS $LCTL get_param -n \
+                       osp.$mdtosc_proc1.prealloc_status)
+       echo "prealloc_status $oa_status"
+
+       if (( oa_status != 0 )); then
+               error "Object allocation still disable after rm"
+       fi
+       do_facet $SINGLEMDS $LCTL set_param \
+                       osp.$mdtosc_proc1.reserved_mb_high=$last_wm_h
+       do_facet $SINGLEMDS $LCTL set_param \
+                       osp.$mdtosc_proc1.reserved_mb_low=$last_wm_l
+
+
+       do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $ost_name ||
+               error "Remove $ost_name from pool failed"
+       do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
+               error "Pool destroy fialed"
+}
+run_test 253 "Check object allocation limit"
+
 test_254() {
        local cl_user
 
@@ -14226,6 +14393,71 @@ test_255a() {
 }
 run_test 255a "check 'lfs ladvise -a willread'"
 
+facet_meminfo() {
+       local facet=$1
+       local info=$2
+
+       do_facet $facet "cat /proc/meminfo | grep ^${info}:" | awk '{print $2}'
+}
+
+test_255b() {
+       lfs setstripe -c -1 -i 0 $DIR/$tfile
+
+       ladvise_no_type dontneed $DIR/$tfile &&
+               skip "dontneed ladvise is not supported" && return
+
+       ladvise_no_ioctl $DIR/$tfile &&
+               skip "ladvise ioctl is not supported" && return
+
+       [ $(lustre_version_code ost1) -lt $(version_code 2.8.54) ] &&
+               skip "lustre < 2.8.54 does not support ladvise" && return
+
+       [ "$(facet_fstype ost1)" = "zfs" ] &&
+               skip "zfs-osd does not support dontneed advice" && return
+
+       local size_mb=100
+       local size=$((size_mb * 1048576))
+       # In order to prevent disturbance of other processes, only check 3/4
+       # of the memory usage
+       local kibibytes=$((size_mb * 1024 * 3 / 4))
+
+       dd if=/dev/zero of=$DIR/$tfile bs=1048576 count=$size_mb ||
+               error "dd to $DIR/$tfile failed"
+
+       local total=$(facet_meminfo ost1 MemTotal)
+       echo "Total memory: $total KiB"
+
+       do_facet ost1 "sync && echo 3 > /proc/sys/vm/drop_caches"
+       local before_read=$(facet_meminfo ost1 Cached)
+       echo "Cache used before read: $before_read KiB"
+
+       lfs ladvise -a willread $DIR/$tfile ||
+               error "Ladvise willread failed"
+       local after_read=$(facet_meminfo ost1 Cached)
+       echo "Cache used after read: $after_read KiB"
+
+       lfs ladvise -a dontneed $DIR/$tfile ||
+               error "Ladvise dontneed again failed"
+       local no_read=$(facet_meminfo ost1 Cached)
+       echo "Cache used after dontneed ladvise: $no_read KiB"
+
+       if [ $total -lt $((before_read + kibibytes)) ]; then
+               echo "Memory is too small, abort checking"
+               return 0
+       fi
+
+       if [ $((before_read + kibibytes)) -gt $after_read ]; then
+               error "Ladvise willread should use more memory" \
+                       "than $kibibytes KiB"
+       fi
+
+       if [ $((no_read + kibibytes)) -gt $after_read ]; then
+               error "Ladvise dontneed should release more memory" \
+                       "than $kibibytes KiB"
+       fi
+}
+run_test 255b "check 'lfs ladvise -a dontneed'"
+
 test_256() {
        local cl_user
        local cat_sl