From 9eb436716500d67d2df66409f23e397060618644 Mon Sep 17 00:00:00 2001 From: Ricky Wai Date: Sat, 15 Feb 2020 01:15:42 +0000 Subject: [PATCH] Retry deleting dm devices. For some reason this can be racy; until we understand the root cause, retry to unblock AdoptableHostTest. Bug: 149396179 Test: atest AdoptableHostTest no longer hangs Change-Id: I162ff8ad305535e7a4fab3d88f38b687b50cf4a3 --- model/PrivateVolume.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/model/PrivateVolume.cpp b/model/PrivateVolume.cpp index 9f1f089..75aa938 100644 --- a/model/PrivateVolume.cpp +++ b/model/PrivateVolume.cpp @@ -36,6 +36,7 @@ #include #include #include +#include using android::base::StringPrintf; @@ -68,8 +69,19 @@ status_t PrivateVolume::doCreate() { // Recover from stale vold by tearing down any old mappings auto& dm = dm::DeviceMapper::Instance(); - if (!dm.DeleteDeviceIfExists(getId())) { + // 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. + bool ret; + int tries = 10; + while (tries-- > 0) { + ret = dm.DeleteDeviceIfExists(getId()); + if (ret || errno != EBUSY) { + break; + } PLOG(ERROR) << "Cannot remove dm device " << getId(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + if (!ret) { return -EIO; } @@ -86,8 +98,19 @@ status_t PrivateVolume::doCreate() { status_t PrivateVolume::doDestroy() { auto& dm = dm::DeviceMapper::Instance(); - if (!dm.DeleteDevice(getId())) { + // 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. + bool ret; + int tries = 10; + while (tries-- > 0) { + ret = dm.DeleteDevice(getId()); + if (ret || errno != EBUSY) { + break; + } PLOG(ERROR) << "Cannot remove dm device " << getId(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + if (!ret) { return -EIO; } return DestroyDeviceNode(mRawDevPath);