[PATCH 1/2] xfs: fix error returns in CoW fork repair

From: Yingjie Gao

Date: Tue May 26 2026 - 08:34:25 EST


The non-realtime CoW fork repair scan returns success after the
common cleanup labels, even if the AG setup, btree queries, or bitmap
updates failed. This can make online repair continue with an
incomplete bad-file-offset bitmap instead of stopping at the original
error.

The force-rebuild path has the opposite cleanup problem: if marking
the entire mapping fails, it returns directly and skips the scrub AG
context and perag reference cleanup.

Send force-rebuild failures through the existing cleanup label and
return the saved error from the function. Successful scans still
return zero.

Fixes: dbbdbd008632 ("xfs: repair problems in CoW forks")
Signed-off-by: Yingjie Gao <gaoyingjie@xxxxxxxxxxxxx>
---
fs/xfs/scrub/cow_repair.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/scrub/cow_repair.c b/fs/xfs/scrub/cow_repair.c
index bffc4666ce60..bc3838bac71a 100644
--- a/fs/xfs/scrub/cow_repair.c
+++ b/fs/xfs/scrub/cow_repair.c
@@ -304,14 +304,14 @@ xrep_cow_find_bad(
error = xrep_cow_mark_file_range(xc, xc->irec.br_startblock,
xc->irec.br_blockcount);
if (error)
- return error;
+ goto out_sa;
}

out_sa:
xchk_ag_free(sc, &sc->sa);
out_pag:
xfs_perag_put(pag);
- return 0;
+ return error;
}

/*
--
2.20.1