xfs: force file creation to the data device for certain layout tests
[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
36 _require_xfs_io_command "fiemap"
37 _require_cp_reflink
38 _require_test
39
40 testdir1=$TEST_DIR/test-$seq
41 rm -rf $testdir1
42 mkdir $testdir1
43
44 _checksum_files() {
45     for F in original copy1 copy2
46     do
47         md5sum $testdir1/$F | _filter_test_dir
48     done
49 }
50
51 rm -f $seqres.full
52
53 echo "Create the original file and reflink to copy1, copy2"
54 $XFS_IO_PROG -f -c 'pwrite -S 0x61 0 9000' $testdir1/original \
55     >> $seqres.full 2>&1
56 cp --reflink $testdir1/original $testdir1/copy1
57 cp --reflink $testdir1/copy1 $testdir1/copy2
58 _verify_reflink $testdir1/original $testdir1/copy1
59 _verify_reflink $testdir1/original $testdir1/copy2
60 echo "Original md5sums:"
61 _checksum_files
62
63 echo "Overwrite original file with new data"
64 $XFS_IO_PROG -c 'pwrite -S 0x62 0 9000' $testdir1/original \
65     >> $seqres.full 2>&1
66 echo "md5sums after overwriting original:"
67 _checksum_files
68
69 echo "Overwrite copy1 with different new data"
70 $XFS_IO_PROG -c 'pwrite -S 0x63 0 9000' $testdir1/copy1 \
71     >> $seqres.full 2>&1
72 echo "md5sums after overwriting copy1:"
73 _checksum_files
74
75 # success, all done
76 status=0
77 exit