Merge "Retry opening loop device" am: c8f5cbb5b1
am: de841f6d89
am: dde25e9167
Change-Id: I14fc99509f8b5f83cc2dd0a035d1b127c581b027
This commit is contained in:
commit
c7da9acdce
1 changed files with 9 additions and 1 deletions
10
Loop.cpp
10
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;
|
||||
|
|
Loading…
Reference in a new issue