|
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/forest.h#2 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef FOREST_H
|
|
Packit Service |
310c69 |
#define FOREST_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "blockMapTree.h"
|
|
Packit Service |
310c69 |
#include "types.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* A function to be called for each allocated PBN when traversing the forest.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param pbn A PBN of a tree node
|
|
Packit Service |
310c69 |
* @param completion The parent completion of the traversal
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
typedef int EntryCallback(PhysicalBlockNumber pbn, VDOCompletion *completion);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the tree page for a given height and page index.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param forest The forest which holds the page
|
|
Packit Service |
310c69 |
* @param rootIndex The index of the tree that holds the page
|
|
Packit Service |
310c69 |
* @param height The height of the desired page
|
|
Packit Service |
310c69 |
* @param pageIndex The index of the desired page
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The requested page
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
TreePage *getTreePageByIndex(Forest *forest,
|
|
Packit Service |
310c69 |
RootCount rootIndex,
|
|
Packit Service |
310c69 |
Height height,
|
|
Packit Service |
310c69 |
PageNumber pageIndex)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Make a collection of trees for a BlockMap, expanding the existing forest if
|
|
Packit Service |
310c69 |
* there is one.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map
|
|
Packit Service |
310c69 |
* @param entries The number of entries the block map will hold
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
int makeForest(BlockMap *map, BlockCount entries)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Free a forest and all of the segments it contains and NULL out the reference
|
|
Packit Service |
310c69 |
* to it.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param forestPtr A pointer to the forest to free
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void freeForest(Forest **forestPtr);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Abandon the unused next forest from a BlockMap.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void abandonForest(BlockMap *map);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Replace a BlockMap's Forest with the already-prepared larger forest.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void replaceForest(BlockMap *map);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Walk the entire forest of a block map.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param map The block map to traverse
|
|
Packit Service |
310c69 |
* @param entryCallback A function to call with the pbn of each allocated node
|
|
Packit Service |
310c69 |
* in the forest
|
|
Packit Service |
310c69 |
* @param parent The completion to notify on each traversed PBN, and
|
|
Packit Service |
310c69 |
* when the traversal is complete
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void traverseForest(BlockMap *map,
|
|
Packit Service |
310c69 |
EntryCallback *entryCallback,
|
|
Packit Service |
310c69 |
VDOCompletion *parent);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Compute the approximate number of pages which the forest will allocate in
|
|
Packit Service |
310c69 |
* order to map the specified number of logical blocks. This method assumes
|
|
Packit Service |
310c69 |
* that the block map is entirely arboreal.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param logicalBlocks The number of blocks to map
|
|
Packit Service |
310c69 |
* @param rootCount The number of trees in the forest
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return A (slight) over-estimate of the total number of possible forest
|
|
Packit Service |
310c69 |
* pages including the leaves
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
BlockCount computeForestSize(BlockCount logicalBlocks, RootCount rootCount)
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result));
|
|
Packit Service |
310c69 |
#endif // FOREST_H
|