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

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

Merge changes Ide9e3315,I6d1e3689 into main

* changes:
  libsnapshot: Pause snapshot merge during shutdown
  libsnapuserd: Pause/Resume Snapshot merge
parents 71ee8d0b d48e75a1
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -418,9 +418,16 @@ class SnapshotManager final : public ISnapshotManager {
    // first-stage to decide whether to launch snapuserd.
    bool IsSnapuserdRequired();

    // This is primarily used to device reboot. If OTA update is in progress,
    // init will avoid killing processes
    bool IsUserspaceSnapshotUpdateInProgress();
    // This is primarily invoked during device reboot after an OTA update.
    //
    // a: Check if the partitions are mounted off snapshots.
    //
    // b: Store all dynamic partitions which are mounted off snapshots. This
    // is used to unmount the partition.
    bool IsUserspaceSnapshotUpdateInProgress(std::vector<std::string>& dynamic_partitions);

    // Pause the snapshot merge.
    bool PauseSnapshotMerge();

    enum class SnapshotDriver {
        DM_SNAPSHOT,
+18 −4
Original line number Diff line number Diff line
@@ -4687,7 +4687,17 @@ std::string SnapshotManager::ReadSourceBuildFingerprint() {
    return status.source_build_fingerprint();
}

bool SnapshotManager::IsUserspaceSnapshotUpdateInProgress() {
bool SnapshotManager::PauseSnapshotMerge() {
    auto snapuserd_client = SnapuserdClient::TryConnect(kSnapuserdSocket, 5s);
    if (snapuserd_client) {
        // Pause the snapshot-merge
        return snapuserd_client->PauseMerge();
    }
    return false;
}

bool SnapshotManager::IsUserspaceSnapshotUpdateInProgress(
        std::vector<std::string>& dynamic_partitions) {
    // We cannot grab /metadata/ota lock here as this
    // is in reboot path. See b/308900853
    //
@@ -4701,18 +4711,22 @@ bool SnapshotManager::IsUserspaceSnapshotUpdateInProgress() {
        LOG(ERROR) << "No dm-enabled block device is found.";
        return false;
    }

    bool is_ota_in_progress = false;
    for (auto& partition : dm_block_devices) {
        std::string partition_name = partition.first + current_suffix;
        DeviceMapper::TargetInfo snap_target;
        if (!GetSingleTarget(partition_name, TableQuery::Status, &snap_target)) {
            return false;
            continue;
        }
        auto type = DeviceMapper::GetTargetType(snap_target.spec);
        // Partition is mounted off snapshots
        if (type == "user") {
            return true;
            dynamic_partitions.emplace_back("/" + partition.first);
            is_ota_in_progress = true;
        }
    }
    return false;
    return is_ota_in_progress;
}

bool SnapshotManager::BootFromSnapshotsWithoutSlotSwitch() {
+4 −2
Original line number Diff line number Diff line
@@ -3112,8 +3112,10 @@ int main(int argc, char** argv) {
    // thereby interfering with the update and snapshot-merge progress.
    // Hence, wait until the update is complete.
    auto sm = android::snapshot::SnapshotManager::New();
    while (sm->IsUserspaceSnapshotUpdateInProgress()) {
        LOG(INFO) << "Snapshot update is in progress. Waiting...";
    std::vector<std::string> snapshot_partitions;
    while (sm->IsUserspaceSnapshotUpdateInProgress(snapshot_partitions)) {
        LOG(INFO) << "Waiting for: " << snapshot_partitions.size()
                  << " partitions to finish snapshot-merge";
        std::this_thread::sleep_for(std::chrono::milliseconds(1000));
    }

+3 −0
Original line number Diff line number Diff line
@@ -108,6 +108,9 @@ class SnapuserdClient {

    // Notify init that snapuserd daemon is ready post selinux transition
    void NotifyTransitionDaemonIsReady();

    // Pause Merge threads
    bool PauseMerge();
};

}  // namespace snapshot
+9 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ bool EnsureSnapuserdStarted() {
            return false;
        }
    }

    if (!android::base::WaitForProperty("snapuserd.ready", "true", 10s)) {
        LOG(ERROR) << "Timed out waiting for snapuserd to be ready.";
        return false;
@@ -389,5 +390,13 @@ void SnapuserdClient::NotifyTransitionDaemonIsReady() {
    }
}

bool SnapuserdClient::PauseMerge() {
    if (!Sendmsg("pause_merge")) {
        LOG(ERROR) << "Failed to pause snapshot merge.";
        return false;
    }
    return true;
}

}  // namespace snapshot
}  // namespace android
Loading