From 1b498ac9b341e086562f54cc49bf035e19a94e1d Mon Sep 17 00:00:00 2001 From: Amir Goldstein Date: Sun, 24 Oct 2021 14:01:23 +0300 Subject: Add support for FOPEN_NOFLUSH flag Allow requesting from kernel to avoid flush on close at file open time. If kernel does not support FOPEN_NOFLUSH flag, the request will be ignored. For passthrough_hp example, request to avoid flush on close when writeback cache is disabled and file is opened O_RDONLY. Signed-off-by: Amir Goldstein --- include/fuse_common.h | 6 +++++- include/fuse_kernel.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/fuse_common.h b/include/fuse_common.h index ea4bdb0..d7481be 100644 --- a/include/fuse_common.h +++ b/include/fuse_common.h @@ -83,8 +83,12 @@ struct fuse_file_info { nothing when set by open()). */ unsigned int cache_readdir : 1; + /** Can be filled in by open, to indicate that flush is not needed + on close. */ + unsigned int noflush : 1; + /** Padding. Reserved for future use*/ - unsigned int padding : 25; + unsigned int padding : 24; unsigned int padding2 : 32; /** File handle id. May be filled in by filesystem in create, diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h index 018a00a..48f2000 100644 --- a/include/fuse_kernel.h +++ b/include/fuse_kernel.h @@ -238,12 +238,14 @@ struct fuse_file_lock { * FOPEN_NONSEEKABLE: the file is not seekable * FOPEN_CACHE_DIR: allow caching this directory * FOPEN_STREAM: the file is stream-like (no file position at all) + * FOPEN_NOFLUSH: don't flush data cache on close (unless FUSE_WRITEBACK_CACHE) */ #define FOPEN_DIRECT_IO (1 << 0) #define FOPEN_KEEP_CACHE (1 << 1) #define FOPEN_NONSEEKABLE (1 << 2) #define FOPEN_CACHE_DIR (1 << 3) #define FOPEN_STREAM (1 << 4) +#define FOPEN_NOFLUSH (1 << 5) /** * INIT request/reply flags -- cgit v1.2.3 From dad15aee26835240d72188179ba177a0bbafe659 Mon Sep 17 00:00:00 2001 From: Amir Goldstein Date: Sun, 5 Dec 2021 18:29:05 +0200 Subject: Add no_rofd_flush mount option To disable flush for read-only fd. Signed-off-by: Amir Goldstein --- include/fuse.h | 8 ++++++++ lib/fuse.c | 6 ++++++ 2 files changed, 14 insertions(+) (limited to 'include') diff --git a/include/fuse.h b/include/fuse.h index a273b15..9148688 100644 --- a/include/fuse.h +++ b/include/fuse.h @@ -247,6 +247,14 @@ struct fuse_config { */ int auto_cache; + /** + * By default, fuse waits for all pending writes to complete + * and calls the FLUSH operation on close(2) of every fuse fd. + * With this option, wait and FLUSH are not done for read-only + * fuse fd, similar to the behavior of NFS/SMB clients. + */ + int no_rofd_flush; + /** * The timeout in seconds for which file attributes are cached * for the purpose of checking if auto_cache should flush the diff --git a/lib/fuse.c b/lib/fuse.c index a95d7c1..cc5bb14 100644 --- a/lib/fuse.c +++ b/lib/fuse.c @@ -3272,6 +3272,10 @@ static void fuse_lib_open(fuse_req_t req, fuse_ino_t ino, if (f->conf.auto_cache) open_auto_cache(f, ino, path, fi); + + if (f->conf.no_rofd_flush && + (fi->flags & O_ACCMODE) == O_RDONLY) + fi->noflush = 1; } fuse_finish_interrupt(f, req, &d); } @@ -4653,6 +4657,7 @@ static const struct fuse_opt fuse_lib_opts[] = { FUSE_LIB_OPT("kernel_cache", kernel_cache, 1), FUSE_LIB_OPT("auto_cache", auto_cache, 1), FUSE_LIB_OPT("noauto_cache", auto_cache, 0), + FUSE_LIB_OPT("no_rofd_flush", no_rofd_flush, 1), FUSE_LIB_OPT("umask=", set_mode, 1), FUSE_LIB_OPT("umask=%o", umask, 0), FUSE_LIB_OPT("uid=", set_uid, 1), @@ -4705,6 +4710,7 @@ void fuse_lib_help(struct fuse_args *args) printf( " -o kernel_cache cache files in kernel\n" " -o [no]auto_cache enable caching based on modification times (off)\n" +" -o no_rofd_flush disable flushing of read-only fd on close (off)\n" " -o umask=M set file permissions (octal)\n" " -o uid=N set file owner\n" " -o gid=N set file group\n" -- cgit v1.2.3