1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 /* 2 /* 3 * linux/fs/bad_inode.c 3 * linux/fs/bad_inode.c 4 * 4 * 5 * Copyright (C) 1997, Stephen Tweedie 5 * Copyright (C) 1997, Stephen Tweedie 6 * 6 * 7 * Provide stub functions for unreadable inod 7 * Provide stub functions for unreadable inodes 8 * 8 * 9 * Fabian Frederick : August 2003 - All file 9 * Fabian Frederick : August 2003 - All file operations assigned to EIO 10 */ 10 */ 11 11 12 #include <linux/fs.h> 12 #include <linux/fs.h> 13 #include <linux/export.h> 13 #include <linux/export.h> 14 #include <linux/stat.h> 14 #include <linux/stat.h> 15 #include <linux/time.h> 15 #include <linux/time.h> 16 #include <linux/namei.h> 16 #include <linux/namei.h> 17 #include <linux/poll.h> 17 #include <linux/poll.h> 18 #include <linux/fiemap.h> 18 #include <linux/fiemap.h> 19 19 20 static int bad_file_open(struct inode *inode, 20 static int bad_file_open(struct inode *inode, struct file *filp) 21 { 21 { 22 return -EIO; 22 return -EIO; 23 } 23 } 24 24 25 static const struct file_operations bad_file_o 25 static const struct file_operations bad_file_ops = 26 { 26 { 27 .open = bad_file_open, 27 .open = bad_file_open, 28 }; 28 }; 29 29 30 static int bad_inode_create(struct mnt_idmap * !! 30 static int bad_inode_create (struct inode *dir, struct dentry *dentry, 31 struct inode *dir, !! 31 umode_t mode, bool excl) 32 umode_t mode, bool << 33 { 32 { 34 return -EIO; 33 return -EIO; 35 } 34 } 36 35 37 static struct dentry *bad_inode_lookup(struct 36 static struct dentry *bad_inode_lookup(struct inode *dir, 38 struct dentry *dentry, 37 struct dentry *dentry, unsigned int flags) 39 { 38 { 40 return ERR_PTR(-EIO); 39 return ERR_PTR(-EIO); 41 } 40 } 42 41 43 static int bad_inode_link (struct dentry *old_ 42 static int bad_inode_link (struct dentry *old_dentry, struct inode *dir, 44 struct dentry *dentry) 43 struct dentry *dentry) 45 { 44 { 46 return -EIO; 45 return -EIO; 47 } 46 } 48 47 49 static int bad_inode_unlink(struct inode *dir, 48 static int bad_inode_unlink(struct inode *dir, struct dentry *dentry) 50 { 49 { 51 return -EIO; 50 return -EIO; 52 } 51 } 53 52 54 static int bad_inode_symlink(struct mnt_idmap !! 53 static int bad_inode_symlink (struct inode *dir, struct dentry *dentry, 55 struct inode *dir !! 54 const char *symname) 56 const char *symna << 57 { 55 { 58 return -EIO; 56 return -EIO; 59 } 57 } 60 58 61 static int bad_inode_mkdir(struct mnt_idmap *i !! 59 static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry, 62 struct dentry *dent !! 60 umode_t mode) 63 { 61 { 64 return -EIO; 62 return -EIO; 65 } 63 } 66 64 67 static int bad_inode_rmdir (struct inode *dir, 65 static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry) 68 { 66 { 69 return -EIO; 67 return -EIO; 70 } 68 } 71 69 72 static int bad_inode_mknod(struct mnt_idmap *i !! 70 static int bad_inode_mknod (struct inode *dir, struct dentry *dentry, 73 struct dentry *dent !! 71 umode_t mode, dev_t rdev) 74 { 72 { 75 return -EIO; 73 return -EIO; 76 } 74 } 77 75 78 static int bad_inode_rename2(struct mnt_idmap !! 76 static int bad_inode_rename2(struct inode *old_dir, struct dentry *old_dentry, 79 struct inode *old << 80 struct inode *new 77 struct inode *new_dir, struct dentry *new_dentry, 81 unsigned int flag 78 unsigned int flags) 82 { 79 { 83 return -EIO; 80 return -EIO; 84 } 81 } 85 82 86 static int bad_inode_readlink(struct dentry *d 83 static int bad_inode_readlink(struct dentry *dentry, char __user *buffer, 87 int buflen) 84 int buflen) 88 { 85 { 89 return -EIO; 86 return -EIO; 90 } 87 } 91 88 92 static int bad_inode_permission(struct mnt_idm !! 89 static int bad_inode_permission(struct inode *inode, int mask) 93 struct inode * << 94 { 90 { 95 return -EIO; 91 return -EIO; 96 } 92 } 97 93 98 static int bad_inode_getattr(struct mnt_idmap !! 94 static int bad_inode_getattr(const struct path *path, struct kstat *stat, 99 const struct path << 100 u32 request_mask, 95 u32 request_mask, unsigned int query_flags) 101 { 96 { 102 return -EIO; 97 return -EIO; 103 } 98 } 104 99 105 static int bad_inode_setattr(struct mnt_idmap !! 100 static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs) 106 struct dentry *di << 107 { 101 { 108 return -EIO; 102 return -EIO; 109 } 103 } 110 104 111 static ssize_t bad_inode_listxattr(struct dent 105 static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer, 112 size_t buffer_size) 106 size_t buffer_size) 113 { 107 { 114 return -EIO; 108 return -EIO; 115 } 109 } 116 110 117 static const char *bad_inode_get_link(struct d 111 static const char *bad_inode_get_link(struct dentry *dentry, 118 struct i 112 struct inode *inode, 119 struct d 113 struct delayed_call *done) 120 { 114 { 121 return ERR_PTR(-EIO); 115 return ERR_PTR(-EIO); 122 } 116 } 123 117 124 static struct posix_acl *bad_inode_get_acl(str !! 118 static struct posix_acl *bad_inode_get_acl(struct inode *inode, int type) 125 { 119 { 126 return ERR_PTR(-EIO); 120 return ERR_PTR(-EIO); 127 } 121 } 128 122 129 static int bad_inode_fiemap(struct inode *inod 123 static int bad_inode_fiemap(struct inode *inode, 130 struct fiemap_exte 124 struct fiemap_extent_info *fieinfo, u64 start, 131 u64 len) 125 u64 len) 132 { 126 { 133 return -EIO; 127 return -EIO; 134 } 128 } 135 129 136 static int bad_inode_update_time(struct inode !! 130 static int bad_inode_update_time(struct inode *inode, struct timespec64 *time, >> 131 int flags) 137 { 132 { 138 return -EIO; 133 return -EIO; 139 } 134 } 140 135 141 static int bad_inode_atomic_open(struct inode 136 static int bad_inode_atomic_open(struct inode *inode, struct dentry *dentry, 142 struct file * 137 struct file *file, unsigned int open_flag, 143 umode_t creat 138 umode_t create_mode) 144 { 139 { 145 return -EIO; 140 return -EIO; 146 } 141 } 147 142 148 static int bad_inode_tmpfile(struct mnt_idmap !! 143 static int bad_inode_tmpfile(struct inode *inode, struct dentry *dentry, 149 struct inode *ino << 150 umode_t mode) 144 umode_t mode) 151 { 145 { 152 return -EIO; 146 return -EIO; 153 } 147 } 154 148 155 static int bad_inode_set_acl(struct mnt_idmap !! 149 static int bad_inode_set_acl(struct inode *inode, struct posix_acl *acl, 156 struct dentry *de << 157 int type) 150 int type) 158 { 151 { 159 return -EIO; 152 return -EIO; 160 } 153 } 161 154 162 static const struct inode_operations bad_inode 155 static const struct inode_operations bad_inode_ops = 163 { 156 { 164 .create = bad_inode_create, 157 .create = bad_inode_create, 165 .lookup = bad_inode_lookup, 158 .lookup = bad_inode_lookup, 166 .link = bad_inode_link, 159 .link = bad_inode_link, 167 .unlink = bad_inode_unlink, 160 .unlink = bad_inode_unlink, 168 .symlink = bad_inode_symlink, 161 .symlink = bad_inode_symlink, 169 .mkdir = bad_inode_mkdir, 162 .mkdir = bad_inode_mkdir, 170 .rmdir = bad_inode_rmdir, 163 .rmdir = bad_inode_rmdir, 171 .mknod = bad_inode_mknod, 164 .mknod = bad_inode_mknod, 172 .rename = bad_inode_rename2, 165 .rename = bad_inode_rename2, 173 .readlink = bad_inode_readlink, 166 .readlink = bad_inode_readlink, 174 .permission = bad_inode_permission 167 .permission = bad_inode_permission, 175 .getattr = bad_inode_getattr, 168 .getattr = bad_inode_getattr, 176 .setattr = bad_inode_setattr, 169 .setattr = bad_inode_setattr, 177 .listxattr = bad_inode_listxattr, 170 .listxattr = bad_inode_listxattr, 178 .get_link = bad_inode_get_link, 171 .get_link = bad_inode_get_link, 179 .get_inode_acl = bad_inode_get_acl, !! 172 .get_acl = bad_inode_get_acl, 180 .fiemap = bad_inode_fiemap, 173 .fiemap = bad_inode_fiemap, 181 .update_time = bad_inode_update_tim 174 .update_time = bad_inode_update_time, 182 .atomic_open = bad_inode_atomic_ope 175 .atomic_open = bad_inode_atomic_open, 183 .tmpfile = bad_inode_tmpfile, 176 .tmpfile = bad_inode_tmpfile, 184 .set_acl = bad_inode_set_acl, 177 .set_acl = bad_inode_set_acl, 185 }; 178 }; 186 179 187 180 188 /* 181 /* 189 * When a filesystem is unable to read an inod 182 * When a filesystem is unable to read an inode due to an I/O error in 190 * its read_inode() function, it can call make 183 * its read_inode() function, it can call make_bad_inode() to return a 191 * set of stubs which will return EIO errors a 184 * set of stubs which will return EIO errors as required. 192 * 185 * 193 * We only need to do limited initialisation: 186 * We only need to do limited initialisation: all other fields are 194 * preinitialised to zero automatically. 187 * preinitialised to zero automatically. 195 */ 188 */ 196 189 197 /** 190 /** 198 * make_bad_inode - mark an inode bad due 191 * make_bad_inode - mark an inode bad due to an I/O error 199 * @inode: Inode to mark bad 192 * @inode: Inode to mark bad 200 * 193 * 201 * When an inode cannot be read due to a 194 * When an inode cannot be read due to a media or remote network 202 * failure this function makes the inode 195 * failure this function makes the inode "bad" and causes I/O operations 203 * on it to fail from this point on. 196 * on it to fail from this point on. 204 */ 197 */ 205 198 206 void make_bad_inode(struct inode *inode) 199 void make_bad_inode(struct inode *inode) 207 { 200 { 208 remove_inode_hash(inode); 201 remove_inode_hash(inode); 209 202 210 inode->i_mode = S_IFREG; 203 inode->i_mode = S_IFREG; 211 simple_inode_init_ts(inode); !! 204 inode->i_atime = inode->i_mtime = inode->i_ctime = >> 205 current_time(inode); 212 inode->i_op = &bad_inode_ops; 206 inode->i_op = &bad_inode_ops; 213 inode->i_opflags &= ~IOP_XATTR; 207 inode->i_opflags &= ~IOP_XATTR; 214 inode->i_fop = &bad_file_ops; 208 inode->i_fop = &bad_file_ops; 215 } 209 } 216 EXPORT_SYMBOL(make_bad_inode); 210 EXPORT_SYMBOL(make_bad_inode); 217 211 218 /* 212 /* 219 * This tests whether an inode has been flagge 213 * This tests whether an inode has been flagged as bad. The test uses 220 * &bad_inode_ops to cover the case of invalid 214 * &bad_inode_ops to cover the case of invalidated inodes as well as 221 * those created by make_bad_inode() above. 215 * those created by make_bad_inode() above. 222 */ 216 */ 223 217 224 /** 218 /** 225 * is_bad_inode - is an inode errored 219 * is_bad_inode - is an inode errored 226 * @inode: inode to test 220 * @inode: inode to test 227 * 221 * 228 * Returns true if the inode in question 222 * Returns true if the inode in question has been marked as bad. 229 */ 223 */ 230 224 231 bool is_bad_inode(struct inode *inode) 225 bool is_bad_inode(struct inode *inode) 232 { 226 { 233 return (inode->i_op == &bad_inode_ops) 227 return (inode->i_op == &bad_inode_ops); 234 } 228 } 235 229 236 EXPORT_SYMBOL(is_bad_inode); 230 EXPORT_SYMBOL(is_bad_inode); 237 231 238 /** 232 /** 239 * iget_failed - Mark an under-construction in 233 * iget_failed - Mark an under-construction inode as dead and release it 240 * @inode: The inode to discard 234 * @inode: The inode to discard 241 * 235 * 242 * Mark an under-construction inode as dead an 236 * Mark an under-construction inode as dead and release it. 243 */ 237 */ 244 void iget_failed(struct inode *inode) 238 void iget_failed(struct inode *inode) 245 { 239 { 246 make_bad_inode(inode); 240 make_bad_inode(inode); 247 unlock_new_inode(inode); 241 unlock_new_inode(inode); 248 iput(inode); 242 iput(inode); 249 } 243 } 250 EXPORT_SYMBOL(iget_failed); 244 EXPORT_SYMBOL(iget_failed); 251 245
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.