xfs_quotaops.c 4.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright (c) 2008, Christoph Hellwig
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
#include "xfs.h"
19
#include "xfs_format.h"
20
#include "xfs_log_format.h"
21
#include "xfs_trans_resv.h"
22
#include "xfs_mount.h"
23
#include "xfs_inode.h"
24 25
#include "xfs_quota.h"
#include "xfs_trans.h"
26
#include "xfs_qm.h"
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#include <linux/quota.h>


STATIC int
xfs_quota_type(int type)
{
	switch (type) {
	case USRQUOTA:
		return XFS_DQ_USER;
	case GRPQUOTA:
		return XFS_DQ_GROUP;
	default:
		return XFS_DQ_PROJ;
	}
}

STATIC int
xfs_fs_get_xstate(
	struct super_block	*sb,
	struct fs_quota_stat	*fqs)
{
	struct xfs_mount	*mp = XFS_M(sb);

	if (!XFS_IS_QUOTA_RUNNING(mp))
		return -ENOSYS;
D
Dave Chinner 已提交
52
	return xfs_qm_scall_getqstat(mp, fqs);
53 54
}

55 56 57 58 59 60 61 62 63
STATIC int
xfs_fs_get_xstatev(
	struct super_block	*sb,
	struct fs_quota_statv	*fqs)
{
	struct xfs_mount	*mp = XFS_M(sb);

	if (!XFS_IS_QUOTA_RUNNING(mp))
		return -ENOSYS;
D
Dave Chinner 已提交
64
	return xfs_qm_scall_getqstatv(mp, fqs);
65 66
}

67 68
static unsigned int
xfs_quota_flags(unsigned int uflags)
69
{
70
	unsigned int flags = 0;
71

72
	if (uflags & FS_QUOTA_UDQ_ACCT)
73
		flags |= XFS_UQUOTA_ACCT;
74
	if (uflags & FS_QUOTA_PDQ_ACCT)
75
		flags |= XFS_PQUOTA_ACCT;
76
	if (uflags & FS_QUOTA_GDQ_ACCT)
77
		flags |= XFS_GQUOTA_ACCT;
78
	if (uflags & FS_QUOTA_UDQ_ENFD)
79
		flags |= XFS_UQUOTA_ENFD;
80 81 82 83
	if (uflags & FS_QUOTA_GDQ_ENFD)
		flags |= XFS_GQUOTA_ENFD;
	if (uflags & FS_QUOTA_PDQ_ENFD)
		flags |= XFS_PQUOTA_ENFD;
84

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
	return flags;
}

STATIC int
xfs_quota_enable(
	struct super_block	*sb,
	unsigned int		uflags)
{
	struct xfs_mount	*mp = XFS_M(sb);

	if (sb->s_flags & MS_RDONLY)
		return -EROFS;
	if (!XFS_IS_QUOTA_RUNNING(mp))
		return -ENOSYS;

	return xfs_qm_scall_quotaon(mp, xfs_quota_flags(uflags));
}

STATIC int
xfs_quota_disable(
	struct super_block	*sb,
	unsigned int		uflags)
{
	struct xfs_mount	*mp = XFS_M(sb);

	if (sb->s_flags & MS_RDONLY)
		return -EROFS;
	if (!XFS_IS_QUOTA_RUNNING(mp))
		return -ENOSYS;
	if (!XFS_IS_QUOTA_ON(mp))
		return -EINVAL;
116

117
	return xfs_qm_scall_quotaoff(mp, xfs_quota_flags(uflags));
118 119
}

E
Eric Sandeen 已提交
120 121 122 123 124 125 126
STATIC int
xfs_fs_rm_xquota(
	struct super_block	*sb,
	unsigned int		uflags)
{
	struct xfs_mount	*mp = XFS_M(sb);
	unsigned int		flags = 0;
D
Dave Chinner 已提交
127

E
Eric Sandeen 已提交
128 129 130 131 132 133 134 135 136 137
	if (sb->s_flags & MS_RDONLY)
		return -EROFS;

	if (XFS_IS_QUOTA_ON(mp))
		return -EINVAL;

	if (uflags & FS_USER_QUOTA)
		flags |= XFS_DQ_USER;
	if (uflags & FS_GROUP_QUOTA)
		flags |= XFS_DQ_GROUP;
138
	if (uflags & FS_PROJ_QUOTA)
E
Eric Sandeen 已提交
139 140
		flags |= XFS_DQ_PROJ;

D
Dave Chinner 已提交
141 142
	return xfs_qm_scall_trunc_qfiles(mp, flags);
}
E
Eric Sandeen 已提交
143

144
STATIC int
C
Christoph Hellwig 已提交
145
xfs_fs_get_dqblk(
146
	struct super_block	*sb,
E
Eric W. Biederman 已提交
147
	struct kqid		qid,
148
	struct qc_dqblk		*qdq)
149 150 151 152 153 154 155 156
{
	struct xfs_mount	*mp = XFS_M(sb);

	if (!XFS_IS_QUOTA_RUNNING(mp))
		return -ENOSYS;
	if (!XFS_IS_QUOTA_ON(mp))
		return -ESRCH;

D
Dave Chinner 已提交
157
	return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
158
				      xfs_quota_type(qid.type), qdq);
159 160 161
}

STATIC int
C
Christoph Hellwig 已提交
162
xfs_fs_set_dqblk(
163
	struct super_block	*sb,
E
Eric W. Biederman 已提交
164
	struct kqid		qid,
165
	struct qc_dqblk		*qdq)
166 167 168 169 170 171 172 173 174 175
{
	struct xfs_mount	*mp = XFS_M(sb);

	if (sb->s_flags & MS_RDONLY)
		return -EROFS;
	if (!XFS_IS_QUOTA_RUNNING(mp))
		return -ENOSYS;
	if (!XFS_IS_QUOTA_ON(mp))
		return -ESRCH;

D
Dave Chinner 已提交
176
	return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
177
				     xfs_quota_type(qid.type), qdq);
178 179
}

180
const struct quotactl_ops xfs_quotactl_operations = {
181
	.get_xstatev		= xfs_fs_get_xstatev,
182
	.get_xstate		= xfs_fs_get_xstate,
183 184
	.quota_enable		= xfs_quota_enable,
	.quota_disable		= xfs_quota_disable,
E
Eric Sandeen 已提交
185
	.rm_xquota		= xfs_fs_rm_xquota,
C
Christoph Hellwig 已提交
186
	.get_dqblk		= xfs_fs_get_dqblk,
C
Christoph Hellwig 已提交
187
	.set_dqblk		= xfs_fs_set_dqblk,
188
};