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

Commit aca0beaf authored by David Anderson's avatar David Anderson
Browse files

libsnapshot: Partially implement OpenSnapshotWriter.

This is a re-landing of the original CL, with a few changes:
 - The correct device is now returned in MapUpdateSnapshot.
 - The old API is used for tests, and the new API is only tested when
   used on a VABC device.
 - A sync() call has been added to ensure that writes to the base and
   target snapshot devices have been fully flushed. This makes
   IsPartitionUnchanged detect the MapUpdateSnapshot bug.

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
Test: full OTA with update_device.py
Test: incremental OTA with update_device.py
Change-Id: I90364a58902a4406a37cb14a816642c57a72bec2
parent f536731e
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",
@@ -247,6 +248,7 @@ cc_defaults {
        "libgmock",
        "liblp",
        "libsnapshot",
        "libsnapshot_cow",
        "libsnapshot_test_helpers",
        "libsparse",
    ],
@@ -275,6 +277,7 @@ cc_binary {
    static_libs: [
        "libfstab",
        "libsnapshot",
        "libsnapshot_cow",
        "update_metadata-protos",
    ],
    shared_libs: [
@@ -338,6 +341,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