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

Commit 8bc625e9 authored by David Anderson's avatar David Anderson
Browse files

snapuserd: Move Process ops out of Worker.

These are so small they can be inlined into MergeWorker. Sharing these
methods will be difficult after decoupling from dm-user, since
acquisition of buffers will change.

Bug: 288273605
Test: snapuserd_test
Change-Id: I1625d1a6e55bcb2041f73453ca15a01f98263e8a
parent c2d5a19d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ ReadWorker::ReadWorker(const std::string& cow_device, const std::string& backing
// Start the replace operation. This will read the
// internal COW format and if the block is compressed,
// it will be de-compressed.
bool Worker::ProcessReplaceOp(const CowOperation* cow_op) {
bool ReadWorker::ProcessReplaceOp(const CowOperation* cow_op) {
    void* buffer = bufsink_.GetPayloadBuffer(BLOCK_SZ);
    if (!buffer) {
        SNAP_LOG(ERROR) << "ProcessReplaceOp failed to allocate buffer";
@@ -120,7 +120,7 @@ bool ReadWorker::ProcessXorOp(const CowOperation* cow_op) {
    return true;
}

bool Worker::ProcessZeroOp() {
bool ReadWorker::ProcessZeroOp() {
    // Zero out the entire block
    void* buffer = bufsink_.GetPayloadBuffer(BLOCK_SZ);
    if (buffer == nullptr) {
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ class ReadWorker : public Worker {
    bool ProcessXorOp(const CowOperation* cow_op);
    bool ProcessOrderedOp(const CowOperation* cow_op);
    bool ProcessCopyOp(const CowOperation* cow_op);
    bool ProcessReplaceOp(const CowOperation* cow_op);
    bool ProcessZeroOp();

    bool ReadAlignedSector(sector_t sector, size_t sz);
    bool ReadUnalignedSector(sector_t sector, size_t size);
+9 −6
Original line number Diff line number Diff line
@@ -105,17 +105,20 @@ bool MergeWorker::MergeReplaceZeroOps() {

        for (size_t i = 0; i < replace_zero_vec.size(); i++) {
            const CowOperation* cow_op = replace_zero_vec[i];

            void* buffer = bufsink_.GetPayloadBuffer(BLOCK_SZ);
            if (!buffer) {
                SNAP_LOG(ERROR) << "Failed to acquire buffer in merge";
                return false;
            }
            if (cow_op->type == kCowReplaceOp) {
                if (!ProcessReplaceOp(cow_op)) {
                    SNAP_LOG(ERROR) << "Merge - ReplaceOp failed for block: " << cow_op->new_block;
                if (!reader_->ReadData(cow_op, buffer, BLOCK_SZ)) {
                    SNAP_LOG(ERROR) << "Failed to read COW in merge";
                    return false;
                }
            } else {
                CHECK(cow_op->type == kCowZeroOp);
                if (!ProcessZeroOp()) {
                    SNAP_LOG(ERROR) << "Merge ZeroOp failed.";
                    return false;
                }
                memset(buffer, 0, BLOCK_SZ);
            }

            bufsink_.UpdateBufferOffset(BLOCK_SZ);
+0 −6
Original line number Diff line number Diff line
@@ -46,12 +46,6 @@ class Worker {
    bool InitReader();
    virtual void CloseFds() { base_path_merge_fd_ = {}; }

    bool ReadDataFromBaseDevice(sector_t sector, size_t read_size);

    // Processing COW operations
    bool ProcessReplaceOp(const CowOperation* cow_op);
    bool ProcessZeroOp();

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