generic/620: fix order of require_scratch calls
[xfstests-dev.git] / common / rc
index 0ce3cb0d7668cf56c7cfa20632a2d03d110fc029..aa4ea7d4dd7be94144bd5a234006e51d4029a6a0 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -277,12 +277,11 @@ _mount_ops_filter()
     local params="$*"
     local last_index=$(( $# - 1 ))
 
-    #get mount point to handle dmapi mtpt option correctly
     [ $last_index -gt 0 ] && shift $last_index
     local fs_escaped=$1
 
-    echo $params | sed -e 's/dmapi/dmi/' \
-        $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$fs_escaped\1\2#; print;"
+    echo $params | \
+        $PERL_PROG -ne "s#mtpt=[^,|^\n|^\s]*#mtpt=$fs_escaped\1\2#; print;"
 
 }
 
@@ -343,6 +342,36 @@ _scratch_mount()
        _try_scratch_mount $* || _fail "mount failed"
 }
 
+_scratch_mount_idmapped()
+{
+       local type="$1"
+       local id="$2"
+
+       if [ "$type" = "u" ]; then
+               # This means root will be able to create files as uid %id in
+               # the underlying filesystem by going through the idmapped mount.
+               $here/src/idmapped-mounts/mount-idmapped --map-mount u:0:$id:1 \
+                                                        --map-mount u:$id:0:1 \
+                                                        --map-mount g:0:0:1 \
+                                                        "$SCRATCH_MNT" "$SCRATCH_MNT" || _fail "mount-idmapped failed"
+       elif [ "$type" = "g" ]; then
+               # This means root will be able to create files as gid %id in
+               # the underlying filesystem by going through the idmapped mount.
+               $here/src/idmapped-mounts/mount-idmapped --map-mount g:0:$id:1 \
+                                                        --map-mount g:$id:0:1 \
+                                                        --map-mount u:0:0:1 \
+                                                        "$SCRATCH_MNT" "$SCRATCH_MNT" || _fail "mount-idmapped failed"
+       elif [ "$type" = "b" ]; then
+               # This means root will be able to create files as uid and gid
+               # %id in the underlying filesystem by going through the idmapped mount.
+               $here/src/idmapped-mounts/mount-idmapped --map-mount b:0:$id:1 \
+                                                        --map-mount b:$id:0:1 \
+                                                        "$SCRATCH_MNT" "$SCRATCH_MNT" || _fail "mount-idmapped failed"
+       else
+               _fail "usage: either \"u\" (uid), \"g\" (gid), or \"b\" (uid and gid) must be specified "
+       fi
+}
+
 _scratch_unmount()
 {
        case "$FSTYP" in
@@ -358,6 +387,11 @@ _scratch_unmount()
        esac
 }
 
+_scratch_umount_idmapped()
+{
+       $UMOUNT_PROG $SCRATCH_MNT
+}
+
 _scratch_remount()
 {
     local opts="$1"
@@ -490,18 +524,6 @@ _scratch_do_mkfs()
        return $mkfs_status
 }
 
-_scratch_metadump()
-{
-       local dumpfile=$1
-       shift
-       local options=
-
-       [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
-               options="-l $SCRATCH_LOGDEV"
-
-       $XFS_METADUMP_PROG $options "$@" $SCRATCH_DEV $dumpfile
-}
-
 _setup_large_ext4_fs()
 {
        local fs_size=$1
@@ -597,6 +619,18 @@ _scratch_mkfs_ext4()
        return $mkfs_status
 }
 
+_ext4_metadump()
+{
+       local device="$1"
+       local dumpfile="$2"
+       local compressopt="$3"
+
+       test -n "$E2IMAGE_PROG" || _fail "e2image not installed"
+       $E2IMAGE_PROG -Q "$device" "$dumpfile"
+       [ "$compressopt" = "compress" ] && [ -n "$DUMP_COMPRESSOR" ] &&
+               $DUMP_COMPRESSOR "$dumpfile" &>> "$seqres.full"
+}
+
 _test_mkfs()
 {
     case $FSTYP in
@@ -1538,7 +1572,7 @@ _require_scratch_nocheck()
        tmpfs)
                if [ -z "$SCRATCH_DEV" -o ! -d "$SCRATCH_MNT" ];
                then
-                   _notrun "this test requires a valid \$SCRATCH_MNT and unique $SCRATCH_DEV"
+                   _notrun "this test requires a valid \$SCRATCH_MNT and unique \$SCRATCH_DEV"
                fi
                ;;
        ubifs)
@@ -1609,7 +1643,8 @@ _require_scratch_size_nocheck()
        [ $devsize -lt $1 ] && _notrun "scratch dev too small"
 }
 
-# require scratch fs which supports >16T of filesystem size.
+# Require scratch fs which supports >16T of filesystem size.
+# _require_scratch must be called before this function is called.
 _require_scratch_16T_support()
 {
        case $FSTYP in
@@ -1767,26 +1802,13 @@ _require_loop()
     fi
 }
 
-# this test requires ext2 filesystem support
-#
-_require_ext2()
-{
-    modprobe ext2 >/dev/null 2>&1
-    if grep ext2 /proc/filesystems >/dev/null 2>&1
-    then
-       :
-    else
-       _notrun "This test requires ext2 filesystem support"
-    fi
-}
-
-# this test requires tmpfs filesystem support
+# this test requires kernel support for a secondary filesystem
 #
-_require_tmpfs()
+_require_extra_fs()
 {
-       modprobe tmpfs >/dev/null 2>&1
-       grep -q tmpfs /proc/filesystems ||
-               _notrun "this test requires tmpfs support"
+       modprobe "$1" >/dev/null 2>&1
+       grep -q -w "$1" /proc/filesystems ||
+               _notrun "this test requires $1 support"
 }
 
 # this test requires that (large) loopback device files are not in use
@@ -1994,6 +2016,40 @@ _require_io_uring()
        esac
 }
 
+# test whether the mount_setattr syscall is available
+_require_mount_setattr()
+{
+       $here/src/feature -r
+       case $? in
+       0)
+               ;;
+       1)
+               _notrun "kernel does not support mount_setattr syscall"
+               ;;
+       *)
+               _fail "unexpected error testing for mount_setattr support"
+               ;;
+       esac
+}
+
+# test whether idmapped mounts are supported
+_require_idmapped_mounts()
+{
+        IDMAPPED_MOUNTS_TEST=$here/src/idmapped-mounts/idmapped-mounts
+        [ -x $IDMAPPED_MOUNTS_TEST ] || _notrun "idmapped-mounts utilities required"
+
+       _require_mount_setattr
+
+       $here/src/idmapped-mounts/idmapped-mounts --supported \
+               --device "$TEST_DEV" \
+               --mount "$TEST_DIR" \
+               --fstype "$FSTYP"
+
+       if [ $? -ne 0 ]; then
+               _notrun "idmapped-mounts not support by $FSTYP"
+       fi
+}
+
 # this test requires that a test program exists under src/
 # $1 - command (require)
 #
@@ -2742,6 +2798,15 @@ _check_generic_filesystem()
     fi
     rm -f $tmp.fsck
 
+    if [ $ok -eq 0 ] && [ -n "$DUMP_CORRUPT_FS" ]; then
+        case "$FSTYP" in
+        ext*)
+            local flatdev="$(basename "$device")"
+            _ext4_metadump "$seqres.$flatdev.check.qcow2" "$device" compress
+            ;;
+        esac
+    fi
+
     if [ $ok -eq 0 ]
     then
         echo "*** mount output ***"            >>$seqres.full
@@ -3573,7 +3638,7 @@ _require_atime()
 {
        _exclude_scratch_mount_option "noatime"
        case $FSTYP in
-       nfs|cifs)
+       nfs|cifs|virtiofs)
                _notrun "atime related mount options have no effect on $FSTYP"
                ;;
        esac
@@ -3782,7 +3847,7 @@ _get_available_space()
 # return device size in kb
 _get_device_size()
 {
-       grep -w `_short_dev $1` /proc/partitions | awk '{print $3}'
+       echo $(($(blockdev --getsz $1) >> 1))
 }
 
 # Make sure we actually have dmesg checking set up.