diff options
author | Daichi Hirono | 2016-11-14 18:31:21 -0600 |
---|---|---|
committer | Daichi Hirono | 2016-11-16 18:10:53 -0600 |
commit | 30e68088951f17ad54c1d15576835ff4eb622c4c (patch) | |
tree | 2798f1f86672712a3e16d35ca3e3bbf0c3046d09 /libappfuse | |
parent | 335502453d9b37c9c853dd3ac904d945b04e01ee (diff) | |
download | platform-system-core-30e68088951f17ad54c1d15576835ff4eb622c4c.tar.gz platform-system-core-30e68088951f17ad54c1d15576835ff4eb622c4c.tar.xz platform-system-core-30e68088951f17ad54c1d15576835ff4eb622c4c.zip |
Stops the loop when all files are closed.
The CL changes FuseBridgeLoop so that it exits when all files opened on
the AppFuse mount point are closed. Note that the client code will
unmount the FUSE mount point after the loop exits.
Bug: 32260320
Test: libappfuse_test
Change-Id: I4965fbb48de8a280c6306e70757a07376b1956a7
Diffstat (limited to 'libappfuse')
-rw-r--r-- | libappfuse/FuseBridgeLoop.cc | 23 | ||||
-rw-r--r-- | libappfuse/tests/FuseBridgeLoopTest.cc | 9 |
2 files changed, 28 insertions, 4 deletions
diff --git a/libappfuse/FuseBridgeLoop.cc b/libappfuse/FuseBridgeLoop.cc index acb963cfc..beee4a6f5 100644 --- a/libappfuse/FuseBridgeLoop.cc +++ b/libappfuse/FuseBridgeLoop.cc | |||
@@ -26,6 +26,7 @@ bool FuseBridgeLoop::Start( | |||
26 | base::unique_fd dev_fd(raw_dev_fd); | 26 | base::unique_fd dev_fd(raw_dev_fd); |
27 | base::unique_fd proxy_fd(raw_proxy_fd); | 27 | base::unique_fd proxy_fd(raw_proxy_fd); |
28 | fuse::FuseBuffer buffer; | 28 | fuse::FuseBuffer buffer; |
29 | size_t open_count = 0; | ||
29 | 30 | ||
30 | LOG(DEBUG) << "Start fuse loop."; | 31 | LOG(DEBUG) << "Start fuse loop."; |
31 | while (true) { | 32 | while (true) { |
@@ -71,8 +72,26 @@ bool FuseBridgeLoop::Start( | |||
71 | return false; | 72 | return false; |
72 | } | 73 | } |
73 | 74 | ||
74 | if (opcode == FUSE_INIT) { | 75 | switch (opcode) { |
75 | callback->OnMount(); | 76 | case FUSE_INIT: |
77 | callback->OnMount(); | ||
78 | break; | ||
79 | case FUSE_OPEN: | ||
80 | if (buffer.response.header.error == fuse::kFuseSuccess) { | ||
81 | open_count++; | ||
82 | } | ||
83 | break; | ||
84 | case FUSE_RELEASE: | ||
85 | if (open_count != 0) { | ||
86 | open_count--; | ||
87 | } else { | ||
88 | LOG(WARNING) << "Unexpected FUSE_RELEASE before opening a file."; | ||
89 | break; | ||
90 | } | ||
91 | if (open_count == 0) { | ||
92 | return true; | ||
93 | } | ||
94 | break; | ||
76 | } | 95 | } |
77 | } | 96 | } |
78 | } | 97 | } |
diff --git a/libappfuse/tests/FuseBridgeLoopTest.cc b/libappfuse/tests/FuseBridgeLoopTest.cc index bd503ebfb..e74d9e700 100644 --- a/libappfuse/tests/FuseBridgeLoopTest.cc +++ b/libappfuse/tests/FuseBridgeLoopTest.cc | |||
@@ -200,11 +200,16 @@ TEST_F(FuseBridgeLoopTest, FuseNotImpl) { | |||
200 | TEST_F(FuseBridgeLoopTest, Proxy) { | 200 | TEST_F(FuseBridgeLoopTest, Proxy) { |
201 | CheckProxy(FUSE_LOOKUP); | 201 | CheckProxy(FUSE_LOOKUP); |
202 | CheckProxy(FUSE_GETATTR); | 202 | CheckProxy(FUSE_GETATTR); |
203 | CheckProxy(FUSE_OPEN); | ||
204 | CheckProxy(FUSE_READ); | 203 | CheckProxy(FUSE_READ); |
205 | CheckProxy(FUSE_WRITE); | 204 | CheckProxy(FUSE_WRITE); |
206 | CheckProxy(FUSE_RELEASE); | ||
207 | CheckProxy(FUSE_FSYNC); | 205 | CheckProxy(FUSE_FSYNC); |
206 | |||
207 | // Invoke FUSE_OPEN and FUSE_RELEASE at last as the loop will exit when all files are closed. | ||
208 | CheckProxy(FUSE_OPEN); | ||
209 | CheckProxy(FUSE_RELEASE); | ||
210 | |||
211 | // Ensure the loop exits. | ||
212 | Close(); | ||
208 | } | 213 | } |
209 | 214 | ||
210 | } // namespace fuse | 215 | } // namespace fuse |