On Thu, Mar 21, 2024 at 4:10 AM Anand Jain <anand.jain@xxxxxxxxxx> wrote: > > As btrfs-corrupt-block now uses --value instead of -v, and --offset > instead of -o, provide backward compatibility for the testcases, by > storing the option to be used in BTRFS_CORRUPT_BLOCK_OPT_VALUE and > BTRFS_CORRUPT_BLOCK_OPT_OFFSET. Also, removes the stdout and stderr > redirection to /dev/null. This is complex and ugly, but most importantly this is not needed at all. Just let all users of btrfs-corrupt-block use --value and --offset, because there was never a released version of btrfs-progs with the short options available. The short options were introduced with: commit b2ada0594116f3f4458581317e226c5976443ad0 Author: Boris Burkov <boris@xxxxxx> Date: Tue Jul 26 13:43:23 2022 -0700 btrfs-progs: corrupt-block: corrupt generic item data And then replacing them with long options happened in this commit: commit 22ffee3c6cf2e6f285e6fd6cb22b88c02510e10e Author: David Sterba <dsterba@xxxxxxxx> Date: Wed Jul 27 20:47:57 2022 +0200 btrfs-progs: corrupt-block: use only long options for value and offset Both commits landed in btrfs-progs 5.19, meaning there are no released versions with the short options. The reason btrfs/290 is using the short options is because the btrfs-progs patch had just been submitted shortly before the test case was added. However what we need is to have a _require_* helper that will make the test btrfs/290 not run if we're using a btrfs-progs version without those new options. Thanks. > > Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx> > --- > This replaces the patch: > [PATCH 1/5] common/verity: use the correct options for btrfs-corrupt-block > > common/btrfs | 16 ++++++++++++++++ > common/verity | 9 ++++++--- > tests/btrfs/290 | 30 ++++++++++++++++++++++-------- > 3 files changed, 44 insertions(+), 11 deletions(-) > > diff --git a/common/btrfs b/common/btrfs > index ae13fb55cbc6..11d74bea9111 100644 > --- a/common/btrfs > +++ b/common/btrfs > @@ -660,6 +660,22 @@ _btrfs_buffered_read_on_mirror() > _require_btrfs_corrupt_block() > { > _require_command "$BTRFS_CORRUPT_BLOCK_PROG" btrfs-corrupt-block > + > + # In the newer version, the option -v is replaced by --value, > + # and -o is replaced by --offset, so normalize them. > + $BTRFS_CORRUPT_BLOCK_PROG -h 2>&1 | grep -q "value VALUE" > + if [ $? == 0 ]; then > + export BTRFS_CORRUPT_BLOCK_OPT_VALUE="--value" > + else > + export BTRFS_CORRUPT_BLOCK_OPT_VALUE="-v" > + fi > + > + $BTRFS_CORRUPT_BLOCK_PROG -h 2>&1 | grep -q "offset OFFSET" > + if [ $? == 0 ]; then > + export BTRFS_CORRUPT_BLOCK_OPT_OFFSET="--offset" > + else > + export BTRFS_CORRUPT_BLOCK_OPT_OFFSET="-o" > + fi > } > > _require_btrfs_send_version() > diff --git a/common/verity b/common/verity > index 03d175ce1b7a..33a1c12f558e 100644 > --- a/common/verity > +++ b/common/verity > @@ -400,9 +400,12 @@ _fsv_scratch_corrupt_merkle_tree() > local ascii=$(printf "%d" "'$byte'") > # This command will find a Merkle tree item for the inode (-I $ino,37,0) > # in the default filesystem tree (-r 5) and corrupt one byte (-b 1) at > - # $offset (-o $offset) with the ascii representation of the byte we read > - # (-v $ascii) > - $BTRFS_CORRUPT_BLOCK_PROG -r 5 -I $ino,37,0 -v $ascii -o $offset -b 1 $SCRATCH_DEV > + # $offset (-o|--offset $offset) with the ascii > + # representation of the byte we read (-v|--value $ascii) > + $BTRFS_CORRUPT_BLOCK_PROG -r 5 -I $ino,37,0 \ > + $BTRFS_CORRUPT_BLOCK_OPT_VALUE $ascii \ > + $BTRFS_CORRUPT_BLOCK_OPT_OFFSET $offset \ > + -b 1 $SCRATCH_DEV > (( offset += 1 )) > done > _scratch_mount > diff --git a/tests/btrfs/290 b/tests/btrfs/290 > index 61e741faeb45..d6f777776838 100755 > --- a/tests/btrfs/290 > +++ b/tests/btrfs/290 > @@ -58,7 +58,7 @@ corrupt_inline() { > _scratch_unmount > # inline data starts at disk_bytenr > # overwrite the first u64 with random bogus junk > - $BTRFS_CORRUPT_BLOCK_PROG -i $ino -x 0 -f disk_bytenr $SCRATCH_DEV > /dev/null 2>&1 > + $BTRFS_CORRUPT_BLOCK_PROG -i $ino -x 0 -f disk_bytenr $SCRATCH_DEV > _scratch_mount > validate $f > } > @@ -72,7 +72,8 @@ corrupt_prealloc_to_reg() { > _scratch_unmount > # ensure non-zero at the pre-allocated region on disk > # set extent type from prealloc (2) to reg (1) > - $BTRFS_CORRUPT_BLOCK_PROG -i $ino -x 0 -f type -v 1 $SCRATCH_DEV >/dev/null 2>&1 > + $BTRFS_CORRUPT_BLOCK_PROG -i $ino -x 0 -f type \ > + $BTRFS_CORRUPT_BLOCK_OPT_VALUE 1 $SCRATCH_DEV > _scratch_mount > # now that it's a regular file, reading actually looks at the previously > # preallocated region, so ensure that has non-zero contents. > @@ -88,7 +89,8 @@ corrupt_reg_to_prealloc() { > _fsv_enable $f > _scratch_unmount > # set type from reg (1) to prealloc (2) > - $BTRFS_CORRUPT_BLOCK_PROG -i $ino -x 0 -f type -v 2 $SCRATCH_DEV >/dev/null 2>&1 > + $BTRFS_CORRUPT_BLOCK_PROG -i $ino -x 0 -f type \ > + $BTRFS_CORRUPT_BLOCK_OPT_VALUE 2 $SCRATCH_DEV > _scratch_mount > validate $f > } > @@ -104,7 +106,8 @@ corrupt_punch_hole() { > _fsv_enable $f > _scratch_unmount > # change disk_bytenr to 0, representing a hole > - $BTRFS_CORRUPT_BLOCK_PROG -i $ino -x 4096 -f disk_bytenr -v 0 $SCRATCH_DEV > /dev/null 2>&1 > + $BTRFS_CORRUPT_BLOCK_PROG -i $ino -x 4096 -f disk_bytenr \ > + $BTRFS_CORRUPT_BLOCK_OPT_VALUE 0 $SCRATCH_DEV > _scratch_mount > validate $f > } > @@ -118,7 +121,8 @@ corrupt_plug_hole() { > _fsv_enable $f > _scratch_unmount > # change disk_bytenr to some value, plugging the hole > - $BTRFS_CORRUPT_BLOCK_PROG -i $ino -x 4096 -f disk_bytenr -v 13639680 $SCRATCH_DEV > /dev/null 2>&1 > + $BTRFS_CORRUPT_BLOCK_PROG -i $ino -x 4096 -f disk_bytenr \ > + $BTRFS_CORRUPT_BLOCK_OPT_VALUE 13639680 $SCRATCH_DEV > _scratch_mount > validate $f > } > @@ -132,7 +136,11 @@ corrupt_verity_descriptor() { > _scratch_unmount > # key for the descriptor item is <inode, BTRFS_VERITY_DESC_ITEM_KEY, 1>, > # 88 is X. So we write 5 Xs to the start of the descriptor > - $BTRFS_CORRUPT_BLOCK_PROG -r 5 -I $ino,36,1 -v 88 -o 0 -b 5 $SCRATCH_DEV > /dev/null 2>&1 > + btrfs in dump-tree -t 5 $SCRATCH_DEV > $tmp.desc_dump_tree > + $BTRFS_CORRUPT_BLOCK_PROG -r 5 -I $ino,36,1 \ > + $BTRFS_CORRUPT_BLOCK_OPT_VALUE 88 \ > + $BTRFS_CORRUPT_BLOCK_OPT_OFFSET 0 \ > + -b 5 $SCRATCH_DEV > _scratch_mount > validate $f > } > @@ -144,7 +152,10 @@ corrupt_root_hash() { > local ino=$(get_ino $f) > _fsv_enable $f > _scratch_unmount > - $BTRFS_CORRUPT_BLOCK_PROG -r 5 -I $ino,36,1 -v 88 -o 16 -b 1 $SCRATCH_DEV > /dev/null 2>&1 > + $BTRFS_CORRUPT_BLOCK_PROG -r 5 -I $ino,36,1 \ > + $BTRFS_CORRUPT_BLOCK_OPT_VALUE 88 \ > + $BTRFS_CORRUPT_BLOCK_OPT_OFFSET 16 \ > + -b 1 $SCRATCH_DEV > _scratch_mount > validate $f > } > @@ -159,7 +170,10 @@ corrupt_merkle_tree() { > # key for the descriptor item is <inode, BTRFS_VERITY_MERKLE_ITEM_KEY, 0>, > # 88 is X. So we write 5 Xs to somewhere in the middle of the first > # merkle item > - $BTRFS_CORRUPT_BLOCK_PROG -r 5 -I $ino,37,0 -v 88 -o 100 -b 5 $SCRATCH_DEV > /dev/null 2>&1 > + $BTRFS_CORRUPT_BLOCK_PROG -r 5 -I $ino,37,0 \ > + $BTRFS_CORRUPT_BLOCK_OPT_VALUE 88 \ > + $BTRFS_CORRUPT_BLOCK_OPT_OFFSET 100 \ > + -b 5 $SCRATCH_DEV > _scratch_mount > validate $f > } > -- > 2.39.3 > >