blob: 4f7aecbe61da3e06a4231a5a29ff6a4e698fb429 [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"
Dave Chinner7fd36c42013-08-12 20:49:32 +100022#include "xfs_sb.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010023#include "xfs_ag.h"
24#include "xfs_mount.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110025#include "xfs_inode.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010026#include "xfs_quota.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010027#include "xfs_trans.h"
Alex Elder06f8e2d2011-08-12 13:57:55 -050028#include "xfs_qm.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010029#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
45STATIC int
Christoph Hellwigfcafb712009-02-09 08:47:34 +010046xfs_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;
Dave Chinner24513372014-06-25 14:58:08 +100054 return xfs_qm_scall_getqstat(mp, fqs);
Christoph Hellwigfcafb712009-02-09 08:47:34 +010055}
56
57STATIC int
Chandra Seetharaman5d5e3d52013-08-06 17:27:08 -050058xfs_fs_get_xstatev(
59 struct super_block *sb,
60 struct fs_quota_statv *fqs)
61{
62 struct xfs_mount *mp = XFS_M(sb);
63
64 if (!XFS_IS_QUOTA_RUNNING(mp))
65 return -ENOSYS;
Dave Chinner24513372014-06-25 14:58:08 +100066 return xfs_qm_scall_getqstatv(mp, fqs);
Chandra Seetharaman5d5e3d52013-08-06 17:27:08 -050067}
68
69STATIC int
Christoph Hellwigfcafb712009-02-09 08:47:34 +010070xfs_fs_set_xstate(
71 struct super_block *sb,
72 unsigned int uflags,
73 int op)
74{
75 struct xfs_mount *mp = XFS_M(sb);
76 unsigned int flags = 0;
77
78 if (sb->s_flags & MS_RDONLY)
79 return -EROFS;
Ryota Yamauchic7ff91d2009-10-30 09:27:44 +010080 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
Christoph Hellwigfcafb712009-02-09 08:47:34 +010081 return -ENOSYS;
Christoph Hellwigfcafb712009-02-09 08:47:34 +010082
Christoph Hellwigade7ce32010-06-04 10:56:01 +020083 if (uflags & FS_QUOTA_UDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010084 flags |= XFS_UQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020085 if (uflags & FS_QUOTA_PDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010086 flags |= XFS_PQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020087 if (uflags & FS_QUOTA_GDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010088 flags |= XFS_GQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020089 if (uflags & FS_QUOTA_UDQ_ENFD)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010090 flags |= XFS_UQUOTA_ENFD;
Chandra Seetharaman83e782e2013-06-27 17:25:10 -050091 if (uflags & FS_QUOTA_GDQ_ENFD)
92 flags |= XFS_GQUOTA_ENFD;
93 if (uflags & FS_QUOTA_PDQ_ENFD)
94 flags |= XFS_PQUOTA_ENFD;
Christoph Hellwigfcafb712009-02-09 08:47:34 +010095
96 switch (op) {
97 case Q_XQUOTAON:
Dave Chinner24513372014-06-25 14:58:08 +100098 return xfs_qm_scall_quotaon(mp, flags);
Christoph Hellwigfcafb712009-02-09 08:47:34 +010099 case Q_XQUOTAOFF:
100 if (!XFS_IS_QUOTA_ON(mp))
101 return -EINVAL;
Dave Chinner24513372014-06-25 14:58:08 +1000102 return xfs_qm_scall_quotaoff(mp, flags);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100103 }
104
105 return -EINVAL;
106}
107
108STATIC int
Eric Sandeen9da93f92014-05-05 17:25:50 +1000109xfs_fs_rm_xquota(
110 struct super_block *sb,
111 unsigned int uflags)
112{
113 struct xfs_mount *mp = XFS_M(sb);
114 unsigned int flags = 0;
Dave Chinner24513372014-06-25 14:58:08 +1000115
Eric Sandeen9da93f92014-05-05 17:25:50 +1000116 if (sb->s_flags & MS_RDONLY)
117 return -EROFS;
118
119 if (XFS_IS_QUOTA_ON(mp))
120 return -EINVAL;
121
122 if (uflags & FS_USER_QUOTA)
123 flags |= XFS_DQ_USER;
124 if (uflags & FS_GROUP_QUOTA)
125 flags |= XFS_DQ_GROUP;
126 if (uflags & FS_USER_QUOTA)
127 flags |= XFS_DQ_PROJ;
128
Dave Chinner24513372014-06-25 14:58:08 +1000129 return xfs_qm_scall_trunc_qfiles(mp, flags);
130}
Eric Sandeen9da93f92014-05-05 17:25:50 +1000131
132STATIC int
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400133xfs_fs_get_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100134 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700135 struct kqid qid,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100136 struct fs_disk_quota *fdq)
137{
138 struct xfs_mount *mp = XFS_M(sb);
139
140 if (!XFS_IS_QUOTA_RUNNING(mp))
141 return -ENOSYS;
142 if (!XFS_IS_QUOTA_ON(mp))
143 return -ESRCH;
144
Dave Chinner24513372014-06-25 14:58:08 +1000145 return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700146 xfs_quota_type(qid.type), fdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100147}
148
149STATIC int
Christoph Hellwigc472b432010-05-06 17:05:17 -0400150xfs_fs_set_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100151 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700152 struct kqid qid,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100153 struct fs_disk_quota *fdq)
154{
155 struct xfs_mount *mp = XFS_M(sb);
156
157 if (sb->s_flags & MS_RDONLY)
158 return -EROFS;
159 if (!XFS_IS_QUOTA_RUNNING(mp))
160 return -ENOSYS;
161 if (!XFS_IS_QUOTA_ON(mp))
162 return -ESRCH;
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100163
Dave Chinner24513372014-06-25 14:58:08 +1000164 return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700165 xfs_quota_type(qid.type), fdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100166}
167
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700168const struct quotactl_ops xfs_quotactl_operations = {
Chandra Seetharaman5d5e3d52013-08-06 17:27:08 -0500169 .get_xstatev = xfs_fs_get_xstatev,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100170 .get_xstate = xfs_fs_get_xstate,
171 .set_xstate = xfs_fs_set_xstate,
Eric Sandeen9da93f92014-05-05 17:25:50 +1000172 .rm_xquota = xfs_fs_rm_xquota,
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400173 .get_dqblk = xfs_fs_get_dqblk,
Christoph Hellwigc472b432010-05-06 17:05:17 -0400174 .set_dqblk = xfs_fs_set_dqblk,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100175};