xfs: zero i_nlink before repair puts inode on unlinked list

LOLLM observes that we don't reset i_nlink if we encounter a file with
no parent that isn't on the unlinked list.  This causes unnecessary
assertion trips on debugging kernels and an inconsistent file, so let's
fix that.

Cc: stable@vger.kernel.org # v6.10
Fixes: 669dfe883c ("xfs: update the unlinked list when repairing link counts")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Assisted-by: LOLLM # finding obvious bugs
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
This commit is contained in:
Darrick J. Wong
2026-07-20 20:24:33 -07:00
committed by Carlos Maiolino
parent 8ed7810472
commit 49933254ba

View File

@@ -232,9 +232,14 @@ xrep_nlinks_repair_inode(
* unlinked list, put it on the unlinked list.
*/
if (total_links == 0 && !xfs_inode_on_unlinked_list(ip)) {
if (actual_nlink)
clear_nlink(VFS_I(ip));
error = xfs_iunlink(sc->tp, ip);
if (error)
if (error) {
if (actual_nlink)
set_nlink(VFS_I(ip), actual_nlink);
goto out_trans;
}
dirty = true;
}