xref: /linux/include/linux/fserror.h (revision dd466ea0029961ee0ee6e8e468faa1506275c8a9)
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 
fserror_report_io(struct inode * inode,enum fserror_type type,loff_t pos,u64 len,int error,gfp_t gfp)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 
fserror_report_data_lost(struct inode * inode,loff_t pos,u64 len,gfp_t gfp)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 
fserror_report_file_metadata(struct inode * inode,int error,gfp_t gfp)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 
fserror_report_metadata(struct super_block * sb,int error,gfp_t gfp)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 
fserror_report_shutdown(struct super_block * sb,gfp_t gfp)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__ */
76