1 ext4: Replace use of iget() with iget_locked()
3 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
6 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
7 index 575b521..d45fcaa 100644
10 @@ -805,9 +805,17 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
11 * is a valid orphan (no e2fsck run on fs). Orphans also include
12 * inodes that were being truncated, so we can't check i_nlink==0.
14 - if (!ext4_test_bit(bit, bitmap_bh->b_data) ||
15 - !(inode = iget(sb, ino)) || is_bad_inode(inode) ||
16 - NEXT_ORPHAN(inode) > max_ino) {
17 + if (!ext4_test_bit(bit, bitmap_bh->b_data))
18 + goto bad_orphan_inode;
19 + inode = iget_locked(sb, ino);
21 + goto bad_orphan_inode;
22 + if (inode->i_state & I_NEW) {
23 + sb->s_op->read_inode(inode);
24 + unlock_new_inode(inode);
26 + if (is_bad_inode(inode) || NEXT_ORPHAN(inode) > max_ino) {
28 ext4_warning(sb, __FUNCTION__,
29 "bad orphan inode %lu! e2fsck was run?", ino);
30 printk(KERN_NOTICE "ext4_test_bit(bit=%d, block=%llu) = %d\n",
31 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
32 index 67b6d8a..57dd8fb 100644
35 @@ -1041,11 +1041,16 @@ static struct dentry *ext4_lookup(struct inode * dir, struct dentry *dentry, str
36 "bad inode number: %lu", ino);
39 - inode = iget(dir->i_sb, ino);
40 + inode = iget_locked(dir->i_sb, ino);
43 return ERR_PTR(-EACCES);
45 + if (inode->i_state & I_NEW) {
46 + inode->i_sb->s_op->read_inode(inode);
47 + unlock_new_inode(inode);
50 if (is_bad_inode(inode)) {
52 return ERR_PTR(-ENOENT);
53 @@ -1080,11 +1085,16 @@ struct dentry *ext4_get_parent(struct dentry *child)
54 "bad inode number: %lu", ino);
57 - inode = iget(child->d_inode->i_sb, ino);
58 + inode = iget_locked(child->d_inode->i_sb, ino);
61 return ERR_PTR(-EACCES);
63 + if (inode->i_state & I_NEW) {
64 + inode->i_sb->s_op->read_inode(inode);
65 + unlock_new_inode(inode);
68 if (is_bad_inode(inode)) {
70 return ERR_PTR(-ENOENT);
71 diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
72 index 4fbba60..ebdca31 100644
73 --- a/fs/ext4/resize.c
74 +++ b/fs/ext4/resize.c
75 @@ -779,7 +779,11 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
76 "No reserved GDT blocks, can't resize");
79 - inode = iget(sb, EXT4_RESIZE_INO);
80 + inode = iget_locked(sb, EXT4_RESIZE_INO);
81 + if (inode && (inode->i_state & I_NEW)) {
82 + sb->s_op->read_inode(inode);
83 + unlock_new_inode(inode);
85 if (!inode || is_bad_inode(inode)) {
86 ext4_warning(sb, __FUNCTION__,
87 "Error opening resize inode");
88 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
89 index 055a0cd..1ef0359 100644
92 @@ -777,9 +777,13 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb,
93 * Currently we don't know the generation for parent directory, so
94 * a generation of 0 means "accept any"
96 - inode = iget(sb, ino);
97 + inode = iget_locked(sb, ino);
99 return ERR_PTR(-ENOMEM);
100 + if (inode->i_state & I_NEW) {
101 + sb->s_op->read_inode(inode);
102 + unlock_new_inode(inode);
104 if (is_bad_inode(inode) ||
105 (generation && inode->i_generation != generation)) {
107 @@ -2243,7 +2247,15 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)
108 * so we can safely mount the rest of the filesystem now.
111 - root = iget(sb, EXT4_ROOT_INO);
112 + root = iget_locked(sb, EXT4_ROOT_INO);
114 + printk(KERN_ERR "EXT4-fs: iget_locked for root inode failed\n");
115 + goto failed_mount4;
117 + if (root->i_state & I_NEW) {
118 + sb->s_op->read_inode(root);
119 + unlock_new_inode(root);
121 sb->s_root = d_alloc_root(root);
123 printk(KERN_ERR "EXT4-fs: get root inode failed\n");
124 @@ -2372,11 +2384,15 @@ static journal_t *ext4_get_journal(struct super_block *sb,
125 * things happen if we iget() an unused inode, as the subsequent
126 * iput() will try to delete it. */
128 - journal_inode = iget(sb, journal_inum);
129 + journal_inode = iget_locked(sb, journal_inum);
130 if (!journal_inode) {
131 - printk(KERN_ERR "EXT4-fs: no journal found.\n");
132 + printk(KERN_ERR "EXT4-fs: iget_locked for journal inode failed.\n");
135 + if (journal_inode->i_state & I_NEW) {
136 + sb->s_op->read_inode(journal_inode);
137 + unlock_new_inode(journal_inode);
139 if (!journal_inode->i_nlink) {
140 make_bad_inode(journal_inode);