xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / btrfs / 035
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/035
6 #
7 # Regression test for overwriting clones
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16
17 _cleanup()
18 {
19     rm -f $tmp.*
20 }
21
22 trap "_cleanup ; exit \$status" 0 1 2 3 15
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/filter.btrfs
28
29 # real QA test starts here
30 _supported_fs btrfs
31 _require_scratch
32 _require_cloner
33
34 _scratch_mkfs > /dev/null 2>&1
35 _scratch_mount
36
37 src_str="aaaaaaaaaa"
38
39 echo -n "$src_str" > $SCRATCH_MNT/src
40
41 $CLONER_PROG $SCRATCH_MNT/src  $SCRATCH_MNT/src.clone1
42
43 src_str="bbbbbbbbbbcccccccccc"
44
45 echo -n "$src_str" > $SCRATCH_MNT/src
46
47 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone2
48
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
53
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
63
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
68
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
72
73 status=0 ; exit