|
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/journalPoint.h#2 $
|
|
Packit Service |
d40955 |
*/
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
#ifndef JOURNAL_POINT_H
|
|
Packit Service |
d40955 |
#define JOURNAL_POINT_H
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
#include "numeric.h"
|
|
Packit Service |
d40955 |
#include "types.h"
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
typedef uint16_t JournalEntryCount;
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
/**
|
|
Packit Service |
d40955 |
* The absolute position of an entry in a recovery journal or slab journal.
|
|
Packit Service |
d40955 |
**/
|
|
Packit Service |
d40955 |
typedef struct {
|
|
Packit Service |
d40955 |
SequenceNumber sequenceNumber;
|
|
Packit Service |
d40955 |
JournalEntryCount entryCount;
|
|
Packit Service |
d40955 |
} JournalPoint;
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
/**
|
|
Packit Service |
d40955 |
* A packed, platform-independent encoding of a JournalPoint.
|
|
Packit Service |
d40955 |
**/
|
|
Packit Service |
d40955 |
typedef struct {
|
|
Packit Service |
d40955 |
/**
|
|
Packit Service |
d40955 |
* The packed representation is the little-endian 64-bit representation of
|
|
Packit Service |
d40955 |
* the low-order 48 bits of the sequence number, shifted up 16 bits, or'ed
|
|
Packit Service |
d40955 |
* with the 16-bit entry count.
|
|
Packit Service |
d40955 |
*
|
|
Packit Service |
d40955 |
* Very long-term, the top 16 bits of the sequence number may not always be
|
|
Packit Service |
d40955 |
* zero, as this encoding assumes--see BZ 1523240.
|
|
Packit Service |
d40955 |
**/
|
|
Packit Service |
d40955 |
byte encodedPoint[8];
|
|
Packit Service |
d40955 |
} __attribute__((packed)) PackedJournalPoint;
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
/**
|
|
Packit Service |
d40955 |
* Move the given journal point forward by one entry.
|
|
Packit Service |
d40955 |
*
|
|
Packit Service |
d40955 |
* @param point the journal point to adjust
|
|
Packit Service |
d40955 |
* @param entriesPerBlock the number of entries in one full block
|
|
Packit Service |
d40955 |
**/
|
|
Packit Service |
d40955 |
static inline void advanceJournalPoint(JournalPoint *point,
|
|
Packit Service |
d40955 |
JournalEntryCount entriesPerBlock)
|
|
Packit Service |
d40955 |
{
|
|
Packit Service |
d40955 |
point->entryCount++;
|
|
Packit Service |
d40955 |
if (point->entryCount == entriesPerBlock) {
|
|
Packit Service |
d40955 |
point->sequenceNumber++;
|
|
Packit Service |
d40955 |
point->entryCount = 0;
|
|
Packit Service |
d40955 |
}
|
|
Packit Service |
d40955 |
}
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
/**
|
|
Packit Service |
d40955 |
* Check whether a journal point is valid.
|
|
Packit Service |
d40955 |
*
|
|
Packit Service |
d40955 |
* @param point the journal point
|
|
Packit Service |
d40955 |
*
|
|
Packit Service |
d40955 |
* @return true if the journal point is valid
|
|
Packit Service |
d40955 |
**/
|
|
Packit Service |
d40955 |
static inline bool isValidJournalPoint(const JournalPoint *point)
|
|
Packit Service |
d40955 |
{
|
|
Packit Service |
d40955 |
return ((point != NULL) && (point->sequenceNumber > 0));
|
|
Packit Service |
d40955 |
}
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
/**
|
|
Packit Service |
d40955 |
* Check whether the first point precedes the second point.
|
|
Packit Service |
d40955 |
*
|
|
Packit Service |
d40955 |
* @param first the first journal point
|
|
Packit Service |
d40955 |
* @param second the second journal point
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
*
|
|
Packit Service |
d40955 |
* @return true if the first point precedes the second point.
|
|
Packit Service |
d40955 |
**/
|
|
Packit Service |
d40955 |
static inline bool beforeJournalPoint(const JournalPoint *first,
|
|
Packit Service |
d40955 |
const JournalPoint *second)
|
|
Packit Service |
d40955 |
{
|
|
Packit Service |
d40955 |
return ((first->sequenceNumber < second->sequenceNumber)
|
|
Packit Service |
d40955 |
|| ((first->sequenceNumber == second->sequenceNumber)
|
|
Packit Service |
d40955 |
&& (first->entryCount < second->entryCount)));
|
|
Packit Service |
d40955 |
}
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
/**
|
|
Packit Service |
d40955 |
* Check whether the first point is the same as the second point.
|
|
Packit Service |
d40955 |
*
|
|
Packit Service |
d40955 |
* @param first the first journal point
|
|
Packit Service |
d40955 |
* @param second the second journal point
|
|
Packit Service |
d40955 |
*
|
|
Packit Service |
d40955 |
* @return true if both points reference the same logical
|
|
Packit Service |
d40955 |
* position of an entry the journal
|
|
Packit Service |
d40955 |
**/
|
|
Packit Service |
d40955 |
static inline bool areEquivalentJournalPoints(const JournalPoint *first,
|
|
Packit Service |
d40955 |
const JournalPoint *second)
|
|
Packit Service |
d40955 |
{
|
|
Packit Service |
d40955 |
return ((first->sequenceNumber == second->sequenceNumber)
|
|
Packit Service |
d40955 |
&& (first->entryCount == second->entryCount));
|
|
Packit Service |
d40955 |
}
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
/**
|
|
Packit Service |
d40955 |
* Encode the journal location represented by a JournalPoint into a
|
|
Packit Service |
d40955 |
* PackedJournalPoint.
|
|
Packit Service |
d40955 |
*
|
|
Packit Service |
d40955 |
* @param unpacked The unpacked input point
|
|
Packit Service |
d40955 |
* @param packed The packed output point
|
|
Packit Service |
d40955 |
**/
|
|
Packit Service |
d40955 |
static inline void packJournalPoint(const JournalPoint *unpacked,
|
|
Packit Service |
d40955 |
PackedJournalPoint *packed)
|
|
Packit Service |
d40955 |
{
|
|
Packit Service |
d40955 |
uint64_t native = ((unpacked->sequenceNumber << 16) | unpacked->entryCount);
|
|
Packit Service |
d40955 |
storeUInt64LE(packed->encodedPoint, native);
|
|
Packit Service |
d40955 |
}
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
/**
|
|
Packit Service |
d40955 |
* Decode the journal location represented by a PackedJournalPoint into a
|
|
Packit Service |
d40955 |
* JournalPoint.
|
|
Packit Service |
d40955 |
*
|
|
Packit Service |
d40955 |
* @param packed The packed input point
|
|
Packit Service |
d40955 |
* @param unpacked The unpacked output point
|
|
Packit Service |
d40955 |
**/
|
|
Packit Service |
d40955 |
static inline void unpackJournalPoint(const PackedJournalPoint *packed,
|
|
Packit Service |
d40955 |
JournalPoint *unpacked)
|
|
Packit Service |
d40955 |
{
|
|
Packit Service |
d40955 |
uint64_t native = getUInt64LE(packed->encodedPoint);
|
|
Packit Service |
d40955 |
unpacked->sequenceNumber = (native >> 16);
|
|
Packit Service |
d40955 |
unpacked->entryCount = (native & 0xffff);
|
|
Packit Service |
d40955 |
}
|
|
Packit Service |
d40955 |
|
|
Packit Service |
d40955 |
#endif // JOURNAL_POINT_H
|