From 26ad7b34d1ef287d1c76fa35b1ca880cd1637de4 Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Thu, 13 Feb 2020 16:20:52 +0100 Subject: [PATCH] Retry deleting dm devices. For some reason this can be racy; until we understand the root cause, retry to unblock presubmit. Bug: 149396179 Test: atest AdoptableHostTest no longer hangs Change-Id: I3fb4f1d966172bac2f6c52d41c4564f905765212 --- cryptfs.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cryptfs.cpp b/cryptfs.cpp index 337bdc2..c06de0a 100644 --- a/cryptfs.cpp +++ b/cryptfs.cpp @@ -64,6 +64,9 @@ #include #include +#include +#include + extern "C" { #include } @@ -1219,9 +1222,22 @@ static int create_crypto_blk_dev(struct crypt_mnt_ftr* crypt_ftr, const unsigned } static int delete_crypto_blk_dev(const std::string& name) { + bool ret; auto& dm = DeviceMapper::Instance(); - if (!dm.DeleteDevice(name)) { - SLOGE("Cannot remove dm-crypt device %s: %s\n", name.c_str(), strerror(errno)); + // TODO(b/149396179) there appears to be a race somewhere in the system where trying + // to delete the device fails with EBUSY; for now, work around this by retrying. + int tries = 5; + while (tries-- > 0) { + ret = dm.DeleteDevice(name); + if (ret || errno != EBUSY) { + break; + } + SLOGW("DM_DEV Cannot remove dm-crypt device %s: %s, retrying...\n", name.c_str(), + strerror(errno)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + if (!ret) { + SLOGE("DM_DEV Cannot remove dm-crypt device %s: %s\n", name.c_str(), strerror(errno)); return -1; } return 0;