linux/fs/xfs/xfs_hooks.h

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (c) 2022-2024 Oracle.  All Rights Reserved.
 * Author: Darrick J. Wong <[email protected]>
 */
#ifndef XFS_HOOKS_H_
#define XFS_HOOKS_H_

#ifdef CONFIG_XFS_LIVE_HOOKS
struct xfs_hooks {};

/*
 * If jump labels are enabled in Kconfig, the static key uses nop sleds and
 * code patching to eliminate the overhead of taking the rwsem in
 * blocking_notifier_call_chain when there are no hooks configured.  If not,
 * the static key per-call overhead is an atomic read.  Most arches that can
 * handle XFS also support jump labels.
 *
 * Note: Patching the kernel code requires taking the cpu hotplug lock.  Other
 * parts of the kernel allocate memory with that lock held, which means that
 * XFS callers cannot hold any locks that might be used by memory reclaim or
 * writeback when calling the static_branch_{inc,dec} functions.
 */
#define DEFINE_STATIC_XFS_HOOK_SWITCH(name)
#define xfs_hooks_switch_on(name)
#define xfs_hooks_switch_off(name)
#define xfs_hooks_switched_on(name)

struct xfs_hook {};

xfs_hook_fn_t;

void xfs_hooks_init(struct xfs_hooks *chain);
int xfs_hooks_add(struct xfs_hooks *chain, struct xfs_hook *hook);
void xfs_hooks_del(struct xfs_hooks *chain, struct xfs_hook *hook);
int xfs_hooks_call(struct xfs_hooks *chain, unsigned long action,
		void *priv);

static inline void xfs_hook_setup(struct xfs_hook *hook, notifier_fn_t fn)
{}

#else

struct xfs_hooks { /* empty */ };

#define DEFINE_STATIC_XFS_HOOK_SWITCH
#define xfs_hooks_switch_on
#define xfs_hooks_switch_off
#define xfs_hooks_switched_on

#define xfs_hooks_init
#define xfs_hooks_call
#endif

#endif /* XFS_HOOKS_H_ */