Commit Graph

828 Commits

Author SHA1 Message Date
gandalfs_cat
54b8cd6757 high-level: add fmask and dmask options
dmask: umask applied to directories
fmask: umask applied to non-directories

to get "typical" permission bits for regular files (0644) and directories (0755), a single
umask option is not sufficient (or well, it isn't the way fuse implements it)

there is precident for separate umask and dmask options in other
filesystems (see for example fat: https://github.com/torvalds/linux/tree/master/fs/fat)

this addition should not affect backward-compatibility; the original
umask option retains the same meaning, but non-zero fmask or
dmask will override it.
2024-07-03 12:50:06 +02:00
Bernd Schubert
f88e08f34d Add nullptr check in fuse_session_mount
The pointer did not have any sanity check.

Addresses https://github.com/libfuse/libfuse/issues/979
2024-06-25 11:34:16 +02:00
Miklos Szeredi
29f621af8d libfuse: null-terminate buffer in fuse_req_getgroups()
After reading the file /proc/$PID/task/$PID/status the buffer wasn't
terminated with a null character.  This could theoretically lead to buffer
overrun by the subsequent strstr() call.

Since the contents of the proc file are guaranteed to contain the pattern
that strstr is looking for, this doesn't happen in normal situations.

Add null termination for robustness.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2024-06-13 16:39:54 +02:00
yangyun
8bd873cbcc fix useless fuse_init_intr_signal in high-level api
The code `fuse_init_intr_signal` in `_fuse_new_317` is useless
since commit 8ee553dac ("fuse_new(): don't accept options that
don't make sense for end-users") has remove the conf.intr option
for end-users. The conf.intr is always zero (i.e., disabled) here.

Move `fuse_init_intr_signal` after the user-defined `init()` function,
so that conf.intr and conf.intr_signal has been configured by the user.
2024-06-11 09:47:31 +02:00
Bernd Schubert
153d65ff6b Rename struct fuse_req::ctr to ::ref_cnt
ref_cnt should make the intention of this variable more clear.
2024-06-04 14:00:55 +02:00
Bernd Schubert
d44162534c Make struct fuse_req::ctr a C11 _Atomic
The variable is not modified exclusively with locks since commit
cef8c8b249 ("Add support for no_interrupt") anymore.
That commit is safe, but might be error prone to future updates.
Changing it to a C11 _Atomic should avoid issues.
2024-06-04 13:59:42 +02:00
yangyun50
cef8c8b249
Add support for no_interrupt (#956)
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-04 13:50:48 +02:00
legezywzh
949944ff3b
Fix compatibility issue around fuse_custom_io->clone_fd (#953)
Fixes: 73cd124d04 ("Add clone_fd to custom IO (#927)")

Signed-off-by: Xiaoguang Wang <lege.wang@jaguarmicro.com>
2024-06-01 23:18:35 +02:00
Bernd Schubert
251d2fb0e1
Remove most includes in compat.c (#954)
compat.c is supposed to be standalone to provide compat ABI symbols.
Including fuse header files can cause conflicts - just the opposite
of what compat.c was made for.
2024-05-27 15:24:10 +02:00
Amir Goldstein
eca63dab45
Enable passthrough mode for read/write operations (#919)
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-13 15:30:25 +02:00
Bernd Schubert
58f85bfa9b
Add in the libfuse version a program was compiled with (#942)
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-13 12:32:06 +02:00
Josef Bacik
2bdec0bc22
Handle NO_OPEN/NO_OPENDIR support automatically (#949)
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-05-10 17:52:20 +02:00
Bernd Schubert
b701673e74
Fix missing fuse_loop_cfg_destroy() in fuse_session_loop_mt_31 (#944)
All credits to Miklos Szeredi <miklos@szeredi.hu> for spotting
this.

Signed-off-by: Bernd Schubert <bernd.schubert@fastmail.fm>
2024-05-05 13:09:56 +02:00
Bernd Schubert
45effd5db8
[libFuse 3.16.2]Compilation failure on freeBSD #936 (#938)
Despite the creation of the header file fuse_config.h during LibFUSE
version 3.16.2's Meson build process, the BSD mount_bsd.c file continues to reference config.h. Consequently, this discrepancy results in compilation failures.

FIX : Point the mount_bsd.c to correct header.
2024-04-25 17:09:05 +02:00
legezywzh
73cd124d04
Add clone_fd to custom IO (#927)
Define a new clone_fd() helper for fuse_custom_io, users
can implement their own clone fd logic.

Signed-off-by: Xiaoguang Wang <lege.wang@jaguarmicro.com>
2024-04-18 11:29:35 +02:00
legezywzh
080077369e
fix max_write update in do_init() (#926)
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-04-16 17:23:57 +02:00
Bernd Schubert
3e283a1bcb Add support for FUSE_CAP_HANDLE_KILLPRIV_V2
This just adds in the basic handler, but does not
use it yet in examples.
2024-03-29 13:04:45 +01:00
farlongsignal
dd95d13aac
fix readdirplus when filler is called with zero offset (#896)
fixes #235

In fill_dir_plus(), there's a lookup for caching dirent attributes.
However, when offset = 0 the cache metadata from the lookup is lost
as only the entry attributes are passed when added to the list. Kernel
doesn't cache the attributes since .ino = 0.

This change moves the entry lookup to happen just before the relevant
fuse_add_direntry_plus() calls
2024-03-24 21:54:19 +01:00
legezywzh
f01d9277cb
reset got_init after handling FUSE_DESTROY message (#910)
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-03-21 10:02:05 +01:00
Bernd Schubert
e48c71d445 Add glibc backtrace to signal handler
It is very hard to see in github tests what is actually failing
with signals - add the gnu-libc backtrace handler.
2024-03-20 12:37:17 +01:00
Bernd Schubert
290c65b1ad posix_spawn style updates
- This adds a wrapper function for the call sequence
of posix_spawn and posix_spawnp.
- Replaces perror() with fuse_log - the latter
can be redirected through the file system log function
and gives better end user friendly output
- other minor changes, like variable renames
- no functional change
2024-03-07 11:56:30 +01:00
Matthias Goergens
bb9cecbf67 Use posix_spawn instead of fork+exec
Client code might allocate a lot of memory before starting the mount.
Fork is slow for processes that are using a lot of memory.  But
posix_spawn fixes that.

Another issue with fork is if the process is also doing RDMA - this
might lead to data corruption, as least if memory used for RDMA
is not marked with MADV_DONTFORK.  At least with linux kernels
before 5.12.
Also see https://blog.nelhage.com/post/a-cursed-bug/ for more details

Change by Bernd:
This also prepares the new fusermount option "--comm-fd", but keeps
the previous way to pass the parameter as env variable. In a future
release (exact data to be determined) we are going to remove usage
of the env variable and will switch to the new parameter.
2024-03-07 11:56:04 +01:00
Matthew
74b1df2e84
Passthrough options starting with "x-" to mtab (#894)
This implements #651, tested with bindfs.

"x-*" options are comments meant to be interpreted by userspace.

#651 is about some 3rd party mount options like 'x-gvfs-notrash'.

This also removes the test if /etc/mtab is a symlink.

This test was added in commit 5f28cd15ab
and the corresponding ChangeLog entry in this commit points to mount
issues for read-only mtab.

However, in all recent Linux distributions /etc/mtab is a symlink to
/proc/self/mounts and never writable. In fact, util-linux 2.39
(libmount) entirely removed support for a writable mtab.

At least since util-linux 2.19 (10-Feb-2011) /run/mount/utab is used
as replacement for userspace mount entries..
2024-02-24 07:56:49 +01:00
yangyun50
402c8fff58
remove duplicated fuse_chan_put() (#893) 2024-02-20 11:52:39 +01:00
HereThereBeDragons
54007eedde add support for kernel flag FUSE_HAS_EXPIRE_ONLY 2024-01-29 08:43:58 +00:00
bigbrotherwei
0c12204145 Add processing for FUSE_CAP_HANDLE_KILLPRIV and disable it by default
'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-20 14:08:07 +00:00
Miklos Szeredi
2c736f516f Don't set FUSE_CAP_PARALLEL_DIROPS by default
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: c9905341ea ("Pass FUSE_PARALLEL_DIROPS to kernel (#861)")
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2024-01-10 21:11:37 +00:00
Bernd Schubert
22741f5582 Add FUSE_CAP_DIRECT_IO_ALLOW_MMAP and use in passthrough_hp
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.
2024-01-10 20:59:03 +00:00
fdinoff
c9905341ea
Pass FUSE_PARALLEL_DIROPS to kernel (#861)
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-11-16 11:23:20 +00:00
legezywzh
c814e3fac0
fuse_clone_chan: avoid additional FD_CLOEXEC setting if O_CLOEXEC defined (#852)
Since open(2) has been called with O_CLOEXEC flag if defined.

Signed-off-by: Xiaoguang Wang <lege.wang@jaguarmicro.com>
Co-authored-by: Xiaoguang Wang <lege.wang@jaguarmicro.com>
2023-10-25 12:19:39 +01:00
ikbenlike
7b9e7eeec6
Make errnum-verification more flexible (#824)
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-08-05 21:39:09 +01:00
Aleksandr Mikhailov
98eb808904
Pass cache_readdir and keep_cache from high level API (#822)
* Pass cache_readdir and keep_cache from high level API

* Update ChangeLog.rst
2023-08-03 18:01:46 +01:00
Bernd Schubert
624783d73b
Allow linking with mold / fix the version script (#814)
This fixes issue https://github.com/libfuse/libfuse/issues/810
and should avoid mold linking errors.
Commit d4e294b removed made fuse_register_module() a static
function, but forgot to remove it from the version script.

Commit fe4f942 introduced copy_file_range to libfuse and
added the non-exiting (neither declared nor defined) function
fuse_reply_copy_file_range() to the version script. Kernel
side just exects an integer reply how much was copied, using
fuse_reply_write() as in fuse_lib_copy_file_range() is sufficient
and no extra function is needed.

Co-authored-by: Bernd Schubert <bschubert@ddn.com>
2023-07-07 16:18:38 +01:00
HereThereBeDragons
51bc827df8
Make expire only function fail if no kernel support (#789) 2023-06-30 13:57:06 +01:00
Matthias Görgens
30a300a848
Remove unnecessary _GNU_SOURCE in fuse.c (#787)
We stopped using pthread_rwlock_t in 3fecccca98, so we don't need `_GNU_SOURCE` anymore in `fuse.c`
2023-06-08 08:26:54 +01:00
Nikolaus Rath
dba6b3983a Do not pass unsupported mount options to the kernel.
The filesystem daemon is responsible for implementing eg. st_atime updates, so passing
options like relatime to the kernel results in them being silently ignored. Instead, such
options need to be interpreted (and filtered out) by the filesystem daemon.
2023-05-12 23:27:43 +01:00
Peri
bb1890afd7
Fix issue #746. (#782)
Added a secondary check in fuse_lib_unlink() after hide_node()
to check again under a lock if the (now hidden) file is still open.
If not then delete it.

This should synchronise fuse_lib_unlink() with fuse_lib_release(),
when nullpath_ok is set.
2023-05-11 02:38:46 +01:00
Matthias Görgens
fcd293f675
Fix memory leak in high level API (#781)
Previously, in the high level API if we received a signal between
setting up signal handlers and processing INIT, we would leak

```
$ ./example/hello -s -d -f mountpoint/
[9/9] Linking target example/hello_ll
FUSE library version: 3.14.1
nullpath_ok: 0

=================================================================
==178330==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 352 byte(s) in 1 object(s) allocated from:
    #0 0x7fbb19abf411 in __interceptor_calloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:77
    #1 0x7fbb1a0efd3b in fuse_fs_new ../lib/fuse.c:4814
    #2 0x7fbb1a0f02b5 in fuse_new_31 ../lib/fuse.c:4913
    #3 0x7fbb1a10ec5e in fuse_main_real ../lib/helper.c:345
    #4 0x5625db8ab418 in main ../example/hello.c:176
    #5 0x7fbb1983c78f  (/usr/lib/libc.so.6+0x2378f)

SUMMARY: AddressSanitizer: 352 byte(s) leaked in 1 allocation(s).
```

That's because `fuse_lowlevel.c`s `fuse_session_destroy` would only call
the user supplied `op.destroy`, if INIT had been processed, but the high
level API relied on `op.destroy` to free `f->fs`.

This patch moves the freeing into `fuse_destroy` that will always be
called by our high-level API.
2023-04-14 12:19:03 +01:00
Matthias Görgens
7297044ada
Fuse mount: make auto_unmount compatible with suid/dev mount options (#762)
* Fuse mount: make auto_unmount compatible with suid/dev mount options

> When you run as root, fuse normally does not call fusermount but uses
> the mount system call directly. When you specify auto_unmount, it goes
> through fusermount instead. However, fusermount is a setuid binary that
> is normally called by regular users, so it cannot in general accept suid
> or dev options.

In this patch, we split up how fuse mounts as root when `auto_unmount`
is specified.

First, we mount using system calls directly, then we reach out to
fusermount to set up auto_unmount only (with no actual mounting done in
fusermount).

Fixes: #148
2023-04-12 08:39:32 +01:00
Bernd Schubert
681a0c1178 Update fuse_kernel.h to state of linux-6.3
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-04-11 19:54:59 +01:00
Giulio Benetti
c60a90b739
Fix MS_LAZYTIME not defined on uclibc and move all MS_* and UMOUNT_* (#753)
as well as <sys/mount.h> inclusion to new fuse_mount_compat.h file.

Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
2023-04-06 12:37:57 +01:00
Matthias Goergens
f2144c6c3a Fix use-after-free warning
When building, I get the following warning:

```bash
$ ninja
[18/71] Compiling C object lib/libfuse3.so.3.14.1.p/modules_iconv.c.o
../lib/modules/iconv.c: In function ‘iconv_convpath’:
../lib/modules/iconv.c:85:38: warning: pointer ‘newpath’ may be used after ‘realloc’ [-Wuse-after-free]
   85 |                         p = tmp + (p - newpath);
      |                                   ~~~^~~~~~~~~~
../lib/modules/iconv.c:80:31: note: call to ‘realloc’ here
   80 |                         tmp = realloc(newpath, newpathlen + 1);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[71/71] Linking target example/passthrough_hp
```

It's a false positive,  I thinks.  But it's also easy to silence this
warning with a small refactor.
2023-03-28 21:32:00 +01:00
Bernd Schubert
81ad52c7db Add more time mount options to fusermount / fix lazytime
Previous patch had forgotten fusermount. And also had "lazyatime"
instead of "lazytime".
2023-03-20 09:00:14 +00:00
Bernd Schubert
1e66c92153 Add more time mount options
These are especially needed for xfstests, but also
useful in general.
2023-03-19 15:13:57 +00:00
Sarath Lakshman
ab5ca07af0 Fix max_threads command line parameter propagation
The fuse_main_real() method doesn't apply the max_threads parameter
parsed through the commandline arguments. This commit fixes the wiring
of max_threads argument.
2023-03-11 17:06:21 +00:00
Dharmendra singh
a5eb7f2a01 Enable parallel direct writes on the same file.
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-03-03 12:41:49 +00:00
Bernd Schubert
2da03e3898 Avoid max-idle threads warning
If a program with API before 312 did not set
max_idle_threads the new default from
fuse_parse_cmdline_312() is applied, which sets
UINT_MAX (-1).

Later in compat fuse_session_loop_mt_32 the old
config v1 struct is converted and that conversion
prints a warning if the default unset value was used.

This could have also happened to programs using the current
API, which just apply values struct fuse_cmdline_opts,
without checking if the defaults are set.
2023-02-20 10:14:17 +00:00
Xiubo Li
418b7efca9 fuse_lowlevel.h: add more setattr flags
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-02-09 10:22:15 +00:00
Bernd Schubert
d7560cc991 Split config.h into private and public config
This addresses https://github.com/libfuse/libfuse/issues/729

commit db35a37def introduced a public
config.h (rename to fuse_config.h to avoid conflicts) that
was installed with the package and included by libfuse users
through fuse_common.h. Probablem is that this file does not have
unique defines so that they are unique to libfuse - on including
the file conflicts with libfuse users came up.

In principle all defines could be prefixed, but then most of them
are internal for libfuse compilation only. So this splits out
publically required defines to a new file 'libfuse_config.h'
and changes back to include of "fuse_config.h" only when
HAVE_LIBFUSE_PRIVATE_CONFIG_H is defined.

This also renames HAVE_LIBC_VERSIONED_SYMBOLS to
LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS, as it actually
better explains for libfuse users what that variable
is for.
2023-02-09 10:21:29 +00:00
Bernd Schubert
db35a37def Install a the configure_file (config.h) and use in headers
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-28 09:35:34 +00:00