generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 110
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. 110
6 #
7 # Tests file clone functionality of btrfs ("reflinks"):
8 #   - Reflink a file
9 #   - Reflink the reflinked file
10 #   - Modify the original file
11 #   - Modify the reflinked file
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1    # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24     cd /
25     rm -f $tmp.* $testdir
26 }
27
28 # get standard environment, filters and checks
29 . common/rc
30 . common/filter
31 . common/reflink
32
33 # real QA test starts here
34 _require_test_reflink
35 _supported_os Linux
36
37 _require_xfs_io_command "fiemap"
38 _require_cp_reflink
39 _require_test
40
41 testdir1=$TEST_DIR/test-$seq
42 rm -rf $testdir1
43 mkdir $testdir1
44
45 _checksum_files() {
46     for F in original copy1 copy2
47     do
48         md5sum $testdir1/$F | _filter_test_dir
49     done
50 }
51
52 rm -f $seqres.full
53
54 echo "Create the original file and reflink to copy1, copy2"
55 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $testdir1/original \
56     >> $seqres.full 2>&1
57 cp --reflink $testdir1/original $testdir1/copy1
58 cp --reflink $testdir1/copy1 $testdir1/copy2
59 _verify_reflink $testdir1/original $testdir1/copy1
60 _verify_reflink $testdir1/original $testdir1/copy2
61 echo "Original md5sums:"
62 _checksum_files
63
64 echo "Overwrite original file with new data"
65 $XFS_IO_PROG -c 'pwrite -S 0x62 0 9000' $testdir1/original \
66     >> $seqres.full 2>&1
67 echo "md5sums after overwriting original:"
68 _checksum_files
69
70 echo "Overwrite copy1 with different new data"
71 $XFS_IO_PROG -c 'pwrite -S 0x63 0 9000' $testdir1/copy1 \
72     >> $seqres.full 2>&1
73 echo "md5sums after overwriting copy1:"
74 _checksum_files
75
76 # success, all done
77 status=0
78 exit