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 | |
| 67 | STATIC int |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 68 | xfs_fs_set_xstate( |
| 69 | struct super_block *sb, |
| 70 | unsigned int uflags, |
| 71 | int op) |
| 72 | { |
| 73 | struct xfs_mount *mp = XFS_M(sb); |
| 74 | unsigned int flags = 0; |
| 75 | |
| 76 | if (sb->s_flags & MS_RDONLY) |
| 77 | return -EROFS; |
Ryota Yamauchi | c7ff91d | 2009-10-30 09:27:44 +0100 | [diff] [blame] | 78 | if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp)) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 79 | return -ENOSYS; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 80 | |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 81 | if (uflags & FS_QUOTA_UDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 82 | flags |= XFS_UQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 83 | if (uflags & FS_QUOTA_PDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 84 | flags |= XFS_PQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 85 | if (uflags & FS_QUOTA_GDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 86 | flags |= XFS_GQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 87 | if (uflags & FS_QUOTA_UDQ_ENFD) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 88 | flags |= XFS_UQUOTA_ENFD; |
Chandra Seetharaman | 83e782e | 2013-06-27 17:25:10 -0500 | [diff] [blame] | 89 | if (uflags & FS_QUOTA_GDQ_ENFD) |
| 90 | flags |= XFS_GQUOTA_ENFD; |
| 91 | if (uflags & FS_QUOTA_PDQ_ENFD) |
| 92 | flags |= XFS_PQUOTA_ENFD; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 93 | |
| 94 | switch (op) { |
| 95 | case Q_XQUOTAON: |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 96 | return xfs_qm_scall_quotaon(mp, flags); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 97 | case Q_XQUOTAOFF: |
| 98 | if (!XFS_IS_QUOTA_ON(mp)) |
| 99 | return -EINVAL; |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 100 | return xfs_qm_scall_quotaoff(mp, flags); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | return -EINVAL; |
| 104 | } |
| 105 | |
| 106 | STATIC int |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 107 | xfs_fs_rm_xquota( |
| 108 | struct super_block *sb, |
| 109 | unsigned int uflags) |
| 110 | { |
| 111 | struct xfs_mount *mp = XFS_M(sb); |
| 112 | unsigned int flags = 0; |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 113 | |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 114 | if (sb->s_flags & MS_RDONLY) |
| 115 | return -EROFS; |
| 116 | |
| 117 | if (XFS_IS_QUOTA_ON(mp)) |
| 118 | return -EINVAL; |
| 119 | |
| 120 | if (uflags & FS_USER_QUOTA) |
| 121 | flags |= XFS_DQ_USER; |
| 122 | if (uflags & FS_GROUP_QUOTA) |
| 123 | flags |= XFS_DQ_GROUP; |
Jie Liu | 74dc93a | 2014-07-24 21:27:17 +1000 | [diff] [blame] | 124 | if (uflags & FS_PROJ_QUOTA) |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 125 | flags |= XFS_DQ_PROJ; |
| 126 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 127 | return xfs_qm_scall_trunc_qfiles(mp, flags); |
| 128 | } |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 129 | |
| 130 | STATIC int |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 131 | xfs_fs_get_dqblk( |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 132 | struct super_block *sb, |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 133 | struct kqid qid, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 134 | struct fs_disk_quota *fdq) |
| 135 | { |
| 136 | struct xfs_mount *mp = XFS_M(sb); |
| 137 | |
| 138 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 139 | return -ENOSYS; |
| 140 | if (!XFS_IS_QUOTA_ON(mp)) |
| 141 | return -ESRCH; |
| 142 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 143 | return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid), |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 144 | xfs_quota_type(qid.type), fdq); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | STATIC int |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 148 | xfs_fs_set_dqblk( |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 149 | struct super_block *sb, |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 150 | struct kqid qid, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 151 | struct fs_disk_quota *fdq) |
| 152 | { |
| 153 | struct xfs_mount *mp = XFS_M(sb); |
| 154 | |
| 155 | if (sb->s_flags & MS_RDONLY) |
| 156 | return -EROFS; |
| 157 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 158 | return -ENOSYS; |
| 159 | if (!XFS_IS_QUOTA_ON(mp)) |
| 160 | return -ESRCH; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 161 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 162 | return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid), |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 163 | xfs_quota_type(qid.type), fdq); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Alexey Dobriyan | 0d54b21 | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 166 | const struct quotactl_ops xfs_quotactl_operations = { |
Chandra Seetharaman | 5d5e3d5 | 2013-08-06 17:27:08 -0500 | [diff] [blame] | 167 | .get_xstatev = xfs_fs_get_xstatev, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 168 | .get_xstate = xfs_fs_get_xstate, |
| 169 | .set_xstate = xfs_fs_set_xstate, |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 170 | .rm_xquota = xfs_fs_rm_xquota, |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 171 | .get_dqblk = xfs_fs_get_dqblk, |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 172 | .set_dqblk = xfs_fs_set_dqblk, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 173 | }; |