Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/bad_inode.c |
| 3 | * |
| 4 | * Copyright (C) 1997, Stephen Tweedie |
| 5 | * |
| 6 | * Provide stub functions for unreadable inodes |
| 7 | * |
| 8 | * Fabian Frederick : August 2003 - All file operations assigned to EIO |
| 9 | */ |
| 10 | |
| 11 | #include <linux/fs.h> |
Paul Gortmaker | 630d9c4 | 2011-11-16 23:57:37 -0500 | [diff] [blame] | 12 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/stat.h> |
| 14 | #include <linux/time.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/namei.h> |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 16 | #include <linux/poll.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 18 | static int bad_file_open(struct inode *inode, struct file *filp) |
| 19 | { |
| 20 | return -EIO; |
| 21 | } |
| 22 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 23 | static const struct file_operations bad_file_ops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 25 | .open = bad_file_open, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 28 | static int bad_inode_create (struct inode *dir, struct dentry *dentry, |
Al Viro | ebfc3b4 | 2012-06-10 18:05:36 -0400 | [diff] [blame] | 29 | umode_t mode, bool excl) |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 30 | { |
| 31 | return -EIO; |
| 32 | } |
| 33 | |
| 34 | static struct dentry *bad_inode_lookup(struct inode *dir, |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 35 | struct dentry *dentry, unsigned int flags) |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 36 | { |
| 37 | return ERR_PTR(-EIO); |
| 38 | } |
| 39 | |
| 40 | static int bad_inode_link (struct dentry *old_dentry, struct inode *dir, |
| 41 | struct dentry *dentry) |
| 42 | { |
| 43 | return -EIO; |
| 44 | } |
| 45 | |
| 46 | static int bad_inode_unlink(struct inode *dir, struct dentry *dentry) |
| 47 | { |
| 48 | return -EIO; |
| 49 | } |
| 50 | |
| 51 | static int bad_inode_symlink (struct inode *dir, struct dentry *dentry, |
| 52 | const char *symname) |
| 53 | { |
| 54 | return -EIO; |
| 55 | } |
| 56 | |
| 57 | static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry, |
Al Viro | 18bb1db | 2011-07-26 01:41:39 -0400 | [diff] [blame] | 58 | umode_t mode) |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 59 | { |
| 60 | return -EIO; |
| 61 | } |
| 62 | |
| 63 | static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry) |
| 64 | { |
| 65 | return -EIO; |
| 66 | } |
| 67 | |
| 68 | static int bad_inode_mknod (struct inode *dir, struct dentry *dentry, |
Al Viro | 1a67aaf | 2011-07-26 01:52:52 -0400 | [diff] [blame] | 69 | umode_t mode, dev_t rdev) |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 70 | { |
| 71 | return -EIO; |
| 72 | } |
| 73 | |
Miklos Szeredi | a0dbc56 | 2014-07-23 15:15:31 +0200 | [diff] [blame] | 74 | static int bad_inode_rename2(struct inode *old_dir, struct dentry *old_dentry, |
| 75 | struct inode *new_dir, struct dentry *new_dentry, |
| 76 | unsigned int flags) |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 77 | { |
| 78 | return -EIO; |
| 79 | } |
| 80 | |
| 81 | static int bad_inode_readlink(struct dentry *dentry, char __user *buffer, |
| 82 | int buflen) |
| 83 | { |
| 84 | return -EIO; |
| 85 | } |
| 86 | |
Al Viro | 10556cb2 | 2011-06-20 19:28:19 -0400 | [diff] [blame] | 87 | static int bad_inode_permission(struct inode *inode, int mask) |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 88 | { |
| 89 | return -EIO; |
| 90 | } |
| 91 | |
| 92 | static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 93 | struct kstat *stat) |
| 94 | { |
| 95 | return -EIO; |
| 96 | } |
| 97 | |
| 98 | static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs) |
| 99 | { |
| 100 | return -EIO; |
| 101 | } |
| 102 | |
| 103 | static int bad_inode_setxattr(struct dentry *dentry, const char *name, |
| 104 | const void *value, size_t size, int flags) |
| 105 | { |
| 106 | return -EIO; |
| 107 | } |
| 108 | |
| 109 | static ssize_t bad_inode_getxattr(struct dentry *dentry, const char *name, |
| 110 | void *buffer, size_t size) |
| 111 | { |
| 112 | return -EIO; |
| 113 | } |
| 114 | |
| 115 | static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer, |
| 116 | size_t buffer_size) |
| 117 | { |
| 118 | return -EIO; |
| 119 | } |
| 120 | |
| 121 | static int bad_inode_removexattr(struct dentry *dentry, const char *name) |
| 122 | { |
| 123 | return -EIO; |
| 124 | } |
| 125 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 126 | static const struct inode_operations bad_inode_ops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 128 | .create = bad_inode_create, |
| 129 | .lookup = bad_inode_lookup, |
| 130 | .link = bad_inode_link, |
| 131 | .unlink = bad_inode_unlink, |
| 132 | .symlink = bad_inode_symlink, |
| 133 | .mkdir = bad_inode_mkdir, |
| 134 | .rmdir = bad_inode_rmdir, |
| 135 | .mknod = bad_inode_mknod, |
Miklos Szeredi | a0dbc56 | 2014-07-23 15:15:31 +0200 | [diff] [blame] | 136 | .rename2 = bad_inode_rename2, |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 137 | .readlink = bad_inode_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* follow_link must be no-op, otherwise unmounting this inode |
| 139 | won't work */ |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 140 | /* put_link returns void */ |
| 141 | /* truncate returns void */ |
| 142 | .permission = bad_inode_permission, |
| 143 | .getattr = bad_inode_getattr, |
| 144 | .setattr = bad_inode_setattr, |
| 145 | .setxattr = bad_inode_setxattr, |
| 146 | .getxattr = bad_inode_getxattr, |
| 147 | .listxattr = bad_inode_listxattr, |
| 148 | .removexattr = bad_inode_removexattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | |
| 152 | /* |
| 153 | * When a filesystem is unable to read an inode due to an I/O error in |
| 154 | * its read_inode() function, it can call make_bad_inode() to return a |
| 155 | * set of stubs which will return EIO errors as required. |
| 156 | * |
| 157 | * We only need to do limited initialisation: all other fields are |
| 158 | * preinitialised to zero automatically. |
| 159 | */ |
| 160 | |
| 161 | /** |
| 162 | * make_bad_inode - mark an inode bad due to an I/O error |
| 163 | * @inode: Inode to mark bad |
| 164 | * |
| 165 | * When an inode cannot be read due to a media or remote network |
| 166 | * failure this function makes the inode "bad" and causes I/O operations |
| 167 | * on it to fail from this point on. |
| 168 | */ |
| 169 | |
Eric Sandeen | be6aab0 | 2007-01-05 16:36:36 -0800 | [diff] [blame] | 170 | void make_bad_inode(struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | remove_inode_hash(inode); |
| 173 | |
| 174 | inode->i_mode = S_IFREG; |
| 175 | inode->i_atime = inode->i_mtime = inode->i_ctime = |
| 176 | current_fs_time(inode->i_sb); |
| 177 | inode->i_op = &bad_inode_ops; |
| 178 | inode->i_fop = &bad_file_ops; |
| 179 | } |
| 180 | EXPORT_SYMBOL(make_bad_inode); |
| 181 | |
| 182 | /* |
| 183 | * This tests whether an inode has been flagged as bad. The test uses |
| 184 | * &bad_inode_ops to cover the case of invalidated inodes as well as |
| 185 | * those created by make_bad_inode() above. |
| 186 | */ |
| 187 | |
| 188 | /** |
| 189 | * is_bad_inode - is an inode errored |
| 190 | * @inode: inode to test |
| 191 | * |
| 192 | * Returns true if the inode in question has been marked as bad. |
| 193 | */ |
| 194 | |
Yaowei Bai | 0e3ef1f | 2015-11-19 21:00:11 +0800 | [diff] [blame^] | 195 | bool is_bad_inode(struct inode *inode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | { |
| 197 | return (inode->i_op == &bad_inode_ops); |
| 198 | } |
| 199 | |
| 200 | EXPORT_SYMBOL(is_bad_inode); |
David Howells | b46980f | 2008-02-07 00:15:27 -0800 | [diff] [blame] | 201 | |
| 202 | /** |
| 203 | * iget_failed - Mark an under-construction inode as dead and release it |
| 204 | * @inode: The inode to discard |
| 205 | * |
| 206 | * Mark an under-construction inode as dead and release it. |
| 207 | */ |
| 208 | void iget_failed(struct inode *inode) |
| 209 | { |
| 210 | make_bad_inode(inode); |
| 211 | unlock_new_inode(inode); |
| 212 | iput(inode); |
| 213 | } |
| 214 | EXPORT_SYMBOL(iget_failed); |