diff options
author | Jaegeuk Kim <jaegeuk.kim@samsung.com> | 2012-12-20 01:10:06 -0500 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk.kim@samsung.com> | 2012-12-27 21:24:09 -0500 |
commit | 71e9fec548a95b2a4cf378646addd5d3098684a2 (patch) | |
tree | 129aef9aacfb87ec29d67a8ca95422a82ab9db12 /fs | |
parent | 690e4a3ead5f88fc95f7650816d1376aa2e79db5 (diff) |
f2fs: invalidate the node page if allocation is failed
The new_node_page() is processed as the following procedure.
1. A new node page is allocated.
2. Set PageUptodate with proper footer information.
3. Check if there is a free space for allocation
4.a. If there is no space, f2fs returns with -ENOSPC.
4.b. Otherwise, go next.
In the case of step #4.a, f2fs remains a wrong node page in the page cache
with the uptodate flag.
Also, even though a new node page is allocated successfully, an error can be
occurred afterwards due to allocation failure of the other data structures.
In such a case, remove_inode_page() would be triggered, so that we have to
clear uptodate flag in truncate_node() too.
So, we should remove the uptodate flag, if allocation is failed.
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/f2fs/node.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index dffac1c11f63..e85643cc74a9 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c | |||
@@ -484,12 +484,14 @@ static void truncate_node(struct dnode_of_data *dn) | |||
484 | struct node_info ni; | 484 | struct node_info ni; |
485 | 485 | ||
486 | get_node_info(sbi, dn->nid, &ni); | 486 | get_node_info(sbi, dn->nid, &ni); |
487 | if (dn->inode->i_blocks == 0) { | ||
488 | BUG_ON(ni.blk_addr != NULL_ADDR); | ||
489 | goto invalidate; | ||
490 | } | ||
487 | BUG_ON(ni.blk_addr == NULL_ADDR); | 491 | BUG_ON(ni.blk_addr == NULL_ADDR); |
488 | 492 | ||
489 | if (ni.blk_addr != NULL_ADDR) | ||
490 | invalidate_blocks(sbi, ni.blk_addr); | ||
491 | |||
492 | /* Deallocate node address */ | 493 | /* Deallocate node address */ |
494 | invalidate_blocks(sbi, ni.blk_addr); | ||
493 | dec_valid_node_count(sbi, dn->inode, 1); | 495 | dec_valid_node_count(sbi, dn->inode, 1); |
494 | set_node_addr(sbi, &ni, NULL_ADDR); | 496 | set_node_addr(sbi, &ni, NULL_ADDR); |
495 | 497 | ||
@@ -499,7 +501,7 @@ static void truncate_node(struct dnode_of_data *dn) | |||
499 | } else { | 501 | } else { |
500 | sync_inode_page(dn); | 502 | sync_inode_page(dn); |
501 | } | 503 | } |
502 | 504 | invalidate: | |
503 | clear_node_page_dirty(dn->node_page); | 505 | clear_node_page_dirty(dn->node_page); |
504 | F2FS_SET_SB_DIRT(sbi); | 506 | F2FS_SET_SB_DIRT(sbi); |
505 | 507 | ||
@@ -768,20 +770,12 @@ int remove_inode_page(struct inode *inode) | |||
768 | dn.inode_page_locked = 1; | 770 | dn.inode_page_locked = 1; |
769 | truncate_node(&dn); | 771 | truncate_node(&dn); |
770 | } | 772 | } |
771 | if (inode->i_blocks == 1) { | ||
772 | /* inernally call f2fs_put_page() */ | ||
773 | set_new_dnode(&dn, inode, page, page, ino); | ||
774 | truncate_node(&dn); | ||
775 | } else if (inode->i_blocks == 0) { | ||
776 | struct node_info ni; | ||
777 | get_node_info(sbi, inode->i_ino, &ni); | ||
778 | 773 | ||
779 | /* called after f2fs_new_inode() is failed */ | 774 | /* 0 is possible, after f2fs_new_inode() is failed */ |
780 | BUG_ON(ni.blk_addr != NULL_ADDR); | 775 | BUG_ON(inode->i_blocks != 0 && inode->i_blocks != 1); |
781 | f2fs_put_page(page, 1); | 776 | set_new_dnode(&dn, inode, page, page, ino); |
782 | } else { | 777 | truncate_node(&dn); |
783 | BUG(); | 778 | |
784 | } | ||
785 | mutex_unlock_op(sbi, NODE_TRUNC); | 779 | mutex_unlock_op(sbi, NODE_TRUNC); |
786 | return 0; | 780 | return 0; |
787 | } | 781 | } |
@@ -845,6 +839,7 @@ struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs) | |||
845 | return page; | 839 | return page; |
846 | 840 | ||
847 | fail: | 841 | fail: |
842 | clear_node_page_dirty(page); | ||
848 | f2fs_put_page(page, 1); | 843 | f2fs_put_page(page, 1); |
849 | return ERR_PTR(err); | 844 | return ERR_PTR(err); |
850 | } | 845 | } |