quota: clean up Q_XQUOTASYNC
[linux-2.6.git] / fs / xfs / linux-2.6 / xfs_quotaops.c
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_dmapi.h"
20 #include "xfs_sb.h"
21 #include "xfs_inum.h"
22 #include "xfs_ag.h"
23 #include "xfs_mount.h"
24 #include "xfs_quota.h"
25 #include "xfs_log.h"
26 #include "xfs_trans.h"
27 #include "xfs_bmap_btree.h"
28 #include "xfs_inode.h"
29 #include "quota/xfs_qm.h"
30 #include <linux/quota.h>
31
32
33 STATIC int
34 xfs_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
46 STATIC int
47 xfs_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
58 STATIC int
59 xfs_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;
69         if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp))
70                 return -ENOSYS;
71         if (!capable(CAP_SYS_ADMIN))
72                 return -EPERM;
73
74         if (uflags & XFS_QUOTA_UDQ_ACCT)
75                 flags |= XFS_UQUOTA_ACCT;
76         if (uflags & XFS_QUOTA_PDQ_ACCT)
77                 flags |= XFS_PQUOTA_ACCT;
78         if (uflags & XFS_QUOTA_GDQ_ACCT)
79                 flags |= XFS_GQUOTA_ACCT;
80         if (uflags & XFS_QUOTA_UDQ_ENFD)
81                 flags |= XFS_UQUOTA_ENFD;
82         if (uflags & (XFS_QUOTA_PDQ_ENFD|XFS_QUOTA_GDQ_ENFD))
83                 flags |= XFS_OQUOTA_ENFD;
84
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
101 STATIC int
102 xfs_fs_get_xquota(
103         struct super_block      *sb,
104         int                     type,
105         qid_t                   id,
106         struct fs_disk_quota    *fdq)
107 {
108         struct xfs_mount        *mp = XFS_M(sb);
109
110         if (!XFS_IS_QUOTA_RUNNING(mp))
111                 return -ENOSYS;
112         if (!XFS_IS_QUOTA_ON(mp))
113                 return -ESRCH;
114
115         return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq);
116 }
117
118 STATIC int
119 xfs_fs_set_xquota(
120         struct super_block      *sb,
121         int                     type,
122         qid_t                   id,
123         struct fs_disk_quota    *fdq)
124 {
125         struct xfs_mount        *mp = XFS_M(sb);
126
127         if (sb->s_flags & MS_RDONLY)
128                 return -EROFS;
129         if (!XFS_IS_QUOTA_RUNNING(mp))
130                 return -ENOSYS;
131         if (!XFS_IS_QUOTA_ON(mp))
132                 return -ESRCH;
133         if (!capable(CAP_SYS_ADMIN))
134                 return -EPERM;
135
136         return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq);
137 }
138
139 const struct quotactl_ops xfs_quotactl_operations = {
140         .get_xstate             = xfs_fs_get_xstate,
141         .set_xstate             = xfs_fs_set_xstate,
142         .get_xquota             = xfs_fs_get_xquota,
143         .set_xquota             = xfs_fs_set_xquota,
144 };