SnapshotManager::WaitForMerge gives more info
It now returns Ok() if successful, NeedsReboot() if merge it should be checked again after reboot, and Error() for other errors. This wraps UpdateState to help clients interpret the UpdateState value. Also separate SnapshotManager::Return from FiemapStatus since they are for different libraries and have (potentially) different set of error codes. Test: libsnapshot_test Bug: 138808328 Change-Id: I8c95417c2b0b7b2a362beb12585f861453a79278
This commit is contained in:
parent
cdebef1d2b
commit
b98a2e36ae
|
@ -30,6 +30,7 @@ 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_; }
|
||||
|
@ -42,6 +43,7 @@ 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) {}
|
||||
|
|
|
@ -181,9 +181,11 @@ class SnapshotManager final {
|
|||
// 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:
|
||||
// - true there is no merge or merge finishes
|
||||
// - false indicating an error has occurred
|
||||
bool WaitForMerge();
|
||||
// - 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.
|
||||
//
|
||||
|
|
|
@ -24,6 +24,8 @@ 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:
|
||||
|
|
|
@ -2305,7 +2305,7 @@ UpdateState SnapshotManager::InitiateMergeAndWait() {
|
|||
return state;
|
||||
}
|
||||
|
||||
bool SnapshotManager::WaitForMerge() {
|
||||
Return SnapshotManager::WaitForMerge() {
|
||||
LOG(INFO) << "Waiting for any previous merge request to complete. "
|
||||
<< "This can take up to several minutes.";
|
||||
while (true) {
|
||||
|
@ -2316,7 +2316,18 @@ bool SnapshotManager::WaitForMerge() {
|
|||
continue;
|
||||
}
|
||||
LOG(INFO) << "Wait for merge exits with state " << state;
|
||||
return state == UpdateState::None || state == UpdateState::MergeCompleted;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue