fstests: Make ./new work for non-root user
[xfstests-dev.git] / common / rc
index ffe5323603ebbee930eeb8183ac15ba1e4537f18..9273ff75c9dc2213df1993953d07f90317700289 100644 (file)
--- a/common/rc
+++ b/common/rc
 #  Mountain View, CA 94043, USA, or: http://www.sgi.com
 #-----------------------------------------------------------------------
 
-BC=$(which bc 2> /dev/null) || BC=
+. common/config
 
-# Valid test names start with 3 digits "NNN":
-#  "[0-9]\{3\}"
-# followed by an optional "-":
-#  "-\?"
-# followed by an optional combination of alphanumeric and "-" chars:
-#  "[[:alnum:]-]*"
-# e.g. 999-the-mark-of-fstests
-#
-VALID_TEST_ID="[0-9]\{3\}"
-VALID_TEST_NAME="$VALID_TEST_ID-\?[[:alnum:]-]*"
+BC=$(which bc 2> /dev/null) || BC=
 
 # Some tests are not relevant or functional when testing XFS realtime
 # subvolumes along with the rtinherit=1 mkfs option.  In these cases,
@@ -110,16 +101,6 @@ _ls_l()
        ls -l $* | sed "s/\(^[-rwxdlbcpsStT]*\)\. /\1 /" | grep -v 'lost+found'
 }
 
-# we need common/config
-if [ "$iam" != "check" ]
-then
-    if ! . ./common/config
-        then
-        echo "$iam: failed to source common/config"
-        exit 1
-    fi
-fi
-
 _dump_err()
 {
     _err_msg="$*"
@@ -2144,6 +2125,9 @@ _require_xfs_io_command()
                echo $testio | grep -q "Inappropriate ioctl" && \
                        _notrun "xfs_io $command support is missing"
                ;;
+       "label")
+               testio=`$XFS_IO_PROG -c "label" $TEST_DIR 2>&1`
+               ;;
        "open")
                # -c "open $f" is broken in xfs_io <= 4.8. Along with the fix,
                # a new -C flag was introduced to execute one shot commands.
@@ -2182,7 +2166,7 @@ _require_xfs_io_command()
        rm -f $testfile 2>&1 > /dev/null
        echo $testio | grep -q "not found" && \
                _notrun "xfs_io $command support is missing"
-       echo $testio | grep -q "Operation not supported" && \
+       echo $testio | grep -q "Operation not supported\|Inappropriate ioctl" && \
                _notrun "xfs_io $command failed (old kernel/wrong fs?)"
        echo $testio | grep -q "Invalid" && \
                _notrun "xfs_io $command failed (old kernel/wrong fs/bad args?)"
@@ -2222,6 +2206,19 @@ _require_odirect()
        rm -f $testfile 2>&1 > /dev/null
 }
 
+_format_swapfile() {
+       local fname="$1"
+       local sz="$2"
+
+       rm -f "$fname"
+       touch "$fname"
+       chmod 0600 "$fname"
+       # Swap files must be nocow on Btrfs.
+       $CHATTR_PROG +C "$fname" > /dev/null 2>&1
+       _pwrite_byte 0x61 0 "$sz" "$fname" >> $seqres.full
+       mkswap "$fname" >> $seqres.full
+}
+
 # Check that the filesystem supports swapfiles
 _require_scratch_swapfile()
 {
@@ -2231,10 +2228,8 @@ _require_scratch_swapfile()
        _scratch_mount
 
        # Minimum size for mkswap is 10 pages
-       local size=$(($(get_page_size) * 10))
+       _format_swapfile "$SCRATCH_MNT/swap" $(($(get_page_size) * 10))
 
-       _pwrite_byte 0x61 0 "$size" "$SCRATCH_MNT/swap" >/dev/null 2>&1
-       mkswap "$SCRATCH_MNT/swap" >/dev/null 2>&1
        if ! swapon "$SCRATCH_MNT/swap" >/dev/null 2>&1; then
                _scratch_unmount
                _notrun "swapfiles are not supported"
@@ -3560,10 +3555,6 @@ _disable_dmesg_check()
 
 init_rc()
 {
-       if [ "$iam" == new ]
-       then
-               return
-       fi
        # make some further configuration checks here
        if [ "$TEST_DEV" = ""  ]
        then
@@ -3788,6 +3779,29 @@ _require_scratch_feature()
        esac
 }
 
+# The maximum filesystem label length, /not/ including terminating NULL
+_label_get_max()
+{
+       case $FSTYP in
+       xfs)
+               echo 12
+               ;;
+       btrfs)
+               echo 255
+               ;;
+       *)
+               _notrun "$FSTYP does not define maximum label length"
+               ;;
+       esac
+}
+
+# Helper to check above early in a script
+_require_label_get_max()
+{
+       # Just call _label_get_max which will notrun if appropriate
+       dummy=$(_label_get_max)
+}
+
 init_rc
 
 ################################################################################