|
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/base/refCountsInternals.h#4 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#ifndef REF_COUNTS_INTERNALS_H
|
|
Packit Service |
b3514a |
#define REF_COUNTS_INTERNALS_H
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "refCounts.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "journalPoint.h"
|
|
Packit Service |
b3514a |
#include "referenceBlock.h"
|
|
Packit Service |
b3514a |
#include "slab.h"
|
|
Packit Service |
b3514a |
#include "blockAllocatorInternals.h"
|
|
Packit Service |
b3514a |
#include "waitQueue.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Represents the possible status of a block.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
typedef enum referenceStatus {
|
|
Packit Service |
b3514a |
RS_FREE, // this block is free
|
|
Packit Service |
b3514a |
RS_SINGLE, // this block is singly-referenced
|
|
Packit Service |
b3514a |
RS_SHARED, // this block is shared
|
|
Packit Service |
b3514a |
RS_PROVISIONAL // this block is provisionally allocated
|
|
Packit Service |
b3514a |
} ReferenceStatus;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* The SearchCursor represents the saved position of a free block search.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
typedef struct searchCursor {
|
|
Packit Service |
b3514a |
/** The reference block containing the current search index */
|
|
Packit Service |
b3514a |
ReferenceBlock *block;
|
|
Packit Service |
b3514a |
/** The position at which to start searching for the next free counter */
|
|
Packit Service |
b3514a |
SlabBlockNumber index;
|
|
Packit Service |
b3514a |
/** The position just past the last valid counter in the current block */
|
|
Packit Service |
b3514a |
SlabBlockNumber endIndex;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** A pointer to the first reference block in the slab */
|
|
Packit Service |
b3514a |
ReferenceBlock *firstBlock;
|
|
Packit Service |
b3514a |
/** A pointer to the last reference block in the slab */
|
|
Packit Service |
b3514a |
ReferenceBlock *lastBlock;
|
|
Packit Service |
b3514a |
} SearchCursor;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* RefCounts structure
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* A reference count is maintained for each PhysicalBlockNumber. The vast
|
|
Packit Service |
b3514a |
* majority of blocks have a very small reference count (usually 0 or 1).
|
|
Packit Service |
b3514a |
* For references less than or equal to MAXIMUM_REFS (254) the reference count
|
|
Packit Service |
b3514a |
* is stored in counters[pbn].
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
struct refCounts {
|
|
Packit Service |
b3514a |
/** The slab of this reference block */
|
|
Packit Service |
b3514a |
Slab *slab;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** The size of the counters array */
|
|
Packit Service |
b3514a |
uint32_t blockCount;
|
|
Packit Service |
b3514a |
/** The number of free blocks */
|
|
Packit Service |
b3514a |
uint32_t freeBlocks;
|
|
Packit Service |
b3514a |
/** The array of reference counts */
|
|
Packit Service |
b3514a |
ReferenceCount *counters; // use ALLOCATE to align data ptr
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** The saved block pointer and array indexes for the free block search */
|
|
Packit Service |
b3514a |
SearchCursor searchCursor;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** A list of the dirty blocks waiting to be written out */
|
|
Packit Service |
b3514a |
WaitQueue dirtyBlocks;
|
|
Packit Service |
b3514a |
/** The number of blocks which are currently writing */
|
|
Packit Service |
b3514a |
size_t activeCount;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** A waiter object for updating the slab summary */
|
|
Packit Service |
b3514a |
Waiter slabSummaryWaiter;
|
|
Packit Service |
b3514a |
/** Whether slab summary update is in progress */
|
|
Packit Service |
b3514a |
bool updatingSlabSummary;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** The notifier for read-only mode */
|
|
Packit Service |
b3514a |
ReadOnlyNotifier *readOnlyNotifier;
|
|
Packit Service |
b3514a |
/** The refcount statistics, shared by all refcounts in our physical zone */
|
|
Packit Service |
b3514a |
AtomicRefCountStatistics *statistics;
|
|
Packit Service |
b3514a |
/** The layer PBN for the first ReferenceBlock */
|
|
Packit Service |
b3514a |
PhysicalBlockNumber origin;
|
|
Packit Service |
b3514a |
/** The latest slab journal entry this RefCounts has been updated with */
|
|
Packit Service |
b3514a |
JournalPoint slabJournalPoint;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** The number of reference count blocks */
|
|
Packit Service |
b3514a |
uint32_t referenceBlockCount;
|
|
Packit Service |
b3514a |
/** reference count block array */
|
|
Packit Service |
b3514a |
ReferenceBlock blocks[];
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Convert a reference count to a reference status.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param count The count to convert
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The appropriate reference status
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result))
|
|
Packit Service |
b3514a |
ReferenceStatus referenceCountToStatus(ReferenceCount count);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Convert a generic VDOCompletion to a RefCounts.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param completion The completion to convert
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The completion as a RefCounts
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
RefCounts *asRefCounts(VDOCompletion *completion)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Get the reference block that covers the given block index (exposed for
|
|
Packit Service |
b3514a |
* testing).
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param refCounts The refcounts object
|
|
Packit Service |
b3514a |
* @param index The block index
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
ReferenceBlock *getReferenceBlock(RefCounts *refCounts, SlabBlockNumber index)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Find the reference counters for a given block (exposed for testing).
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The ReferenceBlock in question
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return A pointer to the reference counters for this block
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
ReferenceCount *getReferenceCountersForBlock(ReferenceBlock *block)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Copy data from a reference block to a buffer ready to be written out
|
|
Packit Service |
b3514a |
* (exposed for testing).
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The block to copy
|
|
Packit Service |
b3514a |
* @param buffer The char buffer to fill with the packed block
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void packReferenceBlock(ReferenceBlock *block, void *buffer);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Get the reference status of a block. Exposed only for unit testing.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] refCounts The refcounts object
|
|
Packit Service |
b3514a |
* @param [in] pbn The physical block number
|
|
Packit Service |
b3514a |
* @param [out] statusPtr Where to put the status of the block
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return A success or error code, specifically:
|
|
Packit Service |
b3514a |
* VDO_OUT_OF_RANGE if the pbn is out of range.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int getReferenceStatus(RefCounts *refCounts,
|
|
Packit Service |
b3514a |
PhysicalBlockNumber pbn,
|
|
Packit Service |
b3514a |
ReferenceStatus *statusPtr)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Find the first block with a reference count of zero in the specified range
|
|
Packit Service |
b3514a |
* of reference counter indexes. Exposed for unit testing.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] refCounts The reference counters to scan
|
|
Packit Service |
b3514a |
* @param [in] startIndex The array index at which to start scanning
|
|
Packit Service |
b3514a |
* (included in the scan)
|
|
Packit Service |
b3514a |
* @param [in] endIndex The array index at which to stop scanning
|
|
Packit Service |
b3514a |
* (excluded from the scan)
|
|
Packit Service |
b3514a |
* @param [out] indexPtr A pointer to hold the array index of the free block
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return true if a free block was found in the specified range
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
bool findFreeBlock(const RefCounts *refCounts,
|
|
Packit Service |
b3514a |
SlabBlockNumber startIndex,
|
|
Packit Service |
b3514a |
SlabBlockNumber endIndex,
|
|
Packit Service |
b3514a |
SlabBlockNumber *indexPtr)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Request a RefCounts save its oldest dirty block asynchronously.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param refCounts The RefCounts object to notify
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void saveOldestReferenceBlock(RefCounts *refCounts);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Reset all reference counts back to RS_FREE.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param refCounts The reference counters to reset
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void resetReferenceCounts(RefCounts *refCounts);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#endif // REF_COUNTS_INTERNALS_H
|