Whamcloud - gitweb
LU-162 Export ext4_discard_preallocations for ldiskfs
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4-osd-iop-common-rhel6.patch
1 Index: linux-2.6.32.i386/fs/ext4/ext4.h
2 ===================================================================
3 --- linux-2.6.32.i386.orig/fs/ext4/ext4.h       2010-04-16 04:57:39.000000000 +0530
4 +++ linux-2.6.32.i386/fs/ext4/ext4.h    2010-04-16 05:27:02.000000000 +0530
5 @@ -1512,6 +1512,19 @@
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 +extern int ext4_add_entry(handle_t *handle, struct dentry *dentry,
12 +                         struct inode *inode);
13 +extern int ext4_delete_entry(handle_t *handle, struct inode * dir,
14 +                            struct ext4_dir_entry_2 * de_del,
15 +                            struct buffer_head * bh);
16 +extern struct buffer_head * ext4_find_entry(struct inode *dir,
17 +                                           const struct qstr *d_name,
18 +                                           struct ext4_dir_entry_2 ** res_dir);
19 +#define ll_ext4_find_entry(inode, dentry, res_dir) ext4_find_entry(inode, &(dentry)->d_name, res_dir)
20 +extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
21 +                              struct inode *inode);
22  
23  /* resize.c */
24  extern int ext4_group_add(struct super_block *sb,
25 Index: linux-2.6.32.i386/fs/ext4/namei.c
26 ===================================================================
27 --- linux-2.6.32.i386.orig/fs/ext4/namei.c      2010-04-16 04:57:39.000000000 +0530
28 +++ linux-2.6.32.i386/fs/ext4/namei.c   2010-04-16 05:28:25.000000000 +0530
29 @@ -24,6 +24,7 @@
30   *     Theodore Ts'o, 2002
31   */
32  
33 +#include <linux/module.h>
34  #include <linux/fs.h>
35  #include <linux/pagemap.h>
36  #include <linux/jbd2.h>
37 @@ -902,9 +903,9 @@
38   * The returned buffer_head has ->b_count elevated.  The caller is expected
39   * to brelse() it when appropriate.
40   */
41 -static struct buffer_head * ext4_find_entry (struct inode *dir,
42 -                                       const struct qstr *d_name,
43 -                                       struct ext4_dir_entry_2 ** res_dir)
44 +struct buffer_head * ext4_find_entry(struct inode *dir,
45 +                                     const struct qstr *d_name,
46 +                                     struct ext4_dir_entry_2 ** res_dir)
47  {
48         struct super_block *sb;
49         struct buffer_head *bh_use[NAMEI_RA_SIZE];
50 @@ -1011,6 +1012,7 @@
51                 brelse(bh_use[ra_ptr]);
52         return ret;
53  }
54 +EXPORT_SYMBOL(ext4_find_entry);
55  
56  static struct buffer_head * ext4_dx_find_entry(struct inode *dir, const struct qstr *d_name,
57                        struct ext4_dir_entry_2 **res_dir, int *err)
58 @@ -1538,8 +1540,8 @@
59   * may not sleep between calling this and putting something into
60   * the entry, as someone else might have used it while you slept.
61   */
62 -static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
63 -                         struct inode *inode)
64 +int ext4_add_entry(handle_t *handle, struct dentry *dentry,
65 +                  struct inode *inode)
66  {
67         struct inode *dir = dentry->d_parent->d_inode;
68         struct buffer_head *bh;
69 @@ -1588,6 +1590,7 @@
70         brelse(bh);
71         return retval;
72  }
73 +EXPORT_SYMBOL(ext4_add_entry);
74  
75  /*
76   * Returns 0 for success, or a negative error value
77 @@ -1728,10 +1731,10 @@
78   * ext4_delete_entry deletes a directory entry by merging it with the
79   * previous entry
80   */
81 -static 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 +int ext4_delete_entry(handle_t *handle,
86 +                     struct inode *dir,
87 +                     struct ext4_dir_entry_2 *de_del,
88 +                     struct buffer_head *bh)
89  {
90         struct ext4_dir_entry_2 *de, *pde;
91         unsigned int blocksize = dir->i_sb->s_blocksize;
92 @@ -1766,7 +1769,7 @@
93         }
94         return -ENOENT;
95  }
96 -
97 +EXPORT_SYMBOL(ext4_delete_entry);
98  /*
99   * DIR_NLINK feature is set if 1) nlinks > EXT4_LINK_MAX or 2) nlinks == 2,
100   * since this indicates that nlinks count was previously 1.
101 @@ -1831,6 +1834,26 @@
102         return inum;
103  }
104  
105 +struct inode * ext4_create_inode(handle_t *handle, struct inode * dir, int mode)
106 +{
107 +       struct inode *inode;
108 +
109 +       inode = ext4_new_inode(handle, dir, mode, 0, 0);
110 +       if (!IS_ERR(inode)) {
111 +               if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode)) {
112 +#ifdef CONFIG_LDISKFS_FS_XATTR
113 +                       inode->i_op = &ext4_special_inode_operations;
114 +#endif
115 +               } else {
116 +                       inode->i_op = &ext4_file_inode_operations;
117 +                       inode->i_fop = &ext4_file_operations;
118 +                       ext4_set_aops(inode);
119 +               }
120 +       }
121 +       return inode;
122 +}
123 +EXPORT_SYMBOL(ext4_create_inode);
124 +
125  /*
126   * By the time this is called, we already have created
127   * the directory cache entry for the new file, but it
128 @@ -1905,40 +1928,33 @@
129         return err;
130  }
131  
132 -static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
133 +/* Initialize @inode as a subdirectory of @dir, and add the
134 + * "." and ".." entries into the first directory block. */
135 +int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
136 +                       struct inode *inode)
137  {
138 -       handle_t *handle;
139 -       struct inode *inode;
140 -       struct buffer_head *dir_block;
141 -       struct ext4_dir_entry_2 *de;
142 +       struct buffer_head * dir_block;
143 +       struct ext4_dir_entry_2 * de;
144         unsigned int blocksize = dir->i_sb->s_blocksize;
145 -       int err, retries = 0;
146 -
147 -       if (EXT4_DIR_LINK_MAX(dir))
148 -               return -EMLINK;
149 +       int err = 0;
150  
151 -retry:
152 -       handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
153 -                                       EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
154 -                                       EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
155         if (IS_ERR(handle))
156                 return PTR_ERR(handle);
157  
158         if (IS_DIRSYNC(dir))
159                 ext4_handle_sync(handle);
160  
161 -       inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
162 -                              &dentry->d_name, 0);
163 -       err = PTR_ERR(inode);
164 -       if (IS_ERR(inode))
165 -               goto out_stop;
166  
167         inode->i_op = &ext4_dir_inode_operations;
168         inode->i_fop = &ext4_dir_operations;
169         inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
170         dir_block = ext4_bread(handle, inode, 0, 1, &err);
171 -       if (!dir_block)
172 -               goto out_clear_inode;
173 +       if (!dir_block) {
174 +               clear_nlink(inode);
175 +               ext4_mark_inode_dirty(handle, inode);
176 +               iput (inode);
177 +               goto get_out;
178 +       }
179         BUFFER_TRACE(dir_block, "get_write_access");
180         ext4_journal_get_write_access(handle, dir_block);
181         de = (struct ext4_dir_entry_2 *) dir_block->b_data;
182 @@ -1960,9 +1976,43 @@
183         ext4_handle_dirty_metadata(handle, dir, dir_block);
184         brelse(dir_block);
185         ext4_mark_inode_dirty(handle, inode);
186 +get_out:
187 +       return err;
188 +}
189 +EXPORT_SYMBOL(ext4_add_dot_dotdot);
190 +
191 +
192 +static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
193 +{
194 +       handle_t *handle;
195 +       struct inode *inode;
196 +       int err, retries = 0;
197 +
198 +       if (EXT4_DIR_LINK_MAX(dir))
199 +               return -EMLINK;
200 +
201 +retry:
202 +       handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
203 +                                       EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
204 +                                       2*EXT4_QUOTA_INIT_BLOCKS(dir->i_sb));
205 +       if (IS_ERR(handle))
206 +               return PTR_ERR(handle);
207 +
208 +       if (IS_DIRSYNC(dir))
209 +               handle->h_sync = 1;
210 +
211 +       inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
212 +                              &dentry->d_name, ext4_dentry_goal(dir->i_sb, dentry));
213 +       err = PTR_ERR(inode);
214 +       if (IS_ERR(inode))
215 +               goto out_stop;
216 +
217 +       err = ext4_add_dot_dotdot(handle, dir, inode);
218 +       if (err)
219 +               goto out_stop;
220 +
221         err = ext4_add_entry(handle, dentry, inode);
222         if (err) {
223 -out_clear_inode:
224                 clear_nlink(inode);
225                 unlock_new_inode(inode);
226                 ext4_mark_inode_dirty(handle, inode);