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

Commit f3b98f4c authored by Akilesh Kailash's avatar Akilesh Kailash Committed by Automerger Merge Worker
Browse files

Merge changes from topic "vabc-user-snapshots" am: 04eecd44

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1885107

Change-Id: I4a2dc23e7895ae924ad0559bd36411c771cc8a53
parents 6565f9fc 04eecd44
Loading
Loading
Loading
Loading
+51 −0
Original line number Original line Diff line number Diff line
@@ -258,11 +258,62 @@ cc_defaults {
    require_root: true,
    require_root: true,
}
}


cc_defaults {
    name: "userspace_snapshot_test_defaults",
    defaults: ["libsnapshot_defaults"],
    srcs: [
        "partition_cow_creator_test.cpp",
        "snapshot_metadata_updater_test.cpp",
        "snapshot_reader_test.cpp",
        "userspace_snapshot_test.cpp",
        "snapshot_writer_test.cpp",
    ],
    shared_libs: [
        "libbinder",
        "libcrypto",
        "libhidlbase",
        "libprotobuf-cpp-lite",
        "libutils",
        "libz",
    ],
    static_libs: [
        "android.hardware.boot@1.0",
        "android.hardware.boot@1.1",
        "libbrotli",
        "libc++fs",
        "libfs_mgr_binder",
        "libgsi",
        "libgmock",
        "liblp",
        "libsnapshot",
        "libsnapshot_cow",
        "libsnapshot_test_helpers",
        "libsparse",
    ],
    header_libs: [
        "libstorage_literals_headers",
    ],
    test_suites: [
        "vts",
        "device-tests"
    ],
    test_options: {
        min_shipping_api_level: 29,
    },
    auto_gen_config: true,
    require_root: true,
}

cc_test {
cc_test {
    name: "vts_libsnapshot_test",
    name: "vts_libsnapshot_test",
    defaults: ["libsnapshot_test_defaults"],
    defaults: ["libsnapshot_test_defaults"],
}
}


cc_test {
    name: "vts_userspace_snapshot_test",
    defaults: ["userspace_snapshot_test_defaults"],
}

cc_binary {
cc_binary {
    name: "snapshotctl",
    name: "snapshotctl",
    srcs: [
    srcs: [
+3 −0
Original line number Original line Diff line number Diff line
@@ -194,6 +194,9 @@ message SnapshotUpdateStatus {


    // Source build fingerprint.
    // Source build fingerprint.
    string source_build_fingerprint = 8;
    string source_build_fingerprint = 8;

    // user-space snapshots
    bool userspace_snapshots = 9;
}
}


// Next: 10
// Next: 10
+1 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ class MockSnapshotManager : public ISnapshotManager {
                (override));
                (override));
    MOCK_METHOD(UpdateState, GetUpdateState, (double* progress), (override));
    MOCK_METHOD(UpdateState, GetUpdateState, (double* progress), (override));
    MOCK_METHOD(bool, UpdateUsesCompression, (), (override));
    MOCK_METHOD(bool, UpdateUsesCompression, (), (override));
    MOCK_METHOD(bool, UpdateUsesUserSnapshots, (), (override));
    MOCK_METHOD(Return, CreateUpdateSnapshots,
    MOCK_METHOD(Return, CreateUpdateSnapshots,
                (const chromeos_update_engine::DeltaArchiveManifest& manifest), (override));
                (const chromeos_update_engine::DeltaArchiveManifest& manifest), (override));
    MOCK_METHOD(bool, MapUpdateSnapshot,
    MOCK_METHOD(bool, MapUpdateSnapshot,
+22 −4
Original line number Original line Diff line number Diff line
@@ -193,6 +193,9 @@ class ISnapshotManager {
    // UpdateState is None, or no snapshots have been created.
    // UpdateState is None, or no snapshots have been created.
    virtual bool UpdateUsesCompression() = 0;
    virtual bool UpdateUsesCompression() = 0;


    // Returns true if userspace snapshots is enabled for the current update.
    virtual bool UpdateUsesUserSnapshots() = 0;

    // Create necessary COW device / files for OTA clients. New logical partitions will be added to
    // Create necessary COW device / files for OTA clients. New logical partitions will be added to
    // group "cow" in target_metadata. Regions of partitions of current_metadata will be
    // group "cow" in target_metadata. Regions of partitions of current_metadata will be
    // "write-protected" and snapshotted.
    // "write-protected" and snapshotted.
@@ -352,6 +355,7 @@ class SnapshotManager final : public ISnapshotManager {
                                   const std::function<bool()>& before_cancel = {}) override;
                                   const std::function<bool()>& before_cancel = {}) override;
    UpdateState GetUpdateState(double* progress = nullptr) override;
    UpdateState GetUpdateState(double* progress = nullptr) override;
    bool UpdateUsesCompression() override;
    bool UpdateUsesCompression() override;
    bool UpdateUsesUserSnapshots() override;
    Return CreateUpdateSnapshots(const DeltaArchiveManifest& manifest) override;
    Return CreateUpdateSnapshots(const DeltaArchiveManifest& manifest) override;
    bool MapUpdateSnapshot(const CreateLogicalPartitionParams& params,
    bool MapUpdateSnapshot(const CreateLogicalPartitionParams& params,
                           std::string* snapshot_path) override;
                           std::string* snapshot_path) override;
@@ -387,6 +391,11 @@ class SnapshotManager final : public ISnapshotManager {
    // first-stage to decide whether to launch snapuserd.
    // first-stage to decide whether to launch snapuserd.
    bool IsSnapuserdRequired();
    bool IsSnapuserdRequired();


    enum class SnapshotDriver {
        DM_SNAPSHOT,
        DM_USER,
    };

  private:
  private:
    FRIEND_TEST(SnapshotTest, CleanFirstStageMount);
    FRIEND_TEST(SnapshotTest, CleanFirstStageMount);
    FRIEND_TEST(SnapshotTest, CreateSnapshot);
    FRIEND_TEST(SnapshotTest, CreateSnapshot);
@@ -456,6 +465,8 @@ class SnapshotManager final : public ISnapshotManager {
    };
    };
    static std::unique_ptr<LockedFile> OpenFile(const std::string& file, int lock_flags);
    static std::unique_ptr<LockedFile> OpenFile(const std::string& file, int lock_flags);


    SnapshotDriver GetSnapshotDriver(LockedFile* lock);

    // Create a new snapshot record. This creates the backing COW store and
    // Create a new snapshot record. This creates the backing COW store and
    // persists information needed to map the device. The device can be mapped
    // persists information needed to map the device. The device can be mapped
    // with MapSnapshot().
    // with MapSnapshot().
@@ -491,8 +502,8 @@ class SnapshotManager final : public ISnapshotManager {


    // Create a dm-user device for a given snapshot.
    // Create a dm-user device for a given snapshot.
    bool MapDmUserCow(LockedFile* lock, const std::string& name, const std::string& cow_file,
    bool MapDmUserCow(LockedFile* lock, const std::string& name, const std::string& cow_file,
                      const std::string& base_device, const std::chrono::milliseconds& timeout_ms,
                      const std::string& base_device, const std::string& base_path_merge,
                      std::string* path);
                      const std::chrono::milliseconds& timeout_ms, std::string* path);


    // Map the source device used for dm-user.
    // Map the source device used for dm-user.
    bool MapSourceDevice(LockedFile* lock, const std::string& name,
    bool MapSourceDevice(LockedFile* lock, const std::string& name,
@@ -591,7 +602,8 @@ class SnapshotManager final : public ISnapshotManager {
    // Internal callback for when merging is complete.
    // Internal callback for when merging is complete.
    bool OnSnapshotMergeComplete(LockedFile* lock, const std::string& name,
    bool OnSnapshotMergeComplete(LockedFile* lock, const std::string& name,
                                 const SnapshotStatus& status);
                                 const SnapshotStatus& status);
    bool CollapseSnapshotDevice(const std::string& name, const SnapshotStatus& status);
    bool CollapseSnapshotDevice(LockedFile* lock, const std::string& name,
                                const SnapshotStatus& status);


    struct MergeResult {
    struct MergeResult {
        explicit MergeResult(UpdateState state,
        explicit MergeResult(UpdateState state,
@@ -689,7 +701,10 @@ class SnapshotManager final : public ISnapshotManager {
    bool UnmapPartitionWithSnapshot(LockedFile* lock, const std::string& target_partition_name);
    bool UnmapPartitionWithSnapshot(LockedFile* lock, const std::string& target_partition_name);


    // Unmap a dm-user device through snapuserd.
    // Unmap a dm-user device through snapuserd.
    bool UnmapDmUserDevice(const std::string& snapshot_name);
    bool UnmapDmUserDevice(const std::string& dm_user_name);

    // Unmap a dm-user device for user space snapshots
    bool UnmapUserspaceSnapshotDevice(LockedFile* lock, const std::string& snapshot_name);


    // If there isn't a previous update, return true. |needs_merge| is set to false.
    // If there isn't a previous update, return true. |needs_merge| is set to false.
    // If there is a previous update but the device has not boot into it, tries to cancel the
    // If there is a previous update but the device has not boot into it, tries to cancel the
@@ -778,6 +793,8 @@ class SnapshotManager final : public ISnapshotManager {


    // Helper of UpdateUsesCompression
    // Helper of UpdateUsesCompression
    bool UpdateUsesCompression(LockedFile* lock);
    bool UpdateUsesCompression(LockedFile* lock);
    // Helper of UpdateUsesUsersnapshots
    bool UpdateUsesUserSnapshots(LockedFile* lock);


    // Wrapper around libdm, with diagnostics.
    // Wrapper around libdm, with diagnostics.
    bool DeleteDeviceIfExists(const std::string& name,
    bool DeleteDeviceIfExists(const std::string& name,
@@ -792,6 +809,7 @@ class SnapshotManager final : public ISnapshotManager {
    std::function<bool(const std::string&)> uevent_regen_callback_;
    std::function<bool(const std::string&)> uevent_regen_callback_;
    std::unique_ptr<SnapuserdClient> snapuserd_client_;
    std::unique_ptr<SnapuserdClient> snapuserd_client_;
    std::unique_ptr<LpMetadata> old_partition_metadata_;
    std::unique_ptr<LpMetadata> old_partition_metadata_;
    std::optional<bool> is_snapshot_userspace_;
};
};


}  // namespace snapshot
}  // namespace snapshot
+1 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ class SnapshotManagerStub : public ISnapshotManager {
                                   const std::function<bool()>& before_cancel = {}) override;
                                   const std::function<bool()>& before_cancel = {}) override;
    UpdateState GetUpdateState(double* progress = nullptr) override;
    UpdateState GetUpdateState(double* progress = nullptr) override;
    bool UpdateUsesCompression() override;
    bool UpdateUsesCompression() override;
    bool UpdateUsesUserSnapshots() override;
    Return CreateUpdateSnapshots(
    Return CreateUpdateSnapshots(
            const chromeos_update_engine::DeltaArchiveManifest& manifest) override;
            const chromeos_update_engine::DeltaArchiveManifest& manifest) override;
    bool MapUpdateSnapshot(const android::fs_mgr::CreateLogicalPartitionParams& params,
    bool MapUpdateSnapshot(const android::fs_mgr::CreateLogicalPartitionParams& params,
Loading