Wait for dm device to be ready before format
It can sometimes take a moment for the dm-device to appear after
creation, causing operations on it such as formatting to fail.
Ensure the device exists before create_crypto_blk_dev returns.
Test: adb sm set-virtual-disk true and format as adoptable.
Bug: 117586466
Change-Id: Id8f571b551f50fc759e78d917e4ac3080e926722
Merged-In: Id8f571b551f50fc759e78d917e4ac3080e926722
diff --git a/cryptfs.cpp b/cryptfs.cpp
index 6e449ac..5be29be 100644
--- a/cryptfs.cpp
+++ b/cryptfs.cpp
@@ -30,6 +30,7 @@
#include "Keymaster.h"
#include "Process.h"
#include "ScryptParameters.h"
+#include "Utils.h"
#include "VoldUtil.h"
#include "VolumeManager.h"
#include "secontext.h"
@@ -73,6 +74,8 @@
#include <crypto_scrypt.h>
}
+using namespace std::chrono_literals;
+
#define UNUSED __attribute__((unused))
#define DM_CRYPT_BUF_SIZE 4096
@@ -1099,6 +1102,12 @@
goto errout;
}
+ /* Ensure the dm device has been created before returning. */
+ if (android::vold::WaitForFile(crypto_blk_name, 1s) < 0) {
+ // WaitForFile generates a suitable log message
+ goto errout;
+ }
+
/* We made it here with no errors. Woot! */
retval = 0;