fsx: Replace use of bzero() with memset()
[xfstests-dev.git] / 200
1 #! /bin/sh
2 # FS QA Test No. 200
3 #
4 # Check out various mount/remount/unmount scenarious on a read-only blockdev.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2009 Christoph Hellwig.
8 #-----------------------------------------------------------------------
9 #
10 # creator
11 owner=hch@lst.de
12
13 seq=`basename $0`
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19
20 _filter_scratch()
21 {
22         sed -e "s,$SCRATCH_DEV,SCRATCH_DEV,g" | \
23                 sed -e "s,$SCRATCH_MNT,SCRATCH_MNT,g"
24 }
25
26 _cleanup()
27 {
28         cd /
29         blockdev --setrw $SCRATCH_DEV
30 }
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 # get standard environment, filters and checks
34 . ./common.rc
35 . ./common.filter
36
37 # real QA test starts here
38 _supported_fs xfs
39 _supported_os Linux
40
41 _require_scratch
42
43 _scratch_mkfs_xfs >/dev/null 2>&1
44
45 #
46 # Mark the device read-only
47 #
48 echo "setting device read-only"
49 blockdev --setro $SCRATCH_DEV
50
51 #
52 # Mount it, and make sure we can't write to it, and we can unmount it again
53 #
54 echo "mounting read-only block device:"
55 _scratch_mount 2>&1 | _filter_scratch
56
57 echo "touching file on read-only filesystem (should fail)"
58 touch $SCRATCH_MNT/foo 2>&1 | _filter_scratch
59
60 #
61 # Apparently this used to be broken at some point:
62 #       http://oss.sgi.com/bugzilla/show_bug.cgi?id=807
63 #
64 echo "unmounting read-only filesystem"
65 umount $SCRATCH_MNT 2>&1 | _filter_scratch
66
67 echo "setting device read-write"
68 blockdev --setrw $SCRATCH_DEV
69
70 echo "mounting read-write block device:"
71 _scratch_mount 2>&1 | _filter_scratch
72
73 echo "touch files"
74 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
75
76 echo "going down:"
77 src/godown -f $SCRATCH_MNT
78
79 echo "unmounting shutdown filesystem:"
80 umount $SCRATCH_MNT 2>&1 | _filter_scratch
81
82 echo "setting device read-only"
83 blockdev --setro $SCRATCH_DEV
84
85 #
86 # Mounting a filesystem that requires log-recovery fails unless
87 # -o norecovery is used.
88 #
89 echo "mounting filesystem that needs recovery on a read-only device:"
90 _scratch_mount 2>&1 | _filter_scratch
91
92 echo "unmounting read-only filesystem"
93 umount $SCRATCH_MNT 2>&1 | _filter_scratch
94
95 #
96 # This is the way out if the underlying device really is read-only.
97 # Doesn't mean it's a good idea in practive, more a last resort
98 # data recovery hack.
99 #
100 echo "mounting filesystem with -o norecovery on a read-only device:"
101 _scratch_mount -o norecovery 2>&1 | _filter_scratch
102
103 echo "unmounting read-only filesystem"
104 umount $SCRATCH_MNT 2>&1 | _filter_scratch
105
106 echo "setting device read-write"
107 blockdev --setrw $SCRATCH_DEV
108
109 #
110 # But log recovery is performed when mount with -o ro as long as
111 # the underlying device is not write protected.
112 #
113 echo "mounting filesystem that needs recovery with -o ro:"
114 _scratch_mount -o ro 2>&1 | _filter_scratch
115
116
117 # success, all done
118 echo "*** done"
119 rm -f $seq.full
120 status=0