From 8acf164d70bdc8a4ee5c997f2e1926c6bfc9bd89 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Tue, 10 May 2022 17:26:55 -0700 Subject: [PATCH 1/2] Install snapuserd.ramdisk with a separate path Test: th Bug: 2095786 Change-Id: Ib51713277f1b56d3dc6b2c2dac6db1b6346ef15f --- fs_mgr/libsnapshot/snapuserd/Android.bp | 47 +++++++++++++++++-------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/fs_mgr/libsnapshot/snapuserd/Android.bp b/fs_mgr/libsnapshot/snapuserd/Android.bp index bc2bcebbf..fbc8c304b 100644 --- a/fs_mgr/libsnapshot/snapuserd/Android.bp +++ b/fs_mgr/libsnapshot/snapuserd/Android.bp @@ -72,7 +72,7 @@ cc_defaults { cflags: [ "-Wall", - "-Werror" + "-Werror", ], static_libs: [ @@ -89,14 +89,7 @@ cc_defaults { "liburing", ], include_dirs: ["bionic/libc/kernel"], -} - -cc_binary { - name: "snapuserd", - defaults: ["snapuserd_defaults"], - init_rc: [ - "snapuserd.rc", - ], + system_shared_libs: [], // snapuserd is started during early boot by first-stage init. At that // point, /system is mounted using the "dm-user" device-mapper kernel @@ -105,16 +98,40 @@ cc_binary { // faults for its code pages. static_executable: true, - system_shared_libs: [], - ramdisk_available: true, - vendor_ramdisk_available: true, - recovery_available: true, - // Snapuserd segfaults with ThinLTO // http://b/208565717 lto: { never: true, - } + }, +} + +cc_binary { + name: "snapuserd", + defaults: ["snapuserd_defaults"], + init_rc: [ + "snapuserd.rc", + ], + ramdisk_available: false, + vendor_ramdisk_available: true, + recovery_available: true, +} + +// This target will install to /system/bin/snapuserd_ramdisk +// It will also create a symblink on /system/bin/snapuserd that point to +// /system/bin/snapuserd_ramdisk . +// This way, init can check if generic ramdisk copy exists. +cc_binary { + name: "snapuserd_ramdisk", + defaults: ["snapuserd_defaults"], + init_rc: [ + "snapuserd.rc", + ], + // This target is specifically for generic ramdisk, therefore we set + // vendor_ramdisk_available to false. + ramdisk_available: true, + vendor_ramdisk_available: false, + ramdisk: true, + symlinks: ["snapuserd"], } cc_test { From 07c86bace1e7a7cc4dd975f10b077d21c3743749 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Wed, 11 May 2022 11:30:44 -0700 Subject: [PATCH 2/2] Prefer generic ramdisk copy of snapuserd Test: th Bug: 219841787 Change-Id: I1319ff968dfa94fec2925b7d5febae32d824fe3a --- init/first_stage_init.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/init/first_stage_init.cpp b/init/first_stage_init.cpp index d050ed783..202a86a80 100644 --- a/init/first_stage_init.cpp +++ b/init/first_stage_init.cpp @@ -119,19 +119,14 @@ static void Copy(const char* src, const char* dst) { // Move snapuserd before switching root, so that it is available at the same path // after switching root. void PrepareSwitchRoot() { - constexpr const char* src = "/system/bin/snapuserd"; - constexpr const char* dst = "/first_stage_ramdisk/system/bin/snapuserd"; + static constexpr const auto& snapuserd = "/system/bin/snapuserd"; + static constexpr const auto& snapuserd_ramdisk = "/system/bin/snapuserd_ramdisk"; + static constexpr const auto& dst = "/first_stage_ramdisk/system/bin/snapuserd"; if (access(dst, X_OK) == 0) { LOG(INFO) << dst << " already exists and it can be executed"; return; } - - if (access(src, F_OK) != 0) { - PLOG(INFO) << "Not moving " << src << " because it cannot be accessed"; - return; - } - auto dst_dir = android::base::Dirname(dst); std::error_code ec; if (access(dst_dir.c_str(), F_OK) != 0) { @@ -139,7 +134,18 @@ void PrepareSwitchRoot() { LOG(FATAL) << "Cannot create " << dst_dir << ": " << ec.message(); } } - Copy(src, dst); + + // prefer the generic ramdisk copy of snapuserd, because that's on system side of treble + // boundary, and therefore is more likely to be updated along with the Android platform. + // The vendor ramdisk copy might be under vendor freeze, or vendor might choose not to update + // it. + if (access(snapuserd_ramdisk, F_OK) == 0) { + LOG(INFO) << "Using generic ramdisk copy of snapuserd " << snapuserd_ramdisk; + Copy(snapuserd_ramdisk, dst); + } else if (access(snapuserd, F_OK) == 0) { + LOG(INFO) << "Using vendor ramdisk copy of snapuserd " << snapuserd; + Copy(snapuserd, dst); + } } } // namespace