mirror of
https://github.com/torvalds/linux.git
synced 2024-11-30 16:11:38 +00:00
xfs: online repair of inodes and forks [v28.3]
In this series, online repair gains the ability to repair inode records. To do this, we must repair the ondisk inode and fork information enough to pass the iget verifiers and hence make the inode igettable again. Once that's done, we can perform higher level repairs on the incore inode. The fstests counterpart of this patchset implements stress testing of repair. This has been running on the djcloud for months with no problems. Enjoy! Signed-off-by: Darrick J. Wong <djwong@kernel.org> -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZXzKAwAKCRBKO3ySh0YR ppnbAP9zh9hc4Lr+3EMMZMsFXNxScP8iV7kCmHoorgMhHI9z8AEApBxkILxLjbwC TJtoSmbnBhQWXR/my0MBPpLgD7v3ugk= =lwKw -----END PGP SIGNATURE----- Merge tag 'repair-inodes-6.8_2023-12-15' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.8-mergeB xfs: online repair of inodes and forks In this series, online repair gains the ability to repair inode records. To do this, we must repair the ondisk inode and fork information enough to pass the iget verifiers and hence make the inode igettable again. Once that's done, we can perform higher level repairs on the incore inode. The fstests counterpart of this patchset implements stress testing of repair. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org> * tag 'repair-inodes-6.8_2023-12-15' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux: xfs: skip the rmapbt search on an empty attr fork unless we know it was zapped xfs: abort directory parent scrub scans if we encounter a zapped directory xfs: zap broken inode forks xfs: repair inode records xfs: set inode sick state flags when we zap either ondisk fork xfs: dont cast to char * for XFS_DFORK_*PTR macros xfs: add missing nrext64 inode flag check to scrub xfs: try to attach dquots to files before repairing them xfs: disable online repair quota helpers when quota not enabled
This commit is contained in:
commit
7b63ce86f9
@ -184,6 +184,7 @@ xfs-y += $(addprefix scrub/, \
|
||||
agheader_repair.o \
|
||||
alloc_repair.o \
|
||||
ialloc_repair.o \
|
||||
inode_repair.o \
|
||||
newbt.o \
|
||||
reap.o \
|
||||
refcount_repair.o \
|
||||
|
@ -1040,23 +1040,16 @@ xfs_attr_shortform_allfit(
|
||||
return xfs_attr_shortform_bytesfit(dp, bytes);
|
||||
}
|
||||
|
||||
/* Verify the consistency of an inline attribute fork. */
|
||||
/* Verify the consistency of a raw inline attribute fork. */
|
||||
xfs_failaddr_t
|
||||
xfs_attr_shortform_verify(
|
||||
struct xfs_inode *ip)
|
||||
struct xfs_attr_shortform *sfp,
|
||||
size_t size)
|
||||
{
|
||||
struct xfs_attr_shortform *sfp;
|
||||
struct xfs_attr_sf_entry *sfep;
|
||||
struct xfs_attr_sf_entry *next_sfep;
|
||||
char *endp;
|
||||
struct xfs_ifork *ifp;
|
||||
int i;
|
||||
int64_t size;
|
||||
|
||||
ASSERT(ip->i_af.if_format == XFS_DINODE_FMT_LOCAL);
|
||||
ifp = xfs_ifork_ptr(ip, XFS_ATTR_FORK);
|
||||
sfp = (struct xfs_attr_shortform *)ifp->if_u1.if_data;
|
||||
size = ifp->if_bytes;
|
||||
|
||||
/*
|
||||
* Give up if the attribute is way too short.
|
||||
|
@ -56,7 +56,8 @@ int xfs_attr_sf_findname(struct xfs_da_args *args,
|
||||
unsigned int *basep);
|
||||
int xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
|
||||
int xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes);
|
||||
xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_inode *ip);
|
||||
xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_attr_shortform *sfp,
|
||||
size_t size);
|
||||
void xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp);
|
||||
|
||||
/*
|
||||
|
@ -6168,19 +6168,18 @@ xfs_bmap_finish_one(
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Check that an inode's extent does not have invalid flags or bad ranges. */
|
||||
/* Check that an extent does not have invalid flags or bad ranges. */
|
||||
xfs_failaddr_t
|
||||
xfs_bmap_validate_extent(
|
||||
struct xfs_inode *ip,
|
||||
xfs_bmap_validate_extent_raw(
|
||||
struct xfs_mount *mp,
|
||||
bool rtfile,
|
||||
int whichfork,
|
||||
struct xfs_bmbt_irec *irec)
|
||||
{
|
||||
struct xfs_mount *mp = ip->i_mount;
|
||||
|
||||
if (!xfs_verify_fileext(mp, irec->br_startoff, irec->br_blockcount))
|
||||
return __this_address;
|
||||
|
||||
if (XFS_IS_REALTIME_INODE(ip) && whichfork == XFS_DATA_FORK) {
|
||||
if (rtfile && whichfork == XFS_DATA_FORK) {
|
||||
if (!xfs_verify_rtbext(mp, irec->br_startblock,
|
||||
irec->br_blockcount))
|
||||
return __this_address;
|
||||
@ -6210,3 +6209,14 @@ xfs_bmap_intent_destroy_cache(void)
|
||||
kmem_cache_destroy(xfs_bmap_intent_cache);
|
||||
xfs_bmap_intent_cache = NULL;
|
||||
}
|
||||
|
||||
/* Check that an inode's extent does not have invalid flags or bad ranges. */
|
||||
xfs_failaddr_t
|
||||
xfs_bmap_validate_extent(
|
||||
struct xfs_inode *ip,
|
||||
int whichfork,
|
||||
struct xfs_bmbt_irec *irec)
|
||||
{
|
||||
return xfs_bmap_validate_extent_raw(ip->i_mount,
|
||||
XFS_IS_REALTIME_INODE(ip), whichfork, irec);
|
||||
}
|
||||
|
@ -263,6 +263,8 @@ static inline uint32_t xfs_bmap_fork_to_state(int whichfork)
|
||||
}
|
||||
}
|
||||
|
||||
xfs_failaddr_t xfs_bmap_validate_extent_raw(struct xfs_mount *mp, bool rtfile,
|
||||
int whichfork, struct xfs_bmbt_irec *irec);
|
||||
xfs_failaddr_t xfs_bmap_validate_extent(struct xfs_inode *ip, int whichfork,
|
||||
struct xfs_bmbt_irec *irec);
|
||||
int xfs_bmap_complain_bad_rec(struct xfs_inode *ip, int whichfork,
|
||||
|
@ -175,7 +175,8 @@ extern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino);
|
||||
extern int xfs_dir2_sf_lookup(struct xfs_da_args *args);
|
||||
extern int xfs_dir2_sf_removename(struct xfs_da_args *args);
|
||||
extern int xfs_dir2_sf_replace(struct xfs_da_args *args);
|
||||
extern xfs_failaddr_t xfs_dir2_sf_verify(struct xfs_inode *ip);
|
||||
xfs_failaddr_t xfs_dir2_sf_verify(struct xfs_mount *mp,
|
||||
struct xfs_dir2_sf_hdr *sfp, int64_t size);
|
||||
int xfs_dir2_sf_entsize(struct xfs_mount *mp,
|
||||
struct xfs_dir2_sf_hdr *hdr, int len);
|
||||
void xfs_dir2_sf_put_ino(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr,
|
||||
|
@ -707,11 +707,10 @@ xfs_dir2_sf_check(
|
||||
/* Verify the consistency of an inline directory. */
|
||||
xfs_failaddr_t
|
||||
xfs_dir2_sf_verify(
|
||||
struct xfs_inode *ip)
|
||||
struct xfs_mount *mp,
|
||||
struct xfs_dir2_sf_hdr *sfp,
|
||||
int64_t size)
|
||||
{
|
||||
struct xfs_mount *mp = ip->i_mount;
|
||||
struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK);
|
||||
struct xfs_dir2_sf_hdr *sfp;
|
||||
struct xfs_dir2_sf_entry *sfep;
|
||||
struct xfs_dir2_sf_entry *next_sfep;
|
||||
char *endp;
|
||||
@ -719,15 +718,9 @@ xfs_dir2_sf_verify(
|
||||
int i;
|
||||
int i8count;
|
||||
int offset;
|
||||
int64_t size;
|
||||
int error;
|
||||
uint8_t filetype;
|
||||
|
||||
ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL);
|
||||
|
||||
sfp = (struct xfs_dir2_sf_hdr *)ifp->if_u1.if_data;
|
||||
size = ifp->if_bytes;
|
||||
|
||||
/*
|
||||
* Give up if the directory is way too short.
|
||||
*/
|
||||
|
@ -1008,7 +1008,7 @@ enum xfs_dinode_fmt {
|
||||
* Return pointers to the data or attribute forks.
|
||||
*/
|
||||
#define XFS_DFORK_DPTR(dip) \
|
||||
((char *)dip + xfs_dinode_size(dip->di_version))
|
||||
((void *)dip + xfs_dinode_size(dip->di_version))
|
||||
#define XFS_DFORK_APTR(dip) \
|
||||
(XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip))
|
||||
#define XFS_DFORK_PTR(dip,w) \
|
||||
|
@ -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);
|
||||
|
@ -702,12 +702,22 @@ xfs_ifork_verify_local_data(
|
||||
xfs_failaddr_t fa = NULL;
|
||||
|
||||
switch (VFS_I(ip)->i_mode & S_IFMT) {
|
||||
case S_IFDIR:
|
||||
fa = xfs_dir2_sf_verify(ip);
|
||||
case S_IFDIR: {
|
||||
struct xfs_mount *mp = ip->i_mount;
|
||||
struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK);
|
||||
struct xfs_dir2_sf_hdr *sfp;
|
||||
|
||||
sfp = (struct xfs_dir2_sf_hdr *)ifp->if_u1.if_data;
|
||||
fa = xfs_dir2_sf_verify(mp, sfp, ifp->if_bytes);
|
||||
break;
|
||||
case S_IFLNK:
|
||||
fa = xfs_symlink_shortform_verify(ip);
|
||||
}
|
||||
case S_IFLNK: {
|
||||
struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK);
|
||||
|
||||
fa = xfs_symlink_shortform_verify(ifp->if_u1.if_data,
|
||||
ifp->if_bytes);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -729,11 +739,20 @@ xfs_ifork_verify_local_attr(
|
||||
struct xfs_ifork *ifp = &ip->i_af;
|
||||
xfs_failaddr_t fa;
|
||||
|
||||
if (!xfs_inode_has_attr_fork(ip))
|
||||
if (!xfs_inode_has_attr_fork(ip)) {
|
||||
fa = __this_address;
|
||||
else
|
||||
fa = xfs_attr_shortform_verify(ip);
|
||||
} else {
|
||||
struct xfs_attr_shortform *sfp;
|
||||
struct xfs_ifork *ifp;
|
||||
int64_t size;
|
||||
|
||||
ASSERT(ip->i_af.if_format == XFS_DINODE_FMT_LOCAL);
|
||||
ifp = xfs_ifork_ptr(ip, XFS_ATTR_FORK);
|
||||
sfp = (struct xfs_attr_shortform *)ifp->if_u1.if_data;
|
||||
size = ifp->if_bytes;
|
||||
|
||||
fa = xfs_attr_shortform_verify(sfp, size);
|
||||
}
|
||||
if (fa) {
|
||||
xfs_inode_verifier_error(ip, -EFSCORRUPTED, "attr fork",
|
||||
ifp->if_u1.if_data, ifp->if_bytes, fa);
|
||||
|
@ -139,7 +139,7 @@ bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset,
|
||||
uint32_t size, struct xfs_buf *bp);
|
||||
void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp,
|
||||
struct xfs_inode *ip, struct xfs_ifork *ifp);
|
||||
xfs_failaddr_t xfs_symlink_shortform_verify(struct xfs_inode *ip);
|
||||
xfs_failaddr_t xfs_symlink_shortform_verify(void *sfp, int64_t size);
|
||||
|
||||
/* Computed inode geometry for the filesystem. */
|
||||
struct xfs_ino_geometry {
|
||||
|
@ -202,15 +202,11 @@ xfs_symlink_local_to_remote(
|
||||
*/
|
||||
xfs_failaddr_t
|
||||
xfs_symlink_shortform_verify(
|
||||
struct xfs_inode *ip)
|
||||
void *sfp,
|
||||
int64_t size)
|
||||
{
|
||||
struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK);
|
||||
char *sfp = (char *)ifp->if_u1.if_data;
|
||||
int size = ifp->if_bytes;
|
||||
char *endp = sfp + size;
|
||||
|
||||
ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL);
|
||||
|
||||
/*
|
||||
* Zero length symlinks should never occur in memory as they are
|
||||
* never allowed to exist on disk.
|
||||
|
@ -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. */
|
||||
@ -78,6 +80,10 @@ xchk_setup_inode_bmap(
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
error = xchk_ino_dqattach(sc);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
xchk_ilock(sc, XFS_ILOCK_EXCL);
|
||||
out:
|
||||
/* scrub teardown will unlock and release the inode */
|
||||
@ -632,6 +638,82 @@ xchk_bmap_check_ag_rmaps(
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decide if we want to scan the reverse mappings to determine if the attr
|
||||
* fork /really/ has zero space mappings.
|
||||
*/
|
||||
STATIC bool
|
||||
xchk_bmap_check_empty_attrfork(
|
||||
struct xfs_inode *ip)
|
||||
{
|
||||
struct xfs_ifork *ifp = &ip->i_af;
|
||||
|
||||
/*
|
||||
* If the dinode repair found a bad attr fork, it will reset the fork
|
||||
* to extents format with zero records and wait for the this scrubber
|
||||
* to reconstruct the block mappings. If the fork is not in this
|
||||
* state, then the fork cannot have been zapped.
|
||||
*/
|
||||
if (ifp->if_format != XFS_DINODE_FMT_EXTENTS || ifp->if_nextents != 0)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Files can have an attr fork in EXTENTS format with zero records for
|
||||
* several reasons:
|
||||
*
|
||||
* a) an attr set created a fork but ran out of space
|
||||
* b) attr replace deleted an old attr but failed during the set step
|
||||
* c) the data fork was in btree format when all attrs were deleted, so
|
||||
* the fork was left in place
|
||||
* d) the inode repair code zapped the fork
|
||||
*
|
||||
* Only in case (d) do we want to scan the rmapbt to see if we need to
|
||||
* rebuild the attr fork. The fork zap code clears all DAC permission
|
||||
* bits and zeroes the uid and gid, so avoid the scan if any of those
|
||||
* three conditions are not met.
|
||||
*/
|
||||
if ((VFS_I(ip)->i_mode & 0777) != 0)
|
||||
return false;
|
||||
if (!uid_eq(VFS_I(ip)->i_uid, GLOBAL_ROOT_UID))
|
||||
return false;
|
||||
if (!gid_eq(VFS_I(ip)->i_gid, GLOBAL_ROOT_GID))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decide if we want to scan the reverse mappings to determine if the data
|
||||
* fork /really/ has zero space mappings.
|
||||
*/
|
||||
STATIC bool
|
||||
xchk_bmap_check_empty_datafork(
|
||||
struct xfs_inode *ip)
|
||||
{
|
||||
struct xfs_ifork *ifp = &ip->i_df;
|
||||
|
||||
/* Don't support realtime rmap checks yet. */
|
||||
if (XFS_IS_REALTIME_INODE(ip))
|
||||
return false;
|
||||
|
||||
/*
|
||||
* If the dinode repair found a bad data fork, it will reset the fork
|
||||
* to extents format with zero records and wait for the this scrubber
|
||||
* to reconstruct the block mappings. If the fork is not in this
|
||||
* state, then the fork cannot have been zapped.
|
||||
*/
|
||||
if (ifp->if_format != XFS_DINODE_FMT_EXTENTS || ifp->if_nextents != 0)
|
||||
return false;
|
||||
|
||||
/*
|
||||
* If we encounter an empty data fork along with evidence that the fork
|
||||
* might not really be empty, we need to scan the reverse mappings to
|
||||
* decide if we're going to rebuild the fork. Data forks with nonzero
|
||||
* file size are scanned.
|
||||
*/
|
||||
return i_size_read(VFS_I(ip)) != 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decide if we want to walk every rmap btree in the fs to make sure that each
|
||||
* rmap for this file fork has corresponding bmbt entries.
|
||||
@ -641,7 +723,6 @@ xchk_bmap_want_check_rmaps(
|
||||
struct xchk_bmap_info *info)
|
||||
{
|
||||
struct xfs_scrub *sc = info->sc;
|
||||
struct xfs_ifork *ifp;
|
||||
|
||||
if (!xfs_has_rmapbt(sc->mp))
|
||||
return false;
|
||||
@ -650,28 +731,10 @@ xchk_bmap_want_check_rmaps(
|
||||
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
||||
return false;
|
||||
|
||||
/* Don't support realtime rmap checks yet. */
|
||||
if (info->is_rt)
|
||||
return false;
|
||||
if (info->whichfork == XFS_ATTR_FORK)
|
||||
return xchk_bmap_check_empty_attrfork(sc->ip);
|
||||
|
||||
/*
|
||||
* The inode repair code zaps broken inode forks by resetting them back
|
||||
* to EXTENTS format and zero extent records. If we encounter a fork
|
||||
* in this state along with evidence that the fork isn't supposed to be
|
||||
* empty, we need to scan the reverse mappings to decide if we're going
|
||||
* to rebuild the fork. Data forks with nonzero file size are scanned.
|
||||
* xattr forks are never empty of content, so they are always scanned.
|
||||
*/
|
||||
ifp = xfs_ifork_ptr(sc->ip, info->whichfork);
|
||||
if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && ifp->if_nextents == 0) {
|
||||
if (info->whichfork == XFS_DATA_FORK &&
|
||||
i_size_read(VFS_I(sc->ip)) == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return xchk_bmap_check_empty_datafork(sc->ip);
|
||||
}
|
||||
|
||||
/* Make sure each rmap has a corresponding bmbt entry. */
|
||||
@ -939,7 +1002,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. */
|
||||
@ -947,7 +1023,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. */
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "xfs_trans_priv.h"
|
||||
#include "xfs_da_format.h"
|
||||
#include "xfs_da_btree.h"
|
||||
#include "xfs_dir2_priv.h"
|
||||
#include "xfs_attr.h"
|
||||
#include "xfs_reflink.h"
|
||||
#include "xfs_ag.h"
|
||||
@ -819,6 +820,26 @@ again:
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_XFS_QUOTA
|
||||
/*
|
||||
* Try to attach dquots to this inode if we think we might want to repair it.
|
||||
* Callers must not hold any ILOCKs. If the dquots are broken and cannot be
|
||||
* attached, a quotacheck will be scheduled.
|
||||
*/
|
||||
int
|
||||
xchk_ino_dqattach(
|
||||
struct xfs_scrub *sc)
|
||||
{
|
||||
ASSERT(sc->tp != NULL);
|
||||
ASSERT(sc->ip != NULL);
|
||||
|
||||
if (!xchk_could_repair(sc))
|
||||
return 0;
|
||||
|
||||
return xrep_ino_dqattach(sc);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Install an inode that we opened by handle for scrubbing. */
|
||||
int
|
||||
xchk_install_handle_inode(
|
||||
@ -1030,6 +1051,11 @@ xchk_setup_inode_contents(
|
||||
error = xchk_trans_alloc(sc, resblks);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
error = xchk_ino_dqattach(sc);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
xchk_ilock(sc, XFS_ILOCK_EXCL);
|
||||
out:
|
||||
/* scrub teardown will unlock and release the inode for us */
|
||||
@ -1135,6 +1161,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;
|
||||
@ -1152,6 +1179,7 @@ xchk_metadata_inode_subtype(
|
||||
break;
|
||||
}
|
||||
|
||||
sc->sick_mask = sick_mask;
|
||||
sc->sm->sm_type = smtype;
|
||||
return error;
|
||||
}
|
||||
|
@ -103,9 +103,15 @@ xchk_setup_rtsummary(struct xfs_scrub *sc)
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_XFS_QUOTA
|
||||
int xchk_ino_dqattach(struct xfs_scrub *sc);
|
||||
int xchk_setup_quota(struct xfs_scrub *sc);
|
||||
#else
|
||||
static inline int
|
||||
xchk_ino_dqattach(struct xfs_scrub *sc)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static inline int
|
||||
xchk_setup_quota(struct xfs_scrub *sc)
|
||||
{
|
||||
return -ENOENT;
|
||||
@ -192,6 +198,8 @@ static inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm)
|
||||
XFS_SCRUB_OFLAG_XCORRUPT);
|
||||
}
|
||||
|
||||
bool xchk_dir_looks_zapped(struct xfs_inode *dp);
|
||||
|
||||
#ifdef CONFIG_XFS_ONLINE_REPAIR
|
||||
/* Decide if a repair is required. */
|
||||
static inline bool xchk_needs_repair(const struct xfs_scrub_metadata *sm)
|
||||
|
@ -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,36 @@ 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;
|
||||
return error;
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* Decide if this directory has been zapped to satisfy the inode and ifork
|
||||
* verifiers. Checking and repairing should be postponed until the directory
|
||||
* is fixed.
|
||||
*/
|
||||
bool
|
||||
xchk_dir_looks_zapped(
|
||||
struct xfs_inode *dp)
|
||||
{
|
||||
/* Repair zapped this dir's data fork a short time ago */
|
||||
if (xfs_ifork_zapped(dp, XFS_DATA_FORK))
|
||||
return true;
|
||||
|
||||
/*
|
||||
* If the dinode repair found a bad data fork, it will reset the fork
|
||||
* to extents format with zero records and wait for the bmapbtd
|
||||
* scrubber to reconstruct the block mappings. Directories always
|
||||
* contain some content, so this is a clear sign of a zapped directory.
|
||||
* The state checked by xfs_ifork_zapped is not persisted, so this is
|
||||
* the secondary strategy if repairs are interrupted by a crash or an
|
||||
* unmount.
|
||||
*/
|
||||
return dp->i_df.if_format == XFS_DINODE_FMT_EXTENTS &&
|
||||
dp->i_df.if_nextents == 0;
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -10,5 +10,7 @@ unsigned int xchk_health_mask_for_scrub_type(__u32 scrub_type);
|
||||
void xchk_update_health(struct xfs_scrub *sc);
|
||||
bool xchk_ag_btree_healthy_enough(struct xfs_scrub *sc, struct xfs_perag *pag,
|
||||
xfs_btnum_t btnum);
|
||||
void xchk_mark_healthy_if_clean(struct xfs_scrub *sc, unsigned int mask);
|
||||
bool xchk_file_looks_zapped(struct xfs_scrub *sc, unsigned int mask);
|
||||
|
||||
#endif /* __XFS_SCRUB_HEALTH_H__ */
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "scrub/common.h"
|
||||
#include "scrub/btree.h"
|
||||
#include "scrub/trace.h"
|
||||
#include "scrub/repair.h"
|
||||
|
||||
/* Prepare the attached inode for scrubbing. */
|
||||
static inline int
|
||||
@ -39,6 +40,10 @@ xchk_prepare_iscrub(
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
error = xchk_ino_dqattach(sc);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
xchk_ilock(sc, XFS_ILOCK_EXCL);
|
||||
return 0;
|
||||
}
|
||||
@ -181,8 +186,11 @@ xchk_setup_inode(
|
||||
* saying the inode is allocated and the icache being unable to load
|
||||
* the inode until we can flag the corruption in xchk_inode. The
|
||||
* scrub function has to note the corruption, since we're not really
|
||||
* supposed to do that from the setup function.
|
||||
* supposed to do that from the setup function. Save the mapping to
|
||||
* make repairs to the ondisk inode buffer.
|
||||
*/
|
||||
if (xchk_could_repair(sc))
|
||||
xrep_setup_inode(sc, &imap);
|
||||
return 0;
|
||||
|
||||
out_cancel:
|
||||
@ -338,6 +346,10 @@ xchk_inode_flags2(
|
||||
if (xfs_dinode_has_bigtime(dip) && !xfs_has_bigtime(mp))
|
||||
goto bad;
|
||||
|
||||
/* no large extent counts without the filesystem feature */
|
||||
if ((flags2 & XFS_DIFLAG2_NREXT64) && !xfs_has_large_extent_counts(mp))
|
||||
goto bad;
|
||||
|
||||
return;
|
||||
bad:
|
||||
xchk_ino_set_corrupt(sc, ino);
|
||||
@ -548,7 +560,7 @@ xchk_dinode(
|
||||
}
|
||||
|
||||
/* di_forkoff */
|
||||
if (XFS_DFORK_APTR(dip) >= (char *)dip + mp->m_sb.sb_inodesize)
|
||||
if (XFS_DFORK_BOFF(dip) >= mp->m_sb.sb_inodesize)
|
||||
xchk_ino_set_corrupt(sc, ino);
|
||||
if (naextents != 0 && dip->di_forkoff == 0)
|
||||
xchk_ino_set_corrupt(sc, ino);
|
||||
|
1525
fs/xfs/scrub/inode_repair.c
Normal file
1525
fs/xfs/scrub/inode_repair.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -156,6 +156,16 @@ xchk_parent_validate(
|
||||
goto out_rele;
|
||||
}
|
||||
|
||||
/*
|
||||
* We cannot yet validate this parent pointer if the directory looks as
|
||||
* though it has been zapped by the inode record repair code.
|
||||
*/
|
||||
if (xchk_dir_looks_zapped(dp)) {
|
||||
error = -EBUSY;
|
||||
xchk_set_incomplete(sc);
|
||||
goto out_unlock;
|
||||
}
|
||||
|
||||
/* Look for a directory entry in the parent pointing to the child. */
|
||||
error = xchk_dir_walk(sc, dp, xchk_parent_actor, &spc);
|
||||
if (!xchk_fblock_xref_process_error(sc, XFS_DATA_FORK, 0, &error))
|
||||
@ -217,6 +227,13 @@ xchk_parent(
|
||||
*/
|
||||
error = xchk_parent_validate(sc, parent_ino);
|
||||
} while (error == -EAGAIN);
|
||||
if (error == -EBUSY) {
|
||||
/*
|
||||
* We could not scan a directory, so we marked the check
|
||||
* incomplete. No further error return is necessary.
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
@ -176,6 +176,16 @@ xrep_roll_ag_trans(
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Roll the scrub transaction, holding the primary metadata locked. */
|
||||
int
|
||||
xrep_roll_trans(
|
||||
struct xfs_scrub *sc)
|
||||
{
|
||||
if (!sc->ip)
|
||||
return xrep_roll_ag_trans(sc);
|
||||
return xfs_trans_roll_inode(&sc->tp, sc->ip);
|
||||
}
|
||||
|
||||
/* Finish all deferred work attached to the repair transaction. */
|
||||
int
|
||||
xrep_defer_finish(
|
||||
@ -673,6 +683,7 @@ xrep_find_ag_btree_roots(
|
||||
return error;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_XFS_QUOTA
|
||||
/* Force a quotacheck the next time we mount. */
|
||||
void
|
||||
xrep_force_quotacheck(
|
||||
@ -699,10 +710,10 @@ xrep_force_quotacheck(
|
||||
*
|
||||
* This function ensures that the appropriate dquots are attached to an inode.
|
||||
* We cannot allow the dquot code to allocate an on-disk dquot block here
|
||||
* because we're already in transaction context with the inode locked. The
|
||||
* on-disk dquot should already exist anyway. If the quota code signals
|
||||
* corruption or missing quota information, schedule quotacheck, which will
|
||||
* repair corruptions in the quota metadata.
|
||||
* because we're already in transaction context. The on-disk dquot should
|
||||
* already exist anyway. If the quota code signals corruption or missing quota
|
||||
* information, schedule quotacheck, which will repair corruptions in the quota
|
||||
* metadata.
|
||||
*/
|
||||
int
|
||||
xrep_ino_dqattach(
|
||||
@ -710,7 +721,10 @@ xrep_ino_dqattach(
|
||||
{
|
||||
int error;
|
||||
|
||||
error = xfs_qm_dqattach_locked(sc->ip, false);
|
||||
ASSERT(sc->tp != NULL);
|
||||
ASSERT(sc->ip != NULL);
|
||||
|
||||
error = xfs_qm_dqattach(sc->ip);
|
||||
switch (error) {
|
||||
case -EFSBADCRC:
|
||||
case -EFSCORRUPTED:
|
||||
@ -734,6 +748,39 @@ xrep_ino_dqattach(
|
||||
|
||||
return error;
|
||||
}
|
||||
#endif /* CONFIG_XFS_QUOTA */
|
||||
|
||||
/*
|
||||
* Ensure that the inode being repaired is ready to handle a certain number of
|
||||
* extents, or return EFSCORRUPTED. Caller must hold the ILOCK of the inode
|
||||
* being repaired and have joined it to the scrub transaction.
|
||||
*/
|
||||
int
|
||||
xrep_ino_ensure_extent_count(
|
||||
struct xfs_scrub *sc,
|
||||
int whichfork,
|
||||
xfs_extnum_t nextents)
|
||||
{
|
||||
xfs_extnum_t max_extents;
|
||||
bool inode_has_nrext64;
|
||||
|
||||
inode_has_nrext64 = xfs_inode_has_large_extent_counts(sc->ip);
|
||||
max_extents = xfs_iext_max_nextents(inode_has_nrext64, whichfork);
|
||||
if (nextents <= max_extents)
|
||||
return 0;
|
||||
if (inode_has_nrext64)
|
||||
return -EFSCORRUPTED;
|
||||
if (!xfs_has_large_extent_counts(sc->mp))
|
||||
return -EFSCORRUPTED;
|
||||
|
||||
max_extents = xfs_iext_max_nextents(true, whichfork);
|
||||
if (nextents > max_extents)
|
||||
return -EFSCORRUPTED;
|
||||
|
||||
sc->ip->i_diflags2 |= XFS_DIFLAG2_NREXT64;
|
||||
xfs_trans_log_inode(sc->tp, sc->ip, XFS_ILOG_CORE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize all the btree cursors for an AG repair except for the btree that
|
||||
|
@ -30,11 +30,22 @@ static inline int xrep_notsupported(struct xfs_scrub *sc)
|
||||
int xrep_attempt(struct xfs_scrub *sc, struct xchk_stats_run *run);
|
||||
void xrep_failure(struct xfs_mount *mp);
|
||||
int xrep_roll_ag_trans(struct xfs_scrub *sc);
|
||||
int xrep_roll_trans(struct xfs_scrub *sc);
|
||||
int xrep_defer_finish(struct xfs_scrub *sc);
|
||||
bool xrep_ag_has_space(struct xfs_perag *pag, xfs_extlen_t nr_blocks,
|
||||
enum xfs_ag_resv_type type);
|
||||
xfs_extlen_t xrep_calc_ag_resblks(struct xfs_scrub *sc);
|
||||
|
||||
static inline int
|
||||
xrep_trans_commit(
|
||||
struct xfs_scrub *sc)
|
||||
{
|
||||
int error = xfs_trans_commit(sc->tp);
|
||||
|
||||
sc->tp = NULL;
|
||||
return error;
|
||||
}
|
||||
|
||||
struct xbitmap;
|
||||
struct xagb_bitmap;
|
||||
|
||||
@ -57,13 +68,25 @@ struct xrep_find_ag_btree {
|
||||
|
||||
int xrep_find_ag_btree_roots(struct xfs_scrub *sc, struct xfs_buf *agf_bp,
|
||||
struct xrep_find_ag_btree *btree_info, struct xfs_buf *agfl_bp);
|
||||
|
||||
#ifdef CONFIG_XFS_QUOTA
|
||||
void xrep_force_quotacheck(struct xfs_scrub *sc, xfs_dqtype_t type);
|
||||
int xrep_ino_dqattach(struct xfs_scrub *sc);
|
||||
#else
|
||||
# define xrep_force_quotacheck(sc, type) ((void)0)
|
||||
# define xrep_ino_dqattach(sc) (0)
|
||||
#endif /* CONFIG_XFS_QUOTA */
|
||||
|
||||
int xrep_ino_ensure_extent_count(struct xfs_scrub *sc, int whichfork,
|
||||
xfs_extnum_t nextents);
|
||||
int xrep_reset_perag_resv(struct xfs_scrub *sc);
|
||||
|
||||
/* Repair setup functions */
|
||||
int xrep_setup_ag_allocbt(struct xfs_scrub *sc);
|
||||
|
||||
struct xfs_imap;
|
||||
int xrep_setup_inode(struct xfs_scrub *sc, const struct xfs_imap *imap);
|
||||
|
||||
void xrep_ag_btcur_init(struct xfs_scrub *sc, struct xchk_ag *sa);
|
||||
|
||||
/* Metadata revalidators */
|
||||
@ -81,12 +104,15 @@ int xrep_agi(struct xfs_scrub *sc);
|
||||
int xrep_allocbt(struct xfs_scrub *sc);
|
||||
int xrep_iallocbt(struct xfs_scrub *sc);
|
||||
int xrep_refcountbt(struct xfs_scrub *sc);
|
||||
int xrep_inode(struct xfs_scrub *sc);
|
||||
|
||||
int xrep_reinit_pagf(struct xfs_scrub *sc);
|
||||
int xrep_reinit_pagi(struct xfs_scrub *sc);
|
||||
|
||||
#else
|
||||
|
||||
#define xrep_ino_dqattach(sc) (0)
|
||||
|
||||
static inline int
|
||||
xrep_attempt(
|
||||
struct xfs_scrub *sc,
|
||||
@ -124,6 +150,8 @@ xrep_setup_nothing(
|
||||
}
|
||||
#define xrep_setup_ag_allocbt xrep_setup_nothing
|
||||
|
||||
#define xrep_setup_inode(sc, imap) ((void)0)
|
||||
|
||||
#define xrep_revalidate_allocbt (NULL)
|
||||
#define xrep_revalidate_iallocbt (NULL)
|
||||
|
||||
@ -135,6 +163,7 @@ xrep_setup_nothing(
|
||||
#define xrep_allocbt xrep_notsupported
|
||||
#define xrep_iallocbt xrep_notsupported
|
||||
#define xrep_refcountbt xrep_notsupported
|
||||
#define xrep_inode xrep_notsupported
|
||||
|
||||
#endif /* CONFIG_XFS_ONLINE_REPAIR */
|
||||
|
||||
|
@ -32,6 +32,10 @@ xchk_setup_rtbitmap(
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
error = xchk_ino_dqattach(sc);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
xchk_ilock(sc, XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP);
|
||||
return 0;
|
||||
}
|
||||
|
@ -63,6 +63,10 @@ xchk_setup_rtsummary(
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
error = xchk_ino_dqattach(sc);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
/*
|
||||
* Locking order requires us to take the rtbitmap first. We must be
|
||||
* careful to unlock it ourselves when we are done with the rtbitmap
|
||||
|
@ -282,7 +282,7 @@ static const struct xchk_meta_ops meta_scrub_ops[] = {
|
||||
.type = ST_INODE,
|
||||
.setup = xchk_setup_inode,
|
||||
.scrub = xchk_inode,
|
||||
.repair = xrep_notsupported,
|
||||
.repair = xrep_inode,
|
||||
},
|
||||
[XFS_SCRUB_TYPE_BMBTD] = { /* inode data fork */
|
||||
.type = ST_INODE,
|
||||
|
@ -12,8 +12,10 @@
|
||||
#include "xfs_log_format.h"
|
||||
#include "xfs_inode.h"
|
||||
#include "xfs_symlink.h"
|
||||
#include "xfs_health.h"
|
||||
#include "scrub/scrub.h"
|
||||
#include "scrub/common.h"
|
||||
#include "scrub/health.h"
|
||||
|
||||
/* Set us up to scrub a symbolic link. */
|
||||
int
|
||||
@ -41,13 +43,19 @@ xchk_symlink(
|
||||
|
||||
if (!S_ISLNK(VFS_I(ip)->i_mode))
|
||||
return -ENOENT;
|
||||
|
||||
if (xchk_file_looks_zapped(sc, XFS_SICK_INO_SYMLINK_ZAPPED)) {
|
||||
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK);
|
||||
len = ip->i_disk_size;
|
||||
|
||||
/* Plausible size? */
|
||||
if (len > XFS_SYMLINK_MAXLEN || len <= 0) {
|
||||
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
|
||||
goto out;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Inline symlink? */
|
||||
@ -55,15 +63,17 @@ xchk_symlink(
|
||||
if (len > xfs_inode_data_fork_size(ip) ||
|
||||
len > strnlen(ifp->if_u1.if_data, xfs_inode_data_fork_size(ip)))
|
||||
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
|
||||
goto out;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Remote symlink; must read the contents. */
|
||||
error = xfs_readlink_bmap_ilocked(sc->ip, sc->buf);
|
||||
if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, 0, &error))
|
||||
goto out;
|
||||
return error;
|
||||
if (strnlen(sc->buf, XFS_SYMLINK_MAXLEN) < len)
|
||||
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
|
||||
out:
|
||||
return error;
|
||||
|
||||
/* If a remote symlink is clean, it is clearly not zapped. */
|
||||
xchk_mark_healthy_if_clean(sc, XFS_SICK_INO_SYMLINK_ZAPPED);
|
||||
return 0;
|
||||
}
|
||||
|
@ -1393,6 +1393,177 @@ DEFINE_NEWBT_EXTENT_EVENT(xrep_newbt_alloc_file_blocks);
|
||||
DEFINE_NEWBT_EXTENT_EVENT(xrep_newbt_free_blocks);
|
||||
DEFINE_NEWBT_EXTENT_EVENT(xrep_newbt_claim_block);
|
||||
|
||||
DECLARE_EVENT_CLASS(xrep_dinode_class,
|
||||
TP_PROTO(struct xfs_scrub *sc, struct xfs_dinode *dip),
|
||||
TP_ARGS(sc, dip),
|
||||
TP_STRUCT__entry(
|
||||
__field(dev_t, dev)
|
||||
__field(xfs_ino_t, ino)
|
||||
__field(uint16_t, mode)
|
||||
__field(uint8_t, version)
|
||||
__field(uint8_t, format)
|
||||
__field(uint32_t, uid)
|
||||
__field(uint32_t, gid)
|
||||
__field(uint64_t, size)
|
||||
__field(uint64_t, nblocks)
|
||||
__field(uint32_t, extsize)
|
||||
__field(uint32_t, nextents)
|
||||
__field(uint16_t, anextents)
|
||||
__field(uint8_t, forkoff)
|
||||
__field(uint8_t, aformat)
|
||||
__field(uint16_t, flags)
|
||||
__field(uint32_t, gen)
|
||||
__field(uint64_t, flags2)
|
||||
__field(uint32_t, cowextsize)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->dev = sc->mp->m_super->s_dev;
|
||||
__entry->ino = sc->sm->sm_ino;
|
||||
__entry->mode = be16_to_cpu(dip->di_mode);
|
||||
__entry->version = dip->di_version;
|
||||
__entry->format = dip->di_format;
|
||||
__entry->uid = be32_to_cpu(dip->di_uid);
|
||||
__entry->gid = be32_to_cpu(dip->di_gid);
|
||||
__entry->size = be64_to_cpu(dip->di_size);
|
||||
__entry->nblocks = be64_to_cpu(dip->di_nblocks);
|
||||
__entry->extsize = be32_to_cpu(dip->di_extsize);
|
||||
__entry->nextents = be32_to_cpu(dip->di_nextents);
|
||||
__entry->anextents = be16_to_cpu(dip->di_anextents);
|
||||
__entry->forkoff = dip->di_forkoff;
|
||||
__entry->aformat = dip->di_aformat;
|
||||
__entry->flags = be16_to_cpu(dip->di_flags);
|
||||
__entry->gen = be32_to_cpu(dip->di_gen);
|
||||
__entry->flags2 = be64_to_cpu(dip->di_flags2);
|
||||
__entry->cowextsize = be32_to_cpu(dip->di_cowextsize);
|
||||
),
|
||||
TP_printk("dev %d:%d ino 0x%llx mode 0x%x version %u format %u uid %u gid %u disize 0x%llx nblocks 0x%llx extsize %u nextents %u anextents %u forkoff 0x%x aformat %u flags 0x%x gen 0x%x flags2 0x%llx cowextsize %u",
|
||||
MAJOR(__entry->dev), MINOR(__entry->dev),
|
||||
__entry->ino,
|
||||
__entry->mode,
|
||||
__entry->version,
|
||||
__entry->format,
|
||||
__entry->uid,
|
||||
__entry->gid,
|
||||
__entry->size,
|
||||
__entry->nblocks,
|
||||
__entry->extsize,
|
||||
__entry->nextents,
|
||||
__entry->anextents,
|
||||
__entry->forkoff,
|
||||
__entry->aformat,
|
||||
__entry->flags,
|
||||
__entry->gen,
|
||||
__entry->flags2,
|
||||
__entry->cowextsize)
|
||||
)
|
||||
|
||||
#define DEFINE_REPAIR_DINODE_EVENT(name) \
|
||||
DEFINE_EVENT(xrep_dinode_class, name, \
|
||||
TP_PROTO(struct xfs_scrub *sc, struct xfs_dinode *dip), \
|
||||
TP_ARGS(sc, dip))
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_header);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_mode);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_flags);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_size);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_extsize_hints);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_zap_symlink);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_zap_dir);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_fixed);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_zap_forks);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_zap_dfork);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_zap_afork);
|
||||
DEFINE_REPAIR_DINODE_EVENT(xrep_dinode_ensure_forkoff);
|
||||
|
||||
DECLARE_EVENT_CLASS(xrep_inode_class,
|
||||
TP_PROTO(struct xfs_scrub *sc),
|
||||
TP_ARGS(sc),
|
||||
TP_STRUCT__entry(
|
||||
__field(dev_t, dev)
|
||||
__field(xfs_ino_t, ino)
|
||||
__field(xfs_fsize_t, size)
|
||||
__field(xfs_rfsblock_t, nblocks)
|
||||
__field(uint16_t, flags)
|
||||
__field(uint64_t, flags2)
|
||||
__field(uint32_t, nextents)
|
||||
__field(uint8_t, format)
|
||||
__field(uint32_t, anextents)
|
||||
__field(uint8_t, aformat)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->dev = sc->mp->m_super->s_dev;
|
||||
__entry->ino = sc->sm->sm_ino;
|
||||
__entry->size = sc->ip->i_disk_size;
|
||||
__entry->nblocks = sc->ip->i_nblocks;
|
||||
__entry->flags = sc->ip->i_diflags;
|
||||
__entry->flags2 = sc->ip->i_diflags2;
|
||||
__entry->nextents = sc->ip->i_df.if_nextents;
|
||||
__entry->format = sc->ip->i_df.if_format;
|
||||
__entry->anextents = sc->ip->i_af.if_nextents;
|
||||
__entry->aformat = sc->ip->i_af.if_format;
|
||||
),
|
||||
TP_printk("dev %d:%d ino 0x%llx disize 0x%llx nblocks 0x%llx flags 0x%x flags2 0x%llx nextents %u format %u anextents %u aformat %u",
|
||||
MAJOR(__entry->dev), MINOR(__entry->dev),
|
||||
__entry->ino,
|
||||
__entry->size,
|
||||
__entry->nblocks,
|
||||
__entry->flags,
|
||||
__entry->flags2,
|
||||
__entry->nextents,
|
||||
__entry->format,
|
||||
__entry->anextents,
|
||||
__entry->aformat)
|
||||
)
|
||||
|
||||
#define DEFINE_REPAIR_INODE_EVENT(name) \
|
||||
DEFINE_EVENT(xrep_inode_class, name, \
|
||||
TP_PROTO(struct xfs_scrub *sc), \
|
||||
TP_ARGS(sc))
|
||||
DEFINE_REPAIR_INODE_EVENT(xrep_inode_blockcounts);
|
||||
DEFINE_REPAIR_INODE_EVENT(xrep_inode_ids);
|
||||
DEFINE_REPAIR_INODE_EVENT(xrep_inode_flags);
|
||||
DEFINE_REPAIR_INODE_EVENT(xrep_inode_blockdir_size);
|
||||
DEFINE_REPAIR_INODE_EVENT(xrep_inode_sfdir_size);
|
||||
DEFINE_REPAIR_INODE_EVENT(xrep_inode_dir_size);
|
||||
DEFINE_REPAIR_INODE_EVENT(xrep_inode_fixed);
|
||||
|
||||
TRACE_EVENT(xrep_dinode_count_rmaps,
|
||||
TP_PROTO(struct xfs_scrub *sc, xfs_rfsblock_t data_blocks,
|
||||
xfs_rfsblock_t rt_blocks, xfs_rfsblock_t attr_blocks,
|
||||
xfs_extnum_t data_extents, xfs_extnum_t rt_extents,
|
||||
xfs_aextnum_t attr_extents),
|
||||
TP_ARGS(sc, data_blocks, rt_blocks, attr_blocks, data_extents,
|
||||
rt_extents, attr_extents),
|
||||
TP_STRUCT__entry(
|
||||
__field(dev_t, dev)
|
||||
__field(xfs_ino_t, ino)
|
||||
__field(xfs_rfsblock_t, data_blocks)
|
||||
__field(xfs_rfsblock_t, rt_blocks)
|
||||
__field(xfs_rfsblock_t, attr_blocks)
|
||||
__field(xfs_extnum_t, data_extents)
|
||||
__field(xfs_extnum_t, rt_extents)
|
||||
__field(xfs_aextnum_t, attr_extents)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->dev = sc->mp->m_super->s_dev;
|
||||
__entry->ino = sc->sm->sm_ino;
|
||||
__entry->data_blocks = data_blocks;
|
||||
__entry->rt_blocks = rt_blocks;
|
||||
__entry->attr_blocks = attr_blocks;
|
||||
__entry->data_extents = data_extents;
|
||||
__entry->rt_extents = rt_extents;
|
||||
__entry->attr_extents = attr_extents;
|
||||
),
|
||||
TP_printk("dev %d:%d ino 0x%llx dblocks 0x%llx rtblocks 0x%llx ablocks 0x%llx dextents %llu rtextents %llu aextents %u",
|
||||
MAJOR(__entry->dev), MINOR(__entry->dev),
|
||||
__entry->ino,
|
||||
__entry->data_blocks,
|
||||
__entry->rt_blocks,
|
||||
__entry->attr_blocks,
|
||||
__entry->data_extents,
|
||||
__entry->rt_extents,
|
||||
__entry->attr_extents)
|
||||
);
|
||||
|
||||
#endif /* IS_ENABLED(CONFIG_XFS_ONLINE_REPAIR) */
|
||||
|
||||
#endif /* _TRACE_XFS_SCRUB_TRACE_H */
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "xfs_bmap.h"
|
||||
#include "xfs_trans.h"
|
||||
#include "xfs_error.h"
|
||||
#include "xfs_health.h"
|
||||
|
||||
/*
|
||||
* Directory file type support functions
|
||||
@ -519,6 +520,8 @@ xfs_readdir(
|
||||
|
||||
if (xfs_is_shutdown(dp->i_mount))
|
||||
return -EIO;
|
||||
if (xfs_ifork_zapped(dp, XFS_DATA_FORK))
|
||||
return -EIO;
|
||||
|
||||
ASSERT(S_ISDIR(VFS_I(dp)->i_mode));
|
||||
ASSERT(xfs_isilocked(dp, XFS_IOLOCK_SHARED | XFS_IOLOCK_EXCL));
|
||||
|
@ -222,7 +222,7 @@ xfs_inode_mark_sick(
|
||||
struct xfs_inode *ip,
|
||||
unsigned int mask)
|
||||
{
|
||||
ASSERT(!(mask & ~XFS_SICK_INO_PRIMARY));
|
||||
ASSERT(!(mask & ~(XFS_SICK_INO_PRIMARY | XFS_SICK_INO_ZAPPED)));
|
||||
trace_xfs_inode_mark_sick(ip, mask);
|
||||
|
||||
spin_lock(&ip->i_flags_lock);
|
||||
@ -246,7 +246,7 @@ xfs_inode_mark_healthy(
|
||||
struct xfs_inode *ip,
|
||||
unsigned int mask)
|
||||
{
|
||||
ASSERT(!(mask & ~XFS_SICK_INO_PRIMARY));
|
||||
ASSERT(!(mask & ~(XFS_SICK_INO_PRIMARY | XFS_SICK_INO_ZAPPED)));
|
||||
trace_xfs_inode_mark_healthy(ip, mask);
|
||||
|
||||
spin_lock(&ip->i_flags_lock);
|
||||
@ -369,6 +369,10 @@ static const struct ioctl_sick_map ino_map[] = {
|
||||
{ XFS_SICK_INO_XATTR, XFS_BS_SICK_XATTR },
|
||||
{ XFS_SICK_INO_SYMLINK, XFS_BS_SICK_SYMLINK },
|
||||
{ XFS_SICK_INO_PARENT, XFS_BS_SICK_PARENT },
|
||||
{ XFS_SICK_INO_BMBTD_ZAPPED, XFS_BS_SICK_BMBTD },
|
||||
{ XFS_SICK_INO_BMBTA_ZAPPED, XFS_BS_SICK_BMBTA },
|
||||
{ XFS_SICK_INO_DIR_ZAPPED, XFS_BS_SICK_DIR },
|
||||
{ XFS_SICK_INO_SYMLINK_ZAPPED, XFS_BS_SICK_SYMLINK },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "xfs_reflink.h"
|
||||
#include "xfs_ag.h"
|
||||
#include "xfs_log_priv.h"
|
||||
#include "xfs_health.h"
|
||||
|
||||
struct kmem_cache *xfs_inode_cache;
|
||||
|
||||
@ -661,6 +662,8 @@ xfs_lookup(
|
||||
|
||||
if (xfs_is_shutdown(dp->i_mount))
|
||||
return -EIO;
|
||||
if (xfs_ifork_zapped(dp, XFS_DATA_FORK))
|
||||
return -EIO;
|
||||
|
||||
error = xfs_dir_lookup(NULL, dp, name, &inum, ci_name);
|
||||
if (error)
|
||||
@ -978,6 +981,8 @@ xfs_create(
|
||||
|
||||
if (xfs_is_shutdown(mp))
|
||||
return -EIO;
|
||||
if (xfs_ifork_zapped(dp, XFS_DATA_FORK))
|
||||
return -EIO;
|
||||
|
||||
prid = xfs_get_initial_prid(dp);
|
||||
|
||||
@ -1217,6 +1222,8 @@ xfs_link(
|
||||
|
||||
if (xfs_is_shutdown(mp))
|
||||
return -EIO;
|
||||
if (xfs_ifork_zapped(tdp, XFS_DATA_FORK))
|
||||
return -EIO;
|
||||
|
||||
error = xfs_qm_dqattach(sip);
|
||||
if (error)
|
||||
@ -2506,6 +2513,8 @@ xfs_remove(
|
||||
|
||||
if (xfs_is_shutdown(mp))
|
||||
return -EIO;
|
||||
if (xfs_ifork_zapped(dp, XFS_DATA_FORK))
|
||||
return -EIO;
|
||||
|
||||
error = xfs_qm_dqattach(dp);
|
||||
if (error)
|
||||
@ -3758,3 +3767,29 @@ xfs_inode_reload_unlinked(
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Has this inode fork been zapped by repair? */
|
||||
bool
|
||||
xfs_ifork_zapped(
|
||||
const struct xfs_inode *ip,
|
||||
int whichfork)
|
||||
{
|
||||
unsigned int datamask = 0;
|
||||
|
||||
switch (whichfork) {
|
||||
case XFS_DATA_FORK:
|
||||
switch (ip->i_vnode.i_mode & S_IFMT) {
|
||||
case S_IFDIR:
|
||||
datamask = XFS_SICK_INO_DIR_ZAPPED;
|
||||
break;
|
||||
case S_IFLNK:
|
||||
datamask = XFS_SICK_INO_SYMLINK_ZAPPED;
|
||||
break;
|
||||
}
|
||||
return ip->i_sick & (XFS_SICK_INO_BMBTD_ZAPPED | datamask);
|
||||
case XFS_ATTR_FORK:
|
||||
return ip->i_sick & XFS_SICK_INO_BMBTA_ZAPPED;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -622,4 +622,6 @@ xfs_inode_unlinked_incomplete(
|
||||
int xfs_inode_reload_unlinked_bucket(struct xfs_trans *tp, struct xfs_inode *ip);
|
||||
int xfs_inode_reload_unlinked(struct xfs_inode *ip);
|
||||
|
||||
bool xfs_ifork_zapped(const struct xfs_inode *ip, int whichfork);
|
||||
|
||||
#endif /* __XFS_INODE_H__ */
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "xfs_trans.h"
|
||||
#include "xfs_ialloc.h"
|
||||
#include "xfs_error.h"
|
||||
#include "xfs_health.h"
|
||||
|
||||
/* ----- Kernel only functions below ----- */
|
||||
int
|
||||
@ -108,6 +109,8 @@ xfs_readlink(
|
||||
|
||||
if (xfs_is_shutdown(mp))
|
||||
return -EIO;
|
||||
if (xfs_ifork_zapped(ip, XFS_DATA_FORK))
|
||||
return -EIO;
|
||||
|
||||
xfs_ilock(ip, XFS_ILOCK_SHARED);
|
||||
|
||||
|
@ -136,6 +136,9 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused,
|
||||
};
|
||||
int error;
|
||||
|
||||
if (xfs_ifork_zapped(XFS_I(inode), XFS_ATTR_FORK))
|
||||
return -EIO;
|
||||
|
||||
error = xfs_attr_get(&args);
|
||||
if (error)
|
||||
return error;
|
||||
@ -294,6 +297,9 @@ xfs_vn_listxattr(
|
||||
struct inode *inode = d_inode(dentry);
|
||||
int error;
|
||||
|
||||
if (xfs_ifork_zapped(XFS_I(inode), XFS_ATTR_FORK))
|
||||
return -EIO;
|
||||
|
||||
/*
|
||||
* First read the regular on-disk attributes.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user