89 lines · c
1// SPDX-License-Identifier: GPL-2.0-or-later2/*3 * Copyright (C) 2022-2023 Oracle. All Rights Reserved.4 * Author: Darrick J. Wong <djwong@kernel.org>5 */6#ifndef XFS_DRAIN_H_7#define XFS_DRAIN_H_8 9struct xfs_perag;10 11#ifdef CONFIG_XFS_DRAIN_INTENTS12/*13 * Passive drain mechanism. This data structure tracks a count of some items14 * and contains a waitqueue for callers who would like to wake up when the15 * count hits zero.16 */17struct xfs_defer_drain {18 /* Number of items pending in some part of the filesystem. */19 atomic_t dr_count;20 21 /* Queue to wait for dri_count to go to zero */22 struct wait_queue_head dr_waiters;23};24 25void xfs_defer_drain_init(struct xfs_defer_drain *dr);26void xfs_defer_drain_free(struct xfs_defer_drain *dr);27 28void xfs_drain_wait_disable(void);29void xfs_drain_wait_enable(void);30 31/*32 * Deferred Work Intent Drains33 * ===========================34 *35 * When a writer thread executes a chain of log intent items, the AG header36 * buffer locks will cycle during a transaction roll to get from one intent37 * item to the next in a chain. Although scrub takes all AG header buffer38 * locks, this isn't sufficient to guard against scrub checking an AG while39 * that writer thread is in the middle of finishing a chain because there's no40 * higher level locking primitive guarding allocation groups.41 *42 * When there's a collision, cross-referencing between data structures (e.g.43 * rmapbt and refcountbt) yields false corruption events; if repair is running,44 * this results in incorrect repairs, which is catastrophic.45 *46 * The solution is to the perag structure the count of active intents and make47 * scrub wait until it has both AG header buffer locks and the intent counter48 * reaches zero. It is therefore critical that deferred work threads hold the49 * AGI or AGF buffers when decrementing the intent counter.50 *51 * Given a list of deferred work items, the deferred work manager will complete52 * a work item and all the sub-items that the parent item creates before moving53 * on to the next work item in the list. This is also true for all levels of54 * sub-items. Writer threads are permitted to queue multiple work items55 * targetting the same AG, so a deferred work item (such as a BUI) that creates56 * sub-items (such as RUIs) must bump the intent counter and maintain it until57 * the sub-items can themselves bump the intent counter.58 *59 * Therefore, the intent count tracks entire lifetimes of deferred work items.60 * All functions that create work items must increment the intent counter as61 * soon as the item is added to the transaction and cannot drop the counter62 * until the item is finished or cancelled.63 */64struct xfs_perag *xfs_perag_intent_get(struct xfs_mount *mp,65 xfs_fsblock_t fsbno);66void xfs_perag_intent_put(struct xfs_perag *pag);67 68void xfs_perag_intent_hold(struct xfs_perag *pag);69void xfs_perag_intent_rele(struct xfs_perag *pag);70 71int xfs_perag_intent_drain(struct xfs_perag *pag);72bool xfs_perag_intent_busy(struct xfs_perag *pag);73#else74struct xfs_defer_drain { /* empty */ };75 76#define xfs_defer_drain_free(dr) ((void)0)77#define xfs_defer_drain_init(dr) ((void)0)78 79#define xfs_perag_intent_get(mp, fsbno) \80 xfs_perag_get((mp), XFS_FSB_TO_AGNO(mp, fsbno))81#define xfs_perag_intent_put(pag) xfs_perag_put(pag)82 83static inline void xfs_perag_intent_hold(struct xfs_perag *pag) { }84static inline void xfs_perag_intent_rele(struct xfs_perag *pag) { }85 86#endif /* CONFIG_XFS_DRAIN_INTENTS */87 88#endif /* XFS_DRAIN_H_ */89