xfs_hooks.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) 2022-2024 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. /* Initialize a notifier chain. */
  15. void
  16. xfs_hooks_init(
  17. struct xfs_hooks *chain)
  18. {
  19. BLOCKING_INIT_NOTIFIER_HEAD(&chain->head);
  20. }
  21. /* Make it so a function gets called whenever we hit a certain hook point. */
  22. int
  23. xfs_hooks_add(
  24. struct xfs_hooks *chain,
  25. struct xfs_hook *hook)
  26. {
  27. ASSERT(hook->nb.notifier_call != NULL);
  28. BUILD_BUG_ON(offsetof(struct xfs_hook, nb) != 0);
  29. return blocking_notifier_chain_register(&chain->head, &hook->nb);
  30. }
  31. /* Remove a previously installed hook. */
  32. void
  33. xfs_hooks_del(
  34. struct xfs_hooks *chain,
  35. struct xfs_hook *hook)
  36. {
  37. blocking_notifier_chain_unregister(&chain->head, &hook->nb);
  38. }
  39. /* Call a hook. Returns the NOTIFY_* value returned by the last hook. */
  40. int
  41. xfs_hooks_call(
  42. struct xfs_hooks *chain,
  43. unsigned long val,
  44. void *priv)
  45. {
  46. return blocking_notifier_call_chain(&chain->head, val, priv);
  47. }