xfstests: support post-udev device mapper nodes
[xfstests-dev.git] / common.rc
index 6bf1e12782ec0f1de82223924d87e1a8b746a3a3..e634fbb359392808ffb25888504742b3a1f46655 100644 (file)
--- a/common.rc
+++ b/common.rc
@@ -327,7 +327,10 @@ _scratch_mkfs_sized()
        _scratch_mkfs_xfs -d size=$fssize -b size=$blocksize
        ;;
     ext2|ext3|ext4)
-       /sbin/mkfs.$FSTYP -b $blocksize $SCRATCH_DEV $blocks
+       /sbin/mkfs.$FSTYP $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
+       ;;
+     btrfs)
+       /sbin/mkfs.$FSTYP $MKFS_OPTIONS $SCRATCH_DEV -b $fssize
        ;;
     *)
        _notrun "Filesystem $FSTYP not supported in _scratch_mkfs_sized"
@@ -349,10 +352,10 @@ _scratch_mkfs_geom()
 
     case $FSTYP in
     xfs)
-       MKFS_OPTIONS="-b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
+       MKFS_OPTIONS+=" -b size=$blocksize, -d su=$sunit_bytes,sw=$swidth_mult"
        ;;
     ext4)
-       MKFS_OPTIONS="-b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
+       MKFS_OPTIONS+=" -b $blocksize -E stride=$sunit_blocks,stripe_width=$swidth_blocks"
        ;;
     *)
        _notrun "can't mkfs $FSTYP with geometry"
@@ -584,7 +587,14 @@ _is_block_dev()
        exit 1
     fi
 
-    [ -b $1 ] && src/lstat64 $1 | $AWK_PROG '/Device type:/ { print $9 }'
+    _dev=$1
+    if [ -L "${_dev}" ]; then
+        _dev=`readlink -f ${_dev}`
+    fi
+
+    if [ -b "${_dev}" ]; then
+        src/lstat64 ${_dev} | $AWK_PROG '/Device type:/ { print $9 }'
+    fi
 }
 
 # Do a command, log it to $seq.full, optionally test return status
@@ -703,6 +713,10 @@ _require_scratch()
                 then
                     _notrun "this test requires a valid \$SCRATCH_DEV"
                 fi
+               if [ ! -d "$SCRATCH_MNT" ]
+               then
+                    _notrun "this test requires a valid \$SCRATCH_MNT"
+               fi
                 ;;
     esac
 
@@ -775,10 +789,12 @@ _require_realtime()
 }
 
 # this test requires that a specified command (executable) exists
+# $1 - command, $2 - name for error message
 #
 _require_command()
 {
-    [ -x "$1" ] || _notrun "$1 utility required, skipped this test"
+    [ -n "$1" ] && _cmd="$1" || _cmd="$2"
+    [ -n "$1" -a -x "$1" ] || _notrun "$_cmd utility required, skipped this test"
 }
 
 # this test requires that external log/realtime devices are not in use
@@ -789,12 +805,38 @@ _require_nonexternal()
        _notrun "External device testing in progress, skipped this test"
 }
 
+# indicate whether YP/NIS is active or not
+#
+_yp_active()
+{
+       local dn
+       dn=$(domainname 2>/dev/null)
+       test -n "${dn}" -a "${dn}" != "(none)"
+       echo $?
+}
+
+# cat the password file
+#
+_cat_passwd()
+{
+       [ $(_yp_active) -eq 0 ] && ypcat passwd
+       cat /etc/passwd
+}
+
+# cat the group file
+#
+_cat_group()
+{
+       [ $(_yp_active) -eq 0 ] && ypcat group
+       cat /etc/group
+}
+
 # check for the fsgqa user on the machine
 #
 _require_user()
 {
     qa_user=fsgqa
-    cat /etc/passwd | grep -q $qa_user
+    _cat_passwd | grep -q $qa_user
     [ "$?" == "0" ] || _notrun "$qa_user user not defined."
 }
 
@@ -812,6 +854,33 @@ _require_xfs_io_falloc()
                _notrun "xfs_io fallocate command failed (old kernel/wrong fs?)"
 }
 
+# check that xfs_io, kernel and filesystem all support fallocate with hole
+# punching
+_require_xfs_io_falloc_punch()
+{
+       testfile=$TEST_DIR/$$.falloc
+       testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
+               -c "fpunch 4k 8k" $testfile 2>&1`
+       rm -f $testfile 2>&1 > /dev/null
+       echo $testio | grep -q "not found" && \
+               _notrun "xfs_io fallocate punch support is missing"
+       echo $testio | grep -q "Operation not supported" && \
+               _notrun "xfs_io fallocate punch command failed (no fs support?)"
+}
+
+# check that xfs_io, kernel and filesystem support fiemap
+_require_xfs_io_fiemap()
+{
+       testfile=$TEST_DIR/$$.fiemap
+       testio=`$XFS_IO_PROG -F -f -c "pwrite 0 20k" -c "fsync" \
+               -c "fiemap -v" $testfile 2>&1`
+       rm -f $testfile 2>&1 > /dev/null
+       echo $testio | grep -q "not found" && \
+               _notrun "xfs_io fiemap support is missing"
+       echo $testio | grep -q "Operation not supported" && \
+               _notrun "xfs_io fiemap command failed (no fs support?)"
+}
+
 # Check that a fs has enough free space (in 1024b blocks)
 #
 _require_fs_space()
@@ -825,6 +894,22 @@ _require_fs_space()
                _notrun "This test requires at least ${GB}GB free on $MNT to run"
 }
 
+#
+# Check if the filesystem supports sparse files.
+#
+# Unfortunately there is no better way to do this than a manual black list.
+#
+_require_sparse_files()
+{
+    case $FSTYP in
+    hfsplus)
+        _notrun "Sparse files not supported by this filesystem type: $FSTYP"
+       ;;
+    *)
+        ;;
+    esac
+}
+
 # check that a FS on a device is mounted
 # if so, return mount point
 #