|
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/extent.h#2 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef EXTENT_H
|
|
Packit Service |
310c69 |
#define EXTENT_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "permassert.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "completion.h"
|
|
Packit Service |
310c69 |
#include "types.h"
|
|
Packit Service |
310c69 |
#include "vio.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* A chain of VIOs which are part of the same request. An extent contains
|
|
Packit Service |
310c69 |
* a chain of at least 'count' VIOs. The 'next' pointer of the last VIO
|
|
Packit Service |
310c69 |
* in the extent (as indicated by the count) may not be NULL, but it is not
|
|
Packit Service |
310c69 |
* part of the extent. A VIO may belong to a single extent.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
struct vdoExtent {
|
|
Packit Service |
310c69 |
// The completion for asynchronous extent processing
|
|
Packit Service |
310c69 |
VDOCompletion completion;
|
|
Packit Service |
310c69 |
// The number of VIOs in the extent
|
|
Packit Service |
310c69 |
BlockCount count;
|
|
Packit Service |
310c69 |
// The number of completed VIOs in the extent
|
|
Packit Service |
310c69 |
BlockCount completeCount;
|
|
Packit Service |
310c69 |
// The VIOs in the extent
|
|
Packit Service |
310c69 |
VIO *vios[];
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Convert a generic VDOCompletion to a VDOExtent.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param completion The completion to convert
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The completion as an extent
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static inline VDOExtent *asVDOExtent(VDOCompletion *completion)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
STATIC_ASSERT(offsetof(VDOExtent, completion) == 0);
|
|
Packit Service |
310c69 |
assertCompletionType(completion->type, VDO_EXTENT_COMPLETION);
|
|
Packit Service |
310c69 |
return (VDOExtent *) completion;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Convert a VDOExtent to VDOCompletion.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param extent The extent to convert
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The extent as a VDOCompletion
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static inline VDOCompletion *extentAsCompletion(VDOExtent *extent)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
return &extent->completion;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Create a VDOExtent.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] layer The layer
|
|
Packit Service |
310c69 |
* @param [in] vioType The usage type to assign to the VIOs in the extent
|
|
Packit Service |
310c69 |
* (data / block map / journal)
|
|
Packit Service |
310c69 |
* @param [in] priority The relative priority to assign to the VIOs
|
|
Packit Service |
310c69 |
* @param [in] blockCount The number of blocks in the buffer
|
|
Packit Service |
310c69 |
* @param [in] data The buffer
|
|
Packit Service |
310c69 |
* @param [out] extentPtr A pointer to hold the new extent
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int createExtent(PhysicalLayer *layer,
|
|
Packit Service |
310c69 |
VIOType vioType,
|
|
Packit Service |
310c69 |
VIOPriority priority,
|
|
Packit Service |
310c69 |
BlockCount blockCount,
|
|
Packit Service |
310c69 |
char *data,
|
|
Packit Service |
310c69 |
VDOExtent **extentPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Free an extent and null out the reference to it.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in,out] extentPtr The reference to the extent to free
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeExtent(VDOExtent **extentPtr);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Read metadata from the underlying storage.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param extent The extent to read
|
|
Packit Service |
310c69 |
* @param startBlock The physical block number of the first block
|
|
Packit Service |
310c69 |
* in the extent
|
|
Packit Service |
310c69 |
* @param count The number of blocks to read (must be less than or
|
|
Packit Service |
310c69 |
* equal to the length of the extent)
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void readPartialMetadataExtent(VDOExtent *extent,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber startBlock,
|
|
Packit Service |
310c69 |
BlockCount count);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Read metadata from the underlying storage.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param extent The extent to read
|
|
Packit Service |
310c69 |
* @param startBlock The physical block number of the first block
|
|
Packit Service |
310c69 |
* in the extent
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static inline void readMetadataExtent(VDOExtent *extent,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber startBlock)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
readPartialMetadataExtent(extent, startBlock, extent->count);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Write metadata to the underlying storage.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param extent The extent to write
|
|
Packit Service |
310c69 |
* @param startBlock The physical block number of the first block in the
|
|
Packit Service |
310c69 |
* extent
|
|
Packit Service |
310c69 |
* @param count The number of blocks to read (must be less than or
|
|
Packit Service |
310c69 |
* equal to the length of the extent)
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void writePartialMetadataExtent(VDOExtent *extent,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber startBlock,
|
|
Packit Service |
310c69 |
BlockCount count);
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Write metadata to the underlying storage.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param extent The extent to write
|
|
Packit Service |
310c69 |
* @param startBlock The physical block number of the first block in the
|
|
Packit Service |
310c69 |
* extent
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static inline void writeMetadataExtent(VDOExtent *extent,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber startBlock)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
writePartialMetadataExtent(extent, startBlock, extent->count);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Notify an extent that one of its VIOs has completed. If the signaling VIO
|
|
Packit Service |
310c69 |
* is the last of the extent's VIOs to complete, the extent will finish. This
|
|
Packit Service |
310c69 |
* function is set as the VIO callback in completeVIO().
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param completion The completion of the VIO which has just finished
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void handleVIOCompletion(VDOCompletion *completion);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif /* EXTENT_H */
|