fstests: move test group info to test files
[xfstests-dev.git] / tests / btrfs / 031
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 031
6 #
7 # Testing cross-subvolume sparse copy on btrfs
8 #    - Create two subvolumes, mount one of them
9 #    - Create a file on each (sub/root)volume,
10 #      reflink them on the other volumes
11 #    - Change one original and two reflinked files
12 #    - Move reflinked files between subvolumes
13 #
14 . ./common/preamble
15 _begin_fstest auto quick subvol clone
16
17 # Import common functions.
18 . ./common/filter
19 . ./common/reflink
20
21 # real QA test starts here
22 _supported_fs btrfs
23
24 _require_test
25 _require_scratch
26 _require_cp_reflink
27
28 _checksum_files()
29 {
30         for f in file1 file2 file3; do
31                 echo "$f:"
32                 for d in $testdir1 $cross_mount_test_dir $subvol2; do
33                         _md5_checksum $d/$f
34                 done
35         done
36 }
37
38 testdir1=$SCRATCH_MNT/test-$seq-1
39 testdir2=$SCRATCH_MNT/test-$seq-2
40 subvol1=$SCRATCH_MNT/subvol-$seq-1
41 subvol2=$SCRATCH_MNT/subvol-$seq-2
42 cross_mount_test_dir=$TEST_DIR/test-$seq
43
44 _scratch_mkfs > /dev/null 2>&1
45 _scratch_mount
46
47 mkdir $testdir1
48 mkdir $testdir2
49 $BTRFS_UTIL_PROG subvolume create $subvol1 >> $seqres.full
50 $BTRFS_UTIL_PROG subvolume create $subvol2 >> $seqres.full
51 rm -rf $cross_mount_test_dir
52 mkdir $cross_mount_test_dir
53
54 _mount -t btrfs -o subvol=subvol-$seq-1 $SCRATCH_DEV $cross_mount_test_dir
55
56 echo "Create initial files"
57 # #testdir1/file1 is very small and will be inlined
58 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 10' $testdir1/file1 \
59     >> $seqres.full
60 $XFS_IO_PROG -f -c 'pwrite -S 0x62 0 13000' $cross_mount_test_dir/file2 \
61     >> $seqres.full
62 $XFS_IO_PROG -f -c 'pwrite -S 0x63 0 17000' $subvol2/file3 \
63     >> $seqres.full
64
65 echo "Create reflinks to the initial files on other subvolumes"
66 cp --reflink=always $testdir1/file1 $subvol1
67 cp --reflink=always $testdir1/file1 $subvol2
68 cp --reflink=always $subvol1/file2 $testdir1/
69 cp --reflink=always $subvol1/file2 $subvol2
70 cp --reflink=always $subvol2/file3 $testdir1/
71 cp --reflink=always $subvol2/file3 $subvol1
72
73 echo "Verify the reflinks"
74 _verify_reflink $cross_mount_test_dir/file2 $testdir1/file2
75 _verify_reflink $cross_mount_test_dir/file2 $subvol2/file2
76 _verify_reflink $subvol2/file3 $testdir1/file3
77 _verify_reflink $subvol2/file3 $cross_mount_test_dir/file3
78 echo "Verify the file contents:"
79 _checksum_files
80
81 echo -e "---\nOverwrite some files with new content"
82 $XFS_IO_PROG -c 'pwrite -S 0x64 0 20' $testdir1/file1 >> $seqres.full
83 $XFS_IO_PROG -c 'pwrite -S 0x66 0 21000' $subvol2/file2 >> $seqres.full
84 $XFS_IO_PROG -c 'pwrite -S 0x65 5000 5000' $cross_mount_test_dir/file3 \
85     >> $seqres.full
86
87 echo -n "Verify that non-overwritten reflinks "
88 echo "still have the same data blocks"
89 _verify_reflink $testdir1/file2 $cross_mount_test_dir/file2
90 _verify_reflink $testdir1/file3 $subvol2/file3
91 echo "Verify the file contents:"
92 _checksum_files
93
94 echo -e "---\nShuffle files between directories"
95 mv $testdir1/file* $testdir2
96 mv $cross_mount_test_dir/file* $testdir1/
97 mv $subvol2/file* $cross_mount_test_dir/
98 mv $testdir2/file* $subvol2/
99
100 # No _verify_reflink here as data is copied when moving files
101 # between subvols
102 echo "Verify the file contents:"
103 _checksum_files
104
105 $UMOUNT_PROG $cross_mount_test_dir
106
107 # success, all done
108 status=0
109 exit