Commit Graph

277 Commits

Author SHA1 Message Date
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
Tofik Sonono
50c74e6459
Support application-defined I/O functions for FUSE fd
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-10 10:04:35 +00:00
HereThereBeDragons
c0a344e379 Test for fuse_lowlevel_notify_expire_entry.
This test is too simple to check for all functionalities of notify_expire as it always successfully passes when libfuse supports the function (even if kernel does not support it -  it just takes it as notify_inval)
2023-01-06 18:35:52 +00:00
HereThereBeDragons
91083df90e adding comments and capability discovery, enum for flags moved to top of file 2023-01-06 18:35:52 +00:00
Bernd Schubert
af5710e7a3 fuse-loop/fuse_do_work: Avoid lots of thread creations/destructions
On benchmarking metadata operations with a single threaded bonnie++
and "max_idle_threads" limited to 1, 'top' was showing suspicious
160% cpu usage.
Profiling the system with flame graphs showed that an astonishing
amount of CPU time was spent in thread creation and destruction.

After verifying the code it turned out that fuse_do_work() was
creating a new thread every time all existing idle threads
were already busy. And then just a few lines later after processing
the current request it noticed that it had created too many threads
and destructed the current thread. I.e. there was a thread
creation/destruction ping-pong.

Code is changed to only create new threads if the max number of
threads is not reached.

Furthermore, thread destruction is disabled, as creation/destruction
is expensive in general.

With this change cpu usage of passthrough_hp went from ~160% to
~80% (with different values of max_idle_threads). And bonnie
values got approximately faster by 90%. This is a with single
threaded bonnie++
bonnie++ -x 4 -q -s0  -d <path> -n 30:1:1:10 -r 0

Without this patch, using the default max_idle_threads=10 and just
a single bonnie++ the thread creation/destruction code path is not
triggered.  Just one libfuse and one application thread is just
a corner case - the requirement for the issue was just
n-application-threads >= max_idle_threads.


Signed-off-by: Bernd Schubert <bschubert@ddn.com>
2022-09-04 13:07:15 +01:00
Dharmendra singh
646ff0bb3b Passthrough_ll should display cmd line options
Make passthrough_ll to display all its cmdline options
instead of keeping them hidden.
(I am not sure if these are intentionally kept hidden)
2022-04-08 15:36:01 +01:00
Bernd Schubert
f0bba7ef2a passthrough_hp: Disable splice with the --nosplice option
passthrough_hp was not updated when splice got enabled by default in libfuse3.
I.e. the --nosplice option and condition on it was a noop.
2022-03-31 15:27:02 +01:00
Bernd Schubert
f8a24e9ec7 passthrough_hp: Fix inode ref in sfs_unlink
sfs_unlink may call do_lookup(), which increases the inode ref count,
but since that function does not return attributes that lookup ref
count won't get automatically decreased.
2022-03-31 15:27:02 +01:00
Nikolaus Rath
66b04453b7
Merge branch 'master' into fopen_noflush 2022-03-14 09:25:00 +00:00
David Galeano
3c2ba7aa25
Removed duplicates code. (#642)
The cap for FUSE_CAP_WRITEBACK_CACHE was printed twice.
2022-02-11 20:07:00 +00:00
Amir Goldstein
1b498ac9b3 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 <amir73il@gmail.com>
2022-01-03 14:55:34 +02:00
Amir Goldstein
80f2b8b469 passthrough_hp: excercise reusing inode numbers
Before last unlink() release the reference on inode.fd to allow reuse
of underlying fs inode number, mark the server inode "deleted" and bump
it's generation counter.

When same inode number is found on lookup(), the server inode object will
be reused as well.

Skip this when inode has an open file and when writeback cache is enabled.

This will be used to verify inode reuse bug fix in the kernel.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
2021-06-14 09:13:12 +01:00
Christian Menges
57b46adc35
Cuse example: Fix memory leak (#607)
* cuse example: fix memory leak

* Travis CI: re-enable leak checking
2021-06-09 09:04:41 +01:00
Christian Menges
7d1ba6b066
Fix memory leaks in examples (#604) 2021-05-09 11:12:01 +01:00
Christian Menges
995d46a205
Bump cxxopts from 2.2.0 to 2.2.1 (#602) 2021-05-09 10:00:57 +01:00
Junichi Uekawa
8c4d315108
Fix doxygen warnings. (#600)
Some parameters were undocumented, and @file does not mean to expand current file name.
2021-05-07 10:43:30 +01:00
Jean-Pierre André
bdd2d4110f
Fix returning d_ino and d_type by readdir(3) in non-plus mode
When not using the readdir_plus mode, the d_type was not returned,
and the use_ino flag was not used for returning d_ino.

This patch fixes the returned values for d_ino and d_type by readdir(3)

The test for the returned value of d_ino has been adjusted to also
take the d_type into consideration and to check the returned values in
both basic readdir and readdir_plus modes. This is done by executing
the passthrough test twice.

Co-authored-by: Jean-Pierre André <jpandre@users.sourceforge.net>
2021-03-18 09:52:30 +00:00
Martin Pärtel
5012a05ac8
Fix returning inode numbers from readdir() in offset==0 mode. (#584)
- Test added for all passthrough examples.
- passthrough.c uses offset==0 mode. The others don't.
- passthrough.c changed to set FUSE_FILL_DIR_PLUS to make the test pass.
- This fixes #583.
2021-02-03 09:53:21 +00:00
Alan Somers
ccba27fbec
Fix FUSE_COPY_FILE_RANGE in the passthrough example (#575)
Only close the file descriptors if they were just opened.  Otherwise,
the second FUSE_COPY_FILE_RANGE operation on any given file will fail
with EBADF.
2021-01-01 19:34:58 +00:00
Rethan
1acfb20cb3
examples/cuse_client: add include file to eliminate compiler warning (#568)
Compiler warning about close(fd), add include file to fix.

Signed-off-by: haoyixing <haoyixing@kuaishou.com>
Co-authored-by: haoyixing <haoyixing@kuaishou.com>
2020-11-24 09:28:13 +00:00
Zhiqiang Liu
8b4c5d90ee example/cuse_client.c: fix fd leakage problem
In cuse_client.c, fd should be closed before return.
Otherwise, it will cause fd leakage problem.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Haotian Li <lihaotian9@huawei.com>
2020-11-06 19:26:03 +00:00
Zhiqiang Liu
2a87b64af7 ioctl_client.c: fix potential fd leakage problem
In ioctl_client.c, fd is not closed before return, thus
it will cause fd leakage problem.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Haotian Li <lihaotian9@huawei.com>
2020-11-06 19:26:03 +00:00
Etienne Dublé
ba3b225a12
Allow caching symlinks in kernel page cache. (#551)
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:
5571f1e654
2020-09-20 19:08:15 +01:00
AKowshik
86f40b8584
Updated example code to work with new API (#547) 2020-09-09 20:17:06 +01:00