summaryrefslogtreecommitdiff
path: root/tests/generic/306
blob: d67185e89a279b013d66abbb50aa56fe65fda00a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2013 Red Hat, Inc.  All Rights Reserved.
#
# FS QA Test No. 306
#
# Test RW open of a device on a RO fs
#
. ./common/preamble
_begin_fstest auto quick rw

# Override the default cleanup function.
_cleanup()
{
    umount $BINDFILE
    cd /
    rm -f $tmp.*
}

# Import common functions.
. ./common/filter

# real QA test starts here

# Modify as appropriate.
_supported_fs generic
_require_scratch
_require_test
_require_symlinks
_require_mknod

DEVNULL=$SCRATCH_MNT/devnull
DEVZERO=$SCRATCH_MNT/devzero
SYMLINK=$SCRATCH_MNT/symlink
BINDFILE=$SCRATCH_MNT/bindfile
TARGET=$TEST_DIR/target

_scratch_mkfs > $seqres.full 2>&1
_scratch_mount

rm -f $DEVNULL $DEVZERO

mknod $DEVNULL c 1 3 || _fail "Could not create devnull device"
mknod $DEVZERO c 1 5 || _fail "Could not create devzero device"
touch $BINDFILE || _fail "Could not create bind mount file"
touch $TARGET || _fail "Could not create symlink target"
ln -s $TARGET $SYMLINK

_scratch_remount ro || _fail "Could not remount scratch readonly"

# We should be able to read & write to/from these devices even on an RO fs
echo "== try to create new file"
touch $SCRATCH_MNT/this_should_fail 2>&1 | _filter_scratch
echo "== pwrite to null device"
$XFS_IO_PROG -c "pwrite 0 512" $DEVNULL | _filter_xfs_io
echo "== pread from zero device"
$XFS_IO_PROG -c "pread 0 512" $DEVZERO | _filter_xfs_io

echo "== truncating write to null device"
echo foo > $DEVNULL 2>&1 | _filter_scratch
echo "== appending write to null device"
echo foo >> $DEVNULL 2>&1 | _filter_scratch

echo "== writing to symlink from ro fs to rw fs"
# Various combinations of O_CREAT & O_TRUNC
$XFS_IO_PROG -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
$XFS_IO_PROG -f -c "pwrite 0 512" $SYMLINK | _filter_xfs_io
$XFS_IO_PROG -t -c "pwrite 0 512" $SYMLINK | _filter_xfs_io

echo "== write to bind-mounted rw file on ro fs"
mount --bind $TARGET $BINDFILE
# with and without -f (adds O_CREAT)
$XFS_IO_PROG -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
$XFS_IO_PROG -f -c "pwrite 0 512" $BINDFILE | _filter_xfs_io
$XFS_IO_PROG -t -c "pwrite 0 512" $BINDFILE | _filter_xfs_io

# success, all done
status=0
exit