action-manager.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2023 Red Hat
  4. */
  5. #ifndef VDO_ACTION_MANAGER_H
  6. #define VDO_ACTION_MANAGER_H
  7. #include "admin-state.h"
  8. #include "types.h"
  9. /*
  10. * An action_manager provides a generic mechanism for applying actions to multi-zone entities (such
  11. * as the block map or slab depot). Each action manager is tied to a specific context for which it
  12. * manages actions. The manager ensures that only one action is active on that context at a time,
  13. * and supports at most one pending action. Calls to schedule an action when there is already a
  14. * pending action will result in VDO_COMPONENT_BUSY errors. Actions may only be submitted to the
  15. * action manager from a single thread (which thread is determined when the action manager is
  16. * constructed).
  17. *
  18. * A scheduled action consists of four components:
  19. *
  20. * preamble
  21. * an optional method to be run on the initiator thread before applying the action to all zones
  22. * zone_action
  23. * an optional method to be applied to each of the zones
  24. * conclusion
  25. * an optional method to be run on the initiator thread once the per-zone method has been
  26. * applied to all zones
  27. * parent
  28. * an optional completion to be finished once the conclusion is done
  29. *
  30. * At least one of the three methods must be provided.
  31. */
  32. /*
  33. * A function which is to be applied asynchronously to a set of zones.
  34. * @context: The object which holds the per-zone context for the action
  35. * @zone_number: The number of zone to which the action is being applied
  36. * @parent: The object to notify when the action is complete
  37. */
  38. typedef void (*vdo_zone_action_fn)(void *context, zone_count_t zone_number,
  39. struct vdo_completion *parent);
  40. /*
  41. * A function which is to be applied asynchronously on an action manager's initiator thread as the
  42. * preamble of an action.
  43. * @context: The object which holds the per-zone context for the action
  44. * @parent: The object to notify when the action is complete
  45. */
  46. typedef void (*vdo_action_preamble_fn)(void *context, struct vdo_completion *parent);
  47. /*
  48. * A function which will run on the action manager's initiator thread as the conclusion of an
  49. * action.
  50. * @context: The object which holds the per-zone context for the action
  51. *
  52. * Return: VDO_SUCCESS or an error
  53. */
  54. typedef int (*vdo_action_conclusion_fn)(void *context);
  55. /*
  56. * A function to schedule an action.
  57. * @context: The object which holds the per-zone context for the action
  58. *
  59. * Return: true if an action was scheduled
  60. */
  61. typedef bool (*vdo_action_scheduler_fn)(void *context);
  62. /*
  63. * A function to get the id of the thread associated with a given zone.
  64. * @context: The action context
  65. * @zone_number: The number of the zone for which the thread ID is desired
  66. */
  67. typedef thread_id_t (*vdo_zone_thread_getter_fn)(void *context, zone_count_t zone_number);
  68. struct action_manager;
  69. int __must_check vdo_make_action_manager(zone_count_t zones,
  70. vdo_zone_thread_getter_fn get_zone_thread_id,
  71. thread_id_t initiator_thread_id, void *context,
  72. vdo_action_scheduler_fn scheduler,
  73. struct vdo *vdo,
  74. struct action_manager **manager_ptr);
  75. const struct admin_state_code *__must_check
  76. vdo_get_current_manager_operation(struct action_manager *manager);
  77. void * __must_check vdo_get_current_action_context(struct action_manager *manager);
  78. bool vdo_schedule_default_action(struct action_manager *manager);
  79. bool vdo_schedule_action(struct action_manager *manager, vdo_action_preamble_fn preamble,
  80. vdo_zone_action_fn action, vdo_action_conclusion_fn conclusion,
  81. struct vdo_completion *parent);
  82. bool vdo_schedule_operation(struct action_manager *manager,
  83. const struct admin_state_code *operation,
  84. vdo_action_preamble_fn preamble, vdo_zone_action_fn action,
  85. vdo_action_conclusion_fn conclusion,
  86. struct vdo_completion *parent);
  87. bool vdo_schedule_operation_with_context(struct action_manager *manager,
  88. const struct admin_state_code *operation,
  89. vdo_action_preamble_fn preamble,
  90. vdo_zone_action_fn action,
  91. vdo_action_conclusion_fn conclusion,
  92. void *context, struct vdo_completion *parent);
  93. #endif /* VDO_ACTION_MANAGER_H */