blob: 1326d81596c2920b27f45021b67b76979e5ef387 [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 Chinner7fd36c42013-08-12 20:49:32 +100020#include "xfs_trans_resv.h"
Dave Chinnered3b4d62010-05-21 12:07:08 +100021#include "xfs_log.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"
25#include "xfs_quota.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010026#include "xfs_trans.h"
27#include "xfs_bmap_btree.h"
28#include "xfs_inode.h"
Alex Elder06f8e2d2011-08-12 13:57:55 -050029#include "xfs_qm.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010030#include <linux/quota.h>
31
32
33STATIC int
34xfs_quota_type(int type)
35{
36 switch (type) {
37 case USRQUOTA:
38 return XFS_DQ_USER;
39 case GRPQUOTA:
40 return XFS_DQ_GROUP;
41 default:
42 return XFS_DQ_PROJ;
43 }
44}
45
46STATIC int
Christoph Hellwigfcafb712009-02-09 08:47:34 +010047xfs_fs_get_xstate(
48 struct super_block *sb,
49 struct fs_quota_stat *fqs)
50{
51 struct xfs_mount *mp = XFS_M(sb);
52
53 if (!XFS_IS_QUOTA_RUNNING(mp))
54 return -ENOSYS;
55 return -xfs_qm_scall_getqstat(mp, fqs);
56}
57
58STATIC int
Chandra Seetharaman5d5e3d52013-08-06 17:27:08 -050059xfs_fs_get_xstatev(
60 struct super_block *sb,
61 struct fs_quota_statv *fqs)
62{
63 struct xfs_mount *mp = XFS_M(sb);
64
65 if (!XFS_IS_QUOTA_RUNNING(mp))
66 return -ENOSYS;
67 return -xfs_qm_scall_getqstatv(mp, fqs);
68}
69
70STATIC int
Christoph Hellwigfcafb712009-02-09 08:47:34 +010071xfs_fs_set_xstate(
72 struct super_block *sb,
73 unsigned int uflags,
74 int op)
75{
76 struct xfs_mount *mp = XFS_M(sb);
77 unsigned int flags = 0;
78
79 if (sb->s_flags & MS_RDONLY)
80 return -EROFS;
Ryota Yamauchic7ff91d2009-10-30 09:27:44 +010081 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
Christoph Hellwigfcafb712009-02-09 08:47:34 +010082 return -ENOSYS;
Christoph Hellwigfcafb712009-02-09 08:47:34 +010083
Christoph Hellwigade7ce32010-06-04 10:56:01 +020084 if (uflags & FS_QUOTA_UDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010085 flags |= XFS_UQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020086 if (uflags & FS_QUOTA_PDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010087 flags |= XFS_PQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020088 if (uflags & FS_QUOTA_GDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010089 flags |= XFS_GQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020090 if (uflags & FS_QUOTA_UDQ_ENFD)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010091 flags |= XFS_UQUOTA_ENFD;
Chandra Seetharaman83e782e2013-06-27 17:25:10 -050092 if (uflags & FS_QUOTA_GDQ_ENFD)
93 flags |= XFS_GQUOTA_ENFD;
94 if (uflags & FS_QUOTA_PDQ_ENFD)
95 flags |= XFS_PQUOTA_ENFD;
Christoph Hellwigfcafb712009-02-09 08:47:34 +010096
97 switch (op) {
98 case Q_XQUOTAON:
99 return -xfs_qm_scall_quotaon(mp, flags);
100 case Q_XQUOTAOFF:
101 if (!XFS_IS_QUOTA_ON(mp))
102 return -EINVAL;
103 return -xfs_qm_scall_quotaoff(mp, flags);
104 case Q_XQUOTARM:
105 if (XFS_IS_QUOTA_ON(mp))
106 return -EINVAL;
107 return -xfs_qm_scall_trunc_qfiles(mp, flags);
108 }
109
110 return -EINVAL;
111}
112
113STATIC int
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400114xfs_fs_get_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100115 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700116 struct kqid qid,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100117 struct fs_disk_quota *fdq)
118{
119 struct xfs_mount *mp = XFS_M(sb);
120
121 if (!XFS_IS_QUOTA_RUNNING(mp))
122 return -ENOSYS;
123 if (!XFS_IS_QUOTA_ON(mp))
124 return -ESRCH;
125
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700126 return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
127 xfs_quota_type(qid.type), fdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100128}
129
130STATIC int
Christoph Hellwigc472b432010-05-06 17:05:17 -0400131xfs_fs_set_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100132 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700133 struct kqid qid,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100134 struct fs_disk_quota *fdq)
135{
136 struct xfs_mount *mp = XFS_M(sb);
137
138 if (sb->s_flags & MS_RDONLY)
139 return -EROFS;
140 if (!XFS_IS_QUOTA_RUNNING(mp))
141 return -ENOSYS;
142 if (!XFS_IS_QUOTA_ON(mp))
143 return -ESRCH;
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100144
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700145 return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
146 xfs_quota_type(qid.type), fdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100147}
148
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700149const struct quotactl_ops xfs_quotactl_operations = {
Chandra Seetharaman5d5e3d52013-08-06 17:27:08 -0500150 .get_xstatev = xfs_fs_get_xstatev,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100151 .get_xstate = xfs_fs_get_xstate,
152 .set_xstate = xfs_fs_set_xstate,
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400153 .get_dqblk = xfs_fs_get_dqblk,
Christoph Hellwigc472b432010-05-06 17:05:17 -0400154 .set_dqblk = xfs_fs_set_dqblk,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100155};