Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
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
|
|
|
import contextlib
|
|
|
|
|
import errno
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
import os
|
2026-11-06 11:24:49 -06:00
|
|
|
import shutil
|
|
|
|
|
import subprocess
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
import sys
|
2026-11-06 11:24:49 -06:00
|
|
|
import tempfile
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
|
|
|
|
|
from posix_parity import fail
|
2026-11-06 11:24:49 -06:00
|
|
|
from posix_parity import find_fusermount
|
|
|
|
|
from posix_parity import find_mergerfs
|
|
|
|
|
from posix_parity import mount_mergerfs
|
|
|
|
|
from posix_parity import unmount_mergerfs
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
|
|
|
|
|
|
2026-04-29 17:44:22 -05:00
|
|
|
SKIP = 77
|
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
|
|
|
CHUNK = 64 * 1024
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
|
|
|
|
|
|
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
|
|
|
class Skip(Exception):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
|
def enospc_pool(options, extra_tmpfs=()):
|
|
|
|
|
"""Mount mergerfs over `source`, the `extra_tmpfs` (name, size)
|
|
|
|
|
branches and an unconstrained `destination`, in that order.
|
|
|
|
|
`source` is a 1 MiB tmpfs holding `target` and is full except for
|
|
|
|
|
one block. `options` is the mount option string, or a function of
|
|
|
|
|
that block size returning it. Yields (branch paths by name, pool,
|
|
|
|
|
target content)."""
|
2026-11-06 11:24:49 -06:00
|
|
|
with tempfile.TemporaryDirectory(prefix="mergerfs-enospc-") as root:
|
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
|
|
|
names = ["source"] + [name for name, _ in extra_tmpfs] + ["destination"]
|
|
|
|
|
branches = {name: os.path.join(root, name) for name in names}
|
|
|
|
|
pool = os.path.join(root, "pool")
|
|
|
|
|
for directory in list(branches.values()) + [pool]:
|
2026-11-06 11:24:49 -06:00
|
|
|
os.mkdir(directory)
|
|
|
|
|
|
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
|
|
|
mounted_tmpfs = []
|
2026-11-06 11:24:49 -06:00
|
|
|
mounted = False
|
|
|
|
|
try:
|
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
|
|
|
for name, size in [("source", "1m")] + list(extra_tmpfs):
|
|
|
|
|
result = subprocess.run(
|
|
|
|
|
["mount", "-t", "tmpfs", "-o", f"size={size}", "tmpfs", branches[name]],
|
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
|
|
|
)
|
|
|
|
|
if result.returncode:
|
|
|
|
|
raise Skip(f"constrained tmpfs unavailable: {result.stderr.decode(errors='replace')}")
|
|
|
|
|
mounted_tmpfs.append(branches[name])
|
|
|
|
|
|
|
|
|
|
source = branches["source"]
|
2026-11-06 11:24:49 -06:00
|
|
|
block_size = os.statvfs(source).f_frsize
|
|
|
|
|
initial = b"initial\n" * (block_size // 8)
|
|
|
|
|
with open(os.path.join(source, "target"), "wb") as stream:
|
|
|
|
|
stream.write(initial)
|
|
|
|
|
|
|
|
|
|
stat = os.statvfs(source)
|
|
|
|
|
remaining = block_size
|
|
|
|
|
available = stat.f_bavail * stat.f_frsize
|
|
|
|
|
with open(os.path.join(source, "filler"), "wb") as stream:
|
|
|
|
|
stream.write(b"F" * (available - remaining))
|
|
|
|
|
|
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
|
|
|
if callable(options):
|
|
|
|
|
options = options(block_size)
|
|
|
|
|
mount_mergerfs([branches[name] for name in names], pool, options)
|
2026-11-06 11:24:49 -06:00
|
|
|
mounted = True
|
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
|
|
|
yield branches, pool, initial
|
|
|
|
|
finally:
|
|
|
|
|
if mounted:
|
|
|
|
|
unmount_mergerfs(pool)
|
|
|
|
|
# The daemon may still hold branch fds while it exits after
|
|
|
|
|
# the unmount. Lazy unmount; the namespace dies with us.
|
|
|
|
|
for path in reversed(mounted_tmpfs):
|
|
|
|
|
subprocess.run(["umount", "--lazy", path], check=True)
|
2026-11-06 11:24:49 -06:00
|
|
|
|
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
|
|
|
|
|
|
|
|
def holders(branches):
|
|
|
|
|
return [name for name, path in branches.items() if os.path.exists(os.path.join(path, "target"))]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_relocated(branches, pool, expected):
|
|
|
|
|
if holders(branches) != ["destination"]:
|
|
|
|
|
return fail(f"target on {holders(branches)}, expected only destination")
|
|
|
|
|
with open(os.path.join(branches["destination"], "target"), "rb") as stream:
|
|
|
|
|
actual = stream.read()
|
|
|
|
|
if actual != expected:
|
|
|
|
|
return fail(f"relocated file corrupted: expected {len(expected)} bytes, got {len(actual)}")
|
|
|
|
|
with open(os.path.join(pool, "target"), "rb") as stream:
|
|
|
|
|
if stream.read() != expected:
|
|
|
|
|
return fail("relocated file differs through the pool")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_partial_append():
|
|
|
|
|
with enospc_pool("minfreespace=0,cache.files=full,cache.writeback=false,moveonenospc=mfs") as (
|
|
|
|
|
branches, pool, initial,
|
|
|
|
|
):
|
|
|
|
|
# The first write appends a prefix before ENOSPC. Relocation must
|
|
|
|
|
# preserve that progress instead of replaying it on the new branch.
|
|
|
|
|
block_size = len(initial)
|
|
|
|
|
payload = bytes(range(256)) * (block_size // 64)
|
|
|
|
|
fd = os.open(os.path.join(pool, "target"), os.O_WRONLY | os.O_APPEND)
|
|
|
|
|
try:
|
|
|
|
|
written = os.write(fd, payload)
|
|
|
|
|
finally:
|
|
|
|
|
os.close(fd)
|
|
|
|
|
if written != len(payload):
|
|
|
|
|
return fail(f"append returned {written}, expected {len(payload)}")
|
|
|
|
|
return check_relocated(branches, pool, initial + payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_second_relocation():
|
|
|
|
|
# lfs over branches with at least minfreespace free picks `middle`
|
|
|
|
|
# first; once it fills too only `destination` is left. The same open
|
|
|
|
|
# handle has to move twice. Sizes follow the block size: a chunk
|
|
|
|
|
# must not fit in the block left free on `source`, and the two
|
|
|
|
|
# blocks the first move frees there must stay below minfreespace.
|
|
|
|
|
# With 64K pages fixed 64K values fail both.
|
|
|
|
|
def options(block_size):
|
|
|
|
|
return (f"minfreespace={max(CHUNK, 4 * block_size)},"
|
|
|
|
|
"cache.files=full,cache.writeback=false,moveonenospc=lfs")
|
|
|
|
|
|
|
|
|
|
with enospc_pool(options, extra_tmpfs=[("middle", "512k")]) as (branches, pool, initial):
|
|
|
|
|
chunk_size = max(CHUNK, 2 * len(initial))
|
|
|
|
|
expected = bytearray(initial)
|
|
|
|
|
fd = os.open(os.path.join(pool, "target"), os.O_WRONLY | os.O_APPEND)
|
|
|
|
|
try:
|
|
|
|
|
for i in range(16):
|
|
|
|
|
chunk = bytes([i]) * chunk_size
|
|
|
|
|
try:
|
|
|
|
|
written = os.write(fd, chunk)
|
|
|
|
|
except OSError as e:
|
|
|
|
|
return fail(f"chunk {i} failed with {e.strerror}; target on {holders(branches)}")
|
|
|
|
|
if written != len(chunk):
|
|
|
|
|
return fail(f"chunk {i} returned {written}, expected {len(chunk)}")
|
|
|
|
|
expected += chunk
|
|
|
|
|
if i == 0 and holders(branches) != ["middle"]:
|
|
|
|
|
return fail(f"first relocation put target on {holders(branches)}, expected middle")
|
|
|
|
|
finally:
|
|
|
|
|
os.close(fd)
|
|
|
|
|
return check_relocated(branches, pool, bytes(expected))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_occupied_destination():
|
|
|
|
|
options = "minfreespace=0,cache.files=off,func.open=ff,moveonenospc=ff"
|
|
|
|
|
with enospc_pool(options, extra_tmpfs=[("occupied", "1m")]) as (branches, pool, initial):
|
|
|
|
|
occupied = os.path.join(branches["occupied"], "target")
|
|
|
|
|
original = b"independent file\n"
|
|
|
|
|
with open(occupied, "wb") as stream:
|
|
|
|
|
stream.write(original)
|
|
|
|
|
|
|
|
|
|
payload = b"A" * (2 * len(initial))
|
|
|
|
|
fd = os.open(os.path.join(pool, "target"), os.O_RDWR | os.O_APPEND)
|
|
|
|
|
try:
|
|
|
|
|
if os.read(fd, len(initial)) != initial:
|
|
|
|
|
return fail("first-found open did not select the source target")
|
|
|
|
|
# Consume the fixture's last block. The target already ends on
|
|
|
|
|
# a block boundary, so even a short append requires relocation.
|
|
|
|
|
with open(os.path.join(branches["source"], "filler"), "ab") as stream:
|
|
|
|
|
stream.write(initial)
|
|
|
|
|
if os.statvfs(branches["source"]).f_bavail != 0:
|
|
|
|
|
return fail("source still has space before append")
|
2026-05-07 20:43:42 -05:00
|
|
|
try:
|
2026-11-06 11:24:49 -06:00
|
|
|
written = os.write(fd, payload)
|
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
|
|
|
except OSError as e:
|
|
|
|
|
if e.errno != errno.ENOSPC:
|
|
|
|
|
raise
|
|
|
|
|
else:
|
|
|
|
|
return fail(f"append returned {written}, expected ENOSPC")
|
2026-11-06 11:24:49 -06:00
|
|
|
finally:
|
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
|
|
|
os.close(fd)
|
|
|
|
|
# A held handle can mask a change in what the pool name resolves to.
|
|
|
|
|
with open(os.path.join(pool, "target"), "rb") as stream:
|
|
|
|
|
if stream.read() != initial:
|
|
|
|
|
return fail("pool reopen did not return the original source contents")
|
|
|
|
|
with open(os.path.join(branches["source"], "target"), "rb") as stream:
|
|
|
|
|
if stream.read() != initial:
|
|
|
|
|
return fail("refused append changed the source target")
|
|
|
|
|
with open(occupied, "rb") as stream:
|
|
|
|
|
if stream.read() != original:
|
|
|
|
|
return fail("relocation overwrote an independent target")
|
|
|
|
|
if os.listdir(branches["destination"]):
|
|
|
|
|
return fail("refused relocation left a copy on the empty branch")
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TESTS = (test_partial_append,
|
|
|
|
|
test_second_relocation,
|
|
|
|
|
test_occupied_destination)
|
2026-05-07 20:43:42 -05:00
|
|
|
|
|
|
|
|
|
2026-11-06 11:24:49 -06:00
|
|
|
def main():
|
|
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == "--isolated":
|
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
|
|
|
for test in TESTS:
|
|
|
|
|
try:
|
|
|
|
|
rv = test()
|
|
|
|
|
except Skip as e:
|
|
|
|
|
print(e, end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
if rv:
|
|
|
|
|
print(f" ({test.__name__})", end="")
|
|
|
|
|
return rv
|
|
|
|
|
return 0
|
2026-11-06 11:24:49 -06:00
|
|
|
|
|
|
|
|
if find_mergerfs() is None or find_fusermount() is None:
|
|
|
|
|
print("mergerfs or fusermount unavailable", end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
if any(shutil.which(tool) is None for tool in ("unshare", "mount", "umount")):
|
|
|
|
|
print("unshare/mount/umount unavailable", end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
|
|
|
|
|
# Limit disk usage inside a private namespace, including for non-root runs.
|
|
|
|
|
namespace = ["unshare", "-Urnm"]
|
|
|
|
|
probe = subprocess.run(namespace + ["true"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
|
if probe.returncode:
|
|
|
|
|
print("private user/mount namespaces unavailable", end="")
|
|
|
|
|
return SKIP
|
|
|
|
|
return subprocess.run(namespace + [sys.executable, os.path.realpath(__file__), "--isolated"]).returncode
|
Add unit and integration tests for recently changed code
Unit tests (29 new in tests/tests.cpp):
- str::eq() and str::startswith() char* nullptr safety
- str::from() u64/s64/int suffix parsing (K/M/G/T, overflow, invalid)
- num::humanize() byte formatting (0, 512, 1K, 1M, 1G, 1T, non-exact)
- RmdirErr priority error accumulation (ENOTEMPTY/EEXIST override rules)
- HashSet inline-to-heap growth, empty string, and large insertion
- fs::inode algorithm switching (valid/invalid names, passthrough raw ino,
distinct inodes across algorithms)
- RND::rand64() bounds (range, max, shrink_to_rand_elem)
- Branches::Impl copy and move assignment re-links default_minfreespace
Integration tests (5 new in tests/):
- TEST_policy_lup: LUP policy create and search
- TEST_rmdir_enotempty_priority: rmdir returns ENOTEMPTY for non-empty dirs
- TEST_open_after_unlink: read/write via fd after unlink
- TEST_api_xattr: mergerfs xattr API (fullpath, relpath, basepath, allpaths)
- TEST_movefile_enospc: moveonenospc configuration round-trip
Also: remove xattr nosys checks from TEST_cfg_xattr_modes, reformat
integration test scripts to use temp_dir/cleanup_dir helpers, and
minor parameter alignment changes in fuse_getxattr, fuse_init,
fuse_rename.
2026-04-29 12:19:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2026-04-29 17:44:22 -05:00
|
|
|
raise SystemExit(main())
|