Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 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" |
Dave Chinner | 6ca1c90 | 2013-08-12 20:49:26 +1000 | [diff] [blame] | 19 | #include "xfs_format.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 20 | #include "xfs_log_format.h" |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 21 | #include "xfs_trans_resv.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 22 | #include "xfs_mount.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 23 | #include "xfs_inode.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 24 | #include "xfs_quota.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 25 | #include "xfs_trans.h" |
Alex Elder | 06f8e2d | 2011-08-12 13:57:55 -0500 | [diff] [blame] | 26 | #include "xfs_qm.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 27 | #include <linux/quota.h> |
| 28 | |
| 29 | |
| 30 | STATIC int |
| 31 | xfs_quota_type(int type) |
| 32 | { |
| 33 | switch (type) { |
| 34 | case USRQUOTA: |
| 35 | return XFS_DQ_USER; |
| 36 | case GRPQUOTA: |
| 37 | return XFS_DQ_GROUP; |
| 38 | default: |
| 39 | return XFS_DQ_PROJ; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | STATIC int |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 44 | xfs_fs_get_xstate( |
| 45 | struct super_block *sb, |
| 46 | struct fs_quota_stat *fqs) |
| 47 | { |
| 48 | struct xfs_mount *mp = XFS_M(sb); |
| 49 | |
| 50 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 51 | return -ENOSYS; |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 52 | return xfs_qm_scall_getqstat(mp, fqs); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | STATIC int |
Chandra Seetharaman | 5d5e3d5 | 2013-08-06 17:27:08 -0500 | [diff] [blame] | 56 | xfs_fs_get_xstatev( |
| 57 | struct super_block *sb, |
| 58 | struct fs_quota_statv *fqs) |
| 59 | { |
| 60 | struct xfs_mount *mp = XFS_M(sb); |
| 61 | |
| 62 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 63 | return -ENOSYS; |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 64 | return xfs_qm_scall_getqstatv(mp, fqs); |
Chandra Seetharaman | 5d5e3d5 | 2013-08-06 17:27:08 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Jan Kara | 38e478c | 2014-10-08 15:56:21 +0200 | [diff] [blame] | 67 | static unsigned int |
| 68 | xfs_quota_flags(unsigned int uflags) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 69 | { |
Jan Kara | 38e478c | 2014-10-08 15:56:21 +0200 | [diff] [blame] | 70 | unsigned int flags = 0; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 71 | |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 72 | if (uflags & FS_QUOTA_UDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 73 | flags |= XFS_UQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 74 | if (uflags & FS_QUOTA_PDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 75 | flags |= XFS_PQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 76 | if (uflags & FS_QUOTA_GDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 77 | flags |= XFS_GQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 78 | if (uflags & FS_QUOTA_UDQ_ENFD) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 79 | flags |= XFS_UQUOTA_ENFD; |
Chandra Seetharaman | 83e782e | 2013-06-27 17:25:10 -0500 | [diff] [blame] | 80 | if (uflags & FS_QUOTA_GDQ_ENFD) |
| 81 | flags |= XFS_GQUOTA_ENFD; |
| 82 | if (uflags & FS_QUOTA_PDQ_ENFD) |
| 83 | flags |= XFS_PQUOTA_ENFD; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 84 | |
Jan Kara | 38e478c | 2014-10-08 15:56:21 +0200 | [diff] [blame] | 85 | return flags; |
| 86 | } |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 87 | |
Jan Kara | 38e478c | 2014-10-08 15:56:21 +0200 | [diff] [blame] | 88 | STATIC int |
| 89 | xfs_quota_enable( |
| 90 | struct super_block *sb, |
| 91 | unsigned int uflags) |
| 92 | { |
| 93 | struct xfs_mount *mp = XFS_M(sb); |
| 94 | |
| 95 | if (sb->s_flags & MS_RDONLY) |
| 96 | return -EROFS; |
| 97 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 98 | return -ENOSYS; |
| 99 | |
| 100 | return xfs_qm_scall_quotaon(mp, xfs_quota_flags(uflags)); |
| 101 | } |
| 102 | |
| 103 | STATIC int |
| 104 | xfs_quota_disable( |
| 105 | struct super_block *sb, |
| 106 | unsigned int uflags) |
| 107 | { |
| 108 | struct xfs_mount *mp = XFS_M(sb); |
| 109 | |
| 110 | if (sb->s_flags & MS_RDONLY) |
| 111 | return -EROFS; |
| 112 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 113 | return -ENOSYS; |
| 114 | if (!XFS_IS_QUOTA_ON(mp)) |
| 115 | return -EINVAL; |
| 116 | |
| 117 | return xfs_qm_scall_quotaoff(mp, xfs_quota_flags(uflags)); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | STATIC int |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 121 | xfs_fs_rm_xquota( |
| 122 | struct super_block *sb, |
| 123 | unsigned int uflags) |
| 124 | { |
| 125 | struct xfs_mount *mp = XFS_M(sb); |
| 126 | unsigned int flags = 0; |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 127 | |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 128 | if (sb->s_flags & MS_RDONLY) |
| 129 | return -EROFS; |
| 130 | |
| 131 | if (XFS_IS_QUOTA_ON(mp)) |
| 132 | return -EINVAL; |
| 133 | |
| 134 | if (uflags & FS_USER_QUOTA) |
| 135 | flags |= XFS_DQ_USER; |
| 136 | if (uflags & FS_GROUP_QUOTA) |
| 137 | flags |= XFS_DQ_GROUP; |
Jie Liu | 74dc93a | 2014-07-24 21:27:17 +1000 | [diff] [blame] | 138 | if (uflags & FS_PROJ_QUOTA) |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 139 | flags |= XFS_DQ_PROJ; |
| 140 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 141 | return xfs_qm_scall_trunc_qfiles(mp, flags); |
| 142 | } |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 143 | |
| 144 | STATIC int |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 145 | xfs_fs_get_dqblk( |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 146 | struct super_block *sb, |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 147 | struct kqid qid, |
Jan Kara | 14bf61f | 2014-10-09 16:03:13 +0200 | [diff] [blame] | 148 | struct qc_dqblk *qdq) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 149 | { |
| 150 | struct xfs_mount *mp = XFS_M(sb); |
| 151 | |
| 152 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 153 | return -ENOSYS; |
| 154 | if (!XFS_IS_QUOTA_ON(mp)) |
| 155 | return -ESRCH; |
| 156 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 157 | return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid), |
Jan Kara | 14bf61f | 2014-10-09 16:03:13 +0200 | [diff] [blame] | 158 | xfs_quota_type(qid.type), qdq); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | STATIC int |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 162 | xfs_fs_set_dqblk( |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 163 | struct super_block *sb, |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 164 | struct kqid qid, |
Jan Kara | 14bf61f | 2014-10-09 16:03:13 +0200 | [diff] [blame] | 165 | struct qc_dqblk *qdq) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 166 | { |
| 167 | struct xfs_mount *mp = XFS_M(sb); |
| 168 | |
| 169 | if (sb->s_flags & MS_RDONLY) |
| 170 | return -EROFS; |
| 171 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 172 | return -ENOSYS; |
| 173 | if (!XFS_IS_QUOTA_ON(mp)) |
| 174 | return -ESRCH; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 175 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 176 | return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid), |
Jan Kara | 14bf61f | 2014-10-09 16:03:13 +0200 | [diff] [blame] | 177 | xfs_quota_type(qid.type), qdq); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 178 | } |
| 179 | |
Alexey Dobriyan | 0d54b21 | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 180 | const struct quotactl_ops xfs_quotactl_operations = { |
Chandra Seetharaman | 5d5e3d5 | 2013-08-06 17:27:08 -0500 | [diff] [blame] | 181 | .get_xstatev = xfs_fs_get_xstatev, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 182 | .get_xstate = xfs_fs_get_xstate, |
Jan Kara | 38e478c | 2014-10-08 15:56:21 +0200 | [diff] [blame] | 183 | .quota_enable = xfs_quota_enable, |
| 184 | .quota_disable = xfs_quota_disable, |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 185 | .rm_xquota = xfs_fs_rm_xquota, |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 186 | .get_dqblk = xfs_fs_get_dqblk, |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 187 | .set_dqblk = xfs_fs_set_dqblk, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 188 | }; |