Skip to content

Commit b46980f

Browse files
dhowellsLinus Torvalds
authored andcommitted
iget: introduce a function to register iget failure
Introduce a function to register failure in an inode construction path. This includes marking the inode under construction as bad, unlocking it and releasing it. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e231c2e commit b46980f

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎Documentation/filesystems/porting‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,19 @@ just takes the superblock and inode number as arguments and does the
184184
test and set for you.
185185

186186
e.g.
187-
inode = iget_locked(sb, ino);
188-
if (inode->i_state & I_NEW) {
189-
read_inode_from_disk(inode);
190-
unlock_new_inode(inode);
191-
}
187+
inode = iget_locked(sb, ino);
188+
if (inode->i_state & I_NEW) {
189+
err = read_inode_from_disk(inode);
190+
if (err < 0) {
191+
iget_failed(inode);
192+
return err;
193+
}
194+
unlock_new_inode(inode);
195+
}
196+
197+
Note that if the process of setting up a new inode fails, then iget_failed()
198+
should be called on the inode to render it dead, and an appropriate error
199+
should be passed back to the caller.
192200

193201
---
194202
[recommended]

‎fs/bad_inode.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,17 @@ int is_bad_inode(struct inode *inode)
359359
}
360360

361361
EXPORT_SYMBOL(is_bad_inode);
362+
363+
/**
364+
* iget_failed - Mark an under-construction inode as dead and release it
365+
* @inode: The inode to discard
366+
*
367+
* Mark an under-construction inode as dead and release it.
368+
*/
369+
void iget_failed(struct inode *inode)
370+
{
371+
make_bad_inode(inode);
372+
unlock_new_inode(inode);
373+
iput(inode);
374+
}
375+
EXPORT_SYMBOL(iget_failed);

‎include/linux/fs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,7 @@ static inline struct inode *iget(struct super_block *sb, unsigned long ino)
17801780
}
17811781

17821782
extern void __iget(struct inode * inode);
1783+
extern void iget_failed(struct inode *);
17831784
extern void clear_inode(struct inode *);
17841785
extern void destroy_inode(struct inode *);
17851786
extern struct inode *new_inode(struct super_block *);

0 commit comments

Comments
 (0)