diff options
author | Ariel Miculas <ariel.miculas@gmail.com> | 2024-06-06 18:28:04 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-06-06 11:51:12 -0400 |
commit | 1135305fb22aeac31ea460b73792b6319f69dd4c (patch) | |
tree | 03775769f27fca378295e6d1cc10dca81d06215d | |
parent | d4d1648841c4b18378aaab9c9b1be7a5f58192a9 (diff) |
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
Signed-off-by: Ariel Miculas <ariel.miculas@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rwxr-xr-x | tests/bcachefs/single_device.ktest | 101 |
1 files 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" |