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

Commit d2d7a1ff authored by Daniel Zheng's avatar Daniel Zheng Committed by Gerrit Code Review
Browse files

Merge changes I56a0d747,I1585601a,I9e44330e into main

* changes:
  libsnapshot: move header op count setup
  libsnapshot: sync header metadata
  libsnapshot: update variable name
parents 7f322bca 209fda35
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -105,8 +105,8 @@ struct ResumePoint {
static constexpr uint8_t kNumResumePoints = 4;

struct CowHeaderV3 : public CowHeader {
    // Location of sequence buffer in COW.
    uint64_t sequence_buffer_offset;
    // Number of sequence data stored (each of which is a 32 byte integer)
    uint64_t sequence_data_count;
    // number of currently written resume points
    uint32_t resume_point_count;
    // Size, in bytes, of the CowResumePoint buffer.
+38 −0
Original line number Diff line number Diff line
@@ -482,5 +482,43 @@ TEST_F(CowTestV3, ResumePointTest) {
    header = reader.header_v3();
    ASSERT_EQ(header.op_count, 15);
}

TEST_F(CowTestV3, BufferMetadataSyncTest) {
    CowOptions options;
    options.op_count_max = 100;
    auto writer = CreateCowWriter(3, options, GetCowFd());
    /*
    Header metadafields
    sequence_data_count = 0;
    resume_point_count = 0;
    resume_point_max = 4;
    */
    ASSERT_TRUE(writer->Finalize());

    CowReader reader;
    ASSERT_TRUE(reader.Parse(cow_->fd));

    auto header = reader.header_v3();
    ASSERT_EQ(header.sequence_data_count, 0);
    ASSERT_EQ(header.resume_point_count, 0);
    ASSERT_EQ(header.resume_point_max, 4);

    writer->AddLabel(0);
    ASSERT_TRUE(reader.Parse(cow_->fd));
    header = reader.header_v3();
    ASSERT_EQ(header.sequence_data_count, 0);
    ASSERT_EQ(header.resume_point_count, 1);
    ASSERT_EQ(header.resume_point_max, 4);

    ASSERT_TRUE(reader.Parse(cow_->fd));
    header = reader.header_v3();

    /*
    Header metadafields
    sequence_data_count = 1;
    resume_point_count = 0;
    resume_point_max = 4;
    */
}
}  // namespace snapshot
}  // namespace android
+4 −3
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ void CowWriterV3::SetupHeaders() {
    // v3 specific fields
    // WIP: not quite sure how some of these are calculated yet, assuming buffer_size is determined
    // during COW size estimation
    header_.sequence_buffer_offset = 0;
    header_.sequence_data_count = 0;
    header_.resume_point_count = 0;
    header_.resume_point_max = kNumResumePoints;
    header_.op_count = 0;
@@ -100,6 +100,7 @@ bool CowWriterV3::ParseOptions() {
        return false;
    }
    header_.compression_algorithm = *algorithm;
    header_.op_count_max = options_.op_count_max;

    if (parts.size() > 1) {
        if (!android::base::ParseUint(parts[1], &compression_.compression_level)) {
@@ -163,7 +164,7 @@ bool CowWriterV3::OpenForWrite() {
            return false;
        }
    }
    header_.op_count_max = options_.op_count_max;

    resume_points_ = std::make_shared<std::vector<ResumePoint>>();

    if (!Sync()) {
@@ -311,7 +312,7 @@ bool CowWriterV3::EmitLabel(uint64_t label) {
        PLOG(ERROR) << "writing resume buffer failed";
        return false;
    }
    return Sync();
    return Finalize();
}

bool CowWriterV3::EmitSequenceData(size_t num_ops, const uint32_t* data) {