On Nov 7, 2022, at 06:23, Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx> wrote: > > From: Wang Shilong <wshilong@xxxxxxx> > > Every threads calculate its own quota accounting, > merge them after threads finish. > > Signed-off-by: Wang Shilong <wshilong@xxxxxxx> > [Note: splitted the patch to seperate libext2fs changes from e2fsck] > Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx> Reviewed-by: Andreas Dilger <adilger@xxxxxxxxx> > --- > lib/support/mkquota.c | 39 +++++++++++++++++++++++++++++++++++++++ > lib/support/quotaio.h | 3 +++ > 2 files changed, 42 insertions(+) > > diff --git a/lib/support/mkquota.c b/lib/support/mkquota.c > index 9339c994..ce1ab4cd 100644 > --- a/lib/support/mkquota.c > +++ b/lib/support/mkquota.c > @@ -618,6 +618,45 @@ out: > return err; > } > > +static errcode_t merge_usage(dict_t *dest, dict_t *src) > +{ > + dnode_t *n; > + struct dquot *src_dq, *dest_dq; > + > + for (n = dict_first(src); n; n = dict_next(src, n)) { > + src_dq = dnode_get(n); > + if (!src_dq) > + continue; > + dest_dq = get_dq(dest, src_dq->dq_id); > + if (dest_dq == NULL) > + return -ENOMEM; > + dest_dq->dq_dqb.dqb_curspace += src_dq->dq_dqb.dqb_curspace; > + dest_dq->dq_dqb.dqb_curinodes += src_dq->dq_dqb.dqb_curinodes; > + } > + > + return 0; > +} > + > + > +errcode_t quota_merge_and_update_usage(quota_ctx_t dest_qctx, > + quota_ctx_t src_qctx) > +{ > + dict_t *dict; > + enum quota_type qtype; > + errcode_t retval = 0; > + > + for (qtype = 0; qtype < MAXQUOTAS; qtype++) { > + dict = src_qctx->quota_dict[qtype]; > + if (!dict) > + continue; > + retval = merge_usage(dest_qctx->quota_dict[qtype], dict); > + if (retval) > + break; > + } > + > + return retval; > +} > + > /* > * Compares the measured quota in qctx->quota_dict with that in the quota inode > * on disk and updates the limits in qctx->quota_dict. 'usage_inconsistent' is > diff --git a/lib/support/quotaio.h b/lib/support/quotaio.h > index 84fac35d..240a0762 100644 > --- a/lib/support/quotaio.h > +++ b/lib/support/quotaio.h > @@ -40,6 +40,7 @@ > #include "ext2fs/ext2_fs.h" > #include "ext2fs/ext2fs.h" > #include "dqblk_v2.h" > +#include "support/dict.h" > > typedef int64_t qsize_t; /* Type in which we store size limitations */ > > @@ -236,6 +237,8 @@ int quota_file_exists(ext2_filsys fs, enum quota_type qtype); > void quota_set_sb_inum(ext2_filsys fs, ext2_ino_t ino, enum quota_type qtype); > errcode_t quota_compare_and_update(quota_ctx_t qctx, enum quota_type qtype, > int *usage_inconsistent); > +errcode_t quota_merge_and_update_usage(quota_ctx_t dest_qctx, > + quota_ctx_t src_qctx); > int parse_quota_opts(const char *opts, int (*func)(char *)); > > /* parse_qtype.c */ > -- > 2.37.3 >