Skip to contentSkip to conversation

Fix Btrfs tests to work on non-4k block sized fs instances

PATCH In review Chandan Rajendra 2 participants 17 messages Nov 25, 2015 Btrfs file system

lore
Share & tools
lore
#1 lore raw

PATCH 1/12 Filter xfs_io and od's output in units of FS block size and the CPU's page size

In reply to Chandan Rajendra

The helpers will be used to make btrfs tests that assume 4k as the block size to work on non-4k blocksized filesystem instances as well.

---
 common/filter | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/rc     |  5 +++++
 2 files changed, 57 insertions(+)
common/filter +52 -0
index af456c9..faa6f82 100644
@@ -229,6 +229,45 @@ _filter_xfs_io_unique()
     common_line_filter | _filter_xfs_io
 }
 
+_filter_xfs_io_units_modified()
+{
+	UNIT=$1
+	UNIT_SIZE=$2
+
+	$AWK_PROG -v unit="$UNIT" -v unit_size=$UNIT_SIZE '
+		/wrote/ {
+			split($2, bytes, "/")
+
+			bytes_written = strtonum(bytes[1])
+
+			offset = strtonum($NF)
+
+			unit_start = offset / unit_size
+			unit_start = int(unit_start)
+			unit_end = (offset + bytes_written - 1) / unit_size
+			unit_end = int(unit_end)
+
+			printf("%ss modified: [%d - %d]\n", unit, unit_start, unit_end)
+
+			next
+		}
+	'
+}
+
+_filter_xfs_io_blocks_modified()
+{
+	BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
+
+	_filter_xfs_io_units_modified "Block" $BLOCK_SIZE
+}
+
+_filter_xfs_io_pages_modified()
+{
+	PAGE_SIZE=$(get_page_size)
+
+	_filter_xfs_io_units_modified "Page" $PAGE_SIZE
+}
+
 _filter_test_dir()
 {
 	sed -e "s,$TEST_DEV,TEST_DEV,g" -e "s,$TEST_DIR,TEST_DIR,g"
@@ -323,5 +362,18 @@ _filter_ro_mount() {
 	    -e "s/mount: cannot mount block device/mount: cannot mount/g"
 }
 
+_filter_od()
+{
+	BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
+	$AWK_PROG -v block_size=$BLOCK_SIZE '
+		/^[0-9]+/ {
+			offset = strtonum("0"$1);
+			$1 = sprintf("%o", offset / block_size);
+			print $0;
+		}
+		/\*/
+	'
+}
+
 # make sure this script returns success
 /bin/true
common/rc +5 -0
index 4c2f42c..acda6cb 100644
@@ -3151,6 +3151,11 @@ get_block_size()
 	echo `stat -f -c %S $1`
 }
 
+get_page_size()
+{
+	echo $(getconf PAGE_SIZE)
+}
+
 init_rc
 
 ################################################################################
Signature · 1 line
2.1.0
#0 lore raw

cover Fix Btrfs tests to work on non-4k block sized fs instances

This patchset fixes Btrfs tests to work on variable block size. This is based off the RFC patch sent during March of this year
(https://www.marc.info/?l=linux-btrfs&m=142736088310300&w=2).

Currently, some of the tests are written with the assumption that 4k is the block size of the filesystem instance. On architectures (e.g. ppc64) with a larger page size (and hence larger block size), these tests fail because the block bondaries assumed by the the tests are no longer true and hence btrfs_ioctl_clone() (which requires a block aligned file offset range) returns -EINVAL.

To fix the issue, This patchset adds three new filter functions:
1. _filter_xfs_io_blocks_modified
2. _filter_xfs_io_pages_modified
3. _filter_od

P.S: Since the changes made are trivial, I could have clubbed all the patches into two patches. First patch introducing the new filtering functions and the second patch containing the changes to made to the tests. If this approach sounds right, I can post version V2 with the two patches containing the relevant changes.

Chandan Rajendra (12):
Filter xfs_io and od's output in units of FS block size and the CPU's
page size
Fix btrfs/017 to work on non-4k block sized filesystems Fix btrfs/052 to work on non-4k block sized filesystems Fix btrfs/055 to work on non-4k block sized filesystems Fix btrfs/056 to work on non-4k block sized filesystems Fix btrfs/094 to work on non-4k block sized filesystems Fix btrfs/095 to work on non-4k block sized filesystems Fix btrfs/096 to work on non-4k block sized filesystems Fix btrfs/097 to work on non-4k block sized filesystems Fix btrfs/098 to work on non-4k block sized filesystems Fix btrfs/103 to work on non-4k block sized filesystems Fix btrfs/106 to work on non-4k block sized filesystems

 common/filter       |  52 +++++
 common/rc           |   5 +
 tests/btrfs/017     |  16 +-
 tests/btrfs/017.out |   3 +-
 tests/btrfs/052     | 127 +++++++-----
 tests/btrfs/052.out | 546 +++++++++++++++++++++++-----------------------------
 tests/btrfs/055     | 128 +++++++-----
 tests/btrfs/055.out | 378 ++++++++++++++++++------------------
 tests/btrfs/056     |  51 +++--
 tests/btrfs/056.out | 152 ++++++---------
 tests/btrfs/094     |  78 +++++---
 tests/btrfs/094.out |  17 +-
 tests/btrfs/095     | 113 ++++++-----
 tests/btrfs/095.out |  10 +-
 tests/btrfs/096     |  45 +++--
 tests/btrfs/096.out |  15 +-
 tests/btrfs/097     |  42 ++--
 tests/btrfs/097.out |   7 +-
 tests/btrfs/098     |  65 ++++---
 tests/btrfs/098.out |   7 +-
 tests/btrfs/103     |  47 +++--
 tests/btrfs/103.out |  48 ++---
 tests/btrfs/106     |  42 ++--
 tests/btrfs/106.out |  14 +-
 24 files changed, 1018 insertions(+), 990 deletions(-)
Signature · 1 line
2.1.0
#2 lore raw

PATCH 2/12 Fix btrfs/017 to work on non-4k block sized filesystems

This commit makes use of the new _filter_xfs_io_blocks_modified filtering function to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/017     | 16 ++++++++++++----
 tests/btrfs/017.out |  3 +--
 2 files changed, 13 insertions(+), 6 deletions(-)
tests/btrfs/017 +12 -4
index f8855e3..34c5f0a 100755
@@ -63,13 +63,21 @@ rm -f $seqres.full
 _scratch_mkfs "--nodesize 65536" >>$seqres.full 2>&1
 _scratch_mount
 
-$XFS_IO_PROG -f -d -c "pwrite 0 8K" $SCRATCH_MNT/foo | _filter_xfs_io
+BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
+EXTENT_SIZE=$((2 * $BLOCK_SIZE))
+
+$XFS_IO_PROG -f -d -c "pwrite 0 $EXTENT_SIZE" $SCRATCH_MNT/foo \
+	| _filter_xfs_io_blocks_modified
 
 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap
 
-$CLONER_PROG -s 0 -d 0 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo-reflink
-$CLONER_PROG -s 0 -d 0 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/snap/foo-reflink
-$CLONER_PROG -s 0 -d 0 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/snap/foo-reflink2
+$CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo $SCRATCH_MNT/foo-reflink
+
+$CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo \
+	     $SCRATCH_MNT/snap/foo-reflink
+
+$CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo \
+	     $SCRATCH_MNT/snap/foo-reflink2
 
 _run_btrfs_util_prog quota enable $SCRATCH_MNT
 _run_btrfs_util_prog quota rescan -w $SCRATCH_MNT
tests/btrfs/017.out +1 -2
index f940f3a..503eb88 100644
@@ -1,5 +1,4 @@
 QA output created by 017
-wrote 8192/8192 bytes at offset 0
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+Blocks modified: [0 - 1]
 65536 65536
 65536 65536
Signature · 1 line
2.1.0
#3 lore raw

PATCH 3/12 Fix btrfs/052 to work on non-4k block sized filesystems

In reply to Chandan Rajendra

This commit makes use of the new _filter_xfs_io_blocks_modified filtering function to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/052     | 127 +++++++-----
 tests/btrfs/052.out | 546 +++++++++++++++++++++++-----------------------------
 2 files changed, 323 insertions(+), 350 deletions(-)
tests/btrfs/052 +77 -50
index c75193d..55c8332 100755
@@ -59,78 +59,105 @@ test_btrfs_clone_same_file()
 	_scratch_mkfs >/dev/null 2>&1
 	_scratch_mount $MOUNT_OPTIONS
 
-	# Create a file with 5 extents, 4 of 8Kb each and 1 of 64Kb.
-	$XFS_IO_PROG -f -c "pwrite -S 0x01 -b 8192 0 8192" $SCRATCH_MNT/foo \
-		| _filter_xfs_io
+	BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
+
+	EXTENT_SIZE=$((2 * $BLOCK_SIZE))
+
+	# Create a file with 5 extents, 4 of 2 blocks each and 1 of 16 blocks.
+	OFFSET=0
+	$XFS_IO_PROG -f -c "pwrite -S 0x01 -b $EXTENT_SIZE $OFFSET $EXTENT_SIZE" $SCRATCH_MNT/foo \
+		| _filter_xfs_io_blocks_modified
 	sync
-	$XFS_IO_PROG -c "pwrite -S 0x02 -b 8192 8192 8192" $SCRATCH_MNT/foo \
-		| _filter_xfs_io
+
+	OFFSET=$(($OFFSET + $EXTENT_SIZE))
+	$XFS_IO_PROG -c "pwrite -S 0x02 -b $EXTENT_SIZE $OFFSET $EXTENT_SIZE" $SCRATCH_MNT/foo \
+		| _filter_xfs_io_blocks_modified
 	sync
-	$XFS_IO_PROG -c "pwrite -S 0x03 -b 8192 16384 8192" $SCRATCH_MNT/foo \
-		| _filter_xfs_io
+
+	OFFSET=$(($OFFSET + $EXTENT_SIZE))
+	$XFS_IO_PROG -c "pwrite -S 0x03 -b $EXTENT_SIZE $OFFSET $EXTENT_SIZE" $SCRATCH_MNT/foo \
+		| _filter_xfs_io_blocks_modified
 	sync
-	$XFS_IO_PROG -c "pwrite -S 0x04 -b 8192 24576 8192" $SCRATCH_MNT/foo \
-		| _filter_xfs_io
+
+	OFFSET=$(($OFFSET + $EXTENT_SIZE))
+	$XFS_IO_PROG -c "pwrite -S 0x04 -b $EXTENT_SIZE $OFFSET $EXTENT_SIZE" $SCRATCH_MNT/foo \
+		| _filter_xfs_io_blocks_modified
 	sync
-	$XFS_IO_PROG -c "pwrite -S 0x05 -b 65536 32768 65536" $SCRATCH_MNT/foo \
-		| _filter_xfs_io
+
+	OFFSET=$(($OFFSET + $EXTENT_SIZE))
+	EXTENT_SIZE=$((16 * $BLOCK_SIZE))
+	$XFS_IO_PROG -c "pwrite -S 0x05 -b $EXTENT_SIZE $OFFSET $EXTENT_SIZE" $SCRATCH_MNT/foo \
+		| _filter_xfs_io_blocks_modified
 	sync
 
 	# Digest of initial content.
-	md5sum $SCRATCH_MNT/foo | _filter_scratch
+	orig_hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
 
 	# Same source and target ranges - must fail.
-	$CLONER_PROG -s 8192 -d 8192 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
+	$CLONER_PROG -s $((2 * $BLOCK_SIZE)) -d $((2 * $BLOCK_SIZE)) \
+		     -l $((2 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/foo
 	# Check file content didn't change.
-	md5sum $SCRATCH_MNT/foo | _filter_scratch
+	hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
+	if [ $orig_hash != $hash ]; then
+		echo "Cloning same source and target ranges:"\
+		     "Mimatching hash values detected."
+	fi
 
 	# Intersection between source and target ranges - must fail too.
-	$CLONER_PROG -s 4096 -d 8192 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
+	# $CLONER_PROG -s 4096 -d 8192 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
+	$CLONER_PROG -s $((1 * $BLOCK_SIZE)) -d $((2 * $BLOCK_SIZE)) \
+		     -l $((2 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/foo
 	# Check file content didn't change.
-	md5sum $SCRATCH_MNT/foo | _filter_scratch
+	hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
+	if [ $orig_hash != $hash ]; then
+		echo "Cloning intersection between source and target ranges:"\
+		     "Mismatching hash values detected."
+	fi
 
 	# Clone an entire extent from a higher range to a lower range.
-	$CLONER_PROG -s 24576 -d 0 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
-
-	# Check entire file, the 8Kb block at offset 0 now has the same content
-	# as the 8Kb block at offset 24576.
-	od -t x1 $SCRATCH_MNT/foo
+	$CLONER_PROG -s $((6 * $BLOCK_SIZE)) -d 0 -l $((2 * $BLOCK_SIZE)) \
+		     $SCRATCH_MNT/foo $SCRATCH_MNT/foo
+	# Check entire file, 0th and 1st blocks now have the same content
+	# as the 6th and 7th blocks.
+	od -t x1 $SCRATCH_MNT/foo | _filter_od
 
 	# Clone an entire extent from a lower range to a higher range.
-	$CLONER_PROG -s 8192 -d 16384 -l 8192 $SCRATCH_MNT/foo $SCRATCH_MNT/foo
-
-	# Check entire file, the 8Kb block at offset 0 now has the same content
-	# as the 8Kb block at offset 24576, and the 8Kb block at offset 16384
-	# now has the same content as the 8Kb block at offset 8192.
-	od -t x1 $SCRATCH_MNT/foo
-
-	# Now clone 1 extent and an half into the file range starting at offset
-	# 65536. So we get the second half of the extent at offset 16384 and the
-	# whole extent at 24576 cloned into the middle of the 64Kb extent that
-	# starts at file offset 32768. This makes the clone ioctl process more
-	# extent items from the b+tree and forces a split of the large 64Kb
-	# extent at the end of the file.
-	$CLONER_PROG -s 20480 -d 65536 -l 12288 $SCRATCH_MNT/foo \
-		$SCRATCH_MNT/foo
-
-	# Check entire file. Besides the previous changes, we now should have
-	# 4096 bytes with the value 0x02 at file offset 65536, and 8192 bytes
-	# with value 0x04 at the file offset 69632. The ranges [32768, 65536[
-	# and [77824, 98304[ should remain with all bytes having the value 0x05.
-	od -t x1 $SCRATCH_MNT/foo
-
-	# Now update 8Kb of data at offset 0. The extent at this position is a
-	# clone of the extent at offset 24576. Check that writing to this offset
-	# doesn't change data at offset 24576.
-	$XFS_IO_PROG -c "pwrite -S 0xff -b 8192 0 8192" $SCRATCH_MNT/foo \
-		| _filter_xfs_io
-	od -t x1 $SCRATCH_MNT/foo
+	$CLONER_PROG -s $((2 * $BLOCK_SIZE)) -d $((4 * $BLOCK_SIZE)) \
+		     -l $((2 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/foo
+	# Check entire file, 0th and 1st blocks now have the same content
+	# as the 6th and 7th block, and 4th and 5th blocks now has the same
+	# content as the 2nd and 3rd blocks.
+	od -t x1 $SCRATCH_MNT/foo | _filter_od
+
+	# Now clone 1 extent and an half into the file range starting
+	# at 16th block So we get the second half of the extent
+	# starting at 4th block and the whole extent starting at 6th
+	# block cloned into the middle of the 16 blocks extent that
+	# starts at 8th block. This makes the clone ioctl process more
+	# extent items from the b+tree and forces a split of the large
+	# 16-block extent at the end of the file.
+	$CLONER_PROG -s $((5 * $BLOCK_SIZE)) -d $((16 * $BLOCK_SIZE)) \
+		     -l $((3 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/foo
+
+	# Check entire file. Besides the previous changes, we now
+	# should have 1 block with the value 0x02 at 16th block, and 2
+	# blocks with value 0x04 starting at the 17th block . The
+	# block ranges [8, 16[ and [19, 24[ should remain with all
+	# bytes having the value 0x05.
+	od -t x1 $SCRATCH_MNT/foo | _filter_od
+
+	# Now update 2 blocks of data at offset 0. The extent at this
+	# position is a clone of the extent at 6th block. Check that
+	# writing to this offset doesn't change data at 6th block.
+	$XFS_IO_PROG -c "pwrite -S 0xff -b $((2 * $BLOCK_SIZE)) 0 $((2 * $BLOCK_SIZE))" \
+		     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+	od -t x1 $SCRATCH_MNT/foo | _filter_od
 
 	# Check that after defragmenting the file and re-mounting, the file
 	# content remains exactly the same as before.
 	_run_btrfs_util_prog filesystem defragment $SCRATCH_MNT/foo
 	_scratch_remount
-	od -t x1 $SCRATCH_MNT/foo
+	od -t x1 $SCRATCH_MNT/foo | _filter_od
 
 	# Verify that there are no consistency errors.
 	_check_scratch_fs
tests/btrfs/052.out +246 -300

745 lines not on this page · raw message

Signature · 1 line
2.1.0
#4 lore raw

PATCH 4/12 Fix btrfs/055 to work on non-4k block sized filesystems

In reply to Chandan Rajendra

This commit makes use of the new _filter_xfs_io_blocks_modified and _filter_od filtering functions to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/055     | 128 ++++++++++--------
 tests/btrfs/055.out | 378 +++++++++++++++++++++++++---------------------------
 2 files changed, 259 insertions(+), 247 deletions(-)
tests/btrfs/055 +75 -53
index c0dd9ed..1f50850 100755
@@ -60,88 +60,110 @@ test_btrfs_clone_with_holes()
 	_scratch_mkfs "$1" >/dev/null 2>&1
 	_scratch_mount
 
-	# Create a file with 4 extents and 1 hole, all with a size of 8Kb each.
-	# The hole is in the range [16384, 24576[.
-	$XFS_IO_PROG -s -f -c "pwrite -S 0x01 -b 8192 0 8192" \
-			-c "pwrite -S 0x02 -b 8192 8192 8192" \
-			-c "pwrite -S 0x04 -b 8192 24576 8192" \
-			-c "pwrite -S 0x05 -b 8192 32768 8192" \
-		$SCRATCH_MNT/foo | _filter_xfs_io
+	BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
 
-	# Clone destination file, 1 extent of 96kb.
-	$XFS_IO_PROG -s -f -c "pwrite -S 0xff -b 98304 0 98304" \
-		$SCRATCH_MNT/bar | _filter_xfs_io
+	EXTENT_SIZE=$((2 * $BLOCK_SIZE))
 
-	# Clone 2nd extent, 8Kb hole and 3rd extent of foo into bar.
-	$CLONER_PROG -s 8192 -d 0 -l 24576 $SCRATCH_MNT/foo $SCRATCH_MNT/bar
+	OFFSET=0
+
+	# Create a file with 4 extents and 1 hole, all with 2 blocks each.
+	# The hole is in the block range [4, 5[.
+	$XFS_IO_PROG -s -f -c "pwrite -S 0x01 -b $EXTENT_SIZE $OFFSET $EXTENT_SIZE" \
+		     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
+	OFFSET=$(($OFFSET + $EXTENT_SIZE))
+	$XFS_IO_PROG -s -f -c "pwrite -S 0x02 -b $EXTENT_SIZE $OFFSET $EXTENT_SIZE" \
+		     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
+	OFFSET=$(($OFFSET + 2 * $EXTENT_SIZE))
+	$XFS_IO_PROG -s -f -c "pwrite -S 0x04 -b $EXTENT_SIZE $OFFSET $EXTENT_SIZE" \
+		     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
+	OFFSET=$(($OFFSET + $EXTENT_SIZE))
+	$XFS_IO_PROG -s -f -c "pwrite -S 0x05 -b $EXTENT_SIZE $OFFSET $EXTENT_SIZE" \
+		     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
+	# Clone destination file, 1 extent of 24 blocks.
+	EXTENT_SIZE=$((24 * $BLOCK_SIZE))
+	$XFS_IO_PROG -s -f -c "pwrite -S 0xff -b $EXTENT_SIZE 0 $EXTENT_SIZE" \
+		$SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
+
+	# Clone 2nd extent, 2-blocks sized hole and 3rd extent of foo into bar.
+	$CLONER_PROG -s $((2 * $BLOCK_SIZE)) -d 0 -l $((6 * $BLOCK_SIZE)) \
+		     $SCRATCH_MNT/foo $SCRATCH_MNT/bar
 
 	# Verify both extents and the hole were cloned.
 	echo "1) Check both extents and the hole were cloned"
-	od -t x1 $SCRATCH_MNT/bar
+	od -t x1 $SCRATCH_MNT/bar | _filter_od
 
-	# Cloning range starts at the middle of an hole.
-	$CLONER_PROG -s 20480 -d 32768 -l 12288 $SCRATCH_MNT/foo \
-		$SCRATCH_MNT/bar
+	# Cloning range starts at the middle of a hole.
+	$CLONER_PROG -s $((5 * $BLOCK_SIZE)) -d $((8 * $BLOCK_SIZE)) \
+		     -l $((3 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/bar
 
-	# Verify that half of the hole and the following 8Kb extent were cloned.
-	echo "2) Check half hole and one 8Kb extent were cloned"
-	od -t x1 $SCRATCH_MNT/bar
+	# Verify that half of the hole and the following 2 block extent were cloned.
+	echo "2) Check half hole and the following 2 block extent were cloned"
+	od -t x1 $SCRATCH_MNT/bar | _filter_od
 
-	# Cloning range ends at the middle of an hole.
-	$CLONER_PROG -s 0 -d 65536 -l 20480 $SCRATCH_MNT/foo $SCRATCH_MNT/bar
+	# Cloning range ends at the middle of a hole.
+	$CLONER_PROG -s 0 -d $((16 * $BLOCK_SIZE)) -l $((5 * $BLOCK_SIZE)) \
+		     $SCRATCH_MNT/foo $SCRATCH_MNT/bar
 
-	# Verify that 2 extents of 8kb and a 4kb hole were cloned.
-	echo "3) Check that 2 extents of 8kb eacg and a 4kb hole were cloned"
-	od -t x1 $SCRATCH_MNT/bar
+	# Verify that 2 extents of 2 blocks size and a 1-block hole were cloned.
+	echo "3) Check that 2 extents of 2 blocks each and a hole of 1 block were cloned"
+	od -t x1 $SCRATCH_MNT/bar | _filter_od
 
-	# Create a 24Kb hole at the end of the source file (foo).
-	$XFS_IO_PROG -c "truncate 65536" $SCRATCH_MNT/foo
+	# Create a 6-block hole at the end of the source file (foo).
+	$XFS_IO_PROG -c "truncate $((16 * $BLOCK_SIZE))" $SCRATCH_MNT/foo \
+		| _filter_xfs_io_blocks_modified
 	sync
 
 	# Now clone a range that overlaps that hole at the end of the foo file.
-	# It should clone the last 4Kb of the extent at offset 32768 and the
-	# first 8kb of the 24kb hole at the end of foo.
-	$CLONER_PROG -s 36864 -d 86016 -l 12288 $SCRATCH_MNT/foo \
-		$SCRATCH_MNT/bar
+	# It should clone the 10th block and the first two blocks of the hole
+	# at the end of foo.
+	$CLONER_PROG -s $((9 * $BLOCK_SIZE)) -d $((21 * $BLOCK_SIZE)) \
+		     -l $((3 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/bar
 
-	# Verify that the second half of the 8Kb extent at offset 32768 of foo
-	# and the first 8Kb of the 24kb hole of foo were cloned into bar.
-	echo "4) Check that 4kb of 1 extent and 8Kb of an hole were cloned"
-	od -t x1 $SCRATCH_MNT/bar
+	# Verify that the 9th block of foo and the first 2 blocks of the
+	# 6-block hole of foo were cloned into bar.
+	echo "4) Check that a block of 1 extent and 2 blocks of a hole were cloned"
+	od -t x1 $SCRATCH_MNT/bar | _filter_od
 
 	# Clone the same range as before, but clone it into a different offset
 	# of the target (bar) such that it increases the size of the target
-	# by 8Kb.
-	$CLONER_PROG -s 36864 -d 94208 -l 12288 $SCRATCH_MNT/foo \
-		$SCRATCH_MNT/bar
+	# by 2 blocks.
+	$CLONER_PROG -s $((9 * $BLOCK_SIZE)) -d $((23 * $BLOCK_SIZE)) \
+		     -l $((3 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/bar
 
-	# Verify that the second half of the 8Kb extent at offset 32768 of foo
-	# and the first 8Kb of the 24kb hole of foo were cloned into bar at
-	# bar's offset 94208 and that bar's size increased by 8Kb.
-	echo "5) Check that 4kb of 1 extent and 8Kb of an hole were cloned and file size increased"
-	od -t x1 $SCRATCH_MNT/bar
+	# Verify that the 9th block of foo and the first 2 blocks of the 6-block
+	# hole of foo were cloned into bar at bar's 23rd block and that bar's
+	# size increased by 2 blocks.
+	echo "5) Check that a block of 1 extent and 2 blocks of a hole were" \
+	     "cloned and file size increased"
+	od -t x1 $SCRATCH_MNT/bar | _filter_od
 
 	# Create a new completely sparse file (no extents, it's a big hole).
-	$XFS_IO_PROG -f -c "truncate 100000" $SCRATCH_MNT/qwerty
+	$XFS_IO_PROG -f -c "truncate $((25 * $BLOCK_SIZE))" $SCRATCH_MNT/qwerty \
+		| _filter_xfs_io_blocks_modified
 	sync
 
 	# Test cloning a range from the sparse file to the bar file without
 	# increasing bar's size.
-	$CLONER_PROG -s 4096 -d 0 -l 8192 $SCRATCH_MNT/qwerty $SCRATCH_MNT/bar
+	$CLONER_PROG -s $((1 * $BLOCK_SIZE)) -d 0 -l $((2 * $BLOCK_SIZE)) \
+		     $SCRATCH_MNT/qwerty $SCRATCH_MNT/bar
 
-	# First 8Kb of bar should now be zeroes.
-	echo "6) Check that 8kb of the hole were cloned"
-	od -t x1 $SCRATCH_MNT/bar
+	# First 2 blocks of bar should now be zeroes.
+	echo "6) Check that 2 blocks of the hole were cloned"
+	od -t x1 $SCRATCH_MNT/bar | _filter_od
 
 	# Test cloning a range from the sparse file to the end of the bar file.
-	# The bar file currently has a size of 106496 bytes.
-	$CLONER_PROG -s 0 -d 106496 -l 32768 $SCRATCH_MNT/qwerty \
+	# The bar file currently has 26 blocks.
+	$CLONER_PROG -s 0 -d $((26 * $BLOCK_SIZE)) -l $((8 * $BLOCK_SIZE)) $SCRATCH_MNT/qwerty \
 		$SCRATCH_MNT/bar
 
-	# Verify bar's size increased to 106496 + 32768 bytes (136Kb), and its
-	# last 32768 bytes are all zeroes.
-	echo "7) Check that 32kb of the hole were cloned and the file size increased"
-	od -t x1 $SCRATCH_MNT/bar
+	# Verify bar's size increased to 26 + 8 blocks, and its
+	# last 8 blocks are all zeroes.
+	echo "7) Check that 8 blocks of the hole were cloned and the file size increased"
+	od -t x1 $SCRATCH_MNT/bar | _filter_od
 
 	# Verify that there are no consistency errors.
 	_check_scratch_fs
tests/btrfs/055.out +184 -194

531 lines not on this page · raw message

Signature · 1 line
2.1.0
#5 lore raw

PATCH 5/12 Fix btrfs/056 to work on non-4k block sized filesystems

In reply to Chandan Rajendra

This commit makes use of the new _filter_xfs_io_blocks_modified and _filter_od filtering functions to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/056     |  51 ++++++++++--------
 tests/btrfs/056.out | 152 +++++++++++++++++++++-------------------------------
 2 files changed, 90 insertions(+), 113 deletions(-)
tests/btrfs/056 +30 -21
index 66a59b8..6dc3bfd 100755
@@ -68,33 +68,42 @@ test_btrfs_clone_fsync_log_recover()
 	MOUNT_OPTIONS="$MOUNT_OPTIONS $2"
 	_mount_flakey
 
-	# Create a file with 4 extents and 1 hole, all with a size of 8Kb each.
-	# The hole is in the range [16384, 24576[.
-	$XFS_IO_PROG -s -f -c "pwrite -S 0x01 -b 8192 0 8192" \
-			-c "pwrite -S 0x02 -b 8192 8192 8192" \
-			-c "pwrite -S 0x04 -b 8192 24576 8192" \
-			-c "pwrite -S 0x05 -b 8192 32768 8192" \
-		$SCRATCH_MNT/foo | _filter_xfs_io
-
-	# Clone destination file, 1 extent of 96kb.
-	$XFS_IO_PROG -f -c "pwrite -S 0xff -b 98304 0 98304" -c "fsync" \
-		$SCRATCH_MNT/bar | _filter_xfs_io
-
-	# Clone second half of the 2nd extent, the 8kb hole, the 3rd extent
+	BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
+
+	EXTENT_SIZE=$((2 * $BLOCK_SIZE))
+
+	# Create a file with 4 extents and 1 hole, all with a size of
+	# 2 blocks each.
+	# The hole is in the block range [4, 5].
+	$XFS_IO_PROG -s -f -c "pwrite -S 0x01 -b $EXTENT_SIZE 0 $EXTENT_SIZE" \
+			-c "pwrite -S 0x02 -b $EXTENT_SIZE $((2 * $BLOCK_SIZE)) $EXTENT_SIZE" \
+			-c "pwrite -S 0x04 -b $EXTENT_SIZE $((6 * $BLOCK_SIZE)) $EXTENT_SIZE" \
+			-c "pwrite -S 0x05 -b $EXTENT_SIZE $((8 * $BLOCK_SIZE)) $EXTENT_SIZE" \
+		$SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
+	# Clone destination file, 1 extent of 24 blocks.
+	$XFS_IO_PROG -f -c "pwrite -S 0xff -b $((24 * $BLOCK_SIZE)) 0 $((24 * $BLOCK_SIZE))" \
+		     -c "fsync" $SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
+
+	# Clone second half of the 2nd extent, the 2 block hole, the 3rd extent
 	# and the first half of the 4th extent into file bar.
-	$CLONER_PROG -s 12288 -d 0 -l 24576 $SCRATCH_MNT/foo $SCRATCH_MNT/bar
+	$CLONER_PROG -s $((3 * $BLOCK_SIZE)) -d 0 -l $((6 * $BLOCK_SIZE)) \
+		     $SCRATCH_MNT/foo $SCRATCH_MNT/bar
 	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar
 
 	# Test small files too consisting of 1 inline extent
-	$XFS_IO_PROG -f -c "pwrite -S 0x00 -b 3500 0 3500" -c "fsync" \
-		$SCRATCH_MNT/foo2 | _filter_xfs_io
+	EXTENT_SIZE=$(($BLOCK_SIZE - 48))
+	$XFS_IO_PROG -f -c "pwrite -S 0x00 -b $EXTENT_SIZE 0 $EXTENT_SIZE" -c "fsync" \
+		$SCRATCH_MNT/foo2 | _filter_xfs_io_blocks_modified
 
-	$XFS_IO_PROG -f -c "pwrite -S 0xcc -b 1000 0 1000" -c "fsync" \
-		$SCRATCH_MNT/bar2 | _filter_xfs_io
+	EXTENT_SIZE=$(($BLOCK_SIZE - 1048))
+	$XFS_IO_PROG -f -c "pwrite -S 0xcc -b $EXTENT_SIZE 0 $EXTENT_SIZE" -c "fsync" \
+		$SCRATCH_MNT/bar2 | _filter_xfs_io_blocks_modified
 
 	# Clone the entire foo2 file into bar2, overwriting all data in bar2
 	# and increasing its size.
-	$CLONER_PROG -s 0 -d 0 -l 3500 $SCRATCH_MNT/foo2 $SCRATCH_MNT/bar2
+	EXTENT_SIZE=$(($BLOCK_SIZE - 48))
+	$CLONER_PROG -s 0 -d 0 -l $EXTENT_SIZE $SCRATCH_MNT/foo2 $SCRATCH_MNT/bar2
 	$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/bar2
 
 	_flakey_drop_and_remount yes
@@ -102,10 +111,10 @@ test_btrfs_clone_fsync_log_recover()
 	# Verify the cloned range was persisted by fsync and the log recovery
 	# code did its work well.
 	echo "Verifying file bar content"
-	od -t x1 $SCRATCH_MNT/bar
+	od -t x1 $SCRATCH_MNT/bar | _filter_od
 
 	echo "Verifying file bar2 content"
-	od -t x1 $SCRATCH_MNT/bar2
+	od -t x1 $SCRATCH_MNT/bar2 | _filter_od
 
 	_unmount_flakey
 
tests/btrfs/056.out +60 -92

189 lines not on this page · raw message

Signature · 1 line
2.1.0
#6 lore raw

PATCH 6/12 Fix btrfs/094 to work on non-4k block sized filesystems

In reply to Chandan Rajendra

This commit makes use of the new _filter_xfs_io_blocks_modified filtering function to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/094     | 78 +++++++++++++++++++++++++++++++----------------------
 tests/btrfs/094.out | 17 +++---------
 2 files changed, 49 insertions(+), 46 deletions(-)
tests/btrfs/094 +46 -32
index 6f6cdeb..868c088 100755
@@ -67,36 +67,41 @@ mkdir $send_files_dir
 _scratch_mkfs >>$seqres.full 2>&1
 _scratch_mount "-o compress"
 
-# Create the file with a single extent of 128K. This creates a metadata file
-# extent item with a data start offset of 0 and a logical length of 128K.
-$XFS_IO_PROG -f -c "pwrite -S 0xaa 64K 128K" -c "fsync" \
-	$SCRATCH_MNT/foo | _filter_xfs_io
-
-# Now rewrite the range 64K to 112K of our file. This will make the inode's
-# metadata continue to point to the 128K extent we created before, but now
-# with an extent item that points to the extent with a data start offset of
-# 112K and a logical length of 16K.
-# That metadata file extent item is associated with the logical file offset
-# at 176K and covers the logical file range 176K to 192K.
-$XFS_IO_PROG -c "pwrite -S 0xbb 64K 112K" -c "fsync" \
-	$SCRATCH_MNT/foo | _filter_xfs_io
-
-# Now rewrite the range 180K to 12K. This will make the inode's metadata
-# continue to point the the 128K extent we created earlier, with a single
-# extent item that points to it with a start offset of 112K and a logical
-# length of 4K.
-# That metadata file extent item is associated with the logical file offset
-# at 176K and covers the logical file range 176K to 180K.
-$XFS_IO_PROG -c "pwrite -S 0xcc 180K 12K" -c "fsync" \
-	$SCRATCH_MNT/foo | _filter_xfs_io
+BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
+
+# Create the file with a single extent of 32 blocks. This creates a metadata
+# file extent item with a data start offset of 0 and a logical length of
+# 32 blocks.
+$XFS_IO_PROG -f -c "pwrite -S 0xaa $((16 * $BLOCK_SIZE)) $((32 * $BLOCK_SIZE))" \
+	     -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
+# Now rewrite the block range [16, 28[ of our file. This will make
+# the inode's metadata continue to point to the single 32 block extent
+# we created before, but now with an extent item that points to the
+# extent with a data start offset referring to the 28th block and a
+# logical length of 4 blocks.
+# That metadata file extent item is associated with the block range
+# [44, 48[.
+$XFS_IO_PROG -c "pwrite -S 0xbb $((16 * $BLOCK_SIZE)) $((28 * $BLOCK_SIZE))" \
+	     -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
+
+# Now rewrite the block range [45, 48[. This will make the inode's
+# metadata continue to point the 32 block extent we created earlier,
+# with a single extent item that points to it with a start offset
+# referring to the 28th block and a logical length of 1 block.
+# That metadata file extent item is associated with the block range
+# [44, 45[.
+$XFS_IO_PROG -c "pwrite -S 0xcc $((45 * $BLOCK_SIZE)) $((3 * $BLOCK_SIZE))" \
+	     -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
 
 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
 
-# Now clone that same region of the 128K extent into a new file, so that it
+# Now clone that same region of the 32 block extent into a new file, so that it
 # gets referenced twice and the incremental send operation below decides to
 # issue a clone operation instead of copying the data.
 touch $SCRATCH_MNT/bar
-$CLONER_PROG -s $((176 * 1024)) -d $((176 * 1024)) -l $((4 * 1024)) \
+$CLONER_PROG -s $((44 * $BLOCK_SIZE)) -d $((44 * $BLOCK_SIZE)) -l $BLOCK_SIZE \
 	$SCRATCH_MNT/foo $SCRATCH_MNT/bar
 
 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
@@ -105,10 +110,11 @@ _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
 	-f $send_files_dir/2.snap
 
-echo "File digests in the original filesystem:"
-md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
-md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
-md5sum $SCRATCH_MNT/mysnap2/bar | _filter_scratch
+# echo "File digests in the original filesystem:"
+declare -A src_fs_hash
+src_fs_hash[mysnap1_foo]=$(md5sum $SCRATCH_MNT/mysnap1/foo | cut -f 1 -d ' ')
+src_fs_hash[mysnap2_foo]=$(md5sum $SCRATCH_MNT/mysnap2/foo | cut -f 1 -d ' ')
+src_fs_hash[mysnap2_bar]=$(md5sum $SCRATCH_MNT/mysnap2/bar | cut -f 1 -d ' ')
 
 # Now recreate the filesystem by receiving both send streams and verify we get
 # the same file contents that the original filesystem had.
@@ -119,10 +125,18 @@ _scratch_mount
 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
 
-echo "File digests in the new filesystem:"
-md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
-md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
-md5sum $SCRATCH_MNT/mysnap2/bar | _filter_scratch
+# echo "File digests in the new filesystem:"
+declare -A dst_fs_hash
+dst_fs_hash[mysnap1_foo]=$(md5sum $SCRATCH_MNT/mysnap1/foo | cut -f 1 -d ' ')
+dst_fs_hash[mysnap2_foo]=$(md5sum $SCRATCH_MNT/mysnap2/foo | cut -f 1 -d ' ')
+dst_fs_hash[mysnap2_bar]=$(md5sum $SCRATCH_MNT/mysnap2/bar | cut -f 1 -d ' ')
+
+for key in "${!src_fs_hash[@]}"; do
+	if [ ${src_fs_hash[$key]} != ${dst_fs_hash[$key]} ]; then
+		echo "Mimatching hash value detected against \
+$(echo $key | tr _ /)"
+	fi
+done
 
 status=0
 exit
tests/btrfs/094.out +3 -14
index c3ac1bf..fe26ea0 100644
@@ -1,15 +1,4 @@
 QA output created by 094
-wrote 131072/131072 bytes at offset 65536
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-wrote 114688/114688 bytes at offset 65536
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-wrote 12288/12288 bytes at offset 184320
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-File digests in the original filesystem:
-f98243c603750f7daf225b1745b31516  SCRATCH_MNT/mysnap1/foo
-f98243c603750f7daf225b1745b31516  SCRATCH_MNT/mysnap2/foo
-7fccf6175f5c68504b408719a21db99f  SCRATCH_MNT/mysnap2/bar
-File digests in the new filesystem:
-f98243c603750f7daf225b1745b31516  SCRATCH_MNT/mysnap1/foo
-f98243c603750f7daf225b1745b31516  SCRATCH_MNT/mysnap2/foo
-7fccf6175f5c68504b408719a21db99f  SCRATCH_MNT/mysnap2/bar
+Blocks modified: [16 - 47]
+Blocks modified: [16 - 43]
+Blocks modified: [45 - 47]
Signature · 1 line
2.1.0
#11 lore raw

PATCH 7/12 Fix btrfs/095 to work on non-4k block sized filesystems

In reply to Chandan Rajendra

This commit makes use of the new _filter_xfs_io_blocks_modified filtering function to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/095     | 113 +++++++++++++++++++++++++++++-----------------------
 tests/btrfs/095.out |  10 +----
 2 files changed, 66 insertions(+), 57 deletions(-)
tests/btrfs/095 +64 -49
index 1b4ba90..e73b14e 100755
@@ -63,85 +63,100 @@ _scratch_mkfs >>$seqres.full 2>&1
 _init_flakey
 _mount_flakey
 
-# Create prealloc extent covering range [160K, 620K[
-$XFS_IO_PROG -f -c "falloc 160K 460K" $SCRATCH_MNT/foo
+BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
 
-# Now write to the last 80K of the prealloc extent plus 40K to the unallocated
-# space that immediately follows it. This creates a new extent of 40K that spans
-# the range [620K, 660K[.
-$XFS_IO_PROG -c "pwrite -S 0xaa 540K 120K" $SCRATCH_MNT/foo | _filter_xfs_io
+# Create prealloc extent covering file block range [40, 155[
+$XFS_IO_PROG -f -c "falloc $((40 * $BLOCK_SIZE)) $((115 * $BLOCK_SIZE))" \
+	     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
+# Now write to the last 20 blocks of the prealloc extent plus 10 blocks to the
+# unallocated space that immediately follows it. This creates a new extent of 10
+# blocks that spans the block range [155, 165[.
+$XFS_IO_PROG -c "pwrite -S 0xaa $((135 * $BLOCK_SIZE)) $((30 * $BLOCK_SIZE))" \
+	     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
 
 # At this point, there are now 2 back references to the prealloc extent in our
-# extent tree. Both are for our file offset 160K and one relates to a file
-# extent item with a data offset of 0 and a length of 380K, while the other
-# relates to a file extent item with a data offset of 380K and a length of 80K.
+# extent tree. Both are for our file offset mapped by the 40th block of the file
+# and one relates to a file extent item with a data offset of 0 and a length of
+# 95 blocks, while the other relates to a file extent item with a data offset of
+# 95 blocks and a length of 20 blocks.
 
 # Make sure everything done so far is durably persisted (all back references are
 # in the extent tree, etc).
 sync
 
-# Now clone all extents of our file that cover the offset 160K up to its eof
-# (660K at this point) into itself at offset 2M. This leaves a hole in the file
-# covering the range [660K, 2M[. The prealloc extent will now be referenced by
-# the file twice, once for offset 160K and once for offset 2M. The 40K extent
-# that follows the prealloc extent will also be referenced twice by our file,
-# once for offset 620K and once for offset 2M + 460K.
-$CLONER_PROG -s $((160 * 1024)) -d $((2 * 1024 * 1024)) -l 0 $SCRATCH_MNT/foo \
-	$SCRATCH_MNT/foo
-
-# Now create one new extent in our file with a size of 100Kb. It will span the
-# range [3M, 3M + 100K[. It also will cause creation of a hole spanning the
-# range [2M + 460K, 3M[. Our new file size is 3M + 100K.
-$XFS_IO_PROG -c "pwrite -S 0xbb 3M 100K" $SCRATCH_MNT/foo | _filter_xfs_io
+# Now clone all extents of our file that cover the file range spanned by 40th
+# block up to its eof (165th block at this point) into itself at 512th
+# block. This leaves a hole in the file covering the block range [165, 512[. The
+# prealloc extent will now be referenced by the file twice, once for offset
+# mapped by the 40th block and once for offset mapped by 512th block. The 10
+# blocks extent that follows the prealloc extent will also be referenced twice
+# by our file, once for offset mapped by the 155th block and once for offset
+# (512 block + 115 blocks)
+$CLONER_PROG -s $((40 * $BLOCK_SIZE)) -d $((512 * $BLOCK_SIZE)) -l 0 \
+	     $SCRATCH_MNT/foo $SCRATCH_MNT/foo
+
+# Now create one new extent in our file with a size of 25 blocks. It will span
+# the block range [768, 768 + 25[. It also will cause creation of a hole
+# spanning the block range [512 + 115, 768[. Our new file size is the file
+# offset mapped by (768 + 25)th block.
+$XFS_IO_PROG -c "pwrite -S 0xbb $((768 * $BLOCK_SIZE)) $((25 * $BLOCK_SIZE))" \
+	     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
 
 # At this point, there are now (in memory) 4 back references to the prealloc
 # extent.
 #
-# Two of them are for file offset 160K, related to file extent items
-# matching the file offsets 160K and 540K respectively, with data offsets of
-# 0 and 380K respectively, and with lengths of 380K and 80K respectively.
+# Two of them are for file offset mapped by the 40th block, related to file
+# extent items matching the file offsets mapped by 40th and 135th block
+# respectively, with data offsets of 0 and 95 blocks respectively, and with
+# lengths of 95 and 20 blocks respectively.
 #
-# The other two references are for file offset 2M, related to file extent items
-# matching the file offsets 2M and 2M + 380K respectively, with data offsets of
-# 0 and 380K respectively, and with lengths of 380K and 80K respectively.
+# The other two references are for file offset mapped by 512th block, related to
+# file extent items matching the file offsets mapped by 512th and (512 + 95)th
+# block respectively, with data offsets mapped by 0th and 95th block
+# respectively, and with lengths of 95 and 20 blocks respectively.
 #
-# The 40K extent has 2 back references, one for file offset 620K and the other
-# for file offset 2M + 460K.
+# The 10 block extent has 2 back references, one for file offset mapped by 155th
+# block and the other for file offset mapped by (512 + 115)th block.
 #
-# The 100K extent has a single back reference and it relates to file offset 3M.
+# The 25 blocks extent has a single back reference and it relates to file offset
+# mapped by 768th block.
 
-# Now clone our 100K extent into offset 600K. That offset covers the last 20K
-# of the prealloc extent, the whole 40K extent and 40K of the hole starting at
-# offset 660K.
-$CLONER_PROG -s $((3 * 1024 * 1024)) -d $((600 * 1024)) -l $((100 * 1024)) \
+
+# Now clone our 25 block extent into offset mapped by 150th block. That offset
+# covers the last 5 blocks of the prealloc extent, the whole 10 block extent and
+# 10 blocks of the hole starting at offset mapped by 165th block.
+$CLONER_PROG -s $((768 * $BLOCK_SIZE)) -d $((150 * $BLOCK_SIZE)) -l $((25 * $BLOCK_SIZE)) \
 	$SCRATCH_MNT/foo $SCRATCH_MNT/foo
 
-# At this point there's only one reference to the 40K extent, at file offset
-# 2M + 460K, we have 4 references for the prealloc extent (2 for file offset
-# 160K and 2 for file offset 2M) and 2 references for the 100K extent (1 for
-# file offset 3M and a new one for file offset 600K).
+# At this point there's only one reference to the 10 block extent, at file
+# offset mapped by (512 + 115) block, we have 4 references for the prealloc
+# extent (2 for file offset mapped by 40th block and 2 for file offset mapped by
+# 512th block) and 2 references for the 25 block extent (1 for file offset
+# mapped by 768th block and a new one for file offset mapped by 150th block).
 
 # Now fsync our file to make all its new data and metadata updates are durably
 # persisted and present if a power failure/crash happens after a successful
 # fsync and before the next transaction commit.
 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
 
-echo "File digest before power failure:"
-md5sum $SCRATCH_MNT/foo | _filter_scratch
+orig_hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
 
 # During log replay, the btrfs delayed references implementation used to run the
 # deletion of back references before the addition of new back references, which
 # made the addition fail as it didn't find the key in the extent tree that it
-# was looking for. The failure triggered by this test was related to the 40K
-# extent, which got 1 reference dropped and 1 reference added during the fsync
-# log replay - when running the delayed references at transaction commit time,
-# btrfs was applying the deletion before the insertion, resulting in a failure
-# of the insertion that ended up turning the fs into read-only mode.
+# was looking for. The failure triggered by this test was related to the 10
+# block extent, which got 1 reference dropped and 1 reference added during the
+# fsync log replay - when running the delayed references at transaction commit
+# time, btrfs was applying the deletion before the insertion, resulting in a
+# failure of the insertion that ended up turning the fs into read-only mode.
 _flakey_drop_and_remount
 
-echo "File digest after log replay:"
-md5sum $SCRATCH_MNT/foo | _filter_scratch
-
+hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
+if [ $orig_hash != $hash ]; then
+	echo "Delayed refs replayed back with incorrect order: "\
+	     "Mimatching hash values detected."
+fi
 _unmount_flakey
 
 status=0
tests/btrfs/095.out +2 -8
index e93435c..89b423f 100644
@@ -1,9 +1,3 @@
 QA output created by 095
-wrote 122880/122880 bytes at offset 552960
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-wrote 102400/102400 bytes at offset 3145728
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-File digest before power failure:
-beaf47c36659ac29bb9363fb8ffa10a1  SCRATCH_MNT/foo
-File digest after log replay:
-beaf47c36659ac29bb9363fb8ffa10a1  SCRATCH_MNT/foo
+Blocks modified: [135 - 164]
+Blocks modified: [768 - 792]
Signature · 1 line
2.1.0
#12 lore raw

PATCH 8/12 Fix btrfs/096 to work on non-4k block sized filesystems

In reply to Chandan Rajendra

This commit makes use of the new _filter_xfs_io_blocks_modified filtering function to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/096     | 45 +++++++++++++++++++++++++--------------------
 tests/btrfs/096.out | 15 +++++----------
 2 files changed, 30 insertions(+), 30 deletions(-)
tests/btrfs/096 +25 -20
index f5b3a7f..896a209 100755
@@ -51,30 +51,35 @@ rm -f $seqres.full
 _scratch_mkfs >>$seqres.full 2>&1
 _scratch_mount
 
-# Create our test files. File foo has the same 2K of data at offset 4K as file
-# bar has at its offset 0.
-$XFS_IO_PROG -f -s -c "pwrite -S 0xaa 0 4K" \
-		-c "pwrite -S 0xbb 4k 2K" \
-		-c "pwrite -S 0xcc 8K 4K" \
-		$SCRATCH_MNT/foo | _filter_xfs_io
+BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
 
-# File bar consists of a single inline extent (2K size).
-$XFS_IO_PROG -f -s -c "pwrite -S 0xbb 0 2K" \
-		$SCRATCH_MNT/bar | _filter_xfs_io
+# Create our test files. File foo has the same 2k of data at offset $BLOCK_SIZE
+# as file bar has at its offset 0.
+$XFS_IO_PROG -f -s -c "pwrite -S 0xaa 0 $BLOCK_SIZE" \
+		-c "pwrite -S 0xbb $BLOCK_SIZE 2k" \
+		-c "pwrite -S 0xcc $(($BLOCK_SIZE * 2)) $BLOCK_SIZE" \
+		$SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
 
-# Now call the clone ioctl to clone the extent of file bar into file foo at its
-# offset 4K. This made file foo have an inline extent at offset 4K, something
-# which the btrfs code can not deal with in future IO operations because all
-# inline extents are supposed to start at an offset of 0, resulting in all sorts
-# of chaos.
-# So here we validate that the clone ioctl returns an EOPNOTSUPP, which is what
-# it returns for other cases dealing with inlined extents.
-$CLONER_PROG -s 0 -d $((4 * 1024)) -l $((2 * 1024)) \
+# File bar consists of a single inline extent (2k in size).
+$XFS_IO_PROG -f -s -c "pwrite -S 0xbb 0 2k" \
+		$SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
+
+# Now call the clone ioctl to clone the extent of file bar into file
+# foo at its $BLOCK_SIZE offset. This made file foo have an inline
+# extent at offset $BLOCK_SIZE, something which the btrfs code can not
+# deal with in future IO operations because all inline extents are
+# supposed to start at an offset of 0, resulting in all sorts of
+# chaos.
+# So here we validate that the clone ioctl returns an EOPNOTSUPP,
+# which is what it returns for other cases dealing with inlined
+# extents.
+$CLONER_PROG -s 0 -d $BLOCK_SIZE -l 2048 \
 	$SCRATCH_MNT/bar $SCRATCH_MNT/foo
 
-# Because of the inline extent at offset 4K, the following write made the kernel
-# crash with a BUG_ON().
-$XFS_IO_PROG -c "pwrite -S 0xdd 6K 2K" $SCRATCH_MNT/foo | _filter_xfs_io
+# Because of the inline extent at offset $BLOCK_SIZE, the following
+# write made the kernel crash with a BUG_ON().
+$XFS_IO_PROG -c "pwrite -S 0xdd $(($BLOCK_SIZE + 2048)) 2k" \
+	     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
 
 status=0
 exit
tests/btrfs/096.out +5 -10
index 235198d..2a4251e 100644
@@ -1,12 +1,7 @@
 QA output created by 096
-wrote 4096/4096 bytes at offset 0
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-wrote 2048/2048 bytes at offset 4096
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-wrote 4096/4096 bytes at offset 8192
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-wrote 2048/2048 bytes at offset 0
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+Blocks modified: [0 - 0]
+Blocks modified: [1 - 1]
+Blocks modified: [2 - 2]
+Blocks modified: [0 - 0]
 clone failed: Operation not supported
-wrote 2048/2048 bytes at offset 6144
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+Blocks modified: [1 - 1]
Signature · 1 line
2.1.0
#13 lore raw

PATCH 9/12 Fix btrfs/097 to work on non-4k block sized filesystems

In reply to Chandan Rajendra

This commit makes use of the new _filter_xfs_io_blocks_modified filtering function to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/097     | 42 +++++++++++++++++++++++++-----------------
 tests/btrfs/097.out |  7 +------
 2 files changed, 26 insertions(+), 23 deletions(-)
tests/btrfs/097 +25 -17
index d9138ea..915ff9d 100755
@@ -57,22 +57,29 @@ mkdir $send_files_dir
 _scratch_mkfs >>$seqres.full 2>&1
 _scratch_mount
 
-# Create our test file with a single extent of 64K starting at file offset 128K.
-$XFS_IO_PROG -f -c "pwrite -S 0xaa 128K 64K" $SCRATCH_MNT/foo | _filter_xfs_io
+BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
+
+# Create our test file with a single extent of 16 blocks starting at a file
+# offset mapped by 32nd block.
+$XFS_IO_PROG -f -c "pwrite -S 0xaa $((32 * $BLOCK_SIZE)) $((16 * $BLOCK_SIZE))" \
+	     $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
 
 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
 
 # Now clone parts of the original extent into lower offsets of the file.
 #
 # The first clone operation adds a file extent item to file offset 0 that points
-# to our initial extent with a data offset of 16K. The corresponding data back
-# reference in the extent tree has an offset of 18446744073709535232, which is
-# the result of file_offset - data_offset = 0 - 16K.
-#
-# The second clone operation adds a file extent item to file offset 16K that
-# points to our initial extent with a data offset of 48K. The corresponding data
-# back reference in the extent tree has an offset of 18446744073709518848, which
-# is the result of file_offset - data_offset = 16K - 48K.
+# to our initial extent with a data offset of 4 blocks. The corresponding data back
+# reference in the extent tree has a large value for the 'offset' field, which is
+# the result of file_offset - data_offset = 0 - (file offset of 4th block).  For
+# example in case of 4k block size, it will be 0 - 16k = 18446744073709535232.
+
+# The second clone operation adds a file extent item to file offset mapped by
+# 4th block that points to our initial extent with a data offset of 12
+# blocks. The corresponding data back reference in the extent tree has a large
+# value for the 'offset' field, which is the result of file_offset - data_offset
+# = (file offset of 4th block) - (file offset of 12th block). For example in
+# case of 4k block size, it will be 16K - 48K = 18446744073709518848.
 #
 # Those large back reference offsets (result of unsigned arithmetic underflow)
 # confused the back reference walking code (used by an incremental send and
@@ -83,10 +90,10 @@ _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
 # "BTRFS error (device sdc): did not find backref in send_root. inode=257, \
 #  offset=0, disk_byte=12845056 found extent=12845056"
 #
-$CLONER_PROG -s $(((128 + 16) * 1024)) -d 0 -l $((16 * 1024)) \
-	$SCRATCH_MNT/foo $SCRATCH_MNT/foo
-$CLONER_PROG -s $(((128 + 48) * 1024)) -d $((16 * 1024)) -l $((16 * 1024)) \
+$CLONER_PROG -s $(((32 + 4) * $BLOCK_SIZE)) -d 0 -l $((4 * $BLOCK_SIZE)) \
 	$SCRATCH_MNT/foo $SCRATCH_MNT/foo
+$CLONER_PROG -s $(((32 + 12) * $BLOCK_SIZE)) -d $((4 * $BLOCK_SIZE)) \
+	     -l $((4 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/foo
 
 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
 
@@ -94,8 +101,7 @@ _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
 	-f $send_files_dir/2.snap
 
-echo "File digest in the original filesystem:"
-md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
+orig_hash=$(md5sum $SCRATCH_MNT/mysnap2/foo | cut -f 1 -d ' ')
 
 # Now recreate the filesystem by receiving both send streams and verify we get
 # the same file contents that the original filesystem had.
@@ -106,8 +112,10 @@ _scratch_mount
 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
 
-echo "File digest in the new filesystem:"
-md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
+hash=$(md5sum $SCRATCH_MNT/mysnap2/foo | cut -f 1 -d ' ')
+if [ $orig_hash != $hash ]; then
+	echo "Btrfs send/receive failed: Mismatching hash values detected."
+fi
 
 status=0
 exit
tests/btrfs/097.out +1 -6
index 5e87eb2..c3a19c1 100644
@@ -1,7 +1,2 @@
 QA output created by 097
-wrote 65536/65536 bytes at offset 131072
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-File digest in the original filesystem:
-6c6079335cff141b8a31233ead04cbff  SCRATCH_MNT/mysnap2/foo
-File digest in the new filesystem:
-6c6079335cff141b8a31233ead04cbff  SCRATCH_MNT/mysnap2/foo
+Blocks modified: [32 - 47]
Signature · 1 line
2.1.0
#14 lore raw

PATCH 10/12 Fix btrfs/098 to work on non-4k block sized filesystems

In reply to Chandan Rajendra

This commit makes use of the new _filter_xfs_io_blocks_modified filtering function to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/098     | 65 ++++++++++++++++++++++++++++++-----------------------
 tests/btrfs/098.out |  7 +-----
 2 files changed, 38 insertions(+), 34 deletions(-)
tests/btrfs/098 +37 -28
index 8aef119..4879a90 100755
@@ -58,43 +58,49 @@ _scratch_mkfs >>$seqres.full 2>&1
 _init_flakey
 _mount_flakey
 
-# Create our test file with a single 100K extent starting at file offset 800K.
-# We fsync the file here to make the fsync log tree gets a single csum item that
-# covers the whole 100K extent, which causes the second fsync, done after the
-# cloning operation below, to not leave in the log tree two csum items covering
-# two sub-ranges ([0, 20K[ and [20K, 100K[)) of our extent.
-$XFS_IO_PROG -f -c "pwrite -S 0xaa 800K 100K"  \
+BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
+
+# Create our test file with a single 25 block extent starting at file offset
+# mapped by 200th block We fsync the file here to make the fsync log tree get a
+# single csum item that covers the whole 25 block extent, which causes the
+# second fsync, done after the cloning operation below, to not leave in the log
+# tree two csum items covering two block sub-ranges ([0, 5[ and [5, 25[)) of our
+# extent.
+$XFS_IO_PROG -f -c "pwrite -S 0xaa $((200 * $BLOCK_SIZE)) $((25 * $BLOCK_SIZE))" \
 		-c "fsync"                     \
-		$SCRATCH_MNT/foo | _filter_xfs_io
+		$SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
 
-# Now clone part of our extent into file offset 400K. This adds a file extent
-# item to our inode's metadata that points to the 100K extent we created before,
-# using a data offset of 20K and a data length of 20K, so that it refers to
-# the sub-range [20K, 40K[ of our original extent.
-$CLONER_PROG -s $((800 * 1024 + 20 * 1024)) -d $((400 * 1024)) \
-	-l $((20 * 1024)) $SCRATCH_MNT/foo $SCRATCH_MNT/foo
+# Now clone part of our extent into file offset mapped by 100th block. This adds
+# a file extent item to our inode's metadata that points to the 25 block extent
+# we created before, using a data offset of 5 blocks and a data length of 5
+# blocks, so that it refers to the block sub-range [5, 10[ of our original
+# extent.
+$CLONER_PROG -s $(((200 * $BLOCK_SIZE) + (5 * $BLOCK_SIZE))) \
+	     -d $((100 * $BLOCK_SIZE)) -l $((5 * $BLOCK_SIZE)) \
+	     $SCRATCH_MNT/foo $SCRATCH_MNT/foo
 
 # Now fsync our file to make sure the extent cloning is durably persisted. This
 # fsync will not add a second csum item to the log tree containing the checksums
-# for the blocks in the sub-range [20K, 40K[ of our extent, because there was
+# for the blocks in the block sub-range [5, 10[ of our extent, because there was
 # already a csum item in the log tree covering the whole extent, added by the
 # first fsync we did before.
 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
 
-echo "File digest before power failure:"
-md5sum $SCRATCH_MNT/foo | _filter_scratch
+orig_hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
 
 # The fsync log replay first processes the file extent item corresponding to the
-# file offset 400K (the one which refers to the [20K, 40K[ sub-range of our 100K
-# extent) and then processes the file extent item for file offset 800K. It used
-# to happen that when processing the later, it erroneously left in the csum tree
-# 2 csum items that overlapped each other, 1 for the sub-range [20K, 40K[ and 1
-# for the whole range of our extent. This introduced a problem where subsequent
-# lookups for the checksums of blocks within the range [40K, 100K[ of our extent
-# would not find anything because lookups in the csum tree ended up looking only
-# at the smaller csum item, the one covering the subrange [20K, 40K[. This made
-# read requests assume an expected checksum with a value of 0 for those blocks,
-# which caused checksum verification failure when the read operations finished.
+# file offset mapped by 100th block (the one which refers to the [5, 10[ block
+# sub-range of our 25 block extent) and then processes the file extent item for
+# file offset mapped by 200th block. It used to happen that when processing the
+# later, it erroneously left in the csum tree 2 csum items that overlapped each
+# other, 1 for the block sub-range [5, 10[ and 1 for the whole range of our
+# extent. This introduced a problem where subsequent lookups for the checksums
+# of blocks within the block range [10, 25[ of our extent would not find
+# anything because lookups in the csum tree ended up looking only at the smaller
+# csum item, the one covering the block subrange [5, 10[. This made read
+# requests assume an expected checksum with a value of 0 for those blocks, which
+# caused checksum verification failure when the read operations finished.
 # However those checksum failure did not result in read requests returning an
 # error to user space (like -EIO for e.g.) because the expected checksum value
 # had the special value 0, and in that case btrfs set all bytes of the
@@ -106,10 +112,13 @@ md5sum $SCRATCH_MNT/foo | _filter_scratch
 #
 _flakey_drop_and_remount
 
-echo "File digest after log replay:"
 # Must match the same digest he had after cloning the extent and before the
 # power failure happened.
-md5sum $SCRATCH_MNT/foo | _filter_scratch
+hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
+if [ $orig_hash != $hash ]; then
+	echo "Log replay caused corrupted file: "\
+	     "Mimatching hash values detected."
+fi
 
 _unmount_flakey
 
tests/btrfs/098.out +1 -6
index 3aa0772..b490cb1 100644
@@ -1,7 +1,2 @@
 QA output created by 098
-wrote 102400/102400 bytes at offset 819200
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-File digest before power failure:
-39b386375971248740ed8651d5a2ed9f  SCRATCH_MNT/foo
-File digest after log replay:
-39b386375971248740ed8651d5a2ed9f  SCRATCH_MNT/foo
+Blocks modified: [200 - 224]
Signature · 1 line
2.1.0
#15 lore raw

PATCH 11/12 Fix btrfs/103 to work on non-4k block sized filesystems

In reply to Chandan Rajendra

This commit makes use of the new _filter_xfs_io_blocks_modified filtering function to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/103     | 47 +++++++++++++++++++++++++++++------------------
 tests/btrfs/103.out | 48 ++++++++++++------------------------------------
 2 files changed, 41 insertions(+), 54 deletions(-)
tests/btrfs/103 +29 -18
index 3020c86..a807900 100755
@@ -56,31 +56,34 @@ test_clone_and_read_compressed_extent()
 	_scratch_mkfs >>$seqres.full 2>&1
 	_scratch_mount $mount_opts
 
+	BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
+
 	# Create a test file with a single extent that is compressed (the
 	# data we write into it is highly compressible no matter which
 	# compression algorithm is used, zlib or lzo).
-	$XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 4K"        \
-			-c "pwrite -S 0xbb 4K 8K"        \
-			-c "pwrite -S 0xcc 12K 4K"       \
-			$SCRATCH_MNT/foo | _filter_xfs_io
+	$XFS_IO_PROG -f -c "pwrite -S 0xaa 0K $((1 * $BLOCK_SIZE))" \
+		-c "pwrite -S 0xbb $((1 * $BLOCK_SIZE)) $((2 * $BLOCK_SIZE))" \
+		-c "pwrite -S 0xcc $((3 * $BLOCK_SIZE)) $((1 * $BLOCK_SIZE))" \
+		$SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
 
 	# Now clone our extent into an adjacent offset.
-	$CLONER_PROG -s $((4 * 1024)) -d $((16 * 1024)) -l $((8 * 1024)) \
-		$SCRATCH_MNT/foo $SCRATCH_MNT/foo
+	$CLONER_PROG -s $((1 * $BLOCK_SIZE)) -d $((4 * $BLOCK_SIZE)) \
+		     -l $((2 * $BLOCK_SIZE)) $SCRATCH_MNT/foo $SCRATCH_MNT/foo
 
 	# Same as before but for this file we clone the extent into a lower
 	# file offset.
-	$XFS_IO_PROG -f -c "pwrite -S 0xaa 8K 4K"         \
-			-c "pwrite -S 0xbb 12K 8K"        \
-			-c "pwrite -S 0xcc 20K 4K"        \
-			$SCRATCH_MNT/bar | _filter_xfs_io
+	$XFS_IO_PROG -f \
+		-c "pwrite -S 0xaa $((2 * $BLOCK_SIZE)) $((1 * $BLOCK_SIZE))" \
+		-c "pwrite -S 0xbb $((3 * $BLOCK_SIZE)) $((2 * $BLOCK_SIZE))" \
+		-c "pwrite -S 0xcc $((5 * $BLOCK_SIZE)) $((1 * $BLOCK_SIZE))" \
+		$SCRATCH_MNT/bar | _filter_xfs_io_blocks_modified
 
-	$CLONER_PROG -s $((12 * 1024)) -d 0 -l $((8 * 1024)) \
+	$CLONER_PROG -s $((3 * $BLOCK_SIZE)) -d 0 -l $((2 * $BLOCK_SIZE)) \
 		$SCRATCH_MNT/bar $SCRATCH_MNT/bar
 
-	echo "File digests before unmounting filesystem:"
-	md5sum $SCRATCH_MNT/foo | _filter_scratch
-	md5sum $SCRATCH_MNT/bar | _filter_scratch
+	foo_orig_hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
+	bar_orig_hash=$(md5sum $SCRATCH_MNT/bar | cut -f 1 -d ' ')
 
 	# Evicting the inode or clearing the page cache before reading again
 	# the file would also trigger the bug - reads were returning all bytes
@@ -91,10 +94,18 @@ test_clone_and_read_compressed_extent()
 	# ranges that point to the same compressed extent.
 	_scratch_remount
 
-	echo "File digests after mounting filesystem again:"
-	# Must match the same digests we got before.
-	md5sum $SCRATCH_MNT/foo | _filter_scratch
-	md5sum $SCRATCH_MNT/bar | _filter_scratch
+	foo_hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
+	bar_hash=$(md5sum $SCRATCH_MNT/bar | cut -f 1 -d ' ')
+
+	if [ $foo_orig_hash != $foo_hash ]; then
+		echo "Read operation failed on $SCRATCH_MNT/foo: "\
+		     "Mimatching hash values detected."
+	fi
+
+	if [ $bar_orig_hash != $bar_hash ]; then
+		echo "Read operation failed on $SCRATCH_MNT/bar: "\
+		     "Mimatching hash values detected."
+	fi
 }
 
 echo -e "\nTesting with zlib compression..."
tests/btrfs/103.out +12 -36

53 lines not on this page · raw message

Signature · 1 line
2.1.0
#16 lore raw

PATCH 12/12 Fix btrfs/106 to work on non-4k block sized filesystems

In reply to Chandan Rajendra

This commit makes use of the new _filter_xfs_io_pages_modified filtering function to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/106     | 42 ++++++++++++++++++++++++------------------
 tests/btrfs/106.out | 14 ++------------
 2 files changed, 26 insertions(+), 30 deletions(-)
tests/btrfs/106 +24 -18
index 1670453..a1bf4ec 100755
@@ -58,31 +58,37 @@ test_clone_and_read_compressed_extent()
 	_scratch_mkfs >>$seqres.full 2>&1
 	_scratch_mount $mount_opts
 
-	# Create our test file with a single extent of 64Kb that is going to be
-	# compressed no matter which compression algorithm is used (zlib/lzo).
-	$XFS_IO_PROG -f -c "pwrite -S 0xaa 0K 64K" \
-		$SCRATCH_MNT/foo | _filter_xfs_io
-
+	PAGE_SIZE=$(get_page_size)
+
+	# Create our test file with 16 pages worth of data in a single extent
+	# that is going to be compressed no matter which compression algorithm
+	# is used (zlib/lzo).
+	$XFS_IO_PROG -f -c "pwrite -S 0xaa 0K $((16 * $PAGE_SIZE))" \
+		     $SCRATCH_MNT/foo | _filter_xfs_io_pages_modified
+	
 	# Now clone the compressed extent into an adjacent file offset.
-	$CLONER_PROG -s 0 -d $((64 * 1024)) -l $((64 * 1024)) \
+	$CLONER_PROG -s 0 -d $((16 * $PAGE_SIZE)) -l $((16 * $PAGE_SIZE)) \
 		$SCRATCH_MNT/foo $SCRATCH_MNT/foo
 
-	echo "File digest before unmount:"
-	md5sum $SCRATCH_MNT/foo | _filter_scratch
+	orig_hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
 
 	# Remount the fs or clear the page cache to trigger the bug in btrfs.
-	# Because the extent has an uncompressed length that is a multiple of
-	# 16 pages, all the pages belonging to the second range of the file
-	# (64K to 128K), which points to the same extent as the first range
-	# (0K to 64K), had their contents full of zeroes instead of the byte
-	# 0xaa. This was a bug exclusively in the read path of compressed
-	# extents, the correct data was stored on disk, btrfs just failed to
-	# fill in the pages correctly.
+	# Because the extent has an uncompressed length that is a multiple of 16
+	# pages, all the pages belonging to the second range of the file that is
+	# mapped by the page index range [16, 31], which points to the same
+	# extent as the first file range mapped by the page index range [0, 15],
+	# had their contents full of zeroes instead of the byte 0xaa. This was a
+	# bug exclusively in the read path of compressed extents, the correct
+	# data was stored on disk, btrfs just failed to fill in the pages
+	# correctly.
 	_scratch_remount
 
-	echo "File digest after remount:"
-	# Must match the digest we got before.
-	md5sum $SCRATCH_MNT/foo | _filter_scratch
+	hash=$(md5sum $SCRATCH_MNT/foo | cut -f 1 -d ' ')
+
+	if [ $orig_hash != $hash ]; then
+		echo "Read operation failed on $SCRATCH_MNT/foo: "\
+		     "Mimatching hash values detected."
+	fi
 }
 
 echo -e "\nTesting with zlib compression..."
tests/btrfs/106.out +2 -12
index 692108d..eceabfa 100644
@@ -1,17 +1,7 @@
 QA output created by 106
 
 Testing with zlib compression...
-wrote 65536/65536 bytes at offset 0
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-File digest before unmount:
-be68df46e3cf60b559376a35f9fbb05d  SCRATCH_MNT/foo
-File digest after remount:
-be68df46e3cf60b559376a35f9fbb05d  SCRATCH_MNT/foo
+Pages modified: [0 - 15]
 
 Testing with lzo compression...
-wrote 65536/65536 bytes at offset 0
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-File digest before unmount:
-be68df46e3cf60b559376a35f9fbb05d  SCRATCH_MNT/foo
-File digest after remount:
-be68df46e3cf60b559376a35f9fbb05d  SCRATCH_MNT/foo
+Pages modified: [0 - 15]
Signature · 1 line
2.1.0
#7 lore raw

Re: [PATCH 06/12] Fix btrfs/094 to work on non-4k block sized filesystems

In reply to Chandan Rajendra
Quoted 132 lines · Chandan Rajendra

This commit makes use of the new _filter_xfs_io_blocks_modified filtering function to print information in terms of file blocks rather than file offset.

---
 tests/btrfs/094     | 78 +++++++++++++++++++++++++++++++----------------------
 tests/btrfs/094.out | 17 +++---------
 2 files changed, 49 insertions(+), 46 deletions(-)
tests/btrfs/094 +46 -32
index 6f6cdeb..868c088 100755
@@ -67,36 +67,41 @@ mkdir $send_files_dir
 _scratch_mkfs >>$seqres.full 2>&1
 _scratch_mount "-o compress"
 
-# Create the file with a single extent of 128K. This creates a metadata file
-# extent item with a data start offset of 0 and a logical length of 128K.
-$XFS_IO_PROG -f -c "pwrite -S 0xaa 64K 128K" -c "fsync" \
-       $SCRATCH_MNT/foo | _filter_xfs_io
-
-# Now rewrite the range 64K to 112K of our file. This will make the inode's
-# metadata continue to point to the 128K extent we created before, but now
-# with an extent item that points to the extent with a data start offset of
-# 112K and a logical length of 16K.
-# That metadata file extent item is associated with the logical file offset
-# at 176K and covers the logical file range 176K to 192K.
-$XFS_IO_PROG -c "pwrite -S 0xbb 64K 112K" -c "fsync" \
-       $SCRATCH_MNT/foo | _filter_xfs_io
-
-# Now rewrite the range 180K to 12K. This will make the inode's metadata
-# continue to point the the 128K extent we created earlier, with a single
-# extent item that points to it with a start offset of 112K and a logical
-# length of 4K.
-# That metadata file extent item is associated with the logical file offset
-# at 176K and covers the logical file range 176K to 180K.
-$XFS_IO_PROG -c "pwrite -S 0xcc 180K 12K" -c "fsync" \
-       $SCRATCH_MNT/foo | _filter_xfs_io
+BLOCK_SIZE=$(get_block_size $SCRATCH_MNT)
+
+# Create the file with a single extent of 32 blocks. This creates a metadata
+# file extent item with a data start offset of 0 and a logical length of
+# 32 blocks.
+$XFS_IO_PROG -f -c "pwrite -S 0xaa $((16 * $BLOCK_SIZE)) $((32 * $BLOCK_SIZE))" \
+            -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
+# Now rewrite the block range [16, 28[ of our file. This will make
+# the inode's metadata continue to point to the single 32 block extent
+# we created before, but now with an extent item that points to the
+# extent with a data start offset referring to the 28th block and a
+# logical length of 4 blocks.
+# That metadata file extent item is associated with the block range
+# [44, 48[.
+$XFS_IO_PROG -c "pwrite -S 0xbb $((16 * $BLOCK_SIZE)) $((28 * $BLOCK_SIZE))" \
+            -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
+
+
+# Now rewrite the block range [45, 48[. This will make the inode's
+# metadata continue to point the 32 block extent we created earlier,
+# with a single extent item that points to it with a start offset
+# referring to the 28th block and a logical length of 1 block.
+# That metadata file extent item is associated with the block range
+# [44, 45[.
+$XFS_IO_PROG -c "pwrite -S 0xcc $((45 * $BLOCK_SIZE)) $((3 * $BLOCK_SIZE))" \
+            -c "fsync" $SCRATCH_MNT/foo | _filter_xfs_io_blocks_modified
 
 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
 
-# Now clone that same region of the 128K extent into a new file, so that it
+# Now clone that same region of the 32 block extent into a new file, so that it
 # gets referenced twice and the incremental send operation below decides to
 # issue a clone operation instead of copying the data.
 touch $SCRATCH_MNT/bar
-$CLONER_PROG -s $((176 * 1024)) -d $((176 * 1024)) -l $((4 * 1024)) \
+$CLONER_PROG -s $((44 * $BLOCK_SIZE)) -d $((44 * $BLOCK_SIZE)) -l $BLOCK_SIZE \
        $SCRATCH_MNT/foo $SCRATCH_MNT/bar
 
 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
@@ -105,10 +110,11 @@ _run_btrfs_util_prog send $SCRATCH_MNT/mysnap1 -f $send_files_dir/1.snap
 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 $SCRATCH_MNT/mysnap2 \
        -f $send_files_dir/2.snap
 
-echo "File digests in the original filesystem:"
-md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
-md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
-md5sum $SCRATCH_MNT/mysnap2/bar | _filter_scratch
+# echo "File digests in the original filesystem:"
+declare -A src_fs_hash
+src_fs_hash[mysnap1_foo]=$(md5sum $SCRATCH_MNT/mysnap1/foo | cut -f 1 -d ' ')
+src_fs_hash[mysnap2_foo]=$(md5sum $SCRATCH_MNT/mysnap2/foo | cut -f 1 -d ' ')
+src_fs_hash[mysnap2_bar]=$(md5sum $SCRATCH_MNT/mysnap2/bar | cut -f 1 -d ' ')
 
 # Now recreate the filesystem by receiving both send streams and verify we get
 # the same file contents that the original filesystem had.
@@ -119,10 +125,18 @@ _scratch_mount
 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/1.snap
 _run_btrfs_util_prog receive $SCRATCH_MNT -f $send_files_dir/2.snap
 
-echo "File digests in the new filesystem:"
-md5sum $SCRATCH_MNT/mysnap1/foo | _filter_scratch
-md5sum $SCRATCH_MNT/mysnap2/foo | _filter_scratch
-md5sum $SCRATCH_MNT/mysnap2/bar | _filter_scratch
+# echo "File digests in the new filesystem:"
+declare -A dst_fs_hash
+dst_fs_hash[mysnap1_foo]=$(md5sum $SCRATCH_MNT/mysnap1/foo | cut -f 1 -d ' ')
+dst_fs_hash[mysnap2_foo]=$(md5sum $SCRATCH_MNT/mysnap2/foo | cut -f 1 -d ' ')
+dst_fs_hash[mysnap2_bar]=$(md5sum $SCRATCH_MNT/mysnap2/bar | cut -f 1 -d ' ')
+
+for key in "${!src_fs_hash[@]}"; do
+       if [ ${src_fs_hash[$key]} != ${dst_fs_hash[$key]} ]; then
+               echo "Mimatching hash value detected against \
+$(echo $key | tr _ /)"
+       fi
+done
 
 status=0
 exit
tests/btrfs/094.out +0 -7
index c3ac1bf..fe26ea0 100644
@@ -1,15 +1,4 @@
 QA output created by 094
-wrote 131072/131072 bytes at offset 65536
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-wrote 114688/114688 bytes at offset 65536
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-wrote 12288/12288 bytes at offset 184320
-XXX Bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
-File digests in the original filesystem:

tests/btrfs/094.out line 4

Quoted 10 lines
tests/btrfs/094.out +3 -7
-f98243c603750f7daf225b1745b31516  SCRATCH_MNT/mysnap1/foo
-f98243c603750f7daf225b1745b31516  SCRATCH_MNT/mysnap2/foo
-7fccf6175f5c68504b408719a21db99f  SCRATCH_MNT/mysnap2/bar
-File digests in the new filesystem:
-f98243c603750f7daf225b1745b31516  SCRATCH_MNT/mysnap1/foo
-f98243c603750f7daf225b1745b31516  SCRATCH_MNT/mysnap2/foo
-7fccf6175f5c68504b408719a21db99f  SCRATCH_MNT/mysnap2/bar
+Blocks modified: [16 - 47]
+Blocks modified: [16 - 43]
+Blocks modified: [45 - 47]

Hi Chandan,

I can't agree with this change. We're no longer checking that file data is correct after the cloning operations. The md5sum checks were exactly for that. So essentially the test is only verifying the clone operations don't fail with errors, it no longer checks for data corruption...

Same comment applies to at least a few other patches in the series.

Quoted 3 lines

--
2.1.0

Signature · 5 lines
Filipe David Manana,

"Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men."
#9 lore raw

Re: [PATCH 06/12] Fix btrfs/094 to work on non-4k block sized filesystems

In reply to Chandan Rajendra
Quoted 17 lines · Chandan Rajendra
Quoted 10 lines · On Wednesday 25 Nov 2015 11:11:27 Filipe Manana wrote:

Hi Chandan,

I can't agree with this change. We're no longer checking that file data is correct after the cloning operations. The md5sum checks were exactly for that. So essentially the test is only verifying the clone operations don't fail with errors, it no longer checks for data corruption...

Same comment applies to at least a few other patches in the series.

Hello Filipe,

All the tests where we had md5sum being echoed into output have been replaced with code to verify the md5sum values as shown below,

Quoted 7 lines
        if [ $foo_orig_hash != $foo_hash ]; then
                echo "Read operation failed on $SCRATCH_MNT/foo: "\
                     "Mimatching hash values detected."
        fi

This will cause a diff between the test's ideal output versus the output obtained during the test run.

Right, it compares the digests before and after some operation (which should always match). However we no longer validate that the file content is correct before the operation. For some of the tests that is more important, like the ones that test read corruption after cloning compressed extents.

Quoted 15 lines

In case of btrfs/094, I have added an associative array to hold the md5sums and
the file content verification is being performed by the following code,

for key in "${!src_fs_hash[@]}"; do

        if [ ${src_fs_hash[$key]} != ${dst_fs_hash[$key]} ]; then
                echo "Mimatching hash value detected against \

$(echo $key | tr _ /)"
fi
done

--
chandan

Signature · 5 lines
Filipe David Manana,

"Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men."
#8 lore raw

Re: [PATCH 06/12] Fix btrfs/094 to work on non-4k block sized filesystems

In reply to Filipe Manana
Quoted 10 lines · On Wednesday 25 Nov 2015 11:11:27 Filipe Manana wrote:

Hi Chandan,

I can't agree with this change. We're no longer checking that file data is correct after the cloning operations. The md5sum checks were exactly for that. So essentially the test is only verifying the clone operations don't fail with errors, it no longer checks for data corruption...

Same comment applies to at least a few other patches in the series.

Hello Filipe,

All the tests where we had md5sum being echoed into output have been replaced with code to verify the md5sum values as shown below,

	if [ $foo_orig_hash != $foo_hash ]; then
		echo "Read operation failed on $SCRATCH_MNT/foo: "\
		     "Mimatching hash values detected."
	fi

This will cause a diff between the test's ideal output versus the output obtained during the test run.

In case of btrfs/094, I have added an associative array to hold the md5sums and
the file content verification is being performed by the following code,

for key in "${!src_fs_hash[@]}"; do

	if [ ${src_fs_hash[$key]} != ${dst_fs_hash[$key]} ]; then
		echo "Mimatching hash value detected against \

$(echo $key | tr _ /)"
fi
done

Signature · 1 line
chandan
#10 lore raw

Re: [PATCH 06/12] Fix btrfs/094 to work on non-4k block sized filesystems

In reply to Filipe Manana
Quoted 27 lines · On Wednesday 25 Nov 2015 11:51:52 Filipe Manana wrote:

On Wed, Nov 25, 2015 at 11:47 AM, Chandan Rajendra

Quoted 24 lines · <[email protected]> wrote:
Quoted 9 lines · On Wednesday 25 Nov 2015 11:11:27 Filipe Manana wrote:

Hi Chandan,

I can't agree with this change. We're no longer checking that file data is correct after the cloning operations. The md5sum checks were exactly for that. So essentially the test is only verifying the clone operations don't fail with errors, it no longer checks for data corruption...

Same comment applies to at least a few other patches in the series.

Hello Filipe,

All the tests where we had md5sum being echoed into output have been replaced with code to verify the md5sum values as shown below,

        if [ $foo_orig_hash != $foo_hash ]; then
        
                echo "Read operation failed on $SCRATCH_MNT/foo: "\
                
                     "Mimatching hash values detected."
        
        fi
Quoted 8 lines
Quoted 2 lines

This will cause a diff between the test's ideal output versus the output obtained during the test run.

Right, it compares the digests before and after some operation (which should always match). However we no longer validate that the file content is correct before the operation. For some of the tests that is more important, like the ones that test read corruption after cloning compressed extents.

Filipe, you are right. I will drop the fautly patches and send V2 containing fixes for only btrfs/017, btrfs/055 and btrfs/056.

Thanks for providing the review comments.

Signature · 1 line
chandan