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.
- 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.
- At shutdown the main loop cancels read threads that are still in
receive_buf. The buffer each one had allocated for the next request
was a raw pointer, so the cancel unwind left it allocated.
LeakSanitizer reported it in about one daemon in six when unmounting
under load.
- Hold it in a unique_ptr so the unwind frees it. The async worker
releases it when handing the request to the process pool, as before.
- 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.
setattr inlined a copy of the helper getattr uses. Call it instead.
Unlike getattr, setattr does not turn a vanished node into ESTALE, so
the helper's result is ignored there, as before.
- DEFERs run in reverse order, so workers posted the semaphore before
setting exited; the main loop could wake, see exited == 0 and wait
again. With one read thread mergerfs then stayed running after
unmount until signaled.
- Set exited and post in a single DEFER, in that order.
- Store cloned read-worker fds on fuse_session and close them there.
- Set up clone fallback through session helpers used by the loop.
- Carry per-request fds through receive, process, and reply paths.
Tests show significant performance increases in highly concurrent
workloads on a high core count system. Upto 15% better on reads and
27% on writes.
- Guard fuse_cfg_t log file and filepath shared pointers with a shared mutex
- Replace atomic shared pointer loads and stores with shared and unique locks
- Add helpers that release path locks and update node state under f.lock.
- Update getattr and setattr stat-cache invalidation while preserving ESTALE handling.
- Rework create, open, tmpfile, and set_path_info to mutate lookup/open state under the shared lock.
- Document the lock/unlock pair as an acquire/release barrier.
- Explain that releasedir waits for in-flight readdir calls before destroy/free.
- Warn against removing the synchronization despite it not being a critical section.
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.
- Reserve a zero stat CRC to represent an invalid cache fingerprint.
- Include device, size, inode, mtime, and ctime data in the fingerprint.
- Recompute the fingerprint during auto-cache open before keeping cache.
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.
- fuse_opt: reformat process_opt_param to project style; return the
rv from sscanf through a named local so the error branch prints
the failing option cleanly.
- cpu.cpp: when parsing /sys/devices/system/cpu/*/topology/core_id,
bail out cleanly on stream read failure rather than recording an
uninitialized core_id.
- fusermount: free(copy) on the success path of parsing the mount
option (previously leaked on every mount), and replace the fixed-
buffer sprintf into procfile with snprintf bounded by the buffer
size.
- maintenance_thread: widen the iteration count from int to u64
so a long-lived daemon doesn't wrap after ~68 years of ticks
(real effect: silence signed-overflow warnings under UBSan).
- ThreadPool::destroy used to iterate _threads directly while another
thread could be adjusting the same vector. Snapshot the vector
under the mutex and iterate the local copy for pthread_cancel /
pthread_join.
- ObjPool::construct now returns NULL when the pooled allocator
returns NULL instead of invoking placement-new on a null
pointer. In destroy, compute to_node(obj) before running the
destructor - the destructor may scrub bytes the to_node helper
reads.
- In the async/sync workers in fuse_loop, msgbuf_alloc can return
NULL under memory pressure. Fail the worker cleanly with a
diagnostic rather than dereferencing. Also introduce a small
_nproc() helper that treats hardware_concurrency()==0 as 1, so
the downstream min/max arithmetic doesn't produce a zero thread
count.
The signal handler reads the global session pointer from an async-
signal context while another thread installs/removes the session
via set/remove_signal_handlers. Use std::atomic<fuse_session*> with
acquire/release ordering so the handler either sees NULL or a fully
published session, never a torn pointer.
Collapse get_node/get_node_nocheck into a single function that
returns NULL when the node is absent rather than abort()ing.
Callers that previously assumed non-NULL now check the return value
and either reply ESTALE/ENOMEM or fall through gracefully; a few
places where the node is load-bearing (e.g. unhash during remove)
use fatal::abort with a descriptive message.
Switch mutex_lock / mutex_unlock pairs to mutex_lockguard so early
returns on error paths no longer leak the lock, and add NULL-safety
around fuse_dh in readdir/readdir_plus, fuse_dirents_init error
returns, the getattr path when both name and fh are empty, and the
msgbuf allocation in fuse_lib_read.
Pull the new xstrdup/xmalloc wrappers from xalloc.hpp for the root
node name so the common-case OOM path terminates with a diagnostic
instead of a silent corrupted node.
Also guard fuse_session_destroy against a NULL session - called
from error-recovery paths.
The low-level init/destroy callbacks were passed a userdata pointer
that mergerfs never consumed - the caller threaded it through
fuse_lowlevel_new only to hand it back unchanged. Remove the
parameter from the ops struct, from fuse_lowlevel_new(_common),
and from the internal fuse_ll struct; update fuse_lib_init and
fuse_lib_destroy accordingly.
Also drop fuse_reply_ioctl_iov: no caller in-tree invokes it and
the public API is defined by this vendored libfuse fork.
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.