Whamcloud - gitweb
LU-5510 scrub: ldiskfs_create_inode returns locked inode
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel6.3 / ext4-osd-iop-common.patch
1 --- a/fs/ext4/ext4.h
2 +++ b/fs/ext4/ext4.h
3 @@ -1778,6 +1778,19 @@ extern int ext4_orphan_add(handle_t *, s
4  extern int ext4_orphan_del(handle_t *, struct inode *);
5  extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
6                                 __u32 start_minor_hash, __u32 *next_hash);
7 +extern struct inode *ext4_create_inode(handle_t *handle,
8 +                                      struct inode * dir, int mode);
9 +extern int ext4_add_entry(handle_t *handle, struct dentry *dentry,
10 +                         struct inode *inode);
11 +extern int ext4_delete_entry(handle_t *handle, struct inode * dir,
12 +                            struct ext4_dir_entry_2 * de_del,
13 +                            struct buffer_head * bh);
14 +extern struct buffer_head * ext4_find_entry(struct inode *dir,
15 +                                           const struct qstr *d_name,
16 +                                           struct ext4_dir_entry_2 ** res_dir);
17 +#define ll_ext4_find_entry(inode, dentry, res_dir) ext4_find_entry(inode, &(dentry)->d_name, res_dir)
18 +extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
19 +                              struct inode *inode);
20  
21  /* resize.c */
22  extern int ext4_group_add(struct super_block *sb,
23 --- a/fs/ext4/namei.c
24 +++ b/fs/ext4/namei.c
25 @@ -24,6 +24,7 @@
26   *     Theodore Ts'o, 2002
27   */
28  
29 +#include <linux/module.h>
30  #include <linux/fs.h>
31  #include <linux/pagemap.h>
32  #include <linux/jbd2.h>
33 @@ -873,9 +874,9 @@ static inline int search_dirblock(struct
34   * The returned buffer_head has ->b_count elevated.  The caller is expected
35   * to brelse() it when appropriate.
36   */
37 -static struct buffer_head * ext4_find_entry (struct inode *dir,
38 -                                       const struct qstr *d_name,
39 -                                       struct ext4_dir_entry_2 ** res_dir)
40 +struct buffer_head * ext4_find_entry(struct inode *dir,
41 +                                     const struct qstr *d_name,
42 +                                     struct ext4_dir_entry_2 ** res_dir)
43  {
44         struct super_block *sb;
45         struct buffer_head *bh_use[NAMEI_RA_SIZE];
46 @@ -981,6 +982,7 @@ cleanup_and_exit:
47                 brelse(bh_use[ra_ptr]);
48         return ret;
49  }
50 +EXPORT_SYMBOL(ext4_find_entry);
51  
52  static struct buffer_head * ext4_dx_find_entry(struct inode *dir, const struct qstr *d_name,
53                        struct ext4_dir_entry_2 **res_dir, int *err)
54 @@ -1515,8 +1517,8 @@ static int make_indexed_dir(handle_t *ha
55   * may not sleep between calling this and putting something into
56   * the entry, as someone else might have used it while you slept.
57   */
58 -static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
59 -                         struct inode *inode)
60 +int ext4_add_entry(handle_t *handle, struct dentry *dentry,
61 +                  struct inode *inode)
62  {
63         struct inode *dir = dentry->d_parent->d_inode;
64         struct buffer_head *bh;
65 @@ -1565,6 +1567,7 @@ static int ext4_add_entry(handle_t *hand
66         brelse(bh);
67         return retval;
68  }
69 +EXPORT_SYMBOL(ext4_add_entry);
70  
71  /*
72   * Returns 0 for success, or a negative error value
73 @@ -1704,10 +1707,10 @@ cleanup:
74   * ext4_delete_entry deletes a directory entry by merging it with the
75   * previous entry
76   */
77 -static int ext4_delete_entry(handle_t *handle,
78 -                            struct inode *dir,
79 -                            struct ext4_dir_entry_2 *de_del,
80 -                            struct buffer_head *bh)
81 +int ext4_delete_entry(handle_t *handle,
82 +                     struct inode *dir,
83 +                     struct ext4_dir_entry_2 *de_del,
84 +                     struct buffer_head *bh)
85  {
86         struct ext4_dir_entry_2 *de, *pde;
87         unsigned int blocksize = dir->i_sb->s_blocksize;
88 @@ -1742,7 +1745,7 @@ static int ext4_delete_entry(handle_t *h
89         }
90         return -ENOENT;
91  }
92 -
93 +EXPORT_SYMBOL(ext4_delete_entry);
94  /*
95   * DIR_NLINK feature is set if 1) nlinks > EXT4_LINK_MAX or 2) nlinks == 2,
96   * since this indicates that nlinks count was previously 1.
97 @@ -1806,6 +1809,29 @@ static unsigned ext4_dentry_goal(struct
98         return inum;
99  }
100  
101 + /* Return locked inode, then the caller can modify the inode's states/flags
102 +  * before others finding it. The caller should unlock the inode by itself. */
103 +struct inode *ext4_create_inode(handle_t *handle, struct inode *dir, int mode)
104 +{
105 +       struct inode *inode;
106 +
107 +       inode = ext4_new_inode(handle, dir, mode, 0,
108 +                              EXT4_SB(dir->i_sb)->s_inode_goal);
109 +       if (!IS_ERR(inode)) {
110 +               if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode)) {
111 +#ifdef CONFIG_EXT4_FS_XATTR
112 +                       inode->i_op = &ext4_special_inode_operations;
113 +#endif
114 +               } else {
115 +                       inode->i_op = &ext4_file_inode_operations;
116 +                       inode->i_fop = &ext4_file_operations;
117 +                       ext4_set_aops(inode);
118 +               }
119 +       }
120 +       return inode;
121 +}
122 +EXPORT_SYMBOL(ext4_create_inode);
123 +
124  /*
125   * By the time this is called, we already have created
126   * the directory cache entry for the new file, but it
127 @@ -1882,44 +1908,32 @@ retry:
128         return err;
129  }
130  
131 -static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
132 +/* Initialize @inode as a subdirectory of @dir, and add the
133 + * "." and ".." entries into the first directory block. */
134 +int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
135 +                       struct inode *inode)
136  {
137 -       handle_t *handle;
138 -       struct inode *inode;
139 -       struct buffer_head *dir_block = NULL;
140 -       struct ext4_dir_entry_2 *de;
141 +       struct buffer_head * dir_block;
142 +       struct ext4_dir_entry_2 * de;
143         unsigned int blocksize = dir->i_sb->s_blocksize;
144 -       int err, retries = 0;
145 +       int err = 0;
146  
147 -       if (EXT4_DIR_LINK_MAX(dir))
148 -               return -EMLINK;
149 -
150 -retry:
151 -       handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
152 -                                       EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
153 -                                       EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
154         if (IS_ERR(handle))
155                 return PTR_ERR(handle);
156  
157         if (IS_DIRSYNC(dir))
158                 ext4_handle_sync(handle);
159  
160 -       inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
161 -                              &dentry->d_name, ext4_dentry_goal(dir->i_sb, dentry));
162 -       err = PTR_ERR(inode);
163 -       if (IS_ERR(inode))
164 -               goto out_stop;
165 -
166         inode->i_op = &ext4_dir_inode_operations;
167         inode->i_fop = &ext4_dir_operations;
168         inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
169         dir_block = ext4_bread(handle, inode, 0, 1, &err);
170         if (!dir_block)
171 -               goto out_clear_inode;
172 +               goto get_out;
173         BUFFER_TRACE(dir_block, "get_write_access");
174         err = ext4_journal_get_write_access(handle, dir_block);
175         if (err)
176 -               goto out_clear_inode;
177 +               goto get_out;
178         de = (struct ext4_dir_entry_2 *) dir_block->b_data;
179         de->inode = cpu_to_le32(inode->i_ino);
180         de->name_len = 1;
181 @@ -1938,18 +1952,47 @@ retry:
182         BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
183         err = ext4_handle_dirty_metadata(handle, inode, dir_block);
184         if (err)
185 -               goto out_clear_inode;
186 +               goto get_out;
187         err = ext4_mark_inode_dirty(handle, inode);
188 -       if (!err)
189 -               err = ext4_add_entry(handle, dentry, inode);
190 -       if (err) {
191 -out_clear_inode:
192 -               clear_nlink(inode);
193 -               unlock_new_inode(inode);
194 -               ext4_mark_inode_dirty(handle, inode);
195 -               iput(inode);
196 +get_out:
197 +       brelse(dir_block);
198 +       return err;
199 +}
200 +EXPORT_SYMBOL(ext4_add_dot_dotdot);
201 +
202 +
203 +static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
204 +{
205 +       handle_t *handle;
206 +       struct inode *inode;
207 +       int err, retries = 0;
208 +
209 +       if (EXT4_DIR_LINK_MAX(dir))
210 +               return -EMLINK;
211 +
212 +retry:
213 +       handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
214 +                                       EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
215 +                                       2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
216 +       if (IS_ERR(handle))
217 +               return PTR_ERR(handle);
218 +
219 +       if (IS_DIRSYNC(dir))
220 +               ext4_handle_sync(handle);
221 +
222 +       inode = ext4_new_inode(handle, dir, S_IFDIR | mode, &dentry->d_name,
223 +                              ext4_dentry_goal(dir->i_sb, dentry));
224 +       err = PTR_ERR(inode);
225 +       if (IS_ERR(inode))
226                 goto out_stop;
227 -       }
228 +
229 +       err = ext4_add_dot_dotdot(handle, dir, inode);
230 +       if (err)
231 +               goto out_clear_inode;
232 +
233 +       err = ext4_add_entry(handle, dentry, inode);
234 +       if (err)
235 +               goto out_clear_inode;
236         ext4_inc_count(handle, dir);
237         ext4_update_dx_flag(dir);
238         err = ext4_mark_inode_dirty(handle, dir);
239 @@ -1958,11 +2001,16 @@ out_clear_inode:
240         d_instantiate(dentry, inode);
241         unlock_new_inode(inode);
242  out_stop:
243 -       brelse(dir_block);
244         ext4_journal_stop(handle);
245         if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
246                 goto retry;
247         return err;
248 +out_clear_inode:
249 +       clear_nlink(inode);
250 +       unlock_new_inode(inode);
251 +       ext4_mark_inode_dirty(handle, inode);
252 +       iput(inode);
253 +       goto out_stop;
254  }
255  
256  /*