Skip to content

Commit ad7d1d1

Browse files
dvandercorpGerrit Code Review
authored andcommitted
Merge changes I82b7d77b,I6b77690c
* changes: first_stage_mount: Create snapshot devices before launching first_stage_console first_stage_mount: Move CreateLogicalPartitions to DoFirstStageMount
2 parents 291a505 + 9583e92 commit ad7d1d1

File tree

3 files changed

+46
-21
lines changed

3 files changed

+46
-21
lines changed

init/first_stage_init.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ int FirstStageMain(int argc, char** argv) {
286286
}
287287
}
288288

289+
289290
if (want_console == FirstStageConsoleParam::CONSOLE_ON_FAILURE) {
291+
if (!DoCreateDevices()) {
292+
LOG(ERROR) << "Failed to create device nodes early";
293+
}
290294
StartConsole(cmdline);
291295
}
292296

@@ -327,7 +331,7 @@ int FirstStageMain(int argc, char** argv) {
327331
}
328332
}
329333

330-
if (!DoFirstStageMount()) {
334+
if (!DoFirstStageMount(want_console != FirstStageConsoleParam::CONSOLE_ON_FAILURE)) {
331335
LOG(FATAL) << "Failed to mount required partitions early ...";
332336
}
333337

init/first_stage_mount.cpp

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class FirstStageMount {
8282
// The factory method to create either FirstStageMountVBootV1 or FirstStageMountVBootV2
8383
// based on device tree configurations.
8484
static std::unique_ptr<FirstStageMount> Create();
85+
bool DoCreateDevices(); // Creates devices and logical partitions from storage devices
8586
bool DoFirstStageMount(); // Mounts fstab entries read from device tree.
8687
bool InitDevices();
8788

@@ -244,15 +245,35 @@ std::unique_ptr<FirstStageMount> FirstStageMount::Create() {
244245
}
245246
}
246247

248+
bool FirstStageMount::DoCreateDevices() {
249+
if (!InitDevices()) return false;
250+
251+
// Mount /metadata before creating logical partitions, since we need to
252+
// know whether a snapshot merge is in progress.
253+
auto metadata_partition = std::find_if(fstab_.begin(), fstab_.end(), [](const auto& entry) {
254+
return entry.mount_point == "/metadata";
255+
});
256+
if (metadata_partition != fstab_.end()) {
257+
if (MountPartition(metadata_partition, true /* erase_same_mounts */)) {
258+
// Copies DSU AVB keys from the ramdisk to /metadata.
259+
// Must be done before the following TrySwitchSystemAsRoot().
260+
// Otherwise, ramdisk will be inaccessible after switching root.
261+
CopyDsuAvbKeys();
262+
}
263+
}
264+
265+
if (!CreateLogicalPartitions()) return false;
266+
267+
return true;
268+
}
269+
247270
bool FirstStageMount::DoFirstStageMount() {
248271
if (!IsDmLinearEnabled() && fstab_.empty()) {
249272
// Nothing to mount.
250273
LOG(INFO) << "First stage mount skipped (missing/incompatible/empty fstab in device tree)";
251274
return true;
252275
}
253276

254-
if (!InitDevices()) return false;
255-
256277
if (!MountPartitions()) return false;
257278

258279
return true;
@@ -505,22 +526,6 @@ bool FirstStageMount::TrySwitchSystemAsRoot() {
505526
}
506527

507528
bool FirstStageMount::MountPartitions() {
508-
// Mount /metadata before creating logical partitions, since we need to
509-
// know whether a snapshot merge is in progress.
510-
auto metadata_partition = std::find_if(fstab_.begin(), fstab_.end(), [](const auto& entry) {
511-
return entry.mount_point == "/metadata";
512-
});
513-
if (metadata_partition != fstab_.end()) {
514-
if (MountPartition(metadata_partition, true /* erase_same_mounts */)) {
515-
// Copies DSU AVB keys from the ramdisk to /metadata.
516-
// Must be done before the following TrySwitchSystemAsRoot().
517-
// Otherwise, ramdisk will be inaccessible after switching root.
518-
CopyDsuAvbKeys();
519-
}
520-
}
521-
522-
if (!CreateLogicalPartitions()) return false;
523-
524529
if (!TrySwitchSystemAsRoot()) return false;
525530

526531
if (!SkipMountingPartitions(&fstab_)) return false;
@@ -829,8 +834,18 @@ bool FirstStageMountVBootV2::InitAvbHandle() {
829834

830835
// Public functions
831836
// ----------------
837+
// Creates devices and logical partitions from storage devices
838+
bool DoCreateDevices() {
839+
std::unique_ptr<FirstStageMount> handle = FirstStageMount::Create();
840+
if (!handle) {
841+
LOG(ERROR) << "Failed to create FirstStageMount";
842+
return false;
843+
}
844+
return handle->DoCreateDevices();
845+
}
846+
832847
// Mounts partitions specified by fstab in device tree.
833-
bool DoFirstStageMount() {
848+
bool DoFirstStageMount(bool create_devices) {
834849
// Skips first stage mount if we're in recovery mode.
835850
if (IsRecoveryMode()) {
836851
LOG(INFO) << "First stage mount skipped (recovery mode)";
@@ -842,6 +857,11 @@ bool DoFirstStageMount() {
842857
LOG(ERROR) << "Failed to create FirstStageMount";
843858
return false;
844859
}
860+
861+
if (create_devices) {
862+
if (!handle->DoCreateDevices()) return false;
863+
}
864+
845865
return handle->DoFirstStageMount();
846866
}
847867

init/first_stage_mount.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
namespace android {
2020
namespace init {
2121

22-
bool DoFirstStageMount();
22+
bool DoCreateDevices();
23+
bool DoFirstStageMount(bool create_devices);
2324
void SetInitAvbVersionInRecovery();
2425

2526
} // namespace init

0 commit comments

Comments
 (0)