Commit | Line | Data |
---|---|---|
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" | |
6ca1c906 | 19 | #include "xfs_format.h" |
239880ef | 20 | #include "xfs_log_format.h" |
7fd36c44 | 21 | #include "xfs_trans_resv.h" |
7fd36c44 | 22 | #include "xfs_sb.h" |
fcafb71b CH |
23 | #include "xfs_ag.h" |
24 | #include "xfs_mount.h" | |
a4fbe6ab | 25 | #include "xfs_inode.h" |
fcafb71b | 26 | #include "xfs_quota.h" |
fcafb71b | 27 | #include "xfs_trans.h" |
06f8e2d6 | 28 | #include "xfs_qm.h" |
fcafb71b CH |
29 | #include <linux/quota.h> |
30 | ||
31 | ||
32 | STATIC int | |
33 | xfs_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 | ||
fcafb71b CH |
45 | STATIC int |
46 | xfs_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; | |
2451337d | 54 | return xfs_qm_scall_getqstat(mp, fqs); |
fcafb71b CH |
55 | } |
56 | ||
5d5e3d57 CS |
57 | STATIC int |
58 | xfs_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; | |
2451337d | 66 | return xfs_qm_scall_getqstatv(mp, fqs); |
5d5e3d57 CS |
67 | } |
68 | ||
fcafb71b CH |
69 | STATIC int |
70 | xfs_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; | |
c7ff91d7 | 80 | if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp)) |
fcafb71b | 81 | return -ENOSYS; |
fcafb71b | 82 | |
ade7ce31 | 83 | if (uflags & FS_QUOTA_UDQ_ACCT) |
fcafb71b | 84 | flags |= XFS_UQUOTA_ACCT; |
ade7ce31 | 85 | if (uflags & FS_QUOTA_PDQ_ACCT) |
fcafb71b | 86 | flags |= XFS_PQUOTA_ACCT; |
ade7ce31 | 87 | if (uflags & FS_QUOTA_GDQ_ACCT) |
fcafb71b | 88 | flags |= XFS_GQUOTA_ACCT; |
ade7ce31 | 89 | if (uflags & FS_QUOTA_UDQ_ENFD) |
fcafb71b | 90 | flags |= XFS_UQUOTA_ENFD; |
83e782e1 CS |
91 | if (uflags & FS_QUOTA_GDQ_ENFD) |
92 | flags |= XFS_GQUOTA_ENFD; | |
93 | if (uflags & FS_QUOTA_PDQ_ENFD) | |
94 | flags |= XFS_PQUOTA_ENFD; | |
fcafb71b CH |
95 | |
96 | switch (op) { | |
97 | case Q_XQUOTAON: | |
2451337d | 98 | return xfs_qm_scall_quotaon(mp, flags); |
fcafb71b CH |
99 | case Q_XQUOTAOFF: |
100 | if (!XFS_IS_QUOTA_ON(mp)) | |
101 | return -EINVAL; | |
2451337d | 102 | return xfs_qm_scall_quotaoff(mp, flags); |
fcafb71b CH |
103 | } |
104 | ||
105 | return -EINVAL; | |
106 | } | |
107 | ||
9da93f9b ES |
108 | STATIC int |
109 | xfs_fs_rm_xquota( | |
110 | struct super_block *sb, | |
111 | unsigned int uflags) | |
112 | { | |
113 | struct xfs_mount *mp = XFS_M(sb); | |
114 | unsigned int flags = 0; | |
2451337d | 115 | |
9da93f9b ES |
116 | if (sb->s_flags & MS_RDONLY) |
117 | return -EROFS; | |
118 | ||
119 | if (XFS_IS_QUOTA_ON(mp)) | |
120 | return -EINVAL; | |
121 | ||
122 | if (uflags & FS_USER_QUOTA) | |
123 | flags |= XFS_DQ_USER; | |
124 | if (uflags & FS_GROUP_QUOTA) | |
125 | flags |= XFS_DQ_GROUP; | |
126 | if (uflags & FS_USER_QUOTA) | |
127 | flags |= XFS_DQ_PROJ; | |
128 | ||
2451337d DC |
129 | return xfs_qm_scall_trunc_qfiles(mp, flags); |
130 | } | |
9da93f9b | 131 | |
fcafb71b | 132 | STATIC int |
b9b2dd36 | 133 | xfs_fs_get_dqblk( |
fcafb71b | 134 | struct super_block *sb, |
74a8a103 | 135 | struct kqid qid, |
fcafb71b CH |
136 | struct fs_disk_quota *fdq) |
137 | { | |
138 | struct xfs_mount *mp = XFS_M(sb); | |
139 | ||
140 | if (!XFS_IS_QUOTA_RUNNING(mp)) | |
141 | return -ENOSYS; | |
142 | if (!XFS_IS_QUOTA_ON(mp)) | |
143 | return -ESRCH; | |
144 | ||
2451337d | 145 | return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid), |
74a8a103 | 146 | xfs_quota_type(qid.type), fdq); |
fcafb71b CH |
147 | } |
148 | ||
149 | STATIC int | |
c472b432 | 150 | xfs_fs_set_dqblk( |
fcafb71b | 151 | struct super_block *sb, |
74a8a103 | 152 | struct kqid qid, |
fcafb71b CH |
153 | struct fs_disk_quota *fdq) |
154 | { | |
155 | struct xfs_mount *mp = XFS_M(sb); | |
156 | ||
157 | if (sb->s_flags & MS_RDONLY) | |
158 | return -EROFS; | |
159 | if (!XFS_IS_QUOTA_RUNNING(mp)) | |
160 | return -ENOSYS; | |
161 | if (!XFS_IS_QUOTA_ON(mp)) | |
162 | return -ESRCH; | |
fcafb71b | 163 | |
2451337d | 164 | return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid), |
74a8a103 | 165 | xfs_quota_type(qid.type), fdq); |
fcafb71b CH |
166 | } |
167 | ||
0d54b217 | 168 | const struct quotactl_ops xfs_quotactl_operations = { |
5d5e3d57 | 169 | .get_xstatev = xfs_fs_get_xstatev, |
fcafb71b CH |
170 | .get_xstate = xfs_fs_get_xstate, |
171 | .set_xstate = xfs_fs_set_xstate, | |
9da93f9b | 172 | .rm_xquota = xfs_fs_rm_xquota, |
b9b2dd36 | 173 | .get_dqblk = xfs_fs_get_dqblk, |
c472b432 | 174 | .set_dqblk = xfs_fs_set_dqblk, |
fcafb71b | 175 | }; |