]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - fs/bad_inode.c
vhost: cache used event for better performance
[mirror_ubuntu-bionic-kernel.git] / fs / bad_inode.c
CommitLineData
1da177e4
LT
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>
630d9c47 12#include <linux/export.h>
1da177e4
LT
13#include <linux/stat.h>
14#include <linux/time.h>
1da177e4 15#include <linux/namei.h>
be6aab0e 16#include <linux/poll.h>
1da177e4 17
be6aab0e
ES
18static int bad_file_open(struct inode *inode, struct file *filp)
19{
20 return -EIO;
21}
22
4b6f5d20 23static const struct file_operations bad_file_ops =
1da177e4 24{
be6aab0e 25 .open = bad_file_open,
1da177e4
LT
26};
27
be6aab0e 28static int bad_inode_create (struct inode *dir, struct dentry *dentry,
ebfc3b49 29 umode_t mode, bool excl)
be6aab0e
ES
30{
31 return -EIO;
32}
33
34static struct dentry *bad_inode_lookup(struct inode *dir,
00cd8dd3 35 struct dentry *dentry, unsigned int flags)
be6aab0e
ES
36{
37 return ERR_PTR(-EIO);
38}
39
40static int bad_inode_link (struct dentry *old_dentry, struct inode *dir,
41 struct dentry *dentry)
42{
43 return -EIO;
44}
45
46static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)
47{
48 return -EIO;
49}
50
51static int bad_inode_symlink (struct inode *dir, struct dentry *dentry,
52 const char *symname)
53{
54 return -EIO;
55}
56
57static int bad_inode_mkdir(struct inode *dir, struct dentry *dentry,
18bb1db3 58 umode_t mode)
be6aab0e
ES
59{
60 return -EIO;
61}
62
63static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
64{
65 return -EIO;
66}
67
68static int bad_inode_mknod (struct inode *dir, struct dentry *dentry,
1a67aafb 69 umode_t mode, dev_t rdev)
be6aab0e
ES
70{
71 return -EIO;
72}
73
a0dbc566
MS
74static 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)
be6aab0e
ES
77{
78 return -EIO;
79}
80
81static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,
82 int buflen)
83{
84 return -EIO;
85}
86
10556cb2 87static int bad_inode_permission(struct inode *inode, int mask)
be6aab0e
ES
88{
89 return -EIO;
90}
91
92static int bad_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
93 struct kstat *stat)
94{
95 return -EIO;
96}
97
98static int bad_inode_setattr(struct dentry *direntry, struct iattr *attrs)
99{
100 return -EIO;
101}
102
be6aab0e
ES
103static ssize_t bad_inode_listxattr(struct dentry *dentry, char *buffer,
104 size_t buffer_size)
105{
106 return -EIO;
107}
108
754661f1 109static const struct inode_operations bad_inode_ops =
1da177e4 110{
be6aab0e
ES
111 .create = bad_inode_create,
112 .lookup = bad_inode_lookup,
113 .link = bad_inode_link,
114 .unlink = bad_inode_unlink,
115 .symlink = bad_inode_symlink,
116 .mkdir = bad_inode_mkdir,
117 .rmdir = bad_inode_rmdir,
118 .mknod = bad_inode_mknod,
2773bf00 119 .rename = bad_inode_rename2,
be6aab0e 120 .readlink = bad_inode_readlink,
1da177e4
LT
121 /* follow_link must be no-op, otherwise unmounting this inode
122 won't work */
be6aab0e
ES
123 /* put_link returns void */
124 /* truncate returns void */
125 .permission = bad_inode_permission,
126 .getattr = bad_inode_getattr,
127 .setattr = bad_inode_setattr,
be6aab0e 128 .listxattr = bad_inode_listxattr,
1da177e4
LT
129};
130
131
132/*
133 * When a filesystem is unable to read an inode due to an I/O error in
134 * its read_inode() function, it can call make_bad_inode() to return a
135 * set of stubs which will return EIO errors as required.
136 *
137 * We only need to do limited initialisation: all other fields are
138 * preinitialised to zero automatically.
139 */
140
141/**
142 * make_bad_inode - mark an inode bad due to an I/O error
143 * @inode: Inode to mark bad
144 *
145 * When an inode cannot be read due to a media or remote network
146 * failure this function makes the inode "bad" and causes I/O operations
147 * on it to fail from this point on.
148 */
149
be6aab0e 150void make_bad_inode(struct inode *inode)
1da177e4
LT
151{
152 remove_inode_hash(inode);
153
154 inode->i_mode = S_IFREG;
155 inode->i_atime = inode->i_mtime = inode->i_ctime =
c2050a45 156 current_time(inode);
1da177e4 157 inode->i_op = &bad_inode_ops;
5f6e59ae 158 inode->i_opflags &= ~IOP_XATTR;
1da177e4
LT
159 inode->i_fop = &bad_file_ops;
160}
161EXPORT_SYMBOL(make_bad_inode);
162
163/*
164 * This tests whether an inode has been flagged as bad. The test uses
165 * &bad_inode_ops to cover the case of invalidated inodes as well as
166 * those created by make_bad_inode() above.
167 */
168
169/**
170 * is_bad_inode - is an inode errored
171 * @inode: inode to test
172 *
173 * Returns true if the inode in question has been marked as bad.
174 */
175
0e3ef1fe 176bool is_bad_inode(struct inode *inode)
1da177e4
LT
177{
178 return (inode->i_op == &bad_inode_ops);
179}
180
181EXPORT_SYMBOL(is_bad_inode);
b46980fe
DH
182
183/**
184 * iget_failed - Mark an under-construction inode as dead and release it
185 * @inode: The inode to discard
186 *
187 * Mark an under-construction inode as dead and release it.
188 */
189void iget_failed(struct inode *inode)
190{
191 make_bad_inode(inode);
192 unlock_new_inode(inode);
193 iput(inode);
194}
195EXPORT_SYMBOL(iget_failed);