quota: Implement VFS support for Q_[X]GETNEXTQUOTA
Jan Kara
reviewercover quota: Implement VFS support for Q_[X]GETNEXTQUOTA
Hello,
two patches below implement support for Q_GETNEXTQUOTA and Q_XGETNEXTQUOTA quotactls for VFS quotas - namely for the vfsv0 and vfsv1 formats of quota files (so that includes non-ancient quota files for ext2, ext4, reiserfs, jfs). Hooking up OCFS2 requires a small wrapper to deal with peculiarities of cluster locking, I'll have a look into that a bit later.
I have also implemented and pushed out support for the new quotactls in quota-tools so repquota(8) and warnquota(8) now use the new quotactl when direct access to the quota file is not available (and falls back to iteration using getpwent() if quotactl is not available).
Unless somebody objects I'll queue these patches to my tree in a few days.
Honza
Jan Kara
reviewerPATCH 1/2 quota: Add support for ->get_nextdqblk() for VFS quota
Add infrastructure for supporting get_nextdqblk() callback for VFS quotas.
--- fs/quota/dquot.c | 26 ++++++++++++++++++++++++++ include/linux/quota.h | 1 + include/linux/quotaops.h | 2 ++ 3 files changed, 29 insertions(+)
fs/quota/dquot.c +26 -0
@@ -2565,6 +2565,30 @@ int dquot_get_dqblk(struct super_block *sb, struct kqid qid, }EXPORT_SYMBOL (dquot_get_dqblk); +int dquot_get_next_dqblk (struct super_block *sb,struct kqid *qid, +struct qc_dqblk *di) +{ +struct dquot *dquot; +struct quota_info *dqopt =sb_dqopt (sb); +int err; + +if (!dqopt->ops[qid->type]->get_next_id) +return -ENOSYS ; +mutex_lock (&dqopt->dqio_mutex); + err = dqopt->ops[qid->type]->get_next_id (sb, qid); +mutex_unlock (&dqopt->dqio_mutex); +if (err <0 ) +return err; + dquot =dqget (sb, *qid); +if (IS_ERR (dquot)) +return PTR_ERR (dquot); +do_get_dqblk (dquot, di); +dqput (dquot); + +return 0 ; +} +EXPORT_SYMBOL (dquot_get_next_dqblk); +#define VFS_QC_MASK \ (QC_SPACE | QC_SPC_SOFT | QC_SPC_HARD | \ QC_INO_COUNT | QC_INO_SOFT | QC_INO_HARD | \
@@ -2765,6 +2789,7 @@ const struct quotactl_ops dquot_quotactl_ops = { .get_state = dquot_get_state, .set_info = dquot_set_dqinfo, .get_dqblk = dquot_get_dqblk, + .get_nextdqblk = dquot_get_next_dqblk, .set_dqblk = dquot_set_dqblk };EXPORT_SYMBOL (dquot_quotactl_ops);
@@ -2776,6 +2801,7 @@ const struct quotactl_ops dquot_quotactl_sysfile_ops = { .get_state = dquot_get_state, .set_info = dquot_set_dqinfo, .get_dqblk = dquot_get_dqblk, + .get_nextdqblk = dquot_get_next_dqblk, .set_dqblk = dquot_set_dqblk };EXPORT_SYMBOL (dquot_quotactl_sysfile_ops);
include/linux/quota.h +1 -0
@@ -306,6 +306,7 @@ struct quota_format_ops {int (*read_dqblk)(struct dquot *dquot);/* Read structure for one user */ int (*commit_dqblk)(struct dquot *dquot);/* Write structure for one user */ int (*release_dqblk)(struct dquot *dquot);/* Called when last reference to dquot is being dropped */ +int (*get_next_id)(struct super_block *sb,struct kqid *qid);/* Get next ID with existing structure in the quota file */ };/* Operations working with dquots */
include/linux/quotaops.h +2 -0
@@ -99,6 +99,8 @@ int dquot_get_state(struct super_block *sb, struct qc_state *state);int dquot_set_dqinfo (struct super_block *sb,int type,struct qc_info *ii);int dquot_get_dqblk (struct super_block *sb,struct kqid id,struct qc_dqblk *di); +int dquot_get_next_dqblk (struct super_block *sb,struct kqid *id, +struct qc_dqblk *di);int dquot_set_dqblk (struct super_block *sb,struct kqid id,struct qc_dqblk *di);
Signature · 1 line
2.6.2
kbuild test robot
build botRe: [PATCH 1/2] quota: Add support for ->get_nextdqblk() for VFS quota
reproduce:
Hi Jan,
[auto build test ERROR on v4.5-rc1]
[also build test ERROR on next-20160127]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Jan-Kara/quota-Implement-VFS-support-for-Q_-X-GETNEXTQUOTA/20160127-194845 config: x86_64-randconfig-x011-01270835 (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All error/warnings (new ones prefixed by >>):
>> fs/quota/dquot.c:2792:2: error: unknown field 'get_nextdqblk' specified in initializer
.get_nextdqblk = dquot_get_next_dqblk,
^
>> fs/quota/dquot.c:2792:19: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types] .get_nextdqblk = dquot_get_next_dqblk,
^
fs/quota/dquot.c:2792:19: note: (near initialization for 'dquot_quotactl_ops.set_dqblk') fs/quota/dquot.c:2804:2: error: unknown field 'get_nextdqblk' specified in initializer
.get_nextdqblk = dquot_get_next_dqblk,
^
fs/quota/dquot.c:2804:19: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
.get_nextdqblk = dquot_get_next_dqblk,
^
fs/quota/dquot.c:2804:19: note: (near initialization for 'dquot_quotactl_sysfile_ops.set_dqblk')
vim +/get_nextdqblk +2792 fs/quota/dquot.c
2786 .quota_on = dquot_quota_on,
2787 .quota_off = dquot_quota_off,
2788 .quota_sync = dquot_quota_sync,
2789 .get_state = dquot_get_state,
2790 .set_info = dquot_set_dqinfo,
2791 .get_dqblk = dquot_get_dqblk,
> 2792 .get_nextdqblk = dquot_get_next_dqblk,
2793 .set_dqblk = dquot_set_dqblk
2794 };
2795 EXPORT_SYMBOL(dquot_quotactl_ops);
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Jan Kara
reviewerPATCH 2/2 quota_v2: Implement get_next_id() for V2 quota format
In reply to Jan KaraImplement functions to get id of next existing quota structure in quota file for quota tree based formats and thus for V2 quota format.
--- fs/quota/quota_tree.c | 67 +++++++++++++++++++++++++++++++++++++++++++-- fs/quota/quota_v2.c | 6 ++++ include/linux/dqblk_qtree.h | 2 ++ 3 files changed, 73 insertions(+), 2 deletions(-)
fs/quota/quota_tree.c +65 -2
@@ -22,10 +22,9 @@ MODULE_LICENSE("GPL");#define __QUOTA_QT_PARANOIA -static int get_index (struct qtree_mem_dqinfo *info,struct kqid qid,int depth) +static int __get_index (struct qtree_mem_dqinfo *info,qid_t id,int depth) {unsigned int epb = info->dqi_usable_bs >>2 ; -qid_t id =from_kqid (&init_user_ns, qid); depth = info->dqi_qtree_depth - depth -1 ;while (depth--)
@@ -33,6 +32,13 @@ static int get_index(struct qtree_mem_dqinfo *info, struct kqid qid, int depth)return id % epb; } +static int get_index (struct qtree_mem_dqinfo *info,struct kqid qid,int depth) +{ +qid_t id =from_kqid (&init_user_ns, qid); + +return __get_index (info, id, depth); +} +/* Number of entries in one blocks */ static int qtree_dqstr_in_blk (struct qtree_mem_dqinfo *info) {
@@ -668,3 +674,60 @@ int qtree_release_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)return 0 ; }EXPORT_SYMBOL (qtree_release_dquot); + +static int find_next_id (struct qtree_mem_dqinfo *info,qid_t *id, +unsigned int blk,int depth) +{ +char *buf =getdqbuf (info->dqi_usable_bs); +__le32 *ref = (__le32 *)buf; +ssize_t ret; +unsigned int epb = info->dqi_usable_bs >>2 ; +unsigned int level_inc =1 ; +int i; + +if (!buf) +return -ENOMEM ; + +for (i = depth; i < info->dqi_qtree_depth -1 ; i++) + level_inc *= epb; + + ret =read_blk (info, blk, buf); +if (ret <0 ) { +quota_error (info->dqi_sb, +"Can't read quota tree block %u" , blk); + goto out_buf; + } +for (i =__get_index (info, *id, depth); i < epb; i++) { +if (ref[i] ==cpu_to_le32 (0 )) { + *id += level_inc; +continue ; + } +if (depth == info->dqi_qtree_depth -1 ) { + ret =0 ; + goto out_buf; + } + ret =find_next_id (info, id,le32_to_cpu (ref[i]), depth +1 ); +if (ret != -ENOENT ) +break ; + } +if (i == epb) { + ret = -ENOENT ; + goto out_buf; + } +out_buf: +kfree (buf); +return ret; +} + +int qtree_get_next_id (struct qtree_mem_dqinfo *info,struct kqid *qid) +{ +qid_t id =from_kqid (&init_user_ns, *qid); +int ret; + + ret =find_next_id (info, &id,QT_TREEOFF ,0 ); +if (ret <0 ) +return ret; + *qid =make_kqid (&init_user_ns, qid->type, id); +return 0 ; +} +EXPORT_SYMBOL (qtree_get_next_id);
fs/quota/quota_v2.c +6 -0
@@ -304,6 +304,11 @@ static int v2_free_file_info(struct super_block *sb, int type)return 0 ; } +static int v2_get_next_id (struct super_block *sb,struct kqid *qid) +{ +return qtree_get_next_id (sb_dqinfo (sb, qid->type)->dqi_priv, qid); +} +static const struct quota_format_ops v2_format_ops = { .check_quota_file = v2_check_quota_file, .read_file_info = v2_read_file_info,
@@ -312,6 +317,7 @@ static const struct quota_format_ops v2_format_ops = { .read_dqblk = v2_read_dquot, .commit_dqblk = v2_write_dquot, .release_dqblk = v2_release_dquot, + .get_next_id = v2_get_next_id, };static struct quota_format_type v2r0_quota_format = {
include/linux/dqblk_qtree.h +2 -0
@@ -15,6 +15,7 @@#define QTREE_DEL_REWRITE 6struct dquot ; +struct kqid ;/* Operations */ struct qtree_fmt_operations {
@@ -52,5 +53,6 @@ static inline int qtree_depth(struct qtree_mem_dqinfo *info) entries *= epb; return i; } +int qtree_get_next_id (struct qtree_mem_dqinfo *info,struct kqid *qid);#endif /* _LINUX_DQBLK_QTREE_H */
Signature · 1 line
2.6.2