1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2884d179dSJan Kara /*
3884d179dSJan Kara * Quota code necessary even when VFS quota support is not compiled
4884d179dSJan Kara * into the kernel. The interesting stuff is over in dquot.c, here
5884d179dSJan Kara * we have symbols for initial quotactl(2) handling, the sysctl(2)
6884d179dSJan Kara * variables, etc - things needed even when quota support disabled.
7884d179dSJan Kara */
8884d179dSJan Kara
9884d179dSJan Kara #include <linux/fs.h>
10884d179dSJan Kara #include <linux/namei.h>
11884d179dSJan Kara #include <linux/slab.h>
12884d179dSJan Kara #include <asm/current.h>
13348332e0SChristoph Hellwig #include <linux/blkdev.h>
14f3da9310SJeff Liu #include <linux/uaccess.h>
15884d179dSJan Kara #include <linux/kernel.h>
16884d179dSJan Kara #include <linux/security.h>
17884d179dSJan Kara #include <linux/syscalls.h>
18884d179dSJan Kara #include <linux/capability.h>
19884d179dSJan Kara #include <linux/quotaops.h>
20884d179dSJan Kara #include <linux/types.h>
219dfa23c8SSascha Hauer #include <linux/mount.h>
228c4e4acdSChristoph Hellwig #include <linux/writeback.h>
237b6924d9SJeremy Cline #include <linux/nospec.h>
2480bdad3dSChristoph Hellwig #include "compat.h"
2560b49885SChristoph Hellwig #include "../internal.h"
26884d179dSJan Kara
check_quotactl_permission(struct super_block * sb,int type,int cmd,qid_t id)27c988afb5SChristoph Hellwig static int check_quotactl_permission(struct super_block *sb, int type, int cmd,
28268157baSJan Kara qid_t id)
29884d179dSJan Kara {
30c988afb5SChristoph Hellwig switch (cmd) {
31c988afb5SChristoph Hellwig /* these commands do not require any special privilegues */
32c988afb5SChristoph Hellwig case Q_GETFMT:
33c988afb5SChristoph Hellwig case Q_SYNC:
34c988afb5SChristoph Hellwig case Q_GETINFO:
35c988afb5SChristoph Hellwig case Q_XGETQSTAT:
36af30cb44SChandra Seetharaman case Q_XGETQSTATV:
37c988afb5SChristoph Hellwig case Q_XQUOTASYNC:
38c988afb5SChristoph Hellwig break;
39c988afb5SChristoph Hellwig /* allow to query information for dquots we "own" */
40c988afb5SChristoph Hellwig case Q_GETQUOTA:
41c988afb5SChristoph Hellwig case Q_XGETQUOTA:
4274a8a103SEric W. Biederman if ((type == USRQUOTA && uid_eq(current_euid(), make_kuid(current_user_ns(), id))) ||
4374a8a103SEric W. Biederman (type == GRPQUOTA && in_egroup_p(make_kgid(current_user_ns(), id))))
44c988afb5SChristoph Hellwig break;
45df561f66SGustavo A. R. Silva fallthrough;
46c988afb5SChristoph Hellwig default:
47884d179dSJan Kara if (!capable(CAP_SYS_ADMIN))
48884d179dSJan Kara return -EPERM;
49884d179dSJan Kara }
50884d179dSJan Kara
51c988afb5SChristoph Hellwig return security_quotactl(cmd, type, id, sb);
52884d179dSJan Kara }
53884d179dSJan Kara
quota_sync_one(struct super_block * sb,void * arg)5401a05b33SAl Viro static void quota_sync_one(struct super_block *sb, void *arg)
5501a05b33SAl Viro {
562c5f648aSJan Kara int type = *(int *)arg;
572c5f648aSJan Kara
582c5f648aSJan Kara if (sb->s_qcop && sb->s_qcop->quota_sync &&
592c5f648aSJan Kara (sb->s_quota_types & (1 << type)))
602c5f648aSJan Kara sb->s_qcop->quota_sync(sb, type);
6101a05b33SAl Viro }
6201a05b33SAl Viro
quota_sync_all(int type)636ae09575SChristoph Hellwig static int quota_sync_all(int type)
64884d179dSJan Kara {
656ae09575SChristoph Hellwig int ret;
666ae09575SChristoph Hellwig
676ae09575SChristoph Hellwig ret = security_quotactl(Q_SYNC, type, 0, NULL);
6801a05b33SAl Viro if (!ret)
6901a05b33SAl Viro iterate_supers(quota_sync_one, &type);
706ae09575SChristoph Hellwig return ret;
71884d179dSJan Kara }
72884d179dSJan Kara
qtype_enforce_flag(int type)73d3b86324SJan Kara unsigned int qtype_enforce_flag(int type)
74d3b86324SJan Kara {
75d3b86324SJan Kara switch (type) {
76d3b86324SJan Kara case USRQUOTA:
77d3b86324SJan Kara return FS_QUOTA_UDQ_ENFD;
78d3b86324SJan Kara case GRPQUOTA:
79d3b86324SJan Kara return FS_QUOTA_GDQ_ENFD;
80d3b86324SJan Kara case PRJQUOTA:
81d3b86324SJan Kara return FS_QUOTA_PDQ_ENFD;
82d3b86324SJan Kara }
83d3b86324SJan Kara return 0;
84d3b86324SJan Kara }
85d3b86324SJan Kara
quota_quotaon(struct super_block * sb,int type,qid_t id,const struct path * path)863218a3ecSEric Sandeen static int quota_quotaon(struct super_block *sb, int type, qid_t id,
878c54ca9cSAl Viro const struct path *path)
88884d179dSJan Kara {
89aaa3daedSJan Kara if (!sb->s_qcop->quota_on && !sb->s_qcop->quota_enable)
90f00c9e44SJan Kara return -ENOSYS;
91d3b86324SJan Kara if (sb->s_qcop->quota_enable)
92d3b86324SJan Kara return sb->s_qcop->quota_enable(sb, qtype_enforce_flag(type));
93f00c9e44SJan Kara if (IS_ERR(path))
94f00c9e44SJan Kara return PTR_ERR(path);
95f00c9e44SJan Kara return sb->s_qcop->quota_on(sb, type, id, path);
96884d179dSJan Kara }
97884d179dSJan Kara
quota_quotaoff(struct super_block * sb,int type)98d3b86324SJan Kara static int quota_quotaoff(struct super_block *sb, int type)
99d3b86324SJan Kara {
100d3b86324SJan Kara if (!sb->s_qcop->quota_off && !sb->s_qcop->quota_disable)
101d3b86324SJan Kara return -ENOSYS;
102d3b86324SJan Kara if (sb->s_qcop->quota_disable)
103d3b86324SJan Kara return sb->s_qcop->quota_disable(sb, qtype_enforce_flag(type));
104d3b86324SJan Kara return sb->s_qcop->quota_off(sb, type);
105d3b86324SJan Kara }
106d3b86324SJan Kara
quota_getfmt(struct super_block * sb,int type,void __user * addr)107c411e5f6SChristoph Hellwig static int quota_getfmt(struct super_block *sb, int type, void __user *addr)
108c411e5f6SChristoph Hellwig {
109884d179dSJan Kara __u32 fmt;
110884d179dSJan Kara
1119d1ccbe7SJan Kara if (!sb_has_quota_active(sb, type))
112884d179dSJan Kara return -ESRCH;
113884d179dSJan Kara fmt = sb_dqopt(sb)->info[type].dqi_format->qf_fmt_id;
114884d179dSJan Kara if (copy_to_user(addr, &fmt, sizeof(fmt)))
115884d179dSJan Kara return -EFAULT;
116884d179dSJan Kara return 0;
117884d179dSJan Kara }
118c411e5f6SChristoph Hellwig
quota_getinfo(struct super_block * sb,int type,void __user * addr)119c411e5f6SChristoph Hellwig static int quota_getinfo(struct super_block *sb, int type, void __user *addr)
120c411e5f6SChristoph Hellwig {
1210a240339SJan Kara struct qc_state state;
1220a240339SJan Kara struct qc_type_state *tstate;
1230a240339SJan Kara struct if_dqinfo uinfo;
124c411e5f6SChristoph Hellwig int ret;
125884d179dSJan Kara
1260a240339SJan Kara if (!sb->s_qcop->get_state)
127f450d4feSChristoph Hellwig return -ENOSYS;
1280a240339SJan Kara ret = sb->s_qcop->get_state(sb, &state);
1290a240339SJan Kara if (ret)
1300a240339SJan Kara return ret;
1310a240339SJan Kara tstate = state.s_state + type;
1320a240339SJan Kara if (!(tstate->flags & QCI_ACCT_ENABLED))
1330a240339SJan Kara return -ESRCH;
1340a240339SJan Kara memset(&uinfo, 0, sizeof(uinfo));
1350a240339SJan Kara uinfo.dqi_bgrace = tstate->spc_timelimit;
1360a240339SJan Kara uinfo.dqi_igrace = tstate->ino_timelimit;
1370a240339SJan Kara if (tstate->flags & QCI_SYSFILE)
1380a240339SJan Kara uinfo.dqi_flags |= DQF_SYS_FILE;
1390a240339SJan Kara if (tstate->flags & QCI_ROOT_SQUASH)
1400a240339SJan Kara uinfo.dqi_flags |= DQF_ROOT_SQUASH;
1410a240339SJan Kara uinfo.dqi_valid = IIF_ALL;
14272d4d0e4SDan Carpenter if (copy_to_user(addr, &uinfo, sizeof(uinfo)))
143884d179dSJan Kara return -EFAULT;
14472d4d0e4SDan Carpenter return 0;
145884d179dSJan Kara }
146c411e5f6SChristoph Hellwig
quota_setinfo(struct super_block * sb,int type,void __user * addr)147c411e5f6SChristoph Hellwig static int quota_setinfo(struct super_block *sb, int type, void __user *addr)
148c411e5f6SChristoph Hellwig {
149884d179dSJan Kara struct if_dqinfo info;
1505eacb2acSJan Kara struct qc_info qinfo;
151884d179dSJan Kara
152884d179dSJan Kara if (copy_from_user(&info, addr, sizeof(info)))
153884d179dSJan Kara return -EFAULT;
154f450d4feSChristoph Hellwig if (!sb->s_qcop->set_info)
155f450d4feSChristoph Hellwig return -ENOSYS;
1565eacb2acSJan Kara if (info.dqi_valid & ~(IIF_FLAGS | IIF_BGRACE | IIF_IGRACE))
1575eacb2acSJan Kara return -EINVAL;
1585eacb2acSJan Kara memset(&qinfo, 0, sizeof(qinfo));
1595eacb2acSJan Kara if (info.dqi_valid & IIF_FLAGS) {
1605eacb2acSJan Kara if (info.dqi_flags & ~DQF_SETINFO_MASK)
1615eacb2acSJan Kara return -EINVAL;
1625eacb2acSJan Kara if (info.dqi_flags & DQF_ROOT_SQUASH)
1635eacb2acSJan Kara qinfo.i_flags |= QCI_ROOT_SQUASH;
1645eacb2acSJan Kara qinfo.i_fieldmask |= QC_FLAGS;
1655eacb2acSJan Kara }
1665eacb2acSJan Kara if (info.dqi_valid & IIF_BGRACE) {
1675eacb2acSJan Kara qinfo.i_spc_timelimit = info.dqi_bgrace;
1685eacb2acSJan Kara qinfo.i_fieldmask |= QC_SPC_TIMER;
1695eacb2acSJan Kara }
1705eacb2acSJan Kara if (info.dqi_valid & IIF_IGRACE) {
1715eacb2acSJan Kara qinfo.i_ino_timelimit = info.dqi_igrace;
1725eacb2acSJan Kara qinfo.i_fieldmask |= QC_INO_TIMER;
1735eacb2acSJan Kara }
1745eacb2acSJan Kara return sb->s_qcop->set_info(sb, type, &qinfo);
175884d179dSJan Kara }
176c411e5f6SChristoph Hellwig
qbtos(qsize_t blocks)17714bf61ffSJan Kara static inline qsize_t qbtos(qsize_t blocks)
17814bf61ffSJan Kara {
17914bf61ffSJan Kara return blocks << QIF_DQBLKSIZE_BITS;
18014bf61ffSJan Kara }
18114bf61ffSJan Kara
stoqb(qsize_t space)18214bf61ffSJan Kara static inline qsize_t stoqb(qsize_t space)
18314bf61ffSJan Kara {
18414bf61ffSJan Kara return (space + QIF_DQBLKSIZE - 1) >> QIF_DQBLKSIZE_BITS;
18514bf61ffSJan Kara }
18614bf61ffSJan Kara
copy_to_if_dqblk(struct if_dqblk * dst,struct qc_dqblk * src)18714bf61ffSJan Kara static void copy_to_if_dqblk(struct if_dqblk *dst, struct qc_dqblk *src)
188b9b2dd36SChristoph Hellwig {
18918da65e7SDan Carpenter memset(dst, 0, sizeof(*dst));
19014bf61ffSJan Kara dst->dqb_bhardlimit = stoqb(src->d_spc_hardlimit);
19114bf61ffSJan Kara dst->dqb_bsoftlimit = stoqb(src->d_spc_softlimit);
19214bf61ffSJan Kara dst->dqb_curspace = src->d_space;
193b9b2dd36SChristoph Hellwig dst->dqb_ihardlimit = src->d_ino_hardlimit;
194b9b2dd36SChristoph Hellwig dst->dqb_isoftlimit = src->d_ino_softlimit;
19514bf61ffSJan Kara dst->dqb_curinodes = src->d_ino_count;
19614bf61ffSJan Kara dst->dqb_btime = src->d_spc_timer;
19714bf61ffSJan Kara dst->dqb_itime = src->d_ino_timer;
198b9b2dd36SChristoph Hellwig dst->dqb_valid = QIF_ALL;
199b9b2dd36SChristoph Hellwig }
200b9b2dd36SChristoph Hellwig
quota_getquota(struct super_block * sb,int type,qid_t id,void __user * addr)201c411e5f6SChristoph Hellwig static int quota_getquota(struct super_block *sb, int type, qid_t id,
202c411e5f6SChristoph Hellwig void __user *addr)
203c411e5f6SChristoph Hellwig {
20474a8a103SEric W. Biederman struct kqid qid;
20514bf61ffSJan Kara struct qc_dqblk fdq;
206884d179dSJan Kara struct if_dqblk idq;
207c411e5f6SChristoph Hellwig int ret;
208884d179dSJan Kara
209f450d4feSChristoph Hellwig if (!sb->s_qcop->get_dqblk)
210f450d4feSChristoph Hellwig return -ENOSYS;
21174a8a103SEric W. Biederman qid = make_kqid(current_user_ns(), type, id);
212d49d3762SEric W. Biederman if (!qid_has_mapping(sb->s_user_ns, qid))
21374a8a103SEric W. Biederman return -EINVAL;
21474a8a103SEric W. Biederman ret = sb->s_qcop->get_dqblk(sb, qid, &fdq);
215268157baSJan Kara if (ret)
216884d179dSJan Kara return ret;
217b9b2dd36SChristoph Hellwig copy_to_if_dqblk(&idq, &fdq);
21880bdad3dSChristoph Hellwig
21980bdad3dSChristoph Hellwig if (compat_need_64bit_alignment_fixup()) {
22080bdad3dSChristoph Hellwig struct compat_if_dqblk __user *compat_dqblk = addr;
22180bdad3dSChristoph Hellwig
22280bdad3dSChristoph Hellwig if (copy_to_user(compat_dqblk, &idq, sizeof(*compat_dqblk)))
22380bdad3dSChristoph Hellwig return -EFAULT;
22480bdad3dSChristoph Hellwig if (put_user(idq.dqb_valid, &compat_dqblk->dqb_valid))
22580bdad3dSChristoph Hellwig return -EFAULT;
22680bdad3dSChristoph Hellwig } else {
227884d179dSJan Kara if (copy_to_user(addr, &idq, sizeof(idq)))
228884d179dSJan Kara return -EFAULT;
22980bdad3dSChristoph Hellwig }
230884d179dSJan Kara return 0;
231884d179dSJan Kara }
232c411e5f6SChristoph Hellwig
233926132c0SEric Sandeen /*
234926132c0SEric Sandeen * Return quota for next active quota >= this id, if any exists,
235ba58148bSEric Sandeen * otherwise return -ENOENT via ->get_nextdqblk
236926132c0SEric Sandeen */
quota_getnextquota(struct super_block * sb,int type,qid_t id,void __user * addr)237926132c0SEric Sandeen static int quota_getnextquota(struct super_block *sb, int type, qid_t id,
238926132c0SEric Sandeen void __user *addr)
239926132c0SEric Sandeen {
240926132c0SEric Sandeen struct kqid qid;
241926132c0SEric Sandeen struct qc_dqblk fdq;
242926132c0SEric Sandeen struct if_nextdqblk idq;
243926132c0SEric Sandeen int ret;
244926132c0SEric Sandeen
245926132c0SEric Sandeen if (!sb->s_qcop->get_nextdqblk)
246926132c0SEric Sandeen return -ENOSYS;
247926132c0SEric Sandeen qid = make_kqid(current_user_ns(), type, id);
248d49d3762SEric W. Biederman if (!qid_has_mapping(sb->s_user_ns, qid))
249926132c0SEric Sandeen return -EINVAL;
250926132c0SEric Sandeen ret = sb->s_qcop->get_nextdqblk(sb, &qid, &fdq);
251926132c0SEric Sandeen if (ret)
252926132c0SEric Sandeen return ret;
253926132c0SEric Sandeen /* struct if_nextdqblk is a superset of struct if_dqblk */
254926132c0SEric Sandeen copy_to_if_dqblk((struct if_dqblk *)&idq, &fdq);
255926132c0SEric Sandeen idq.dqb_id = from_kqid(current_user_ns(), qid);
256926132c0SEric Sandeen if (copy_to_user(addr, &idq, sizeof(idq)))
257926132c0SEric Sandeen return -EFAULT;
258926132c0SEric Sandeen return 0;
259926132c0SEric Sandeen }
260926132c0SEric Sandeen
copy_from_if_dqblk(struct qc_dqblk * dst,struct if_dqblk * src)26114bf61ffSJan Kara static void copy_from_if_dqblk(struct qc_dqblk *dst, struct if_dqblk *src)
262c472b432SChristoph Hellwig {
26314bf61ffSJan Kara dst->d_spc_hardlimit = qbtos(src->dqb_bhardlimit);
26414bf61ffSJan Kara dst->d_spc_softlimit = qbtos(src->dqb_bsoftlimit);
26514bf61ffSJan Kara dst->d_space = src->dqb_curspace;
266c472b432SChristoph Hellwig dst->d_ino_hardlimit = src->dqb_ihardlimit;
267c472b432SChristoph Hellwig dst->d_ino_softlimit = src->dqb_isoftlimit;
26814bf61ffSJan Kara dst->d_ino_count = src->dqb_curinodes;
26914bf61ffSJan Kara dst->d_spc_timer = src->dqb_btime;
27014bf61ffSJan Kara dst->d_ino_timer = src->dqb_itime;
271c472b432SChristoph Hellwig
272c472b432SChristoph Hellwig dst->d_fieldmask = 0;
273c472b432SChristoph Hellwig if (src->dqb_valid & QIF_BLIMITS)
27414bf61ffSJan Kara dst->d_fieldmask |= QC_SPC_SOFT | QC_SPC_HARD;
275c472b432SChristoph Hellwig if (src->dqb_valid & QIF_SPACE)
27614bf61ffSJan Kara dst->d_fieldmask |= QC_SPACE;
277c472b432SChristoph Hellwig if (src->dqb_valid & QIF_ILIMITS)
27814bf61ffSJan Kara dst->d_fieldmask |= QC_INO_SOFT | QC_INO_HARD;
279c472b432SChristoph Hellwig if (src->dqb_valid & QIF_INODES)
28014bf61ffSJan Kara dst->d_fieldmask |= QC_INO_COUNT;
281c472b432SChristoph Hellwig if (src->dqb_valid & QIF_BTIME)
28214bf61ffSJan Kara dst->d_fieldmask |= QC_SPC_TIMER;
283c472b432SChristoph Hellwig if (src->dqb_valid & QIF_ITIME)
28414bf61ffSJan Kara dst->d_fieldmask |= QC_INO_TIMER;
285c472b432SChristoph Hellwig }
286c472b432SChristoph Hellwig
quota_setquota(struct super_block * sb,int type,qid_t id,void __user * addr)287c411e5f6SChristoph Hellwig static int quota_setquota(struct super_block *sb, int type, qid_t id,
288c411e5f6SChristoph Hellwig void __user *addr)
289c411e5f6SChristoph Hellwig {
29014bf61ffSJan Kara struct qc_dqblk fdq;
291884d179dSJan Kara struct if_dqblk idq;
29274a8a103SEric W. Biederman struct kqid qid;
293884d179dSJan Kara
29480bdad3dSChristoph Hellwig if (compat_need_64bit_alignment_fixup()) {
29580bdad3dSChristoph Hellwig struct compat_if_dqblk __user *compat_dqblk = addr;
29680bdad3dSChristoph Hellwig
29780bdad3dSChristoph Hellwig if (copy_from_user(&idq, compat_dqblk, sizeof(*compat_dqblk)) ||
29880bdad3dSChristoph Hellwig get_user(idq.dqb_valid, &compat_dqblk->dqb_valid))
29980bdad3dSChristoph Hellwig return -EFAULT;
30080bdad3dSChristoph Hellwig } else {
301884d179dSJan Kara if (copy_from_user(&idq, addr, sizeof(idq)))
302884d179dSJan Kara return -EFAULT;
30380bdad3dSChristoph Hellwig }
304f450d4feSChristoph Hellwig if (!sb->s_qcop->set_dqblk)
305f450d4feSChristoph Hellwig return -ENOSYS;
30674a8a103SEric W. Biederman qid = make_kqid(current_user_ns(), type, id);
307d49d3762SEric W. Biederman if (!qid_has_mapping(sb->s_user_ns, qid))
30874a8a103SEric W. Biederman return -EINVAL;
309c472b432SChristoph Hellwig copy_from_if_dqblk(&fdq, &idq);
31074a8a103SEric W. Biederman return sb->s_qcop->set_dqblk(sb, qid, &fdq);
311884d179dSJan Kara }
312884d179dSJan Kara
quota_enable(struct super_block * sb,void __user * addr)31338e478c4SJan Kara static int quota_enable(struct super_block *sb, void __user *addr)
314c411e5f6SChristoph Hellwig {
315884d179dSJan Kara __u32 flags;
316884d179dSJan Kara
317884d179dSJan Kara if (copy_from_user(&flags, addr, sizeof(flags)))
318884d179dSJan Kara return -EFAULT;
31938e478c4SJan Kara if (!sb->s_qcop->quota_enable)
320f450d4feSChristoph Hellwig return -ENOSYS;
32138e478c4SJan Kara return sb->s_qcop->quota_enable(sb, flags);
32238e478c4SJan Kara }
32338e478c4SJan Kara
quota_disable(struct super_block * sb,void __user * addr)32438e478c4SJan Kara static int quota_disable(struct super_block *sb, void __user *addr)
32538e478c4SJan Kara {
32638e478c4SJan Kara __u32 flags;
32738e478c4SJan Kara
32838e478c4SJan Kara if (copy_from_user(&flags, addr, sizeof(flags)))
32938e478c4SJan Kara return -EFAULT;
33038e478c4SJan Kara if (!sb->s_qcop->quota_disable)
33138e478c4SJan Kara return -ENOSYS;
33238e478c4SJan Kara return sb->s_qcop->quota_disable(sb, flags);
333884d179dSJan Kara }
334884d179dSJan Kara
quota_state_to_flags(struct qc_state * state)335bc230e4aSJan Kara static int quota_state_to_flags(struct qc_state *state)
336bc230e4aSJan Kara {
337bc230e4aSJan Kara int flags = 0;
338bc230e4aSJan Kara
339bc230e4aSJan Kara if (state->s_state[USRQUOTA].flags & QCI_ACCT_ENABLED)
340bc230e4aSJan Kara flags |= FS_QUOTA_UDQ_ACCT;
341bc230e4aSJan Kara if (state->s_state[USRQUOTA].flags & QCI_LIMITS_ENFORCED)
342bc230e4aSJan Kara flags |= FS_QUOTA_UDQ_ENFD;
343bc230e4aSJan Kara if (state->s_state[GRPQUOTA].flags & QCI_ACCT_ENABLED)
344bc230e4aSJan Kara flags |= FS_QUOTA_GDQ_ACCT;
345bc230e4aSJan Kara if (state->s_state[GRPQUOTA].flags & QCI_LIMITS_ENFORCED)
346bc230e4aSJan Kara flags |= FS_QUOTA_GDQ_ENFD;
347bc230e4aSJan Kara if (state->s_state[PRJQUOTA].flags & QCI_ACCT_ENABLED)
348bc230e4aSJan Kara flags |= FS_QUOTA_PDQ_ACCT;
349bc230e4aSJan Kara if (state->s_state[PRJQUOTA].flags & QCI_LIMITS_ENFORCED)
350bc230e4aSJan Kara flags |= FS_QUOTA_PDQ_ENFD;
351bc230e4aSJan Kara return flags;
352bc230e4aSJan Kara }
353bc230e4aSJan Kara
quota_getstate(struct super_block * sb,int type,struct fs_quota_stat * fqs)354555b2c3dSEric Sandeen static int quota_getstate(struct super_block *sb, int type,
355555b2c3dSEric Sandeen struct fs_quota_stat *fqs)
356bc230e4aSJan Kara {
357bc230e4aSJan Kara struct qc_state state;
358bc230e4aSJan Kara int ret;
359bc230e4aSJan Kara
3603cd0126dSEric Sandeen memset(&state, 0, sizeof (struct qc_state));
361bc230e4aSJan Kara ret = sb->s_qcop->get_state(sb, &state);
362bc230e4aSJan Kara if (ret < 0)
363bc230e4aSJan Kara return ret;
364bc230e4aSJan Kara
365bc230e4aSJan Kara memset(fqs, 0, sizeof(*fqs));
366bc230e4aSJan Kara fqs->qs_version = FS_QSTAT_VERSION;
367bc230e4aSJan Kara fqs->qs_flags = quota_state_to_flags(&state);
368bc230e4aSJan Kara /* No quota enabled? */
369bc230e4aSJan Kara if (!fqs->qs_flags)
370bc230e4aSJan Kara return -ENOSYS;
371bc230e4aSJan Kara fqs->qs_incoredqs = state.s_incoredqs;
372555b2c3dSEric Sandeen
373bc230e4aSJan Kara fqs->qs_btimelimit = state.s_state[type].spc_timelimit;
374bc230e4aSJan Kara fqs->qs_itimelimit = state.s_state[type].ino_timelimit;
375bc230e4aSJan Kara fqs->qs_rtbtimelimit = state.s_state[type].rt_spc_timelimit;
376bc230e4aSJan Kara fqs->qs_bwarnlimit = state.s_state[type].spc_warnlimit;
377bc230e4aSJan Kara fqs->qs_iwarnlimit = state.s_state[type].ino_warnlimit;
3783cd0126dSEric Sandeen
3793cd0126dSEric Sandeen /* Inodes may be allocated even if inactive; copy out if present */
3803cd0126dSEric Sandeen if (state.s_state[USRQUOTA].ino) {
381bc230e4aSJan Kara fqs->qs_uquota.qfs_ino = state.s_state[USRQUOTA].ino;
382bc230e4aSJan Kara fqs->qs_uquota.qfs_nblks = state.s_state[USRQUOTA].blocks;
383bc230e4aSJan Kara fqs->qs_uquota.qfs_nextents = state.s_state[USRQUOTA].nextents;
384bc230e4aSJan Kara }
3853cd0126dSEric Sandeen if (state.s_state[GRPQUOTA].ino) {
386bc230e4aSJan Kara fqs->qs_gquota.qfs_ino = state.s_state[GRPQUOTA].ino;
387bc230e4aSJan Kara fqs->qs_gquota.qfs_nblks = state.s_state[GRPQUOTA].blocks;
388bc230e4aSJan Kara fqs->qs_gquota.qfs_nextents = state.s_state[GRPQUOTA].nextents;
389bc230e4aSJan Kara }
3903cd0126dSEric Sandeen if (state.s_state[PRJQUOTA].ino) {
391bc230e4aSJan Kara /*
392bc230e4aSJan Kara * Q_XGETQSTAT doesn't have room for both group and project
393bc230e4aSJan Kara * quotas. So, allow the project quota values to be copied out
394bc230e4aSJan Kara * only if there is no group quota information available.
395bc230e4aSJan Kara */
396bc230e4aSJan Kara if (!(state.s_state[GRPQUOTA].flags & QCI_ACCT_ENABLED)) {
397bc230e4aSJan Kara fqs->qs_gquota.qfs_ino = state.s_state[PRJQUOTA].ino;
398bc230e4aSJan Kara fqs->qs_gquota.qfs_nblks =
399bc230e4aSJan Kara state.s_state[PRJQUOTA].blocks;
400bc230e4aSJan Kara fqs->qs_gquota.qfs_nextents =
401bc230e4aSJan Kara state.s_state[PRJQUOTA].nextents;
402bc230e4aSJan Kara }
403bc230e4aSJan Kara }
404bc230e4aSJan Kara return 0;
405bc230e4aSJan Kara }
406bc230e4aSJan Kara
compat_copy_fs_qfilestat(struct compat_fs_qfilestat __user * to,struct fs_qfilestat * from)40780bdad3dSChristoph Hellwig static int compat_copy_fs_qfilestat(struct compat_fs_qfilestat __user *to,
40880bdad3dSChristoph Hellwig struct fs_qfilestat *from)
40980bdad3dSChristoph Hellwig {
41080bdad3dSChristoph Hellwig if (copy_to_user(to, from, sizeof(*to)) ||
41180bdad3dSChristoph Hellwig put_user(from->qfs_nextents, &to->qfs_nextents))
41280bdad3dSChristoph Hellwig return -EFAULT;
41380bdad3dSChristoph Hellwig return 0;
41480bdad3dSChristoph Hellwig }
41580bdad3dSChristoph Hellwig
compat_copy_fs_quota_stat(struct compat_fs_quota_stat __user * to,struct fs_quota_stat * from)41680bdad3dSChristoph Hellwig static int compat_copy_fs_quota_stat(struct compat_fs_quota_stat __user *to,
41780bdad3dSChristoph Hellwig struct fs_quota_stat *from)
41880bdad3dSChristoph Hellwig {
41980bdad3dSChristoph Hellwig if (put_user(from->qs_version, &to->qs_version) ||
42080bdad3dSChristoph Hellwig put_user(from->qs_flags, &to->qs_flags) ||
42180bdad3dSChristoph Hellwig put_user(from->qs_pad, &to->qs_pad) ||
42280bdad3dSChristoph Hellwig compat_copy_fs_qfilestat(&to->qs_uquota, &from->qs_uquota) ||
42380bdad3dSChristoph Hellwig compat_copy_fs_qfilestat(&to->qs_gquota, &from->qs_gquota) ||
42480bdad3dSChristoph Hellwig put_user(from->qs_incoredqs, &to->qs_incoredqs) ||
42580bdad3dSChristoph Hellwig put_user(from->qs_btimelimit, &to->qs_btimelimit) ||
42680bdad3dSChristoph Hellwig put_user(from->qs_itimelimit, &to->qs_itimelimit) ||
42780bdad3dSChristoph Hellwig put_user(from->qs_rtbtimelimit, &to->qs_rtbtimelimit) ||
42880bdad3dSChristoph Hellwig put_user(from->qs_bwarnlimit, &to->qs_bwarnlimit) ||
42980bdad3dSChristoph Hellwig put_user(from->qs_iwarnlimit, &to->qs_iwarnlimit))
43080bdad3dSChristoph Hellwig return -EFAULT;
43180bdad3dSChristoph Hellwig return 0;
43280bdad3dSChristoph Hellwig }
43380bdad3dSChristoph Hellwig
quota_getxstate(struct super_block * sb,int type,void __user * addr)434555b2c3dSEric Sandeen static int quota_getxstate(struct super_block *sb, int type, void __user *addr)
435c411e5f6SChristoph Hellwig {
436c411e5f6SChristoph Hellwig struct fs_quota_stat fqs;
437c411e5f6SChristoph Hellwig int ret;
438c411e5f6SChristoph Hellwig
43959b6ba69SJan Kara if (!sb->s_qcop->get_state)
440f450d4feSChristoph Hellwig return -ENOSYS;
441555b2c3dSEric Sandeen ret = quota_getstate(sb, type, &fqs);
44280bdad3dSChristoph Hellwig if (ret)
443c411e5f6SChristoph Hellwig return ret;
44480bdad3dSChristoph Hellwig
44580bdad3dSChristoph Hellwig if (compat_need_64bit_alignment_fixup())
44680bdad3dSChristoph Hellwig return compat_copy_fs_quota_stat(addr, &fqs);
44780bdad3dSChristoph Hellwig if (copy_to_user(addr, &fqs, sizeof(fqs)))
44880bdad3dSChristoph Hellwig return -EFAULT;
44980bdad3dSChristoph Hellwig return 0;
450884d179dSJan Kara }
451c411e5f6SChristoph Hellwig
quota_getstatev(struct super_block * sb,int type,struct fs_quota_statv * fqs)452555b2c3dSEric Sandeen static int quota_getstatev(struct super_block *sb, int type,
453555b2c3dSEric Sandeen struct fs_quota_statv *fqs)
454bc230e4aSJan Kara {
455bc230e4aSJan Kara struct qc_state state;
456bc230e4aSJan Kara int ret;
457bc230e4aSJan Kara
4583cd0126dSEric Sandeen memset(&state, 0, sizeof (struct qc_state));
459bc230e4aSJan Kara ret = sb->s_qcop->get_state(sb, &state);
460bc230e4aSJan Kara if (ret < 0)
461bc230e4aSJan Kara return ret;
462bc230e4aSJan Kara
463bc230e4aSJan Kara memset(fqs, 0, sizeof(*fqs));
464bc230e4aSJan Kara fqs->qs_version = FS_QSTAT_VERSION;
465bc230e4aSJan Kara fqs->qs_flags = quota_state_to_flags(&state);
466bc230e4aSJan Kara /* No quota enabled? */
467bc230e4aSJan Kara if (!fqs->qs_flags)
468bc230e4aSJan Kara return -ENOSYS;
469bc230e4aSJan Kara fqs->qs_incoredqs = state.s_incoredqs;
470555b2c3dSEric Sandeen
471bc230e4aSJan Kara fqs->qs_btimelimit = state.s_state[type].spc_timelimit;
472bc230e4aSJan Kara fqs->qs_itimelimit = state.s_state[type].ino_timelimit;
473bc230e4aSJan Kara fqs->qs_rtbtimelimit = state.s_state[type].rt_spc_timelimit;
474bc230e4aSJan Kara fqs->qs_bwarnlimit = state.s_state[type].spc_warnlimit;
475bc230e4aSJan Kara fqs->qs_iwarnlimit = state.s_state[type].ino_warnlimit;
476f998d7d5SDarrick J. Wong fqs->qs_rtbwarnlimit = state.s_state[type].rt_spc_warnlimit;
4773cd0126dSEric Sandeen
4783cd0126dSEric Sandeen /* Inodes may be allocated even if inactive; copy out if present */
4793cd0126dSEric Sandeen if (state.s_state[USRQUOTA].ino) {
480bc230e4aSJan Kara fqs->qs_uquota.qfs_ino = state.s_state[USRQUOTA].ino;
481bc230e4aSJan Kara fqs->qs_uquota.qfs_nblks = state.s_state[USRQUOTA].blocks;
482bc230e4aSJan Kara fqs->qs_uquota.qfs_nextents = state.s_state[USRQUOTA].nextents;
483bc230e4aSJan Kara }
4843cd0126dSEric Sandeen if (state.s_state[GRPQUOTA].ino) {
485bc230e4aSJan Kara fqs->qs_gquota.qfs_ino = state.s_state[GRPQUOTA].ino;
486bc230e4aSJan Kara fqs->qs_gquota.qfs_nblks = state.s_state[GRPQUOTA].blocks;
487bc230e4aSJan Kara fqs->qs_gquota.qfs_nextents = state.s_state[GRPQUOTA].nextents;
488bc230e4aSJan Kara }
4893cd0126dSEric Sandeen if (state.s_state[PRJQUOTA].ino) {
490bc230e4aSJan Kara fqs->qs_pquota.qfs_ino = state.s_state[PRJQUOTA].ino;
491bc230e4aSJan Kara fqs->qs_pquota.qfs_nblks = state.s_state[PRJQUOTA].blocks;
492bc230e4aSJan Kara fqs->qs_pquota.qfs_nextents = state.s_state[PRJQUOTA].nextents;
493bc230e4aSJan Kara }
494bc230e4aSJan Kara return 0;
495bc230e4aSJan Kara }
496bc230e4aSJan Kara
quota_getxstatev(struct super_block * sb,int type,void __user * addr)497555b2c3dSEric Sandeen static int quota_getxstatev(struct super_block *sb, int type, void __user *addr)
498af30cb44SChandra Seetharaman {
499af30cb44SChandra Seetharaman struct fs_quota_statv fqs;
500af30cb44SChandra Seetharaman int ret;
501af30cb44SChandra Seetharaman
50259b6ba69SJan Kara if (!sb->s_qcop->get_state)
503af30cb44SChandra Seetharaman return -ENOSYS;
504af30cb44SChandra Seetharaman
505af30cb44SChandra Seetharaman memset(&fqs, 0, sizeof(fqs));
506af30cb44SChandra Seetharaman if (copy_from_user(&fqs, addr, 1)) /* Just read qs_version */
507af30cb44SChandra Seetharaman return -EFAULT;
508af30cb44SChandra Seetharaman
509af30cb44SChandra Seetharaman /* If this kernel doesn't support user specified version, fail */
510af30cb44SChandra Seetharaman switch (fqs.qs_version) {
511af30cb44SChandra Seetharaman case FS_QSTATV_VERSION1:
512af30cb44SChandra Seetharaman break;
513af30cb44SChandra Seetharaman default:
514af30cb44SChandra Seetharaman return -EINVAL;
515af30cb44SChandra Seetharaman }
516555b2c3dSEric Sandeen ret = quota_getstatev(sb, type, &fqs);
517af30cb44SChandra Seetharaman if (!ret && copy_to_user(addr, &fqs, sizeof(fqs)))
518af30cb44SChandra Seetharaman return -EFAULT;
519af30cb44SChandra Seetharaman return ret;
520af30cb44SChandra Seetharaman }
521af30cb44SChandra Seetharaman
52214bf61ffSJan Kara /*
52314bf61ffSJan Kara * XFS defines BBTOB and BTOBB macros inside fs/xfs/ and we cannot move them
52414bf61ffSJan Kara * out of there as xfsprogs rely on definitions being in that header file. So
52514bf61ffSJan Kara * just define same functions here for quota purposes.
52614bf61ffSJan Kara */
52714bf61ffSJan Kara #define XFS_BB_SHIFT 9
52814bf61ffSJan Kara
quota_bbtob(u64 blocks)52914bf61ffSJan Kara static inline u64 quota_bbtob(u64 blocks)
53014bf61ffSJan Kara {
53114bf61ffSJan Kara return blocks << XFS_BB_SHIFT;
53214bf61ffSJan Kara }
53314bf61ffSJan Kara
quota_btobb(u64 bytes)53414bf61ffSJan Kara static inline u64 quota_btobb(u64 bytes)
53514bf61ffSJan Kara {
53614bf61ffSJan Kara return (bytes + (1 << XFS_BB_SHIFT) - 1) >> XFS_BB_SHIFT;
53714bf61ffSJan Kara }
53814bf61ffSJan Kara
copy_from_xfs_dqblk_ts(const struct fs_disk_quota * d,__s32 timer,__s8 timer_hi)539ad47ff33SDarrick J. Wong static inline s64 copy_from_xfs_dqblk_ts(const struct fs_disk_quota *d,
540ad47ff33SDarrick J. Wong __s32 timer, __s8 timer_hi)
541ad47ff33SDarrick J. Wong {
542ad47ff33SDarrick J. Wong if (d->d_fieldmask & FS_DQ_BIGTIME)
543ad47ff33SDarrick J. Wong return (u32)timer | (s64)timer_hi << 32;
544ad47ff33SDarrick J. Wong return timer;
545ad47ff33SDarrick J. Wong }
546ad47ff33SDarrick J. Wong
copy_from_xfs_dqblk(struct qc_dqblk * dst,struct fs_disk_quota * src)54714bf61ffSJan Kara static void copy_from_xfs_dqblk(struct qc_dqblk *dst, struct fs_disk_quota *src)
54814bf61ffSJan Kara {
54914bf61ffSJan Kara dst->d_spc_hardlimit = quota_bbtob(src->d_blk_hardlimit);
55014bf61ffSJan Kara dst->d_spc_softlimit = quota_bbtob(src->d_blk_softlimit);
55114bf61ffSJan Kara dst->d_ino_hardlimit = src->d_ino_hardlimit;
55214bf61ffSJan Kara dst->d_ino_softlimit = src->d_ino_softlimit;
55314bf61ffSJan Kara dst->d_space = quota_bbtob(src->d_bcount);
55414bf61ffSJan Kara dst->d_ino_count = src->d_icount;
555ad47ff33SDarrick J. Wong dst->d_ino_timer = copy_from_xfs_dqblk_ts(src, src->d_itimer,
556ad47ff33SDarrick J. Wong src->d_itimer_hi);
557ad47ff33SDarrick J. Wong dst->d_spc_timer = copy_from_xfs_dqblk_ts(src, src->d_btimer,
558ad47ff33SDarrick J. Wong src->d_btimer_hi);
55914bf61ffSJan Kara dst->d_ino_warns = src->d_iwarns;
56014bf61ffSJan Kara dst->d_spc_warns = src->d_bwarns;
56114bf61ffSJan Kara dst->d_rt_spc_hardlimit = quota_bbtob(src->d_rtb_hardlimit);
56214bf61ffSJan Kara dst->d_rt_spc_softlimit = quota_bbtob(src->d_rtb_softlimit);
56314bf61ffSJan Kara dst->d_rt_space = quota_bbtob(src->d_rtbcount);
564ad47ff33SDarrick J. Wong dst->d_rt_spc_timer = copy_from_xfs_dqblk_ts(src, src->d_rtbtimer,
565ad47ff33SDarrick J. Wong src->d_rtbtimer_hi);
56614bf61ffSJan Kara dst->d_rt_spc_warns = src->d_rtbwarns;
56714bf61ffSJan Kara dst->d_fieldmask = 0;
56814bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_ISOFT)
56914bf61ffSJan Kara dst->d_fieldmask |= QC_INO_SOFT;
57014bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_IHARD)
57114bf61ffSJan Kara dst->d_fieldmask |= QC_INO_HARD;
57214bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_BSOFT)
57314bf61ffSJan Kara dst->d_fieldmask |= QC_SPC_SOFT;
57414bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_BHARD)
57514bf61ffSJan Kara dst->d_fieldmask |= QC_SPC_HARD;
57614bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_RTBSOFT)
57714bf61ffSJan Kara dst->d_fieldmask |= QC_RT_SPC_SOFT;
57814bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_RTBHARD)
57914bf61ffSJan Kara dst->d_fieldmask |= QC_RT_SPC_HARD;
58014bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_BTIMER)
58114bf61ffSJan Kara dst->d_fieldmask |= QC_SPC_TIMER;
58214bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_ITIMER)
58314bf61ffSJan Kara dst->d_fieldmask |= QC_INO_TIMER;
58414bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_RTBTIMER)
58514bf61ffSJan Kara dst->d_fieldmask |= QC_RT_SPC_TIMER;
58614bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_BWARNS)
58714bf61ffSJan Kara dst->d_fieldmask |= QC_SPC_WARNS;
58814bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_IWARNS)
58914bf61ffSJan Kara dst->d_fieldmask |= QC_INO_WARNS;
59014bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_RTBWARNS)
59114bf61ffSJan Kara dst->d_fieldmask |= QC_RT_SPC_WARNS;
59214bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_BCOUNT)
59314bf61ffSJan Kara dst->d_fieldmask |= QC_SPACE;
59414bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_ICOUNT)
59514bf61ffSJan Kara dst->d_fieldmask |= QC_INO_COUNT;
59614bf61ffSJan Kara if (src->d_fieldmask & FS_DQ_RTBCOUNT)
59714bf61ffSJan Kara dst->d_fieldmask |= QC_RT_SPACE;
59814bf61ffSJan Kara }
59914bf61ffSJan Kara
copy_qcinfo_from_xfs_dqblk(struct qc_info * dst,struct fs_disk_quota * src)600c39fb53bSJan Kara static void copy_qcinfo_from_xfs_dqblk(struct qc_info *dst,
601c39fb53bSJan Kara struct fs_disk_quota *src)
602c39fb53bSJan Kara {
603c39fb53bSJan Kara memset(dst, 0, sizeof(*dst));
604c39fb53bSJan Kara dst->i_spc_timelimit = src->d_btimer;
605c39fb53bSJan Kara dst->i_ino_timelimit = src->d_itimer;
606c39fb53bSJan Kara dst->i_rt_spc_timelimit = src->d_rtbtimer;
607c39fb53bSJan Kara dst->i_ino_warnlimit = src->d_iwarns;
608c39fb53bSJan Kara dst->i_spc_warnlimit = src->d_bwarns;
609c39fb53bSJan Kara dst->i_rt_spc_warnlimit = src->d_rtbwarns;
610c39fb53bSJan Kara if (src->d_fieldmask & FS_DQ_BWARNS)
611c39fb53bSJan Kara dst->i_fieldmask |= QC_SPC_WARNS;
612c39fb53bSJan Kara if (src->d_fieldmask & FS_DQ_IWARNS)
613c39fb53bSJan Kara dst->i_fieldmask |= QC_INO_WARNS;
614c39fb53bSJan Kara if (src->d_fieldmask & FS_DQ_RTBWARNS)
615c39fb53bSJan Kara dst->i_fieldmask |= QC_RT_SPC_WARNS;
616c39fb53bSJan Kara if (src->d_fieldmask & FS_DQ_BTIMER)
617c39fb53bSJan Kara dst->i_fieldmask |= QC_SPC_TIMER;
618c39fb53bSJan Kara if (src->d_fieldmask & FS_DQ_ITIMER)
619c39fb53bSJan Kara dst->i_fieldmask |= QC_INO_TIMER;
620c39fb53bSJan Kara if (src->d_fieldmask & FS_DQ_RTBTIMER)
621c39fb53bSJan Kara dst->i_fieldmask |= QC_RT_SPC_TIMER;
622c39fb53bSJan Kara }
623c39fb53bSJan Kara
quota_setxquota(struct super_block * sb,int type,qid_t id,void __user * addr)624c411e5f6SChristoph Hellwig static int quota_setxquota(struct super_block *sb, int type, qid_t id,
625c411e5f6SChristoph Hellwig void __user *addr)
626c411e5f6SChristoph Hellwig {
627884d179dSJan Kara struct fs_disk_quota fdq;
62814bf61ffSJan Kara struct qc_dqblk qdq;
62974a8a103SEric W. Biederman struct kqid qid;
630884d179dSJan Kara
631884d179dSJan Kara if (copy_from_user(&fdq, addr, sizeof(fdq)))
632884d179dSJan Kara return -EFAULT;
633c472b432SChristoph Hellwig if (!sb->s_qcop->set_dqblk)
634f450d4feSChristoph Hellwig return -ENOSYS;
63574a8a103SEric W. Biederman qid = make_kqid(current_user_ns(), type, id);
636d49d3762SEric W. Biederman if (!qid_has_mapping(sb->s_user_ns, qid))
63774a8a103SEric W. Biederman return -EINVAL;
638c39fb53bSJan Kara /* Are we actually setting timer / warning limits for all users? */
639cfd4c70aSEric W. Biederman if (from_kqid(sb->s_user_ns, qid) == 0 &&
640c39fb53bSJan Kara fdq.d_fieldmask & (FS_DQ_WARNS_MASK | FS_DQ_TIMER_MASK)) {
641c39fb53bSJan Kara struct qc_info qinfo;
642c39fb53bSJan Kara int ret;
643c39fb53bSJan Kara
644c39fb53bSJan Kara if (!sb->s_qcop->set_info)
645c39fb53bSJan Kara return -EINVAL;
646c39fb53bSJan Kara copy_qcinfo_from_xfs_dqblk(&qinfo, &fdq);
647c39fb53bSJan Kara ret = sb->s_qcop->set_info(sb, type, &qinfo);
648c39fb53bSJan Kara if (ret)
649c39fb53bSJan Kara return ret;
650c39fb53bSJan Kara /* These are already done */
651c39fb53bSJan Kara fdq.d_fieldmask &= ~(FS_DQ_WARNS_MASK | FS_DQ_TIMER_MASK);
652c39fb53bSJan Kara }
65314bf61ffSJan Kara copy_from_xfs_dqblk(&qdq, &fdq);
65414bf61ffSJan Kara return sb->s_qcop->set_dqblk(sb, qid, &qdq);
65514bf61ffSJan Kara }
65614bf61ffSJan Kara
copy_to_xfs_dqblk_ts(const struct fs_disk_quota * d,__s32 * timer_lo,__s8 * timer_hi,s64 timer)657ad47ff33SDarrick J. Wong static inline void copy_to_xfs_dqblk_ts(const struct fs_disk_quota *d,
658ad47ff33SDarrick J. Wong __s32 *timer_lo, __s8 *timer_hi, s64 timer)
659ad47ff33SDarrick J. Wong {
660ad47ff33SDarrick J. Wong *timer_lo = timer;
661ad47ff33SDarrick J. Wong if (d->d_fieldmask & FS_DQ_BIGTIME)
662ad47ff33SDarrick J. Wong *timer_hi = timer >> 32;
663ad47ff33SDarrick J. Wong }
664ad47ff33SDarrick J. Wong
want_bigtime(s64 timer)665ad47ff33SDarrick J. Wong static inline bool want_bigtime(s64 timer)
666ad47ff33SDarrick J. Wong {
667ad47ff33SDarrick J. Wong return timer > S32_MAX || timer < S32_MIN;
668ad47ff33SDarrick J. Wong }
669ad47ff33SDarrick J. Wong
copy_to_xfs_dqblk(struct fs_disk_quota * dst,struct qc_dqblk * src,int type,qid_t id)67014bf61ffSJan Kara static void copy_to_xfs_dqblk(struct fs_disk_quota *dst, struct qc_dqblk *src,
67114bf61ffSJan Kara int type, qid_t id)
67214bf61ffSJan Kara {
67314bf61ffSJan Kara memset(dst, 0, sizeof(*dst));
674ad47ff33SDarrick J. Wong if (want_bigtime(src->d_ino_timer) || want_bigtime(src->d_spc_timer) ||
675ad47ff33SDarrick J. Wong want_bigtime(src->d_rt_spc_timer))
676ad47ff33SDarrick J. Wong dst->d_fieldmask |= FS_DQ_BIGTIME;
67714bf61ffSJan Kara dst->d_version = FS_DQUOT_VERSION;
67814bf61ffSJan Kara dst->d_id = id;
67914bf61ffSJan Kara if (type == USRQUOTA)
68014bf61ffSJan Kara dst->d_flags = FS_USER_QUOTA;
68114bf61ffSJan Kara else if (type == PRJQUOTA)
68214bf61ffSJan Kara dst->d_flags = FS_PROJ_QUOTA;
68314bf61ffSJan Kara else
68414bf61ffSJan Kara dst->d_flags = FS_GROUP_QUOTA;
68514bf61ffSJan Kara dst->d_blk_hardlimit = quota_btobb(src->d_spc_hardlimit);
68614bf61ffSJan Kara dst->d_blk_softlimit = quota_btobb(src->d_spc_softlimit);
68714bf61ffSJan Kara dst->d_ino_hardlimit = src->d_ino_hardlimit;
68814bf61ffSJan Kara dst->d_ino_softlimit = src->d_ino_softlimit;
68914bf61ffSJan Kara dst->d_bcount = quota_btobb(src->d_space);
69014bf61ffSJan Kara dst->d_icount = src->d_ino_count;
691ad47ff33SDarrick J. Wong copy_to_xfs_dqblk_ts(dst, &dst->d_itimer, &dst->d_itimer_hi,
692ad47ff33SDarrick J. Wong src->d_ino_timer);
693ad47ff33SDarrick J. Wong copy_to_xfs_dqblk_ts(dst, &dst->d_btimer, &dst->d_btimer_hi,
694ad47ff33SDarrick J. Wong src->d_spc_timer);
69514bf61ffSJan Kara dst->d_iwarns = src->d_ino_warns;
69614bf61ffSJan Kara dst->d_bwarns = src->d_spc_warns;
69714bf61ffSJan Kara dst->d_rtb_hardlimit = quota_btobb(src->d_rt_spc_hardlimit);
69814bf61ffSJan Kara dst->d_rtb_softlimit = quota_btobb(src->d_rt_spc_softlimit);
69914bf61ffSJan Kara dst->d_rtbcount = quota_btobb(src->d_rt_space);
700ad47ff33SDarrick J. Wong copy_to_xfs_dqblk_ts(dst, &dst->d_rtbtimer, &dst->d_rtbtimer_hi,
701ad47ff33SDarrick J. Wong src->d_rt_spc_timer);
70214bf61ffSJan Kara dst->d_rtbwarns = src->d_rt_spc_warns;
703884d179dSJan Kara }
704c411e5f6SChristoph Hellwig
quota_getxquota(struct super_block * sb,int type,qid_t id,void __user * addr)705c411e5f6SChristoph Hellwig static int quota_getxquota(struct super_block *sb, int type, qid_t id,
706c411e5f6SChristoph Hellwig void __user *addr)
707c411e5f6SChristoph Hellwig {
708884d179dSJan Kara struct fs_disk_quota fdq;
70914bf61ffSJan Kara struct qc_dqblk qdq;
71074a8a103SEric W. Biederman struct kqid qid;
711c411e5f6SChristoph Hellwig int ret;
712884d179dSJan Kara
713b9b2dd36SChristoph Hellwig if (!sb->s_qcop->get_dqblk)
714f450d4feSChristoph Hellwig return -ENOSYS;
71574a8a103SEric W. Biederman qid = make_kqid(current_user_ns(), type, id);
716d49d3762SEric W. Biederman if (!qid_has_mapping(sb->s_user_ns, qid))
71774a8a103SEric W. Biederman return -EINVAL;
71814bf61ffSJan Kara ret = sb->s_qcop->get_dqblk(sb, qid, &qdq);
71914bf61ffSJan Kara if (ret)
72014bf61ffSJan Kara return ret;
72114bf61ffSJan Kara copy_to_xfs_dqblk(&fdq, &qdq, type, id);
72214bf61ffSJan Kara if (copy_to_user(addr, &fdq, sizeof(fdq)))
723884d179dSJan Kara return -EFAULT;
724c411e5f6SChristoph Hellwig return ret;
725884d179dSJan Kara }
726c411e5f6SChristoph Hellwig
7278b375249SEric Sandeen /*
7288b375249SEric Sandeen * Return quota for next active quota >= this id, if any exists,
729ba58148bSEric Sandeen * otherwise return -ENOENT via ->get_nextdqblk.
7308b375249SEric Sandeen */
quota_getnextxquota(struct super_block * sb,int type,qid_t id,void __user * addr)7318b375249SEric Sandeen static int quota_getnextxquota(struct super_block *sb, int type, qid_t id,
7328b375249SEric Sandeen void __user *addr)
7338b375249SEric Sandeen {
7348b375249SEric Sandeen struct fs_disk_quota fdq;
7358b375249SEric Sandeen struct qc_dqblk qdq;
7368b375249SEric Sandeen struct kqid qid;
7378b375249SEric Sandeen qid_t id_out;
7388b375249SEric Sandeen int ret;
7398b375249SEric Sandeen
7408b375249SEric Sandeen if (!sb->s_qcop->get_nextdqblk)
7418b375249SEric Sandeen return -ENOSYS;
7428b375249SEric Sandeen qid = make_kqid(current_user_ns(), type, id);
743d49d3762SEric W. Biederman if (!qid_has_mapping(sb->s_user_ns, qid))
7448b375249SEric Sandeen return -EINVAL;
7458b375249SEric Sandeen ret = sb->s_qcop->get_nextdqblk(sb, &qid, &qdq);
7468b375249SEric Sandeen if (ret)
7478b375249SEric Sandeen return ret;
7488b375249SEric Sandeen id_out = from_kqid(current_user_ns(), qid);
7498b375249SEric Sandeen copy_to_xfs_dqblk(&fdq, &qdq, type, id_out);
7508b375249SEric Sandeen if (copy_to_user(addr, &fdq, sizeof(fdq)))
7518b375249SEric Sandeen return -EFAULT;
7528b375249SEric Sandeen return ret;
7538b375249SEric Sandeen }
7548b375249SEric Sandeen
quota_rmxquota(struct super_block * sb,void __user * addr)7559da93f9bSEric Sandeen static int quota_rmxquota(struct super_block *sb, void __user *addr)
7569da93f9bSEric Sandeen {
7579da93f9bSEric Sandeen __u32 flags;
7589da93f9bSEric Sandeen
7599da93f9bSEric Sandeen if (copy_from_user(&flags, addr, sizeof(flags)))
7609da93f9bSEric Sandeen return -EFAULT;
7619da93f9bSEric Sandeen if (!sb->s_qcop->rm_xquota)
7629da93f9bSEric Sandeen return -ENOSYS;
7639da93f9bSEric Sandeen return sb->s_qcop->rm_xquota(sb, flags);
7649da93f9bSEric Sandeen }
7659da93f9bSEric Sandeen
766c411e5f6SChristoph Hellwig /* Copy parameters and call proper function */
do_quotactl(struct super_block * sb,int type,int cmd,qid_t id,void __user * addr,const struct path * path)767c411e5f6SChristoph Hellwig static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
7688c54ca9cSAl Viro void __user *addr, const struct path *path)
769c411e5f6SChristoph Hellwig {
770c988afb5SChristoph Hellwig int ret;
771c988afb5SChristoph Hellwig
7727b6924d9SJeremy Cline type = array_index_nospec(type, MAXQUOTAS);
7732c5f648aSJan Kara /*
7742c5f648aSJan Kara * Quota not supported on this fs? Check this before s_quota_types
7752c5f648aSJan Kara * since they needn't be set if quota is not supported at all.
7762c5f648aSJan Kara */
777c988afb5SChristoph Hellwig if (!sb->s_qcop)
778c988afb5SChristoph Hellwig return -ENOSYS;
7792c5f648aSJan Kara if (!(sb->s_quota_types & (1 << type)))
7802c5f648aSJan Kara return -EINVAL;
781c988afb5SChristoph Hellwig
782c988afb5SChristoph Hellwig ret = check_quotactl_permission(sb, type, cmd, id);
783c988afb5SChristoph Hellwig if (ret < 0)
784c988afb5SChristoph Hellwig return ret;
785c988afb5SChristoph Hellwig
786c411e5f6SChristoph Hellwig switch (cmd) {
787c411e5f6SChristoph Hellwig case Q_QUOTAON:
7883218a3ecSEric Sandeen return quota_quotaon(sb, type, id, path);
789c411e5f6SChristoph Hellwig case Q_QUOTAOFF:
790d3b86324SJan Kara return quota_quotaoff(sb, type);
791c411e5f6SChristoph Hellwig case Q_GETFMT:
792c411e5f6SChristoph Hellwig return quota_getfmt(sb, type, addr);
793c411e5f6SChristoph Hellwig case Q_GETINFO:
794c411e5f6SChristoph Hellwig return quota_getinfo(sb, type, addr);
795c411e5f6SChristoph Hellwig case Q_SETINFO:
796c411e5f6SChristoph Hellwig return quota_setinfo(sb, type, addr);
797c411e5f6SChristoph Hellwig case Q_GETQUOTA:
798c411e5f6SChristoph Hellwig return quota_getquota(sb, type, id, addr);
799926132c0SEric Sandeen case Q_GETNEXTQUOTA:
800926132c0SEric Sandeen return quota_getnextquota(sb, type, id, addr);
801c411e5f6SChristoph Hellwig case Q_SETQUOTA:
802c411e5f6SChristoph Hellwig return quota_setquota(sb, type, id, addr);
803c411e5f6SChristoph Hellwig case Q_SYNC:
804f450d4feSChristoph Hellwig if (!sb->s_qcop->quota_sync)
805f450d4feSChristoph Hellwig return -ENOSYS;
806ceed1723SJan Kara return sb->s_qcop->quota_sync(sb, type);
807c411e5f6SChristoph Hellwig case Q_XQUOTAON:
80838e478c4SJan Kara return quota_enable(sb, addr);
809c411e5f6SChristoph Hellwig case Q_XQUOTAOFF:
81038e478c4SJan Kara return quota_disable(sb, addr);
8119da93f9bSEric Sandeen case Q_XQUOTARM:
8129da93f9bSEric Sandeen return quota_rmxquota(sb, addr);
813c411e5f6SChristoph Hellwig case Q_XGETQSTAT:
814555b2c3dSEric Sandeen return quota_getxstate(sb, type, addr);
815af30cb44SChandra Seetharaman case Q_XGETQSTATV:
816555b2c3dSEric Sandeen return quota_getxstatev(sb, type, addr);
817c411e5f6SChristoph Hellwig case Q_XSETQLIM:
818c411e5f6SChristoph Hellwig return quota_setxquota(sb, type, id, addr);
819c411e5f6SChristoph Hellwig case Q_XGETQUOTA:
820c411e5f6SChristoph Hellwig return quota_getxquota(sb, type, id, addr);
8218b375249SEric Sandeen case Q_XGETNEXTQUOTA:
8228b375249SEric Sandeen return quota_getnextxquota(sb, type, id, addr);
823884d179dSJan Kara case Q_XQUOTASYNC:
824bc98a42cSDavid Howells if (sb_rdonly(sb))
8258c4e4acdSChristoph Hellwig return -EROFS;
8264b217ed9SChristoph Hellwig /* XFS quotas are fully coherent now, making this call a noop */
8278c4e4acdSChristoph Hellwig return 0;
828884d179dSJan Kara default:
829f450d4feSChristoph Hellwig return -EINVAL;
830884d179dSJan Kara }
831884d179dSJan Kara }
832884d179dSJan Kara
833dcdbed85SJan Kara /* Return 1 if 'cmd' will block on frozen filesystem */
quotactl_cmd_write(int cmd)834dcdbed85SJan Kara static int quotactl_cmd_write(int cmd)
835dcdbed85SJan Kara {
836ccf370e4SJan Kara /*
837ccf370e4SJan Kara * We cannot allow Q_GETQUOTA and Q_GETNEXTQUOTA without write access
838ccf370e4SJan Kara * as dquot_acquire() may allocate space for new structure and OCFS2
839ccf370e4SJan Kara * needs to increment on-disk use count.
840ccf370e4SJan Kara */
841dcdbed85SJan Kara switch (cmd) {
842dcdbed85SJan Kara case Q_GETFMT:
843dcdbed85SJan Kara case Q_GETINFO:
844dcdbed85SJan Kara case Q_SYNC:
845dcdbed85SJan Kara case Q_XGETQSTAT:
846af30cb44SChandra Seetharaman case Q_XGETQSTATV:
847dcdbed85SJan Kara case Q_XGETQUOTA:
8488b375249SEric Sandeen case Q_XGETNEXTQUOTA:
849dcdbed85SJan Kara case Q_XQUOTASYNC:
850dcdbed85SJan Kara return 0;
851dcdbed85SJan Kara }
852dcdbed85SJan Kara return 1;
853dcdbed85SJan Kara }
85456df1278SLee Jones
8557d6cd73dSJan Kara /* Return true if quotactl command is manipulating quota on/off state */
quotactl_cmd_onoff(int cmd)8567d6cd73dSJan Kara static bool quotactl_cmd_onoff(int cmd)
8577d6cd73dSJan Kara {
85841c4f85cSJavier Barrio return (cmd == Q_QUOTAON) || (cmd == Q_QUOTAOFF) ||
85941c4f85cSJavier Barrio (cmd == Q_XQUOTAON) || (cmd == Q_XQUOTAOFF);
8607d6cd73dSJan Kara }
8617d6cd73dSJan Kara
862884d179dSJan Kara /*
863884d179dSJan Kara * look up a superblock on which quota ops will be performed
864884d179dSJan Kara * - use the name of a block device to find the superblock thereon
865884d179dSJan Kara */
quotactl_block(const char __user * special,int cmd)866dcdbed85SJan Kara static struct super_block *quotactl_block(const char __user *special, int cmd)
867884d179dSJan Kara {
868884d179dSJan Kara #ifdef CONFIG_BLOCK
869884d179dSJan Kara struct super_block *sb;
87091a27b2aSJeff Layton struct filename *tmp = getname(special);
87160b49885SChristoph Hellwig bool excl = false, thawed = false;
8724e7b5671SChristoph Hellwig int error;
8734e7b5671SChristoph Hellwig dev_t dev;
874884d179dSJan Kara
875884d179dSJan Kara if (IS_ERR(tmp))
876884d179dSJan Kara return ERR_CAST(tmp);
8774e7b5671SChristoph Hellwig error = lookup_bdev(tmp->name, &dev);
878884d179dSJan Kara putname(tmp);
8794e7b5671SChristoph Hellwig if (error)
8804e7b5671SChristoph Hellwig return ERR_PTR(error);
88160b49885SChristoph Hellwig
88260b49885SChristoph Hellwig if (quotactl_cmd_onoff(cmd)) {
88360b49885SChristoph Hellwig excl = true;
88460b49885SChristoph Hellwig thawed = true;
88560b49885SChristoph Hellwig } else if (quotactl_cmd_write(cmd)) {
88660b49885SChristoph Hellwig thawed = true;
88760b49885SChristoph Hellwig }
88860b49885SChristoph Hellwig
88960b49885SChristoph Hellwig retry:
8904e7b5671SChristoph Hellwig sb = user_get_super(dev, excl);
8914e7b5671SChristoph Hellwig if (!sb)
8924e7b5671SChristoph Hellwig return ERR_PTR(-ENODEV);
8934e7b5671SChristoph Hellwig if (thawed && sb->s_writers.frozen != SB_UNFROZEN) {
89460b49885SChristoph Hellwig if (excl)
89560b49885SChristoph Hellwig up_write(&sb->s_umount);
896dcdbed85SJan Kara else
89760b49885SChristoph Hellwig up_read(&sb->s_umount);
898*576215cfSJan Kara /* Wait for sb to unfreeze */
899*576215cfSJan Kara sb_start_write(sb);
900*576215cfSJan Kara sb_end_write(sb);
90160b49885SChristoph Hellwig put_super(sb);
90260b49885SChristoph Hellwig goto retry;
90360b49885SChristoph Hellwig }
904884d179dSJan Kara return sb;
90560b49885SChristoph Hellwig
906884d179dSJan Kara #else
907884d179dSJan Kara return ERR_PTR(-ENODEV);
908884d179dSJan Kara #endif
909884d179dSJan Kara }
910884d179dSJan Kara
911884d179dSJan Kara /*
912884d179dSJan Kara * This is the system call interface. This communicates with
913884d179dSJan Kara * the user-level programs. Currently this only supports diskquota
914884d179dSJan Kara * calls. Maybe we need to add the process quotas etc. in the future,
915884d179dSJan Kara * but we probably should use rlimits for that.
916884d179dSJan Kara */
SYSCALL_DEFINE4(quotactl,unsigned int,cmd,const char __user *,special,qid_t,id,void __user *,addr)91780bdad3dSChristoph Hellwig SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
91880bdad3dSChristoph Hellwig qid_t, id, void __user *, addr)
919884d179dSJan Kara {
920884d179dSJan Kara uint cmds, type;
921884d179dSJan Kara struct super_block *sb = NULL;
922f00c9e44SJan Kara struct path path, *pathp = NULL;
923884d179dSJan Kara int ret;
924884d179dSJan Kara
925884d179dSJan Kara cmds = cmd >> SUBCMDSHIFT;
926884d179dSJan Kara type = cmd & SUBCMDMASK;
927884d179dSJan Kara
928a6810312SChengguang Xu if (type >= MAXQUOTAS)
929a6810312SChengguang Xu return -EINVAL;
930a6810312SChengguang Xu
9316ae09575SChristoph Hellwig /*
9326ae09575SChristoph Hellwig * As a special case Q_SYNC can be called without a specific device.
9336ae09575SChristoph Hellwig * It will iterate all superblocks that have quota enabled and call
9346ae09575SChristoph Hellwig * the sync action on each of them.
9356ae09575SChristoph Hellwig */
9366ae09575SChristoph Hellwig if (!special) {
9376ae09575SChristoph Hellwig if (cmds == Q_SYNC)
9386ae09575SChristoph Hellwig return quota_sync_all(type);
9396ae09575SChristoph Hellwig return -ENODEV;
9406ae09575SChristoph Hellwig }
9416ae09575SChristoph Hellwig
942f00c9e44SJan Kara /*
943f00c9e44SJan Kara * Path for quotaon has to be resolved before grabbing superblock
944f00c9e44SJan Kara * because that gets s_umount sem which is also possibly needed by path
945f00c9e44SJan Kara * resolution (think about autofs) and thus deadlocks could arise.
946f00c9e44SJan Kara */
947f00c9e44SJan Kara if (cmds == Q_QUOTAON) {
948815d405cSTrond Myklebust ret = user_path_at(AT_FDCWD, addr, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &path);
949f00c9e44SJan Kara if (ret)
950f00c9e44SJan Kara pathp = ERR_PTR(ret);
951f00c9e44SJan Kara else
952f00c9e44SJan Kara pathp = &path;
953f00c9e44SJan Kara }
954f00c9e44SJan Kara
955dcdbed85SJan Kara sb = quotactl_block(special, cmds);
9560aaa6188SJan Kara if (IS_ERR(sb)) {
9570aaa6188SJan Kara ret = PTR_ERR(sb);
9580aaa6188SJan Kara goto out;
9590aaa6188SJan Kara }
960884d179dSJan Kara
961f00c9e44SJan Kara ret = do_quotactl(sb, type, cmds, id, addr, pathp);
962884d179dSJan Kara
9637d6cd73dSJan Kara if (!quotactl_cmd_onoff(cmds))
9646ae09575SChristoph Hellwig drop_super(sb);
9657d6cd73dSJan Kara else
9667d6cd73dSJan Kara drop_super_exclusive(sb);
9670aaa6188SJan Kara out:
968f00c9e44SJan Kara if (pathp && !IS_ERR(pathp))
969f00c9e44SJan Kara path_put(pathp);
970884d179dSJan Kara return ret;
971884d179dSJan Kara }
9729dfa23c8SSascha Hauer
SYSCALL_DEFINE4(quotactl_fd,unsigned int,fd,unsigned int,cmd,qid_t,id,void __user *,addr)97364c2c2c6SJan Kara SYSCALL_DEFINE4(quotactl_fd, unsigned int, fd, unsigned int, cmd,
97464c2c2c6SJan Kara qid_t, id, void __user *, addr)
9759dfa23c8SSascha Hauer {
9769dfa23c8SSascha Hauer struct super_block *sb;
9779dfa23c8SSascha Hauer unsigned int cmds = cmd >> SUBCMDSHIFT;
9789dfa23c8SSascha Hauer unsigned int type = cmd & SUBCMDMASK;
97964c2c2c6SJan Kara struct fd f;
9809dfa23c8SSascha Hauer int ret;
9819dfa23c8SSascha Hauer
98264c2c2c6SJan Kara f = fdget_raw(fd);
98364c2c2c6SJan Kara if (!f.file)
98464c2c2c6SJan Kara return -EBADF;
98564c2c2c6SJan Kara
98664c2c2c6SJan Kara ret = -EINVAL;
9879dfa23c8SSascha Hauer if (type >= MAXQUOTAS)
98864c2c2c6SJan Kara goto out;
9899dfa23c8SSascha Hauer
9909dfa23c8SSascha Hauer if (quotactl_cmd_write(cmds)) {
99164c2c2c6SJan Kara ret = mnt_want_write(f.file->f_path.mnt);
9929dfa23c8SSascha Hauer if (ret)
9939dfa23c8SSascha Hauer goto out;
9949dfa23c8SSascha Hauer }
9959dfa23c8SSascha Hauer
99664c2c2c6SJan Kara sb = f.file->f_path.mnt->mnt_sb;
9979dfa23c8SSascha Hauer if (quotactl_cmd_onoff(cmds))
9989dfa23c8SSascha Hauer down_write(&sb->s_umount);
9999dfa23c8SSascha Hauer else
10009dfa23c8SSascha Hauer down_read(&sb->s_umount);
10019dfa23c8SSascha Hauer
10029dfa23c8SSascha Hauer ret = do_quotactl(sb, type, cmds, id, addr, ERR_PTR(-EINVAL));
10039dfa23c8SSascha Hauer
10049dfa23c8SSascha Hauer if (quotactl_cmd_onoff(cmds))
10059dfa23c8SSascha Hauer up_write(&sb->s_umount);
10069dfa23c8SSascha Hauer else
10079dfa23c8SSascha Hauer up_read(&sb->s_umount);
10089dfa23c8SSascha Hauer
10099dfa23c8SSascha Hauer if (quotactl_cmd_write(cmds))
101064c2c2c6SJan Kara mnt_drop_write(f.file->f_path.mnt);
10119dfa23c8SSascha Hauer out:
101264c2c2c6SJan Kara fdput(f);
10139dfa23c8SSascha Hauer return ret;
10149dfa23c8SSascha Hauer }
1015