Blame source/vdo/base/vdoInternal.h

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