From 8696a5d11b6613e4b205e124599d7d1d9df3f4fc Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 10 Jun 2020 23:50:02 -0700 Subject: [PATCH] remount: Do not allow remounting during checkpoints. Bug: 157540389 Test: manual test Change-Id: I5931a583e48ddac05f319629ae2f7f5f0f6cf032 --- fs_mgr/Android.bp | 3 +++ fs_mgr/fs_mgr_remount.cpp | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/fs_mgr/Android.bp b/fs_mgr/Android.bp index f5daf9174..cd6459989 100644 --- a/fs_mgr/Android.bp +++ b/fs_mgr/Android.bp @@ -162,10 +162,13 @@ cc_binary { defaults: ["fs_mgr_defaults"], static_libs: [ "libavb_user", + "libutils", + "libvold_binder", ], shared_libs: [ "libbootloader_message", "libbase", + "libbinder", "libcutils", "libcrypto", "libext4_utils", diff --git a/fs_mgr/fs_mgr_remount.cpp b/fs_mgr/fs_mgr_remount.cpp index 052efa765..b8b074e0f 100644 --- a/fs_mgr/fs_mgr_remount.cpp +++ b/fs_mgr/fs_mgr_remount.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -31,6 +32,8 @@ #include #include #include +#include +#include #include #include #include @@ -103,8 +106,23 @@ void MyLogger(android::base::LogId id, android::base::LogSeverity severity, cons ::exit(0); // SUCCESS } +static android::sp GetVold() { + while (true) { + if (auto sm = android::defaultServiceManager()) { + if (auto binder = sm->getService(android::String16("vold"))) { + if (auto vold = android::interface_cast(binder)) { + return vold; + } + } + } + std::this_thread::sleep_for(2s); + } +} + } // namespace +using namespace std::chrono_literals; + enum RemountStatus { REMOUNT_SUCCESS = 0, NOT_USERDEBUG, @@ -117,7 +135,9 @@ enum RemountStatus { BAD_OVERLAY, NO_MOUNTS, REMOUNT_FAILED, - MUST_REBOOT + MUST_REBOOT, + BINDER_ERROR, + CHECKPOINTING }; static int do_remount(int argc, char* argv[]) { @@ -194,6 +214,22 @@ static int do_remount(int argc, char* argv[]) { return NO_FSTAB; } + if (android::base::GetBoolProperty("ro.virtual_ab.enabled", false) && + !android::base::GetBoolProperty("ro.virtual_ab.retrofit", false)) { + // Virtual A/B devices can use /data as backing storage; make sure we're + // not checkpointing. + auto vold = GetVold(); + bool checkpointing = false; + if (!vold->isCheckpointing(&checkpointing).isOk()) { + LOG(ERROR) << "Could not determine checkpointing status."; + return BINDER_ERROR; + } + if (checkpointing) { + LOG(ERROR) << "Cannot use remount when a checkpoint is in progress."; + return CHECKPOINTING; + } + } + // Generate the list of supported overlayfs mount points. auto overlayfs_candidates = fs_mgr_overlayfs_candidate_list(fstab);