Merge "Revert "Shove type into source_info"" into main
This commit is contained in:
commit
d6fe3032a9
14 changed files with 99 additions and 135 deletions
|
@ -161,6 +161,9 @@ struct CowOperationV2 {
|
|||
|
||||
// The on disk format of cow (currently == CowOperation)
|
||||
struct CowOperationV3 {
|
||||
// The operation code (see the constants and structures below).
|
||||
uint8_t type;
|
||||
|
||||
// If this operation reads from the data section of the COW, this contains
|
||||
// the length.
|
||||
uint16_t data_length;
|
||||
|
@ -168,10 +171,6 @@ struct CowOperationV3 {
|
|||
// The block of data in the new image that this operation modifies.
|
||||
uint32_t new_block;
|
||||
|
||||
// source_info with have the following layout
|
||||
// |---4 bits ---| ---12 bits---| --- 48 bits ---|
|
||||
// |--- type --- | -- unused -- | --- source --- |
|
||||
//
|
||||
// The value of |source| depends on the operation code.
|
||||
//
|
||||
// CopyOp: a 32-bit block location in the source image.
|
||||
|
@ -180,6 +179,8 @@ struct CowOperationV3 {
|
|||
// ZeroOp: unused
|
||||
// LabelOp: a 64-bit opaque identifier.
|
||||
//
|
||||
// For ops other than Label:
|
||||
// Bits 47-62 are reserved and must be zero.
|
||||
// A block is compressed if it’s data is < block_sz
|
||||
uint64_t source_info;
|
||||
} __attribute__((packed));
|
||||
|
@ -211,21 +212,9 @@ static constexpr uint8_t kCowReadAheadNotStarted = 0;
|
|||
static constexpr uint8_t kCowReadAheadInProgress = 1;
|
||||
static constexpr uint8_t kCowReadAheadDone = 2;
|
||||
|
||||
// this is a mask to grab the last 48 bits of a 64 bit integer
|
||||
static constexpr uint64_t kCowOpSourceInfoDataMask = (0x1ULL << 48) - 1;
|
||||
// this is a mask to grab the first 4 bits of a 64 bit integer
|
||||
static constexpr uint64_t kCowOpSourceInfoTypeBit = 60;
|
||||
static constexpr uint64_t kCowOpSourceInfoTypeNumBits = 4;
|
||||
static constexpr uint64_t kCowOpSourceInfoTypeMask = (1 << kCowOpSourceInfoTypeNumBits) - 1;
|
||||
static constexpr uint64_t kCowOpSourceInfoDataMask = (1ULL << 48) - 1;
|
||||
|
||||
static constexpr void SetCowOpSourceInfoType(CowOperation* op, const uint8_t type) {
|
||||
op->source_info |= uint64_t(type) << kCowOpSourceInfoTypeBit;
|
||||
}
|
||||
static constexpr uint64_t GetCowOpSourceInfoType(const CowOperation& op) {
|
||||
return (op.source_info >> kCowOpSourceInfoTypeBit) & kCowOpSourceInfoTypeMask;
|
||||
}
|
||||
|
||||
static constexpr uint64_t GetCowOpSourceInfoData(const CowOperation& op) {
|
||||
static inline uint64_t GetCowOpSourceInfoData(const CowOperation& op) {
|
||||
return op.source_info & kCowOpSourceInfoDataMask;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,19 +81,16 @@ std::ostream& operator<<(std::ostream& os, CowOperationV2 const& op) {
|
|||
|
||||
std::ostream& operator<<(std::ostream& os, CowOperation const& op) {
|
||||
os << "CowOperation(";
|
||||
EmitCowTypeString(os, GetCowOpSourceInfoType(op));
|
||||
if (GetCowOpSourceInfoType(op) == kCowReplaceOp || GetCowOpSourceInfoType(op) == kCowXorOp ||
|
||||
GetCowOpSourceInfoType(op) == kCowSequenceOp) {
|
||||
EmitCowTypeString(os, op.type);
|
||||
if (op.type == kCowReplaceOp || op.type == kCowXorOp || op.type == kCowSequenceOp) {
|
||||
os << ", data_length:" << op.data_length;
|
||||
}
|
||||
if (GetCowOpSourceInfoType(op) != kCowClusterOp &&
|
||||
GetCowOpSourceInfoType(op) != kCowSequenceOp && GetCowOpSourceInfoType(op) != kCowLabelOp) {
|
||||
if (op.type != kCowClusterOp && op.type != kCowSequenceOp && op.type != kCowLabelOp) {
|
||||
os << ", new_block:" << op.new_block;
|
||||
}
|
||||
if (GetCowOpSourceInfoType(op) == kCowXorOp || GetCowOpSourceInfoType(op) == kCowReplaceOp ||
|
||||
GetCowOpSourceInfoType(op) == kCowCopyOp) {
|
||||
if (op.type == kCowXorOp || op.type == kCowReplaceOp || op.type == kCowCopyOp) {
|
||||
os << ", source:" << (op.source_info & kCowOpSourceInfoDataMask);
|
||||
} else if (GetCowOpSourceInfoType(op) == kCowClusterOp) {
|
||||
} else if (op.type == kCowClusterOp) {
|
||||
os << ", cluster_data:" << (op.source_info & kCowOpSourceInfoDataMask);
|
||||
} else {
|
||||
os << ", label:0x" << android::base::StringPrintf("%" PRIx64, op.source_info);
|
||||
|
@ -123,7 +120,7 @@ int64_t GetNextDataOffset(const CowOperationV2& op, uint32_t cluster_ops) {
|
|||
}
|
||||
|
||||
bool IsMetadataOp(const CowOperation& op) {
|
||||
switch (GetCowOpSourceInfoType(op)) {
|
||||
switch (op.type) {
|
||||
case kCowLabelOp:
|
||||
case kCowClusterOp:
|
||||
case kCowFooterOp:
|
||||
|
@ -135,7 +132,7 @@ bool IsMetadataOp(const CowOperation& op) {
|
|||
}
|
||||
|
||||
bool IsOrderedOp(const CowOperation& op) {
|
||||
switch (GetCowOpSourceInfoType(op)) {
|
||||
switch (op.type) {
|
||||
case kCowCopyOp:
|
||||
case kCowXorOp:
|
||||
return true;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <libsnapshot/cow_format.h>
|
||||
#include <libsnapshot/cow_reader.h>
|
||||
#include <zlib.h>
|
||||
|
||||
|
@ -140,7 +139,7 @@ bool CowReader::Parse(android::base::borrowed_fd fd, std::optional<uint64_t> lab
|
|||
const auto& v2_op = parser.ops()->at(i);
|
||||
|
||||
auto& new_op = ops_->at(i);
|
||||
SetCowOpSourceInfoType(&new_op, v2_op.type);
|
||||
new_op.type = v2_op.type;
|
||||
new_op.data_length = v2_op.data_length;
|
||||
|
||||
if (v2_op.new_block > std::numeric_limits<uint32_t>::max()) {
|
||||
|
@ -150,7 +149,7 @@ bool CowReader::Parse(android::base::borrowed_fd fd, std::optional<uint64_t> lab
|
|||
new_op.new_block = v2_op.new_block;
|
||||
|
||||
uint64_t source_info = v2_op.source;
|
||||
if (GetCowOpSourceInfoType(new_op) != kCowLabelOp) {
|
||||
if (new_op.type != kCowLabelOp) {
|
||||
source_info &= kCowOpSourceInfoDataMask;
|
||||
if (source_info != v2_op.source) {
|
||||
LOG(ERROR) << "Out-of-range source value in COW op: " << v2_op;
|
||||
|
@ -167,7 +166,7 @@ bool CowReader::Parse(android::base::borrowed_fd fd, std::optional<uint64_t> lab
|
|||
return false;
|
||||
}
|
||||
}
|
||||
new_op.source_info |= source_info;
|
||||
new_op.source_info = source_info;
|
||||
}
|
||||
|
||||
// If we're resuming a write, we're not ready to merge
|
||||
|
@ -290,7 +289,7 @@ bool CowReader::PrepMergeOps() {
|
|||
for (size_t i = 0; i < ops_->size(); i++) {
|
||||
auto& current_op = ops_->data()[i];
|
||||
|
||||
if (GetCowOpSourceInfoType(current_op) == kCowSequenceOp) {
|
||||
if (current_op.type == kCowSequenceOp) {
|
||||
size_t seq_len = current_op.data_length / sizeof(uint32_t);
|
||||
|
||||
merge_op_blocks->resize(merge_op_blocks->size() + seq_len);
|
||||
|
@ -602,7 +601,7 @@ std::unique_ptr<ICowOpIter> CowReader::GetMergeOpIter(bool ignore_progress) {
|
|||
}
|
||||
|
||||
bool CowReader::GetRawBytes(const CowOperation* op, void* buffer, size_t len, size_t* read) {
|
||||
switch (GetCowOpSourceInfoType(*op)) {
|
||||
switch (op->type) {
|
||||
case kCowSequenceOp:
|
||||
case kCowReplaceOp:
|
||||
case kCowXorOp:
|
||||
|
@ -695,7 +694,7 @@ ssize_t CowReader::ReadData(const CowOperation* op, void* buffer, size_t buffer_
|
|||
}
|
||||
|
||||
uint64_t offset;
|
||||
if (GetCowOpSourceInfoType(*op) == kCowXorOp) {
|
||||
if (op->type == kCowXorOp) {
|
||||
offset = data_loc_->at(op->new_block);
|
||||
} else {
|
||||
offset = GetCowOpSourceInfoData(*op);
|
||||
|
@ -712,7 +711,7 @@ ssize_t CowReader::ReadData(const CowOperation* op, void* buffer, size_t buffer_
|
|||
}
|
||||
|
||||
bool CowReader::GetSourceOffset(const CowOperation* op, uint64_t* source_offset) {
|
||||
switch (GetCowOpSourceInfoType(*op)) {
|
||||
switch (op->type) {
|
||||
case kCowCopyOp:
|
||||
*source_offset = GetCowOpSourceInfoData(*op) * header_.block_size;
|
||||
return true;
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include <android-base/logging.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <gflags/gflags.h>
|
||||
#include <libsnapshot/cow_format.h>
|
||||
#include <libsnapshot/cow_reader.h>
|
||||
#include "parser_v2.h"
|
||||
|
||||
|
@ -199,7 +198,7 @@ static bool Inspect(const std::string& path) {
|
|||
|
||||
if (!FLAGS_silent && FLAGS_show_ops) std::cout << *op << "\n";
|
||||
|
||||
if ((FLAGS_decompress || extract_to >= 0) && GetCowOpSourceInfoType(*op) == kCowReplaceOp) {
|
||||
if ((FLAGS_decompress || extract_to >= 0) && op->type == kCowReplaceOp) {
|
||||
if (reader.ReadData(op, buffer.data(), buffer.size()) < 0) {
|
||||
std::cerr << "Failed to decompress for :" << *op << "\n";
|
||||
success = false;
|
||||
|
@ -213,13 +212,12 @@ static bool Inspect(const std::string& path) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
} else if (extract_to >= 0 && !IsMetadataOp(*op) &&
|
||||
GetCowOpSourceInfoType(*op) != kCowZeroOp) {
|
||||
} else if (extract_to >= 0 && !IsMetadataOp(*op) && op->type != kCowZeroOp) {
|
||||
PLOG(ERROR) << "Cannot extract op yet: " << *op;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (GetCowOpSourceInfoType(*op) == kCowSequenceOp && FLAGS_show_merge_sequence) {
|
||||
if (op->type == kCowSequenceOp && FLAGS_show_merge_sequence) {
|
||||
size_t read;
|
||||
std::vector<uint32_t> merge_op_blocks;
|
||||
size_t seq_len = op->data_length / sizeof(uint32_t);
|
||||
|
@ -237,13 +235,13 @@ static bool Inspect(const std::string& path) {
|
|||
}
|
||||
}
|
||||
|
||||
if (GetCowOpSourceInfoType(*op) == kCowCopyOp) {
|
||||
if (op->type == kCowCopyOp) {
|
||||
copy_ops++;
|
||||
} else if (GetCowOpSourceInfoType(*op) == kCowReplaceOp) {
|
||||
} else if (op->type == kCowReplaceOp) {
|
||||
replace_ops++;
|
||||
} else if (GetCowOpSourceInfoType(*op) == kCowZeroOp) {
|
||||
} else if (op->type == kCowZeroOp) {
|
||||
zero_ops++;
|
||||
} else if (GetCowOpSourceInfoType(*op) == kCowXorOp) {
|
||||
} else if (op->type == kCowXorOp) {
|
||||
xor_ops++;
|
||||
}
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ ssize_t CompressedSnapshotReader::ReadBlock(uint64_t chunk, size_t start_offset,
|
|||
op = ops_[chunk];
|
||||
}
|
||||
|
||||
if (!op || GetCowOpSourceInfoType(*op) == kCowCopyOp) {
|
||||
if (!op || op->type == kCowCopyOp) {
|
||||
borrowed_fd fd = GetSourceFd();
|
||||
if (fd < 0) {
|
||||
// GetSourceFd sets errno.
|
||||
|
@ -169,15 +169,15 @@ ssize_t CompressedSnapshotReader::ReadBlock(uint64_t chunk, size_t start_offset,
|
|||
// ReadFullyAtOffset sets errno.
|
||||
return -1;
|
||||
}
|
||||
} else if (GetCowOpSourceInfoType(*op) == kCowZeroOp) {
|
||||
} else if (op->type == kCowZeroOp) {
|
||||
memset(buffer, 0, bytes_to_read);
|
||||
} else if (GetCowOpSourceInfoType(*op) == kCowReplaceOp) {
|
||||
} else if (op->type == kCowReplaceOp) {
|
||||
if (cow_->ReadData(op, buffer, bytes_to_read, start_offset) < bytes_to_read) {
|
||||
LOG(ERROR) << "CompressedSnapshotReader failed to read replace op";
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
} else if (GetCowOpSourceInfoType(*op) == kCowXorOp) {
|
||||
} else if (op->type == kCowXorOp) {
|
||||
borrowed_fd fd = GetSourceFd();
|
||||
if (fd < 0) {
|
||||
// GetSourceFd sets errno.
|
||||
|
@ -208,8 +208,7 @@ ssize_t CompressedSnapshotReader::ReadBlock(uint64_t chunk, size_t start_offset,
|
|||
((char*)buffer)[i] ^= data[i];
|
||||
}
|
||||
} else {
|
||||
LOG(ERROR) << "CompressedSnapshotReader unknown op type: "
|
||||
<< uint32_t(GetCowOpSourceInfoType(*op));
|
||||
LOG(ERROR) << "CompressedSnapshotReader unknown op type: " << uint32_t(op->type);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <libsnapshot/cow_reader.h>
|
||||
#include <libsnapshot/cow_writer.h>
|
||||
#include "cow_decompress.h"
|
||||
#include "libsnapshot/cow_format.h"
|
||||
#include "writer_v2.h"
|
||||
|
||||
using android::base::unique_fd;
|
||||
|
@ -86,7 +85,7 @@ TEST_F(CowTest, CopyContiguous) {
|
|||
size_t i = 0;
|
||||
while (!iter->AtEnd()) {
|
||||
auto op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowCopyOp);
|
||||
ASSERT_EQ(op->type, kCowCopyOp);
|
||||
ASSERT_EQ(op->data_length, 0);
|
||||
ASSERT_EQ(op->new_block, 10 + i);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 1000 + i);
|
||||
|
@ -132,7 +131,7 @@ TEST_F(CowTest, ReadWrite) {
|
|||
ASSERT_FALSE(iter->AtEnd());
|
||||
auto op = iter->Get();
|
||||
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowCopyOp);
|
||||
ASSERT_EQ(op->type, kCowCopyOp);
|
||||
ASSERT_EQ(op->data_length, 0);
|
||||
ASSERT_EQ(op->new_block, 10);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 20);
|
||||
|
@ -143,7 +142,7 @@ TEST_F(CowTest, ReadWrite) {
|
|||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowReplaceOp);
|
||||
ASSERT_EQ(op->type, kCowReplaceOp);
|
||||
ASSERT_EQ(op->data_length, 4096);
|
||||
ASSERT_EQ(op->new_block, 50);
|
||||
ASSERT_TRUE(ReadData(reader, op, sink.data(), sink.size()));
|
||||
|
@ -154,7 +153,7 @@ TEST_F(CowTest, ReadWrite) {
|
|||
op = iter->Get();
|
||||
|
||||
// Note: the zero operation gets split into two blocks.
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowZeroOp);
|
||||
ASSERT_EQ(op->type, kCowZeroOp);
|
||||
ASSERT_EQ(op->data_length, 0);
|
||||
ASSERT_EQ(op->new_block, 51);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 0);
|
||||
|
@ -163,7 +162,7 @@ TEST_F(CowTest, ReadWrite) {
|
|||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowZeroOp);
|
||||
ASSERT_EQ(op->type, kCowZeroOp);
|
||||
ASSERT_EQ(op->data_length, 0);
|
||||
ASSERT_EQ(op->new_block, 52);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 0);
|
||||
|
@ -207,7 +206,7 @@ TEST_F(CowTest, ReadWriteXor) {
|
|||
ASSERT_FALSE(iter->AtEnd());
|
||||
auto op = iter->Get();
|
||||
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowCopyOp);
|
||||
ASSERT_EQ(op->type, kCowCopyOp);
|
||||
ASSERT_EQ(op->data_length, 0);
|
||||
ASSERT_EQ(op->new_block, 10);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 20);
|
||||
|
@ -218,7 +217,7 @@ TEST_F(CowTest, ReadWriteXor) {
|
|||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowXorOp);
|
||||
ASSERT_EQ(op->type, kCowXorOp);
|
||||
ASSERT_EQ(op->data_length, 4096);
|
||||
ASSERT_EQ(op->new_block, 50);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 98314); // 4096 * 24 + 10
|
||||
|
@ -230,7 +229,7 @@ TEST_F(CowTest, ReadWriteXor) {
|
|||
op = iter->Get();
|
||||
|
||||
// Note: the zero operation gets split into two blocks.
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowZeroOp);
|
||||
ASSERT_EQ(op->type, kCowZeroOp);
|
||||
ASSERT_EQ(op->data_length, 0);
|
||||
ASSERT_EQ(op->new_block, 51);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 0);
|
||||
|
@ -239,7 +238,7 @@ TEST_F(CowTest, ReadWriteXor) {
|
|||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowZeroOp);
|
||||
ASSERT_EQ(op->type, kCowZeroOp);
|
||||
ASSERT_EQ(op->data_length, 0);
|
||||
ASSERT_EQ(op->new_block, 52);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 0);
|
||||
|
@ -274,7 +273,7 @@ TEST_F(CowTest, CompressGz) {
|
|||
|
||||
std::string sink(data.size(), '\0');
|
||||
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowReplaceOp);
|
||||
ASSERT_EQ(op->type, kCowReplaceOp);
|
||||
ASSERT_EQ(op->data_length, 56); // compressed!
|
||||
ASSERT_EQ(op->new_block, 50);
|
||||
ASSERT_TRUE(ReadData(reader, op, sink.data(), sink.size()));
|
||||
|
@ -326,7 +325,7 @@ TEST_P(CompressionTest, ThreadedBatchWrites) {
|
|||
while (!iter->AtEnd()) {
|
||||
auto op = iter->Get();
|
||||
|
||||
if (GetCowOpSourceInfoType(*op) == kCowXorOp) {
|
||||
if (op->type == kCowXorOp) {
|
||||
total_blocks += 1;
|
||||
std::string sink(xor_data.size(), '\0');
|
||||
ASSERT_EQ(op->new_block, 50);
|
||||
|
@ -335,7 +334,7 @@ TEST_P(CompressionTest, ThreadedBatchWrites) {
|
|||
ASSERT_EQ(sink, xor_data);
|
||||
}
|
||||
|
||||
if (GetCowOpSourceInfoType(*op) == kCowReplaceOp) {
|
||||
if (op->type == kCowReplaceOp) {
|
||||
total_blocks += 1;
|
||||
if (op->new_block == 100) {
|
||||
data.resize(options.block_size);
|
||||
|
@ -400,7 +399,7 @@ TEST_P(CompressionTest, NoBatchWrites) {
|
|||
while (!iter->AtEnd()) {
|
||||
auto op = iter->Get();
|
||||
|
||||
if (GetCowOpSourceInfoType(*op) == kCowReplaceOp) {
|
||||
if (op->type == kCowReplaceOp) {
|
||||
total_blocks += 1;
|
||||
if (op->new_block == 50) {
|
||||
data.resize(options.block_size);
|
||||
|
@ -520,7 +519,7 @@ TEST_F(CowTest, ClusterCompressGz) {
|
|||
|
||||
std::string sink(data.size(), '\0');
|
||||
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowReplaceOp);
|
||||
ASSERT_EQ(op->type, kCowReplaceOp);
|
||||
ASSERT_EQ(op->data_length, 56); // compressed!
|
||||
ASSERT_EQ(op->new_block, 50);
|
||||
ASSERT_TRUE(ReadData(reader, op, sink.data(), sink.size()));
|
||||
|
@ -530,7 +529,7 @@ TEST_F(CowTest, ClusterCompressGz) {
|
|||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowClusterOp);
|
||||
ASSERT_EQ(op->type, kCowClusterOp);
|
||||
|
||||
iter->Next();
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
|
@ -547,7 +546,7 @@ TEST_F(CowTest, ClusterCompressGz) {
|
|||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowClusterOp);
|
||||
ASSERT_EQ(op->type, kCowClusterOp);
|
||||
|
||||
iter->Next();
|
||||
ASSERT_TRUE(iter->AtEnd());
|
||||
|
@ -581,7 +580,7 @@ TEST_F(CowTest, CompressTwoBlocks) {
|
|||
std::string sink(options.block_size, '\0');
|
||||
|
||||
auto op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowReplaceOp);
|
||||
ASSERT_EQ(op->type, kCowReplaceOp);
|
||||
ASSERT_EQ(op->new_block, 51);
|
||||
ASSERT_TRUE(ReadData(reader, op, sink.data(), sink.size()));
|
||||
}
|
||||
|
@ -654,7 +653,7 @@ TEST_F(CowTest, AppendLabelSmall) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
auto op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowReplaceOp);
|
||||
ASSERT_EQ(op->type, kCowReplaceOp);
|
||||
ASSERT_TRUE(ReadData(reader, op, sink.data(), sink.size()));
|
||||
ASSERT_EQ(sink, data);
|
||||
|
||||
|
@ -664,14 +663,14 @@ TEST_F(CowTest, AppendLabelSmall) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowLabelOp);
|
||||
ASSERT_EQ(op->type, kCowLabelOp);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 3);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowReplaceOp);
|
||||
ASSERT_EQ(op->type, kCowReplaceOp);
|
||||
ASSERT_TRUE(ReadData(reader, op, sink.data(), sink.size()));
|
||||
ASSERT_EQ(sink, data2);
|
||||
|
||||
|
@ -717,14 +716,14 @@ TEST_F(CowTest, AppendLabelMissing) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
auto op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowLabelOp);
|
||||
ASSERT_EQ(op->type, kCowLabelOp);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 0);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowZeroOp);
|
||||
ASSERT_EQ(op->type, kCowZeroOp);
|
||||
|
||||
iter->Next();
|
||||
|
||||
|
@ -775,7 +774,7 @@ TEST_F(CowTest, AppendExtendedCorrupted) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
auto op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowLabelOp);
|
||||
ASSERT_EQ(op->type, kCowLabelOp);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 5);
|
||||
|
||||
iter->Next();
|
||||
|
@ -826,7 +825,7 @@ TEST_F(CowTest, AppendbyLabel) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
auto op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowReplaceOp);
|
||||
ASSERT_EQ(op->type, kCowReplaceOp);
|
||||
ASSERT_TRUE(ReadData(reader, op, sink.data(), sink.size()));
|
||||
ASSERT_EQ(sink, data.substr(0, options.block_size));
|
||||
|
||||
|
@ -836,7 +835,7 @@ TEST_F(CowTest, AppendbyLabel) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowReplaceOp);
|
||||
ASSERT_EQ(op->type, kCowReplaceOp);
|
||||
ASSERT_TRUE(ReadData(reader, op, sink.data(), sink.size()));
|
||||
ASSERT_EQ(sink, data.substr(options.block_size, 2 * options.block_size));
|
||||
|
||||
|
@ -844,25 +843,25 @@ TEST_F(CowTest, AppendbyLabel) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowLabelOp);
|
||||
ASSERT_EQ(op->type, kCowLabelOp);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 4);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowZeroOp);
|
||||
ASSERT_EQ(op->type, kCowZeroOp);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowZeroOp);
|
||||
ASSERT_EQ(op->type, kCowZeroOp);
|
||||
|
||||
iter->Next();
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowLabelOp);
|
||||
ASSERT_EQ(op->type, kCowLabelOp);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 5);
|
||||
|
||||
iter->Next();
|
||||
|
@ -907,7 +906,7 @@ TEST_F(CowTest, ClusterTest) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
auto op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowReplaceOp);
|
||||
ASSERT_EQ(op->type, kCowReplaceOp);
|
||||
ASSERT_TRUE(ReadData(reader, op, sink.data(), sink.size()));
|
||||
ASSERT_EQ(sink, data.substr(0, options.block_size));
|
||||
|
||||
|
@ -915,51 +914,51 @@ TEST_F(CowTest, ClusterTest) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowLabelOp);
|
||||
ASSERT_EQ(op->type, kCowLabelOp);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 4);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowZeroOp);
|
||||
ASSERT_EQ(op->type, kCowZeroOp);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowClusterOp);
|
||||
ASSERT_EQ(op->type, kCowClusterOp);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowZeroOp);
|
||||
ASSERT_EQ(op->type, kCowZeroOp);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowLabelOp);
|
||||
ASSERT_EQ(op->type, kCowLabelOp);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 5);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowCopyOp);
|
||||
ASSERT_EQ(op->type, kCowCopyOp);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowClusterOp);
|
||||
ASSERT_EQ(op->type, kCowClusterOp);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowLabelOp);
|
||||
ASSERT_EQ(op->type, kCowLabelOp);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 6);
|
||||
|
||||
iter->Next();
|
||||
|
@ -1006,14 +1005,14 @@ TEST_F(CowTest, ClusterAppendTest) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
auto op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowLabelOp);
|
||||
ASSERT_EQ(op->type, kCowLabelOp);
|
||||
ASSERT_EQ(GetCowOpSourceInfoData(*op), 50);
|
||||
|
||||
iter->Next();
|
||||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowReplaceOp);
|
||||
ASSERT_EQ(op->type, kCowReplaceOp);
|
||||
ASSERT_TRUE(ReadData(reader, op, sink.data(), sink.size()));
|
||||
ASSERT_EQ(sink, data2);
|
||||
|
||||
|
@ -1021,7 +1020,7 @@ TEST_F(CowTest, ClusterAppendTest) {
|
|||
|
||||
ASSERT_FALSE(iter->AtEnd());
|
||||
op = iter->Get();
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(*op), kCowClusterOp);
|
||||
ASSERT_EQ(op->type, kCowClusterOp);
|
||||
|
||||
iter->Next();
|
||||
|
||||
|
@ -1118,12 +1117,12 @@ TEST_F(CowTest, ResumeMidCluster) {
|
|||
num_in_cluster++;
|
||||
max_in_cluster = std::max(max_in_cluster, num_in_cluster);
|
||||
|
||||
if (GetCowOpSourceInfoType(*op) == kCowReplaceOp) {
|
||||
if (op->type == kCowReplaceOp) {
|
||||
num_replace++;
|
||||
|
||||
ASSERT_EQ(op->new_block, num_replace);
|
||||
ASSERT_TRUE(CompareDataBlock(&reader, op, "Block " + std::to_string(num_replace)));
|
||||
} else if (GetCowOpSourceInfoType(*op) == kCowClusterOp) {
|
||||
} else if (op->type == kCowClusterOp) {
|
||||
num_in_cluster = 0;
|
||||
num_clusters++;
|
||||
}
|
||||
|
@ -1179,12 +1178,12 @@ TEST_F(CowTest, ResumeEndCluster) {
|
|||
num_in_cluster++;
|
||||
max_in_cluster = std::max(max_in_cluster, num_in_cluster);
|
||||
|
||||
if (GetCowOpSourceInfoType(*op) == kCowReplaceOp) {
|
||||
if (op->type == kCowReplaceOp) {
|
||||
num_replace++;
|
||||
|
||||
ASSERT_EQ(op->new_block, num_replace);
|
||||
ASSERT_TRUE(CompareDataBlock(&reader, op, "Block " + std::to_string(num_replace)));
|
||||
} else if (GetCowOpSourceInfoType(*op) == kCowClusterOp) {
|
||||
} else if (op->type == kCowClusterOp) {
|
||||
num_in_cluster = 0;
|
||||
num_clusters++;
|
||||
}
|
||||
|
@ -1230,12 +1229,12 @@ TEST_F(CowTest, DeleteMidCluster) {
|
|||
|
||||
num_in_cluster++;
|
||||
max_in_cluster = std::max(max_in_cluster, num_in_cluster);
|
||||
if (GetCowOpSourceInfoType(*op) == kCowReplaceOp) {
|
||||
if (op->type == kCowReplaceOp) {
|
||||
num_replace++;
|
||||
|
||||
ASSERT_EQ(op->new_block, num_replace);
|
||||
ASSERT_TRUE(CompareDataBlock(&reader, op, "Block " + std::to_string(num_replace)));
|
||||
} else if (GetCowOpSourceInfoType(*op) == kCowClusterOp) {
|
||||
} else if (op->type == kCowClusterOp) {
|
||||
num_in_cluster = 0;
|
||||
num_clusters++;
|
||||
}
|
||||
|
|
|
@ -49,14 +49,5 @@ class CowOperationV3Test : public ::testing::Test {
|
|||
std::unique_ptr<TemporaryFile> cow_;
|
||||
};
|
||||
|
||||
TEST_F(CowOperationV3Test, CowTypeTest) {
|
||||
CowOperationV3 new_op;
|
||||
CowOperationV2 old_op;
|
||||
old_op.type = kCowReplaceOp;
|
||||
ASSERT_NE(GetCowOpSourceInfoType(new_op), old_op.type);
|
||||
SetCowOpSourceInfoType(&new_op, old_op.type);
|
||||
ASSERT_EQ(GetCowOpSourceInfoType(new_op), old_op.type);
|
||||
}
|
||||
|
||||
} // namespace snapshot
|
||||
} // namespace android
|
|
@ -25,7 +25,6 @@
|
|||
#include <csignal>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include "libsnapshot/cow_format.h"
|
||||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
|
@ -407,9 +406,9 @@ bool Snapuserd::ReadMetadata() {
|
|||
break;
|
||||
}
|
||||
|
||||
if (GetCowOpSourceInfoType(*cow_op) == kCowReplaceOp) {
|
||||
if (cow_op->type == kCowReplaceOp) {
|
||||
replace_ops++;
|
||||
} else if (GetCowOpSourceInfoType(*cow_op) == kCowZeroOp) {
|
||||
} else if (cow_op->type == kCowZeroOp) {
|
||||
zero_ops++;
|
||||
}
|
||||
|
||||
|
@ -541,7 +540,7 @@ bool Snapuserd::ReadMetadata() {
|
|||
chunk_vec_.push_back(std::make_pair(ChunkToSector(data_chunk_id), cow_op));
|
||||
offset += sizeof(struct disk_exception);
|
||||
num_ops += 1;
|
||||
if (GetCowOpSourceInfoType(*cow_op) == kCowCopyOp) {
|
||||
if (cow_op->type == kCowCopyOp) {
|
||||
copy_ops++;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "libsnapshot/cow_format.h"
|
||||
#include "snapuserd.h"
|
||||
|
||||
#include <csignal>
|
||||
|
@ -193,7 +192,7 @@ void ReadAheadThread::PrepareReadAhead(uint64_t* source_offset, int* pending_ops
|
|||
const CowOperation* cow_op = GetRAOpIter();
|
||||
CHECK_NE(cow_op, nullptr);
|
||||
*source_offset = GetCowOpSourceInfoData(*cow_op);
|
||||
if (GetCowOpSourceInfoData(*cow_op) == kCowCopyOp) {
|
||||
if (cow_op->type == kCowCopyOp) {
|
||||
*source_offset *= BLOCK_SZ;
|
||||
}
|
||||
RAIterNext();
|
||||
|
@ -212,7 +211,7 @@ void ReadAheadThread::PrepareReadAhead(uint64_t* source_offset, int* pending_ops
|
|||
const CowOperation* op = GetRAOpIter();
|
||||
CHECK_NE(op, nullptr);
|
||||
uint64_t next_offset = GetCowOpSourceInfoData(*op);
|
||||
if (GetCowOpSourceInfoData(*op) == kCowCopyOp) {
|
||||
if (op->type == kCowCopyOp) {
|
||||
next_offset *= BLOCK_SZ;
|
||||
}
|
||||
if (next_offset + nr_consecutive * BLOCK_SZ != *source_offset) {
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "libsnapshot/cow_format.h"
|
||||
#include "snapuserd.h"
|
||||
|
||||
#include <csignal>
|
||||
|
@ -178,7 +177,7 @@ bool WorkerThread::ProcessCowOp(const CowOperation* cow_op) {
|
|||
return false;
|
||||
}
|
||||
|
||||
switch (GetCowOpSourceInfoType(*cow_op)) {
|
||||
switch (cow_op->type) {
|
||||
case kCowReplaceOp: {
|
||||
return ProcessReplaceOp(cow_op);
|
||||
}
|
||||
|
@ -192,8 +191,7 @@ bool WorkerThread::ProcessCowOp(const CowOperation* cow_op) {
|
|||
}
|
||||
|
||||
default: {
|
||||
SNAP_LOG(ERROR) << "Unsupported operation-type found: "
|
||||
<< GetCowOpSourceInfoType(*cow_op);
|
||||
SNAP_LOG(ERROR) << "Unsupported operation-type found: " << cow_op->type;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "libsnapshot/cow_format.h"
|
||||
#include "snapuserd_core.h"
|
||||
#include "utility.h"
|
||||
|
||||
|
@ -115,13 +114,13 @@ bool MergeWorker::MergeReplaceZeroOps() {
|
|||
SNAP_LOG(ERROR) << "AcquireBuffer failed in MergeReplaceOps";
|
||||
return false;
|
||||
}
|
||||
if (GetCowOpSourceInfoType(*cow_op) == kCowReplaceOp) {
|
||||
if (cow_op->type == kCowReplaceOp) {
|
||||
if (!reader_->ReadData(cow_op, buffer, BLOCK_SZ)) {
|
||||
SNAP_LOG(ERROR) << "Failed to read COW in merge";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
CHECK(GetCowOpSourceInfoType(*cow_op) == kCowZeroOp);
|
||||
CHECK(cow_op->type == kCowZeroOp);
|
||||
memset(buffer, 0, BLOCK_SZ);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "libsnapshot/cow_format.h"
|
||||
#include "snapuserd_core.h"
|
||||
#include "utility.h"
|
||||
|
||||
|
@ -64,7 +63,7 @@ bool ReadWorker::ReadFromSourceDevice(const CowOperation* cow_op, void* buffer)
|
|||
<< " Op: " << *cow_op;
|
||||
if (!android::base::ReadFullyAtOffset(backing_store_fd_, buffer, BLOCK_SZ, offset)) {
|
||||
std::string op;
|
||||
if (GetCowOpSourceInfoType(*cow_op) == kCowCopyOp)
|
||||
if (cow_op->type == kCowCopyOp)
|
||||
op = "Copy-op";
|
||||
else {
|
||||
op = "Xor-op";
|
||||
|
@ -134,7 +133,7 @@ bool ReadWorker::ProcessOrderedOp(const CowOperation* cow_op, void* buffer) {
|
|||
}
|
||||
case MERGE_GROUP_STATE::GROUP_MERGE_PENDING: {
|
||||
bool ret;
|
||||
if (GetCowOpSourceInfoType(*cow_op) == kCowCopyOp) {
|
||||
if (cow_op->type == kCowCopyOp) {
|
||||
ret = ProcessCopyOp(cow_op, buffer);
|
||||
} else {
|
||||
ret = ProcessXorOp(cow_op, buffer);
|
||||
|
@ -168,7 +167,7 @@ bool ReadWorker::ProcessCowOp(const CowOperation* cow_op, void* buffer) {
|
|||
return false;
|
||||
}
|
||||
|
||||
switch (GetCowOpSourceInfoType(*cow_op)) {
|
||||
switch (cow_op->type) {
|
||||
case kCowReplaceOp: {
|
||||
return ProcessReplaceOp(cow_op, buffer);
|
||||
}
|
||||
|
@ -184,7 +183,7 @@ bool ReadWorker::ProcessCowOp(const CowOperation* cow_op, void* buffer) {
|
|||
}
|
||||
|
||||
default: {
|
||||
SNAP_LOG(ERROR) << "Unknown operation-type found: " << GetCowOpSourceInfoType(*cow_op);
|
||||
SNAP_LOG(ERROR) << "Unknown operation-type found: " << cow_op->type;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <android-base/strings.h>
|
||||
#include <snapuserd/dm_user_block_server.h>
|
||||
|
||||
#include "libsnapshot/cow_format.h"
|
||||
#include "merge_worker.h"
|
||||
#include "read_worker.h"
|
||||
|
||||
|
@ -197,13 +196,13 @@ bool SnapshotHandler::ReadMetadata() {
|
|||
while (!cowop_iter->AtEnd()) {
|
||||
const CowOperation* cow_op = cowop_iter->Get();
|
||||
|
||||
if (GetCowOpSourceInfoType(*cow_op) == kCowCopyOp) {
|
||||
if (cow_op->type == kCowCopyOp) {
|
||||
copy_ops += 1;
|
||||
} else if (GetCowOpSourceInfoType(*cow_op) == kCowReplaceOp) {
|
||||
} else if (cow_op->type == kCowReplaceOp) {
|
||||
replace_ops += 1;
|
||||
} else if (GetCowOpSourceInfoType(*cow_op) == kCowZeroOp) {
|
||||
} else if (cow_op->type == kCowZeroOp) {
|
||||
zero_ops += 1;
|
||||
} else if (GetCowOpSourceInfoType(*cow_op) == kCowXorOp) {
|
||||
} else if (cow_op->type == kCowXorOp) {
|
||||
xor_ops += 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "libsnapshot/cow_format.h"
|
||||
#include "snapuserd_core.h"
|
||||
#include "utility.h"
|
||||
|
||||
|
@ -78,7 +77,7 @@ int ReadAhead::PrepareNextReadAhead(uint64_t* source_offset, int* pending_ops,
|
|||
SNAP_LOG(ERROR) << "PrepareNextReadAhead operation has no source offset: " << *cow_op;
|
||||
return nr_consecutive;
|
||||
}
|
||||
if (GetCowOpSourceInfoType(*cow_op) == kCowXorOp) {
|
||||
if (cow_op->type == kCowXorOp) {
|
||||
xor_op_vec.push_back(cow_op);
|
||||
}
|
||||
|
||||
|
@ -107,7 +106,7 @@ int ReadAhead::PrepareNextReadAhead(uint64_t* source_offset, int* pending_ops,
|
|||
break;
|
||||
}
|
||||
|
||||
if (GetCowOpSourceInfoType(*op) == kCowXorOp) {
|
||||
if (op->type == kCowXorOp) {
|
||||
xor_op_vec.push_back(op);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue