Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75b982ad authored by David Anderson's avatar David Anderson
Browse files

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
parent 6560d237
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -147,6 +147,7 @@ cc_binary {
    static_libs: [
        "libgtest_prod",
        "libhealthhalutils",
        "libsnapshot_cow",
        "libsnapshot_nobinder",
        "update_metadata-protos",
    ],
+4 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ filegroup {
        "snapshot_stats.cpp",
        "snapshot_stub.cpp",
        "snapshot_metadata_updater.cpp",
        "snapshot_writer.cpp",
        "partition_cow_creator.cpp",
        "return.cpp",
        "utility.cpp",
@@ -215,6 +216,7 @@ cc_defaults {
        "libgmock",
        "liblp",
        "libsnapshot",
        "libsnapshot_cow",
        "libsnapshot_test_helpers",
        "libsparse",
    ],
@@ -249,6 +251,7 @@ cc_binary {
    static_libs: [
        "libfstab",
        "libsnapshot",
        "libsnapshot_cow",
        "update_metadata-protos",
    ],
    shared_libs: [
@@ -312,6 +315,7 @@ cc_defaults {
        "libgmock", // from libsnapshot_test_helpers
        "liblog",
        "liblp",
        "libsnapshot_cow",
        "libsnapshot_test_helpers",
        "libprotobuf-mutator",
    ],
+6 −3
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ namespace snapshot {

static_assert(sizeof(off_t) == sizeof(uint64_t));

using android::base::borrowed_fd;
using android::base::unique_fd;

bool ICowWriter::AddCopy(uint64_t new_block, uint64_t old_block) {
    if (!ValidateNewBlock(new_block)) {
        return false;
@@ -98,12 +101,12 @@ bool CowWriter::ParseOptions() {
    return true;
}

bool CowWriter::Initialize(android::base::unique_fd&& fd, OpenMode mode) {
bool CowWriter::Initialize(unique_fd&& fd, OpenMode mode) {
    owned_fd_ = std::move(fd);
    return Initialize(android::base::borrowed_fd{owned_fd_}, mode);
    return Initialize(borrowed_fd{owned_fd_}, mode);
}

bool CowWriter::Initialize(android::base::borrowed_fd fd, OpenMode mode) {
bool CowWriter::Initialize(borrowed_fd fd, OpenMode mode) {
    fd_ = fd;

    if (!ParseOptions()) {
+3 −0
Original line number Diff line number Diff line
@@ -58,6 +58,9 @@ class ICowWriter {
    // Return number of bytes the cow image occupies on disk.
    virtual uint64_t GetCowSize() = 0;

    // Returns true if AddCopy() operations are supported.
    virtual bool SupportsCopyOperation() const { return true; }

    const CowOptions& options() { return options_; }

  protected:
+1 −3
Original line number Diff line number Diff line
@@ -38,9 +38,7 @@ class MockSnapshotManager : public ISnapshotManager {
                (const android::fs_mgr::CreateLogicalPartitionParams& params,
                 std::string* snapshot_path),
                (override));
    MOCK_METHOD(std::unique_ptr<ICowWriter>, OpenSnapshotWriter,
                (const android::fs_mgr::CreateLogicalPartitionParams& params), (override));
    MOCK_METHOD(std::unique_ptr<FileDescriptor>, OpenSnapshotReader,
    MOCK_METHOD(std::unique_ptr<ISnapshotWriter>, OpenSnapshotWriter,
                (const android::fs_mgr::CreateLogicalPartitionParams& params), (override));
    MOCK_METHOD(bool, UnmapUpdateSnapshot, (const std::string& target_partition_name), (override));
    MOCK_METHOD(bool, NeedSnapshotsInFirstStageMount, (), (override));
Loading