Skip to content

Commit 80e4e12

Browse files
committed
xfs: scrub inodes
Scrub the fields within an inode. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent edc09b5 commit 80e4e12

File tree

8 files changed

+693
-3
lines changed

8 files changed

+693
-3
lines changed

fs/xfs/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ xfs-y += $(addprefix scrub/, \
148148
btree.o \
149149
common.o \
150150
ialloc.o \
151+
inode.o \
151152
refcount.o \
152153
rmap.o \
153154
scrub.o \

fs/xfs/libxfs/xfs_fs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,10 @@ struct xfs_scrub_metadata {
494494
#define XFS_SCRUB_TYPE_FINOBT 8 /* free inode btree */
495495
#define XFS_SCRUB_TYPE_RMAPBT 9 /* reverse mapping btree */
496496
#define XFS_SCRUB_TYPE_REFCNTBT 10 /* reference count btree */
497+
#define XFS_SCRUB_TYPE_INODE 11 /* inode record */
497498

498499
/* Number of scrub subcommands. */
499-
#define XFS_SCRUB_TYPE_NR 11
500+
#define XFS_SCRUB_TYPE_NR 12
500501

501502
/* i: Repair this metadata. */
502503
#define XFS_SCRUB_IFLAG_REPAIR (1 << 0)

fs/xfs/scrub/common.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "xfs_trans.h"
3131
#include "xfs_sb.h"
3232
#include "xfs_inode.h"
33+
#include "xfs_icache.h"
34+
#include "xfs_itable.h"
3335
#include "xfs_alloc.h"
3436
#include "xfs_alloc_btree.h"
3537
#include "xfs_bmap.h"
@@ -488,3 +490,55 @@ xfs_scrub_checkpoint_log(
488490
xfs_ail_push_all_sync(mp->m_ail);
489491
return 0;
490492
}
493+
494+
/*
495+
* Given an inode and the scrub control structure, grab either the
496+
* inode referenced in the control structure or the inode passed in.
497+
* The inode is not locked.
498+
*/
499+
int
500+
xfs_scrub_get_inode(
501+
struct xfs_scrub_context *sc,
502+
struct xfs_inode *ip_in)
503+
{
504+
struct xfs_mount *mp = sc->mp;
505+
struct xfs_inode *ip = NULL;
506+
int error;
507+
508+
/*
509+
* If userspace passed us an AG number or a generation number
510+
* without an inode number, they haven't got a clue so bail out
511+
* immediately.
512+
*/
513+
if (sc->sm->sm_agno || (sc->sm->sm_gen && !sc->sm->sm_ino))
514+
return -EINVAL;
515+
516+
/* We want to scan the inode we already had opened. */
517+
if (sc->sm->sm_ino == 0 || sc->sm->sm_ino == ip_in->i_ino) {
518+
sc->ip = ip_in;
519+
return 0;
520+
}
521+
522+
/* Look up the inode, see if the generation number matches. */
523+
if (xfs_internal_inum(mp, sc->sm->sm_ino))
524+
return -ENOENT;
525+
error = xfs_iget(mp, NULL, sc->sm->sm_ino,
526+
XFS_IGET_UNTRUSTED | XFS_IGET_DONTCACHE, 0, &ip);
527+
if (error == -ENOENT || error == -EINVAL) {
528+
/* inode doesn't exist... */
529+
return -ENOENT;
530+
} else if (error) {
531+
trace_xfs_scrub_op_error(sc,
532+
XFS_INO_TO_AGNO(mp, sc->sm->sm_ino),
533+
XFS_INO_TO_AGBNO(mp, sc->sm->sm_ino),
534+
error, __return_address);
535+
return error;
536+
}
537+
if (VFS_I(ip)->i_generation != sc->sm->sm_gen) {
538+
iput(VFS_I(ip));
539+
return -ENOENT;
540+
}
541+
542+
sc->ip = ip;
543+
return 0;
544+
}

fs/xfs/scrub/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ int xfs_scrub_setup_ag_rmapbt(struct xfs_scrub_context *sc,
8787
struct xfs_inode *ip);
8888
int xfs_scrub_setup_ag_refcountbt(struct xfs_scrub_context *sc,
8989
struct xfs_inode *ip);
90+
int xfs_scrub_setup_inode(struct xfs_scrub_context *sc,
91+
struct xfs_inode *ip);
9092

9193

9294
void xfs_scrub_ag_free(struct xfs_scrub_context *sc, struct xfs_scrub_ag *sa);
@@ -105,5 +107,6 @@ int xfs_scrub_walk_agfl(struct xfs_scrub_context *sc,
105107

106108
int xfs_scrub_setup_ag_btree(struct xfs_scrub_context *sc,
107109
struct xfs_inode *ip, bool force_log);
110+
int xfs_scrub_get_inode(struct xfs_scrub_context *sc, struct xfs_inode *ip_in);
108111

109112
#endif /* __XFS_SCRUB_COMMON_H__ */

0 commit comments

Comments
 (0)