f2fs: fix handling errors got by f2fs_write_inode

Ruslan reported that f2fs hangs with an infinite loop in f2fs_sync_file():

	while (sync_node_pages(sbi, inode->i_ino, &wbc) == 0)
		f2fs_write_inode(inode, NULL);

The reason was revealed that the cold flag is not set even thought this inode is
a normal file. Therefore, sync_node_pages() skips to write node blocks since it
only writes cold node blocks.

The cold flag is stored to the node_footer in node block, and whenever a new
node page is allocated, it is set according to its file type, file or directory.

But, after sudden-power-off, when recovering the inode page, f2fs doesn't recover
its cold flag.

So, let's assign the cold flag in more right places.

One more thing:
If f2fs_write_inode() returns an error due to whatever situations, there would
be no dirty node pages so that sync_node_pages() returns zero.
(i.e., zero means nothing was written.)

Reported-by: Ruslan N. Marchenko <me@ruff.mobi>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
This commit is contained in:
Jaegeuk Kim 2012-12-19 15:28:39 +09:00
parent 38e0abdcfb
commit 398b1ac5a5
4 changed files with 10 additions and 5 deletions

View File

@ -11,6 +11,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/f2fs_fs.h> #include <linux/f2fs_fs.h>
#include "f2fs.h" #include "f2fs.h"
#include "node.h"
#include "acl.h" #include "acl.h"
static unsigned long dir_blocks(struct inode *inode) static unsigned long dir_blocks(struct inode *inode)
@ -308,6 +309,7 @@ static int init_inode_metadata(struct inode *inode, struct dentry *dentry)
ipage = get_node_page(F2FS_SB(dir->i_sb), inode->i_ino); ipage = get_node_page(F2FS_SB(dir->i_sb), inode->i_ino);
if (IS_ERR(ipage)) if (IS_ERR(ipage))
return PTR_ERR(ipage); return PTR_ERR(ipage);
set_cold_node(inode, ipage);
init_dent_inode(dentry, ipage); init_dent_inode(dentry, ipage);
f2fs_put_page(ipage, 1); f2fs_put_page(ipage, 1);
} }

View File

@ -160,15 +160,17 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
if (need_to_sync_dir(sbi, inode)) if (need_to_sync_dir(sbi, inode))
need_cp = true; need_cp = true;
f2fs_write_inode(inode, NULL);
if (need_cp) { if (need_cp) {
/* all the dirty node pages should be flushed for POR */ /* all the dirty node pages should be flushed for POR */
ret = f2fs_sync_fs(inode->i_sb, 1); ret = f2fs_sync_fs(inode->i_sb, 1);
clear_inode_flag(F2FS_I(inode), FI_NEED_CP); clear_inode_flag(F2FS_I(inode), FI_NEED_CP);
} else { } else {
while (sync_node_pages(sbi, inode->i_ino, &wbc) == 0) /* if there is no written node page, write its inode page */
f2fs_write_inode(inode, NULL); while (!sync_node_pages(sbi, inode->i_ino, &wbc)) {
ret = f2fs_write_inode(inode, NULL);
if (ret)
goto out;
}
filemap_fdatawait_range(sbi->node_inode->i_mapping, filemap_fdatawait_range(sbi->node_inode->i_mapping,
0, LONG_MAX); 0, LONG_MAX);
} }

View File

@ -203,6 +203,7 @@ void update_inode(struct inode *inode, struct page *node_page)
ri->i_flags = cpu_to_le32(F2FS_I(inode)->i_flags); ri->i_flags = cpu_to_le32(F2FS_I(inode)->i_flags);
ri->i_pino = cpu_to_le32(F2FS_I(inode)->i_pino); ri->i_pino = cpu_to_le32(F2FS_I(inode)->i_pino);
ri->i_generation = cpu_to_le32(inode->i_generation); ri->i_generation = cpu_to_le32(inode->i_generation);
set_cold_node(inode, node_page);
set_page_dirty(node_page); set_page_dirty(node_page);
} }

View File

@ -834,11 +834,11 @@ struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs)
goto fail; goto fail;
} }
set_node_addr(sbi, &new_ni, NEW_ADDR); set_node_addr(sbi, &new_ni, NEW_ADDR);
set_cold_node(dn->inode, page);
dn->node_page = page; dn->node_page = page;
sync_inode_page(dn); sync_inode_page(dn);
set_page_dirty(page); set_page_dirty(page);
set_cold_node(dn->inode, page);
if (ofs == 0) if (ofs == 0)
inc_valid_inode_count(sbi); inc_valid_inode_count(sbi);