aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--src/bindfs.15
-rw-r--r--src/bindfs.c15
3 files changed, 22 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 1d5d982..bb20c1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2022-04-03 Martin Pärtel <martin dot partel at gmail dot com>
+
+ * Added --direct-io (issue #110, thanks @DUOLabs333)
+
2021-02-15 Martin Pärtel <martin dot partel at gmail dot com>
* Fixed build on old compilers by adhering more strictly to C99.
diff --git a/src/bindfs.1 b/src/bindfs.1
index b681e44..db2e4fe 100644
--- a/src/bindfs.1
+++ b/src/bindfs.1
@@ -389,6 +389,11 @@ otherwise thread-safe, there is currently a race condition that may pose
a security risk for some use cases. See \fB\%BUGS\fP below.
.TP
+.B \-\-direct\-io, \-o direct\-io
+Forces each read/write operation to be forwarded 1:1 to the underlying FS,
+disabling batching and caching by the kernel.
+
+.TP
.B \-\-forward\-odirect=\fIalignment\fP, \-o forward\-odirect=\fIalignment\fP
Enable experimental \fBO_DIRECT\fP forwarding, with all read/write requests rounded
to the given alignment (in bytes). By default, the \fBO_DIRECT\fP flag is
diff --git a/src/bindfs.c b/src/bindfs.c
index bc24154..fd09704 100644
--- a/src/bindfs.c
+++ b/src/bindfs.c
@@ -203,6 +203,8 @@ static struct Settings {
#ifdef __linux__
int forward_odirect;
size_t odirect_alignment;
+
+ bool direct_io;
#endif
uid_t uid_offset;
@@ -689,6 +691,7 @@ static void *bindfs_init()
cfg->entry_timeout = 0;
cfg->attr_timeout = 0;
cfg->negative_timeout = 0;
+ cfg->direct_io = settings.direct_io;
#endif
assert(settings.permchain != NULL);
@@ -1283,6 +1286,9 @@ static int bindfs_open(const char *path, struct fuse_file_info *fi)
flags &= ~O_DIRECT;
}
#endif
+#ifndef HAVE_FUSE_3 // With FUSE 3, we set this in bindfs_init
+ fi->direct_io = settings.direct_io;
+#endif
fd = open(real_path, flags);
free(real_path);
@@ -1790,7 +1796,8 @@ enum OptionKey {
OPTKEY_ENABLE_IOCTL,
OPTKEY_HIDE_HARD_LINKS,
OPTKEY_RESOLVE_SYMLINKS,
- OPTKEY_BLOCK_DEVICES_AS_FILES
+ OPTKEY_BLOCK_DEVICES_AS_FILES,
+ OPTKEY_DIRECT_IO
};
static int process_option(void *data, const char *arg, int key,
@@ -1898,7 +1905,9 @@ static int process_option(void *data, const char *arg, int key,
case OPTKEY_BLOCK_DEVICES_AS_FILES:
settings.block_devices_as_files = 1;
return 0;
-
+ case OPTKEY_DIRECT_IO:
+ settings.direct_io = true;
+ return 0;
case OPTKEY_NONOPTION:
if (!settings.mntsrc) {
if (strncmp(arg, "/proc/", strlen("/proc/")) == 0) {
@@ -2388,6 +2397,7 @@ int main(int argc, char *argv[])
OPT2("--delete-deny", "delete-deny", OPTKEY_DELETE_DENY),
OPT2("--rename-deny", "rename-deny", OPTKEY_RENAME_DENY),
+ OPT2("--direct-io", "direct-io", OPTKEY_DIRECT_IO),
OPT2("--hide-hard-links", "hide-hard-links", OPTKEY_HIDE_HARD_LINKS),
OPT2("--resolve-symlinks", "resolve-symlinks", OPTKEY_RESOLVE_SYMLINKS),
@@ -2455,6 +2465,7 @@ int main(int argc, char *argv[])
#ifdef __linux__
settings.forward_odirect = 0;
settings.odirect_alignment = 0;
+ settings.direct_io = false;
#endif
atexit(&atexit_func);