Commit graph

550 commits

Author SHA1 Message Date
Antonio SJ Musumeci
c9854f236f fix: make the rename-exdev fallback safe and transactional
rename-exdev (opt-in; the default is passthrough) moves a source it
cannot rename across branches into a staging tree and publishes a
symlink at the destination. This reworks that fallback so a rename
either completes or leaves both names as they were.

- Staging opens every component relative to a pinned parent with
  O_NOFOLLOW, requires a daemon-owned staging root, and refuses when
  the tree can't be trusted.
- Staged names are taken without replacement and must be free on
  every configured branch, not only those holding the source, so a
  later lookup cannot reach another rename's payload. Over-long names
  are shortened. Fallback renames are serialized.
- Destinations: a compatible existing destination is replaced, kept
  under a temporary name until every branch is published, and
  restored if a later branch fails. A destination on a read-only
  branch, or a no-create one where the link can't be created, is
  refused before anything moves. Temporary and restore names never
  replace an entry, and a restore that fails is reported.
- An ordinary rename (rename-exdev=passthrough) also refuses with
  EXDEV when the destination exists on a read-only branch that does
  not hold the source: that copy could neither be replaced nor
  removed and would shadow the renamed file there. It is never
  scheduled for removal either.
- The replacement symlink is prepared in a daemon-private directory,
  its UID and GID are verified through a pinned descriptor, and it is
  published without replacement, before any source moves. A sticky,
  world-writable destination directory under Linux protected symlinks
  is refused. Each prepared link is tracked by identity for cleanup.
- Symlink sources are recreated with their original text, owner and
  times instead of staged, since staging changes where a relative
  target resolves. Sources of different types on different branches
  are refused. A hidden source that cannot be removed fails the rename.
- libfuse re-parents the kernel's node onto the staged inode, using a
  name allocated before publication, so open handles and cached
  dentries keep working and nothing can fail after the rename commits.
- Without renameat2 (FreeBSD 14.4 and 15.0, or seccomp), regular
  files and directories use a portable layout: a fresh daemon-owned
  wrapper, access gates that mirror the source's parents with the
  source's GID and its read and execute bits only, and the payload
  directory inside the last gate. Foreign-owned parents, unsettable
  group ownership and non-trivial ACLs are refused before the source
  moves. A namespace the source never entered is removed. A portable
  directory that can't be restored stays staged with its path logged,
  and an existing directory destination is refused before a portable
  source moves: keeping it aside would need the no-replace rename the
  portable layout lacks.
- Document the fallback, its refusals and FreeBSD limits.
- TEST_rename_exdev_publication, TEST_rename_exdev_portable and
  tests.cpp cover publication rollback, shadows, collisions,
  ownership, sticky directories, mixed source types, a refused portable
  directory destination and the portable layout through a mounted
  pool. TEST_rename_exdev_publication keeps its fixture if its tmpfs
  can't be detached.

Performance: an ordinary rename only adds an lstat per read-only
branch, and only when one is configured. The fallback adds about two
lstats per branch plus the staging work, and fallback renames run one
at a time.
2026-11-29 23:11:10 -05:00
Antonio SJ Musumeci
11e759101d fix: make the preload helper correct on FreeBSD and safe on reopen
- The helper called Linux fgetxattr on FreeBSD. Read mergerfs.fullpath
  there through extattr_get_fd in EXTATTR_NAMESPACE_USER; Linux keeps
  user.mergerfs.fullpath.
- FreeBSD mode_t is promoted when passed through an ellipsis, so
  reading it back as mode_t was undefined. Read the promoted type.
- O_TMPFILE includes O_DIRECTORY on Linux, so a plain directory open
  consumed a mode argument that wasn't passed. Require O_CREAT or the
  whole nonzero O_TMPFILE mask.
- The backing path is returned without a terminating NUL. Reject empty
  or oversized values and terminate it before reopening; keep the
  already-open descriptor when no usable path is available.
- The reopen of the backing file repeated O_TRUNC, and creat() ran
  creat() again. The open through mergerfs had already truncated that
  file, so the second truncation could only destroy data another
  process wrote in between. Drop O_TRUNC from the reopen and reopen
  creat()ed files O_WRONLY.
- fopen and fopen64 reopened the branch path with the caller's mode,
  so w truncated a second time and a could recreate a name removed in
  between. Redirect only modes starting with r, including r+, as
  given, and keep the original stream otherwise; tooling.md says so.
  TEST_preload_fopen_modes checks the bytes and that a missing branch
  name is not created.
- fs_fstatat.hpp used AT_SYMLINK_NOFOLLOW without including fcntl.h,
  which failed against FreeBSD headers.
2026-11-29 23:11:08 -05:00
Antonio SJ Musumeci
eea1c1bc09 fix: keep readdir listings stable under fill errors
- func.readdir=cor appended entries in whichever order branch workers
  finished. Directory offsets are positions in that list, so a reader
  reopening an unchanged directory and seeking to a previously issued
  cookie (NFS does this) could see a duplicate and miss a later entry.
  Read branches concurrently into their own buffers, then merge and
  deduplicate them in configured branch order. The merge mutex is gone.
- Growing a dirents buffer overwrote the only pointer with realloc's
  result while recording the new capacity, so an allocation failure
  leaked the buffer and the next fill wrote through NULL. Grow both
  vectors without changing pointer, length or capacity until the
  allocation succeeds, and return ENOMEM.
- seq and cosr ignored that failure and served a listing with entries
  missing. Every policy now returns the error, and libfuse resets the
  handle's buffer whenever a fill fails, so a later request at a
  nonzero offset re-enumerates instead of serving a partial or stale
  listing as success. cosr closes the directories its workers opened
  when it gives up early.
- Document the fill-error contract, which doesn't promise that every
  branch was read: seq and cosr can treat a branch read error as the
  end of the directory. Document cor's memory use, and refer to
  func.getattr, not fuse.getattr.
- TEST_readdir_cor_cookie_replay compares cor listings, offsets and
  inodes with seq and replays cookies on fresh handles.
  TEST_dirents_allocation injects allocation failures into the dirents
  code. TEST_readdir_cor_enomem fails one allocation in a mounted
  daemon for cor and seq and checks the same handle then serves the
  exact suffix.

Performance: cor copies each entry twice and merges serially after the
parallel reads. Listing 100,000 entries over 4 tmpfs branches took
the same time before and after (81-83 ms per listing for cor:4 and
seq). Peak daemon memory for cor:4 dropped from 27.4 MB to 18.7 MB.
2026-11-29 23:11:07 -05:00
Antonio SJ Musumeci
b367b593ba fix: make the statfs cache correct and its timeout configurable
- A failed statvfs was cached as a success: for the next cache.statfs
  seconds every caller got the entry's old or zeroed stats and create
  policies chose branches from them. Keep a failure as an error for the
  timeout, like a success, so a slow failing branch isn't retried under
  the lock by every caller in turn. Document that the branch then stays
  excluded from space-based create policies until the timeout expires.
- A new entry was told apart from a fresh one only by a time of 0, so a
  timeout of at least the current time in seconds returned the zeroed
  struct as success. Give entries a valid flag set by the first
  statvfs, and measure age with a steady clock from when statvfs
  returned.
- cache.statfs given at mount was stored but never applied. Bind the
  option directly to the atomic the cache reads, so mount options,
  config files and control-file updates follow one path and concurrent
  readback no longer races with updates.
- tests.cpp checks that a cached failure is never served as success,
  that failures are kept until the timeout, huge timeouts, an invalid
  update keeping a cached ENOENT, and a timeout of 0 exposing a newly
  created directory immediately.
2026-11-29 23:11:06 -05:00
Antonio SJ Musumeci
8cc6be6ff2 fix: make enum, minfreespace and process-name options safe to change
- Options set through the .mergerfs xattr are written while request
  threads read them, with no synchronization. That is a data race; on
  32-bit targets a request could see half of a new 64-bit minfreespace.
- Store the default minfreespace as std::atomic<u64> with relaxed
  loads and stores. Per-branch values are unchanged.
- Store every enum option (rename-exdev, xattr, cache.files, statfs,
  nfsopenhack, follow-symlinks and the rest) atomically. Copies take a
  snapshot.
- getxattr, setxattr and removexattr read the xattr option once per
  request instead of twice.
- cache.files.process-names was cleared and refilled in place while
  open and create looked names up in it, which could walk freed tree
  nodes. Build the new set aside and swap it in under a lock that
  lookups share.
- Other options (booleans, numbers and strings) are still plain values;
  this covers only the ones above.
2026-11-29 23:11:03 -05:00
Antonio SJ Musumeci
e4e9d54fe7 fix: keep temp file names within short NAME_MAX limits
- fs_mktemp computed the prefix length as name_max - 6 - 2 in size_t.
  Below a NAME_MAX of 8 that wrapped, so the whole source file name
  was used and every temp file name was too long. moveonenospc and
  copy-on-write always failed on such a branch.
- Shorten the random suffix when the limit is that small and never
  let the prefix length go negative. Names on normal filesystems are
  unchanged.
2026-11-29 23:11:02 -05:00
Antonio SJ Musumeci
962c111eb3 fix: restore the mode when an nfsopenhack open fails
- nfsopenhack adds S_IWUSR|S_IWGRP to a read-only file so the open
  can succeed, and resets the mode on the new fd. When the open still
  failed, the write bits stayed on the file.
- Pin the inode before changing its permissions. Use that reference for
  the temporary mode, retry and restoration, so a concurrent rename
  cannot apply the original mode to an unrelated replacement.
2026-11-29 23:11:01 -05:00
Antonio SJ Musumeci
d679fdd265 fix: validate and cap thread and queue counts
- std::stoi threw std::out_of_range for a func.readdir concurrency or
  queue depth above INT_MAX, e.g. cor:99999999999. Given at mount,
  mergerfs aborted. Set at runtime through .mergerfs, the daemon shut
  down and the mount went away, or with process-thread-count>0 the
  request never got a reply. Parse with str::from, which reports the
  overflow, and reject the value like any other malformed one.
- Reject a readdir queue depth whose product with the concurrency
  overflows an int, e.g. cor:2147483647:2147483647, instead of
  wrapping it.
- Limit read-thread-count, process-thread-count and the cor/cosr pool
  size to 64 threads per pool, after resolving automatic and
  CPU-divided counts, and log a warning when clamping. Resolve
  negative FUSE counts without overflowing on INT_MIN, and drop the
  unreachable negative readdir concurrency branch.
- process-thread-queue-depth is multiplied by the process thread count.
  Saturate the product at INT_MAX instead of overflowing.
- Correct the docs: cor/cosr counts accept digits only and 0 means the
  core count, at most 8; a queue depth of 0 means 2 per thread;
  read-thread-count=0 with process-thread-count=0 is 2 read threads
  and max(2, cores - 2) process threads, at most 8; the queue limit is
  depth times process threads, each read thread holding one in-flight
  buffer of its own. Point at threads.md for how the settings combine.
- Document the per-read-thread /dev/fuse clones and their fallback.
- tests.cpp covers the overflow cases.

Performance: default thread counts are unchanged (8 on hosts with 8 or
more cores). Only explicit or CPU-divided counts above 64, which
2.42.0 honored, are reduced.
2026-11-29 23:11:00 -05:00
Antonio SJ Musumeci
61597c8dfd fix: pick the moveonenospc source and destination correctly
- moveonenospc copied from the branch stored when the file was opened,
  which a move never updates, so a second ENOSPC on the same handle
  tried to copy a path that no longer existed. Find the source branch
  from the fd's device and inode at the start of each move, trying the
  stored branch first. No match leaves the write's ENOSPC in place.
- The source branch was dropped from the create policy's result, so a
  policy returning one branch (ff, mfs, lfs, lus, pfrd) left nothing
  when it picked the source, and a destination that was the source by
  another path (bind mount) was renamed over the file and unlinked.
  Remove every alias of the source before the policy runs, so it picks
  another branch; with no candidate left the move is refused.
- Refuse relocation if a duplicate on another branch could become
  visible once the source is removed, and publish without replacing a
  destination that appeared meanwhile. When the no-replace rename is
  unsupported, publish with link(); a staging name that cannot be
  removed afterwards is logged instead of silently left behind.
- Ask the create policy by the parent directory, as create does. The
  existing-path policies and newest only pick a branch that has the
  path they are given, and the destination has the directory but not
  the file yet.
- TEST_movefile_enospc moves a handle twice and checks duplicates
  through the pool. tests.cpp covers the source by its own path and an
  alias, and every existing-path policy for nested and root files.
2026-11-29 23:10:59 -05:00
Antonio SJ Musumeci
e47e82b3f9 refactor: remove the unfinished _clonepath2
It was never called and only produced an unused-function warning.
Drop the includes only it used and a duplicate fs_clonepath.hpp
include, and fix a typo in a comment.
2026-11-29 23:10:56 -05:00
Antonio S. Musumeci
9d12bcf235 Return ENOENT, not EBADF, for removed nodes with no open file
Once a file or directory is removed (unlink, rmdir, rename over it)
libfuse has no path for its node and falls back to the fh based
getattr/setattr/statx with fh=0. If mergerfs had no open file for the
node (a directory, an O_PATH fd, a cwd, or a dentry resolved just
before the removal) it returned EBADF. The kernel sends GETATTR for
such nodes in the permission checks of a path walk, so lstat() of a
directory, or of a path below it, could fail with EBADF while rm -rf
removed it. Two rm -rf at once, one on a directory and one on the
directory above it, met it when one removed a directory the other
still had open: the other's unlinkat() through its dirfd failed, rm
reported "Bad file descriptor" and left entries behind.

mergerfs now returns ENOENT. That is what a local filesystem gives
*at() calls in a removed directory, and what rm -f ignores. ESTALE
would make the kernel redo a path based lookup, which helps a stat
racing a rename over the path. But a call through a dirfd or cwd of a
removed directory meets the same node again and fails anyway, and the
concurrent rm -rf still did. Calls on the removed object itself, which
succeed on a local filesystem, get ENOENT instead of EBADF.

TEST_rm_rf_concurrent runs the two cases reported. The rm -rf one is
a narrow race; TEST_use_dirfd_after_rmdir covers its cause without
one, with cache.attr=0 so the kernel sends GETATTR every time.

See #1693.
2026-11-17 12:25:50 -06:00
Antonio SJ Musumeci
ecb4de5bc0 Fix branch snapshot lifetime in EXDEV link fallback 2026-11-06 12:10:05 -06:00
Antonio SJ Musumeci
78a67fd066 fix: preserve partial append progress during ENOSPC recovery 2026-11-06 11:24:49 -06:00
Antonio SJ Musumeci
2513d3c067 Cap getdents64 requests at 128 KiB for virtiofs compatibility 2026-11-05 16:05:51 -06:00
Antonio SJ Musumeci
74eade91f5 Preserve directory modes when cloning paths across branches
- Restore source permissions after ownership to preserve setgid and clear unwanted inherited mode bits.
- Add regression coverage for directory modes, group inheritance, and existing destination directories.
- Update the branch configuration test to use the current API.
- Document metadata preservation when cloning directory paths.
2026-11-04 19:25:10 -06:00
Antonio SJ Musumeci
b10fb10590 fix: preserve source ownership in EXDEV symlink fallbacks 2026-11-01 21:11:04 -06:00
Antonio SJ Musumeci
7b7e96bbc5 fix: initialize EXDEV rename staging for root sources 2026-11-01 21:11:04 -06:00
Antonio SJ Musumeci
3d81e24f32 fix: keep EXDEV rename symlink targets relative 2026-11-01 21:11:04 -06:00
Antonio SJ Musumeci
28d809f2f8 Fix MSP create policy hangs when no branches qualify
- Stop parent traversal after evaluating the empty relative root.
- Preserve filtering errors, parent fallback, and closest-path selection.
- Cover all four MSP policies with rejection and fallback regressions.
- Document errors when traversal exhausts the branch root.
2026-11-01 21:11:04 -06:00
Antonio SJ Musumeci
5f7fa17ad8 Inline ioprio disabled fast path
- Expose the ioprio enabled flag as an atomic for relaxed inline checks
- Inline SetFrom construction so disabled read/write paths avoid a function call
- Move priority application into a slow helper used only when ioprio is enabled
2026-05-14 00:22:06 -04:00
Antonio SJ Musumeci
02dc36080c Use shared_mutex for ReadDir state
- Replace atomic shared pointer loads/stores with shared/unique locking.
- Store the configured readdir mode directly as std::string.
- Copy the active ReadDir implementation under lock before invoking it.
2026-05-14 00:22:06 -04:00
Antonio SJ Musumeci
8734847968 Guard branch snapshots with shared_mutex
Important changes:
- Replace atomic shared_ptr operations with shared_mutex-protected snapshots.
- Retry copy-on-write branch updates when another writer publishes first.
- Keep long-running parsing and read-only filesystem checks outside branch locks.
2026-05-14 00:22:06 -04:00
Antonio SJ Musumeci
608cd00764 Use atomic open file reference counts
- Use relaxed increment under the map bucket lock when duplicating file handles.
- Use acq_rel decrement when releasing and checking for final references.
- Load moved ref_count with relaxed ordering during map insertion.
2026-05-14 00:22:06 -04:00
Antonio SJ Musumeci
b13727abde Document readdir merge mutex scope
- Explain that the mutex is per readdir call.
- Document that only dirent deduplication and list append are serialized.
- Clarify that per-branch opendir and getdents64 work runs outside the critical section.
2026-05-14 00:22:06 -04:00
Antonio SJ Musumeci
231aac15cd Use shared write locks until ENOSPC relocation
- Replace the per-file Mutex with std::shared_mutex for shared write access.
- Run direct and cached writes under a shared lock while the fd is stable.
- Retry failed writes under a unique lock before move-on-ENOSPC relocation.
2026-05-14 00:22:06 -04:00
Antonio SJ Musumeci
1e0bd54989 Move statvfs cache to use shared mutex
Its read heavy and micro benchmarks show no regression on the low end
and 30%+ throughput improvements on the highend.
2026-05-14 00:22:06 -04:00
Antonio SJ Musumeci
dfe053a0ae Require C++20-capable build toolchains
Important changes:
- Switch mergerfs and vendored libfuse Makefiles to -std=c++20.
- Select the latest available GCC/G++ or toolset in container builds.
- Verify compiler C++20 support during package installation.
- Fix dynamic SysLog formatting for fmt C++20 checks.
2026-05-13 13:55:43 -05:00
Antonio SJ Musumeci
f1034a3ad6 Remove timed node removal 2026-05-06 20:49:46 -04:00
Antonio SJ Musumeci
8117998205 Remove unused lock operation plumbing 2026-05-06 20:49:46 -04:00
Antonio SJ Musumeci
ef1e01b5a5 Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
  distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace

Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip

Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 17:41:00 -04:00
Antonio SJ Musumeci
660f556ac6 Don't return success on ENOTEMPTY rmdir errors 2026-04-29 12:23:49 -04:00
Antonio SJ Musumeci
997b036064 Reject invalid policies 2026-04-29 00:34:00 -04:00
Antonio SJ Musumeci
9308a3729c When file unlinked check open_files map
Inadvertantly removed. Didn't realize that the kernel would not always
send file handle when unlinked.
2026-04-28 16:04:26 -04:00
Antonio SJ Musumeci
7616d8b1ac Rework readlink to not depend on cstr nul termination 2026-04-26 01:37:08 -04:00
Antonio SJ Musumeci
e613d9415f Better same file check for fsck 2026-04-22 22:28:56 -05:00
Antonio S. Musumeci
da68cf3a85 Formatting: normalize brace style and parameter alignment
Some checks failed
mkdocs / deploy (push) Has been cancelled
No functional change: libfuse/helper.cpp (fuse_daemonize,
fuse_helper_opt_proc, fuse_parse_cmdline) and mergerfs
fuse_init.cpp (_want helpers) reformatted to match the project's
GNU-style brace placement and aligned parameter lists.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
e67b7d0825 log: default debug log path to empty; skip set when empty
libfuse previously initialized its debug log filepath to
"/dev/stderr", forcing the config layer to reopen stderr on every
load whether or not the user asked for it. Default the libfuse log
path to "" and have the mergerfs config layer only forward the
request to libfuse when the user supplied an explicit path.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
981d5473ee str: null-safe same() and startswith()
Both helpers previously called strcmp/pointer-dereference directly
on their arguments, so a stray NULL (e.g. an unset env string or an
absent xattr) crashed the process. Guard both helpers: same()
returns true only if both pointers are equal, startswith() returns
false if either side is NULL.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
364f8c4407 fs_movefile_and_open: -ENOSPC when no destination branch available
The create policy can legitimately return success with an empty
destination list (e.g. every candidate rejected). Previously we
then dereferenced dst_branch[0] and faulted. Return -ENOSPC so the
original write that triggered the move propagates a sensible errno
to userspace.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
ef9c7ad5df fuse_statfs: scale with long double to avoid integer overflow
The branch-aggregation code computed
  blocks * f_frsize / min_frsize
as u64 arithmetic. With large filesystems the intermediate product
blocks * f_frsize overflows 64 bits long before the division can
bring the result back into range, producing garbage bavail/bfree
values reported to userspace.

Compute the scale factor once in long double and multiply each
count by it, so the only narrowing happens in the final cast back
to fsblkcnt_t.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
4288a60c5d fuse_readlink: always null-terminate buffer
Old code only null-terminated when the returned/copied length was
strictly less than the caller-supplied bufsize_, leaving the buffer
unterminated on an exact-fill. Since buf_ is consumed as a C string,
reserve one byte for the terminator up front and unconditionally
terminate.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
cf38a37176 fuse_readdir: atomic initialized flag; bound error string; check msgbuf allocation
- ReadDir::_initialized is set by the first thread through the
  lazy-init path and read by every subsequent caller; make it
  std::atomic<bool> so the read/write pair has a happens-before
  relationship.

- The 'no valid mergerfs branch found' error directory entry used
  strcpy into a fixed-size dirent buffer. The message happens to
  fit today but the buffer is only NAME_MAX wide; switch to a
  length-bounded strncpy driven by the constexpr string size.

- The getdents implementations for seq/cor/cosr allocated a msgbuf
  without checking for allocation failure and then dereferenced it.
  Return -ENOMEM when the allocation fails.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
f5d9a60b9d fuse_getattr/statx: populate timeouts in fake_root and controlfile replies
The fake-root and control-file fast paths returned a synthetic stat
without touching the timeout struct. Callers that took those paths
ended up sending whatever the timeout struct happened to hold,
which is uninitialized memory for the control-file path and
whatever a prior call left there for the fake-root path. Kernel
behavior is undefined when the timeout is garbage.

Pass timeout_ into both helpers and set entry/attr from the
configured cache values.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
0c17492c78 FUSE: pass Branches::Ptr by value with empty-branches guards
Previously most FUSE ops took a reference to the live cfg.branches
object. With atomic_load now producing a shared_ptr snapshot, pass
it by value: the op works against a single stable view of the
configuration for its whole lifetime, immune to concurrent
reconfiguration.

Also bail out with -ENOENT when the policy returns an empty branch
set rather than dereferencing branches[0]. This was reachable if a
policy rejected every branch (e.g. everything readonly while
looking for a writable target).

Covers access, chmod, chown, create, getattr, getxattr, ioctl,
link, listxattr, mkdir, mknod, open, readdir (cor/cosr),
readlink, removexattr, rename, rmdir, setxattr, statfs, statx,
symlink, truncate, unlink, utimens.

While here, in _getattr only dereference st_->st_mode when lstat
succeeded (it is otherwise uninitialized).
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
98648ae44b FUSE: require valid file/dir handle; drop open_files fallback
Several FUSE ops fell back to looking up a FileInfo via
state.open_files when the kernel-provided fh was zero, returning
-ENOENT if the lookup failed. This path papered over handle-tracking
bugs and added cost on every call. Use the handle directly and
return -EBADF when it is invalid - the kernel should always hand us
a valid fh for an open resource.

Also simplify FileInfo::from_fh / DirInfo::from_fh and their to_fh
helpers: callers now handle the null-pointer case explicitly so the
ASSERT_NOT_NULL checks are redundant.

Covers fallocate, fchmod, fchown, fgetattr, flock, ftruncate,
futimens, read, release, releasedir, write, statx, ioctl (file +
dir), readdir (sequential, concurrent-on-read,
concurrent-on-search), and the passthrough fast paths in
create/open.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
0dcca0f1a3 branches: re-link default_minfreespace pointer on copy/move; atomically publish branch mode changes
Branches using the default minfreespace held a reference to their
owning Impl's _default_minfreespace. After a copy or move the
pointer still referenced the source Impl, which could become
invalid or diverge after further configuration changes. Switch to
a pointer and re-link it to the destination Impl on copy/move.

While here, convert set_branch_mode to do an atomic_store of a
newly constructed Impl rather than mutating the shared pointer
target in place. Readers holding an atomic_load snapshot are no
longer affected by a concurrent mode change.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
103cd358f2 state: atomic ref_count in OpenFile
ref_count is read and written from multiple FUSE worker threads
during open/release. Make it std::atomic<int> and provide a move
constructor so OpenFile remains movable when the underlying atomic
is non-movable.
2026-04-18 13:47:23 -05:00
Antonio S. Musumeci
aa46001923 Remove unused rwlock.hpp header and includes
rwlock.hpp was left over after migrating to atomic shared pointers
for branches configuration. No code references ReadGuard/WriteGuard
any longer, so drop the header and its stale includes.
2026-04-18 13:47:23 -05:00
Antonio SJ Musumeci
ff48ff6047 Handle/ignore SIGHUP
Some checks are pending
mkdocs / deploy (push) Waiting to run
2026-04-17 11:14:05 -05:00
Antonio S. Musumeci
a1e681f36b Use ReaddirCalc in all readdir implementations
* avoids per-entry path construction
2026-04-12 23:44:23 -05:00