Merge "SnapshotManager::WaitForMerge gives more info"
am: e99ec483b1
Change-Id: I369b2220bb42258d19fe275fd69c83a03a3c9bba
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/return.h b/fs_mgr/libsnapshot/include/libsnapshot/return.h
index dedc445..1f132fa 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/return.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/return.h
@@ -30,6 +30,7 @@
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 @@
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) {}
diff --git a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
index e503ec3..959d8a7 100644
--- a/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
+++ b/fs_mgr/libsnapshot/include/libsnapshot/snapshot.h
@@ -181,9 +181,11 @@
// 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.
//
diff --git a/fs_mgr/libsnapshot/return.cpp b/fs_mgr/libsnapshot/return.cpp
index cc64af5..6559c12 100644
--- a/fs_mgr/libsnapshot/return.cpp
+++ b/fs_mgr/libsnapshot/return.cpp
@@ -24,6 +24,8 @@
switch (error_code()) {
case ErrorCode::ERROR:
return "Error";
+ case ErrorCode::NEEDS_REBOOT:
+ return "Retry after reboot";
case ErrorCode::SUCCESS:
[[fallthrough]];
case ErrorCode::NO_SPACE:
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index c731cb0..912087c 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -2346,7 +2346,7 @@
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) {
@@ -2357,7 +2357,18 @@
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();
+ }
}
}