Skip to content

Commit 804414a

Browse files
authored
tests/block_cloning: rename and document get_same_blocks helper
`get_same_blocks` is a helper to compare two files and return a list of the blocks that are clones of each other. Its very necessary for block cloning tests. Previously it was incorrectly called `unique_blocks`, which is the _inverse_ of what it does (an early version did list unique blocks; it was changed but the name was not). So if nothing else, it should be called `duplicate_blocks`. But, keeping the details of a clone operation in your head is actually quite difficult, without the additional overhead of wondering how the tools work. So I've renamed it to better describe what it does, added a usage note, and changed it to return block indexes from 0 instead of 1, to match how L0 blocks are normally counted. Reviewed-by: Umer Saleem <[email protected]> Reviewed-by: Kay Pedersen <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #15181
1 parent ed39d66 commit 804414a

10 files changed

+33
-25
lines changed

tests/zfs-tests/tests/functional/block_cloning/block_cloning.kshlib

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@ function have_same_content
3434
log_must [ "$hash1" = "$hash2" ]
3535
}
3636

37-
function unique_blocks
37+
#
38+
# get_same_blocks dataset1 path/to/file1 dataset2 path/to/file2
39+
#
40+
# Returns a space-separated list of the indexes (starting at 0) of the L0
41+
# blocks that are shared between both files (by first DVA and checksum).
42+
# Assumes that the two files have the same content, use have_same_content to
43+
# confirm that.
44+
#
45+
function get_same_blocks
3846
{
3947
typeset zdbout=${TMPDIR:-$TEST_BASE_DIR}/zdbout.$$
4048
zdb -vvvvv $1 -O $2 | \
41-
awk '/ L0 / { print ++l " " $3 " " $7 }' > $zdbout.a
49+
awk '/ L0 / { print l++ " " $3 " " $7 }' > $zdbout.a
4250
zdb -vvvvv $3 -O $4 | \
43-
awk '/ L0 / { print ++l " " $3 " " $7 }' > $zdbout.b
51+
awk '/ L0 / { print l++ " " $3 " " $7 }' > $zdbout.b
4452
echo $(sort $zdbout.a $zdbout.b | uniq -d | cut -f1 -d' ')
4553
}
4654

tests/zfs-tests/tests/functional/block_cloning/block_cloning_copyfilerange.ksh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ log_must sync_pool $TESTPOOL
5454

5555
log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2
5656

57-
typeset blocks=$(unique_blocks $TESTPOOL file1 $TESTPOOL file2)
58-
log_must [ "$blocks" = "1 2 3 4" ]
57+
typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2)
58+
log_must [ "$blocks" = "0 1 2 3" ]
5959

6060
log_pass $claim

tests/zfs-tests/tests/functional/block_cloning/block_cloning_copyfilerange_cross_dataset.ksh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ log_must sync_pool $TESTPOOL
5858

5959
log_must have_same_content /$TESTPOOL/$TESTFS1/file1 /$TESTPOOL/$TESTFS2/file2
6060

61-
typeset blocks=$(unique_blocks \
61+
typeset blocks=$(get_same_blocks \
6262
$TESTPOOL/$TESTFS1 file1 $TESTPOOL/$TESTFS2 file2)
63-
log_must [ "$blocks" = "1 2 3 4" ]
63+
log_must [ "$blocks" = "0 1 2 3" ]
6464

6565
log_pass $claim

tests/zfs-tests/tests/functional/block_cloning/block_cloning_copyfilerange_fallback.ksh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ log_must sync_pool $TESTPOOL
5858

5959
log_must have_same_content /$TESTPOOL/file /$TESTPOOL/clone
6060

61-
typeset blocks=$(unique_blocks $TESTPOOL file $TESTPOOL clone)
62-
log_must [ "$blocks" = "1 2 3 4" ]
61+
typeset blocks=$(get_same_blocks $TESTPOOL file $TESTPOOL clone)
62+
log_must [ "$blocks" = "0 1 2 3" ]
6363

6464

6565
log_note "Copying within a block with copy_file_range"
@@ -69,8 +69,8 @@ log_must sync_pool $TESTPOOL
6969

7070
log_must have_same_content /$TESTPOOL/file /$TESTPOOL/clone
7171

72-
typeset blocks=$(unique_blocks $TESTPOOL file $TESTPOOL clone)
73-
log_must [ "$blocks" = "2 3 4" ]
72+
typeset blocks=$(get_same_blocks $TESTPOOL file $TESTPOOL clone)
73+
log_must [ "$blocks" = "1 2 3" ]
7474

7575

7676
log_note "Copying across a block with copy_file_range"
@@ -80,7 +80,7 @@ log_must sync_pool $TESTPOOL
8080

8181
log_must have_same_content /$TESTPOOL/file /$TESTPOOL/clone
8282

83-
typeset blocks=$(unique_blocks $TESTPOOL file $TESTPOOL clone)
84-
log_must [ "$blocks" = "2" ]
83+
typeset blocks=$(get_same_blocks $TESTPOOL file $TESTPOOL clone)
84+
log_must [ "$blocks" = "1" ]
8585

8686
log_pass $claim

tests/zfs-tests/tests/functional/block_cloning/block_cloning_copyfilerange_fallback_same_txg.ksh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ log_must sync_pool $TESTPOOL
5959

6060
log_must have_same_content /$TESTPOOL/file /$TESTPOOL/clone
6161

62-
typeset blocks=$(unique_blocks $TESTPOOL file $TESTPOOL clone)
62+
typeset blocks=$(get_same_blocks $TESTPOOL file $TESTPOOL clone)
6363
log_must [ "$blocks" = "" ]
6464

6565
log_pass $claim

tests/zfs-tests/tests/functional/block_cloning/block_cloning_copyfilerange_partial.ksh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ log_must sync_pool $TESTPOOL
5454

5555
log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2
5656

57-
typeset blocks=$(unique_blocks $TESTPOOL file1 $TESTPOOL file2)
57+
typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2)
5858
log_must [ "$blocks" = "" ]
5959

6060
log_must clonefile -f /$TESTPOOL/file1 /$TESTPOOL/file2 131072 131072 262144
6161
log_must sync_pool $TESTPOOL
6262

6363
log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2
6464

65-
typeset blocks=$(unique_blocks $TESTPOOL file1 $TESTPOOL file2)
66-
log_must [ "$blocks" = "2 3" ]
65+
typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2)
66+
log_must [ "$blocks" = "1 2" ]
6767

6868
log_pass $claim

tests/zfs-tests/tests/functional/block_cloning/block_cloning_disabled_copyfilerange.ksh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ log_must sync_pool $TESTPOOL
5454

5555
log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2
5656

57-
typeset blocks=$(unique_blocks $TESTPOOL file1 $TESTPOOL file2)
57+
typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2)
5858
log_must [ "$blocks" = "" ]
5959

6060
log_pass $claim

tests/zfs-tests/tests/functional/block_cloning/block_cloning_ficlone.ksh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ log_must sync_pool $TESTPOOL
5050

5151
log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2
5252

53-
typeset blocks=$(unique_blocks $TESTPOOL file1 $TESTPOOL file2)
54-
log_must [ "$blocks" = "1 2 3 4" ]
53+
typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2)
54+
log_must [ "$blocks" = "0 1 2 3" ]
5555

5656
log_pass $claim

tests/zfs-tests/tests/functional/block_cloning/block_cloning_ficlonerange.ksh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ log_must sync_pool $TESTPOOL
5050

5151
log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2
5252

53-
typeset blocks=$(unique_blocks $TESTPOOL file1 $TESTPOOL file2)
54-
log_must [ "$blocks" = "1 2 3 4" ]
53+
typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2)
54+
log_must [ "$blocks" = "0 1 2 3" ]
5555

5656
log_pass $claim

tests/zfs-tests/tests/functional/block_cloning/block_cloning_ficlonerange_partial.ksh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ log_must sync_pool $TESTPOOL
5050

5151
log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2
5252

53-
typeset blocks=$(unique_blocks $TESTPOOL file1 $TESTPOOL file2)
53+
typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2)
5454
log_must [ "$blocks" = "" ]
5555

5656
log_must clonefile -r /$TESTPOOL/file1 /$TESTPOOL/file2 131072 131072 262144
5757
log_must sync_pool $TESTPOOL
5858

5959
log_must have_same_content /$TESTPOOL/file1 /$TESTPOOL/file2
6060

61-
typeset blocks=$(unique_blocks $TESTPOOL file1 $TESTPOOL file2)
62-
log_must [ "$blocks" = "2 3" ]
61+
typeset blocks=$(get_same_blocks $TESTPOOL file1 $TESTPOOL file2)
62+
log_must [ "$blocks" = "1 2" ]
6363

6464
log_pass $claim

0 commit comments

Comments
 (0)