generic/050: fix xfsquota configuration failures
[xfstests-dev.git] / tests / generic / 050
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Christoph Hellwig.
4 #
5 # FS QA Test No. 050
6 #
7 # Check out various mount/remount/unmount scenarious on a read-only blockdev.
8 #
9 seqfull=$0
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17
18 _cleanup()
19 {
20         cd /
21         blockdev --setrw $SCRATCH_DEV
22 }
23 trap "_cleanup; exit \$status" 0 1 2 3 15
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # real QA test starts here
30 _supported_fs generic
31 _supported_os Linux
32
33 _require_scratch_nocheck
34 _require_scratch_shutdown
35 _require_local_device $SCRATCH_DEV
36 _require_norecovery
37
38 # Select appropriate output file
39 features=""
40 if ! _has_metadata_journaling $SCRATCH_DEV >/dev/null; then
41         features="nojournal"
42 elif [ "$FSTYP" = "xfs" ] && echo "$MOUNT_OPTIONS" | grep -q quota ; then
43         # Mounting with quota on XFS requires a writable fs, which means
44         # we expect to fail the ro blockdev test with with EPERM.
45         features="xfsquota"
46 fi
47 _link_out_file "$features"
48
49 _scratch_mkfs >/dev/null 2>&1
50
51 #
52 # Mark the device read-only
53 #
54 echo "setting device read-only"
55 blockdev --setro $SCRATCH_DEV
56
57 #
58 # Mount it, and make sure we can't write to it, and we can unmount it again
59 #
60 echo "mounting read-only block device:"
61 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
62 if [ "${PIPESTATUS[0]}" -eq 0 ]; then
63         echo "touching file on read-only filesystem (should fail)"
64         touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
65 fi
66
67 #
68 # Apparently this used to be broken at some point:
69 #       http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
70 #
71 echo "unmounting read-only filesystem"
72 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
73
74 echo "setting device read-write"
75 blockdev --setrw $SCRATCH_DEV
76
77 echo "mounting read-write block device:"
78 _try_scratch_mount 2>&1 | _filter_scratch
79
80 echo "touch files"
81 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
82
83 echo "going down:"
84 _scratch_shutdown -f
85
86 echo "unmounting shutdown filesystem:"
87 _scratch_unmount 2>&1 | _filter_scratch
88
89 echo "setting device read-only"
90 blockdev --setro $SCRATCH_DEV
91
92 #
93 # Mounting a filesystem that requires log-recovery fails unless
94 # -o norecovery is used.
95 #
96 echo "mounting filesystem that needs recovery on a read-only device:"
97 _try_scratch_mount 2>&1 | _filter_ro_mount | _filter_scratch
98
99 echo "unmounting read-only filesystem"
100 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
101
102 #
103 # This is the way out if the underlying device really is read-only.
104 # Doesn't mean it's a good idea in practice, more a last resort
105 # data recovery hack.
106 #
107 echo "mounting filesystem with -o norecovery on a read-only device:"
108 _try_scratch_mount -o norecovery 2>&1 | _filter_ro_mount | _filter_scratch
109 echo "unmounting read-only filesystem"
110 _scratch_unmount 2>&1 | _filter_scratch | _filter_ending_dot
111
112 echo "setting device read-write"
113 blockdev --setrw $SCRATCH_DEV
114
115 #
116 # But log recovery is performed when mount with -o ro as long as
117 # the underlying device is not write protected.
118 #
119 echo "mounting filesystem that needs recovery with -o ro:"
120 _try_scratch_mount -o ro 2>&1 | _filter_scratch
121
122 # success, all done
123 echo "*** done"
124 rm -f $seqres.full
125 status=0