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_format.h" 20 #include "xfs_log_format.h" 21 #include "xfs_trans_resv.h" 22 #include "xfs_sb.h" 23 #include "xfs_mount.h" 24 #include "xfs_inode.h" 25 #include "xfs_quota.h" 26 #include "xfs_trans.h" 27 #include "xfs_qm.h" 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 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_get_xstatev( 58 struct super_block *sb, 59 struct fs_quota_statv *fqs) 60 { 61 struct xfs_mount *mp = XFS_M(sb); 62 63 if (!XFS_IS_QUOTA_RUNNING(mp)) 64 return -ENOSYS; 65 return xfs_qm_scall_getqstatv(mp, fqs); 66 } 67 68 STATIC int 69 xfs_fs_set_xstate( 70 struct super_block *sb, 71 unsigned int uflags, 72 int op) 73 { 74 struct xfs_mount *mp = XFS_M(sb); 75 unsigned int flags = 0; 76 77 if (sb->s_flags & MS_RDONLY) 78 return -EROFS; 79 if (op != Q_XQUOTARM && !XFS_IS_QUOTA_RUNNING(mp)) 80 return -ENOSYS; 81 82 if (uflags & FS_QUOTA_UDQ_ACCT) 83 flags |= XFS_UQUOTA_ACCT; 84 if (uflags & FS_QUOTA_PDQ_ACCT) 85 flags |= XFS_PQUOTA_ACCT; 86 if (uflags & FS_QUOTA_GDQ_ACCT) 87 flags |= XFS_GQUOTA_ACCT; 88 if (uflags & FS_QUOTA_UDQ_ENFD) 89 flags |= XFS_UQUOTA_ENFD; 90 if (uflags & FS_QUOTA_GDQ_ENFD) 91 flags |= XFS_GQUOTA_ENFD; 92 if (uflags & FS_QUOTA_PDQ_ENFD) 93 flags |= XFS_PQUOTA_ENFD; 94 95 switch (op) { 96 case Q_XQUOTAON: 97 return xfs_qm_scall_quotaon(mp, flags); 98 case Q_XQUOTAOFF: 99 if (!XFS_IS_QUOTA_ON(mp)) 100 return -EINVAL; 101 return xfs_qm_scall_quotaoff(mp, flags); 102 } 103 104 return -EINVAL; 105 } 106 107 STATIC int 108 xfs_fs_rm_xquota( 109 struct super_block *sb, 110 unsigned int uflags) 111 { 112 struct xfs_mount *mp = XFS_M(sb); 113 unsigned int flags = 0; 114 115 if (sb->s_flags & MS_RDONLY) 116 return -EROFS; 117 118 if (XFS_IS_QUOTA_ON(mp)) 119 return -EINVAL; 120 121 if (uflags & FS_USER_QUOTA) 122 flags |= XFS_DQ_USER; 123 if (uflags & FS_GROUP_QUOTA) 124 flags |= XFS_DQ_GROUP; 125 if (uflags & FS_PROJ_QUOTA) 126 flags |= XFS_DQ_PROJ; 127 128 return xfs_qm_scall_trunc_qfiles(mp, flags); 129 } 130 131 STATIC int 132 xfs_fs_get_dqblk( 133 struct super_block *sb, 134 struct kqid qid, 135 struct fs_disk_quota *fdq) 136 { 137 struct xfs_mount *mp = XFS_M(sb); 138 139 if (!XFS_IS_QUOTA_RUNNING(mp)) 140 return -ENOSYS; 141 if (!XFS_IS_QUOTA_ON(mp)) 142 return -ESRCH; 143 144 return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid), 145 xfs_quota_type(qid.type), fdq); 146 } 147 148 STATIC int 149 xfs_fs_set_dqblk( 150 struct super_block *sb, 151 struct kqid qid, 152 struct fs_disk_quota *fdq) 153 { 154 struct xfs_mount *mp = XFS_M(sb); 155 156 if (sb->s_flags & MS_RDONLY) 157 return -EROFS; 158 if (!XFS_IS_QUOTA_RUNNING(mp)) 159 return -ENOSYS; 160 if (!XFS_IS_QUOTA_ON(mp)) 161 return -ESRCH; 162 163 return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid), 164 xfs_quota_type(qid.type), fdq); 165 } 166 167 const struct quotactl_ops xfs_quotactl_operations = { 168 .get_xstatev = xfs_fs_get_xstatev, 169 .get_xstate = xfs_fs_get_xstate, 170 .set_xstate = xfs_fs_set_xstate, 171 .rm_xquota = xfs_fs_rm_xquota, 172 .get_dqblk = xfs_fs_get_dqblk, 173 .set_dqblk = xfs_fs_set_dqblk, 174 }; 175