aboutsummaryrefslogtreecommitdiffstats
path: root/example
AgeCommit message (Collapse)AuthorLines
2024-04-20example/: Convert all fuse_session_loop_mt users to 3.12 API (#931)Bernd Schubert-21/+36
Convert all the remaining users of fuse_session_loop_mt() to the new 3.12 config api.
2024-04-20passthrough_ll: fix fd leaks in lo_destroy() (#929)legezywzh-0/+1
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-02Add more documentation for FUSE_CAP_EXPORT_SUPPORT (#917)Bernd Schubert-6/+0
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-03-29Add support for FUSE_CAP_HANDLE_KILLPRIV_V2Bernd Schubert-0/+8
This just adds in the basic handler, but does not use it yet in examples.
2024-03-20Add FUSE_FILL_DIR_DEFAULTS enum (#903)FredyVia-10/+10
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-20Fix example/fix-notify_inval_inode.c (#908)Bernd Schubert-5/+27
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-20Fix use-after-free in example/poll.cBernd Schubert-6/+16
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-02-26example/notify_store_retrieve: Fix races and handle errorsBernd Schubert-11/+38
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-26Enable direct IO for passthrough examples when open has flag O_DIRECTyangyun-0/+28
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-23passthrough_example: make parallel_direct_writes more clearlyyangyun-4/+26
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-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-12-28examples/notify_store_retrieve: Add a clean shutdownBernd Schubert-11/+20
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-17Allow *xattr operations on root directory (ino 1)amitgeron-3/+3
2023-10-12passthrough_hp: Fix clone-fd option (#850)SteveYang-0/+2
The clone-fd option is set valued but not used in the context. Use it in the code.
2023-10-11Enabled parallel direct IO writes for passthrough examplesBernd Schubert-0/+13
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-10Fix typo in commentNikolaus Rath-1/+1
2023-09-23passthrough-hp: Fix --clone-fdBernd Schubert-3/+2
Actually one had to use --clone-fd=1 instead of just --clone-fd.
2023-09-23passthough_hp: Add a direct-io optionBernd Schubert-2/+12
this is needed to test FOPEN_DIRECT_IO with xfstests. Also useful for some benchmarks.
2023-07-01Add missing include.Nikolaus Rath-0/+1
2023-06-30Make expire only function fail if no kernel support (#789)HereThereBeDragons-8/+33
2023-05-12Add support for running xfstests.Nikolaus Rath-2/+56
2023-05-12Do not daemonize to earlyNikolaus Rath-2/+3
fuse_session_mount() may print errors to stderr, if we daemonize before that than these are lost.
2023-04-12Fuse mount: make auto_unmount compatible with suid/dev mount options (#762)Matthias Görgens-2/+7
* 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-01Fix compiler warning in hello_ll.c (#760)Nikolaus Rath-2/+4
2023-04-01Add unit tests for setxattr() et alNikolaus Rath-5/+54
Hopefully, this will catch issues as in commit 024eccbf3
2023-03-29Fix typos and configure spellcheck for PRsYaroslav Halchenko-2/+2
2023-01-28Install a the configure_file (config.h) and use in headersBernd Schubert-19/+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-15use off_t over __off64_tpsykose-2/+2
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-13passthrough_hp: Avoid a bit code dup in readdirBernd Schubert-14/+9
Just a slight code simplification.
2023-01-13passthrough_hp: Add options for clone_fd, max_threads, daemonizeBernd Schubert-2/+29
This is useful for benchmarking. Note: This changes behavior - passthrough_hp runs in background by default now.
2023-01-10Support application-defined I/O functions for FUSE fdTofik Sonono-3/+361
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-06Test for fuse_lowlevel_notify_expire_entry.HereThereBeDragons-5/+18
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-06adding comments and capability discovery, enum for flags moved to top of fileHereThereBeDragons-0/+2
2022-09-04fuse-loop/fuse_do_work: Avoid lots of thread creations/destructionsBernd Schubert-5/+9
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-04-08Passthrough_ll should display cmd line optionsDharmendra singh-0/+18
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-03-31passthrough_hp: Disable splice with the --nosplice optionBernd Schubert-7/+13
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-31passthrough_hp: Fix inode ref in sfs_unlinkBernd Schubert-0/+26
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-14Merge branch 'master' into fopen_noflushNikolaus Rath-2/+0
2022-02-11Removed duplicates code. (#642)David Galeano-2/+0
The cap for FUSE_CAP_WRITEBACK_CACHE was printed twice.
2022-01-03Add support for FOPEN_NOFLUSH flagAmir Goldstein-0/+1
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>
2021-06-14passthrough_hp: excercise reusing inode numbersAmir Goldstein-7/+50
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-09Cuse example: Fix memory leak (#607)Christian Menges-5/+11
* cuse example: fix memory leak * Travis CI: re-enable leak checking
2021-05-09Fix memory leaks in examples (#604)Christian Menges-1/+17
2021-05-09Bump cxxopts from 2.2.0 to 2.2.1 (#602)Christian Menges-41/+78
2021-05-07Fix doxygen warnings. (#600)Junichi Uekawa-3/+3
Some parameters were undocumented, and @file does not mean to expand current file name.
2021-03-18Fix returning d_ino and d_type by readdir(3) in non-plus modeJean-Pierre André-2/+16
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-02-03Fix returning inode numbers from readdir() in offset==0 mode. (#584)Martin Pärtel-1/+1
- 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-01-01Fix FUSE_COPY_FILE_RANGE in the passthrough example (#575)Alan Somers-2/+4
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.
2020-11-24examples/cuse_client: add include file to eliminate compiler warning (#568)Rethan-0/+2
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-06example/cuse_client.c: fix fd leakage problemZhiqiang Liu-4/+10
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>