From 1dd5c4f78773ee5728f6183602f7b9b9407414ce Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 11 Jun 2019 14:51:25 -0700 Subject: [PATCH] Block and wait for /dev/block/loop to appear in case it was created asynchronously. Bug: 134711825 Test: StorageManagerTest Change-Id: Id8616804bba622226ca21b8eff0d3eb577b4b7e0 --- Loop.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Loop.cpp b/Loop.cpp index fa8f8ba..9fa876c 100644 --- a/Loop.cpp +++ b/Loop.cpp @@ -31,16 +31,20 @@ #include +#include + #include #include #include #include +#include #include #include "Loop.h" #include "VoldUtil.h" #include "sehandle.h" +using namespace std::literals; using android::base::StringPrintf; using android::base::unique_fd; @@ -74,6 +78,10 @@ int Loop::create(const std::string& target, std::string& out_device) { PLOG(ERROR) << "Failed to open " << target; return -errno; } + if (!android::fs_mgr::WaitForFile(out_device, 2s)) { + LOG(ERROR) << "Failed to find " << out_device; + return -ENOENT; + } unique_fd device_fd(open(out_device.c_str(), O_RDWR | O_CLOEXEC)); if (device_fd.get() == -1) { PLOG(ERROR) << "Failed to open " << out_device;