public inbox for linux-bcachefs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tests/bcachefs/single_device: test bcachefs format from source
@ 2024-06-06 15:28 Ariel Miculas
  2024-06-06 15:51 ` Kent Overstreet
  0 siblings, 1 reply; 2+ messages in thread
From: Ariel Miculas @ 2024-06-06 15:28 UTC (permalink / raw)
  To: linux-bcachefs; +Cc: Ariel Miculas

Add a test which checks formatting and initializing a bcachefs
filesystem from a source directory:
`bcachefs format --source=source_dir`

Create a new `prepare_fs` function shared by both `migrate_from_fs` and
`build_from_fs`.

Other changes:
- add `ro` mount options when `nochanges` is supplied
- add a function which checks rsync's --itemize-changes output
- pass the --hard-links options to rsync when comparing changes
- avoid creating hardlinks for symlinks

Signed-off-by: Ariel Miculas <ariel.miculas@gmail.com>
---
 tests/bcachefs/single_device.ktest | 101 +++++++++++++++++++++++++++--
 1 file changed, 94 insertions(+), 7 deletions(-)

diff --git a/tests/bcachefs/single_device.ktest b/tests/bcachefs/single_device.ktest
index 8e9b5a3..4c9caa7 100755
--- a/tests/bcachefs/single_device.ktest
+++ b/tests/bcachefs/single_device.ktest
@@ -1252,11 +1252,8 @@ disabled_test_swapfile()
     check_counters ${ktest_scratch_dev[0]}
 }
 
-# migrate from other filesystems in place:
-
-migrate_from_fs()
+prepare_source_fs()
 {
-    set_watchdog 180
     local fstype=$1
 
     if [[ $fstype = ext4 ]]; then
@@ -1270,10 +1267,97 @@ migrate_from_fs()
     cp -a /usr /mnt
 
     for i in /mnt/usr/bin/*; do
+    if [ ! -L $i ]; then
 	ln $i ${i}-migrate2
-	setfattr -n user.foo -v test $i 
+    fi
+	setfattr -n user.foo -v test $i
     done
 
+}
+
+check_rsync_log()
+{
+    # rsync itemized output
+    # https://jhpce.jhu.edu/files/rsync-itemize-table/
+    # .: the item is not being updated (though it might have attributes that are being modified)
+
+    # We don't expect any lines to start with anything other than a dot
+    # Ideally the output should be empty, but the lost+found/ directory is
+    # ignored and the mountpoints themselves could have a modified time
+    # Sample expected output:
+    # .d..t...... ./
+    # .d..t...... lost+found/
+    ! grep -E '^[^.]' $1
+}
+
+# build a filesystem from a source
+
+build_from_fs()
+{
+    set_watchdog 180
+
+    prepare_source_fs $1
+
+    bcachefs format				\
+	--source=/mnt ${ktest_scratch_dev[1]} | tee /root/buildlog
+
+    echo "Attempting to mount bcachefs filesystem"
+
+    if true; then
+	mkdir -p /mnt2
+	mount -t bcachefs -o noexcl,nochanges,ro ${ktest_scratch_dev[1]} /mnt2
+
+	rsync	--archive			\
+	    --acls				\
+	    --xattrs				\
+	    --checksum				\
+	    --hard-links			\
+	    --dry-run				\
+	    --itemize-changes		 	\
+	    /mnt/ /mnt2/ > /root/rsynclog-build
+
+	check_rsync_log /root/rsynclog-build
+
+	umount /mnt2
+	echo "rsync passed"
+    fi
+
+    umount /mnt
+
+    bcachefs fsck -ny ${ktest_scratch_dev[1]}
+    check_counters ${ktest_scratch_dev[1]}
+}
+
+test_build_from_ext4()
+{
+    build_from_fs ext4
+}
+
+require-kernel-config XFS_FS
+test_build_from_xfs()
+{
+    build_from_fs xfs
+}
+
+require-kernel-config BTRFS_FS
+test_build_from_btrfs()
+{
+    build_from_fs btrfs
+}
+
+test_build_from_bcachefs()
+{
+    build_from_fs bcachefs
+}
+
+# migrate from other filesystems in place:
+
+migrate_from_fs()
+{
+    set_watchdog 180
+
+    prepare_source_fs $1
+
     bcachefs migrate				\
 	--encrypted				\
 	--no_passphrase				\
@@ -1287,16 +1371,19 @@ migrate_from_fs()
 
     if true; then
 	mkdir -p /mnt2
-	mount -t bcachefs -o noexcl,nochanges,sb=$offset ${ktest_scratch_dev[0]} /mnt2
+	mount -t bcachefs -o noexcl,nochanges,ro,sb=$offset ${ktest_scratch_dev[0]} /mnt2
 
 	rsync	--archive			\
 	    --acls				\
 	    --xattrs				\
 	    --checksum				\
+	    --hard-links			\
 	    --exclude=/bcachefs			\
 	    --dry-run				\
 	    --itemize-changes		 	\
-	    /mnt/ /mnt2/ > /root/rsynclog
+	    /mnt/ /mnt2/ > /root/rsynclog-migrate
+
+	check_rsync_log /root/rsynclog-migrate
 
 	umount /mnt2
 	echo "rsync passed"
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-06 15:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-06 15:28 [PATCH] tests/bcachefs/single_device: test bcachefs format from source Ariel Miculas
2024-06-06 15:51 ` Kent Overstreet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox