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 827509 : xfs_hooks_init( 59 : struct xfs_hooks *chain) 60 : { 61 827509 : BLOCKING_INIT_NOTIFIER_HEAD(&chain->head); 62 827509 : } 63 : 64 : /* Make it so a function gets called whenever we hit a certain hook point. */ 65 : int 66 23603760 : xfs_hooks_add( 67 : struct xfs_hooks *chain, 68 : struct xfs_hook *hook) 69 : { 70 23603760 : ASSERT(hook->nb.notifier_call != NULL); 71 23603760 : BUILD_BUG_ON(offsetof(struct xfs_hook, nb) != 0); 72 : 73 23603760 : return blocking_notifier_chain_register(&chain->head, &hook->nb); 74 : } 75 : 76 : /* Remove a previously installed hook. */ 77 : void 78 23702077 : xfs_hooks_del( 79 : struct xfs_hooks *chain, 80 : struct xfs_hook *hook) 81 : { 82 23702077 : blocking_notifier_chain_unregister(&chain->head, &hook->nb); 83 23781333 : } 84 : 85 : /* Call a hook. Returns the NOTIFY_* value returned by the last hook. */ 86 : int 87 229393805 : xfs_hooks_call( 88 : struct xfs_hooks *chain, 89 : unsigned long val, 90 : void *priv) 91 : { 92 229393805 : return blocking_notifier_call_chain(&chain->head, val, priv); 93 : } 94 : #endif /* CONFIG_XFS_LIVE_HOOKS_BLOCKING */