Merge "Helper function to mount snapshot devices in recovery"

This commit is contained in:
Treehugger Robot 2020-01-07 20:26:43 +00:00 committed by Gerrit Code Review
commit 7cd37ba4dc
2 changed files with 49 additions and 0 deletions

View File

@ -74,6 +74,12 @@ static constexpr const std::string_view kCowGroupName = "cow";
bool SourceCopyOperationIsClone(const chromeos_update_engine::InstallOperation& operation);
enum class CreateResult : unsigned int {
ERROR,
CREATED,
NOT_CREATED,
};
enum class UpdateState : unsigned int {
// No update or merge is in progress.
None,
@ -246,6 +252,17 @@ class SnapshotManager final {
// optional callback fires periodically to query progress via GetUpdateState.
bool HandleImminentDataWipe(const std::function<void()>& callback = {});
// This method is only allowed in recovery and is used as a helper to
// initialize the snapshot devices as a requirement to mount a snapshotted
// /system in recovery.
// This function returns:
// - CreateResult::CREATED if snapshot devices were successfully created;
// - CreateResult::NOT_CREATED if it was not necessary to create snapshot
// devices;
// - CreateResult::ERROR if a fatal error occurred, mounting /system should
// be aborted.
CreateResult RecoveryCreateSnapshotDevices();
// Dump debug information.
bool Dump(std::ostream& os);

View File

@ -2356,5 +2356,37 @@ bool SnapshotManager::EnsureNoOverflowSnapshot(LockedFile* lock) {
return true;
}
CreateResult SnapshotManager::RecoveryCreateSnapshotDevices() {
if (!device_->IsRecovery()) {
LOG(ERROR) << __func__ << " is only allowed in recovery.";
return CreateResult::NOT_CREATED;
}
auto mount = EnsureMetadataMounted();
if (!mount || !mount->HasDevice()) {
LOG(ERROR) << "Couldn't mount Metadata.";
return CreateResult::NOT_CREATED;
}
auto state_file = GetStateFilePath();
if (access(state_file.c_str(), F_OK) != 0 && errno == ENOENT) {
LOG(ERROR) << "Couldn't access state file.";
return CreateResult::NOT_CREATED;
}
if (!NeedSnapshotsInFirstStageMount()) {
return CreateResult::NOT_CREATED;
}
auto slot_suffix = device_->GetOtherSlotSuffix();
auto slot_number = SlotNumberForSlotSuffix(slot_suffix);
auto super_path = device_->GetSuperDevice(slot_number);
if (!CreateLogicalAndSnapshotPartitions(super_path)) {
LOG(ERROR) << "Unable to map partitions.";
return CreateResult::ERROR;
}
return CreateResult::CREATED;
}
} // namespace snapshot
} // namespace android