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

xfs: set inode sick state flags when we zap either ondisk fork



In a few patches, we'll add some online repair code that tries to
massage the ondisk inode record just enough to get it to pass the inode
verifiers so that we can continue with more file repairs.  Part of that
massaging can include zapping the ondisk forks to clear errors.  After
that point, the bmap fork repair functions will rebuild the zapped
forks.

Christoph asked for stronger protections against online repair zapping a
fork to get the inode to load vs. other threads trying to access the
partially repaired file.  Do this by adding a special "[DA]FORK_ZAPPED"
inode health flag whenever repair zaps a fork, and sprinkling checks for
that flag into the various file operations for things that don't like
handling an unexpected zero-extents fork.

In practice xfs_scrub will scrub and fix the forks almost immediately
after zapping them, so the window is very small.  However, if a crash or
unmount should occur, we can still detect these zapped inode forks by
looking for a zero-extents fork when data was expected.

Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent 6b5d9177
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -68,6 +68,11 @@ struct xfs_fsop_geom;
#define XFS_SICK_INO_SYMLINK	(1 << 6)  /* symbolic link remote target */
#define XFS_SICK_INO_PARENT	(1 << 7)  /* parent pointers */

#define XFS_SICK_INO_BMBTD_ZAPPED	(1 << 8)  /* data fork erased */
#define XFS_SICK_INO_BMBTA_ZAPPED	(1 << 9)  /* attr fork erased */
#define XFS_SICK_INO_DIR_ZAPPED		(1 << 10) /* directory erased */
#define XFS_SICK_INO_SYMLINK_ZAPPED	(1 << 11) /* symlink erased */

/* Primary evidence of health problems in a given group. */
#define XFS_SICK_FS_PRIMARY	(XFS_SICK_FS_COUNTERS | \
				 XFS_SICK_FS_UQUOTA | \
@@ -97,6 +102,11 @@ struct xfs_fsop_geom;
				 XFS_SICK_INO_SYMLINK | \
				 XFS_SICK_INO_PARENT)

#define XFS_SICK_INO_ZAPPED	(XFS_SICK_INO_BMBTD_ZAPPED | \
				 XFS_SICK_INO_BMBTA_ZAPPED | \
				 XFS_SICK_INO_DIR_ZAPPED | \
				 XFS_SICK_INO_SYMLINK_ZAPPED)

/* These functions must be provided by the xfs implementation. */

void xfs_fs_mark_sick(struct xfs_mount *mp, unsigned int mask);
+37 −2
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@
#include "xfs_bmap_btree.h"
#include "xfs_rmap.h"
#include "xfs_rmap_btree.h"
#include "xfs_health.h"
#include "scrub/scrub.h"
#include "scrub/common.h"
#include "scrub/btree.h"
#include "scrub/health.h"
#include "xfs_ag.h"

/* Set us up with an inode's bmap. */
@@ -943,7 +945,20 @@ int
xchk_bmap_data(
	struct xfs_scrub	*sc)
{
	return xchk_bmap(sc, XFS_DATA_FORK);
	int			error;

	if (xchk_file_looks_zapped(sc, XFS_SICK_INO_BMBTD_ZAPPED)) {
		xchk_ino_set_corrupt(sc, sc->ip->i_ino);
		return 0;
	}

	error = xchk_bmap(sc, XFS_DATA_FORK);
	if (error)
		return error;

	/* If the data fork is clean, it is clearly not zapped. */
	xchk_mark_healthy_if_clean(sc, XFS_SICK_INO_BMBTD_ZAPPED);
	return 0;
}

/* Scrub an inode's attr fork. */
@@ -951,7 +966,27 @@ int
xchk_bmap_attr(
	struct xfs_scrub	*sc)
{
	return xchk_bmap(sc, XFS_ATTR_FORK);
	int			error;

	/*
	 * If the attr fork has been zapped, it's possible that forkoff was
	 * reset to zero and hence sc->ip->i_afp is NULL.  We don't want the
	 * NULL ifp check in xchk_bmap to conclude that the attr fork is ok,
	 * so short circuit that logic by setting the corruption flag and
	 * returning immediately.
	 */
	if (xchk_file_looks_zapped(sc, XFS_SICK_INO_BMBTA_ZAPPED)) {
		xchk_ino_set_corrupt(sc, sc->ip->i_ino);
		return 0;
	}

	error = xchk_bmap(sc, XFS_ATTR_FORK);
	if (error)
		return error;

	/* If the attr fork is clean, it is clearly not zapped. */
	xchk_mark_healthy_if_clean(sc, XFS_SICK_INO_BMBTA_ZAPPED);
	return 0;
}

/* Scrub an inode's CoW fork. */
+2 −0
Original line number Diff line number Diff line
@@ -1160,6 +1160,7 @@ xchk_metadata_inode_subtype(
	unsigned int		scrub_type)
{
	__u32			smtype = sc->sm->sm_type;
	unsigned int		sick_mask = sc->sick_mask;
	int			error;

	sc->sm->sm_type = scrub_type;
@@ -1177,6 +1178,7 @@ xchk_metadata_inode_subtype(
		break;
	}

	sc->sick_mask = sick_mask;
	sc->sm->sm_type = smtype;
	return error;
}
+13 −3
Original line number Diff line number Diff line
@@ -15,10 +15,12 @@
#include "xfs_icache.h"
#include "xfs_dir2.h"
#include "xfs_dir2_priv.h"
#include "xfs_health.h"
#include "scrub/scrub.h"
#include "scrub/common.h"
#include "scrub/dabtree.h"
#include "scrub/readdir.h"
#include "scrub/health.h"

/* Set us up to scrub directories. */
int
@@ -760,6 +762,11 @@ xchk_directory(
	if (!S_ISDIR(VFS_I(sc->ip)->i_mode))
		return -ENOENT;

	if (xchk_file_looks_zapped(sc, XFS_SICK_INO_DIR_ZAPPED)) {
		xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
		return 0;
	}

	/* Plausible size? */
	if (sc->ip->i_disk_size < xfs_dir2_sf_hdr_size(0)) {
		xchk_ino_set_corrupt(sc, sc->ip->i_ino);
@@ -784,7 +791,10 @@ xchk_directory(

	/* Look up every name in this directory by hash. */
	error = xchk_dir_walk(sc, sc->ip, xchk_dir_actor, NULL);
	if (error == -ECANCELED)
		error = 0;
	if (error && error != -ECANCELED)
		return error;

	/* If the dir is clean, it is clearly not zapped. */
	xchk_mark_healthy_if_clean(sc, XFS_SICK_INO_DIR_ZAPPED);
	return 0;
}
+32 −0
Original line number Diff line number Diff line
@@ -117,6 +117,38 @@ xchk_health_mask_for_scrub_type(
	return type_to_health_flag[scrub_type].sick_mask;
}

/*
 * If the scrub state is clean, add @mask to the scrub sick mask to clear
 * additional sick flags from the metadata object's sick state.
 */
void
xchk_mark_healthy_if_clean(
	struct xfs_scrub	*sc,
	unsigned int		mask)
{
	if (!(sc->sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
				  XFS_SCRUB_OFLAG_XCORRUPT)))
		sc->sick_mask |= mask;
}

/*
 * If we're scrubbing a piece of file metadata for the first time, does it look
 * like it has been zapped?  Skip the check if we just repaired the metadata
 * and are revalidating it.
 */
bool
xchk_file_looks_zapped(
	struct xfs_scrub	*sc,
	unsigned int		mask)
{
	ASSERT((mask & ~XFS_SICK_INO_ZAPPED) == 0);

	if (sc->flags & XREP_ALREADY_FIXED)
		return false;

	return xfs_inode_has_sickness(sc->ip, mask);
}

/*
 * Update filesystem health assessments based on what we found and did.
 *
Loading