|
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/kernelLayer.h#18 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#ifndef KERNELLAYER_H
|
|
Packit Service |
b3514a |
#define KERNELLAYER_H
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include <linux/device-mapper.h>
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "atomic.h"
|
|
Packit Service |
b3514a |
#include "constants.h"
|
|
Packit Service |
b3514a |
#include "flush.h"
|
|
Packit Service |
b3514a |
#include "intMap.h"
|
|
Packit Service |
b3514a |
#include "physicalLayer.h"
|
|
Packit Service |
b3514a |
#include "ringNode.h"
|
|
Packit Service |
b3514a |
#include "volumeGeometry.h"
|
|
Packit Service |
b3514a |
#include "waitQueue.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "batchProcessor.h"
|
|
Packit Service |
b3514a |
#include "bufferPool.h"
|
|
Packit Service |
b3514a |
#include "deadlockQueue.h"
|
|
Packit Service |
b3514a |
#include "deviceConfig.h"
|
|
Packit Service |
b3514a |
#include "histogram.h"
|
|
Packit Service |
b3514a |
#include "kernelStatistics.h"
|
|
Packit Service |
b3514a |
#include "kernelTypes.h"
|
|
Packit Service |
b3514a |
#include "kernelVDO.h"
|
|
Packit Service |
b3514a |
#include "ktrace.h"
|
|
Packit Service |
b3514a |
#include "limiter.h"
|
|
Packit Service |
b3514a |
#include "statistics.h"
|
|
Packit Service |
b3514a |
#include "workQueue.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
enum {
|
|
Packit Service |
b3514a |
VDO_SECTORS_PER_BLOCK = (VDO_BLOCK_SIZE >> SECTOR_SHIFT)
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef enum {
|
|
Packit Service |
b3514a |
LAYER_SIMPLE_THINGS_INITIALIZED,
|
|
Packit Service |
b3514a |
LAYER_BUFFER_POOLS_INITIALIZED,
|
|
Packit Service |
b3514a |
LAYER_REQUEST_QUEUE_INITIALIZED,
|
|
Packit Service |
b3514a |
LAYER_CPU_QUEUE_INITIALIZED,
|
|
Packit Service |
b3514a |
LAYER_BIO_ACK_QUEUE_INITIALIZED,
|
|
Packit Service |
b3514a |
LAYER_BIO_DATA_INITIALIZED,
|
|
Packit Service |
b3514a |
LAYER_STARTING,
|
|
Packit Service |
b3514a |
LAYER_RUNNING,
|
|
Packit Service |
b3514a |
LAYER_SUSPENDED,
|
|
Packit Service |
b3514a |
LAYER_STOPPING,
|
|
Packit Service |
b3514a |
LAYER_STOPPED,
|
|
Packit Service |
b3514a |
LAYER_RESUMING,
|
|
Packit Service |
b3514a |
} KernelLayerState;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/* Keep BIO statistics atomically */
|
|
Packit Service |
b3514a |
struct atomicBioStats {
|
|
Packit Service |
b3514a |
atomic64_t read; // Number of not REQ_WRITE bios
|
|
Packit Service |
b3514a |
atomic64_t write; // Number of REQ_WRITE bios
|
|
Packit Service |
b3514a |
atomic64_t discard; // Number of REQ_DISCARD bios
|
|
Packit Service |
b3514a |
atomic64_t flush; // Number of REQ_FLUSH bios
|
|
Packit Service |
b3514a |
atomic64_t fua; // Number of REQ_FUA bios
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Data managing the reporting of Albireo timeouts
|
|
Packit Service |
b3514a |
typedef struct periodicEventReporter {
|
|
Packit Service |
b3514a |
uint64_t lastReportedValue;
|
|
Packit Service |
b3514a |
const char *format;
|
|
Packit Service |
b3514a |
atomic64_t value;
|
|
Packit Service |
b3514a |
Jiffies reportingInterval; // jiffies
|
|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* Just an approximation. If nonzero, then either the work item has
|
|
Packit Service |
b3514a |
* been queued to run, or some other thread currently has
|
|
Packit Service |
b3514a |
* responsibility for enqueueing it, or the reporter function is
|
|
Packit Service |
b3514a |
* running but hasn't looked at the current value yet.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* If this is set, don't set the timer again, because we don't want
|
|
Packit Service |
b3514a |
* the work item queued twice. Use an atomic xchg or cmpxchg to
|
|
Packit Service |
b3514a |
* test-and-set it, and an atomic store to clear it.
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
atomic_t workItemQueued;
|
|
Packit Service |
b3514a |
KvdoWorkItem workItem;
|
|
Packit Service |
b3514a |
KernelLayer *layer;
|
|
Packit Service |
b3514a |
} PeriodicEventReporter;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
static inline uint64_t getEventCount(PeriodicEventReporter *reporter)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return atomic64_read(&reporter->value);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* The VDO representation of the target device
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
struct kernelLayer {
|
|
Packit Service |
b3514a |
PhysicalLayer common;
|
|
Packit Service |
b3514a |
// Layer specific info
|
|
Packit Service |
b3514a |
DeviceConfig *deviceConfig;
|
|
Packit Service |
b3514a |
/** A ring of all DeviceConfigs referencing this layer */
|
|
Packit Service |
b3514a |
RingNode deviceConfigRing;
|
|
Packit Service |
b3514a |
char threadNamePrefix[MAX_QUEUE_NAME_LEN];
|
|
Packit Service |
b3514a |
struct kobject kobj;
|
|
Packit Service |
b3514a |
struct kobject wqDirectory;
|
|
Packit Service |
b3514a |
struct kobject statsDirectory;
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* A counter value to attach to thread names and log messages to
|
|
Packit Service |
b3514a |
* identify the individual device.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
unsigned int instance;
|
|
Packit Service |
b3514a |
/** Contains the current KernelLayerState, which rarely changes */
|
|
Packit Service |
b3514a |
Atomic32 state;
|
|
Packit Service |
b3514a |
bool noFlushSuspend;
|
|
Packit Service |
b3514a |
bool allocationsAllowed;
|
|
Packit Service |
b3514a |
AtomicBool processingMessage;
|
|
Packit Service |
b3514a |
/** Limit the number of requests that are being processed. */
|
|
Packit Service |
b3514a |
Limiter requestLimiter;
|
|
Packit Service |
b3514a |
Limiter discardLimiter;
|
|
Packit Service |
b3514a |
KVDO kvdo;
|
|
Packit Service |
b3514a |
/** Incoming bios we've had to buffer to avoid deadlock. */
|
|
Packit Service |
b3514a |
DeadlockQueue deadlockQueue;
|
|
Packit Service |
b3514a |
// for REQ_FLUSH processing
|
|
Packit Service |
b3514a |
struct bio_list waitingFlushes;
|
|
Packit Service |
b3514a |
KVDOFlush *spareKVDOFlush;
|
|
Packit Service |
b3514a |
spinlock_t flushLock;
|
|
Packit Service |
b3514a |
Jiffies flushArrivalTime;
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Bio submission manager used for sending bios to the storage
|
|
Packit Service |
b3514a |
* device.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
IOSubmitter *ioSubmitter;
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Work queue (possibly with multiple threads) for miscellaneous
|
|
Packit Service |
b3514a |
* CPU-intensive, non-blocking work.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
KvdoWorkQueue *cpuQueue;
|
|
Packit Service |
b3514a |
/** N blobs of context data for LZ4 code, one per CPU thread. */
|
|
Packit Service |
b3514a |
char **compressionContext;
|
|
Packit Service |
b3514a |
Atomic32 compressionContextIndex;
|
|
Packit Service |
b3514a |
/** Optional work queue for calling bio_endio. */
|
|
Packit Service |
b3514a |
KvdoWorkQueue *bioAckQueue;
|
|
Packit Service |
b3514a |
/** Underlying block device info. */
|
|
Packit Service |
b3514a |
uint64_t startingSectorOffset;
|
|
Packit Service |
b3514a |
VolumeGeometry geometry;
|
|
Packit Service |
b3514a |
// Memory allocation
|
|
Packit Service |
b3514a |
BufferPool *dataKVIOPool;
|
|
Packit Service |
b3514a |
struct bio_set *bioset;
|
|
Packit Service |
b3514a |
// Albireo specific info
|
|
Packit Service |
b3514a |
DedupeIndex *dedupeIndex;
|
|
Packit Service |
b3514a |
// Statistics
|
|
Packit Service |
b3514a |
atomic64_t biosSubmitted;
|
|
Packit Service |
b3514a |
atomic64_t biosCompleted;
|
|
Packit Service |
b3514a |
atomic64_t dedupeContextBusy;
|
|
Packit Service |
b3514a |
atomic64_t flushOut;
|
|
Packit Service |
b3514a |
AtomicBioStats biosIn;
|
|
Packit Service |
b3514a |
AtomicBioStats biosInPartial;
|
|
Packit Service |
b3514a |
AtomicBioStats biosOut;
|
|
Packit Service |
b3514a |
AtomicBioStats biosOutCompleted;
|
|
Packit Service |
b3514a |
AtomicBioStats biosAcknowledged;
|
|
Packit Service |
b3514a |
AtomicBioStats biosAcknowledgedPartial;
|
|
Packit Service |
b3514a |
AtomicBioStats biosMeta;
|
|
Packit Service |
b3514a |
AtomicBioStats biosMetaCompleted;
|
|
Packit Service |
b3514a |
AtomicBioStats biosJournal;
|
|
Packit Service |
b3514a |
AtomicBioStats biosPageCache;
|
|
Packit Service |
b3514a |
AtomicBioStats biosJournalCompleted;
|
|
Packit Service |
b3514a |
AtomicBioStats biosPageCacheCompleted;
|
|
Packit Service |
b3514a |
// for reporting Albireo timeouts
|
|
Packit Service |
b3514a |
PeriodicEventReporter albireoTimeoutReporter;
|
|
Packit Service |
b3514a |
// Debugging
|
|
Packit Service |
b3514a |
/* Whether to dump VDO state on shutdown */
|
|
Packit Service |
b3514a |
bool dumpOnShutdown;
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Whether we should collect tracing info. (Actually, this controls
|
|
Packit Service |
b3514a |
* allocations; non-null record pointers cause recording.)
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
bool vioTraceRecording;
|
|
Packit Service |
b3514a |
SampleCounter traceSampleCounter;
|
|
Packit Service |
b3514a |
/* Should we log tracing info? */
|
|
Packit Service |
b3514a |
bool traceLogging;
|
|
Packit Service |
b3514a |
/* Storage for trace data. */
|
|
Packit Service |
b3514a |
BufferPool *traceBufferPool;
|
|
Packit Service |
b3514a |
/* Private storage for procfs. */
|
|
Packit Service |
b3514a |
void *procfsPrivate;
|
|
Packit Service |
b3514a |
/* For returning batches of DataKVIOs to their pool */
|
|
Packit Service |
b3514a |
BatchProcessor *dataKVIOReleaser;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Administrative operations
|
|
Packit Service |
b3514a |
/* The object used to wait for administrative operations to complete */
|
|
Packit Service |
b3514a |
struct completion callbackSync;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
// Statistics reporting
|
|
Packit Service |
b3514a |
/* Protects the *statsStorage structs */
|
|
Packit Service |
b3514a |
struct mutex statsMutex;
|
|
Packit Service |
b3514a |
/* Used when shutting down the sysfs statistics */
|
|
Packit Service |
b3514a |
struct completion statsShutdown;;
|
|
Packit Service |
b3514a |
/* true if sysfs statistics directory is set up */
|
|
Packit Service |
b3514a |
bool statsAdded;
|
|
Packit Service |
b3514a |
/* Used to gather statistics without allocating memory */
|
|
Packit Service |
b3514a |
VDOStatistics vdoStatsStorage;
|
|
Packit Service |
b3514a |
KernelStatistics kernelStatsStorage;
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef enum bioQAction {
|
|
Packit Service |
b3514a |
BIO_Q_ACTION_COMPRESSED_DATA,
|
|
Packit Service |
b3514a |
BIO_Q_ACTION_DATA,
|
|
Packit Service |
b3514a |
BIO_Q_ACTION_FLUSH,
|
|
Packit Service |
b3514a |
BIO_Q_ACTION_HIGH,
|
|
Packit Service |
b3514a |
BIO_Q_ACTION_METADATA,
|
|
Packit Service |
b3514a |
BIO_Q_ACTION_READCACHE,
|
|
Packit Service |
b3514a |
BIO_Q_ACTION_VERIFY
|
|
Packit Service |
b3514a |
} BioQAction;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef enum cpuQAction {
|
|
Packit Service |
b3514a |
CPU_Q_ACTION_COMPLETE_KVIO,
|
|
Packit Service |
b3514a |
CPU_Q_ACTION_COMPRESS_BLOCK,
|
|
Packit Service |
b3514a |
CPU_Q_ACTION_EVENT_REPORTER,
|
|
Packit Service |
b3514a |
CPU_Q_ACTION_HASH_BLOCK,
|
|
Packit Service |
b3514a |
} CPUQAction;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef enum bioAckQAction {
|
|
Packit Service |
b3514a |
BIO_ACK_Q_ACTION_ACK,
|
|
Packit Service |
b3514a |
} BioAckQAction;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef void (*DedupeShutdownCallbackFunction)(KernelLayer *layer);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* Wrapper for the Enqueueable object, to associate it with a kernel
|
|
Packit Service |
b3514a |
* layer work item.
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
typedef struct kvdoEnqueueable {
|
|
Packit Service |
b3514a |
KvdoWorkItem workItem;
|
|
Packit Service |
b3514a |
Enqueueable enqueueable;
|
|
Packit Service |
b3514a |
} KvdoEnqueueable;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Implements LayerFilter.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
bool layerIsNamed(KernelLayer *layer, void *context)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Creates a kernel specific physical layer to be used by VDO
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param startingSector The sector offset of our table entry in the
|
|
Packit Service |
b3514a |
* DM device
|
|
Packit Service |
b3514a |
* @param instance Device instantiation counter
|
|
Packit Service |
b3514a |
* @param parentKobject The parent sysfs node
|
|
Packit Service |
b3514a |
* @param config The device configuration
|
|
Packit Service |
b3514a |
* @param threadConfigPointer Where to store the new threadConfig handle
|
|
Packit Service |
b3514a |
* @param reason The reason for any failure during this call
|
|
Packit Service |
b3514a |
* @param layerPtr A pointer to hold the created layer
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int makeKernelLayer(uint64_t startingSector,
|
|
Packit Service |
b3514a |
unsigned int instance,
|
|
Packit Service |
b3514a |
DeviceConfig *config,
|
|
Packit Service |
b3514a |
struct kobject *parentKobject,
|
|
Packit Service |
b3514a |
ThreadConfig **threadConfigPointer,
|
|
Packit Service |
b3514a |
char **reason,
|
|
Packit Service |
b3514a |
KernelLayer **layerPtr)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Prepare to modify a kernel layer.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The layer to modify
|
|
Packit Service |
b3514a |
* @param config The new device configuration
|
|
Packit Service |
b3514a |
* @param errorPtr A pointer to store the reason for any failure
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int prepareToModifyKernelLayer(KernelLayer *layer,
|
|
Packit Service |
b3514a |
DeviceConfig *config,
|
|
Packit Service |
b3514a |
char **errorPtr)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Modify a kernel physical layer.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The layer to modify
|
|
Packit Service |
b3514a |
* @param config The new device configuration
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int modifyKernelLayer(KernelLayer *layer,
|
|
Packit Service |
b3514a |
DeviceConfig *config)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Free a kernel physical layer.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The layer, which must have been created by
|
|
Packit Service |
b3514a |
* makeKernelLayer
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void freeKernelLayer(KernelLayer *layer);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Make and configure a kernel layer. This method does not alter the VDO state
|
|
Packit Service |
b3514a |
* on disk. It should be run from the VDO constructor for devices which have
|
|
Packit Service |
b3514a |
* not been started.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer
|
|
Packit Service |
b3514a |
* @param loadConfig Load-time parameters for the VDO
|
|
Packit Service |
b3514a |
* @param reason The reason for any failure during this call
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @note redundant starts are silently ignored
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int preloadKernelLayer(KernelLayer *layer,
|
|
Packit Service |
b3514a |
const VDOLoadConfig *loadConfig,
|
|
Packit Service |
b3514a |
char **reason);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Start the kernel layer. This method finishes bringing a VDO online now that
|
|
Packit Service |
b3514a |
* a table is being resumed for the first time.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer
|
|
Packit Service |
b3514a |
* @param reason The reason for any failure during this call
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int startKernelLayer(KernelLayer *layer, char **reason);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Stop the kernel layer.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void stopKernelLayer(KernelLayer *layer);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Suspend the kernel layer.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int suspendKernelLayer(KernelLayer *layer);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Resume the kernel layer.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int resumeKernelLayer(KernelLayer *layer);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Get the kernel layer state.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return the instantaneously correct kernel layer state
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline KernelLayerState getKernelLayerState(const KernelLayer *layer)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return atomicLoad32(&layer->state);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Function call to begin processing a bio passed in from the block layer
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The physical layer
|
|
Packit Service |
b3514a |
* @param bio The bio from the block layer
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return value to return from the VDO map function. Either an error code
|
|
Packit Service |
b3514a |
* or DM_MAPIO_REMAPPED or DM_MAPPED_SUBMITTED (see vdoMapBio for
|
|
Packit Service |
b3514a |
* details).
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int kvdoMapBio(KernelLayer *layer, BIO *bio);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Convert a generic PhysicalLayer to a kernelLayer.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The PhysicalLayer to convert
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The PhysicalLayer as a KernelLayer
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline KernelLayer *asKernelLayer(PhysicalLayer *layer)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return container_of(layer, KernelLayer, common);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Convert a block number (or count) to a (512-byte-)sector number.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* The argument type is sector_t to force conversion to the type we
|
|
Packit Service |
b3514a |
* want, although the actual values passed are of various integral
|
|
Packit Service |
b3514a |
* types. It's just too easy to forget and do the multiplication
|
|
Packit Service |
b3514a |
* without casting, resulting in 32-bit arithmetic that accidentally
|
|
Packit Service |
b3514a |
* produces wrong results in devices over 2TB (2**32 sectors).
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] layer the physical layer
|
|
Packit Service |
b3514a |
* @param [in] blockNumber the block number/count
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return the sector number/count
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline sector_t blockToSector(KernelLayer *layer, sector_t blockNumber)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return (blockNumber * VDO_SECTORS_PER_BLOCK);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Convert a sector number (or count) to a block number. Does not
|
|
Packit Service |
b3514a |
* check to make sure the sector number is an integral number of
|
|
Packit Service |
b3514a |
* blocks.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] layer the physical layer
|
|
Packit Service |
b3514a |
* @param [in] sectorNumber the sector number/count
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return the block number/count
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline sector_t sectorToBlock(KernelLayer *layer, sector_t sectorNumber)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return (sectorNumber / VDO_SECTORS_PER_BLOCK);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Convert a sector number to an offset within a block.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] layer the physical layer
|
|
Packit Service |
b3514a |
* @param [in] sectorNumber the sector number
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return the offset within the block
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline BlockSize sectorToBlockOffset(KernelLayer *layer,
|
|
Packit Service |
b3514a |
sector_t sectorNumber)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
unsigned int sectorsPerBlockMask = VDO_SECTORS_PER_BLOCK - 1;
|
|
Packit Service |
b3514a |
return to_bytes(sectorNumber & sectorsPerBlockMask);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Get the block device object currently underlying a kernel layer.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer in question
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The block device object under the layer
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
struct block_device *getKernelLayerBdev(const KernelLayer *layer)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Set the layer's active config.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer in question
|
|
Packit Service |
b3514a |
* @param config The config in question
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline void setKernelLayerActiveConfig(KernelLayer *layer,
|
|
Packit Service |
b3514a |
DeviceConfig *config)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
layer->deviceConfig = config;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Given an error code, return a value we can return to the OS. The
|
|
Packit Service |
b3514a |
* input error code may be a system-generated value (such as -EIO), an
|
|
Packit Service |
b3514a |
* errno macro used in our code (such as EIO), or a UDS or VDO status
|
|
Packit Service |
b3514a |
* code; the result must be something the rest of the OS can consume
|
|
Packit Service |
b3514a |
* (negative errno values such as -EIO, in the case of the kernel).
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param error the error code to convert
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return a system error code value
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int mapToSystemError(int error);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Record and eventually report that some number of dedupe requests
|
|
Packit Service |
b3514a |
* reached their expiration time without getting an answer, so we
|
|
Packit Service |
b3514a |
* timed out on them.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This is called in a timer context, so it shouldn't do the reporting
|
|
Packit Service |
b3514a |
* directly.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer for the device
|
|
Packit Service |
b3514a |
* @param expiredCount The number of expired requests we timed out on
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void kvdoReportDedupeTimeout(KernelLayer *layer, unsigned int expiredCount);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Wait until there are no requests in progress.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer for the device
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void waitForNoRequestsActive(KernelLayer *layer);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Enqueues an item on our internal "cpu queues". Since there is more than
|
|
Packit Service |
b3514a |
* one, we rotate through them in hopes of creating some general balance.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer
|
|
Packit Service |
b3514a |
* @param item The work item to enqueue
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
static inline void enqueueCPUWorkQueue(KernelLayer *layer, KvdoWorkItem *item)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
enqueueWorkQueue(layer->cpuQueue, item);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Adjust parameters to prepare to use a larger physical space.
|
|
Packit Service |
b3514a |
* The size must be larger than the current size.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer the kernel layer
|
|
Packit Service |
b3514a |
* @param physicalCount the new physical size in blocks
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
int prepareToResizePhysical(KernelLayer *layer, BlockCount physicalCount);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Adjusts parameters to reflect resizing the underlying device.
|
|
Packit Service |
b3514a |
* The size must be larger than the current size.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer the kernel layer
|
|
Packit Service |
b3514a |
* @param physicalCount the new physical count in blocks
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
int resizePhysical(KernelLayer *layer, BlockCount physicalCount);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Adjust parameters to prepare to present a larger logical space.
|
|
Packit Service |
b3514a |
* The size must be larger than the current size.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer the kernel layer
|
|
Packit Service |
b3514a |
* @param logicalCount the new logical size in blocks
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
int prepareToResizeLogical(KernelLayer *layer, BlockCount logicalCount);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Adjust parameters to present a larger logical space.
|
|
Packit Service |
b3514a |
* The size must be larger than the current size.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer the kernel layer
|
|
Packit Service |
b3514a |
* @param logicalCount the new logical size in blocks
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
int resizeLogical(KernelLayer *layer, BlockCount logicalCount);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Indicate whether the kernel layer is configured to use a separate
|
|
Packit Service |
b3514a |
* work queue for acknowledging received and processed bios.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Note that this directly controls handling of write operations, but
|
|
Packit Service |
b3514a |
* the compile-time flag USE_BIO_ACK_QUEUE_FOR_READ is also checked
|
|
Packit Service |
b3514a |
* for read operations.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return Whether a bio-acknowledgement work queue is in use
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline bool useBioAckQueue(KernelLayer *layer)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return layer->deviceConfig->threadCounts.bioAckThreads > 0;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Update bookkeeping for the completion of some number of requests, so that
|
|
Packit Service |
b3514a |
* more incoming requests can be accepted.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param layer The kernel layer
|
|
Packit Service |
b3514a |
* @param count The number of completed requests
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void completeManyRequests(KernelLayer *layer, uint32_t count);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#endif /* KERNELLAYER_H */
|