Whamcloud - gitweb
LU-4322 tests: disable sanity 101a in DNE
[fs/lustre-release.git] / lustre / tests / sanity.sh
index 53ff4d2..306157f 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))
@@ -2120,14 +2124,17 @@ test_31n() {
        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 +2163,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 +2371,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 +3141,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 +3158,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 +3987,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 +4703,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 +5812,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 +6412,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
@@ -10845,7 +10946,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
@@ -11762,11 +11863,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