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

Commit 8ec7d3da authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Revert "snapuserd: Make header_response a state variable.""

parents c288e140 e2e8f55b
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ class Worker {

    // Functions interacting with dm-user
    bool ReadDmUserHeader();
    bool WriteDmUserPayload(size_t size);
    bool WriteDmUserPayload(size_t size, bool header_response);
    bool DmuserReadRequest();

    // IO Path
@@ -130,11 +130,11 @@ class Worker {
    bool ReadDataFromBaseDevice(sector_t sector, size_t read_size);
    bool ReadFromSourceDevice(const CowOperation* cow_op);

    bool ReadAlignedSector(sector_t sector, size_t sz);
    bool ReadAlignedSector(sector_t sector, size_t sz, bool header_response);
    bool ReadUnalignedSector(sector_t sector, size_t size);
    int ReadUnalignedSector(sector_t sector, size_t size,
                            std::vector<std::pair<sector_t, const CowOperation*>>::iterator& it);
    bool RespondIOError();
    bool RespondIOError(bool header_response);

    // Processing COW operations
    bool ProcessCowOp(const CowOperation* cow_op);
@@ -176,7 +176,6 @@ class Worker {
    unique_fd backing_store_fd_;
    unique_fd base_path_merge_fd_;
    unique_fd ctrl_fd_;
    bool header_response_ = false;

    std::unique_ptr<ICowOpIter> cowop_iter_;
    size_t ra_block_index_ = 0;
+23 −23
Original line number Diff line number Diff line
@@ -306,10 +306,10 @@ bool Worker::ReadDmUserHeader() {
}

// Send the payload/data back to dm-user misc device.
bool Worker::WriteDmUserPayload(size_t size) {
bool Worker::WriteDmUserPayload(size_t size, bool header_response) {
    size_t payload_size = size;
    void* buf = bufsink_.GetPayloadBufPtr();
    if (header_response_) {
    if (header_response) {
        payload_size += sizeof(struct dm_user_header);
        buf = bufsink_.GetBufPtr();
    }
@@ -319,9 +319,6 @@ bool Worker::WriteDmUserPayload(size_t size) {
        return false;
    }

    // After the first header is sent in response to a request, we cannot
    // send any additional headers.
    header_response_ = false;
    return true;
}

@@ -344,7 +341,7 @@ bool Worker::ReadDataFromBaseDevice(sector_t sector, size_t read_size) {
    return true;
}

bool Worker::ReadAlignedSector(sector_t sector, size_t sz) {
bool Worker::ReadAlignedSector(sector_t sector, size_t sz, bool header_response) {
    struct dm_user_header* header = bufsink_.GetHeaderPtr();
    size_t remaining_size = sz;
    std::vector<std::pair<sector_t, const CowOperation*>>& chunk_vec = snapuserd_->GetChunkVec();
@@ -392,7 +389,7 @@ bool Worker::ReadAlignedSector(sector_t sector, size_t sz) {

            // Just return the header if it is an error
            if (header->type == DM_USER_RESP_ERROR) {
                if (!RespondIOError()) {
                if (!RespondIOError(header_response)) {
                    return false;
                }

@@ -407,12 +404,14 @@ bool Worker::ReadAlignedSector(sector_t sector, size_t sz) {
        }

        if (!io_error) {
            if (!WriteDmUserPayload(total_bytes_read)) {
            if (!WriteDmUserPayload(total_bytes_read, header_response)) {
                return false;
            }

            SNAP_LOG(DEBUG) << "WriteDmUserPayload success total_bytes_read: " << total_bytes_read
                            << " header-response: " << header_response
                            << " remaining_size: " << remaining_size;
            header_response = false;
            remaining_size -= total_bytes_read;
        }
    } while (remaining_size > 0 && !io_error);
@@ -485,6 +484,7 @@ bool Worker::ReadUnalignedSector(sector_t sector, size_t size) {
    // to any COW ops. In that case, we just need to read from the base
    // device.
    bool merge_complete = false;
    bool header_response = true;
    if (it == chunk_vec.end()) {
        if (chunk_vec.size() > 0) {
            // I/O request beyond the last mapped sector
@@ -503,7 +503,7 @@ bool Worker::ReadUnalignedSector(sector_t sector, size_t size) {
            --it;
        }
    } else {
        return ReadAlignedSector(sector, size);
        return ReadAlignedSector(sector, size, header_response);
    }

    loff_t requested_offset = sector << SECTOR_SHIFT;
@@ -537,7 +537,7 @@ bool Worker::ReadUnalignedSector(sector_t sector, size_t size) {
        if (ret < 0) {
            SNAP_LOG(ERROR) << "ReadUnalignedSector failed for sector: " << sector
                            << " size: " << size << " it->sector: " << it->first;
            return RespondIOError();
            return RespondIOError(header_response);
        }

        remaining_size -= ret;
@@ -545,13 +545,14 @@ bool Worker::ReadUnalignedSector(sector_t sector, size_t size) {
        sector += (ret >> SECTOR_SHIFT);

        // Send the data back
        if (!WriteDmUserPayload(total_bytes_read)) {
        if (!WriteDmUserPayload(total_bytes_read, header_response)) {
            return false;
        }

        header_response = false;
        // If we still have pending data to be processed, this will be aligned I/O
        if (remaining_size) {
            return ReadAlignedSector(sector, remaining_size);
            return ReadAlignedSector(sector, remaining_size, header_response);
        }
    } else {
        // This is all about handling I/O request to be routed to base device
@@ -565,21 +566,21 @@ bool Worker::ReadUnalignedSector(sector_t sector, size_t size) {
        CHECK(diff_size <= BLOCK_SZ);
        if (remaining_size < diff_size) {
            if (!ReadDataFromBaseDevice(sector, remaining_size)) {
                return RespondIOError();
                return RespondIOError(header_response);
            }
            total_bytes_read += remaining_size;

            if (!WriteDmUserPayload(total_bytes_read)) {
            if (!WriteDmUserPayload(total_bytes_read, header_response)) {
                return false;
            }
        } else {
            if (!ReadDataFromBaseDevice(sector, diff_size)) {
                return RespondIOError();
                return RespondIOError(header_response);
            }

            total_bytes_read += diff_size;

            if (!WriteDmUserPayload(total_bytes_read)) {
            if (!WriteDmUserPayload(total_bytes_read, header_response)) {
                return false;
            }

@@ -587,16 +588,17 @@ bool Worker::ReadUnalignedSector(sector_t sector, size_t size) {
            size_t num_sectors_read = (diff_size >> SECTOR_SHIFT);
            sector += num_sectors_read;
            CHECK(IsBlockAligned(sector << SECTOR_SHIFT));
            header_response = false;

            // If we still have pending data to be processed, this will be aligned I/O
            return ReadAlignedSector(sector, remaining_size);
            return ReadAlignedSector(sector, remaining_size, header_response);
        }
    }

    return true;
}

bool Worker::RespondIOError() {
bool Worker::RespondIOError(bool header_response) {
    struct dm_user_header* header = bufsink_.GetHeaderPtr();
    header->type = DM_USER_RESP_ERROR;
    // This is an issue with the dm-user interface. There
@@ -608,9 +610,9 @@ bool Worker::RespondIOError() {
    // this back to dm-user.
    //
    // TODO: Fix the interface
    CHECK(header_response_);
    CHECK(header_response);

    if (!WriteDmUserPayload(0)) {
    if (!WriteDmUserPayload(0, header_response)) {
        return false;
    }

@@ -627,7 +629,7 @@ bool Worker::DmuserReadRequest() {
        return ReadUnalignedSector(header->sector, header->len);
    }

    return ReadAlignedSector(header->sector, header->len);
    return ReadAlignedSector(header->sector, header->len, true);
}

bool Worker::ProcessIORequest() {
@@ -643,8 +645,6 @@ bool Worker::ProcessIORequest() {
    SNAP_LOG(DEBUG) << "Daemon: msg->type: " << std::dec << header->type;
    SNAP_LOG(DEBUG) << "Daemon: msg->flags: " << std::dec << header->flags;

    header_response_ = true;

    switch (header->type) {
        case DM_USER_REQ_MAP_READ: {
            if (!DmuserReadRequest()) {