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

Commit 83127b73 authored by Daniel Rosenberg's avatar Daniel Rosenberg
Browse files

libsnapshot: Add Sequence Ops

This adds the ability to write sequence ops. A Sequence op is a list of
block values in the new image. These ops may have dependencies on data
that is overwritten by future ops, so must be merged in a specific
order, regardless of their order in the cow file.

This patch only introduces the operation. The following patches will
actually make use of it.

Bug: 177104308
Test: Builds
Change-Id: I9162b49e5061079416ac9e5661c8b1245298044b
parent 5e2363e1
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ std::ostream& operator<<(std::ostream& os, CowOperation const& op) {
        os << "kCowLabelOp,   ";
    else if (op.type == kCowClusterOp)
        os << "kCowClusterOp  ";
    else if (op.type == kCowSequenceOp)
        os << "kCowSequenceOp ";
    else if (op.type == kCowFooterOp)
        os << "kCowFooterOp  ";
    else
@@ -81,6 +83,7 @@ bool IsMetadataOp(const CowOperation& op) {
        case kCowLabelOp:
        case kCowClusterOp:
        case kCowFooterOp:
        case kCowSequenceOp:
            return true;
        default:
            return false;
+2 −0
Original line number Diff line number Diff line
@@ -201,6 +201,8 @@ bool CowReader::ParseOps(std::optional<uint64_t> label) {
                current_op_num--;
                done = true;
                break;
            } else if (current_op.type == kCowSequenceOp) {
                has_seq_ops_ = true;
            }
        }

+22 −3
Original line number Diff line number Diff line
@@ -76,9 +76,8 @@ bool ICowWriter::AddLabel(uint64_t label) {
    return EmitLabel(label);
}

bool ICowWriter::AddSequenceData(size_t /*num_ops*/, const uint32_t* /*data*/) {
    LOG(ERROR) << "AddSequenceData not yet implemented";
    return false;
bool ICowWriter::AddSequenceData(size_t num_ops, const uint32_t* data) {
    return EmitSequenceData(num_ops, data);
}

bool ICowWriter::ValidateNewBlock(uint64_t new_block) {
@@ -337,6 +336,26 @@ bool CowWriter::EmitLabel(uint64_t label) {
    return WriteOperation(op) && Sync();
}

bool CowWriter::EmitSequenceData(size_t num_ops, const uint32_t* data) {
    CHECK(!merge_in_progress_);
    size_t to_add = 0;
    size_t max_ops = std::numeric_limits<uint16_t>::max() / sizeof(uint32_t);
    while (num_ops > 0) {
        CowOperation op = {};
        op.type = kCowSequenceOp;
        op.source = next_data_pos_;
        to_add = std::min(num_ops, max_ops);
        op.data_length = static_cast<uint16_t>(to_add * sizeof(uint32_t));
        if (!WriteOperation(op, data, op.data_length)) {
            PLOG(ERROR) << "AddSequenceData: write failed";
            return false;
        }
        num_ops -= to_add;
        data += to_add;
    }
    return true;
}

bool CowWriter::EmitCluster() {
    CowOperation op = {};
    op.type = kCowClusterOp;
+1 −0
Original line number Diff line number Diff line
@@ -148,6 +148,7 @@ static constexpr uint8_t kCowReplaceOp = 2;
static constexpr uint8_t kCowZeroOp = 3;
static constexpr uint8_t kCowLabelOp = 4;
static constexpr uint8_t kCowClusterOp = 5;
static constexpr uint8_t kCowSequenceOp = 7;
static constexpr uint8_t kCowFooterOp = -1;

static constexpr uint8_t kCowCompressNone = 0;
+1 −0
Original line number Diff line number Diff line
@@ -165,6 +165,7 @@ class CowReader : public ICowReader {
    std::shared_ptr<std::vector<CowOperation>> ops_;
    uint64_t total_data_ops_;
    uint64_t copy_ops_;
    bool has_seq_ops_;
};

}  // namespace snapshot
Loading