xfstests: optionally run all tests under quota
[xfstests-dev.git] / 287
1 #! /bin/bash
2 # FS QA Test No. 285
3 #
4 # Test to verify project quota xfs_admin, xfsdump/xfsrestore and
5 # xfs_db functionality
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2012 Red Hat, Inc. All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25 # creator
26 owner=ranto.boris@gmail.com
27
28 seq=`basename $0`
29 echo "QA output created by $seq"
30 tmp=/tmp/$$
31 here=`pwd`
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34 rm -f $seq.full
35
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.quota
39
40 _cleanup()
41 {
42         cd /
43         umount $SCRATCH_MNT 2>/dev/null
44         rm -rf $tmp.*
45 }
46
47 _print_projid()
48 {
49         $XFS_DB_PROG -c "inode $1" \
50                 -c "print core.projid_lo" \
51                 -c "print core.projid_hi" \
52                 $SCRATCH_DEV
53 }
54
55 # real QA test starts here
56 _supported_fs xfs
57 _require_xfs_quota
58 _require_scratch
59 _require_projid32bit
60
61 # create xfs fs without projid32bit ability, will be gained by xfs_admin
62 _scratch_mkfs_xfs -i projid32bit=0 -d size=200m >> $seq.full \
63                 || _fail "mkfs failed"
64 _qmount_option "pquota"
65 _qmount
66 # require project quotas
67 _require_prjquota $SCRATCH_DEV
68
69 dir=$SCRATCH_MNT/pquota
70
71 status=1
72
73 mkdir -p $dir
74 touch $dir/{16,32}bit
75 inode16a=$(ls -i $dir/16bit | cut -d ' ' -f 1)
76 inode32a=$(ls -i $dir/32bit | cut -d ' ' -f 1)
77 $XFS_QUOTA_PROG -x -c "project -s -p $dir/16bit 1234" $SCRATCH_DEV \
78                 >> $seq.full
79 $XFS_QUOTA_PROG -x -c "project -s -p $dir/32bit 2123456789" $SCRATCH_DEV \
80                 >> $seq.full 2>&1
81
82 echo "No 32bit project quotas:"
83 $XFS_IO_PROG -r -c "lsproj" $dir/16bit
84 $XFS_IO_PROG -r -c "lsproj" $dir/32bit
85
86 umount $SCRATCH_MNT
87
88 # Now, enable projid32bit support by xfs_admin
89 xfs_admin -p $SCRATCH_DEV >> $seq.full 2>&1 || _fail "xfs_admin failed"
90
91 # Now mount the fs, 32bit project quotas shall be supported, now
92 _qmount_option "pquota"
93 _qmount
94 $XFS_QUOTA_PROG -x -c "project -s -p $dir/32bit 2123456789" $SCRATCH_DEV \
95                 >> $seq.full
96
97 # These will be checked by $seq.out
98 echo "With 32bit project quota support:"
99 $XFS_IO_PROG -r -c "lsproj" $dir/16bit
100 $XFS_IO_PROG -r -c "lsproj" $dir/32bit
101
102 # Dump the fs to a temporary file
103 rm -f $tmp.dump.img
104 $XFSDUMP_PROG -f $tmp.dump -L label -M media -l 0 $SCRATCH_MNT >> $seq.full \
105                 || _fail "dump failed"
106
107 # Prepare the device to restore the dumped file system
108 restore_dir=$SCRATCH_MNT/restore/pquota
109
110 # Just make the restore dir, the pquota dir will be created by xfsrestore
111 mkdir -p $SCRATCH_MNT/restore
112
113 # Restore
114 $XFSRESTORE_PROG -f $tmp.dump $SCRATCH_MNT/restore >> $seq.full 2>&1 \
115                 || _fail "xfsrestore failed"
116
117 # Check that they are the same
118 diff -urpN $SCRATCH_MNT/{,restore}/pquota || _fail "diff failed"
119
120 touch $restore_dir/32bitv2
121 inode16b=$(ls -i $restore_dir/16bit | cut -d ' ' -f 1)
122 inode32b=$(ls -i $restore_dir/32bit | cut -d ' ' -f 1)
123 inode32v2=$(ls -i $restore_dir/32bitv2 | cut -d ' ' -f 1)
124 $XFS_QUOTA_PROG -x -c "project -s -p $restore_dir/32bitv2 2123456789" \
125                 $SCRATCH_MNT >> $seq.full
126 echo "The restored file system + one additional file:"
127 $XFS_IO_PROG -r -c "lsproj" $restore_dir/16bit
128 $XFS_IO_PROG -r -c "lsproj" $restore_dir/32bit
129 $XFS_IO_PROG -r -c "lsproj" $restore_dir/32bitv2
130
131 umount $SCRATCH_MNT
132
133 # Now, we can examine the file systems with xfs_db
134 echo "These two values of 16bit project quota ids shall be the same"
135 _print_projid $inode16a
136 _print_projid $inode16b
137
138 echo "These three values of 32bit project quota ids shall be the same"
139 _print_projid $inode32b
140 _print_projid $inode32a
141 _print_projid $inode32v2
142
143 status=0
144 exit