Merge "Add v3 writer" into main am: 3062a64f06
am: 82e5bde2a1
am: e5573d47ab
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2750004 Change-Id: Ic2894b012cda6a6123aac1e1deeb8e2457f0006b Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
3ed84cdfee
4 changed files with 215 additions and 0 deletions
|
@ -201,6 +201,7 @@ cc_library_static {
|
|||
"libsnapshot_cow/snapshot_reader.cpp",
|
||||
"libsnapshot_cow/writer_base.cpp",
|
||||
"libsnapshot_cow/writer_v2.cpp",
|
||||
"libsnapshot_cow/writer_v3.cpp",
|
||||
],
|
||||
export_include_dirs: ["include"],
|
||||
host_supported: true,
|
||||
|
@ -392,6 +393,7 @@ cc_test {
|
|||
srcs: [
|
||||
"libsnapshot_cow/snapshot_reader_test.cpp",
|
||||
"libsnapshot_cow/test_v2.cpp",
|
||||
"libsnapshot_cow/test_v3.cpp",
|
||||
],
|
||||
cflags: [
|
||||
"-D_FILE_OFFSET_BITS=64",
|
||||
|
|
53
fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp
Normal file
53
fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright (C) 2023 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <libsnapshot/cow_reader.h>
|
||||
#include <libsnapshot/cow_writer.h>
|
||||
#include "cow_decompress.h"
|
||||
#include "libsnapshot/cow_format.h"
|
||||
#include "writer_v3.h"
|
||||
using android::base::unique_fd;
|
||||
using testing::AssertionFailure;
|
||||
using testing::AssertionResult;
|
||||
using testing::AssertionSuccess;
|
||||
|
||||
namespace android {
|
||||
namespace snapshot {
|
||||
|
||||
class CowOperationV3Test : public ::testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() override {
|
||||
cow_ = std::make_unique<TemporaryFile>();
|
||||
ASSERT_GE(cow_->fd, 0) << strerror(errno);
|
||||
}
|
||||
|
||||
virtual void TearDown() override { cow_ = nullptr; }
|
||||
|
||||
unique_fd GetCowFd() { return unique_fd{dup(cow_->fd)}; }
|
||||
|
||||
std::unique_ptr<TemporaryFile> cow_;
|
||||
};
|
||||
|
||||
} // namespace snapshot
|
||||
} // namespace android
|
117
fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp
Normal file
117
fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.cpp
Normal file
|
@ -0,0 +1,117 @@
|
|||
//
|
||||
// Copyright (C) 2020 The Android Open Source_info Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include "writer_v3.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/parseint.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <brotli/encode.h>
|
||||
#include <libsnapshot/cow_format.h>
|
||||
#include <libsnapshot/cow_reader.h>
|
||||
#include <libsnapshot/cow_writer.h>
|
||||
#include <lz4.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <linux/fs.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// The info messages here are spammy, but as useful for update_engine. Disable
|
||||
// them when running on the host.
|
||||
#ifdef __ANDROID__
|
||||
#define LOG_INFO LOG(INFO)
|
||||
#else
|
||||
#define LOG_INFO LOG(VERBOSE)
|
||||
#endif
|
||||
|
||||
namespace android {
|
||||
namespace snapshot {
|
||||
|
||||
static_assert(sizeof(off_t) == sizeof(uint64_t));
|
||||
|
||||
using android::base::unique_fd;
|
||||
|
||||
CowWriterV3::CowWriterV3(const CowOptions& options, unique_fd&& fd)
|
||||
: CowWriterBase(options, std::move(fd)) {}
|
||||
|
||||
CowWriterV3::~CowWriterV3() {}
|
||||
|
||||
bool CowWriterV3::Initialize(std::optional<uint64_t> label) {
|
||||
LOG(ERROR) << __LINE__ << " " << __FILE__ << " <- function here should never be called";
|
||||
if (label) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CowWriterV3::EmitCopy(uint64_t new_block, uint64_t old_block, uint64_t num_blocks) {
|
||||
LOG(ERROR) << __LINE__ << " " << __FILE__ << " <- function here should never be called";
|
||||
if (new_block || old_block || num_blocks) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CowWriterV3::EmitRawBlocks(uint64_t new_block_start, const void* data, size_t size) {
|
||||
LOG(ERROR) << __LINE__ << " " << __FILE__ << " <- function here should never be called";
|
||||
|
||||
if (new_block_start || data || size) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CowWriterV3::EmitXorBlocks(uint32_t new_block_start, const void* data, size_t size,
|
||||
uint32_t old_block, uint16_t offset) {
|
||||
LOG(ERROR) << __LINE__ << " " << __FILE__ << " <- function here should never be called";
|
||||
if (new_block_start || old_block || offset || data || size) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CowWriterV3::EmitZeroBlocks(uint64_t new_block_start, uint64_t num_blocks) {
|
||||
LOG(ERROR) << __LINE__ << " " << __FILE__ << " <- function here should never be called";
|
||||
if (new_block_start && num_blocks) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CowWriterV3::EmitLabel(uint64_t label) {
|
||||
LOG(ERROR) << __LINE__ << " " << __FILE__ << " <- function here should never be called";
|
||||
if (label) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CowWriterV3::EmitSequenceData(size_t num_ops, const uint32_t* data) {
|
||||
LOG(ERROR) << __LINE__ << " " << __FILE__ << " <- function here should never be called";
|
||||
if (num_ops && data) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CowWriterV3::Finalize() {
|
||||
LOG(ERROR) << __LINE__ << " " << __FILE__ << " <- function here should never be called";
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t CowWriterV3::GetCowSize() {
|
||||
LOG(ERROR) << __LINE__ << " " << __FILE__
|
||||
<< " <- Get Cow Size function here should never be called";
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace snapshot
|
||||
} // namespace android
|
43
fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.h
Normal file
43
fs_mgr/libsnapshot/libsnapshot_cow/writer_v3.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2023 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <future>
|
||||
#include "writer_base.h"
|
||||
|
||||
namespace android {
|
||||
namespace snapshot {
|
||||
|
||||
class CowWriterV3 : public CowWriterBase {
|
||||
public:
|
||||
explicit CowWriterV3(const CowOptions& options, android::base::unique_fd&& fd);
|
||||
~CowWriterV3() override;
|
||||
|
||||
bool Initialize(std::optional<uint64_t> label = {}) override;
|
||||
bool Finalize() override;
|
||||
uint64_t GetCowSize() override;
|
||||
|
||||
protected:
|
||||
virtual bool EmitCopy(uint64_t new_block, uint64_t old_block, uint64_t num_blocks = 1) override;
|
||||
virtual bool EmitRawBlocks(uint64_t new_block_start, const void* data, size_t size) override;
|
||||
virtual bool EmitXorBlocks(uint32_t new_block_start, const void* data, size_t size,
|
||||
uint32_t old_block, uint16_t offset) override;
|
||||
virtual bool EmitZeroBlocks(uint64_t new_block_start, uint64_t num_blocks) override;
|
||||
virtual bool EmitLabel(uint64_t label) override;
|
||||
virtual bool EmitSequenceData(size_t num_ops, const uint32_t* data) override;
|
||||
};
|
||||
|
||||
} // namespace snapshot
|
||||
} // namespace android
|
Loading…
Reference in a new issue