|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/recoveryJournalInternals.h#10 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef RECOVERY_JOURNAL_INTERNALS_H
|
|
Packit Service |
310c69 |
#define RECOVERY_JOURNAL_INTERNALS_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "numeric.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "adminState.h"
|
|
Packit Service |
310c69 |
#include "fixedLayout.h"
|
|
Packit Service |
310c69 |
#include "journalPoint.h"
|
|
Packit Service |
310c69 |
#include "lockCounter.h"
|
|
Packit Service |
310c69 |
#include "recoveryJournal.h"
|
|
Packit Service |
310c69 |
#include "ringNode.h"
|
|
Packit Service |
310c69 |
#include "statistics.h"
|
|
Packit Service |
310c69 |
#include "types.h"
|
|
Packit Service |
310c69 |
#include "waitQueue.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct recoveryJournalBlock RecoveryJournalBlock;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
struct recoveryJournal {
|
|
Packit Service |
310c69 |
/** The thread ID of the journal zone */
|
|
Packit Service |
310c69 |
ThreadID threadID;
|
|
Packit Service |
310c69 |
/** The slab depot which can hold locks on this journal */
|
|
Packit Service |
310c69 |
SlabDepot *depot;
|
|
Packit Service |
310c69 |
/** The block map which can hold locks on this journal */
|
|
Packit Service |
310c69 |
BlockMap *blockMap;
|
|
Packit Service |
310c69 |
/** The queue of VIOs waiting to make increment entries */
|
|
Packit Service |
310c69 |
WaitQueue incrementWaiters;
|
|
Packit Service |
310c69 |
/** The queue of VIOs waiting to make decrement entries */
|
|
Packit Service |
310c69 |
WaitQueue decrementWaiters;
|
|
Packit Service |
310c69 |
/** The number of free entries in the journal */
|
|
Packit Service |
310c69 |
uint64_t availableSpace;
|
|
Packit Service |
310c69 |
/** The number of decrement entries which need to be made */
|
|
Packit Service |
310c69 |
VIOCount pendingDecrementCount;
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Whether the journal is adding entries from the increment or
|
|
Packit Service |
310c69 |
* decrement waiters queues
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
bool addingEntries;
|
|
Packit Service |
310c69 |
/** The notifier for read-only mode */
|
|
Packit Service |
310c69 |
ReadOnlyNotifier *readOnlyNotifier;
|
|
Packit Service |
310c69 |
/** The administrative state of the journal */
|
|
Packit Service |
310c69 |
AdminState state;
|
|
Packit Service |
310c69 |
/** Whether a reap is in progress */
|
|
Packit Service |
310c69 |
bool reaping;
|
|
Packit Service |
310c69 |
/** The partition which holds the journal on disk */
|
|
Packit Service |
310c69 |
Partition *partition;
|
|
Packit Service |
310c69 |
/** The oldest active block in the journal on disk for block map rebuild */
|
|
Packit Service |
310c69 |
SequenceNumber blockMapHead;
|
|
Packit Service |
310c69 |
/** The oldest active block in the journal on disk for slab journal replay */
|
|
Packit Service |
310c69 |
SequenceNumber slabJournalHead;
|
|
Packit Service |
310c69 |
/** The newest block in the journal on disk to which a write has finished */
|
|
Packit Service |
310c69 |
SequenceNumber lastWriteAcknowledged;
|
|
Packit Service |
310c69 |
/** The end of the half-open interval of the active journal */
|
|
Packit Service |
310c69 |
SequenceNumber tail;
|
|
Packit Service |
310c69 |
/** The point at which the last entry will have been added */
|
|
Packit Service |
310c69 |
JournalPoint appendPoint;
|
|
Packit Service |
310c69 |
/** The journal point of the VIO most recently released from the journal */
|
|
Packit Service |
310c69 |
JournalPoint commitPoint;
|
|
Packit Service |
310c69 |
/** The nonce of the VDO */
|
|
Packit Service |
310c69 |
Nonce nonce;
|
|
Packit Service |
310c69 |
/** The number of recoveries completed by the VDO */
|
|
Packit Service |
310c69 |
uint8_t recoveryCount;
|
|
Packit Service |
310c69 |
/** The number of entries which fit in a single block */
|
|
Packit Service |
310c69 |
JournalEntryCount entriesPerBlock;
|
|
Packit Service |
310c69 |
/** Unused in-memory journal blocks */
|
|
Packit Service |
310c69 |
RingNode freeTailBlocks;
|
|
Packit Service |
310c69 |
/** In-memory journal blocks with records */
|
|
Packit Service |
310c69 |
RingNode activeTailBlocks;
|
|
Packit Service |
310c69 |
/** A pointer to the active block (the one we are adding entries to now) */
|
|
Packit Service |
310c69 |
RecoveryJournalBlock *activeBlock;
|
|
Packit Service |
310c69 |
/** Journal blocks that need writing */
|
|
Packit Service |
310c69 |
WaitQueue pendingWrites;
|
|
Packit Service |
310c69 |
/** The new block map reap head after reaping */
|
|
Packit Service |
310c69 |
SequenceNumber blockMapReapHead;
|
|
Packit Service |
310c69 |
/** The head block number for the block map rebuild range */
|
|
Packit Service |
310c69 |
BlockCount blockMapHeadBlockNumber;
|
|
Packit Service |
310c69 |
/** The new slab journal reap head after reaping */
|
|
Packit Service |
310c69 |
SequenceNumber slabJournalReapHead;
|
|
Packit Service |
310c69 |
/** The head block number for the slab journal replay range */
|
|
Packit Service |
310c69 |
BlockCount slabJournalHeadBlockNumber;
|
|
Packit Service |
310c69 |
/** The VIO on which we can call flush (less ick, but still ick) */
|
|
Packit Service |
310c69 |
VIO *flushVIO;
|
|
Packit Service |
310c69 |
/** The data block which must live in the VIO in the flush extent */
|
|
Packit Service |
310c69 |
char *unusedFlushVIOData;
|
|
Packit Service |
310c69 |
/** The number of blocks in the on-disk journal */
|
|
Packit Service |
310c69 |
BlockCount size;
|
|
Packit Service |
310c69 |
/** The number of logical blocks that are in-use */
|
|
Packit Service |
310c69 |
BlockCount logicalBlocksUsed;
|
|
Packit Service |
310c69 |
/** The number of block map pages that are allocated */
|
|
Packit Service |
310c69 |
BlockCount blockMapDataBlocks;
|
|
Packit Service |
310c69 |
/** The number of journal blocks written but not yet acknowledged */
|
|
Packit Service |
310c69 |
BlockCount pendingWriteCount;
|
|
Packit Service |
310c69 |
/** The threshold at which slab journal tail blocks will be written out */
|
|
Packit Service |
310c69 |
BlockCount slabJournalCommitThreshold;
|
|
Packit Service |
310c69 |
/** Counters for events in the journal that are reported as statistics */
|
|
Packit Service |
310c69 |
RecoveryJournalStatistics events;
|
|
Packit Service |
310c69 |
/** The locks for each on-disk block */
|
|
Packit Service |
310c69 |
LockCounter *lockCounter;
|
|
Packit Service |
310c69 |
};
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Get the physical block number for a given sequence number.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param journal The journal
|
|
Packit Service |
310c69 |
* @param sequence The sequence number of the desired block
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The block number corresponding to the sequence number
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result))
|
|
Packit Service |
310c69 |
static inline PhysicalBlockNumber
|
|
Packit Service |
310c69 |
getRecoveryJournalBlockNumber(const RecoveryJournal *journal,
|
|
Packit Service |
310c69 |
SequenceNumber sequence)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
// Since journal size is a power of two, the block number modulus can just
|
|
Packit Service |
310c69 |
// be extracted from the low-order bits of the sequence.
|
|
Packit Service |
310c69 |
return (sequence & (journal->size - 1));
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Compute the checkByte for a given sequence number.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param journal The journal
|
|
Packit Service |
310c69 |
* @param sequence The sequence number
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return The check byte corresponding to the sequence number
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
__attribute__((warn_unused_result))
|
|
Packit Service |
310c69 |
static inline uint8_t computeRecoveryCheckByte(const RecoveryJournal *journal,
|
|
Packit Service |
310c69 |
SequenceNumber sequence)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
// The check byte must change with each trip around the journal.
|
|
Packit Service |
310c69 |
return (((sequence / journal->size) & 0x7F) | 0x80);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif // RECOVERY_JOURNAL_INTERNALS_H
|