Blame source/vdo/base/dirtyLists.h

Packit b55c50
/*
Packit b55c50
 * Copyright (c) 2020 Red Hat, Inc.
Packit b55c50
 *
Packit b55c50
 * This program is free software; you can redistribute it and/or
Packit b55c50
 * modify it under the terms of the GNU General Public License
Packit b55c50
 * as published by the Free Software Foundation; either version 2
Packit b55c50
 * of the License, or (at your option) any later version.
Packit b55c50
 * 
Packit b55c50
 * This program is distributed in the hope that it will be useful,
Packit b55c50
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit b55c50
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit b55c50
 * GNU General Public License for more details.
Packit b55c50
 * 
Packit b55c50
 * You should have received a copy of the GNU General Public License
Packit b55c50
 * along with this program; if not, write to the Free Software
Packit b55c50
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit b55c50
 * 02110-1301, USA. 
Packit b55c50
 *
Packit b55c50
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/dirtyLists.h#1 $
Packit b55c50
 */
Packit b55c50
Packit b55c50
#ifndef DIRTY_LISTS_H
Packit b55c50
#define DIRTY_LISTS_H
Packit b55c50
Packit b55c50
#include "ringNode.h"
Packit b55c50
#include "types.h"
Packit b55c50
Packit b55c50
/**
Packit b55c50
 * A collection of lists of dirty elements ordered by age. An element is always
Packit b55c50
 * placed on the oldest list in which it was dirtied (moving between lists or
Packit b55c50
 * removing altogether is cheap). Whenever the current period is advanced, any
Packit b55c50
 * elements older than the maxium age are expired. If an element is to be added
Packit b55c50
 * with a dirty age older than the maximum age, it is expired immediately.
Packit b55c50
 **/
Packit b55c50
typedef struct dirtyLists DirtyLists;
Packit b55c50
Packit b55c50
/**
Packit b55c50
 * A function which will be called with a ring of dirty elements which have
Packit b55c50
 * been expired. All of the expired elements must be removed from the ring
Packit b55c50
 * before this function returns.
Packit b55c50
 *
Packit b55c50
 * @param expired  The list of expired elements
Packit b55c50
 * @param context  The context for the callback
Packit b55c50
 **/
Packit b55c50
typedef void DirtyCallback(RingNode *expired, void *context);
Packit b55c50
Packit b55c50
/**
Packit b55c50
 * Construct a new set of dirty lists.
Packit b55c50
 *
Packit b55c50
 * @param [in]  maximumAge     The age at which an element will be expired
Packit b55c50
 * @param [in]  callback       The function to call when a set of elements have
Packit b55c50
 *                             expired
Packit b55c50
 * @param [in]  context        The context for the callback
Packit b55c50
 * @param [out] dirtyListsPtr  A pointer to hold the new DirtyLists
Packit b55c50
 *
Packit b55c50
 * @return VDO_SUCCESS or an error
Packit b55c50
 **/
Packit b55c50
int makeDirtyLists(BlockCount      maximumAge,
Packit b55c50
                   DirtyCallback  *callback,
Packit b55c50
                   void           *context,
Packit b55c50
                   DirtyLists    **dirtyListsPtr)
Packit b55c50
  __attribute__((warn_unused_result));
Packit b55c50
Packit b55c50
/**
Packit b55c50
 * Free a set of dirty lists and null out the pointer to them.
Packit b55c50
 *
Packit b55c50
 * @param dirtyListsPtr A pointer to the dirty lists to be freed
Packit b55c50
 **/
Packit b55c50
void freeDirtyLists(DirtyLists **dirtyListsPtr);
Packit b55c50
Packit b55c50
/**
Packit b55c50
 * Set the current period. This function should only be called once.
Packit b55c50
 *
Packit b55c50
 * @param dirtyLists  The dirtyLists
Packit b55c50
 * @param period      The current period
Packit b55c50
 **/
Packit b55c50
void setCurrentPeriod(DirtyLists *dirtyLists, SequenceNumber period);
Packit b55c50
Packit b55c50
/**
Packit b55c50
 * Add an element to the dirty lists.
Packit b55c50
 *
Packit b55c50
 * @param dirtyLists  The DirtyLists receiving the element
Packit b55c50
 * @param node        The RingNode of the element to add
Packit b55c50
 * @param oldPeriod   The period in which the element was previous dirtied,
Packit b55c50
 *                    or 0 if it was not dirty
Packit b55c50
 * @param newPeriod   The period in which the element has now been dirtied,
Packit b55c50
 *                    or 0 if it does not hold a lock
Packit b55c50
 **/
Packit b55c50
void addToDirtyLists(DirtyLists     *dirtyLists,
Packit b55c50
                     RingNode       *node,
Packit b55c50
                     SequenceNumber  oldPeriod,
Packit b55c50
                     SequenceNumber  newPeriod);
Packit b55c50
Packit b55c50
/**
Packit b55c50
 * Advance the current period. If the current period is greater than the number
Packit b55c50
 * of lists, expire the oldest lists.
Packit b55c50
 *
Packit b55c50
 * @param dirtyLists  The DirtyLists to advance
Packit b55c50
 * @param period      The new current period
Packit b55c50
 **/
Packit b55c50
void advancePeriod(DirtyLists *dirtyLists, SequenceNumber period);
Packit b55c50
Packit b55c50
/**
Packit b55c50
 * Flush all dirty lists. This will cause the period to be advanced past the
Packit b55c50
 * current period.
Packit b55c50
 *
Packit b55c50
 * @param dirtyLists  The dirtyLists to flush
Packit b55c50
 **/
Packit b55c50
void flushDirtyLists(DirtyLists *dirtyLists);
Packit b55c50
Packit b55c50
#endif // DIRTY_LISTS_H