diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2020-01-07 20:26:43 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-01-07 20:26:43 +0000 |
| commit | 5ee782079adc054c8402ffd2254e59e3285b1204 (patch) | |
| tree | 75518fe845376382f12a8ee70691a1cf0c00c387 /install | |
| parent | 8b9ac5b83dc71280a375603af298191d40053755 (diff) | |
| parent | a9665ced57ebd3f00f11cd8d9d99b33269687286 (diff) | |
Merge "Mount snapshotted /system in Virtual A/B devices"
Diffstat (limited to 'install')
| -rw-r--r-- | install/include/install/snapshot_utils.h | 9 | ||||
| -rw-r--r-- | install/snapshot_utils.cpp | 25 |
2 files changed, 34 insertions, 0 deletions
diff --git a/install/include/install/snapshot_utils.h b/install/include/install/snapshot_utils.h index 00c3ef7e..f4b978d2 100644 --- a/install/include/install/snapshot_utils.h +++ b/install/include/install/snapshot_utils.h @@ -19,3 +19,12 @@ #include "recovery_ui/device.h" bool FinishPendingSnapshotMerges(Device* device); + +/* + * This function tries to create the snapshotted devices in the case a Virtual + * A/B device is updating. + * The function returns false in case of critical failure that would prevent + * the further mountings of devices, or true in case of success, if either the + * devices were created or there was no need to. + */ +bool CreateSnapshotPartitions(); diff --git a/install/snapshot_utils.cpp b/install/snapshot_utils.cpp index 69da5eea..7235e67c 100644 --- a/install/snapshot_utils.cpp +++ b/install/snapshot_utils.cpp @@ -15,6 +15,7 @@ * limitations under the License. */ +#include <android-base/logging.h> #include <android-base/properties.h> #include <libsnapshot/snapshot.h> @@ -22,6 +23,7 @@ #include "recovery_ui/ui.h" #include "recovery_utils/roots.h" +using android::snapshot::CreateResult; using android::snapshot::SnapshotManager; bool FinishPendingSnapshotMerges(Device* device) { @@ -47,3 +49,26 @@ bool FinishPendingSnapshotMerges(Device* device) { } return true; } + +bool CreateSnapshotPartitions() { + if (!android::base::GetBoolProperty("ro.virtual_ab.enabled", false)) { + // If the device does not support Virtual A/B, there's no need to create + // snapshot devices. + return true; + } + + auto sm = SnapshotManager::NewForFirstStageMount(); + if (!sm) { + // SnapshotManager could not be created. The device is still in a + // consistent state and can continue with the mounting of the existing + // devices, but cannot initialize snapshot devices. + LOG(WARNING) << "Could not create SnapshotManager"; + return true; + } + + auto ret = sm->RecoveryCreateSnapshotDevices(); + if (ret == CreateResult::ERROR) { + return false; + } + return true; +} |
