2025-04-08 23:19:21 -05:00
|
|
|
# moveonenospc
|
|
|
|
|
|
|
|
|
|
When writing to a file a [number of
|
|
|
|
|
errors](https://man7.org/linux/man-pages/man2/write.2.html#ERRORS) are
|
|
|
|
|
possible. The `ENOSPC` error indicates their is no room for the
|
|
|
|
|
data. That could be true due to the filesystem having actually no
|
|
|
|
|
available space for data, or because a secondary resource (such as
|
|
|
|
|
inodes) has been used up, or the filesystem might have a quota feature
|
|
|
|
|
that is limiting how much storage a particular user may use, or (as on
|
|
|
|
|
`ext4` there might be a feature which reserves space for privileged
|
|
|
|
|
processes.
|
|
|
|
|
|
|
|
|
|
Since mergerfs [does not offer](../index.md#non-features) splitting of
|
|
|
|
|
files across filesystems there are situations where a file is opened
|
|
|
|
|
or created on a filesystem which is nearly full and eventually
|
|
|
|
|
receives a `ENOSPC` error despite the pool having capacity. The
|
|
|
|
|
`moveonenospc` feature allows the user to have some control over this
|
|
|
|
|
situation.
|
|
|
|
|
|
|
|
|
|
When enabled and a `write` fails with `ENOSPC` or `EDQUOT` mergerfs
|
|
|
|
|
will:
|
|
|
|
|
|
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-18 23:45:00 -05:00
|
|
|
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.
|
2025-04-08 23:19:21 -05:00
|
|
|
2. ["Move"](../faq/technical_behavior_and_limitations.md#how-does-mergerfs-handle-moving-and-copying-of-files)
|
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-18 23:45:00 -05:00
|
|
|
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.
|
2026-11-06 11:24:49 -06:00
|
|
|
3. Retry only the unwritten portion of the request, so a partially
|
|
|
|
|
completed append is not duplicated.
|
2025-04-08 23:19:21 -05:00
|
|
|
|
|
|
|
|
If at any point something fails the progress so far will be cleaned up
|
fix: report partial writes, but not partial writeback, after ENOSPC
- When ENOSPC recovery failed after part of a write reached the file
(moveonenospc off, no branch to move to, or the move or retry
failing), write returned the error and dropped the count although
those bytes were on disk. An O_APPEND writer retrying the whole
buffer duplicated them. Return the bytes written as a short write,
as a local filesystem does; a write that wrote nothing still returns
the error.
- The kernel flushes its page cache (cache.writeback, dirty mmap pages)
with writepage requests, ignores the size in the reply and drops the
pages. A short count there lost data while write, fsync, msync and
close all succeeded. Use the request's writepage flag, not the
handle's cache mode, so cached and direct-I/O handles both return the
error for an incomplete flush.
- TEST_movefile_enospc covers a short append, writeback and mmap
flushes and a direct shared mapping where the kernel allows one.
tests.cpp calls the write callback directly so the direct-handle
contract is covered on every kernel. Document both in moveonenospc.md.
2026-11-22 01:27:22 -05:00
|
|
|
as appropriate and the original error returned. If part of the write
|
|
|
|
|
already reached the file the bytes written are returned instead, as a
|
|
|
|
|
short write, as with a local filesystem. The exception is data the
|
|
|
|
|
kernel is flushing from its page cache (`cache.writeback` or dirty
|
|
|
|
|
`mmap` pages), including writeback on a direct-I/O handle. The kernel
|
|
|
|
|
cannot act on a short write for those pages, so the error is returned
|
|
|
|
|
and reaches `fsync`, `msync` or `close`.
|
|
|
|
|
|
|
|
|
|
If `moveonenospc` is disabled the underlying error will be returned,
|
|
|
|
|
or the bytes written if part of the write succeeded.
|
2025-04-08 23:19:21 -05:00
|
|
|
|
2025-09-21 11:42:15 -05:00
|
|
|
NOTE: This feature has NO effect on policies. It ONLY applies to the
|
2025-04-08 23:19:21 -05:00
|
|
|
literal write function. If the create function returns `ENOSPC` or the
|
|
|
|
|
[policy returns `ENOSPC`](functions_categories_policies.md#filtering)
|
|
|
|
|
that error will be returned back to the application making the
|
|
|
|
|
`create` request.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Additional Reading
|
|
|
|
|
|
|
|
|
|
* [Functions, Categories, Policies](functions_categories_policies.md)
|
|
|
|
|
* [Why do I get an "out of space" / "no space left on device" / ENOSPC
|
|
|
|
|
error even though there appears to be lots of space
|
|
|
|
|
available?](../faq/why_isnt_it_working.md#why-do-i-get-an-out-of-space-no-space-left-on-device-enospc-error-even-though-there-appears-to-be-lots-of-space-available)
|
|
|
|
|
|