Blame view

fs/xfs/xfs_qm_bhv.c 4.76 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
932f2c323   Nathan Scott   [XFS] statvfs com...
2
   * Copyright (c) 2000-2006 Silicon Graphics, Inc.
4ce3121f6   Nathan Scott   [XFS] Update lice...
3
   * All Rights Reserved.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
   *
4ce3121f6   Nathan Scott   [XFS] Update lice...
5
6
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
   * published by the Free Software Foundation.
   *
4ce3121f6   Nathan Scott   [XFS] Update lice...
9
10
11
12
   * This program is distributed in the hope that it would be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
   *
4ce3121f6   Nathan Scott   [XFS] Update lice...
14
15
16
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write the Free Software Foundation,
   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
19
  #include "xfs.h"
  #include "xfs_fs.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
20
  #include "xfs_bit.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  #include "xfs_log.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
22
  #include "xfs_inum.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
  #include "xfs_trans.h"
  #include "xfs_sb.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
25
  #include "xfs_ag.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
  #include "xfs_alloc.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
28
  #include "xfs_quota.h"
  #include "xfs_mount.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
  #include "xfs_bmap_btree.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  #include "xfs_inode.h"
a844f4510   Nathan Scott   [XFS] Remove xfs_...
31
  #include "xfs_itable.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
  #include "xfs_bmap.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
34
  #include "xfs_rtalloc.h"
  #include "xfs_error.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
  #include "xfs_attr.h"
  #include "xfs_buf_item.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
  #include "xfs_qm.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38

b09cc7710   Christoph Hellwig   [XFS] remove depe...
39
40
  STATIC void
  xfs_fill_statvfs_from_dquot(
00dd4029e   Christoph Hellwig   [XFS] remove bhv_...
41
  	struct kstatfs		*statp,
b09cc7710   Christoph Hellwig   [XFS] remove depe...
42
  	xfs_disk_dquot_t	*dp)
932f2c323   Nathan Scott   [XFS] statvfs com...
43
  {
932f2c323   Nathan Scott   [XFS] statvfs com...
44
  	__uint64_t		limit;
932f2c323   Nathan Scott   [XFS] statvfs com...
45

2a293b7d5   Christoph Hellwig   [XFS] All xfs_dis...
46
47
48
  	limit = dp->d_blk_softlimit ?
  		be64_to_cpu(dp->d_blk_softlimit) :
  		be64_to_cpu(dp->d_blk_hardlimit);
932f2c323   Nathan Scott   [XFS] statvfs com...
49
50
  	if (limit && statp->f_blocks > limit) {
  		statp->f_blocks = limit;
9b00f3076   Christoph Hellwig   xfs: quota limit ...
51
  		statp->f_bfree = statp->f_bavail =
2a293b7d5   Christoph Hellwig   [XFS] All xfs_dis...
52
53
  			(statp->f_blocks > be64_to_cpu(dp->d_bcount)) ?
  			 (statp->f_blocks - be64_to_cpu(dp->d_bcount)) : 0;
932f2c323   Nathan Scott   [XFS] statvfs com...
54
  	}
2a293b7d5   Christoph Hellwig   [XFS] All xfs_dis...
55
56
57
58
  
  	limit = dp->d_ino_softlimit ?
  		be64_to_cpu(dp->d_ino_softlimit) :
  		be64_to_cpu(dp->d_ino_hardlimit);
932f2c323   Nathan Scott   [XFS] statvfs com...
59
60
  	if (limit && statp->f_files > limit) {
  		statp->f_files = limit;
2a293b7d5   Christoph Hellwig   [XFS] All xfs_dis...
61
62
63
  		statp->f_ffree =
  			(statp->f_files > be64_to_cpu(dp->d_icount)) ?
  			 (statp->f_ffree - be64_to_cpu(dp->d_icount)) : 0;
932f2c323   Nathan Scott   [XFS] statvfs com...
64
  	}
932f2c323   Nathan Scott   [XFS] statvfs com...
65
  }
b09cc7710   Christoph Hellwig   [XFS] remove depe...
66
67
68
69
70
71
72
73
  
  /*
   * Directory tree accounting is implemented using project quotas, where
   * the project identifier is inherited from parent directories.
   * A statvfs (df, etc.) of a directory that is using project quota should
   * return a statvfs of the project, not the entire filesystem.
   * This makes such trees appear as if they are filesystems in themselves.
   */
7d095257e   Christoph Hellwig   xfs: kill xfs_qmops
74
  void
b09cc7710   Christoph Hellwig   [XFS] remove depe...
75
76
  xfs_qm_statvfs(
  	xfs_inode_t		*ip,
00dd4029e   Christoph Hellwig   [XFS] remove bhv_...
77
  	struct kstatfs		*statp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
  {
b09cc7710   Christoph Hellwig   [XFS] remove depe...
79
80
  	xfs_mount_t		*mp = ip->i_mount;
  	xfs_dquot_t		*dqp;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81

6743099ce   Arkadiusz Mi?kiewicz   xfs: Extend proje...
82
  	if (!xfs_qm_dqget(mp, NULL, xfs_get_projid(ip), XFS_DQ_PROJ, 0, &dqp)) {
7d095257e   Christoph Hellwig   xfs: kill xfs_qmops
83
  		xfs_fill_statvfs_from_dquot(statp, &dqp->q_core);
b09cc7710   Christoph Hellwig   [XFS] remove depe...
84
  		xfs_qm_dqput(dqp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
  }
7d095257e   Christoph Hellwig   xfs: kill xfs_qmops
87
  int
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
89
90
91
92
93
  xfs_qm_newmount(
  	xfs_mount_t	*mp,
  	uint		*needquotamount,
  	uint		*quotaflags)
  {
  	uint		quotaondisk;
c8ad20ffe   Nathan Scott   [XFS] Add support...
94
  	uint		uquotaondisk = 0, gquotaondisk = 0, pquotaondisk = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95

621187099   Eric Sandeen   [XFS] remove shou...
96
  	quotaondisk = xfs_sb_version_hasquota(&mp->m_sb) &&
c8ad20ffe   Nathan Scott   [XFS] Add support...
97
  				(mp->m_sb.sb_qflags & XFS_ALL_QUOTA_ACCT);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
99
100
  
  	if (quotaondisk) {
  		uquotaondisk = mp->m_sb.sb_qflags & XFS_UQUOTA_ACCT;
c8ad20ffe   Nathan Scott   [XFS] Add support...
101
  		pquotaondisk = mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
102
103
104
105
106
107
108
109
110
111
112
113
  		gquotaondisk = mp->m_sb.sb_qflags & XFS_GQUOTA_ACCT;
  	}
  
  	/*
  	 * If the device itself is read-only, we can't allow
  	 * the user to change the state of quota on the mount -
  	 * this would generate a transaction on the ro device,
  	 * which would lead to an I/O error and shutdown
  	 */
  
  	if (((uquotaondisk && !XFS_IS_UQUOTA_ON(mp)) ||
  	    (!uquotaondisk &&  XFS_IS_UQUOTA_ON(mp)) ||
c8ad20ffe   Nathan Scott   [XFS] Add support...
114
115
  	     (pquotaondisk && !XFS_IS_PQUOTA_ON(mp)) ||
  	    (!pquotaondisk &&  XFS_IS_PQUOTA_ON(mp)) ||
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
116
  	     (gquotaondisk && !XFS_IS_GQUOTA_ON(mp)) ||
c8ad20ffe   Nathan Scott   [XFS] Add support...
117
  	    (!gquotaondisk &&  XFS_IS_OQUOTA_ON(mp)))  &&
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
  	    xfs_dev_is_read_only(mp, "changing quota state")) {
0b932cccb   Dave Chinner   xfs: Convert rema...
119
  		xfs_warn(mp, "please mount with%s%s%s%s.",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120
121
  			(!quotaondisk ? "out quota" : ""),
  			(uquotaondisk ? " usrquota" : ""),
c8ad20ffe   Nathan Scott   [XFS] Add support...
122
  			(pquotaondisk ? " prjquota" : ""),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
124
125
126
127
128
129
130
131
132
133
  			(gquotaondisk ? " grpquota" : ""));
  		return XFS_ERROR(EPERM);
  	}
  
  	if (XFS_IS_QUOTA_ON(mp) || quotaondisk) {
  		/*
  		 * Call mount_quotas at this point only if we won't have to do
  		 * a quotacheck.
  		 */
  		if (quotaondisk && !XFS_QM_NEED_QUOTACHECK(mp)) {
  			/*
25985edce   Lucas De Marchi   Fix common misspe...
134
  			 * If an error occurred, qm_mount_quotas code
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135
136
137
138
  			 * has already disabled quotas. So, just finish
  			 * mounting, and get on with the boring life
  			 * without disk quotas.
  			 */
4249023a5   Christoph Hellwig   [XFS] cleanup xfs...
139
  			xfs_qm_mount_quotas(mp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  		} else {
  			/*
  			 * Clear the quota flags, but remember them. This
  			 * is so that the quota code doesn't get invoked
  			 * before we're ready. This can happen when an
  			 * inode goes inactive and wants to free blocks,
  			 * or via xfs_log_mount_finish.
  			 */
  			*needquotamount = B_TRUE;
  			*quotaflags = mp->m_qflags;
  			mp->m_qflags = 0;
  		}
  	}
  
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
156
157
158
  void __init
  xfs_qm_init(void)
  {
b09cc7710   Christoph Hellwig   [XFS] remove depe...
159
160
  	printk(KERN_INFO "SGI XFS Quota Management subsystem
  ");
794ee1bae   Jes Sorensen   [PATCH] mutex sub...
161
  	mutex_init(&xfs_Gqm_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
163
164
165
166
167
  	xfs_qm_init_procfs();
  }
  
  void __exit
  xfs_qm_exit(void)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
168
169
  	xfs_qm_cleanup_procfs();
  	if (qm_dqzone)
3758dee9f   Nathan Scott   [XFS] Fixup namin...
170
  		kmem_zone_destroy(qm_dqzone);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171
  	if (qm_dqtrxzone)
3758dee9f   Nathan Scott   [XFS] Fixup namin...
172
  		kmem_zone_destroy(qm_dqtrxzone);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
173
  }