[PATCH] common/btrfs: set BTRFS_CORRUPT_BLOCK_OPT_<VALUE|OFFSET>

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]



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@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





[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux