2 fs/ext4/ext4.h | 13 +++++
3 fs/ext4/namei.c | 131 +++++++++++++++++++++++++++++++++++++-------------------
4 2 files changed, 101 insertions(+), 43 deletions(-)
8 @@ -1895,6 +1895,19 @@ 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_add_entry(handle_t *handle, struct dentry *dentry,
15 + struct inode *inode);
16 +extern int ext4_delete_entry(handle_t *handle, struct inode * dir,
17 + struct ext4_dir_entry_2 * de_del,
18 + struct buffer_head * bh);
19 +extern struct buffer_head * ext4_find_entry(struct inode *dir,
20 + const struct qstr *d_name,
21 + struct ext4_dir_entry_2 ** res_dir);
22 +#define ll_ext4_find_entry(inode, dentry, res_dir) ext4_find_entry(inode, &(dentry)->d_name, res_dir)
23 +extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
24 + struct inode *inode);
27 extern int ext4_group_add(struct super_block *sb,
34 +#include <linux/module.h>
36 #include <linux/pagemap.h>
37 #include <linux/jbd2.h>
38 @@ -873,9 +874,9 @@ static inline int search_dirblock(struct
39 * The returned buffer_head has ->b_count elevated. The caller is expected
40 * to brelse() it when appropriate.
42 -static struct buffer_head * ext4_find_entry (struct inode *dir,
43 - const struct qstr *d_name,
44 - struct ext4_dir_entry_2 ** res_dir)
45 +struct buffer_head * ext4_find_entry(struct inode *dir,
46 + const struct qstr *d_name,
47 + struct ext4_dir_entry_2 ** res_dir)
49 struct super_block *sb;
50 struct buffer_head *bh_use[NAMEI_RA_SIZE];
51 @@ -981,6 +982,7 @@ cleanup_and_exit:
52 brelse(bh_use[ra_ptr]);
55 +EXPORT_SYMBOL(ext4_find_entry);
57 static struct buffer_head * ext4_dx_find_entry(struct inode *dir, const struct qstr *d_name,
58 struct ext4_dir_entry_2 **res_dir, int *err)
59 @@ -1503,8 +1505,8 @@ static int make_indexed_dir(handle_t *ha
60 * may not sleep between calling this and putting something into
61 * the entry, as someone else might have used it while you slept.
63 -static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
64 - struct inode *inode)
65 +int ext4_add_entry(handle_t *handle, struct dentry *dentry,
66 + struct inode *inode)
68 struct inode *dir = dentry->d_parent->d_inode;
69 struct buffer_head *bh;
70 @@ -1555,6 +1557,7 @@ static int ext4_add_entry(handle_t *hand
71 ext4_set_inode_state(inode, EXT4_STATE_NEWENTRY);
74 +EXPORT_SYMBOL(ext4_add_entry);
77 * Returns 0 for success, or a negative error value
78 @@ -1698,10 +1701,10 @@ cleanup:
79 * ext4_delete_entry deletes a directory entry by merging it with the
82 -static int ext4_delete_entry(handle_t *handle,
84 - struct ext4_dir_entry_2 *de_del,
85 - struct buffer_head *bh)
86 +int ext4_delete_entry(handle_t *handle,
88 + struct ext4_dir_entry_2 *de_del,
89 + struct buffer_head *bh)
91 struct ext4_dir_entry_2 *de, *pde;
92 unsigned int blocksize = dir->i_sb->s_blocksize;
93 @@ -1744,7 +1747,7 @@ static int ext4_delete_entry(handle_t *h
98 +EXPORT_SYMBOL(ext4_delete_entry);
100 * DIR_NLINK feature is set if 1) nlinks > EXT4_LINK_MAX or 2) nlinks == 2,
101 * since this indicates that nlinks count was previously 1.
102 @@ -1808,6 +1811,29 @@ static unsigned ext4_dentry_goal(struct
106 + /* Return locked inode, then the caller can modify the inode's states/flags
107 + * before others finding it. The caller should unlock the inode by itself. */
108 +struct inode *ext4_create_inode(handle_t *handle, struct inode *dir, int mode)
110 + struct inode *inode;
112 + inode = ext4_new_inode(handle, dir, mode, NULL,
113 + EXT4_SB(dir->i_sb)->s_inode_goal);
114 + if (!IS_ERR(inode)) {
115 + if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode)) {
116 +#ifdef CONFIG_EXT4_FS_XATTR
117 + inode->i_op = &ext4_special_inode_operations;
120 + inode->i_op = &ext4_file_inode_operations;
121 + inode->i_fop = &ext4_file_operations;
122 + ext4_set_aops(inode);
127 +EXPORT_SYMBOL(ext4_create_inode);
130 * By the time this is called, we already have created
131 * the directory cache entry for the new file, but it
132 @@ -1886,46 +1912,32 @@ retry:
136 -static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
137 +/* Initialize @inode as a subdirectory of @dir, and add the
138 + * "." and ".." entries into the first directory block. */
139 +int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
140 + struct inode *inode)
143 - struct inode *inode;
144 - struct buffer_head *dir_block = NULL;
145 + struct buffer_head *dir_block;
146 struct ext4_dir_entry_2 *de;
147 unsigned int blocksize = dir->i_sb->s_blocksize;
148 - int err, retries = 0;
151 - if (EXT4_DIR_LINK_MAX(dir))
154 - dquot_initialize(dir);
157 - handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
158 - EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
159 - EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
161 return PTR_ERR(handle);
164 ext4_handle_sync(handle);
166 - inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
167 - &dentry->d_name, ext4_dentry_goal(dir->i_sb, dentry));
168 - err = PTR_ERR(inode);
172 inode->i_op = &ext4_dir_inode_operations;
173 inode->i_fop = &ext4_dir_operations;
174 inode->i_size = EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
175 dir_block = ext4_bread(handle, inode, 0, 1, &err);
177 - goto out_clear_inode;
179 BUFFER_TRACE(dir_block, "get_write_access");
180 err = ext4_journal_get_write_access(handle, dir_block);
182 - goto out_clear_inode;
184 de = (struct ext4_dir_entry_2 *) dir_block->b_data;
185 de->inode = cpu_to_le32(inode->i_ino);
187 @@ -1944,18 +1956,47 @@ retry:
188 BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
189 err = ext4_handle_dirty_metadata(handle, inode, dir_block);
191 - goto out_clear_inode;
193 err = ext4_mark_inode_dirty(handle, inode);
195 - err = ext4_add_entry(handle, dentry, inode);
198 - clear_nlink(inode);
199 - unlock_new_inode(inode);
200 - ext4_mark_inode_dirty(handle, inode);
206 +EXPORT_SYMBOL(ext4_add_dot_dotdot);
208 +static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
211 + struct inode *inode;
212 + int err, retries = 0;
214 + if (EXT4_DIR_LINK_MAX(dir))
217 + dquot_initialize(dir);
220 + handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
221 + EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
222 + EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
223 + if (IS_ERR(handle))
224 + return PTR_ERR(handle);
226 + if (IS_DIRSYNC(dir))
227 + ext4_handle_sync(handle);
229 + inode = ext4_new_inode(handle, dir, S_IFDIR | mode, &dentry->d_name,
230 + ext4_dentry_goal(dir->i_sb, dentry));
231 + err = PTR_ERR(inode);
236 + err = ext4_add_dot_dotdot(handle, dir, inode);
238 + goto out_clear_inode;
239 + err = ext4_add_entry(handle, dentry, inode);
241 + goto out_clear_inode;
242 ext4_inc_count(handle, dir);
243 ext4_update_dx_flag(dir);
244 err = ext4_mark_inode_dirty(handle, dir);
245 @@ -1964,11 +2005,16 @@ out_clear_inode:
246 d_instantiate(dentry, inode);
247 unlock_new_inode(inode);
250 ext4_journal_stop(handle);
251 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
255 + clear_nlink(inode);
256 + unlock_new_inode(inode);
257 + ext4_mark_inode_dirty(handle, inode);