On Tue, Apr 26, 2022 at 03:40:15PM -0700, Boris Burkov wrote: > The behavior of orphans is most interesting across mounts, interrupted > at arbitrary points during fsverity enable. To cover as many such cases > as possible, use dmlogwrites and dmsnapshot as in > log-writes/replay-individual.sh. At each log entry, we want to assert a > somewhat complicated invariant: > > If verity has not yet started: an orphan indicates that verity has > started. > If verity has started: mount should handle the orphan and blow away > verity data: expect 0 merkle items after mounting the snapshot dev. If > we can measure the file, verity has finished. > If verity has finished: the orphan should be gone, so mount should not > blow away merkle items. Expect the same number of merkle items before > and after mounting the snapshot dev. > > Note that this relies on grepping btrfs inspect-internal dump-tree. > Until btrfs-progs has the ability to print the new Merkle items, they > will show up as UNKNOWN.36/37. > > Signed-off-by: Boris Burkov <boris@xxxxxx> > --- > tests/btrfs/291 | 161 ++++++++++++++++++++++++++++++++++++++++++++ > tests/btrfs/291.out | 2 + > 2 files changed, 163 insertions(+) > create mode 100755 tests/btrfs/291 > create mode 100644 tests/btrfs/291.out > > diff --git a/tests/btrfs/291 b/tests/btrfs/291 > new file mode 100755 > index 00000000..1bb3f1b3 > --- /dev/null > +++ b/tests/btrfs/291 > @@ -0,0 +1,161 @@ > +#! /bin/bash > +# SPDX-License-Identifier: GPL-2.0 > +# Copyright (C) 2021 Facebook, Inc. All Rights Reserved. > +# > +# FS QA Test 291 > +# > +# Test btrfs consistency after each FUA while enabling verity on a file > +# This test works by following the pattern in log-writes/replay-individual.sh: > +# 1. run a workload (verity + sync) while logging to the log device > +# 2. replay an entry to the replay device > +# 3. snapshot the replay device to the snapshot device > +# 4. run destructive tests on the snapshot device (e.g. mount with orphans) > +# 5. goto 2 > +# > +. ./common/preamble > +_begin_fstest auto verity > + > +# Override the default cleanup function. > +_cleanup() > +{ > + cd / > + _log_writes_cleanup &> /dev/null > + rm -f $img > + $LVM_PROG vgremove -f -y $vgname >>$seqres.full 2>&1 > + losetup -d $loop_dev >>$seqres.full 2>&1 > +} > + > +# Import common functions. > +. ./common/filter > +. ./common/attr > +. ./common/dmlogwrites > +. ./common/verity > + > +# real QA test starts here > +_supported_fs btrfs > + > +_require_scratch > +_require_test > +_require_log_writes > +_require_dm_target snapshot > +_require_command $LVM_PROG lvm > +_require_scratch_verity > +_require_btrfs_command inspect-internal dump-tree > +_require_test_program "log-writes/replay-log" > + > +sync_loop() { > + i=$1 > + [ -z "$i" ] && _fail "sync loop needs a number of iterations" > + while [ $i -gt 0 ] > + do > + $XFS_IO_PROG -c sync $SCRATCH_MNT > + let i-=1 > + done > +} > + > +dump_tree() { > + local dev=$1 > + $BTRFS_UTIL_PROG inspect-internal dump-tree $dev > +} > + > +count_item() { > + local dev=$1 > + local item=$2 > + dump_tree $dev | grep -c $item > +} > + > +_log_writes_init $SCRATCH_DEV > +_log_writes_mkfs > +_log_writes_mount > + > +f=$SCRATCH_MNT/fsv > +MB=$((1024 * 1024)) > +img=$TEST_DIR/$$.img > +$XFS_IO_PROG -fc "pwrite -q 0 $((10 * $MB))" $f > +$XFS_IO_PROG -c sync $SCRATCH_MNT > +sync_loop 10 & > +sync_proc=$! > +_fsv_enable $f > +$XFS_IO_PROG -c sync $SCRATCH_MNT > +wait $sync_proc > + > +_log_writes_unmount > +_log_writes_remove > + > +# the snapshot and the replay will each be the size of the log writes dev > +# so we create a loop device of size 2 * logwrites and then split it into > +# replay and snapshot with lvm. > +log_writes_blocks=$(blockdev --getsz $LOGWRITES_DEV) > +replay_bytes=$((512 * $log_writes_blocks)) > +img_bytes=$((2 * $replay_bytes)) > + > +$XFS_IO_PROG -fc "pwrite -q -S 0 $img_bytes $MB" $img >>$seqres.full 2>&1 || \ > + _fail "failed to create image for loop device" > +loop_dev=$(losetup -f --show $img) I got bit by this recently, you need _require_loop for this test. Thanks, Josef