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

Source file repositories/reference/linux-study-clean/drivers/md/dm-vdo/admin-state.c

File Facts

System
Linux kernel
Corpus path
drivers/md/dm-vdo/admin-state.c
Extension
.c
Size
18299 bytes
Lines
532
Domain
Driver Families
Bucket
drivers/md
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (initiator != NULL) {
			state->starting = true;
			initiator(state);
			state->starting = false;
			if (state->complete)
				vdo_finish_operation(state, VDO_SUCCESS);
		}

		return VDO_SUCCESS;
	}

	if (waiter != NULL)
		vdo_continue_completion(waiter, result);

	return result;
}

/**
 * start_operation() - Start an operation if it may be started given the current state.
 * @state: The current admin state.
 * @operation: The operation to be started.
 * @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: 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)
{
	return (begin_operation(state, operation, waiter, initiator) == VDO_SUCCESS);
}

/**
 * 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)
{
	int result;

	if (valid)
		return true;

	result = vdo_log_error_strerror(VDO_INVALID_ADMIN_STATE,
					"%s is not a %s", code->name, what);
	if (waiter != NULL)
		vdo_continue_completion(waiter, result);

	return false;
}

/**
 * assert_vdo_drain_operation() - Check that an operation is a drain.
 * @operation: The operation to check.
 * @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)
{
	return check_code(operation->draining, operation, "drain operation", waiter);
}

/**
 * vdo_start_draining() - Initiate a drain operation if the current state permits it.
 * @state: The current admin state.
 * @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)
{
	const struct admin_state_code *code = vdo_get_admin_state_code(state);

	if (!assert_vdo_drain_operation(operation, waiter))

Annotation

Implementation Notes