|
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/blockMap.h#4 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef BLOCK_MAP_H
|
|
Packit Service |
310c69 |
#define BLOCK_MAP_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "adminState.h"
|
|
Packit Service |
310c69 |
#include "blockMapEntry.h"
|
|
Packit Service |
310c69 |
#include "completion.h"
|
|
Packit Service |
310c69 |
#include "fixedLayout.h"
|
|
Packit Service |
310c69 |
#include "statistics.h"
|
|
Packit Service |
310c69 |
#include "types.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Create a block map.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] logicalBlocks The number of logical blocks for the VDO
|
|
Packit Service |
310c69 |
* @param [in] threadConfig The thread configuration of the VDO
|
|
Packit Service |
310c69 |
* @param [in] flatPageCount The number of flat pages
|
|
Packit Service |
310c69 |
* @param [in] rootOrigin The absolute PBN of the first root page
|
|
Packit Service |
310c69 |
* @param [in] rootCount The number of tree roots
|
|
Packit Service |
310c69 |
* @param [out] mapPtr The pointer to hold the new block map
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeBlockMap(BlockCount logicalBlocks,
|
|
Packit Service |
310c69 |
const ThreadConfig *threadConfig,
|
|
Packit Service |
310c69 |
BlockCount flatPageCount,
|
|
Packit Service |
310c69 |
PhysicalBlockNumber rootOrigin,
|
|
Packit Service |
310c69 |
BlockCount rootCount,
|
|
Packit Service |
310c69 |
BlockMap **mapPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Quiesce all block map I/O, possibly writing out all dirty metadata.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map to drain
|
|
Packit Service |
310c69 |
* @param operation The type of drain to perform
|
|
Packit Service |
310c69 |
* @param parent The completion to notify when the drain is complete
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void drainBlockMap(BlockMap *map,
|
|
Packit Service |
310c69 |
AdminStateCode operation,
|
|
Packit Service |
310c69 |
VDOCompletion *parent);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Resume I/O for a quiescent block map.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map to resume
|
|
Packit Service |
310c69 |
* @param parent The completion to notify when the resume is complete
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void resumeBlockMap(BlockMap *map, VDOCompletion *parent);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Prepare to grow the block map by allocating an expanded collection of trees.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map to grow
|
|
Packit Service |
310c69 |
* @param newLogicalBlocks The new logical size of the VDO
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int prepareToGrowBlockMap(BlockMap *map, BlockCount newLogicalBlocks)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the logical size to which this block map is prepared to grow.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The new number of entries the block map will be grown to or 0 if
|
|
Packit Service |
310c69 |
* the block map is not prepared to grow
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
BlockCount getNewEntryCount(BlockMap *map)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Grow a block map on which prepareToGrowBlockMap() has already been called.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map to grow
|
|
Packit Service |
310c69 |
* @param parent The object to notify when the growth is complete
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void growBlockMap(BlockMap *map, VDOCompletion *parent);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Abandon any preparations which were made to grow this block map.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The map which won't be grown
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void abandonBlockMapGrowth(BlockMap *map);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Decode the state of a block map saved in a buffer, without creating page
|
|
Packit Service |
310c69 |
* caches.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] buffer A buffer containing the super block state
|
|
Packit Service |
310c69 |
* @param [in] logicalBlocks The number of logical blocks for the VDO
|
|
Packit Service |
310c69 |
* @param [in] threadConfig The thread configuration of the VDO
|
|
Packit Service |
310c69 |
* @param [out] mapPtr The pointer to hold the new block map
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int decodeBlockMap(Buffer *buffer,
|
|
Packit Service |
310c69 |
BlockCount logicalBlocks,
|
|
Packit Service |
310c69 |
const ThreadConfig *threadConfig,
|
|
Packit Service |
310c69 |
BlockMap **mapPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Create a block map from the saved state of a Sodium block map, and do any
|
|
Packit Service |
310c69 |
* necessary upgrade work.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [in] buffer A buffer containing the super block state
|
|
Packit Service |
310c69 |
* @param [in] logicalBlocks The number of logical blocks for the VDO
|
|
Packit Service |
310c69 |
* @param [in] threadConfig The thread configuration of the VDO
|
|
Packit Service |
310c69 |
* @param [out] mapPtr The pointer to hold the new block map
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int decodeSodiumBlockMap(Buffer *buffer,
|
|
Packit Service |
310c69 |
BlockCount logicalBlocks,
|
|
Packit Service |
310c69 |
const ThreadConfig *threadConfig,
|
|
Packit Service |
310c69 |
BlockMap **mapPtr)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Allocate the page caches for a block map.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map needing caches.
|
|
Packit Service |
310c69 |
* @param layer The physical layer for the cache
|
|
Packit Service |
310c69 |
* @param readOnlyNotifier The read only mode context
|
|
Packit Service |
310c69 |
* @param journal The recovery journal (may be NULL)
|
|
Packit Service |
310c69 |
* @param nonce The nonce to distinguish initialized pages
|
|
Packit Service |
310c69 |
* @param cacheSize The block map cache size, in pages
|
|
Packit Service |
310c69 |
* @param maximumAge The number of journal blocks before a dirtied page
|
|
Packit Service |
310c69 |
* is considered old and must be written out
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error code
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeBlockMapCaches(BlockMap *map,
|
|
Packit Service |
310c69 |
PhysicalLayer *layer,
|
|
Packit Service |
310c69 |
ReadOnlyNotifier *readOnlyNotifier,
|
|
Packit Service |
310c69 |
RecoveryJournal *journal,
|
|
Packit Service |
310c69 |
Nonce nonce,
|
|
Packit Service |
310c69 |
PageCount cacheSize,
|
|
Packit Service |
310c69 |
BlockCount maximumAge)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Free a block map and null out the reference to it.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param mapPtr A pointer to the block map to free
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeBlockMap(BlockMap **mapPtr);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the size of the encoded state of a block map.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The encoded size of the map's state
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
size_t getBlockMapEncodedSize(void)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Encode the state of a block map into a buffer.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map to encode
|
|
Packit Service |
310c69 |
* @param buffer The buffer to encode into
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return UDS_SUCCESS or an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int encodeBlockMap(const BlockMap *map, Buffer *buffer)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Obtain any necessary state from the recovery journal that is needed for
|
|
Packit Service |
310c69 |
* normal block map operation.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The map in question
|
|
Packit Service |
310c69 |
* @param journal The journal to initialize from
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void initializeBlockMapFromJournal(BlockMap *map, RecoveryJournal *journal);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the portion of the block map for a given logical zone.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The map
|
|
Packit Service |
310c69 |
* @param zoneNumber The number of the zone
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The requested block map zone
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
BlockMapZone *getBlockMapZone(BlockMap *map, ZoneCount zoneNumber)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Compute the logical zone on which the entry for a DataVIO
|
|
Packit Service |
310c69 |
* resides
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The logical zone number for the DataVIO
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
ZoneCount computeLogicalZone(DataVIO *dataVIO);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Compute the block map slot in which the block map entry for a DataVIO
|
|
Packit Service |
310c69 |
* resides, and cache that number in the DataVIO.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO
|
|
Packit Service |
310c69 |
* @param callback The function to call once the slot has been found
|
|
Packit Service |
310c69 |
* @param threadID The thread on which to run the callback
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void findBlockMapSlotAsync(DataVIO *dataVIO,
|
|
Packit Service |
310c69 |
VDOAction *callback,
|
|
Packit Service |
310c69 |
ThreadID threadID);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get number of block map pages at predetermined locations.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The number of fixed pages used by the map
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
PageCount getNumberOfFixedBlockMapPages(const BlockMap *map)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get number of block map entries.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The number of entries stored in the map
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
BlockCount getNumberOfBlockMapEntries(const BlockMap *map)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Notify the block map that the recovery journal has finished a new block.
|
|
Packit Service |
310c69 |
* This method must be called from the journal zone thread.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map
|
|
Packit Service |
310c69 |
* @param recoveryBlockNumber The sequence number of the finished recovery
|
|
Packit Service |
310c69 |
* journal block
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void advanceBlockMapEra(BlockMap *map, SequenceNumber recoveryBlockNumber);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the block number of the physical block containing the data for the
|
|
Packit Service |
310c69 |
* specified logical block number. All blocks are mapped to physical block
|
|
Packit Service |
310c69 |
* zero by default, which is conventionally the zero block.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO of the block to map
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void getMappedBlockAsync(DataVIO *dataVIO);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Associate the logical block number for a block represented by a DataVIO
|
|
Packit Service |
310c69 |
* with the physical block number in its newMapped field.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param dataVIO The DataVIO of the block to map
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void putMappedBlockAsync(DataVIO *dataVIO);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the stats for the block map page cache.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map containing the cache
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The block map statistics
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
BlockMapStatistics getBlockMapStatistics(BlockMap *map)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif // BLOCK_MAP_H
|