diff options
Diffstat (limited to 'fs/xfs/scrub')
-rw-r--r-- | fs/xfs/scrub/bmap_repair.c | 4 | ||||
-rw-r--r-- | fs/xfs/scrub/common.c | 168 | ||||
-rw-r--r-- | fs/xfs/scrub/common.h | 2 | ||||
-rw-r--r-- | fs/xfs/scrub/inode_repair.c | 4 | ||||
-rw-r--r-- | fs/xfs/scrub/repair.c | 3 | ||||
-rw-r--r-- | fs/xfs/scrub/rtrmap_repair.c | 4 | ||||
-rw-r--r-- | fs/xfs/scrub/trace.h | 31 |
7 files changed, 193 insertions, 23 deletions
diff --git a/fs/xfs/scrub/bmap_repair.c b/fs/xfs/scrub/bmap_repair.c index 334d970b1314..0f52356d6ed3 100644 --- a/fs/xfs/scrub/bmap_repair.c +++ b/fs/xfs/scrub/bmap_repair.c @@ -333,7 +333,9 @@ xrep_bmap_scan_rt( if (xrep_is_rtmeta_ino(sc, sc->ip->i_ino)) return 0; - xchk_rt_lock(sc, &sc->sr); + error = xchk_rt_lock(sc, &sc->sr); + if (error) + return error; xrep_rt_btcur_init(sc, &sc->sr); error = xfs_rmap_query_all(sc->sr.rmap_cur, xrep_bmap_walk_rtrmap, rb); xchk_rt_btcur_free(&sc->sr); diff --git a/fs/xfs/scrub/common.c b/fs/xfs/scrub/common.c index 0ea9b6b299ae..323179b3d17a 100644 --- a/fs/xfs/scrub/common.c +++ b/fs/xfs/scrub/common.c @@ -484,7 +484,35 @@ want_ag_read_header_failure( * * The headers should be released by xchk_ag_free, but as a fail safe we attach * all the buffers we grab to the scrub transaction so they'll all be freed - * when we cancel it. Returns ENOENT if we can't grab the perag structure. + * when we cancel it. + */ +static inline int +__xchk_ag_read_headers( + struct xfs_scrub *sc, + xfs_agnumber_t agno, + struct xchk_ag *sa) +{ + struct xfs_mount *mp = sc->mp; + int error; + + error = xfs_ialloc_read_agi(mp, sc->tp, agno, &sa->agi_bp); + if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGI)) + return error; + + error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, &sa->agf_bp); + if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGF)) + return error; + + error = xfs_alloc_read_agfl(mp, sc->tp, agno, &sa->agfl_bp); + if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGFL)) + return error; + + return 0; +} + +/* + * Grab all the headers for an AG, and wait until there aren't any pending + * intents. Returns -ENOENT if we can't grab the perag structure. */ int xchk_ag_read_headers( @@ -502,29 +530,83 @@ xchk_ag_read_headers( return xchk_ag_lock(sc); } -/* Lock the AG headers. */ +static inline bool +xchk_ag_intents_pending( + struct xfs_perag *pag) +{ + int intents = atomic_read(&pag->pag_intents); + + trace_xchk_ag_read_headers(pag->pag_mount, pag->pag_agno, intents, + _RET_IP_); + + return intents > 0; +} + +/* Lock the AG headers, waiting for pending intents to drain. */ int xchk_ag_lock( struct xfs_scrub *sc) { - struct xfs_mount *mp = sc->mp; struct xchk_ag *sa = &sc->sa; - xfs_agnumber_t agno = sa->pag->pag_agno; - int error; + int error = 0; - error = xfs_ialloc_read_agi(mp, sc->tp, agno, &sa->agi_bp); - if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGI)) - return error; + ASSERT(sa->pag != NULL); + ASSERT(sa->agi_bp == NULL); + ASSERT(sa->agf_bp == NULL); + ASSERT(sa->agfl_bp == NULL); - error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, &sa->agf_bp); - if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGF)) - return error; + do { + if (xchk_should_terminate(sc, &error)) + break; - error = xfs_alloc_read_agfl(mp, sc->tp, agno, &sa->agfl_bp); - if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGFL)) - return error; + error = __xchk_ag_read_headers(sc, sa->pag->pag_agno, sa); + if (error) + break; - return 0; + /* + * Decide if this AG is quiet enough for all metadata to be + * consistent with each other. XFS allows the AG header buffer + * locks to cycle across transaction rolls while processing + * chains of deferred ops, which means that there could be + * other threads in the middle of processing a chain of + * deferred ops. For regular operations we are careful about + * ordering operations to prevent collisions between threads + * (which is why we don't need a per-AG lock), but scrub and + * repair have to serialize against chained operations. + * + * We just locked all the AG headers buffers; now take a look + * to see if there are any intents in progress. If there are, + * drop the AG headers and wait for the intents to drain. + * Since we hold all the AG header locks for the duration of + * the scrub, this is the only time we have to sample the + * intents counter; any threads increasing it after this point + * can't possibly be in the middle of a chain of AG metadata + * updates. + */ + if (!xchk_ag_intents_pending(sa->pag)) { + error = 0; + break; + } + + if (sa->agfl_bp) { + xfs_trans_brelse(sc->tp, sa->agfl_bp); + sa->agfl_bp = NULL; + } + + if (sa->agf_bp) { + xfs_trans_brelse(sc->tp, sa->agf_bp); + sa->agf_bp = NULL; + } + + if (sa->agi_bp) { + xfs_trans_brelse(sc->tp, sa->agi_bp); + sa->agi_bp = NULL; + } + + error = xfs_perag_wait_intents(sa->pag); + } while (!error); + + return error; } /* Release all the AG btree cursors. */ @@ -653,14 +735,62 @@ xchk_ag_init( return 0; } -/* Lock everything we need to work on realtime metadata. */ -void +#if IS_ENABLED(CONFIG_XFS_RT) +static inline bool +xchk_rt_intents_pending( + struct xfs_mount *mp) +{ + int intents = atomic_read(&mp->m_rt_intents); + + trace_xchk_rt_lock(mp, -1U, intents, _RET_IP_); + + return intents > 0; +} +#else +# define xchk_rt_intents_pending(mp) (false) +#endif + +/* Lock everything we need to work on realtime metadata and wait for intents. */ +int xchk_rt_lock( struct xfs_scrub *sc, struct xchk_rt *sr) { - xfs_rtlock(NULL, sc->mp, XFS_RTLOCK_ALL); - sr->locked = true; + int error = 0; + + do { + if (xchk_should_terminate(sc, &error)) + break; + + xfs_rtlock(NULL, sc->mp, XFS_RTLOCK_ALL); + + /* + * Decide if the RT volume is quiet enough for all metadata to + * be consistent with each other. Regular file IO doesn't get + * to lock all the rt inodes at the same time, which means that + * there could be other threads in the middle of processing a + * chain of deferred ops. + * + * We just locked all the rt inodes; now take a look to see if + * there are any rt intents in progress. If there are, drop + * the rt inode locks and wait for the intents to drain. Since + * we hold the rt inode locks for the duration of the scrub, + * this is the only time we have to sample the intents counter; + * any threads increasing it after this point can't possibly be + * in the middle of a chain of rt metadata updates. + */ + if (!xchk_rt_intents_pending(sc->mp)) { + sr->locked = true; + error = 0; + break; + } + + xfs_rtunlock(sc->mp, XFS_RTLOCK_ALL); + + error = xfs_rt_wait_intents(sc->mp); + } while (!error); + + return error; } /* diff --git a/fs/xfs/scrub/common.h b/fs/xfs/scrub/common.h index 74f0606174df..819bb7e2007a 100644 --- a/fs/xfs/scrub/common.h +++ b/fs/xfs/scrub/common.h @@ -157,7 +157,7 @@ xchk_ag_init_existing( void xchk_rt_init(struct xfs_scrub *sc, struct xchk_rt *sr); void xchk_rt_btcur_free(struct xchk_rt *sr); -void xchk_rt_lock(struct xfs_scrub *sc, struct xchk_rt *sr); +int xchk_rt_lock(struct xfs_scrub *sc, struct xchk_rt *sr); void xchk_rt_unlock(struct xfs_scrub *sc, struct xchk_rt *sr); int xchk_ag_read_headers(struct xfs_scrub *sc, xfs_agnumber_t agno, struct xchk_ag *sa); diff --git a/fs/xfs/scrub/inode_repair.c b/fs/xfs/scrub/inode_repair.c index 97605313f097..8eec28aa1a95 100644 --- a/fs/xfs/scrub/inode_repair.c +++ b/fs/xfs/scrub/inode_repair.c @@ -597,7 +597,9 @@ xrep_dinode_count_rt_rmaps( xrep_is_rtmeta_ino(sc, sc->sm->sm_ino)) return 0; - xchk_rt_lock(sc, &sc->sr); + error = xchk_rt_lock(sc, &sc->sr); + if (error) + return error; xrep_rt_btcur_init(sc, &sc->sr); error = xfs_rmap_query_all(sc->sr.rmap_cur, xrep_dinode_walk_rtrmap, dis); diff --git a/fs/xfs/scrub/repair.c b/fs/xfs/scrub/repair.c index 47592ca215c6..e35c2c8b0513 100644 --- a/fs/xfs/scrub/repair.c +++ b/fs/xfs/scrub/repair.c @@ -477,6 +477,7 @@ xrep_newbt_schedule_reap( INIT_LIST_HEAD(&efi_item.xefi_list); list_add(&efi_item.xefi_list, &items); + xfs_fs_bump_intents(xnr->sc->mp, false, resv->fsbno); resv->efi = xfs_extent_free_defer_type.create_intent(xnr->sc->tp, &items, 1, false); } @@ -698,6 +699,7 @@ xrep_newbt_destroy( goto junkit; list_del(&resv->list); + xfs_fs_drop_intents(sc->mp, false, resv->fsbno); kmem_free(resv); } @@ -710,6 +712,7 @@ junkit: list_for_each_entry_safe(resv, n, &xnr->resv_list, list) { xfs_extent_free_defer_type.abort_intent(resv->efi); list_del(&resv->list); + xfs_fs_drop_intents(sc->mp, false, resv->fsbno); kmem_free(resv); } diff --git a/fs/xfs/scrub/rtrmap_repair.c b/fs/xfs/scrub/rtrmap_repair.c index f669f51f6f70..d68ef4d1ec16 100644 --- a/fs/xfs/scrub/rtrmap_repair.c +++ b/fs/xfs/scrub/rtrmap_repair.c @@ -569,7 +569,9 @@ xrep_rtrmap_find_rmaps( error = xchk_setup_fs(sc); if (error) return error; - xchk_rt_lock(sc, &sc->sr); + error = xchk_rt_lock(sc, &sc->sr); + if (error) + return error; /* Scan for old rtrmap blocks. */ for_each_perag(sc->mp, agno, pag) { diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h index 9878ee415e8b..5c43578a174e 100644 --- a/fs/xfs/scrub/trace.h +++ b/fs/xfs/scrub/trace.h @@ -717,6 +717,37 @@ TRACE_EVENT(xchk_iallocbt_check_cluster, __entry->cluster_ino) ) +DECLARE_EVENT_CLASS(xchk_ag_class, + TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, int refcount, + unsigned long caller_ip), + TP_ARGS(mp, agno, refcount, caller_ip), + TP_STRUCT__entry( + __field(dev_t, dev) + __field(xfs_agnumber_t, agno) + __field(int, refcount) + __field(unsigned long, caller_ip) + ), + TP_fast_assign( + __entry->dev = mp->m_super->s_dev; + __entry->agno = agno; + __entry->refcount = refcount; + __entry->caller_ip = caller_ip; + ), + TP_printk("dev %d:%d agno %u refcount %d caller %pS", + MAJOR(__entry->dev), MINOR(__entry->dev), + __entry->agno, + __entry->refcount, + (char *)__entry->caller_ip) +); + +#define DEFINE_XCHK_AG_EVENT(name) \ +DEFINE_EVENT(xchk_ag_class, name, \ + TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, int refcount, \ + unsigned long caller_ip), \ + TP_ARGS(mp, agno, refcount, caller_ip)) +DEFINE_XCHK_AG_EVENT(xchk_ag_read_headers); +DEFINE_XCHK_AG_EVENT(xchk_rt_lock); + TRACE_EVENT(xchk_fscounters_calc, TP_PROTO(struct xfs_mount *mp, uint64_t icount, uint64_t ifree, uint64_t fdblocks, uint64_t delalloc), |