blob: 20e30f93b0c7dab8b548527c46634c49486e02cd [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"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010019#include "xfs_sb.h"
Dave Chinnered3b4d62010-05-21 12:07:08 +100020#include "xfs_log.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010021#include "xfs_ag.h"
22#include "xfs_mount.h"
23#include "xfs_quota.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010024#include "xfs_trans.h"
25#include "xfs_bmap_btree.h"
26#include "xfs_inode.h"
Alex Elder06f8e2d2011-08-12 13:57:55 -050027#include "xfs_qm.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010028#include <linux/quota.h>
29
30
31STATIC int
32xfs_quota_type(int type)
33{
34 switch (type) {
35 case USRQUOTA:
36 return XFS_DQ_USER;
37 case GRPQUOTA:
38 return XFS_DQ_GROUP;
39 default:
40 return XFS_DQ_PROJ;
41 }
42}
43
44STATIC int
Christoph Hellwigfcafb712009-02-09 08:47:34 +010045xfs_fs_get_xstate(
46 struct super_block *sb,
47 struct fs_quota_stat *fqs)
48{
49 struct xfs_mount *mp = XFS_M(sb);
50
51 if (!XFS_IS_QUOTA_RUNNING(mp))
52 return -ENOSYS;
53 return -xfs_qm_scall_getqstat(mp, fqs);
54}
55
56STATIC int
57xfs_fs_set_xstate(
58 struct super_block *sb,
59 unsigned int uflags,
60 int op)
61{
62 struct xfs_mount *mp = XFS_M(sb);
63 unsigned int flags = 0;
64
65 if (sb->s_flags & MS_RDONLY)
66 return -EROFS;
Ryota Yamauchic7ff91d2009-10-30 09:27:44 +010067 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
Christoph Hellwigfcafb712009-02-09 08:47:34 +010068 return -ENOSYS;
Christoph Hellwigfcafb712009-02-09 08:47:34 +010069
Christoph Hellwigade7ce32010-06-04 10:56:01 +020070 if (uflags & FS_QUOTA_UDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010071 flags |= XFS_UQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020072 if (uflags & FS_QUOTA_PDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010073 flags |= XFS_PQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020074 if (uflags & FS_QUOTA_GDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010075 flags |= XFS_GQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020076 if (uflags & FS_QUOTA_UDQ_ENFD)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010077 flags |= XFS_UQUOTA_ENFD;
Chandra Seetharaman83e782e2013-06-27 17:25:10 -050078 if (uflags & FS_QUOTA_GDQ_ENFD)
79 flags |= XFS_GQUOTA_ENFD;
80 if (uflags & FS_QUOTA_PDQ_ENFD)
81 flags |= XFS_PQUOTA_ENFD;
Christoph Hellwigfcafb712009-02-09 08:47:34 +010082
83 switch (op) {
84 case Q_XQUOTAON:
85 return -xfs_qm_scall_quotaon(mp, flags);
86 case Q_XQUOTAOFF:
87 if (!XFS_IS_QUOTA_ON(mp))
88 return -EINVAL;
89 return -xfs_qm_scall_quotaoff(mp, flags);
90 case Q_XQUOTARM:
91 if (XFS_IS_QUOTA_ON(mp))
92 return -EINVAL;
93 return -xfs_qm_scall_trunc_qfiles(mp, flags);
94 }
95
96 return -EINVAL;
97}
98
99STATIC int
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400100xfs_fs_get_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100101 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700102 struct kqid qid,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100103 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
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700112 return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
113 xfs_quota_type(qid.type), fdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100114}
115
116STATIC int
Christoph Hellwigc472b432010-05-06 17:05:17 -0400117xfs_fs_set_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100118 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700119 struct kqid qid,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100120 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;
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100130
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700131 return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
132 xfs_quota_type(qid.type), fdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100133}
134
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700135const struct quotactl_ops xfs_quotactl_operations = {
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100136 .get_xstate = xfs_fs_get_xstate,
137 .set_xstate = xfs_fs_set_xstate,
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400138 .get_dqblk = xfs_fs_get_dqblk,
Christoph Hellwigc472b432010-05-06 17:05:17 -0400139 .set_dqblk = xfs_fs_set_dqblk,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100140};