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