quota: add new quotactl Q_GETNEXTQUOTA
Subsystems (4)
v2 cover quota: add new quotactl Q_GETNEXTQUOTA
This adds a new quotactl, Q_GETNEXTQUOTA.
Q_GETNEXTQUOTA is exactly like Q_GETQUOTA, except that it will return quota information for the id equal to or greater than the id requested. In other words, if the specified id has no quota, the command will return quota information for the next higher id which does have a quota set. If no higher id has an active quota, -ESRCH is returned.
So if you ask for id X, you can get back quota for id X, id X+N, or -ESRCH if no higher id has a quota.
This allows filesystems to do efficient iteration in kernelspace, much like extN filesystems do in userspace when asked to report all active quotas.
Today, filesystems such as XFS require getpwent()-style iterations, and for systems which have i.e. LDAP backends, this can be very slow, or even impossible if iteration is not allowed in the configuration.
Patches 1 and 4 are just small fixups that turned up along the way; 2 and 3 add the actual quota plumbing, and the rest are xfs-specific to allow xfs to support this new interface.
For non-xfs quota, this does require a new structure which is able to pass back the discovered ID along with the quota info. For xfs-quota, the id is already present in the structure.
I sent a regression test to the fstests list today, and will send updated xfsprogs & linux-quota patches soon.
Thanks,
-Eric
PATCH v2 1/7 quota: remove unused cmd argument from quota_quotaon()
The cmd argument to quota_quotaon() via Q_QUOTAON quotactl is not used, so remove it.
--- fs/quota/quota.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/quota/quota.c +2 -2
@@ -79,7 +79,7 @@ unsigned int qtype_enforce_flag(int type)return 0 ; } -static int quota_quotaon (struct super_block *sb,int type,int cmd,qid_t id, +static int quota_quotaon (struct super_block *sb,int type,qid_t id,struct path *path) {if (!sb->s_qcop->quota_on && !sb->s_qcop->quota_enable)
@@ -659,7 +659,7 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,switch (cmd) {case Q_QUOTAON : -return quota_quotaon (sb, type, cmd, id, path); +return quota_quotaon (sb, type, id, path);case Q_QUOTAOFF :return quota_quotaoff (sb, type);case Q_GETFMT :
Signature · 1 line
1.7.1
PATCH v2 2/7 quota: add new quotactl Q_XGETNEXTQUOTA
In reply to Eric SandeenQ_XGETNEXTQUOTA is exactly like Q_XGETQUOTA, except that it will return quota information for the id equal to or greater than the id requested. In other words, if the requested id has no quota, the command will return quota information for the next higher id which does have a quota set. If no higher id has an active quota, -ESRCH is returned.
This allows filesystems to do efficient iteration in kernelspace, much like extN filesystems do in userspace when asked to report all active quotas.
The patch adds a d_id field to struct qc_dqblk so that we can pass back the id of the quota which was found, and return it to userspace.
Today, filesystems such as XFS require getpwent-style iterations, and for systems which have i.e. LDAP backends, this can be very slow, or even impossible if iteration is not allowed in the configuration.
--- fs/quota/quota.c | 30 ++++++++++++++++++++++++++++++ include/linux/quota.h | 3 +++ include/uapi/linux/dqblk_xfs.h | 1 + 3 files changed, 34 insertions(+), 0 deletions(-)
fs/quota/quota.c +30 -0
@@ -33,6 +33,7 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,/* allow to query information for dquots we "own" */ case Q_GETQUOTA :case Q_XGETQUOTA : +case Q_XGETNEXTQUOTA :if ((type ==USRQUOTA &&uid_eq (current_euid (),make_kuid (current_user_ns (), id))) || (type ==GRPQUOTA &&in_egroup_p (make_kgid (current_user_ns (), id))))break ;
@@ -625,6 +626,32 @@ static int quota_getxquota(struct super_block *sb, int type, qid_t id,return ret; } +/* +* Return quota for next active quota >= this id, if any exists, +* otherwise return -ESRCH via ->get_nextdqblk. +*/ +static int quota_getnextxquota (struct super_block *sb,int type,qid_t id, +void __user *addr) +{ +struct fs_disk_quota fdq; +struct qc_dqblk qdq; +struct kqid qid; +int ret; + +if (!sb->s_qcop->get_nextdqblk) +return -ENOSYS ; + qid =make_kqid (current_user_ns (), type, id); +if (!qid_valid (qid)) +return -EINVAL ; + ret = sb->s_qcop->get_nextdqblk (sb, qid, &qdq); +if (ret) +return ret; +copy_to_xfs_dqblk (&fdq, &qdq, type, qdq.d_id); +if (copy_to_user (addr, &fdq,sizeof (fdq))) +return -EFAULT ; +return ret; +} +static int quota_rmxquota (struct super_block *sb,void __user *addr) {__u32 flags;
@@ -690,6 +717,8 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,return quota_setxquota (sb, type, id, addr);case Q_XGETQUOTA :return quota_getxquota (sb, type, id, addr); +case Q_XGETNEXTQUOTA : +return quota_getnextxquota (sb, type, id, addr);case Q_XQUOTASYNC :if (sb->s_flags &MS_RDONLY )return -EROFS ;
@@ -712,6 +741,7 @@ static int quotactl_cmd_write(int cmd)case Q_XGETQSTAT :case Q_XGETQSTATV :case Q_XGETQUOTA : +case Q_XGETNEXTQUOTA :case Q_XQUOTASYNC :return 0 ; }
include/linux/quota.h +3 -0
@@ -327,6 +327,7 @@ struct path;/* Structure for communicating via ->get_dqblk() & ->set_dqblk() */ struct qc_dqblk { +u32 d_id;/* user/group/project ID for this quota */ int d_fieldmask;/* mask of fields to change in ->set_dqblk() */ u64 d_spc_hardlimit;/* absolute limit on used space */ u64 d_spc_softlimit;/* preferred limit on used space */
@@ -425,6 +426,8 @@ struct quotactl_ops {int (*quota_sync)(struct super_block *,int );int (*set_info)(struct super_block *,int ,struct qc_info *);int (*get_dqblk)(struct super_block *,struct kqid ,struct qc_dqblk *); +int (*get_nextdqblk)(struct super_block *,struct kqid , +struct qc_dqblk *);int (*set_dqblk)(struct super_block *,struct kqid ,struct qc_dqblk *);int (*get_state)(struct super_block *,struct qc_state *);int (*rm_xquota)(struct super_block *,unsigned int );
include/uapi/linux/dqblk_xfs.h +1 -0
@@ -39,6 +39,7 @@#define Q_XQUOTARM XQM_CMD(6)/* free disk space used by dquots */ #define Q_XQUOTASYNC XQM_CMD(7)/* delalloc flush, updates dquots */ #define Q_XGETQSTATV XQM_CMD(8)/* newer version of get quota */ +#define Q_XGETNEXTQUOTA XQM_CMD(9)/* get disk limits and usage >= ID */ /* * fs_disk_quota structure:
Signature · 1 line
1.7.1
Jan Kara
reviewerRe: [PATCH 2/7] quota: add new quotactl Q_XGETNEXTQUOTA
Quoted 21 lines · Eric Sandeen
Q_XGETNEXTQUOTAis exactly likeQ_XGETQUOTA, except that it will return quota information for the id equal to or greater than the id requested. In other words, if the requested id has no quota, the command will return quota information for the next higher id which does have a quota set. If no higher id has an active quota,-ESRCHis returned.This allows filesystems to do efficient iteration in kernelspace, much like extN filesystems do in userspace when asked to report all active quotas.
The patch adds a
d_idfield to structqc_dqblkso that we can pass back the id of the quota which was found, and return it to userspace.Today, filesystems such as XFS require getpwent-style iterations, and for systems which have i.e. LDAP backends, this can be very slow, or even impossible if iteration is not allowed in the configuration.
Signed-off-by Eric Sandeen <[email protected]>
...
fs/quota/quota.c static int check_quotactl_permission(struct super_block *sb, int type, int cmd, · line 36
Quoted 9 lines
fs/quota/quota.c +1
-0@@ -33,6 +33,7 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,/* allow to query information for dquots we "own" */ case Q_GETQUOTA :case Q_XGETQUOTA : +case Q_XGETNEXTQUOTA :
IMO you should require CAP_SYS_ADMIN for the quotactl. Definitely doing the UID and GID checks for GETNEXTQUOTA looks strange to me since the returned structure may be for a different ID. Or did you assume that existing user will have quota structure allocated so we always return quotas for that ID in that case? I'm not sure this is good to rely on...
fs/quota/quota.c static int quota_getxquota(struct super_block *sb, int type, qid_t id, · line 653
Quoted 8 lines
fs/quota/quota.c +8
-0+ ret = sb->s_qcop->get_nextdqblk (sb, qid, &qdq); +if (ret) +return ret; +copy_to_xfs_dqblk (&fdq, &qdq, type, qdq.d_id); +if (copy_to_user (addr, &fdq,sizeof (fdq))) +return -EFAULT ; +return ret; +}
So how about passing pointer to 'qid' to ->get_nextdqblk() and return the ID that way? That will also force you to fix the issue that you currently completely miss user-namespace conversions for the ID ;).
I definitely dislike mixing d_id in the qdq structure with arguments of fs callbacks and that d_id doesn't get filled for most callbacks. That is going to cause confusion.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 2/7] quota: add new quotactl Q_XGETNEXTQUOTA
Quoted 23 lines · Jan Kara
Quoted 21 lines · Eric Sandeen
Q_XGETNEXTQUOTAis exactly likeQ_XGETQUOTA, except that it will return quota information for the id equal to or greater than the id requested. In other words, if the requested id has no quota, the command will return quota information for the next higher id which does have a quota set. If no higher id has an active quota,-ESRCHis returned.This allows filesystems to do efficient iteration in kernelspace, much like extN filesystems do in userspace when asked to report all active quotas.
The patch adds a
d_idfield to structqc_dqblkso that we can pass back the id of the quota which was found, and return it to userspace.Today, filesystems such as XFS require getpwent-style iterations, and for systems which have i.e. LDAP backends, this can be very slow, or even impossible if iteration is not allowed in the configuration.
Signed-off-by Eric Sandeen <[email protected]>...
Quoted 15 lines
fs/quota/quota.c static int check_quotactl_permission(struct super_block *sb, int type, int cmd, · line 36
Quoted 9 lines
fs/quota/quota.c +1
-0@@ -33,6 +33,7 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,/* allow to query information for dquots we "own" */ case Q_GETQUOTA :case Q_XGETQUOTA : +case Q_XGETNEXTQUOTA :IMO you should require
CAP_SYS_ADMINfor the quotactl. Definitely doing the UID and GID checks for GETNEXTQUOTA looks strange to me since the returned structure may be for a different ID. Or did you assume that existing user will have quota structure allocated so we always return quotas for that ID in that case? I'm not sure this is good to rely on...
Oh whoops. OK that was dumb of me, thanks for catching it. No, I didn't intend to rely on the asking user having a quota, it was just a dumb mistake. :)
Quoted 4 lines
Quoted 4 lines
fs/quota/quota.c +4
-0+ ret = sb->s_qcop->get_nextdqblk (sb, qid, &qdq); +if (ret) +return ret; +copy_to_xfs_dqblk (&fdq, &qdq, type, qdq.d_id);
Quoted 8 lines
fs/quota/quota.c static int quota_getxquota(struct super_block *sb, int type, qid_t id, · line 653
Quoted 4 lines
fs/quota/quota.c +4
-0+if (copy_to_user (addr, &fdq,sizeof (fdq))) +return -EFAULT ; +return ret; +}So how about passing pointer to 'qid' to ->get_nextdqblk() and return the ID that way? That will also force you to fix the issue that you currently completely miss user-namespace conversions for the ID ;).
Ok.
Quoted 3 lines
I definitely dislike mixing
d_idin the qdq structure with arguments of fs callbacks and thatd_iddoesn't get filled for most callbacks. That is going to cause confusion.
Yeah, fair enough. I'll change it.
Thanks,
-Eric
Quoted 2 lines
Honza
PATCH v2 3/7 quota: add new quotactl Q_GETNEXTQUOTA
In reply to Eric SandeenQ_GETNEXTQUOTA is exactly like Q_GETQUOTA, except that it will return quota information for the id equal to or greater than the id requested. In other words, if the requested id has no quota, the command will return quota information for the next higher id which does have a quota set. If no higher id has an active quota, -ESRCH is returned.
This allows filesystems to do efficient iteration in kernelspace, much like extN filesystems do in userspace when asked to report all active quotas.
This does require a new data structure for userspace, as the current structure does not include an ID for the returned quota information.
Today, Ext4 with a hidden quota inode requires getpwent-style iterations, and for systems which have i.e. LDAP backends, this can be very slow, or even impossible if iteration is not allowed in the configuration.
--- fs/quota/compat.c | 27 +++++++++++++++++++++++++++ fs/quota/quota.c | 31 +++++++++++++++++++++++++++++++ include/uapi/linux/quota.h | 14 ++++++++++++++ 3 files changed, 72 insertions(+), 0 deletions(-)
fs/quota/compat.c +27 -0
@@ -19,6 +19,19 @@ struct compat_if_dqblk {compat_uint_t dqb_valid; }; +struct compat_if_nextdqblk { +compat_u64 dqb_bhardlimit; +compat_u64 dqb_bsoftlimit; +compat_u64 dqb_curspace; +compat_u64 dqb_ihardlimit; +compat_u64 dqb_isoftlimit; +compat_u64 dqb_curinodes; +compat_u64 dqb_btime; +compat_u64 dqb_itime; +compat_uint_t dqb_valid; +compat_uint_t dqb_id; +}; +/* XFS structures */ struct compat_fs_qfilestat {compat_u64 dqb_bhardlimit;
@@ -46,6 +59,8 @@ asmlinkage long sys32_quotactl(unsigned int cmd, const char __user *special,unsigned int cmds;struct if_dqblk __user *dqblk;struct compat_if_dqblk __user *compat_dqblk; +struct if_nextdqblk __user *nxtdqblk; +struct compat_if_nextdqblk __user *compat_nextdqblk;struct fs_quota_stat __user *fsqstat;struct compat_fs_quota_stat __user *compat_fsqstat;compat_uint_t data;
@@ -66,6 +81,18 @@ asmlinkage long sys32_quotactl(unsigned int cmd, const char __user *special, put_user(data, &compat_dqblk->dqb_valid)) ret = -EFAULT ;break ; +case Q_GETNEXTQUOTA : + nxtdqblk =compat_alloc_user_space (sizeof (struct if_nextdqblk )); + compat_nextdqblk = addr; + ret =sys_quotactl (cmd, special, id, nxtdqblk); +if (ret) +break ; +if (copy_in_user (compat_nextdqblk, nxtdqblk, +sizeof (*compat_nextdqblk)) || +get_user (data, &nxtdqblk->dqb_valid) || +put_user (data, &compat_nextdqblk->dqb_valid)) + ret = -EFAULT ; +break ;case Q_SETQUOTA : dqblk =compat_alloc_user_space (sizeof (struct if_dqblk )); compat_dqblk = addr;
fs/quota/quota.c +31 -0
@@ -32,6 +32,7 @@ static int check_quotactl_permission(struct super_block *sb, int type, int cmd,break ;/* allow to query information for dquots we "own" */ case Q_GETQUOTA : +case Q_GETNEXTQUOTA :case Q_XGETQUOTA :case Q_XGETNEXTQUOTA : if ((type == USRQUOTA && uid_eq(current_euid(), make_kuid(current_user_ns(), id))) ||
@@ -218,6 +219,34 @@ static int quota_getquota(struct super_block *sb, int type, qid_t id,if (ret)return ret;copy_to_if_dqblk (&idq, &fdq); +if (copy_to_user (addr, &idq,sizeof (struct if_dqblk ))) +return -EFAULT ; +return 0 ; +} + +/* +* Return quota for next active quota >= this id, if any exists, +* otherwise return -ESRCH via ->get_nextdqblk +*/ +static int quota_getnextquota (struct super_block *sb,int type,qid_t id, +void __user *addr) +{ +struct kqid qid; +struct qc_dqblk fdq; +struct if_nextdqblk idq; +int ret; + +if (!sb->s_qcop->get_nextdqblk) +return -ENOSYS ; + qid =make_kqid (current_user_ns (), type, id); +if (!qid_valid (qid)) +return -EINVAL ; + ret = sb->s_qcop->get_nextdqblk (sb, qid, &fdq); +if (ret) +return ret; +/* struct if_nextdqblk is a superset of struct if_dqblk */ +copy_to_if_dqblk ((struct if_dqblk *)&idq, &fdq); + idq.dqb_id = fdq.d_id;if (copy_to_user (addr, &idq,sizeof (idq)))return -EFAULT ;return 0 ;
@@ -697,6 +726,8 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,return quota_setinfo (sb, type, addr);case Q_GETQUOTA :return quota_getquota (sb, type, id, addr); +case Q_GETNEXTQUOTA : +return quota_getnextquota (sb, type, id, addr);case Q_SETQUOTA :return quota_setquota (sb, type, id, addr);case Q_SYNC :
include/uapi/linux/quota.h +14 -0
@@ -71,6 +71,7 @@#define Q_SETINFO 0x800006/* set information about quota files */ #define Q_GETQUOTA 0x800007/* get user quota structure */ #define Q_SETQUOTA 0x800008/* set user quota structure */ +#define Q_GETNEXTQUOTA 0x800009/* get disk limits and usage >= ID */ /* Quota format type IDs */ #define QFMT_VFS_OLD 1
@@ -119,6 +120,19 @@ struct if_dqblk {__u32 dqb_valid; }; +struct if_nextdqblk { +__u64 dqb_bhardlimit; +__u64 dqb_bsoftlimit; +__u64 dqb_curspace; +__u64 dqb_ihardlimit; +__u64 dqb_isoftlimit; +__u64 dqb_curinodes; +__u64 dqb_btime; +__u64 dqb_itime; +__u32 dqb_valid; +__u32 dqb_id; +}; +/* * Structure used for setting quota information about file via quotactl * Following flags are used to specify which fields are valid
Signature · 1 line
1.7.1
Jan Kara
reviewerQuoted 15 lines · Eric Sandeen
Q_GETNEXTQUOTAis exactly likeQ_GETQUOTA, except that it will return quota information for the id equal to or greater than the id requested. In other words, if the requested id has no quota, the command will return quota information for the next higher id which does have a quota set. If no higher id has an active quota,-ESRCHis returned.This allows filesystems to do efficient iteration in kernelspace, much like extN filesystems do in userspace when asked to report all active quotas.
This does require a new data structure for userspace, as the current structure does not include an ID for the returned quota information.
Quoted 6 lines
Today, Ext4 with a hidden quota inode requires getpwent-style iterations, and for systems which have i.e. LDAP backends, this can be very slow, or even impossible if iteration is not allowed in the configuration.
Signed-off-by Eric Sandeen <[email protected]>
Same comments as for XFS version apply here. Furthermore:
Quoted 11 lines
fs/quota/compat.c +3
-0@@ -19,6 +19,19 @@ struct compat_if_dqblk {compat_uint_t dqb_valid; }; +struct compat_if_nextdqblk { +compat_u64 dqb_bhardlimit; +compat_u64 dqb_bsoftlimit;
fs/quota/compat.c struct compat_if_dqblk { · line 34
Quoted 10 lines
fs/quota/compat.c +10
-0+compat_u64 dqb_curspace; +compat_u64 dqb_ihardlimit; +compat_u64 dqb_isoftlimit; +compat_u64 dqb_curinodes; +compat_u64 dqb_btime; +compat_u64 dqb_itime; +compat_uint_t dqb_valid; +compat_uint_t dqb_id; +}; +
Is there a need for compat version of this structure? Everything is naturally aligned and the size is a multiple of 8 bytes. But these things keep surprising me... Added CC to linux-api in a hope that there's someone who definitely knows.
On a side note when I have API people attention: AFAIU we need struct compat_if_dqblk (defined in fs/quota/compat.c) because its size is not multiple of 8 bytes, right? But what is then then reason for get_user() / put_user() when the structure is copied into userspace (see below)? copy_in_user() should have copied everything...
if (copy_in_user(compat_dqblk, dqblk, sizeof(*compat_dqblk)) ||
get_user(data, &dqblk->dqb_valid) ||
put_user(data, &compat_dqblk->dqb_valid))
ret = -EFAULT;
HonzaSignature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 1 line · Jan Kara
On Thu 21-01-16 22:07:20, Eric Sandeen wrote:
...
Quoted 1 line
Same comments as for XFS version apply here.
*nod*
Quoted 20 lines
Furthermore:
Quoted 18 lines
fs/quota/compat.c +10
-0@@ -19,6 +19,19 @@ struct compat_if_dqblk {compat_uint_t dqb_valid; }; +struct compat_if_nextdqblk { +compat_u64 dqb_bhardlimit; +compat_u64 dqb_bsoftlimit; +compat_u64 dqb_curspace; +compat_u64 dqb_ihardlimit; +compat_u64 dqb_isoftlimit; +compat_u64 dqb_curinodes; +compat_u64 dqb_btime; +compat_u64 dqb_itime; +compat_uint_t dqb_valid;
Quoted 8 lines
fs/quota/compat.c struct compat_if_dqblk { · line 34
Quoted 3 lines
fs/quota/compat.c +3
-0+compat_uint_t dqb_id; +}; +Is there a need for compat version of this structure? Everything is naturally aligned and the size is a multiple of 8 bytes. But these things keep surprising me... Added CC to linux-api in a hope that there's someone who definitely knows.
Ok, yeah, I wasn't sure. I'll take all the compat stuff out of this one, and can do a separate patch if needed, but I bet you're right, it's probably not. I did set up to test 32-compat calls, so I'll just test w/o this.
I'd be perfectly happy to drop it. :)
Thanks for the review, Jan.
-Eric
PATCH v2 4/7 xfs: don't overflow quota ID when initializing dqblk
In reply to Eric SandeenQuota IDs are unsigned, and so we can pass in values up to 2^32-1. But if we try to initialize a block containing values over MAX_INT, curid will overflow and assert.
curid holds a quota ID, so give it the proper xfs_dqid_t type (and remove the now-impossible ASSERT).
--- fs/xfs/xfs_dquot.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/xfs/xfs_dquot.c +2 -2
@@ -232,7 +232,8 @@ xfs_qm_init_dquot_blk( {struct xfs_quotainfo *q = mp->m_quotainfo;xfs_dqblk_t *d; -int curid, i; +xfs_dqid_t curid; +int i;ASSERT (tp);ASSERT (xfs_buf_islocked (bp));
@@ -243,7 +244,6 @@ xfs_qm_init_dquot_blk(* ID of the first dquot in the block - id's are zero based. */ curid = id - (id % q->qi_dqperchunk); -ASSERT (curid >=0 );memset (d,0 ,BBTOB (q->qi_dqchunklen));for (i =0 ; i < q->qi_dqperchunk; i++, d++, curid++) { d->dd_diskdq.d_magic =cpu_to_be16 (XFS_DQUOT_MAGIC );
Signature · 1 line
1.7.1
PATCH v2 5/7 xfs: get quota inode from mp & flags rather than dqp
In reply to Eric SandeenAllow us to get the appropriate quota inode from any mp & quota flags, not necessarily associated with a particular dqp. Needed for when we are searching for the next active ID with quotas and we want to examine the quota inode.
--- fs/xfs/xfs_dquot.c | 3 ++- fs/xfs/xfs_qm.h | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-)
fs/xfs/xfs_dquot.c +2 -1
@@ -464,12 +464,13 @@ xfs_qm_dqtobp(struct xfs_bmbt_irec map;int nmaps =1 , error;struct xfs_buf *bp; -struct xfs_inode *quotip =xfs_dq_to_quota_inode (dqp); +struct xfs_inode *quotip;struct xfs_mount *mp = dqp->q_mount;xfs_dqid_t id =be32_to_cpu (dqp->q_core.d_id);struct xfs_trans *tp = (tpp ? *tpp :NULL );uint lock_mode; + quotip =xfs_quota_inode (dqp->q_mount, dqp->dq_flags); dqp->q_fileoffset = (xfs_fileoff_t )id / mp->m_quotainfo->qi_dqperchunk; lock_mode =xfs_ilock_data_map_shared (quotip);
fs/xfs/xfs_qm.h +5 -5
@@ -104,15 +104,15 @@ xfs_dquot_tree( }static inline struct xfs_inode * -xfs_dq_to_quota_inode (struct xfs_dquot *dqp) +xfs_quota_inode (xfs_mount_t *mp,uint dq_flags) { -switch (dqp->dq_flags &XFS_DQ_ALLTYPES ) { +switch (dq_flags &XFS_DQ_ALLTYPES ) {case XFS_DQ_USER : -return dqp->q_mount->m_quotainfo->qi_uquotaip; +return mp->m_quotainfo->qi_uquotaip;case XFS_DQ_GROUP : -return dqp->q_mount->m_quotainfo->qi_gquotaip; +return mp->m_quotainfo->qi_gquotaip;case XFS_DQ_PROJ : -return dqp->q_mount->m_quotainfo->qi_pquotaip; +return mp->m_quotainfo->qi_pquotaip;default :ASSERT (0 ); }
Signature · 1 line
1.7.1
PATCH v2 6/7 xfs: Factor xfs_seek_hole_data into helper
In reply to Eric SandeenFactor xfs_seek_hole_data into an unlocked helper which takes an xfs inode rather than a file for internal use.
Also allow specification of "end" - the vfs lseek interface is defined such that any offset past eof/i_size shall return -ENXIO, but we will use this for quota code which does not maintain i_size, and we want to be able to SEEK_DATA past i_size as well. So the lseek path can send in i_size, and the quota code can determine its own ending offset.
--- fs/xfs/xfs_file.c | 82 ++++++++++++++++++++++++++++++++++++---------------- fs/xfs/xfs_inode.h | 2 + 2 files changed, 59 insertions(+), 25 deletions(-)
fs/xfs/xfs_file.c +57 -25
@@ -1337,31 +1337,31 @@ out:return found; } -STATIC loff_t -xfs_seek_hole_data ( -struct file *file, +/* +* caller must lock inode with xfs_ilock_data_map_shared, +* can we craft an appropriate ASSERT? +* +* end is because the VFS-level lseek interface is defined such that any +* offset past i_size shall return -ENXIO, but we use this for quota code +* which does not maintain i_size, and we want to SEEK_DATA past i_size. +*/ +loff_t +__xfs_seek_hole_data ( +struct inode *inode,loff_t start, +loff_t end,int whence) { -struct inode *inode = file->f_mapping->host;struct xfs_inode *ip =XFS_I (inode);struct xfs_mount *mp = ip->i_mount;loff_t uninitialized_var (offset ); -xfs_fsize_t isize;xfs_fileoff_t fsbno; -xfs_filblks_t end; -uint lock; +xfs_filblks_t lastbno;int error; -if (XFS_FORCED_SHUTDOWN (mp)) -return -EIO ; - - lock =xfs_ilock_data_map_shared (ip); - - isize =i_size_read (inode); -if (start >= isize) { +if (start >= end) { error = -ENXIO ; - goto out_unlock; + goto out_error; }/*
@@ -1369,22 +1369,22 @@ xfs_seek_hole_data(* by fsbno to the end block of the file. */ fsbno =XFS_B_TO_FSBT (mp, start); - end =XFS_B_TO_FSB (mp, isize); + lastbno =XFS_B_TO_FSB (mp, end);for (;;) {struct xfs_bmbt_irec map[2 ];int nmap =2 ;unsigned int i; - error =xfs_bmapi_read (ip, fsbno, end - fsbno, map, &nmap, + error =xfs_bmapi_read (ip, fsbno, lastbno - fsbno, map, &nmap,XFS_BMAPI_ENTIRE );if (error) - goto out_unlock; + goto out_error;/* No extents at given offset, must be beyond EOF */ if (nmap ==0 ) { error = -ENXIO ; - goto out_unlock; + goto out_error; }for (i =0 ; i < nmap; i++) {
@@ -1426,7 +1426,7 @@ xfs_seek_hole_data(* hole at the end of any file). */ if (whence ==SEEK_HOLE ) { - offset = isize; + offset = end;break ; }/*
@@ -1434,7 +1434,7 @@ xfs_seek_hole_data(*/ ASSERT (whence ==SEEK_DATA ); error = -ENXIO ; - goto out_unlock; + goto out_error; }ASSERT (i >1 );
@@ -1445,14 +1445,14 @@ xfs_seek_hole_data(*/ fsbno = map[i -1 ].br_startoff + map[i -1 ].br_blockcount; start =XFS_FSB_TO_B (mp, fsbno); -if (start >= isize) { +if (start >= end) {if (whence ==SEEK_HOLE ) { - offset = isize; + offset = end;break ; }ASSERT (whence ==SEEK_DATA ); error = -ENXIO ; - goto out_unlock; + goto out_error; } }
@@ -1464,7 +1464,39 @@ out:* situation in particular. */ if (whence ==SEEK_HOLE ) - offset =min_t (loff_t, offset, isize); + offset =min_t (loff_t, offset, end); + +return offset; + +out_error: +return error; +} + +STATIC loff_t +xfs_seek_hole_data ( +struct file *file, +loff_t start, +int whence) +{ +struct inode *inode = file->f_mapping->host; +struct xfs_inode *ip =XFS_I (inode); +struct xfs_mount *mp = ip->i_mount; +uint lock; +loff_t offset, end; +int error =0 ; + +if (XFS_FORCED_SHUTDOWN (mp)) +return -EIO ; + + lock =xfs_ilock_data_map_shared (ip); + + end =i_size_read (inode); + offset =__xfs_seek_hole_data (inode, start, end, whence); +if (offset <0 ) { + error = offset; + goto out_unlock; + } + offset =vfs_setpos (file, offset, inode->i_sb->s_maxbytes); out_unlock:
fs/xfs/xfs_inode.h +2 -0
@@ -437,6 +437,8 @@ int xfs_update_prealloc_flags(struct xfs_inode *ip,int xfs_zero_eof (struct xfs_inode *ip,xfs_off_t offset,xfs_fsize_t isize,bool *did_zeroing);int xfs_iozero (struct xfs_inode *ip,loff_t pos,size_t count); +loff_t __xfs_seek_hole_data (struct inode *inode,loff_t start, +loff_t eof,int whence);/* from xfs_iops.c */
Signature · 1 line
1.7.1
PATCH v2 7/7 xfs: wire up Q_XGETNEXTQUOTA / get_nextdqblk
In reply to Eric SandeenAdd code to allow the Q_XGETNEXTQUOTA quotactl to quickly find all active quotas by examining the quota inode, and skipping over unallocated or uninitialized regions.
Userspace can then use this interface rather than i.e. a getpwent() loop when asked to report all active quotas.
--- fs/xfs/libxfs/xfs_quota_defs.h | 3 +- fs/xfs/xfs_dquot.c | 96 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_qm.h | 2 +- fs/xfs/xfs_qm_syscalls.c | 6 ++- fs/xfs/xfs_quotaops.c | 22 +++++++++- 5 files changed, 124 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_quota_defs.h +2 -1
@@ -37,7 +37,7 @@ typedef __uint16_t xfs_qwarncnt_t;#define XFS_DQ_PROJ 0x0002/* project quota */ #define XFS_DQ_GROUP 0x0004/* a group quota */ #define XFS_DQ_DIRTY 0x0008/* dquot is dirty */ -#define XFS_DQ_FREEING 0x0010/* dquot is beeing torn down */ +#define XFS_DQ_FREEING 0x0010/* dquot is being torn down */ #define XFS_DQ_ALLTYPES (XFS_DQ_USER|XFS_DQ_PROJ|XFS_DQ_GROUP)
@@ -116,6 +116,7 @@ typedef __uint16_t xfs_qwarncnt_t;#define XFS_QMOPT_DQREPAIR 0x0001000/* repair dquot if damaged */ #define XFS_QMOPT_GQUOTA 0x0002000/* group dquot requested */ #define XFS_QMOPT_ENOSPC 0x0004000/* enospc instead of edquot (prj) */ +#define XFS_QMOPT_DQNEXT 0x0008000/* return next dquot >= this ID */ /* * flags to xfs_trans_mod_dquot to indicate which field needs to be
fs/xfs/xfs_dquot.c +96 -0
132 lines not on this page · raw message
fs/xfs/xfs_qm.h +1 -1
@@ -165,7 +165,7 @@ extern void xfs_qm_dqrele_all_inodes(struct xfs_mount *, uint);/* quota ops */ extern int xfs_qm_scall_trunc_qfiles (struct xfs_mount *,uint );extern int xfs_qm_scall_getquota (struct xfs_mount *,xfs_dqid_t , -uint ,struct qc_dqblk *); +uint ,struct qc_dqblk *,uint );extern int xfs_qm_scall_setqlim (struct xfs_mount *,xfs_dqid_t ,uint ,struct qc_dqblk *);extern int xfs_qm_scall_quotaon (struct xfs_mount *,uint );
fs/xfs/xfs_qm_syscalls.c +4 -2
@@ -637,7 +637,8 @@ xfs_qm_scall_getquota(struct xfs_mount *mp, xfs_dqid_t id, uint type, - struct qc_dqblk *dst) + struct qc_dqblk *dst, + uint dqget_flags) { struct xfs_dquot *dqp;int error;
@@ -647,7 +648,7 @@ xfs_qm_scall_getquota(* we aren't passing the XFS_QMOPT_DOALLOC flag. If it doesn't * exist, we'll get ENOENT back. */ - error =xfs_qm_dqget (mp,NULL , id, type,0 , &dqp); + error =xfs_qm_dqget (mp,NULL , id, type, dqget_flags, &dqp);if (error)return error;
@@ -661,6 +662,7 @@ xfs_qm_scall_getquota( }memset (dst,0 ,sizeof (*dst)); + dst->d_id =be32_to_cpu (dqp->q_core.d_id); dst->d_spc_hardlimit =XFS_FSB_TO_B (mp,be64_to_cpu (dqp->q_core.d_blk_hardlimit)); dst->d_spc_softlimit =
fs/xfs/xfs_quotaops.c +21 -1
@@ -238,7 +238,26 @@ xfs_fs_get_dqblk(return -ESRCH ;return xfs_qm_scall_getquota (mp,from_kqid (&init_user_ns, qid), -xfs_quota_type (qid.type), qdq); +xfs_quota_type (qid.type), qdq,0 ); +} + +/* Return quota info for active quota >= this qid */ +STATIC int +xfs_fs_get_nextdqblk ( +struct super_block *sb, +struct kqid qid, +struct qc_dqblk *qdq) +{ +struct xfs_mount *mp =XFS_M (sb); + +if (!XFS_IS_QUOTA_RUNNING (mp)) +return -ENOSYS ; +if (!XFS_IS_QUOTA_ON (mp)) +return -ESRCH ; + +return xfs_qm_scall_getquota (mp,from_kqid (&init_user_ns, qid), +xfs_quota_type (qid.type), qdq, +XFS_QMOPT_DQNEXT ); }STATIC int
@@ -267,5 +286,6 @@ const struct quotactl_ops xfs_quotactl_operations = { .quota_disable = xfs_quota_disable, .rm_xquota = xfs_fs_rm_xquota, .get_dqblk = xfs_fs_get_dqblk, + .get_nextdqblk = xfs_fs_get_nextdqblk, .set_dqblk = xfs_fs_set_dqblk, };
Signature · 1 line
1.7.1