reflink: ensure that we can handle reflinking a lot of extents
[xfstests-dev.git] / tests / generic / 306
1 #! /bin/bash
2 # FS QA Test No. 306
3 #
4 # Test RW open of a device on a RO fs
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35     umount $BINDFILE
36     cd /
37     rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # real QA test starts here
45
46 # Modify as appropriate.
47 _supported_fs generic
48 _supported_os Linux
49 _require_scratch
50 _require_test
51
52 DEVNULL=$SCRATCH_MNT/devnull
53 DEVZERO=$SCRATCH_MNT/devzero
54 SYMLINK=$SCRATCH_MNT/symlink
55 BINDFILE=$SCRATCH_MNT/bindfile
56 TARGET=$TEST_DIR/target
57
58 rm -f $seqres.full
59 _scratch_mkfs > $seqres.full 2>&1
60 _scratch_mount
61
62 rm -f $DEVNULL $DEVZERO
63
64 mknod $DEVNULL c 1 3 || _fail "Could not create devnull device"
65 mknod $DEVZERO c 1 5 || _fail "Could not create devzero device"
66 touch $BINDFILE || _fail "Could not create bind mount file"
67 touch $TARGET || _fail "Could not create symlink target"
68 ln -s $TARGET $SYMLINK
69
70 _scratch_unmount || _fail "Could not unmount scratch device"
71 _scratch_mount -o ro || _fail "Could not mount scratch readonly"
72
73 # We should be able to read & write to/from these devices even on an RO fs
74 echo "== try to create new file"
75 touch $SCRATCH_MNT/this_should_fail 2>&1 | _filter_scratch
76 echo "== pwrite to null device"
77 $XFS_IO_PROG -c "pwrite 0 512" $DEVNULL | _filter_xfs_io
78 echo "== pread from zero device"
79 $XFS_IO_PROG -c "pread 0 512" $DEVZERO | _filter_xfs_io
80
81 echo "== truncating write to null device"
82 echo foo > $DEVNULL 2>&1 | _filter_scratch
83 echo "== appending write to null device"
84 echo foo >> $DEVNULL 2>&1 | _filter_scratch
85
86 echo "== writing to symlink from ro fs to rw fs"
87 # Various combinations of O_CREAT & O_TRUNC
88 $XFS_IO_PROG -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
89 $XFS_IO_PROG -f -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
90 $XFS_IO_PROG -t -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
91
92 echo "== write to bind-mounted rw file on ro fs"
93 mount --bind $TARGET $BINDFILE
94 # with and without -f (adds O_CREAT)
95 $XFS_IO_PROG -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
96 $XFS_IO_PROG -f -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
97 $XFS_IO_PROG -t -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
98
99 # success, all done
100 status=0
101 exit