#!/bin/bash . $(dirname $(readlink -e ${BASH_SOURCE[0]}))/bcachefs-test-libs.sh require-kernel-config BCACHEFS_TESTS require-kernel-config BCACHEFS_QUOTA require-kernel-config MD require-kernel-config BLK_DEV_MD require-kernel-config MD_FAULTY config-scratch-devs 4G config-scratch-devs 4G test_stress_ng() { set_watchdog 300 setup_tracing 'bcachefs:*' run_quiet "" bcachefs format --no_initialize --version=11 -f /dev/sdb mount -t bcachefs /dev/sdb /mnt cd /mnt stress-ng -v -t 60 --class filesystem --all 1 || true stress-ng -v -t 60 --class filesystem --all 2 || true cd /root umount /mnt } test_punch() { set_watchdog 10 run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt xfs_io -f /mnt/foo -c "pwrite -S 0x55 0 16384" xfs_io -f /mnt/foo -c "fsync" xfs_io -f /mnt/foo -c "fpunch 4095 4097" md5sum /mnt/foo umount /mnt mount -t bcachefs /dev/sdb /mnt md5sum /mnt/foo umount /mnt } test_remount_ro_rw() { set_watchdog 10 run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt mount -o remount,ro /mnt mount -o remount,rw /mnt touch /mnt/foo umount /mnt } test_extent_merge2() { set_watchdog 10 echo 1 > /sys/module/bcachefs/parameters/debug_check_iterators run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt fallocate -o 0 -l 4096 /mnt/foo fallocate -o 4096 -l 4096 /mnt/foo umount /mnt bcachefs fsck -n /dev/sdb } test_reflink2() { set_watchdog 10 bcachefs_antagonist run_quiet "" bcachefs format /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/urandom of=/mnt/foo bs=16k count=1 oflag=direct cp --reflink /mnt/foo /mnt/foo2 cp --reflink /mnt/foo /mnt/foo3 cp --reflink /mnt/foo /mnt/foo4 cp --reflink /mnt/foo /mnt/foo5 cp --reflink /mnt/foo /mnt/foo6 cat /sys/kernel/debug/bcachefs/*/btrees/reflink dd if=/dev/urandom of=/mnt/foo2 bs=4k oflag=direct conv=notrunc count=1 dd if=/dev/urandom of=/mnt/foo3 bs=4k oflag=direct conv=notrunc count=1 seek=1 dd if=/dev/urandom of=/mnt/foo4 bs=4k oflag=direct conv=notrunc count=1 seek=3 dd if=/dev/urandom of=/mnt/foo5 bs=4k oflag=direct conv=notrunc count=2 dd if=/dev/urandom of=/mnt/foo6 bs=4k oflag=direct conv=notrunc count=1 seek=3 dd if=/dev/urandom of=/mnt/foo6 bs=4k oflag=direct conv=notrunc count=1 seek=2 cat /sys/kernel/debug/bcachefs/*/btrees/reflink cat /sys/kernel/debug/bcachefs/*/btrees/reflink|wc -l rm /mnt/foo* cat /sys/kernel/debug/bcachefs/*/btrees/reflink|wc -l umount /mnt } test_reflink() { set_watchdog 10 run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt run_fio_randrw --filesize=1000M & while [[ ! -f /mnt/fiotest ]]; do sleep 1 done for i in `seq 0 10`; do sleep 0.5 cp --reflink /mnt/fiotest /mnt/fiotest2 rm /mnt/fiotest2 done wait cat /sys/kernel/debug/bcachefs/*/btrees/reflink|wc -l rm /mnt/fiotest* nr_left=`cat /sys/kernel/debug/bcachefs/*/btrees/reflink|wc -l` echo "nr_left: $nr_left" [[ $nr_left = 0 ]] umount /mnt } test_fio_raw() { set_watchdog 60 fio --eta=always \ --exitall_on_error=1 \ --randrepeat=0 \ --ioengine=libaio \ --iodepth=64 \ --iodepth_batch=16 \ --direct=1 \ --numjobs=1 \ --filename=/dev/sdb \ --name=randread \ --rw=randread \ --size=40G \ --bs=4k } test_rewrite_old_nodes() { set_watchdog 60 run_quiet "" bcachefs format -f --no_initialize --version=10 /dev/sdb bcachefs show-super /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/zero of=/mnt/foo bs=4k count=65536 oflag=direct umount /mnt bcachefs show-super /dev/sdb bcachefs fsck /dev/sdb bcachefs show-super /dev/sdb mount -t bcachefs -o version_upgrade /dev/sdb /mnt bcachefs data job rewrite_old_nodes /mnt umount /mnt bcachefs fsck /dev/sdb bcachefs show-super /dev/sdb } test_merge_torture_flakey() { set_watchdog 600 local loops=$((($ktest_priority + 1) * 3)) local n=40M mdadm -B /dev/md0 -lfaulty -n1 /dev/sdb run_quiet "" bcachefs format -f --btree_node_size=32k --errors=panic /dev/md0 for i in `seq 0 $loops`; do echo "loop: $i" mount -t bcachefs -o fsck /dev/md0 /mnt echo seq_delete $n 1 > /sys/fs/bcachefs/*/perf_test echo -n "nodes: " grep "^l " /sys/kernel/debug/bcachefs/*/btrees/xattrs-formats|wc -l df -h /mnt echo seq_insert $n 1 > /sys/fs/bcachefs/*/perf_test & sleep 10 mdadm -G /dev/md0 -pwrite-all wait umount /mnt mdadm -G /dev/md0 -pnone mount -t bcachefs -o fsck /dev/md0 /mnt echo seq_delete $n 1 > /sys/fs/bcachefs/*/perf_test & sleep 2 mdadm -G /dev/md0 -pwrite-all wait umount /mnt mdadm -G /dev/md0 -pnone done mdadm --stop /dev/md0 } # Disabled, because currently OOMs d_test_merge_torture() { setup_tracing local loops=$((($ktest_priority + 1) * 3)) local n=10M run_quiet "" bcachefs format -f --errors=panic --btree_node_size=8k --no_initialize /dev/sdb for i in `seq 0 $loops`; do mount -t bcachefs -o fsck /dev/sdb /mnt echo "loop: $i" echo rand_insert $n 1 > /sys/fs/bcachefs/*/perf_test df -h /mnt echo rand_delete $n 1 > /sys/fs/bcachefs/*/perf_test echo -n "nodes: " grep "^l " /sys/kernel/debug/bcachefs/*/xattrs-formats|wc -l df -h /mnt umount /mnt done } test_make_files() { set_watchdog 30 run_quiet "" bcachefs format -f /dev/sdb mount -t bcachefs /dev/sdb /mnt echo 3 > /proc/sys/vm/drop_caches free -m for i in `seq 0 1`; do echo -n > /mnt/$i done free -m echo 3 > /proc/sys/vm/drop_caches free -m umount /mnt } test_journal_resize() { set_watchdog 30 run_quiet "" bcachefs format -f /dev/sdb mount -t bcachefs /dev/sdb /mnt run_fio_randrw --filesize=2G & sleep 4 bcachefs device resize-journal /dev/sdb 1G wait umount /mnt } test_drop_alloc() { set_watchdog 120 run_quiet "" bcachefs format -f /dev/sdb mount -t bcachefs /dev/sdb /mnt run_fio_randrw --filesize=2G umount /mnt mount -t bcachefs -o reconstruct_alloc,fsck,fix_errors /dev/sdb /mnt umount /mnt bcachefs fsck -n /dev/sdb } test_reflink_inline_data() { set_watchdog 30 run_quiet "" bcachefs format -f /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/urandom of=/root/foo bs=256 count=1 cp /root/foo /mnt/foo1 cp /mnt/foo1 /mnt/foo2 cp --reflink /mnt/foo2 /mnt/foo3 md5sum /root/foo /mnt/foo* umount /mnt } test_split_compressed() { set_watchdog 30 run_quiet "" bcachefs format --compression=zstd /dev/sdb mount -t bcachefs /dev/sdb /mnt # Test that splitting of compressed extents is working correctly: dd if=/dev/zero of=/mnt/foo bs=128k count=1 oflag=direct dd if=/dev/urandom of=/mnt/foo bs=4k count=1 seek=1 oflag=direct conv=notrunc umount /mnt } test_fcollapse() { set_watchdog 30 run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/zero of=/mnt/foo bs=4k count=4 oflag=direct echo "before fcollapse" cat /sys/kernel/debug/bcachefs/*/btrees/extents ls -l /mnt/foo echo xfs_io -c "fcollapse 4k 2k" /mnt/foo echo "after fcollapse" cat /sys/kernel/debug/bcachefs/*/btrees/extents ls -l /mnt/foo echo umount /mnt } test_finsert() { set_watchdog 30 run_quiet "" bcachefs format /dev/sdb mount -t bcachefs -o fsck /dev/sdb /mnt dd if=/dev/zero of=/mnt/foo bs=64k count=1 oflag=direct cat /sys/kernel/debug/bcachefs/*/btrees/extents xfs_io -c "finsert 1024 1024" /mnt/foo umount /mnt } test_key_merge() { set_watchdog 30 run_quiet "" bcachefs format --data_checksum=none /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/zero of=/mnt/foo bs=8k count=128 oflag=direct NR=$(cat /sys/kernel/debug/bcachefs/*/btrees/extents|wc -l) [[ $NR -eq 4 ]] umount /mnt } test_key_merge_csum() { set_watchdog 30 run_quiet "" bcachefs format --data_checksum=crc32c /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/urandom of=/mnt/foo bs=8k count=128 oflag=direct cat /mnt/foo > /dev/null NR=$(cat /sys/kernel/debug/bcachefs/*/btrees/extents|wc -l) [[ $NR -le 16 ]] umount /mnt } test_reconstruct_alloc() { set_watchdog 120 run_quiet "" bcachefs format --btree_node_size=16k /dev/sdb mount -t bcachefs -o reconstruct_alloc,fix_errors,fsck /dev/sdb /mnt umount /mnt bcachefs fsck -n /dev/sdb mount -t bcachefs /dev/sdb /mnt run_fio_randrw umount /mnt echo "Running fsck --reconstruct_alloc" fsck.bcachefs -ny --reconstruct_alloc /dev/sdb && rc=$? || rc=$? if (( $rc != 0 && $rc != 1 )); then echo "Bad exit status from fsck: $rc" exit 1 fi echo "Mounting with -o reconstruct_alloc" mount -t bcachefs -o reconstruct_alloc,fix_errors,fsck /dev/sdb /mnt umount /mnt bcachefs fsck -n /dev/sdb mount -t bcachefs -o fsck /dev/sdb /mnt umount /mnt } test_recovery() { set_watchdog 30 run_quiet "" bcachefs format \ --errors=panic \ --encrypted --no_passphrase \ --bucket=8k \ /dev/sdb for i in `seq 0 1`; do mount -t bcachefs /dev/sdb /mnt dd if=/dev/zero of=/mnt/foo bs=4k count=8 oflag=direct dd if=/dev/zero of=/mnt/foo bs=4k count=8 oflag=direct sync #run_fio_randrw #fio --eta=always \ # --exitall_on_error=1 \ # --randrepeat=0 \ # --ioengine=libaio \ # --iodepth=64 \ # --iodepth_batch=16 \ # --direct=1 \ # --numjobs=1 \ # --filename=/mnt/fiotest \ # --filesize=15M \ # --name=randwrite \ # --rw=randwrite \ # --bsrange=4k-8k $ktest_dir/tests/xfstests/src/godown -f /mnt umount /mnt done } test_lz4_zeros() { set_watchdog 30 run_quiet "" bcachefs format -f --errors=panic --compression=lz4 --data_checksum=none --bucket=2M /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/zero of=/mnt/foo bs=1M count=10 # XXX check disk space used umount /mnt } test_lz4_incompressible() { set_watchdog 30 run_quiet "" bcachefs format -f --errors=panic --compression=lz4 --data_checksum=none --bucket=2M /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/urandom of=/mnt/foo || true umount /mnt } test_lz4() { run_basic_fio_test \ --compression=lz4 \ /dev/sdb } test_lz4_buffered() { set_watchdog 120 #bcachefs_antagonist run_quiet "" bcachefs format -f \ --errors=panic \ --compression=lz4 \ /dev/sdb mount -t bcachefs /dev/sdb /mnt echo starting copy cp -rx / /mnt echo starting sync sync #echo starting gc #echo 1 | tee /sys/fs/bcachefs/*/internal/trigger_gc >& /dev/null || true echo starting rm rm -rf /mnt/* umount /mnt } test_gzip() { run_basic_fio_test \ --compression=gzip \ /dev/sdb } test_zstd() { run_basic_fio_test \ --compression=zstd \ /dev/sdb } disabled_test_background_compression() { run_quiet "" bcachefs format -f \ --errors=panic \ --background_compression=zstd \ /dev/sdb mount -t bcachefs /dev/sdb /mnt echo zstd > /sys/fs/bcachefs/*/options/background_compression run_fio_randrw } test_compress_no_checksum() { run_basic_fio_test \ --compression=lz4 \ --metadata_checksum=none \ --data_checksum=none \ /dev/sdb } test_no_checksum() { run_basic_fio_test \ --metadata_checksum=none \ --data_checksum=none \ /dev/sdb } test_crc32c() { run_basic_fio_test \ --metadata_checksum=crc32c \ --data_checksum=crc32c \ /dev/sdb } test_crc64() { run_basic_fio_test \ --metadata_checksum=crc64 \ --data_checksum=crc64 \ /dev/sdb } test_crypto_locked_mnt() { echo foo|bcachefs format --encrypted /dev/sdb echo foo|bcachefs unlock -k session /dev/sdb mount -t bcachefs -o verbose /dev/sdb /mnt umount /mnt bcachefs fsck /dev/sdb } test_crypto() { run_basic_fio_test \ --encrypted --no_passphrase \ /dev/sdb mount -t bcachefs -o fsck /dev/sdb /mnt umount /mnt bcachefs fsck \ /dev/sdb } test_crypto_lz4() { run_basic_fio_test \ --encrypted --no_passphrase \ --compression=lz4 \ /dev/sdb } run_copygc_torture() { set_watchdog 1200 loops=$((($ktest_priority + 1) * 4)) bcachefs_antagonist run_quiet "" bcachefs format -f \ --errors=panic \ --no_initialize --version=14 \ --data_checksum=none \ "$@" /dev/sdb mount -t bcachefs /dev/sdb /mnt fill_device /mnt/fiotest for i in $(seq 1 $loops); do run_fio_base \ --buffer_compress_percentage=50 \ \ --name=randwrite \ --stonewall \ --rw=randwrite \ --loops=$loops \ --bsrange=4k-128k cur_size=$(stat -c '%s' /mnt/fiotest) new_size=$(($cur_size - 1048576)) echo "truncating to $new_size" truncate --size=$new_size /mnt/fiotest done rm /mnt/fiotest expect_sysfs cache dirty_buckets 0 expect_sysfs cache dirty_data 0 expect_sysfs cache cached_buckets 0 expect_sysfs cache cached_data 0 umount /mnt bcachefs fsck -n /dev/sdb } test_copygc_torture() { #run_copygc_torture --bucket=256k --btree_node_size=8k run_copygc_torture --bucket=32k --btree_node_size=32k } test_copygc_torture_no_checksum() { run_copygc_torture --bucket=256k --btree_node_size=16k --data_checksum=none } test_copygc_torture_lz4() { run_copygc_torture --bucket=256k --btree_node_size=16k --compression=lz4 } test_small_buckets() { run_basic_fio_test \ --bucket=32k \ /dev/sdb } # Gets stuck due to only having 512 buckets test_large_buckets() { run_basic_fio_test \ --bucket=8M \ --data_checksum=none \ /dev/sdb } test_small_nodes() { run_basic_fio_test \ --bucket=256k \ --btree_node_size=4k \ /dev/sdb } d_test_crypto_passphrase() { bcachefs_antagonist echo ""|bcachefs format -f --encrypted /dev/sdb echo ""|bcachefs unlock /dev/sdb mount -t bcachefs /dev/sdb /mnt umount /mnt bcachefs fsck /dev/sdb } test_partial_overwritten_extents() { set_watchdog 10 run_quiet "" bcachefs format -f \ --errors=panic \ --encrypted --no_passphrase \ /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/urandom of=/mnt/foo bs=32k count=1 skip=0 oflag=direct dd if=/mnt/foo of=/dev/null bs=4k count=8 skip=0 iflag=direct dd if=/dev/urandom of=/mnt/foo bs=32k count=1 skip=0 oflag=direct dd if=/dev/zero of=/mnt/foo bs=4k count=1 skip=0 oflag=direct conv=notrunc dd if=/mnt/foo of=/dev/null bs=4k count=8 skip=0 iflag=direct dd if=/dev/urandom of=/mnt/bar bs=32k count=1 skip=0 oflag=direct dd if=/dev/zero of=/mnt/bar bs=4k count=1 skip=7 oflag=direct conv=notrunc dd if=/mnt/bar of=/dev/null bs=4k count=8 skip=0 iflag=direct > /dev/null dd if=/dev/urandom of=/mnt/baz bs=32k count=1 skip=0 oflag=direct dd if=/dev/zero of=/mnt/baz bs=4k count=1 skip=0 oflag=direct conv=notrunc dd if=/dev/zero of=/mnt/baz bs=4k count=1 skip=7 oflag=direct conv=notrunc dd if=/mnt/baz of=/dev/null bs=4k count=8 skip=0 iflag=direct > /dev/null umount /mnt } # test the xattr interface for per-inode IO options: test_xattr() { set_watchdog 10 run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt mkdir /mnt/foo setfattr -n bcachefs.compression -v lz4 /mnt/foo getfattr -n bcachefs.compression /mnt/foo echo "checking xattr propagation to children" touch /mnt/foo/bar getfattr -n bcachefs_effective.compression /mnt/foo/bar echo "checking xattr deletion" setfattr -x bcachefs.compression /mnt/foo/bar #getfattr -n bcachefs.compression /mnt/foo/bar rsync -rX /mnt/foo/ /mnt/baz getfattr -R -m - -d /mnt umount /mnt } test_quota() { set_watchdog 10 bcachefs_antagonist run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs -o usrquota,grpquota,prjquota /dev/sdb /mnt loops=$((($ktest_priority + 1) * 4)) run_fio_randrw rm /mnt/fiotest umount /mnt } # test nfs exports: require-kernel-config NFSD require-kernel-config NFSD_V4 test_nfs() { set_watchdog 10 mkdir /export1 /export2 run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /export2 echo "/export1 *(ro,insecure,all_squash,no_subtree_check)" >> /etc/exports echo "/export2 *(ro,insecure,all_squash,no_subtree_check)" >> /etc/exports exportfs -a exportfs -ua umount /export2 } # We should get this working at some point: d_test_suspend() { set_watchdog 10 #setup_tracing 'bcachefs:*' ( p="/sys/power" sleep 10 echo freezer > $p/pm_test echo freeze > $p/state #echo 1 > /sys/fs/bcachefs/suspend #s2ram --no_kms --force )& run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt if false; then run_dbench else bcachefs_antagonist run_stress fi } test_journal_torture() { set_watchdog 60 bcachefs_antagonist run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt #enable_memory_faults echo 1 > /sys/fs/bcachefs/*/options/journal_flush_delay run_fio_randrw #disable_memory_faults umount /mnt } test_online_resize() { set_watchdog 60 bcachefs_antagonist run_quiet "" bcachefs format -f \ --errors=panic \ --fs_size=1G \ /dev/sdb mount -t bcachefs /dev/sdb /mnt df -h /mnt bcachefs device resize /dev/sdb df -h /mnt umount /mnt } test_offline_resize() { set_watchdog 60 bcachefs_antagonist run_quiet "" bcachefs format -f \ --errors=panic \ --fs_size=1G \ /dev/sdb mount -t bcachefs /dev/sdb /mnt df -h /mnt cat /proc/mounts umount /mnt bcachefs device resize /dev/sdb mount -t bcachefs /dev/sdb /mnt df -h /mnt umount /mnt } test_offline_resize_lv() { set_watchdog 60 pvcreate /dev/sdb vgcreate vg /dev/sdb lvcreate -L 1G -n foo vg dev=/dev/vg/foo run_quiet "" bcachefs format -f \ --errors=panic \ $dev mount -t bcachefs $dev /mnt df -h /mnt cat /proc/mounts lvresize -L +1G $dev bcachefs device resize $dev df -h /mnt umount /mnt mount -t bcachefs $dev /mnt df -h /mnt umount /mnt vgremove -f vg } test_sysfs() { set_watchdog 10 run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt find -H /sys/fs/bcachefs/ -type f -perm -0400 -exec cat {} \; > /dev/null umount /mnt } test_debugfs() { set_watchdog 30 run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/zero of=/mnt/test1 bs=1k count=10240 oflag=direct dd if=/dev/zero of=/mnt/test2 bs=1k count=10240 oflag=direct find -H /sys/kernel/debug/bcachefs/ -type f -perm -0400 -exec cat {} \; > /dev/null umount /mnt } test_set_option() { set_watchdog 10 run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs set-option --compression=zstd /dev/sdb cat /sys/fs/bcachefs/*/options/compression umount /mnt bcachefs set-option --compression=lz4 /dev/sdb mount -t bcachefs /dev/sdb /mnt cat /sys/fs/bcachefs/*/options/compression umount /mnt } disabled_test_swapfile() { run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt fallocate -l 1G /mnt/swapfile mkswap /mnt/swapfile swapon /mnt/swapfile swapoff /mnt/swapfile umount /mnt } # migrate from other filesystems in place: migrate_from_fs() { set_watchdog 180 local fstype=$1 if [[ $fstype = ext4 ]]; then run_quiet "" mkfs.$fstype -F /dev/sdb mount -t $fstype -o user_xattr /dev/sdb /mnt else run_quiet "" mkfs.$fstype -f /dev/sdb mount -t $fstype /dev/sdb /mnt fi cp -a /usr /mnt for i in /mnt/usr/bin/*; do ln $i ${i}-migrate2 setfattr -n user.foo -v test $i done bcachefs migrate \ --encrypted \ --no_passphrase \ -F -f /mnt | tee /root/migratelog offset=$(grep -oE 'sb=[[:digit:]]+' /root/migratelog|head -n1|sed -e 's/sb=//') echo "Attempting to mount bcachefs filesystem with superblock offset $offset" if true; then mkdir -p /mnt2 mount -t bcachefs -o noexcl,nochanges,sb=$offset /dev/sdb /mnt2 rsync --archive \ --acls \ --xattrs \ --checksum \ --exclude=/bcachefs \ --dry-run \ --itemize-changes \ /mnt/ /mnt2/ > /root/rsynclog umount /mnt2 echo "rsync passed" fi umount /mnt fsck.$fstype -n /dev/sdb mount -t bcachefs -o sb=$offset /dev/sdb /mnt umount /mnt echo "Creating default superblock" bcachefs migrate-superblock -d /dev/sdb -o $offset mount -t bcachefs /dev/sdb /mnt rm /mnt/old_migrated_filesystem umount /mnt } test_migrate_from_ext4() { migrate_from_fs ext4 } require-kernel-config XFS_FS test_migrate_from_xfs() { migrate_from_fs xfs } require-kernel-config BTRFS_FS test_migrate_from_btrfs() { migrate_from_fs btrfs } d_test_migrate_from_bcachefs() { migrate_from_fs bcachefs } # we don't currently have fault injection: d_test_init_faults() { setup_tracing 'bcachefs:*' run_quiet "" bcachefs format -f \ --errors=remount-ro \ /dev/sdb # put some data on the filesystem mount -t bcachefs /dev/sdb /mnt run_fio_randrw # dbench would be better, create a directory structure #run_dbench umount /mnt init_fault_fn() { set_faults "$1 enable" # should fail: ! mount -t bcachefs -o verbose /dev/sdb /mnt } run_fault_injection_test bcachefs:bch_fs_init init_fault_fn run_fault_injection_test bcachefs:meta:read init_fault_fn } # we don't currently have fault injection: d_test_meta_write_faults() { setup_tracing 'bcachefs:*' run_quiet "" bcachefs format -f \ --errors=remount-ro \ /dev/sdb meta_write_fault_fn() { mount -t bcachefs /dev/sdb /mnt (sleep 2; set_faults "$1 enable") & # Should fail due to read only cache set ! run_fio # XXX: verify we've gone RO umount /mnt } run_fault_injection_test bcachefs:meta::write meta_write_fault_fn } test_long_name() { set_watchdog 20 run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt local i=1 local n="1" while touch /mnt/$n 2> /dev/null; do n="1$n" i=$(($i + 1)) done echo $i umount /mnt } test_many_files() { set_watchdog 60 run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt for i in {1..1000}; do touch /mnt/$i done umount /mnt mount -t bcachefs /dev/sdb /mnt umount /mnt } disabled_test_invalid_keys() { echo 1 > /sys/module/bcachefs/parameters/inject_invalid_keys run_quiet "" bcachefs format -f \ --errors=continue \ /dev/sdb mount -t bcachefs /dev/sdb /mnt for i in {1..1000}; do touch /mnt/$i done umount /mnt mount -t bcachefs -o fix_errors /dev/sdb /mnt umount /mnt echo 0 > /sys/module/bcachefs/parameters/inject_invalid_keys } test_buffered_reads() { set_watchdog 60 run_quiet "" bcachefs format -f \ --errors=panic \ --bucket=8M \ --data_checksum=none \ /dev/sdb mount -t bcachefs /dev/sdb /mnt dd if=/dev/zero of=/mnt/foo bs=1M oflag=direct 2>/dev/null || true time dd if=/mnt/foo of=/dev/null bs=1M count=1024 umount /mnt } test_small_fs() { set_watchdog 60 run_quiet "" bcachefs format -f \ --errors=panic \ --bucket=4k \ --fs_size=512k \ /dev/sdb mount -t bcachefs /dev/sdb /mnt df -h /mnt dd if=/dev/zero of=/mnt/foo bs=4k oflag=direct 2>/dev/null || true df -h /mnt umount /mnt } test_small_torture() { run_copygc_torture --bucket=4k --fs_size=32M } test_small_fsck() { set_watchdog 60 run_quiet "" bcachefs format -f \ --errors=panic \ --fs_size=1M \ /dev/sdb for i in {1..100}; do bcachefs fsck /dev/sdb done } test_gc() { set_watchdog 60 run_quiet "" bcachefs format -f \ --errors=panic \ --compression=lz4 \ /dev/sdb mount -t bcachefs /dev/sdb /mnt antagonist_trigger_gc & run_fio_randrw umount /mnt mount -t bcachefs /dev/sdb /mnt umount /mnt } test_attr_inherit() { set_watchdog 60 run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt mkdir /mnt/foo mkdir /mnt/bar setfattr -n bcachefs.compression -v lz4 /mnt/foo setfattr -n bcachefs.compression -v gzip /mnt/bar touch /mnt/foo/baz getfattr -R -d -m - /mnt mv /mnt/foo/baz /mnt/bar/baz getfattr -R -d -m - /mnt setfattr -n bcachefs.compression -v lz4 /mnt/bar/baz getfattr -R -d -m - /mnt/bar/baz setfattr -x bcachefs.compression /mnt/bar/baz getfattr -R -d -m - /mnt/bar/baz umount /mnt } test_setattr() { set_watchdog 60 run_quiet "" bcachefs format -f \ --errors=panic \ /dev/sdb mount -t bcachefs /dev/sdb /mnt mkdir /mnt/foo touch /mnt/foo/bar bcachefs setattr --compression lz4 /mnt/foo bcachefs setattr --foreground_target= /mnt/foo getfattr -R -d -m - /mnt umount /mnt } test_mount_twice() { set_watchdog 60 mkdir -p /mnt/1 /mnt/2 #run_quiet "" bcachefs format -f /dev/sdb mkfs.ext2 /dev/sdb mount -t ext2 /dev/sdb /mnt/1 mount -t ext2 /dev/sdb /mnt/2 umount /mnt/1 umount /mnt/2 } test_dump() { set_watchdog 60 run_quiet "" bcachefs format /dev/sdb mount -t bcachefs /dev/sdb /mnt touch /mnt/a touch /mnt/b umount /mnt bcachefs dump -o /tmp/sdb.qcow2 /dev/sdb } test_kill_btree_node() { set_watchdog 60 run_quiet "" bcachefs format --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt cp -a /usr /mnt umount /mnt # Doesn't yet work with the alloc btree: for btree in extents backpointers freespace; do echo "Killing a btree node in btree $btree " local index=1 [[ $btree = freespace ]] && index=0 bcachefs kill_btree_node -b $btree -i $index /dev/sdb echo "Running fsck" # How to assert exit status equals something specific with -o errexit? mount -t bcachefs -o fsck,fix_errors,verbose /dev/sdb /mnt umount /mnt #bcachefs fsck -y /dev/sdb || true echo echo "Running fsck again; should be clean" bcachefs fsck -y /dev/sdb || true done } main "$@"