xfs: check unused nlink fields in the ondisk inode
authorDarrick J. Wong <djwong@kernel.org>
Mon, 15 Apr 2024 21:55:03 +0000 (14:55 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 15 Apr 2024 21:58:59 +0000 (14:58 -0700)
v2/v3 inodes use di_nlink and not di_onlink; and v1 inodes use di_onlink
and not di_nlink.  Whichever field is not in use, make sure its contents
are zero, and teach xfs_scrub to fix that if it is.

This clears a bunch of missing scrub failure errors in xfs/385 for
core.onlink.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_inode_buf.c
fs/xfs/scrub/inode_repair.c

index d0dcce462bf4234e813bceb19448f65903c66956..d79002343d0b631290d7dfdaf69e715075111c52 100644 (file)
@@ -491,6 +491,14 @@ xfs_dinode_verify(
                        return __this_address;
        }
 
+       if (dip->di_version > 1) {
+               if (dip->di_onlink)
+                       return __this_address;
+       } else {
+               if (dip->di_nlink)
+                       return __this_address;
+       }
+
        /* don't allow invalid i_size */
        di_size = be64_to_cpu(dip->di_size);
        if (di_size & (1ULL << 63))
index 0dde5df2f8d39fa41a06cb6c41cd08bde380c2ed..e3b74ea50fdeffc8e9b06a92accc95541bc4a342 100644 (file)
@@ -516,6 +516,17 @@ xrep_dinode_mode(
        return 0;
 }
 
+/* Fix unused link count fields having nonzero values. */
+STATIC void
+xrep_dinode_nlinks(
+       struct xfs_dinode       *dip)
+{
+       if (dip->di_version > 1)
+               dip->di_onlink = 0;
+       else
+               dip->di_nlink = 0;
+}
+
 /* Fix any conflicting flags that the verifiers complain about. */
 STATIC void
 xrep_dinode_flags(
@@ -1377,6 +1388,7 @@ xrep_dinode_core(
        iget_error = xrep_dinode_mode(ri, dip);
        if (iget_error)
                goto write;
+       xrep_dinode_nlinks(dip);
        xrep_dinode_flags(sc, dip, ri->rt_extents > 0);
        xrep_dinode_size(ri, dip);
        xrep_dinode_extsize_hints(sc, dip);