Commit graph

1631 commits

Author SHA1 Message Date
Antonio S. Musumeci
ef0ab108c5 test: don't let the default minfreespace fail the #1693 rm -rf tests
- TEST_rm_rf_concurrent and TEST_use_dirfd_after_rmdir mounted with the
  default minfreespace of 4G. Where the test tree has less than that
  free every mkdir and create fails with ENOSPC, so they failed for a
  reason that has nothing to do with removed nodes: one with a
  traceback, the other with "No space left on device". Set
  minfreespace=0, as b0d34430 did for the EXDEV tests.
- In TEST_rm_rf_concurrent, an rm that fails without writing to stderr
  raised IndexError from taking the last line of nothing. Report the
  exit status in that case.
2026-11-22 08:39:21 -05:00
Antonio S. Musumeci
6d9b997e5d docs: correct read-thread-count in the options list
- read-thread-count=0 was documented as the number of logical cores.
  It is capped at 8, or becomes 2 read threads when process-thread-count
  is enabled too, as threads.md says.
- Drop the sentence that read-thread-count=-1 with process-thread-count
  picks reasonable values. -1 follows the negative rule like any other
  negative count: the core count divided by 1, up to the 64 limit. Only
  0 is resolved specially.
- Point at threads.md for how the two settings combine.
2026-11-22 08:38:40 -05:00
Antonio S. Musumeci
175630ac42 fix: ask the moveonenospc policy by parent directory
- 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.
2026-11-22 08:38:13 -05:00
Antonio S. Musumeci
898ad5992d fix: keep failed statvfs results in the cache and track entry validity
- 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.
2026-11-22 08:28:48 -05:00
Antonio S. Musumeci
64d3af02a3 fix: return the error, not a short count, for page cache flushes
- 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.
2026-11-22 08:27:04 -05:00
Antonio S. Musumeci
6e9bdd9564 fix: pass CPPFLAGS and LDFLAGS to the fusermount and mount helpers
- c8f32f9f added CPPFLAGS to the libfuse object rules but not to the
  rules building mergerfs-fusermount and mount.mergerfs, and the
  fusermount rule never used LDFLAGS. So the setuid fusermount missed
  the distro's -D_FORTIFY_SOURCE and relro/now link flags, and neither
  helper got the release target's -DNDEBUG.
- Use CPPFLAGS in both rules and LDFLAGS in the fusermount one. With
  Debian-style flags the helper now links with BIND_NOW.
2026-11-22 01:29:03 -05:00
Antonio S. Musumeci
9586fd9dbd fix: build RPMs with NDEBUG like the Debian packages
- mergerfs.spec ran plain make with the distro flags, so RPMs were
  built without -DNDEBUG and their asserts stayed live: a failed one
  aborts the daemon. debian/rules builds the release target, which
  adds -DNDEBUG.
- Build the release target in the spec too. The distro CFLAGS,
  CXXFLAGS and LDFLAGS still apply; a dry run shows every mergerfs and
  libfuse object now gets -DNDEBUG.
2026-11-22 01:28:03 -05:00
Antonio S. Musumeci
bc7b7ffeae fix: report a short write when ENOSPC recovery fails after a prefix
- 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.
2026-11-22 01:27:22 -05:00
Antonio S. Musumeci
33b0799d6b fix: make the statfs cache timeout safe to change at runtime
- 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.
2026-11-22 01:25:44 -05:00
Antonio S. Musumeci
48f26f3731 docs: correct func.readdir counts and the queue depth of 0
- func.readdir's cor and cosr rows said a negative thread count is the
  core count divided by it. The parser only accepts digits, so a
  negative count is rejected as invalid. Say what 0 does instead: the
  core count, at most 8 threads, and a queue depth of 2 per thread.
- process-thread-queue-depth said 0 makes the depth the process thread
  count. It sets the per-thread depth to 2, as threads.md says.
2026-11-22 01:25:13 -05:00
Antonio S. Musumeci
cd0679b01f fix: leave the source branch out before moveonenospc picks a branch
- 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.
2026-11-22 01:24:45 -05:00
Antonio SJ Musumeci
db9e991ebd fix: saturate the process thread queue depth instead of overflowing
- process-thread-queue-depth is multiplied by the process thread
  count. A large depth overflowed the int, e.g.
  process-thread-queue-depth=1073741824 with 2 process threads, which
  is undefined behaviour.
- Cap the product at INT_MAX. The queue only counts free slots, so a
  depth that large is unbounded in practice, as asked for.
2026-11-21 18:12:38 -05:00
Antonio SJ Musumeci
127c2e6238 fix: cap thread pools at 64 and warn when clamped
- 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.
2026-11-21 17:48:28 -05:00
Antonio SJ Musumeci
8d93e29ad8 fix: give tagless Debian snapshots a numeric version
Use 0~git.<commit-count>.<hash> so tagless snapshots sort in ancestry
order and accept hashes beginning with a letter. A shallow checkout
without a reachable tag must supply a version rather than compare
unreliable history depths. Preserve explicit and tag-derived versions.
2026-11-21 14:53:57 -05:00
Antonio SJ Musumeci
c9d34cdff9 fix: keep the requested version when generating a Debian changelog
When no tag range produces entries, emit the history at the requested
ref instead of an empty changelog. Keep the newest tag across empty
ranges so co-located tags and explicit versions at HEAD retain their
requested package version.
Resolve the selected revision before printing any entries; a repository
without a usable revision must fail rather than emit a malformed header.
2026-11-21 14:53:57 -05:00
Antonio SJ Musumeci
2c6d7c2b49 fix: free a read thread's buffer when it is cancelled at shutdown
- 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.
2026-11-21 14:53:56 -05:00
Antonio SJ Musumeci
4a665bbf32 fix: make the default minfreespace safe to change at runtime
- 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.
2026-11-21 14:53:56 -05:00
Antonio SJ Musumeci
416af29cc1 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-21 14:53:56 -05:00
Antonio SJ Musumeci
e5a4f72c4d 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-21 14:53:55 -05:00
Antonio SJ Musumeci
3735d7215d fix: apply cache.statfs given at mount
- 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.
2026-11-21 14:53:55 -05:00
Antonio SJ Musumeci
5e74822f91 fix: don't cache a failed statvfs as a success
- 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.
2026-11-21 14:53:55 -05:00
Antonio SJ Musumeci
7d677d1a37 fix: reject func.readdir counts that overflow an int
- 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.
2026-11-21 14:53:54 -05:00
Antonio SJ Musumeci
fe2d94dd1c fix: restore NDEBUG=1 release flags for static builds
- c8f32f9f dropped the NDEBUG branch from both Makefiles, so the
  static containerfiles and the container image, which run
  `make NDEBUG=1 LTO=1 STATIC=1`, built -O0 -g3 with asserts live.
- NDEBUG=1 now selects -O3 -DNDEBUG, matching `make release`, in
  mergerfs and vendored libfuse. NDEBUG=0 or unset is unchanged.
2026-11-21 01:09:37 -05:00
Antonio SJ Musumeci
b934e8bd59 fix: relocate from the fd's current branch on repeated ENOSPC
- 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.
2026-11-21 01:09:37 -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
neargye
cb930ee7a0 Fix fuse loop hang when a read worker exits
- 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.
2026-11-17 09:00:59 -06:00
Antonio SJ Musumeci
6d138906ec Fix ARMv5 atomic loads from Boost dummy storage 2026-11-14 18:27:14 -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
b0d344308d test: disable minimum free space threshold in EXDEV tests 2026-11-06 11:24:54 -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
bdfbedad8b Fix release builds and drop Debian 11 targets
Enable parallel Debian package builds through debhelper, remove Debian 11 release targets, and select the installed GCC Toolset activation script on Rocky Linux 10 while preserving older layouts. Update the build documentation.
2026-11-05 15:02:42 -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
5d5d7af90b Add Fedora 45 and Ubuntu 26.10 build targets 2026-11-02 18:57:58 -06:00
Antonio SJ Musumeci
1a152db265 fix: pass base directory paths to TMPFILE callbacks 2026-11-01 21:11:04 -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
8e87bcbff2 docs: Add Unraid migration guidance for mergerfs
- Add a top-level Migration page covering both migration directions.
- Explain filesystem reuse, parity constraints, partition requirements,
  and unlocking encrypted Unraid disks.
- Describe intact ZFS pool imports and subdirectory branch reuse,
  distinguishing them from cases requiring a data copy.
- Add navigation and link the guide from the Unraid comparison.
2026-10-03 16:52:25 -05:00
Antonio SJ Musumeci
fcd7527c9d docs: document mergerfs tradeoffs and web UI management
* Add: a comprehensive downsides FAQ with mitigations and practical
  priorities.
* Document: mergerfs-webui and link it from setup and configuration
  guides.
* Replace: obsolete mergerfs.fsck references with fsck.mergerfs
  guidance.
2026-10-01 20:14:52 -04:00
Antonio SJ Musumeci
83d1630f55 docs: rework and expand project comparisons 2026-09-22 14:50:47 -05:00
Antonio SJ Musumeci
cfb925e5ae docs: clarify branch resolution and mount ordering 2026-09-21 13:46:38 -05:00
Antonio SJ Musumeci
515b0549ef docs/performance: explain mergerfs IO performance vs RAID
Describe why mergerfs does not aggregate branch performance like
RAID/ZFS (whose aggregate throughput is also capped by shared
interconnects) and instead provides independent per-branch
performance: best case A+B+C across concurrent streams, worst case
single-stream limited to one branch's speed.
2026-09-05 16:00:43 -04:00
natalefalco
8ea47df13e Include Docker Compose setup for mergerfs
Added Docker Compose configuration for running mergerfs.
2026-07-31 08:13:59 -05:00
shyney7
42ab831d97 docs/setup: link install :z example to SELinux FAQ 2026-05-17 10:14:21 -05:00
shyney7
89b4046d11 docs/faq: add SELinux relabeling entry 2026-05-17 10:14:21 -05:00
Antonio SJ Musumeci
7ec6f8e2f2 Manage cloned /dev/fuse fds in sessions
- 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.
2026-05-14 20:13:07 -05: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
30d59d4458 Use shared_mutex for fuse log config
- 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
2026-05-14 00:22:06 -04:00