Skip to contentSkip to conversation

tests/bcachefs/single_device: test bcachefs format from source

PATCH Applied Ariel Miculas 2 participants 2 messages Jun 6, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/bcachefs/single_device: test bcachefs format from source

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

---
 tests/bcachefs/single_device.ktest | 101 +++++++++++++++++++++++++++--
 1 file changed, 94 insertions(+), 7 deletions(-)
tests/bcachefs/single_device.ktest +94 -7
index 8e9b5a3..4c9caa7 100755
@@ -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"
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · 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.

Quoted 7 lines

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

Applied