Commit graph

1627 commits

Author SHA1 Message Date
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
844e1acffd docs: limit the Compose mount to the permissions mergerfs needs
The sample enabled privileged mode in addition to passing /dev/fuse
and granting SYS_ADMIN. That exposed unrelated host devices and
capabilities to the container. Remove the blanket grant and keep the
same device, capability and propagation settings as the rootful CLI
example.

Docker's default AppArmor profile denies mount(2), so on hosts where
AppArmor is enforcing the container also needs apparmor=unconfined or
a profile that allows the FUSE mount. Say so rather than restoring
privileged mode.
2026-11-29 23:11:05 -05:00
Antonio SJ Musumeci
d786081b16 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-29 23:11:04 -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
d1be8ac1db test: don't let the default minfreespace fail the #1693 tests
TEST_rm_rf_concurrent and TEST_use_dirfd_after_rmdir mount with
minfreespace=0, so a test filesystem with less than 4G free does not
fail every create with ENOSPC. An rm that fails without output reports
its exit status instead of raising IndexError.
2026-11-29 23:10:57 -05:00
Antonio SJ Musumeci
330e453f43 test: never delete a fixture through a live mount
Fixture cleanup trusted fusermount's exit status, ignored unmount
failures and then ran rmtree over the fixture, through the mount if
it was still attached. unmount_mergerfs now checks the mount table
after each attempt, including the lazy -uz fallback, and raises
UnmountError if the mount stays attached. The fixture is then kept
and its path reported instead of deleted, without masking an
exception from the test body. TEST_teardown_safety checks both.
2026-11-29 23:10:57 -05:00
Antonio SJ Musumeci
271a4324a7 refactor: use free_path_and_update_stat in setattr
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.
2026-11-29 23:10:57 -05:00
Antonio SJ Musumeci
7e29c3f72a test: run test_clonepath_modes where gid 1 is unmapped, and clean up
Root in a user namespace may not have gid 1 mapped, so the chown to it
failed and the test aborted. Use a distinct group only when gid 1 is
available and differs from the caller's, and only check setgid group
inheritance then; permissions, ownership and existing destinations
are still checked on single-group hosts. TEST_ASSERT aborts without
unwinding and left the fixture in /tmp, so the body checks and
returns and the caller always removes it.
2026-11-29 23:10:56 -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 SJ Musumeci
cf8c489ae2 docs: fix the runtime interface example and package file names
- getfattr prints the key it was asked for, and the create policies
  the example sets and shows are real ones (pfrd, epmfs), not the
  nonexistent prfd.
- rpmbuild names its output mergerfs-<version>-1.<dist>.<arch>.rpm,
  and the static release archive includes the version in its name.
- --nosignature applies to every distribution that enforces RPM
  signatures, not only Fedora 45.
2026-11-29 23:10:56 -05:00
Antonio SJ Musumeci
a5ab77bc6b docs: note the trees the EXDEV fallbacks leave on branches
mergerfs stores nothing on its branches by default, but the opt-in
link-exdev and rename-exdev fallbacks create .mergerfs_symlink_exdev/
and .mergerfs_rename_exdev/ at branch roots, and files renamed by
rename-exdev live inside the latter. Say so where the downsides and
migration pages promise that mergerfs can be removed, or the pool
retired, without touching the data.
2026-11-29 23:10:55 -05:00
Antonio SJ Musumeci
5139801064 docs: describe SELinux relabeling without version-specific details
Keep the mechanism and the recommendations, but drop the promises of
exact runtime messages, log levels and probe results, which vary by
container runtime version. Give the ausearch and sesearch checks
instead. The downsides page now says to omit :z and :Z on mergerfs
bind mounts.
2026-11-29 23:10:54 -05:00
Antonio SJ Musumeci
4540af2a75 build: keep the compiler handoff and probe files out of /tmp
- install-build-pkgs runs as root and handed its compiler choice to
  build-mergerfs through /tmp/build-env, which another user could
  create before root writes it. Use /etc/mergerfs-build-env, written
  to a temporary name, made mode 0644 and renamed into place, so a
  normal user can source it regardless of root's umask and never reads
  it half written.
- The C++20 probe compiles in a private temporary directory instead of
  at fixed names in /tmp.
- yum hosts also consider an already installed devtoolset, which "yum
  list available" omits.
- Document sourcing the handoff file before make deb.
2026-11-29 23:10:54 -05:00
Antonio SJ Musumeci
8e6bfc4b0c build: pass CPPFLAGS and LDFLAGS to the fusermount and mount helpers
The mergerfs-fusermount and mount.mergerfs rules ignored CPPFLAGS, and
the fusermount rule also ignored LDFLAGS, so the setuid helper was
built without the distribution's _FORTIFY_SOURCE and relro/now
hardening. Use both in both rules.
2026-11-29 23:10:53 -05:00
Antonio SJ Musumeci
3c02e47e47 build: make NDEBUG=1 and make release build the release profile
- The RELEASE=1 profile replaced 2.42.0's NDEBUG=1 one, but the
  static archives and the container image still build with NDEBUG=1,
  which therefore selected the debug profile: -O0 -g3 with assertions
  on. Both Makefiles accept NDEBUG=1 again, as -O3 -DNDEBUG, and the
  debug profile defines DEBUG. The vendored libfuse follows the same
  profile as mergerfs.
- make release first removes the objects, binaries and stamp under
  build/ and cleans vendored/libfuse, because make only compares
  timestamps: objects from an earlier debug build were otherwise
  linked into the release binary unchanged. Packages and build reports
  in build/pkgs are kept; TEST_release_pkg_preservation checks both.
- make release also builds preload.so. It takes the release defines
  through its own PRELOAD_CPPFLAGS: the global CPPFLAGS add
  _FILE_OFFSET_BITS=64, which would hide its unsuffixed
  open/openat/fopen/creat interposers.
- mergerfs.spec builds the release target, as debian/rules does. The
  distribution's CFLAGS, CXXFLAGS and LDFLAGS still apply.
- The release driver mounts the repository with ":ro,z", not ":ro:z",
  which Podman read as an extra field instead of a mount option.
  TEST_release_metadata runs the driver against a fake podman and
  checks the volume argument and the build report.
- Remove release-installer: build-release has no installer target.
- make help printed a literal "\n" where /bin/sh is bash. Match the
  build.md transcript to its output and document the profiles.

Performance: static archives and the container image go from -O0 with
assertions back to optimized builds, now -O3 -DNDEBUG (2.42.0: -O2
-DNDEBUG). RPM packages keep the distribution's -O2 and no longer
evaluate assertions. A plain make is unoptimized, as before.
2026-11-29 23:10:53 -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
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