Blame source/vdo/base/hashLockInternals.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/hashLockInternals.h#2 $
Packit Service 310c69
 */
Packit Service 310c69
Packit Service 310c69
#ifndef HASH_LOCK_INTERNALS_H
Packit Service 310c69
#define HASH_LOCK_INTERNALS_H
Packit Service 310c69
Packit Service 310c69
#include "completion.h"
Packit Service 310c69
#include "ringNode.h"
Packit Service 310c69
#include "types.h"
Packit Service 310c69
#include "uds.h"
Packit Service 310c69
#include "waitQueue.h"
Packit Service 310c69
Packit Service 310c69
typedef enum {
Packit Service 310c69
  /** State for locks that are not in use or are being initialized. */
Packit Service 310c69
  HASH_LOCK_INITIALIZING = 0,
Packit Service 310c69
Packit Service 310c69
  // This is the sequence of states typically used on the non-dedupe path.
Packit Service 310c69
  HASH_LOCK_QUERYING,
Packit Service 310c69
  HASH_LOCK_WRITING,
Packit Service 310c69
  HASH_LOCK_UPDATING,
Packit Service 310c69
Packit Service 310c69
  // The remaining states are typically used on the dedupe path in this order.
Packit Service 310c69
  HASH_LOCK_LOCKING,
Packit Service 310c69
  HASH_LOCK_VERIFYING,
Packit Service 310c69
  HASH_LOCK_DEDUPING,
Packit Service 310c69
  HASH_LOCK_UNLOCKING,
Packit Service 310c69
Packit Service 310c69
  // XXX This is a temporary state denoting a lock which is sending VIOs back
Packit Service 310c69
  // to the old dedupe and vioWrite pathways. It won't be in the final version
Packit Service 310c69
  // of VDOSTORY-190.
Packit Service 310c69
  HASH_LOCK_BYPASSING,
Packit Service 310c69
Packit Service 310c69
  /**
Packit Service 310c69
   * Terminal state for locks returning to the pool. Must be last both because
Packit Service 310c69
   * it's the final state, and also because it's used to count the states.
Packit Service 310c69
   **/
Packit Service 310c69
  HASH_LOCK_DESTROYING,
Packit Service 310c69
} HashLockState;
Packit Service 310c69
Packit Service 310c69
struct hashLock {
Packit Service 310c69
  /** When the lock is unused, this RingNode allows the lock to be pooled */
Packit Service 310c69
  RingNode       poolNode;
Packit Service 310c69
Packit Service 310c69
  /** The block hash covered by this lock */
Packit Service 310c69
  UdsChunkName   hash;
Packit Service 310c69
Packit Service 310c69
  /**
Packit Service 310c69
   * A ring containing the DataVIOs sharing this lock, all having the same
Packit Service 310c69
   * chunk name and data block contents, linked by their hashLockNode fields.
Packit Service 310c69
   **/
Packit Service 310c69
  RingNode       duplicateRing;
Packit Service 310c69
Packit Service 310c69
  /** The number of DataVIOs sharing this lock instance */
Packit Service 310c69
  VIOCount       referenceCount;
Packit Service 310c69
Packit Service 310c69
  /** The maximum value of referenceCount in the lifetime of this lock */
Packit Service 310c69
  VIOCount       maxReferences;
Packit Service 310c69
Packit Service 310c69
  /** The current state of this lock */
Packit Service 310c69
  HashLockState  state;
Packit Service 310c69
Packit Service 310c69
  /** True if the UDS index should be updated with new advice */
Packit Service 310c69
  bool           updateAdvice;
Packit Service 310c69
Packit Service 310c69
  /** True if the advice has been verified to be a true duplicate */
Packit Service 310c69
  bool           verified;
Packit Service 310c69
Packit Service 310c69
  /** True if the lock has already accounted for an initial verification */
Packit Service 310c69
  bool           verifyCounted;
Packit Service 310c69
Packit Service 310c69
  /** True if this lock is registered in the lock map (cleared on rollover) */
Packit Service 310c69
  bool           registered;
Packit Service 310c69
Packit Service 310c69
  /**
Packit Service 310c69
   * If verified is false, this is the location of a possible duplicate.
Packit Service 310c69
   * If verified is true, is is the verified location of a true duplicate.
Packit Service 310c69
   **/
Packit Service 310c69
  ZonedPBN       duplicate;
Packit Service 310c69
Packit Service 310c69
  /** The PBN lock on the block containing the duplicate data */
Packit Service 310c69
  PBNLock       *duplicateLock;
Packit Service 310c69
Packit Service 310c69
  /** The DataVIO designated to act on behalf of the lock */
Packit Service 310c69
  DataVIO       *agent;
Packit Service 310c69
Packit Service 310c69
  /**
Packit Service 310c69
   * Other DataVIOs with data identical to the agent who are currently waiting
Packit Service 310c69
   * for the agent to get the information they all need to deduplicate--either
Packit Service 310c69
   * against each other, or against an existing duplicate on disk.
Packit Service 310c69
   **/
Packit Service 310c69
  WaitQueue      waiters;
Packit Service 310c69
};
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Initialize a HashLock instance which has been newly allocated.
Packit Service 310c69
 *
Packit Service 310c69
 * @param lock  The lock to initialize
Packit Service 310c69
 **/
Packit Service 310c69
static inline void initializeHashLock(HashLock *lock)
Packit Service 310c69
{
Packit Service 310c69
  initializeRing(&lock->poolNode);
Packit Service 310c69
  initializeRing(&lock->duplicateRing);
Packit Service 310c69
  initializeWaitQueue(&lock->waiters);
Packit Service 310c69
}
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the string representation of a hash lock state.
Packit Service 310c69
 *
Packit Service 310c69
 * @param state  The hash lock state
Packit Service 310c69
 *
Packit Service 310c69
 * @return The short string representing the state
Packit Service 310c69
 **/
Packit Service 310c69
const char *getHashLockStateName(HashLockState state)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
#endif // HASH_LOCK_INTERNALS_H