From cdc2a1c83575a349ee44035de8c3b38b8b401003 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Thu, 3 May 2012 13:49:46 -0700 Subject: Sleep to wait for dm to create node There appears to be a race condition from when the device mapper is asked to create a device and when it actually appears. When we moved ASECs to use Ext4, mount started winning the race more often. Just insert a sleep-retry loop here to counter-act this race. We should ideally look at the uevent replies, but it takes a bit more effort to separate them out. Change-Id: Ie8a5b36b1c9a26f2320a178d37312059d03a1281 --- VolumeManager.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/VolumeManager.cpp b/VolumeManager.cpp index 3a63a19..76febed 100644 --- a/VolumeManager.cpp +++ b/VolumeManager.cpp @@ -948,6 +948,19 @@ int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid) { } } + /* + * The device mapper node needs to be created. Sometimes it takes a + * while. Wait for up to 1 second. We could also inspect incoming uevents, + * but that would take more effort. + */ + int tries = 25; + while (tries--) { + if (!access(dmDevice, F_OK) || errno != ENOENT) { + break; + } + usleep(40 * 1000); + } + int result; if (sb.c_opts & ASEC_SB_C_OPTS_EXT4) { result = Ext4::doMount(dmDevice, mountPoint, true, false, true); -- cgit v1.1