All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: fstests@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org, dsterba@suse.cz
Subject: [PATCH] common/btrfs: set BTRFS_CORRUPT_BLOCK_OPT_<VALUE|OFFSET>
Date: Thu, 21 Mar 2024 09:39:22 +0530	[thread overview]
Message-ID: <eb2493499d2f30f43afa09e980589bb4f15e9789.1710984595.git.anand.jain@oracle.com> (raw)
In-Reply-To: <cover.1710871719.git.dsterba@suse.com>

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.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
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


  parent reply	other threads:[~2024-03-21  4:10 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 18:11 [PATCH 0/5] Btrfs fstests fixups and updates David Sterba
2024-03-19 18:12 ` [PATCH 1/5] common/verity: use the correct options for btrfs-corrupt-block David Sterba
2024-03-20  9:58   ` Anand Jain
2024-03-20 15:23     ` David Sterba
2024-03-24  7:56       ` Anand Jain
2024-03-19 18:12 ` [PATCH 2/5] btrfs/131,btrfs/172,btrfs/206: add check for block-group-tree feature in btrfs David Sterba
2024-03-20 10:01   ` Anand Jain
2024-03-19 18:12 ` [PATCH 3/5] btrfs/330: add test to validate ro/rw subvol mounting David Sterba
2024-03-20 11:33   ` Anand Jain
2024-03-20 17:01     ` Filipe Manana
2024-03-21  3:51       ` Anand Jain
2024-03-19 18:12 ` [PATCH 4/5] common/rc: use proper temporary file path in _repair_test_fs() David Sterba
2024-03-20 11:35   ` Anand Jain
2024-03-19 18:12 ` [PATCH 5/5] generic/733: disable for btrfs David Sterba
2024-03-19 21:01   ` Christoph Hellwig
2024-03-19 21:10     ` Darrick J. Wong
2024-03-19 21:16       ` Christoph Hellwig
2024-03-20 15:58     ` David Sterba
2024-03-21 21:36       ` Christoph Hellwig
2024-03-21 21:52         ` Kent Overstreet
2024-03-22 15:08           ` Josef Bacik
2024-03-22 15:45             ` Darrick J. Wong
2024-03-22 18:28             ` Kent Overstreet
2024-03-20  9:49 ` [PATCH 0/5] Btrfs fstests fixups and updates Anand Jain
2024-03-20 15:26   ` David Sterba
2024-03-21  4:09 ` Anand Jain [this message]
2024-03-21 11:13   ` [PATCH] common/btrfs: set BTRFS_CORRUPT_BLOCK_OPT_<VALUE|OFFSET> Filipe Manana
2024-03-21 12:34     ` Anand Jain
2024-03-24  8:35 ` [PATCH 0/5] Btrfs fstests fixups and updates Anand Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb2493499d2f30f43afa09e980589bb4f15e9789.1710984595.git.anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.cz \
    --cc=fstests@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.