forked from aosp-mirror/platform_system_core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libsnapshot: Partially implement OpenSnapshotWriter.
Implement OpenSnapshotWriter for non-compressed Virtual A/B. This is done by adding an OnlineKernelSnapshotWriter class, which forwards all writes to a dm-snapshot block device. This also introduces a new ISnapshotWriter class which extends ICowWriter, and adds features specific to libsnapshot (versus ICowWriter which is intended only for the new COW format). The OpenSnapshotReader call has been moved here since the writer retains all the information needed to create the reader. To test the new call, vts_libsnapshot_test has been modified to use OpenSnapshotWriter. As part of this change, all consumers of libsnapshot must now link to libsnapshot_cow. Bug: 168554689 Test: vts_libsnapshot_test Change-Id: Ieedfadc557833c1e0540922aabc6e95c80266a64
- Loading branch information
1 parent
6560d23
commit 75b982a
Showing
16 changed files
with
385 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (C) 2020 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 <android-base/unique_fd.h> | ||
|
||
#include <libsnapshot/cow_writer.h> | ||
|
||
namespace chromeos_update_engine { | ||
class FileDescriptor; | ||
} // namespace chromeos_update_engine | ||
|
||
namespace android { | ||
namespace snapshot { | ||
|
||
class ISnapshotWriter : public ICowWriter { | ||
public: | ||
using FileDescriptor = chromeos_update_engine::FileDescriptor; | ||
|
||
explicit ISnapshotWriter(const CowOptions& options); | ||
|
||
// Set the source device. This is used for AddCopy() operations, if the | ||
// underlying writer needs the original bytes (for example if backed by | ||
// dm-snapshot or if writing directly to an unsnapshotted region). | ||
void SetSourceDevice(android::base::unique_fd&& source_fd); | ||
|
||
virtual std::unique_ptr<FileDescriptor> OpenReader() = 0; | ||
|
||
protected: | ||
android::base::unique_fd source_fd_; | ||
}; | ||
|
||
// Write directly to a dm-snapshot device. | ||
class OnlineKernelSnapshotWriter : public ISnapshotWriter { | ||
public: | ||
OnlineKernelSnapshotWriter(const CowOptions& options); | ||
|
||
// Set the device used for all writes. | ||
void SetSnapshotDevice(android::base::unique_fd&& snapshot_fd, uint64_t cow_size); | ||
|
||
bool Flush() override; | ||
uint64_t GetCowSize() override { return cow_size_; } | ||
virtual std::unique_ptr<FileDescriptor> OpenReader() override; | ||
|
||
protected: | ||
bool EmitRawBlocks(uint64_t new_block_start, const void* data, size_t size) override; | ||
bool EmitZeroBlocks(uint64_t new_block_start, uint64_t num_blocks) override; | ||
bool EmitCopy(uint64_t new_block, uint64_t old_block) override; | ||
|
||
private: | ||
android::base::unique_fd snapshot_fd_; | ||
uint64_t cow_size_ = 0; | ||
}; | ||
|
||
} // namespace snapshot | ||
} // namespace android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.