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
Unified · Split
| @@ -55,6 +55,7 @@ · 54 unmodified lines | |||
| 55 | #define ENOSR 82 /* Out of streams resources */ | 55 | #define ENOSR 82 /* Out of streams resources */ |
| 56 | #define ETIME 83 /* Timer expired */ | 56 | #define ETIME 83 /* Timer expired */ |
| 57 | #define EBADMSG 84 /* Not a data message */ | 57 | #define EBADMSG 84 /* Not a data message */ |
| 58 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 58 | #define EPROTO 85 /* Protocol error */ | 59 | #define EPROTO 85 /* Protocol error */ |
| 59 | #define ENODATA 86 /* No data available */ | 60 | #define ENODATA 86 /* No data available */ |
| 60 | #define ENOSTR 87 /* Device not a stream */ | 61 | #define ENOSTR 87 /* Device not a stream */ |
| @@ -96,6 +97,7 @@ · 35 unmodified lines | |||
| 96 | #define EREMCHG 115 /* Remote address changed */ | 97 | #define EREMCHG 115 /* Remote address changed */ |
| 97 | 98 | ||
| 98 | #define EUCLEAN 117 /* Structure needs cleaning */ | 99 | #define EUCLEAN 117 /* Structure needs cleaning */ |
| 100 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 99 | #define ENOTNAM 118 /* Not a XENIX named type file */ | 101 | #define ENOTNAM 118 /* Not a XENIX named type file */ |
| 100 | #define ENAVAIL 119 /* No XENIX semaphores available */ | 102 | #define ENAVAIL 119 /* No XENIX semaphores available */ |
| 101 | #define EISNAM 120 /* Is a named type file */ | 103 | #define EISNAM 120 /* Is a named type file */ |
| @@ -50,6 +50,7 @@ · 49 unmodified lines | |||
| 50 | #define EDOTDOT 73 /* RFS specific error */ | 50 | #define EDOTDOT 73 /* RFS specific error */ |
| 51 | #define EMULTIHOP 74 /* Multihop attempted */ | 51 | #define EMULTIHOP 74 /* Multihop attempted */ |
| 52 | #define EBADMSG 77 /* Not a data message */ | 52 | #define EBADMSG 77 /* Not a data message */ |
| 53 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 53 | #define ENAMETOOLONG 78 /* File name too long */ | 54 | #define ENAMETOOLONG 78 /* File name too long */ |
| 54 | #define EOVERFLOW 79 /* Value too large for defined data type */ | 55 | #define EOVERFLOW 79 /* Value too large for defined data type */ |
| 55 | #define ENOTUNIQ 80 /* Name not unique on network */ | 56 | #define ENOTUNIQ 80 /* Name not unique on network */ |
| @@ -88,6 +89,7 @@ · 32 unmodified lines | |||
| 88 | #define EISCONN 133 /* Transport endpoint is already connected */ | 89 | #define EISCONN 133 /* Transport endpoint is already connected */ |
| 89 | #define ENOTCONN 134 /* Transport endpoint is not connected */ | 90 | #define ENOTCONN 134 /* Transport endpoint is not connected */ |
| 90 | #define EUCLEAN 135 /* Structure needs cleaning */ | 91 | #define EUCLEAN 135 /* Structure needs cleaning */ |
| 92 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 91 | #define ENOTNAM 137 /* Not a XENIX named type file */ | 93 | #define ENOTNAM 137 /* Not a XENIX named type file */ |
| 92 | #define ENAVAIL 138 /* No XENIX semaphores available */ | 94 | #define ENAVAIL 138 /* No XENIX semaphores available */ |
| 93 | #define EISNAM 139 /* Is a named type file */ | 95 | #define EISNAM 139 /* Is a named type file */ |
| @@ -36,6 +36,7 @@ · 35 unmodified lines | |||
| 36 | 36 | ||
| 37 | #define EDOTDOT 66 /* RFS specific error */ | 37 | #define EDOTDOT 66 /* RFS specific error */ |
| 38 | #define EBADMSG 67 /* Not a data message */ | 38 | #define EBADMSG 67 /* Not a data message */ |
| 39 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 39 | #define EUSERS 68 /* Too many users */ | 40 | #define EUSERS 68 /* Too many users */ |
| 40 | #define EDQUOT 69 /* Quota exceeded */ | 41 | #define EDQUOT 69 /* Quota exceeded */ |
| 41 | #define ESTALE 70 /* Stale file handle */ | 42 | #define ESTALE 70 /* Stale file handle */ |
| @@ -62,6 +63,7 @@ · 20 unmodified lines | |||
| 62 | #define ERESTART 175 /* Interrupted system call should be restarted */ | 63 | #define ERESTART 175 /* Interrupted system call should be restarted */ |
| 63 | #define ESTRPIPE 176 /* Streams pipe error */ | 64 | #define ESTRPIPE 176 /* Streams pipe error */ |
| 64 | #define EUCLEAN 177 /* Structure needs cleaning */ | 65 | #define EUCLEAN 177 /* Structure needs cleaning */ |
| 66 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 65 | #define ENOTNAM 178 /* Not a XENIX named type file */ | 67 | #define ENOTNAM 178 /* Not a XENIX named type file */ |
| 66 | #define ENAVAIL 179 /* No XENIX semaphores available */ | 68 | #define ENAVAIL 179 /* No XENIX semaphores available */ |
| 67 | #define EISNAM 180 /* Is a named type file */ | 69 | #define EISNAM 180 /* Is a named type file */ |
| @@ -48,6 +48,7 @@ · 47 unmodified lines | |||
| 48 | #define ENOSR 74 /* Out of streams resources */ | 48 | #define ENOSR 74 /* Out of streams resources */ |
| 49 | #define ENOMSG 75 /* No message of desired type */ | 49 | #define ENOMSG 75 /* No message of desired type */ |
| 50 | #define EBADMSG 76 /* Not a data message */ | 50 | #define EBADMSG 76 /* Not a data message */ |
| 51 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 51 | #define EIDRM 77 /* Identifier removed */ | 52 | #define EIDRM 77 /* Identifier removed */ |
| 52 | #define EDEADLK 78 /* Resource deadlock would occur */ | 53 | #define EDEADLK 78 /* Resource deadlock would occur */ |
| 53 | #define ENOLCK 79 /* No record locks available */ | 54 | #define ENOLCK 79 /* No record locks available */ |
| @@ -91,6 +92,7 @@ · 37 unmodified lines | |||
| 91 | #define ENOTUNIQ 115 /* Name not unique on network */ | 92 | #define ENOTUNIQ 115 /* Name not unique on network */ |
| 92 | #define ERESTART 116 /* Interrupted syscall should be restarted */ | 93 | #define ERESTART 116 /* Interrupted syscall should be restarted */ |
| 93 | #define EUCLEAN 117 /* Structure needs cleaning */ | 94 | #define EUCLEAN 117 /* Structure needs cleaning */ |
| 95 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 94 | #define ENOTNAM 118 /* Not a XENIX named type file */ | 96 | #define ENOTNAM 118 /* Not a XENIX named type file */ |
| 95 | #define ENAVAIL 119 /* No XENIX semaphores available */ | 97 | #define ENAVAIL 119 /* No XENIX semaphores available */ |
| 96 | #define EISNAM 120 /* Is a named type file */ | 98 | #define EISNAM 120 /* Is a named type file */ |
| @@ -16,7 +16,7 @@ obj-y := open.o read_write.o file_table.o super.o \ · 15 unmodified lines | |||
| 16 | stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \ | 16 | stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \ |
| 17 | fs_dirent.o fs_context.o fs_parser.o fsopen.o init.o \ | 17 | fs_dirent.o fs_context.o fs_parser.o fsopen.o init.o \ |
| 18 | kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \ | 18 | kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \ |
| 19 | file_attr.o | 19 | file_attr.o fserror.o |
| 20 | 20 | ||
| 21 | obj-$(CONFIG_BUFFER_HEAD) += buffer.o mpage.o | 21 | obj-$(CONFIG_BUFFER_HEAD) += buffer.o mpage.o |
| 22 | obj-$(CONFIG_PROC_FS) += proc_namespace.o | 22 | obj-$(CONFIG_PROC_FS) += proc_namespace.o |
| @@ -541,6 +541,4 @@ long erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); · 540 unmodified lines | |||
| 541 | long erofs_compat_ioctl(struct file *filp, unsigned int cmd, | 541 | long erofs_compat_ioctl(struct file *filp, unsigned int cmd, |
| 542 | unsigned long arg); | 542 | unsigned long arg); |
| 543 | 543 | ||
| 544 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 545 | |||
| 546 | #endif /* __EROFS_INTERNAL_H */ | 544 | #endif /* __EROFS_INTERNAL_H */ |
| @@ -357,7 +357,6 @@ struct ext2_inode { · 356 unmodified lines | |||
| 357 | */ | 357 | */ |
| 358 | #define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */ | 358 | #define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */ |
| 359 | #define EXT2_ERROR_FS 0x0002 /* Errors detected */ | 359 | #define EXT2_ERROR_FS 0x0002 /* Errors detected */ |
| 360 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 361 | 360 | ||
| 362 | /* | 361 | /* |
| 363 | * Mount flags | 362 | * Mount flags |
| @@ -3938,7 +3938,4 @@ extern int ext4_block_write_begin(handle_t *handle, struct folio *folio, · 3937 unmodified lines | |||
| 3938 | get_block_t *get_block); | 3938 | get_block_t *get_block); |
| 3939 | #endif /* __KERNEL__ */ | 3939 | #endif /* __KERNEL__ */ |
| 3940 | 3940 | ||
| 3941 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 3942 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 3943 | |||
| 3944 | #endif /* _EXT4_H */ | 3941 | #endif /* _EXT4_H */ |
| @@ -26,6 +26,7 @@ · 25 unmodified lines | |||
| 26 | #include <linux/fsmap.h> | 26 | #include <linux/fsmap.h> |
| 27 | #include "fsmap.h" | 27 | #include "fsmap.h" |
| 28 | #include <trace/events/ext4.h> | 28 | #include <trace/events/ext4.h> |
| 29 | #include <linux/fserror.h> | ||
| 29 | 30 | ||
| 30 | typedef void ext4_update_sb_callback(struct ext4_sb_info *sbi, | 31 | typedef void ext4_update_sb_callback(struct ext4_sb_info *sbi, |
| 31 | struct ext4_super_block *es, | 32 | struct ext4_super_block *es, |
| @@ -844,6 +845,7 @@ int ext4_force_shutdown(struct super_block *sb, u32 flags) · 812 unmodified lines | |||
| 844 | return -EINVAL; | 845 | return -EINVAL; |
| 845 | } | 846 | } |
| 846 | clear_opt(sb, DISCARD); | 847 | clear_opt(sb, DISCARD); |
| 848 | fserror_report_shutdown(sb, GFP_KERNEL); | ||
| 847 | return 0; | 849 | return 0; |
| 848 | } | 850 | } |
| 849 | 851 | ||
| @@ -48,6 +48,7 @@ · 47 unmodified lines | |||
| 48 | #include <linux/fsnotify.h> | 48 | #include <linux/fsnotify.h> |
| 49 | #include <linux/fs_context.h> | 49 | #include <linux/fs_context.h> |
| 50 | #include <linux/fs_parser.h> | 50 | #include <linux/fs_parser.h> |
| 51 | #include <linux/fserror.h> | ||
| 51 | 52 | ||
| 52 | #include "ext4.h" | 53 | #include "ext4.h" |
| 53 | #include "ext4_extents.h" /* Needed for trace points definition */ | 54 | #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 | |||
| 824 | sb->s_id, function, line, current->comm, &vaf); | 825 | sb->s_id, function, line, current->comm, &vaf); |
| 825 | va_end(args); | 826 | va_end(args); |
| 826 | } | 827 | } |
| 827 | fsnotify_sb_error(sb, NULL, error ? error : EFSCORRUPTED); | 828 | fserror_report_metadata(sb, error ? -abs(error) : -EFSCORRUPTED, |
| 829 | GFP_ATOMIC); | ||
| 828 | 830 | ||
| 829 | ext4_handle_error(sb, force_ro, error, 0, block, function, line); | 831 | ext4_handle_error(sb, force_ro, error, 0, block, function, line); |
| 830 | } | 832 | } |
| @@ -856,7 +858,9 @@ void __ext4_error_inode(struct inode *inode, const char *function, · 25 unmodified lines | |||
| 856 | current->comm, &vaf); | 858 | current->comm, &vaf); |
| 857 | va_end(args); | 859 | va_end(args); |
| 858 | } | 860 | } |
| 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); | ||
| 860 | 864 | ||
| 861 | ext4_handle_error(inode->i_sb, false, error, inode->i_ino, block, | 865 | ext4_handle_error(inode->i_sb, false, error, inode->i_ino, block, |
| 862 | function, line); | 866 | function, line); |
| @@ -896,7 +900,7 @@ void __ext4_error_file(struct file *file, const char *function, · 33 unmodified lines | |||
| 896 | current->comm, path, &vaf); | 900 | current->comm, path, &vaf); |
| 897 | va_end(args); | 901 | va_end(args); |
| 898 | } | 902 | } |
| 899 | fsnotify_sb_error(inode->i_sb, inode, EFSCORRUPTED); | 903 | fserror_report_file_metadata(inode, -EFSCORRUPTED, GFP_ATOMIC); |
| 900 | 904 | ||
| 901 | ext4_handle_error(inode->i_sb, false, EFSCORRUPTED, inode->i_ino, block, | 905 | ext4_handle_error(inode->i_sb, false, EFSCORRUPTED, inode->i_ino, block, |
| 902 | function, line); | 906 | function, line); |
| @@ -965,7 +969,8 @@ void __ext4_std_error(struct super_block *sb, const char *function, · 62 unmodified lines | |||
| 965 | printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n", | 969 | printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n", |
| 966 | sb->s_id, function, line, errstr); | 970 | sb->s_id, function, line, errstr); |
| 967 | } | 971 | } |
| 968 | fsnotify_sb_error(sb, NULL, errno ? errno : EFSCORRUPTED); | 972 | fserror_report_metadata(sb, errno ? -abs(errno) : -EFSCORRUPTED, |
| 973 | GFP_ATOMIC); | ||
| 969 | 974 | ||
| 970 | ext4_handle_error(sb, false, -errno, 0, 0, function, line); | 975 | ext4_handle_error(sb, false, -errno, 0, 0, function, line); |
| 971 | } | 976 | } |
| @@ -5004,7 +5004,4 @@ static inline void f2fs_invalidate_internal_cache(struct f2fs_sb_info *sbi, · 5003 unmodified lines | |||
| 5004 | f2fs_invalidate_compress_pages_range(sbi, blkaddr, len); | 5004 | f2fs_invalidate_compress_pages_range(sbi, blkaddr, len); |
| 5005 | } | 5005 | } |
| 5006 | 5006 | ||
| 5007 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 5008 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 5009 | |||
| 5010 | #endif /* _LINUX_F2FS_H */ | 5007 | #endif /* _LINUX_F2FS_H */ |
| @@ -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); | ||
| @@ -8,6 +8,7 @@ · 7 unmodified lines | |||
| 8 | #include <linux/writeback.h> | 8 | #include <linux/writeback.h> |
| 9 | #include <linux/swap.h> | 9 | #include <linux/swap.h> |
| 10 | #include <linux/migrate.h> | 10 | #include <linux/migrate.h> |
| 11 | #include <linux/fserror.h> | ||
| 11 | #include "internal.h" | 12 | #include "internal.h" |
| 12 | #include "trace.h" | 13 | #include "trace.h" |
| 13 | 14 | ||
| @@ -371,8 +372,11 @@ static int iomap_read_inline_data(const struct iomap_iter *iter, · 357 unmodified lines | |||
| 371 | if (folio_test_uptodate(folio)) | 372 | if (folio_test_uptodate(folio)) |
| 372 | return 0; | 373 | return 0; |
| 373 | 374 | ||
| 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); | ||
| 375 | return -EIO; | 378 | return -EIO; |
| 379 | } | ||
| 376 | if (offset > 0) | 380 | if (offset > 0) |
| 377 | ifs_alloc(iter->inode, folio, iter->flags); | 381 | ifs_alloc(iter->inode, folio, iter->flags); |
| 378 | 382 | ||
| @@ -399,6 +403,11 @@ void iomap_finish_folio_read(struct folio *folio, size_t off, size_t len, · 20 unmodified lines | |||
| 399 | spin_unlock_irqrestore(&ifs->state_lock, flags); | 403 | spin_unlock_irqrestore(&ifs->state_lock, flags); |
| 400 | } | 404 | } |
| 401 | 405 | ||
| 406 | if (error) | ||
| 407 | fserror_report_io(folio->mapping->host, FSERR_BUFFERED_READ, | ||
| 408 | folio_pos(folio) + off, len, error, | ||
| 409 | GFP_ATOMIC); | ||
| 410 | |||
| 402 | if (finished) | 411 | if (finished) |
| 403 | folio_end_read(folio, uptodate); | 412 | folio_end_read(folio, uptodate); |
| 404 | } | 413 | } |
| @@ -540,6 +549,10 @@ static int iomap_read_folio_iter(struct iomap_iter *iter, · 135 unmodified lines | |||
| 540 | if (!*bytes_submitted) | 549 | if (!*bytes_submitted) |
| 541 | iomap_read_init(folio); | 550 | iomap_read_init(folio); |
| 542 | ret = ctx->ops->read_folio_range(iter, ctx, plen); | 551 | 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); | ||
| 543 | if (ret) | 556 | if (ret) |
| 544 | return ret; | 557 | return ret; |
| 545 | *bytes_submitted += plen; | 558 | *bytes_submitted += plen; |
| @@ -815,6 +828,10 @@ static int __iomap_write_begin(const struct iomap_iter *iter, · 269 unmodified lines | |||
| 815 | else | 828 | else |
| 816 | status = iomap_bio_read_folio_range_sync(iter, | 829 | status = iomap_bio_read_folio_range_sync(iter, |
| 817 | folio, block_start, plen); | 830 | folio, block_start, plen); |
| 831 | if (status < 0) | ||
| 832 | fserror_report_io(iter->inode, | ||
| 833 | FSERR_BUFFERED_READ, pos, | ||
| 834 | len, status, GFP_NOFS); | ||
| 818 | if (status) | 835 | if (status) |
| 819 | return status; | 836 | return status; |
| 820 | } | 837 | } |
| @@ -1805,6 +1822,7 @@ int iomap_writeback_folio(struct iomap_writepage_ctx *wpc, struct folio *folio) · 984 unmodified lines | |||
| 1805 | u64 pos = folio_pos(folio); | 1822 | u64 pos = folio_pos(folio); |
| 1806 | u64 end_pos = pos + folio_size(folio); | 1823 | u64 end_pos = pos + folio_size(folio); |
| 1807 | u64 end_aligned = 0; | 1824 | u64 end_aligned = 0; |
| 1825 | loff_t orig_pos = pos; | ||
| 1808 | size_t bytes_submitted = 0; | 1826 | size_t bytes_submitted = 0; |
| 1809 | int error = 0; | 1827 | int error = 0; |
| 1810 | u32 rlen; | 1828 | u32 rlen; |
| @@ -1848,6 +1866,9 @@ int iomap_writeback_folio(struct iomap_writepage_ctx *wpc, struct folio *folio) · 37 unmodified lines | |||
| 1848 | 1866 | ||
| 1849 | if (bytes_submitted) | 1867 | if (bytes_submitted) |
| 1850 | wpc->nr_folios++; | 1868 | wpc->nr_folios++; |
| 1869 | if (error && pos > orig_pos) | ||
| 1870 | fserror_report_io(inode, FSERR_BUFFERED_WRITE, orig_pos, 0, | ||
| 1871 | error, GFP_NOFS); | ||
| 1851 | 1872 | ||
| 1852 | /* | 1873 | /* |
| 1853 | * We can have dirty bits set past end of file in page_mkwrite path | 1874 | * We can have dirty bits set past end of file in page_mkwrite path |
| @@ -7,6 +7,7 @@ · 6 unmodified lines | |||
| 7 | #include <linux/pagemap.h> | 7 | #include <linux/pagemap.h> |
| 8 | #include <linux/iomap.h> | 8 | #include <linux/iomap.h> |
| 9 | #include <linux/task_io_accounting_ops.h> | 9 | #include <linux/task_io_accounting_ops.h> |
| 10 | #include <linux/fserror.h> | ||
| 10 | #include "internal.h" | 11 | #include "internal.h" |
| 11 | #include "trace.h" | 12 | #include "trace.h" |
| 12 | 13 | ||
| @@ -78,6 +79,13 @@ static void iomap_dio_submit_bio(const struct iomap_iter *iter, · 65 unmodified lines | |||
| 78 | } | 79 | } |
| 79 | } | 80 | } |
| 80 | 81 | ||
| 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 | |||
| 81 | ssize_t iomap_dio_complete(struct iomap_dio *dio) | 89 | ssize_t iomap_dio_complete(struct iomap_dio *dio) |
| 82 | { | 90 | { |
| 83 | const struct iomap_dio_ops *dops = dio->dops; | 91 | const struct iomap_dio_ops *dops = dio->dops; |
| @@ -87,6 +95,10 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) · 3 unmodified lines | |||
| 87 | 95 | ||
| 88 | if (dops && dops->end_io) | 96 | if (dops && dops->end_io) |
| 89 | ret = dops->end_io(iocb, dio->size, ret, dio->flags); | 97 | 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); | ||
| 90 | 102 | ||
| 91 | if (likely(!ret)) { | 103 | if (likely(!ret)) { |
| 92 | ret = dio->size; | 104 | ret = dio->size; |
| @@ -6,6 +6,7 @@ · 5 unmodified lines | |||
| 6 | #include <linux/list_sort.h> | 6 | #include <linux/list_sort.h> |
| 7 | #include <linux/pagemap.h> | 7 | #include <linux/pagemap.h> |
| 8 | #include <linux/writeback.h> | 8 | #include <linux/writeback.h> |
| 9 | #include <linux/fserror.h> | ||
| 9 | #include "internal.h" | 10 | #include "internal.h" |
| 10 | #include "trace.h" | 11 | #include "trace.h" |
| 11 | 12 | ||
| @@ -55,6 +56,11 @@ static u32 iomap_finish_ioend_buffered(struct iomap_ioend *ioend) · 43 unmodified lines | |||
| 55 | 56 | ||
| 56 | /* walk all folios in bio, ending page IO on them */ | 57 | /* walk all folios in bio, ending page IO on them */ |
| 57 | bio_for_each_folio_all(fi, bio) { | 58 | 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); | ||
| 58 | iomap_finish_folio_write(inode, fi.folio, fi.length); | 64 | iomap_finish_folio_write(inode, fi.folio, fi.length); |
| 59 | folio_count++; | 65 | folio_count++; |
| 60 | } | 66 | } |
| @@ -175,6 +175,4 @@ static inline int minix_test_bit(int nr, const void *vaddr) · 174 unmodified lines | |||
| 175 | __minix_error_inode((inode), __func__, __LINE__, \ | 175 | __minix_error_inode((inode), __func__, __LINE__, \ |
| 176 | (fmt), ##__VA_ARGS__) | 176 | (fmt), ##__VA_ARGS__) |
| 177 | 177 | ||
| 178 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 179 | |||
| 180 | #endif /* FS_MINIX_H */ | 178 | #endif /* FS_MINIX_H */ |
| @@ -36,6 +36,7 @@ · 35 unmodified lines | |||
| 36 | #include <linux/lockdep.h> | 36 | #include <linux/lockdep.h> |
| 37 | #include <linux/user_namespace.h> | 37 | #include <linux/user_namespace.h> |
| 38 | #include <linux/fs_context.h> | 38 | #include <linux/fs_context.h> |
| 39 | #include <linux/fserror.h> | ||
| 39 | #include <uapi/linux/mount.h> | 40 | #include <uapi/linux/mount.h> |
| 40 | #include "internal.h" | 41 | #include "internal.h" |
| 41 | 42 | ||
| @@ -363,6 +364,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, · 321 unmodified lines | |||
| 363 | spin_lock_init(&s->s_inode_list_lock); | 364 | spin_lock_init(&s->s_inode_list_lock); |
| 364 | INIT_LIST_HEAD(&s->s_inodes_wb); | 365 | INIT_LIST_HEAD(&s->s_inodes_wb); |
| 365 | spin_lock_init(&s->s_inode_wblist_lock); | 366 | spin_lock_init(&s->s_inode_wblist_lock); |
| 367 | fserror_mount(s); | ||
| 366 | 368 | ||
| 367 | s->s_count = 1; | 369 | s->s_count = 1; |
| 368 | atomic_set(&s->s_active, 1); | 370 | atomic_set(&s->s_active, 1); |
| @@ -622,6 +624,7 @@ void generic_shutdown_super(struct super_block *sb) · 253 unmodified lines | |||
| 622 | sync_filesystem(sb); | 624 | sync_filesystem(sb); |
| 623 | sb->s_flags &= ~SB_ACTIVE; | 625 | sb->s_flags &= ~SB_ACTIVE; |
| 624 | 626 | ||
| 627 | fserror_unmount(sb); | ||
| 625 | cgroup_writeback_umount(sb); | 628 | cgroup_writeback_umount(sb); |
| 626 | 629 | ||
| 627 | /* Evict all inodes with zero refcount. */ | 630 | /* Evict all inodes with zero refcount. */ |
| @@ -55,8 +55,6 @@ · 54 unmodified lines | |||
| 55 | #define MF_DUPLICATE_MD 0x01 | 55 | #define MF_DUPLICATE_MD 0x01 |
| 56 | #define MF_MIRROR_FE_LOADED 0x02 | 56 | #define MF_MIRROR_FE_LOADED 0x02 |
| 57 | 57 | ||
| 58 | #define EFSCORRUPTED EUCLEAN | ||
| 59 | |||
| 60 | struct udf_meta_data { | 58 | struct udf_meta_data { |
| 61 | __u32 s_meta_file_loc; | 59 | __u32 s_meta_file_loc; |
| 62 | __u32 s_mirror_file_loc; | 60 | __u32 s_mirror_file_loc; |
| @@ -26,6 +26,8 @@ · 25 unmodified lines | |||
| 26 | #include "xfs_rtrefcount_btree.h" | 26 | #include "xfs_rtrefcount_btree.h" |
| 27 | #include "xfs_metafile.h" | 27 | #include "xfs_metafile.h" |
| 28 | 28 | ||
| 29 | #include <linux/fserror.h> | ||
| 30 | |||
| 29 | /* | 31 | /* |
| 30 | * Write new AG headers to disk. Non-transactional, but need to be | 32 | * Write new AG headers to disk. Non-transactional, but need to be |
| 31 | * written and completed prior to the growfs transaction being logged. | 33 | * written and completed prior to the growfs transaction being logged. |
| @@ -540,6 +542,8 @@ xfs_do_force_shutdown( · 508 unmodified lines | |||
| 540 | "Please unmount the filesystem and rectify the problem(s)"); | 542 | "Please unmount the filesystem and rectify the problem(s)"); |
| 541 | if (xfs_error_level >= XFS_ERRLEVEL_HIGH) | 543 | if (xfs_error_level >= XFS_ERRLEVEL_HIGH) |
| 542 | xfs_stack_trace(); | 544 | xfs_stack_trace(); |
| 545 | |||
| 546 | fserror_report_shutdown(mp->m_super, GFP_KERNEL); | ||
| 543 | } | 547 | } |
| 544 | 548 | ||
| 545 | /* | 549 | /* |
| @@ -20,6 +20,8 @@ · 19 unmodified lines | |||
| 20 | #include "xfs_quota_defs.h" | 20 | #include "xfs_quota_defs.h" |
| 21 | #include "xfs_rtgroup.h" | 21 | #include "xfs_rtgroup.h" |
| 22 | 22 | ||
| 23 | #include <linux/fserror.h> | ||
| 24 | |||
| 23 | static void | 25 | static void |
| 24 | xfs_health_unmount_group( | 26 | xfs_health_unmount_group( |
| 25 | struct xfs_group *xg, | 27 | struct xfs_group *xg, |
| @@ -111,6 +113,8 @@ xfs_fs_mark_sick( · 85 unmodified lines | |||
| 111 | spin_lock(&mp->m_sb_lock); | 113 | spin_lock(&mp->m_sb_lock); |
| 112 | mp->m_fs_sick |= mask; | 114 | mp->m_fs_sick |= mask; |
| 113 | spin_unlock(&mp->m_sb_lock); | 115 | spin_unlock(&mp->m_sb_lock); |
| 116 | |||
| 117 | fserror_report_metadata(mp->m_super, -EFSCORRUPTED, GFP_NOFS); | ||
| 114 | } | 118 | } |
| 115 | 119 | ||
| 116 | /* Mark per-fs metadata as having been checked and found unhealthy by fsck. */ | 120 | /* Mark per-fs metadata as having been checked and found unhealthy by fsck. */ |
| @@ -126,6 +130,8 @@ xfs_fs_mark_corrupt( · 9 unmodified lines | |||
| 126 | mp->m_fs_sick |= mask; | 130 | mp->m_fs_sick |= mask; |
| 127 | mp->m_fs_checked |= mask; | 131 | mp->m_fs_checked |= mask; |
| 128 | spin_unlock(&mp->m_sb_lock); | 132 | spin_unlock(&mp->m_sb_lock); |
| 133 | |||
| 134 | fserror_report_metadata(mp->m_super, -EFSCORRUPTED, GFP_NOFS); | ||
| 129 | } | 135 | } |
| 130 | 136 | ||
| 131 | /* Mark a per-fs metadata healed. */ | 137 | /* Mark a per-fs metadata healed. */ |
| @@ -198,6 +204,8 @@ xfs_group_mark_sick( · 66 unmodified lines | |||
| 198 | spin_lock(&xg->xg_state_lock); | 204 | spin_lock(&xg->xg_state_lock); |
| 199 | xg->xg_sick |= mask; | 205 | xg->xg_sick |= mask; |
| 200 | spin_unlock(&xg->xg_state_lock); | 206 | spin_unlock(&xg->xg_state_lock); |
| 207 | |||
| 208 | fserror_report_metadata(xg->xg_mount->m_super, -EFSCORRUPTED, GFP_NOFS); | ||
| 201 | } | 209 | } |
| 202 | 210 | ||
| 203 | /* | 211 | /* |
| @@ -215,6 +223,8 @@ xfs_group_mark_corrupt( · 11 unmodified lines | |||
| 215 | xg->xg_sick |= mask; | 223 | xg->xg_sick |= mask; |
| 216 | xg->xg_checked |= mask; | 224 | xg->xg_checked |= mask; |
| 217 | spin_unlock(&xg->xg_state_lock); | 225 | spin_unlock(&xg->xg_state_lock); |
| 226 | |||
| 227 | fserror_report_metadata(xg->xg_mount->m_super, -EFSCORRUPTED, GFP_NOFS); | ||
| 218 | } | 228 | } |
| 219 | 229 | ||
| 220 | /* | 230 | /* |
| @@ -287,6 +297,8 @@ xfs_inode_mark_sick( · 66 unmodified lines | |||
| 287 | spin_lock(&VFS_I(ip)->i_lock); | 297 | spin_lock(&VFS_I(ip)->i_lock); |
| 288 | inode_state_clear(VFS_I(ip), I_DONTCACHE); | 298 | inode_state_clear(VFS_I(ip), I_DONTCACHE); |
| 289 | spin_unlock(&VFS_I(ip)->i_lock); | 299 | spin_unlock(&VFS_I(ip)->i_lock); |
| 300 | |||
| 301 | fserror_report_file_metadata(VFS_I(ip), -EFSCORRUPTED, GFP_NOFS); | ||
| 290 | } | 302 | } |
| 291 | 303 | ||
| 292 | /* Mark inode metadata as having been checked and found unhealthy by fsck. */ | 304 | /* Mark inode metadata as having been checked and found unhealthy by fsck. */ |
| @@ -311,6 +323,8 @@ xfs_inode_mark_corrupt( · 18 unmodified lines | |||
| 311 | spin_lock(&VFS_I(ip)->i_lock); | 323 | spin_lock(&VFS_I(ip)->i_lock); |
| 312 | inode_state_clear(VFS_I(ip), I_DONTCACHE); | 324 | inode_state_clear(VFS_I(ip), I_DONTCACHE); |
| 313 | spin_unlock(&VFS_I(ip)->i_lock); | 325 | spin_unlock(&VFS_I(ip)->i_lock); |
| 326 | |||
| 327 | fserror_report_file_metadata(VFS_I(ip), -EFSCORRUPTED, GFP_NOFS); | ||
| 314 | } | 328 | } |
| 315 | 329 | ||
| 316 | /* Mark parts of an inode healed. */ | 330 | /* Mark parts of an inode healed. */ |
| @@ -121,8 +121,6 @@ typedef __u32 xfs_nlink_t; · 120 unmodified lines | |||
| 121 | 121 | ||
| 122 | #define ENOATTR ENODATA /* Attribute not found */ | 122 | #define ENOATTR ENODATA /* Attribute not found */ |
| 123 | #define EWRONGFS EINVAL /* Mount with wrong filesystem type */ | 123 | #define EWRONGFS EINVAL /* Mount with wrong filesystem type */ |
| 124 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 125 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 126 | 124 | ||
| 127 | #define __return_address __builtin_return_address(0) | 125 | #define __return_address __builtin_return_address(0) |
| 128 | 126 | ||
| @@ -26,6 +26,7 @@ · 25 unmodified lines | |||
| 26 | #include <linux/mm.h> | 26 | #include <linux/mm.h> |
| 27 | #include <linux/dax.h> | 27 | #include <linux/dax.h> |
| 28 | #include <linux/fs.h> | 28 | #include <linux/fs.h> |
| 29 | #include <linux/fserror.h> | ||
| 29 | 30 | ||
| 30 | struct xfs_failure_info { | 31 | struct xfs_failure_info { |
| 31 | xfs_agblock_t startblock; | 32 | xfs_agblock_t startblock; |
| @@ -116,6 +117,9 @@ xfs_dax_failure_fn( · 84 unmodified lines | |||
| 116 | invalidate_inode_pages2_range(mapping, pgoff, | 117 | invalidate_inode_pages2_range(mapping, pgoff, |
| 117 | pgoff + pgcnt - 1); | 118 | pgoff + pgcnt - 1); |
| 118 | 119 | ||
| 120 | fserror_report_data_lost(VFS_I(ip), (u64)pgoff << PAGE_SHIFT, | ||
| 121 | (u64)pgcnt << PAGE_SHIFT, GFP_NOFS); | ||
| 122 | |||
| 119 | xfs_irele(ip); | 123 | xfs_irele(ip); |
| 120 | return error; | 124 | return error; |
| 121 | } | 125 | } |
| @@ -35,6 +35,7 @@ struct user_namespace; · 34 unmodified lines | |||
| 35 | struct workqueue_struct; | 35 | struct workqueue_struct; |
| 36 | struct writeback_control; | 36 | struct writeback_control; |
| 37 | struct xattr_handler; | 37 | struct xattr_handler; |
| 38 | struct fserror_event; | ||
| 38 | 39 | ||
| 39 | extern struct super_block *blockdev_superblock; | 40 | extern struct super_block *blockdev_superblock; |
| 40 | 41 | ||
| @@ -124,6 +125,9 @@ struct super_operations { · 83 unmodified lines | |||
| 124 | */ | 125 | */ |
| 125 | int (*remove_bdev)(struct super_block *sb, struct block_device *bdev); | 126 | int (*remove_bdev)(struct super_block *sb, struct block_device *bdev); |
| 126 | void (*shutdown)(struct super_block *sb); | 127 | void (*shutdown)(struct super_block *sb); |
| 128 | |||
| 129 | /* Report a filesystem error */ | ||
| 130 | void (*report_error)(const struct fserror_event *event); | ||
| 127 | }; | 131 | }; |
| 128 | 132 | ||
| 129 | struct super_block { | 133 | struct super_block { |
| @@ -268,6 +272,9 @@ struct super_block { · 138 unmodified lines | |||
| 268 | spinlock_t s_inode_wblist_lock; | 272 | spinlock_t s_inode_wblist_lock; |
| 269 | struct list_head s_inodes_wb; /* writeback inodes */ | 273 | struct list_head s_inodes_wb; /* writeback inodes */ |
| 270 | long s_min_writeback_pages; | 274 | long s_min_writeback_pages; |
| 275 | |||
| 276 | /* number of fserrors that are being sent to fsnotify/filesystems */ | ||
| 277 | refcount_t s_pending_errors; | ||
| 271 | } __randomize_layout; | 278 | } __randomize_layout; |
| 272 | 279 | ||
| 273 | /* | 280 | /* |
| @@ -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__ */ | ||
| @@ -1815,7 +1815,4 @@ static inline int jbd2_handle_buffer_credits(handle_t *handle) · 1814 unmodified lines | |||
| 1815 | 1815 | ||
| 1816 | #endif /* __KERNEL__ */ | 1816 | #endif /* __KERNEL__ */ |
| 1817 | 1817 | ||
| 1818 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 1819 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 1820 | |||
| 1821 | #endif /* _LINUX_JBD2_H */ | 1818 | #endif /* _LINUX_JBD2_H */ |
| @@ -55,6 +55,7 @@ · 54 unmodified lines | |||
| 55 | #define EMULTIHOP 72 /* Multihop attempted */ | 55 | #define EMULTIHOP 72 /* Multihop attempted */ |
| 56 | #define EDOTDOT 73 /* RFS specific error */ | 56 | #define EDOTDOT 73 /* RFS specific error */ |
| 57 | #define EBADMSG 74 /* Not a data message */ | 57 | #define EBADMSG 74 /* Not a data message */ |
| 58 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 58 | #define EOVERFLOW 75 /* Value too large for defined data type */ | 59 | #define EOVERFLOW 75 /* Value too large for defined data type */ |
| 59 | #define ENOTUNIQ 76 /* Name not unique on network */ | 60 | #define ENOTUNIQ 76 /* Name not unique on network */ |
| 60 | #define EBADFD 77 /* File descriptor in bad state */ | 61 | #define EBADFD 77 /* File descriptor in bad state */ |
| @@ -98,6 +99,7 @@ · 37 unmodified lines | |||
| 98 | #define EINPROGRESS 115 /* Operation now in progress */ | 99 | #define EINPROGRESS 115 /* Operation now in progress */ |
| 99 | #define ESTALE 116 /* Stale file handle */ | 100 | #define ESTALE 116 /* Stale file handle */ |
| 100 | #define EUCLEAN 117 /* Structure needs cleaning */ | 101 | #define EUCLEAN 117 /* Structure needs cleaning */ |
| 102 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 101 | #define ENOTNAM 118 /* Not a XENIX named type file */ | 103 | #define ENOTNAM 118 /* Not a XENIX named type file */ |
| 102 | #define ENAVAIL 119 /* No XENIX semaphores available */ | 104 | #define ENAVAIL 119 /* No XENIX semaphores available */ |
| 103 | #define EISNAM 120 /* Is a named type file */ | 105 | #define EISNAM 120 /* Is a named type file */ |
| @@ -55,6 +55,7 @@ · 54 unmodified lines | |||
| 55 | #define ENOSR 82 /* Out of streams resources */ | 55 | #define ENOSR 82 /* Out of streams resources */ |
| 56 | #define ETIME 83 /* Timer expired */ | 56 | #define ETIME 83 /* Timer expired */ |
| 57 | #define EBADMSG 84 /* Not a data message */ | 57 | #define EBADMSG 84 /* Not a data message */ |
| 58 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 58 | #define EPROTO 85 /* Protocol error */ | 59 | #define EPROTO 85 /* Protocol error */ |
| 59 | #define ENODATA 86 /* No data available */ | 60 | #define ENODATA 86 /* No data available */ |
| 60 | #define ENOSTR 87 /* Device not a stream */ | 61 | #define ENOSTR 87 /* Device not a stream */ |
| @@ -96,6 +97,7 @@ · 35 unmodified lines | |||
| 96 | #define EREMCHG 115 /* Remote address changed */ | 97 | #define EREMCHG 115 /* Remote address changed */ |
| 97 | 98 | ||
| 98 | #define EUCLEAN 117 /* Structure needs cleaning */ | 99 | #define EUCLEAN 117 /* Structure needs cleaning */ |
| 100 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 99 | #define ENOTNAM 118 /* Not a XENIX named type file */ | 101 | #define ENOTNAM 118 /* Not a XENIX named type file */ |
| 100 | #define ENAVAIL 119 /* No XENIX semaphores available */ | 102 | #define ENAVAIL 119 /* No XENIX semaphores available */ |
| 101 | #define EISNAM 120 /* Is a named type file */ | 103 | #define EISNAM 120 /* Is a named type file */ |
| @@ -50,6 +50,7 @@ · 49 unmodified lines | |||
| 50 | #define EDOTDOT 73 /* RFS specific error */ | 50 | #define EDOTDOT 73 /* RFS specific error */ |
| 51 | #define EMULTIHOP 74 /* Multihop attempted */ | 51 | #define EMULTIHOP 74 /* Multihop attempted */ |
| 52 | #define EBADMSG 77 /* Not a data message */ | 52 | #define EBADMSG 77 /* Not a data message */ |
| 53 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 53 | #define ENAMETOOLONG 78 /* File name too long */ | 54 | #define ENAMETOOLONG 78 /* File name too long */ |
| 54 | #define EOVERFLOW 79 /* Value too large for defined data type */ | 55 | #define EOVERFLOW 79 /* Value too large for defined data type */ |
| 55 | #define ENOTUNIQ 80 /* Name not unique on network */ | 56 | #define ENOTUNIQ 80 /* Name not unique on network */ |
| @@ -88,6 +89,7 @@ · 32 unmodified lines | |||
| 88 | #define EISCONN 133 /* Transport endpoint is already connected */ | 89 | #define EISCONN 133 /* Transport endpoint is already connected */ |
| 89 | #define ENOTCONN 134 /* Transport endpoint is not connected */ | 90 | #define ENOTCONN 134 /* Transport endpoint is not connected */ |
| 90 | #define EUCLEAN 135 /* Structure needs cleaning */ | 91 | #define EUCLEAN 135 /* Structure needs cleaning */ |
| 92 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 91 | #define ENOTNAM 137 /* Not a XENIX named type file */ | 93 | #define ENOTNAM 137 /* Not a XENIX named type file */ |
| 92 | #define ENAVAIL 138 /* No XENIX semaphores available */ | 94 | #define ENAVAIL 138 /* No XENIX semaphores available */ |
| 93 | #define EISNAM 139 /* Is a named type file */ | 95 | #define EISNAM 139 /* Is a named type file */ |
| @@ -36,6 +36,7 @@ · 35 unmodified lines | |||
| 36 | 36 | ||
| 37 | #define EDOTDOT 66 /* RFS specific error */ | 37 | #define EDOTDOT 66 /* RFS specific error */ |
| 38 | #define EBADMSG 67 /* Not a data message */ | 38 | #define EBADMSG 67 /* Not a data message */ |
| 39 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 39 | #define EUSERS 68 /* Too many users */ | 40 | #define EUSERS 68 /* Too many users */ |
| 40 | #define EDQUOT 69 /* Quota exceeded */ | 41 | #define EDQUOT 69 /* Quota exceeded */ |
| 41 | #define ESTALE 70 /* Stale file handle */ | 42 | #define ESTALE 70 /* Stale file handle */ |
| @@ -62,6 +63,7 @@ · 20 unmodified lines | |||
| 62 | #define ERESTART 175 /* Interrupted system call should be restarted */ | 63 | #define ERESTART 175 /* Interrupted system call should be restarted */ |
| 63 | #define ESTRPIPE 176 /* Streams pipe error */ | 64 | #define ESTRPIPE 176 /* Streams pipe error */ |
| 64 | #define EUCLEAN 177 /* Structure needs cleaning */ | 65 | #define EUCLEAN 177 /* Structure needs cleaning */ |
| 66 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 65 | #define ENOTNAM 178 /* Not a XENIX named type file */ | 67 | #define ENOTNAM 178 /* Not a XENIX named type file */ |
| 66 | #define ENAVAIL 179 /* No XENIX semaphores available */ | 68 | #define ENAVAIL 179 /* No XENIX semaphores available */ |
| 67 | #define EISNAM 180 /* Is a named type file */ | 69 | #define EISNAM 180 /* Is a named type file */ |
| @@ -48,6 +48,7 @@ · 47 unmodified lines | |||
| 48 | #define ENOSR 74 /* Out of streams resources */ | 48 | #define ENOSR 74 /* Out of streams resources */ |
| 49 | #define ENOMSG 75 /* No message of desired type */ | 49 | #define ENOMSG 75 /* No message of desired type */ |
| 50 | #define EBADMSG 76 /* Not a data message */ | 50 | #define EBADMSG 76 /* Not a data message */ |
| 51 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 51 | #define EIDRM 77 /* Identifier removed */ | 52 | #define EIDRM 77 /* Identifier removed */ |
| 52 | #define EDEADLK 78 /* Resource deadlock would occur */ | 53 | #define EDEADLK 78 /* Resource deadlock would occur */ |
| 53 | #define ENOLCK 79 /* No record locks available */ | 54 | #define ENOLCK 79 /* No record locks available */ |
| @@ -91,6 +92,7 @@ · 37 unmodified lines | |||
| 91 | #define ENOTUNIQ 115 /* Name not unique on network */ | 92 | #define ENOTUNIQ 115 /* Name not unique on network */ |
| 92 | #define ERESTART 116 /* Interrupted syscall should be restarted */ | 93 | #define ERESTART 116 /* Interrupted syscall should be restarted */ |
| 93 | #define EUCLEAN 117 /* Structure needs cleaning */ | 94 | #define EUCLEAN 117 /* Structure needs cleaning */ |
| 95 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 94 | #define ENOTNAM 118 /* Not a XENIX named type file */ | 96 | #define ENOTNAM 118 /* Not a XENIX named type file */ |
| 95 | #define ENAVAIL 119 /* No XENIX semaphores available */ | 97 | #define ENAVAIL 119 /* No XENIX semaphores available */ |
| 96 | #define EISNAM 120 /* Is a named type file */ | 98 | #define EISNAM 120 /* Is a named type file */ |
| @@ -55,6 +55,7 @@ · 54 unmodified lines | |||
| 55 | #define EMULTIHOP 72 /* Multihop attempted */ | 55 | #define EMULTIHOP 72 /* Multihop attempted */ |
| 56 | #define EDOTDOT 73 /* RFS specific error */ | 56 | #define EDOTDOT 73 /* RFS specific error */ |
| 57 | #define EBADMSG 74 /* Not a data message */ | 57 | #define EBADMSG 74 /* Not a data message */ |
| 58 | #define EFSBADCRC EBADMSG /* Bad CRC detected */ | ||
| 58 | #define EOVERFLOW 75 /* Value too large for defined data type */ | 59 | #define EOVERFLOW 75 /* Value too large for defined data type */ |
| 59 | #define ENOTUNIQ 76 /* Name not unique on network */ | 60 | #define ENOTUNIQ 76 /* Name not unique on network */ |
| 60 | #define EBADFD 77 /* File descriptor in bad state */ | 61 | #define EBADFD 77 /* File descriptor in bad state */ |
| @@ -98,6 +99,7 @@ · 37 unmodified lines | |||
| 98 | #define EINPROGRESS 115 /* Operation now in progress */ | 99 | #define EINPROGRESS 115 /* Operation now in progress */ |
| 99 | #define ESTALE 116 /* Stale file handle */ | 100 | #define ESTALE 116 /* Stale file handle */ |
| 100 | #define EUCLEAN 117 /* Structure needs cleaning */ | 101 | #define EUCLEAN 117 /* Structure needs cleaning */ |
| 102 | #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ | ||
| 101 | #define ENOTNAM 118 /* Not a XENIX named type file */ | 103 | #define ENOTNAM 118 /* Not a XENIX named type file */ |
| 102 | #define ENAVAIL 119 /* No XENIX semaphores available */ | 104 | #define ENAVAIL 119 /* No XENIX semaphores available */ |
| 103 | #define EISNAM 120 /* Is a named type file */ | 105 | #define EISNAM 120 /* Is a named type file */ |