Line data Source code
1 : // SPDX-License-Identifier: GPL-2.0-or-later 2 : /* 3 : * Copyright (C) 2022-2023 Oracle. All Rights Reserved. 4 : * Author: Darrick J. Wong <djwong@kernel.org> 5 : */ 6 : #include "xfs.h" 7 : #include "xfs_fs.h" 8 : #include "xfs_shared.h" 9 : #include "xfs_format.h" 10 : #include "xfs_trans_resv.h" 11 : #include "xfs_mount.h" 12 : #include "xfs_ag.h" 13 : #include "xfs_trace.h" 14 : 15 : #if defined(CONFIG_XFS_LIVE_HOOKS_SRCU) 16 : /* Initialize a notifier chain. */ 17 : void 18 : xfs_hooks_init( 19 : struct xfs_hooks *chain) 20 : { 21 : srcu_init_notifier_head(&chain->head); 22 : } 23 : 24 : /* Make it so a function gets called whenever we hit a certain hook point. */ 25 : int 26 : xfs_hooks_add( 27 : struct xfs_hooks *chain, 28 : struct xfs_hook *hook) 29 : { 30 : ASSERT(hook->nb.notifier_call != NULL); 31 : BUILD_BUG_ON(offsetof(struct xfs_hook, nb) != 0); 32 : 33 : return srcu_notifier_chain_register(&chain->head, &hook->nb); 34 : } 35 : 36 : /* Remove a previously installed hook. */ 37 : void 38 : xfs_hooks_del( 39 : struct xfs_hooks *chain, 40 : struct xfs_hook *hook) 41 : { 42 : srcu_notifier_chain_unregister(&chain->head, &hook->nb); 43 : rcu_barrier(); 44 : } 45 : 46 : /* Call a hook. Returns the NOTIFY_* value returned by the last hook. */ 47 : int 48 : xfs_hooks_call( 49 : struct xfs_hooks *chain, 50 : unsigned long val, 51 : void *priv) 52 : { 53 : return srcu_notifier_call_chain(&chain->head, val, priv); 54 : } 55 : #elif defined(CONFIG_XFS_LIVE_HOOKS_BLOCKING) 56 : /* Initialize a notifier chain. */ 57 : void 58 216824 : xfs_hooks_init( 59 : struct xfs_hooks *chain) 60 : { 61 216824 : BLOCKING_INIT_NOTIFIER_HEAD(&chain->head); 62 216824 : } 63 : 64 : /* Make it so a function gets called whenever we hit a certain hook point. */ 65 : int 66 11841319 : xfs_hooks_add( 67 : struct xfs_hooks *chain, 68 : struct xfs_hook *hook) 69 : { 70 11841319 : ASSERT(hook->nb.notifier_call != NULL); 71 11841319 : BUILD_BUG_ON(offsetof(struct xfs_hook, nb) != 0); 72 : 73 11841319 : return blocking_notifier_chain_register(&chain->head, &hook->nb); 74 : } 75 : 76 : /* Remove a previously installed hook. */ 77 : void 78 11846162 : xfs_hooks_del( 79 : struct xfs_hooks *chain, 80 : struct xfs_hook *hook) 81 : { 82 11846162 : blocking_notifier_chain_unregister(&chain->head, &hook->nb); 83 11846930 : } 84 : 85 : /* Call a hook. Returns the NOTIFY_* value returned by the last hook. */ 86 : int 87 144845228 : xfs_hooks_call( 88 : struct xfs_hooks *chain, 89 : unsigned long val, 90 : void *priv) 91 : { 92 144845228 : return blocking_notifier_call_chain(&chain->head, val, priv); 93 : } 94 : #endif /* CONFIG_XFS_LIVE_HOOKS_BLOCKING */