perf trace: Disable events and drain events when forked workload ends
[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"
6ca1c906 19#include "xfs_format.h"
239880ef 20#include "xfs_log_format.h"
7fd36c44 21#include "xfs_trans_resv.h"
fcafb71b 22#include "xfs_mount.h"
a4fbe6ab 23#include "xfs_inode.h"
fcafb71b 24#include "xfs_quota.h"
fcafb71b 25#include "xfs_trans.h"
06f8e2d6 26#include "xfs_qm.h"
fcafb71b
CH
27#include <linux/quota.h>
28
29
30STATIC int
31xfs_quota_type(int type)
32{
33 switch (type) {
34 case USRQUOTA:
35 return XFS_DQ_USER;
36 case GRPQUOTA:
37 return XFS_DQ_GROUP;
38 default:
39 return XFS_DQ_PROJ;
40 }
41}
42
fcafb71b
CH
43STATIC int
44xfs_fs_get_xstate(
45 struct super_block *sb,
46 struct fs_quota_stat *fqs)
47{
48 struct xfs_mount *mp = XFS_M(sb);
49
50 if (!XFS_IS_QUOTA_RUNNING(mp))
51 return -ENOSYS;
2451337d 52 return xfs_qm_scall_getqstat(mp, fqs);
fcafb71b
CH
53}
54
5d5e3d57
CS
55STATIC int
56xfs_fs_get_xstatev(
57 struct super_block *sb,
58 struct fs_quota_statv *fqs)
59{
60 struct xfs_mount *mp = XFS_M(sb);
61
62 if (!XFS_IS_QUOTA_RUNNING(mp))
63 return -ENOSYS;
2451337d 64 return xfs_qm_scall_getqstatv(mp, fqs);
5d5e3d57
CS
65}
66
38e478c4
JK
67static unsigned int
68xfs_quota_flags(unsigned int uflags)
fcafb71b 69{
38e478c4 70 unsigned int flags = 0;
fcafb71b 71
ade7ce31 72 if (uflags & FS_QUOTA_UDQ_ACCT)
fcafb71b 73 flags |= XFS_UQUOTA_ACCT;
ade7ce31 74 if (uflags & FS_QUOTA_PDQ_ACCT)
fcafb71b 75 flags |= XFS_PQUOTA_ACCT;
ade7ce31 76 if (uflags & FS_QUOTA_GDQ_ACCT)
fcafb71b 77 flags |= XFS_GQUOTA_ACCT;
ade7ce31 78 if (uflags & FS_QUOTA_UDQ_ENFD)
fcafb71b 79 flags |= XFS_UQUOTA_ENFD;
83e782e1
CS
80 if (uflags & FS_QUOTA_GDQ_ENFD)
81 flags |= XFS_GQUOTA_ENFD;
82 if (uflags & FS_QUOTA_PDQ_ENFD)
83 flags |= XFS_PQUOTA_ENFD;
fcafb71b 84
38e478c4
JK
85 return flags;
86}
87
88STATIC int
89xfs_quota_enable(
90 struct super_block *sb,
91 unsigned int uflags)
92{
93 struct xfs_mount *mp = XFS_M(sb);
94
95 if (sb->s_flags & MS_RDONLY)
96 return -EROFS;
97 if (!XFS_IS_QUOTA_RUNNING(mp))
98 return -ENOSYS;
99
100 return xfs_qm_scall_quotaon(mp, xfs_quota_flags(uflags));
101}
102
103STATIC int
104xfs_quota_disable(
105 struct super_block *sb,
106 unsigned int uflags)
107{
108 struct xfs_mount *mp = XFS_M(sb);
109
110 if (sb->s_flags & MS_RDONLY)
111 return -EROFS;
112 if (!XFS_IS_QUOTA_RUNNING(mp))
113 return -ENOSYS;
114 if (!XFS_IS_QUOTA_ON(mp))
115 return -EINVAL;
fcafb71b 116
38e478c4 117 return xfs_qm_scall_quotaoff(mp, xfs_quota_flags(uflags));
fcafb71b
CH
118}
119
9da93f9b
ES
120STATIC int
121xfs_fs_rm_xquota(
122 struct super_block *sb,
123 unsigned int uflags)
124{
125 struct xfs_mount *mp = XFS_M(sb);
126 unsigned int flags = 0;
2451337d 127
9da93f9b
ES
128 if (sb->s_flags & MS_RDONLY)
129 return -EROFS;
130
131 if (XFS_IS_QUOTA_ON(mp))
132 return -EINVAL;
133
134 if (uflags & FS_USER_QUOTA)
135 flags |= XFS_DQ_USER;
136 if (uflags & FS_GROUP_QUOTA)
137 flags |= XFS_DQ_GROUP;
74dc93a9 138 if (uflags & FS_PROJ_QUOTA)
9da93f9b
ES
139 flags |= XFS_DQ_PROJ;
140
2451337d
DC
141 return xfs_qm_scall_trunc_qfiles(mp, flags);
142}
9da93f9b 143
fcafb71b 144STATIC int
b9b2dd36 145xfs_fs_get_dqblk(
fcafb71b 146 struct super_block *sb,
74a8a103 147 struct kqid qid,
14bf61ff 148 struct qc_dqblk *qdq)
fcafb71b
CH
149{
150 struct xfs_mount *mp = XFS_M(sb);
151
152 if (!XFS_IS_QUOTA_RUNNING(mp))
153 return -ENOSYS;
154 if (!XFS_IS_QUOTA_ON(mp))
155 return -ESRCH;
156
2451337d 157 return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
14bf61ff 158 xfs_quota_type(qid.type), qdq);
fcafb71b
CH
159}
160
161STATIC int
c472b432 162xfs_fs_set_dqblk(
fcafb71b 163 struct super_block *sb,
74a8a103 164 struct kqid qid,
14bf61ff 165 struct qc_dqblk *qdq)
fcafb71b
CH
166{
167 struct xfs_mount *mp = XFS_M(sb);
168
169 if (sb->s_flags & MS_RDONLY)
170 return -EROFS;
171 if (!XFS_IS_QUOTA_RUNNING(mp))
172 return -ENOSYS;
173 if (!XFS_IS_QUOTA_ON(mp))
174 return -ESRCH;
fcafb71b 175
2451337d 176 return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
14bf61ff 177 xfs_quota_type(qid.type), qdq);
fcafb71b
CH
178}
179
0d54b217 180const struct quotactl_ops xfs_quotactl_operations = {
5d5e3d57 181 .get_xstatev = xfs_fs_get_xstatev,
fcafb71b 182 .get_xstate = xfs_fs_get_xstate,
38e478c4
JK
183 .quota_enable = xfs_quota_enable,
184 .quota_disable = xfs_quota_disable,
9da93f9b 185 .rm_xquota = xfs_fs_rm_xquota,
b9b2dd36 186 .get_dqblk = xfs_fs_get_dqblk,
c472b432 187 .set_dqblk = xfs_fs_set_dqblk,
fcafb71b 188};