Blame source/vdo/base/physicalZone.h

Packit Service d40955
/*
Packit Service d40955
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service d40955
 *
Packit Service d40955
 * This program is free software; you can redistribute it and/or
Packit Service d40955
 * modify it under the terms of the GNU General Public License
Packit Service d40955
 * as published by the Free Software Foundation; either version 2
Packit Service d40955
 * of the License, or (at your option) any later version.
Packit Service d40955
 * 
Packit Service d40955
 * This program is distributed in the hope that it will be useful,
Packit Service d40955
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service d40955
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service d40955
 * GNU General Public License for more details.
Packit Service d40955
 * 
Packit Service d40955
 * You should have received a copy of the GNU General Public License
Packit Service d40955
 * along with this program; if not, write to the Free Software
Packit Service d40955
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service d40955
 * 02110-1301, USA. 
Packit Service d40955
 *
Packit Service d40955
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/physicalZone.h#1 $
Packit Service d40955
 */
Packit Service d40955
Packit Service d40955
#ifndef PHYSICAL_ZONE_H
Packit Service d40955
#define PHYSICAL_ZONE_H
Packit Service d40955
Packit Service d40955
#include "pbnLock.h"
Packit Service d40955
#include "types.h"
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Create a physical zone.
Packit Service d40955
 *
Packit Service d40955
 * @param [in]  vdo         The VDO to which the zone will belong
Packit Service d40955
 * @param [in]  zoneNumber  The number of the zone to create
Packit Service d40955
 * @param [out] zonePtr     A pointer to hold the new PhysicalZone
Packit Service d40955
 *
Packit Service d40955
 * @return VDO_SUCCESS or an error code
Packit Service d40955
 **/
Packit Service d40955
int makePhysicalZone(VDO *vdo, ZoneCount zoneNumber, PhysicalZone **zonePtr)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Free a physical zone and null out the reference to it.
Packit Service d40955
 *
Packit Service d40955
 * @param zonePtr  A pointer to the zone to free
Packit Service d40955
 **/
Packit Service d40955
void freePhysicalZone(PhysicalZone **zonePtr);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Get the zone number of a physical zone.
Packit Service d40955
 *
Packit Service d40955
 * @param zone  The zone
Packit Service d40955
 *
Packit Service d40955
 * @return The number of the zone
Packit Service d40955
 **/
Packit Service d40955
ZoneCount getPhysicalZoneNumber(const PhysicalZone *zone)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Get the ID of a physical zone's thread.
Packit Service d40955
 *
Packit Service d40955
 * @param zone  The zone
Packit Service d40955
 *
Packit Service d40955
 * @return The zone's thread ID
Packit Service d40955
 **/
Packit Service d40955
ThreadID getPhysicalZoneThreadID(const PhysicalZone *zone)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Get the block allocator from a physical zone.
Packit Service d40955
 *
Packit Service d40955
 * @param zone  The zone
Packit Service d40955
 *
Packit Service d40955
 * @return The zone's allocator
Packit Service d40955
 **/
Packit Service d40955
BlockAllocator *getBlockAllocator(const PhysicalZone *zone)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Get the lock on a PBN if one exists.
Packit Service d40955
 *
Packit Service d40955
 * @param zone  The physical zone responsible for the PBN
Packit Service d40955
 * @param pbn   The physical block number whose lock is desired
Packit Service d40955
 *
Packit Service d40955
 * @return The lock or NULL if the PBN is not locked
Packit Service d40955
 **/
Packit Service d40955
PBNLock *getPBNLock(PhysicalZone *zone, PhysicalBlockNumber pbn)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Attempt to lock a physical block in the zone responsible for it. If the PBN
Packit Service d40955
 * is already locked, the existing lock will be returned. Otherwise, a new
Packit Service d40955
 * lock instance will be borrowed from the pool, initialized, and returned.
Packit Service d40955
 * The lock owner will be NULL for a new lock acquired by the caller, who is
Packit Service d40955
 * responsible for setting that field promptly. The lock owner will be
Packit Service d40955
 * non-NULL when there is already an existing lock on the PBN.
Packit Service d40955
 *
Packit Service d40955
 * @param [in]  zone     The physical zone responsible for the PBN
Packit Service d40955
 * @param [in]  pbn      The physical block number to lock
Packit Service d40955
 * @param [in]  type     The type with which to initialize a new lock
Packit Service d40955
 * @param [out] lockPtr  A pointer to receive the lock, existing or new
Packit Service d40955
 *
Packit Service d40955
 * @return VDO_SUCCESS or an error
Packit Service d40955
 **/
Packit Service d40955
int attemptPBNLock(PhysicalZone         *zone,
Packit Service d40955
                   PhysicalBlockNumber   pbn,
Packit Service d40955
                   PBNLockType           type,
Packit Service d40955
                   PBNLock             **lockPtr)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Release a physical block lock if it is held, return it to the lock pool,
Packit Service d40955
 * and null out the caller's reference to it. It must be the last live
Packit Service d40955
 * reference, as if the memory were being freed (the lock memory will
Packit Service d40955
 * re-initialized or zeroed).
Packit Service d40955
 *
Packit Service d40955
 * @param [in]     zone       The physical zone in which the lock was obtained
Packit Service d40955
 * @param [in]     lockedPBN  The physical block number to unlock
Packit Service d40955
 * @param [in,out] lockPtr    The last reference to the lock being released
Packit Service d40955
 **/
Packit Service d40955
void releasePBNLock(PhysicalZone         *zone,
Packit Service d40955
                    PhysicalBlockNumber   lockedPBN,
Packit Service d40955
                    PBNLock             **lockPtr);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Dump information about a physical zone to the log for debugging.
Packit Service d40955
 *
Packit Service d40955
 * @param zone   The zone to dump
Packit Service d40955
 **/
Packit Service d40955
void dumpPhysicalZone(const PhysicalZone *zone);
Packit Service d40955
Packit Service d40955
#endif // PHYSICAL_ZONE_H