Loading fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h +7 −3 Original line number Diff line number Diff line Loading @@ -33,7 +33,10 @@ namespace android { namespace snapshot { struct CowSizeInfo { uint64_t cow_size; uint64_t op_count_max; }; struct CowOptions { uint32_t block_size = 4096; std::string compression; Loading Loading @@ -92,8 +95,9 @@ class ICowWriter { // to ensure that the correct headers and footers are written. virtual bool Finalize() = 0; // Return number of bytes the cow image occupies on disk. virtual uint64_t GetCowSize() = 0; // Return number of bytes the cow image occupies on disk + the size of sequence && ops buffer // The latter two fields are used in v3 cow format and left as 0 for v2 cow format virtual CowSizeInfo GetCowSizeInfo() const = 0; virtual uint32_t GetBlockSize() const = 0; virtual std::optional<uint32_t> GetMaxBlocks() const = 0; Loading fs_mgr/libsnapshot/include/libsnapshot/mock_cow_writer.h +1 −2 Original line number Diff line number Diff line Loading @@ -24,8 +24,7 @@ class MockCowWriter : public ICowWriter { using FileDescriptor = chromeos_update_engine::FileDescriptor; MOCK_METHOD(bool, Finalize, (), (override)); MOCK_METHOD(uint64_t, GetCowSize, (), (override)); MOCK_METHOD(CowSizeInfo, GetCowSizeInfo, (), (const, override)); MOCK_METHOD(bool, AddCopy, (uint64_t, uint64_t, uint64_t), (override)); MOCK_METHOD(bool, AddRawBlocks, (uint64_t, const void*, size_t), (override)); Loading fs_mgr/libsnapshot/libsnapshot_cow/test_v2.cpp +9 −9 Original line number Diff line number Diff line Loading @@ -601,14 +601,14 @@ TEST_F(CowTest, GetSize) { ASSERT_TRUE(writer.AddCopy(10, 20)); ASSERT_TRUE(writer.AddRawBlocks(50, data.data(), data.size())); ASSERT_TRUE(writer.AddZeroBlocks(51, 2)); auto size_before = writer.GetCowSize(); auto size_before = writer.GetCowSizeInfo().cow_size; ASSERT_TRUE(writer.Finalize()); auto size_after = writer.GetCowSize(); auto size_after = writer.GetCowSizeInfo().cow_size; ASSERT_EQ(size_before, size_after); struct stat buf; ASSERT_GE(fstat(cow_->fd, &buf), 0) << strerror(errno); ASSERT_EQ(buf.st_size, writer.GetCowSize()); ASSERT_EQ(buf.st_size, writer.GetCowSizeInfo().cow_size); } TEST_F(CowTest, AppendLabelSmall) { Loading Loading @@ -637,7 +637,7 @@ TEST_F(CowTest, AppendLabelSmall) { struct stat buf; ASSERT_EQ(fstat(cow_->fd, &buf), 0); ASSERT_EQ(buf.st_size, writer->GetCowSize()); ASSERT_EQ(buf.st_size, writer->GetCowSizeInfo().cow_size); // Read back both operations, and label. CowReader reader; Loading Loading @@ -690,7 +690,7 @@ TEST_F(CowTest, AppendLabelMissing) { ASSERT_TRUE(writer->AddRawBlocks(50, data.data(), data.size())); ASSERT_TRUE(writer->AddLabel(1)); // Drop the tail end of the last op header, corrupting it. ftruncate(cow_->fd, writer->GetCowSize() - sizeof(CowFooter) - 3); ftruncate(cow_->fd, writer->GetCowSizeInfo().cow_size - sizeof(CowFooter) - 3); ASSERT_EQ(lseek(cow_->fd, 0, SEEK_SET), 0); Loading @@ -705,7 +705,7 @@ TEST_F(CowTest, AppendLabelMissing) { struct stat buf; ASSERT_EQ(fstat(cow_->fd, &buf), 0); ASSERT_EQ(buf.st_size, writer->GetCowSize()); ASSERT_EQ(buf.st_size, writer->GetCowSizeInfo().cow_size); // Read back both operations. CowReader reader; Loading Loading @@ -763,7 +763,7 @@ TEST_F(CowTest, AppendExtendedCorrupted) { struct stat buf; ASSERT_EQ(fstat(cow_->fd, &buf), 0); ASSERT_EQ(buf.st_size, writer->GetCowSize()); ASSERT_EQ(buf.st_size, writer->GetCowSizeInfo().cow_size); // Read back all valid operations CowReader reader; Loading Loading @@ -812,7 +812,7 @@ TEST_F(CowTest, AppendbyLabel) { struct stat buf; ASSERT_EQ(fstat(cow_->fd, &buf), 0); ASSERT_EQ(buf.st_size, writer->GetCowSize()); ASSERT_EQ(buf.st_size, writer->GetCowSizeInfo().cow_size); // Read back all ops CowReader reader; Loading Loading @@ -989,7 +989,7 @@ TEST_F(CowTest, ClusterAppendTest) { struct stat buf; ASSERT_EQ(fstat(cow_->fd, &buf), 0); ASSERT_EQ(buf.st_size, writer->GetCowSize()); ASSERT_EQ(buf.st_size, writer->GetCowSizeInfo().cow_size); // Read back both operations, plus cluster op at end CowReader reader; Loading fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -658,14 +658,14 @@ TEST_F(CowTestV3, CowSizeEstimate) { options.compression = "none"; auto estimator = android::snapshot::CreateCowEstimator(3, options); ASSERT_TRUE(estimator->AddZeroBlocks(0, 1024 * 1024)); const auto cow_size = estimator->GetCowSize(); const auto cow_size = estimator->GetCowSizeInfo().cow_size; options.op_count_max = 1024 * 1024; options.max_blocks = 1024 * 1024; CowWriterV3 writer(options, GetCowFd()); ASSERT_TRUE(writer.Initialize()); ASSERT_TRUE(writer.AddZeroBlocks(0, 1024 * 1024)); ASSERT_LE(writer.GetCowSize(), cow_size); ASSERT_LE(writer.GetCowSizeInfo().cow_size, cow_size); } TEST_F(CowTestV3, CopyOpMany) { Loading fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -576,12 +576,14 @@ bool CowWriterV2::Finalize() { return Sync(); } uint64_t CowWriterV2::GetCowSize() { CowSizeInfo CowWriterV2::GetCowSizeInfo() const { CowSizeInfo info; if (current_data_size_ > 0) { return next_data_pos_ + sizeof(footer_); info.cow_size = next_data_pos_ + sizeof(footer_); } else { return next_op_pos_ + sizeof(footer_); info.cow_size = next_op_pos_ + sizeof(footer_); } return info; } bool CowWriterV2::GetDataPos(uint64_t* pos) { Loading Loading
fs_mgr/libsnapshot/include/libsnapshot/cow_writer.h +7 −3 Original line number Diff line number Diff line Loading @@ -33,7 +33,10 @@ namespace android { namespace snapshot { struct CowSizeInfo { uint64_t cow_size; uint64_t op_count_max; }; struct CowOptions { uint32_t block_size = 4096; std::string compression; Loading Loading @@ -92,8 +95,9 @@ class ICowWriter { // to ensure that the correct headers and footers are written. virtual bool Finalize() = 0; // Return number of bytes the cow image occupies on disk. virtual uint64_t GetCowSize() = 0; // Return number of bytes the cow image occupies on disk + the size of sequence && ops buffer // The latter two fields are used in v3 cow format and left as 0 for v2 cow format virtual CowSizeInfo GetCowSizeInfo() const = 0; virtual uint32_t GetBlockSize() const = 0; virtual std::optional<uint32_t> GetMaxBlocks() const = 0; Loading
fs_mgr/libsnapshot/include/libsnapshot/mock_cow_writer.h +1 −2 Original line number Diff line number Diff line Loading @@ -24,8 +24,7 @@ class MockCowWriter : public ICowWriter { using FileDescriptor = chromeos_update_engine::FileDescriptor; MOCK_METHOD(bool, Finalize, (), (override)); MOCK_METHOD(uint64_t, GetCowSize, (), (override)); MOCK_METHOD(CowSizeInfo, GetCowSizeInfo, (), (const, override)); MOCK_METHOD(bool, AddCopy, (uint64_t, uint64_t, uint64_t), (override)); MOCK_METHOD(bool, AddRawBlocks, (uint64_t, const void*, size_t), (override)); Loading
fs_mgr/libsnapshot/libsnapshot_cow/test_v2.cpp +9 −9 Original line number Diff line number Diff line Loading @@ -601,14 +601,14 @@ TEST_F(CowTest, GetSize) { ASSERT_TRUE(writer.AddCopy(10, 20)); ASSERT_TRUE(writer.AddRawBlocks(50, data.data(), data.size())); ASSERT_TRUE(writer.AddZeroBlocks(51, 2)); auto size_before = writer.GetCowSize(); auto size_before = writer.GetCowSizeInfo().cow_size; ASSERT_TRUE(writer.Finalize()); auto size_after = writer.GetCowSize(); auto size_after = writer.GetCowSizeInfo().cow_size; ASSERT_EQ(size_before, size_after); struct stat buf; ASSERT_GE(fstat(cow_->fd, &buf), 0) << strerror(errno); ASSERT_EQ(buf.st_size, writer.GetCowSize()); ASSERT_EQ(buf.st_size, writer.GetCowSizeInfo().cow_size); } TEST_F(CowTest, AppendLabelSmall) { Loading Loading @@ -637,7 +637,7 @@ TEST_F(CowTest, AppendLabelSmall) { struct stat buf; ASSERT_EQ(fstat(cow_->fd, &buf), 0); ASSERT_EQ(buf.st_size, writer->GetCowSize()); ASSERT_EQ(buf.st_size, writer->GetCowSizeInfo().cow_size); // Read back both operations, and label. CowReader reader; Loading Loading @@ -690,7 +690,7 @@ TEST_F(CowTest, AppendLabelMissing) { ASSERT_TRUE(writer->AddRawBlocks(50, data.data(), data.size())); ASSERT_TRUE(writer->AddLabel(1)); // Drop the tail end of the last op header, corrupting it. ftruncate(cow_->fd, writer->GetCowSize() - sizeof(CowFooter) - 3); ftruncate(cow_->fd, writer->GetCowSizeInfo().cow_size - sizeof(CowFooter) - 3); ASSERT_EQ(lseek(cow_->fd, 0, SEEK_SET), 0); Loading @@ -705,7 +705,7 @@ TEST_F(CowTest, AppendLabelMissing) { struct stat buf; ASSERT_EQ(fstat(cow_->fd, &buf), 0); ASSERT_EQ(buf.st_size, writer->GetCowSize()); ASSERT_EQ(buf.st_size, writer->GetCowSizeInfo().cow_size); // Read back both operations. CowReader reader; Loading Loading @@ -763,7 +763,7 @@ TEST_F(CowTest, AppendExtendedCorrupted) { struct stat buf; ASSERT_EQ(fstat(cow_->fd, &buf), 0); ASSERT_EQ(buf.st_size, writer->GetCowSize()); ASSERT_EQ(buf.st_size, writer->GetCowSizeInfo().cow_size); // Read back all valid operations CowReader reader; Loading Loading @@ -812,7 +812,7 @@ TEST_F(CowTest, AppendbyLabel) { struct stat buf; ASSERT_EQ(fstat(cow_->fd, &buf), 0); ASSERT_EQ(buf.st_size, writer->GetCowSize()); ASSERT_EQ(buf.st_size, writer->GetCowSizeInfo().cow_size); // Read back all ops CowReader reader; Loading Loading @@ -989,7 +989,7 @@ TEST_F(CowTest, ClusterAppendTest) { struct stat buf; ASSERT_EQ(fstat(cow_->fd, &buf), 0); ASSERT_EQ(buf.st_size, writer->GetCowSize()); ASSERT_EQ(buf.st_size, writer->GetCowSizeInfo().cow_size); // Read back both operations, plus cluster op at end CowReader reader; Loading
fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -658,14 +658,14 @@ TEST_F(CowTestV3, CowSizeEstimate) { options.compression = "none"; auto estimator = android::snapshot::CreateCowEstimator(3, options); ASSERT_TRUE(estimator->AddZeroBlocks(0, 1024 * 1024)); const auto cow_size = estimator->GetCowSize(); const auto cow_size = estimator->GetCowSizeInfo().cow_size; options.op_count_max = 1024 * 1024; options.max_blocks = 1024 * 1024; CowWriterV3 writer(options, GetCowFd()); ASSERT_TRUE(writer.Initialize()); ASSERT_TRUE(writer.AddZeroBlocks(0, 1024 * 1024)); ASSERT_LE(writer.GetCowSize(), cow_size); ASSERT_LE(writer.GetCowSizeInfo().cow_size, cow_size); } TEST_F(CowTestV3, CopyOpMany) { Loading
fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -576,12 +576,14 @@ bool CowWriterV2::Finalize() { return Sync(); } uint64_t CowWriterV2::GetCowSize() { CowSizeInfo CowWriterV2::GetCowSizeInfo() const { CowSizeInfo info; if (current_data_size_ > 0) { return next_data_pos_ + sizeof(footer_); info.cow_size = next_data_pos_ + sizeof(footer_); } else { return next_op_pos_ + sizeof(footer_); info.cow_size = next_op_pos_ + sizeof(footer_); } return info; } bool CowWriterV2::GetDataPos(uint64_t* pos) { Loading