Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 65796039 authored by David Anderson's avatar David Anderson Committed by Gerrit Code Review
Browse files

Merge "snapuserd: Remove legacy xor code."

parents 2812fd84 0172b1cc
Loading
Loading
Loading
Loading
+0 −29
Original line number Diff line number Diff line
@@ -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) {
    CowSnapuserdMetadataTest harness;
    harness.Setup();
+4 −10
Original line number Diff line number Diff line
@@ -350,7 +350,7 @@ bool Snapuserd::ReadMetadata() {
    CowHeader header;
    CowOptions options;
    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";

@@ -515,10 +515,6 @@ bool Snapuserd::ReadMetadata() {
            //===========================================================
            uint64_t block_source = cow_op->source;
            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 (dest_blocks.count(cow_op->new_block) || source_blocks.count(block_source) ||
                    (block_offset > 0 && source_blocks.count(block_source + 1))) {
@@ -538,7 +534,7 @@ bool Snapuserd::ReadMetadata() {
        } while (!cowop_rm_iter->Done() && pending_ordered_ops);

        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
                        << " Pending-ordered-ops in this area: " << pending_ordered_ops;

@@ -556,8 +552,6 @@ bool Snapuserd::ReadMetadata() {
            num_ops += 1;
            if (cow_op->type == kCowCopyOp) {
                copy_ops++;
            } else {  // it->second->type == kCowXorOp
                xor_ops++;
            }

            if (read_ahead_feature_) {
@@ -629,8 +623,8 @@ bool Snapuserd::ReadMetadata() {
    SNAP_LOG(INFO) << "ReadMetadata completed. Final-chunk-id: " << data_chunk_id
                   << " Num Sector: " << ChunkToSector(data_chunk_id)
                   << " Replace-ops: " << replace_ops << " Zero-ops: " << zero_ops
                   << " Copy-ops: " << copy_ops << " Xor-ops: " << xor_ops
                   << " Areas: " << vec_.size() << " Num-ops-merged: " << header.num_merge_ops
                   << " Copy-ops: " << copy_ops << " Areas: " << vec_.size()
                   << " Num-ops-merged: " << header.num_merge_ops
                   << " Total-data-ops: " << reader_->get_num_total_data_ops();

    // Total number of sectors required for creating dm-user device
+1 −3
Original line number Diff line number Diff line
@@ -170,9 +170,8 @@ class WorkerThread {
    // Processing COW operations
    bool ProcessCowOp(const CowOperation* cow_op);
    bool ProcessReplaceOp(const CowOperation* cow_op);
    // Handles Copy and Xor
    // Handles Copy
    bool ProcessCopyOp(const CowOperation* cow_op);
    bool ProcessXorOp(const CowOperation* cow_op);
    bool ProcessZeroOp();

    bool ReadFromBaseDevice(const CowOperation* cow_op);
@@ -191,7 +190,6 @@ class WorkerThread {

    std::unique_ptr<CowReader> reader_;
    BufferSink bufsink_;
    XorSink xorsink_;

    std::string cow_device_;
    std::string backing_store_device_;
+0 −4
Original line number Diff line number Diff line
@@ -174,10 +174,6 @@ ReadAheadThread::ReadAheadThread(const std::string& cow_device, const std::strin
void ReadAheadThread::CheckOverlap(const CowOperation* cow_op) {
    uint64_t source_block = cow_op->source;
    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) ||
        (source_offset > 0 && source_blocks_.count(source_block + 1))) {
        overlap_ = true;
+2 −30
Original line number Diff line number Diff line
@@ -116,13 +116,7 @@ bool WorkerThread::ReadFromBaseDevice(const CowOperation* cow_op) {
        offset *= BLOCK_SZ;
    }
    if (!android::base::ReadFullyAtOffset(backing_store_fd_, buffer, BLOCK_SZ, offset)) {
        std::string op;
        if (cow_op->type == kCowCopyOp)
            op = "Copy-op";
        else {
            op = "Xor-op";
        }
        SNAP_PLOG(ERROR) << op << " failed. Read from backing store: " << backing_store_device_
        SNAP_PLOG(ERROR) << "Copy op failed. Read from backing store: " << backing_store_device_
                         << "at block :" << offset / BLOCK_SZ << " offset:" << offset % BLOCK_SZ;
        return false;
    }
@@ -158,23 +152,6 @@ bool WorkerThread::ProcessCopyOp(const CowOperation* cow_op) {
    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() {
    // Zero out the entire block
    void* buffer = bufsink_.GetPayloadBuffer(BLOCK_SZ);
@@ -206,12 +183,8 @@ bool WorkerThread::ProcessCowOp(const CowOperation* cow_op) {
            return ProcessCopyOp(cow_op);
        }

        case kCowXorOp: {
            return ProcessXorOp(cow_op);
        }

        default: {
            SNAP_LOG(ERROR) << "Unknown operation-type found: " << cow_op->type;
            SNAP_LOG(ERROR) << "Unsupported operation-type found: " << cow_op->type;
        }
    }
    return false;
@@ -830,7 +803,6 @@ void WorkerThread::InitializeBufsink() {

bool WorkerThread::RunThread() {
    InitializeBufsink();
    xorsink_.Initialize(&bufsink_, BLOCK_SZ);

    if (!InitializeFds()) {
        return false;