f2fs: revisit inline_data to avoid data races and potential bugs
This patch simplifies the inline_data usage with the following rule. 1. inline_data is set during the file creation. 2. If new data is requested to be written ranges out of inline_data, f2fs converts that inode permanently. 3. There is no cases which converts non-inline_data inode to inline_data. 4. The inline_data flag should be changed under inode page lock. Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
@@ -67,12 +67,38 @@ static void __set_inode_rdev(struct inode *inode, struct f2fs_inode *ri)
|
||||
}
|
||||
}
|
||||
|
||||
static int __recover_inline_status(struct inode *inode, struct page *ipage)
|
||||
{
|
||||
void *inline_data = inline_data_addr(ipage);
|
||||
struct f2fs_inode *ri;
|
||||
void *zbuf;
|
||||
|
||||
zbuf = kzalloc(MAX_INLINE_DATA, GFP_NOFS);
|
||||
if (!zbuf)
|
||||
return -ENOMEM;
|
||||
|
||||
if (!memcmp(zbuf, inline_data, MAX_INLINE_DATA)) {
|
||||
kfree(zbuf);
|
||||
return 0;
|
||||
}
|
||||
kfree(zbuf);
|
||||
|
||||
f2fs_wait_on_page_writeback(ipage, NODE);
|
||||
set_inode_flag(F2FS_I(inode), FI_DATA_EXIST);
|
||||
|
||||
ri = F2FS_INODE(ipage);
|
||||
set_raw_inline(F2FS_I(inode), ri);
|
||||
set_page_dirty(ipage);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_read_inode(struct inode *inode)
|
||||
{
|
||||
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
|
||||
struct f2fs_inode_info *fi = F2FS_I(inode);
|
||||
struct page *node_page;
|
||||
struct f2fs_inode *ri;
|
||||
int err = 0;
|
||||
|
||||
/* Check if ino is within scope */
|
||||
if (check_nid_range(sbi, inode->i_ino)) {
|
||||
@@ -114,11 +140,15 @@ static int do_read_inode(struct inode *inode)
|
||||
get_extent_info(&fi->ext, ri->i_ext);
|
||||
get_inline_info(fi, ri);
|
||||
|
||||
/* check data exist */
|
||||
if (f2fs_has_inline_data(inode) && !f2fs_exist_data(inode))
|
||||
err = __recover_inline_status(inode, node_page);
|
||||
|
||||
/* get rdev by using inline_info */
|
||||
__get_inode_rdev(inode, ri);
|
||||
|
||||
f2fs_put_page(node_page, 1);
|
||||
return 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
|
||||
@@ -329,6 +359,7 @@ void handle_failed_inode(struct inode *inode)
|
||||
|
||||
remove_inode_page(inode);
|
||||
|
||||
clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
|
||||
clear_inode_flag(F2FS_I(inode), FI_INLINE_DENTRY);
|
||||
alloc_nid_failed(sbi, inode->i_ino);
|
||||
f2fs_unlock_op(sbi);
|
||||
|
Reference in New Issue
Block a user