2 fs/ext4/ext4.h | 13 +++++
3 fs/ext4/namei.c | 131 +++++++++++++++++++++++++++++++++++++-------------------
4 2 files changed, 101 insertions(+), 43 deletions(-)
8 @@ -1895,6 +1895,13 @@ 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_delete_entry(handle_t *handle, struct inode * dir,
15 + struct ext4_dir_entry_2 * de_del,
16 + struct buffer_head * bh);
17 +extern int ext4_add_dot_dotdot(handle_t *handle, struct inode *dir,
18 + struct inode *inode);
21 extern int ext4_group_add(struct super_block *sb,
28 +#include <linux/module.h>
30 #include <linux/pagemap.h>
31 #include <linux/jbd2.h>
32 @@ -1698,10 +1701,10 @@ cleanup:
33 * ext4_delete_entry deletes a directory entry by merging it with the
36 -static int ext4_delete_entry(handle_t *handle,
38 - struct ext4_dir_entry_2 *de_del,
39 - struct buffer_head *bh)
40 +int ext4_delete_entry(handle_t *handle,
42 + struct ext4_dir_entry_2 *de_del,
43 + struct buffer_head *bh)
45 struct ext4_dir_entry_2 *de, *pde;
46 unsigned int blocksize = dir->i_sb->s_blocksize;
47 @@ -1744,7 +1747,7 @@ static int ext4_delete_entry(handle_t *h
52 +EXPORT_SYMBOL(ext4_delete_entry);
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 @@ -1808,6 +1811,29 @@ static unsigned ext4_dentry_goal(struct
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)
64 + struct inode *inode;
66 + inode = ext4_new_inode(handle, dir, mode, NULL,
67 + EXT4_SB(dir->i_sb)->s_inode_goal);
68 + if (!IS_ERR(inode)) {
69 + if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode)) {
70 +#ifdef CONFIG_EXT4_FS_XATTR
71 + inode->i_op = &ext4_special_inode_operations;
74 + inode->i_op = &ext4_file_inode_operations;
75 + inode->i_fop = &ext4_file_operations;
76 + ext4_set_aops(inode);
81 +EXPORT_SYMBOL(ext4_create_inode);
84 * By the time this is called, we already have created
85 * the directory cache entry for the new file, but it
86 @@ -1886,46 +1912,32 @@ retry:
90 -static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
91 +/* Initialize @inode as a subdirectory of @dir, and add the
92 + * "." and ".." entries into the first directory block. */
93 +int ext4_add_dot_dotdot(handle_t *handle, struct inode * dir,
94 + struct inode *inode)
97 - struct inode *inode;
98 - struct buffer_head *dir_block = NULL;
99 + struct buffer_head *dir_block;
100 struct ext4_dir_entry_2 *de;
101 unsigned int blocksize = dir->i_sb->s_blocksize;
102 - int err, retries = 0;
105 - if (EXT4_DIR_LINK_MAX(dir))
108 - dquot_initialize(dir);
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));
115 return PTR_ERR(handle);
118 ext4_handle_sync(handle);
120 - inode = ext4_new_inode(handle, dir, S_IFDIR | mode,
121 - &dentry->d_name, 0);
122 - err = PTR_ERR(inode);
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);
131 - goto out_clear_inode;
133 BUFFER_TRACE(dir_block, "get_write_access");
134 err = ext4_journal_get_write_access(handle, dir_block);
136 - goto out_clear_inode;
138 de = (struct ext4_dir_entry_2 *) dir_block->b_data;
139 de->inode = cpu_to_le32(inode->i_ino);
141 @@ -1944,18 +1956,46 @@ retry:
142 BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
143 err = ext4_handle_dirty_metadata(handle, inode, dir_block);
145 - goto out_clear_inode;
147 err = ext4_mark_inode_dirty(handle, inode);
149 - err = ext4_add_entry(handle, dentry, inode);
152 - clear_nlink(inode);
153 - unlock_new_inode(inode);
154 - ext4_mark_inode_dirty(handle, inode);
160 +EXPORT_SYMBOL(ext4_add_dot_dotdot);
162 +static int ext4_mkdir(struct inode *dir, struct dentry *dentry, int mode)
165 + struct inode *inode;
166 + int err, retries = 0;
168 + if (EXT4_DIR_LINK_MAX(dir))
171 + dquot_initialize(dir);
174 + handle = ext4_journal_start(dir, EXT4_DATA_TRANS_BLOCKS(dir->i_sb) +
175 + EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3 +
176 + EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
177 + if (IS_ERR(handle))
178 + return PTR_ERR(handle);
180 + if (IS_DIRSYNC(dir))
181 + ext4_handle_sync(handle);
183 + inode = ext4_new_inode(handle, dir, S_IFDIR | mode, &dentry->d_name, 0);
184 + err = PTR_ERR(inode);
189 + err = ext4_add_dot_dotdot(handle, dir, inode);
191 + goto out_clear_inode;
192 + err = ext4_add_entry(handle, dentry, inode);
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 @@ -1964,11 +2005,16 @@ out_clear_inode:
199 d_instantiate(dentry, inode);
200 unlock_new_inode(inode);
203 ext4_journal_stop(handle);
204 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
208 + clear_nlink(inode);
209 + unlock_new_inode(inode);
210 + ext4_mark_inode_dirty(handle, inode);