reflink: refactor mixed block creation code
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 10 Feb 2016 07:47:22 +0000 (23:47 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Fri, 12 Feb 2016 17:39:05 +0000 (09:39 -0800)
Refactor the code that creates files with mixed block types that we feed
into CoW tests to make sure that we can tiptoe around that kind of stuff.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
13 files changed:
common/reflink
tests/generic/188
tests/generic/189
tests/generic/190
tests/generic/191
tests/generic/194
tests/generic/195
tests/generic/196
tests/generic/197
tests/generic/199
tests/generic/199.out
tests/generic/200
tests/generic/200.out

index 3d6a8c14c5514afd2114cad225d33d47240b10c1..b92f6646f707f1584efc114f66a1de04f9b9b691 100644 (file)
@@ -187,3 +187,111 @@ _dedupe_range() {
 
        "$XFS_IO_PROG" $xfs_io_args -f -c "dedupe $file1 $offset1 $offset2 $len" "$file2"
 }
+
+# Create a file of interleaved unwritten and reflinked blocks
+_weave_reflink_unwritten() {
+       blksz=$1
+       nr=$2
+       sfile=$3
+       dfile=$4
+
+       _pwrite_byte 0x61 0 $((blksz * nr)) $sfile
+       $XFS_IO_PROG -f -c "falloc 0 $((blksz * nr))" $dfile
+       _pwrite_byte 0x00 0 $((blksz * nr)) $dfile.chk
+       seq 0 2 $((nr - 1)) | while read i; do
+               _reflink_range $sfile $((blksz * i)) $dfile $((blksz * i)) $blksz
+               _pwrite_byte 0x61 $((blksz * i)) $blksz $dfile.chk
+       done
+}
+
+# Create a file of interleaved holes and reflinked blocks
+_weave_reflink_holes() {
+       blksz=$1
+       nr=$2
+       sfile=$3
+       dfile=$4
+
+       _pwrite_byte 0x61 0 $((blksz * nr)) $sfile
+       $XFS_IO_PROG -f -c "truncate $((blksz * nr))" $dfile
+       _pwrite_byte 0x00 0 $((blksz * nr)) $dfile.chk
+       seq 0 2 $((nr - 1)) | while read i; do
+               _reflink_range $sfile $((blksz * i)) $dfile $((blksz * i)) $blksz
+               _pwrite_byte 0x61 $((blksz * i)) $blksz $dfile.chk
+       done
+}
+
+# For a file created with _weave_reflink_holes, fill the holes with delalloc
+# extents
+_weave_reflink_holes_delalloc() {
+       blksz=$1
+       nr=$2
+       dfile=$3
+
+       seq 1 2 $((nr - 1)) | while read i; do
+               _pwrite_byte 0x62 $((blksz * i)) $blksz $dfile
+               _pwrite_byte 0x62 $((blksz * i)) $blksz $dfile.chk
+       done
+}
+
+# Create a file of interleaved regular blocks and reflinked blocks
+_weave_reflink_regular() {
+       blksz=$1
+       nr=$2
+       sfile=$3
+       dfile=$4
+
+       _pwrite_byte 0x61 0 $((blksz * nr)) $sfile
+       _pwrite_byte 0x62 0 $((blksz * nr)) $dfile
+       _pwrite_byte 0x62 0 $((blksz * nr)) $dfile.chk
+       seq 0 2 $((nr - 1)) | while read i; do
+               _reflink_range $sfile $((blksz * i)) $dfile $((blksz * i)) $blksz
+               _pwrite_byte 0x61 $((blksz * i)) $blksz $dfile.chk
+       done
+}
+
+# Create a file of interleaved holes, unwritten blocks, regular blocks, and
+# reflinked blocks
+_weave_reflink_rainbow() {
+       blksz=$1
+       nr=$2
+       sfile=$3
+       dfile=$4
+
+       _pwrite_byte 0x61 0 $((blksz * nr)) $sfile
+       $XFS_IO_PROG -f -c "truncate $((blksz * nr))" $dfile
+       _pwrite_byte 0x00 0 $((blksz * nr)) $dfile.chk
+       # 0 blocks are reflinked
+       seq 0 5 $((nr - 1)) | while read i; do
+               _reflink_range $sfile $((blksz * i)) $dfile $((blksz * i)) $blksz
+               _pwrite_byte 0x61 $((blksz * i)) $blksz $dfile.chk
+       done
+       # 1 blocks are unwritten
+       seq 1 5 $((nr - 1)) | while read i; do
+               $XFS_IO_PROG -f -c "falloc $((blksz * i)) $blksz" $dfile
+               _pwrite_byte 0x00 $((blksz * i)) $blksz $dfile.chk
+       done
+       # 2 blocks are holes
+       seq 2 5 $((nr - 1)) | while read i; do
+               _pwrite_byte 0x00 $((blksz * i)) $blksz $dfile.chk
+       done
+       # 3 blocks are regular
+       seq 3 5 $((nr - 1)) | while read i; do
+               _pwrite_byte 0x71 $((blksz * i)) $blksz $dfile
+               _pwrite_byte 0x71 $((blksz * i)) $blksz $dfile.chk
+       done
+       # 4 blocks will be delalloc later
+}
+
+# For a file created with _weave_reflink_rainbow, fill the holes with delalloc
+# extents
+_weave_reflink_rainbow_delalloc() {
+       blksz=$1
+       nr=$2
+       dfile=$3
+
+       # 4 blocks are delalloc (do later)
+       seq 4 5 $((nr - 1)) | while read i; do
+               _pwrite_byte 0x62 $((blksz * i)) $blksz $dfile
+               _pwrite_byte 0x62 $((blksz * i)) $blksz $dfile.chk
+       done
+}
index 7596c4b904b68dd9af669e996941e3740b7a522c..86980cced4230ae1d958d6ad8129306b0328a989 100755 (executable)
@@ -63,13 +63,7 @@ mkdir $testdir
 echo "Create the original files"
 blksz=65536
 nr=64
-_pwrite_byte 0x61 0 $((blksz * nr)) "$testdir/file1" >> "$seqres.full"
-$XFS_IO_PROG -f -c "falloc 0 $((blksz * nr))" "$testdir/file3" >> "$seqres.full"
-_pwrite_byte 0x00 0 $((blksz * nr)) "$testdir/file3.chk" >> "$seqres.full"
-seq 0 2 $((nr-1)) | while read f; do
-       _reflink_range "$testdir/file1" $((blksz * f)) "$testdir/file3" $((blksz * f)) $blksz >> "$seqres.full"
-       _pwrite_byte 0x61 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_unwritten $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
 _scratch_remount
 
 echo "Compare files"
index 130dc58aa17ccfc5b9c2a97a941859c1a1dbcbce..8f5a338ab2fabaf86d3dc469bbb2ed93fb96a5e8 100755 (executable)
@@ -63,13 +63,7 @@ mkdir $testdir
 echo "Create the original files"
 blksz=65536
 nr=64
-_pwrite_byte 0x61 0 $((blksz * nr)) "$testdir/file1" >> "$seqres.full"
-$XFS_IO_PROG -f -c "falloc 0 $((blksz * nr))" "$testdir/file3" >> "$seqres.full"
-_pwrite_byte 0x00 0 $((blksz * nr)) "$testdir/file3.chk" >> "$seqres.full"
-seq 0 2 $((nr-1)) | while read f; do
-       _reflink_range "$testdir/file1" $((blksz * f)) "$testdir/file3" $((blksz * f)) $blksz >> "$seqres.full"
-       _pwrite_byte 0x61 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_unwritten $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
 _scratch_remount
 
 echo "Compare files"
index 0171475358d19bf14f4a704117c381a59ec5e6c5..8edfeb7e6cf7ab0dd47e171bd3a0da87503736e8 100755 (executable)
@@ -63,13 +63,7 @@ mkdir $testdir
 echo "Create the original files"
 blksz=65536
 nr=64
-_pwrite_byte 0x61 0 $((blksz * nr)) "$testdir/file1" >> "$seqres.full"
-$XFS_IO_PROG -f -c "truncate $((blksz * nr))" "$testdir/file3" >> "$seqres.full"
-_pwrite_byte 0x00 0 $((blksz * nr)) "$testdir/file3.chk" >> "$seqres.full"
-seq 0 2 $((nr-1)) | while read f; do
-       _reflink_range "$testdir/file1" $((blksz * f)) "$testdir/file3" $((blksz * f)) $blksz >> "$seqres.full"
-       _pwrite_byte 0x61 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_holes $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
 _scratch_remount
 
 echo "Compare files"
index 34d96f958220d6e6cd2057e555e03f27a97a0e01..dd97baad3c39eec1f332ed9c7e2be25d75f1ced2 100755 (executable)
@@ -63,13 +63,7 @@ mkdir $testdir
 echo "Create the original files"
 blksz=65536
 nr=64
-_pwrite_byte 0x61 0 $((blksz * nr)) "$testdir/file1" >> "$seqres.full"
-$XFS_IO_PROG -f -c "truncate $((blksz * nr))" "$testdir/file3" >> "$seqres.full"
-_pwrite_byte 0x00 0 $((blksz * nr)) "$testdir/file3.chk" >> "$seqres.full"
-seq 0 2 $((nr-1)) | while read f; do
-       _reflink_range "$testdir/file1" $((blksz * f)) "$testdir/file3" $((blksz * f)) $blksz >> "$seqres.full"
-       _pwrite_byte 0x61 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_holes $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
 _scratch_remount
 
 echo "Compare files"
index e9feaadf7c553f3ca9a7da2cb0618daac789c179..82b310096fc3b2492c41fd400c1d58e694ba8265 100755 (executable)
@@ -64,13 +64,7 @@ mkdir $testdir
 echo "Create the original files"
 blksz=65536
 nr=64
-_pwrite_byte 0x61 0 $((blksz * nr)) "$testdir/file1" >> "$seqres.full"
-$XFS_IO_PROG -f -c "truncate $((blksz * nr))" "$testdir/file3" >> "$seqres.full"
-_pwrite_byte 0x00 0 $((blksz * nr)) "$testdir/file3.chk" >> "$seqres.full"
-seq 0 2 $((nr-1)) | while read f; do
-       _reflink_range "$testdir/file1" $((blksz * f)) "$testdir/file3" $((blksz * f)) $blksz >> "$seqres.full"
-       _pwrite_byte 0x61 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_holes $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
 _scratch_remount
 
 echo "Compare files"
@@ -79,10 +73,7 @@ md5sum "$testdir/file3" | _filter_scratch
 md5sum "$testdir/file3.chk" | _filter_scratch
 
 echo "directio CoW across the transition"
-seq 1 2 $((nr-1)) | while read f; do
-       _pwrite_byte 0x62 $((blksz * f)) $blksz "$testdir/file3" >> "$seqres.full"
-       _pwrite_byte 0x62 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_holes_delalloc $blksz $nr $testdir/file3 >> $seqres.full
 "$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 -b $((blksz * nr / 2)) $((blksz * nr / 4)) $((blksz * nr / 2))" "$testdir/file3" >> "$seqres.full"
 _pwrite_byte 0x63 $((blksz * nr / 4)) $((blksz * nr / 2)) "$testdir/file3.chk" >> "$seqres.full"
 _scratch_remount
index 32548baa09464dc6fd29c82d0c1ce65f434fc702..ce4c0a9b9b844ba9da0bdba3b9bdfb46589cb3f5 100755 (executable)
@@ -64,13 +64,7 @@ mkdir $testdir
 echo "Create the original files"
 blksz=65536
 nr=64
-_pwrite_byte 0x61 0 $((blksz * nr)) "$testdir/file1" >> "$seqres.full"
-$XFS_IO_PROG -f -c "truncate $((blksz * nr))" "$testdir/file3" >> "$seqres.full"
-_pwrite_byte 0x00 0 $((blksz * nr)) "$testdir/file3.chk" >> "$seqres.full"
-seq 0 2 $((nr-1)) | while read f; do
-       _reflink_range "$testdir/file1" $((blksz * f)) "$testdir/file3" $((blksz * f)) $blksz >> "$seqres.full"
-       _pwrite_byte 0x61 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_holes $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
 _scratch_remount
 
 echo "Compare files"
@@ -79,10 +73,7 @@ md5sum "$testdir/file3" | _filter_scratch
 md5sum "$testdir/file3.chk" | _filter_scratch
 
 echo "CoW across the transition"
-seq 1 2 $((nr-1)) | while read f; do
-       _pwrite_byte 0x62 $((blksz * f)) $blksz "$testdir/file3" >> "$seqres.full"
-       _pwrite_byte 0x62 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_holes_delalloc $blksz $nr $testdir/file3 >> $seqres.full
 "$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((blksz * nr / 2)) $((blksz * nr / 4)) $((blksz * nr / 2))" "$testdir/file3" >> "$seqres.full"
 _pwrite_byte 0x63 $((blksz * nr / 4)) $((blksz * nr / 2)) "$testdir/file3.chk" >> "$seqres.full"
 _scratch_remount
index 4ec2cffbe1ad978c1454b278cc2e8b573857cfb8..a7a0035bf0769e997986f7f4365121f32c38ef9a 100755 (executable)
@@ -63,13 +63,7 @@ mkdir $testdir
 echo "Create the original files"
 blksz=65536
 nr=64
-_pwrite_byte 0x61 0 $((blksz * nr)) "$testdir/file1" >> "$seqres.full"
-_pwrite_byte 0x62 0 $((blksz * nr)) "$testdir/file3" >> "$seqres.full"
-_pwrite_byte 0x62 0 $((blksz * nr)) "$testdir/file3.chk" >> "$seqres.full"
-seq 0 2 $((nr-1)) | while read f; do
-       _reflink_range "$testdir/file1" $((blksz * f)) "$testdir/file3" $((blksz * f)) $blksz >> "$seqres.full"
-       _pwrite_byte 0x61 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_regular $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
 _scratch_remount
 
 echo "Compare files"
index 356a587ba12da3cba6dfe5c6667157c4e72db4ad..84a14ffecb372e8595481d4fcef7fab82f1c6960 100755 (executable)
@@ -63,13 +63,7 @@ mkdir $testdir
 echo "Create the original files"
 blksz=65536
 nr=64
-_pwrite_byte 0x61 0 $((blksz * nr)) "$testdir/file1" >> "$seqres.full"
-_pwrite_byte 0x62 0 $((blksz * nr)) "$testdir/file3" >> "$seqres.full"
-_pwrite_byte 0x62 0 $((blksz * nr)) "$testdir/file3.chk" >> "$seqres.full"
-seq 0 2 $((nr-1)) | while read f; do
-       _reflink_range "$testdir/file1" $((blksz * f)) "$testdir/file3" $((blksz * f)) $blksz >> "$seqres.full"
-       _pwrite_byte 0x61 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_regular $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
 _scratch_remount
 
 echo "Compare files"
index 03b8fdada6b255c4725308080b117cb2ca25dedc..6a65533bf0b3509e2ec1b165e87b0a689d250c4a 100755 (executable)
@@ -69,30 +69,7 @@ mkdir $testdir
 echo "Create the original files"
 blksz=65536
 nr=64
-_pwrite_byte 0x61 0 $((blksz * nr)) "$testdir/file1" >> "$seqres.full"
-$XFS_IO_PROG -f -c "truncate $((blksz * nr))" "$testdir/file3" >> "$seqres.full"
-# 0 blocks are reflinked
-seq 0 5 $nr | while read f; do
-       _reflink_range "$testdir/file1" $((blksz * f)) "$testdir/file3" $((blksz * f)) $blksz >> "$seqres.full"
-       _pwrite_byte 0x61 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
-sync
-# 1 blocks are unwritten
-seq 1 5 $nr | while read f; do
-       $XFS_IO_PROG -f -c "falloc $((blksz * f)) $blksz" "$testdir/file3" >> "$seqres.full"
-       _pwrite_byte 0x00 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
-sync
-# 2 blocks are holes
-seq 2 5 $nr | while read f; do
-       _pwrite_byte 0x00 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
-# 3 blocks are regular
-seq 3 5 $nr | while read f; do
-       _pwrite_byte 0x71 $((blksz * f)) $blksz "$testdir/file3" >> "$seqres.full"
-       _pwrite_byte 0x71 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
-sync
+_weave_reflink_rainbow $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
 _scratch_remount
 
 echo "Compare files"
@@ -101,11 +78,7 @@ md5sum "$testdir/file3" | _filter_scratch
 md5sum "$testdir/file3.chk" | _filter_scratch
 
 echo "directio CoW across the transition"
-# 4 blocks are delalloc (do later)
-seq 4 5 $nr | while read f; do
-       _pwrite_byte 0x62 $((blksz * f)) $blksz "$testdir/file3" >> "$seqres.full"
-       _pwrite_byte 0x62 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_rainbow_delalloc $blksz $nr $testdir/file3 >> $seqres.full
 # now cow
 "$XFS_IO_PROG" -d -f -c "pwrite -S 0x63 -b $((blksz * nr / 2)) $((blksz * nr / 4)) $((blksz * nr / 2))" "$testdir/file3" >> "$seqres.full"
 _pwrite_byte 0x63 $((blksz * nr / 4)) $((blksz * nr / 2)) "$testdir/file3.chk" >> "$seqres.full"
index b35c135fee2399d8f6e8c7f53596a89a56fa4c99..a1016aced8d6806f2dd6a7a218b320584ac35268 100644 (file)
@@ -8,5 +8,5 @@ bdbcf02ee0aa977795a79d25fcfdccb1  SCRATCH_MNT/test-199/file1
 directio CoW across the transition
 Compare files
 bdbcf02ee0aa977795a79d25fcfdccb1  SCRATCH_MNT/test-199/file1
-36f6b5317a9a921fc91175390ccf7f69  SCRATCH_MNT/test-199/file3
-36f6b5317a9a921fc91175390ccf7f69  SCRATCH_MNT/test-199/file3.chk
+26aa3a0749b867ec58363c8539ee5471  SCRATCH_MNT/test-199/file3
+26aa3a0749b867ec58363c8539ee5471  SCRATCH_MNT/test-199/file3.chk
index e71eedcc674b9f9909e760313b6cb103d4021db8..541d16de74b5aa08a34a9c634a1794dcf5067689 100755 (executable)
@@ -69,30 +69,7 @@ mkdir $testdir
 echo "Create the original files"
 blksz=65536
 nr=64
-_pwrite_byte 0x61 0 $((blksz * nr)) "$testdir/file1" >> "$seqres.full"
-$XFS_IO_PROG -f -c "truncate $((blksz * nr))" "$testdir/file3" >> "$seqres.full"
-# 0 blocks are reflinked
-seq 0 5 $nr | while read f; do
-       _reflink_range "$testdir/file1" $((blksz * f)) "$testdir/file3" $((blksz * f)) $blksz >> "$seqres.full"
-       _pwrite_byte 0x61 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
-sync
-# 1 blocks are unwritten
-seq 1 5 $nr | while read f; do
-       $XFS_IO_PROG -f -c "falloc $((blksz * f)) $blksz" "$testdir/file3" >> "$seqres.full"
-       _pwrite_byte 0x00 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
-sync
-# 2 blocks are holes
-seq 2 5 $nr | while read f; do
-       _pwrite_byte 0x00 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
-# 3 blocks are regular
-seq 3 5 $nr | while read f; do
-       _pwrite_byte 0x71 $((blksz * f)) $blksz "$testdir/file3" >> "$seqres.full"
-       _pwrite_byte 0x71 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
-sync
+_weave_reflink_rainbow $blksz $nr $testdir/file1 $testdir/file3 >> $seqres.full
 _scratch_remount
 
 echo "Compare files"
@@ -101,11 +78,7 @@ md5sum "$testdir/file3" | _filter_scratch
 md5sum "$testdir/file3.chk" | _filter_scratch
 
 echo "directio CoW across the transition"
-# 4 blocks are delalloc (do later)
-seq 4 5 $nr | while read f; do
-       _pwrite_byte 0x62 $((blksz * f)) $blksz "$testdir/file3" >> "$seqres.full"
-       _pwrite_byte 0x62 $((blksz * f)) $blksz "$testdir/file3.chk" >> "$seqres.full"
-done
+_weave_reflink_rainbow_delalloc $blksz $nr $testdir/file3 >> $seqres.full
 # now cow
 "$XFS_IO_PROG" -f -c "pwrite -S 0x63 -b $((blksz * nr / 2)) $((blksz * nr / 4)) $((blksz * nr / 2))" "$testdir/file3" >> "$seqres.full"
 _pwrite_byte 0x63 $((blksz * nr / 4)) $((blksz * nr / 2)) "$testdir/file3.chk" >> "$seqres.full"
index 140eff907fe03b31cb440a0e3398aabd7b83d983..76c01c7f77c5a5b7a5659aeab23ece572a277e57 100644 (file)
@@ -8,5 +8,5 @@ bdbcf02ee0aa977795a79d25fcfdccb1  SCRATCH_MNT/test-200/file1
 directio CoW across the transition
 Compare files
 bdbcf02ee0aa977795a79d25fcfdccb1  SCRATCH_MNT/test-200/file1
-36f6b5317a9a921fc91175390ccf7f69  SCRATCH_MNT/test-200/file3
-36f6b5317a9a921fc91175390ccf7f69  SCRATCH_MNT/test-200/file3.chk
+26aa3a0749b867ec58363c8539ee5471  SCRATCH_MNT/test-200/file3
+26aa3a0749b867ec58363c8539ee5471  SCRATCH_MNT/test-200/file3.chk