Whamcloud - gitweb
LU-14953 e2fsck: pfsck progress report
[tools/e2fsprogs.git] / e2fsck / e2fsck.h
index b45912e..3749b68 100644 (file)
@@ -211,6 +211,7 @@ struct resource_track {
 #define E2F_FLAG_TIME_INSANE   0x2000 /* Time is insane */
 #define E2F_FLAG_PROBLEMS_FIXED        0x4000 /* At least one problem was fixed */
 #define E2F_FLAG_ALLOC_OK      0x8000 /* Can we allocate blocks? */
+#define E2F_FLAG_DUP_BLOCK     0x20000 /* dup block found during pass1 */
 
 #define E2F_RESET_FLAGS (E2F_FLAG_TIME_INSANE | E2F_FLAG_PROBLEMS_FIXED)
 
@@ -261,6 +262,26 @@ struct e2fsck_fc_replay_state {
        __u16 fc_super_state;
 };
 
+#ifdef HAVE_PTHREAD
+/*
+ * Fields that used for multi-thread
+ */
+struct e2fsck_thread {
+       /* Thread index */
+       int             et_thread_index;
+       /* The start group number for this thread */
+       dgrp_t          et_group_start;
+       /* The end (not included) group number for this thread*/
+       dgrp_t          et_group_end;
+       /* The next group number to check */
+       dgrp_t          et_group_next;
+       /* Scanned inode number */
+       ext2_ino_t      et_inode_number;
+       int             et_log_length;
+       char            et_log_buf[2048];
+};
+#endif
+
 struct e2fsck_struct {
        /* Global context to get the cancel flag */
        e2fsck_t                global_ctx;
@@ -314,6 +335,7 @@ struct e2fsck_struct {
 
        ext2_refcount_t refcount;
        ext2_refcount_t refcount_extra;
+       ext2_refcount_t refcount_orig;
 
        /*
         * Quota blocks and inodes to be charged for each ea block.
@@ -345,8 +367,6 @@ struct e2fsck_struct {
         */
        ext2_ino_t              stashed_ino;
        struct ext2_inode       *stashed_inode;
-       /* Thread index, if global_ctx is null, this field is unused */
-       int                     thread_index;
 
        /*
         * Location of the lost and found directory
@@ -464,8 +484,49 @@ struct e2fsck_struct {
 
        /* Fast commit replay state */
        struct e2fsck_fc_replay_state fc_replay_state;
+#ifdef HAVE_PTHREAD
+       /* if @global_ctx is null, this field is unused */
+       struct e2fsck_thread     thread_info;
+       __u32                    pfs_num_threads;
+       __u32                    mmp_update_thread;
+       int                      fs_need_locking;
+       /* serialize fix operation for multiple threads */
+       pthread_rwlock_t         fs_fix_rwlock;
+       /* protect block_found_map, block_dup_map */
+       pthread_rwlock_t         fs_block_map_rwlock;
+       struct e2fsck_thread_info       *infos;
+#endif
+};
+
+#ifdef HAVE_PTHREAD
+#ifdef DEBUG_THREADS
+/*
+ * Enabling DEBUG_THREADS would cause the parallel
+ * fsck threads run sequentially.
+ */
+struct e2fsck_thread_debug {
+       pthread_mutex_t etd_mutex;
+       pthread_cond_t  etd_cond;
+       int             etd_finished_threads;
+};
+#endif
+
+struct e2fsck_thread_info {
+       /* ID returned by pthread_create() */
+       pthread_t                eti_thread_id;
+       /* Application-defined thread index */
+       int                      eti_thread_index;
+       /* Thread has been started */
+       int                      eti_started;
+       /* Context used for this thread */
+       e2fsck_t                 eti_thread_ctx;
+#ifdef DEBUG_THREADS
+       struct e2fsck_thread_debug      *eti_debug;
+#endif
 };
 
+#endif
+
 /* Data structures to evaluate whether an extent tree needs rebuilding. */
 struct extent_tree_level {
        unsigned int    num_extents;
@@ -493,6 +554,8 @@ extern int e2fsck_strnlen(const char * s, int count);
 
 extern void e2fsck_pass1(e2fsck_t ctx);
 extern void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf);
+extern void e2fsck_pass1_check_lock(e2fsck_t ctx);
+extern void e2fsck_pass1_check_unlock(e2fsck_t ctx);
 extern void e2fsck_pass2(e2fsck_t ctx);
 extern void e2fsck_pass3(e2fsck_t ctx);
 extern void e2fsck_pass4(e2fsck_t ctx);
@@ -511,6 +574,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);
@@ -525,6 +590,7 @@ extern int e2fsck_dir_info_get_parent(e2fsck_t ctx, ext2_ino_t ino,
                                      ext2_ino_t *parent);
 extern int e2fsck_dir_info_get_dotdot(e2fsck_t ctx, ext2_ino_t ino,
                                      ext2_ino_t *dotdot);
+extern void e2fsck_merge_dx_dir(e2fsck_t global_ctx, e2fsck_t thread_ctx);
 
 /* dx_dirinfo.c */
 extern void e2fsck_add_dx_dir(e2fsck_t ctx, ext2_ino_t ino,
@@ -665,6 +731,7 @@ void check_resize_inode(e2fsck_t ctx);
 int check_init_orphan_file(e2fsck_t ctx);
 
 /* util.c */
+#define E2FSCK_MAX_THREADS     (65535)
 extern void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
                                    const char *description);
 extern int ask(e2fsck_t ctx, const char * string, int def);
@@ -733,6 +800,12 @@ extern errcode_t e2fsck_allocate_subcluster_bitmap(ext2_filsys fs,
                                                   const char *profile_name,
                                                   ext2fs_block_bitmap *ret);
 unsigned long long get_memory_size(void);
+extern void e2fsck_pass1_fix_lock(e2fsck_t ctx);
+extern void e2fsck_pass1_fix_unlock(e2fsck_t ctx);
+extern void e2fsck_pass1_block_map_w_lock(e2fsck_t ctx);
+extern void e2fsck_pass1_block_map_w_unlock(e2fsck_t ctx);
+extern void e2fsck_pass1_block_map_r_lock(e2fsck_t ctx);
+extern void e2fsck_pass1_block_map_r_unlock(e2fsck_t ctx);
 
 /* unix.c */
 extern void e2fsck_clear_progbar(e2fsck_t ctx);