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