summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Rosenberg <drosen@google.com>2019-04-02 15:52:12 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-04-02 15:52:12 -0700
commitc7da9acdce329fa0565c025b6a0410baf61450ef (patch)
tree0fb12223f6a574ba3c3e3883edc640312e02cd5f
parentcd1f06f6ec6a144a6d361877b2a05969efb128f9 (diff)
parentdde25e9167ff7ba4c7e7d3eb35827e88f502c6af (diff)
downloadvold-c7da9acdce329fa0565c025b6a0410baf61450ef.tar.gz
Merge "Retry opening loop device" am: c8f5cbb5b1 am: de841f6d89
am: dde25e9167 Change-Id: I14fc99509f8b5f83cc2dd0a035d1b127c581b027
-rw-r--r--Loop.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/Loop.cpp b/Loop.cpp
index 4926ea8c..fa8f8ba2 100644
--- a/Loop.cpp
+++ b/Loop.cpp
@@ -45,6 +45,7 @@ using android::base::StringPrintf;
using android::base::unique_fd;
static const char* kVoldPrefix = "vold:";
+static constexpr size_t kLoopDeviceRetryAttempts = 3u;
int Loop::create(const std::string& target, std::string& out_device) {
unique_fd ctl_fd(open("/dev/loop-control", O_RDWR | O_CLOEXEC));
@@ -61,7 +62,14 @@ int Loop::create(const std::string& target, std::string& out_device) {
out_device = StringPrintf("/dev/block/loop%d", num);
- unique_fd target_fd(open(target.c_str(), O_RDWR | O_CLOEXEC));
+ unique_fd target_fd;
+ for (size_t i = 0; i != kLoopDeviceRetryAttempts; ++i) {
+ target_fd.reset(open(target.c_str(), O_RDWR | O_CLOEXEC));
+ if (target_fd.get() != -1) {
+ break;
+ }
+ usleep(50000);
+ }
if (target_fd.get() == -1) {
PLOG(ERROR) << "Failed to open " << target;
return -errno;