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
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
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.
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.
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 #-----------------------------------------------------------------------
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
34 status=1 # failure is the default!
35 trap "_cleanup; exit \$status" 0 1 2 3 15
42 $BTRFS_UTIL_PROG subvolume delete $SUBVOL1 >> $seqres.full
43 $BTRFS_UTIL_PROG subvolume delete $SUBVOL2 >> $seqres.full
48 # get standard environment, filters and checks
52 # real QA test starts here
60 for F in file1 file2 file3
63 for D in $TESTDIR1 $SCRATCH_MNT $SUBVOL2
70 TESTDIR1=$TEST_DIR/test-$seq-1
71 TESTDIR2=$TEST_DIR/test-$seq-2
72 SUBVOL1=$TEST_DIR/subvol-$seq-1
73 SUBVOL2=$TEST_DIR/subvol-$seq-2
75 _scratch_unmount 2>/dev/null
77 rm -rf $TESTDIR1 $TESTDIR2
78 $BTRFS_UTIL_PROG subvolume delete $SUBVOL1 >/dev/null 2>&1
79 $BTRFS_UTIL_PROG subvolume delete $SUBVOL2 >/dev/null 2>&1
83 $BTRFS_UTIL_PROG subvolume create $SUBVOL1 >> $seqres.full
84 $BTRFS_UTIL_PROG subvolume create $SUBVOL2 >> $seqres.full
85 _mount -t btrfs -o subvol=subvol-$seq-1 $TEST_DEV $SCRATCH_MNT
87 echo "Create initial files"
88 # TESTDIR1/file1 is very small and will be inlined
89 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 10' $TESTDIR1/file1 \
91 $XFS_IO_PROG -f -c 'pwrite -S 0x62 0 13000' $SCRATCH_MNT/file2 \
93 $XFS_IO_PROG -f -c 'pwrite -S 0x63 0 17000' $SUBVOL2/file3 \
96 echo "Create reflinks to the initial files on other subvolumes"
97 cp --reflink=always $TESTDIR1/file1 $SUBVOL1
98 cp --reflink=always $TESTDIR1/file1 $SUBVOL2
99 cp --reflink=always $SUBVOL1/file2 $TESTDIR1/
100 cp --reflink=always $SUBVOL1/file2 $SUBVOL2
101 cp --reflink=always $SUBVOL2/file3 $TESTDIR1/
102 cp --reflink=always $SUBVOL2/file3 $SUBVOL1
104 echo "Verify the reflinks"
105 _verify_reflink $SCRATCH_MNT/file2 $TESTDIR1/file2
106 _verify_reflink $SCRATCH_MNT/file2 $SUBVOL2/file2
107 _verify_reflink $SUBVOL2/file3 $TESTDIR1/file3
108 _verify_reflink $SUBVOL2/file3 $SCRATCH_MNT/file3
109 echo "Verify the file contents:"
112 echo -e "---\nOverwrite some files with new content"
113 $XFS_IO_PROG -c 'pwrite -S 0x64 0 20' $TESTDIR1/file1 >> $seqres.full
114 $XFS_IO_PROG -c 'pwrite -S 0x66 0 21000' $SUBVOL2/file2 >> $seqres.full
115 $XFS_IO_PROG -c 'pwrite -S 0x65 5000 5000' $SCRATCH_MNT/file3 \
118 echo -n "Verify that non-overwritten reflinks "
119 echo "still have the same data blocks"
120 _verify_reflink $TESTDIR1/file2 $SCRATCH_MNT/file2
121 _verify_reflink $TESTDIR1/file3 $SUBVOL2/file3
122 echo "Verify the file contents:"
125 echo -e "---\nShuffle files between directories"
126 mv $TESTDIR1/file* $TESTDIR2
127 mv $SCRATCH_MNT/file* $TESTDIR1/
128 mv $SUBVOL2/file* $SCRATCH_MNT/
129 mv $TESTDIR2/file* $SUBVOL2/
131 # No _verify_reflink here as data is copied when moving files
133 echo "Verify the file contents:"