Commit ddce3b94 authored by Theodore Ts'o's avatar Theodore Ts'o

ext4: refactor initialize_dirent_tail()

Move the calculation of the location of the dirent tail into
initialize_dirent_tail().  Also prefix the function with ext4_ to fix
kernel namepsace polution.
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent f036adb3
...@@ -3147,7 +3147,7 @@ extern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode, ...@@ -3147,7 +3147,7 @@ extern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
struct ext4_dir_entry_2 *de, struct ext4_dir_entry_2 *de,
int blocksize, int csum_size, int blocksize, int csum_size,
unsigned int parent_ino, int dotdot_real_len); unsigned int parent_ino, int dotdot_real_len);
extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t, extern void ext4_initialize_dirent_tail(struct buffer_head *bh,
unsigned int blocksize); unsigned int blocksize);
extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode, extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode,
struct buffer_head *bh); struct buffer_head *bh);
......
...@@ -1132,7 +1132,6 @@ static int ext4_finish_convert_inline_dir(handle_t *handle, ...@@ -1132,7 +1132,6 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
{ {
int err, csum_size = 0, header_size = 0; int err, csum_size = 0, header_size = 0;
struct ext4_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
struct ext4_dir_entry_tail *t;
void *target = dir_block->b_data; void *target = dir_block->b_data;
/* /*
...@@ -1158,11 +1157,9 @@ static int ext4_finish_convert_inline_dir(handle_t *handle, ...@@ -1158,11 +1157,9 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
inline_size - EXT4_INLINE_DOTDOT_SIZE + header_size, inline_size - EXT4_INLINE_DOTDOT_SIZE + header_size,
inode->i_sb->s_blocksize - csum_size); inode->i_sb->s_blocksize - csum_size);
if (csum_size) { if (csum_size)
t = EXT4_DIRENT_TAIL(dir_block->b_data, ext4_initialize_dirent_tail(dir_block,
inode->i_sb->s_blocksize); inode->i_sb->s_blocksize);
initialize_dirent_tail(t, inode->i_sb->s_blocksize);
}
set_buffer_uptodate(dir_block); set_buffer_uptodate(dir_block);
err = ext4_handle_dirty_dirblock(handle, inode, dir_block); err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
if (err) if (err)
......
...@@ -293,9 +293,11 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname, ...@@ -293,9 +293,11 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
struct inode *dir, struct inode *inode); struct inode *dir, struct inode *inode);
/* checksumming functions */ /* checksumming functions */
void initialize_dirent_tail(struct ext4_dir_entry_tail *t, void ext4_initialize_dirent_tail(struct buffer_head *bh,
unsigned int blocksize) unsigned int blocksize)
{ {
struct ext4_dir_entry_tail *t = EXT4_DIRENT_TAIL(bh->b_data, blocksize);
memset(t, 0, sizeof(struct ext4_dir_entry_tail)); memset(t, 0, sizeof(struct ext4_dir_entry_tail));
t->det_rec_len = ext4_rec_len_to_disk( t->det_rec_len = ext4_rec_len_to_disk(
sizeof(struct ext4_dir_entry_tail), blocksize); sizeof(struct ext4_dir_entry_tail), blocksize);
...@@ -1813,7 +1815,6 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, ...@@ -1813,7 +1815,6 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
char *data1 = (*bh)->b_data, *data2; char *data1 = (*bh)->b_data, *data2;
unsigned split, move, size; unsigned split, move, size;
struct ext4_dir_entry_2 *de = NULL, *de2; struct ext4_dir_entry_2 *de = NULL, *de2;
struct ext4_dir_entry_tail *t;
int csum_size = 0; int csum_size = 0;
int err = 0, i; int err = 0, i;
...@@ -1874,11 +1875,8 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir, ...@@ -1874,11 +1875,8 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
(char *) de2, (char *) de2,
blocksize); blocksize);
if (csum_size) { if (csum_size) {
t = EXT4_DIRENT_TAIL(data2, blocksize); ext4_initialize_dirent_tail(*bh, blocksize);
initialize_dirent_tail(t, blocksize); ext4_initialize_dirent_tail(bh2, blocksize);
t = EXT4_DIRENT_TAIL(data1, blocksize);
initialize_dirent_tail(t, blocksize);
} }
dxtrace(dx_show_leaf(dir, hinfo, (struct ext4_dir_entry_2 *) data1, dxtrace(dx_show_leaf(dir, hinfo, (struct ext4_dir_entry_2 *) data1,
...@@ -2039,8 +2037,7 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname, ...@@ -2039,8 +2037,7 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
struct dx_frame frames[EXT4_HTREE_LEVEL], *frame; struct dx_frame frames[EXT4_HTREE_LEVEL], *frame;
struct dx_entry *entries; struct dx_entry *entries;
struct ext4_dir_entry_2 *de, *de2; struct ext4_dir_entry_2 *de, *de2;
struct ext4_dir_entry_tail *t; char *data2, *top;
char *data1, *top;
unsigned len; unsigned len;
int retval; int retval;
unsigned blocksize; unsigned blocksize;
...@@ -2080,21 +2077,18 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname, ...@@ -2080,21 +2077,18 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
return PTR_ERR(bh2); return PTR_ERR(bh2);
} }
ext4_set_inode_flag(dir, EXT4_INODE_INDEX); ext4_set_inode_flag(dir, EXT4_INODE_INDEX);
data1 = bh2->b_data; data2 = bh2->b_data;
memcpy (data1, de, len); memcpy(data2, de, len);
de = (struct ext4_dir_entry_2 *) data1; de = (struct ext4_dir_entry_2 *) data2;
top = data1 + len; top = data2 + len;
while ((char *)(de2 = ext4_next_entry(de, blocksize)) < top) while ((char *)(de2 = ext4_next_entry(de, blocksize)) < top)
de = de2; de = de2;
de->rec_len = ext4_rec_len_to_disk(data1 + (blocksize - csum_size) - de->rec_len = ext4_rec_len_to_disk(data2 + (blocksize - csum_size) -
(char *) de, (char *) de, blocksize);
blocksize);
if (csum_size) { if (csum_size)
t = EXT4_DIRENT_TAIL(data1, blocksize); ext4_initialize_dirent_tail(bh2, blocksize);
initialize_dirent_tail(t, blocksize);
}
/* Initialize the root; the dot dirents already exist */ /* Initialize the root; the dot dirents already exist */
de = (struct ext4_dir_entry_2 *) (&root->dotdot); de = (struct ext4_dir_entry_2 *) (&root->dotdot);
...@@ -2164,7 +2158,6 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -2164,7 +2158,6 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
struct inode *dir = d_inode(dentry->d_parent); struct inode *dir = d_inode(dentry->d_parent);
struct buffer_head *bh = NULL; struct buffer_head *bh = NULL;
struct ext4_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
struct ext4_dir_entry_tail *t;
struct super_block *sb; struct super_block *sb;
struct ext4_sb_info *sbi; struct ext4_sb_info *sbi;
struct ext4_filename fname; struct ext4_filename fname;
...@@ -2249,10 +2242,8 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -2249,10 +2242,8 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
de->inode = 0; de->inode = 0;
de->rec_len = ext4_rec_len_to_disk(blocksize - csum_size, blocksize); de->rec_len = ext4_rec_len_to_disk(blocksize - csum_size, blocksize);
if (csum_size) { if (csum_size)
t = EXT4_DIRENT_TAIL(bh->b_data, blocksize); ext4_initialize_dirent_tail(bh, blocksize);
initialize_dirent_tail(t, blocksize);
}
retval = add_dirent_to_buf(handle, &fname, dir, inode, de, bh); retval = add_dirent_to_buf(handle, &fname, dir, inode, de, bh);
out: out:
...@@ -2712,7 +2703,6 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir, ...@@ -2712,7 +2703,6 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
{ {
struct buffer_head *dir_block = NULL; struct buffer_head *dir_block = NULL;
struct ext4_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
struct ext4_dir_entry_tail *t;
ext4_lblk_t block = 0; ext4_lblk_t block = 0;
unsigned int blocksize = dir->i_sb->s_blocksize; unsigned int blocksize = dir->i_sb->s_blocksize;
int csum_size = 0; int csum_size = 0;
...@@ -2736,10 +2726,8 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir, ...@@ -2736,10 +2726,8 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
de = (struct ext4_dir_entry_2 *)dir_block->b_data; de = (struct ext4_dir_entry_2 *)dir_block->b_data;
ext4_init_dot_dotdot(inode, de, blocksize, csum_size, dir->i_ino, 0); ext4_init_dot_dotdot(inode, de, blocksize, csum_size, dir->i_ino, 0);
set_nlink(inode, 2); set_nlink(inode, 2);
if (csum_size) { if (csum_size)
t = EXT4_DIRENT_TAIL(dir_block->b_data, blocksize); ext4_initialize_dirent_tail(dir_block, blocksize);
initialize_dirent_tail(t, blocksize);
}
BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata"); BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
err = ext4_handle_dirty_dirblock(handle, inode, dir_block); err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment