aboutsummaryrefslogtreecommitdiffstats
path: root/lib/fuse_lowlevel.c
AgeCommit message (Collapse)AuthorLines
2024-06-04Rename struct fuse_req::ctr to ::ref_cntBernd Schubert-11/+11
ref_cnt should make the intention of this variable more clear.
2024-06-04Add support for no_interrupt (#956)yangyun50-9/+21
The function fuse_session_process_buf_int() would do much things for FUSE_INTERRUPT requests, even there are no FUSE_INTERRUPT requests: 1. check every non-FUSE_INTERRUPT request and add these requests to the linked list(se->list) under a big lock(se->lock). 2. the function fuse_free_req() frees every request and remove them from the linked list(se->list) under a bing lock(se->lock). These operations are not meaningful when there are no FUSE_INTERRUPT requests, and have a great impact on the performance of fuse filesystem because the big lock for each request. In some cases, FUSE_INTERRUPT requests are infrequent, even none at all. Besides, the user-defined filesystem may do nothing for FUSE_INTERRUPT requests. And the kernel side has the option "no_interrupt" in struct fuse_conn. This kernel option can be enabled by return ENOSYS in libfuse for the reply of FUSE_INTERRUPT request. But I don't find the code to enable the "no_interrupt" kernel option in libfuse. So add the no_interrupt support, and when this operaion is enabled: 1. remove the useless locking operaions and list operations. 2. return ENOSYS for the reply of FUSE_INTERRUPT request to inform the kernel to disable FUSE_INTERRUPT request.
2024-06-01Fix compatibility issue around fuse_custom_io->clone_fd (#953)legezywzh-4/+20
Fixes: 73cd124d0408 ("Add clone_fd to custom IO (#927)") Signed-off-by: Xiaoguang Wang <lege.wang@jaguarmicro.com>
2024-05-13Enable passthrough mode for read/write operations (#919)Amir Goldstein-0/+43
Add support for filesystem passthrough read/write of files. When the FUSE_PASSTHROUGH capability is enabled, the FUSE server may decide, while handling the "open" or "create" requests, if the given file can be accessed by that process in "passthrough" mode, meaning that all the further read and write operations would be forwarded by the kernel directly to the backing file rather than to the FUSE server. All requests other than read or write are still handled by the server. This allows for an improved performance on reads and writes, especially in the case of reads at random offsets, for which no (readahead) caching mechanism would help, reducing the performance gap between FUSE and native filesystem access. Extend also the passthrough_hp example with the new passthrough feature. This example opens a kernel backing file per FUSE inode on the first FUSE file open of that inode and closes the backing file on the release of the last FUSE file on that inode. All opens of the same inode passthrough to the same backing file. A combination of fi->direct_io and fi->passthrough is allowed. It means that read/write operations go directly to the server, but mmap is done on the backing file. This allows to open some fds of the inode in passthrough mode and some fd of the same inode in direct_io/passthrough_mmap mode. Signed-off-by: Alessio Balsini <balsini@android.com> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
2024-05-13Add in the libfuse version a program was compiled with (#942)Bernd Schubert-3/+30
The API stays the same, the libfuse version comes from inlined functions, which are defined fuse_lowlevel.h and fuse.h. As these inlined functions are defined in the header files they get added into the application, similar as if these were preprocessor macros. Macro vs inlined function is then just a style issue - I personally prefer the latter. fuse_session_new() -> static inlinei, in the application _fuse_session_new -> inside of libfuse fuse_new() -> static inline, in the application _fuse_new() -> inside of libfuse Note: Entirely untested is the fuse 30 api - we need a test for it. And we do not have any ABI tests at all. Signed-off-by: Bernd Schubert <bernd.schubert@fastmail.fm>
2024-05-10Handle NO_OPEN/NO_OPENDIR support automatically (#949)Josef Bacik-0/+4
If the file system doesn't provide a ->open or an ->opendir, and the kernel supports FUSE_CAP_NO_OPEN_SUPPORT or FUSE_CAP_NO_OPENDIR_SUPPORT, allow the implementation to set FUSE_CAP_NO_OPEN*_SUPPORT on conn->want in order to automatically get this behavior. Expand the documentation to be more explicit about the behavior of libfuse in the different cases WRT this capability. Signed-off-by: Josef Bacik <josef@toxicpanda.com>
2024-04-16fix max_write update in do_init() (#926)legezywzh-3/+3
If user updates conn->max_write in fuse_lowlevel_ops' init() method, do_init() will miss the "conn.max_write > bufsize - FUSE_BUFFER_HEADER_SIZE" judgment, and ->init method will be called after it, which obviously is a bug. Signed-off-by: Xiaoguang Wang <lege.wang@jaguarmicro.com> Co-authored-by: Xiaoguang Wang <lege.wang@jaguarmicro.com>
2024-03-29Add support for FUSE_CAP_HANDLE_KILLPRIV_V2Bernd Schubert-0/+4
This just adds in the basic handler, but does not use it yet in examples.
2024-03-21reset got_init after handling FUSE_DESTROY message (#910)legezywzh-0/+1
User may still need to mount same fuse filesystem after umounting it(In this case, the userspace filesystem server needs to keep live), and after handling FUSE_DESTROY message, new FUSE_INIT message may come, so need to reset got_init to be zero. Signed-off-by: Xiaoguang Wang <lege.wang@jaguarmicro.com>
2024-02-20remove duplicated fuse_chan_put() (#893)yangyun50-2/+0
2024-01-29add support for kernel flag FUSE_HAS_EXPIRE_ONLYHereThereBeDragons-1/+1
2024-01-20Add processing for FUSE_CAP_HANDLE_KILLPRIV and disable it by defaultbigbrotherwei-1/+2
'FUSE_CAP_HANDLE_KILLPRIV' is not enabled by default anymore, as that would be a sudden security issue introduced by a new ABI and API compatible libfuse version.
2024-01-10Don't set FUSE_CAP_PARALLEL_DIROPS by defaultMiklos Szeredi-1/+0
Allowing parallel dir operations could result in a crash in a filesystem implementation that is not prepared for this. To be safe keep this flag off by default (this is not a regression, since there was no public release where this flag wasn't ignored). If the filesystem wants better performance, then it should set this flag explicitly. Fixes: c9905341ea34 ("Pass FUSE_PARALLEL_DIROPS to kernel (#861)") Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2024-01-10Add FUSE_CAP_DIRECT_IO_ALLOW_MMAP and use in passthrough_hpBernd Schubert-0/+4
This is not called FUSE_CAP_DIRECT_IO_RELAX, as the kernel flag FUSE_DIRECT_IO_RELAX is supposed to be renamed to FUSE_DIRECT_IO_ALLOW_MMAP. The corresponding kernel patches just did not land yet.
2023-11-16Pass FUSE_PARALLEL_DIROPS to kernel (#861)fdinoff-0/+2
This tells the kernel that parallel lookup/readdir operations are supported. This is enabled by default but was not passed to the kernel so you always get the synchronized version.
2023-08-05Make errnum-verification more flexible (#824)ikbenlike-0/+5
Instead of hardcoding the value to check against, use a more dynamic method to verify the error number before passing it to the kernel.
2023-06-30Make expire only function fail if no kernel support (#789)HereThereBeDragons-5/+36
2023-04-11Update fuse_kernel.h to state of linux-6.3Bernd Schubert-1/+15
This syncs fuse_kernel.h to <linux-6.3>/include/uapi/linux/fuse.h Special handling is done for setxattr as in linux commit 52a4c95f4d24b struct fuse_setxattr_in was extended. Extended struct is only used when FUSE_SETXATTR_EXT is passed in FUSE_INIT reply.
2023-03-03Enable parallel direct writes on the same file.Dharmendra singh-0/+2
Right now fuse kernel serializes direct writes on the same file. This serialization is good for such FUSE implementations which rely on the inode lock to avoid any data inconsistency issues but it hurts badly such FUSE implementations which have their own mechanism of dealing with cache/data integrity and can handle parallel direct writes on the same file. This patch allows parallel direct writes on the same file to be enabled with the help of a flag FOPEN_PARALLEL_DIRECT_WRITES. FUSE implementations which want to use this feature can set this flag during fuse init. Default behaviour remains same i.e no parallel direct writes on the same file. Corresponding fuse kernel patch(Merged). https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.2&id=153524053bbb0d27bb2e0be36d1b46862e9ce74c
2023-02-09fuse_lowlevel.h: add more setattr flagsXiubo Li-0/+2
Such as for the xfstest-dev's generic/684 test case it will clear suid and sgid if the fallocate request is commited by an unprivileged user. The kernel fuse passed the ATTR_KILL_SUID/ATTR_KILL_SGID flags to userspace but it will be dropped. Signed-off-by: Xiubo Li <xiubli@redhat.com>
2023-01-28Install a the configure_file (config.h) and use in headersBernd Schubert-1/+1
This addresses: https://github.com/libfuse/libfuse/issues/724 HAVE_LIBC_VERSIONED_SYMBOLS configures the library if to use versioned symbols and is set at meson configuration time. External filesystems (the main target, actually) include fuse headers and the preprocessor then acts on HAVE_LIBC_VERSIONED_SYMBOLS. Problem was now that 'config.h' was not distributed with libfuse and so HAVE_LIBC_VERSIONED_SYMBOLS was never defined with external tools and the preprocessor did the wrong decision. This commit also increases the the minimal meson version, as this depends on meson feature only available in 0.50 <quote 'meson' > WARNING: Project specifies a minimum meson_ version '>= 0.42' but uses features which were added in newer versions: * 0.50.0: {'install arg in configure_file'} </quote> Additionally the config file has been renamed to "fuse_config.h" to avoid clashes - 'config.h' is not very specific.
2023-01-10Support application-defined I/O functions for FUSE fdTofik Sonono-9/+75
The io for FUSE requests and responses can now be further customized by allowing to write custom functions for reading/writing the responses. This includes overriding the splice io. The reason for this addition is that having a custom file descriptor is not sufficient to allow custom io. Different types of file descriptor require different mechanisms of io interaction. For example, some file descriptor communication has boundaries (SOCK_DGRAM, EOF, etc...), while other types of fd:s might be unbounded (SOCK_STREAMS, ...). For unbounded communication, you have to read the header of the FUSE request first, and then read the remaining packet data. Furthermore, the one read call does not necessarily return all the data expected, requiring further calls in a loop.
2023-01-06adding comments and capability discovery, enum for flags moved to top of fileHereThereBeDragons-0/+2
2023-01-06Initial patch provided by Miklos Szeredi <mszeredi@redhat.com>HereThereBeDragons-4/+14
2023-01-02Revert "libfuse custom communication interface"Nikolaus Rath-4/+0
This reverts commit 777663953382925c7403f0560c28ec9bbd14d7be.
2022-11-15libfuse custom communication interfacey-0/+4
libfuse can now be used without having a mount interface.
2022-09-08Use destroy_req instead of free to destroy fuse_reqFrank Dinoff-1/+3
If we get the interrupt before the fuse op, the fuse_req is deleted without decrementing the refcount on the cloned file descriptor. This leads to a leak of the cloned /dev/fuse file descriptor.
2022-04-17Set FUSE_INIT_EXT in fuse_init_out::flagsBernd Schubert-2/+5
It is better to tell the kernel that libfuse knows about the 64 bit flag extension.
2022-04-08Modify structures in libfuse to handle flags beyond 32 bits.Dharmendra Singh-36/+45
In fuse kernel, 'commit 53db28933e95 ("fuse: extend init flags")' made the changes to handle flags going beyond 32 bits but i think changes were not done in libfuse to handle the same. This patch prepares the ground in libfuse for incoming FUSE kernel patches (Atomic open + lookup) where flags went beyond 32 bits. It makes struct same as in fuse kernel resulting in name change of few fields.
2022-03-21Fix fd leak with clone_fdFrank Dinoff-3/+9
do_interrupt would destroy_req on the request without decrementing the channel's refcount. With clone_fd this could leak file descriptors if the worker thread holding the cloned fd was destroyed. (Only max_idle_threads are kept).
2022-01-03Add support for FOPEN_NOFLUSH flagAmir Goldstein-0/+2
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 <amir73il@gmail.com>
2020-10-29remove fuse_mutex_initRosen Penev-2/+2
This seems to have been added before 2006 to fix a uclibc bug. It doesn't seem to be the case anymore so just get rid of it. Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-09-20Allow caching symlinks in kernel page cache. (#551)Etienne Dublé-0/+4
This commit defines a new capability called `FUSE_CAP_CACHE_SYMLINKS`. It is off by default but you can now enable it by setting this flag in in the `want` field of the `fuse_conn_info` structure. When enabled, the kernel will save symlinks in its page cache, by making use of the feature introduced in kernel 4.20: https://github.com/torvalds/linux/commit/5571f1e65486be025f73fa6aa30fb03725d362a2
2020-08-28Suppress some bogus thread sanitizer warnings.Nikolaus Rath-1/+9
2020-08-09fuse_send_data_iov(): correctly calculate total buffer size.Nikolaus Rath-1/+1
Fixes: #538.
2020-07-10fuse_lowlevel: Move assert for se before dereferencing it with se->debug (#530)winndows-2/+1
Move assert for se before dereferencing it with se->debug. Signed-off-by: Liao Pingfang <liao.pingfang@zte.com.cn> Co-authored-by: Liao Pingfang <liao.pingfang@zte.com.cn>
2020-05-15Avoid closing se->fd twice in fuse_lowlevel.c (#516)Fabian Vogt-0/+1
If fuse_session_unmount is called before fuse_session_destroy, both would try to close(se->fd). Avoid that by resetting it in fuse_session_unmount.
2020-03-13Fix issue preventing using splice with reads (#505)Jean-Yves VET-8/+6
Context: SPLICE_WRITE is not used with regular buffers (i.e. when they are not file-descriptor backed buffers). There is a bug which assumes file descriptors are used. If the amount of data associated with those FD is lower than twice the page size, SPLICE_WRITE is not utilized. With regular buffers the aggregated size was always 0. Because vmsplice (splice user pages to/from a pipe) is called before splice in fuse_lowlevel.c, regular buffers would also work with splice. This patch prevents to fallback to non-splice enabled copies when itheir is no FD involved.
2020-01-02Fixed memory leak in fuse_session_new()Bill Zissimopoulos-1/+2
2019-11-29Kill off some proto_major < 6 checks (#476)Dr. David Alan Gilbert-5/+5
fuse_init already refuses to start if we're on major < 7 , so we can kill off checks for old major versions. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2019-11-27Added support for FUSE_EXPLICIT_INVAL_DATA to enable (#474)Albert Chen-0/+4
2019-11-03Implement lseek operation (#457)Yuri Per-0/+25
2019-09-04Introduce callback for loggingStefan Hajnoczi-47/+47
Introduce an API for custom log handler functions. This allows libfuse applications to send messages to syslog(3) or other logging systems. See include/fuse_log.h for details. Convert libfuse from fprintf(stderr, ...) to log_fuse(level, ...). Most messages are error messages with FUSE_LOG_ERR log level. There are also some debug messages which now use the FUSE_LOG_DEBUG log level. Note that lib/mount_util.c is used by both libfuse and fusermount3. Since fusermount3 does not link against libfuse, we cannot call fuse_log() from lib/mount_util.c. This file will continue to use fprintf(stderr, ...) until someone figures out how to split it up. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2019-08-29Avoid gcc 9.1 strncpy(3) warnings (#447)Stefan Hajnoczi-2/+2
Recent GCC releases have warnings related to common strncpy(3) bugs. These warnings can be avoided by explicitly NUL-terminating the buffer or using memcpy(3) when the intention is to copy just the characters without the NUL terminator. This commit fixes the following warnings: [1/27] Compiling C object 'test/9f86d08@@test_syscalls@exe/test_syscalls.c.o'. In function ‘test_socket’, inlined from ‘main’ at ../test/test_syscalls.c:1899:9: ../test/test_syscalls.c:1760:2: warning: ‘strncpy’ output may be truncated copying 108 bytes from a string of length 1023 [-Wstringop-truncation] 1760 | strncpy(su.sun_path, testsock, sizeof(su.sun_path)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [2/27] Compiling C object 'lib/76b5a35@@fuse3@sha/fuse.c.o'. ../lib/fuse.c: In function ‘add_name’: ../lib/fuse.c:968:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 968 | strncpy(s, name, len); | ^~~~~~~~~~~~~~~~~~~~~ ../lib/fuse.c:944:15: note: length computed here 944 | size_t len = strlen(name); | ^~~~~~~~~~~~ [3/27] Compiling C object 'lib/76b5a35@@fuse3@sha/fuse_lowlevel.c.o'. ../lib/fuse_lowlevel.c: In function ‘fuse_add_direntry’: ../lib/fuse_lowlevel.c:288:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 288 | strncpy(dirent->name, name, namelen); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/fuse_lowlevel.c:276:12: note: length computed here 276 | namelen = strlen(name); | ^~~~~~~~~~~~ ../lib/fuse_lowlevel.c: In function ‘fuse_add_direntry_plus’: ../lib/fuse_lowlevel.c:381:2: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] 381 | strncpy(dirent->name, name, namelen); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/fuse_lowlevel.c:366:12: note: length computed here 366 | namelen = strlen(name); | ^~~~~~~~~~~~ Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2019-07-23fuse-lowlevel: set pipe size to max (#438)Giuseppe Scrivano-0/+35
on failure to set the pipe size, set it to the maximum allowed by the kernel. If the first request required more than the maximum allowed, the can_grow flag would be reset thus preventing any further resize. Grow the pipe to the maximum allowed to increase the likelihood of using splice for successive requests instead of falling back to read/write. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-06-13fuse_lowlevel: Add max_pages support (#384)scosu-9/+21
Starting with kernel version 4.20 fuse supports a new property 'max_pages' which is the maximum number of pages that can be used per request. This can be set via an argument during initialization. This new property allows writes to be larger than 128k. This patch sets the property if the matching capability is set (FUSE_MAX_PAGES). It will also set max_write to 1MiB. Filesystems have the possibility to decrease this size by setting max_write to a smaller size. The max_pages and bufsize fields are adjusted accordingly. Cc: Constantine Shulyupin <const@MakeLinux.com> Signed-off-by: Markus Pargmann <scosu@quobyte.com>
2019-06-06Avoid pointer arithmetic with `void *`Michael Forney-1/+1
The pointer operand to the binary `+` operator must be to a complete object type. Since we are working with byte sizes, use `char *` instead.
2019-04-16Add documentation for opting out of opendir and releasedir (#391)Chad Austin-0/+2
2019-04-06Add support for in-kernel readdir caching.Nikolaus Rath-0/+2
Fixes: #394.
2019-04-06Delete FUSE_FSYNC_FDATASYNCNikolaus Rath-2/+2
This constant is not defined in the kernel, so it will be lost when fuse_kernel.h is not synchronized. Instead, the kernel just passes a flag value of "1", so for now we also use a literal in userspace.