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
This commit is contained in:
Ricky Wai 2020-02-15 01:15:42 +00:00
parent 8b31810922
commit 9eb4367165

View file

@ -36,6 +36,7 @@
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <thread>
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);