generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 058
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/058
6 #
7 # Regression test for a btrfs issue where we create a RO snapshot to use for
8 # a send operation which fails with a -ESTALE error, due to the presence of
9 # orphan inodes accessible through the snapshot's commit root but no longer
10 # present through the main root.
11 #
12 # This issue is fixed by the following linux kernel btrfs patch:
13 #
14 #    Btrfs: update commit root on snapshot creation after orphan cleanup
15 #
16 . ./common/preamble
17 _begin_fstest auto quick send snapshot
18
19 # Override the default cleanup function.
20 _cleanup()
21 {
22         if [ ! -z $XFS_IO_PID ]; then
23                 kill $XFS_IO_PID > /dev/null 2>&1
24         fi
25         rm -fr $tmp
26 }
27
28 # Import common functions.
29 . ./common/filter
30
31 # real QA test starts here
32 _supported_fs btrfs
33 _require_scratch
34 _require_xfs_io_command "-T"
35
36 _scratch_mkfs >/dev/null 2>&1
37 _scratch_mount
38
39 # Create a tmpfile file, write some data to it and leave it open, so that our
40 # main subvolume has an orphan inode item.
41 $XFS_IO_PROG -T $SCRATCH_MNT >>$seqres.full 2>&1 < <(
42         echo "pwrite 0 65536"
43         read
44 ) &
45 XFS_IO_PID=$!
46
47 # Give it some time to the xfs_io process to create the tmpfile.
48 sleep 3
49
50 # With the tmpfile open, create a RO snapshot and use it for a send operation.
51 # The send operation used to fail with -ESTALE due to the presence of the
52 # orphan inode.
53 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap
54 _run_btrfs_util_prog send -f /dev/null $SCRATCH_MNT/mysnap
55
56 status=0
57 exit