Merge changes I56a0d747,I1585601a,I9e44330e into main
* changes:
libsnapshot: move header op count setup
libsnapshot: sync header metadata
libsnapshot: update variable name
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h b/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h
index 75467cb..9e6cfea 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h
@@ -105,8 +105,8 @@
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.
diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp
index c41e07c..9f857ee 100644
--- a/fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp
+++ b/fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp
@@ -482,5 +482,43 @@
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
diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp
index 6883c5e..81ccea9 100644
--- a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp
+++ b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp
@@ -77,7 +77,7 @@
// 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 @@
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 @@
return false;
}
}
- header_.op_count_max = options_.op_count_max;
+
resume_points_ = std::make_shared<std::vector<ResumePoint>>();
if (!Sync()) {
@@ -311,7 +312,7 @@
PLOG(ERROR) << "writing resume buffer failed";
return false;
}
- return Sync();
+ return Finalize();
}
bool CowWriterV3::EmitSequenceData(size_t num_ops, const uint32_t* data) {