]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair: warn about unwritten bits set in rmap btree keys
authorDarrick J. Wong <djwong@kernel.org>
Mon, 5 Jun 2023 15:36:18 +0000 (08:36 -0700)
committerCarlos Maiolino <cem@kernel.org>
Wed, 12 Jul 2023 07:15:19 +0000 (09:15 +0200)
Now that we've changed libxfs to handle the rmapbt flags correctly when
creating and comparing rmapbt keys, teach repair to warn about keys that
have the unwritten bit erroneously set.  The old broken behavior never
caused any problems, so we only warn once per filesystem and don't set
the exitcode to 1 if we're running in dry run mode.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
repair/scan.c

index d66ce60cbb310d38df9dcfade3eb495e0abf817f..008ef65ac75122bbc36fb298d4acb43a12763caf 100644 (file)
@@ -966,6 +966,30 @@ verify_rmap_agbno(
        return agbno < libxfs_ag_block_count(mp, agno);
 }
 
+static inline void
+warn_rmap_unwritten_key(
+       xfs_agblock_t           agno)
+{
+       static bool             warned = false;
+       static pthread_mutex_t  lock = PTHREAD_MUTEX_INITIALIZER;
+
+       if (warned)
+               return;
+
+       pthread_mutex_lock(&lock);
+       if (!warned) {
+               if (no_modify)
+                       do_log(
+ _("would clear unwritten flag on rmapbt key in agno 0x%x\n"),
+                              agno);
+               else
+                       do_warn(
+ _("clearing unwritten flag on rmapbt key in agno 0x%x\n"),
+                              agno);
+               warned = true;
+       }
+       pthread_mutex_unlock(&lock);
+}
 
 static void
 scan_rmapbt(
@@ -1218,6 +1242,8 @@ advance:
                key.rm_flags = 0;
                key.rm_startblock = be32_to_cpu(kp->rm_startblock);
                key.rm_owner = be64_to_cpu(kp->rm_owner);
+               if (kp->rm_offset & cpu_to_be64(XFS_RMAP_OFF_UNWRITTEN))
+                       warn_rmap_unwritten_key(agno);
                if (libxfs_rmap_irec_offset_unpack(be64_to_cpu(kp->rm_offset),
                                &key)) {
                        /* Look for impossible flags. */
@@ -1239,6 +1265,8 @@ advance:
                key.rm_flags = 0;
                key.rm_startblock = be32_to_cpu(kp->rm_startblock);
                key.rm_owner = be64_to_cpu(kp->rm_owner);
+               if (kp->rm_offset & cpu_to_be64(XFS_RMAP_OFF_UNWRITTEN))
+                       warn_rmap_unwritten_key(agno);
                if (libxfs_rmap_irec_offset_unpack(be64_to_cpu(kp->rm_offset),
                                &key)) {
                        /* Look for impossible flags. */