libsnapshot: sync header metadata

After we write emit a label, we need to update the number of resume
points + sequence data and op_count. Realistically we could just call
Finalize, but maybe synching these specific fields could prevent
unexpected outcomes.

Test: cow_api_test
Change-Id: I1585601a134221689ce8d5675a2a3e32f1e8a0e6
This commit is contained in:
Daniel Zheng 2023-11-20 03:01:03 -08:00
parent 5d30009a7e
commit 763776435d
2 changed files with 39 additions and 1 deletions

View file

@ -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

View file

@ -311,7 +311,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) {