4f864100fde32da2e72985830faf146a96fcdac1
[xfstests-dev.git] / tests / xfs / 007
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. xfs/007
6 #
7 # Test to verify Q_XQUOTARM functionality.
8 #
9 . ./common/preamble
10 _begin_fstest auto quota quick
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/quota
15
16 # Modify as appropriate.
17 _supported_fs xfs
18
19 _require_scratch
20 _require_xfs_quota
21
22 _scratch_mkfs_xfs | _filter_mkfs > /dev/null 2> $tmp.mkfs
23 . $tmp.mkfs
24
25 do_test()
26 {
27         qino_1=$1
28         qino_2=$2
29         off_opts=$3
30
31         echo "*** umount"
32         _scratch_unmount
33
34         QINO_1=`_scratch_xfs_get_sb_field $qino_1`
35         QINO_2=`_scratch_xfs_get_sb_field $qino_2`
36
37         echo "*** Usage before quotarm ***"
38         _scratch_xfs_db -c "inode $QINO_1" -c "p core.nblocks"
39         _scratch_xfs_db -c "inode $QINO_2" -c "p core.nblocks"
40
41         _qmount
42         echo "*** turn off $off_opts quotas"
43         $XFS_QUOTA_PROG -x -c "off -$off_opts" $SCRATCH_MNT
44
45         # Remount the filesystem with no quota options to force quotas off.
46         # This takes care of newer kernels where quotaoff clears the superblock
47         # quota enforcement flags but doesn't shut down accounting.
48         _scratch_unmount
49         _qmount_option ""
50         _scratch_mount
51
52         rm_commands=(-x -c "remove -$off_opts")
53
54         # Remounting a V4 fs with no quota options means that the internal
55         # gquotino -> pquotino remapping does not happen.  If we want to
56         # truncate the "project" quota file we must run remove -g.  However,
57         # xfs_quota has a nasty sharp edge wherein passing '-g' and '-p' only
58         # results in a QUOTARM call for the group quota file, so we must make
59         # a separate remove call.
60         [ $_fs_has_crcs == 0 ] && [ "$off_opts" = "up" ] && \
61                 rm_commands+=(-c "remove -g")
62
63         $XFS_QUOTA_PROG "${rm_commands[@]}" $SCRATCH_MNT
64
65         echo "*** umount"
66         _scratch_unmount
67
68         echo "*** Usage after quotarm ***"
69         _scratch_xfs_db -c "inode $QINO_1" -c "p core.nblocks"
70         _scratch_xfs_db -c "inode $QINO_2" -c "p core.nblocks"
71 }
72
73 # Test user and group first
74 _qmount_option "uquota,gquota"
75 _qmount
76 do_test uquotino gquotino ug
77
78 # Test user and project. Note that pquotino only exists on v5 (crc=1)
79 # superblocks. Older supers reuse gquotino.
80 PQUOTINO=pquotino
81 if [ $_fs_has_crcs == 0 ]; then
82         PQUOTINO=gquotino
83 fi
84 _qmount_option "uquota,pquota"
85 _qmount
86 _require_prjquota $SCRATCH_DEV
87 do_test uquotino $PQUOTINO up
88
89 # success, all done
90 status=0
91 exit