2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
5 # FS QA Test No. btrfs/035
7 # Regression test for overwriting clones
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
22 trap "_cleanup ; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
27 . ./common/filter.btrfs
29 # real QA test starts here
35 _scratch_mkfs > /dev/null 2>&1
40 echo -n "$src_str" > $SCRATCH_MNT/src
42 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone1
44 src_str="bbbbbbbbbbcccccccccc"
46 echo -n "$src_str" > $SCRATCH_MNT/src
48 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone2
50 snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone1 | awk '{print $5}'`
51 echo "attempting ioctl (src.clone1 src)"
52 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
53 $SCRATCH_MNT/src.clone1 $SCRATCH_MNT/src | _filter_btrfs_cloner_error
55 # The clone operation should have failed. If it did not it meant we had data
56 # loss, because file "src.clone1" has an inline extent which is 10 bytes long
57 # while file "src" has an inline extent which is 20 bytes long. The clone
58 # operation would remove the inline extent of "src" and then copy the inline
59 # extent from "src.clone1" into "src", which means we would lose the last 10
60 # bytes of data from "src" (on read we would get 0x00 as the value for any
61 # of those 10 bytes, because the file's size remains as 20 bytes).
62 echo "File src data after attempt to clone from src.clone1 into src:"
63 od -t x1 $SCRATCH_MNT/src
65 snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone2 | awk '{print $5}'`
66 echo "attempting ioctl (src.clone2 src)"
67 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
68 $SCRATCH_MNT/src.clone2 $SCRATCH_MNT/src
70 # The clone operation should have succeeded.
71 echo "File src data after attempt to clone from src.clone2 into src:"
72 od -t x1 $SCRATCH_MNT/src