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

Commit da9db4f3 authored by Akilesh Kailash's avatar Akilesh Kailash Committed by Gerrit Code Review
Browse files

Merge changes Id9263be8,Idd9a60b0 into main

* changes:
  snapuserd: Remove legacy dm-snapshot based snapshot and snapshot-merge
  libsnapshot: Prepare removal of legacy snapshot
parents ba28275e 10233e2f
Loading
Loading
Loading
Loading
+0 −18
Original line number Diff line number Diff line
@@ -321,24 +321,6 @@ cc_test {
    },
}

cc_test {
    name: "vabc_legacy_tests",
    defaults: [
        "libsnapshot_test_defaults",
        "libsnapshot_hal_deps",
    ],
    cppflags: [
        "-DLIBSNAPSHOT_TEST_VABC_LEGACY",
    ],
    test_suites: [
        "device-tests",
    ],
    test_options: {
        // Legacy VABC launched in Android S.
        min_shipping_api_level: 31,
    },
}

cc_test {
    name: "vts_ota_config_test",
    srcs: [
+3 −0
Original line number Diff line number Diff line
@@ -212,6 +212,9 @@ message SnapshotUpdateStatus {

    // io_uring support
    bool io_uring_enabled = 10;

    // legacy dm-snapshot based snapuserd
    bool legacy_snapuserd = 11;
}

// Next: 10
+4 −0
Original line number Diff line number Diff line
@@ -829,6 +829,9 @@ class SnapshotManager final : public ISnapshotManager {
    // Set read-ahead size during OTA
    void SetReadAheadSize(const std::string& entry_block_device, off64_t size_kb);

    // Returns true post OTA reboot if legacy snapuserd is required
    bool IsLegacySnapuserdPostReboot();

    android::dm::IDeviceMapper& dm_;
    std::unique_ptr<IDeviceInfo> device_;
    std::string metadata_dir_;
@@ -839,6 +842,7 @@ class SnapshotManager final : public ISnapshotManager {
    std::unique_ptr<SnapuserdClient> snapuserd_client_;
    std::unique_ptr<LpMetadata> old_partition_metadata_;
    std::optional<bool> is_snapshot_userspace_;
    std::optional<bool> is_legacy_snapuserd_;
};

}  // namespace snapshot
+70 −6
Original line number Diff line number Diff line
@@ -265,7 +265,6 @@ std::string SnapshotManager::ReadUpdateSourceSlotSuffix() {
    auto boot_file = GetSnapshotBootIndicatorPath();
    std::string contents;
    if (!android::base::ReadFileToString(boot_file, &contents)) {
        PLOG(WARNING) << "Cannot read " << boot_file;
        return {};
    }
    return contents;
@@ -2118,6 +2117,53 @@ bool SnapshotManager::UpdateUsesIouring(LockedFile* lock) {
    return update_status.io_uring_enabled();
}

/*
 * Please see b/304829384 for more details.
 *
 * In Android S, we use dm-snapshot for mounting snapshots and snapshot-merge
 * process. If the vendor partition continues to be on Android S, then
 * "snapuserd" binary in first stage ramdisk will be from vendor partition.
 * Thus, we need to maintain backward compatibility.
 *
 * Now, We take a two step approach to maintain the backward compatibility:
 *
 * 1: During OTA installation, we will continue to use "user-space" snapshots
 * for OTA installation as both update-engine and snapuserd binary will be from system partition.
 * However, during installation, we mark "legacy_snapuserd" in
 * SnapshotUpdateStatus file to mark that this is a path to support backward compatibility.
 * Thus, this function will return "false" during OTA installation.
 *
 * 2: Post OTA reboot, there are two key steps:
 *    a: During first stage init, "init" and "snapuserd" could be from vendor
 *    partition. This could be from Android S. Thus, the snapshot mount path
 *    will be based off dm-snapshot.
 *
 *    b: Post selinux transition, "init" and "update-engine" will be "system"
 *    partition. Now, since the snapshots are mounted off dm-snapshot,
 *    update-engine interaction with "snapuserd" should work based off
 *    dm-snapshots.
 *
 *    TL;DR: update-engine will use the "system" snapuserd for installing new
 *    updates (this is safe as there is no "vendor" snapuserd running during
 *    installation). Post reboot, update-engine will use the legacy path when
 *    communicating with "vendor" snapuserd that was started in first-stage
 *    init. Hence, this function checks:
 *         i: Are we in post OTA reboot
 *         ii: Is the Vendor from Android 12
 *         iii: If both (i) and (ii) are true, then use the dm-snapshot based
 *         approach.
 *
 */
bool SnapshotManager::IsLegacySnapuserdPostReboot() {
    if (is_legacy_snapuserd_.has_value() && is_legacy_snapuserd_.value() == true) {
        auto slot = GetCurrentSlot();
        if (slot == Slot::Target) {
            return true;
        }
    }
    return false;
}

bool SnapshotManager::UpdateUsesUserSnapshots() {
    // This and the following function is constantly
    // invoked during snapshot merge. We want to avoid
@@ -2129,7 +2175,12 @@ bool SnapshotManager::UpdateUsesUserSnapshots() {
    // during merge phase. Hence, once we know that
    // the value is read from disk the very first time,
    // it is safe to read successive checks from memory.

    if (is_snapshot_userspace_.has_value()) {
        // Check if legacy snapuserd is running post OTA reboot
        if (IsLegacySnapuserdPostReboot()) {
            return false;
        }
        return is_snapshot_userspace_.value();
    }

@@ -2140,13 +2191,16 @@ bool SnapshotManager::UpdateUsesUserSnapshots() {
}

bool SnapshotManager::UpdateUsesUserSnapshots(LockedFile* lock) {
    // See UpdateUsesUserSnapshots()
    if (is_snapshot_userspace_.has_value()) {
        return is_snapshot_userspace_.value();
    }

    if (!is_snapshot_userspace_.has_value()) {
        SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock);
        is_snapshot_userspace_ = update_status.userspace_snapshots();
        is_legacy_snapuserd_ = update_status.legacy_snapuserd();
    }

    if (IsLegacySnapuserdPostReboot()) {
        return false;
    }

    return is_snapshot_userspace_.value();
}

@@ -3210,6 +3264,8 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
    // Deduce supported features.
    bool userspace_snapshots = CanUseUserspaceSnapshots();
    bool legacy_compression = GetLegacyCompressionEnabledProperty();
    bool is_legacy_snapuserd = IsVendorFromAndroid12();

    if (!vabc_disable_reason.empty()) {
        if (userspace_snapshots) {
            LOG(INFO) << "Userspace snapshots disabled: " << vabc_disable_reason;
@@ -3219,6 +3275,7 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
        }
        userspace_snapshots = false;
        legacy_compression = false;
        is_legacy_snapuserd = false;
    }

    if (legacy_compression || userspace_snapshots) {
@@ -3231,6 +3288,8 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
        }
    }

    LOG(INFO) << "userspace snapshots: " << userspace_snapshots
              << " legacy_snapuserd: " << legacy_compression;
    const bool using_snapuserd = userspace_snapshots || legacy_compression;
    if (!using_snapuserd) {
        LOG(INFO) << "Using legacy Virtual A/B (dm-snapshot)";
@@ -3328,6 +3387,10 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
            status.set_io_uring_enabled(true);
            LOG(INFO) << "io_uring for snapshots enabled";
        }

        if (is_legacy_snapuserd) {
            status.set_legacy_snapuserd(true);
        }
    } else if (legacy_compression) {
        LOG(INFO) << "Virtual A/B using legacy snapuserd";
    } else {
@@ -3335,6 +3398,7 @@ Return SnapshotManager::CreateUpdateSnapshots(const DeltaArchiveManifest& manife
    }

    is_snapshot_userspace_.emplace(userspace_snapshots);
    is_legacy_snapuserd_.emplace(is_legacy_snapuserd);

    if (!device()->IsTestDevice() && using_snapuserd) {
        // Terminate stale daemon if any
+3 −13
Original line number Diff line number Diff line
@@ -56,14 +56,12 @@

#if defined(LIBSNAPSHOT_TEST_VAB_LEGACY)
#define DEFAULT_MODE "vab-legacy"
#elif defined(LIBSNAPSHOT_TEST_VABC_LEGACY)
#define DEFAULT_MODE "vabc-legacy"
#else
#define DEFAULT_MODE ""
#endif

DEFINE_string(force_mode, DEFAULT_MODE,
              "Force testing older modes (vab-legacy, vabc-legacy) ignoring device config.");
              "Force testing older modes (vab-legacy) ignoring device config.");
DEFINE_string(force_iouring_disable, "",
              "Force testing mode (iouring_disabled) - disable io_uring");
DEFINE_string(compression_method, "gz", "Default compression algorithm.");
@@ -140,17 +138,10 @@ class SnapshotTest : public ::testing::Test {
    void SetupProperties() {
        std::unordered_map<std::string, std::string> properties;

        ASSERT_TRUE(android::base::SetProperty("snapuserd.test.dm.snapshots", "0"))
                << "Failed to disable property: virtual_ab.userspace.snapshots.enabled";
        ASSERT_TRUE(android::base::SetProperty("snapuserd.test.io_uring.force_disable", "0"))
                << "Failed to set property: snapuserd.test.io_uring.disabled";

        if (FLAGS_force_mode == "vabc-legacy") {
            ASSERT_TRUE(android::base::SetProperty("snapuserd.test.dm.snapshots", "1"))
                    << "Failed to disable property: virtual_ab.userspace.snapshots.enabled";
            properties["ro.virtual_ab.compression.enabled"] = "true";
            properties["ro.virtual_ab.userspace.snapshots.enabled"] = "false";
        } else if (FLAGS_force_mode == "vab-legacy") {
        if (FLAGS_force_mode == "vab-legacy") {
            properties["ro.virtual_ab.compression.enabled"] = "false";
            properties["ro.virtual_ab.userspace.snapshots.enabled"] = "false";
        }
@@ -2894,7 +2885,7 @@ int main(int argc, char** argv) {

    android::base::SetProperty("ctl.stop", "snapuserd");

    std::unordered_set<std::string> modes = {"", "vab-legacy", "vabc-legacy"};
    std::unordered_set<std::string> modes = {"", "vab-legacy"};
    if (modes.count(FLAGS_force_mode) == 0) {
        std::cerr << "Unexpected force_config argument\n";
        return 1;
@@ -2905,7 +2896,6 @@ int main(int argc, char** argv) {

    int ret = RUN_ALL_TESTS();

    android::base::SetProperty("snapuserd.test.dm.snapshots", "0");
    android::base::SetProperty("snapuserd.test.io_uring.force_disable", "0");

    android::snapshot::KillSnapuserd();
Loading