From ed1a7d5fafd98049777c2c26349984ae31563a86 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Tue, 12 Sep 2023 14:37:44 -0700 Subject: [PATCH 1/2] Add v3 Cow Header Adding Version 3 of CowHeader. This will inherit from original CowHeader and add a compression field. We are no longer supporting different compressions per operation so having this one field is enough. Test: cow_api_test Change-Id: If88dceda139807cc5e647b706ddeb2b3e83c024f --- fs_mgr/libsnapshot/include/libsnapshot/cow_format.h | 12 ++++++++++++ fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h b/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h index bfa8f6bea..b271dad6c 100644 --- a/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h +++ b/fs_mgr/libsnapshot/include/libsnapshot/cow_format.h @@ -91,6 +91,18 @@ struct CowHeader { // Scratch space used during merge uint32_t buffer_size; + +} __attribute__((packed)); + +struct CowHeaderV3 : public CowHeader { + // Location of sequence buffer in COW. + uint64_t sequence_buffer_offset; + // Size, in bytes, of the CowResumePoint buffer. + uint32_t resume_buffer_size; + // Size, in bytes, of the CowOperation buffer. + uint32_t op_buffer_size; + // Compression Algorithm + uint32_t compression_algorithm; } __attribute__((packed)); // This structure is the same size of a normal Operation, but is repurposed for the footer. diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp index e51dbde63..a6f449faa 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp +++ b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp @@ -243,7 +243,7 @@ bool CowWriterV2::OpenForWrite() { // Headers are not complete, but this ensures the file is at the right // position. - if (!android::base::WriteFully(fd_, &header_, sizeof(header_))) { + if (!android::base::WriteFully(fd_, &header_, sizeof(CowHeader))) { PLOG(ERROR) << "write failed"; return false; } @@ -262,7 +262,7 @@ bool CowWriterV2::OpenForWrite() { return false; } - if (lseek(fd_.get(), sizeof(header_) + header_.buffer_size, SEEK_SET) < 0) { + if (lseek(fd_.get(), sizeof(CowHeader) + header_.buffer_size, SEEK_SET) < 0) { PLOG(ERROR) << "lseek failed"; return false; } From bb45742ba141ad149c3960854ff32074390a9f5a Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Tue, 10 Oct 2023 13:19:56 -0700 Subject: [PATCH 2/2] Move Cow Header child writer v2 writer and v3 writer will write different versions of the header. It's better to have each writer hold it's own header. Test: th Change-Id: Ibe310d58b830950ad556aabcd0c1009483fc8d86 --- fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h | 1 - fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h b/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h index cdf622268..709b248e6 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h +++ b/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h @@ -63,7 +63,6 @@ class CowWriterBase : public ICowWriter { bool ValidateNewBlock(uint64_t new_block); CowOptions options_; - CowHeader header_{}; android::base::unique_fd fd_; bool is_dev_null_ = false; diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h index ce97b0182..24170ebbd 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h +++ b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h @@ -63,6 +63,7 @@ class CowWriterV2 : public CowWriterBase { private: CowFooter footer_{}; + CowHeader header_{}; CowCompression compression_; // in the case that we are using one thread for compression, we can store and re-use the same // compressor