xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / generic / 306
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 306
6 #
7 # Test RW open of a device on a RO fs
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 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     umount $BINDFILE
21     cd /
22     rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30
31 # Modify as appropriate.
32 _supported_fs generic
33 _require_scratch
34 _require_test
35 _require_symlinks
36 _require_mknod
37
38 DEVNULL=$SCRATCH_MNT/devnull
39 DEVZERO=$SCRATCH_MNT/devzero
40 SYMLINK=$SCRATCH_MNT/symlink
41 BINDFILE=$SCRATCH_MNT/bindfile
42 TARGET=$TEST_DIR/target
43
44 rm -f $seqres.full
45 _scratch_mkfs > $seqres.full 2>&1
46 _scratch_mount
47
48 rm -f $DEVNULL $DEVZERO
49
50 mknod $DEVNULL c 1 3 || _fail "Could not create devnull device"
51 mknod $DEVZERO c 1 5 || _fail "Could not create devzero device"
52 touch $BINDFILE || _fail "Could not create bind mount file"
53 touch $TARGET || _fail "Could not create symlink target"
54 ln -s $TARGET $SYMLINK
55
56 _scratch_remount ro || _fail "Could not remount scratch readonly"
57
58 # We should be able to read & write to/from these devices even on an RO fs
59 echo "== try to create new file"
60 touch $SCRATCH_MNT/this_should_fail 2>&1 | _filter_scratch
61 echo "== pwrite to null device"
62 $XFS_IO_PROG -c "pwrite 0 512" $DEVNULL | _filter_xfs_io
63 echo "== pread from zero device"
64 $XFS_IO_PROG -c "pread 0 512" $DEVZERO | _filter_xfs_io
65
66 echo "== truncating write to null device"
67 echo foo > $DEVNULL 2>&1 | _filter_scratch
68 echo "== appending write to null device"
69 echo foo >> $DEVNULL 2>&1 | _filter_scratch
70
71 echo "== writing to symlink from ro fs to rw fs"
72 # Various combinations of O_CREAT & O_TRUNC
73 $XFS_IO_PROG -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
74 $XFS_IO_PROG -f -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
75 $XFS_IO_PROG -t -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
76
77 echo "== write to bind-mounted rw file on ro fs"
78 mount --bind $TARGET $BINDFILE
79 # with and without -f (adds O_CREAT)
80 $XFS_IO_PROG -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
81 $XFS_IO_PROG -f -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
82 $XFS_IO_PROG -t -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
83
84 # success, all done
85 status=0
86 exit