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.
This commit is contained in:
Antonio SJ Musumeci 2026-11-18 23:45:00 -05:00
parent d1be8ac1db
commit 61597c8dfd
9 changed files with 558 additions and 78 deletions

View file

@ -20,9 +20,16 @@ situation.
When enabled and a `write` fails with `ENOSPC` or `EDQUOT` mergerfs
will:
1. Run the policy defined by `moveonenospc` to find a target branch.
1. Check that the file's path is absent on every branch other than the
source and its aliases, including read-only and no-create branches.
If the path already exists (even as a dangling symlink), or a branch
cannot be checked, refuse the move: removing the source could make a
later open find a different file. Otherwise, use the `moveonenospc`
policy to choose a destination from the eligible branches.
2. ["Move"](../faq/technical_behavior_and_limitations.md#how-does-mergerfs-handle-moving-and-copying-of-files)
the file from the source branch to the target branch.
the file from the source branch to the target branch. If another entry
appears at the destination during the copy, the move fails without
overwriting that entry or removing the source.
3. Retry only the unwritten portion of the request, so a partially
completed append is not duplicated.