blob: acf50712f4d74531c11a5919172af4a83e1bba52 [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"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010020#include "xfs_sb.h"
Dave Chinnered3b4d62010-05-21 12:07:08 +100021#include "xfs_log.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010022#include "xfs_ag.h"
23#include "xfs_mount.h"
24#include "xfs_quota.h"
Christoph Hellwigfcafb712009-02-09 08:47:34 +010025#include "xfs_trans.h"
26#include "xfs_bmap_btree.h"
27#include "xfs_inode.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;
54 return -xfs_qm_scall_getqstat(mp, fqs);
55}
56
57STATIC int
58xfs_fs_set_xstate(
59 struct super_block *sb,
60 unsigned int uflags,
61 int op)
62{
63 struct xfs_mount *mp = XFS_M(sb);
64 unsigned int flags = 0;
65
66 if (sb->s_flags & MS_RDONLY)
67 return -EROFS;
Ryota Yamauchic7ff91d2009-10-30 09:27:44 +010068 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
Christoph Hellwigfcafb712009-02-09 08:47:34 +010069 return -ENOSYS;
Christoph Hellwigfcafb712009-02-09 08:47:34 +010070
Christoph Hellwigade7ce32010-06-04 10:56:01 +020071 if (uflags & FS_QUOTA_UDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010072 flags |= XFS_UQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020073 if (uflags & FS_QUOTA_PDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010074 flags |= XFS_PQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020075 if (uflags & FS_QUOTA_GDQ_ACCT)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010076 flags |= XFS_GQUOTA_ACCT;
Christoph Hellwigade7ce32010-06-04 10:56:01 +020077 if (uflags & FS_QUOTA_UDQ_ENFD)
Christoph Hellwigfcafb712009-02-09 08:47:34 +010078 flags |= XFS_UQUOTA_ENFD;
Chandra Seetharaman83e782e2013-06-27 17:25:10 -050079 if (uflags & FS_QUOTA_GDQ_ENFD)
80 flags |= XFS_GQUOTA_ENFD;
81 if (uflags & FS_QUOTA_PDQ_ENFD)
82 flags |= XFS_PQUOTA_ENFD;
Christoph Hellwigfcafb712009-02-09 08:47:34 +010083
84 switch (op) {
85 case Q_XQUOTAON:
86 return -xfs_qm_scall_quotaon(mp, flags);
87 case Q_XQUOTAOFF:
88 if (!XFS_IS_QUOTA_ON(mp))
89 return -EINVAL;
90 return -xfs_qm_scall_quotaoff(mp, flags);
91 case Q_XQUOTARM:
92 if (XFS_IS_QUOTA_ON(mp))
93 return -EINVAL;
94 return -xfs_qm_scall_trunc_qfiles(mp, flags);
95 }
96
97 return -EINVAL;
98}
99
100STATIC int
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400101xfs_fs_get_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100102 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700103 struct kqid qid,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100104 struct fs_disk_quota *fdq)
105{
106 struct xfs_mount *mp = XFS_M(sb);
107
108 if (!XFS_IS_QUOTA_RUNNING(mp))
109 return -ENOSYS;
110 if (!XFS_IS_QUOTA_ON(mp))
111 return -ESRCH;
112
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700113 return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
114 xfs_quota_type(qid.type), fdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100115}
116
117STATIC int
Christoph Hellwigc472b432010-05-06 17:05:17 -0400118xfs_fs_set_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100119 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700120 struct kqid qid,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100121 struct fs_disk_quota *fdq)
122{
123 struct xfs_mount *mp = XFS_M(sb);
124
125 if (sb->s_flags & MS_RDONLY)
126 return -EROFS;
127 if (!XFS_IS_QUOTA_RUNNING(mp))
128 return -ENOSYS;
129 if (!XFS_IS_QUOTA_ON(mp))
130 return -ESRCH;
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100131
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700132 return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
133 xfs_quota_type(qid.type), fdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100134}
135
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700136const struct quotactl_ops xfs_quotactl_operations = {
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100137 .get_xstate = xfs_fs_get_xstate,
138 .set_xstate = xfs_fs_set_xstate,
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400139 .get_dqblk = xfs_fs_get_dqblk,
Christoph Hellwigc472b432010-05-06 17:05:17 -0400140 .set_dqblk = xfs_fs_set_dqblk,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100141};