Skip to contentSkip to conversation

ceph: preserve data writeback errors in fsync()

PATCH In review Andrew Morton 2 participants 2 messages Nov 28 Ceph client

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: preserve data writeback errors in fsync()

From: Andrew Morton <[email protected]>
Subject: ceph: preserve data writeback errors in fsync()
Date: Mon, 23 Nov 2026 13:28:28 -0800

file_write_and_wait_range() can return -EIO for failed data writeback and advances the file's writeback error cursor. ceph_fsync() then overwrites that return value with the result of ceph_wait_on_async_create(), which is normally zero. The later file_check_and_advance_wb_err() cannot recover the error because the cursor has already advanced. As a result, fsync() can report success after an ordinary writeback I/O failure or after a memory failure poisons a dirty page-cache page.

Keep the data writeback result when the async create wait succeeds, while still returning an error from that wait if it fails.

Cc Ilya Dryomov <[email protected]>
Cc Alex Markuze <[email protected]>
Cc Xiubo Li <[email protected]>
Cc Viacheslav Dubeyko <[email protected]>
 fs/ceph/caps.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ceph/caps.c renamed from fs/ceph/caps.c~ceph-preserve-data-writeback-errors-in-fsync +4 -2
@@ -2651,9 +2651,11 @@ int ceph_fsync(struct file *file, loff_t
 	if (datasync)
 		goto out;
 
-	ret = ceph_wait_on_async_create(inode);
-	if (ret)
+	err = ceph_wait_on_async_create(inode);
+	if (err) {
+		ret = err;
 		goto out;
+	}
 
 	dirty = try_flush_caps(inode, &flush_tid);
 	doutc(cl, "dirty caps are %s\n", ceph_cap_string(dirty));

_

Reviewed-by Tested-by on v1 1/1
#1 lore raw

Hi Andrew,

Good catch, thanks.

This came in with the async create wait, so I think it should carry:

Fixes 891f3f5a6a06 ("ceph: add infrastructure for waiting for async

create to complete")
Cc: [email protected]

I reproduced it on the ceph-client testing branch (3f90412e989c), with a KASAN + lockdep kernel against a vstart cluster, in two ways: a dirty page-cache page poisoned with MADV_HWPOISON, and an ordinary writeback failure (data pool quota full, so the OSD writes fail with -ENOSPC). Return values of the first and second call on the same fd:

                            without patch    with patch
  fsync()      hwpoison     0, 0             -EIO, 0
  fsync()      pool full    0, 0             -ENOSPC, 0
  fdatasync()  hwpoison     -EIO, 0          -EIO, 0
  fdatasync()  pool full    -ENOSPC, 0       -ENOSPC, 0

Without the patch fsync() returns 0 and the error is lost, while fdatasync() on the same setup reports it. With the patch both report it once. An error-free fsync() still returns 0, and a short fsstress run with fsync/fdatasync ops was clean.

Feel free to add:

Thanks,
- Xiubo

Quoted 42 lines · Andrew Morton

From: Andrew Morton <[email protected]>
Subject: ceph: preserve data writeback errors in fsync()
Date: Mon, 23 Nov 2026 13:28:28 -0800

file_write_and_wait_range() can return -EIO for failed data writeback and advances the file's writeback error cursor. ceph_fsync() then overwrites that return value with the result of ceph_wait_on_async_create(), which is normally zero. The later file_check_and_advance_wb_err() cannot recover the error because the cursor has already advanced. As a result, fsync() can report success after an ordinary writeback I/O failure or after a memory failure poisons a dirty page-cache page.

Keep the data writeback result when the async create wait succeeds, while still returning an error from that wait if it fails.

Cc Ilya Dryomov <[email protected]>
Cc Alex Markuze <[email protected]>
Cc Xiubo Li <[email protected]>
Cc Viacheslav Dubeyko <[email protected]>
 fs/ceph/caps.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ceph/caps.c renamed from fs/ceph/caps.c~ceph-preserve-data-writeback-errors-in-fsync +4 -2
@@ -2651,9 +2651,11 @@ int ceph_fsync(struct file *file, loff_t
        if (datasync)
                goto out;
 
-       ret = ceph_wait_on_async_create(inode);
-       if (ret)
+       err = ceph_wait_on_async_create(inode);
+       if (err) {
+               ret = err;
                goto out;
+       }
 
        dirty = try_flush_caps(inode, &flush_tid);
        doutc(cl, "dirty caps are %s\n", ceph_cap_string(dirty));

_