aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Xi <lixi@ddn.com>2019-09-02 16:14:38 +0800
committerTheodore Ts'o <tytso@mit.edu>2021-01-25 15:17:12 -0500
commitfdbf5e226cf931a5713414001b95e4697997a464 (patch)
treeaefb26613c765651da2078da996bcab0e7b93ea2
parent13d3c76475d050941d244c85cbb9256ffd980f88 (diff)
downloade2fsprogs-fdbf5e226cf931a5713414001b95e4697997a464.tar.gz
e2fsck: merge dir_info after thread finishes
dir_info need be merged after thread finish. Signed-off-by: Li Xi <lixi@ddn.com> 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/dirinfo.c66
-rw-r--r--e2fsck/e2fsck.h2
-rw-r--r--e2fsck/pass1.c58
3 files changed, 123 insertions, 3 deletions
diff --git a/e2fsck/dirinfo.c b/e2fsck/dirinfo.c
index 28baaca2e..b4adaa6e3 100644
--- a/e2fsck/dirinfo.c
+++ b/e2fsck/dirinfo.c
@@ -170,6 +170,72 @@ e2fsck_dir_info_min_larger_equal(struct dir_info_db *dir_info,
}
/*
+ * Merge two sorted dir info to @dest
+ */
+void e2fsck_merge_dir_info(e2fsck_t ctx, struct dir_info_db *src,
+ struct dir_info_db *dest)
+{
+ size_t size_dir_info = sizeof(struct dir_info);
+ ext2_ino_t size = dest->size;
+ struct dir_info *src_array = src->array;
+ struct dir_info *dest_array = dest->array;
+ ext2_ino_t src_count = src->count;
+ ext2_ino_t dest_count = dest->count;
+ ext2_ino_t total_count = src_count + dest_count;
+ struct dir_info *tmp_array;
+ struct dir_info *array_ptr;
+ ext2_ino_t src_index = 0;
+ ext2_ino_t dest_index = 0;
+
+ if (src->count == 0)
+ return;
+
+ if (size < total_count)
+ size = total_count;
+
+ if (size < src->size)
+ size = src->size;
+
+ tmp_array = e2fsck_allocate_memory(ctx, size * size_dir_info,
+ "directory map");
+ array_ptr = tmp_array;
+ /*
+ * This can be improved by binary search and memcpy, but codes
+ * would be more complex. And if the groups distributed to each
+ * thread are strided, this implementation won't be too bad
+ * comparing to the optimiztion.
+ */
+ while (src_index < src_count || dest_index < dest_count) {
+ if (src_index >= src_count) {
+ memcpy(array_ptr, &dest_array[dest_index],
+ (dest_count - dest_index) * size_dir_info);
+ break;
+ }
+ if (dest_index >= dest_count) {
+ memcpy(array_ptr, &src_array[src_index],
+ (src_count - src_index) * size_dir_info);
+ break;
+ }
+ if (src_array[src_index].ino < dest_array[dest_index].ino) {
+ *array_ptr = src_array[src_index];
+ src_index++;
+ } else {
+ assert(src_array[src_index].ino >
+ dest_array[dest_index].ino);
+ *array_ptr = dest_array[dest_index];
+ dest_index++;
+ }
+ array_ptr++;
+ }
+
+ if (dest->array)
+ ext2fs_free_mem(&dest->array);
+ dest->array = tmp_array;
+ dest->size = size;
+ dest->count = total_count;
+}
+
+/*
*
* Insert an inode into the sorted array. The array should have at least one
* free slot.
diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h
index 8576c007f..531a353e9 100644
--- a/e2fsck/e2fsck.h
+++ b/e2fsck/e2fsck.h
@@ -507,6 +507,8 @@ extern void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
/* dirinfo.c */
extern void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent);
+void e2fsck_merge_dir_info(e2fsck_t ctx, struct dir_info_db *src,
+ struct dir_info_db *dest);
extern void e2fsck_free_dir_info(e2fsck_t ctx);
extern int e2fsck_get_num_dirinfo(e2fsck_t ctx);
extern struct dir_info_iter *e2fsck_dir_info_iter_begin(e2fsck_t ctx);
diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index 58bcc407a..a1ea487a9 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -2363,6 +2363,21 @@ out_context:
return retval;
}
+static void e2fsck_pass1_merge_dir_info(e2fsck_t global_ctx, e2fsck_t thread_ctx)
+{
+ if (thread_ctx->dir_info == NULL)
+ return;
+
+ if (global_ctx->dir_info == NULL) {
+ global_ctx->dir_info = thread_ctx->dir_info;
+ thread_ctx->dir_info = NULL;
+ return;
+ }
+
+ e2fsck_merge_dir_info(global_ctx, thread_ctx->dir_info,
+ global_ctx->dir_info);
+}
+
static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx)
{
errcode_t retval;
@@ -2372,6 +2387,7 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx
FILE *global_logf = global_ctx->logf;
FILE *global_problem_logf = global_ctx->problem_logf;
ext2fs_inode_bitmap inode_bad_map = global_ctx->inode_bad_map;
+ struct dir_info_db *dir_info = global_ctx->dir_info;
ext2fs_inode_bitmap inode_used_map = global_ctx->inode_used_map;
ext2fs_inode_bitmap inode_dir_map = global_ctx->inode_dir_map;
ext2fs_inode_bitmap inode_bb_map = global_ctx->inode_bb_map;
@@ -2404,6 +2420,8 @@ static int e2fsck_pass1_thread_join_one(e2fsck_t global_ctx, e2fsck_t thread_ctx
global_ctx->block_dup_map = block_dup_map;
global_ctx->block_ea_map = block_ea_map;
global_ctx->block_metadata_map = block_metadata_map;
+ global_ctx->dir_info = dir_info;
+ e2fsck_pass1_merge_dir_info(global_ctx, thread_ctx);
/* Keep the global singal flags*/
global_ctx->flags |= (flags & E2F_FLAG_SIGNAL_MASK) |
@@ -2503,6 +2521,7 @@ static int e2fsck_pass1_thread_join(e2fsck_t global_ctx, e2fsck_t thread_ctx)
e2fsck_pass1_free_bitmap(&thread_ctx->block_dup_map);
e2fsck_pass1_free_bitmap(&thread_ctx->block_ea_map);
e2fsck_pass1_free_bitmap(&thread_ctx->block_metadata_map);
+ e2fsck_free_dir_info(thread_ctx);
ext2fs_free_mem(&thread_ctx);
return retval;
@@ -2667,15 +2686,48 @@ out_abort:
}
#endif
+/* TODO: tdb needs to be handled properly for multiple threads*/
+static int multiple_threads_supported(e2fsck_t ctx)
+{
+#ifdef CONFIG_TDB
+ unsigned int threshold;
+ ext2_ino_t num_dirs;
+ errcode_t retval;
+ char *tdb_dir;
+ int enable;
+
+ profile_get_string(ctx->profile, "scratch_files", "directory", 0, 0,
+ &tdb_dir);
+ profile_get_uint(ctx->profile, "scratch_files",
+ "numdirs_threshold", 0, 0, &threshold);
+ profile_get_boolean(ctx->profile, "scratch_files",
+ "icount", 0, 1, &enable);
+
+ retval = ext2fs_get_num_dirs(ctx->fs, &num_dirs);
+ if (retval)
+ num_dirs = 1024; /* Guess */
+
+ /* tdb is unsupported now */
+ if (enable && tdb_dir && !access(tdb_dir, W_OK) &&
+ (!threshold || num_dirs > threshold))
+ return 0;
+ #endif
+ return 1;
+}
+
void e2fsck_pass1(e2fsck_t ctx)
{
init_ext2_max_sizes();
#ifdef HAVE_PTHREAD
- e2fsck_pass1_multithread(ctx);
-#else
- e2fsck_pass1_run(ctx);
+ if (multiple_threads_supported(ctx)) {
+ e2fsck_pass1_multithread(ctx);
+ return;
+ }
+ fprintf(stderr, "Fall through single thread for pass1 "
+ "because tdb could not handle properly\n");
#endif
+ e2fsck_pass1_run(ctx);
}
#undef FINISH_INODE_LOOP