|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/adminCompletion.h#4 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef ADMIN_COMPLETION_H
|
|
Packit Service |
310c69 |
#define ADMIN_COMPLETION_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "atomic.h"
|
|
Packit Service |
310c69 |
#include "completion.h"
|
|
Packit Service |
310c69 |
#include "types.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef enum adminOperationType {
|
|
Packit Service |
310c69 |
ADMIN_OPERATION_UNKNOWN = 0,
|
|
Packit Service |
310c69 |
ADMIN_OPERATION_GROW_LOGICAL,
|
|
Packit Service |
310c69 |
ADMIN_OPERATION_GROW_PHYSICAL,
|
|
Packit Service |
310c69 |
ADMIN_OPERATION_PREPARE_GROW_PHYSICAL,
|
|
Packit Service |
310c69 |
ADMIN_OPERATION_LOAD,
|
|
Packit Service |
310c69 |
ADMIN_OPERATION_RESUME,
|
|
Packit Service |
310c69 |
ADMIN_OPERATION_SAVE,
|
|
Packit Service |
310c69 |
ADMIN_OPERATION_SUSPEND,
|
|
Packit Service |
310c69 |
} AdminOperationType;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct adminCompletion AdminCompletion;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* A function which gets the ID of the thread on which the current phase of an
|
|
Packit Service |
310c69 |
* admin operation should be run.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param adminCompletion The AdminCompletion
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The ID of the thread on which the current phase should be performed
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef ThreadID ThreadIDGetterForPhase(AdminCompletion *adminCompletion);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
struct adminCompletion {
|
|
Packit Service |
310c69 |
/** The completion */
|
|
Packit Service |
310c69 |
VDOCompletion completion;
|
|
Packit Service |
310c69 |
/** The sub-task completion */
|
|
Packit Service |
310c69 |
VDOCompletion subTaskCompletion;
|
|
Packit Service |
310c69 |
/** Whether this completion is in use */
|
|
Packit Service |
310c69 |
AtomicBool busy;
|
|
Packit Service |
310c69 |
/** The operation type */
|
|
Packit Service |
310c69 |
AdminOperationType type;
|
|
Packit Service |
310c69 |
/** Method to get the ThreadID for the current phase */
|
|
Packit Service |
310c69 |
ThreadIDGetterForPhase *getThreadID;
|
|
Packit Service |
310c69 |
/** The current phase of the operation */
|
|
Packit Service |
310c69 |
uint32_t phase;
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Check that an AdminCompletion's type is as expected.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param completion The AdminCompletion to check
|
|
Packit Service |
310c69 |
* @param expected The expected type
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void assertAdminOperationType(AdminCompletion *completion,
|
|
Packit Service |
310c69 |
AdminOperationType expected);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Convert the sub-task completion of an AdminCompletion to an AdminCompletion.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param completion the AdminCompletion's sub-task completion
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The sub-task completion as its enclosing AdminCompletion
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
AdminCompletion *adminCompletionFromSubTask(VDOCompletion *completion)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Assert that we are operating on the correct thread for the current phase.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param adminCompletion The AdminCompletion to check
|
|
Packit Service |
310c69 |
* @param what The method doing the phase check
|
|
Packit Service |
310c69 |
* @param phaseNames The names of the phases of the current operation
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void assertAdminPhaseThread(AdminCompletion *adminCompletion,
|
|
Packit Service |
310c69 |
const char *what,
|
|
Packit Service |
310c69 |
const char *phaseNames[]);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the VDO from the sub-task completion of its AdminCompletion.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param completion the sub-task completion
|
|
Packit Service |
310c69 |
* @param expected the expected operation type of the AdminCompletion
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The VDO
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
VDO *vdoFromAdminSubTask(VDOCompletion *completion,
|
|
Packit Service |
310c69 |
AdminOperationType expected)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Initialize an admin completion.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param vdo The VDO which owns the completion
|
|
Packit Service |
310c69 |
* @param adminCompletion The AdminCompletion to initialize
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int initializeAdminCompletion(VDO *vdo, AdminCompletion *adminCompletion)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Clean up an admin completion's resources.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param adminCompletion The AdminCompletion to uninitialize
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void uninitializeAdminCompletion(AdminCompletion *adminCompletion);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Reset an AdminCompletion's sub-task completion.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param completion The AdminCompletion's sub-task completion
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The sub-task completion for the convenience of callers
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
VDOCompletion *resetAdminSubTask(VDOCompletion *completion);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Prepare the sub-task completion of a VDO's AdminCompletion
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param vdo The VDO
|
|
Packit Service |
310c69 |
* @param callback The callback for the sub-task
|
|
Packit Service |
310c69 |
* @param errorHandler The error handler for the sub-task
|
|
Packit Service |
310c69 |
* @param threadID The ID of the thread on which to run the callback
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void prepareAdminSubTaskOnThread(VDO *vdo,
|
|
Packit Service |
310c69 |
VDOAction *callback,
|
|
Packit Service |
310c69 |
VDOAction *errorHandler,
|
|
Packit Service |
310c69 |
ThreadID threadID);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Prepare the sub-task completion of a VDO's AdminCompletion to run on the
|
|
Packit Service |
310c69 |
* same thread as the AdminCompletion's main completion.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param vdo The VDO
|
|
Packit Service |
310c69 |
* @param callback The callback for the sub-task
|
|
Packit Service |
310c69 |
* @param errorHandler The error handler for the sub-task
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void prepareAdminSubTask(VDO *vdo,
|
|
Packit Service |
310c69 |
VDOAction *callback,
|
|
Packit Service |
310c69 |
VDOAction *errorHandler);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Perform an administrative operation (load, suspend, grow logical, or grow
|
|
Packit Service |
310c69 |
* physical). This method should not be called from base threads unless it is
|
|
Packit Service |
310c69 |
* certain the calling thread won't be needed to perform the operation. It may
|
|
Packit Service |
310c69 |
* (and should) be called from non-base threads.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param vdo The VDO on which to perform the operation
|
|
Packit Service |
310c69 |
* @param type The type of operation to perform
|
|
Packit Service |
310c69 |
* @param threadIDGetter A function for getting the ID of the thread on which
|
|
Packit Service |
310c69 |
* a given phase should be run
|
|
Packit Service |
310c69 |
* @param action The action which starts the operation
|
|
Packit Service |
310c69 |
* @param errorHandler The error handler for the operation
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The result of the operation
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int performAdminOperation(VDO *vdo,
|
|
Packit Service |
310c69 |
AdminOperationType type,
|
|
Packit Service |
310c69 |
ThreadIDGetterForPhase *threadIDGetter,
|
|
Packit Service |
310c69 |
VDOAction *action,
|
|
Packit Service |
310c69 |
VDOAction *errorHandler)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif /* ADMIN_COMPLETION_H */
|