Remove ext2/ext3 BKL patches which conflict with the ro bind mount patches.
[ext4-patch-queue.git] / replace-iget-with-iget-unlocked
blob1c15e0f1fdda108ef599f9ed75faa35c0433b01e
1 ext4: Replace use of iget() with iget_locked()
2     
3 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
5 ---
6 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
7 index 575b521..d45fcaa 100644
8 --- a/fs/ext4/ialloc.c
9 +++ b/fs/ext4/ialloc.c
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.
13          */
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);
20 +       if (!inode)
21 +               goto bad_orphan_inode;
22 +       if (inode->i_state & I_NEW) {
23 +               sb->s_op->read_inode(inode);
24 +               unlock_new_inode(inode);
25 +       }
26 +       if (is_bad_inode(inode) || NEXT_ORPHAN(inode) > max_ino) {
27 +       bad_orphan_inode:
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
33 --- a/fs/ext4/namei.c
34 +++ b/fs/ext4/namei.c
35 @@ -1041,11 +1041,16 @@ static struct dentry *ext4_lookup(struct inode * dir, struct dentry *dentry, str
36                                    "bad inode number: %lu", ino);
37                         inode = NULL;
38                 } else
39 -                       inode = iget(dir->i_sb, ino);
40 +                       inode = iget_locked(dir->i_sb, ino);
42                 if (!inode)
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);
48 +               }
50                 if (is_bad_inode(inode)) {
51                         iput(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);
55                 inode = NULL;
56         } else
57 -               inode = iget(child->d_inode->i_sb, ino);
58 +               inode = iget_locked(child->d_inode->i_sb, ino);
60         if (!inode)
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);
66 +       }
68         if (is_bad_inode(inode)) {
69                 iput(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");
77                         return -EPERM;
78                 }
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);
84 +               }
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
90 --- a/fs/ext4/super.c
91 +++ b/fs/ext4/super.c
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"
95          */
96 -       inode = iget(sb, ino);
97 +       inode = iget_locked(sb, ino);
98         if (inode == NULL)
99                 return ERR_PTR(-ENOMEM);
100 +       if (inode->i_state & I_NEW) {
101 +               sb->s_op->read_inode(inode);
102 +               unlock_new_inode(inode);
103 +       }
104         if (is_bad_inode(inode) ||
105             (generation && inode->i_generation != generation)) {
106                 iput(inode);
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.
109          */
111 -       root = iget(sb, EXT4_ROOT_INO);
112 +       root = iget_locked(sb, EXT4_ROOT_INO);
113 +       if (!root) {
114 +               printk(KERN_ERR "EXT4-fs: iget_locked for root inode failed\n");
115 +               goto failed_mount4;
116 +       }
117 +       if (root->i_state & I_NEW) {
118 +               sb->s_op->read_inode(root);
119 +               unlock_new_inode(root);
120 +       }
121         sb->s_root = d_alloc_root(root);
122         if (!sb->s_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");
133                 return NULL;
134         }
135 +       if (journal_inode->i_state & I_NEW) {
136 +               sb->s_op->read_inode(journal_inode);
137 +               unlock_new_inode(journal_inode);
138 +       }
139         if (!journal_inode->i_nlink) {
140                 make_bad_inode(journal_inode);
141                 iput(journal_inode);