#!/bin/bash . $(dirname $(readlink -e "${BASH_SOURCE[0]}"))/bcachefs-test-libs.sh config-scratch-devs 4G config-scratch-devs 4G test_snapshots_simple() { NR_SNAPS=1 bcachefs_antagonist run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt pushd /mnt for i in `seq 0 $NR_SNAPS`; do dd if=/dev/zero of=/mnt/foo bs=1M count=1 oflag=direct bcachefs subvolume snapshot snap-$i done popd umount /mnt sleep 0.2 bcachefs fsck -n /dev/sdb exit for i in `seq 0 $NR_SNAPS|sort -r`; do umount /mnt sleep 0.2 bcachefs fsck -n /dev/sdb mount -t bcachefs /dev/sdb /mnt echo "deleting snap-$i" bcachefs subvolume delete /mnt/snap-$i df -h /mnt done umount /mnt sleep 0.2 mount -t bcachefs -o fsck /dev/sdb /mnt umount /mnt } test_files_many() { #bcachefs_antagonist run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt for i in $(seq 0 1000001); do echo $i > /mnt/$i done umount /mnt sleep 0.2 time mount -t bcachefs -o fsck /dev/sdb /mnt umount /mnt } d_test_snapshots_many() { #bcachefs_antagonist run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt cd /mnt for i in $(seq 0 1000001); do bcachefs subvolume snapshot "snap_$(date -u +%F-%H%M%_S%N)" echo $i > snap_number done umount /mnt sleep 0.2 mount -t bcachefs -o fsck /dev/sdb /mnt umount /mnt } test_dbench() { # so wait doesn't hang [[ $(jobs -p) != "" ]] && kill $(jobs -p) NR_SNAPS=10 run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt ( cd /mnt for i in `seq 0 $NR_SNAPS`; do sleep 1 bcachefs subvolume snapshot snap-$i done ) & dbench -S -t $NR_SNAPS 1 -D /mnt/ wait df -h /mnt for i in `seq 0 $NR_SNAPS|sort -r`; do echo "deleting snap-$i" bcachefs subvolume delete /mnt/snap-$i df -h /mnt done umount /mnt sleep 0.2 #bcachefs fsck -n /dev/sdb mount -t bcachefs -o fsck /dev/sdb /mnt df -h /mnt umount /mnt } test_reflink() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt pushd /mnt cp -a /usr . bcachefs subvolume snapshot snap-$i cp -r --reflink usr usr2 popd umount /mnt } d_test_finsert() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt pushd /mnt dd if=/dev/zero of=foo bs=1M count=8 oflag=direct bcachefs subvolume snapshot snap-$i xfs_io -c "finsert 1024 1024" foo popd umount /mnt } d_test_snapshots_fio() { # so wait doesn't hang [[ $(jobs -p) != "" ]] && kill $(jobs -p) run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt fallocate -l500M /mnt/fiotest ( cd /mnt for i in `seq 0 10`; do sleep 2 bcachefs subvolume snapshot snap-$i done ) & fio --eta=always \ --eta-interval=1s \ --exitall_on_error=1 \ --randrepeat=0 \ --ioengine=libaio \ --iodepth=64 \ --iodepth_batch=16 \ --direct=1 \ --numjobs=1 \ --verify=crc32c \ --verify_fatal=1 \ --verify_async=1 \ --filename=/mnt/fiotest \ --filesize=1G \ --io_size=12G \ --fallocate=none \ --name=randwrite \ --rw=randwrite \ --bsrange=4k-32k || true wait df -h /mnt for i in `seq 0 10`; do fio --eta=always \ --eta-interval=1s \ --exitall_on_error=1 \ --randrepeat=0 \ --ioengine=libaio \ --iodepth=64 \ --iodepth_batch=16 \ --direct=1 \ --numjobs=1 \ --verify=crc32c \ --verify_only=1 \ --filename=/mnt/snap-$i/fiotest \ --filesize=1G \ --io_size=12G \ --fallocate=none \ --name=randwrite \ --rw=randwrite \ --bsrange=4k-32k || true done for i in `seq 0 10|sort -r`; do umount /mnt sleep 0.1 mount -t bcachefs -o fsck /dev/sdb /mnt echo "deleting snap-$i" cd /mnt bcachefs subvolume delete snap-$i df -h /mnt cd / done umount /mnt sleep 0.1 mount -t bcachefs -o fsck /dev/sdb /mnt df -h /mnt umount /mnt } test_subvol_create() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/subvolume_1 touch /mnt/foo mv /mnt/foo /mnt/subvolume_1 umount /mnt bcachefs fsck -n /dev/sdb } test_subvol_delete() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/subvolume_1 rm -rf /mnt/subvolume_1 umount /mnt bcachefs fsck -n /dev/sdb } test_subvol_snapshot_create() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/subvolume_1 bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1 umount /mnt bcachefs fsck -n /dev/sdb } test_subvol_snapshot_create_ro() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/subvolume_1 bcachefs subvolume snapshot -r /mnt/subvolume_1 /mnt/snapshot_1 ! touch /mnt/snapshot_1/foo umount /mnt bcachefs fsck -n /dev/sdb } test_subvol_snapshot_delete() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/subvolume_1 bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1 bcachefs subvolume delete /mnt/snapshot_1 umount /mnt bcachefs fsck -n /dev/sdb } test_subvol_snapshot_delete_create() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/subvolume_1 bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1 bcachefs subvolume delete /mnt/snapshot_1 bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1 umount /mnt bcachefs fsck -n /dev/sdb } d_test_subvol_snapshot_rm() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/subvolume_1 bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1 rm -r /mnt/snapshot_1 umount /mnt bcachefs fsck -n /dev/sdb } # Create a subvolume, then snapshot the parent subvolume, then move the child # subvolume: test_mkdir_mv_snapshot() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt mkdir /mnt/dir1 bcachefs subvolume snapshot /mnt/ /mnt/snap1 mv /mnt/dir1 /mnt/dir2 umount /mnt bcachefs fsck -n /dev/sdb } test_subvol_mv_snapshot() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/sub1 bcachefs subvolume snapshot /mnt/ /mnt/snap1 mv /mnt/sub1 /mnt/sub2 umount /mnt bcachefs fsck -n /dev/sdb } # Test moving a subvol to another subvol test_subvol_mv_subvol() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/sub1 bcachefs subvolume create /mnt/sub2 mv /mnt/sub1 /mnt/sub2 umount /mnt bcachefs fsck -n /dev/sdb } test_subvol_snapshot_reuse_snapshot_name() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/subvolume_1 bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1 bcachefs subvolume delete /mnt/snapshot_1 bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1 umount /mnt bcachefs fsck -n /dev/sdb } test_subvol_delete_snapshot_of_deleted_subvol() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt bcachefs subvolume create /mnt/subvolume_1 bcachefs subvolume snapshot /mnt/subvolume_1 /mnt/snapshot_1 rm -rf /mnt/subvolume_1 bcachefs subvolume delete /mnt/snapshot_1 umount /mnt bcachefs fsck -n /dev/sdb } test_subvol_snapshot_delete_repeat() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt for i in $(seq 1 64); do bcachefs subvolume snapshot /mnt/$i bcachefs subvolume delete /mnt/$i done umount /mnt bcachefs fsck -n /dev/sdb } test_subvol_snapshot_delete_fio() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt for i in $(seq 1 10); do #run_fio_randrw --filesize=500M --bs=4k dd if=/dev/zero of=/mnt/test bs=4k count=1024 oflag=direct bcachefs subvolume snapshot /mnt/$i done for i in $(seq 1 10); do umount /mnt bcachefs fsck -n /dev/sdb mount -t bcachefs -o fsck /dev/sdb /mnt done umount /mnt bcachefs fsck -n /dev/sdb } test_snapshot_copygc() { run_quiet "" bcachefs format -f --errors=panic /dev/sdb mount -t bcachefs /dev/sdb /mnt for i in $(seq 1 4); do run_fio_randrw --filesize=1000M --loops=4 --bs=4k bcachefs subvolume snapshot /mnt/$i done bcachefs fs usage -h /mnt umount /mnt } main "$@"