linux/drivers/md/dm-vdo/action-manager.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright 2023 Red Hat
 */

#include "action-manager.h"

#include "memory-alloc.h"
#include "permassert.h"

#include "admin-state.h"
#include "completion.h"
#include "status-codes.h"
#include "types.h"
#include "vdo.h"

/**
 * struct action - An action to be performed in each of a set of zones.
 * @in_use: Whether this structure is in use.
 * @operation: The admin operation associated with this action.
 * @preamble: The method to run on the initiator thread before the action is applied to each zone.
 * @zone_action: The action to be performed in each zone.
 * @conclusion: The method to run on the initiator thread after the action is applied to each zone.
 * @parent: The object to notify when the action is complete.
 * @context: The action specific context.
 * @next: The action to perform after this one.
 */
struct action {};

/**
 * struct action_manager - Definition of an action manager.
 * @completion: The completion for performing actions.
 * @state: The state of this action manager.
 * @actions: The two action slots.
 * @current_action: The current action slot.
 * @zones: The number of zones in which an action is to be applied.
 * @Scheduler: A function to schedule a default next action.
 * @get_zone_thread_id: A function to get the id of the thread on which to apply an action to a
 *                      zone.
 * @initiator_thread_id: The ID of the thread on which actions may be initiated.
 * @context: Opaque data associated with this action manager.
 * @acting_zone: The zone currently being acted upon.
 */
struct action_manager {};

static inline struct action_manager *as_action_manager(struct vdo_completion *completion)
{}

/* Implements vdo_action_scheduler_fn. */
static bool no_default_action(void *context __always_unused)
{}

/* Implements vdo_action_preamble_fn. */
static void no_preamble(void *context __always_unused, struct vdo_completion *completion)
{}

/* Implements vdo_action_conclusion_fn. */
static int no_conclusion(void *context __always_unused)
{}

/**
 * vdo_make_action_manager() - Make an action manager.
 * @zones: The number of zones to which actions will be applied.
 * @get_zone_thread_id: A function to get the thread id associated with a zone.
 * @initiator_thread_id: The thread on which actions may initiated.
 * @context: The object which holds the per-zone context for the action.
 * @scheduler: A function to schedule a next action after an action concludes if there is no
 *             pending action (may be NULL).
 * @vdo: The vdo used to initialize completions.
 * @manager_ptr: A pointer to hold the new action manager.
 *
 * Return: VDO_SUCCESS or an error code.
 */
int vdo_make_action_manager(zone_count_t zones,
			    vdo_zone_thread_getter_fn get_zone_thread_id,
			    thread_id_t initiator_thread_id, void *context,
			    vdo_action_scheduler_fn scheduler, struct vdo *vdo,
			    struct action_manager **manager_ptr)
{}

const struct admin_state_code *vdo_get_current_manager_operation(struct action_manager *manager)
{}

void *vdo_get_current_action_context(struct action_manager *manager)
{}

static void finish_action_callback(struct vdo_completion *completion);
static void apply_to_zone(struct vdo_completion *completion);

static thread_id_t get_acting_zone_thread_id(struct action_manager *manager)
{}

static void preserve_error(struct vdo_completion *completion)
{}

static void prepare_for_next_zone(struct action_manager *manager)
{}

static void prepare_for_conclusion(struct action_manager *manager)
{}

static void apply_to_zone(struct vdo_completion *completion)
{}

static void handle_preamble_error(struct vdo_completion *completion)
{}

static void launch_current_action(struct action_manager *manager)
{}

/**
 * vdo_schedule_default_action() - Attempt to schedule the default action.
 * @manager: The action manager.
 *
 * If the manager is not operating normally, the action will not be scheduled.
 *
 * Return: true if an action was scheduled.
 */
bool vdo_schedule_default_action(struct action_manager *manager)
{}

static void finish_action_callback(struct vdo_completion *completion)
{}

/**
 * vdo_schedule_action() - Schedule an action to be applied to all zones.
 * @manager: The action manager to schedule the action on.
 * @preamble: A method to be invoked on the initiator thread once this action is started but before
 *            applying to each zone; may be NULL.
 * @action: The action to apply to each zone; may be NULL.
 * @conclusion: A method to be invoked back on the initiator thread once the action has been
 *              applied to all zones; may be NULL.
 * @parent: The object to notify once the action is complete or if the action can not be scheduled;
 *          may be NULL.
 *
 * The action will be launched immediately if there is no current action, or as soon as the current
 * action completes. If there is already a pending action, this action will not be scheduled, and,
 * if it has a parent, that parent will be notified. At least one of the preamble, action, or
 * conclusion must not be NULL.
 *
 * Return: true if the action was scheduled.
 */
bool vdo_schedule_action(struct action_manager *manager, vdo_action_preamble_fn preamble,
			 vdo_zone_action_fn action, vdo_action_conclusion_fn conclusion,
			 struct vdo_completion *parent)
{}

/**
 * vdo_schedule_operation() - Schedule an operation to be applied to all zones.
 * @manager: The action manager to schedule the action on.
 * @operation: The operation this action will perform
 * @preamble: A method to be invoked on the initiator thread once this action is started but before
 *            applying to each zone; may be NULL.
 * @action: The action to apply to each zone; may be NULL.
 * @conclusion: A method to be invoked back on the initiator thread once the action has been
 *              applied to all zones; may be NULL.
 * @parent: The object to notify once the action is complete or if the action can not be scheduled;
 *          may be NULL.
 *
 * The operation's action will be launched immediately if there is no current action, or as soon as
 * the current action completes. If there is already a pending action, this operation will not be
 * scheduled, and, if it has a parent, that parent will be notified. At least one of the preamble,
 * action, or conclusion must not be NULL.
 *
 * Return: true if the action was scheduled.
 */
bool vdo_schedule_operation(struct action_manager *manager,
			    const struct admin_state_code *operation,
			    vdo_action_preamble_fn preamble, vdo_zone_action_fn action,
			    vdo_action_conclusion_fn conclusion,
			    struct vdo_completion *parent)
{}

/**
 * vdo_schedule_operation_with_context() - Schedule an operation on all zones.
 * @manager: The action manager to schedule the action on.
 * @operation: The operation this action will perform.
 * @preamble: A method to be invoked on the initiator thread once this action is started but before
 *            applying to each zone; may be NULL.
 * @action: The action to apply to each zone; may be NULL.
 * @conclusion: A method to be invoked back on the initiator thread once the action has been
 *              applied to all zones; may be NULL.
 * @context: An action-specific context which may be retrieved via
 *           vdo_get_current_action_context(); may be NULL.
 * @parent: The object to notify once the action is complete or if the action can not be scheduled;
 *          may be NULL.
 *
 * The operation's action will be launched immediately if there is no current action, or as soon as
 * the current action completes. If there is already a pending action, this operation will not be
 * scheduled, and, if it has a parent, that parent will be notified. At least one of the preamble,
 * action, or conclusion must not be NULL.
 *
 * Return: true if the action was scheduled
 */
bool vdo_schedule_operation_with_context(struct action_manager *manager,
					 const struct admin_state_code *operation,
					 vdo_action_preamble_fn preamble,
					 vdo_zone_action_fn action,
					 vdo_action_conclusion_fn conclusion,
					 void *context, struct vdo_completion *parent)
{}