Blame vdo/base/referenceBlock.h

Packit Service b3514a
/*
Packit Service b3514a
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service b3514a
 *
Packit Service b3514a
 * This program is free software; you can redistribute it and/or
Packit Service b3514a
 * modify it under the terms of the GNU General Public License
Packit Service b3514a
 * as published by the Free Software Foundation; either version 2
Packit Service b3514a
 * of the License, or (at your option) any later version.
Packit Service b3514a
 * 
Packit Service b3514a
 * This program is distributed in the hope that it will be useful,
Packit Service b3514a
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service b3514a
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service b3514a
 * GNU General Public License for more details.
Packit Service b3514a
 * 
Packit Service b3514a
 * You should have received a copy of the GNU General Public License
Packit Service b3514a
 * along with this program; if not, write to the Free Software
Packit Service b3514a
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service b3514a
 * 02110-1301, USA. 
Packit Service b3514a
 *
Packit Service b3514a
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/referenceBlock.h#1 $
Packit Service b3514a
 */
Packit Service b3514a
Packit Service b3514a
#ifndef REFERENCE_BLOCK_H
Packit Service b3514a
#define REFERENCE_BLOCK_H
Packit Service b3514a
Packit Service b3514a
#include "constants.h"
Packit Service b3514a
#include "journalPoint.h"
Packit Service b3514a
#include "types.h"
Packit Service b3514a
#include "waitQueue.h"
Packit Service b3514a
Packit Service b3514a
/**
Packit Service b3514a
 * A type representing a reference count.
Packit Service b3514a
 **/
Packit Service b3514a
typedef uint8_t ReferenceCount;
Packit Service b3514a
Packit Service b3514a
/**
Packit Service b3514a
 * Special ReferenceCount values.
Packit Service b3514a
 **/
Packit Service b3514a
enum {
Packit Service b3514a
  EMPTY_REFERENCE_COUNT       = 0,
Packit Service b3514a
  MAXIMUM_REFERENCE_COUNT     = 254,
Packit Service b3514a
  PROVISIONAL_REFERENCE_COUNT = 255,
Packit Service b3514a
};
Packit Service b3514a
Packit Service b3514a
enum {
Packit Service b3514a
  COUNTS_PER_SECTOR = ((VDO_SECTOR_SIZE - sizeof(PackedJournalPoint))
Packit Service b3514a
                       / sizeof(ReferenceCount)),
Packit Service b3514a
  COUNTS_PER_BLOCK  = COUNTS_PER_SECTOR * SECTORS_PER_BLOCK,
Packit Service b3514a
};
Packit Service b3514a
Packit Service b3514a
/**
Packit Service b3514a
 * The format of a ReferenceSector on disk.
Packit Service b3514a
 **/
Packit Service b3514a
typedef struct {
Packit Service b3514a
  PackedJournalPoint commitPoint;
Packit Service b3514a
  ReferenceCount     counts[COUNTS_PER_SECTOR];
Packit Service b3514a
} __attribute__((packed)) PackedReferenceSector;
Packit Service b3514a
Packit Service b3514a
typedef struct {
Packit Service b3514a
  PackedReferenceSector sectors[SECTORS_PER_BLOCK];
Packit Service b3514a
} PackedReferenceBlock;
Packit Service b3514a
Packit Service b3514a
/*
Packit Service b3514a
 * ReferenceBlock structure
Packit Service b3514a
 *
Packit Service b3514a
 * Blocks are used as a proxy, permitting saves of partial refcounts.
Packit Service b3514a
 **/
Packit Service b3514a
typedef struct {
Packit Service b3514a
  /** This block waits on the refCounts to tell it to write */
Packit Service b3514a
  Waiter          waiter;
Packit Service b3514a
  /** The parent RefCount structure */
Packit Service b3514a
  RefCounts      *refCounts;
Packit Service b3514a
  /** The number of references in this block that represent allocations */
Packit Service b3514a
  BlockSize       allocatedCount;
Packit Service b3514a
  /** The slab journal block on which this block must hold a lock */
Packit Service b3514a
  SequenceNumber  slabJournalLock;
Packit Service b3514a
  /**
Packit Service b3514a
   * The slab journal block which should be released when this block
Packit Service b3514a
   * is committed
Packit Service b3514a
   **/
Packit Service b3514a
  SequenceNumber  slabJournalLockToRelease;
Packit Service b3514a
  /** The point up to which each sector is accurate on disk */
Packit Service b3514a
  JournalPoint    commitPoints[SECTORS_PER_BLOCK];
Packit Service b3514a
  /** Whether this block has been modified since it was written to disk */
Packit Service b3514a
  bool            isDirty;
Packit Service b3514a
  /** Whether this block is currently writing */
Packit Service b3514a
  bool            isWriting;
Packit Service b3514a
} ReferenceBlock;
Packit Service b3514a
Packit Service b3514a
#endif // REFERENCE_BLOCK_H