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

Commit 3634255e authored by Yifan Hong's avatar Yifan Hong
Browse files

libsnapshot: delete WaitForMerge.

Now that update_engine is responsible for initiating the
merge, WaitForMerge function becomes useless.

Bug: 147696014
Test: compiles
Change-Id: I3779bdf9dd8d1716238e21d09acf0499e3fc90a3
Merged-In: I3779bdf9dd8d1716238e21d09acf0499e3fc90a3
parent d5675f67
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ class Return {
    enum class ErrorCode : int32_t {
        SUCCESS = static_cast<int32_t>(FiemapStatus::ErrorCode::SUCCESS),
        ERROR = static_cast<int32_t>(FiemapStatus::ErrorCode::ERROR),
        NEEDS_REBOOT = ERROR + 1,
        NO_SPACE = static_cast<int32_t>(FiemapStatus::ErrorCode::NO_SPACE),
    };
    ErrorCode error_code() const { return error_code_; }
@@ -43,7 +42,6 @@ class Return {
    static Return Ok() { return Return(ErrorCode::SUCCESS); }
    static Return Error() { return Return(ErrorCode::ERROR); }
    static Return NoSpace(uint64_t size) { return Return(ErrorCode::NO_SPACE, size); }
    static Return NeedsReboot() { return Return(ErrorCode::NEEDS_REBOOT); }
    // Does not set required_size_ properly even when status.error_code() == NO_SPACE.
    explicit Return(const FiemapStatus& status)
        : error_code_(FromFiemapStatusErrorCode(status.error_code())), required_size_(0) {}
+0 −9
Original line number Diff line number Diff line
@@ -185,15 +185,6 @@ class SnapshotManager final {
    UpdateState InitiateMergeAndWait(SnapshotMergeReport* report = nullptr,
                                     const std::function<bool()>& before_cancel = {});

    // Wait for the merge if rebooted into the new slot. Does NOT initiate a
    // merge. If the merge has not been initiated (but should be), wait.
    // Returns:
    //   - Return::Ok(): there is no merge or merge finishes
    //   - Return::NeedsReboot(): merge finishes but need a reboot before
    //     applying the next update.
    //   - Return::Error(): other irrecoverable errors
    Return WaitForMerge();

    // Find the status of the current update, if any.
    //
    // |progress| depends on the returned status:
+0 −2
Original line number Diff line number Diff line
@@ -24,8 +24,6 @@ std::string Return::string() const {
    switch (error_code()) {
        case ErrorCode::ERROR:
            return "Error";
        case ErrorCode::NEEDS_REBOOT:
            return "Retry after reboot";
        case ErrorCode::SUCCESS:
            [[fallthrough]];
        case ErrorCode::NO_SPACE:
+0 −26
Original line number Diff line number Diff line
@@ -2551,32 +2551,6 @@ UpdateState SnapshotManager::InitiateMergeAndWait(SnapshotMergeReport* stats_rep
    return state;
}

Return SnapshotManager::WaitForMerge() {
    LOG(INFO) << "Waiting for any previous merge request to complete. "
              << "This can take up to several minutes.";
    while (true) {
        auto state = ProcessUpdateState();
        if (state == UpdateState::Unverified && GetCurrentSlot() == Slot::Target) {
            LOG(INFO) << "Wait for merge to be initiated.";
            std::this_thread::sleep_for(kUpdateStateCheckInterval);
            continue;
        }
        LOG(INFO) << "Wait for merge exits with state " << state;
        switch (state) {
            case UpdateState::None:
                [[fallthrough]];
            case UpdateState::MergeCompleted:
                [[fallthrough]];
            case UpdateState::Cancelled:
                return Return::Ok();
            case UpdateState::MergeNeedsReboot:
                return Return::NeedsReboot();
            default:
                return Return::Error();
        }
    }
}

bool SnapshotManager::HandleImminentDataWipe(const std::function<void()>& callback) {
    if (!device_->IsRecovery()) {
        LOG(ERROR) << "Data wipes are only allowed in recovery.";
+0 −39
Original line number Diff line number Diff line
@@ -1570,45 +1570,6 @@ TEST_F(SnapshotUpdateTest, Overflow) {
            << "FinishedSnapshotWrites should detect overflow of CoW device.";
}

TEST_F(SnapshotUpdateTest, WaitForMerge) {
    AddOperationForPartitions();

    // Execute the update.
    ASSERT_TRUE(sm->BeginUpdate());
    ASSERT_TRUE(sm->CreateUpdateSnapshots(manifest_));

    // Write some data to target partitions.
    for (const auto& name : {"sys_b", "vnd_b", "prd_b"}) {
        ASSERT_TRUE(WriteSnapshotAndHash(name));
    }

    ASSERT_TRUE(sm->FinishedSnapshotWrites());

    // Simulate shutting down the device.
    ASSERT_TRUE(UnmapAll());

    // After reboot, init does first stage mount.
    {
        auto init = SnapshotManager::NewForFirstStageMount(new TestDeviceInfo(fake_super, "_b"));
        ASSERT_NE(nullptr, init);
        ASSERT_TRUE(init->CreateLogicalAndSnapshotPartitions("super", snapshot_timeout_));
    }

    auto new_sm = SnapshotManager::New(new TestDeviceInfo(fake_super, "_b"));
    ASSERT_NE(nullptr, new_sm);

    auto waiter = std::async(std::launch::async, [&new_sm] { return new_sm->WaitForMerge(); });
    ASSERT_EQ(std::future_status::timeout, waiter.wait_for(1s))
            << "WaitForMerge should block when not initiated";

    auto merger =
            std::async(std::launch::async, [&new_sm] { return new_sm->InitiateMergeAndWait(); });
    // Small images, so should be merged pretty quickly.
    ASSERT_EQ(std::future_status::ready, waiter.wait_for(3s)) << "WaitForMerge did not finish";
    ASSERT_TRUE(waiter.get());
    ASSERT_THAT(merger.get(), AnyOf(UpdateState::None, UpdateState::MergeCompleted));
}

TEST_F(SnapshotUpdateTest, LowSpace) {
    static constexpr auto kMaxFree = 10_MiB;
    auto userdata = std::make_unique<LowSpaceUserdata>();