From 1804f4671b76293a8a792e5be4e514cefc0f012f Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Wed, 1 Sep 2021 11:25:04 -0700 Subject: xfs: experiment with dontcache when scanning inodes Add some experimental flags to drop inodes from the cache after a scan. Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_fs.h | 17 ++++++++++++++--- fs/xfs/scrub/common.c | 25 +++++++++++++++++++++---- fs/xfs/scrub/common.h | 3 +++ fs/xfs/scrub/dir.c | 2 +- fs/xfs/scrub/dir_repair.c | 4 ++-- fs/xfs/scrub/inode_repair.c | 3 +-- fs/xfs/scrub/iscan.c | 4 ++-- fs/xfs/scrub/parent.c | 2 +- fs/xfs/scrub/parent_repair.c | 6 +++--- fs/xfs/scrub/quotacheck.c | 2 +- fs/xfs/scrub/rmap_repair.c | 2 +- fs/xfs/scrub/rtrmap_repair.c | 2 +- fs/xfs/scrub/scrub.c | 11 +++++------ fs/xfs/scrub/trace.h | 3 ++- fs/xfs/xfs_ioctl.c | 3 +++ fs/xfs/xfs_itable.c | 8 +++++--- fs/xfs/xfs_itable.h | 3 +++ fs/xfs/xfs_iwalk.h | 6 +++++- 18 files changed, 74 insertions(+), 32 deletions(-) diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index 9a4bff3187b8..0b03f198442e 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -502,9 +502,13 @@ struct xfs_bulk_ireq { */ #define XFS_BULK_IREQ_METADIR (1 << 2) +/* Don't mark inodes DONTCACHE */ +#define XFS_BULK_IREQ_RETAIN_INODES (1 << 3) + #define XFS_BULK_IREQ_FLAGS_ALL (XFS_BULK_IREQ_AGNO | \ XFS_BULK_IREQ_SPECIAL | \ - XFS_BULK_IREQ_METADIR) + XFS_BULK_IREQ_METADIR | \ + XFS_BULK_IREQ_RETAIN_INODES) /* Operate on the root directory inode. */ #define XFS_BULK_IREQ_SPECIAL_ROOT (1) @@ -785,8 +789,12 @@ struct xfs_scrub_metadata { /* i: Allow scrub to freeze the filesystem to perform global scans. */ #define XFS_SCRUB_IFLAG_FREEZE_OK (1 << 8) +/* i: Don't mark inodes DONTCACHE at the end. */ +#define XFS_SCRUB_IFLAG_RETAIN_INODES (1 << 9) + #define XFS_SCRUB_FLAGS_IN (XFS_SCRUB_IFLAG_REPAIR | \ - XFS_SCRUB_IFLAG_FREEZE_OK) + XFS_SCRUB_IFLAG_FREEZE_OK | \ + XFS_SCRUB_IFLAG_RETAIN_INODES) #define XFS_SCRUB_FLAGS_OUT (XFS_SCRUB_OFLAG_CORRUPT | \ XFS_SCRUB_OFLAG_PREEN | \ XFS_SCRUB_OFLAG_XFAIL | \ @@ -815,7 +823,10 @@ struct xfs_scrub_vec_head { struct xfs_scrub_vec svh_vecs[0]; }; -#define XFS_SCRUB_VEC_FLAGS_ALL (0) +/* i: Don't mark inodes DONTCACHE at the end. */ +#define XFS_SCRUB_VEC_IFLAG_RETAIN_INODES (1 << 0) + +#define XFS_SCRUB_VEC_FLAGS_ALL (XFS_SCRUB_VEC_IFLAG_RETAIN_INODES) static inline size_t sizeof_xfs_scrub_vec(unsigned int nr) { diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c index 0055299170e2..0ea9b6b299ae 100644 --- a/fs/xfs/scrub/common.c +++ b/fs/xfs/scrub/common.c @@ -863,8 +863,7 @@ xchk_get_inode( /* Look up the inode, see if the generation number matches. */ if (xfs_internal_inum(mp, sc->sm->sm_ino)) return -ENOENT; - error = xfs_iget(mp, NULL, sc->sm->sm_ino, - XFS_IGET_UNTRUSTED | XFS_IGET_DONTCACHE, 0, &ip); + error = xfs_iget(mp, NULL, sc->sm->sm_ino, XFS_IGET_UNTRUSTED, 0, &ip); switch (error) { case -ENOENT: /* Inode doesn't exist, just bail out. */ @@ -886,7 +885,7 @@ xchk_get_inode( * that it no longer exists. */ error = xfs_imap(sc->mp, sc->tp, sc->sm->sm_ino, &imap, - XFS_IGET_UNTRUSTED | XFS_IGET_DONTCACHE); + XFS_IGET_UNTRUSTED); if (error) return -ENOENT; error = -EFSCORRUPTED; @@ -911,7 +910,7 @@ xchk_get_inode( */ if (VFS_I(ip)->i_generation != sc->sm->sm_gen || (xfs_is_metadata_inode(ip) && !S_ISDIR(VFS_I(ip)->i_mode))) { - xfs_irele(ip); + xchk_irele(sc, ip); return -ENOENT; } @@ -919,6 +918,24 @@ xchk_get_inode( return 0; } +void +__xchk_irele( + struct xfs_inode *ip, + bool set_dontcache) +{ + if (set_dontcache && atomic_read(&VFS_I(ip)->i_count) == 1) + d_mark_dontcache(VFS_I(ip)); + xfs_irele(ip); +} + +void +xchk_irele( + struct xfs_scrub *sc, + struct xfs_inode *ip) +{ + __xchk_irele(ip, !(sc->sm->sm_flags & XFS_SCRUB_IFLAG_RETAIN_INODES)); +} + /* Set us up to scrub a file's contents. */ int xchk_setup_inode_contents( diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h index ead7789fba5f..72c7d2636b56 100644 --- a/fs/xfs/scrub/common.h +++ b/fs/xfs/scrub/common.h @@ -177,6 +177,9 @@ void xchk_iunlock(struct xfs_scrub *sc, unsigned int ilock_flags); void xchk_buffer_recheck(struct xfs_scrub *sc, struct xfs_buf *bp); void xchk_whine(const struct xfs_mount *mp, const char *fmt, ...); +void __xchk_irele(struct xfs_inode *ip, bool set_dontcache); +void xchk_irele(struct xfs_scrub *sc, struct xfs_inode *ip); + /* * Don't bother cross-referencing if we already found corruption or cross * referencing discrepancies. diff --git a/fs/xfs/scrub/dir.c b/fs/xfs/scrub/dir.c index 31e3626db100..7b8fafe4cffa 100644 --- a/fs/xfs/scrub/dir.c +++ b/fs/xfs/scrub/dir.c @@ -104,7 +104,7 @@ xchk_dir_check_ftype( if (xfs_is_metadata_inode(ip) ^ xfs_is_metadata_inode(sdc->sc->ip)) xchk_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, 0); - xfs_irele(ip); + xchk_irele(sdc->sc, ip); out: return error; } diff --git a/fs/xfs/scrub/dir_repair.c b/fs/xfs/scrub/dir_repair.c index b64be71d9884..0d1130ae455f 100644 --- a/fs/xfs/scrub/dir_repair.c +++ b/fs/xfs/scrub/dir_repair.c @@ -211,12 +211,12 @@ xrep_directory_salvage_entry( /* Don't mix metadata and regular directory trees. */ if (xfs_is_metadata_inode(ip) ^ xfs_is_metadata_inode(rd->sc->ip)) { - xfs_irele(ip); + xchk_irele(rd->sc, ip); return 0; } key.ftype = xfs_mode_to_ftype(VFS_I(ip)->i_mode); - xfs_irele(ip); + xchk_irele(rd->sc, ip); /* Remember this for later. */ error = xfblob_store(rd->dir_names, &key.name_cookie, name, diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index c64adde40dce..97605313f097 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -1182,8 +1182,7 @@ xrep_dinode_core( return error; /* ...and reload it? */ - error = xfs_iget(sc->mp, sc->tp, ino, - XFS_IGET_UNTRUSTED | XFS_IGET_DONTCACHE, 0, &sc->ip); + error = xfs_iget(sc->mp, sc->tp, ino, XFS_IGET_UNTRUSTED, 0, &sc->ip); if (error) return error; diff --git a/fs/xfs/scrub/iscan.c b/fs/xfs/scrub/iscan.c index ae056e6748f2..7b16d221b5e7 100644 --- a/fs/xfs/scrub/iscan.c +++ b/fs/xfs/scrub/iscan.c @@ -292,8 +292,8 @@ xchk_iscan_iget( struct xfs_mount *mp = sc->mp; int error; - error = xfs_iget(mp, sc->tp, iscan->cursor_ino, - XFS_IGET_DONTCACHE | XFS_IGET_UNTRUSTED, 0, ipp); + error = xfs_iget(mp, sc->tp, iscan->cursor_ino, XFS_IGET_UNTRUSTED, 0, + ipp); trace_xchk_iscan_iget(mp, iscan, error); diff --git a/fs/xfs/scrub/parent.c b/fs/xfs/scrub/parent.c index e4de4cb6ea19..ec351a393b2d 100644 --- a/fs/xfs/scrub/parent.c +++ b/fs/xfs/scrub/parent.c @@ -270,7 +270,7 @@ xchk_parent_validate( out_unlock: xfs_iunlock(dp, XFS_IOLOCK_SHARED); out_rele: - xfs_irele(dp); + xchk_irele(sc, dp); return error; } diff --git a/fs/xfs/scrub/parent_repair.c b/fs/xfs/scrub/parent_repair.c index 28ffcee4f9e5..b9d244594913 100644 --- a/fs/xfs/scrub/parent_repair.c +++ b/fs/xfs/scrub/parent_repair.c @@ -285,7 +285,7 @@ xrep_parent_confirm( *parent_ino = fpi.found_parent; out_rele: - xfs_irele(fpi.dp); + xchk_irele(sc, fpi.dp); return error; } @@ -319,7 +319,7 @@ xrep_parent_from_dcache( ret = XFS_I(pip)->i_ino; } - xfs_irele(XFS_I(pip)); + xchk_irele(sc, XFS_I(pip)); out_dput: dput(dentry); @@ -363,7 +363,7 @@ xrep_parent_scan( if (S_ISDIR(VFS_I(fpi.dp)->i_mode)) ret = xrep_findparent_walk_directory(&fpi); xchk_iscan_mark_visited(&iscan, fpi.dp); - xfs_irele(fpi.dp); + xchk_irele(sc, fpi.dp); if (ret) break; diff --git a/fs/xfs/scrub/quotacheck.c b/fs/xfs/scrub/quotacheck.c index 3c19bc157a03..d7cf1e1554ac 100644 --- a/fs/xfs/scrub/quotacheck.c +++ b/fs/xfs/scrub/quotacheck.c @@ -495,7 +495,7 @@ xqcheck_collect_counts( break; error = xqcheck_inode(xqc, ip); - xfs_irele(ip); + xchk_irele(sc, ip); if (error) break; diff --git a/fs/xfs/scrub/rmap_repair.c b/fs/xfs/scrub/rmap_repair.c index dfc0697809e7..876717816081 100644 --- a/fs/xfs/scrub/rmap_repair.c +++ b/fs/xfs/scrub/rmap_repair.c @@ -954,7 +954,7 @@ end_agscan: break; error = xrep_rmap_scan_inode(rr, ip); - xfs_irele(ip); + xchk_irele(sc, ip); if (error) break; diff --git a/fs/xfs/scrub/rtrmap_repair.c b/fs/xfs/scrub/rtrmap_repair.c index b91b1a378d15..f669f51f6f70 100644 --- a/fs/xfs/scrub/rtrmap_repair.c +++ b/fs/xfs/scrub/rtrmap_repair.c @@ -551,7 +551,7 @@ xrep_rtrmap_find_rmaps( break; error = xrep_rtrmap_scan_inode(rr, ip); - xfs_irele(ip); + xchk_irele(sc, ip); if (error) break; diff --git a/fs/xfs/scrub/scrub.c b/fs/xfs/scrub/scrub.c index 238dc7029070..f755c6d4ff5e 100644 --- a/fs/xfs/scrub/scrub.c +++ b/fs/xfs/scrub/scrub.c @@ -172,7 +172,7 @@ xchk_teardown( if (sc->ip) { if (sc->ilock_flags) xchk_iunlock(sc, sc->ilock_flags); - xfs_irele(sc->ip); + xchk_irele(sc, sc->ip); sc->ip = NULL; } if (sc->flags & XREP_ATOMIC_EXCHANGE) { @@ -731,7 +731,8 @@ xfs_scrubv_metadata( * consider setting dontcache at the end. */ if (v->sv_type < XFS_SCRUB_TYPE_NR && - meta_scrub_ops[v->sv_type].type == ST_INODE) + meta_scrub_ops[v->sv_type].type == ST_INODE && + !(vhead->svh_flags & XFS_SCRUB_VEC_IFLAG_RETAIN_INODES)) set_dontcache = true; trace_xchk_scrubv_item(mp, vhead, v); @@ -748,7 +749,7 @@ xfs_scrubv_metadata( if (ip && (VFS_I(ip)->i_generation != vhead->svh_gen || (xfs_is_metadata_inode(ip) && !S_ISDIR(VFS_I(ip)->i_mode)))) { - xfs_irele(ip); + __xchk_irele(ip, set_dontcache); ip = NULL; } } @@ -803,8 +804,6 @@ xfs_scrubv_metadata( * If we're holding the only reference to this inode and the scan was * clean, mark it dontcache so that we don't pollute the cache. */ - if (set_dontcache && atomic_read(&VFS_I(ip)->i_count) == 1) - d_mark_dontcache(VFS_I(ip)); - xfs_irele(ip); + __xchk_irele(ip, set_dontcache); return error; } diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h index 04e3b3424b18..4b2b15d9ac1e 100644 --- a/fs/xfs/scrub/trace.h +++ b/fs/xfs/scrub/trace.h @@ -108,7 +108,8 @@ TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_BARRIER); { XFS_SCRUB_OFLAG_INCOMPLETE, "incomplete" }, \ { XFS_SCRUB_OFLAG_WARNING, "warning" }, \ { XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED, "norepair" }, \ - { XFS_SCRUB_IFLAG_FREEZE_OK, "freeze" } + { XFS_SCRUB_IFLAG_FREEZE_OK, "freeze" }, \ + { XFS_SCRUB_IFLAG_RETAIN_INODES, "icache" } DECLARE_EVENT_CLASS(xchk_class, TP_PROTO(struct xfs_inode *ip, struct xfs_scrub_metadata *sm, diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 97ccc69a3bf4..fb94301dbc85 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -897,6 +897,9 @@ xfs_bulk_ireq_setup( if (hdr->flags & XFS_BULK_IREQ_METADIR) breq->flags |= XFS_IWALK_METADIR; + if (hdr->flags & XFS_BULK_IREQ_RETAIN_INODES) + breq->flags |= XFS_IWALK_RETAIN_INODES; + return 0; } diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c index f92057ad686b..528bf3e59995 100644 --- a/fs/xfs/xfs_itable.c +++ b/fs/xfs/xfs_itable.c @@ -74,11 +74,13 @@ xfs_bulkstat_one_int( struct xfs_inode *ip; /* incore inode pointer */ struct inode *inode; struct xfs_bulkstat *buf = bc->buf; + int flags = XFS_IGET_UNTRUSTED; int error = -EINVAL; - error = xfs_iget(mp, tp, ino, - (XFS_IGET_DONTCACHE | XFS_IGET_UNTRUSTED), - XFS_ILOCK_SHARED, &ip); + if (!(bc->breq->flags & XFS_IBULK_RETAIN_INODES)) + flags |= XFS_IGET_DONTCACHE; + + error = xfs_iget(mp, tp, ino, flags, XFS_ILOCK_SHARED, &ip); if (error == -ENOENT || error == -EINVAL) goto out_advance; if (error) diff --git a/fs/xfs/xfs_itable.h b/fs/xfs/xfs_itable.h index f5a13f69883a..7fc2e40d30bd 100644 --- a/fs/xfs/xfs_itable.h +++ b/fs/xfs/xfs_itable.h @@ -22,6 +22,9 @@ struct xfs_ibulk { /* Signal that we can return metadata directories. */ #define XFS_IBULK_METADIR (XFS_IWALK_METADIR) +/* Don't drop inodes. */ +#define XFS_IBULK_RETAIN_INODES (XFS_IWALK_RETAIN_INODES) + /* * Advance the user buffer pointer by one record of the given size. If the * buffer is now full, return the appropriate error code. diff --git a/fs/xfs/xfs_iwalk.h b/fs/xfs/xfs_iwalk.h index d7a082e45cbf..bdec747ff834 100644 --- a/fs/xfs/xfs_iwalk.h +++ b/fs/xfs/xfs_iwalk.h @@ -31,8 +31,12 @@ int xfs_iwalk_threaded(struct xfs_mount *mp, xfs_ino_t startino, /* Signal that we can return metadata directories. */ #define XFS_IWALK_METADIR (0x2) +/* Don't drop inodes. */ +#define XFS_IWALK_RETAIN_INODES (0x4) + #define XFS_IWALK_FLAGS_ALL (XFS_IWALK_SAME_AG | \ - XFS_IWALK_METADIR) + XFS_IWALK_METADIR | \ + XFS_IWALK_RETAIN_INODES) /* Walk all inode btree records in the filesystem starting from @startino. */ typedef int (*xfs_inobt_walk_fn)(struct xfs_mount *mp, struct xfs_trans *tp, -- cgit v1.2.3