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" |
Dave Chinner | 7fd36c4 | 2013-08-12 20:49:32 +1000 | [diff] [blame] | 22 | #include "xfs_sb.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 23 | #include "xfs_ag.h" |
| 24 | #include "xfs_mount.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 25 | #include "xfs_inode.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 26 | #include "xfs_quota.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 27 | #include "xfs_trans.h" |
Alex Elder | 06f8e2d | 2011-08-12 13:57:55 -0500 | [diff] [blame] | 28 | #include "xfs_qm.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 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 | |
| 45 | STATIC int |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 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; |
| 54 | return -xfs_qm_scall_getqstat(mp, fqs); |
| 55 | } |
| 56 | |
| 57 | STATIC int |
Chandra Seetharaman | 5d5e3d5 | 2013-08-06 17:27:08 -0500 | [diff] [blame] | 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; |
| 66 | return -xfs_qm_scall_getqstatv(mp, fqs); |
| 67 | } |
| 68 | |
| 69 | STATIC int |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 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; |
Ryota Yamauchi | c7ff91d | 2009-10-30 09:27:44 +0100 | [diff] [blame] | 80 | if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp)) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 81 | return -ENOSYS; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 82 | |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 83 | if (uflags & FS_QUOTA_UDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 84 | flags |= XFS_UQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 85 | if (uflags & FS_QUOTA_PDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 86 | flags |= XFS_PQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 87 | if (uflags & FS_QUOTA_GDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 88 | flags |= XFS_GQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 89 | if (uflags & FS_QUOTA_UDQ_ENFD) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 90 | flags |= XFS_UQUOTA_ENFD; |
Chandra Seetharaman | 83e782e | 2013-06-27 17:25:10 -0500 | [diff] [blame] | 91 | if (uflags & FS_QUOTA_GDQ_ENFD) |
| 92 | flags |= XFS_GQUOTA_ENFD; |
| 93 | if (uflags & FS_QUOTA_PDQ_ENFD) |
| 94 | flags |= XFS_PQUOTA_ENFD; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 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 | |
| 112 | STATIC int |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 113 | xfs_fs_get_dqblk( |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 114 | struct super_block *sb, |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 115 | struct kqid qid, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 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 | |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 125 | return -xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid), |
| 126 | xfs_quota_type(qid.type), fdq); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | STATIC int |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 130 | xfs_fs_set_dqblk( |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 131 | struct super_block *sb, |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 132 | struct kqid qid, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 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; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 143 | |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 144 | return -xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid), |
| 145 | xfs_quota_type(qid.type), fdq); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Alexey Dobriyan | 0d54b21 | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 148 | const struct quotactl_ops xfs_quotactl_operations = { |
Chandra Seetharaman | 5d5e3d5 | 2013-08-06 17:27:08 -0500 | [diff] [blame] | 149 | .get_xstatev = xfs_fs_get_xstatev, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 150 | .get_xstate = xfs_fs_get_xstate, |
| 151 | .set_xstate = xfs_fs_set_xstate, |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 152 | .get_dqblk = xfs_fs_get_dqblk, |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 153 | .set_dqblk = xfs_fs_set_dqblk, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 154 | }; |