]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
xfs: test filesystem creation with xfs_protofile
authorDarrick J. Wong <djwong@kernel.org>
Thu, 20 Feb 2025 21:47:05 +0000 (13:47 -0800)
committerZorro Lang <zlang@kernel.org>
Thu, 6 Mar 2025 13:25:55 +0000 (21:25 +0800)
Test how well we can format a fully populated filesystem with a
protofile that was generated with xfs_protofile.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/config
tests/xfs/818 [new file with mode: 0755]
tests/xfs/818.out [new file with mode: 0644]

index 0b01b205ee7a53770c69055a756a23082e7b2c4f..2afbda1417461d1a55af52261dff3b34e14d38d1 100644 (file)
@@ -161,6 +161,7 @@ export MKSWAP_PROG="$(type -P mkswap)"
 MKSWAP_PROG="$MKSWAP_PROG -f"
 
 export XFS_LOGPRINT_PROG="$(type -P xfs_logprint)"
+export XFS_PROTOFILE_PROG="$(type -P xfs_protofile)"
 export XFS_REPAIR_PROG="$(type -P xfs_repair)"
 export XFS_DB_PROG="$(type -P xfs_db)"
 export XFS_METADUMP_PROG="$(type -P xfs_metadump)"
diff --git a/tests/xfs/818 b/tests/xfs/818
new file mode 100755 (executable)
index 0000000..aeb4623
--- /dev/null
@@ -0,0 +1,115 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 Oracle, Inc.  All Rights Reserved.
+#
+# FS QA Test No. 818
+#
+# Populate a XFS filesystem, use xfs_protofile to recreate the filesystem, and
+# compare the contents.
+#
+. ./common/preamble
+_begin_fstest auto scrub
+
+_cleanup()
+{
+       command -v _kill_fsstress &>/dev/null && _kill_fsstress
+       cd /
+       test -e "$testfiles" && _unmount $testfiles/mount &>/dev/null
+       test -e "$testfiles" && rm -r -f $testfiles
+}
+
+_register_cleanup "_cleanup" BUS
+
+# Import common functions.
+. ./common/filter
+. ./common/populate
+. ./common/fuzzy
+
+_require_command "$XFS_PROTOFILE_PROG" xfs_protofile
+_require_test
+_require_scratch
+_require_scrub
+_require_populate_commands
+
+make_md5()
+{
+       (cd $1 ; find . -type f -print0 | xargs -0 md5sum) > $tmp.md5.$2
+}
+
+cmp_md5()
+{
+       (cd $1 ; md5sum --quiet -c $tmp.md5.$2)
+}
+
+make_stat()
+{
+       # columns:      raw mode in hex,
+       #               major rdev for special
+       #               minor rdev for special
+       #               uid of owner
+       #               gid of owner
+       #               file type
+       #               total size
+       #               name
+       # We can't directly control directory sizes so filter them.
+       (cd $1 ; find . -print0 |
+               xargs -0 stat -c '%f %t:%T %u %g %F %s %n' |
+               sed -e 's/ directory [1-9][0-9]* / directory SIZE /g' |
+               sort) > $tmp.stat.$2
+}
+
+cmp_stat()
+{
+       diff -u $tmp.stat.$1 $tmp.stat.$2
+}
+
+testfiles=$TEST_DIR/$seq
+mkdir -p $testfiles/mount
+
+echo "Format and populate"
+_scratch_populate_cached nofill >> $seqres.full 2>&1
+_scratch_mount
+
+_run_fsstress -n 1000 -d $SCRATCH_MNT/newfiles
+
+make_stat $SCRATCH_MNT before
+make_md5 $SCRATCH_MNT before
+
+kb_needed=$(du -k -s $SCRATCH_MNT | awk '{print $1}')
+img_size=$((kb_needed * 2))
+test "$img_size" -lt $((300 * 1024)) && img_size=$((300 * 1024))
+
+echo "Clone image with protofile"
+$XFS_PROTOFILE_PROG $SCRATCH_MNT > $testfiles/protofile
+
+truncate -s "${img_size}k" $testfiles/image
+if ! _try_mkfs_dev -p $testfiles/protofile $testfiles/image &> $tmp.mkfs; then
+       cat $tmp.mkfs >> $seqres.full
+
+       # mkfs.xfs' protofile parser has some limitations in what it can copy
+       # in from the prototype files.  If a source file has more than 64k
+       # worth of xattr names then formatting will fail because listxattr
+       # cannot return that much information.
+       if grep -q 'Argument list too long' $tmp.mkfs; then
+               _notrun "source filesystem was too large"
+       fi
+
+       # The protofile parser does not preserve cloned reflinked space, so
+       # the new filesystem can run out of space.
+       if grep -q 'No space left on device' $tmp.mkfs; then
+               _notrun "not enough space in filesystem"
+       fi
+       cat $tmp.mkfs
+fi
+
+_mount $testfiles/image $testfiles/mount
+
+echo "Check file contents"
+make_stat $testfiles/mount after
+cmp_stat before after
+cmp_md5 $testfiles/mount before
+_unmount $testfiles/mount
+
+# success, all done
+status=0
+exit
diff --git a/tests/xfs/818.out b/tests/xfs/818.out
new file mode 100644 (file)
index 0000000..7bee3a1
--- /dev/null
@@ -0,0 +1,4 @@
+QA output created by 818
+Format and populate
+Clone image with protofile
+Check file contents