Commit Graph

1967 Commits

Author SHA1 Message Date
Bernd Schubert
8a9e2dc20c
Use std=gnu11 (#940)
We already have some C11 pieces like Static_assert and we are likely
going to add more - tell meson to use C11.
Plain C11 does not work as there are several language extension,
like typeof - part of C23 only. We might be able to fix/workaround
such extensions with compiler ifdef, but then I prefer gnu11 over
checking which compiler is used (example gcc has __typeof vs
clangs __typeof++). And compiler extension would also defeat pedantic.
2024-04-27 14:25:48 +02:00
dependabot[bot]
cdcaabd2c3
Bump actions/checkout from 4.1.2 to 4.1.3 (#934)
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.2 to 4.1.3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](9bb56186c3...1d96c772d1)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-26 14:19:16 +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
Bernd Schubert
80663a7936
Use single place to define the version and increase version to 3.17.0 (#932)
* Use single place to define the version

Defining the version in fuse_common.h, is removed, it is defined
through meson and provided by "libfuse_config.h". I.e. it avoids
to define the version twice - once in meson and once in
fuse_common.h.

Ideal would be to set integers in the meson file and create the version
string from these integers. However, meson requires that "project"
is the first meson.build keyword - with that it requires to
set the version from a string and then major/minor/hotfix integers
are created from string split.

Signed-off-by: Bernd Schubert <bernd.schubert@fastmail.fm>

* Increase the version to 3.17.0

This is to prepare the branch for the next release.

Signed-off-by: Bernd Schubert <bernd.schubert@fastmail.fm>

---------

Signed-off-by: Bernd Schubert <bernd.schubert@fastmail.fm>
2024-04-22 12:05:39 +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
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
20de66dc89
fusermount: Fix use of uninitialized x_mnt_opts (#924)
x_mnt_opts was not initialized to 0, but strncat was done

Spotted by cppcheck running on our ddn branch.
2024-04-06 15:19:33 +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
Bernd Schubert
67d4db4050 Fix FUSE_CAP_DIRECT_IO_ALLOW_MMAP - use new numerical value
Commit 22741f5  accidentally re-used (1 << 27), which is
already taken for FUSE_CAP_SETXATTR_EXT.

Fortunately not part of any release yet.
2024-03-27 21:35:50 +01:00
Ashley Pittman
e3bd7de517 Install all test/build python packages from requirements.txt
Have GitHub actions setup python on runners and install
all python dependencies via pip.

Signed-off-by: Ashley Pittman <ashley@pittman.co.uk>
2024-03-27 17:26:14 +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
e547a66566
ci-build.sh: Fix checking for function arguments (#909)
Checking for an emtpy string actually doesn't work for $@,
so just check for number of arguments.

Co-authored-by: Bernd Schubert <bschubert@ddn.com>
2024-03-20 16:43:54 +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
dependabot[bot]
b4804ce3f8
Bump actions/checkout from 4.1.1 to 4.1.2 (#905)
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.1.2.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](b4ffde65f4...9bb56186c3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-20 14:53:43 +01:00
Bernd Schubert
694f3d5231
Merge pull request #904 from bsbernd/s-bit-fusermount
Add back s-bit for compiled fusermount
2024-03-20 13:30:12 +01:00
Bernd Schubert
425f52a1f5 Add final "meson setup --reconfigure" to README.md
This reconfigure is recommended to ensure the build system
(ninja/cmake/...) get the updated meson config. They
typically do, but it depends on file time stamps - is
a potential random error source.
2024-03-20 12:59:59 +01:00
Bernd Schubert
0d90a90b06 /test_ctests / test_notify1: Print cmdline on failure
Tests sometimes fail with

pytest.fail('file system process terminated prematurely')

And it is not clear what actually happens.
2024-03-20 12:37:17 +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
99ef7a93ea ci-build.sh: Add back test without versioned symbols
Commit b1cdc497 ("ci-build.sh: Run ASAN and UBSAN at the same time")
also accidentally removed the test for versioned symbols.

Also export clang/clang++ to make sure new shells get it.
2024-03-20 12:37:15 +01:00
Bernd Schubert
255de0b78a Build clang/sanitized build first
This was stalling - easier to check what happens
when it fails fast. And in general, sanitized
builds are faster than valgrind and detect almost
as much errors as valgrind (same level would be
achieved with MSAN, but that is hard to use),
so failures can be detected faster whan sanitizers
run first.
2024-03-20 12:32:39 +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
f041818c63 Add back s-bit for compiled fusermount
This is also needed by some tests and was accidentally removed
in commit aab146eea8
2024-03-20 12:32:39 +01:00
Bernd Schubert
71a97226e8 Fix test failures: Create missing mount dir
Tests were failing because mount dir was missing.
Unclear to me why this became only recently an issue
(github internal - out of the sudden tests were hanging).
2024-03-20 12:32:30 +01:00
Bernd Schubert
38d40c5bc1 ci-build.sh: Reduce pytest --maxfail from 99 to 1
We want to see errors - reduce allowed errors.
With --maxfail=99 tests out of the sudden started to hang
in github, without a change in libfuse (I had actually tested
to previous release tags). With --maxfail=1 pytest aborts
and we see failing github.

Also increase python log level to NOTSET - NOTSET should print
all messages.

Also use "pytest" has wrapper for "python3 -m"
2024-03-20 09:09:29 +01:00
Bernd Schubert
a6a219f534
Merge pull request #901 from bsbernd/posix_spawn
Switch from fork to posix_spawn
2024-03-07 12:03:41 +01:00
Bernd Schubert
aab146eea8 ci-build.sh: Always install and add s-bit for fusermount3
As per pull #898, fusermount3 had a severe issue that
should have been detected by ASAN. I guess tests used
the system default and not the sanitized binary.
Order of execution of fusermount3 is to try
1) full install path
if that fails
2) just fusermount3

So tests should be fixed by installing libfuse, setting the s-bit
on fusermount3 and then to run the tests.
2024-03-07 11:56:30 +01:00
Bernd Schubert
b1cdc497b8 ci-build.sh: Run ASAN and UBSAN at the same time
Also set halt_on_error=1 to make UBSAN to fail if it
would find something.
2024-03-07 11:56:30 +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
Bernd Schubert
a6ac2ec12d Fix undefined loff_t in test_write_cache.c on alpine
This fixes #899. Seems that Alpine (and maybe Fedora) need
_GNU_SOURCE to get loff_t.
2024-03-06 13:12:50 +01:00
Bernd Schubert
9e35addc35 fusermount: Fix head-buffer-overflow in extract_x_options
Commit 74b1df2e introduced a heap-buffer-overflow, as
allocated memory was not initialized and extract_x_options
was also not checking for the remaining buffer size.
Fix is to initialize the buffer and to also not exceed the buffer
size. Actually not exceeding buffer size is rather complex with C
and introduced quite some code changes.

Also fixed is a memory leak of allocated buffers in the commit
mentioned above.
2024-03-05 23:58:49 +01:00
Bernd Schubert
6bda4091d4 meson: Point OSX (darwin) to https://www.fuse-t.org/
www.fuse-t.org is a more recent fuse extension for OSX
based on NFS.
2024-02-26 22:11:19 +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
Bernd Schubert
31bf17c744
Fix tests/test_write_cache in write back mode (#892)
This test could fail whenever a something (kernel, userspace) decides
to flush in between of two 2048B writes. These two writes are supposed
to be merged into a single 4906 byte write by the kernel writeback cache,
but _sometimes_ the test fails because 2048 byte writes get through.
Fixes #882

Solution here is a modification how the test works - instead
of requiring an exact aggregation of 2x2048B into 4096B,
it now writes 64x2048B and requires in write-back modes
the number of received writes requests is lower than 64 - we
can expect that at least some writes get aggregated, but we do
know how many.

Co-authored-by: Bernd Schubert <bschubert@ddn.com>
2024-02-26 19:09:00 +01:00
Bernd Schubert
f557f36775
Merge pull request #888 from yangyun50/master
passthrough examples: enable direct io when open has flag: O_DIRECT
2024-02-26 09:48:04 +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
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
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
yangyun50
402c8fff58
remove duplicated fuse_chan_put() (#893) 2024-02-20 11:52:39 +01:00
HereThereBeDragons
67d28fb4b7 make FUSE_CAP_EXPIRE_ONLY test depend on available cap and not on version 2024-01-29 08:43:58 +00: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
Bernd Schubert
0392acbb23 Add in rename to FUSE_DIRECT_IO_ALLOW_MMAP
Add in the rename of FUSE_DIRECT_IO_RELAX to
FUSE_DIRECT_IO_ALLOW_MMAP.
2024-01-10 20:59:03 +00:00