blob: 446a2fc9825e76aae76edec9e4ccf2d442415696 [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
59xfs_fs_set_xstate(
60 struct super_block *sb,
61 unsigned int uflags,
62 int op)
63{
64 struct xfs_mount *mp = XFS_M(sb);
65 unsigned int flags = 0;
66
67 if (sb->s_flags & MS_RDONLY)
68 return -EROFS;
Ryota Yamauchic7ff91d2009-10-30 09:27:44 +010069 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
Christoph Hellwigfcafb712009-02-09 08:47:34 +010070 return -ENOSYS;
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
85 switch (op) {
86 case Q_XQUOTAON:
87 return -xfs_qm_scall_quotaon(mp, flags);
88 case Q_XQUOTAOFF:
89 if (!XFS_IS_QUOTA_ON(mp))
90 return -EINVAL;
91 return -xfs_qm_scall_quotaoff(mp, flags);
92 case Q_XQUOTARM:
93 if (XFS_IS_QUOTA_ON(mp))
94 return -EINVAL;
95 return -xfs_qm_scall_trunc_qfiles(mp, flags);
96 }
97
98 return -EINVAL;
99}
100
101STATIC int
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400102xfs_fs_get_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100103 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700104 struct kqid qid,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100105 struct fs_disk_quota *fdq)
106{
107 struct xfs_mount *mp = XFS_M(sb);
108
109 if (!XFS_IS_QUOTA_RUNNING(mp))
110 return -ENOSYS;
111 if (!XFS_IS_QUOTA_ON(mp))
112 return -ESRCH;
113
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700114 return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
115 xfs_quota_type(qid.type), fdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100116}
117
118STATIC int
Christoph Hellwigc472b432010-05-06 17:05:17 -0400119xfs_fs_set_dqblk(
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100120 struct super_block *sb,
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700121 struct kqid qid,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100122 struct fs_disk_quota *fdq)
123{
124 struct xfs_mount *mp = XFS_M(sb);
125
126 if (sb->s_flags & MS_RDONLY)
127 return -EROFS;
128 if (!XFS_IS_QUOTA_RUNNING(mp))
129 return -ENOSYS;
130 if (!XFS_IS_QUOTA_ON(mp))
131 return -ESRCH;
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100132
Eric W. Biederman74a8a102012-09-16 02:07:49 -0700133 return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
134 xfs_quota_type(qid.type), fdq);
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100135}
136
Alexey Dobriyan0d54b212009-09-21 17:01:09 -0700137const struct quotactl_ops xfs_quotactl_operations = {
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100138 .get_xstate = xfs_fs_get_xstate,
139 .set_xstate = xfs_fs_set_xstate,
Christoph Hellwigb9b2dd32010-05-06 17:04:58 -0400140 .get_dqblk = xfs_fs_get_dqblk,
Christoph Hellwigc472b432010-05-06 17:05:17 -0400141 .set_dqblk = xfs_fs_set_dqblk,
Christoph Hellwigfcafb712009-02-09 08:47:34 +0100142};