Whamcloud - gitweb
LU-12151 osd-ldiskfs: pass owner down rather than transfer it
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / sles11sp2 / ext4-osd-iop-common.patch
1 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
2 index 986e058..344ed3a 100644
3 --- a/fs/ext4/ext4.h
4 +++ b/fs/ext4/ext4.h
5 @@ -1879,6 +1879,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 cb049fe..2071f02 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 @@ -1688,10 +1689,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 @@ -1734,7 +1735,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 @@ -1781,6 +1782,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, NULL,
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 @@ -1857,46 +1882,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 buffer_head *dir_block;
101         struct ext4_dir_entry_2 *de;
102         unsigned int blocksize = dir->i_sb->s_blocksize;
103 -       int err, retries = 0;
104 -
105 -       if (EXT4_DIR_LINK_MAX(dir))
106 -               return -EMLINK;
107 -
108 -       dquot_initialize(dir);
109 +       int err = 0;
110  
111 -retry:
112 -       handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
113 -                                       EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
114 -                                       EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
115         if (IS_ERR(handle))
116                 return PTR_ERR(handle);
117  
118         if (IS_DIRSYNC(dir))
119                 ext4_handle_sync(handle);
120  
121 -       inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
122 -                              &dentry->d_name, 0);
123 -       err = PTR_ERR(inode);
124 -       if (IS_ERR(inode))
125 -               goto out_stop;
126 -
127         inode->i_op = &ext4_dir_inode_operations;
128         inode->i_fop = &ext4_dir_operations;
129         inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
130         dir_block = ext4_bread(handle, inode, 0, 1, &err);
131         if (!dir_block)
132 -               goto out_clear_inode;
133 +               goto get_out;
134         BUFFER_TRACE(dir_block, "get_write_access");
135         err = ext4_journal_get_write_access(handle, dir_block);
136         if (err)
137 -               goto out_clear_inode;
138 +               goto get_out;
139         de = (struct ext4_dir_entry_2 *) dir_block->b_data;
140         de->inode = cpu_to_le32(inode->i_ino);
141         de->name_len = 1;
142 @@ -1915,18 +1926,46 @@ retry:
143         BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
144         err = ext4_handle_dirty_metadata(handle, inode, dir_block);
145         if (err)
146 -               goto out_clear_inode;
147 +               goto get_out;
148         err = ext4_mark_inode_dirty(handle, inode);
149 -       if (!err)
150 -               err = ext4_add_entry(handle, dentry, inode);
151 -       if (err) {
152 -out_clear_inode:
153 -               clear_nlink(inode);
154 -               unlock_new_inode(inode);
155 -               ext4_mark_inode_dirty(handle, inode);
156 -               iput(inode);
157 +get_out:
158 +       brelse(dir_block);
159 +       return err;
160 +}
161 +EXPORT_SYMBOL(ext4_add_dot_dotdot);
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 +       dquot_initialize(dir);
173 +
174 +retry:
175 +       handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
176 +                                       EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
177 +                                       EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
178 +       if (IS_ERR(handle))
179 +               return PTR_ERR(handle);
180 +
181 +       if (IS_DIRSYNC(dir))
182 +               ext4_handle_sync(handle);
183 +
184 +       inode = ext4_new_inode(handle, dir, S_IFDIR | mode, &dentry->d_name, 0);
185 +       err = PTR_ERR(inode);
186 +       if (IS_ERR(inode))
187                 goto out_stop;
188 -       }
189 +
190 +       err = ext4_add_dot_dotdot(handle, dir, inode);
191 +       if (err)
192 +               goto out_clear_inode;
193 +       err = ext4_add_entry(handle, dentry, inode);
194 +       if (err)
195 +               goto out_clear_inode;
196         ext4_inc_count(handle, dir);
197         ext4_update_dx_flag(dir);
198         err = ext4_mark_inode_dirty(handle, dir);
199 @@ -1935,11 +1974,16 @@ out_clear_inode:
200         d_instantiate(dentry, inode);
201         unlock_new_inode(inode);
202  out_stop:
203 -       brelse(dir_block);
204         ext4_journal_stop(handle);
205         if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
206                 goto retry;
207         return err;
208 +out_clear_inode:
209 +       clear_nlink(inode);
210 +       unlock_new_inode(inode);
211 +       ext4_mark_inode_dirty(handle, inode);
212 +       iput(inode);
213 +       goto out_stop;
214  }
215  
216  /*