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" |
Jan Kara | 5d3684c | 2014-11-19 12:03:59 +0100 | [diff] [blame] | 26 | #include "xfs_trace.h" |
| 27 | #include "xfs_icache.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 | |
Jan Kara | 5d3684c | 2014-11-19 12:03:59 +0100 | [diff] [blame] | 32 | static void |
| 33 | xfs_qm_fill_state( |
| 34 | struct qc_type_state *tstate, |
| 35 | struct xfs_mount *mp, |
| 36 | struct xfs_inode *ip, |
| 37 | xfs_ino_t ino) |
| 38 | { |
| 39 | struct xfs_quotainfo *q = mp->m_quotainfo; |
| 40 | bool tempqip = false; |
| 41 | |
| 42 | tstate->ino = ino; |
| 43 | if (!ip && ino == NULLFSINO) |
| 44 | return; |
| 45 | if (!ip) { |
| 46 | if (xfs_iget(mp, NULL, ino, 0, 0, &ip)) |
| 47 | return; |
| 48 | tempqip = true; |
| 49 | } |
| 50 | tstate->flags |= QCI_SYSFILE; |
| 51 | tstate->blocks = ip->i_d.di_nblocks; |
| 52 | tstate->nextents = ip->i_d.di_nextents; |
| 53 | tstate->spc_timelimit = q->qi_btimelimit; |
| 54 | tstate->ino_timelimit = q->qi_itimelimit; |
| 55 | tstate->rt_spc_timelimit = q->qi_rtbtimelimit; |
| 56 | tstate->spc_warnlimit = q->qi_bwarnlimit; |
| 57 | tstate->ino_warnlimit = q->qi_iwarnlimit; |
| 58 | tstate->rt_spc_warnlimit = q->qi_rtbwarnlimit; |
| 59 | if (tempqip) |
| 60 | IRELE(ip); |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Return quota status information, such as enforcements, quota file inode |
| 65 | * numbers etc. |
| 66 | */ |
| 67 | static int |
| 68 | xfs_fs_get_quota_state( |
| 69 | struct super_block *sb, |
| 70 | struct qc_state *state) |
| 71 | { |
| 72 | struct xfs_mount *mp = XFS_M(sb); |
| 73 | struct xfs_quotainfo *q = mp->m_quotainfo; |
| 74 | |
| 75 | memset(state, 0, sizeof(*state)); |
| 76 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 77 | return 0; |
| 78 | state->s_incoredqs = q->qi_dquots; |
| 79 | if (XFS_IS_UQUOTA_RUNNING(mp)) |
| 80 | state->s_state[USRQUOTA].flags |= QCI_ACCT_ENABLED; |
| 81 | if (XFS_IS_UQUOTA_ENFORCED(mp)) |
| 82 | state->s_state[USRQUOTA].flags |= QCI_LIMITS_ENFORCED; |
| 83 | if (XFS_IS_GQUOTA_RUNNING(mp)) |
| 84 | state->s_state[GRPQUOTA].flags |= QCI_ACCT_ENABLED; |
| 85 | if (XFS_IS_GQUOTA_ENFORCED(mp)) |
| 86 | state->s_state[GRPQUOTA].flags |= QCI_LIMITS_ENFORCED; |
| 87 | if (XFS_IS_PQUOTA_RUNNING(mp)) |
| 88 | state->s_state[PRJQUOTA].flags |= QCI_ACCT_ENABLED; |
| 89 | if (XFS_IS_PQUOTA_ENFORCED(mp)) |
| 90 | state->s_state[PRJQUOTA].flags |= QCI_LIMITS_ENFORCED; |
| 91 | |
| 92 | xfs_qm_fill_state(&state->s_state[USRQUOTA], mp, q->qi_uquotaip, |
| 93 | mp->m_sb.sb_uquotino); |
| 94 | xfs_qm_fill_state(&state->s_state[GRPQUOTA], mp, q->qi_gquotaip, |
| 95 | mp->m_sb.sb_gquotino); |
| 96 | xfs_qm_fill_state(&state->s_state[PRJQUOTA], mp, q->qi_pquotaip, |
| 97 | mp->m_sb.sb_pquotino); |
| 98 | return 0; |
| 99 | } |
| 100 | |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 101 | STATIC int |
| 102 | xfs_quota_type(int type) |
| 103 | { |
| 104 | switch (type) { |
| 105 | case USRQUOTA: |
| 106 | return XFS_DQ_USER; |
| 107 | case GRPQUOTA: |
| 108 | return XFS_DQ_GROUP; |
| 109 | default: |
| 110 | return XFS_DQ_PROJ; |
| 111 | } |
| 112 | } |
| 113 | |
Jan Kara | c14cad9 | 2014-12-16 13:07:45 +0100 | [diff] [blame] | 114 | #define XFS_QC_SETINFO_MASK (QC_TIMER_MASK | QC_WARNS_MASK) |
| 115 | |
| 116 | /* |
| 117 | * Adjust quota timers & warnings |
| 118 | */ |
| 119 | static int |
| 120 | xfs_fs_set_info( |
| 121 | struct super_block *sb, |
| 122 | int type, |
| 123 | struct qc_info *info) |
| 124 | { |
| 125 | struct xfs_mount *mp = XFS_M(sb); |
| 126 | struct qc_dqblk newlim; |
| 127 | |
| 128 | if (sb->s_flags & MS_RDONLY) |
| 129 | return -EROFS; |
| 130 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 131 | return -ENOSYS; |
| 132 | if (!XFS_IS_QUOTA_ON(mp)) |
| 133 | return -ESRCH; |
| 134 | if (info->i_fieldmask & ~XFS_QC_SETINFO_MASK) |
| 135 | return -EINVAL; |
| 136 | if ((info->i_fieldmask & XFS_QC_SETINFO_MASK) == 0) |
| 137 | return 0; |
| 138 | |
| 139 | newlim.d_fieldmask = info->i_fieldmask; |
| 140 | newlim.d_spc_timer = info->i_spc_timelimit; |
| 141 | newlim.d_ino_timer = info->i_ino_timelimit; |
| 142 | newlim.d_rt_spc_timer = info->i_rt_spc_timelimit; |
| 143 | newlim.d_ino_warns = info->i_ino_warnlimit; |
| 144 | newlim.d_spc_warns = info->i_spc_warnlimit; |
| 145 | newlim.d_rt_spc_warns = info->i_rt_spc_warnlimit; |
| 146 | |
| 147 | return xfs_qm_scall_setqlim(mp, 0, xfs_quota_type(type), &newlim); |
| 148 | } |
| 149 | |
Jan Kara | 38e478c | 2014-10-08 15:56:21 +0200 | [diff] [blame] | 150 | static unsigned int |
| 151 | xfs_quota_flags(unsigned int uflags) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 152 | { |
Jan Kara | 38e478c | 2014-10-08 15:56:21 +0200 | [diff] [blame] | 153 | unsigned int flags = 0; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 154 | |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 155 | if (uflags & FS_QUOTA_UDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 156 | flags |= XFS_UQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 157 | if (uflags & FS_QUOTA_PDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 158 | flags |= XFS_PQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 159 | if (uflags & FS_QUOTA_GDQ_ACCT) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 160 | flags |= XFS_GQUOTA_ACCT; |
Christoph Hellwig | ade7ce3 | 2010-06-04 10:56:01 +0200 | [diff] [blame] | 161 | if (uflags & FS_QUOTA_UDQ_ENFD) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 162 | flags |= XFS_UQUOTA_ENFD; |
Chandra Seetharaman | 83e782e | 2013-06-27 17:25:10 -0500 | [diff] [blame] | 163 | if (uflags & FS_QUOTA_GDQ_ENFD) |
| 164 | flags |= XFS_GQUOTA_ENFD; |
| 165 | if (uflags & FS_QUOTA_PDQ_ENFD) |
| 166 | flags |= XFS_PQUOTA_ENFD; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 167 | |
Jan Kara | 38e478c | 2014-10-08 15:56:21 +0200 | [diff] [blame] | 168 | return flags; |
| 169 | } |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 170 | |
Jan Kara | 38e478c | 2014-10-08 15:56:21 +0200 | [diff] [blame] | 171 | STATIC int |
| 172 | xfs_quota_enable( |
| 173 | struct super_block *sb, |
| 174 | unsigned int uflags) |
| 175 | { |
| 176 | struct xfs_mount *mp = XFS_M(sb); |
| 177 | |
| 178 | if (sb->s_flags & MS_RDONLY) |
| 179 | return -EROFS; |
| 180 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 181 | return -ENOSYS; |
| 182 | |
| 183 | return xfs_qm_scall_quotaon(mp, xfs_quota_flags(uflags)); |
| 184 | } |
| 185 | |
| 186 | STATIC int |
| 187 | xfs_quota_disable( |
| 188 | struct super_block *sb, |
| 189 | unsigned int uflags) |
| 190 | { |
| 191 | struct xfs_mount *mp = XFS_M(sb); |
| 192 | |
| 193 | if (sb->s_flags & MS_RDONLY) |
| 194 | return -EROFS; |
| 195 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 196 | return -ENOSYS; |
| 197 | if (!XFS_IS_QUOTA_ON(mp)) |
| 198 | return -EINVAL; |
| 199 | |
| 200 | return xfs_qm_scall_quotaoff(mp, xfs_quota_flags(uflags)); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | STATIC int |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 204 | xfs_fs_rm_xquota( |
| 205 | struct super_block *sb, |
| 206 | unsigned int uflags) |
| 207 | { |
| 208 | struct xfs_mount *mp = XFS_M(sb); |
| 209 | unsigned int flags = 0; |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 210 | |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 211 | if (sb->s_flags & MS_RDONLY) |
| 212 | return -EROFS; |
| 213 | |
| 214 | if (XFS_IS_QUOTA_ON(mp)) |
| 215 | return -EINVAL; |
| 216 | |
| 217 | if (uflags & FS_USER_QUOTA) |
| 218 | flags |= XFS_DQ_USER; |
| 219 | if (uflags & FS_GROUP_QUOTA) |
| 220 | flags |= XFS_DQ_GROUP; |
Jie Liu | 74dc93a | 2014-07-24 21:27:17 +1000 | [diff] [blame] | 221 | if (uflags & FS_PROJ_QUOTA) |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 222 | flags |= XFS_DQ_PROJ; |
| 223 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 224 | return xfs_qm_scall_trunc_qfiles(mp, flags); |
| 225 | } |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 226 | |
| 227 | STATIC int |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 228 | xfs_fs_get_dqblk( |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 229 | struct super_block *sb, |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 230 | struct kqid qid, |
Jan Kara | 14bf61f | 2014-10-09 16:03:13 +0200 | [diff] [blame] | 231 | struct qc_dqblk *qdq) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 232 | { |
| 233 | struct xfs_mount *mp = XFS_M(sb); |
Eric Sandeen | 296c24e | 2016-02-08 11:27:38 +1100 | [diff] [blame] | 234 | xfs_dqid_t id; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 235 | |
| 236 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 237 | return -ENOSYS; |
| 238 | if (!XFS_IS_QUOTA_ON(mp)) |
| 239 | return -ESRCH; |
| 240 | |
Eric Sandeen | 296c24e | 2016-02-08 11:27:38 +1100 | [diff] [blame] | 241 | id = from_kqid(&init_user_ns, qid); |
| 242 | return xfs_qm_scall_getquota(mp, &id, |
| 243 | xfs_quota_type(qid.type), qdq, 0); |
| 244 | } |
| 245 | |
| 246 | /* Return quota info for active quota >= this qid */ |
| 247 | STATIC int |
| 248 | xfs_fs_get_nextdqblk( |
| 249 | struct super_block *sb, |
| 250 | struct kqid *qid, |
| 251 | struct qc_dqblk *qdq) |
| 252 | { |
| 253 | int ret; |
| 254 | struct xfs_mount *mp = XFS_M(sb); |
| 255 | xfs_dqid_t id; |
| 256 | |
| 257 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 258 | return -ENOSYS; |
| 259 | if (!XFS_IS_QUOTA_ON(mp)) |
| 260 | return -ESRCH; |
| 261 | |
| 262 | id = from_kqid(&init_user_ns, *qid); |
| 263 | ret = xfs_qm_scall_getquota(mp, &id, |
| 264 | xfs_quota_type(qid->type), qdq, |
| 265 | XFS_QMOPT_DQNEXT); |
| 266 | if (ret) |
| 267 | return ret; |
| 268 | |
| 269 | /* ID may be different, so convert back what we got */ |
| 270 | *qid = make_kqid(current_user_ns(), qid->type, id); |
| 271 | return 0; |
| 272 | |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | STATIC int |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 276 | xfs_fs_set_dqblk( |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 277 | struct super_block *sb, |
Eric W. Biederman | 74a8a10 | 2012-09-16 02:07:49 -0700 | [diff] [blame] | 278 | struct kqid qid, |
Jan Kara | 14bf61f | 2014-10-09 16:03:13 +0200 | [diff] [blame] | 279 | struct qc_dqblk *qdq) |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 280 | { |
| 281 | struct xfs_mount *mp = XFS_M(sb); |
| 282 | |
| 283 | if (sb->s_flags & MS_RDONLY) |
| 284 | return -EROFS; |
| 285 | if (!XFS_IS_QUOTA_RUNNING(mp)) |
| 286 | return -ENOSYS; |
| 287 | if (!XFS_IS_QUOTA_ON(mp)) |
| 288 | return -ESRCH; |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 289 | |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 290 | return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid), |
Jan Kara | 14bf61f | 2014-10-09 16:03:13 +0200 | [diff] [blame] | 291 | xfs_quota_type(qid.type), qdq); |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 292 | } |
| 293 | |
Alexey Dobriyan | 0d54b21 | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 294 | const struct quotactl_ops xfs_quotactl_operations = { |
Jan Kara | 5d3684c | 2014-11-19 12:03:59 +0100 | [diff] [blame] | 295 | .get_state = xfs_fs_get_quota_state, |
Jan Kara | c14cad9 | 2014-12-16 13:07:45 +0100 | [diff] [blame] | 296 | .set_info = xfs_fs_set_info, |
Jan Kara | 38e478c | 2014-10-08 15:56:21 +0200 | [diff] [blame] | 297 | .quota_enable = xfs_quota_enable, |
| 298 | .quota_disable = xfs_quota_disable, |
Eric Sandeen | 9da93f9 | 2014-05-05 17:25:50 +1000 | [diff] [blame] | 299 | .rm_xquota = xfs_fs_rm_xquota, |
Christoph Hellwig | b9b2dd3 | 2010-05-06 17:04:58 -0400 | [diff] [blame] | 300 | .get_dqblk = xfs_fs_get_dqblk, |
Eric Sandeen | 296c24e | 2016-02-08 11:27:38 +1100 | [diff] [blame] | 301 | .get_nextdqblk = xfs_fs_get_nextdqblk, |
Christoph Hellwig | c472b43 | 2010-05-06 17:05:17 -0400 | [diff] [blame] | 302 | .set_dqblk = xfs_fs_set_dqblk, |
Christoph Hellwig | fcafb71 | 2009-02-09 08:47:34 +0100 | [diff] [blame] | 303 | }; |