aboutsummaryrefslogtreecommitdiffstats
path: root/example/passthrough_fh.c
diff options
context:
space:
mode:
authoryangyun <yangyun50@huawei.com>2024-02-23 14:16:05 +0800
committeryangyun <yangyun50@huawei.com>2024-02-26 09:32:29 +0800
commitc45863318889fa6344534537c7ef91a37b3fba32 (patch)
tree4d829004b7be50dee6bdb43381efa5a063f8ba14 /example/passthrough_fh.c
parentfce970c313bf25ba9ae5b6a335e3293736df3d48 (diff)
downloadlibfuse-c45863318889fa6344534537c7ef91a37b3fba32.tar.gz
Enable direct IO for passthrough examples when open has flag O_DIRECT
Shared locks (parallel_direct_writes) cannot be enabled for O_DIRECT, as O_DIRECT may be set past file open time with fcntl(fd, F_SETFD, ...). Kernel side fuse has precautions for shared lock direct-IO (direct_io in libfuse), as it needs an exclusive inode lock when direct and page cache IO happend at the same time. In order to enjoy the parallel_direct_writes feature (i.e., get a shared lock, not exclusive lock) for writes to the same file), direct_io is needed. The feature direct_io is corresponding to FOPEN_DIRECT_IO in fuse kernel. FOPEN_DIRECT_IO and O_DIRECT are not entirely the same as described above. So enable direct_io (i.e., FOPEN_DIRECT_IO in fuse kernel) to enjoy parallel direct_writes. Some patches related to FOPEN_DIRECT_IO and O_DIRECT are below: https://lore.kernel.org/all/753d6823-e984-4730-a126-d66b65ea772c@ddn.com
Diffstat (limited to 'example/passthrough_fh.c')
-rw-r--r--example/passthrough_fh.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/example/passthrough_fh.c b/example/passthrough_fh.c
index ec426a8..701d59e 100644
--- a/example/passthrough_fh.c
+++ b/example/passthrough_fh.c
@@ -384,6 +384,14 @@ static int xmp_open(const char *path, struct fuse_file_info *fi)
if (fd == -1)
return -errno;
+ /* Enable direct_io when open has flags O_DIRECT to enjoy the feature
+ parallel_direct_writes (i.e., to get a shared lock, not exclusive lock,
+ for writes to the same file). */
+ if (fi->flags & O_DIRECT) {
+ fi->direct_io = 1;
+ fi->parallel_direct_writes = 1;
+ }
+
fi->fh = fd;
return 0;
}