fix: return the error, not a short count, for page cache flushes

- 072b07b6 made a write that fails with ENOSPC after part of it landed
  return the bytes written. The kernel issues writes to flush its page
  cache (cache.writeback, dirty mmap pages) with the writepage flag
  and ignores the size in the reply, then drops the pages. The short
  count lost the rest of the data and hid the error: write, fsync,
  msync and close all succeeded with half the data on disk, where
  2.42.2 returned ENOSPC from fsync or msync.
- Keep the short count for ordinary writes, which the kernel does
  handle, and return the error when the request has writepage set.
- TEST_movefile_enospc covers a writeback flush and an mmap msync with
  moveonenospc=false; both fail without this change. Note the
  exception in moveonenospc.md.

Initialize the flush-test error list before the first I/O operation so
an unexpected error propagates and the descriptor is still closed.
Use the mapping as a context manager for the same reason.
This commit is contained in:
Antonio S. Musumeci 2026-11-22 08:27:04 -05:00
parent 6e9bdd9564
commit 64d3af02a3
3 changed files with 82 additions and 11 deletions

View file

@ -36,7 +36,10 @@ will:
If at any point something fails the progress so far will be cleaned up
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.
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). It can't act on a short write, 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.