aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/quota/xfs_qm.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/quota/xfs_qm.c')
-rw-r--r--fs/xfs/quota/xfs_qm.c187
1 files changed, 77 insertions, 110 deletions
diff --git a/fs/xfs/quota/xfs_qm.c b/fs/xfs/quota/xfs_qm.c
index efde16e0a913..1aea42d71a64 100644
--- a/fs/xfs/quota/xfs_qm.c
+++ b/fs/xfs/quota/xfs_qm.c
@@ -1,39 +1,25 @@
1/* 1/*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved. 2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or
5 * under the terms of version 2 of the GNU General Public License as 6 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
7 * 8 *
8 * This program is distributed in the hope that it would be useful, but 9 * This program is distributed in the hope that it would be useful,
9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
11 * 13 *
12 * Further, this software is distributed without any warranty that it is 14 * You should have received a copy of the GNU General Public License
13 * free of the rightful claim of any third person regarding infringement 15 * along with this program; if not, write the Free Software Foundation,
14 * or the like. Any license provided herein, whether implied or 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */ 17 */
32
33#include "xfs.h" 18#include "xfs.h"
34#include "xfs_fs.h" 19#include "xfs_fs.h"
35#include "xfs_inum.h" 20#include "xfs_bit.h"
36#include "xfs_log.h" 21#include "xfs_log.h"
22#include "xfs_inum.h"
37#include "xfs_clnt.h" 23#include "xfs_clnt.h"
38#include "xfs_trans.h" 24#include "xfs_trans.h"
39#include "xfs_sb.h" 25#include "xfs_sb.h"
@@ -44,21 +30,20 @@
44#include "xfs_dmapi.h" 30#include "xfs_dmapi.h"
45#include "xfs_quota.h" 31#include "xfs_quota.h"
46#include "xfs_mount.h" 32#include "xfs_mount.h"
47#include "xfs_alloc_btree.h"
48#include "xfs_bmap_btree.h" 33#include "xfs_bmap_btree.h"
34#include "xfs_alloc_btree.h"
49#include "xfs_ialloc_btree.h" 35#include "xfs_ialloc_btree.h"
50#include "xfs_btree.h"
51#include "xfs_ialloc.h"
52#include "xfs_attr_sf.h"
53#include "xfs_dir_sf.h" 36#include "xfs_dir_sf.h"
54#include "xfs_dir2_sf.h" 37#include "xfs_dir2_sf.h"
38#include "xfs_attr_sf.h"
55#include "xfs_dinode.h" 39#include "xfs_dinode.h"
56#include "xfs_inode.h" 40#include "xfs_inode.h"
57#include "xfs_bmap.h" 41#include "xfs_btree.h"
58#include "xfs_bit.h" 42#include "xfs_ialloc.h"
43#include "xfs_itable.h"
59#include "xfs_rtalloc.h" 44#include "xfs_rtalloc.h"
60#include "xfs_error.h" 45#include "xfs_error.h"
61#include "xfs_itable.h" 46#include "xfs_bmap.h"
62#include "xfs_rw.h" 47#include "xfs_rw.h"
63#include "xfs_acl.h" 48#include "xfs_acl.h"
64#include "xfs_cap.h" 49#include "xfs_cap.h"
@@ -67,7 +52,6 @@
67#include "xfs_buf_item.h" 52#include "xfs_buf_item.h"
68#include "xfs_trans_space.h" 53#include "xfs_trans_space.h"
69#include "xfs_utils.h" 54#include "xfs_utils.h"
70
71#include "xfs_qm.h" 55#include "xfs_qm.h"
72 56
73/* 57/*
@@ -76,8 +60,9 @@
76 * quota functionality, including maintaining the freelist and hash 60 * quota functionality, including maintaining the freelist and hash
77 * tables of dquots. 61 * tables of dquots.
78 */ 62 */
79mutex_t xfs_Gqm_lock; 63mutex_t xfs_Gqm_lock;
80struct xfs_qm *xfs_Gqm; 64struct xfs_qm *xfs_Gqm;
65uint ndquot;
81 66
82kmem_zone_t *qm_dqzone; 67kmem_zone_t *qm_dqzone;
83kmem_zone_t *qm_dqtrxzone; 68kmem_zone_t *qm_dqtrxzone;
@@ -107,10 +92,10 @@ extern mutex_t qcheck_lock;
107 for (dqp = (l)->qh_next; dqp != NULL; dqp = dqp->NXT) { \ 92 for (dqp = (l)->qh_next; dqp != NULL; dqp = dqp->NXT) { \
108 cmn_err(CE_DEBUG, " %d. \"%d (%s)\" " \ 93 cmn_err(CE_DEBUG, " %d. \"%d (%s)\" " \
109 "bcnt = %d, icnt = %d, refs = %d", \ 94 "bcnt = %d, icnt = %d, refs = %d", \
110 ++i, (int) INT_GET(dqp->q_core.d_id, ARCH_CONVERT), \ 95 ++i, (int) be32_to_cpu(dqp->q_core.d_id), \
111 DQFLAGTO_TYPESTR(dqp), \ 96 DQFLAGTO_TYPESTR(dqp), \
112 (int) INT_GET(dqp->q_core.d_bcount, ARCH_CONVERT), \ 97 (int) be64_to_cpu(dqp->q_core.d_bcount), \
113 (int) INT_GET(dqp->q_core.d_icount, ARCH_CONVERT), \ 98 (int) be64_to_cpu(dqp->q_core.d_icount), \
114 (int) dqp->q_nrefs); } \ 99 (int) dqp->q_nrefs); } \
115} 100}
116#else 101#else
@@ -124,25 +109,25 @@ extern mutex_t qcheck_lock;
124STATIC struct xfs_qm * 109STATIC struct xfs_qm *
125xfs_Gqm_init(void) 110xfs_Gqm_init(void)
126{ 111{
127 xfs_qm_t *xqm; 112 xfs_dqhash_t *udqhash, *gdqhash;
128 int hsize, i; 113 xfs_qm_t *xqm;
129 114 uint i, hsize, flags = KM_SLEEP | KM_MAYFAIL;
130 xqm = kmem_zalloc(sizeof(xfs_qm_t), KM_SLEEP);
131 ASSERT(xqm);
132 115
133 /* 116 /*
134 * Initialize the dquot hash tables. 117 * Initialize the dquot hash tables.
135 */ 118 */
136 hsize = (DQUOT_HASH_HEURISTIC < XFS_QM_NCSIZE_THRESHOLD) ? 119 hsize = XFS_QM_HASHSIZE_HIGH;
137 XFS_QM_HASHSIZE_LOW : XFS_QM_HASHSIZE_HIGH; 120 while (!(udqhash = kmem_zalloc(hsize * sizeof(xfs_dqhash_t), flags))) {
138 xqm->qm_dqhashmask = hsize - 1; 121 if ((hsize >>= 1) <= XFS_QM_HASHSIZE_LOW)
122 flags = KM_SLEEP;
123 }
124 gdqhash = kmem_zalloc(hsize * sizeof(xfs_dqhash_t), KM_SLEEP);
125 ndquot = hsize << 8;
139 126
140 xqm->qm_usr_dqhtable = (xfs_dqhash_t *)kmem_zalloc(hsize * 127 xqm = kmem_zalloc(sizeof(xfs_qm_t), KM_SLEEP);
141 sizeof(xfs_dqhash_t), 128 xqm->qm_dqhashmask = hsize - 1;
142 KM_SLEEP); 129 xqm->qm_usr_dqhtable = udqhash;
143 xqm->qm_grp_dqhtable = (xfs_dqhash_t *)kmem_zalloc(hsize * 130 xqm->qm_grp_dqhtable = gdqhash;
144 sizeof(xfs_dqhash_t),
145 KM_SLEEP);
146 ASSERT(xqm->qm_usr_dqhtable != NULL); 131 ASSERT(xqm->qm_usr_dqhtable != NULL);
147 ASSERT(xqm->qm_grp_dqhtable != NULL); 132 ASSERT(xqm->qm_grp_dqhtable != NULL);
148 133
@@ -743,7 +728,7 @@ xfs_qm_dqattach_one(
743 */ 728 */
744 if (udqhint && 729 if (udqhint &&
745 (dqp = udqhint->q_gdquot) && 730 (dqp = udqhint->q_gdquot) &&
746 (INT_GET(dqp->q_core.d_id, ARCH_CONVERT) == id)) { 731 (be32_to_cpu(dqp->q_core.d_id) == id)) {
747 ASSERT(XFS_DQ_IS_LOCKED(udqhint)); 732 ASSERT(XFS_DQ_IS_LOCKED(udqhint));
748 xfs_dqlock(dqp); 733 xfs_dqlock(dqp);
749 XFS_DQHOLD(dqp); 734 XFS_DQHOLD(dqp);
@@ -1213,42 +1198,24 @@ xfs_qm_init_quotainfo(
1213 * a user or group before he or she can not perform any 1198 * a user or group before he or she can not perform any
1214 * more writing. If it is zero, a default is used. 1199 * more writing. If it is zero, a default is used.
1215 */ 1200 */
1216 qinf->qi_btimelimit = 1201 qinf->qi_btimelimit = ddqp->d_btimer ?
1217 INT_GET(ddqp->d_btimer, ARCH_CONVERT) ? 1202 be32_to_cpu(ddqp->d_btimer) : XFS_QM_BTIMELIMIT;
1218 INT_GET(ddqp->d_btimer, ARCH_CONVERT) : 1203 qinf->qi_itimelimit = ddqp->d_itimer ?
1219 XFS_QM_BTIMELIMIT; 1204 be32_to_cpu(ddqp->d_itimer) : XFS_QM_ITIMELIMIT;
1220 qinf->qi_itimelimit = 1205 qinf->qi_rtbtimelimit = ddqp->d_rtbtimer ?
1221 INT_GET(ddqp->d_itimer, ARCH_CONVERT) ? 1206 be32_to_cpu(ddqp->d_rtbtimer) : XFS_QM_RTBTIMELIMIT;
1222 INT_GET(ddqp->d_itimer, ARCH_CONVERT) : 1207 qinf->qi_bwarnlimit = ddqp->d_bwarns ?
1223 XFS_QM_ITIMELIMIT; 1208 be16_to_cpu(ddqp->d_bwarns) : XFS_QM_BWARNLIMIT;
1224 qinf->qi_rtbtimelimit = 1209 qinf->qi_iwarnlimit = ddqp->d_iwarns ?
1225 INT_GET(ddqp->d_rtbtimer, ARCH_CONVERT) ? 1210 be16_to_cpu(ddqp->d_iwarns) : XFS_QM_IWARNLIMIT;
1226 INT_GET(ddqp->d_rtbtimer, ARCH_CONVERT) : 1211 qinf->qi_rtbwarnlimit = ddqp->d_rtbwarns ?
1227 XFS_QM_RTBTIMELIMIT; 1212 be16_to_cpu(ddqp->d_rtbwarns) : XFS_QM_RTBWARNLIMIT;
1228 qinf->qi_bwarnlimit = 1213 qinf->qi_bhardlimit = be64_to_cpu(ddqp->d_blk_hardlimit);
1229 INT_GET(ddqp->d_bwarns, ARCH_CONVERT) ? 1214 qinf->qi_bsoftlimit = be64_to_cpu(ddqp->d_blk_softlimit);
1230 INT_GET(ddqp->d_bwarns, ARCH_CONVERT) : 1215 qinf->qi_ihardlimit = be64_to_cpu(ddqp->d_ino_hardlimit);
1231 XFS_QM_BWARNLIMIT; 1216 qinf->qi_isoftlimit = be64_to_cpu(ddqp->d_ino_softlimit);
1232 qinf->qi_iwarnlimit = 1217 qinf->qi_rtbhardlimit = be64_to_cpu(ddqp->d_rtb_hardlimit);
1233 INT_GET(ddqp->d_iwarns, ARCH_CONVERT) ? 1218 qinf->qi_rtbsoftlimit = be64_to_cpu(ddqp->d_rtb_softlimit);
1234 INT_GET(ddqp->d_iwarns, ARCH_CONVERT) :
1235 XFS_QM_IWARNLIMIT;
1236 qinf->qi_rtbwarnlimit =
1237 INT_GET(ddqp->d_rtbwarns, ARCH_CONVERT) ?
1238 INT_GET(ddqp->d_rtbwarns, ARCH_CONVERT) :
1239 XFS_QM_RTBWARNLIMIT;
1240 qinf->qi_bhardlimit =
1241 INT_GET(ddqp->d_blk_hardlimit, ARCH_CONVERT);
1242 qinf->qi_bsoftlimit =
1243 INT_GET(ddqp->d_blk_softlimit, ARCH_CONVERT);
1244 qinf->qi_ihardlimit =
1245 INT_GET(ddqp->d_ino_hardlimit, ARCH_CONVERT);
1246 qinf->qi_isoftlimit =
1247 INT_GET(ddqp->d_ino_softlimit, ARCH_CONVERT);
1248 qinf->qi_rtbhardlimit =
1249 INT_GET(ddqp->d_rtb_hardlimit, ARCH_CONVERT);
1250 qinf->qi_rtbsoftlimit =
1251 INT_GET(ddqp->d_rtb_softlimit, ARCH_CONVERT);
1252 1219
1253 /* 1220 /*
1254 * We sent the XFS_QMOPT_DQSUSER flag to dqget because 1221 * We sent the XFS_QMOPT_DQSUSER flag to dqget because
@@ -1527,15 +1494,15 @@ xfs_qm_reset_dqcounts(
1527 */ 1494 */
1528 (void) xfs_qm_dqcheck(ddq, id+j, type, XFS_QMOPT_DQREPAIR, 1495 (void) xfs_qm_dqcheck(ddq, id+j, type, XFS_QMOPT_DQREPAIR,
1529 "xfs_quotacheck"); 1496 "xfs_quotacheck");
1530 INT_SET(ddq->d_bcount, ARCH_CONVERT, 0ULL); 1497 ddq->d_bcount = 0;
1531 INT_SET(ddq->d_icount, ARCH_CONVERT, 0ULL); 1498 ddq->d_icount = 0;
1532 INT_SET(ddq->d_rtbcount, ARCH_CONVERT, 0ULL); 1499 ddq->d_rtbcount = 0;
1533 INT_SET(ddq->d_btimer, ARCH_CONVERT, (time_t)0); 1500 ddq->d_btimer = 0;
1534 INT_SET(ddq->d_itimer, ARCH_CONVERT, (time_t)0); 1501 ddq->d_itimer = 0;
1535 INT_SET(ddq->d_rtbtimer, ARCH_CONVERT, (time_t)0); 1502 ddq->d_rtbtimer = 0;
1536 INT_SET(ddq->d_bwarns, ARCH_CONVERT, 0UL); 1503 ddq->d_bwarns = 0;
1537 INT_SET(ddq->d_iwarns, ARCH_CONVERT, 0UL); 1504 ddq->d_iwarns = 0;
1538 INT_SET(ddq->d_rtbwarns, ARCH_CONVERT, 0UL); 1505 ddq->d_rtbwarns = 0;
1539 ddq = (xfs_disk_dquot_t *) ((xfs_dqblk_t *)ddq + 1); 1506 ddq = (xfs_disk_dquot_t *) ((xfs_dqblk_t *)ddq + 1);
1540 } 1507 }
1541 1508
@@ -1708,14 +1675,14 @@ xfs_qm_quotacheck_dqadjust(
1708 * Adjust the inode count and the block count to reflect this inode's 1675 * Adjust the inode count and the block count to reflect this inode's
1709 * resource usage. 1676 * resource usage.
1710 */ 1677 */
1711 INT_MOD(dqp->q_core.d_icount, ARCH_CONVERT, +1); 1678 be64_add(&dqp->q_core.d_icount, 1);
1712 dqp->q_res_icount++; 1679 dqp->q_res_icount++;
1713 if (nblks) { 1680 if (nblks) {
1714 INT_MOD(dqp->q_core.d_bcount, ARCH_CONVERT, nblks); 1681 be64_add(&dqp->q_core.d_bcount, nblks);
1715 dqp->q_res_bcount += nblks; 1682 dqp->q_res_bcount += nblks;
1716 } 1683 }
1717 if (rtblks) { 1684 if (rtblks) {
1718 INT_MOD(dqp->q_core.d_rtbcount, ARCH_CONVERT, rtblks); 1685 be64_add(&dqp->q_core.d_rtbcount, rtblks);
1719 dqp->q_res_rtbcount += rtblks; 1686 dqp->q_res_rtbcount += rtblks;
1720 } 1687 }
1721 1688
@@ -2202,7 +2169,7 @@ xfs_qm_shake_freelist(
2202 xfs_dqtrace_entry(dqp, "DQSHAKE: UNLINKING"); 2169 xfs_dqtrace_entry(dqp, "DQSHAKE: UNLINKING");
2203#ifdef QUOTADEBUG 2170#ifdef QUOTADEBUG
2204 cmn_err(CE_DEBUG, "Shake 0x%p, ID 0x%x\n", 2171 cmn_err(CE_DEBUG, "Shake 0x%p, ID 0x%x\n",
2205 dqp, INT_GET(dqp->q_core.d_id, ARCH_CONVERT)); 2172 dqp, be32_to_cpu(dqp->q_core.d_id));
2206#endif 2173#endif
2207 ASSERT(dqp->q_nrefs == 0); 2174 ASSERT(dqp->q_nrefs == 0);
2208 nextdqp = dqp->dq_flnext; 2175 nextdqp = dqp->dq_flnext;
@@ -2670,7 +2637,7 @@ xfs_qm_vop_chown_reserve(
2670 XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS; 2637 XFS_QMOPT_RES_RTBLKS : XFS_QMOPT_RES_REGBLKS;
2671 2638
2672 if (XFS_IS_UQUOTA_ON(mp) && udqp && 2639 if (XFS_IS_UQUOTA_ON(mp) && udqp &&
2673 ip->i_d.di_uid != (uid_t)INT_GET(udqp->q_core.d_id, ARCH_CONVERT)) { 2640 ip->i_d.di_uid != (uid_t)be32_to_cpu(udqp->q_core.d_id)) {
2674 delblksudq = udqp; 2641 delblksudq = udqp;
2675 /* 2642 /*
2676 * If there are delayed allocation blocks, then we have to 2643 * If there are delayed allocation blocks, then we have to
@@ -2683,10 +2650,10 @@ xfs_qm_vop_chown_reserve(
2683 } 2650 }
2684 } 2651 }
2685 if (XFS_IS_OQUOTA_ON(ip->i_mount) && gdqp) { 2652 if (XFS_IS_OQUOTA_ON(ip->i_mount) && gdqp) {
2686 if ((XFS_IS_GQUOTA_ON(ip->i_mount) && ip->i_d.di_gid != 2653 if ((XFS_IS_GQUOTA_ON(ip->i_mount) &&
2687 INT_GET(gdqp->q_core.d_id, ARCH_CONVERT)) || 2654 ip->i_d.di_gid != be32_to_cpu(gdqp->q_core.d_id)) ||
2688 (XFS_IS_PQUOTA_ON(ip->i_mount) && ip->i_d.di_projid != 2655 (XFS_IS_PQUOTA_ON(ip->i_mount) &&
2689 INT_GET(gdqp->q_core.d_id, ARCH_CONVERT))) { 2656 ip->i_d.di_projid != be32_to_cpu(gdqp->q_core.d_id))) {
2690 delblksgdq = gdqp; 2657 delblksgdq = gdqp;
2691 if (delblks) { 2658 if (delblks) {
2692 ASSERT(ip->i_gdquot); 2659 ASSERT(ip->i_gdquot);
@@ -2776,7 +2743,7 @@ xfs_qm_vop_dqattach_and_dqmod_newinode(
2776 xfs_dqunlock(udqp); 2743 xfs_dqunlock(udqp);
2777 ASSERT(ip->i_udquot == NULL); 2744 ASSERT(ip->i_udquot == NULL);
2778 ip->i_udquot = udqp; 2745 ip->i_udquot = udqp;
2779 ASSERT(ip->i_d.di_uid == INT_GET(udqp->q_core.d_id, ARCH_CONVERT)); 2746 ASSERT(ip->i_d.di_uid == be32_to_cpu(udqp->q_core.d_id));
2780 xfs_trans_mod_dquot(tp, udqp, XFS_TRANS_DQ_ICOUNT, 1); 2747 xfs_trans_mod_dquot(tp, udqp, XFS_TRANS_DQ_ICOUNT, 1);
2781 } 2748 }
2782 if (gdqp) { 2749 if (gdqp) {
@@ -2785,7 +2752,7 @@ xfs_qm_vop_dqattach_and_dqmod_newinode(
2785 xfs_dqunlock(gdqp); 2752 xfs_dqunlock(gdqp);
2786 ASSERT(ip->i_gdquot == NULL); 2753 ASSERT(ip->i_gdquot == NULL);
2787 ip->i_gdquot = gdqp; 2754 ip->i_gdquot = gdqp;
2788 ASSERT(ip->i_d.di_gid == INT_GET(gdqp->q_core.d_id, ARCH_CONVERT)); 2755 ASSERT(ip->i_d.di_gid == be32_to_cpu(gdqp->q_core.d_id));
2789 xfs_trans_mod_dquot(tp, gdqp, XFS_TRANS_DQ_ICOUNT, 1); 2756 xfs_trans_mod_dquot(tp, gdqp, XFS_TRANS_DQ_ICOUNT, 1);
2790 } 2757 }
2791} 2758}