Open/create files that are opened with O_WRONLY with O_RDWR instead.
When the writeback cache for FUSE is enabled, the kernel may have to
generate read requests to fetch up-to-date pages for use in the cache
(in case of partial writes). This means that when we receive a request
to open or create a file with O_WRONLY, we need to open the underlying
file with O_RDWR.
Bug: 149039466
Test: atest FuseDaemonHostTest
Change-Id: I4a6f1f829b57d79dd8413d203783a4511d16d094
diff --git a/jni/FuseDaemon.cpp b/jni/FuseDaemon.cpp
index 1fa5ebe..282a088 100644
--- a/jni/FuseDaemon.cpp
+++ b/jni/FuseDaemon.cpp
@@ -853,7 +853,15 @@
return;
}
- const int fd = open(path.c_str(), fi->flags);
+ // With the writeback cache enabled, FUSE may generate READ requests even for files that
+ // were opened O_WRONLY; so make sure we open it O_RDWR instead.
+ int open_flags = fi->flags;
+ if (open_flags & O_WRONLY) {
+ open_flags &= ~O_WRONLY;
+ open_flags |= O_RDWR;
+ }
+
+ const int fd = open(path.c_str(), open_flags);
if (fd < 0) {
fuse_reply_err(req, errno);
return;
@@ -1362,8 +1370,16 @@
return;
}
+ // With the writeback cache enabled, FUSE may generate READ requests even for files that
+ // were opened O_WRONLY; so make sure we open it O_RDWR instead.
+ int open_flags = fi->flags;
+ if (open_flags & O_WRONLY) {
+ open_flags &= ~O_WRONLY;
+ open_flags |= O_RDWR;
+ }
+
mode = (mode & (~0777)) | 0664;
- int fd = open(child_path.c_str(), fi->flags, mode);
+ int fd = open(child_path.c_str(), open_flags, mode);
if (fd < 0) {
int error_code = errno;
// We've already inserted the file into the MP database before the