|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
b3514a |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
b3514a |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
b3514a |
* of the License, or (at your option) any later version.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
b3514a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b3514a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
b3514a |
* GNU General Public License for more details.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
b3514a |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
b3514a |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
b3514a |
* 02110-1301, USA.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/recoveryJournalBlock.h#8 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#ifndef RECOVERY_JOURNAL_BLOCK_H
|
|
Packit Service |
b3514a |
#define RECOVERY_JOURNAL_BLOCK_H
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "permassert.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "packedRecoveryJournalBlock.h"
|
|
Packit Service |
b3514a |
#include "recoveryJournalInternals.h"
|
|
Packit Service |
b3514a |
#include "ringNode.h"
|
|
Packit Service |
b3514a |
#include "types.h"
|
|
Packit Service |
b3514a |
#include "waitQueue.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
struct recoveryJournalBlock {
|
|
Packit Service |
b3514a |
/** The doubly linked pointers for the free or active lists */
|
|
Packit Service |
b3514a |
RingNode ringNode;
|
|
Packit Service |
b3514a |
/** The waiter for the pending full block list */
|
|
Packit Service |
b3514a |
Waiter writeWaiter;
|
|
Packit Service |
b3514a |
/** The journal to which this block belongs */
|
|
Packit Service |
b3514a |
RecoveryJournal *journal;
|
|
Packit Service |
b3514a |
/** A pointer to a block-sized buffer holding the packed block data */
|
|
Packit Service |
b3514a |
char *block;
|
|
Packit Service |
b3514a |
/** A pointer to the current sector in the packed block buffer */
|
|
Packit Service |
b3514a |
PackedJournalSector *sector;
|
|
Packit Service |
b3514a |
/** The VIO for writing this block */
|
|
Packit Service |
b3514a |
VIO *vio;
|
|
Packit Service |
b3514a |
/** The sequence number for this block */
|
|
Packit Service |
b3514a |
SequenceNumber sequenceNumber;
|
|
Packit Service |
b3514a |
/** The location of this block in the on-disk journal */
|
|
Packit Service |
b3514a |
PhysicalBlockNumber blockNumber;
|
|
Packit Service |
b3514a |
/** Whether this block is being committed */
|
|
Packit Service |
b3514a |
bool committing;
|
|
Packit Service |
b3514a |
/** Whether this block has an uncommitted increment for a partial write */
|
|
Packit Service |
b3514a |
bool hasPartialWriteEntry;
|
|
Packit Service |
b3514a |
/** Whether this block has an uncommitted increment for a write with FUA */
|
|
Packit Service |
b3514a |
bool hasFUAEntry;
|
|
Packit Service |
b3514a |
/** The total number of entries in this block */
|
|
Packit Service |
b3514a |
JournalEntryCount entryCount;
|
|
Packit Service |
b3514a |
/** The total number of uncommitted entries (queued or committing) */
|
|
Packit Service |
b3514a |
JournalEntryCount uncommittedEntryCount;
|
|
Packit Service |
b3514a |
/** The number of new entries in the current commit */
|
|
Packit Service |
b3514a |
JournalEntryCount entriesInCommit;
|
|
Packit Service |
b3514a |
/** The queue of VIOs which will make entries for the next commit */
|
|
Packit Service |
b3514a |
WaitQueue entryWaiters;
|
|
Packit Service |
b3514a |
/** The queue of VIOs waiting for the current commit */
|
|
Packit Service |
b3514a |
WaitQueue commitWaiters;
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Return the block associated with a ring node.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param node The ring node to recast as a block
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The block
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline RecoveryJournalBlock *blockFromRingNode(RingNode *node)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
STATIC_ASSERT(offsetof(RecoveryJournalBlock, ringNode) == 0);
|
|
Packit Service |
b3514a |
return (RecoveryJournalBlock *) node;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Return the block associated with a waiter
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param waiter The waiter to recast as a block
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The block
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
static inline RecoveryJournalBlock *blockFromWaiter(Waiter *waiter)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return (RecoveryJournalBlock *)
|
|
Packit Service |
b3514a |
((uintptr_t) waiter - offsetof(RecoveryJournalBlock, writeWaiter));
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Check whether a recovery block is dirty, indicating it has any uncommitted
|
|
Packit Service |
b3514a |
* entries, which includes both entries not written and entries written but
|
|
Packit Service |
b3514a |
* not yet acknowledged.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The block to check
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return true if the block has any uncommitted entries
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result))
|
|
Packit Service |
b3514a |
static inline bool isRecoveryBlockDirty(const RecoveryJournalBlock *block)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return (block->uncommittedEntryCount > 0);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Check whether a journal block is empty.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The block to check
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return true if the block has no entries
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result))
|
|
Packit Service |
b3514a |
static inline bool isRecoveryBlockEmpty(const RecoveryJournalBlock *block)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return (block->entryCount == 0);
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Check whether a journal block is full.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The block to check
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return true if the the block is full
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result))
|
|
Packit Service |
b3514a |
static inline bool isRecoveryBlockFull(const RecoveryJournalBlock *block)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return ((block == NULL)
|
|
Packit Service |
b3514a |
|| (block->journal->entriesPerBlock == block->entryCount));
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Construct a journal block.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] layer The layer from which to construct VIOs
|
|
Packit Service |
b3514a |
* @param [in] journal The journal to which the block will belong
|
|
Packit Service |
b3514a |
* @param [out] blockPtr A pointer to receive the new block
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int makeRecoveryBlock(PhysicalLayer *layer,
|
|
Packit Service |
b3514a |
RecoveryJournal *journal,
|
|
Packit Service |
b3514a |
RecoveryJournalBlock **blockPtr)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Free a tail block and null out the reference to it.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param blockPtr The reference to the tail block to free
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void freeRecoveryBlock(RecoveryJournalBlock **blockPtr);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Initialize the next active recovery journal block.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The journal block to initialize
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void initializeRecoveryBlock(RecoveryJournalBlock *block);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Enqueue a DataVIO to asynchronously encode and commit its next recovery
|
|
Packit Service |
b3514a |
* journal entry in this block. The DataVIO will not be continued until the
|
|
Packit Service |
b3514a |
* entry is committed to the on-disk journal. The caller is responsible for
|
|
Packit Service |
b3514a |
* ensuring the block is not already full.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The journal block in which to make an entry
|
|
Packit Service |
b3514a |
* @param dataVIO The DataVIO to enqueue
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error code if the DataVIO could not be enqueued
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int enqueueRecoveryBlockEntry(RecoveryJournalBlock *block, DataVIO *dataVIO)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Attempt to commit a block. If the block is not the oldest block with
|
|
Packit Service |
b3514a |
* uncommitted entries or if it is already being committed, nothing will be
|
|
Packit Service |
b3514a |
* done.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The block to write
|
|
Packit Service |
b3514a |
* @param callback The function to call when the write completes
|
|
Packit Service |
b3514a |
* @param errorHandler The handler for flush or write errors
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS, or an error if the write could not be launched
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int commitRecoveryBlock(RecoveryJournalBlock *block,
|
|
Packit Service |
b3514a |
VDOAction *callback,
|
|
Packit Service |
b3514a |
VDOAction *errorHandler)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Dump the contents of the recovery block to the log.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The block to dump
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void dumpRecoveryBlock(const RecoveryJournalBlock *block);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Check whether a journal block can be committed.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param block The journal block in question
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return true if the block can be committed now
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
bool canCommitRecoveryBlock(RecoveryJournalBlock *block)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#endif // RECOVERY_JOURNAL_BLOCK_H
|