Blame source/vdo/base/blockAllocator.h

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/blockAllocator.h#12 $
Packit Service 310c69
 */
Packit Service 310c69
Packit Service 310c69
#ifndef BLOCK_ALLOCATOR_H
Packit Service 310c69
#define BLOCK_ALLOCATOR_H
Packit Service 310c69
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
#include "vioPool.h"
Packit Service 310c69
#include "waitQueue.h"
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Create a block allocator.
Packit Service 310c69
 *
Packit Service 310c69
 * @param [in]  depot             The slab depot for this allocator
Packit Service 310c69
 * @param [in]  zoneNumber        The physical zone number for this allocator
Packit Service 310c69
 * @param [in]  threadID          The thread ID for this allocator's zone
Packit Service 310c69
 * @param [in]  nonce             The nonce of the VDO
Packit Service 310c69
 * @param [in]  vioPoolSize       The size of the VIO pool
Packit Service 310c69
 * @param [in]  layer             The physical layer below this allocator
Packit Service 310c69
 * @param [in]  readOnlyNotifier  The context for entering read-only mode
Packit Service 310c69
 * @param [out] allocatorPtr      A pointer to hold the allocator
Packit Service 310c69
 *
Packit Service 310c69
 * @return A success or error code
Packit Service 310c69
 **/
Packit Service 310c69
int makeBlockAllocator(SlabDepot         *depot,
Packit Service 310c69
                       ZoneCount          zoneNumber,
Packit Service 310c69
                       ThreadID           threadID,
Packit Service 310c69
                       Nonce              nonce,
Packit Service 310c69
                       BlockCount         vioPoolSize,
Packit Service 310c69
                       PhysicalLayer     *layer,
Packit Service 310c69
                       ReadOnlyNotifier  *readOnlyNotifier,
Packit Service 310c69
                       BlockAllocator   **allocatorPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Destroy a block allocator and null out the reference to it.
Packit Service 310c69
 *
Packit Service 310c69
 * @param blockAllocatorPtr  The reference to the allocator to destroy
Packit Service 310c69
 **/
Packit Service 310c69
void freeBlockAllocator(BlockAllocator **blockAllocatorPtr);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Queue a slab for allocation or scrubbing.
Packit Service 310c69
 *
Packit Service 310c69
 * @param slab  The slab to queue
Packit Service 310c69
 **/
Packit Service 310c69
void queueSlab(Slab *slab);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Update the block allocator to reflect an increment or decrement of the free
Packit Service 310c69
 * block count in a slab. This adjusts the allocated block count and
Packit Service 310c69
 * reprioritizes the slab when appropriate.
Packit Service 310c69
 *
Packit Service 310c69
 * @param slab       The slab whose free block count changed
Packit Service 310c69
 * @param increment  True if the free block count went up by one,
Packit Service 310c69
 *                   false if it went down by one
Packit Service 310c69
 **/
Packit Service 310c69
void adjustFreeBlockCount(Slab *slab, bool increment);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Allocate a physical block.
Packit Service 310c69
 *
Packit Service 310c69
 * The block allocated will have a provisional reference and the
Packit Service 310c69
 * reference must be either confirmed with a subsequent call to
Packit Service 310c69
 * incrementReferenceCount() or vacated with a subsequent call to
Packit Service 310c69
 * decrementReferenceCount().
Packit Service 310c69
 *
Packit Service 310c69
 * @param [in]  allocator       The block allocator
Packit Service 310c69
 * @param [out] blockNumberPtr  A pointer to receive the allocated block number
Packit Service 310c69
 *
Packit Service 310c69
 * @return UDS_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int allocateBlock(BlockAllocator      *allocator,
Packit Service 310c69
                  PhysicalBlockNumber *blockNumberPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Release an unused provisional reference.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The block allocator
Packit Service 310c69
 * @param pbn        The block to dereference
Packit Service 310c69
 * @param why        Why the block was referenced (for logging)
Packit Service 310c69
 **/
Packit Service 310c69
void releaseBlockReference(BlockAllocator      *allocator,
Packit Service 310c69
                           PhysicalBlockNumber  pbn,
Packit Service 310c69
                           const char          *why);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the number of allocated blocks, which is the total number of
Packit Service 310c69
 * blocks in all slabs that have a non-zero reference count.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The block allocator
Packit Service 310c69
 *
Packit Service 310c69
 * @return The number of blocks with a non-zero reference count
Packit Service 310c69
 **/
Packit Service 310c69
BlockCount getAllocatedBlocks(const BlockAllocator *allocator)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the number of unrecovered slabs.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The block allocator
Packit Service 310c69
 *
Packit Service 310c69
 * @return The number of slabs that are unrecovered
Packit Service 310c69
 **/
Packit Service 310c69
BlockCount getUnrecoveredSlabCount(const BlockAllocator *allocator)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Load the state of an allocator from disk.
Packit Service 310c69
 *
Packit Service 310c69
 * 

Implements ZoneAction.

Packit Service 310c69
 **/
Packit Service 310c69
void loadBlockAllocator(void          *context,
Packit Service 310c69
                        ZoneCount      zoneNumber,
Packit Service 310c69
                        VDOCompletion *parent);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Inform a block allocator that its slab journals have been recovered from the
Packit Service 310c69
 * recovery journal.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The allocator to inform
Packit Service 310c69
 * @param result     The result of the recovery operation
Packit Service 310c69
 **/
Packit Service 310c69
void notifySlabJournalsAreRecovered(BlockAllocator *allocator, int result);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Prepare the block allocator to come online and start allocating blocks.
Packit Service 310c69
 *
Packit Service 310c69
 * 

Implements ZoneAction.

Packit Service 310c69
 **/
Packit Service 310c69
void prepareAllocatorToAllocate(void          *context,
Packit Service 310c69
                                ZoneCount      zoneNumber,
Packit Service 310c69
                                VDOCompletion *parent);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Register a slab with the allocator, ready for use.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The allocator to use
Packit Service 310c69
 * @param slab       The slab in question
Packit Service 310c69
 **/
Packit Service 310c69
void registerSlabWithAllocator(BlockAllocator *allocator, Slab *slab);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Register the new slabs belonging to this allocator.
Packit Service 310c69
 *
Packit Service 310c69
 * 

Implements ZoneAction.

Packit Service 310c69
 **/
Packit Service 310c69
void registerNewSlabsForAllocator(void          *context,
Packit Service 310c69
                                  ZoneCount      zoneNumber,
Packit Service 310c69
                                  VDOCompletion *parent);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Drain all allocator I/O. Depending upon the type of drain, some or all
Packit Service 310c69
 * dirty metadata may be written to disk. The type of drain will be determined
Packit Service 310c69
 * from the state of the allocator's depot.
Packit Service 310c69
 *
Packit Service 310c69
 * 

Implements ZoneAction.

Packit Service 310c69
 **/
Packit Service 310c69
void drainBlockAllocator(void          *context,
Packit Service 310c69
                         ZoneCount      zoneNumber,
Packit Service 310c69
                         VDOCompletion *parent);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Resume a quiescent allocator.
Packit Service 310c69
 *
Packit Service 310c69
 * 

Implements ZoneAction.

Packit Service 310c69
 **/
Packit Service 310c69
void resumeBlockAllocator(void          *context,
Packit Service 310c69
                          ZoneCount      zoneNumber,
Packit Service 310c69
                          VDOCompletion *parent);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Request a commit of all dirty tail blocks which are locking a given recovery
Packit Service 310c69
 * journal block.
Packit Service 310c69
 *
Packit Service 310c69
 * 

Implements ZoneAction.

Packit Service 310c69
 **/
Packit Service 310c69
void releaseTailBlockLocks(void          *context,
Packit Service 310c69
                           ZoneCount      zoneNumber,
Packit Service 310c69
                           VDOCompletion *parent);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the slab summary zone for an allocator.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The allocator
Packit Service 310c69
 *
Packit Service 310c69
 * @return The SlabSummaryZone for that allocator
Packit Service 310c69
 **/
Packit Service 310c69
SlabSummaryZone *getSlabSummaryZone(const BlockAllocator *allocator)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Acquire a VIO from a block allocator's VIO pool (asynchronous).
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The allocator from which to get a VIO
Packit Service 310c69
 * @param waiter     The object requesting the VIO
Packit Service 310c69
 *
Packit Service 310c69
 * @return VDO_SUCCESS or an error
Packit Service 310c69
 **/
Packit Service 310c69
int acquireVIO(BlockAllocator *allocator, Waiter *waiter)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Return a VIO to a block allocator's VIO pool
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The block allocator which owns the VIO
Packit Service 310c69
 * @param entry      The VIO being returned
Packit Service 310c69
 **/
Packit Service 310c69
void returnVIO(BlockAllocator *allocator, VIOPoolEntry *entry);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Initiate scrubbing all unrecovered slabs.
Packit Service 310c69
 *
Packit Service 310c69
 * 

Implements ZoneAction.

Packit Service 310c69
 **/
Packit Service 310c69
void scrubAllUnrecoveredSlabsInZone(void          *context,
Packit Service 310c69
                                    ZoneCount      zoneNumber,
Packit Service 310c69
                                    VDOCompletion *parent);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Queue a waiter for a clean slab.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The allocator to wait on
Packit Service 310c69
 * @param waiter     The waiter
Packit Service 310c69
 *
Packit Service 310c69
 * @return VDO_SUCCESS if the waiter was queued, VDO_NO_SPACE if there are no
Packit Service 310c69
 *         slabs to scrub, and some other error otherwise
Packit Service 310c69
 **/
Packit Service 310c69
int enqueueForCleanSlab(BlockAllocator *allocator, Waiter *waiter)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Increase the scrubbing priority of a slab.
Packit Service 310c69
 *
Packit Service 310c69
 * @param slab  The slab
Packit Service 310c69
 **/
Packit Service 310c69
void increaseScrubbingPriority(Slab *slab);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the statistics for this allocator.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The allocator to query
Packit Service 310c69
 *
Packit Service 310c69
 * @return A copy of the current statistics for the allocator
Packit Service 310c69
 **/
Packit Service 310c69
BlockAllocatorStatistics
Packit Service 310c69
getBlockAllocatorStatistics(const BlockAllocator *allocator)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the aggregated slab journal statistics for the slabs in this allocator.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The allocator to query
Packit Service 310c69
 *
Packit Service 310c69
 * @return A copy of the current statistics for the allocator
Packit Service 310c69
 **/
Packit Service 310c69
SlabJournalStatistics getSlabJournalStatistics(const BlockAllocator *allocator)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the cumulative RefCounts statistics for the slabs in this allocator.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The allocator to query
Packit Service 310c69
 *
Packit Service 310c69
 * @return A copy of the current statistics for the allocator
Packit Service 310c69
 **/
Packit Service 310c69
RefCountsStatistics getRefCountsStatistics(const BlockAllocator *allocator)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Dump information about a block allocator to the log for debugging.
Packit Service 310c69
 *
Packit Service 310c69
 * @param allocator  The allocator to dump
Packit Service 310c69
 **/
Packit Service 310c69
void dumpBlockAllocator(const BlockAllocator *allocator);
Packit Service 310c69
Packit Service 310c69
#endif // BLOCK_ALLOCATOR_H