Merge "libsnapshot: Remove invalid snapshot metadata"
This commit is contained in:
commit
e3cca4a0d1
3 changed files with 38 additions and 1 deletions
|
|
@ -538,6 +538,9 @@ class SnapshotManager final : public ISnapshotManager {
|
||||||
// Unmap a COW and remove it from a MetadataBuilder.
|
// Unmap a COW and remove it from a MetadataBuilder.
|
||||||
void UnmapAndDeleteCowPartition(MetadataBuilder* current_metadata);
|
void UnmapAndDeleteCowPartition(MetadataBuilder* current_metadata);
|
||||||
|
|
||||||
|
// Remove invalid snapshots if any
|
||||||
|
void RemoveInvalidSnapshots(LockedFile* lock);
|
||||||
|
|
||||||
// Unmap and remove all known snapshots.
|
// Unmap and remove all known snapshots.
|
||||||
bool RemoveAllSnapshots(LockedFile* lock);
|
bool RemoveAllSnapshots(LockedFile* lock);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,10 @@ bool SnapshotManager::TryCancelUpdate(bool* needs_merge) {
|
||||||
if (!file) return false;
|
if (!file) return false;
|
||||||
|
|
||||||
UpdateState state = ReadUpdateState(file.get());
|
UpdateState state = ReadUpdateState(file.get());
|
||||||
if (state == UpdateState::None) return true;
|
if (state == UpdateState::None) {
|
||||||
|
RemoveInvalidSnapshots(file.get());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (state == UpdateState::Initiated) {
|
if (state == UpdateState::Initiated) {
|
||||||
LOG(INFO) << "Update has been initiated, now canceling";
|
LOG(INFO) << "Update has been initiated, now canceling";
|
||||||
|
|
@ -1903,6 +1906,33 @@ bool SnapshotManager::GetSnapshotFlashingStatus(LockedFile* lock,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SnapshotManager::RemoveInvalidSnapshots(LockedFile* lock) {
|
||||||
|
std::vector<std::string> snapshots;
|
||||||
|
|
||||||
|
// Remove the stale snapshot metadata
|
||||||
|
//
|
||||||
|
// We make sure that all the three cases
|
||||||
|
// are valid before removing the snapshot metadata:
|
||||||
|
//
|
||||||
|
// 1: dm state is active
|
||||||
|
// 2: Root fs is not mounted off as a snapshot device
|
||||||
|
// 3: Snapshot slot suffix should match current device slot
|
||||||
|
if (!ListSnapshots(lock, &snapshots, device_->GetSlotSuffix()) || snapshots.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We indeed have some invalid snapshots
|
||||||
|
for (const auto& name : snapshots) {
|
||||||
|
if (dm_.GetState(name) == DmDeviceState::ACTIVE && !IsSnapshotDevice(name)) {
|
||||||
|
if (!DeleteSnapshot(lock, name)) {
|
||||||
|
LOG(ERROR) << "Failed to delete invalid snapshot: " << name;
|
||||||
|
} else {
|
||||||
|
LOG(INFO) << "Invalid snapshot: " << name << " deleted";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool SnapshotManager::RemoveAllSnapshots(LockedFile* lock) {
|
bool SnapshotManager::RemoveAllSnapshots(LockedFile* lock) {
|
||||||
std::vector<std::string> snapshots;
|
std::vector<std::string> snapshots;
|
||||||
if (!ListSnapshots(lock, &snapshots)) {
|
if (!ListSnapshots(lock, &snapshots)) {
|
||||||
|
|
|
||||||
|
|
@ -795,6 +795,10 @@ int SecondStageMain(int argc, char** argv) {
|
||||||
InstallRebootSignalHandlers();
|
InstallRebootSignalHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No threads should be spin up until signalfd
|
||||||
|
// is registered. If the threads are indeed required,
|
||||||
|
// each of these threads _should_ make sure SIGCHLD signal
|
||||||
|
// is blocked. See b/223076262
|
||||||
boot_clock::time_point start_time = boot_clock::now();
|
boot_clock::time_point start_time = boot_clock::now();
|
||||||
|
|
||||||
trigger_shutdown = [](const std::string& command) { shutdown_state.TriggerShutdown(command); };
|
trigger_shutdown = [](const std::string& command) { shutdown_state.TriggerShutdown(command); };
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue