All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ceph: preserve data writeback errors in fsync()
@ 2026-11-28  6:25 Andrew Morton
  2026-11-28  9:59 ` Xiubo Li
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Morton @ 2026-11-28  6:25 UTC (permalink / raw)
  To: Ilya Dryomov, Alex Markuze, Xiubo Li, Viacheslav Dubeyko
  Cc: ceph-devel, Andrew Morton

From: Andrew Morton <akpm@linux-foundation.org>
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.

Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: Alex Markuze <amarkuze@redhat.com>
Cc: Xiubo Li <xiubo.li@clyso.com>
Cc: Viacheslav Dubeyko <slava@dubeyko.com>

 fs/ceph/caps.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--- a/fs/ceph/caps.c~ceph-preserve-data-writeback-errors-in-fsync
+++ a/fs/ceph/caps.c
@@ -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));
_

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ceph: preserve data writeback errors in fsync()
  2026-11-28  6:25 [PATCH] ceph: preserve data writeback errors in fsync() Andrew Morton
@ 2026-11-28  9:59 ` Xiubo Li
  0 siblings, 0 replies; 2+ messages in thread
From: Xiubo Li @ 2026-11-28  9:59 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Ilya Dryomov, Alex Markuze, Viacheslav Dubeyko, ceph-devel

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: stable@vger.kernel.org

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:

Reviewed-by: Xiubo Li <xiubo.li@clyso.com>
Tested-by: Xiubo Li <xiubo.li@clyso.com>

Thanks,
- Xiubo

On Sat, 28 Nov 2026 at 07:25, Andrew Morton <akpm@linux-foundation.org> wrote:
>
> From: Andrew Morton <akpm@linux-foundation.org>
> 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.
>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Cc: Ilya Dryomov <idryomov@gmail.com>
> Cc: Alex Markuze <amarkuze@redhat.com>
> Cc: Xiubo Li <xiubo.li@clyso.com>
> Cc: Viacheslav Dubeyko <slava@dubeyko.com>
>
>  fs/ceph/caps.c |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> --- a/fs/ceph/caps.c~ceph-preserve-data-writeback-errors-in-fsync
> +++ a/fs/ceph/caps.c
> @@ -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));
> _

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-28 10:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  6:25 [PATCH] ceph: preserve data writeback errors in fsync() Andrew Morton
2026-11-28  9:59 ` Xiubo Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.