]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common/ext4: provide custom ext4 scratch fs options
authorDarrick J. Wong <djwong@kernel.org>
Tue, 9 Aug 2022 21:00:58 +0000 (14:00 -0700)
committerZorro Lang <zlang@kernel.org>
Sat, 20 Aug 2022 14:08:28 +0000 (22:08 +0800)
Create a _scratch_options backend for ext* so that we can inject
pathnames to external log devices into the scratch fs mount options.
This enables common/dm* to install block device filters, e.g. dm-error
for stress testing.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/ext4
common/rc

index 287705afe2cc849aa95615070bb314681112eec2..f4c3c4139a150657234d28324aa4d485d86b31b1 100644 (file)
@@ -63,16 +63,32 @@ _setup_large_ext4_fs()
        return 0
 }
 
+_scratch_mkfs_ext4_opts()
+{
+       mkfs_opts=$*
+
+       _scratch_options mkfs
+
+       echo "$MKFS_EXT4_PROG $SCRATCH_OPTIONS $mkfs_opts"
+}
+
 _scratch_mkfs_ext4()
 {
-       local mkfs_cmd="$MKFS_EXT4_PROG -F"
+       local mkfs_cmd="`_scratch_mkfs_ext4_opts`"
        local mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \" | grep -v \"^$\""
        local tmp=`mktemp -u`
        local mkfs_status
 
-       [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
-           $mkfs_cmd -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV && \
-           mkfs_cmd="$mkfs_cmd -J device=$SCRATCH_LOGDEV"
+       if [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ]; then
+               $MKFS_EXT4_PROG -F -O journal_dev $MKFS_OPTIONS $* $SCRATCH_LOGDEV 2>$tmp.mkfserr 1>$tmp.mkfsstd
+               mkjournal_status=$?
+
+               if [ $mkjournal_status -ne 0 ]; then
+                       cat $tmp.mkfsstd
+                       cat $tmp.mkfserr >&2
+                       return $mkjournal_status
+               fi
+       fi
 
        _scratch_do_mkfs "$mkfs_cmd" "$mkfs_filter" $* 2>$tmp.mkfserr 1>$tmp.mkfsstd
        mkfs_status=$?
@@ -154,3 +170,24 @@ _require_scratch_richacl_ext4()
                || _notrun "kernel doesn't support richacl feature on $FSTYP"
        _scratch_unmount
 }
+
+_scratch_ext4_options()
+{
+       local type=$1
+       local log_opt=""
+
+       case $type in
+       mkfs)
+               SCRATCH_OPTIONS="$SCRATCH_OPTIONS -F"
+               log_opt="-J device=$SCRATCH_LOGDEV"
+               ;;
+       mount)
+               # As of kernel 5.19, the kernel mount option path parser only
+               # accepts direct paths to block devices--the final path
+               # component cannot be a symlink.
+               log_opt="-o journal_path=$(realpath -q "$SCRATCH_LOGDEV")"
+               ;;
+       esac
+       [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+               SCRATCH_OPTIONS="$SCRATCH_OPTIONS ${log_opt}"
+}
index dc1d65c3cc9076e49e5dcbf21712fa8cd5e257c6..e20c494c70204d35534fd4c8ef6f0c71d69a6669 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -178,6 +178,9 @@ _scratch_options()
     "xfs")
        _scratch_xfs_options "$@"
        ;;
+    ext2|ext3|ext4|ext4dev)
+       _scratch_ext4_options "$@"
+       ;;
     esac
 }
 
@@ -964,6 +967,13 @@ _scratch_mkfs_sized()
                fi
                ;;
        ext2|ext3|ext4|ext4dev)
+               # Can't use _scratch_mkfs_ext4 here because the block count has
+               # to come after the device path.
+               if [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ]; then
+                       ${MKFS_PROG} -F -O journal_dev $MKFS_OPTIONS $SCRATCH_LOGDEV || \
+                               _notrun "Could not make scratch logdev"
+                       MKFS_OPTIONS="$MKFS_OPTIONS -J device=$SCRATCH_LOGDEV"
+               fi
                ${MKFS_PROG} -t $FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV $blocks
                ;;
        gfs2)
@@ -1093,7 +1103,7 @@ _scratch_mkfs_blocksized()
                _scratch_mkfs_xfs $MKFS_OPTIONS -b size=$blocksize
                ;;
        ext2|ext3|ext4)
-               ${MKFS_PROG} -t $FSTYP -F $MKFS_OPTIONS -b $blocksize $SCRATCH_DEV
+               _scratch_mkfs_ext4 $MKFS_OPTIONS -b $blocksize
                ;;
        gfs2)
                ${MKFS_PROG} -t $FSTYP $MKFS_OPTIONS -O -b $blocksize $SCRATCH_DEV