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
34 _scratch_mkfs > /dev/null 2>&1
39 echo -n "$src_str" > $SCRATCH_MNT/src
41 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone1
43 src_str="bbbbbbbbbbcccccccccc"
45 echo -n "$src_str" > $SCRATCH_MNT/src
47 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone2
49 snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone1 | awk '{print $5}'`
50 echo "attempting ioctl (src.clone1 src)"
51 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
52 $SCRATCH_MNT/src.clone1 $SCRATCH_MNT/src | _filter_btrfs_cloner_error
54 # The clone operation should have failed. If it did not it meant we had data
55 # loss, because file "src.clone1" has an inline extent which is 10 bytes long
56 # while file "src" has an inline extent which is 20 bytes long. The clone
57 # operation would remove the inline extent of "src" and then copy the inline
58 # extent from "src.clone1" into "src", which means we would lose the last 10
59 # bytes of data from "src" (on read we would get 0x00 as the value for any
60 # of those 10 bytes, because the file's size remains as 20 bytes).
61 echo "File src data after attempt to clone from src.clone1 into src:"
62 od -t x1 $SCRATCH_MNT/src
64 snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone2 | awk '{print $5}'`
65 echo "attempting ioctl (src.clone2 src)"
66 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
67 $SCRATCH_MNT/src.clone2 $SCRATCH_MNT/src
69 # The clone operation should have succeeded.
70 echo "File src data after attempt to clone from src.clone2 into src:"
71 od -t x1 $SCRATCH_MNT/src