|
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/kvio.h#3 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#ifndef KVIO_H
|
|
Packit Service |
b3514a |
#define KVIO_H
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "allocatingVIO.h"
|
|
Packit Service |
b3514a |
#include "vio.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "kernelLayer.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* A specific (semi-opaque) encapsulation of a single block
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
struct kvio {
|
|
Packit Service |
b3514a |
KvdoEnqueueable enqueueable;
|
|
Packit Service |
b3514a |
VIO *vio;
|
|
Packit Service |
b3514a |
KernelLayer *layer;
|
|
Packit Service |
b3514a |
BIO *bio;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* A bio pointer used in enqueueBioMap (used via submitBio etc), to
|
|
Packit Service |
b3514a |
* pass information -- which bio to submit to the storage device --
|
|
Packit Service |
b3514a |
* across a thread switch. This may match another bio pointer in
|
|
Packit Service |
b3514a |
* this structure, or could point somewhere else.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
BIO *bioToSubmit;
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* A list of enqueued bios with consecutive block numbers, stored by
|
|
Packit Service |
b3514a |
* enqueueBioMap under the first-enqueued KVIO. The other KVIOs are
|
|
Packit Service |
b3514a |
* found via their bio entries in this list, and are not added to
|
|
Packit Service |
b3514a |
* the work queue as separate work items.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
struct bio_list biosMerged;
|
|
Packit Service |
b3514a |
/** A slot for an arbitrary bit of data, for use by systemtap. */
|
|
Packit Service |
b3514a |
long debugSlot;
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef struct {
|
|
Packit Service |
b3514a |
KVIO kvio;
|
|
Packit Service |
b3514a |
VIO vio;
|
|
Packit Service |
b3514a |
} MetadataKVIO;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef struct {
|
|
Packit Service |
b3514a |
KVIO kvio;
|
|
Packit Service |
b3514a |
AllocatingVIO allocatingVIO;
|
|
Packit Service |
b3514a |
} CompressedWriteKVIO;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Determine whether a KVIO is a data VIO or not
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param kvio The KVIO to check
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return true if a data KVIO
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
static inline bool isData(KVIO *kvio)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return isDataVIO(kvio->vio);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Determine whether a KVIO is a compressed block write VIO or not
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param kvio The KVIO to check
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return true if a compressed block writer
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
static inline bool isCompressedWriter(KVIO *kvio)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return isCompressedWriteVIO(kvio->vio);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Determine whether a KVIO is a metadata VIO or not
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param kvio The KVIO to check
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return true if a metadata KVIO
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
static inline bool isMetadata(KVIO *kvio)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return isMetadataVIO(kvio->vio);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Convert a VIO to a MetadataKVIO.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param vio The VIO to convert
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return the VIO as a KVIO
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline MetadataKVIO *vioAsMetadataKVIO(VIO *vio)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
ASSERT_LOG_ONLY(isMetadataVIO(vio), "VIO is a metadata VIO");
|
|
Packit Service |
b3514a |
return container_of(vio, MetadataKVIO, vio);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Convert a MetadataKVIO to a KVIO.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param metadataKVIO The MetadataKVIO to convert
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The MetadataKVIO as a KVIO
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline KVIO *metadataKVIOAsKVIO(MetadataKVIO *metadataKVIO)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return &metadataKVIO->kvio;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Returns a pointer to the CompressedWriteKVIO wrapping an AllocatingVIO.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param allocatingVIO The AllocatingVIO to convert
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return the CompressedWriteKVIO
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline CompressedWriteKVIO *
|
|
Packit Service |
b3514a |
allocatingVIOAsCompressedWriteKVIO(AllocatingVIO *allocatingVIO)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
ASSERT_LOG_ONLY(isCompressedWriteAllocatingVIO(allocatingVIO),
|
|
Packit Service |
b3514a |
"AllocatingVIO is a compressed write");
|
|
Packit Service |
b3514a |
return container_of(allocatingVIO, CompressedWriteKVIO, allocatingVIO);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Convert a CompressedWriteKVIO to a KVIO.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param compressedWriteKVIO The CompressedWriteKVIO to convert
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The CompressedWriteKVIO as a KVIO
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline
|
|
Packit Service |
b3514a |
KVIO *compressedWriteKVIOAsKVIO(CompressedWriteKVIO *compressedWriteKVIO)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return &compressedWriteKVIO->kvio;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Returns a pointer to the KVIO wrapping a work item
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param item the work item
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return the KVIO
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline KVIO *workItemAsKVIO(KvdoWorkItem *item)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return container_of(item, KVIO, enqueueable.workItem);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Enqueue a KVIO on a work queue.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param queue The queue
|
|
Packit Service |
b3514a |
* @param kvio The KVIO
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline void enqueueKVIOWork(KvdoWorkQueue *queue, KVIO *kvio)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
enqueueWorkQueue(queue, &kvio->enqueueable.workItem);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Add a trace record for the current source location.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param kvio The KVIO structure to be updated
|
|
Packit Service |
b3514a |
* @param location The source-location descriptor to be recorded
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline void kvioAddTraceRecord(KVIO *kvio, TraceLocation location)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
vioAddTraceRecord(kvio->vio, location);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Set up the work item for a KVIO.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param kvio The KVIO to set up
|
|
Packit Service |
b3514a |
* @param work The function pointer to execute
|
|
Packit Service |
b3514a |
* @param statsFunction A function pointer to record for stats, or NULL
|
|
Packit Service |
b3514a |
* @param action Action code, mapping to a relative priority
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline void setupKVIOWork(KVIO *kvio,
|
|
Packit Service |
b3514a |
KvdoWorkFunction work,
|
|
Packit Service |
b3514a |
void *statsFunction,
|
|
Packit Service |
b3514a |
unsigned int action)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
setupWorkItem(&kvio->enqueueable.workItem, work, statsFunction, action);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Set up and enqueue a KVIO.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param kvio The KVIO to set up
|
|
Packit Service |
b3514a |
* @param work The function pointer to execute
|
|
Packit Service |
b3514a |
* @param statsFunction A function pointer to record for stats, or NULL
|
|
Packit Service |
b3514a |
* @param action Action code, mapping to a relative priority
|
|
Packit Service |
b3514a |
* @param queue The queue on which to enqueue the KVIO
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline void launchKVIO(KVIO *kvio,
|
|
Packit Service |
b3514a |
KvdoWorkFunction work,
|
|
Packit Service |
b3514a |
void *statsFunction,
|
|
Packit Service |
b3514a |
unsigned int action,
|
|
Packit Service |
b3514a |
KvdoWorkQueue *queue)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
setupKVIOWork(kvio, work, statsFunction, action);
|
|
Packit Service |
b3514a |
enqueueKVIOWork(queue, kvio);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Move a KVIO back to the base threads.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param kvio The KVIO to enqueue
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void kvdoEnqueueVIOCallback(KVIO *kvio);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Handles kvio-related I/O post-processing.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param kvio The kvio to finalize
|
|
Packit Service |
b3514a |
* @param error Possible error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void kvdoContinueKvio(KVIO *kvio, int error);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Initialize a KVIO.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param kvio The KVIO to initialize
|
|
Packit Service |
b3514a |
* @param layer The physical layer
|
|
Packit Service |
b3514a |
* @param vioType The type of VIO to create
|
|
Packit Service |
b3514a |
* @param priority The relative priority to assign to the KVIO
|
|
Packit Service |
b3514a |
* @param parent The parent of the KVIO completion
|
|
Packit Service |
b3514a |
* @param bio The bio to associate with this KVIO
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void initializeKVIO(KVIO *kvio,
|
|
Packit Service |
b3514a |
KernelLayer *layer,
|
|
Packit Service |
b3514a |
VIOType vioType,
|
|
Packit Service |
b3514a |
VIOPriority priority,
|
|
Packit Service |
b3514a |
void *parent,
|
|
Packit Service |
b3514a |
BIO *bio);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Destroy a MetadataKVIO and NULL out the pointer to it.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param metadataKVIOPtr A pointer to the MetadataKVIO to destroy
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void freeMetadataKVIO(MetadataKVIO **metadataKVIOPtr);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Destroy a CompressedWriteKVIO and NULL out the pointer to it.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param compressedWriteKVIOPtr A pointer to the CompressedWriteKVIO to
|
|
Packit Service |
b3514a |
* destroy
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void freeCompressedWriteKVIO(CompressedWriteKVIO **compressedWriteKVIOPtr);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Create a new VIO (and its enclosing KVIO) for metadata operations.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Implements MetadataVIOCreator.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] layer The physical layer
|
|
Packit Service |
b3514a |
* @param [in] vioType The type of VIO to create
|
|
Packit Service |
b3514a |
* @param [in] priority The relative priority to assign to the VIO
|
|
Packit Service |
b3514a |
* @param [in] parent The parent to assign to the VIO's completion
|
|
Packit Service |
b3514a |
* @param [in] data The buffer
|
|
Packit Service |
b3514a |
* @param [out] vioPtr A pointer to hold new VIO
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int kvdoCreateMetadataVIO(PhysicalLayer *layer,
|
|
Packit Service |
b3514a |
VIOType vioType,
|
|
Packit Service |
b3514a |
VIOPriority priority,
|
|
Packit Service |
b3514a |
void *parent,
|
|
Packit Service |
b3514a |
char *data,
|
|
Packit Service |
b3514a |
VIO **vioPtr)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Create a new AllocatingVIO (and its enclosing KVIO) for compressed writes.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Implements CompressedWriteVIOCreator.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] layer The physical layer
|
|
Packit Service |
b3514a |
* @param [in] parent The parent to assign to the AllocatingVIO's
|
|
Packit Service |
b3514a |
* completion
|
|
Packit Service |
b3514a |
* @param [in] data The buffer
|
|
Packit Service |
b3514a |
* @param [out] allocatingVIOPtr A pointer to hold new AllocatingVIO
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int kvdoCreateCompressedWriteVIO(PhysicalLayer *layer,
|
|
Packit Service |
b3514a |
void *parent,
|
|
Packit Service |
b3514a |
char *data,
|
|
Packit Service |
b3514a |
AllocatingVIO **allocatingVIOPtr)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Submit a compressed block write.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Implements CompressedWriter.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param allocatingVIO The AllocatingVIO for the compressed write
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void kvdoWriteCompressedBlock(AllocatingVIO *allocatingVIO);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Read or write a single metadata VIO.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Implements MetadataReader and MetadataWriter
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param vio The VIO to read or write
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void kvdoSubmitMetadataVIO(VIO *vio);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Issue an empty flush to the lower layer using the BIO in a metadata VIO.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Implements MetadataWriter.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param vio The VIO to flush
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void kvdoFlushVIO(VIO *vio);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#endif /* KVIO_H */
|