Loading...
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"
19#include "xfs_format.h"
20#include "xfs_log_format.h"
21#include "xfs_trans_resv.h"
22#include "xfs_sb.h"
23#include "xfs_ag.h"
24#include "xfs_mount.h"
25#include "xfs_inode.h"
26#include "xfs_quota.h"
27#include "xfs_trans.h"
28#include "xfs_qm.h"
29#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
46xfs_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_get_xstatev(
59 struct super_block *sb,
60 struct fs_quota_statv *fqs)
61{
62 struct xfs_mount *mp = XFS_M(sb);
63
64 if (!XFS_IS_QUOTA_RUNNING(mp))
65 return -ENOSYS;
66 return -xfs_qm_scall_getqstatv(mp, fqs);
67}
68
69STATIC int
70xfs_fs_set_xstate(
71 struct super_block *sb,
72 unsigned int uflags,
73 int op)
74{
75 struct xfs_mount *mp = XFS_M(sb);
76 unsigned int flags = 0;
77
78 if (sb->s_flags & MS_RDONLY)
79 return -EROFS;
80 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
81 return -ENOSYS;
82
83 if (uflags & FS_QUOTA_UDQ_ACCT)
84 flags |= XFS_UQUOTA_ACCT;
85 if (uflags & FS_QUOTA_PDQ_ACCT)
86 flags |= XFS_PQUOTA_ACCT;
87 if (uflags & FS_QUOTA_GDQ_ACCT)
88 flags |= XFS_GQUOTA_ACCT;
89 if (uflags & FS_QUOTA_UDQ_ENFD)
90 flags |= XFS_UQUOTA_ENFD;
91 if (uflags & FS_QUOTA_GDQ_ENFD)
92 flags |= XFS_GQUOTA_ENFD;
93 if (uflags & FS_QUOTA_PDQ_ENFD)
94 flags |= XFS_PQUOTA_ENFD;
95
96 switch (op) {
97 case Q_XQUOTAON:
98 return -xfs_qm_scall_quotaon(mp, flags);
99 case Q_XQUOTAOFF:
100 if (!XFS_IS_QUOTA_ON(mp))
101 return -EINVAL;
102 return -xfs_qm_scall_quotaoff(mp, flags);
103 case Q_XQUOTARM:
104 if (XFS_IS_QUOTA_ON(mp))
105 return -EINVAL;
106 return -xfs_qm_scall_trunc_qfiles(mp, flags);
107 }
108
109 return -EINVAL;
110}
111
112STATIC int
113xfs_fs_get_dqblk(
114 struct super_block *sb,
115 struct kqid qid,
116 struct fs_disk_quota *fdq)
117{
118 struct xfs_mount *mp = XFS_M(sb);
119
120 if (!XFS_IS_QUOTA_RUNNING(mp))
121 return -ENOSYS;
122 if (!XFS_IS_QUOTA_ON(mp))
123 return -ESRCH;
124
125 return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
126 xfs_quota_type(qid.type), fdq);
127}
128
129STATIC int
130xfs_fs_set_dqblk(
131 struct super_block *sb,
132 struct kqid qid,
133 struct fs_disk_quota *fdq)
134{
135 struct xfs_mount *mp = XFS_M(sb);
136
137 if (sb->s_flags & MS_RDONLY)
138 return -EROFS;
139 if (!XFS_IS_QUOTA_RUNNING(mp))
140 return -ENOSYS;
141 if (!XFS_IS_QUOTA_ON(mp))
142 return -ESRCH;
143
144 return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
145 xfs_quota_type(qid.type), fdq);
146}
147
148const struct quotactl_ops xfs_quotactl_operations = {
149 .get_xstatev = xfs_fs_get_xstatev,
150 .get_xstate = xfs_fs_get_xstate,
151 .set_xstate = xfs_fs_set_xstate,
152 .get_dqblk = xfs_fs_get_dqblk,
153 .set_dqblk = xfs_fs_set_dqblk,
154};
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"
19#include "xfs_sb.h"
20#include "xfs_log.h"
21#include "xfs_ag.h"
22#include "xfs_mount.h"
23#include "xfs_quota.h"
24#include "xfs_trans.h"
25#include "xfs_bmap_btree.h"
26#include "xfs_inode.h"
27#include "xfs_qm.h"
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
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;
67 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
68 return -ENOSYS;
69
70 if (uflags & FS_QUOTA_UDQ_ACCT)
71 flags |= XFS_UQUOTA_ACCT;
72 if (uflags & FS_QUOTA_PDQ_ACCT)
73 flags |= XFS_PQUOTA_ACCT;
74 if (uflags & FS_QUOTA_GDQ_ACCT)
75 flags |= XFS_GQUOTA_ACCT;
76 if (uflags & FS_QUOTA_UDQ_ENFD)
77 flags |= XFS_UQUOTA_ENFD;
78 if (uflags & (FS_QUOTA_PDQ_ENFD|FS_QUOTA_GDQ_ENFD))
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
98xfs_fs_get_dqblk(
99 struct super_block *sb,
100 int type,
101 qid_t id,
102 struct fs_disk_quota *fdq)
103{
104 struct xfs_mount *mp = XFS_M(sb);
105
106 if (!XFS_IS_QUOTA_RUNNING(mp))
107 return -ENOSYS;
108 if (!XFS_IS_QUOTA_ON(mp))
109 return -ESRCH;
110
111 return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq);
112}
113
114STATIC int
115xfs_fs_set_dqblk(
116 struct super_block *sb,
117 int type,
118 qid_t id,
119 struct fs_disk_quota *fdq)
120{
121 struct xfs_mount *mp = XFS_M(sb);
122
123 if (sb->s_flags & MS_RDONLY)
124 return -EROFS;
125 if (!XFS_IS_QUOTA_RUNNING(mp))
126 return -ENOSYS;
127 if (!XFS_IS_QUOTA_ON(mp))
128 return -ESRCH;
129
130 return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq);
131}
132
133const struct quotactl_ops xfs_quotactl_operations = {
134 .get_xstate = xfs_fs_get_xstate,
135 .set_xstate = xfs_fs_set_xstate,
136 .get_dqblk = xfs_fs_get_dqblk,
137 .set_dqblk = xfs_fs_set_dqblk,
138};