Whamcloud - gitweb
LU-12151 osd-ldiskfs: pass owner down rather than transfer it
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel6.3 / ext4-osd-iop-common.patch
1 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
2 index 1d41eef..87b4ea3 100644
3 --- a/fs/ext4/ext4.h
4 +++ b/fs/ext4/ext4.h
5 @@ -1825,6 +1825,14 @@ extern int ext4_orphan_add(handle_t *, struct inode *);
6  extern int ext4_orphan_del(handle_t *, struct inode *);
7  extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
8                                 __u32 start_minor_hash, __u32 *next_hash);
9 +extern struct inode *ext4_create_inode(handle_t *handle,
10 +                                      struct inode * dir, int mode,
11 +                                      uid_t *owner);
12 +extern int ext4_delete_entry(handle_t *handle, struct inode * dir,
13 +                            struct ext4_dir_entry_2 * de_del,
14 +                            struct buffer_head * bh);
15 +extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
16 +                              struct inode *inode);
17  
18  /* resize.c */
19  extern int ext4_group_add(struct super_block *sb,
20 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
21 index 6433d87..0f3783b 100644
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 @@ -1691,10 +1692,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 @@ -1729,7 +1730,7 @@ static int ext4_delete_entry(handle_t *handle,
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 @@ -1776,6 +1777,30 @@ static int ext4_add_nondir(handle_t *handle,
57         return err;
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 +                               uid_t *owner)
64 +{
65 +       struct inode *inode;
66 +
67 +       inode = ext4_new_inode(handle, dir, mode, 0,
68 +                              EXT4_SB(dir->i_sb)->s_inode_goal);
69 +       if (!IS_ERR(inode)) {
70 +               if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode)) {
71 +#ifdef CONFIG_EXT4_FS_XATTR
72 +                       inode->i_op = &ext4_special_inode_operations;
73 +#endif
74 +               } else {
75 +                       inode->i_op = &ext4_file_inode_operations;
76 +                       inode->i_fop = &ext4_file_operations;
77 +                       ext4_set_aops(inode);
78 +               }
79 +       }
80 +       return inode;
81 +}
82 +EXPORT_SYMBOL(ext4_create_inode);
83 +
84  /*
85   * By the time this is called, we already have created
86   * the directory cache entry for the new file, but it
87 @@ -1850,44 +1875,32 @@ retry:
88         return err;
89  }
90  
91 -static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
92 +/* Initialize @inode as a subdirectory of @dir, and add the
93 + * "." and ".." entries into the first directory block. */
94 +int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
95 +                       struct inode *inode)
96  {
97 -       handle_t *handle;
98 -       struct inode *inode;
99 -       struct buffer_head *dir_block = NULL;
100 -       struct ext4_dir_entry_2 *de;
101 +       struct buffer_head * dir_block;
102 +       struct ext4_dir_entry_2 * de;
103         unsigned int blocksize = dir->i_sb->s_blocksize;
104 -       int err, retries = 0;
105 -
106 -       if (EXT4_DIR_LINK_MAX(dir))
107 -               return -EMLINK;
108 +       int err = 0;
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 @@ -1906,18 +1919,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 +
163 +static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
164 +{
165 +       handle_t *handle;
166 +       struct inode *inode;
167 +       int err, retries = 0;
168 +
169 +       if (EXT4_DIR_LINK_MAX(dir))
170 +               return -EMLINK;
171 +
172 +retry:
173 +       handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
174 +                                       EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
175 +                                       2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
176 +       if (IS_ERR(handle))
177 +               return PTR_ERR(handle);
178 +
179 +       if (IS_DIRSYNC(dir))
180 +               ext4_handle_sync(handle);
181 +
182 +       inode = ext4_new_inode(handle, dir, S_IFDIR | mode, &dentry->d_name, 0);
183 +       err = PTR_ERR(inode);
184 +       if (IS_ERR(inode))
185                 goto out_stop;
186 -       }
187 +
188 +       err = ext4_add_dot_dotdot(handle, dir, inode);
189 +       if (err)
190 +               goto out_clear_inode;
191 +
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 @@ -1926,11 +1967,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  /*