Commit 40cb8613 authored by Darrick J. Wong's avatar Darrick J. Wong
Browse files

xfs: check unused nlink fields in the ondisk inode



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: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent ab97f4b1
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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))
+12 −0
Original line number Diff line number Diff line
@@ -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);