]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
repair: simplify rt_lock handling
authorChristoph Hellwig <hch@lst.de>
Thu, 15 Aug 2024 06:52:04 +0000 (08:52 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 15 Aug 2024 12:57:50 +0000 (14:57 +0200)
No need to cacheline align rt_lock if we move it next to the data
it protects.  Also reduce the critical section to just where those
data structures are accessed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
repair/dinode.c
repair/globals.c
repair/globals.h
repair/incore.c

index cec372dbf2d715eced80fae10ff0402eac8f9f3f..763adc73c09af8c2700cea0831bf5afce97e4d0f 100644 (file)
@@ -422,7 +422,7 @@ process_rt_rec(
        bool                    zap_metadata)
 {
        xfs_fsblock_t           lastb;
-       int                     bad;
+       int                     bad = 0;
 
        /*
         * check numeric validity of the extent
@@ -456,23 +456,22 @@ _("inode %" PRIu64 " - bad rt extent overflows - start %" PRIu64 ", "
                return 1;
        }
 
+       pthread_mutex_lock(&rt_lock);
        bad = check_rt_rec_state(mp, ino, irec);
-       if (bad)
-               return bad;
-
-       if (check_dups) {
-               bad = process_rt_rec_dups(mp, ino, irec);
-               if (bad)
-                       return bad;
-       } else {
-               process_rt_rec_state(mp, ino, zap_metadata, irec);
+       if (!bad) {
+               if (check_dups)
+                       bad = process_rt_rec_dups(mp, ino, irec);
+               else
+                       process_rt_rec_state(mp, ino, zap_metadata, irec);
        }
+       pthread_mutex_unlock(&rt_lock);
 
        /*
         * bump up the block counter
         */
-       *tot += irec->br_blockcount;
-       return 0;
+       if (!bad)
+               *tot += irec->br_blockcount;
+       return bad;
 }
 
 static inline bool
@@ -589,10 +588,8 @@ _("zero length extent (off = %" PRIu64 ", fsbno = %" PRIu64 ") in ino %" PRIu64
                }
 
                if (isrt && !xfs_has_rtgroups(mp)) {
-                       pthread_mutex_lock(&rt_lock.lock);
                        error2 = process_rt_rec(mp, &irec, ino, tot, check_dups,
                                        zap_metadata);
-                       pthread_mutex_unlock(&rt_lock.lock);
                        if (error2)
                                return error2;
 
index a3eec43ba97df9462b013197407ff0984990fbf1..d0c2a3f57a9a255d5376ca258ce86d9c76b63386 100644 (file)
@@ -122,7 +122,6 @@ uint32_t    sb_unit;
 uint32_t       sb_width;
 
 struct aglock  *ag_locks;
-struct aglock  rt_lock;
 
 time_t         report_interval;
 uint64_t       *prog_rpt_done;
index ffed60cf4ab424055b2438f7c89db947747b9a2b..c2593c8947682236500f9000d0ce5d6087ff5ed0 100644 (file)
@@ -166,7 +166,7 @@ struct aglock {
        pthread_mutex_t lock __attribute__((__aligned__(64)));
 };
 extern struct aglock   *ag_locks;
-extern struct aglock   rt_lock;
+extern pthread_mutex_t rt_lock;
 
 extern time_t          report_interval;
 extern uint64_t                *prog_rpt_done;
index 869c3a06693ab317248d0c79af744461f4925c27..3aae0eaf1bbf9fe183bec80316acb33f1f5900bb 100644 (file)
@@ -166,6 +166,7 @@ get_bmap_ext(
 
 static uint64_t                *rt_bmap;
 static size_t          rt_bmap_size;
+pthread_mutex_t                rt_lock;
 
 /* block records fit into uint64_t's units */
 #define XR_BB_UNIT     64                      /* number of bits/unit */
@@ -218,6 +219,7 @@ init_rt_bmap(
        if (mp->m_sb.sb_rextents == 0)
                return;
 
+       pthread_mutex_init(&rt_lock, NULL);
        rt_bmap_size = roundup(howmany(mp->m_sb.sb_rextents, (NBBY / XR_BB)),
                               sizeof(uint64_t));
 
@@ -237,8 +239,9 @@ free_rt_bmap(xfs_mount_t *mp)
 {
        free(rt_bmap);
        rt_bmap = NULL;
-}
+       pthread_mutex_destroy(&rt_lock);
 
+}
 
 void
 reset_bmaps(xfs_mount_t *mp)
@@ -322,7 +325,6 @@ init_bmaps(
                btree_init(&ag_bmap[i]);
                pthread_mutex_init(&ag_locks[i].lock, NULL);
        }
-       pthread_mutex_init(&rt_lock.lock, NULL);
 
        init_rt_bmap(mp);
        reset_bmaps(mp);
@@ -336,8 +338,6 @@ free_bmaps(
                mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount;
        unsigned int            i;
 
-       pthread_mutex_destroy(&rt_lock.lock);
-
        for (i = 0; i < nr_groups; i++)
                pthread_mutex_destroy(&ag_locks[i].lock);