@@ -56,6 +56,7 @@
#include <e2p/e2p.h>
#include "problem.h"
+#include "support/dict.h"
#ifdef NO_INLINE_FUNCS
#define _INLINE_
@@ -2447,6 +2448,11 @@ static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx,
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:
@@ -2533,6 +2539,20 @@ static int e2fsck_pass1_merge_dirs_to_hash(e2fsck_t global_ctx, e2fsck_t thread_
return retval;
}
+static void e2fsck_pass1_merge_quota_ctx(e2fsck_t global_ctx, e2fsck_t thread_ctx)
+{
+ dict_t *dict;
+ enum quota_type qtype;
+
+ for (qtype = 0; qtype < MAXQUOTAS; qtype++) {
+ dict = thread_ctx->qctx->quota_dict[qtype];
+ if (dict)
+ quota_merge_and_update_usage(
+ global_ctx->qctx->quota_dict[qtype], dict);
+ }
+ quota_release_context(&thread_ctx->qctx);
+}
+
static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx)
{
errcode_t retval;
@@ -2575,6 +2595,7 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx
int dx_dir_info_size = global_ctx->dx_dir_info_size;
int 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;
@@ -2645,6 +2666,8 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx
com_err(global_ctx->program_name, 0, _("while merging dirs to hash\n"));
return retval;
}
+ global_ctx->qctx = qctx;
+ e2fsck_pass1_merge_quota_ctx(global_ctx, thread_ctx);
/*
* PASS1_COPY_CTX_BITMAP might return directly from this function,
@@ -639,6 +639,25 @@ out:
return err;
}
+errcode_t quota_merge_and_update_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;
+}
+
/*
* 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
@@ -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,7 @@ 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(dict_t *dest, dict_t *src);
int parse_quota_opts(const char *opts, int (*func)(char *));
/* parse_qtype.c */