|
Packit Service |
cbade1 |
/*
|
|
Packit Service |
cbade1 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
cbade1 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
cbade1 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
cbade1 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
cbade1 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
cbade1 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
cbade1 |
* GNU General Public License for more details.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
cbade1 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
cbade1 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
cbade1 |
* 02110-1301, USA.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/vioPool.h#4 $
|
|
Packit Service |
cbade1 |
*/
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
#ifndef VIO_POOL_H
|
|
Packit Service |
cbade1 |
#define VIO_POOL_H
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
#include "permassert.h"
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
#include "completion.h"
|
|
Packit Service |
cbade1 |
#include "types.h"
|
|
Packit Service |
cbade1 |
#include "waitQueue.h"
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* A VIOPool is a collection of preallocated VIOs used to write arbitrary
|
|
Packit Service |
cbade1 |
* metadata blocks.
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* An VIOPoolEntry is the pair of VIO and buffer whether in use or not.
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
typedef struct {
|
|
Packit Service |
cbade1 |
RingNode node;
|
|
Packit Service |
cbade1 |
VIO *vio;
|
|
Packit Service |
cbade1 |
void *buffer;
|
|
Packit Service |
cbade1 |
void *parent;
|
|
Packit Service |
cbade1 |
void *context;
|
|
Packit Service |
cbade1 |
} VIOPoolEntry;
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* A function which constructs a VIO for a pool.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param [in] layer The physical layer in which the VIO will operate
|
|
Packit Service |
cbade1 |
* @param [in] parent The parent of the VIO
|
|
Packit Service |
cbade1 |
* @param [in] buffer The data buffer for the VIO
|
|
Packit Service |
cbade1 |
* @param [out] vioPtr A pointer to hold the new VIO
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
typedef int VIOConstructor(PhysicalLayer *layer,
|
|
Packit Service |
cbade1 |
void *parent,
|
|
Packit Service |
cbade1 |
void *buffer,
|
|
Packit Service |
cbade1 |
VIO **vioPtr);
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Create a new VIO pool.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param [in] layer the physical layer to write to and read from
|
|
Packit Service |
cbade1 |
* @param [in] poolSize the number of VIOs in the pool
|
|
Packit Service |
cbade1 |
* @param [in] threadID the ID of the thread using this pool
|
|
Packit Service |
cbade1 |
* @param [in] vioConstructor the constructor for VIOs in the pool
|
|
Packit Service |
cbade1 |
* @param [in] context the context that each entry will have
|
|
Packit Service |
cbade1 |
* @param [out] poolPtr the resulting pool
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @return a success or error code
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
int makeVIOPool(PhysicalLayer *layer,
|
|
Packit Service |
cbade1 |
size_t poolSize,
|
|
Packit Service |
cbade1 |
ThreadID threadID,
|
|
Packit Service |
cbade1 |
VIOConstructor *vioConstructor,
|
|
Packit Service |
cbade1 |
void *context,
|
|
Packit Service |
cbade1 |
VIOPool **poolPtr)
|
|
Packit Service |
cbade1 |
__attribute__((warn_unused_result));
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Destroy a VIO pool
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param poolPtr the pointer holding the pool, which will be nulled out
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
void freeVIOPool(VIOPool **poolPtr);
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Check whether an VIO pool has outstanding entries.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @return true if the pool is busy
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
bool isVIOPoolBusy(VIOPool *pool)
|
|
Packit Service |
cbade1 |
__attribute__((warn_unused_result));
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Acquire a VIO and buffer from the pool (asynchronous).
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param pool the VIO pool
|
|
Packit Service |
cbade1 |
* @param waiter object that is requesting a VIO
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
int acquireVIOFromPool(VIOPool *pool, Waiter *waiter);
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Return a VIO and its buffer to the pool.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param pool the VIO pool
|
|
Packit Service |
cbade1 |
* @param entry a VIO pool entry
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
void returnVIOToPool(VIOPool *pool, VIOPoolEntry *entry);
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Convert a RingNode to the VIOPoolEntry that contains it.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param node The RingNode to convert
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @return The VIOPoolEntry wrapping the RingNode
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
static inline VIOPoolEntry *asVIOPoolEntry(RingNode *node)
|
|
Packit Service |
cbade1 |
{
|
|
Packit Service |
cbade1 |
STATIC_ASSERT(offsetof(VIOPoolEntry, node) == 0);
|
|
Packit Service |
cbade1 |
return (VIOPoolEntry *) node;
|
|
Packit Service |
cbade1 |
}
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
/**
|
|
Packit Service |
cbade1 |
* Return the outage count of an VIO pool.
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @param pool The pool
|
|
Packit Service |
cbade1 |
*
|
|
Packit Service |
cbade1 |
* @return the number of times an acquisition request had to wait
|
|
Packit Service |
cbade1 |
**/
|
|
Packit Service |
cbade1 |
uint64_t getVIOPoolOutageCount(VIOPool *pool)
|
|
Packit Service |
cbade1 |
__attribute__((warn_unused_result));
|
|
Packit Service |
cbade1 |
|
|
Packit Service |
cbade1 |
#endif // VIO_POOL_H
|