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" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 19 | #include "xfs_sb.h" |
Dave Chinner | ed3b4d6 | 2010-05-21 12:07:08 +1000 | [diff] [blame] | 20 | #include "xfs_log.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 21 | #include "xfs_ag.h" |
| 22 | #include "xfs_mount.h" |
| 23 | #include "xfs_quota.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 24 | #include "xfs_trans.h" |
| 25 | #include "xfs_bmap_btree.h" |
| 26 | #include "xfs_inode.h" |
Alex Elder | 06f8e2d | 2011-08-12 13:57:55 -0500 | [diff] [blame] | 27 | #include "xfs_qm.h" |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 28 | #include <linux/quota.h> |
| 29 | |
| 30 | |
| 31 | STATIC int |
| 32 | xfs_quota_type(int type) |
| 33 | { |
| 34 | switch (type) { |
| 35 | case USRQUOTA: |
| 36 | return XFS_DQ_USER; |
| 37 | case GRPQUOTA: |
| 38 | return XFS_DQ_GROUP; |
| 39 | default: |
| 40 | return XFS_DQ_PROJ; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | STATIC int |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 45 | xfs_fs_get_xstate( |
| 46 | struct super_block *sb, |
| 47 | struct fs_quota_stat *fqs) |
| 48 | { |
| 49 | struct xfs_mount *mp = XFS_M(sb); |
| 50 | |
| 51 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 52 | return -ENOSYS; |
| 53 | return -xfs_qm_scall_getqstat(mp, fqs); |
| 54 | } |
| 55 | |
| 56 | STATIC int |
| 57 | xfs_fs_set_xstate( |
| 58 | struct super_block *sb, |
| 59 | unsigned int uflags, |
| 60 | int op) |
| 61 | { |
| 62 | struct xfs_mount *mp = XFS_M(sb); |
| 63 | unsigned int flags = 0; |
| 64 | |
| 65 | if (sb->s_flags & MS_RDONLY) |
| 66 | return -EROFS; |
Ryota Yamauchi | c7ff91d | 2009-10-30 09:27:44 +0100 | [diff] [blame] | 67 | if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp)) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 68 | return -ENOSYS; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 69 | |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 70 | if (uflags & FS_QUOTA_UDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 71 | flags |= XFS_UQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 72 | if (uflags & FS_QUOTA_PDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 73 | flags |= XFS_PQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 74 | if (uflags & FS_QUOTA_GDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 75 | flags |= XFS_GQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 76 | if (uflags & FS_QUOTA_UDQ_ENFD) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 77 | flags |= XFS_UQUOTA_ENFD; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 78 | if (uflags & (FS_QUOTA_PDQ_ENFD|FS_QUOTA_GDQ_ENFD)) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 79 | flags |= XFS_OQUOTA_ENFD; |
| 80 | |
| 81 | switch (op) { |
| 82 | case Q_XQUOTAON: |
| 83 | return -xfs_qm_scall_quotaon(mp, flags); |
| 84 | case Q_XQUOTAOFF: |
| 85 | if (!XFS_IS_QUOTA_ON(mp)) |
| 86 | return -EINVAL; |
| 87 | return -xfs_qm_scall_quotaoff(mp, flags); |
| 88 | case Q_XQUOTARM: |
| 89 | if (XFS_IS_QUOTA_ON(mp)) |
| 90 | return -EINVAL; |
| 91 | return -xfs_qm_scall_trunc_qfiles(mp, flags); |
| 92 | } |
| 93 | |
| 94 | return -EINVAL; |
| 95 | } |
| 96 | |
| 97 | STATIC int |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 98 | xfs_fs_get_dqblk( |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 99 | struct super_block *sb, |
| 100 | int type, |
| 101 | qid_t id, |
| 102 | struct fs_disk_quota *fdq) |
| 103 | { |
| 104 | struct xfs_mount *mp = XFS_M(sb); |
| 105 | |
| 106 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 107 | return -ENOSYS; |
| 108 | if (!XFS_IS_QUOTA_ON(mp)) |
| 109 | return -ESRCH; |
| 110 | |
| 111 | return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq); |
| 112 | } |
| 113 | |
| 114 | STATIC int |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 115 | xfs_fs_set_dqblk( |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 116 | struct super_block *sb, |
| 117 | int type, |
| 118 | qid_t id, |
| 119 | struct fs_disk_quota *fdq) |
| 120 | { |
| 121 | struct xfs_mount *mp = XFS_M(sb); |
| 122 | |
| 123 | if (sb->s_flags & MS_RDONLY) |
| 124 | return -EROFS; |
| 125 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 126 | return -ENOSYS; |
| 127 | if (!XFS_IS_QUOTA_ON(mp)) |
| 128 | return -ESRCH; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 129 | |
| 130 | return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq); |
| 131 | } |
| 132 | |
Alexey Dobriyan | 0d54b21 | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 133 | const struct quotactl_ops xfs_quotactl_operations = { |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 134 | .get_xstate = xfs_fs_get_xstate, |
| 135 | .set_xstate = xfs_fs_set_xstate, |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 136 | .get_dqblk = xfs_fs_get_dqblk, |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 137 | .set_dqblk = xfs_fs_set_dqblk, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 138 | }; |