common: Check the file system consistency on SCRATCH_DEV
[xfstests-dev.git] / tests / shared / 272
1 #! /bin/bash
2 # FSQA Test No. 272
3 #
4 # Test data journaling flag switch for a single file  
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2006 Silicon Graphics, 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
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
33
34 # ext3 doesn't support direct IO in journalling mode
35 write_opt_list="iflag=noatime conv=notrunc conv=fsync"
36 # For filesystems that can handle it, add also direct IO test
37 [ $FSTYP = "ext4" ] && write_opt_list="$write_opt_list oflag=direct"
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42 _workout()
43 {
44         echo "Switch data journalling mode. Silence is golden."
45         chattr_opt_list="+j -j +jS -j"
46         idx=0
47         #
48         for write_opt in $write_opt_list
49         do
50                 idx=$((idx + 1))
51                 for chattr_opt in $chattr_opt_list
52                 do
53                     
54                         echo "OP write_opt: $write_opt 4M, \
55 chattr_opt: $chattr_opt" >>$seqres.full
56                         dd if=/dev/zero of=$SCRATCH_MNT/file.$idx \
57                                 bs=1M count=4 $write_opt \
58                                 >> $seqres.full 2>&1 || exit
59                         chattr $chattr_opt $SCRATCH_MNT/file.$idx >> $seqres.full \
60                                 || exit
61                 done
62         done
63         sync
64         # Same as previous test, but for one file,
65         # and with ENOSPC triggering
66         for write_opt in $write_opt_list
67         do
68                 idx=$((idx + 1))
69                 for chattr_opt in $chattr_opt_list
70                 do
71
72                         echo "OP write_opt: $write_opt ENOSPC, \
73 chattr_opt: $chattr_opt" >>$seqres.full
74                         dd if=/dev/zero of=$SCRATCH_MNT/file.$idx \
75                                 bs=1M $write_opt >> $seqres.full 2>&1
76                         chattr $chattr_opt $SCRATCH_MNT/file.$idx \
77                                 >> $seqres.full || exit
78                 done
79                 sync
80                 unlink $SCRATCH_MNT/file.$idx
81         done
82 }
83
84 # real QA test starts here
85 _supported_fs ext3 ext4
86 _supported_os Linux
87 _need_to_be_root
88 _require_scratch
89
90 _scratch_mkfs_sized $((64 * 1024 * 1024)) >> $seqres.full 2>&1
91 _scratch_mount
92
93 if ! _workout; then
94         echo "workout failed"
95         _scratch_unmount
96         status=1
97         exit
98 fi
99
100 if ! _scratch_unmount; then
101         echo "failed to umount"
102         status=1
103         exit
104 fi
105 echo "Check filesystem"
106 status=0
107 exit