quota: add new quotactl Q_GETNEXTQUOTA
Subsystems (3)
v3 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.
V3:
* Remove 32-bit compat stuff (i686/x86_64 at least works w/o it...)
* Require CAP_SYS_ADMIN for these calls
* Pass back found ID in &qid passed to ->get_nextdqblk, rather than modifying struct qc_dqblk
* Munge that found ID back through user-namespace conversions before returning it in the user structure.
Thanks,
-Eric
PATCH v3 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
Re: [PATCH 1/7] quota: remove unused cmd argument from quota_quotaon()
Quoted 4 lines · Eric Sandeen
The cmd argument to
quota_quotaon()viaQ_QUOTAONquotactl is not used, so remove it.Signed-off-by Eric Sandeen <[email protected]>
Looks good. You can add:
Honza
Quoted 29 lines
--- 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
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerRe: [PATCH 1/7] quota: remove unused cmd argument from quota_quotaon()
Quoted 9 lines · Jan Kara
Quoted 4 lines · Eric Sandeen
The cmd argument to
quota_quotaon()viaQ_QUOTAONquotactl is not used, so remove it.Signed-off-by Eric Sandeen <[email protected]>Looks good. You can add:
Reviewed-by Jan Kara <[email protected]>
Ah, I'm in a reviewe mode... ;) I'll just take this patch to my tree.
Honza
Quoted 32 lines
Quoted 29 lines
--- 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.1Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v3 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 | 31 +++++++++++++++++++++++++++++++ include/linux/quota.h | 2 ++ include/uapi/linux/dqblk_xfs.h | 1 + 3 files changed, 34 insertions(+), 0 deletions(-)
fs/quota/quota.c +31 -0
@@ -625,6 +625,34 @@ 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; +qid_t id_out; +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; + id_out =from_kqid (current_user_ns (), qid); +copy_to_xfs_dqblk (&fdq, &qdq, type, id_out); +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 +718,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 +742,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 +2 -0
@@ -425,6 +425,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 7 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.
Quoted 7 lines
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.
This paragraph is no longer true. Otherwise the patch looks good to me.
Honza
Quoted 97 lines
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 | 31 +++++++++++++++++++++++++++++++ include/linux/quota.h | 2 ++ include/uapi/linux/dqblk_xfs.h | 1 + 3 files changed, 34 insertions(+), 0 deletions(-)fs/quota/quota.c +31
-0@@ -625,6 +625,34 @@ 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; +qid_t id_out; +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; + id_out =from_kqid (current_user_ns (), qid); +copy_to_xfs_dqblk (&fdq, &qdq, type, id_out); +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 +718,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 +742,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 +2
-0@@ -425,6 +425,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
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Jan Kara
reviewerRe: [PATCH 2/7] quota: add new quotactl Q_XGETNEXTQUOTA
In reply to Eric SandeenQuoted 6 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.
Actually, is -ESRCH the right return value? It seems XFS traditionally returns -ENOENT when id doesn't exist. So that would look more logical to me.
Honza
Quoted 104 lines
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 | 31 +++++++++++++++++++++++++++++++ include/linux/quota.h | 2 ++ include/uapi/linux/dqblk_xfs.h | 1 + 3 files changed, 34 insertions(+), 0 deletions(-)fs/quota/quota.c +31
-0@@ -625,6 +625,34 @@ 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; +qid_t id_out; +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; + id_out =from_kqid (current_user_ns (), qid); +copy_to_xfs_dqblk (&fdq, &qdq, type, id_out); +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 +718,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 +742,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 +2
-0@@ -425,6 +425,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
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 2/7] quota: add new quotactl Q_XGETNEXTQUOTA
Quoted 11 lines · Jan Kara
Quoted 6 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.Actually, is
-ESRCHthe right return value? It seems XFS traditionally returns-ENOENTwhen id doesn't exist. So that would look more logical to me.
Hm, I was just going by the quotactl manpage, TBH, which says:
ESRCH No disc quota is found for the indicated user.
But yes, you are right, it is ENOENT for xfs... argh. I suppose the quotactl manpage could use an update as well, then.
At this point do you want me to update the patches & resend or do you want to fix that up too? :( I reference -ESRCH in comments too, I think.
-Eric
Jan Kara
reviewerRe: [PATCH 2/7] quota: add new quotactl Q_XGETNEXTQUOTA
Quoted 13 lines · Eric Sandeen
Quoted 11 lines · Jan Kara
Quoted 6 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.Actually, is
-ESRCHthe right return value? It seems XFS traditionally returns-ENOENTwhen id doesn't exist. So that would look more logical to me.
Quoted 7 lines
Hm, I was just going by the quotactl manpage, TBH, which says:
ESRCH No disc quota is found for the indicated user.
But yes, you are right, it is ENOENT for xfs... argh. I suppose the quotactl manpage could use an update as well, then.
Yeah, so VFS quotas use ESRCH when quota for particular fs is not enabled (while ENOENT means device you passed in doesn't exist). So probably a solution that keeps XFS and VFS interfaces most selfconsistent is to return ENOENT from Q_XGETNEXTQUOTA and ESRCH from Q_GETNEXTQUOTA. I'll update your patches in this sense in the comments and changelogs. But XFS patches (which I don't carry) need updating the actual code...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH 2/7] quota: add new quotactl Q_XGETNEXTQUOTA
Quoted 22 lines · Jan Kara
Quoted 13 lines · Eric Sandeen
Quoted 11 lines · Jan Kara
Quoted 6 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.Actually, is
-ESRCHthe right return value? It seems XFS traditionally returns-ENOENTwhen id doesn't exist. So that would look more logical to me.Quoted 7 lines
Hm, I was just going by the quotactl manpage, TBH, which says:
ESRCH No disc quota is found for the indicated user.
But yes, you are right, it is ENOENT for xfs... argh. I suppose the quotactl manpage could use an update as well, then.
Quoted 6 lines
Yeah, so VFS quotas use ESRCH when quota for particular fs is not enabled (while ENOENT means device you passed in doesn't exist). So probably a solution that keeps XFS and VFS interfaces most selfconsistent is to return ENOENT from
Q_XGETNEXTQUOTAand ESRCH fromQ_GETNEXTQUOTA. I'll update your patches in this sense in the comments and changelogs. But XFS patches (which I don't carry) need updating the actual code...
*nod* thanks. I'll just resend the XFS patches to the XFS list.
-Eric
Re: [PATCH 2/7] quota: add new quotactl Q_XGETNEXTQUOTA
In reply to Jan KaraQuoted 2 lines · Jan Kara
Yeah, so VFS quotas use ESRCH when quota for particular fs is not enabled (while ENOENT means device you passed in doesn't exist).
And what does it return for "that ID has no quota?" Anything? Maybe not, see below?
Quoted 5 lines
So probably a
solution that keeps XFS and VFS interfaces most selfconsistent is to return ENOENT fromQ_XGETNEXTQUOTAand ESRCH fromQ_GETNEXTQUOTA. I'll update your patches in this sense in the comments and changelogs. But XFS patches (which I don't carry) need updating the actual code...
Actually, ok, now I'm a little more confused.
Today, Q_XGETQUOTA and Q_GETQUOTA will both return -ENOENT on XFS if a quota doesn't exist for that ID:
quotactl(Q_GETQUOTA|USRQUOTA, "/dev/sdb2", 123456789, 0x7ffdf2edbc80) = -1 ENOENT (No such file or directory) quotactl(Q_XGETQUOTA|USRQUOTA, "/dev/sdb2", 123456789, 0x7ffdf2edbc10) = -1 ENOENT (No such file or directory)
It seems like the *NEXT* variants (on xfs at least?) may as well continue to do the same...
But on ext4, I see 0 returned for a nonexistent quota:
quotactl(Q_GETQUOTA|USRQUOTA, "/dev/sdb1", 123456789, {bhardlimit=0, bsoftlimit=0, curspace=0, ihardlimit=0, isoftlimit=0, curinodes=0, ...}) = 0
quotactl(Q_XGETQUOTA|USRQUOTA, "/dev/sdb1", 123456789, {version=1, flags=XFS_USER_QUOTA, fieldmask=0, id=123456789, blk_hardlimit=0, blk_softlimit=0, ino_hardlimit=0, ino_softlimit=0, bcount=0, icount=0, ...}) = 0
So the difference doesn't seem to be XGETQUOTA vs GETQUOTA, rather it's the filesystem handling the call?
Still, we do need a way to pass back "No more quotas to find" from Q_[X]GETNEXTQUOTA; XFS will do -ENOENT, but if -ENOENT and -ESRCH already have specific meanings on non-xfs filesystems, I'm not sure where we go from there.
Sorry for my confusion. :(
-Eric
Jan Kara
reviewerRe: [PATCH 2/7] quota: add new quotactl Q_XGETNEXTQUOTA
Quoted 25 lines · Eric Sandeen
Quoted 2 lines · Jan Kara
Yeah, so VFS quotas use ESRCH when quota for particular fs is not enabled (while ENOENT means device you passed in doesn't exist).
And what does it return for "that ID has no quota?" Anything? Maybe not, see below?
Quoted 5 lines
So probably a
solution that keeps XFS and VFS interfaces most selfconsistent is to return ENOENT fromQ_XGETNEXTQUOTAand ESRCH fromQ_GETNEXTQUOTA. I'll update your patches in this sense in the comments and changelogs. But XFS patches (which I don't carry) need updating the actual code...Actually, ok, now I'm a little more confused.
Today,
Q_XGETQUOTAandQ_GETQUOTAwill both return-ENOENTon XFS if a quota doesn't exist for that ID:
quotactl(Q_GETQUOTA|USRQUOTA, "/dev/sdb2", 123456789, 0x7ffdf2edbc80)= -1 ENOENT (No such file or directory)quotactl(Q_XGETQUOTA|USRQUOTA, "/dev/sdb2", 123456789, 0x7ffdf2edbc10)= -1 ENOENT (No such file or directory)It seems like the *NEXT* variants (on xfs at least?) may as well continue to do the same...
Quoted 7 lines
But on ext4, I see 0 returned for a nonexistent quota:
quotactl(Q_GETQUOTA|USRQUOTA, "
/dev/sdb1", 123456789, {bhardlimit=0, bsoftlimit=0, curspace=0, ihardlimit=0, isoftlimit=0, curinodes=0, ...}) = 0
quotactl(Q_XGETQUOTA|USRQUOTA, "/dev/sdb1", 123456789, {version=1, flags=XFS_USER_QUOTA, fieldmask=0, id=123456789, blk_hardlimit=0, blk_softlimit=0, ino_hardlimit=0, ino_softlimit=0, bcount=0, icount=0, ...}) = 0So the difference doesn't seem to be XGETQUOTA vs GETQUOTA, rather it's the filesystem handling the call?
Yes, it's about whether fs/quota/dquot.c or XFS handles the call. VFS traditionally returns structure full of zeros when you call Q_GETQUOTA for non-existent ID on a system that otherwise supports quotas (that is a historical heritage of old quota file format). This is however impractical for Q_GETNEXTQUOTA so there we have to define some error terminating the iteration.
Quoted 4 lines
Still, we do need a way to pass back "No more quotas to find" from Q_[X]GETNEXTQUOTA; XFS will do
-ENOENT, but if-ENOENTand-ESRCHalready have specific meanings on non-xfs filesystems, I'm not sure where we go from there.
Yeah, we have to simply overload one of the error codes for VFS implementation and I'm not strongly convinced which one. But since you pointed out that it's not really about the interface but about backing fs, I think making both ENOENT is probably going to be less confusing for userspace.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v3 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/quota.c | 30 ++++++++++++++++++++++++++++++ include/uapi/linux/quota.h | 14 ++++++++++++++ 2 files changed, 44 insertions(+), 0 deletions(-)
fs/quota/quota.c +30 -0
@@ -222,6 +222,34 @@ static int quota_getquota(struct super_block *sb, int type, qid_t id,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 =from_kqid (current_user_ns (), qid); +if (copy_to_user (addr, &idq,sizeof (idq))) +return -EFAULT ; +return 0 ; +} +static void copy_from_if_dqblk (struct qc_dqblk *dst,struct if_dqblk *src) { dst->d_spc_hardlimit =qbtos (src->dqb_bhardlimit);
@@ -698,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]>
The patch seems to be missing addition of Q_GETNEXTQUOTA into quotactl_cmd_write(). Otherwise it looks good to me.
Honza
Quoted 88 lines
--- fs/quota/quota.c | 30 ++++++++++++++++++++++++++++++ include/uapi/linux/quota.h | 14 ++++++++++++++ 2 files changed, 44 insertions(+), 0 deletions(-)fs/quota/quota.c +30
-0@@ -222,6 +222,34 @@ static int quota_getquota(struct super_block *sb, int type, qid_t id,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 =from_kqid (current_user_ns (), qid); +if (copy_to_user (addr, &idq,sizeof (idq))) +return -EFAULT ; +return 0 ; +} +static void copy_from_if_dqblk (struct qc_dqblk *dst,struct if_dqblk *src) { dst->d_spc_hardlimit =qbtos (src->dqb_bhardlimit);@@ -698,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
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v3 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 v3 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 v3 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 v3 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 | 4 +- fs/xfs/xfs_qm_syscalls.c | 12 +++-- fs/xfs/xfs_quotaops.c | 36 ++++++++++++++- 5 files changed, 142 insertions(+), 9 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 +2 -2
@@ -164,8 +164,8 @@ 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 *); +extern int xfs_qm_scall_getquota (struct xfs_mount *,xfs_dqid_t *, +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 +8 -4
@@ -635,9 +635,10 @@ out:int xfs_qm_scall_getquota (struct xfs_mount *mp, -xfs_dqid_t id, +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;
@@ -660,6 +661,9 @@ xfs_qm_scall_getquota( goto out_put; } +/* Fill in the ID we actually read from disk */ + *id =be32_to_cpu (dqp->q_core.d_id); +memset (dst,0 ,sizeof (*dst)); dst->d_spc_hardlimit =XFS_FSB_TO_B (mp,be64_to_cpu (dqp->q_core.d_blk_hardlimit));
@@ -701,7 +705,7 @@ xfs_qm_scall_getquota(if (((XFS_IS_UQUOTA_ENFORCED (mp) && type ==XFS_DQ_USER ) || (XFS_IS_GQUOTA_ENFORCED (mp) && type ==XFS_DQ_GROUP ) || (XFS_IS_PQUOTA_ENFORCED (mp) && type ==XFS_DQ_PROJ )) && - id !=0 ) { + *id !=0 ) {if ((dst->d_space > dst->d_spc_softlimit) && (dst->d_spc_softlimit >0 )) {ASSERT (dst->d_spc_timer !=0 );
fs/xfs/xfs_quotaops.c +34 -2
@@ -231,14 +231,45 @@ xfs_fs_get_dqblk( struct qc_dqblk *qdq) {struct xfs_mount *mp =XFS_M (sb); +xfs_dqid_t id;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); + id =from_kqid (&init_user_ns, qid); +return xfs_qm_scall_getquota (mp, &id, +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) +{ +int ret; +struct xfs_mount *mp =XFS_M (sb); +xfs_dqid_t id; + +if (!XFS_IS_QUOTA_RUNNING (mp)) +return -ENOSYS ; +if (!XFS_IS_QUOTA_ON (mp)) +return -ESRCH ; + + id =from_kqid (&init_user_ns, *qid); + ret =xfs_qm_scall_getquota (mp, &id, +xfs_quota_type (qid->type), qdq, +XFS_QMOPT_DQNEXT ); +if (ret) +return ret; + +/* ID may be different, so convert back what we got */ + *qid =make_kqid (current_user_ns (), qid->type, id); +return 0 ; + }STATIC int
@@ -267,5 +298,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
PATCH v4 7/7 xfs: wire up Q_XGETNEXTQUOTA / get_nextdqblk
Add 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.
---
V4: Return -ENOENT not -ESRCH from xfs_dq_get_next_id() when there are no more allocated quotas to be found; this is consistent with the normal, non-next-getquota interface in xfs.
fs/xfs/libxfs/xfs_quota_defs.h | 3 +- fs/xfs/xfs_dquot.c | 96 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_qm.h | 4 +- fs/xfs/xfs_qm_syscalls.c | 12 +++-- fs/xfs/xfs_quotaops.c | 36 ++++++++++++++- 5 files changed, 142 insertions(+), 9 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 +2 -2
@@ -164,8 +164,8 @@ 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 *); +extern int xfs_qm_scall_getquota (struct xfs_mount *,xfs_dqid_t *, +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 +8 -4
@@ -635,9 +635,10 @@ out:int xfs_qm_scall_getquota (struct xfs_mount *mp, -xfs_dqid_t id, +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;
@@ -660,6 +661,9 @@ xfs_qm_scall_getquota( goto out_put; } +/* Fill in the ID we actually read from disk */ + *id =be32_to_cpu (dqp->q_core.d_id); +memset (dst,0 ,sizeof (*dst)); dst->d_spc_hardlimit =XFS_FSB_TO_B (mp,be64_to_cpu (dqp->q_core.d_blk_hardlimit));
@@ -701,7 +705,7 @@ xfs_qm_scall_getquota(if (((XFS_IS_UQUOTA_ENFORCED (mp) && type ==XFS_DQ_USER ) || (XFS_IS_GQUOTA_ENFORCED (mp) && type ==XFS_DQ_GROUP ) || (XFS_IS_PQUOTA_ENFORCED (mp) && type ==XFS_DQ_PROJ )) && - id !=0 ) { + *id !=0 ) {if ((dst->d_space > dst->d_spc_softlimit) && (dst->d_spc_softlimit >0 )) {ASSERT (dst->d_spc_timer !=0 );
fs/xfs/xfs_quotaops.c +34 -2
@@ -231,14 +231,45 @@ xfs_fs_get_dqblk( struct qc_dqblk *qdq) {struct xfs_mount *mp =XFS_M (sb); +xfs_dqid_t id;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); + id =from_kqid (&init_user_ns, qid); +return xfs_qm_scall_getquota (mp, &id, +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) +{ +int ret; +struct xfs_mount *mp =XFS_M (sb); +xfs_dqid_t id; + +if (!XFS_IS_QUOTA_RUNNING (mp)) +return -ENOSYS ; +if (!XFS_IS_QUOTA_ON (mp)) +return -ESRCH ; + + id =from_kqid (&init_user_ns, *qid); + ret =xfs_qm_scall_getquota (mp, &id, +xfs_quota_type (qid->type), qdq, +XFS_QMOPT_DQNEXT ); +if (ret) +return ret; + +/* ID may be different, so convert back what we got */ + *qid =make_kqid (current_user_ns (), qid->type, id); +return 0 ; + }STATIC int
@@ -267,5 +298,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, };
Jan Kara
reviewerQuoted 29 lines · Eric Sandeen
This adds a new quotactl,
Q_GETNEXTQUOTA.
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 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,-ESRCHis returned.So if you ask for id X, you can get back quota for id X, id X+N, or
-ESRCHif 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.
Quoted 7 lines
V3:
* Remove 32-bit compat stuff (i686/x86_64 at least works w/o it...)
* RequireCAP_SYS_ADMINfor these calls
* Pass back found ID in &qid passed to ->get_nextdqblk, rather than modifying structqc_dqblk
* Munge that found ID back through user-namespace conversions before returning it in the user structure.
So I've taken patch 1/7 into my tree since that is completely independent. Patches 2/7 and 3/7 look mostly good to me (except for that small omission in 3/7) so I can take them to my tree as well. Once I'll finish testing some UDF changes I have pending I'll push the tree to:
git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git for_next
and Dave can pull from there to have a basis for XFS patches. I want to implement Q_GETNEXTQUOTA for VFS quota formats as well and those will go through my tree so that's why I want the interface changes go via my tree.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 1 line · Jan Kara
On Fri 22-01-16 12:25:29, Eric Sandeen wrote:
...
Quoted 4 lines
So I've taken patch 1/7 into my tree since that is completely independent. Patches 2/7 and 3/7 look mostly good to me (except for that small omission in 3/7) so I can take them to my tree as well. Once I'll finish testing some UDF changes I have pending I'll push the tree to:
Jan, thanks for catching & fixing those issues.
Quoted 5 lines
git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.gitfor_nextand Dave can pull from there to have a basis for XFS patches. I want to implement
Q_GETNEXTQUOTAfor VFS quota formats as well and those will go through my tree so that's why I want the interface changes go via my tree.
Makes sense to me.
Thanks,
-Eric
Jan Kara
reviewerJust for reference attached are two patches that implement support for Q_GETNEXTQUOTA and Q_XGETNEXTQUOTA in quota-tools. I have used it for testing XFS and VFS infrastructure for these new quotactls.
Honza
Quoted 39 lines · Eric Sandeen
This adds a new quotactl,
Q_GETNEXTQUOTA.
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 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,-ESRCHis returned.So if you ask for id X, you can get back quota for id X, id X+N, or
-ESRCHif 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.
V3:
* Remove 32-bit compat stuff (i686/x86_64 at least works w/o it...)
* RequireCAP_SYS_ADMINfor these calls
* Pass back found ID in &qid passed to ->get_nextdqblk, rather than modifying structqc_dqblk
* Munge that found ID back through user-namespace conversions before returning it in the user structure.Thanks,
-Eric
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 1 line
From
9ae91376373b1b0a8d4573834d0d99722a5909f6Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Tue, 26 Jan 2016 13:10:59 +0100
Subject: [PATCH 1/2] Scan dquots using Q_GETNEXTQUOTA
Check for new kernel quotactl Q_GETNEXTQUOTA and if available use it for scanning all dquot structures.
--- quota.h | 14 ++++++++++++++ quotaio_generic.c | 34 ++++++++++++++++++++++++++++++++++ quotaio_generic.h | 4 ++++ quotaio_meta.c | 14 +++++++++++++- 4 files changed, 65 insertions(+), 1 deletion(-)
quota.h +14 -0
@@ -63,6 +63,7 @@ typedef int64_t qsize_t; /* Type in which we store size limitations */#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 structure used for communication with userspace via quotactl
@@ -91,6 +92,19 @@ struct if_dqblk {u_int32_t dqb_valid; }; +struct if_nextdqblk { +u_int64_t dqb_bhardlimit; +u_int64_t dqb_bsoftlimit; +u_int64_t dqb_curspace; +u_int64_t dqb_ihardlimit; +u_int64_t dqb_isoftlimit; +u_int64_t dqb_curinodes; +u_int64_t dqb_btime; +u_int64_t dqb_itime; +u_int32_t dqb_valid; +u_int32_t dqb_id; +}; +/* * Structure used for setting quota information about file via quotactl * Following flags are used to specify which fields are valid
quotaio_generic.c +34 -0
@@ -161,3 +161,37 @@ int generic_scan_dquots(struct quota_handle *h,free (dquot);return ret; } + +int vfs_scan_dquots (struct quota_handle *h, +int (*process_dquot)(struct dquot *dquot,char *dqname)) +{ +struct dquot *dquot =get_empty_dquot (); +qid_t id =0 ; +struct if_nextdqblk kdqblk; +int ret; + + dquot->dq_h = h; +while (1 ) { + ret =quotactl (QCMD (Q_GETNEXTQUOTA , h->qh_type), + h->qh_quotadev, id, (void *)&kdqblk); +if (ret <0 ) +break ; + +/* +* This is a slight hack but we know struct if_dqblk is a +* subset of struct if_nextdqblk +*/ +generic_kern2utildqblk (&dquot->dq_dqb, + (struct if_dqblk *)&kdqblk); + dquot->dq_id = kdqblk.dqb_id; + ret =process_dquot (dquot,NULL ); +if (ret <0 ) +break ; + id = kdqblk.dqb_id +1 ; + } +free (dquot); + +if (errno ==ESRCH ) +return 0 ; +return ret; +}
quotaio_generic.h +4 -0
@@ -27,4 +27,8 @@ int generic_scan_dquots(struct quota_handle *h,int (*process_dquot)(struct dquot *dquot,char *dqname), int (*get_dquot)(struct dquot *dquot)); +/* Scan all dquots using kernel quotactl to get existing ids */ +int vfs_scan_dquots (struct quota_handle *h, +int (*process_dquot)(struct dquot *dquot,char *dqname)); +#endif
quotaio_meta.c +13 -1
@@ -8,6 +8,7 @@#include <string.h> #include <stdlib.h> +#include <errno.h> #include <sys/types.h>
@@ -55,7 +56,18 @@ static int meta_commit_dquot(struct dquot *dquot, int flags)static int meta_scan_dquots (struct quota_handle *h,int (*process_dquot)(struct dquot *dquot,char *dqname)) { -return generic_scan_dquots (h, process_dquot, vfs_get_dquot); +struct if_nextdqblk kdqblk; +int ret; + + ret =quotactl (QCMD (Q_GETNEXTQUOTA , h->qh_type), h->qh_quotadev,0 , + (void *)&kdqblk); +/* +* Fall back to scanning using passwd if Q_GETNEXTQUOTA is not +* supported +*/ +if (ret <0 && (errno ==ENOSYS || errno ==EINVAL )) +return generic_scan_dquots (h, process_dquot, vfs_get_dquot); +return vfs_scan_dquots (h, process_dquot); }struct quotafile_ops quotafile_ops_meta = {
Signature · 1 line
2.6.2
Quoted 1 line
From
304bed24716fdbb7c636ea8df0462d4f979f23a0Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Tue, 26 Jan 2016 14:06:59 +0100
Subject: [PATCH 2/2] Add support for scanning using Q_XGETNEXTQUOTA
Add support for scanning of all available quota structures using Q_XGETNEXTQUOTA quotactl.
--- quotaio_xfs.c | 42 +++++++++++++++++++++++++++++++++++++++--- quotaio_xfs.h | 1 + 2 files changed, 40 insertions(+), 3 deletions(-)
quotaio_xfs.c +39 -3
54 lines not on this page · raw message
quotaio_xfs.h +1 -0
@@ -46,6 +46,7 @@#define Q_XSETQLIM XQM_CMD(0x4)/* set disk limits only */ #define Q_XGETQSTAT XQM_CMD(0x5)/* returns fs_quota_stat_t struct */ #define Q_XQUOTARM XQM_CMD(0x6)/* free quota files' space */ +#define Q_XGETNEXTQUOTA XQM_CMD(0x9)/* get disk limits and usage >= ID */ /* * fs_disk_quota structure:
Signature · 1 line
2.6.2