blob: 6923905ab33d973eb30206dd97c247eafffbd2f4 [file] [log] [blame]
Christoph Hellwigfcafb712009-02-09 08:47:34 +01001/*
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"
Dave Chinner6ca1c902013-08-12 20:49:26 +100019#include "xfs_format.h"
Dave Chinner239880e2013-10-23 10:50:10 +110020#include "xfs_log_format.h"
Dave Chinner7fd36c42013-08-12 20:49:32 +100021#include "xfs_trans_resv.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010022#include "xfs_mount.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110023#include "xfs_inode.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010024#include "xfs_quota.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010025#include "xfs_trans.h"
Alex Elder06f8e2d2011-08-12 13:57:55 -050026#include "xfs_qm.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010027#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
43STATIC int
Christoph Hellwigfcafb712009-02-09 08:47:34 +010044xfs_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;
Dave Chinner24513372014-06-25 14:58:08 +100052 return xfs_qm_scall_getqstat(mp, fqs);
Christoph Hellwigfcafb712009-02-09 08:47:34 +010053}
54
55STATIC int
Chandra Seetharaman5d5e3d52013-08-06 17:27:08 -050056xfs_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;
Dave Chinner24513372014-06-25 14:58:08 +100064 return xfs_qm_scall_getqstatv(mp, fqs);
Chandra Seetharaman5d5e3d52013-08-06 17:27:08 -050065}
66
Jan Kara38e478c2014-10-08 15:56:21 +020067static unsigned int
68xfs_quota_flags(unsigned int uflags)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010069{
Jan Kara38e478c2014-10-08 15:56:21 +020070 unsigned int flags = 0;
Christoph Hellwigfcafb712009-02-09 08:47:34 +010071
Christoph Hellwigade7ce32010-06-04 10:56:01 +020072 if (uflags & FS_QUOTA_UDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010073 flags |= XFS_UQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020074 if (uflags & FS_QUOTA_PDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010075 flags |= XFS_PQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020076 if (uflags & FS_QUOTA_GDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010077 flags |= XFS_GQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020078 if (uflags & FS_QUOTA_UDQ_ENFD)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010079 flags |= XFS_UQUOTA_ENFD;
Chandra Seetharaman83e782e2013-06-27 17:25:10 -050080 if (uflags & FS_QUOTA_GDQ_ENFD)
81 flags |= XFS_GQUOTA_ENFD;
82 if (uflags & FS_QUOTA_PDQ_ENFD)
83 flags |= XFS_PQUOTA_ENFD;
Christoph Hellwigfcafb712009-02-09 08:47:34 +010084
Jan Kara38e478c2014-10-08 15:56:21 +020085 return flags;
86}
Christoph Hellwigfcafb712009-02-09 08:47:34 +010087
Jan Kara38e478c2014-10-08 15:56:21 +020088STATIC 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;
116
117 return xfs_qm_scall_quotaoff(mp, xfs_quota_flags(uflags));
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100118}
119
120STATIC int
Eric Sandeen9da93f92014-05-05 17:25:50 +1000121xfs_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;
Dave Chinner24513372014-06-25 14:58:08 +1000127
Eric Sandeen9da93f92014-05-05 17:25:50 +1000128 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;
Jie Liu74dc93a2014-07-24 21:27:17 +1000138 if (uflags & FS_PROJ_QUOTA)
Eric Sandeen9da93f92014-05-05 17:25:50 +1000139 flags |= XFS_DQ_PROJ;
140
Dave Chinner24513372014-06-25 14:58:08 +1000141 return xfs_qm_scall_trunc_qfiles(mp, flags);
142}
Eric Sandeen9da93f92014-05-05 17:25:50 +1000143
144STATIC int
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400145xfs_fs_get_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100146 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700147 struct kqid qid,
Jan Kara14bf61f2014-10-09 16:03:13 +0200148 struct qc_dqblk *qdq)
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100149{
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
Dave Chinner24513372014-06-25 14:58:08 +1000157 return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
Jan Kara14bf61f2014-10-09 16:03:13 +0200158 xfs_quota_type(qid.type), qdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100159}
160
161STATIC int
Christoph Hellwigc472b432010-05-06 17:05:17 -0400162xfs_fs_set_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100163 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700164 struct kqid qid,
Jan Kara14bf61f2014-10-09 16:03:13 +0200165 struct qc_dqblk *qdq)
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100166{
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;
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100175
Dave Chinner24513372014-06-25 14:58:08 +1000176 return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
Jan Kara14bf61f2014-10-09 16:03:13 +0200177 xfs_quota_type(qid.type), qdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100178}
179
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700180const struct quotactl_ops xfs_quotactl_operations = {
Chandra Seetharaman5d5e3d52013-08-06 17:27:08 -0500181 .get_xstatev = xfs_fs_get_xstatev,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100182 .get_xstate = xfs_fs_get_xstate,
Jan Kara38e478c2014-10-08 15:56:21 +0200183 .quota_enable = xfs_quota_enable,
184 .quota_disable = xfs_quota_disable,
Eric Sandeen9da93f92014-05-05 17:25:50 +1000185 .rm_xquota = xfs_fs_rm_xquota,
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400186 .get_dqblk = xfs_fs_get_dqblk,
Christoph Hellwigc472b432010-05-06 17:05:17 -0400187 .set_dqblk = xfs_fs_set_dqblk,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100188};