Merge "snapuserd: Remove legacy xor code." am: 657960396c

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2504296

Change-Id: I66efd239a4ae993321665bf15118bc7d866f8def
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
David Anderson 2023-04-14 23:23:52 +00:00 committed by Automerger Merge Worker
commit b8a12d8dbd
5 changed files with 7 additions and 76 deletions

View File

@ -1152,35 +1152,6 @@ void CowSnapuserdMetadataTest::ValidateMetadata() {
} }
} }
TEST(Snapuserd_Test, xor_buffer) {
std::string data = "Test String";
std::string jumbled = {0x0C, 0x2A, 0x21, 0x54, 0x73, 0x27, 0x06, 0x1B, 0x07, 0x09, 0x46};
std::string result = "XOR String!";
BufferSink sink;
XorSink xor_sink;
sink.Initialize(sizeof(struct dm_user_header) + 10);
int buffsize = 5;
xor_sink.Initialize(&sink, buffsize);
void* buff = sink.GetPayloadBuffer(data.length());
memcpy(buff, data.data(), data.length());
size_t actual;
size_t count = 0;
while (count < data.length()) {
void* xor_buff = xor_sink.GetBuffer(10, &actual);
ASSERT_EQ(actual, buffsize);
ASSERT_NE(xor_buff, nullptr);
memcpy(xor_buff, jumbled.data() + count, buffsize);
xor_sink.ReturnData(xor_buff, actual);
count += actual;
}
std::string answer = reinterpret_cast<char*>(sink.GetPayloadBufPtr());
ASSERT_EQ(answer, result);
}
TEST(Snapuserd_Test, Snapshot_Metadata) { TEST(Snapuserd_Test, Snapshot_Metadata) {
CowSnapuserdMetadataTest harness; CowSnapuserdMetadataTest harness;
harness.Setup(); harness.Setup();

View File

@ -350,7 +350,7 @@ bool Snapuserd::ReadMetadata() {
CowHeader header; CowHeader header;
CowOptions options; CowOptions options;
bool metadata_found = false; bool metadata_found = false;
int replace_ops = 0, zero_ops = 0, copy_ops = 0, xor_ops = 0; int replace_ops = 0, zero_ops = 0, copy_ops = 0;
SNAP_LOG(DEBUG) << "ReadMetadata: Parsing cow file"; SNAP_LOG(DEBUG) << "ReadMetadata: Parsing cow file";
@ -515,10 +515,6 @@ bool Snapuserd::ReadMetadata() {
//=========================================================== //===========================================================
uint64_t block_source = cow_op->source; uint64_t block_source = cow_op->source;
uint64_t block_offset = 0; uint64_t block_offset = 0;
if (cow_op->type == kCowXorOp) {
block_source /= BLOCK_SZ;
block_offset = cow_op->source % BLOCK_SZ;
}
if (prev_id.has_value()) { if (prev_id.has_value()) {
if (dest_blocks.count(cow_op->new_block) || source_blocks.count(block_source) || if (dest_blocks.count(cow_op->new_block) || source_blocks.count(block_source) ||
(block_offset > 0 && source_blocks.count(block_source + 1))) { (block_offset > 0 && source_blocks.count(block_source + 1))) {
@ -538,7 +534,7 @@ bool Snapuserd::ReadMetadata() {
} while (!cowop_rm_iter->Done() && pending_ordered_ops); } while (!cowop_rm_iter->Done() && pending_ordered_ops);
data_chunk_id = GetNextAllocatableChunkId(data_chunk_id); data_chunk_id = GetNextAllocatableChunkId(data_chunk_id);
SNAP_LOG(DEBUG) << "Batch Merge copy-ops/xor-ops of size: " << vec.size() SNAP_LOG(DEBUG) << "Batch Merge copy-ops of size: " << vec.size()
<< " Area: " << vec_.size() << " Area offset: " << offset << " Area: " << vec_.size() << " Area offset: " << offset
<< " Pending-ordered-ops in this area: " << pending_ordered_ops; << " Pending-ordered-ops in this area: " << pending_ordered_ops;
@ -556,8 +552,6 @@ bool Snapuserd::ReadMetadata() {
num_ops += 1; num_ops += 1;
if (cow_op->type == kCowCopyOp) { if (cow_op->type == kCowCopyOp) {
copy_ops++; copy_ops++;
} else { // it->second->type == kCowXorOp
xor_ops++;
} }
if (read_ahead_feature_) { if (read_ahead_feature_) {
@ -629,8 +623,8 @@ bool Snapuserd::ReadMetadata() {
SNAP_LOG(INFO) << "ReadMetadata completed. Final-chunk-id: " << data_chunk_id SNAP_LOG(INFO) << "ReadMetadata completed. Final-chunk-id: " << data_chunk_id
<< " Num Sector: " << ChunkToSector(data_chunk_id) << " Num Sector: " << ChunkToSector(data_chunk_id)
<< " Replace-ops: " << replace_ops << " Zero-ops: " << zero_ops << " Replace-ops: " << replace_ops << " Zero-ops: " << zero_ops
<< " Copy-ops: " << copy_ops << " Xor-ops: " << xor_ops << " Copy-ops: " << copy_ops << " Areas: " << vec_.size()
<< " Areas: " << vec_.size() << " Num-ops-merged: " << header.num_merge_ops << " Num-ops-merged: " << header.num_merge_ops
<< " Total-data-ops: " << reader_->get_num_total_data_ops(); << " Total-data-ops: " << reader_->get_num_total_data_ops();
// Total number of sectors required for creating dm-user device // Total number of sectors required for creating dm-user device

View File

@ -170,9 +170,8 @@ class WorkerThread {
// Processing COW operations // Processing COW operations
bool ProcessCowOp(const CowOperation* cow_op); bool ProcessCowOp(const CowOperation* cow_op);
bool ProcessReplaceOp(const CowOperation* cow_op); bool ProcessReplaceOp(const CowOperation* cow_op);
// Handles Copy and Xor // Handles Copy
bool ProcessCopyOp(const CowOperation* cow_op); bool ProcessCopyOp(const CowOperation* cow_op);
bool ProcessXorOp(const CowOperation* cow_op);
bool ProcessZeroOp(); bool ProcessZeroOp();
bool ReadFromBaseDevice(const CowOperation* cow_op); bool ReadFromBaseDevice(const CowOperation* cow_op);
@ -191,7 +190,6 @@ class WorkerThread {
std::unique_ptr<CowReader> reader_; std::unique_ptr<CowReader> reader_;
BufferSink bufsink_; BufferSink bufsink_;
XorSink xorsink_;
std::string cow_device_; std::string cow_device_;
std::string backing_store_device_; std::string backing_store_device_;

View File

@ -174,10 +174,6 @@ ReadAheadThread::ReadAheadThread(const std::string& cow_device, const std::strin
void ReadAheadThread::CheckOverlap(const CowOperation* cow_op) { void ReadAheadThread::CheckOverlap(const CowOperation* cow_op) {
uint64_t source_block = cow_op->source; uint64_t source_block = cow_op->source;
uint64_t source_offset = 0; uint64_t source_offset = 0;
if (cow_op->type == kCowXorOp) {
source_block /= BLOCK_SZ;
source_offset = cow_op->source % BLOCK_SZ;
}
if (dest_blocks_.count(cow_op->new_block) || source_blocks_.count(source_block) || if (dest_blocks_.count(cow_op->new_block) || source_blocks_.count(source_block) ||
(source_offset > 0 && source_blocks_.count(source_block + 1))) { (source_offset > 0 && source_blocks_.count(source_block + 1))) {
overlap_ = true; overlap_ = true;

View File

@ -116,13 +116,7 @@ bool WorkerThread::ReadFromBaseDevice(const CowOperation* cow_op) {
offset *= BLOCK_SZ; offset *= BLOCK_SZ;
} }
if (!android::base::ReadFullyAtOffset(backing_store_fd_, buffer, BLOCK_SZ, offset)) { if (!android::base::ReadFullyAtOffset(backing_store_fd_, buffer, BLOCK_SZ, offset)) {
std::string op; SNAP_PLOG(ERROR) << "Copy op failed. Read from backing store: " << backing_store_device_
if (cow_op->type == kCowCopyOp)
op = "Copy-op";
else {
op = "Xor-op";
}
SNAP_PLOG(ERROR) << op << " failed. Read from backing store: " << backing_store_device_
<< "at block :" << offset / BLOCK_SZ << " offset:" << offset % BLOCK_SZ; << "at block :" << offset / BLOCK_SZ << " offset:" << offset % BLOCK_SZ;
return false; return false;
} }
@ -158,23 +152,6 @@ bool WorkerThread::ProcessCopyOp(const CowOperation* cow_op) {
return true; return true;
} }
bool WorkerThread::ProcessXorOp(const CowOperation* cow_op) {
if (!GetReadAheadPopulatedBuffer(cow_op)) {
SNAP_LOG(DEBUG) << " GetReadAheadPopulatedBuffer failed..."
<< " new_block: " << cow_op->new_block;
if (!ReadFromBaseDevice(cow_op)) {
return false;
}
}
xorsink_.Reset();
if (!reader_->ReadData(*cow_op, &xorsink_)) {
SNAP_LOG(ERROR) << "ProcessXorOp failed for block " << cow_op->new_block;
return false;
}
return true;
}
bool WorkerThread::ProcessZeroOp() { bool WorkerThread::ProcessZeroOp() {
// Zero out the entire block // Zero out the entire block
void* buffer = bufsink_.GetPayloadBuffer(BLOCK_SZ); void* buffer = bufsink_.GetPayloadBuffer(BLOCK_SZ);
@ -206,12 +183,8 @@ bool WorkerThread::ProcessCowOp(const CowOperation* cow_op) {
return ProcessCopyOp(cow_op); return ProcessCopyOp(cow_op);
} }
case kCowXorOp: {
return ProcessXorOp(cow_op);
}
default: { default: {
SNAP_LOG(ERROR) << "Unknown operation-type found: " << cow_op->type; SNAP_LOG(ERROR) << "Unsupported operation-type found: " << cow_op->type;
} }
} }
return false; return false;
@ -830,7 +803,6 @@ void WorkerThread::InitializeBufsink() {
bool WorkerThread::RunThread() { bool WorkerThread::RunThread() {
InitializeBufsink(); InitializeBufsink();
xorsink_.Initialize(&bufsink_, BLOCK_SZ);
if (!InitializeFds()) { if (!InitializeFds()) {
return false; return false;