f2fs: introduce f2fs_update_dentry to clean up duplicated codes
This patch introduces f2fs_update_dentry to remove redundant code in f2fs_add_inline_entry and __f2fs_add_link. Signed-off-by: Chao Yu <chao2.yu@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
1753396a0a
commit
3b4d732a56
3 changed files with 31 additions and 22 deletions
|
@ -474,6 +474,24 @@ int room_for_filename(const void *bitmap, int slots, int max_slots)
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void f2fs_update_dentry(struct inode *inode, struct f2fs_dentry_ptr *d,
|
||||||
|
const struct qstr *name, f2fs_hash_t name_hash,
|
||||||
|
unsigned int bit_pos)
|
||||||
|
{
|
||||||
|
struct f2fs_dir_entry *de;
|
||||||
|
int slots = GET_DENTRY_SLOTS(name->len);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
de = &d->dentry[bit_pos];
|
||||||
|
de->hash_code = name_hash;
|
||||||
|
de->name_len = cpu_to_le16(name->len);
|
||||||
|
memcpy(d->filename[bit_pos], name->name, name->len);
|
||||||
|
de->ino = cpu_to_le32(inode->i_ino);
|
||||||
|
set_de_type(de, inode);
|
||||||
|
for (i = 0; i < slots; i++)
|
||||||
|
test_and_set_bit_le(bit_pos + i, (void *)d->bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Caller should grab and release a rwsem by calling f2fs_lock_op() and
|
* Caller should grab and release a rwsem by calling f2fs_lock_op() and
|
||||||
* f2fs_unlock_op().
|
* f2fs_unlock_op().
|
||||||
|
@ -486,15 +504,14 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name,
|
||||||
unsigned int current_depth;
|
unsigned int current_depth;
|
||||||
unsigned long bidx, block;
|
unsigned long bidx, block;
|
||||||
f2fs_hash_t dentry_hash;
|
f2fs_hash_t dentry_hash;
|
||||||
struct f2fs_dir_entry *de;
|
|
||||||
unsigned int nbucket, nblock;
|
unsigned int nbucket, nblock;
|
||||||
size_t namelen = name->len;
|
size_t namelen = name->len;
|
||||||
struct page *dentry_page = NULL;
|
struct page *dentry_page = NULL;
|
||||||
struct f2fs_dentry_block *dentry_blk = NULL;
|
struct f2fs_dentry_block *dentry_blk = NULL;
|
||||||
|
struct f2fs_dentry_ptr d;
|
||||||
int slots = GET_DENTRY_SLOTS(namelen);
|
int slots = GET_DENTRY_SLOTS(namelen);
|
||||||
struct page *page;
|
struct page *page;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (f2fs_has_inline_dentry(dir)) {
|
if (f2fs_has_inline_dentry(dir)) {
|
||||||
err = f2fs_add_inline_entry(dir, name, inode);
|
err = f2fs_add_inline_entry(dir, name, inode);
|
||||||
|
@ -553,14 +570,10 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name,
|
||||||
err = PTR_ERR(page);
|
err = PTR_ERR(page);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
de = &dentry_blk->dentry[bit_pos];
|
|
||||||
de->hash_code = dentry_hash;
|
make_dentry_ptr(&d, (void *)dentry_blk, 1);
|
||||||
de->name_len = cpu_to_le16(namelen);
|
f2fs_update_dentry(inode, &d, name, dentry_hash, bit_pos);
|
||||||
memcpy(dentry_blk->filename[bit_pos], name->name, name->len);
|
|
||||||
de->ino = cpu_to_le32(inode->i_ino);
|
|
||||||
set_de_type(de, inode);
|
|
||||||
for (i = 0; i < slots; i++)
|
|
||||||
test_and_set_bit_le(bit_pos + i, &dentry_blk->dentry_bitmap);
|
|
||||||
set_page_dirty(dentry_page);
|
set_page_dirty(dentry_page);
|
||||||
|
|
||||||
/* we don't need to mark_inode_dirty now */
|
/* we don't need to mark_inode_dirty now */
|
||||||
|
|
|
@ -1376,6 +1376,8 @@ ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
|
||||||
void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
|
void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
|
||||||
struct page *, struct inode *);
|
struct page *, struct inode *);
|
||||||
int update_dent_inode(struct inode *, const struct qstr *);
|
int update_dent_inode(struct inode *, const struct qstr *);
|
||||||
|
void f2fs_update_dentry(struct inode *, struct f2fs_dentry_ptr *,
|
||||||
|
const struct qstr *, f2fs_hash_t , unsigned int);
|
||||||
int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
|
int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
|
||||||
void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *,
|
void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *,
|
||||||
struct inode *);
|
struct inode *);
|
||||||
|
|
|
@ -386,15 +386,12 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *name,
|
||||||
struct page *ipage;
|
struct page *ipage;
|
||||||
unsigned int bit_pos;
|
unsigned int bit_pos;
|
||||||
f2fs_hash_t name_hash;
|
f2fs_hash_t name_hash;
|
||||||
struct f2fs_dir_entry *de;
|
|
||||||
size_t namelen = name->len;
|
size_t namelen = name->len;
|
||||||
struct f2fs_inline_dentry *dentry_blk = NULL;
|
struct f2fs_inline_dentry *dentry_blk = NULL;
|
||||||
|
struct f2fs_dentry_ptr d;
|
||||||
int slots = GET_DENTRY_SLOTS(namelen);
|
int slots = GET_DENTRY_SLOTS(namelen);
|
||||||
struct page *page;
|
struct page *page;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int i;
|
|
||||||
|
|
||||||
name_hash = f2fs_dentry_hash(name);
|
|
||||||
|
|
||||||
ipage = get_node_page(sbi, dir->i_ino);
|
ipage = get_node_page(sbi, dir->i_ino);
|
||||||
if (IS_ERR(ipage))
|
if (IS_ERR(ipage))
|
||||||
|
@ -418,14 +415,11 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *name,
|
||||||
}
|
}
|
||||||
|
|
||||||
f2fs_wait_on_page_writeback(ipage, NODE);
|
f2fs_wait_on_page_writeback(ipage, NODE);
|
||||||
de = &dentry_blk->dentry[bit_pos];
|
|
||||||
de->hash_code = name_hash;
|
name_hash = f2fs_dentry_hash(name);
|
||||||
de->name_len = cpu_to_le16(namelen);
|
make_dentry_ptr(&d, (void *)dentry_blk, 2);
|
||||||
memcpy(dentry_blk->filename[bit_pos], name->name, name->len);
|
f2fs_update_dentry(inode, &d, name, name_hash, bit_pos);
|
||||||
de->ino = cpu_to_le32(inode->i_ino);
|
|
||||||
set_de_type(de, inode);
|
|
||||||
for (i = 0; i < slots; i++)
|
|
||||||
test_and_set_bit_le(bit_pos + i, &dentry_blk->dentry_bitmap);
|
|
||||||
set_page_dirty(ipage);
|
set_page_dirty(ipage);
|
||||||
|
|
||||||
/* we don't need to mark_inode_dirty now */
|
/* we don't need to mark_inode_dirty now */
|
||||||
|
|
Loading…
Reference in a new issue