btrfs/035: check for data loss
[xfstests-dev.git] / tests / btrfs / 035
1 #!/bin/bash
2 # FS QA Test No. btrfs/035
3 #
4 # Regression test for overwriting clones
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32
33 _cleanup()
34 {
35     rm -f $tmp.*
36 }
37
38 trap "_cleanup ; exit \$status" 0 1 2 3 15
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # real QA test starts here
45 _supported_fs btrfs
46 _supported_os Linux
47 _require_scratch
48 _require_cloner
49
50 _scratch_mkfs > /dev/null 2>&1
51 _scratch_mount
52
53 src_str="aaaaaaaaaa"
54
55 echo -n "$src_str" > $SCRATCH_MNT/src
56
57 $CLONER_PROG $SCRATCH_MNT/src  $SCRATCH_MNT/src.clone1
58
59 src_str="bbbbbbbbbbcccccccccc"
60
61 echo -n "$src_str" > $SCRATCH_MNT/src
62
63 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone2
64
65 snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone1 | awk '{print $5}'`
66 echo "attempting ioctl (src.clone1 src)"
67 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
68         $SCRATCH_MNT/src.clone1 $SCRATCH_MNT/src
69
70 # The clone operation should have failed. If it did not it meant we had data
71 # loss, because file "src.clone1" has an inline extent which is 10 bytes long
72 # while file "src" has an inline extent which is 20 bytes long. The clone
73 # operation would remove the inline extent of "src" and then copy the inline
74 # extent from "src.clone1" into "src", which means we would lose the last 10
75 # bytes of data from "src" (on read we would get 0x00 as the value for any
76 # of those 10 bytes, because the file's size remains as 20 bytes).
77 echo "File src data after attempt to clone from src.clone1 into src:"
78 od -t x1 $SCRATCH_MNT/src
79
80 snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone2 | awk '{print $5}'`
81 echo "attempting ioctl (src.clone2 src)"
82 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
83         $SCRATCH_MNT/src.clone2 $SCRATCH_MNT/src
84
85 # The clone operation should have succeeded.
86 echo "File src data after attempt to clone from src.clone2 into src:"
87 od -t x1 $SCRATCH_MNT/src
88
89 status=0 ; exit