Merge tag 'v3.10.79' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / xfs / xfs_quotaops.c
CommitLineData
fcafb71b
CH
1/*
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"
fcafb71b 19#include "xfs_sb.h"
ed3b4d6c 20#include "xfs_log.h"
fcafb71b
CH
21#include "xfs_ag.h"
22#include "xfs_mount.h"
23#include "xfs_quota.h"
fcafb71b
CH
24#include "xfs_trans.h"
25#include "xfs_bmap_btree.h"
26#include "xfs_inode.h"
06f8e2d6 27#include "xfs_qm.h"
fcafb71b
CH
28#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
fcafb71b
CH
44STATIC int
45xfs_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;
c7ff91d7 67 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
fcafb71b 68 return -ENOSYS;
fcafb71b 69
ade7ce31 70 if (uflags & FS_QUOTA_UDQ_ACCT)
fcafb71b 71 flags |= XFS_UQUOTA_ACCT;
ade7ce31 72 if (uflags & FS_QUOTA_PDQ_ACCT)
fcafb71b 73 flags |= XFS_PQUOTA_ACCT;
ade7ce31 74 if (uflags & FS_QUOTA_GDQ_ACCT)
fcafb71b 75 flags |= XFS_GQUOTA_ACCT;
ade7ce31 76 if (uflags & FS_QUOTA_UDQ_ENFD)
fcafb71b 77 flags |= XFS_UQUOTA_ENFD;
ade7ce31 78 if (uflags & (FS_QUOTA_PDQ_ENFD|FS_QUOTA_GDQ_ENFD))
fcafb71b
CH
79 flags |= XFS_OQUOTA_ENFD;
80
81 switch (op) {
82 case Q_XQUOTAON:
83 return -xfs_qm_scall_quotaon(mp, flags);
84 case Q_XQUOTAOFF:
85 if (!XFS_IS_QUOTA_ON(mp))
86 return -EINVAL;
87 return -xfs_qm_scall_quotaoff(mp, flags);
88 case Q_XQUOTARM:
89 if (XFS_IS_QUOTA_ON(mp))
90 return -EINVAL;
91 return -xfs_qm_scall_trunc_qfiles(mp, flags);
92 }
93
94 return -EINVAL;
95}
96
97STATIC int
b9b2dd36 98xfs_fs_get_dqblk(
fcafb71b 99 struct super_block *sb,
74a8a103 100 struct kqid qid,
fcafb71b
CH
101 struct fs_disk_quota *fdq)
102{
103 struct xfs_mount *mp = XFS_M(sb);
104
105 if (!XFS_IS_QUOTA_RUNNING(mp))
106 return -ENOSYS;
107 if (!XFS_IS_QUOTA_ON(mp))
108 return -ESRCH;
109
74a8a103
EB
110 return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
111 xfs_quota_type(qid.type), fdq);
fcafb71b
CH
112}
113
114STATIC int
c472b432 115xfs_fs_set_dqblk(
fcafb71b 116 struct super_block *sb,
74a8a103 117 struct kqid qid,
fcafb71b
CH
118 struct fs_disk_quota *fdq)
119{
120 struct xfs_mount *mp = XFS_M(sb);
121
122 if (sb->s_flags & MS_RDONLY)
123 return -EROFS;
124 if (!XFS_IS_QUOTA_RUNNING(mp))
125 return -ENOSYS;
126 if (!XFS_IS_QUOTA_ON(mp))
127 return -ESRCH;
fcafb71b 128
74a8a103
EB
129 return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
130 xfs_quota_type(qid.type), fdq);
fcafb71b
CH
131}
132
0d54b217 133const struct quotactl_ops xfs_quotactl_operations = {
fcafb71b
CH
134 .get_xstate = xfs_fs_get_xstate,
135 .set_xstate = xfs_fs_set_xstate,
b9b2dd36 136 .get_dqblk = xfs_fs_get_dqblk,
c472b432 137 .set_dqblk = xfs_fs_set_dqblk,
fcafb71b 138};