xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / btrfs / 058
1 #! /bin/bash
2 # FS QA Test No. btrfs/058
3 #
4 # Regression test for a btrfs issue where we create a RO snapshot to use for
5 # a send operation which fails with a -ESTALE error, due to the presence of
6 # orphan inodes accessible through the snapshot's commit root but no longer
7 # present through the main root.
8 #
9 # This issue is fixed by the following linux kernel btrfs patch:
10 #
11 #    Btrfs: update commit root on snapshot creation after orphan cleanup
12 #
13 #-----------------------------------------------------------------------
14 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
15 # Author: Filipe Manana <fdmanana@suse.com>
16 #
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License as
19 # published by the Free Software Foundation.
20 #
21 # This program is distributed in the hope that it would be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write the Free Software Foundation,
28 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
29 #-----------------------------------------------------------------------
30 #
31
32 seq=`basename $0`
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
35
36 tmp=/tmp/$$
37 status=1        # failure is the default!
38 trap "_cleanup; exit \$status" 0 1 2 3 15
39
40 _cleanup()
41 {
42         if [ ! -z $XFS_IO_PID ]; then
43                 kill $XFS_IO_PID > /dev/null 2>&1
44         fi
45         rm -fr $tmp
46 }
47
48 # get standard environment, filters and checks
49 . ./common/rc
50 . ./common/filter
51
52 # real QA test starts here
53 _supported_fs btrfs
54 _supported_os Linux
55 _require_scratch
56 # Requiring flink command tests for the presence of the -T option used
57 # to pass O_TMPFILE to open(2).
58 _require_xfs_io_command "flink"
59
60 rm -f $seqres.full
61
62 _scratch_mkfs >/dev/null 2>&1
63 _scratch_mount
64
65 # Create a tmpfile file, write some data to it and leave it open, so that our
66 # main subvolume has an orphan inode item.
67 $XFS_IO_PROG -T $SCRATCH_MNT >>$seqres.full 2>&1 < <(
68         echo "pwrite 0 65536"
69         read
70 ) &
71 XFS_IO_PID=$!
72
73 # Give it some time to the xfs_io process to create the tmpfile.
74 sleep 3
75
76 # With the tmpfile open, create a RO snapshot and use it for a send operation.
77 # The send operation used to fail with -ESTALE due to the presence of the
78 # orphan inode.
79 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap
80 _run_btrfs_util_prog send $SCRATCH_MNT/mysnap -f /dev/null
81
82 status=0
83 exit