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