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.
This commit is contained in:
Antonio S. Musumeci 2026-11-22 01:27:22 -05:00
parent 33b0799d6b
commit bc7b7ffeae
3 changed files with 54 additions and 10 deletions

View file

@ -111,6 +111,35 @@ def test_partial_append():
return check_relocated(branches, pool, initial + payload)
def test_partial_without_move():
with enospc_pool("minfreespace=0,cache.files=full,cache.writeback=false,moveonenospc=false") as (
branches, pool, initial,
):
# Only one block fits. The bytes written before ENOSPC stay on
# disk, so the write must report them as a short write, not
# fail: a caller that retries the whole buffer would append
# them twice.
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:
try:
written = os.write(fd, payload)
except OSError as e:
return fail(f"append failed with {e.strerror} after writing a prefix")
finally:
os.close(fd)
if not 0 < written < len(payload):
return fail(f"append returned {written}, expected a short write")
with open(os.path.join(branches["source"], "target"), "rb") as stream:
actual = stream.read()
if actual != initial + payload[:written]:
return fail(f"source holds {len(actual)} bytes, expected {len(initial) + written}")
if holders(branches) != ["source"]:
return fail(f"target on {holders(branches)}, expected only source")
return 0
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
@ -187,6 +216,7 @@ def test_occupied_destination():
TESTS = (test_partial_append,
test_partial_without_move,
test_second_relocation,
test_occupied_destination)