Merge "Fix Deadlock Issue On AppFuseBridge" am: 1e03ef5ac9
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1219563 Change-Id: I5fddba76878a64f9e361151ae5b15bd821179b02
This commit is contained in:
commit
b82ec57b44
2 changed files with 17 additions and 3 deletions
|
|
@ -311,6 +311,8 @@ class BridgeEpollController : private EpollController {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::recursive_mutex FuseBridgeLoop::mutex_;
|
||||||
|
|
||||||
FuseBridgeLoop::FuseBridgeLoop() : opened_(true) {
|
FuseBridgeLoop::FuseBridgeLoop() : opened_(true) {
|
||||||
base::unique_fd epoll_fd(epoll_create1(EPOLL_CLOEXEC));
|
base::unique_fd epoll_fd(epoll_create1(EPOLL_CLOEXEC));
|
||||||
if (epoll_fd.get() == -1) {
|
if (epoll_fd.get() == -1) {
|
||||||
|
|
@ -328,7 +330,7 @@ bool FuseBridgeLoop::AddBridge(int mount_id, base::unique_fd dev_fd, base::uniqu
|
||||||
|
|
||||||
std::unique_ptr<FuseBridgeEntry> bridge(
|
std::unique_ptr<FuseBridgeEntry> bridge(
|
||||||
new FuseBridgeEntry(mount_id, std::move(dev_fd), std::move(proxy_fd)));
|
new FuseBridgeEntry(mount_id, std::move(dev_fd), std::move(proxy_fd)));
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||||
if (!opened_) {
|
if (!opened_) {
|
||||||
LOG(ERROR) << "Tried to add a mount to a closed bridge";
|
LOG(ERROR) << "Tried to add a mount to a closed bridge";
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -372,7 +374,7 @@ void FuseBridgeLoop::Start(FuseBridgeLoopCallback* callback) {
|
||||||
const bool wait_result = epoll_controller_->Wait(bridges_.size(), &entries);
|
const bool wait_result = epoll_controller_->Wait(bridges_.size(), &entries);
|
||||||
LOG(VERBOSE) << "Receive epoll events";
|
LOG(VERBOSE) << "Receive epoll events";
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||||
if (!(wait_result && ProcessEventLocked(entries, callback))) {
|
if (!(wait_result && ProcessEventLocked(entries, callback))) {
|
||||||
for (auto it = bridges_.begin(); it != bridges_.end();) {
|
for (auto it = bridges_.begin(); it != bridges_.end();) {
|
||||||
callback->OnClosed(it->second->mount_id());
|
callback->OnClosed(it->second->mount_id());
|
||||||
|
|
@ -385,5 +387,13 @@ void FuseBridgeLoop::Start(FuseBridgeLoopCallback* callback) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FuseBridgeLoop::Lock() {
|
||||||
|
mutex_.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FuseBridgeLoop::Unlock() {
|
||||||
|
mutex_.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace fuse
|
} // namespace fuse
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,10 @@ class FuseBridgeLoop final {
|
||||||
// thread from one which invokes |Start|.
|
// thread from one which invokes |Start|.
|
||||||
bool AddBridge(int mount_id, base::unique_fd dev_fd, base::unique_fd proxy_fd);
|
bool AddBridge(int mount_id, base::unique_fd dev_fd, base::unique_fd proxy_fd);
|
||||||
|
|
||||||
|
static void Lock();
|
||||||
|
|
||||||
|
static void Unlock();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool ProcessEventLocked(const std::unordered_set<FuseBridgeEntry*>& entries,
|
bool ProcessEventLocked(const std::unordered_set<FuseBridgeEntry*>& entries,
|
||||||
FuseBridgeLoopCallback* callback);
|
FuseBridgeLoopCallback* callback);
|
||||||
|
|
@ -60,7 +64,7 @@ class FuseBridgeLoop final {
|
||||||
std::map<int, std::unique_ptr<FuseBridgeEntry>> bridges_;
|
std::map<int, std::unique_ptr<FuseBridgeEntry>> bridges_;
|
||||||
|
|
||||||
// Lock for multi-threading.
|
// Lock for multi-threading.
|
||||||
std::mutex mutex_;
|
static std::recursive_mutex mutex_;
|
||||||
|
|
||||||
bool opened_;
|
bool opened_;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue