Blame source/vdo/base/vdoInternal.h

Packit Service cbade1
/*
Packit Service cbade1
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service cbade1
 *
Packit Service cbade1
 * This program is free software; you can redistribute it and/or
Packit Service cbade1
 * modify it under the terms of the GNU General Public License
Packit Service cbade1
 * as published by the Free Software Foundation; either version 2
Packit Service cbade1
 * of the License, or (at your option) any later version.
Packit Service cbade1
 * 
Packit Service cbade1
 * This program is distributed in the hope that it will be useful,
Packit Service cbade1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service cbade1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service cbade1
 * GNU General Public License for more details.
Packit Service cbade1
 * 
Packit Service cbade1
 * You should have received a copy of the GNU General Public License
Packit Service cbade1
 * along with this program; if not, write to the Free Software
Packit Service cbade1
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service cbade1
 * 02110-1301, USA. 
Packit Service cbade1
 *
Packit Service cbade1
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/vdoInternal.h#11 $
Packit Service cbade1
 */
Packit Service cbade1
Packit Service cbade1
#ifndef VDO_INTERNAL_H
Packit Service cbade1
#define VDO_INTERNAL_H
Packit Service cbade1
Packit Service cbade1
#include "vdo.h"
Packit Service cbade1
Packit Service cbade1
#include "adminCompletion.h"
Packit Service cbade1
#include "adminState.h"
Packit Service cbade1
#include "atomic.h"
Packit Service cbade1
#include "header.h"
Packit Service cbade1
#include "packer.h"
Packit Service cbade1
#include "statistics.h"
Packit Service cbade1
#include "superBlock.h"
Packit Service cbade1
#include "readOnlyNotifier.h"
Packit Service cbade1
#include "types.h"
Packit Service cbade1
#include "uds.h"
Packit Service cbade1
#include "vdoLayout.h"
Packit Service cbade1
#include "vdoState.h"
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Error counters are atomic since updates can arrive concurrently from
Packit Service cbade1
 * arbitrary threads.
Packit Service cbade1
 **/
Packit Service cbade1
typedef struct atomicErrorStatistics {
Packit Service cbade1
  // Dedupe path error stats
Packit Service cbade1
  Atomic64 invalidAdvicePBNCount;
Packit Service cbade1
  Atomic64 noSpaceErrorCount;
Packit Service cbade1
  Atomic64 readOnlyErrorCount;
Packit Service cbade1
} AtomicErrorStatistics;
Packit Service cbade1
Packit Service cbade1
struct vdo {
Packit Service cbade1
  /* The state of this VDO */
Packit Service cbade1
  VDOState              state;
Packit Service cbade1
  /* The read-only notifier */
Packit Service cbade1
  ReadOnlyNotifier     *readOnlyNotifier;
Packit Service cbade1
  /* The number of times this VDO has recovered from a dirty state */
Packit Service cbade1
  uint64_t              completeRecoveries;
Packit Service cbade1
  /* The number of times this VDO has recovered from a read-only state */
Packit Service cbade1
  uint64_t              readOnlyRecoveries;
Packit Service cbade1
  /* The format-time configuration of this VDO */
Packit Service cbade1
  VDOConfig             config;
Packit Service cbade1
  /* The load-time configuration of this VDO */
Packit Service cbade1
  VDOLoadConfig         loadConfig;
Packit Service cbade1
  /* The nonce for this VDO */
Packit Service cbade1
  Nonce                 nonce;
Packit Service cbade1
Packit Service cbade1
  /* The super block */
Packit Service cbade1
  SuperBlock           *superBlock;
Packit Service cbade1
Packit Service cbade1
  /* The physical storage below us */
Packit Service cbade1
  PhysicalLayer        *layer;
Packit Service cbade1
Packit Service cbade1
  /* Our partitioning of the physical layer's storage */
Packit Service cbade1
  VDOLayout            *layout;
Packit Service cbade1
Packit Service cbade1
  /* The block map */
Packit Service cbade1
  BlockMap             *blockMap;
Packit Service cbade1
Packit Service cbade1
  /* The journal for block map recovery */
Packit Service cbade1
  RecoveryJournal      *recoveryJournal;
Packit Service cbade1
Packit Service cbade1
  /* The slab depot */
Packit Service cbade1
  SlabDepot            *depot;
Packit Service cbade1
Packit Service cbade1
  /* The compressed-block packer */
Packit Service cbade1
  Packer               *packer;
Packit Service cbade1
  /* Whether incoming data should be compressed */
Packit Service cbade1
  AtomicBool            compressing;
Packit Service cbade1
Packit Service cbade1
  /* The handler for flush requests */
Packit Service cbade1
  Flusher              *flusher;
Packit Service cbade1
Packit Service cbade1
  /* The master version of the VDO when loaded (for upgrading) */
Packit Service cbade1
  VersionNumber         loadVersion;
Packit Service cbade1
  /* The state the VDO was in when loaded (primarily for unit tests) */
Packit Service cbade1
  VDOState              loadState;
Packit Service cbade1
  /* Whether VIO tracing is enabled */
Packit Service cbade1
  bool                  vioTraceRecording;
Packit Service cbade1
Packit Service cbade1
  /* The logical zones of this VDO */
Packit Service cbade1
  LogicalZones          *logicalZones;
Packit Service cbade1
Packit Service cbade1
  /* The physical zones of this VDO */
Packit Service cbade1
  PhysicalZone         **physicalZones;
Packit Service cbade1
Packit Service cbade1
  /* The hash lock zones of this VDO */
Packit Service cbade1
  HashZone             **hashZones;
Packit Service cbade1
Packit Service cbade1
  /* The completion for administrative operations */
Packit Service cbade1
  AdminCompletion        adminCompletion;
Packit Service cbade1
Packit Service cbade1
  /* The administrative state of the VDO */
Packit Service cbade1
  AdminState             adminState;
Packit Service cbade1
Packit Service cbade1
  /* Whether a close is required */
Packit Service cbade1
  bool                   closeRequired;
Packit Service cbade1
Packit Service cbade1
  /* Atomic global counts of error events */
Packit Service cbade1
  AtomicErrorStatistics  errorStats;
Packit Service cbade1
};
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Get the component data size of a VDO.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO whose component data size is desired
Packit Service cbade1
 *
Packit Service cbade1
 * @return the component data size of the VDO
Packit Service cbade1
 **/
Packit Service cbade1
size_t getComponentDataSize(VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Encode the VDO and save the super block synchronously.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO whose state is being saved
Packit Service cbade1
 *
Packit Service cbade1
 * @return VDO_SUCCESS or an error
Packit Service cbade1
 **/
Packit Service cbade1
int saveVDOComponents(VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Encode the VDO and save the super block asynchronously. All non-user mode
Packit Service cbade1
 * super block savers should use this bottle neck instead of calling
Packit Service cbade1
 * saveSuperBlockAsync() directly.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo     The VDO whose state is being saved
Packit Service cbade1
 * @param parent  The completion to notify when the save is complete
Packit Service cbade1
 **/
Packit Service cbade1
void saveVDOComponentsAsync(VDO *vdo, VDOCompletion *parent);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Re-encode the VDO component after a reconfiguration and save the super
Packit Service cbade1
 * block synchronously. This function avoids the need to decode and re-encode
Packit Service cbade1
 * the other components by simply copying their previous encoding.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO which was reconfigured
Packit Service cbade1
 *
Packit Service cbade1
 * @return VDO_SUCCESS or an error code
Packit Service cbade1
 **/
Packit Service cbade1
int saveReconfiguredVDO(VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Decode the VDO master version from the component data buffer in the super
Packit Service cbade1
 * block and store it in the VDO's loadVersion field.
Packit Service cbade1
 **/
Packit Service cbade1
int decodeVDOVersion(VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Loads the VDO master version into the VDO and checks that the version
Packit Service cbade1
 * can be understood by VDO.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to validate
Packit Service cbade1
 *
Packit Service cbade1
 * @return VDO_SUCCESS or an error if the loaded version is not supported
Packit Service cbade1
 **/
Packit Service cbade1
int validateVDOVersion(VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Decode the component data for the VDO itself from the component data buffer
Packit Service cbade1
 * in the super block.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to decode
Packit Service cbade1
 *
Packit Service cbade1
 * @return VDO_SUCCESS or an error
Packit Service cbade1
 **/
Packit Service cbade1
int decodeVDOComponent(VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Validate constraints on VDO config.
Packit Service cbade1
 *
Packit Service cbade1
 * @param config          The VDO config
Packit Service cbade1
 * @param blockCount      The block count of the VDO
Packit Service cbade1
 * @param requireLogical  Set to true if the number logical blocks
Packit Service cbade1
 *                        must be configured (otherwise, it may be zero)
Packit Service cbade1
 *
Packit Service cbade1
 * @return a success or error code
Packit Service cbade1
 **/
Packit Service cbade1
int validateVDOConfig(const VDOConfig *config,
Packit Service cbade1
                      BlockCount       blockCount,
Packit Service cbade1
                      bool             requireLogical)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Enable a VDO to enter read-only mode on errors.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to enable
Packit Service cbade1
 *
Packit Service cbade1
 * @return VDO_SUCCESS or an error
Packit Service cbade1
 **/
Packit Service cbade1
int enableReadOnlyEntry(VDO *vdo);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Get the block map.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO whose block map is desired
Packit Service cbade1
 *
Packit Service cbade1
 * @return the block map from the VDO
Packit Service cbade1
 **/
Packit Service cbade1
BlockMap *getBlockMap(const VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Get the slab depot from a VDO.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO whose slab depot is desired
Packit Service cbade1
 *
Packit Service cbade1
 * @return the slab depot from the VDO
Packit Service cbade1
 **/
Packit Service cbade1
SlabDepot *getSlabDepot(VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Get the recovery journal from a VDO.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO whose recovery journal is desired
Packit Service cbade1
 *
Packit Service cbade1
 * @return the recovery journal from the VDO
Packit Service cbade1
 **/
Packit Service cbade1
RecoveryJournal *getRecoveryJournal(VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Check whether a VDO is in read-only mode.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to query
Packit Service cbade1
 *
Packit Service cbade1
 * @return true if the VDO is in read-only mode
Packit Service cbade1
 **/
Packit Service cbade1
bool inReadOnlyMode(const VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Check whether the VDO is in a clean state.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to query
Packit Service cbade1
 *
Packit Service cbade1
 * @return true if the VDO is clean
Packit Service cbade1
 **/
Packit Service cbade1
bool isClean(const VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Check whether the VDO was in a clean state when it was loaded.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to query
Packit Service cbade1
 *
Packit Service cbade1
 * @return true if the VDO was clean
Packit Service cbade1
 **/
Packit Service cbade1
bool wasClean(const VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Check whether the VDO requires a read-only mode rebuild.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to query
Packit Service cbade1
 *
Packit Service cbade1
 * @return true if the VDO requires a read-only rebuild
Packit Service cbade1
 **/
Packit Service cbade1
bool requiresReadOnlyRebuild(const VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Check whether a VDO requires rebuilding.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to query
Packit Service cbade1
 *
Packit Service cbade1
 * @return true if the VDO must be rebuilt
Packit Service cbade1
 **/
Packit Service cbade1
bool requiresRebuild(const VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Check whether a VDO should enter recovery mode.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to query
Packit Service cbade1
 *
Packit Service cbade1
 * @return true if the VDO requires recovery
Packit Service cbade1
 **/
Packit Service cbade1
bool requiresRecovery(const VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Check whether a VDO was replaying the recovery journal into the block map
Packit Service cbade1
 * when it crashed.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to query
Packit Service cbade1
 *
Packit Service cbade1
 * @return true if the VDO crashed while reconstructing the
Packit Service cbade1
 *         block map
Packit Service cbade1
 **/
Packit Service cbade1
bool isReplaying(const VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Check whether the VDO is in recovery mode.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO to query
Packit Service cbade1
 *
Packit Service cbade1
 * @return true if the VDO is in recovery mode
Packit Service cbade1
 **/
Packit Service cbade1
bool inRecoveryMode(const VDO *vdo)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Put the VDO into recovery mode
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO
Packit Service cbade1
 **/
Packit Service cbade1
void enterRecoveryMode(VDO *vdo);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Leave recovery mode if slab scrubbing has actually finished.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo  The VDO
Packit Service cbade1
 **/
Packit Service cbade1
void leaveRecoveryMode(VDO *vdo);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Assert that we are running on the admin thread.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo   The VDO
Packit Service cbade1
 * @param name  The name of the function which should be running on the admin
Packit Service cbade1
 *              thread (for logging).
Packit Service cbade1
 **/
Packit Service cbade1
void assertOnAdminThread(VDO *vdo, const char *name);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Assert that this function was called on the specified logical zone thread.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo          The VDO
Packit Service cbade1
 * @param logicalZone  The number of the logical zone
Packit Service cbade1
 * @param name         The name of the calling function
Packit Service cbade1
 **/
Packit Service cbade1
void assertOnLogicalZoneThread(const VDO  *vdo,
Packit Service cbade1
                               ZoneCount   logicalZone,
Packit Service cbade1
                               const char *name);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Assert that this function was called on the specified physical zone thread.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo           The VDO
Packit Service cbade1
 * @param physicalZone  The number of the physical zone
Packit Service cbade1
 * @param name          The name of the calling function
Packit Service cbade1
 **/
Packit Service cbade1
void assertOnPhysicalZoneThread(const VDO  *vdo,
Packit Service cbade1
                                ZoneCount   physicalZone,
Packit Service cbade1
                                const char *name);
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Select the hash zone responsible for locking a given chunk name.
Packit Service cbade1
 *
Packit Service cbade1
 * @param vdo   The VDO containing the hash zones
Packit Service cbade1
 * @param name  The chunk name
Packit Service cbade1
 *
Packit Service cbade1
 * @return  The hash zone responsible for the chunk name
Packit Service cbade1
 **/
Packit Service cbade1
HashZone *selectHashZone(const VDO *vdo, const UdsChunkName *name)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**
Packit Service cbade1
 * Get the physical zone responsible for a given physical block number of a
Packit Service cbade1
 * data block in this VDO instance, or of the zero block (for which a NULL
Packit Service cbade1
 * zone is returned). For any other block number that is not in the range of
Packit Service cbade1
 * valid data block numbers in any slab, an error will be returned. This
Packit Service cbade1
 * function is safe to call on invalid block numbers; it will not put the VDO
Packit Service cbade1
 * into read-only mode.
Packit Service cbade1
 *
Packit Service cbade1
 * @param [in]  vdo      The VDO containing the physical zones
Packit Service cbade1
 * @param [in]  pbn      The PBN of the data block
Packit Service cbade1
 * @param [out] zonePtr  A pointer to return the physical zone
Packit Service cbade1
 *
Packit Service cbade1
 * @return VDO_SUCCESS or VDO_OUT_OF_RANGE if the block number is invalid
Packit Service cbade1
 *         or an error code for any other failure
Packit Service cbade1
 **/
Packit Service cbade1
int getPhysicalZone(const VDO            *vdo,
Packit Service cbade1
                    PhysicalBlockNumber   pbn,
Packit Service cbade1
                    PhysicalZone        **zonePtr)
Packit Service cbade1
  __attribute__((warn_unused_result));
Packit Service cbade1
Packit Service cbade1
/**********************************************************************/
Packit Service cbade1
// Asynchronous callback to share a duplicate block. This is only public so
Packit Service cbade1
// test code may compare it against the current callback in the completion.
Packit Service cbade1
void shareBlock(VDOCompletion *completion);
Packit Service cbade1
Packit Service cbade1
#endif /* VDO_INTERNAL_H */