generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
10 _begin_fstest auto quick clone
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/filter.btrfs
15
16 # real QA test starts here
17 _supported_fs btrfs
18 _require_scratch
19 _require_cloner
20
21 _scratch_mkfs > /dev/null 2>&1
22 _scratch_mount
23
24 src_str="aaaaaaaaaa"
25
26 echo -n "$src_str" > $SCRATCH_MNT/src
27
28 $CLONER_PROG $SCRATCH_MNT/src  $SCRATCH_MNT/src.clone1
29
30 src_str="bbbbbbbbbbcccccccccc"
31
32 echo -n "$src_str" > $SCRATCH_MNT/src
33
34 $CLONER_PROG $SCRATCH_MNT/src $SCRATCH_MNT/src.clone2
35
36 snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone1 | awk '{print $5}'`
37 echo "attempting ioctl (src.clone1 src)"
38 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
39         $SCRATCH_MNT/src.clone1 $SCRATCH_MNT/src | _filter_btrfs_cloner_error
40
41 # The clone operation should have failed. If it did not it meant we had data
42 # loss, because file "src.clone1" has an inline extent which is 10 bytes long
43 # while file "src" has an inline extent which is 20 bytes long. The clone
44 # operation would remove the inline extent of "src" and then copy the inline
45 # extent from "src.clone1" into "src", which means we would lose the last 10
46 # bytes of data from "src" (on read we would get 0x00 as the value for any
47 # of those 10 bytes, because the file's size remains as 20 bytes).
48 echo "File src data after attempt to clone from src.clone1 into src:"
49 od -t x1 $SCRATCH_MNT/src
50
51 snap_src_sz=`ls -lah $SCRATCH_MNT/src.clone2 | awk '{print $5}'`
52 echo "attempting ioctl (src.clone2 src)"
53 $CLONER_PROG -s 0 -d 0 -l ${snap_src_sz} \
54         $SCRATCH_MNT/src.clone2 $SCRATCH_MNT/src
55
56 # The clone operation should have succeeded.
57 echo "File src data after attempt to clone from src.clone2 into src:"
58 od -t x1 $SCRATCH_MNT/src
59
60 status=0 ; exit