Whamcloud - gitweb
LU-946 lprocfs: List open files in filesystem
[fs/lustre-release.git] / lustre / tests / sanity.sh
index 53ff4d2..b9f8686 100644 (file)
@@ -1718,26 +1718,7 @@ check_seq_oid()
                local dev=$(ostdevname $ost)
                local oid_hex
 
-               if [ $(facet_fstype ost$ost) != ldiskfs ]; then
-                       echo "Currently only works with ldiskfs-based OSTs"
-                       continue
-               fi
-
-                log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
-
-                #don't unmount/remount the OSTs if we don't need to do that
-               # LU-2577 changes filter_fid to be smaller, so debugfs needs
-               # update too, until that use mount/ll_decode_filter_fid/mount
-               local dir=$(facet_mntpt ost$ost)
-               local opts=${OST_MOUNT_OPTS}
-
-               if !  do_facet ost$ost test -b ${dev}; then
-                       opts=$(csa_add "$opts" -o loop)
-               fi
-
-               stop ost$ost
-               do_facet ost$ost mount -t $(facet_fstype ost$ost) $opts $dev $dir ||
-                       { error "mounting $dev as $FSTYPE failed"; return 3; }
+               log "want: stripe:$stripe_nr ost:$obdidx oid:$oid/$hex seq:$seq"
 
                seq=$(echo $seq | sed -e "s/^0x//g")
                if [ $seq == 0 ]; then
@@ -1745,25 +1726,48 @@ check_seq_oid()
                else
                        oid_hex=$(echo $hex | sed -e "s/^0x//g")
                fi
-               local obj_file=$(do_facet ost$ost find $dir/O/$seq -name $oid_hex)
-               local ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID $obj_file)
-               do_facet ost$ost umount -d $dir
-               start ost$ost $dev $OST_MOUNT_OPTS
+               local obj_file="O/$seq/d$((oid %32))/$oid_hex"
 
-               # re-enable when debugfs will understand new filter_fid
-               #local ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
-                #           $dev 2>/dev/null" | grep "parent=")
+               local ff
+               #
+               # Don't unmount/remount the OSTs if we don't need to do that.
+               # LU-2577 changes filter_fid to be smaller, so debugfs needs
+               # update too, until that use mount/ll_decode_filter_fid/mount.
+               # Re-enable when debugfs will understand new filter_fid.
+               #
+               if false && [ $(facet_fstype ost$ost) == ldiskfs ]; then
+                       ff=$(do_facet ost$ost "$DEBUGFS -c -R 'stat $obj_file' \
+                               $dev 2>/dev/null" | grep "parent=")
+               else
+                       stop ost$ost
+                       mount_fstype ost$ost
+                       ff=$(do_facet ost$ost $LL_DECODE_FILTER_FID \
+                               $(facet_mntpt ost$ost)/$obj_file)
+                       unmount_fstype ost$ost
+                       start ost$ost $dev $OST_MOUNT_OPTS
+               fi
 
-                [ -z "$ff" ] && error "$obj_file: no filter_fid info"
+               [ -z "$ff" ] && error "$obj_file: no filter_fid info"
 
-                echo "$ff" | sed -e 's#.*objid=#got: objid=#'
+               echo "$ff" | sed -e 's#.*objid=#got: objid=#'
 
-                # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
-                # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
-                local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
-                local ff_pseq=$(echo $ff_parent | cut -d: -f1)
-                local ff_poid=$(echo $ff_parent | cut -d: -f2)
-                local ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
+               # /mnt/O/0/d23/23: objid=23 seq=0 parent=[0x200000400:0x1e:0x1]
+               # fid: objid=23 seq=0 parent=[0x200000400:0x1e:0x0] stripe=1
+               local ff_parent=$(echo $ff|sed -e 's/.*parent=.//')
+               local ff_pseq=$(echo $ff_parent | cut -d: -f1)
+               local ff_poid=$(echo $ff_parent | cut -d: -f2)
+               local ff_pstripe
+               if echo $ff_parent | grep -q 'stripe='; then
+                       ff_pstripe=$(echo $ff_parent | sed -e 's/.*stripe=//')
+               else
+                       #
+                       # $LL_DECODE_FILTER_FID does not print "stripe="; look
+                       # into f_ver in this case.  See the comment on
+                       # ff_parent.
+                       #
+                       ff_pstripe=$(echo $ff_parent | cut -d: -f3 |
+                               sed -e 's/\]//')
+               fi
 
                 # compare lmm_seq and filter_fid->ff_parent.f_seq
                 [ $ff_pseq = $lmm_seq ] ||
@@ -1771,7 +1775,7 @@ check_seq_oid()
                 # compare lmm_object_id and filter_fid->ff_parent.f_oid
                 [ $ff_poid = $lmm_oid ] ||
                         error "FF parent OID $ff_poid != $lmm_oid"
-                [ $ff_pstripe = $stripe_nr ] ||
+               (($ff_pstripe == $stripe_nr)) ||
                         error "FF stripe $ff_pstripe != $stripe_nr"
 
                 stripe_nr=$((stripe_nr + 1))
@@ -2116,18 +2120,20 @@ test_31m() {
 run_test 31m "link to file: the same, non-existing, dir==============="
 
 test_31n() {
-       [ -e /proc/self/fd/173 ] && echo "skipping, fd 173 is in use" && return
        touch $DIR/$tfile || error "cannot create '$DIR/$tfile'"
        nlink=$(stat --format=%h $DIR/$tfile)
        [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
-       exec 173<$DIR/$tfile
-       trap "exec 173<&-" EXIT
-       nlink=$(stat --dereference --format=%h /proc/self/fd/173)
+       local fd=$(free_fd)
+       local cmd="exec $fd<$DIR/$tfile"
+       eval $cmd
+       cmd="exec $fd<&-"
+       trap "eval $cmd" EXIT
+       nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
        [ ${nlink:--1} -eq 1 ] || error "nlink is $nlink, expected 1"
        rm $DIR/$tfile || error "cannot remove '$DIR/$tfile'"
-       nlink=$(stat --dereference --format=%h /proc/self/fd/173)
+       nlink=$(stat --dereference --format=%h /proc/self/fd/$fd)
        [ ${nlink:--1} -eq 0 ] || error "nlink is $nlink, expected 0"
-       exec 173<&-
+       eval $cmd
 }
 run_test 31n "check link count of unlinked file"
 
@@ -2156,7 +2162,7 @@ run_test 31o "duplicate hard links with same filename"
 
 cleanup_test32_mount() {
        trap 0
-       $UMOUNT $DIR/$tdir/ext2-mountpoint
+       $UMOUNT -d $DIR/$tdir/ext2-mountpoint
 }
 
 test_32a() {
@@ -2364,7 +2370,7 @@ run_test 32p "open d32p/symlink->tmp/symlink->lustre-root/$tfile"
 
 cleanup_testdir_mount() {
        trap 0
-       $UMOUNT $DIR/$tdir
+       $UMOUNT -d $DIR/$tdir
 }
 
 test_32q() {
@@ -3134,7 +3140,7 @@ run_test 39n "check that O_NOATIME is honored"
 test_39o() {
        TESTDIR=$DIR/$tdir/$tfile
        [ -e $TESTDIR ] && rm -rf $TESTDIR
-       mkdir -p $TESTDIR
+       test_mkdir -p $TESTDIR
        cd $TESTDIR
        links1=2
        ls
@@ -3151,6 +3157,30 @@ test_39o() {
 }
 run_test 39o "directory cached attributes updated after create ========"
 
+test_39p() {
+       [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
+       local MDTIDX=1
+       TESTDIR=$DIR/$tdir/$tfile
+       [ -e $TESTDIR ] && rm -rf $TESTDIR
+       mkdir -p $TESTDIR
+       cd $TESTDIR
+       links1=2
+       ls
+       $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir1
+       $LFS mkdir -i $MDTIDX $TESTDIR/remote_dir2
+       ls
+       links2=$(stat -c %h .)
+       [ $(($links1 + 2)) != $links2 ] &&
+               error "wrong links count $(($links1 + 2)) != $links2"
+       rmdir remote_dir2
+       links3=$(stat -c %h .)
+       [ $(($links1 + 1)) != $links3 ] &&
+               error "wrong links count $links1 != $links3"
+       return 0
+}
+run_test 39p "remote directory cached attributes updated after create ========"
+
+
 test_40() {
        dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
        $RUNAS $OPENFILE -f O_WRONLY:O_TRUNC $DIR/$tfile &&
@@ -3956,7 +3986,7 @@ test_54c() {
        dd if=/dev/zero of=$tdir/tmp bs=`page_size` count=30 || error "dd write"
        df $tdir
        dd if=$tdir/tmp of=/dev/zero bs=`page_size` count=30 || error "dd read"
-       $UMOUNT $tdir
+       $UMOUNT -d $tdir
        losetup -d $loopdev
        rm $loopdev
 }
@@ -4672,7 +4702,7 @@ test_57b() {
        local MDSFREE2=$(do_facet $mymds \
                lctl get_param -n osd*.*MDT000$((num -1)).kbytesfree)
        local MDCFREE2=$(lctl get_param -n mdc.*MDT000$((num -1))-mdc-*.kbytesfree)
-       if [ "$MDCFREE2" -lt "$((MDCFREE - 8))" ]; then
+       if [ "$MDCFREE2" -lt "$((MDCFREE - 16))" ]; then
                if [ "$MDSFREE" != "$MDSFREE2" ]; then
                        error "MDC before $MDCFREE != after $MDCFREE2"
                else
@@ -5781,6 +5811,7 @@ cleanup_101a() {
 
 test_101a() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run" && return
+       [ $MDSCOUNT -ge 2 ] && skip "skip now for >= 2 MDTs" && return #LU-4322
        local s
        local discard
        local nreads=10000
@@ -6380,6 +6411,75 @@ run_test 102m "Ensure listxattr fails on small bufffer ========"
 
 cleanup_test102
 
+getxattr() { # getxattr path name
+       # Return the base64 encoding of the value of xattr name on path.
+       local path=$1
+       local name=$2
+
+       # # getfattr --absolute-names --encoding=base64 --name=trusted.lov $path
+       # file: $path
+       # trusted.lov=0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
+       #
+       # We print just 0s0AvRCwEAAAAGAAAAAAAAAAAEAAACAAAAAAAQAAEAA...AAAAAAAAA=
+
+       getfattr --absolute-names --encoding=base64 --name=$name $path |
+               awk -F= -v name=$name '$1 == name {
+                       print substr($0, index($0, "=") + 1);
+       }'
+}
+
+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
+
+       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
+
+       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 lfsck_namespace; do
+               # Try to copy xattr from $file0 to $file1.
+               value=$(getxattr $file0 trusted.$name 2> /dev/null)
+
+               setfattr --name=trusted.$name --value="$value" $file1 ||
+                       error "setxattr 'trusted.$name' failed"
+
+               # Try to set a garbage xattr.
+               value=0sVGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIGl0c2VsZi4=
+
+               setfattr --name=trusted.$name --value="$value" $file1 ||
+                       error "setxattr 'trusted.$name' failed"
+
+               # Try to remove the xattr from $file1. We don't care if this
+               # appears to succeed or fail, we just don't want there to be
+               # any changes or crashes.
+               setfattr --remove=$trusted.$name $file1 2> /dev/null
+       done
+
+       # Get 'after' xattrs of file1.
+       getfattr --absolute-names --dump --match=- $file1 > $xattr1
+
+       if ! diff $xattr0 $xattr1; then
+               error "before and after xattrs of '$file1' differ"
+       fi
+
+       rm -rf $file0 $file1 $xattr0 $xattr1
+
+       return 0
+}
+run_test 102n "silently ignore setxattr on internal trusted xattrs"
+
 run_acl_subtest()
 {
     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test
@@ -7863,11 +7963,15 @@ test_129() {
        ENOSPC=28
        EFBIG=27
 
+       rm -rf $DIR/$tdir
        test_mkdir -p $DIR/$tdir
 
-       MAX=$(stat -c%s "$DIR/$tdir")
+       # block size of mds1
+       local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
+       local MDSBLOCKSIZE=$($LCTL get_param -n mdc.*MDT0000*.blocksize)
+       local MAX=$((MDSBLOCKSIZE * 3))
        set_dir_limits $MAX
-       local I=0
+       local I=$(stat -c%s "$DIR/$tdir")
        local J=0
        while [ ! $I -gt $MAX ]; do
                $MULTIOP $DIR/$tdir/$J Oc
@@ -7875,18 +7979,22 @@ test_129() {
                #check two errors ENOSPC for new version of ext4 max_dir_size patch
                #mainline kernel commit df981d03eeff7971ac7e6ff37000bfa702327ef1
                #and EFBIG for previous versions
-               if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ] && [ $I -gt 0 ]; then
+               if [ $rc -eq $EFBIG -o $rc -eq $ENOSPC ]; then
                        set_dir_limits 0
                        echo "return code $rc received as expected"
-                       multiop $DIR/$tdir/$J Oc
-                       rc=$?
+                       multiop $DIR/$tdir/$J Oc ||
+                               error_exit "multiop failed w/o dir size limit"
+
                        I=$(stat -c%s "$DIR/$tdir")
-                       if [ $I -gt $MAX ] && [ $rc -eq 0 ]; then
-                               return 0
+
+                       if [ $(lustre_version_code $SINGLEMDS) -lt \
+                                       $(version_code 2.4.51) ]
+                       then
+                               [ $I -eq $MAX ] && return 0
                        else
-                               error_exit "return code $rc current dir size $I " \
-                                          "previous limit $MAX"
+                               [ $I -gt $MAX ] && return 0
                        fi
+                       error_exit "current dir size $I, previous limit $MAX"
                elif [ $rc -ne 0 ]; then
                        set_dir_limits 0
                        error_exit "return code $rc received instead of expected " \
@@ -9081,6 +9189,39 @@ test_154c() {
 }
 run_test 154c "lfs path2fid and fid2path multiple arguments"
 
+test_154d() {
+       [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.5.53) ]] &&
+               skip "Need MDS version at least 2.5.53" && return
+
+       if remote_mds; then
+               nid=$($LCTL list_nids | sed  "s/\./\\\./g")
+       else
+               nid="0@lo"
+       fi
+       local proc_ofile="mdt.*.exports.'$nid'.open_files"
+       local fd
+       local cmd
+
+       rm -f $DIR/$tfile
+       touch $DIR/$tfile
+
+       fid=$($LFS path2fid $DIR/$tfile)
+       # Open the file
+       fd=$(free_fd)
+       cmd="exec $fd<$DIR/$tfile"
+       eval $cmd
+       fid_list=$(do_facet $SINGLEMDS $LCTL get_param $proc_ofile)
+       echo $fid_list | grep $fid
+       rc=$?
+
+       cmd="exec $fd>/dev/null"
+       eval $cmd
+       if [ $rc -ne 0 ]; then
+               error "FID $fid not found in open files list $fid_list"
+       fi
+}
+run_test 154d "Verify open file fid"
+
 test_155_small_load() {
     local temp=$TMP/$tfile
     local file=$DIR/$tfile
@@ -9869,6 +10010,15 @@ obdecho_test() {
        local pages=${3:-64}
         local rc=0
         local id
+
+       local count=10
+       local obd_size=$(get_obd_size $node $OBD)
+       local page_size=$(get_page_size $node)
+       if [[ -n "$obd_size" ]]; then
+               local new_count=$((obd_size / (pages * page_size / 1024)))
+               [[ $new_count -ge $count ]] || count=$new_count
+       fi
+
         do_facet $node "$LCTL attach echo_client ec ec_uuid" || rc=1
         [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec setup $OBD" ||
                            rc=2; }
@@ -9880,7 +10030,7 @@ obdecho_test() {
        [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec getattr $id" ||
                           rc=4; }
        [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec "                 \
-                          "test_brw 10 w v $pages $id" || rc=4; }
+                          "test_brw $count w v $pages $id" || rc=4; }
        [ $rc -eq 0 ] && { do_facet $node "$LCTL --device ec destroy $id 1" ||
                           rc=4; }
        [ $rc -eq 0 -o $rc -gt 2 ] && { do_facet $node "$LCTL --device ec "    \
@@ -10845,7 +10995,7 @@ test_208() {
 run_test 208 "Exclusive open"
 
 test_209() {
-       [[ $($LCTL get_param -n mdc.*.connect_flags) == ~disp_stripe ]] &&
+       [ -z "$(lctl get_param -n mdc.*.connect_flags | grep disp_stripe)" ] &&
                skip_env "must have disp_stripe" && return
 
        touch $DIR/$tfile
@@ -11123,6 +11273,10 @@ test_219() {
         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 seek=3
         $LCTL set_param fail_loc=0x411
         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 seek=2 conv=notrunc
+
+       # LU-4201
+       dd if=/dev/zero of=$DIR/$tfile-2 bs=1024 count=1
+       $CHECKSTAT -s 1024 $DIR/$tfile-2 || error "checkstat wrong size"
 }
 run_test 219 "LU-394: Write partial won't cause uncontiguous pages vec at LND"
 
@@ -11698,7 +11852,7 @@ test_232() {
 }
 run_test 232 "failed lock should not block umount"
 
-test_233() {
+test_233a() {
        [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.64) ] ||
        { skip "Need MDS version at least 2.3.64"; return; }
 
@@ -11706,7 +11860,21 @@ test_233() {
        stat $MOUNT/.lustre/fid/$fid > /dev/null ||
                error "cannot access $MOUNT using its FID '$fid'"
 }
-run_test 233 "checking that OBF of the FS root succeeds"
+run_test 233a "checking that OBF of the FS root succeeds"
+
+test_233b() {
+       [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.90) ] ||
+       { skip "Need MDS version at least 2.5.90"; return; }
+
+       local fid=$($LFS path2fid $MOUNT/.lustre)
+       stat $MOUNT/.lustre/fid/$fid > /dev/null ||
+               error "cannot access $MOUNT/.lustre using its FID '$fid'"
+
+       fid=$($LFS path2fid $MOUNT/.lustre/fid)
+       stat $MOUNT/.lustre/fid/$fid > /dev/null ||
+               error "cannot access $MOUNT/.lustre/fid using its FID '$fid'"
+}
+run_test 233b "checking that OBF of the FS .lustre succeeds"
 
 test_234() {
        local p="$TMP/sanityN-$TESTNAME.parameters"
@@ -11762,11 +11930,14 @@ test_236() {
        cp $ref1 $file1 || error "cp $ref1 $file1 failed: rc = $?"
        $SETSTRIPE -c 2 $file2 || error "cannot setstripe on '$file2': rc = $?"
        cp $ref2 $file2 || error "cp $ref2 $file2 failed: rc = $?"
-       exec {FD}<>$file2
+       local fd=$(free_fd)
+       local cmd="exec $fd<>$file2"
+       eval $cmd
        rm $file2
-       $LFS swap_layouts $file1 /proc/self/fd/${FD} ||
-               error "cannot swap layouts of '$file1' and /proc/self/fd/${FD}"
-       exec {FD}>&-
+       $LFS swap_layouts $file1 /proc/self/fd/${fd} ||
+               error "cannot swap layouts of '$file1' and /proc/self/fd/${fd}"
+       cmd="exec $fd>&-"
+       eval $cmd
        cmp $ref2 $file1 || error "content compare failed ($ref2 != $file1)"
 
        #cleanup