]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
repair: Protect bad inode list with mutex
authorDave Chinner <dchinner@redhat.com>
Thu, 15 Apr 2021 19:44:49 +0000 (15:44 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 15 Apr 2021 19:44:49 +0000 (15:44 -0400)
To enable phase 6 parallelisation, we need to protect the bad inode
list from concurrent modification and/or access. Wrap it with a
mutex and clean up the nasty typedefs.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
repair/dir2.c
repair/dir2.h

index eabdb4f2d497be8d5b9d73a7dc92c912c37093c3..fdf915327e2d3472226c6b6c20409d9b36bfccd8 100644 (file)
  * Known bad inode list.  These are seen when the leaf and node
  * block linkages are incorrect.
  */
-typedef struct dir2_bad {
+struct dir2_bad {
        xfs_ino_t       ino;
        struct dir2_bad *next;
-} dir2_bad_t;
+};
 
-static dir2_bad_t *dir2_bad_list;
+static struct dir2_bad *dir2_bad_list;
+pthread_mutex_t                dir2_bad_list_lock = PTHREAD_MUTEX_INITIALIZER;
 
 static void
 dir2_add_badlist(
        xfs_ino_t       ino)
 {
-       dir2_bad_t      *l;
+       struct dir2_bad *l;
 
-       if ((l = malloc(sizeof(dir2_bad_t))) == NULL) {
+       l = malloc(sizeof(*l));
+       if (!l) {
                do_error(
 _("malloc failed (%zu bytes) dir2_add_badlist:ino %" PRIu64 "\n"),
-                       sizeof(dir2_bad_t), ino);
+                       sizeof(*l), ino);
                exit(1);
        }
+       pthread_mutex_lock(&dir2_bad_list_lock);
        l->next = dir2_bad_list;
        dir2_bad_list = l;
        l->ino = ino;
+       pthread_mutex_unlock(&dir2_bad_list_lock);
 }
 
-int
+bool
 dir2_is_badino(
        xfs_ino_t       ino)
 {
-       dir2_bad_t      *l;
+       struct dir2_bad *l;
+       bool            ret = false;
 
-       for (l = dir2_bad_list; l; l = l->next)
-               if (l->ino == ino)
-                       return 1;
-       return 0;
+       pthread_mutex_lock(&dir2_bad_list_lock);
+       for (l = dir2_bad_list; l; l = l->next) {
+               if (l->ino == ino) {
+                       ret = true;
+                       break;
+               }
+       }
+       pthread_mutex_unlock(&dir2_bad_list_lock);
+       return ret;
 }
 
 /*
index 5795aac5eaab355c290b245c8f8b08d2b3bf9b59..af4cfb1da3297419b5458770e20cb9771f2dc4f6 100644 (file)
@@ -27,7 +27,7 @@ process_sf_dir2_fixi8(
        struct xfs_dir2_sf_hdr  *sfp,
        xfs_dir2_sf_entry_t     **next_sfep);
 
-int
+bool
 dir2_is_badino(
        xfs_ino_t       ino);