2 # FS QA Test No. btrfs/035
4 # Regression test for overwriting clones
6 #-----------------------------------------------------------------------
7 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
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.
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.
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
22 #-----------------------------------------------------------------------
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
31 status=1 # failure is the default!
38 trap "_cleanup ; exit \$status" 0 1 2 3 15
40 # get standard environment, filters and checks
44 # real QA test starts here
50 _scratch_mkfs > /dev/null 2>&1
55 echo -n "$src_str" > $SCRATCH_MNT/src
57 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone1
59 src_str="bbbbbbbbbbcccccccccc"
61 echo -n "$src_str" > $SCRATCH_MNT/src
63 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone2
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
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
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
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