UpdateAttempterAndroid::Init initiates merge
On update_engine starts, schedule CleanupPreviousUpdateAction that calls
CleanupSuccessfulUpdate to do necessary cleanup as soon as possible.
In the good case, update_engine initiates merge when
sys.boot_completed, and clean up snapshots.
If the update is
rolled back or partitions are flashed, the following happens (on
a Virtual A/B device):
- UpdateAttempterAndroid::CleanupSuccessfulUpdate is called
- DynamicPartitionControlAndroid::CleanupSuccessfulUpdate is called
- SnapshotManager::InitiateMergeAndWait is called
- SnapshotManager::RemoveAllUpdateState(before_cancel) is called
- before_cancel is called,
DeltaPerformer::ResetUpdateProgress is called
- All update states in update_engine is reset.
- SnapshotManager proceeds to delete snapshots
- All update states in SnapshotManager is reset.
Hence, on an VAB device, when an update is rolled back or partitions
are flashed, the whole update needs to be re-applied
(while in A/B, it skips writing and directly start verifying hashes of
the target partitions because the update markers are still there).
Bug: 147696014
Test: apply OTA then reboot, inspect logs and do `snapshotctl dump`
Change-Id: I0fc5e7768dfb53e4fd474f2d8d85d2a1b615a88b
diff --git a/common/action.h b/common/action.h
index 9e2f5ff..c93e73c 100644
--- a/common/action.h
+++ b/common/action.h
@@ -222,6 +222,16 @@
out_pipe_;
};
+// An action that does nothing and completes with kSuccess immediately.
+class NoOpAction : public AbstractAction {
+ public:
+ ~NoOpAction() override {}
+ void PerformAction() override {
+ processor_->ActionComplete(this, ErrorCode::kSuccess);
+ }
+ std::string Type() const override { return "NoOpAction"; }
+};
+
}; // namespace chromeos_update_engine
#endif // UPDATE_ENGINE_COMMON_ACTION_H_
diff --git a/common/dynamic_partition_control_interface.h b/common/dynamic_partition_control_interface.h
index 48cd9be..8de9d76 100644
--- a/common/dynamic_partition_control_interface.h
+++ b/common/dynamic_partition_control_interface.h
@@ -22,6 +22,8 @@
#include <memory>
#include <string>
+#include "update_engine/common/action.h"
+#include "update_engine/common/cleanup_previous_update_action_delegate.h"
#include "update_engine/common/error_code.h"
#include "update_engine/update_metadata.pb.h"
@@ -38,6 +40,9 @@
Value value_;
};
+class BootControlInterface;
+class PrefsInterface;
+
class DynamicPartitionControlInterface {
public:
virtual ~DynamicPartitionControlInterface() = default;
@@ -79,6 +84,7 @@
// this function to indicate writes to new partitions are done.
virtual bool FinishUpdate() = 0;
+ // Deprecated. Use GetCleanupPreviousUpdateAction instead.
// Before applying the next update, call this function to clean up previous
// update files. This function blocks until delta files are merged into
// current OS partitions and finished cleaning up.
@@ -86,6 +92,20 @@
// - If any error, but caller should retry after reboot, return kError.
// - If any irrecoverable failures, return kDeviceCorrupted.
virtual ErrorCode CleanupSuccessfulUpdate() = 0;
+
+ // Get an action to clean up previous update.
+ // Return NoOpAction on non-Virtual A/B devices.
+ // Before applying the next update, run this action to clean up previous
+ // update files. This function blocks until delta files are merged into
+ // current OS partitions and finished cleaning up.
+ // - If successful, action completes with kSuccess.
+ // - If any error, but caller should retry after reboot, action completes with
+ // kError.
+ // - If any irrecoverable failures, action completes with kDeviceCorrupted.
+ virtual std::unique_ptr<AbstractAction> GetCleanupPreviousUpdateAction(
+ BootControlInterface* boot_control,
+ PrefsInterface* prefs,
+ CleanupPreviousUpdateActionDelegateInterface* delegate) = 0;
};
} // namespace chromeos_update_engine
diff --git a/common/dynamic_partition_control_stub.cc b/common/dynamic_partition_control_stub.cc
index cc36c5c..70d6768 100644
--- a/common/dynamic_partition_control_stub.cc
+++ b/common/dynamic_partition_control_stub.cc
@@ -16,6 +16,7 @@
#include <stdint.h>
+#include <memory>
#include <string>
#include <base/logging.h>
@@ -56,4 +57,12 @@
return ErrorCode::kError;
}
+std::unique_ptr<AbstractAction>
+DynamicPartitionControlStub::GetCleanupPreviousUpdateAction(
+ BootControlInterface* boot_control,
+ PrefsInterface* prefs,
+ CleanupPreviousUpdateActionDelegateInterface* delegate) {
+ return std::make_unique<NoOpAction>();
+}
+
} // namespace chromeos_update_engine
diff --git a/common/dynamic_partition_control_stub.h b/common/dynamic_partition_control_stub.h
index 02575a1..92e9922 100644
--- a/common/dynamic_partition_control_stub.h
+++ b/common/dynamic_partition_control_stub.h
@@ -19,6 +19,7 @@
#include <stdint.h>
+#include <memory>
#include <string>
#include "update_engine/common/dynamic_partition_control_interface.h"
@@ -40,6 +41,10 @@
bool FinishUpdate() override;
ErrorCode CleanupSuccessfulUpdate() override;
+ std::unique_ptr<AbstractAction> GetCleanupPreviousUpdateAction(
+ BootControlInterface* boot_control,
+ PrefsInterface* prefs,
+ CleanupPreviousUpdateActionDelegateInterface* delegate) override;
};
} // namespace chromeos_update_engine