lib/: spdx license conversion
[xfstests-dev.git] / tests / generic / 111
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. 111
6 #
7 # Tests file clone functionality of btrfs ("reflinks") on directory
8 # trees.
9 #   - Create directory and subdirectory, each having one file
10 #   - Create 2 recursive reflinked copies of the tree
11 #   - Modify the original files
12 #   - Modify one of the copies
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1    # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25     cd /
26     rm -f $tmp.* $testdir
27 }
28
29 # get standard environment, filters and checks
30 . common/rc
31 . common/filter
32 . common/reflink
33
34 # real QA test starts here
35 _require_test_reflink
36 _supported_os Linux
37
38 _require_xfs_io_command "fiemap"
39 _require_cp_reflink
40 _require_test
41
42 testdir1=$TEST_DIR/test-$seq
43 rm -rf $testdir1
44 mkdir $testdir1
45
46 _checksum_files() {
47     for F in original/file1 original/subdir/file2 \
48                  copy1/file1 copy1/subdir/file2 \
49                  copy2/file1 copy2/subdir/file2
50         do
51             md5sum $testdir1/$F | _filter_test_dir
52         done
53 }
54
55 rm -f $seqres.full
56
57 mkdir $testdir1/original
58 mkdir $testdir1/original/subdir
59
60 echo "Create the original files and reflink dirs"
61 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $testdir1/original/file1 \
62     >> $seqres.full 2>&1
63 $XFS_IO_PROG -f -c 'pwrite -S 0x62 0 11000' \
64     $testdir1/original/subdir/file2 >> $seqres.full 2>&1
65 cp --recursive --reflink $testdir1/original $testdir1/copy1
66 cp --recursive --reflink $testdir1/copy1 $testdir1/copy2
67
68 _verify_reflink $testdir1/original/file1 $testdir1/copy1/file1
69 _verify_reflink $testdir1/original/subdir/file2 \
70     $testdir1/copy1/subdir/file2
71 _verify_reflink $testdir1/original/file1 $testdir1/copy2/file1
72 _verify_reflink $testdir1/original/subdir/file2 \
73     $testdir1/copy2/subdir/file2
74
75 echo "Original md5sums:"
76 _checksum_files
77
78 echo "Overwrite original/file1 and original/subdir/file2 with new data"
79 $XFS_IO_PROG -c 'pwrite -S 0x63 0 13000' $testdir1/original/file1 \
80     >> $seqres.full 2>&1
81 $XFS_IO_PROG -c 'pwrite -S 0x64 5000 1000' \
82     $testdir1/original/subdir/file2 >> $seqres.full 2>&1
83 echo "md5sums now:"
84 _checksum_files
85
86 echo "Overwrite copy1/file1 and copy1/subdir/file2 with new data"
87 $XFS_IO_PROG -c 'pwrite -S 0x65 0 9000' $testdir1/copy1/file1 \
88     >> $seqres.full 2>&1
89 $XFS_IO_PROG -c 'pwrite -S 0x66 5000 25000' \
90     $testdir1/copy1/subdir/file2 >> $seqres.full 2>&1
91 echo "md5sums now:"
92 _checksum_files
93
94 # success, all done
95 status=0
96 exit