linux/drivers/md/dm-vdo/admin-state.c

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

#include "admin-state.h"

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

#include "completion.h"
#include "types.h"

static const struct admin_state_code VDO_CODE_NORMAL_OPERATION =;
const struct admin_state_code *VDO_ADMIN_STATE_NORMAL_OPERATION =;
static const struct admin_state_code VDO_CODE_OPERATING =;
const struct admin_state_code *VDO_ADMIN_STATE_OPERATING =;
static const struct admin_state_code VDO_CODE_FORMATTING =;
const struct admin_state_code *VDO_ADMIN_STATE_FORMATTING =;
static const struct admin_state_code VDO_CODE_PRE_LOADING =;
const struct admin_state_code *VDO_ADMIN_STATE_PRE_LOADING =;
static const struct admin_state_code VDO_CODE_PRE_LOADED =;
const struct admin_state_code *VDO_ADMIN_STATE_PRE_LOADED =;
static const struct admin_state_code VDO_CODE_LOADING =;
const struct admin_state_code *VDO_ADMIN_STATE_LOADING =;
static const struct admin_state_code VDO_CODE_LOADING_FOR_RECOVERY =;
const struct admin_state_code *VDO_ADMIN_STATE_LOADING_FOR_RECOVERY =;
static const struct admin_state_code VDO_CODE_LOADING_FOR_REBUILD =;
const struct admin_state_code *VDO_ADMIN_STATE_LOADING_FOR_REBUILD =;
static const struct admin_state_code VDO_CODE_WAITING_FOR_RECOVERY =;
const struct admin_state_code *VDO_ADMIN_STATE_WAITING_FOR_RECOVERY =;
static const struct admin_state_code VDO_CODE_NEW =;
const struct admin_state_code *VDO_ADMIN_STATE_NEW =;
static const struct admin_state_code VDO_CODE_INITIALIZED =;
const struct admin_state_code *VDO_ADMIN_STATE_INITIALIZED =;
static const struct admin_state_code VDO_CODE_RECOVERING =;
const struct admin_state_code *VDO_ADMIN_STATE_RECOVERING =;
static const struct admin_state_code VDO_CODE_REBUILDING =;
const struct admin_state_code *VDO_ADMIN_STATE_REBUILDING =;
static const struct admin_state_code VDO_CODE_SAVING =;
const struct admin_state_code *VDO_ADMIN_STATE_SAVING =;
static const struct admin_state_code VDO_CODE_SAVED =;
const struct admin_state_code *VDO_ADMIN_STATE_SAVED =;
static const struct admin_state_code VDO_CODE_SCRUBBING =;
const struct admin_state_code *VDO_ADMIN_STATE_SCRUBBING =;
static const struct admin_state_code VDO_CODE_SAVE_FOR_SCRUBBING =;
const struct admin_state_code *VDO_ADMIN_STATE_SAVE_FOR_SCRUBBING =;
static const struct admin_state_code VDO_CODE_STOPPING =;
const struct admin_state_code *VDO_ADMIN_STATE_STOPPING =;
static const struct admin_state_code VDO_CODE_STOPPED =;
const struct admin_state_code *VDO_ADMIN_STATE_STOPPED =;
static const struct admin_state_code VDO_CODE_SUSPENDING =;
const struct admin_state_code *VDO_ADMIN_STATE_SUSPENDING =;
static const struct admin_state_code VDO_CODE_SUSPENDED =;
const struct admin_state_code *VDO_ADMIN_STATE_SUSPENDED =;
static const struct admin_state_code VDO_CODE_SUSPENDED_OPERATION =;
const struct admin_state_code *VDO_ADMIN_STATE_SUSPENDED_OPERATION =;
static const struct admin_state_code VDO_CODE_RESUMING =;
const struct admin_state_code *VDO_ADMIN_STATE_RESUMING =;

/**
 * get_next_state() - Determine the state which should be set after a given operation completes
 *                    based on the operation and the current state.
 * @operation The operation to be started.
 *
 * Return: The state to set when the operation completes or NULL if the operation can not be
 *         started in the current state.
 */
static const struct admin_state_code *get_next_state(const struct admin_state *state,
						     const struct admin_state_code *operation)
{}

/**
 * vdo_finish_operation() - Finish the current operation.
 *
 * Will notify the operation waiter if there is one. This method should be used for operations
 * started with vdo_start_operation(). For operations which were started with vdo_start_draining(),
 * use vdo_finish_draining() instead.
 *
 * Return: true if there was an operation to finish.
 */
bool vdo_finish_operation(struct admin_state *state, int result)
{}

/**
 * begin_operation() - Begin an operation if it may be started given the current state.
 * @waiter A completion to notify when the operation is complete; may be NULL.
 * @initiator The vdo_admin_initiator_fn to call if the operation may begin; may be NULL.
 *
 * Return: VDO_SUCCESS or an error.
 */
static int __must_check begin_operation(struct admin_state *state,
					const struct admin_state_code *operation,
					struct vdo_completion *waiter,
					vdo_admin_initiator_fn initiator)
{}

/**
 * start_operation() - Start an operation if it may be started given the current state.
 * @waiter     A completion to notify when the operation is complete.
 * @initiator The vdo_admin_initiator_fn to call if the operation may begin; may be NULL.
 *
 * Return: true if the operation was started.
 */
static inline bool __must_check start_operation(struct admin_state *state,
						const struct admin_state_code *operation,
						struct vdo_completion *waiter,
						vdo_admin_initiator_fn initiator)
{}

/**
 * check_code() - Check the result of a state validation.
 * @valid true if the code is of an appropriate type.
 * @code The code which failed to be of the correct type.
 * @what What the code failed to be, for logging.
 * @waiter The completion to notify of the error; may be NULL.
 *
 * If the result failed, log an invalid state error and, if there is a waiter, notify it.
 *
 * Return: The result of the check.
 */
static bool check_code(bool valid, const struct admin_state_code *code, const char *what,
		       struct vdo_completion *waiter)
{}

/**
 * assert_vdo_drain_operation() - Check that an operation is a drain.
 * @waiter The completion to finish with an error if the operation is not a drain.
 *
 * Return: true if the specified operation is a drain.
 */
static bool __must_check assert_vdo_drain_operation(const struct admin_state_code *operation,
						    struct vdo_completion *waiter)
{}

/**
 * vdo_start_draining() - Initiate a drain operation if the current state permits it.
 * @operation The type of drain to initiate.
 * @waiter The completion to notify when the drain is complete.
 * @initiator The vdo_admin_initiator_fn to call if the operation may begin; may be NULL.
 *
 * Return: true if the drain was initiated, if not the waiter will be notified.
 */
bool vdo_start_draining(struct admin_state *state,
			const struct admin_state_code *operation,
			struct vdo_completion *waiter, vdo_admin_initiator_fn initiator)
{}

/**
 * vdo_finish_draining() - Finish a drain operation if one was in progress.
 *
 * Return: true if the state was draining; will notify the waiter if so.
 */
bool vdo_finish_draining(struct admin_state *state)
{}

/**
 * vdo_finish_draining_with_result() - Finish a drain operation with a status code.
 *
 * Return: true if the state was draining; will notify the waiter if so.
 */
bool vdo_finish_draining_with_result(struct admin_state *state, int result)
{}

/**
 * vdo_assert_load_operation() - Check that an operation is a load.
 * @waiter The completion to finish with an error if the operation is not a load.
 *
 * Return: true if the specified operation is a load.
 */
bool vdo_assert_load_operation(const struct admin_state_code *operation,
			       struct vdo_completion *waiter)
{}

/**
 * vdo_start_loading() - Initiate a load operation if the current state permits it.
 * @operation The type of load to initiate.
 * @waiter The completion to notify when the load is complete (may be NULL).
 * @initiator The vdo_admin_initiator_fn to call if the operation may begin; may be NULL.
 *
 * Return: true if the load was initiated, if not the waiter will be notified.
 */
bool vdo_start_loading(struct admin_state *state,
		       const struct admin_state_code *operation,
		       struct vdo_completion *waiter, vdo_admin_initiator_fn initiator)
{}

/**
 * vdo_finish_loading() - Finish a load operation if one was in progress.
 *
 * Return: true if the state was loading; will notify the waiter if so.
 */
bool vdo_finish_loading(struct admin_state *state)
{}

/**
 * vdo_finish_loading_with_result() - Finish a load operation with a status code.
 * @result The result of the load operation.
 *
 * Return: true if the state was loading; will notify the waiter if so.
 */
bool vdo_finish_loading_with_result(struct admin_state *state, int result)
{}

/**
 * assert_vdo_resume_operation() - Check whether an admin_state_code is a resume operation.
 * @waiter The completion to notify if the operation is not a resume operation; may be NULL.
 *
 * Return: true if the code is a resume operation.
 */
static bool __must_check assert_vdo_resume_operation(const struct admin_state_code *operation,
						     struct vdo_completion *waiter)
{}

/**
 * vdo_start_resuming() - Initiate a resume operation if the current state permits it.
 * @operation The type of resume to start.
 * @waiter The completion to notify when the resume is complete (may be NULL).
 * @initiator The vdo_admin_initiator_fn to call if the operation may begin; may be NULL.
 *
 * Return: true if the resume was initiated, if not the waiter will be notified.
 */
bool vdo_start_resuming(struct admin_state *state,
			const struct admin_state_code *operation,
			struct vdo_completion *waiter, vdo_admin_initiator_fn initiator)
{}

/**
 * vdo_finish_resuming() - Finish a resume operation if one was in progress.
 *
 * Return: true if the state was resuming; will notify the waiter if so.
 */
bool vdo_finish_resuming(struct admin_state *state)
{}

/**
 * vdo_finish_resuming_with_result() - Finish a resume operation with a status code.
 * @result The result of the resume operation.
 *
 * Return: true if the state was resuming; will notify the waiter if so.
 */
bool vdo_finish_resuming_with_result(struct admin_state *state, int result)
{}

/**
 * vdo_resume_if_quiescent() - Change the state to normal operation if the current state is
 *                             quiescent.
 *
 * Return: VDO_SUCCESS if the state resumed, VDO_INVALID_ADMIN_STATE otherwise.
 */
int vdo_resume_if_quiescent(struct admin_state *state)
{}

/**
 * vdo_start_operation() - Attempt to start an operation.
 *
 * Return: VDO_SUCCESS if the operation was started, VDO_INVALID_ADMIN_STATE if not
 */
int vdo_start_operation(struct admin_state *state,
			const struct admin_state_code *operation)
{}

/**
 * vdo_start_operation_with_waiter() - Attempt to start an operation.
 * @waiter the completion to notify when the operation completes or fails to start; may be NULL.
 * @initiator The vdo_admin_initiator_fn to call if the operation may begin; may be NULL.
 *
 * Return: VDO_SUCCESS if the operation was started, VDO_INVALID_ADMIN_STATE if not
 */
int vdo_start_operation_with_waiter(struct admin_state *state,
				    const struct admin_state_code *operation,
				    struct vdo_completion *waiter,
				    vdo_admin_initiator_fn initiator)
{}