xfstests: include test subdirectory support
[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
26 seq=`basename $0`
27 echo "QA output created by $seq"
28 tmp=/tmp/$$
29 here=`pwd`
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32 rm -f $seq.full
33
34 # get standard environment, filters and checks
35 . ./common.rc
36 . ./common.quota
37
38 _cleanup()
39 {
40         cd /
41         umount $SCRATCH_MNT 2>/dev/null
42         rm -rf $tmp.*
43 }
44
45 _print_projid()
46 {
47         $XFS_DB_PROG -c "inode $1" \
48                 -c "print core.projid_lo" \
49                 -c "print core.projid_hi" \
50                 $SCRATCH_DEV
51 }
52
53 # real QA test starts here
54 _supported_fs xfs
55 _require_xfs_quota
56 _require_scratch
57 _require_projid32bit
58
59 # create xfs fs without projid32bit ability, will be gained by xfs_admin
60 _scratch_mkfs_xfs -i projid32bit=0 -d size=200m >> $seq.full \
61                 || _fail "mkfs failed"
62 _qmount_option "pquota"
63 _qmount
64 # require project quotas
65 _require_prjquota $SCRATCH_DEV
66
67 dir=$SCRATCH_MNT/pquota
68
69 status=1
70
71 mkdir -p $dir
72 touch $dir/{16,32}bit
73 inode16a=$(ls -i $dir/16bit | cut -d ' ' -f 1)
74 inode32a=$(ls -i $dir/32bit | cut -d ' ' -f 1)
75 $XFS_QUOTA_PROG -x -c "project -s -p $dir/16bit 1234" $SCRATCH_DEV \
76                 >> $seq.full
77 $XFS_QUOTA_PROG -x -c "project -s -p $dir/32bit 2123456789" $SCRATCH_DEV \
78                 >> $seq.full 2>&1
79
80 echo "No 32bit project quotas:"
81 $XFS_IO_PROG -r -c "lsproj" $dir/16bit
82 $XFS_IO_PROG -r -c "lsproj" $dir/32bit
83
84 umount $SCRATCH_MNT
85
86 # Now, enable projid32bit support by xfs_admin
87 xfs_admin -p $SCRATCH_DEV >> $seq.full 2>&1 || _fail "xfs_admin failed"
88
89 # Now mount the fs, 32bit project quotas shall be supported, now
90 _qmount_option "pquota"
91 _qmount
92 $XFS_QUOTA_PROG -x -c "project -s -p $dir/32bit 2123456789" $SCRATCH_DEV \
93                 >> $seq.full
94
95 # These will be checked by $seq.out
96 echo "With 32bit project quota support:"
97 $XFS_IO_PROG -r -c "lsproj" $dir/16bit
98 $XFS_IO_PROG -r -c "lsproj" $dir/32bit
99
100 # Dump the fs to a temporary file
101 rm -f $tmp.dump.img
102 $XFSDUMP_PROG -f $tmp.dump -L label -M media -l 0 $SCRATCH_MNT >> $seq.full \
103                 || _fail "dump failed"
104
105 # Prepare the device to restore the dumped file system
106 restore_dir=$SCRATCH_MNT/restore/pquota
107
108 # Just make the restore dir, the pquota dir will be created by xfsrestore
109 mkdir -p $SCRATCH_MNT/restore
110
111 # Restore
112 $XFSRESTORE_PROG -f $tmp.dump $SCRATCH_MNT/restore >> $seq.full 2>&1 \
113                 || _fail "xfsrestore failed"
114
115 # Check that they are the same
116 diff -urpN $SCRATCH_MNT/{,restore}/pquota || _fail "diff failed"
117
118 touch $restore_dir/32bitv2
119 inode16b=$(ls -i $restore_dir/16bit | cut -d ' ' -f 1)
120 inode32b=$(ls -i $restore_dir/32bit | cut -d ' ' -f 1)
121 inode32v2=$(ls -i $restore_dir/32bitv2 | cut -d ' ' -f 1)
122 $XFS_QUOTA_PROG -x -c "project -s -p $restore_dir/32bitv2 2123456789" \
123                 $SCRATCH_MNT >> $seq.full
124 echo "The restored file system + one additional file:"
125 $XFS_IO_PROG -r -c "lsproj" $restore_dir/16bit
126 $XFS_IO_PROG -r -c "lsproj" $restore_dir/32bit
127 $XFS_IO_PROG -r -c "lsproj" $restore_dir/32bitv2
128
129 umount $SCRATCH_MNT
130
131 # Now, we can examine the file systems with xfs_db
132 echo "These two values of 16bit project quota ids shall be the same"
133 _print_projid $inode16a
134 _print_projid $inode16b
135
136 echo "These three values of 32bit project quota ids shall be the same"
137 _print_projid $inode32b
138 _print_projid $inode32a
139 _print_projid $inode32v2
140
141 status=0
142 exit