Skip to content

ceph: fix -EAGAIN from buffered writes racing with snapshots

Venky Shankar ceph-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest1 patch 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1ceph: don't fail write_begin with -EAGAIN after flushing old snapcfs/ceph/addr.c+6 -11 reply

Reviews trailers per patch

The patch has a Reviewed-by or Acked-by.

PatchAlex Markuze
1/1R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/1] ceph: fix -EAGAIN from buffered writes racing with snapshots

Buffered writes on a CephFS kernel mount can fail with EAGAIN ("Resource temporarily unavailable") when they rewrite a page that is still dirty in an older snap context which cannot be flushed yet. We have been hitting this in CephFS QA (teuthology) runs that take snapshots while the workload is writing:

- kernel untar/build workunit, failing in the final link (ceph-client testing kernel, 7.3.0-rc1-g7f77d684f595)
https://pulpito.ceph.com/vshankar-2026-10-07_07:40:54-fs:workload-wip-77519-trial1-distro-default-trial/613906/

  2026-10-07T08:18:00.721 INFO:tasks.workunit.client.0.trial024.stderr:ld: final link failed: Resource temporarily unavailable

- dbench workunit (stock distro kernel)
https://pulpito.ceph.com/vshankar-2026-10-02_21:48:19-fs-wip-vshankar-testing-20261002.175142-distro-default-trial/602723/

  2026-10-02T22:35:02.642 INFO:tasks.workunit.client.0.trial029.stdout:[483386] write failed on handle 10895 (Resource temporarily unavailable)

Tracker: https://tracker.ceph.com/issues/57656

When ceph_netfs_check_write_begin() finds the folio dirty in a snap context that is neither the head nor the oldest one with dirty data, it unlocks and puts the folio, kicks writeback, waits for the older snap contexts to be flushed and then returns -EAGAIN so that the write is retried.

Since commit fac47b43c760 ("netfs: do not unlock and put the folio twice"), netfs_write_begin() retries only when ->check_write_begin() returns 0 with *foliop cleared; -EAGAIN gets no special treatment. That commit converted ceph to clear *foliop but left the -EAGAIN return in place, so since v5.19 the error goes all the way up to write(2) as soon as the wait succeeds. The patch returns the wait result as is.

Reproducer (single kernel client, snapshots enabled), in a directory on the mount:

f=file

  w() { dd if=/dev/urandom of=$f bs=4096 count=1 seek=$1 \
           conv=notrunc status=none; }
  w 0; mkdir .snap/a   # block 0 dirty in snap a
  w 1; mkdir .snap/b   # block 1 dirty in snap b
  w 1                  # unpatched: EAGAIN

The last write finds block 1 dirty in snap b while snap a still has a dirty page, so it waits for a to be flushed (~10ms here) and then fails. The dirty pages are not written back on snapshot creation, so the default 30s dirty expiry leaves plenty of time to hit this.

Results:
- unpatched: EAGAIN on the first iteration
- patched: 50 out of 50 iterations pass

With ceph dynamic debug enabled, the unpatched run shows ceph_find_incompatible() reporting the folio as "not current or oldest", writeback completing snap a's cap snap, and the writer dropping its cap refs right after waking up instead of retrying.

Venky Shankar (1):
ceph: don't fail write_begin with -EAGAIN after flushing old snapc

 fs/ceph/addr.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.50.1 (Apple Git-155)