Blame source/vdo/base/slabJournal.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/slabJournal.h#8 $
Packit Service d40955
 */
Packit Service d40955
Packit Service d40955
#ifndef SLAB_JOURNAL_H
Packit Service d40955
#define SLAB_JOURNAL_H
Packit Service d40955
Packit Service d40955
#include "completion.h"
Packit Service d40955
#include "journalPoint.h"
Packit Service d40955
#include "ringNode.h"
Packit Service d40955
#include "types.h"
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Convert a completion to a SlabJournal.
Packit Service d40955
 *
Packit Service d40955
 * @param completion  The completion to convert
Packit Service d40955
 *
Packit Service d40955
 * @return The completion as a SlabJournal
Packit Service d40955
 **/
Packit Service d40955
SlabJournal *asSlabJournal(VDOCompletion *completion)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Calculate the number of slab journal entries per block.
Packit Service d40955
 *
Packit Service d40955
 * @return The number of slab journal entries per block
Packit Service d40955
 **/
Packit Service d40955
size_t getSlabJournalEntriesPerBlock(void)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Obtain a pointer to a SlabJournal structure from a pointer to the
Packit Service d40955
 * dirtyRingNode field within it.
Packit Service d40955
 *
Packit Service d40955
 * @param node  The RingNode to convert
Packit Service d40955
 *
Packit Service d40955
 * @return The RingNode as a SlabJournal
Packit Service d40955
 **/
Packit Service d40955
SlabJournal *slabJournalFromDirtyNode(RingNode *node)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Create a slab journal.
Packit Service d40955
 *
Packit Service d40955
 * @param [in]  allocator        The block allocator which owns this journal
Packit Service d40955
 * @param [in]  slab             The parent slab of the journal
Packit Service d40955
 * @param [in]  recoveryJournal  The recovery journal of the VDO
Packit Service d40955
 * @param [out] journalPtr       The pointer to hold the new slab journal
Packit Service d40955
 *
Packit Service d40955
 * @return VDO_SUCCESS or error code
Packit Service d40955
 **/
Packit Service d40955
int makeSlabJournal(BlockAllocator   *allocator,
Packit Service d40955
                    Slab             *slab,
Packit Service d40955
                    RecoveryJournal  *recoveryJournal,
Packit Service d40955
                    SlabJournal     **journalPtr)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Free a slab journal and null out the reference to it.
Packit Service d40955
 *
Packit Service d40955
 * @param journalPtr  The reference to the slab journal to free
Packit Service d40955
 **/
Packit Service d40955
void freeSlabJournal(SlabJournal **journalPtr);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Check whether a slab journal is blank, meaning it has never had any entries
Packit Service d40955
 * recorded in it.
Packit Service d40955
 *
Packit Service d40955
 * @param journal  The journal to query
Packit Service d40955
 *
Packit Service d40955
 * @return true if the slab journal has never been modified
Packit Service d40955
 **/
Packit Service d40955
bool isSlabJournalBlank(const SlabJournal *journal)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Check whether the slab journal is on the block allocator's ring of dirty
Packit Service d40955
 * journals.
Packit Service d40955
 *
Packit Service d40955
 * @param journal  The journal to query
Packit Service d40955
 *
Packit Service d40955
 * @return true if the journal has been added to the dirty ring
Packit Service d40955
 **/
Packit Service d40955
bool isSlabJournalDirty(const SlabJournal *journal)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Check whether a slab journal is active.
Packit Service d40955
 *
Packit Service d40955
 * @param journal  The slab journal to check
Packit Service d40955
 *
Packit Service d40955
 * @return true if the journal is active
Packit Service d40955
 **/
Packit Service d40955
bool isSlabJournalActive(SlabJournal *journal)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Abort any VIOs waiting to make slab journal entries.
Packit Service d40955
 *
Packit Service d40955
 * @param journal  The journal to abort
Packit Service d40955
 **/
Packit Service d40955
void abortSlabJournalWaiters(SlabJournal *journal);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Reopen a slab journal by emptying it and then adding any pending entries.
Packit Service d40955
 *
Packit Service d40955
 * @param journal  The journal to reopen
Packit Service d40955
 **/
Packit Service d40955
void reopenSlabJournal(SlabJournal *journal);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Attempt to replay a recovery journal entry into a slab journal.
Packit Service d40955
 *
Packit Service d40955
 * @param journal        The slab journal to use
Packit Service d40955
 * @param pbn            The PBN for the entry
Packit Service d40955
 * @param operation      The type of entry to add
Packit Service d40955
 * @param recoveryPoint  The recovery journal point corresponding to this entry
Packit Service d40955
 * @param parent         The completion to notify when there is space to add
Packit Service d40955
 *                       the entry if the entry could not be added immediately
Packit Service d40955
 *
Packit Service d40955
 * @return true if the entry was added immediately
Packit Service d40955
 **/
Packit Service d40955
bool attemptReplayIntoSlabJournal(SlabJournal         *journal,
Packit Service d40955
                                  PhysicalBlockNumber  pbn,
Packit Service d40955
                                  JournalOperation     operation,
Packit Service d40955
                                  JournalPoint        *recoveryPoint,
Packit Service d40955
                                  VDOCompletion       *parent)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Add an entry to a slab journal.
Packit Service d40955
 *
Packit Service d40955
 * @param journal  The slab journal to use
Packit Service d40955
 * @param dataVIO  The DataVIO for which to add the entry
Packit Service d40955
 **/
Packit Service d40955
void addSlabJournalEntry(SlabJournal *journal, DataVIO *dataVIO);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Adjust the reference count for a slab journal block. Note that when the
Packit Service d40955
 * adjustment is negative, the slab journal will be reaped.
Packit Service d40955
 *
Packit Service d40955
 * @param journal         The slab journal
Packit Service d40955
 * @param sequenceNumber  The journal sequence number of the referenced block
Packit Service d40955
 * @param adjustment      Amount to adjust the reference counter
Packit Service d40955
 **/
Packit Service d40955
void adjustSlabJournalBlockReference(SlabJournal    *journal,
Packit Service d40955
                                     SequenceNumber  sequenceNumber,
Packit Service d40955
                                     int             adjustment);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Request the slab journal to release the recovery journal lock it may hold on
Packit Service d40955
 * a specified recovery journal block.
Packit Service d40955
 *
Packit Service d40955
 * @param journal       The slab journal
Packit Service d40955
 * @param recoveryLock  The sequence number of the recovery journal block
Packit Service d40955
 *                      whose locks should be released
Packit Service d40955
 *
Packit Service d40955
 * @return true if the journal does hold a lock on the specified
Packit Service d40955
 *         block (which it will release)
Packit Service d40955
 **/
Packit Service d40955
bool releaseRecoveryJournalLock(SlabJournal    *journal,
Packit Service d40955
                                SequenceNumber  recoveryLock)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Commit the tail block of a slab journal.
Packit Service d40955
 *
Packit Service d40955
 * @param journal  The journal whose tail block should be committed
Packit Service d40955
 **/
Packit Service d40955
void commitSlabJournalTail(SlabJournal *journal);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Drain slab journal I/O. Depending upon the type of drain (as recorded in
Packit Service d40955
 * the journal's slab), any dirty journal blocks may be written out.
Packit Service d40955
 *
Packit Service d40955
 * @param journal  The journal to drain
Packit Service d40955
 **/
Packit Service d40955
void drainSlabJournal(SlabJournal *journal);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Decode the slab journal by reading its tail.
Packit Service d40955
 *
Packit Service d40955
 * @param journal  The journal to decode
Packit Service d40955
 **/
Packit Service d40955
void decodeSlabJournal(SlabJournal *journal);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Check to see if the journal should be scrubbed.
Packit Service d40955
 *
Packit Service d40955
 * @param journal  The slab journal
Packit Service d40955
 *
Packit Service d40955
 * @return true if the journal requires scrubbing
Packit Service d40955
 **/
Packit Service d40955
bool requiresScrubbing(const SlabJournal *journal)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Dump the slab journal.
Packit Service d40955
 *
Packit Service d40955
 * @param journal       The slab journal to dump
Packit Service d40955
 **/
Packit Service d40955
void dumpSlabJournal(const SlabJournal *journal);
Packit Service d40955
Packit Service d40955
#endif // SLAB_JOURNAL_H