linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xfs: report a writeback error on a read() call
@ 2025-06-22 12:32 ying chen
  2025-06-24 14:14 ` Christoph Hellwig
  0 siblings, 1 reply; 18+ messages in thread
From: ying chen @ 2025-06-22 12:32 UTC (permalink / raw)
  To: djwong, linux-xfs, linux-kernel

Normally, user space returns immediately after writing data to the
buffer cache. However, if an error occurs during the actual disk
write operation, data loss may ensue, and there is no way to report
this error back to user space immediately. Current kernels may report
writeback errors when fsync() is called, but frequent invocations of
fsync() can degrade performance. Therefore, a new sysctl
fs.xfs.report_writeback_error_on_read is introduced, which, when set
to 1, reports writeback errors when read() is called. This allows user
space to be notified of writeback errors more promptly.

Signed-off-by: fengchangqing <fengchangqing@pinduoduo.com>
---
 fs/xfs/xfs_file.c    | 9 +++++++++
 fs/xfs/xfs_globals.c | 1 +
 fs/xfs/xfs_linux.h   | 1 +
 fs/xfs/xfs_sysctl.c  | 9 +++++++++
 fs/xfs/xfs_sysctl.h  | 1 +
 5 files changed, 21 insertions(+)

diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 595a5bc..8bf0a83 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -288,12 +288,21 @@
        struct inode            *inode = file_inode(iocb->ki_filp);
        struct xfs_mount        *mp = XFS_I(inode)->i_mount;
        ssize_t                 ret = 0;
+       int                     error = 0;
+       errseq_t                since;

        XFS_STATS_INC(mp, xs_read_calls);

        if (xfs_is_shutdown(mp))
                return -EIO;

+       if (xfs_report_writeback_error_on_read) {
+               since = READ_ONCE(iocb->ki_filp->f_wb_err);
+               error = filemap_check_wb_err(inode->i_mapping, since);
+               if (error)
+                       return  error;
+       }
+
        if (IS_DAX(inode))
                ret = xfs_file_dax_read(iocb, to);
        else if (iocb->ki_flags & IOCB_DIRECT)
diff --git a/fs/xfs/xfs_globals.c b/fs/xfs/xfs_globals.c
index 4d0a98f..9983a2f 100644
--- a/fs/xfs/xfs_globals.c
+++ b/fs/xfs/xfs_globals.c
@@ -29,6 +29,7 @@
        .inherit_nodfrg = {     0,              1,              1       },
        .fstrm_timer    = {     1,              30*100,         3600*100},
        .blockgc_timer  = {     1,              300,            3600*24},
+       .report_writeback_error_on_read = {     0,              0,
         1},
 };

 struct xfs_globals xfs_globals = {
diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
index f987802..bbe8bdb 100644
--- a/fs/xfs/xfs_linux.h
+++ b/fs/xfs/xfs_linux.h
@@ -100,6 +100,7 @@
 #define xfs_inherit_nodefrag   xfs_params.inherit_nodfrg.val
 #define xfs_fstrm_centisecs    xfs_params.fstrm_timer.val
 #define xfs_blockgc_secs       xfs_params.blockgc_timer.val
+#define xfs_report_writeback_error_on_read
xfs_params.report_writeback_error_on_read.val

 #define current_cpu()          (raw_smp_processor_id())
 #define current_set_flags_nested(sp, f)                \
diff --git a/fs/xfs/xfs_sysctl.c b/fs/xfs/xfs_sysctl.c
index 546a6cd..fbec214 100644
--- a/fs/xfs/xfs_sysctl.c
+++ b/fs/xfs/xfs_sysctl.c
@@ -194,6 +194,15 @@
                .extra1         = &xfs_params.blockgc_timer.min,
                .extra2         = &xfs_params.blockgc_timer.max,
        },
+       {
+               .procname       = "report_writeback_error_on_read",
+               .data           =
&xfs_params.report_writeback_error_on_read.val,
+               .maxlen         = sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = xfs_deprecated_dointvec_minmax,
+               .extra1         =
&xfs_params.report_writeback_error_on_read.min,
+               .extra2         =
&xfs_params.report_writeback_error_on_read.max,
+       },
        /* please keep this the last entry */
 #ifdef CONFIG_PROC_FS
        {
diff --git a/fs/xfs/xfs_sysctl.h b/fs/xfs/xfs_sysctl.h
index f78ad6b..fa0688a 100644
--- a/fs/xfs/xfs_sysctl.h
+++ b/fs/xfs/xfs_sysctl.h
@@ -36,6 +36,7 @@
        xfs_sysctl_val_t inherit_nodfrg;/* Inherit the "nodefrag" inode flag. */
        xfs_sysctl_val_t fstrm_timer;   /* Filestream dir-AG assoc'n timeout. */
        xfs_sysctl_val_t blockgc_timer; /* Interval between blockgc scans */
+       xfs_sysctl_val_t report_writeback_error_on_read; /*  Report a
writeback error on a read() call. */
 } xfs_param_t;

 /*
--
1.8.3.1

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

end of thread, other threads:[~2025-06-27 21:19 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-22 12:32 [PATCH] xfs: report a writeback error on a read() call ying chen
2025-06-24 14:14 ` Christoph Hellwig
2025-06-24 18:26   ` Jeff Layton
2025-06-24 19:56     ` Matthew Wilcox
2025-06-24 20:25       ` Jeff Layton
2025-06-25  2:44   ` Yafang Shao
2025-06-25  7:01     ` Christoph Hellwig
2025-06-25 10:40       ` Jeff Layton
2025-06-25 11:21         ` Christoph Hellwig
2025-06-25 11:49           ` Jeff Layton
2025-06-25 11:56             ` Christoph Hellwig
2025-06-25 14:06               ` Jeff Layton
2025-06-26  2:41                 ` Yafang Shao
2025-06-26  3:57                   ` Dave Chinner
2025-06-26 10:25                     ` Christoph Hellwig
2025-06-26 22:22                       ` Dave Chinner
2025-06-27 21:19                         ` Matthew Wilcox
2025-06-26 10:23                   ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).