Commit 622f28ae authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: enable inline dir handling

Add inline dir functions into normal dir ops' function to handle inline ops.
Besides, we enable inline dir mode when a new dir inode is created if
inline_data option is on.
Signed-off-by: default avatarChao Yu <chao2.yu@samsung.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 201a05be
......@@ -201,6 +201,9 @@ struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
unsigned int max_depth;
unsigned int level;
if (f2fs_has_inline_dentry(dir))
return find_in_inline_dir(dir, child, res_page);
if (npages == 0)
return NULL;
......@@ -227,6 +230,9 @@ struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p)
struct f2fs_dir_entry *de;
struct f2fs_dentry_block *dentry_blk;
if (f2fs_has_inline_dentry(dir))
return f2fs_parent_inline_dir(dir, p);
page = get_lock_data_page(dir, 0);
if (IS_ERR(page))
return NULL;
......@@ -247,7 +253,8 @@ ino_t f2fs_inode_by_name(struct inode *dir, struct qstr *qstr)
de = f2fs_find_entry(dir, qstr, &page);
if (de) {
res = le32_to_cpu(de->ino);
kunmap(page);
if (!f2fs_has_inline_dentry(dir))
kunmap(page);
f2fs_put_page(page, 0);
}
......@@ -261,7 +268,8 @@ void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
f2fs_wait_on_page_writeback(page, DATA);
de->ino = cpu_to_le32(inode->i_ino);
set_de_type(de, inode);
kunmap(page);
if (!f2fs_has_inline_dentry(dir))
kunmap(page);
set_page_dirty(page);
dir->i_mtime = dir->i_ctime = CURRENT_TIME;
mark_inode_dirty(dir);
......@@ -303,6 +311,9 @@ static int make_empty_dir(struct inode *inode,
struct f2fs_dentry_block *dentry_blk;
struct f2fs_dir_entry *de;
if (f2fs_has_inline_dentry(inode))
return make_empty_inline_dir(inode, parent, page);
dentry_page = get_new_data_page(inode, page, 0, true);
if (IS_ERR(dentry_page))
return PTR_ERR(dentry_page);
......@@ -462,6 +473,14 @@ int __f2fs_add_link(struct inode *dir, const struct qstr *name,
int err = 0;
int i;
if (f2fs_has_inline_dentry(dir)) {
err = f2fs_add_inline_entry(dir, name, inode);
if (!err || err != -EAGAIN)
return err;
else
err = 0;
}
dentry_hash = f2fs_dentry_hash(name);
level = 0;
current_depth = F2FS_I(dir)->i_current_depth;
......@@ -600,6 +619,9 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
int slots = GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len));
int i;
if (f2fs_has_inline_dentry(dir))
return f2fs_delete_inline_entry(dentry, page, dir, inode);
lock_page(page);
f2fs_wait_on_page_writeback(page, DATA);
......@@ -637,6 +659,9 @@ bool f2fs_empty_dir(struct inode *dir)
struct f2fs_dentry_block *dentry_blk;
unsigned long nblock = dir_blocks(dir);
if (f2fs_has_inline_dentry(dir))
return f2fs_empty_inline_dir(dir);
for (bidx = 0; bidx < nblock; bidx++) {
dentry_page = get_lock_data_page(dir, bidx);
if (IS_ERR(dentry_page)) {
......@@ -676,6 +701,9 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
unsigned int n = ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK);
unsigned char d_type = DT_UNKNOWN;
if (f2fs_has_inline_dentry(inode))
return f2fs_read_inline_dir(file, ctx);
bit_pos = ((unsigned long)ctx->pos % NR_DENTRY_IN_BLOCK);
/* readahead for multi pages of dir */
......
......@@ -314,7 +314,7 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence)
goto fail;
/* handle inline data case */
if (f2fs_has_inline_data(inode)) {
if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode)) {
if (whence == SEEK_HOLE)
data_ofs = isize;
goto found;
......
......@@ -424,7 +424,7 @@ int f2fs_convert_inline_dir(struct inode *dir, struct page *ipage,
/* clear inline dir and flag after data writeback */
zero_user_segment(ipage, INLINE_DATA_OFFSET,
INLINE_DATA_OFFSET + MAX_INLINE_DATA);
clear_inode_flag(F2FS_I(dir), FI_INLINE_DENTRY);
stat_dec_inline_inode(dir);
if (i_size_read(dir) < PAGE_CACHE_SIZE) {
......
......@@ -54,6 +54,10 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
nid_free = true;
goto out;
}
if (test_opt(sbi, INLINE_DENTRY) && S_ISDIR(inode->i_mode))
set_inode_flag(F2FS_I(inode), FI_INLINE_DENTRY);
trace_f2fs_new_inode(inode, 0);
mark_inode_dirty(inode);
return inode;
......@@ -187,7 +191,8 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
de = f2fs_find_entry(dir, &dentry->d_name, &page);
if (de) {
nid_t ino = le32_to_cpu(de->ino);
kunmap(page);
if (!f2fs_has_inline_dentry(dir))
kunmap(page);
f2fs_put_page(page, 0);
inode = f2fs_iget(dir->i_sb, ino);
......@@ -219,7 +224,8 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
err = acquire_orphan_inode(sbi);
if (err) {
f2fs_unlock_op(sbi);
kunmap(page);
if (!f2fs_has_inline_dentry(dir))
kunmap(page);
f2fs_put_page(page, 0);
goto fail;
}
......@@ -443,7 +449,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
old_dir_page, new_dir);
update_inode_page(old_inode);
} else {
kunmap(old_dir_page);
if (!f2fs_has_inline_dentry(old_inode))
kunmap(old_dir_page);
f2fs_put_page(old_dir_page, 0);
}
drop_nlink(old_dir);
......@@ -456,15 +463,18 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
put_out_dir:
f2fs_unlock_op(sbi);
kunmap(new_page);
if (!f2fs_has_inline_dentry(new_dir))
kunmap(new_page);
f2fs_put_page(new_page, 0);
out_dir:
if (old_dir_entry) {
kunmap(old_dir_page);
if (!f2fs_has_inline_dentry(old_inode))
kunmap(old_dir_page);
f2fs_put_page(old_dir_page, 0);
}
out_old:
kunmap(old_page);
if (!f2fs_has_inline_dentry(old_dir))
kunmap(old_page);
f2fs_put_page(old_page, 0);
out:
return err;
......@@ -596,19 +606,23 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
f2fs_unlock_op(sbi);
out_new_dir:
if (new_dir_entry) {
kunmap(new_dir_page);
if (!f2fs_has_inline_dentry(new_inode))
kunmap(new_dir_page);
f2fs_put_page(new_dir_page, 0);
}
out_old_dir:
if (old_dir_entry) {
kunmap(old_dir_page);
if (!f2fs_has_inline_dentry(old_inode))
kunmap(old_dir_page);
f2fs_put_page(old_dir_page, 0);
}
out_new:
kunmap(new_page);
if (!f2fs_has_inline_dentry(new_dir))
kunmap(new_page);
f2fs_put_page(new_page, 0);
out_old:
kunmap(old_page);
if (!f2fs_has_inline_dentry(old_dir))
kunmap(old_page);
f2fs_put_page(old_page, 0);
out:
return err;
......
......@@ -129,7 +129,8 @@ static int recover_dentry(struct inode *inode, struct page *ipage)
goto out;
out_unmap_put:
kunmap(page);
if (!f2fs_has_inline_dentry(dir))
kunmap(page);
f2fs_put_page(page, 0);
out_err:
iput(dir);
......
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