Whamcloud - gitweb
e2fsck: kickoff mutex lock for block found map
[tools/e2fsprogs.git] / e2fsck / e2fsck.h
index b5b16f0..9721894 100644 (file)
 #endif
 
 #include "support/quotaio.h"
+#if __GNUC_PREREQ (4, 6)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+#endif
 #include "ext2fs/fast_commit.h"
+#if __GNUC_PREREQ (4, 6)
+#pragma GCC diagnostic pop
+#endif
 
 /*
  * Exit codes used by fsck-type programs
@@ -179,6 +186,7 @@ struct resource_track {
 #define E2F_OPT_UNSHARE_BLOCKS  0x40000
 #define E2F_OPT_CLEAR_UNINIT   0x80000 /* Hack to clear the uninit bit */
 #define E2F_OPT_CHECK_ENCODING  0x100000 /* Force verification of encoded filenames */
+#define E2F_OPT_MULTITHREAD    0x200000 /* Use multiple threads to speedup */
 
 /*
  * E2fsck flags
@@ -203,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)
 
@@ -226,10 +235,10 @@ typedef struct ea_refcount *ext2_refcount_t;
  */
 typedef struct e2fsck_struct *e2fsck_t;
 
-#define MAX_EXTENT_DEPTH_COUNT 5
+#define MAX_EXTENT_DEPTH_COUNT 8
 
 /*
- * This strucutre is used to manage the list of extents in a file. Placing
+ * This structure is used to manage the list of extents in a file. Placing
  * it here since this is used by fast_commit.h.
  */
 struct extent_list {
@@ -247,13 +256,35 @@ struct e2fsck_fc_replay_state {
        struct extent_list fc_extent_list;
        int fc_replay_num_tags;
        int fc_replay_expected_off;
-       int fc_current_pass;
+       enum passtype fc_current_pass;
        int fc_cur_tag;
-       int fc_crc;
+       unsigned int fc_crc;
        __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;
+       char            et_log_buf[2048];
+       int             et_log_length;
+};
+#endif
+
 struct e2fsck_struct {
+       /* Global context to get the cancel flag */
+       e2fsck_t                global_ctx;
        ext2_filsys fs;
        const char *program_name;
        char *filesystem_name;
@@ -273,6 +304,7 @@ struct e2fsck_struct {
        ext2_ino_t free_inodes;
        int     mount_flags;
        int     openfs_flags;
+       io_manager io_manager;
        blkid_cache blkid;      /* blkid cache */
 
 #ifdef HAVE_SETJMP_H
@@ -303,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.
@@ -332,8 +365,13 @@ struct e2fsck_struct {
        /*
         * For pass1_check_directory and pass1_get_blocks
         */
-       ext2_ino_t stashed_ino;
-       struct ext2_inode *stashed_inode;
+       ext2_ino_t              stashed_ino;
+       struct ext2_inode       *stashed_inode;
+
+       /* if @global_ctx is null, this field is unused */
+#ifdef HAVE_PTHREAD
+       struct e2fsck_thread     thread_info;
+#endif
 
        /*
         * Location of the lost and found directory
@@ -415,6 +453,7 @@ struct e2fsck_struct {
        __u32 fs_fragmented;
        __u32 fs_fragmented_dir;
        __u32 large_files;
+       __u32 large_dirs;
        __u32 fs_ext_attr_inodes;
        __u32 fs_ext_attr_blocks;
        __u32 extent_depth_count[MAX_EXTENT_DEPTH_COUNT];
@@ -450,8 +489,43 @@ struct e2fsck_struct {
 
        /* Fast commit replay state */
        struct e2fsck_fc_replay_state fc_replay_state;
+#ifdef HAVE_PTHREAD
+       /* serialize fix operation for multiple threads */
+       pthread_mutex_t          fs_fix_mutex;
+       /* protect block_found_map, block_dup_map */
+       pthread_rwlock_t         fs_block_map_rwlock;
+#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;
@@ -497,6 +571,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);
@@ -511,6 +587,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,
@@ -648,6 +725,7 @@ void sigcatcher_setup(void);
 void check_super_block(e2fsck_t ctx);
 int check_backup_super_block(e2fsck_t ctx);
 void check_resize_inode(e2fsck_t ctx);
+int check_init_orphan_file(e2fsck_t ctx);
 
 /* util.c */
 extern void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
@@ -718,6 +796,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);