From 32f281d77a9faea65afa4f216a9ffc595e0319f1 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 21 Nov 2020 13:43:47 -0800 Subject: [PATCH 1/2] init: Pass a uevent regen callback to libsnapshot. In first-stage init, libsnapshot needs to know how to wait for device paths, since ueventd isn't running yet. We do this by passing a callback wrapping BlockDevInitializer. Bug: 173476209 Test: device boots into first-stage init after full VABC ota Change-Id: I9a87f98824e65a9379cb0b99c001e28cccd9d205 --- init/block_dev_initializer.cpp | 4 ++-- init/block_dev_initializer.h | 2 +- init/first_stage_mount.cpp | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/init/block_dev_initializer.cpp b/init/block_dev_initializer.cpp index 8db9793f5..9c2a7bb14 100644 --- a/init/block_dev_initializer.cpp +++ b/init/block_dev_initializer.cpp @@ -40,8 +40,8 @@ bool BlockDevInitializer::InitDeviceMapper() { return InitMiscDevice("device-mapper"); } -bool BlockDevInitializer::InitDmUser() { - return InitMiscDevice("dm-user"); +bool BlockDevInitializer::InitDmUser(const std::string& name) { + return InitMiscDevice("dm-user!" + name); } bool BlockDevInitializer::InitMiscDevice(const std::string& name) { diff --git a/init/block_dev_initializer.h b/init/block_dev_initializer.h index b8dd3f172..79fe4ecd8 100644 --- a/init/block_dev_initializer.h +++ b/init/block_dev_initializer.h @@ -27,7 +27,7 @@ class BlockDevInitializer final { BlockDevInitializer(); bool InitDeviceMapper(); - bool InitDmUser(); + bool InitDmUser(const std::string& name); bool InitDevices(std::set devices); bool InitDmDevice(const std::string& device); diff --git a/init/first_stage_mount.cpp b/init/first_stage_mount.cpp index b7d50cf54..a0511cc38 100644 --- a/init/first_stage_mount.cpp +++ b/init/first_stage_mount.cpp @@ -343,6 +343,15 @@ bool FirstStageMount::CreateLogicalPartitions() { if (!InitRequiredDevices({"userdata"})) { return false; } + sm->SetUeventRegenCallback([this](const std::string& device) -> bool { + if (android::base::StartsWith(device, "/dev/block/dm-")) { + return block_dev_init_.InitDmDevice(device); + } + if (android::base::StartsWith(device, "/dev/dm-user/")) { + return block_dev_init_.InitDmUser(android::base::Basename(device)); + } + return block_dev_init_.InitDevices({device}); + }); return sm->CreateLogicalAndSnapshotPartitions(super_path_); } } From 1d57fb839de219e16ec108c8f35152a0350a0d76 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 22 Nov 2020 00:25:36 -0800 Subject: [PATCH 2/2] init: Fix ordering of second-stage snapuserd transition. Running snapuserd before early-init means ueventd is missing, which means we can't use WaitForFile() when dm-user misc devices are created. Fix this by starting the transition after early-init. Bug: 173476209 Test: full OTA with VABC applies and boots Change-Id: Ice594cceb44981ae38deb82289d313c14726c36b --- init/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/init.cpp b/init/init.cpp index c6f206644..1d0a9dca7 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -875,13 +875,13 @@ int SecondStageMain(int argc, char** argv) { SetProperty(gsi::kGsiInstalledProp, is_installed); am.QueueBuiltinAction(SetupCgroupsAction, "SetupCgroups"); - am.QueueBuiltinAction(TransitionSnapuserdAction, "TransitionSnapuserd"); am.QueueBuiltinAction(SetKptrRestrictAction, "SetKptrRestrict"); am.QueueBuiltinAction(TestPerfEventSelinuxAction, "TestPerfEventSelinux"); am.QueueEventTrigger("early-init"); // Queue an action that waits for coldboot done so we know ueventd has set up all of /dev... am.QueueBuiltinAction(wait_for_coldboot_done_action, "wait_for_coldboot_done"); + am.QueueBuiltinAction(TransitionSnapuserdAction, "TransitionSnapuserd"); // ... so that we can start queuing up actions that require stuff from /dev. am.QueueBuiltinAction(MixHwrngIntoLinuxRngAction, "MixHwrngIntoLinuxRng"); am.QueueBuiltinAction(SetMmapRndBitsAction, "SetMmapRndBits");