| 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" | 
|  | 19 | #include "xfs_dmapi.h" | 
|  | 20 | #include "xfs_sb.h" | 
|  | 21 | #include "xfs_inum.h" | 
| Dave Chinner | ed3b4d6 | 2010-05-21 12:07:08 +1000 | [diff] [blame] | 22 | #include "xfs_log.h" | 
| Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 23 | #include "xfs_ag.h" | 
|  | 24 | #include "xfs_mount.h" | 
|  | 25 | #include "xfs_quota.h" | 
| Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 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 | 
| Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 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; | 
| Ryota Yamauchi | c7ff91d | 2009-10-30 09:27:44 +0100 | [diff] [blame] | 69 | if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp)) | 
| Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 70 | return -ENOSYS; | 
| Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 71 |  | 
|  | 72 | if (uflags & XFS_QUOTA_UDQ_ACCT) | 
|  | 73 | flags |= XFS_UQUOTA_ACCT; | 
|  | 74 | if (uflags & XFS_QUOTA_PDQ_ACCT) | 
|  | 75 | flags |= XFS_PQUOTA_ACCT; | 
|  | 76 | if (uflags & XFS_QUOTA_GDQ_ACCT) | 
|  | 77 | flags |= XFS_GQUOTA_ACCT; | 
|  | 78 | if (uflags & XFS_QUOTA_UDQ_ENFD) | 
|  | 79 | flags |= XFS_UQUOTA_ENFD; | 
|  | 80 | if (uflags & (XFS_QUOTA_PDQ_ENFD|XFS_QUOTA_GDQ_ENFD)) | 
|  | 81 | flags |= XFS_OQUOTA_ENFD; | 
|  | 82 |  | 
|  | 83 | switch (op) { | 
|  | 84 | case Q_XQUOTAON: | 
|  | 85 | return -xfs_qm_scall_quotaon(mp, flags); | 
|  | 86 | case Q_XQUOTAOFF: | 
|  | 87 | if (!XFS_IS_QUOTA_ON(mp)) | 
|  | 88 | return -EINVAL; | 
|  | 89 | return -xfs_qm_scall_quotaoff(mp, flags); | 
|  | 90 | case Q_XQUOTARM: | 
|  | 91 | if (XFS_IS_QUOTA_ON(mp)) | 
|  | 92 | return -EINVAL; | 
|  | 93 | return -xfs_qm_scall_trunc_qfiles(mp, flags); | 
|  | 94 | } | 
|  | 95 |  | 
|  | 96 | return -EINVAL; | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 | STATIC int | 
| Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 100 | xfs_fs_get_dqblk( | 
| Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 101 | struct super_block	*sb, | 
|  | 102 | int			type, | 
|  | 103 | qid_t			id, | 
|  | 104 | struct fs_disk_quota	*fdq) | 
|  | 105 | { | 
|  | 106 | struct xfs_mount	*mp = XFS_M(sb); | 
|  | 107 |  | 
|  | 108 | if (!XFS_IS_QUOTA_RUNNING(mp)) | 
|  | 109 | return -ENOSYS; | 
|  | 110 | if (!XFS_IS_QUOTA_ON(mp)) | 
|  | 111 | return -ESRCH; | 
|  | 112 |  | 
|  | 113 | return -xfs_qm_scall_getquota(mp, id, xfs_quota_type(type), fdq); | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | STATIC int | 
| Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 117 | xfs_fs_set_dqblk( | 
| Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 118 | struct super_block	*sb, | 
|  | 119 | int			type, | 
|  | 120 | qid_t			id, | 
|  | 121 | struct fs_disk_quota	*fdq) | 
|  | 122 | { | 
|  | 123 | struct xfs_mount	*mp = XFS_M(sb); | 
|  | 124 |  | 
|  | 125 | if (sb->s_flags & MS_RDONLY) | 
|  | 126 | return -EROFS; | 
|  | 127 | if (!XFS_IS_QUOTA_RUNNING(mp)) | 
|  | 128 | return -ENOSYS; | 
|  | 129 | if (!XFS_IS_QUOTA_ON(mp)) | 
|  | 130 | return -ESRCH; | 
| Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 131 |  | 
|  | 132 | return -xfs_qm_scall_setqlim(mp, id, xfs_quota_type(type), fdq); | 
|  | 133 | } | 
|  | 134 |  | 
| Alexey Dobriyan | 0d54b21 | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 135 | const struct quotactl_ops xfs_quotactl_operations = { | 
| Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 136 | .get_xstate		= xfs_fs_get_xstate, | 
|  | 137 | .set_xstate		= xfs_fs_set_xstate, | 
| Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 138 | .get_dqblk		= xfs_fs_get_dqblk, | 
| Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 139 | .set_dqblk		= xfs_fs_set_dqblk, | 
| Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 140 | }; |