Skip to content

Commit a5c46e5

Browse files
committed
xfs: scrub directory metadata
Scrub the hash tree and all the entries in a directory. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent 7c4a07a commit a5c46e5

11 files changed

Lines changed: 393 additions & 4 deletions

File tree

‎fs/xfs/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ xfs-y += $(addprefix scrub/, \
149149
btree.o \
150150
common.o \
151151
dabtree.o \
152+
dir.o \
152153
ialloc.o \
153154
inode.o \
154155
refcount.o \

‎fs/xfs/libxfs/xfs_dir2.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR };
3939
/*
4040
* Convert inode mode to directory entry filetype
4141
*/
42-
unsigned char xfs_mode_to_ftype(int mode)
42+
unsigned char
43+
xfs_mode_to_ftype(
44+
int mode)
4345
{
4446
switch (mode & S_IFMT) {
4547
case S_IFREG:

‎fs/xfs/libxfs/xfs_dir2.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,21 @@ xfs_dir2_leaf_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_leaf *lp)
324324
sizeof(struct xfs_dir2_leaf_tail));
325325
}
326326

327+
/*
328+
* The Linux API doesn't pass down the total size of the buffer
329+
* we read into down to the filesystem. With the filldir concept
330+
* it's not needed for correct information, but the XFS dir2 leaf
331+
* code wants an estimate of the buffer size to calculate it's
332+
* readahead window and size the buffers used for mapping to
333+
* physical blocks.
334+
*
335+
* Try to give it an estimate that's good enough, maybe at some
336+
* point we can change the ->readdir prototype to include the
337+
* buffer size. For now we use the current glibc buffer size.
338+
* musl libc hardcodes 2k and dietlibc uses PAGE_SIZE.
339+
*/
340+
#define XFS_READDIR_BUFSIZE (32768)
341+
342+
unsigned char xfs_dir3_get_dtype(struct xfs_mount *mp, uint8_t filetype);
343+
327344
#endif /* __XFS_DIR2_H__ */

‎fs/xfs/libxfs/xfs_fs.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,10 @@ struct xfs_scrub_metadata {
498498
#define XFS_SCRUB_TYPE_BMBTD 12 /* data fork block mapping */
499499
#define XFS_SCRUB_TYPE_BMBTA 13 /* attr fork block mapping */
500500
#define XFS_SCRUB_TYPE_BMBTC 14 /* CoW fork block mapping */
501+
#define XFS_SCRUB_TYPE_DIR 15 /* directory */
501502

502503
/* Number of scrub subcommands. */
503-
#define XFS_SCRUB_TYPE_NR 15
504+
#define XFS_SCRUB_TYPE_NR 16
504505

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

‎fs/xfs/scrub/common.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,31 @@ xfs_scrub_get_inode(
542542
sc->ip = ip;
543543
return 0;
544544
}
545+
546+
/* Set us up to scrub a file's contents. */
547+
int
548+
xfs_scrub_setup_inode_contents(
549+
struct xfs_scrub_context *sc,
550+
struct xfs_inode *ip,
551+
unsigned int resblks)
552+
{
553+
struct xfs_mount *mp = sc->mp;
554+
int error;
555+
556+
error = xfs_scrub_get_inode(sc, ip);
557+
if (error)
558+
return error;
559+
560+
/* Got the inode, lock it and we're ready to go. */
561+
sc->ilock_flags = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
562+
xfs_ilock(sc->ip, sc->ilock_flags);
563+
error = xfs_scrub_trans_alloc(sc->sm, mp, &sc->tp);
564+
if (error)
565+
goto out;
566+
sc->ilock_flags |= XFS_ILOCK_EXCL;
567+
xfs_ilock(sc->ip, XFS_ILOCK_EXCL);
568+
569+
out:
570+
/* scrub teardown will unlock and release the inode for us */
571+
return error;
572+
}

‎fs/xfs/scrub/common.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ int xfs_scrub_setup_inode_bmap(struct xfs_scrub_context *sc,
9393
struct xfs_inode *ip);
9494
int xfs_scrub_setup_inode_bmap_data(struct xfs_scrub_context *sc,
9595
struct xfs_inode *ip);
96+
int xfs_scrub_setup_directory(struct xfs_scrub_context *sc,
97+
struct xfs_inode *ip);
9698

9799
void xfs_scrub_ag_free(struct xfs_scrub_context *sc, struct xfs_scrub_ag *sa);
98100
int xfs_scrub_ag_init(struct xfs_scrub_context *sc, xfs_agnumber_t agno,
@@ -111,5 +113,7 @@ int xfs_scrub_walk_agfl(struct xfs_scrub_context *sc,
111113
int xfs_scrub_setup_ag_btree(struct xfs_scrub_context *sc,
112114
struct xfs_inode *ip, bool force_log);
113115
int xfs_scrub_get_inode(struct xfs_scrub_context *sc, struct xfs_inode *ip_in);
116+
int xfs_scrub_setup_inode_contents(struct xfs_scrub_context *sc,
117+
struct xfs_inode *ip, unsigned int resblks);
114118

115119
#endif /* __XFS_SCRUB_COMMON_H__ */

0 commit comments

Comments
 (0)