ext4: Replace use of iget() with iget_locked()
Theodore Ts'o
maintainerPATCH 1/1 ext4: Replace use of iget() with iget_locked()
In the mm tree is a patch queued up to nuke iget(). So replace use of iget() with iget_locked(). I will be pushing this to Linus shortly.
- Ted
commit 46ea772acbda42780ae014e608f51e71083be46b
Author: Theodore Ts'o <[email protected]> Date: Sat Feb 2 10:52:41 2008 -0500
ext4: Replace use of iget() with iget_locked()
Signed-off-by "Theodore Ts'o" <[email protected]>
fs/ext4/ialloc.c +11 -3
@@ -805,9 +805,17 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)* is a valid orphan (no e2fsck run on fs). Orphans also include * inodes that were being truncated, so we can't check i_nlink==0. */ -if (!ext4_test_bit (bit, bitmap_bh->b_data) || - !(inode =iget (sb, ino)) ||is_bad_inode (inode) || -NEXT_ORPHAN (inode) > max_ino) { +if (!ext4_test_bit (bit, bitmap_bh->b_data)) + goto bad_orphan_inode; + inode =iget_locked (sb, ino); +if (!inode) + goto bad_orphan_inode; +if (inode->i_state &I_NEW ) { + sb->s_op->read_inode (inode); +unlock_new_inode (inode); + } +if (is_bad_inode (inode) ||NEXT_ORPHAN (inode) > max_ino) { + bad_orphan_inode:ext4_warning (sb, __FUNCTION__,"bad orphan inode %lu! e2fsck was run?" , ino); printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
fs/ext4/super.c +20 -4
@@ -777,9 +777,13 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb,* Currently we don't know the generation for parent directory, so * a generation of 0 means "accept any" */ - inode =iget (sb, ino); + inode =iget_locked (sb, ino);if (inode ==NULL )return ERR_PTR (-ENOMEM ); +if (inode->i_state &I_NEW ) { + sb->s_op->read_inode (inode); +unlock_new_inode (inode); + }if (is_bad_inode (inode) || (generation && inode->i_generation != generation)) {iput (inode);
@@ -2243,7 +2247,15 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)* so we can safely mount the rest of the filesystem now. */ - root =iget (sb,EXT4_ROOT_INO ); + root =iget_locked (sb,EXT4_ROOT_INO ); +if (!root) { +printk (KERN_ERR "EXT4-fs: iget_locked for root inode failed\n" ); + goto failed_mount4; + } +if (root->i_state &I_NEW ) { + sb->s_op->read_inode (root); +unlock_new_inode (root); + } sb->s_root =d_alloc_root (root);if (!sb->s_root) {printk (KERN_ERR "EXT4-fs: get root inode failed\n" );
@@ -2372,11 +2384,15 @@ static journal_t *ext4_get_journal(struct super_block *sb,* things happen if we iget() an unused inode, as the subsequent * iput() will try to delete it. */ - journal_inode =iget (sb, journal_inum); + journal_inode =iget_locked (sb, journal_inum);if (!journal_inode) { -printk (KERN_ERR "EXT4-fs: no journal found.\n" ); +printk (KERN_ERR "EXT4-fs: iget_locked for journal inode failed.\n" );return NULL ; } +if (journal_inode->i_state &I_NEW ) { + sb->s_op->read_inode (journal_inode); +unlock_new_inode (journal_inode); + }if (!journal_inode->i_nlink) {make_bad_inode (journal_inode);iput (journal_inode);
Theodore Tso
maintainerQuoted 2 lines · Theodore Ts'o
In the mm tree is a patch queued up to nuke
iget(). So replace use ofiget()withiget_locked(). I will be pushing this to Linus shortly.
Oops, wrong version of the patch; this is the correct one.
- Ted
ext4: Replace use of iget() with iget_locked()
Signed-off-by "Theodore Ts'o" <[email protected]>
---
fs/ext4/ialloc.c +11 -3
@@ -805,9 +805,17 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)* is a valid orphan (no e2fsck run on fs). Orphans also include * inodes that were being truncated, so we can't check i_nlink==0. */ -if (!ext4_test_bit (bit, bitmap_bh->b_data) || - !(inode =iget (sb, ino)) ||is_bad_inode (inode) || -NEXT_ORPHAN (inode) > max_ino) { +if (!ext4_test_bit (bit, bitmap_bh->b_data)) + goto bad_orphan_inode; + inode =iget_locked (sb, ino); +if (!inode) + goto bad_orphan_inode; +if (inode->i_state &I_NEW ) { + sb->s_op->read_inode (inode); +unlock_new_inode (inode); + } +if (is_bad_inode (inode) ||NEXT_ORPHAN (inode) > max_ino) { + bad_orphan_inode:ext4_warning (sb, __FUNCTION__,"bad orphan inode %lu! e2fsck was run?" , ino); printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
fs/ext4/namei.c +12 -2
@@ -1041,11 +1041,16 @@ static struct dentry *ext4_lookup(struct inode * dir, struct dentry *dentry, str "bad inode number: %lu", ino); inode =NULL ; }else - inode =iget (dir->i_sb, ino); + inode =iget_locked (dir->i_sb, ino);if (!inode)return ERR_PTR (-EACCES ); +if (inode->i_state &I_NEW ) { + inode->i_sb->s_op->read_inode (inode); +unlock_new_inode (inode); + } +if (is_bad_inode (inode)) {iput (inode);return ERR_PTR (-ENOENT );
@@ -1080,11 +1085,16 @@ struct dentry *ext4_get_parent(struct dentry *child) "bad inode number: %lu", ino); inode =NULL ; }else - inode =iget (child->d_inode->i_sb, ino); + inode =iget_locked (child->d_inode->i_sb, ino);if (!inode)return ERR_PTR (-EACCES ); +if (inode->i_state &I_NEW ) { + inode->i_sb->s_op->read_inode (inode); +unlock_new_inode (inode); + } +if (is_bad_inode (inode)) {iput (inode);return ERR_PTR (-ENOENT );
fs/ext4/resize.c +5 -1
@@ -779,7 +779,11 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input) "No reserved GDT blocks, can't resize");return -EPERM ; } - inode =iget (sb,EXT4_RESIZE_INO ); + inode =iget_locked (sb,EXT4_RESIZE_INO ); +if (inode && (inode->i_state &I_NEW )) { + sb->s_op->read_inode (inode); +unlock_new_inode (inode); + }if (!inode ||is_bad_inode (inode)) {ext4_warning (sb, __FUNCTION__,"Error opening resize inode" );
fs/ext4/super.c +20 -4
@@ -777,9 +777,13 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb,* Currently we don't know the generation for parent directory, so * a generation of 0 means "accept any" */ - inode =iget (sb, ino); + inode =iget_locked (sb, ino);if (inode ==NULL )return ERR_PTR (-ENOMEM ); +if (inode->i_state &I_NEW ) { + sb->s_op->read_inode (inode); +unlock_new_inode (inode); + }if (is_bad_inode (inode) || (generation && inode->i_generation != generation)) {iput (inode);
@@ -2243,7 +2247,15 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)* so we can safely mount the rest of the filesystem now. */ - root =iget (sb,EXT4_ROOT_INO ); + root =iget_locked (sb,EXT4_ROOT_INO ); +if (!root) { +printk (KERN_ERR "EXT4-fs: iget_locked for root inode failed\n" ); + goto failed_mount4; + } +if (root->i_state &I_NEW ) { + sb->s_op->read_inode (root); +unlock_new_inode (root); + } sb->s_root =d_alloc_root (root);if (!sb->s_root) {printk (KERN_ERR "EXT4-fs: get root inode failed\n" );
@@ -2372,11 +2384,15 @@ static journal_t *ext4_get_journal(struct super_block *sb,* things happen if we iget() an unused inode, as the subsequent * iput() will try to delete it. */ - journal_inode =iget (sb, journal_inum); + journal_inode =iget_locked (sb, journal_inum);if (!journal_inode) { -printk (KERN_ERR "EXT4-fs: no journal found.\n" ); +printk (KERN_ERR "EXT4-fs: iget_locked for journal inode failed.\n" );return NULL ; } +if (journal_inode->i_state &I_NEW ) { + sb->s_op->read_inode (journal_inode); +unlock_new_inode (journal_inode); + }if (!journal_inode->i_nlink) {make_bad_inode (journal_inode);iput (journal_inode);