Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Move Sync to base class
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zbw182 committed Oct 10, 2023
1 parent f7f3b62 commit f9f8330
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
11 changes: 11 additions & 0 deletions fs_mgr/libsnapshot/libsnapshot_cow/writer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,16 @@ std::unique_ptr<chromeos_update_engine::FileDescriptor> 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
1 change: 1 addition & 0 deletions fs_mgr/libsnapshot/libsnapshot_cow/writer_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CowWriterBase : public ICowWriter {
// If the given label is not found, Initialize will fail.
virtual bool Initialize(std::optional<uint64_t> 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,
Expand Down
11 changes: 0 additions & 11 deletions fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion fs_mgr/libsnapshot/libsnapshot_cow/writer_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f9f8330

Please sign in to comment.