Skip to content

Commit

Permalink
iget: introduce a function to register iget failure
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Christoph Hellwig <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
dhowells authored and Linus Torvalds committed Feb 7, 2008
1 parent e231c2e commit b46980f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Documentation/filesystems/porting
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,19 @@ just takes the superblock and inode number as arguments and does the
test and set for you.

e.g.
inode = iget_locked(sb, ino);
if (inode->i_state & I_NEW) {
read_inode_from_disk(inode);
unlock_new_inode(inode);
}
inode = iget_locked(sb, ino);
if (inode->i_state & I_NEW) {
err = read_inode_from_disk(inode);
if (err < 0) {
iget_failed(inode);
return err;
}
unlock_new_inode(inode);
}

Note that if the process of setting up a new inode fails, then iget_failed()
should be called on the inode to render it dead, and an appropriate error
should be passed back to the caller.

---
[recommended]
Expand Down
14 changes: 14 additions & 0 deletions fs/bad_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,17 @@ int is_bad_inode(struct inode *inode)
}

EXPORT_SYMBOL(is_bad_inode);

/**
* iget_failed - Mark an under-construction inode as dead and release it
* @inode: The inode to discard
*
* Mark an under-construction inode as dead and release it.
*/
void iget_failed(struct inode *inode)
{
make_bad_inode(inode);
unlock_new_inode(inode);
iput(inode);
}
EXPORT_SYMBOL(iget_failed);
1 change: 1 addition & 0 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,7 @@ static inline struct inode *iget(struct super_block *sb, unsigned long ino)
}

extern void __iget(struct inode * inode);
extern void iget_failed(struct inode *);
extern void clear_inode(struct inode *);
extern void destroy_inode(struct inode *);
extern struct inode *new_inode(struct super_block *);
Expand Down

0 comments on commit b46980f

Please sign in to comment.