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