From f9f833066d4aac40648f0b528d56967317ff77a0 Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Mon, 9 Oct 2023 13:02:21 -0700 Subject: [PATCH] Move Sync to base class This function will be called in header write for both v3 and v2 writer. Seems okay to move to base class as theres no unique functionality to the v2 writer. Test: cow_api_test Change-Id: I70c1b08ce67127c9dcbd0f54b574d2cd5ad1d0b5 --- fs_mgr/libsnapshot/libsnapshot_cow/writer_base.cpp | 11 +++++++++++ fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h | 1 + fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp | 11 ----------- fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h | 1 - 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.cpp index ff34c597b34b..2ffc37b7d0aa 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.cpp +++ b/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.cpp @@ -191,5 +191,16 @@ std::unique_ptr CowWriterBase::OpenFileD block_dev_size); } +bool CowWriterBase::Sync() { + if (is_dev_null_) { + return true; + } + if (fsync(fd_.get()) < 0) { + PLOG(ERROR) << "fsync failed"; + return false; + } + return true; +} + } // namespace snapshot } // namespace android diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h b/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h index c8b477275822..cdf62226866f 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h +++ b/fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h @@ -34,6 +34,7 @@ class CowWriterBase : public ICowWriter { // If the given label is not found, Initialize will fail. virtual bool Initialize(std::optional label = {}) = 0; + bool Sync(); bool AddCopy(uint64_t new_block, uint64_t old_block, uint64_t num_blocks = 1) override; bool AddRawBlocks(uint64_t new_block_start, const void* data, size_t size) override; bool AddXorBlocks(uint32_t new_block_start, const void* data, size_t size, uint32_t old_block, diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp index a52297ffc0ce..e51dbde6340c 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp +++ b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp @@ -704,17 +704,6 @@ bool CowWriterV2::WriteRawData(const void* data, const size_t size) { return true; } -bool CowWriterV2::Sync() { - if (is_dev_null_) { - return true; - } - if (fsync(fd_.get()) < 0) { - PLOG(ERROR) << "fsync failed"; - return false; - } - return true; -} - bool CowWriterV2::Truncate(off_t length) { if (is_dev_null_ || is_block_device_) { return true; diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h index c72a9b47c5d7..ce97b0182fd0 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h +++ b/fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h @@ -58,7 +58,6 @@ class CowWriterV2 : public CowWriterBase { bool FlushCluster(); bool CompressBlocks(size_t num_blocks, const void* data); - bool Sync(); bool Truncate(off_t length); bool EnsureSpaceAvailable(const uint64_t bytes_needed) const;