|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
b3514a |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
b3514a |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
b3514a |
* of the License, or (at your option) any later version.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
b3514a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b3514a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
b3514a |
* GNU General Public License for more details.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
b3514a |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
b3514a |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
b3514a |
* 02110-1301, USA.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/kernelVDO.c#7 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "kernelVDOInternals.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include <linux/delay.h>
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "memoryAlloc.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "statistics.h"
|
|
Packit Service |
b3514a |
#include "threadConfig.h"
|
|
Packit Service |
b3514a |
#include "vdo.h"
|
|
Packit Service |
b3514a |
#include "vdoDebug.h"
|
|
Packit Service |
b3514a |
#include "vdoLoad.h"
|
|
Packit Service |
b3514a |
#include "vdoResize.h"
|
|
Packit Service |
b3514a |
#include "vdoResizeLogical.h"
|
|
Packit Service |
b3514a |
#include "vdoResume.h"
|
|
Packit Service |
b3514a |
#include "vdoSuspend.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "kernelLayer.h"
|
|
Packit Service |
b3514a |
#include "kvio.h"
|
|
Packit Service |
b3514a |
#include "logger.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
enum { PARANOID_THREAD_CONSISTENCY_CHECKS = 0 };
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static void startKVDORequestQueue(void *ptr)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
KVDOThread *thread = ptr;
|
|
Packit Service |
b3514a |
KVDO *kvdo = thread->kvdo;
|
|
Packit Service |
b3514a |
KernelLayer *layer = container_of(kvdo, KernelLayer, kvdo);
|
|
Packit Service |
b3514a |
registerAllocatingThread(&thread->allocatingThread,
|
|
Packit Service |
b3514a |
&layer->allocationsAllowed);
|
|
Packit Service |
b3514a |
setWorkQueuePrivateData(thread);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static void finishKVDORequestQueue(void *ptr)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
unregisterAllocatingThread();
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static const KvdoWorkQueueType requestQueueType = {
|
|
Packit Service |
b3514a |
.start = startKVDORequestQueue,
|
|
Packit Service |
b3514a |
.finish = finishKVDORequestQueue,
|
|
Packit Service |
b3514a |
.actionTable = {
|
|
Packit Service |
b3514a |
{ .name = "req_completion",
|
|
Packit Service |
b3514a |
.code = REQ_Q_ACTION_COMPLETION,
|
|
Packit Service |
b3514a |
.priority = 1 },
|
|
Packit Service |
b3514a |
{ .name = "req_flush",
|
|
Packit Service |
b3514a |
.code = REQ_Q_ACTION_FLUSH,
|
|
Packit Service |
b3514a |
.priority = 2 },
|
|
Packit Service |
b3514a |
{ .name = "req_map_bio",
|
|
Packit Service |
b3514a |
.code = REQ_Q_ACTION_MAP_BIO,
|
|
Packit Service |
b3514a |
.priority = 0 },
|
|
Packit Service |
b3514a |
{ .name = "req_sync",
|
|
Packit Service |
b3514a |
.code = REQ_Q_ACTION_SYNC,
|
|
Packit Service |
b3514a |
.priority = 2 },
|
|
Packit Service |
b3514a |
{ .name = "req_vio_callback",
|
|
Packit Service |
b3514a |
.code = REQ_Q_ACTION_VIO_CALLBACK,
|
|
Packit Service |
b3514a |
.priority = 1 },
|
|
Packit Service |
b3514a |
},
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int initializeKVDO(KVDO *kvdo,
|
|
Packit Service |
b3514a |
const ThreadConfig *threadConfig,
|
|
Packit Service |
b3514a |
char **reason)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
unsigned int baseThreads = threadConfig->baseThreadCount;
|
|
Packit Service |
b3514a |
int result = ALLOCATE(baseThreads, KVDOThread,
|
|
Packit Service |
b3514a |
"request processing work queue",
|
|
Packit Service |
b3514a |
&kvdo->threads);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
*reason = "Cannot allocation thread structures";
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
KernelLayer *layer = container_of(kvdo, KernelLayer, kvdo);
|
|
Packit Service |
b3514a |
for (kvdo->initializedThreadCount = 0;
|
|
Packit Service |
b3514a |
kvdo->initializedThreadCount < baseThreads;
|
|
Packit Service |
b3514a |
kvdo->initializedThreadCount++) {
|
|
Packit Service |
b3514a |
KVDOThread *thread = &kvdo->threads[kvdo->initializedThreadCount];
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
thread->kvdo = kvdo;
|
|
Packit Service |
b3514a |
thread->threadID = kvdo->initializedThreadCount;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
char queueName[MAX_QUEUE_NAME_LEN];
|
|
Packit Service |
b3514a |
// Copy only LEN - 1 bytes and ensure NULL termination.
|
|
Packit Service |
b3514a |
getVDOThreadName(threadConfig, kvdo->initializedThreadCount,
|
|
Packit Service |
b3514a |
queueName, sizeof(queueName));
|
|
Packit Service |
b3514a |
int result = makeWorkQueue(layer->threadNamePrefix, queueName,
|
|
Packit Service |
b3514a |
&layer->wqDirectory, layer, thread,
|
|
Packit Service |
b3514a |
&requestQueueType, 1, &thread->requestQueue);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
*reason = "Cannot initialize request queue";
|
|
Packit Service |
b3514a |
while (kvdo->initializedThreadCount > 0) {
|
|
Packit Service |
b3514a |
unsigned int threadToDestroy = kvdo->initializedThreadCount - 1;
|
|
Packit Service |
b3514a |
thread = &kvdo->threads[threadToDestroy];
|
|
Packit Service |
b3514a |
finishWorkQueue(thread->requestQueue);
|
|
Packit Service |
b3514a |
freeWorkQueue(&thread->requestQueue);
|
|
Packit Service |
b3514a |
kvdo->initializedThreadCount--;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
FREE(kvdo->threads);
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int preloadKVDO(KVDO *kvdo,
|
|
Packit Service |
b3514a |
PhysicalLayer *common,
|
|
Packit Service |
b3514a |
const VDOLoadConfig *loadConfig,
|
|
Packit Service |
b3514a |
bool vioTraceRecording,
|
|
Packit Service |
b3514a |
char **reason)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
KernelLayer *layer = asKernelLayer(common);
|
|
Packit Service |
b3514a |
init_completion(&layer->callbackSync);
|
|
Packit Service |
b3514a |
int result = prepareToLoadVDO(kvdo->vdo, loadConfig);
|
|
Packit Service |
b3514a |
if ((result != VDO_SUCCESS) && (result != VDO_READ_ONLY)) {
|
|
Packit Service |
b3514a |
*reason = "Cannot load metadata from device";
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
setVDOTracingFlags(kvdo->vdo, vioTraceRecording);
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int startKVDO(KVDO *kvdo, PhysicalLayer *common, char **reason)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
KernelLayer *layer = asKernelLayer(common);
|
|
Packit Service |
b3514a |
init_completion(&layer->callbackSync);
|
|
Packit Service |
b3514a |
int result = performVDOLoad(kvdo->vdo);
|
|
Packit Service |
b3514a |
if ((result != VDO_SUCCESS) && (result != VDO_READ_ONLY)) {
|
|
Packit Service |
b3514a |
*reason = "Cannot load metadata from device";
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int suspendKVDO(KVDO *kvdo)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if (kvdo->vdo == NULL) {
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
KernelLayer *layer = container_of(kvdo, KernelLayer, kvdo);
|
|
Packit Service |
b3514a |
init_completion(&layer->callbackSync);
|
|
Packit Service |
b3514a |
int result = performVDOSuspend(kvdo->vdo, !layer->noFlushSuspend);
|
|
Packit Service |
b3514a |
if ((result != VDO_SUCCESS) && (result != VDO_READ_ONLY)) {
|
|
Packit Service |
b3514a |
char errorName[80] = "";
|
|
Packit Service |
b3514a |
char errorMessage[ERRBUF_SIZE] = "";
|
|
Packit Service |
b3514a |
logError("%s: Suspend device failed %d (%s: %s)",
|
|
Packit Service |
b3514a |
__func__, result,
|
|
Packit Service |
b3514a |
stringErrorName(result, errorName, sizeof(errorName)),
|
|
Packit Service |
b3514a |
stringError(result, errorMessage, sizeof(errorMessage)));
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Convert VDO_READ_ONLY to VDO_SUCCESS since a read-only suspension still
|
|
Packit Service |
b3514a |
// leaves the VDO suspended.
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int resumeKVDO(KVDO *kvdo)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
if (kvdo->vdo == NULL) {
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
KernelLayer *layer = container_of(kvdo, KernelLayer, kvdo);
|
|
Packit Service |
b3514a |
init_completion(&layer->callbackSync);
|
|
Packit Service |
b3514a |
return performVDOResume(kvdo->vdo);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void finishKVDO(KVDO *kvdo)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
for (int i = 0; i < kvdo->initializedThreadCount; i++) {
|
|
Packit Service |
b3514a |
finishWorkQueue(kvdo->threads[i].requestQueue);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void destroyKVDO(KVDO *kvdo)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
destroyVDO(kvdo->vdo);
|
|
Packit Service |
b3514a |
for (int i = 0; i < kvdo->initializedThreadCount; i++) {
|
|
Packit Service |
b3514a |
freeWorkQueue(&kvdo->threads[i].requestQueue);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
FREE(kvdo->threads);
|
|
Packit Service |
b3514a |
kvdo->threads = NULL;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void dumpKVDOWorkQueue(KVDO *kvdo)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
for (int i = 0; i < kvdo->initializedThreadCount; i++) {
|
|
Packit Service |
b3514a |
dumpWorkQueue(kvdo->threads[i].requestQueue);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
typedef struct {
|
|
Packit Service |
b3514a |
KvdoWorkItem workItem;
|
|
Packit Service |
b3514a |
KVDO *kvdo;
|
|
Packit Service |
b3514a |
void *data;
|
|
Packit Service |
b3514a |
struct completion *completion;
|
|
Packit Service |
b3514a |
} SyncQueueWork;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Initiate an arbitrary asynchronous base-code operation and wait for
|
|
Packit Service |
b3514a |
* it.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* An async queue operation is performed and we wait for completion.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param kvdo The kvdo data handle
|
|
Packit Service |
b3514a |
* @param action The operation to perform
|
|
Packit Service |
b3514a |
* @param data Unique data that can be used by the operation
|
|
Packit Service |
b3514a |
* @param threadID The thread on which to perform the operation
|
|
Packit Service |
b3514a |
* @param completion The completion to wait on
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS of an error code
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void performKVDOOperation(KVDO *kvdo,
|
|
Packit Service |
b3514a |
KvdoWorkFunction action,
|
|
Packit Service |
b3514a |
void *data,
|
|
Packit Service |
b3514a |
ThreadID threadID,
|
|
Packit Service |
b3514a |
struct completion *completion)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SyncQueueWork sync;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
memset(&sync, 0, sizeof(sync));
|
|
Packit Service |
b3514a |
setupWorkItem(&sync.workItem, action, NULL, REQ_Q_ACTION_SYNC);
|
|
Packit Service |
b3514a |
sync.kvdo = kvdo;
|
|
Packit Service |
b3514a |
sync.data = data;
|
|
Packit Service |
b3514a |
sync.completion = completion;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
init_completion(completion);
|
|
Packit Service |
b3514a |
enqueueKVDOWork(kvdo, &sync.workItem, threadID);
|
|
Packit Service |
b3514a |
wait_for_completion(completion);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
typedef struct {
|
|
Packit Service |
b3514a |
bool enable;
|
|
Packit Service |
b3514a |
bool wasEnabled;
|
|
Packit Service |
b3514a |
} VDOCompressData;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Does the work of calling the base code to set compress state, then
|
|
Packit Service |
b3514a |
* tells the function waiting on completion to go ahead.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param item The work item
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void setCompressingWork(KvdoWorkItem *item)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SyncQueueWork *work = container_of(item, SyncQueueWork, workItem);
|
|
Packit Service |
b3514a |
VDOCompressData *data = (VDOCompressData *)work->data;
|
|
Packit Service |
b3514a |
data->wasEnabled = setVDOCompressing(getVDO(work->kvdo), data->enable);
|
|
Packit Service |
b3514a |
complete(work->completion);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/***********************************************************************/
|
|
Packit Service |
b3514a |
bool setKVDOCompressing(KVDO *kvdo, bool enableCompression)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
struct completion compressWait;
|
|
Packit Service |
b3514a |
VDOCompressData data;
|
|
Packit Service |
b3514a |
data.enable = enableCompression;
|
|
Packit Service |
b3514a |
performKVDOOperation(kvdo, setCompressingWork, &data,
|
|
Packit Service |
b3514a |
getPackerZoneThread(getThreadConfig(kvdo->vdo)),
|
|
Packit Service |
b3514a |
&compressWait);
|
|
Packit Service |
b3514a |
return data.wasEnabled;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
typedef struct {
|
|
Packit Service |
b3514a |
int result;
|
|
Packit Service |
b3514a |
} VDOReadOnlyData;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static void enterReadOnlyModeWork(KvdoWorkItem *item)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SyncQueueWork *work = container_of(item, SyncQueueWork, workItem);
|
|
Packit Service |
b3514a |
VDOReadOnlyData *data = work->data;
|
|
Packit Service |
b3514a |
makeVDOReadOnly(getVDO(work->kvdo), data->result);
|
|
Packit Service |
b3514a |
complete(work->completion);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/***********************************************************************/
|
|
Packit Service |
b3514a |
void setKVDOReadOnly(KVDO *kvdo, int result)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
struct completion readOnlyWait;
|
|
Packit Service |
b3514a |
VDOReadOnlyData data;
|
|
Packit Service |
b3514a |
data.result = result;
|
|
Packit Service |
b3514a |
performKVDOOperation(kvdo, enterReadOnlyModeWork, &data,
|
|
Packit Service |
b3514a |
getAdminThread(getThreadConfig(kvdo->vdo)),
|
|
Packit Service |
b3514a |
&readOnlyWait);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Does the work of calling the vdo statistics gathering tool
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param item The work item
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void getVDOStatisticsWork(KvdoWorkItem *item)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SyncQueueWork *work = container_of(item, SyncQueueWork, workItem);
|
|
Packit Service |
b3514a |
VDOStatistics *stats = (VDOStatistics *)work->data;
|
|
Packit Service |
b3514a |
getVDOStatistics(getVDO(work->kvdo), stats);
|
|
Packit Service |
b3514a |
complete(work->completion);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/***********************************************************************/
|
|
Packit Service |
b3514a |
void getKVDOStatistics(KVDO *kvdo, VDOStatistics *stats)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
struct completion statsWait;
|
|
Packit Service |
b3514a |
memset(stats, 0, sizeof(VDOStatistics));
|
|
Packit Service |
b3514a |
performKVDOOperation(kvdo, getVDOStatisticsWork, stats,
|
|
Packit Service |
b3514a |
getAdminThread(getThreadConfig(kvdo->vdo)),
|
|
Packit Service |
b3514a |
&statsWait);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* A structure to invoke an arbitrary VDO action.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
typedef struct vdoActionData {
|
|
Packit Service |
b3514a |
VDOAction *action;
|
|
Packit Service |
b3514a |
VDOCompletion *vdoCompletion;
|
|
Packit Service |
b3514a |
struct completion waiter;
|
|
Packit Service |
b3514a |
} VDOActionData;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Initialize a VDOActionData structure so that the specified action
|
|
Packit Service |
b3514a |
* can be invoked on the specified completion.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param data A VDOActionData.
|
|
Packit Service |
b3514a |
* @param action The VDOAction to execute.
|
|
Packit Service |
b3514a |
* @param vdoCompletion The VDO completion upon which the action acts.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void initializeVDOActionData(VDOActionData *data,
|
|
Packit Service |
b3514a |
VDOAction *action,
|
|
Packit Service |
b3514a |
VDOCompletion *vdoCompletion)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
*data = (VDOActionData) {
|
|
Packit Service |
b3514a |
.action = action,
|
|
Packit Service |
b3514a |
.vdoCompletion = vdoCompletion,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* The VDO callback that completes the KVDO completion.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param vdoCompletion The VDO completion which was acted upon.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void finishVDOAction(VDOCompletion *vdoCompletion)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SyncQueueWork *work = vdoCompletion->parent;
|
|
Packit Service |
b3514a |
complete(work->completion);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Perform a VDO base code action as specified by a VDOActionData.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Sets the completion callback and parent inside the VDOActionData
|
|
Packit Service |
b3514a |
* so that the corresponding kernel completion is completed when
|
|
Packit Service |
b3514a |
* the VDO completion is.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param item A KVDO work queue item.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static void performVDOActionWork(KvdoWorkItem *item)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
SyncQueueWork *work = container_of(item, SyncQueueWork, workItem);
|
|
Packit Service |
b3514a |
VDOActionData *data = work->data;
|
|
Packit Service |
b3514a |
ThreadID id = getPhysicalLayer()->getCurrentThreadID();
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
setCallbackWithParent(data->vdoCompletion, finishVDOAction, id, work);
|
|
Packit Service |
b3514a |
data->action(data->vdoCompletion);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int performKVDOExtendedCommand(KVDO *kvdo, int argc, char **argv)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
VDOActionData data;
|
|
Packit Service |
b3514a |
VDOCommandCompletion cmd;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
int result = initializeVDOCommandCompletion(&cmd, getVDO(kvdo), argc, argv);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
initializeVDOActionData(&data, executeVDOExtendedCommand, &cmd.completion);
|
|
Packit Service |
b3514a |
performKVDOOperation(kvdo, performVDOActionWork, &data,
|
|
Packit Service |
b3514a |
getAdminThread(getThreadConfig(kvdo->vdo)),
|
|
Packit Service |
b3514a |
&data.waiter);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
return destroyVDOCommandCompletion(&cmd);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void dumpKVDOStatus(KVDO *kvdo)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
dumpVDOStatus(kvdo->vdo);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
bool getKVDOCompressing(KVDO *kvdo)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return getVDOCompressing(kvdo->vdo);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int kvdoPrepareToGrowPhysical(KVDO *kvdo, BlockCount physicalCount)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
VDO *vdo = kvdo->vdo;
|
|
Packit Service |
b3514a |
return prepareToGrowPhysical(vdo, physicalCount);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int kvdoResizePhysical(KVDO *kvdo, BlockCount physicalCount)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
KernelLayer *layer = container_of(kvdo, KernelLayer, kvdo);
|
|
Packit Service |
b3514a |
init_completion(&layer->callbackSync);
|
|
Packit Service |
b3514a |
int result = performGrowPhysical(kvdo->vdo, physicalCount);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
logError("resize operation failed, result = %d", result);
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
return VDO_SUCCESS;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int kvdoPrepareToGrowLogical(KVDO *kvdo, BlockCount logicalCount)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
VDO *vdo = kvdo->vdo;
|
|
Packit Service |
b3514a |
return prepareToGrowLogical(vdo, logicalCount);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
int kvdoResizeLogical(KVDO *kvdo, BlockCount logicalCount)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
KernelLayer *layer = container_of(kvdo, KernelLayer, kvdo);
|
|
Packit Service |
b3514a |
init_completion(&layer->callbackSync);
|
|
Packit Service |
b3514a |
int result = performGrowLogical(kvdo->vdo, logicalCount);
|
|
Packit Service |
b3514a |
if (result != VDO_SUCCESS) {
|
|
Packit Service |
b3514a |
logError("grow logical operation failed, result = %d", result);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
return result;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
WritePolicy getKVDOWritePolicy(KVDO *kvdo)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return getWritePolicy(kvdo->vdo);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void enqueueKVDOThreadWork(KVDOThread *thread,
|
|
Packit Service |
b3514a |
KvdoWorkItem *item)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
enqueueWorkQueue(thread->requestQueue, item);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void enqueueKVDOWork(KVDO *kvdo, KvdoWorkItem *item, ThreadID threadID)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
enqueueKVDOThreadWork(&kvdo->threads[threadID], item);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void enqueueKVIO(KVIO *kvio,
|
|
Packit Service |
b3514a |
KvdoWorkFunction work,
|
|
Packit Service |
b3514a |
void *statsFunction,
|
|
Packit Service |
b3514a |
unsigned int action)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
ThreadID threadID = vioAsCompletion(kvio->vio)->callbackThreadID;
|
|
Packit Service |
b3514a |
BUG_ON(threadID >= kvio->layer->kvdo.initializedThreadCount);
|
|
Packit Service |
b3514a |
launchKVIO(kvio, work, statsFunction, action,
|
|
Packit Service |
b3514a |
kvio->layer->kvdo.threads[threadID].requestQueue);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static void kvdoEnqueueWork(KvdoWorkItem *workItem)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
KvdoEnqueueable *kvdoEnqueueable = container_of(workItem,
|
|
Packit Service |
b3514a |
KvdoEnqueueable,
|
|
Packit Service |
b3514a |
workItem);
|
|
Packit Service |
b3514a |
runCallback(kvdoEnqueueable->enqueueable.completion);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
void kvdoEnqueue(Enqueueable *enqueueable)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
KvdoEnqueueable *kvdoEnqueueable = container_of(enqueueable,
|
|
Packit Service |
b3514a |
KvdoEnqueueable,
|
|
Packit Service |
b3514a |
enqueueable);
|
|
Packit Service |
b3514a |
KernelLayer *layer = asKernelLayer(enqueueable->completion->layer);
|
|
Packit Service |
b3514a |
ThreadID threadID = enqueueable->completion->callbackThreadID;
|
|
Packit Service |
b3514a |
if (ASSERT(threadID < layer->kvdo.initializedThreadCount,
|
|
Packit Service |
b3514a |
"threadID %u (completion type %d) is less than thread count %u",
|
|
Packit Service |
b3514a |
threadID, enqueueable->completion->type,
|
|
Packit Service |
b3514a |
layer->kvdo.initializedThreadCount) != UDS_SUCCESS) {
|
|
Packit Service |
b3514a |
BUG();
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
if (enqueueable->completion->type == VIO_COMPLETION) {
|
|
Packit Service |
b3514a |
vioAddTraceRecord(asVIO(enqueueable->completion),
|
|
Packit Service |
b3514a |
THIS_LOCATION("$F($cb)"));
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
setupWorkItem(&kvdoEnqueueable->workItem, kvdoEnqueueWork,
|
|
Packit Service |
b3514a |
(KvdoWorkFunction) enqueueable->completion->callback,
|
|
Packit Service |
b3514a |
REQ_Q_ACTION_COMPLETION);
|
|
Packit Service |
b3514a |
enqueueKVDOThreadWork(&layer->kvdo.threads[threadID],
|
|
Packit Service |
b3514a |
&kvdoEnqueueable->workItem);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
ThreadID kvdoGetCurrentThreadID(void)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
KVDOThread *thread = getWorkQueuePrivateData();
|
|
Packit Service |
b3514a |
if (thread == NULL) {
|
|
Packit Service |
b3514a |
return INVALID_THREAD_ID;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
ThreadID threadID = thread->threadID;
|
|
Packit Service |
b3514a |
if (PARANOID_THREAD_CONSISTENCY_CHECKS) {
|
|
Packit Service |
b3514a |
KVDO *kvdo = thread->kvdo;
|
|
Packit Service |
b3514a |
KernelLayer *kernelLayer = asKernelLayer(getPhysicalLayer());
|
|
Packit Service |
b3514a |
BUG_ON(&kernelLayer->kvdo != kvdo);
|
|
Packit Service |
b3514a |
BUG_ON(threadID >= kvdo->initializedThreadCount);
|
|
Packit Service |
b3514a |
BUG_ON(thread != &kvdo->threads[threadID]);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
return threadID;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**********************************************************************/
|
|
Packit Service |
b3514a |
static PhysicalLayer *getKernelPhysicalLayer(void)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
KVDOThread *thread = getWorkQueuePrivateData();
|
|
Packit Service |
b3514a |
if (thread == NULL) {
|
|
Packit Service |
b3514a |
return NULL;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
KVDO *kvdo = thread->kvdo;
|
|
Packit Service |
b3514a |
KernelLayer *layer = container_of(kvdo, KernelLayer, kvdo);
|
|
Packit Service |
b3514a |
return &layer->common;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
void initKernelVDOOnce(void)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
registerPhysicalLayerGetter(getKernelPhysicalLayer);
|
|
Packit Service |
b3514a |
}
|