diff options
author | 2024-07-24 12:33:40 +0100 | |
---|---|---|
committer | 2024-07-29 16:33:30 +0000 | |
commit | 6979528e6e74677ca39932ce2712cce8e5ca32c2 (patch) | |
tree | 81b379fa08276d17356ae13ddab412134b5991df /dexopt_chroot_setup | |
parent | 8fd86be0bd99d39a9c2251b0da4f2a7ed7f9ec53 (diff) |
Clean up the mounts for Pre-reboot Dexopt on system_server restart.
When there is a system_server restart, it's possible that a previous
Pre-reboot Dexopt job didn't end normally and left over a chroot, so we
need to clean it up, or we may potentially block update_engine (if there
is an OTA).
Bug: 354140992
Test: Run Pre-reboot Dexopt and then kill system_server.
Change-Id: Ieb5ee411d136224e4f1bb50cb1389d2472d27143
Diffstat (limited to 'dexopt_chroot_setup')
4 files changed, 23 insertions, 10 deletions
diff --git a/dexopt_chroot_setup/binder/com/android/server/art/IDexoptChrootSetup.aidl b/dexopt_chroot_setup/binder/com/android/server/art/IDexoptChrootSetup.aidl index f8770147fc..867fdf9e38 100644 --- a/dexopt_chroot_setup/binder/com/android/server/art/IDexoptChrootSetup.aidl +++ b/dexopt_chroot_setup/binder/com/android/server/art/IDexoptChrootSetup.aidl @@ -38,6 +38,12 @@ interface IDexoptChrootSetup { */ void init(); - /** Tears down the chroot environment. */ - void tearDown(); + /** + * Tears down the chroot environment. + * + * @param allowConcurrent If true, allows this method to be called concurrently when another + * call to the service is still being processed. Note that the service does not process this + * call concurrently but waits until the other call is done. + */ + void tearDown(boolean allowConcurrent); } diff --git a/dexopt_chroot_setup/dexopt_chroot_setup.cc b/dexopt_chroot_setup/dexopt_chroot_setup.cc index ff016d64d5..1710f07b5f 100644 --- a/dexopt_chroot_setup/dexopt_chroot_setup.cc +++ b/dexopt_chroot_setup/dexopt_chroot_setup.cc @@ -365,9 +365,16 @@ ScopedAStatus DexoptChrootSetup::init() { return ScopedAStatus::ok(); } -ScopedAStatus DexoptChrootSetup::tearDown() { - if (!mu_.try_lock()) { - return Fatal("Unexpected concurrent calls"); +ScopedAStatus DexoptChrootSetup::tearDown(bool in_allowConcurrent) { + if (in_allowConcurrent) { + // Normally, we don't expect concurrent calls, but this method may be called upon system server + // restart when another call initiated by the previous system_server instance is still being + // processed. + mu_.lock(); + } else { + if (!mu_.try_lock()) { + return Fatal("Unexpected concurrent calls"); + } } std::lock_guard<std::mutex> lock(mu_, std::adopt_lock); diff --git a/dexopt_chroot_setup/dexopt_chroot_setup.h b/dexopt_chroot_setup/dexopt_chroot_setup.h index de0e35fa4d..3e39be4bb8 100644 --- a/dexopt_chroot_setup/dexopt_chroot_setup.h +++ b/dexopt_chroot_setup/dexopt_chroot_setup.h @@ -35,7 +35,7 @@ class DexoptChrootSetup : public aidl::com::android::server::art::BnDexoptChroot ndk::ScopedAStatus init() override; - ndk::ScopedAStatus tearDown() override; + ndk::ScopedAStatus tearDown(bool in_allowConcurrent) override; android::base::Result<void> Start(); diff --git a/dexopt_chroot_setup/dexopt_chroot_setup_test.cc b/dexopt_chroot_setup/dexopt_chroot_setup_test.cc index 1b4186f0dd..c5faca7f4e 100644 --- a/dexopt_chroot_setup/dexopt_chroot_setup_test.cc +++ b/dexopt_chroot_setup/dexopt_chroot_setup_test.cc @@ -89,7 +89,7 @@ class DexoptChrootSetupTest : public CommonArtTest { return; } scratch_dir_.reset(); - dexopt_chroot_setup_->tearDown(); + dexopt_chroot_setup_->tearDown(/*in_allowConcurrent=*/false); CommonArtTest::TearDown(); } @@ -184,17 +184,17 @@ TEST_F(DexoptChrootSetupTest, Run) { EXPECT_EQ(status.getExceptionCode(), EX_ILLEGAL_STATE); EXPECT_STREQ(status.getMessage(), "init must not be repeatedly called"); - ASSERT_STATUS_OK(dexopt_chroot_setup_->tearDown()); + ASSERT_STATUS_OK(dexopt_chroot_setup_->tearDown(/*in_allowConcurrent=*/false)); EXPECT_FALSE(std::filesystem::exists(DexoptChrootSetup::CHROOT_DIR)); // Check that `tearDown` can be repeatedly called too. - ASSERT_STATUS_OK(dexopt_chroot_setup_->tearDown()); + ASSERT_STATUS_OK(dexopt_chroot_setup_->tearDown(/*in_allowConcurrent=*/false)); // Check that `setUp` can be followed directly by a `tearDown`. ASSERT_STATUS_OK( dexopt_chroot_setup_->setUp(/*in_otaSlot=*/std::nullopt, /*in_mapSnapshotsForOta=*/false)); - ASSERT_STATUS_OK(dexopt_chroot_setup_->tearDown()); + ASSERT_STATUS_OK(dexopt_chroot_setup_->tearDown(/*in_allowConcurrent=*/false)); EXPECT_FALSE(std::filesystem::exists(DexoptChrootSetup::CHROOT_DIR)); } |