aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWang Shilong <wshilong@ddn.com>2020-03-06 23:08:07 +0800
committerTheodore Ts'o <tytso@mit.edu>2021-01-25 15:17:48 -0500
commita0af18577fbb960eb20695afbb4af4e23b864909 (patch)
treede3ec5fe5d4a48761744ecd1e42b752ebe261c2f
parentc36fa1b28bd4171f53ab4f89a90f6b3b8bf80fd2 (diff)
downloade2fsprogs-a0af18577fbb960eb20695afbb4af4e23b864909.tar.gz
e2fsck: merge quota context after threads finish
Every threads calculate its own quota accounting, merge them after threads finish. Signed-off-by: Wang Shilong <wshilong@ddn.com> Reviewed-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--e2fsck/pass1.c15
-rw-r--r--lib/support/mkquota.c39
-rw-r--r--lib/support/quotaio.h3
3 files changed, 56 insertions, 1 deletions
diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index 4e7520cbf..dd590356b 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -2388,6 +2388,12 @@ static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thre
log_out(thread_context, _("Scan group range [%d, %d)\n"),
tinfo->et_group_start, tinfo->et_group_end);
thread_context->fs = thread_fs;
+ retval = quota_init_context(&thread_context->qctx, thread_fs, 0);
+ if (retval) {
+ com_err(global_ctx->program_name, retval,
+ "while init quota context");
+ goto out_fs;
+ }
*thread_ctx = thread_context;
return 0;
out_fs:
@@ -2481,7 +2487,6 @@ static errcode_t e2fsck_pass1_merge_dirs_to_hash(e2fsck_t global_ctx,
return retval;
}
-
static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx)
{
errcode_t retval;
@@ -2525,6 +2530,7 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx
ext2_ino_t dx_dir_info_size = global_ctx->dx_dir_info_size;
ext2_ino_t dx_dir_info_count = global_ctx->dx_dir_info_count;
ext2_u32_list dirs_to_hash = global_ctx->dirs_to_hash;
+ quota_ctx_t qctx = global_ctx->qctx;
#ifdef HAVE_SETJMP_H
jmp_buf old_jmp;
@@ -2600,6 +2606,12 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx
return retval;
}
+ global_ctx->qctx = qctx;
+ retval = quota_merge_and_update_usage(global_ctx->qctx,
+ thread_ctx->qctx);
+ if (retval)
+ return retval;
+
retval = e2fsck_pass1_merge_bitmap(global_fs,
&thread_ctx->inode_used_map,
&global_ctx->inode_used_map);
@@ -2688,6 +2700,7 @@ static int e2fsck_pass1_thread_join(e2fsck_t global_ctx, e2fsck_t thread_ctx)
ext2fs_free_icount(thread_ctx->inode_link_info);
if (thread_ctx->dirs_to_hash)
ext2fs_badblocks_list_free(thread_ctx->dirs_to_hash);
+ quota_release_context(&thread_ctx->qctx);
ext2fs_free_mem(&thread_ctx);
return retval;
diff --git a/lib/support/mkquota.c b/lib/support/mkquota.c
index 6f7ae6d6a..c16a3d0a0 100644
--- a/lib/support/mkquota.c
+++ b/lib/support/mkquota.c
@@ -639,6 +639,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 606897000..bca295a11 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 */
@@ -233,6 +234,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 */