Whamcloud - gitweb
0f101ede8be1d8cd7f67e7c13ed21196cdc3f6f3
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / sles11sp2 / ext4-osd-iop-common.patch
1 ---
2  fs/ext4/ext4.h  |   13 +++++
3  fs/ext4/namei.c |  131 +++++++++++++++++++++++++++++++++++++-------------------
4  2 files changed, 101 insertions(+), 43 deletions(-)
5
6 --- a/fs/ext4/ext4.h
7 +++ b/fs/ext4/ext4.h
8 @@ -1895,6 +1895,13 @@ extern int ext4_orphan_add(handle_t *, s
9  extern int ext4_orphan_del(handle_t *, struct inode *);
10  extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
11                                 __u32 start_minor_hash, __u32 *next_hash);
12 +extern struct inode *ext4_create_inode(handle_t *handle,
13 +                                      struct inode * dir, int mode);
14 +extern int ext4_delete_entry(handle_t *handle, struct inode * dir,
15 +                            struct ext4_dir_entry_2 * de_del,
16 +                            struct buffer_head * bh);
17 +extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
18 +                              struct inode *inode);
19
20  /* resize.c */
21  extern int ext4_group_add(struct super_block *sb,
22 --- a/fs/ext4/namei.c
23 +++ b/fs/ext4/namei.c
24 @@ -24,6 +24,7 @@
25   *     Theodore Ts'o, 2002
26   */
27
28 +#include <linux/module.h>
29  #include <linux/fs.h>
30  #include <linux/pagemap.h>
31  #include <linux/jbd2.h>
32 @@ -1698,10 +1701,10 @@ cleanup:
33   * ext4_delete_entry deletes a directory entry by merging it with the
34   * previous entry
35   */
36 -static int ext4_delete_entry(handle_t *handle,
37 -                            struct inode *dir,
38 -                            struct ext4_dir_entry_2 *de_del,
39 -                            struct buffer_head *bh)
40 +int ext4_delete_entry(handle_t *handle,
41 +                     struct inode *dir,
42 +                     struct ext4_dir_entry_2 *de_del,
43 +                     struct buffer_head *bh)
44  {
45         struct ext4_dir_entry_2 *de, *pde;
46         unsigned int blocksize = dir->i_sb->s_blocksize;
47 @@ -1744,7 +1747,7 @@ static int ext4_delete_entry(handle_t *h
48         }
49         return -ENOENT;
50  }
51 -
52 +EXPORT_SYMBOL(ext4_delete_entry);
53  /*
54   * DIR_NLINK feature is set if 1) nlinks > EXT4_LINK_MAX or 2) nlinks == 2,
55   * since this indicates that nlinks count was previously 1.
56 @@ -1808,6 +1811,29 @@ static unsigned ext4_dentry_goal(struct
57         return inum;
58  }
59
60 + /* Return locked inode, then the caller can modify the inode's states/flags
61 +  * before others finding it. The caller should unlock the inode by itself. */
62 +struct inode *ext4_create_inode(handle_t *handle, struct inode *dir, int mode)
63 +{
64 +       struct inode *inode;
65 +
66 +       inode = ext4_new_inode(handle, dir, mode, NULL,
67 +                              EXT4_SB(dir->i_sb)->s_inode_goal);
68 +       if (!IS_ERR(inode)) {
69 +               if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode)) {
70 +#ifdef CONFIG_EXT4_FS_XATTR
71 +                       inode->i_op = &ext4_special_inode_operations;
72 +#endif
73 +               } else {
74 +                       inode->i_op = &ext4_file_inode_operations;
75 +                       inode->i_fop = &ext4_file_operations;
76 +                       ext4_set_aops(inode);
77 +               }
78 +       }
79 +       return inode;
80 +}
81 +EXPORT_SYMBOL(ext4_create_inode);
82 +
83  /*
84   * By the time this is called, we already have created
85   * the directory cache entry for the new file, but it
86 @@ -1886,46 +1912,32 @@ retry:
87         return err;
88  }
89
90 -static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
91 +/* Initialize @inode as a subdirectory of @dir, and add the
92 + * "." and ".." entries into the first directory block. */
93 +int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
94 +                       struct inode *inode)
95  {
96 -       handle_t *handle;
97 -       struct inode *inode;
98 -       struct buffer_head *dir_block = NULL;
99 +       struct buffer_head *dir_block;
100         struct ext4_dir_entry_2 *de;
101         unsigned int blocksize = dir->i_sb->s_blocksize;
102 -       int err, retries = 0;
103 +       int err = 0;
104
105 -       if (EXT4_DIR_LINK_MAX(dir))
106 -               return -EMLINK;
107 -
108 -       dquot_initialize(dir);
109 -
110 -retry:
111 -       handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
112 -                                       EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
113 -                                       EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
114         if (IS_ERR(handle))
115                 return PTR_ERR(handle);
116
117         if (IS_DIRSYNC(dir))
118                 ext4_handle_sync(handle);
119
120 -       inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
121 -                              &dentry->d_name, 0);
122 -       err = PTR_ERR(inode);
123 -       if (IS_ERR(inode))
124 -               goto out_stop;
125 -
126         inode->i_op = &ext4_dir_inode_operations;
127         inode->i_fop = &ext4_dir_operations;
128         inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
129         dir_block = ext4_bread(handle, inode, 0, 1, &err);
130         if (!dir_block)
131 -               goto out_clear_inode;
132 +               goto get_out;
133         BUFFER_TRACE(dir_block, "get_write_access");
134         err = ext4_journal_get_write_access(handle, dir_block);
135         if (err)
136 -               goto out_clear_inode;
137 +               goto get_out;
138         de = (struct ext4_dir_entry_2 *) dir_block->b_data;
139         de->inode = cpu_to_le32(inode->i_ino);
140         de->name_len = 1;
141 @@ -1944,18 +1956,46 @@ retry:
142         BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
143         err = ext4_handle_dirty_metadata(handle, inode, dir_block);
144         if (err)
145 -               goto out_clear_inode;
146 +               goto get_out;
147         err = ext4_mark_inode_dirty(handle, inode);
148 -       if (!err)
149 -               err = ext4_add_entry(handle, dentry, inode);
150 -       if (err) {
151 -out_clear_inode:
152 -               clear_nlink(inode);
153 -               unlock_new_inode(inode);
154 -               ext4_mark_inode_dirty(handle, inode);
155 -               iput(inode);
156 +get_out:
157 +       brelse(dir_block);
158 +       return err;
159 +}
160 +EXPORT_SYMBOL(ext4_add_dot_dotdot);
161 +
162 +static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
163 +{
164 +       handle_t *handle;
165 +       struct inode *inode;
166 +       int err, retries = 0;
167 +
168 +       if (EXT4_DIR_LINK_MAX(dir))
169 +               return -EMLINK;
170 +
171 +       dquot_initialize(dir);
172 +
173 +retry:
174 +       handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
175 +                                       EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
176 +                                       EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
177 +       if (IS_ERR(handle))
178 +               return PTR_ERR(handle);
179 +
180 +       if (IS_DIRSYNC(dir))
181 +               ext4_handle_sync(handle);
182 +
183 +       inode = ext4_new_inode(handle, dir, S_IFDIR | mode, &dentry->d_name, 0);
184 +       err = PTR_ERR(inode);
185 +       if (IS_ERR(inode))
186                 goto out_stop;
187 -       }
188 +
189 +       err = ext4_add_dot_dotdot(handle, dir, inode);
190 +       if (err)
191 +               goto out_clear_inode;
192 +       err = ext4_add_entry(handle, dentry, inode);
193 +       if (err)
194 +               goto out_clear_inode;
195         ext4_inc_count(handle, dir);
196         ext4_update_dx_flag(dir);
197         err = ext4_mark_inode_dirty(handle, dir);
198 @@ -1964,11 +2005,16 @@ out_clear_inode:
199         d_instantiate(dentry, inode);
200         unlock_new_inode(inode);
201  out_stop:
202 -       brelse(dir_block);
203         ext4_journal_stop(handle);
204         if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
205                 goto retry;
206         return err;
207 +out_clear_inode:
208 +       clear_nlink(inode);
209 +       unlock_new_inode(inode);
210 +       ext4_mark_inode_dirty(handle, inode);
211 +       iput(inode);
212 +       goto out_stop;
213  }
214
215  /*