History

Merge patch series "fs: generic file IO error reporting"

Darrick J. Wong <djwong@kernel.org> says: This patchset adds some generic helpers so that filesystems can report errors to fsnotify in a standard way. Then it adapts iomap to use the generic helpers so that any iomap-enabled filesystem can report I/O errors through this mechanism as well. Finally, it makes XFS report metadata errors through this mechanism in much the same way that ext4 does now. These are a prerequisite for the XFS self-healing series which will come at a later time. * patches from https://patch.msgid.link/176826402528.3490369.2415315475116356277.stgit@frogsfrogsfrogs: ext4: convert to new fserror helpers xfs: translate fsdax media errors into file "data lost" errors when convenient xfs: report fs metadata errors via fsnotify iomap: report file I/O errors to the VFS fs: report filesystem and file I/O errors to fsnotify uapi: promote EFSCORRUPTED and EUCLEAN to errno.h

Christian Brauner committed 10 months ago

Commit 347b7042 parents 8f0b4cc 81d2e1331 files · +373 −24Browse files

Unified · Split

31 files
  1. arch/alpha/include/uapi/asm/errno.h +2 −0
  2. arch/mips/include/uapi/asm/errno.h +2 −0
  3. arch/parisc/include/uapi/asm/errno.h +2 −0
  4. arch/sparc/include/uapi/asm/errno.h +2 −0
  5. fs/Makefile +1 −1
  6. fs/erofs/internal.h +0 −2
  7. fs/ext2/ext2.h +0 −1
  8. fs/ext4/ext4.h +0 −3
  9. fs/ext4/ioctl.c +2 −0
  10. fs/ext4/super.c +9 −4
  11. fs/f2fs/f2fs.h +0 −3
  12. fs/fserror.c +194 −0
  13. fs/iomap/buffered-io.c +22 −1
  14. fs/iomap/direct-io.c +12 −0
  15. fs/iomap/ioend.c +6 −0
  16. fs/minix/minix.h +0 −2
  17. fs/super.c +3 −0
  18. fs/udf/udf_sb.h +0 −2
  19. fs/xfs/xfs_fsops.c +4 −0
  20. fs/xfs/xfs_health.c +14 −0
  21. fs/xfs/xfs_linux.h +0 −2
  22. fs/xfs/xfs_notify_failure.c +4 −0
  23. include/linux/fs/super_types.h +7 −0
  24. include/linux/fserror.h +75 −0
  25. include/linux/jbd2.h +0 −3
  26. include/uapi/asm-generic/errno.h +2 −0
  27. tools/arch/alpha/include/uapi/asm/errno.h +2 −0
  28. tools/arch/mips/include/uapi/asm/errno.h +2 −0
  29. tools/arch/parisc/include/uapi/asm/errno.h +2 −0
  30. tools/arch/sparc/include/uapi/asm/errno.h +2 −0
  31. tools/include/uapi/asm-generic/errno.h +2 −0
arch/alpha/include/uapi/asm/errno.h+2−0
@@ -55,6 +55,7 @@ · 54 unmodified lines
5555 #define ENOSR 82 /* Out of streams resources */
5656 #define ETIME 83 /* Timer expired */
5757 #define EBADMSG 84 /* Not a data message */
58+#define EFSBADCRC EBADMSG /* Bad CRC detected */
5859 #define EPROTO 85 /* Protocol error */
5960 #define ENODATA 86 /* No data available */
6061 #define ENOSTR 87 /* Device not a stream */
@@ -96,6 +97,7 @@ · 35 unmodified lines
9697 #define EREMCHG 115 /* Remote address changed */
9798
9899 #define EUCLEAN 117 /* Structure needs cleaning */
100+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
99101 #define ENOTNAM 118 /* Not a XENIX named type file */
100102 #define ENAVAIL 119 /* No XENIX semaphores available */
101103 #define EISNAM 120 /* Is a named type file */
arch/mips/include/uapi/asm/errno.h+2−0
@@ -50,6 +50,7 @@ · 49 unmodified lines
5050 #define EDOTDOT 73 /* RFS specific error */
5151 #define EMULTIHOP 74 /* Multihop attempted */
5252 #define EBADMSG 77 /* Not a data message */
53+#define EFSBADCRC EBADMSG /* Bad CRC detected */
5354 #define ENAMETOOLONG 78 /* File name too long */
5455 #define EOVERFLOW 79 /* Value too large for defined data type */
5556 #define ENOTUNIQ 80 /* Name not unique on network */
@@ -88,6 +89,7 @@ · 32 unmodified lines
8889 #define EISCONN 133 /* Transport endpoint is already connected */
8990 #define ENOTCONN 134 /* Transport endpoint is not connected */
9091 #define EUCLEAN 135 /* Structure needs cleaning */
92+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
9193 #define ENOTNAM 137 /* Not a XENIX named type file */
9294 #define ENAVAIL 138 /* No XENIX semaphores available */
9395 #define EISNAM 139 /* Is a named type file */
arch/parisc/include/uapi/asm/errno.h+2−0
@@ -36,6 +36,7 @@ · 35 unmodified lines
3636
3737 #define EDOTDOT 66 /* RFS specific error */
3838 #define EBADMSG 67 /* Not a data message */
39+#define EFSBADCRC EBADMSG /* Bad CRC detected */
3940 #define EUSERS 68 /* Too many users */
4041 #define EDQUOT 69 /* Quota exceeded */
4142 #define ESTALE 70 /* Stale file handle */
@@ -62,6 +63,7 @@ · 20 unmodified lines
6263 #define ERESTART 175 /* Interrupted system call should be restarted */
6364 #define ESTRPIPE 176 /* Streams pipe error */
6465 #define EUCLEAN 177 /* Structure needs cleaning */
66+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
6567 #define ENOTNAM 178 /* Not a XENIX named type file */
6668 #define ENAVAIL 179 /* No XENIX semaphores available */
6769 #define EISNAM 180 /* Is a named type file */
arch/sparc/include/uapi/asm/errno.h+2−0
@@ -48,6 +48,7 @@ · 47 unmodified lines
4848 #define ENOSR 74 /* Out of streams resources */
4949 #define ENOMSG 75 /* No message of desired type */
5050 #define EBADMSG 76 /* Not a data message */
51+#define EFSBADCRC EBADMSG /* Bad CRC detected */
5152 #define EIDRM 77 /* Identifier removed */
5253 #define EDEADLK 78 /* Resource deadlock would occur */
5354 #define ENOLCK 79 /* No record locks available */
@@ -91,6 +92,7 @@ · 37 unmodified lines
9192 #define ENOTUNIQ 115 /* Name not unique on network */
9293 #define ERESTART 116 /* Interrupted syscall should be restarted */
9394 #define EUCLEAN 117 /* Structure needs cleaning */
95+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
9496 #define ENOTNAM 118 /* Not a XENIX named type file */
9597 #define ENAVAIL 119 /* No XENIX semaphores available */
9698 #define EISNAM 120 /* Is a named type file */
fs/Makefile+1−1
@@ -16,7 +16,7 @@ obj-y := open.o read_write.o file_table.o super.o \ · 15 unmodified lines
1616 stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \
1717 fs_dirent.o fs_context.o fs_parser.o fsopen.o init.o \
1818 kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \
19− file_attr.o
19+ file_attr.o fserror.o
2020
2121 obj-$(CONFIG_BUFFER_HEAD) += buffer.o mpage.o
2222 obj-$(CONFIG_PROC_FS) += proc_namespace.o
fs/erofs/internal.h+0−2
@@ -541,6 +541,4 @@ long erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); · 540 unmodified lines
541541 long erofs_compat_ioctl(struct file *filp, unsigned int cmd,
542542 unsigned long arg);
543543
544−#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
545−
546544 #endif /* __EROFS_INTERNAL_H */
fs/ext2/ext2.h+0−1
@@ -357,7 +357,6 @@ struct ext2_inode { · 356 unmodified lines
357357 */
358358 #define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
359359 #define EXT2_ERROR_FS 0x0002 /* Errors detected */
360−#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
361360
362361 /*
363362 * Mount flags
fs/ext4/ext4.h+0−3
@@ -3938,7 +3938,4 @@ extern int ext4_block_write_begin(handle_t *handle, struct folio *folio, · 3937 unmodified lines
39383938 get_block_t *get_block);
39393939 #endif /* __KERNEL__ */
39403940
3941−#define EFSBADCRC EBADMSG /* Bad CRC detected */
3942−#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
3943−
39443941 #endif /* _EXT4_H */
fs/ext4/ioctl.c+2−0
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include <linux/fsmap.h>
2727 #include "fsmap.h"
2828 #include <trace/events/ext4.h>
29+#include <linux/fserror.h>
2930
3031 typedef void ext4_update_sb_callback(struct ext4_sb_info *sbi,
3132 struct ext4_super_block *es,
@@ -844,6 +845,7 @@ int ext4_force_shutdown(struct super_block *sb, u32 flags) · 812 unmodified lines
844845 return -EINVAL;
845846 }
846847 clear_opt(sb, DISCARD);
848+ fserror_report_shutdown(sb, GFP_KERNEL);
847849 return 0;
848850 }
849851
fs/ext4/super.c+9−4
@@ -48,6 +48,7 @@ · 47 unmodified lines
4848 #include <linux/fsnotify.h>
4949 #include <linux/fs_context.h>
5050 #include <linux/fs_parser.h>
51+#include <linux/fserror.h>
5152
5253 #include "ext4.h"
5354 #include "ext4_extents.h" /* Needed for trace points definition */
@@ -824,7 +825,8 @@ void __ext4_error(struct super_block *sb, const char *function, · 770 unmodified lines
824825 sb->s_id, function, line, current->comm, &vaf);
825826 va_end(args);
826827 }
827− fsnotify_sb_error(sb, NULL, error ? error : EFSCORRUPTED);
828+ fserror_report_metadata(sb, error ? -abs(error) : -EFSCORRUPTED,
829+ GFP_ATOMIC);
828830
829831 ext4_handle_error(sb, force_ro, error, 0, block, function, line);
830832 }
@@ -856,7 +858,9 @@ void __ext4_error_inode(struct inode *inode, const char *function, · 25 unmodified lines
856858 current->comm, &vaf);
857859 va_end(args);
858860 }
859− fsnotify_sb_error(inode->i_sb, inode, error ? error : EFSCORRUPTED);
861+ fserror_report_file_metadata(inode,
862+ error ? -abs(error) : -EFSCORRUPTED,
863+ GFP_ATOMIC);
860864
861865 ext4_handle_error(inode->i_sb, false, error, inode->i_ino, block,
862866 function, line);
@@ -896,7 +900,7 @@ void __ext4_error_file(struct file *file, const char *function, · 33 unmodified lines
896900 current->comm, path, &vaf);
897901 va_end(args);
898902 }
899− fsnotify_sb_error(inode->i_sb, inode, EFSCORRUPTED);
903+ fserror_report_file_metadata(inode, -EFSCORRUPTED, GFP_ATOMIC);
900904
901905 ext4_handle_error(inode->i_sb, false, EFSCORRUPTED, inode->i_ino, block,
902906 function, line);
@@ -965,7 +969,8 @@ void __ext4_std_error(struct super_block *sb, const char *function, · 62 unmodified lines
965969 printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n",
966970 sb->s_id, function, line, errstr);
967971 }
968− fsnotify_sb_error(sb, NULL, errno ? errno : EFSCORRUPTED);
972+ fserror_report_metadata(sb, errno ? -abs(errno) : -EFSCORRUPTED,
973+ GFP_ATOMIC);
969974
970975 ext4_handle_error(sb, false, -errno, 0, 0, function, line);
971976 }
fs/f2fs/f2fs.h+0−3
@@ -5004,7 +5004,4 @@ static inline void f2fs_invalidate_internal_cache(struct f2fs_sb_info *sbi, · 5003 unmodified lines
50045004 f2fs_invalidate_compress_pages_range(sbi, blkaddr, len);
50055005 }
50065006
5007−#define EFSBADCRC EBADMSG /* Bad CRC detected */
5008−#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
5009−
50105007 #endif /* _LINUX_F2FS_H */
fs/fserror.c+194−0
@@ -0,0 +1,194 @@
1+// SPDX-License-Identifier: GPL-2.0-or-later
2+/*
3+ * Copyright (c) 2025 Oracle. All Rights Reserved.
4+ * Author: Darrick J. Wong <djwong@kernel.org>
5+ */
6+#include <linux/fs.h>
7+#include <linux/fsnotify.h>
8+#include <linux/mempool.h>
9+#include <linux/fserror.h>
10+
11+#define FSERROR_DEFAULT_EVENT_POOL_SIZE (32)
12+
13+static struct mempool fserror_events_pool;
14+
15+void fserror_mount(struct super_block *sb)
16+{
17+ /*
18+ * The pending error counter is biased by 1 so that we don't wake_var
19+ * until we're actually trying to unmount.
20+ */
21+ refcount_set(&sb->s_pending_errors, 1);
22+}
23+
24+void fserror_unmount(struct super_block *sb)
25+{
26+ /*
27+ * If we don't drop the pending error count to zero, then wait for it
28+ * to drop below 1, which means that the pending errors cleared and
29+ * hopefully we didn't saturate with 1 billion+ concurrent events.
30+ */
31+ if (!refcount_dec_and_test(&sb->s_pending_errors))
32+ wait_var_event(&sb->s_pending_errors,
33+ refcount_read(&sb->s_pending_errors) < 1);
34+}
35+
36+static inline void fserror_pending_dec(struct super_block *sb)
37+{
38+ if (refcount_dec_and_test(&sb->s_pending_errors))
39+ wake_up_var(&sb->s_pending_errors);
40+}
41+
42+static inline void fserror_free_event(struct fserror_event *event)
43+{
44+ fserror_pending_dec(event->sb);
45+ mempool_free(event, &fserror_events_pool);
46+}
47+
48+static void fserror_worker(struct work_struct *work)
49+{
50+ struct fserror_event *event =
51+ container_of(work, struct fserror_event, work);
52+ struct super_block *sb = event->sb;
53+
54+ if (sb->s_flags & SB_ACTIVE) {
55+ struct fs_error_report report = {
56+ /* send positive error number to userspace */
57+ .error = -event->error,
58+ .inode = event->inode,
59+ .sb = event->sb,
60+ };
61+
62+ if (sb->s_op->report_error)
63+ sb->s_op->report_error(event);
64+
65+ fsnotify(FS_ERROR, &report, FSNOTIFY_EVENT_ERROR, NULL, NULL,
66+ NULL, 0);
67+ }
68+
69+ iput(event->inode);
70+ fserror_free_event(event);
71+}
72+
73+static inline struct fserror_event *fserror_alloc_event(struct super_block *sb,
74+ gfp_t gfp_flags)
75+{
76+ struct fserror_event *event = NULL;
77+
78+ /*
79+ * If pending_errors already reached zero or is no longer active,
80+ * the superblock is being deactivated so there's no point in
81+ * continuing.
82+ *
83+ * The order of the check of s_pending_errors and SB_ACTIVE are
84+ * mandated by order of accesses in generic_shutdown_super and
85+ * fserror_unmount. Barriers are implicitly provided by the refcount
86+ * manipulations in this function and fserror_unmount.
87+ */
88+ if (!refcount_inc_not_zero(&sb->s_pending_errors))
89+ return NULL;
90+ if (!(sb->s_flags & SB_ACTIVE))
91+ goto out_pending;
92+
93+ event = mempool_alloc(&fserror_events_pool, gfp_flags);
94+ if (!event)
95+ goto out_pending;
96+
97+ /* mempool_alloc doesn't support GFP_ZERO */
98+ memset(event, 0, sizeof(*event));
99+ event->sb = sb;
100+ INIT_WORK(&event->work, fserror_worker);
101+
102+ return event;
103+
104+out_pending:
105+ fserror_pending_dec(sb);
106+ return NULL;
107+}
108+
109+/**
110+ * fserror_report - report a filesystem error of some kind
111+ *
112+ * @sb: superblock of the filesystem
113+ * @inode: inode within that filesystem, if applicable
114+ * @type: type of error encountered
115+ * @pos: start of inode range affected, if applicable
116+ * @len: length of inode range affected, if applicable
117+ * @error: error number encountered, must be negative
118+ * @gfp: memory allocation flags for conveying the event to a worker,
119+ * since this function can be called from atomic contexts
120+ *
121+ * Report details of a filesystem error to the super_operations::report_error
122+ * callback if present; and to fsnotify for distribution to userspace. @sb,
123+ * @gfp, @type, and @error must all be specified. For file I/O errors, the
124+ * @inode, @pos, and @len fields must also be specified. For file metadata
125+ * errors, @inode must be specified. If @inode is not NULL, then @inode->i_sb
126+ * must point to @sb.
127+ *
128+ * Reporting work is deferred to a workqueue to ensure that ->report_error is
129+ * called from process context without any locks held. An active reference to
130+ * the inode is maintained until event handling is complete, and unmount will
131+ * wait for queued events to drain.
132+ */
133+void fserror_report(struct super_block *sb, struct inode *inode,
134+ enum fserror_type type, loff_t pos, u64 len, int error,
135+ gfp_t gfp)
136+{
137+ struct fserror_event *event;
138+
139+ /* sb and inode must be from the same filesystem */
140+ WARN_ON_ONCE(inode && inode->i_sb != sb);
141+
142+ /* error number must be negative */
143+ WARN_ON_ONCE(error >= 0);
144+
145+ event = fserror_alloc_event(sb, gfp);
146+ if (!event)
147+ goto lost;
148+
149+ event->type = type;
150+ event->pos = pos;
151+ event->len = len;
152+ event->error = error;
153+
154+ /*
155+ * Can't iput from non-sleeping context, so grabbing another reference
156+ * to the inode must be the last thing before submitting the event.
157+ */
158+ if (inode) {
159+ event->inode = igrab(inode);
160+ if (!event->inode)
161+ goto lost_event;
162+ }
163+
164+ /*
165+ * Use schedule_work here even if we're already in process context so
166+ * that fsnotify and super_operations::report_error implementations are
167+ * guaranteed to run in process context without any locks held. Since
168+ * errors are supposed to be rare, the overhead shouldn't kill us any
169+ * more than the failing device will.
170+ */
171+ schedule_work(&event->work);
172+ return;
173+
174+lost_event:
175+ fserror_free_event(event);
176+lost:
177+ if (inode)
178+ pr_err_ratelimited(
179+ "%s: lost file I/O error report for ino %lu type %u pos 0x%llx len 0x%llx error %d",
180+ sb->s_id, inode->i_ino, type, pos, len, error);
181+ else
182+ pr_err_ratelimited(
183+ "%s: lost filesystem error report for type %u error %d",
184+ sb->s_id, type, error);
185+}
186+EXPORT_SYMBOL_GPL(fserror_report);
187+
188+static int __init fserror_init(void)
189+{
190+ return mempool_init_kmalloc_pool(&fserror_events_pool,
191+ FSERROR_DEFAULT_EVENT_POOL_SIZE,
192+ sizeof(struct fserror_event));
193+}
194+fs_initcall(fserror_init);
fs/iomap/buffered-io.c+22−1
@@ -8,6 +8,7 @@ · 7 unmodified lines
88 #include <linux/writeback.h>
99 #include <linux/swap.h>
1010 #include <linux/migrate.h>
11+#include <linux/fserror.h>
1112 #include "internal.h"
1213 #include "trace.h"
1314
@@ -371,8 +372,11 @@ static int iomap_read_inline_data(const struct iomap_iter *iter, · 357 unmodified lines
371372 if (folio_test_uptodate(folio))
372373 return 0;
373374
374− if (WARN_ON_ONCE(size > iomap->length))
375+ if (WARN_ON_ONCE(size > iomap->length)) {
376+ fserror_report_io(iter->inode, FSERR_BUFFERED_READ,
377+ iomap->offset, size, -EIO, GFP_NOFS);
375378 return -EIO;
379+ }
376380 if (offset > 0)
377381 ifs_alloc(iter->inode, folio, iter->flags);
378382
@@ -399,6 +403,11 @@ void iomap_finish_folio_read(struct folio *folio, size_t off, size_t len, · 20 unmodified lines
399403 spin_unlock_irqrestore(&ifs->state_lock, flags);
400404 }
401405
406+ if (error)
407+ fserror_report_io(folio->mapping->host, FSERR_BUFFERED_READ,
408+ folio_pos(folio) + off, len, error,
409+ GFP_ATOMIC);
410+
402411 if (finished)
403412 folio_end_read(folio, uptodate);
404413 }
@@ -540,6 +549,10 @@ static int iomap_read_folio_iter(struct iomap_iter *iter, · 135 unmodified lines
540549 if (!*bytes_submitted)
541550 iomap_read_init(folio);
542551 ret = ctx->ops->read_folio_range(iter, ctx, plen);
552+ if (ret < 0)
553+ fserror_report_io(iter->inode,
554+ FSERR_BUFFERED_READ, pos,
555+ plen, ret, GFP_NOFS);
543556 if (ret)
544557 return ret;
545558 *bytes_submitted += plen;
@@ -815,6 +828,10 @@ static int __iomap_write_begin(const struct iomap_iter *iter, · 269 unmodified lines
815828 else
816829 status = iomap_bio_read_folio_range_sync(iter,
817830 folio, block_start, plen);
831+ if (status < 0)
832+ fserror_report_io(iter->inode,
833+ FSERR_BUFFERED_READ, pos,
834+ len, status, GFP_NOFS);
818835 if (status)
819836 return status;
820837 }
@@ -1805,6 +1822,7 @@ int iomap_writeback_folio(struct iomap_writepage_ctx *wpc, struct folio *folio) · 984 unmodified lines
18051822 u64 pos = folio_pos(folio);
18061823 u64 end_pos = pos + folio_size(folio);
18071824 u64 end_aligned = 0;
1825+ loff_t orig_pos = pos;
18081826 size_t bytes_submitted = 0;
18091827 int error = 0;
18101828 u32 rlen;
@@ -1848,6 +1866,9 @@ int iomap_writeback_folio(struct iomap_writepage_ctx *wpc, struct folio *folio) · 37 unmodified lines
18481866
18491867 if (bytes_submitted)
18501868 wpc->nr_folios++;
1869+ if (error && pos > orig_pos)
1870+ fserror_report_io(inode, FSERR_BUFFERED_WRITE, orig_pos, 0,
1871+ error, GFP_NOFS);
18511872
18521873 /*
18531874 * We can have dirty bits set past end of file in page_mkwrite path
fs/iomap/direct-io.c+12−0
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 #include <linux/pagemap.h>
88 #include <linux/iomap.h>
99 #include <linux/task_io_accounting_ops.h>
10+#include <linux/fserror.h>
1011 #include "internal.h"
1112 #include "trace.h"
1213
@@ -78,6 +79,13 @@ static void iomap_dio_submit_bio(const struct iomap_iter *iter, · 65 unmodified lines
7879 }
7980 }
8081
82+static inline enum fserror_type iomap_dio_err_type(const struct iomap_dio *dio)
83+{
84+ if (dio->flags & IOMAP_DIO_WRITE)
85+ return FSERR_DIRECTIO_WRITE;
86+ return FSERR_DIRECTIO_READ;
87+}
88+
8189 ssize_t iomap_dio_complete(struct iomap_dio *dio)
8290 {
8391 const struct iomap_dio_ops *dops = dio->dops;
@@ -87,6 +95,10 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) · 3 unmodified lines
8795
8896 if (dops && dops->end_io)
8997 ret = dops->end_io(iocb, dio->size, ret, dio->flags);
98+ if (dio->error)
99+ fserror_report_io(file_inode(iocb->ki_filp),
100+ iomap_dio_err_type(dio), offset, dio->size,
101+ dio->error, GFP_NOFS);
90102
91103 if (likely(!ret)) {
92104 ret = dio->size;
fs/iomap/ioend.c+6−0
@@ -6,6 +6,7 @@ · 5 unmodified lines
66 #include <linux/list_sort.h>
77 #include <linux/pagemap.h>
88 #include <linux/writeback.h>
9+#include <linux/fserror.h>
910 #include "internal.h"
1011 #include "trace.h"
1112
@@ -55,6 +56,11 @@ static u32 iomap_finish_ioend_buffered(struct iomap_ioend *ioend) · 43 unmodified lines
5556
5657 /* walk all folios in bio, ending page IO on them */
5758 bio_for_each_folio_all(fi, bio) {
59+ if (ioend->io_error)
60+ fserror_report_io(inode, FSERR_BUFFERED_WRITE,
61+ folio_pos(fi.folio) + fi.offset,
62+ fi.length, ioend->io_error,
63+ GFP_ATOMIC);
5864 iomap_finish_folio_write(inode, fi.folio, fi.length);
5965 folio_count++;
6066 }
fs/minix/minix.h+0−2
@@ -175,6 +175,4 @@ static inline int minix_test_bit(int nr, const void *vaddr) · 174 unmodified lines
175175 __minix_error_inode((inode), __func__, __LINE__, \
176176 (fmt), ##__VA_ARGS__)
177177
178−#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
179−
180178 #endif /* FS_MINIX_H */
fs/super.c+3−0
@@ -36,6 +36,7 @@ · 35 unmodified lines
3636 #include <linux/lockdep.h>
3737 #include <linux/user_namespace.h>
3838 #include <linux/fs_context.h>
39+#include <linux/fserror.h>
3940 #include <uapi/linux/mount.h>
4041 #include "internal.h"
4142
@@ -363,6 +364,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, · 321 unmodified lines
363364 spin_lock_init(&s->s_inode_list_lock);
364365 INIT_LIST_HEAD(&s->s_inodes_wb);
365366 spin_lock_init(&s->s_inode_wblist_lock);
367+ fserror_mount(s);
366368
367369 s->s_count = 1;
368370 atomic_set(&s->s_active, 1);
@@ -622,6 +624,7 @@ void generic_shutdown_super(struct super_block *sb) · 253 unmodified lines
622624 sync_filesystem(sb);
623625 sb->s_flags &= ~SB_ACTIVE;
624626
627+ fserror_unmount(sb);
625628 cgroup_writeback_umount(sb);
626629
627630 /* Evict all inodes with zero refcount. */
fs/udf/udf_sb.h+0−2
@@ -55,8 +55,6 @@ · 54 unmodified lines
5555 #define MF_DUPLICATE_MD 0x01
5656 #define MF_MIRROR_FE_LOADED 0x02
5757
58−#define EFSCORRUPTED EUCLEAN
59−
6058 struct udf_meta_data {
6159 __u32 s_meta_file_loc;
6260 __u32 s_mirror_file_loc;
fs/xfs/xfs_fsops.c+4−0
@@ -26,6 +26,8 @@ · 25 unmodified lines
2626 #include "xfs_rtrefcount_btree.h"
2727 #include "xfs_metafile.h"
2828
29+#include <linux/fserror.h>
30+
2931 /*
3032 * Write new AG headers to disk. Non-transactional, but need to be
3133 * written and completed prior to the growfs transaction being logged.
@@ -540,6 +542,8 @@ xfs_do_force_shutdown( · 508 unmodified lines
540542 "Please unmount the filesystem and rectify the problem(s)");
541543 if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
542544 xfs_stack_trace();
545+
546+ fserror_report_shutdown(mp->m_super, GFP_KERNEL);
543547 }
544548
545549 /*
fs/xfs/xfs_health.c+14−0
@@ -20,6 +20,8 @@ · 19 unmodified lines
2020 #include "xfs_quota_defs.h"
2121 #include "xfs_rtgroup.h"
2222
23+#include <linux/fserror.h>
24+
2325 static void
2426 xfs_health_unmount_group(
2527 struct xfs_group *xg,
@@ -111,6 +113,8 @@ xfs_fs_mark_sick( · 85 unmodified lines
111113 spin_lock(&mp->m_sb_lock);
112114 mp->m_fs_sick |= mask;
113115 spin_unlock(&mp->m_sb_lock);
116+
117+ fserror_report_metadata(mp->m_super, -EFSCORRUPTED, GFP_NOFS);
114118 }
115119
116120 /* Mark per-fs metadata as having been checked and found unhealthy by fsck. */
@@ -126,6 +130,8 @@ xfs_fs_mark_corrupt( · 9 unmodified lines
126130 mp->m_fs_sick |= mask;
127131 mp->m_fs_checked |= mask;
128132 spin_unlock(&mp->m_sb_lock);
133+
134+ fserror_report_metadata(mp->m_super, -EFSCORRUPTED, GFP_NOFS);
129135 }
130136
131137 /* Mark a per-fs metadata healed. */
@@ -198,6 +204,8 @@ xfs_group_mark_sick( · 66 unmodified lines
198204 spin_lock(&xg->xg_state_lock);
199205 xg->xg_sick |= mask;
200206 spin_unlock(&xg->xg_state_lock);
207+
208+ fserror_report_metadata(xg->xg_mount->m_super, -EFSCORRUPTED, GFP_NOFS);
201209 }
202210
203211 /*
@@ -215,6 +223,8 @@ xfs_group_mark_corrupt( · 11 unmodified lines
215223 xg->xg_sick |= mask;
216224 xg->xg_checked |= mask;
217225 spin_unlock(&xg->xg_state_lock);
226+
227+ fserror_report_metadata(xg->xg_mount->m_super, -EFSCORRUPTED, GFP_NOFS);
218228 }
219229
220230 /*
@@ -287,6 +297,8 @@ xfs_inode_mark_sick( · 66 unmodified lines
287297 spin_lock(&VFS_I(ip)->i_lock);
288298 inode_state_clear(VFS_I(ip), I_DONTCACHE);
289299 spin_unlock(&VFS_I(ip)->i_lock);
300+
301+ fserror_report_file_metadata(VFS_I(ip), -EFSCORRUPTED, GFP_NOFS);
290302 }
291303
292304 /* Mark inode metadata as having been checked and found unhealthy by fsck. */
@@ -311,6 +323,8 @@ xfs_inode_mark_corrupt( · 18 unmodified lines
311323 spin_lock(&VFS_I(ip)->i_lock);
312324 inode_state_clear(VFS_I(ip), I_DONTCACHE);
313325 spin_unlock(&VFS_I(ip)->i_lock);
326+
327+ fserror_report_file_metadata(VFS_I(ip), -EFSCORRUPTED, GFP_NOFS);
314328 }
315329
316330 /* Mark parts of an inode healed. */
fs/xfs/xfs_linux.h+0−2
@@ -121,8 +121,6 @@ typedef __u32 xfs_nlink_t; · 120 unmodified lines
121121
122122 #define ENOATTR ENODATA /* Attribute not found */
123123 #define EWRONGFS EINVAL /* Mount with wrong filesystem type */
124−#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
125−#define EFSBADCRC EBADMSG /* Bad CRC detected */
126124
127125 #define __return_address __builtin_return_address(0)
128126
fs/xfs/xfs_notify_failure.c+4−0
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include <linux/mm.h>
2727 #include <linux/dax.h>
2828 #include <linux/fs.h>
29+#include <linux/fserror.h>
2930
3031 struct xfs_failure_info {
3132 xfs_agblock_t startblock;
@@ -116,6 +117,9 @@ xfs_dax_failure_fn( · 84 unmodified lines
116117 invalidate_inode_pages2_range(mapping, pgoff,
117118 pgoff + pgcnt - 1);
118119
120+ fserror_report_data_lost(VFS_I(ip), (u64)pgoff << PAGE_SHIFT,
121+ (u64)pgcnt << PAGE_SHIFT, GFP_NOFS);
122+
119123 xfs_irele(ip);
120124 return error;
121125 }
include/linux/fs/super_types.h+7−0
@@ -35,6 +35,7 @@ struct user_namespace; · 34 unmodified lines
3535 struct workqueue_struct;
3636 struct writeback_control;
3737 struct xattr_handler;
38+struct fserror_event;
3839
3940 extern struct super_block *blockdev_superblock;
4041
@@ -124,6 +125,9 @@ struct super_operations { · 83 unmodified lines
124125 */
125126 int (*remove_bdev)(struct super_block *sb, struct block_device *bdev);
126127 void (*shutdown)(struct super_block *sb);
128+
129+ /* Report a filesystem error */
130+ void (*report_error)(const struct fserror_event *event);
127131 };
128132
129133 struct super_block {
@@ -268,6 +272,9 @@ struct super_block { · 138 unmodified lines
268272 spinlock_t s_inode_wblist_lock;
269273 struct list_head s_inodes_wb; /* writeback inodes */
270274 long s_min_writeback_pages;
275+
276+ /* number of fserrors that are being sent to fsnotify/filesystems */
277+ refcount_t s_pending_errors;
271278 } __randomize_layout;
272279
273280 /*
include/linux/fserror.h+75−0
@@ -0,0 +1,75 @@
1+/* SPDX-License-Identifier: GPL-2.0-or-later */
2+/*
3+ * Copyright (c) 2025 Oracle. All Rights Reserved.
4+ * Author: Darrick J. Wong <djwong@kernel.org>
5+ */
6+#ifndef _LINUX_FSERROR_H__
7+#define _LINUX_FSERROR_H__
8+
9+void fserror_mount(struct super_block *sb);
10+void fserror_unmount(struct super_block *sb);
11+
12+enum fserror_type {
13+ /* pagecache I/O failed */
14+ FSERR_BUFFERED_READ,
15+ FSERR_BUFFERED_WRITE,
16+
17+ /* direct I/O failed */
18+ FSERR_DIRECTIO_READ,
19+ FSERR_DIRECTIO_WRITE,
20+
21+ /* out of band media error reported */
22+ FSERR_DATA_LOST,
23+
24+ /* filesystem metadata */
25+ FSERR_METADATA,
26+};
27+
28+struct fserror_event {
29+ struct work_struct work;
30+ struct super_block *sb;
31+ struct inode *inode;
32+ loff_t pos;
33+ u64 len;
34+ enum fserror_type type;
35+
36+ /* negative error number */
37+ int error;
38+};
39+
40+void fserror_report(struct super_block *sb, struct inode *inode,
41+ enum fserror_type type, loff_t pos, u64 len, int error,
42+ gfp_t gfp);
43+
44+static inline void fserror_report_io(struct inode *inode,
45+ enum fserror_type type, loff_t pos,
46+ u64 len, int error, gfp_t gfp)
47+{
48+ fserror_report(inode->i_sb, inode, type, pos, len, error, gfp);
49+}
50+
51+static inline void fserror_report_data_lost(struct inode *inode, loff_t pos,
52+ u64 len, gfp_t gfp)
53+{
54+ fserror_report(inode->i_sb, inode, FSERR_DATA_LOST, pos, len, -EIO,
55+ gfp);
56+}
57+
58+static inline void fserror_report_file_metadata(struct inode *inode, int error,
59+ gfp_t gfp)
60+{
61+ fserror_report(inode->i_sb, inode, FSERR_METADATA, 0, 0, error, gfp);
62+}
63+
64+static inline void fserror_report_metadata(struct super_block *sb, int error,
65+ gfp_t gfp)
66+{
67+ fserror_report(sb, NULL, FSERR_METADATA, 0, 0, error, gfp);
68+}
69+
70+static inline void fserror_report_shutdown(struct super_block *sb, gfp_t gfp)
71+{
72+ fserror_report(sb, NULL, FSERR_METADATA, 0, 0, -ESHUTDOWN, gfp);
73+}
74+
75+#endif /* _LINUX_FSERROR_H__ */
include/linux/jbd2.h+0−3
@@ -1815,7 +1815,4 @@ static inline int jbd2_handle_buffer_credits(handle_t *handle) · 1814 unmodified lines
18151815
18161816 #endif /* __KERNEL__ */
18171817
1818−#define EFSBADCRC EBADMSG /* Bad CRC detected */
1819−#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
1820−
18211818 #endif /* _LINUX_JBD2_H */
include/uapi/asm-generic/errno.h+2−0
@@ -55,6 +55,7 @@ · 54 unmodified lines
5555 #define EMULTIHOP 72 /* Multihop attempted */
5656 #define EDOTDOT 73 /* RFS specific error */
5757 #define EBADMSG 74 /* Not a data message */
58+#define EFSBADCRC EBADMSG /* Bad CRC detected */
5859 #define EOVERFLOW 75 /* Value too large for defined data type */
5960 #define ENOTUNIQ 76 /* Name not unique on network */
6061 #define EBADFD 77 /* File descriptor in bad state */
@@ -98,6 +99,7 @@ · 37 unmodified lines
9899 #define EINPROGRESS 115 /* Operation now in progress */
99100 #define ESTALE 116 /* Stale file handle */
100101 #define EUCLEAN 117 /* Structure needs cleaning */
102+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
101103 #define ENOTNAM 118 /* Not a XENIX named type file */
102104 #define ENAVAIL 119 /* No XENIX semaphores available */
103105 #define EISNAM 120 /* Is a named type file */
tools/arch/alpha/include/uapi/asm/errno.h+2−0
@@ -55,6 +55,7 @@ · 54 unmodified lines
5555 #define ENOSR 82 /* Out of streams resources */
5656 #define ETIME 83 /* Timer expired */
5757 #define EBADMSG 84 /* Not a data message */
58+#define EFSBADCRC EBADMSG /* Bad CRC detected */
5859 #define EPROTO 85 /* Protocol error */
5960 #define ENODATA 86 /* No data available */
6061 #define ENOSTR 87 /* Device not a stream */
@@ -96,6 +97,7 @@ · 35 unmodified lines
9697 #define EREMCHG 115 /* Remote address changed */
9798
9899 #define EUCLEAN 117 /* Structure needs cleaning */
100+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
99101 #define ENOTNAM 118 /* Not a XENIX named type file */
100102 #define ENAVAIL 119 /* No XENIX semaphores available */
101103 #define EISNAM 120 /* Is a named type file */
tools/arch/mips/include/uapi/asm/errno.h+2−0
@@ -50,6 +50,7 @@ · 49 unmodified lines
5050 #define EDOTDOT 73 /* RFS specific error */
5151 #define EMULTIHOP 74 /* Multihop attempted */
5252 #define EBADMSG 77 /* Not a data message */
53+#define EFSBADCRC EBADMSG /* Bad CRC detected */
5354 #define ENAMETOOLONG 78 /* File name too long */
5455 #define EOVERFLOW 79 /* Value too large for defined data type */
5556 #define ENOTUNIQ 80 /* Name not unique on network */
@@ -88,6 +89,7 @@ · 32 unmodified lines
8889 #define EISCONN 133 /* Transport endpoint is already connected */
8990 #define ENOTCONN 134 /* Transport endpoint is not connected */
9091 #define EUCLEAN 135 /* Structure needs cleaning */
92+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
9193 #define ENOTNAM 137 /* Not a XENIX named type file */
9294 #define ENAVAIL 138 /* No XENIX semaphores available */
9395 #define EISNAM 139 /* Is a named type file */
tools/arch/parisc/include/uapi/asm/errno.h+2−0
@@ -36,6 +36,7 @@ · 35 unmodified lines
3636
3737 #define EDOTDOT 66 /* RFS specific error */
3838 #define EBADMSG 67 /* Not a data message */
39+#define EFSBADCRC EBADMSG /* Bad CRC detected */
3940 #define EUSERS 68 /* Too many users */
4041 #define EDQUOT 69 /* Quota exceeded */
4142 #define ESTALE 70 /* Stale file handle */
@@ -62,6 +63,7 @@ · 20 unmodified lines
6263 #define ERESTART 175 /* Interrupted system call should be restarted */
6364 #define ESTRPIPE 176 /* Streams pipe error */
6465 #define EUCLEAN 177 /* Structure needs cleaning */
66+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
6567 #define ENOTNAM 178 /* Not a XENIX named type file */
6668 #define ENAVAIL 179 /* No XENIX semaphores available */
6769 #define EISNAM 180 /* Is a named type file */
tools/arch/sparc/include/uapi/asm/errno.h+2−0
@@ -48,6 +48,7 @@ · 47 unmodified lines
4848 #define ENOSR 74 /* Out of streams resources */
4949 #define ENOMSG 75 /* No message of desired type */
5050 #define EBADMSG 76 /* Not a data message */
51+#define EFSBADCRC EBADMSG /* Bad CRC detected */
5152 #define EIDRM 77 /* Identifier removed */
5253 #define EDEADLK 78 /* Resource deadlock would occur */
5354 #define ENOLCK 79 /* No record locks available */
@@ -91,6 +92,7 @@ · 37 unmodified lines
9192 #define ENOTUNIQ 115 /* Name not unique on network */
9293 #define ERESTART 116 /* Interrupted syscall should be restarted */
9394 #define EUCLEAN 117 /* Structure needs cleaning */
95+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
9496 #define ENOTNAM 118 /* Not a XENIX named type file */
9597 #define ENAVAIL 119 /* No XENIX semaphores available */
9698 #define EISNAM 120 /* Is a named type file */
tools/include/uapi/asm-generic/errno.h+2−0
@@ -55,6 +55,7 @@ · 54 unmodified lines
5555 #define EMULTIHOP 72 /* Multihop attempted */
5656 #define EDOTDOT 73 /* RFS specific error */
5757 #define EBADMSG 74 /* Not a data message */
58+#define EFSBADCRC EBADMSG /* Bad CRC detected */
5859 #define EOVERFLOW 75 /* Value too large for defined data type */
5960 #define ENOTUNIQ 76 /* Name not unique on network */
6061 #define EBADFD 77 /* File descriptor in bad state */
@@ -98,6 +99,7 @@ · 37 unmodified lines
9899 #define EINPROGRESS 115 /* Operation now in progress */
99100 #define ESTALE 116 /* Stale file handle */
100101 #define EUCLEAN 117 /* Structure needs cleaning */
102+#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
101103 #define ENOTNAM 118 /* Not a XENIX named type file */
102104 #define ENAVAIL 119 /* No XENIX semaphores available */
103105 #define EISNAM 120 /* Is a named type file */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t