Add xfsdump support for the security extended attributes namespace.
[xfstests-dev.git] / common.dump
index 7191d1d6e33409d8f7694d28b16b33509fb9f55c..fa38afb9f2247fb2b005b9a27c752ef873f4b444 100644 (file)
@@ -3,7 +3,7 @@
 #
 # Functions useful for xfsdump/xfsrestore tests
 #
-# Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+# Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
 # 
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of version 2 of the GNU General Public License as
@@ -35,7 +35,7 @@
 #
 
 # --- initializations ---
-rm -f $seq.full
+rm -f $here/$seq.full
 
 if [ -n "$DEBUGDUMP" ]; then
   _dump_debug=-v5
@@ -81,16 +81,8 @@ for dir in /var/xfsdump/inventory /var/lib/xfsdump/inventory; do
     fi
 done
 
-# remove this when xfstests irix/linux port done
-if [ "X$XFS_HOST_OS" = "Xirix" ]
-then # IRIX
-    have_mtvariable=false
-    MKFS_OPTS=""
-else # Linux
-    have_mtvariable=true
-    MKFS_OPTS="-f"
-fi
-
+have_mtvariable=false
+[ `uname` = "Linux" ] && have_mtvariable=true
 
 #
 # do a remote/local mt
@@ -122,7 +114,7 @@ _check_onl()
     _limit=10
     i=0
     while [ $i -lt $_limit ]; do  
-        echo "Checking online..." >>$seq.full
+        echo "Checking online..." >>$here/$seq.full
        if _mt status >$tmp.status 2>&1; then
            break; 
        else
@@ -156,12 +148,12 @@ _check_onl()
 
 _wait_tape()
 {
-    echo "Wait for tape, $dumptape, ..." >>$seq.full
+    echo "Wait for tape, $dumptape, ..." >>$here/$seq.full
 
     i=0
     while [ $i -lt 20 ]; do  
-        echo "Checking status..." >>$seq.full
-       if _mt status 2>&1 | tee -a $seq.full | egrep -i "onl|ready" >/dev/null; then
+        echo "Checking status..." >>$here/$seq.full
+       if _mt status 2>&1 | tee -a $here/$seq.full | egrep -i "onl|ready" >/dev/null; then
            break; 
        else
            sleep 2 
@@ -175,7 +167,7 @@ _wait_tape()
 #
 _rewind()
 {
-    echo "Initiate rewind..." >>$seq.full
+    echo "Initiate rewind..." >>$here/$seq.full
     _wait_tape
     _mt rewind >/dev/null
     _wait_tape
@@ -188,7 +180,7 @@ _rewind()
 #
 _erase_soft()
 {
-    echo "Erasing tape" | tee -a $seq.full
+    echo "Erasing tape" | tee -a $here/$seq.full
     _rewind
     _mt weof 3
     _rewind
@@ -196,7 +188,7 @@ _erase_soft()
 
 _erase_hard()
 {
-    echo "Erasing tape" | tee -a $seq.full
+    echo "Erasing tape" | tee -a $here/$seq.full
     _mt erase
 }
 
@@ -236,23 +228,12 @@ _require_tape()
     _set_variable
 }
 
-_error()
-{
-    echo "Error: $*" | tee -a $seq.full
-    echo "(see $seq.full for details)"
-    status=1
-    exit
-}
-
 _wipe_fs()
 {
     _require_scratch
 
-    mkfs_xfs $MKFS_OPTS $SCRATCH_DEV>>$seq.full  ||\
-       _error "mkfs failed"
-      
-    mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
-       _error "mount failed"
+    _scratch_mkfs_xfs >>$here/$seq.full || _fail "mkfs failed"
+    _scratch_mount >>$here/$seq.full || _fail "mount failed"
 }
 
 # 
@@ -281,11 +262,11 @@ _cleanup()
     done
 
     if [ $status -ne $NOTRUNSTS ]; then
-       # Sleep added to stop _check_fs from complaining that the
+       # Sleep added to stop _check_scratch_fs from complaining that the
        # scratch_dev is still busy
        sleep 10
 
-       _check_fs $SCRATCH_DEV
+       _check_scratch_fs
     fi
 }
 
@@ -297,22 +278,20 @@ _cleanup()
 _stable_fs()
 {
     _saveddir=`pwd`; cd /
-    umount $SCRATCH_MNT >>$seq.full ||\
-       _error "unmount failed"
-    mount -t xfs $SCRATCH_DEV $SCRATCH_MNT >>$seq.full ||\
-       _error "mount failed"
+    umount $SCRATCH_MNT >>$here/$seq.full || _fail "unmount failed"
+    _scratch_mount >>$here/$seq.full || _fail "mount failed"
     cd $_saveddir
 }
 
 #
-# Run src/fsstress to create a mixture of 
+# Run fsstress to create a mixture of 
 # files,dirs,links,symlinks
 #
 # Pinched from test 013.
 #
 _create_dumpdir_stress()
 {
-    echo "Creating directory system to dump using src/fsstress."
+    echo "Creating directory system to dump using fsstress."
 
     _wipe_fs
 
@@ -328,14 +307,14 @@ _create_dumpdir_stress()
     echo "-----------------------------------------------"
     echo "fsstress : $_param"
     echo "-----------------------------------------------"
-    if ! $here/src/fsstress $_param -s 1 $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
+    if ! $here/ltp/fsstress $_param -s 1 $FSSTRESS_AVOID -n $_count -d $dump_dir >$tmp.out 2>&1
     then
-        echo "    fsstress (count=$_count) returned $? - see $seq.full"
+        echo "    fsstress (count=$_count) returned $? - see $here/$seq.full"
         
-        echo "--------------------------------------"       >>$here/$seq.full
-        echo "output from fsstress:"                        >>$here/$seq.full
-        echo "--------------------------------------"       >>$here/$seq.full
-        cat $tmp.out                                        >>$here/$seq.full
+        echo "--------------------------------------"       >>$here/$here/$seq.full
+        echo "output from fsstress:"                        >>$here/$here/$seq.full
+        echo "--------------------------------------"       >>$here/$here/$seq.full
+        cat $tmp.out                                        >>$here/$here/$seq.full
         status=1
     fi
 
@@ -424,13 +403,13 @@ End-of-File
 _mk_fillconfig_ea()
 {
     cat <<End-of-File >$tmp.config
-# pathname     size    user    group    perm   name value
+# pathname     size    user    group    perm   name value namespace
 #
-smalll         10      $nobody $nobody  777    attr1 some_text    
-biggg          102400  $nobody $nobody  777    attr2 some_text2
-sub/smalll     10      $nobody $nobody  777    attr3 some_text3
-sub/biggg      102400  $nobody $nobody  777    attr4 some_text4
-dir            d       $nobody $nobody  777    attr5 dir_text
+smalll         10      $nobody $nobody  777    attr1 some_text   user 
+biggg          102400  $nobody $nobody  777    attr2 some_text2  root
+sub/smalll     10      $nobody $nobody  777    attr3 some_text3  user
+sub/biggg      102400  $nobody $nobody  777    attr4 some_text4  root
+dir            d       $nobody $nobody  777    attr5 dir_text    user
 #
 # Add more files so that there are more than the number
 # of streams.
@@ -455,6 +434,25 @@ sub/n              8192    $nobody $nobody
 End-of-File
 }
 
+#
+# extended file attribute flags
+#
+_mk_fillconfig_xattr()
+{
+    cat <<End-of-File >$tmp.config
+# pathname     size    user    group    perm   name 
+#
+xflag_realtime 10      $nobody $nobody  777    XFS_XFLAG_REALTIME
+xflag_prealloc 10      $nobody $nobody  777    XFS_XFLAG_PREALLOC
+xflag_immutable 10     $nobody $nobody  777    XFS_XFLAG_IMMUTABLE
+xflag_append   10      $nobody $nobody  777    XFS_XFLAG_APPEND
+xflag_sync     10      $nobody $nobody  777    XFS_XFLAG_SYNC
+xflag_noatime  10      $nobody $nobody  777    XFS_XFLAG_NOATIME
+xflag_nodump   10      $nobody $nobody  777    XFS_XFLAG_NODUMP
+xflag_hasattr  10      $nobody $nobody  777    XFS_XFLAG_HASATTR
+End-of-File
+}
+
 #
 # Create a bunch of directories/files of different sizes
 # filled with data.
@@ -465,13 +463,12 @@ _do_create_dumpdir_fill()
 {
     echo "Creating directory system to dump using src/fill."
 
-    mkdir -p $dump_dir ||\
-       _error "cannot mkdir \"$dump_dir\""
+    mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
     cd $dump_dir
 
     $verbose && echo -n "Setup "
     sed -e '/^#/d' $tmp.config \
-    | while read file nbytes owner group perms ea_name ea_value
+    | while read file nbytes owner group perms ea_name ea_value namespace
     do
        if [ $nbytes = "d" ]; then
            # create a directory
@@ -520,8 +517,19 @@ _do_create_dumpdir_fill()
        if [ -n "$perms" ]; then
            chmod $perms $file
        fi
+       # extended attributes (EA)
        if [ -n "$ea_name" -a -n "$ea_value" ]; then
-           attr -s $ea_name -V $ea_value $file
+           if [ "X$namespace" = "Xroot" ]; then
+               attr -R -s $ea_name -V $ea_value $file
+           else
+               attr -s $ea_name -V $ea_value $file
+           fi
+       # extended file attribute flags - no value - NOT EAs
+       elif [ -n "$ea_name" -a -z "$ea_value" ]; then
+           # set the flag
+           # TODO XXX
+            # use xfs_io to send the ioctl
+           :
        fi
        $verbose && echo -n "."
     done
@@ -530,6 +538,17 @@ _do_create_dumpdir_fill()
     cd $here
 }
 
+_create_dumpdir_largefile()
+{
+    _wipe_fs
+    mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
+    _largesize=4294967297
+    _largefile=$dump_dir/largefile
+    echo "dd a largefile at offset $_largesize"
+    POSIXLY_CORRECT=yes \
+    dd if=/dev/zero of=$_largefile bs=1 seek=$_largesize count=10 2>&1
+    _stable_fs
+}      
 
 _create_dumpdir_fill()
 {
@@ -595,8 +614,7 @@ _do_create_dump_symlinks()
 {
     echo "Creating directory system of symlinks to dump."
 
-    mkdir -p $dump_dir ||\
-       _error "cannot mkdir \"$dump_dir\""
+    mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
     cd $dump_dir
 
     $verbose && echo -n "Setup "
@@ -718,8 +736,7 @@ _create_dumpdir_hardlinks()
     _wipe_fs
     echo "Creating directory system of hardlinks to incrementally dump."
 
-    mkdir -p $dump_dir ||\
-       _error "cannot mkdir \"$dump_dir\""
+    mkdir -p $dump_dir || _fail "cannot mkdir \"$dump_dir\""
     cd $dump_dir
 
     _create_hardset $_numsets
@@ -731,14 +748,17 @@ _create_dumpdir_hardlinks()
 #
 # Filter for ls
 # Filter out dates on symlinks and char devices
+# Filter out size on directories because this can differ
+# when transitioning to long inode numbers (ie. 64 bits).
 #
 _ls_filter()
 {
   $AWK_PROG '
         /^l/ { date = $8; sub(date,"DATE"); print}
         /^c/ { date = $9; sub(date,"DATE"); print}
+        /^d/ { size = $5; sub(size,"SIZE"); print}
         {print}' \
-  | sed -e 's/total [0-9][0-9]*/total TOTAL/'
+  | sed -e 's/total [0-9][0-9]*/total TOTAL/' -e 's/[ \t][ \t]*/ /g'
 }
 
 
@@ -835,12 +855,12 @@ _parse_args()
         case $1
         in
         -f)
-            [ -z "$2" ] && _error "missing argument for -f"
+            [ -z "$2" ] && _fail "missing argument for -f"
            dumptape=$2 
            shift
             ;;
         -L)
-            [ -z "$2" ] && _error "missing argument for -L"
+            [ -z "$2" ] && _fail "missing argument for -L"
            session_label=$2
            shift
             ;;
@@ -861,12 +881,12 @@ _parse_args()
             do_quota_check=false
             ;;
         -l)
-            [ -z "$2" ] && _error "missing argument for -l"
+            [ -z "$2" ] && _fail "missing argument for -l"
            dump_args="$dump_args -l$2"
            shift
             ;;
        *)
-            _error "invalid argument to common.dump function: $1"
+            _fail "invalid argument to common.dump function: $1"
             ;;
         esac
        shift
@@ -884,7 +904,7 @@ _do_dump_sub()
     echo "Dumping to tape..."
     opts="$_dump_debug$dump_args -s $dump_sdir -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
     echo "xfsdump $opts" | _dir_filter  
-    xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsdump $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
@@ -897,7 +917,7 @@ _do_dump()
     echo "Dumping to tape..."
     opts="$_dump_debug$dump_args -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
     echo "xfsdump $opts" | _dir_filter  
-    xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsdump $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 
@@ -912,7 +932,7 @@ _do_dump_min()
     onemeg=1048576
     opts="$_dump_debug$dump_args -m -b $onemeg -l0 -f $dumptape -M $media_label -L $session_label $SCRATCH_MNT"
     echo "xfsdump $opts" | _dir_filter  
-    xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsdump $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 
@@ -926,7 +946,7 @@ _do_dump_file()
     echo "Dumping to file..."
     opts="$_dump_debug$dump_args -f $dump_file -M $media_label -L $session_label $SCRATCH_MNT"
     echo "xfsdump $opts" | _dir_filter  
-    xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsdump $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
@@ -948,15 +968,14 @@ _do_dump_multi_file()
     echo "Dumping to files..."
     opts="$_dump_debug$dump_args $multi_args -L $session_label $SCRATCH_MNT"
     echo "xfsdump $opts" | _dir_filter  
-    xfsdump $opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsdump $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 
 _prepare_restore_dir()
 {
     rm -rf $restore_dir
-    mkdir $restore_dir ||\
-       _error "failed to mkdir $restore_dir"
+    mkdir $restore_dir || _fail "failed to mkdir $restore_dir"
 }
 
 
@@ -983,7 +1002,7 @@ _do_restore()
     echo "Restoring from tape..."
     opts="$_restore_debug -f $dumptape  -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter  
-    xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
@@ -998,7 +1017,7 @@ _do_restore_min()
     onemeg=1048576
     opts="$_restore_debug -m -b $onemeg -f $dumptape  -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter  
-    xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
@@ -1012,7 +1031,7 @@ _do_restore_file()
     echo "Restoring from file..."
     opts="$_restore_debug -f $dump_file  -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter  
-    xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
@@ -1029,7 +1048,7 @@ _do_restore_file_cum()
     echo "Restoring cumumlative from file..."
     opts="$_restore_debug -f $dump_file -r $restore_dir"
     echo "xfsrestore $opts" | _dir_filter  
-    xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 _do_restore_toc()
@@ -1038,7 +1057,7 @@ _do_restore_toc()
     opts="$_restore_debug -f $dump_file -t"
     echo "xfsrestore $opts" | _dir_filter
     cd $SCRATCH_MNT # for IRIX which needs xfs cwd
-    xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter_main |\
+    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter_main |\
     _check_quota_file |\
     _check_quota_entries |\
     $AWK_PROG 'NF != 1 { print; next }
@@ -1069,7 +1088,7 @@ _do_restore_multi_file()
     echo "Restoring from file..."
     opts="$_restore_debug $multi_args -L $session_label $restore_dir"
     echo "xfsrestore $opts" | _dir_filter  
-    xfsrestore $opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsrestore $opts 2>&1 | tee -a $here/$seq.full | _dump_filter
 }
 
 #
@@ -1085,7 +1104,7 @@ _do_dump_restore()
     restore_opts="$_restore_debug - $restore_dir"
     dump_opts="$_dump_debug$dump_args -s $dump_sdir - $SCRATCH_MNT"
     echo "xfsdump $dump_opts | xfsrestore $restore_opts" | _dir_filter  
-    xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $seq.full | _dump_filter
+    xfsdump $dump_opts 2>$tmp.dump.mlog | xfsrestore $restore_opts 2>&1 | tee -a $here/$seq.full | _dump_filter
     _dump_filter <$tmp.dump.mlog
 }
 
@@ -1101,8 +1120,8 @@ _ls_compare_sub()
     # verify we got back what we dumped
     #
     echo "Comparing listing of dump directory with restore directory"
-    ls -lR $dump_dir | tee -a $seq.full | _ls_filter >$tmp.dump_dir
-    ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
+    ls -lR $dump_dir | tee -a $here/$seq.full | _ls_filter >$tmp.dump_dir
+    ls -lR $restore_dir/$dump_sdir | tee -a $here/$seq.full | _ls_filter \
     | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
 
     diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
@@ -1124,8 +1143,8 @@ _ls_nodate_compare_sub()
     # verify we got back what we dumped
     #
     echo "Comparing listing of dump directory with restore directory"
-    ls -lR $dump_dir | tee -a $seq.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
-    ls -lR $restore_dir/$dump_sdir | tee -a $seq.full | _ls_filter \
+    ls -lR $dump_dir | tee -a $here/$seq.full | _ls_filter | _ls_nodate_filter >$tmp.dump_dir
+    ls -lR $restore_dir/$dump_sdir | tee -a $here/$seq.full | _ls_filter \
     | _ls_nodate_filter | sed -e "s#$restore_sdir\/##" >$tmp.restore_dir
 
     diff -cs $tmp.dump_dir $tmp.restore_dir | sed -e "s#$tmp#TMP#g"
@@ -1152,7 +1171,8 @@ _get_eas_on_path()
     # sed 's/["]//g' |\
     # sort |\
 # and this is now the Linux way...
-    getfattr --absolute-names -Rh $_path |\
+    echo "User names"
+    getfattr --absolute-names -Rh -m user $_path |\
     perl -wn -e '
        if (m/^# file: (\S+)/) { $file = $1 }
        elsif (m/^user\.(\w+)/) { print $file, " ",$1,"\n" }' |\
@@ -1160,6 +1180,28 @@ _get_eas_on_path()
     while read file ea_name; do
        attr -g $ea_name $file
     done
+
+    if [ "$USE_ATTR_SECURE" = yes ]; then
+       echo "Security names"
+       getfattr --absolute-names -Rh -m security $_path |\
+       perl -wn -e '
+           if (m/^# file: (\S+)/) { $file = $1 }
+           elsif (m/^security\.(\w+)/) { print $file, " ",$1,"\n" }' |\
+       sort |\
+       while read file ea_name; do
+           attr -g $ea_name $file
+       done
+    fi
+
+    echo "Root names"
+    getfattr --absolute-names -Rh -m trusted $_path |\
+    perl -wn -e '
+       if (m/^# file: (\S+)/) { $file = $1 }
+       elsif (m/^trusted\.(\w+)/) { print $file, " ",$1,"\n" }' |\
+    sort |\
+    while read file ea_name; do
+       attr -R -g $ea_name $file
+    done
 }
 
 #
@@ -1200,7 +1242,7 @@ _diff_compare()
 #
 _dump_inventory()
 {
-    xfsdump $_dump_debug -I | tee -a $seq.full | _dump_filter_main
+    xfsdump $_dump_debug -I | tee -a $here/$seq.full | _dump_filter_main
 }
 
 #
@@ -1210,9 +1252,9 @@ _dump_inventory()
 _do_invutil()
 {
     host=`hostname`
-    echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$seq.full
+    echo "xfsinvutil $_invutil_debug -M $host:$SCRATCH_MNT \"$middate\" $*" >$here/$seq.full
     xfsinvutil $_invutil_debug $* -M $host:$SCRATCH_MNT "$middate" \
-    | tee -a $seq.full | _invutil_filter
+    | tee -a $here/$seq.full | _invutil_filter
 }
 
 #
@@ -1228,7 +1270,7 @@ _check_quota()
     $here/src/feature -U $SCRATCH_DEV && uquota=1
     $here/src/feature -G $SCRATCH_DEV && gquota=1
 
-    $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v full=$seq.full \
+    $AWK_PROG -v uquota=$uquota -v gquota=$gquota -v full=$here/$seq.full \
               -v usermsg="$usermsg" -v groupmsg="$groupmsg" '
        $0 ~ groupmsg {
                        print "Found group quota:", $0 >>full