f2fs: reuse make_empty_dir code for inline_dentry

This patch introduces do_make_empty_dir to mitigate code redundancy
for inline_dentry.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Jaegeuk Kim 2014-10-18 23:06:41 -07:00
parent 7b3cd7d6f0
commit 062a3e7ba7
3 changed files with 31 additions and 33 deletions

View File

@ -323,12 +323,35 @@ int update_dent_inode(struct inode *inode, const struct qstr *name)
return 0; return 0;
} }
void do_make_empty_dir(struct inode *inode, struct inode *parent,
struct f2fs_dentry_ptr *d)
{
struct f2fs_dir_entry *de;
de = &d->dentry[0];
de->name_len = cpu_to_le16(1);
de->hash_code = 0;
de->ino = cpu_to_le32(inode->i_ino);
memcpy(d->filename[0], ".", 1);
set_de_type(de, inode);
de = &d->dentry[1];
de->hash_code = 0;
de->name_len = cpu_to_le16(2);
de->ino = cpu_to_le32(parent->i_ino);
memcpy(d->filename[1], "..", 2);
set_de_type(de, inode);
test_and_set_bit_le(0, (void *)d->bitmap);
test_and_set_bit_le(1, (void *)d->bitmap);
}
static int make_empty_dir(struct inode *inode, static int make_empty_dir(struct inode *inode,
struct inode *parent, struct page *page) struct inode *parent, struct page *page)
{ {
struct page *dentry_page; struct page *dentry_page;
struct f2fs_dentry_block *dentry_blk; struct f2fs_dentry_block *dentry_blk;
struct f2fs_dir_entry *de; struct f2fs_dentry_ptr d;
if (f2fs_has_inline_dentry(inode)) if (f2fs_has_inline_dentry(inode))
return make_empty_inline_dir(inode, parent, page); return make_empty_inline_dir(inode, parent, page);
@ -339,22 +362,9 @@ static int make_empty_dir(struct inode *inode,
dentry_blk = kmap_atomic(dentry_page); dentry_blk = kmap_atomic(dentry_page);
de = &dentry_blk->dentry[0]; make_dentry_ptr(&d, (void *)dentry_blk, 1);
de->name_len = cpu_to_le16(1); do_make_empty_dir(inode, parent, &d);
de->hash_code = 0;
de->ino = cpu_to_le32(inode->i_ino);
memcpy(dentry_blk->filename[0], ".", 1);
set_de_type(de, inode);
de = &dentry_blk->dentry[1];
de->hash_code = 0;
de->name_len = cpu_to_le16(2);
de->ino = cpu_to_le32(parent->i_ino);
memcpy(dentry_blk->filename[1], "..", 2);
set_de_type(de, inode);
test_and_set_bit_le(0, &dentry_blk->dentry_bitmap);
test_and_set_bit_le(1, &dentry_blk->dentry_bitmap);
kunmap_atomic(dentry_blk); kunmap_atomic(dentry_blk);
set_page_dirty(dentry_page); set_page_dirty(dentry_page);

View File

@ -1275,6 +1275,8 @@ struct f2fs_dir_entry *find_target_dentry(struct qstr *, int *,
struct f2fs_dentry_ptr *); struct f2fs_dentry_ptr *);
bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *, bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *,
unsigned int); unsigned int);
void do_make_empty_dir(struct inode *, struct inode *,
struct f2fs_dentry_ptr *);
struct page *init_inode_metadata(struct inode *, struct inode *, struct page *init_inode_metadata(struct inode *, struct inode *,
const struct qstr *, struct page *); const struct qstr *, struct page *);
void update_parent_metadata(struct inode *, struct inode *, unsigned int); void update_parent_metadata(struct inode *, struct inode *, unsigned int);

View File

@ -314,26 +314,12 @@ int make_empty_inline_dir(struct inode *inode, struct inode *parent,
struct page *ipage) struct page *ipage)
{ {
struct f2fs_inline_dentry *dentry_blk; struct f2fs_inline_dentry *dentry_blk;
struct f2fs_dir_entry *de; struct f2fs_dentry_ptr d;
dentry_blk = inline_data_addr(ipage); dentry_blk = inline_data_addr(ipage);
de = &dentry_blk->dentry[0]; make_dentry_ptr(&d, (void *)dentry_blk, 2);
de->name_len = cpu_to_le16(1); do_make_empty_dir(inode, parent, &d);
de->hash_code = 0;
de->ino = cpu_to_le32(inode->i_ino);
memcpy(dentry_blk->filename[0], ".", 1);
set_de_type(de, inode);
de = &dentry_blk->dentry[1];
de->hash_code = 0;
de->name_len = cpu_to_le16(2);
de->ino = cpu_to_le32(parent->i_ino);
memcpy(dentry_blk->filename[1], "..", 2);
set_de_type(de, inode);
test_and_set_bit_le(0, &dentry_blk->dentry_bitmap);
test_and_set_bit_le(1, &dentry_blk->dentry_bitmap);
set_page_dirty(ipage); set_page_dirty(ipage);