From ad662cc1734675623a484e111fa2422a08ee45d6 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Mon, 5 Jun 2023 08:36:18 -0700 Subject: [PATCH] xfs_repair: warn about unwritten bits set in rmap btree keys 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 Reviewed-by: Carlos Maiolino Signed-off-by: Carlos Maiolino --- repair/scan.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/repair/scan.c b/repair/scan.c index d66ce60cb..008ef65ac 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -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. */ -- 2.39.5