btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 031
1 #! /bin/bash
2 # FS QA Test No. 031
3 #
4 # Testing cross-subvolume sparse copy on btrfs
5 #    - Create two subvolumes, mount one of them
6 #    - Create a file on each (sub/root)volume,
7 #      reflink them on the other volumes
8 #    - Change one original and two reflinked files
9 #    - Move reflinked files between subvolumes
10 #
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2014, Oracle and/or its affiliates.  All Rights Reserved.
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
17 #
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 #-----------------------------------------------------------------------
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1    # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 _cleanup()
38 {
39     cd /
40     rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46 . ./common/reflink
47
48 # real QA test starts here
49 _supported_fs btrfs
50 _supported_os Linux
51
52 _require_test
53 _require_scratch
54 _require_cp_reflink
55
56 _checksum_files()
57 {
58         for f in file1 file2 file3; do
59                 echo "$f:"
60                 for d in $testdir1 $cross_mount_test_dir $subvol2; do
61                         _md5_checksum $d/$f
62                 done
63         done
64 }
65
66 testdir1=$SCRATCH_MNT/test-$seq-1
67 testdir2=$SCRATCH_MNT/test-$seq-2
68 subvol1=$SCRATCH_MNT/subvol-$seq-1
69 subvol2=$SCRATCH_MNT/subvol-$seq-2
70 cross_mount_test_dir=$TEST_DIR/test-$seq
71
72 rm -f $seqres.full
73
74 _scratch_mkfs > /dev/null 2>&1
75 _scratch_mount
76
77 mkdir $testdir1
78 mkdir $testdir2
79 $BTRFS_UTIL_PROG subvolume create $subvol1 >> $seqres.full
80 $BTRFS_UTIL_PROG subvolume create $subvol2 >> $seqres.full
81 rm -rf $cross_mount_test_dir
82 mkdir $cross_mount_test_dir
83
84 _mount -t btrfs -o subvol=subvol-$seq-1 $SCRATCH_DEV $cross_mount_test_dir
85
86 echo "Create initial files"
87 # #testdir1/file1 is very small and will be inlined
88 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 10' $testdir1/file1 \
89     >> $seqres.full
90 $XFS_IO_PROG -f -c 'pwrite -S 0x62 0 13000' $cross_mount_test_dir/file2 \
91     >> $seqres.full
92 $XFS_IO_PROG -f -c 'pwrite -S 0x63 0 17000' $subvol2/file3 \
93     >> $seqres.full
94
95 echo "Create reflinks to the initial files on other subvolumes"
96 cp --reflink=always $testdir1/file1 $subvol1
97 cp --reflink=always $testdir1/file1 $subvol2
98 cp --reflink=always $subvol1/file2 $testdir1/
99 cp --reflink=always $subvol1/file2 $subvol2
100 cp --reflink=always $subvol2/file3 $testdir1/
101 cp --reflink=always $subvol2/file3 $subvol1
102
103 echo "Verify the reflinks"
104 _verify_reflink $cross_mount_test_dir/file2 $testdir1/file2
105 _verify_reflink $cross_mount_test_dir/file2 $subvol2/file2
106 _verify_reflink $subvol2/file3 $testdir1/file3
107 _verify_reflink $subvol2/file3 $cross_mount_test_dir/file3
108 echo "Verify the file contents:"
109 _checksum_files
110
111 echo -e "---\nOverwrite some files with new content"
112 $XFS_IO_PROG -c 'pwrite -S 0x64 0 20' $testdir1/file1 >> $seqres.full
113 $XFS_IO_PROG -c 'pwrite -S 0x66 0 21000' $subvol2/file2 >> $seqres.full
114 $XFS_IO_PROG -c 'pwrite -S 0x65 5000 5000' $cross_mount_test_dir/file3 \
115     >> $seqres.full
116
117 echo -n "Verify that non-overwritten reflinks "
118 echo "still have the same data blocks"
119 _verify_reflink $testdir1/file2 $cross_mount_test_dir/file2
120 _verify_reflink $testdir1/file3 $subvol2/file3
121 echo "Verify the file contents:"
122 _checksum_files
123
124 echo -e "---\nShuffle files between directories"
125 mv $testdir1/file* $testdir2
126 mv $cross_mount_test_dir/file* $testdir1/
127 mv $subvol2/file* $cross_mount_test_dir/
128 mv $testdir2/file* $subvol2/
129
130 # No _verify_reflink here as data is copied when moving files
131 # between subvols
132 echo "Verify the file contents:"
133 _checksum_files
134
135 $UMOUNT_PROG $cross_mount_test_dir
136
137 # success, all done
138 status=0
139 exit