Blame source/vdo/base/vioPool.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/vioPool.h#4 $
Packit Service 75d76b
 */
Packit Service 75d76b
Packit Service 75d76b
#ifndef VIO_POOL_H
Packit Service 75d76b
#define VIO_POOL_H
Packit Service 75d76b
Packit Service 75d76b
#include "permassert.h"
Packit Service 75d76b
Packit Service 75d76b
#include "completion.h"
Packit Service 75d76b
#include "types.h"
Packit Service 75d76b
#include "waitQueue.h"
Packit Service 75d76b
Packit Service 75d76b
/**
Packit Service 75d76b
 * A VIOPool is a collection of preallocated VIOs used to write arbitrary
Packit Service 75d76b
 * metadata blocks.
Packit Service 75d76b
 **/
Packit Service 75d76b
Packit Service 75d76b
/**
Packit Service 75d76b
 * An VIOPoolEntry is the pair of VIO and buffer whether in use or not.
Packit Service 75d76b
 **/
Packit Service 75d76b
typedef struct {
Packit Service 75d76b
  RingNode  node;
Packit Service 75d76b
  VIO      *vio;
Packit Service 75d76b
  void     *buffer;
Packit Service 75d76b
  void     *parent;
Packit Service 75d76b
  void     *context;
Packit Service 75d76b
} VIOPoolEntry;
Packit Service 75d76b
Packit Service 75d76b
/**
Packit Service 75d76b
 * A function which constructs a VIO for a pool.
Packit Service 75d76b
 *
Packit Service 75d76b
 * @param [in]  layer   The physical layer in which the VIO will operate
Packit Service 75d76b
 * @param [in]  parent  The parent of the VIO
Packit Service 75d76b
 * @param [in]  buffer  The data buffer for the VIO
Packit Service 75d76b
 * @param [out] vioPtr  A pointer to hold the new VIO
Packit Service 75d76b
 **/
Packit Service 75d76b
typedef int VIOConstructor(PhysicalLayer  *layer,
Packit Service 75d76b
                           void           *parent,
Packit Service 75d76b
                           void           *buffer,
Packit Service 75d76b
                           VIO           **vioPtr);
Packit Service 75d76b
Packit Service 75d76b
/**
Packit Service 75d76b
 * Create a new VIO pool.
Packit Service 75d76b
 *
Packit Service 75d76b
 * @param [in]  layer           the physical layer to write to and read from
Packit Service 75d76b
 * @param [in]  poolSize        the number of VIOs in the pool
Packit Service 75d76b
 * @param [in]  threadID        the ID of the thread using this pool
Packit Service 75d76b
 * @param [in]  vioConstructor  the constructor for VIOs in the pool
Packit Service 75d76b
 * @param [in]  context         the context that each entry will have
Packit Service 75d76b
 * @param [out] poolPtr         the resulting pool
Packit Service 75d76b
 *
Packit Service 75d76b
 * @return a success or error code
Packit Service 75d76b
 **/
Packit Service 75d76b
int makeVIOPool(PhysicalLayer   *layer,
Packit Service 75d76b
                size_t           poolSize,
Packit Service 75d76b
                ThreadID         threadID,
Packit Service 75d76b
                VIOConstructor  *vioConstructor,
Packit Service 75d76b
                void            *context,
Packit Service 75d76b
                VIOPool        **poolPtr)
Packit Service 75d76b
  __attribute__((warn_unused_result));
Packit Service 75d76b
Packit Service 75d76b
/**
Packit Service 75d76b
 * Destroy a VIO pool
Packit Service 75d76b
 *
Packit Service 75d76b
 * @param poolPtr  the pointer holding the pool, which will be nulled out
Packit Service 75d76b
 **/
Packit Service 75d76b
void freeVIOPool(VIOPool **poolPtr);
Packit Service 75d76b
Packit Service 75d76b
/**
Packit Service 75d76b
 * Check whether an VIO pool has outstanding entries.
Packit Service 75d76b
 *
Packit Service 75d76b
 * @return true if the pool is busy
Packit Service 75d76b
 **/
Packit Service 75d76b
bool isVIOPoolBusy(VIOPool *pool)
Packit Service 75d76b
  __attribute__((warn_unused_result));
Packit Service 75d76b
Packit Service 75d76b
/**
Packit Service 75d76b
 * Acquire a VIO and buffer from the pool (asynchronous).
Packit Service 75d76b
 *
Packit Service 75d76b
 * @param pool    the VIO pool
Packit Service 75d76b
 * @param waiter  object that is requesting a VIO
Packit Service 75d76b
 *
Packit Service 75d76b
 * @return VDO_SUCCESS or an error
Packit Service 75d76b
 **/
Packit Service 75d76b
int acquireVIOFromPool(VIOPool *pool, Waiter *waiter);
Packit Service 75d76b
Packit Service 75d76b
/**
Packit Service 75d76b
 * Return a VIO and its buffer to the pool.
Packit Service 75d76b
 *
Packit Service 75d76b
 * @param pool   the VIO pool
Packit Service 75d76b
 * @param entry  a VIO pool entry
Packit Service 75d76b
 **/
Packit Service 75d76b
void returnVIOToPool(VIOPool *pool, VIOPoolEntry *entry);
Packit Service 75d76b
Packit Service 75d76b
/**
Packit Service 75d76b
 * Convert a RingNode to the VIOPoolEntry that contains it.
Packit Service 75d76b
 *
Packit Service 75d76b
 * @param node  The RingNode to convert
Packit Service 75d76b
 *
Packit Service 75d76b
 * @return The VIOPoolEntry wrapping the RingNode
Packit Service 75d76b
 **/
Packit Service 75d76b
static inline VIOPoolEntry *asVIOPoolEntry(RingNode *node)
Packit Service 75d76b
{
Packit Service 75d76b
  STATIC_ASSERT(offsetof(VIOPoolEntry, node) == 0);
Packit Service 75d76b
  return (VIOPoolEntry *) node;
Packit Service 75d76b
}
Packit Service 75d76b
Packit Service 75d76b
/**
Packit Service 75d76b
 * Return the outage count of an VIO pool.
Packit Service 75d76b
 *
Packit Service 75d76b
 * @param pool  The pool
Packit Service 75d76b
 *
Packit Service 75d76b
 * @return the number of times an acquisition request had to wait
Packit Service 75d76b
 **/
Packit Service 75d76b
uint64_t getVIOPoolOutageCount(VIOPool *pool)
Packit Service 75d76b
  __attribute__((warn_unused_result));
Packit Service 75d76b
Packit Service 75d76b
#endif // VIO_POOL_H