Commit Graph

300 Commits

Author SHA1 Message Date
Bernd Schubert
e2eb1abb10 Add FUSE_CAP_NO_EXPORT and use it in passthrough_hp
This should stop some more xfstest test failures.
2024-11-13 16:43:59 +01:00
Bernd Schubert
15f5c81123 Add fuse_set_feature_flag() / fuse_unset_feature_flag
Simplify setting feature flags a bit by adding a helper
function.

Also move the check for valid flags into a funtion we can re-use
in a later patch.
2024-11-13 16:43:59 +01:00
Bernd Schubert
00c0e9a45b passthrough_hp: Use fuse_loop_cfg_set_max_threads()
fuse_loop_cfg_set_idle_threads() was by accident and
setting it might cause a performance issue.
2024-09-19 16:59:13 +02:00
Bernd Schubert
97991a6569 example/passthrough_hp: Set keep_cache and noflush in sfs_create
These flags should be also set for O_CREAT
2024-09-13 19:10:44 +02:00
Bernd Schubert
c00c9fd831 example/passthrough_hp: No auto FOPEN_DIRECT_IO in passthrough mode
sfs_open and sfs_create set fi->direct_io (FOPEN_DIRECT_IO) when
O_DIRECT is given, in order to benefit from a shared inode lock
in kernel, i.e. to get parallel DIO writes. However, kernel side
disabled passthrough when FOPEN_DIRECT_IO is set. Reads/writes
had been totally failing in this case for O_DIRECT as
sfs_write_buf() and sfs_read() have a sanity check. That sanity
check could be modified, but for performance passthrough is
better than parallel DIO, hence, we only want automatic
FOPEN_DIRECT_IO for O_DIRECT when passthrough is not enabled.

Fixes: https://github.com/libfuse/libfuse/issues/1027

This also fixes automatically switching to FOPEN_DIRECT_IO
for O_DIRECT in sfs_create().
2024-09-13 19:10:44 +02:00
Bernd Schubert
0a76670183 getattr: Make use of FUSE_GETATTR_FH in lowlevel examples
High level examples were already using it, but not
lowlevel. Also update the documentation.
2024-09-12 18:21:25 +02:00
yangyun
d30247c36d remove unused headers in example/poll_client
fuse_config.h is used in libfuse internally. This may confuse developers
that fuse_config.h is used in the examples.
2024-08-26 18:01:33 +02:00
yangyun
0750b4a194 Fix FUSE_USE_VERSION in example/notify_store_retrieve.c
This is an addition to commit e75d2c54a3. This example sets
FUSE_USE_VERSION = 34 but uses fuse_loop_cfg_* APIs, which is
not allowed since these APIs are not introduced in version 34.
2024-08-19 13:53:11 +02:00
Bernd Schubert
cb7c16acbf example/passthrough_hp: Remove unused includes
Fix some clang-tidy warnings.

Signed-off-by: Bernd Schubert <bschubert@ddn.com>
2024-08-01 16:04:57 +02:00
Bernd Schubert
e75d2c54a3 Fix FUSE_USE_VERSION in example/
This is an addition to commit a8f1ae35af, which
introduced the 312 API, but didn't set the right
API version in all examples.

Signed-off-by: Bernd Schubert <bschubert@ddn.com>
2024-08-01 16:04:57 +02:00
Bernd Schubert
a83041fa1f example/passthrough_hp: Fix . and .. readdir lookup count
Commit 170edc6a8e added dot and dotdot (. and ..) to readdir
results, but introduced an issue when max number of entries
was reached - lookup count must not be decreased without
doing the lookup.
With ext4 as underlying file system readir seems to return . and ..
at random offsets and randomly failed xfstests for me.

This also fixes indentation, as passthrough_hp.cc does not follow
the linux indentation style (if we decide to fix this, it needs
to be done for the entire file).

Signed-off-by: Bernd Schubert <bschubert@ddn.com>
2024-07-30 10:53:16 +02:00
Bernd Schubert
dae1184302 Add syslog and fatal signal handler feature
I see random ENOTCONN failures in xfstest generic/013 and generic/014
in my branch, but earliest on the 2nd run - takes ~12hours to get
the issue, but then there are no further information logged.
ENOTCONN points to a daemon crash - I need backtraces and a core dump.

This adds optional handling of fatal signals to print a core dump
and optional syslog logging with these new public functions:

fuse_set_fail_signal_handlers()
    In addition to the existing fuse_set_signal_handlers(). This is not
    enabled together with fuse_set_signal_handlers(), as it is change
    in behavior and file systems might already have their own fatal
    handlers.

fuse_log_enable_syslog
    Print logs to syslog instead of stderr

fuse_log_close_syslog
    Close syslog (for now just does closelog())

Code in fuse_signals.c is also updated, to be an array of signals,
and setting signal handlers is now down with a for-loop instead
of one hand coded set_one_signal_handler() per signal.
2024-07-14 14:28:44 +02:00
Joanne Koong
170edc6a8e passthrough_hp: include . and .. in readdir
generic/401 fails currently because it checks that "." and ".." are
listed as directory entries.

Include "." and ".." as listed directory entries in passthrough_hp's
readdir implementation.

Signed-off by: Joanne Koong <joannelkoong@gmail.com>
2024-07-08 23:29:57 +02:00
desertwitch
366f6a6a9a example/notify_inval_entry.c: improve comment readability
Follow the same format as other arguments passed to example commands.
2024-07-08 09:53:08 +02:00
desertwitch
a36f16a3a4 example/notify_inval_entry.c: fix example command in comments
Notifications should be enabled here, but present command example would disable them.
2024-07-08 09:53:08 +02:00
CismonX
285465fbdb Fix wrong use of the EBADFD errno
should use EBADF instead
2024-06-25 07:16:49 +02:00
CismonX
0a62f5d761 Do not build the hello_ll_uds example for *BSD
since there's no splice(2) support
2024-06-25 07:16:49 +02:00
Josef Bacik
c9204dbd0d libfuse: have passthrough_hp return an error with invalid mount options
generic/003 fails currently because if you specify -o relatime we will
fail to mount, but not return an error, so the test thinks that we
support relatime and then hilarity ensues.  Set ret so that if we get
any failures while trying to mount we will properly error out.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
2024-06-07 21:33:04 +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
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
a8f1ae35af
example/: Convert all fuse_session_loop_mt users to 3.12 API (#931)
Convert all the remaining users of fuse_session_loop_mt() to
the new 3.12 config api.
2024-04-20 22:56:13 +02:00
legezywzh
285da329ea
passthrough_ll: fix fd leaks in lo_destroy() (#929)
By virtio-fs and libfuse fuse_custom_io, passthrough_ll could be
a virtio filesystem device backend, this bug was found when doing
mount, fsstress and umount repeatedly.

Signed-off-by: Xiaoguang Wang <lege.wang@jaguarmicro.com>
Co-authored-by: Xiaoguang Wang <lege.wang@jaguarmicro.com>
2024-04-20 13:40:16 +02:00
Bernd Schubert
e2df577a7c
Add more documentation for FUSE_CAP_EXPORT_SUPPORT (#917)
Add more documentation for FUSE_CAP_EXPORT_SUPPORT

Also remove the flag from passthrough_ll.c and passthrough_hp.cc
as these implementations do _not_ handle that flag. They just
cast fuse_ino_t to an inode and cause a heap buffer overflow
for unknown objects (simplest reproducer are the examples
in "man 2 open_by_handle_at", but to unmount/mount the file
system after name_to_handle_at and before open_by_handle_at).

Fixes https://github.com/libfuse/libfuse/issues/838

---------

Co-authored-by: Nikolaus Rath <Nikolaus@rath.org>
2024-04-02 23:52:18 +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
FredyVia
c021e910a5
Add FUSE_FILL_DIR_DEFAULTS enum (#903)
In order to use the fuse_fill_dir_t function in a C++ program, add the enum item:
FUSE_FILL_DIR_DEFAULTS

Without this change g++ compilation failed with
example/hello.c:94:35: error: invalid conversion from ‘int’ to ‘fuse_fill_dir_flags’ [-fpermissive]
   94 |         filler(buf, ".", NULL, 0, 0);
      |                                   ^
      |                                   |
      |                                   int
2024-03-20 16:08:04 +01:00
Bernd Schubert
9a823df6d9
Fix example/fix-notify_inval_inode.c (#908)
Similar issue as fixed in commit
3c7ba570 "examples/notify_store_retrieve: Add a clean shutdown".
Basically a clean shutdown was missing, but even with clean
shutdown it does not work, as kernel side releases inodes before
sending FUSE_DESTROY - the intervaled thread then gets
-ENOENT.

Co-authored-by: Bernd Schubert <bschubert@ddn.com>
2024-03-20 15:25:41 +01:00
Bernd Schubert
982743f0ca Fix use-after-free in example/poll.c
As noticed by valgrind in issue #907 example/poll.c
triggers a use-after-free

==85200== Thread 2:
==85200== Invalid read of size 4
==85200==    at 0x485E54A: send_notify_iov (fuse_lowlevel.c:2267)
==85200==    by 0x485E54A: fuse_lowlevel_notify_poll (fuse_lowlevel.c:2289)
==85200==    by 0x1096F2: fsel_producer (poll.c:245)
==85200==    by 0x4897EA6: start_thread (pthread_create.c:477)
==85200==    by 0x49ADA6E: clone (clone.S:95)
==85200==  Address 0x5291d68 is 392 bytes inside a block of size 920 free'd
==85200==    at 0x48399AB: free (vg_replace_malloc.c:538)
==85200==    by 0x485A12C: fuse_destroy (fuse.c:5103)
==85200==    by 0x486220F: fuse_main_real (helper.c:389)
==85200==    by 0x1091D6: main (poll.c:288)
==85200==  Block was alloc'd at
==85200==    at 0x483AB65: calloc (vg_replace_malloc.c:760)
==85200==    by 0x485BAA0: fuse_session_new (fuse_lowlevel.c:3036)
==85200==    by 0x4859AF2: fuse_new@@FUSE_3.1 (fuse.c:4966)
==85200==    by 0x4862129: fuse_main_real (helper.c:345)
==85200==    by 0x1091D6: main (poll.c:288)

Issue is that the "fsel_producer" thread is still active after
fuse_destroy - it gets destructed too late.
2024-03-20 12:32:39 +01:00
Bernd Schubert
420a6c3c5d example/notify_store_retrieve: Fix races and handle errors
This test was racy, the lookup counter must only be increased once
kernel side has lookup completed and knows about the inode.
However, this is still racy as

app thread
(python script)  kernel-side       libfuse thread       kernel
----------------------------------------------------------------------
    open file
                 lookup req
                 wait
                                   handle req
                                   reply
                                                      wake app thread
                                                      return
                 new_inode()
                 <continue file open>

So actually on libfuse side even after returning from kernel side
it is not ensured that the kernel has created the inode. I.e.
using lookup_cnt in the test is still racy.
A new variabled 'open_cnt' is added that is only increased in open
Using open_cnt should be safe to use as kernel side (with atomic-open)
first does lookup, from that data creates the inode and only then sends
an open request. I.e. update_fs_loop() must only call
fuse_lowlevel_notify_store() once it is absolutely sure kernel side has
created the inode (open_cnt) and when it is sure the kernel inode still
exists (lookup_cnt).

Not really nice, but we actually need to accept some errors, as
these still come up at umount time. Typically it is hard to hit,
but tests in github actually frequently get it. Actually, it can be
easily reproduced by commenting out the sleep line in
update_fs_loop(). Underlying issue is that kernel side is
sending ->destroy() only when it already internally released all
inodes - too late for this test. The errors I run into are ENOENT
and EBADFD, but I added back in ENODEV for safety.

In order to avoid any other kind races mutex lock is also introduced.
2024-02-26 20:37:53 +01:00
yangyun
c458633188 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
2024-02-26 09:32:29 +08:00
yangyun
fce970c313 passthrough_example: make parallel_direct_writes more clearly
Move the parallel_direct_writes enable action to the init function in high level API,
it is more recommended just like commit 8ee553dac. Besides, add some comments to show
that the feature parallel_direct_writes is depend on the feature direct_io (refer to
kernel side patch series to consolidate direct IO, link: https://lwn.net/ml/linux-fsdevel/
20230918150313.3845114-1-bschubert@ddn.com for the reason).
2024-02-23 15:01:29 +08: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
Bernd Schubert
3c7ba57050 examples/notify_store_retrieve: Add a clean shutdown
On shutdown update_fs_loop() was failing frequently in github
test with ENOENT, but only ENODEV was tested for and only for the.
With clean shutdown there is no need to test for such errors at all.
2023-12-28 09:18:12 +00:00
amitgeron
bd8985945b
Allow *xattr operations on root directory (ino 1) 2023-12-17 17:45:47 +00:00
SteveYang
05b696edb3
passthrough_hp: Fix clone-fd option (#850)
The clone-fd option is set valued but not used in the context. Use it in the code.
2023-10-12 10:18:28 +01:00
Bernd Schubert
063ef8e03f Enabled parallel direct IO writes for passthrough examples
All these passthrough examples don't need writes to be serialized.

Actually, most file systems probably handle non serialized parallel
direct writes - the FOPEN_PARALLEL_DIRECT_WRITES flag is just
to avoid a regression for those file system that rely on serialized
DIO writes in fuse kernel. Passthrough file system forward the IO
to another file system, which actually handles that internally -
serialized in fuser kernel is not needed.
2023-10-11 08:39:11 +01:00
Nikolaus Rath
ef11cf9eac Fix typo in comment 2023-10-10 08:44:23 +01:00
Bernd Schubert
98ee575ddb passthrough-hp: Fix --clone-fd
Actually one had to use --clone-fd=1 instead of
just --clone-fd.
2023-09-23 14:41:31 +01:00
Bernd Schubert
7a9717e145 passthough_hp: Add a direct-io option
this is needed to test FOPEN_DIRECT_IO with xfstests. Also useful
for some benchmarks.
2023-09-23 14:41:31 +01:00
Nikolaus Rath
b51f69f620 Add missing include. 2023-07-01 14:10:47 +01:00
HereThereBeDragons
51bc827df8
Make expire only function fail if no kernel support (#789) 2023-06-30 13:57:06 +01:00
Nikolaus Rath
4c177c9047 Add support for running xfstests. 2023-05-12 23:29:03 +01:00
Nikolaus Rath
ad1abf3f2e Do not daemonize to early
fuse_session_mount() may print errors to stderr, if we daemonize before
that than these are lost.
2023-05-12 23:29: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
Nikolaus Rath
2113871279
Fix compiler warning in hello_ll.c (#760) 2023-04-01 22:42:18 +01:00
Nikolaus Rath
d65686ac2c Add unit tests for setxattr() et al
Hopefully, this will catch issues as in commit 024eccbf3
2023-04-01 16:49:01 +01:00
Yaroslav Halchenko
0f8cb28883
Fix typos and configure spellcheck for PRs 2023-03-29 19:47:13 +01: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
psykose
19d95c0e70 use off_t over __off64_t
when -D_FILE_OFFSET_BITS=64 is defined, the off_t type is 64 bits wide
already. the fuse_common.h header already checks for this, and errors
when it is not, so be consistent with all the other uses of off_t.

some libcs like musl do not have a 32-bit off_t type, and don't define
__off64_t.
2023-01-15 10:09:10 +00:00
Bernd Schubert
c67b9219cf passthrough_hp: Avoid a bit code dup in readdir
Just a slight code simplification.
2023-01-13 10:21:42 +00:00
Bernd Schubert
856c683c36 passthrough_hp: Add options for clone_fd, max_threads, daemonize
This is useful for benchmarking.

Note: This changes behavior - passthrough_hp runs in background by default
      now.
2023-01-13 10:21:42 +00:00