Merge branch 'devicetree/merge' of git://git.secretlab.ca/git/linux-2.6
[linux-2.6-block.git] / fs / xfs / xfs_quotaops.c
CommitLineData
fcafb71b
CH
1/*
2 * Copyright (c) 2008, Christoph Hellwig
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18#include "xfs.h"
fcafb71b
CH
19#include "xfs_sb.h"
20#include "xfs_inum.h"
ed3b4d6c 21#include "xfs_log.h"
fcafb71b
CH
22#include "xfs_ag.h"
23#include "xfs_mount.h"
24#include "xfs_quota.h"
fcafb71b
CH
25#include "xfs_trans.h"
26#include "xfs_bmap_btree.h"
27#include "xfs_inode.h"
06f8e2d6 28#include "xfs_qm.h"
fcafb71b
CH
29#include <linux/quota.h>
30
31
32STATIC int
33xfs_quota_type(int type)
34{
35 switch (type) {
36 case USRQUOTA:
37 return XFS_DQ_USER;
38 case GRPQUOTA:
39 return XFS_DQ_GROUP;
40 default:
41 return XFS_DQ_PROJ;
42 }
43}
44
fcafb71b
CH
45STATIC int
46xfs_fs_get_xstate(
47 struct super_block *sb,
48 struct fs_quota_stat *fqs)
49{
50 struct xfs_mount *mp = XFS_M(sb);
51
52 if (!XFS_IS_QUOTA_RUNNING(mp))
53 return -ENOSYS;
54 return -xfs_qm_scall_getqstat(mp, fqs);
55}
56
57STATIC int
58xfs_fs_set_xstate(
59 struct super_block *sb,
60 unsigned int uflags,
61 int op)
62{
63 struct xfs_mount *mp = XFS_M(sb);
64 unsigned int flags = 0;
65
66 if (sb->s_flags & MS_RDONLY)
67 return -EROFS;
c7ff91d7 68 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
fcafb71b 69 return -ENOSYS;
fcafb71b 70
ade7ce31 71 if (uflags & FS_QUOTA_UDQ_ACCT)
fcafb71b 72 flags |= XFS_UQUOTA_ACCT;
ade7ce31 73 if (uflags & FS_QUOTA_PDQ_ACCT)
fcafb71b 74 flags |= XFS_PQUOTA_ACCT;
ade7ce31 75 if (uflags & FS_QUOTA_GDQ_ACCT)
fcafb71b 76 flags |= XFS_GQUOTA_ACCT;
ade7ce31 77 if (uflags & FS_QUOTA_UDQ_ENFD)
fcafb71b 78 flags |= XFS_UQUOTA_ENFD;
ade7ce31 79 if (uflags & (FS_QUOTA_PDQ_ENFD|FS_QUOTA_GDQ_ENFD))
fcafb71b
CH
80 flags |= XFS_OQUOTA_ENFD;
81
82 switch (op) {
83 case Q_XQUOTAON:
84 return -xfs_qm_scall_quotaon(mp, flags);
85 case Q_XQUOTAOFF:
86 if (!XFS_IS_QUOTA_ON(mp))
87 return -EINVAL;
88 return -xfs_qm_scall_quotaoff(mp, flags);
89 case Q_XQUOTARM:
90 if (XFS_IS_QUOTA_ON(mp))
91 return -EINVAL;
92 return -xfs_qm_scall_trunc_qfiles(mp, flags);
93 }
94
95 return -EINVAL;
96}
97
98STATIC int
b9b2dd36 99xfs_fs_get_dqblk(
fcafb71b
CH
100 struct super_block *sb,
101 int type,
102 qid_t id,
103 struct fs_disk_quota *fdq)
104{
105 struct xfs_mount *mp = XFS_M(sb);
106
107 if (!XFS_IS_QUOTA_RUNNING(mp))
108 return -ENOSYS;
109 if (!XFS_IS_QUOTA_ON(mp))
110 return -ESRCH;
111
112 return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq);
113}
114
115STATIC int
c472b432 116xfs_fs_set_dqblk(
fcafb71b
CH
117 struct super_block *sb,
118 int type,
119 qid_t id,
120 struct fs_disk_quota *fdq)
121{
122 struct xfs_mount *mp = XFS_M(sb);
123
124 if (sb->s_flags & MS_RDONLY)
125 return -EROFS;
126 if (!XFS_IS_QUOTA_RUNNING(mp))
127 return -ENOSYS;
128 if (!XFS_IS_QUOTA_ON(mp))
129 return -ESRCH;
fcafb71b
CH
130
131 return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq);
132}
133
0d54b217 134const struct quotactl_ops xfs_quotactl_operations = {
fcafb71b
CH
135 .get_xstate = xfs_fs_get_xstate,
136 .set_xstate = xfs_fs_set_xstate,
b9b2dd36 137 .get_dqblk = xfs_fs_get_dqblk,
c472b432 138 .set_dqblk = xfs_fs_set_dqblk,
fcafb71b 139};