- moveonenospc passed the file's own path to the create policy.
create passes the parent directory. The existing path policies
(epall, epff, eplfs, eplus, epmfs, eppfrd, eprand) and newest only
pick a branch that already has the path they are given, and the
destination has the directory but not the file yet, so they found
nothing and the write kept failing with ENOSPC. Only a branch that
already held a copy of the file could qualify, and the move would
have overwritten that copy.
- Pass the parent directory, as create does. The clonepath that
follows already takes it. Both a file in a directory and one at the
root, whose parent is empty, work.
- test_fs_movefile_and_open_existing_path_policies moves a file to a
branch that has only its directory with each of those policies.
Every case fails without this change.
- A new entry was told apart from a fresh one only by its time of 0.
With a timeout at least the current time in seconds, such as
cache.statfs=4294967295, a new entry looked fresh before statvfs
had run, so the zeroed struct was returned as success: every branch
reported no free space and every create failed with ENOSPC, and a
nonexistent path succeeded. 3735d721 applies cache.statfs from the
mount options, which made it reachable from fstab. Give the entry a
valid flag set by the first statvfs.
- 5e74822f stopped caching a failure as a success by retrying it on
every call, under the exclusive lock. With a branch that fails
slowly, such as an unreachable network mount, each caller then
waited for its own failure one after the other: eight callers took
2.4s where 2.42.2 took 0.3s. Keep the failure, as an error, for the
timeout like a success. It is still never returned as zeroed space.
- Read the clock again once the lock is held, so a caller that waited
doesn't compute a negative age against the entry another refreshed.
- Tests: a failure is kept until the timeout, and timeouts of
4294967295 and UINT64_MAX still return real values and errors. Both
fail without this change.
Measure age with a steady clock, starting when statvfs returns. Even a
refresh slower than the configured timeout can be shared by callers
that waited for it; wall-clock adjustments cannot extend its lifetime.
- 072b07b6 made a write that fails with ENOSPC after part of it landed
return the bytes written. The kernel issues writes to flush its page
cache (cache.writeback, dirty mmap pages) with the writepage flag
and ignores the size in the reply, then drops the pages. The short
count lost the rest of the data and hid the error: write, fsync,
msync and close all succeeded with half the data on disk, where
2.42.2 returned ENOSPC from fsync or msync.
- Keep the short count for ordinary writes, which the kernel does
handle, and return the error when the request has writepage set.
- TEST_movefile_enospc covers a writeback flush and an mmap msync with
moveonenospc=false; both fail without this change. Note the
exception in moveonenospc.md.
Initialize the flush-test error list before the first I/O operation so
an unexpected error propagates and the descriptor is still closed.
Use the mapping as a context manager for the same reason.
- 78a67fd0 kept the bytes written before ENOSPC when the move worked.
When it didn't (moveonenospc off, no branch to move to, the move or
the retry failing, or a non-ENOSPC error), write still returned the
error and dropped the count, though those bytes were on disk. An
O_APPEND writer that retried the whole buffer duplicated them.
- Return the bytes written as a short write whenever some reached the
file, as a local filesystem does. A write that wrote nothing still
returns the error.
- TEST_movefile_enospc checks it with moveonenospc=false and a write
bigger than the space left. Document it in moveonenospc.md.
- Setting cache.statfs through the control file writes the timeout
while request threads read it without a lock, a data race that can
tear on 32-bit builds. Make it an atomic, as 4a665bbf did for the
default minfreespace.
- Load it once per call so the hit check and the refresh check use
the same value.
- The source branch was dropped from the create policy's result. ff,
mfs, lfs, lus and pfrd return a single branch, so when that branch
was the source nothing was left and the write kept ENOSPC even with
room elsewhere. That happens when the source has free space by
statvfs but still returns ENOSPC or EDQUOT: a quota, exhausted
inodes, full btrfs metadata, or a cached statfs.
- Build the candidate list without the source (matched by device and
inode, as before) and run the policy on that, so it picks another
branch. With no candidate left the move is still refused.
- test_fs_movefile_and_open_same_branch now checks that ff relocates
past a source listed first, by its own path or an alias, and that a
list made only of the source is refused.
Refuse relocation if a duplicate on another branch could become visible
when the source is removed. Keep non-replacing publication to protect
against a late arrival at the destination. The mounted test checks the
original and duplicate contents, then reopens the file through the pool.
- Limit read-thread-count, process-thread-count and the cor/cosr pool
size in func.readdir to 64 threads per pool. Apply the cap after
resolving automatic and CPU-divided counts; keep disabled process
pools disabled and preserve the configured strings.
- Log a syslog warning identifying the setting and limit when clamped.
For readdir, warn only when applying a valid concurrent policy,
not during validation.
- Document the fixed cap and warning behavior. Queue depths retain
their separate limits and use the clamped thread count.
- Resolve negative FUSE counts without overflowing on INT_MIN.
Document that both readdir inputs must fit in int and that a queue
depth whose product with the resolved thread count exceeds INT_MAX
is rejected, not clamped.
- Setting minfreespace through the .mergerfs xattr wrote the shared
default while request threads read it through each branch, with no
synchronization. That is a data race; on 32-bit targets a request
could see half of the new 64-bit value.
- Store the default as std::atomic<u64> and read and write it with
relaxed loads and stores. Per-branch values are unchanged.
- 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.
- 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.
- The statvfs cache timeout was only set from the runtime xattr path
in fuse_setxattr. cache.statfs=N given at mount was stored in the
config and reported back, but the cache stayed off and every
policy check paid a raw statvfs.
- Set the timeout in options::parse before finish_initializing. The
default (0) is unchanged.
- With cache.statfs=N, statvfs_cache set the entry's timestamp before
calling statvfs. When that call failed, the failure was returned
once and then every caller for the next N seconds got success with
the entry's old or zeroed stats, and create policies chose
branches from them.
- Refresh the entry only when statvfs succeeds. A failure is
returned and retried on the next call.
- tests.cpp checks that a second lookup of a missing path still
fails.
- std::stoi threw std::out_of_range for a 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.
- Also reject a queue depth whose product with the concurrency
overflows an int, e.g. cor:2147483647:2147483647, instead of
wrapping it.
- tests.cpp covers both.
- 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 and failed with ENOSPC.
- Find the source branch from the fd at the start of each move, as
before e216a81a. findonfs now matches inode as well as device, so
branches on one filesystem are told apart, and tries the stored
branch first. No match leaves the write's ENOSPC in place.
- Drop destinations that are the source directory, matched by device
and inode so another path to it counts. The copy was renamed over
the file and then unlinked, deleting it while the write reported
success. A first move could already pick the source (EDQUOT with
free space); finding the real source let later moves do it too.
With no destination left the write keeps its error.
- TEST_movefile_enospc adds a handle that has to move twice.
tests.cpp covers a move onto the source branch by its own path
and by an alias.
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.
- 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.
- 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.
- 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
- 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.
- 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.
- 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.
- 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.
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.
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.
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.
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.
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.
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.
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.
- 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.
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.
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).
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.
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.