aboutsummaryrefslogtreecommitdiffstats
path: root/fs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/inode.c')
-rw-r--r--fs/inode.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/fs/inode.c b/fs/inode.c
index 901bad1e5f12..b2ba83d2c4e1 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -120,12 +120,11 @@ static void wake_up_inode(struct inode *inode)
120 * These are initializations that need to be done on every inode 120 * These are initializations that need to be done on every inode
121 * allocation as the fields are not initialised by slab allocation. 121 * allocation as the fields are not initialised by slab allocation.
122 */ 122 */
123struct inode *inode_init_always(struct super_block *sb, struct inode *inode) 123int inode_init_always(struct super_block *sb, struct inode *inode)
124{ 124{
125 static const struct address_space_operations empty_aops; 125 static const struct address_space_operations empty_aops;
126 static struct inode_operations empty_iops; 126 static struct inode_operations empty_iops;
127 static const struct file_operations empty_fops; 127 static const struct file_operations empty_fops;
128
129 struct address_space *const mapping = &inode->i_data; 128 struct address_space *const mapping = &inode->i_data;
130 129
131 inode->i_sb = sb; 130 inode->i_sb = sb;
@@ -152,7 +151,7 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode)
152 inode->dirtied_when = 0; 151 inode->dirtied_when = 0;
153 152
154 if (security_inode_alloc(inode)) 153 if (security_inode_alloc(inode))
155 goto out_free_inode; 154 goto out;
156 155
157 /* allocate and initialize an i_integrity */ 156 /* allocate and initialize an i_integrity */
158 if (ima_inode_alloc(inode)) 157 if (ima_inode_alloc(inode))
@@ -183,9 +182,7 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode)
183 if (sb->s_bdev) { 182 if (sb->s_bdev) {
184 struct backing_dev_info *bdi; 183 struct backing_dev_info *bdi;
185 184
186 bdi = sb->s_bdev->bd_inode_backing_dev_info; 185 bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info;
187 if (!bdi)
188 bdi = sb->s_bdev->bd_inode->i_mapping->backing_dev_info;
189 mapping->backing_dev_info = bdi; 186 mapping->backing_dev_info = bdi;
190 } 187 }
191 inode->i_private = NULL; 188 inode->i_private = NULL;
@@ -198,16 +195,12 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode)
198 inode->i_fsnotify_mask = 0; 195 inode->i_fsnotify_mask = 0;
199#endif 196#endif
200 197
201 return inode; 198 return 0;
202 199
203out_free_security: 200out_free_security:
204 security_inode_free(inode); 201 security_inode_free(inode);
205out_free_inode: 202out:
206 if (inode->i_sb->s_op->destroy_inode) 203 return -ENOMEM;
207 inode->i_sb->s_op->destroy_inode(inode);
208 else
209 kmem_cache_free(inode_cachep, (inode));
210 return NULL;
211} 204}
212EXPORT_SYMBOL(inode_init_always); 205EXPORT_SYMBOL(inode_init_always);
213 206
@@ -220,12 +213,21 @@ static struct inode *alloc_inode(struct super_block *sb)
220 else 213 else
221 inode = kmem_cache_alloc(inode_cachep, GFP_KERNEL); 214 inode = kmem_cache_alloc(inode_cachep, GFP_KERNEL);
222 215
223 if (inode) 216 if (!inode)
224 return inode_init_always(sb, inode); 217 return NULL;
225 return NULL; 218
219 if (unlikely(inode_init_always(sb, inode))) {
220 if (inode->i_sb->s_op->destroy_inode)
221 inode->i_sb->s_op->destroy_inode(inode);
222 else
223 kmem_cache_free(inode_cachep, inode);
224 return NULL;
225 }
226
227 return inode;
226} 228}
227 229
228void destroy_inode(struct inode *inode) 230void __destroy_inode(struct inode *inode)
229{ 231{
230 BUG_ON(inode_has_buffers(inode)); 232 BUG_ON(inode_has_buffers(inode));
231 ima_inode_free(inode); 233 ima_inode_free(inode);
@@ -237,13 +239,17 @@ void destroy_inode(struct inode *inode)
237 if (inode->i_default_acl && inode->i_default_acl != ACL_NOT_CACHED) 239 if (inode->i_default_acl && inode->i_default_acl != ACL_NOT_CACHED)
238 posix_acl_release(inode->i_default_acl); 240 posix_acl_release(inode->i_default_acl);
239#endif 241#endif
242}
243EXPORT_SYMBOL(__destroy_inode);
244
245void destroy_inode(struct inode *inode)
246{
247 __destroy_inode(inode);
240 if (inode->i_sb->s_op->destroy_inode) 248 if (inode->i_sb->s_op->destroy_inode)
241 inode->i_sb->s_op->destroy_inode(inode); 249 inode->i_sb->s_op->destroy_inode(inode);
242 else 250 else
243 kmem_cache_free(inode_cachep, (inode)); 251 kmem_cache_free(inode_cachep, (inode));
244} 252}
245EXPORT_SYMBOL(destroy_inode);
246
247 253
248/* 254/*
249 * These are initializations that only need to be done 255 * These are initializations that only need to be done