aboutsummaryrefslogtreecommitdiffstats
path: root/fs/f2fs/node.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/f2fs/node.c')
-rw-r--r--fs/f2fs/node.c37
1 files changed, 14 insertions, 23 deletions
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 19870361497e..5066bfd256c9 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 504invalidate:
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}
@@ -834,17 +828,18 @@ struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs)
834 goto fail; 828 goto fail;
835 } 829 }
836 set_node_addr(sbi, &new_ni, NEW_ADDR); 830 set_node_addr(sbi, &new_ni, NEW_ADDR);
831 set_cold_node(dn->inode, page);
837 832
838 dn->node_page = page; 833 dn->node_page = page;
839 sync_inode_page(dn); 834 sync_inode_page(dn);
840 set_page_dirty(page); 835 set_page_dirty(page);
841 set_cold_node(dn->inode, page);
842 if (ofs == 0) 836 if (ofs == 0)
843 inc_valid_inode_count(sbi); 837 inc_valid_inode_count(sbi);
844 838
845 return page; 839 return page;
846 840
847fail: 841fail:
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}
@@ -1093,7 +1088,6 @@ static int f2fs_write_node_page(struct page *page,
1093{ 1088{
1094 struct f2fs_sb_info *sbi = F2FS_SB(page->mapping->host->i_sb); 1089 struct f2fs_sb_info *sbi = F2FS_SB(page->mapping->host->i_sb);
1095 nid_t nid; 1090 nid_t nid;
1096 unsigned int nofs;
1097 block_t new_addr; 1091 block_t new_addr;
1098 struct node_info ni; 1092 struct node_info ni;
1099 1093
@@ -1110,7 +1104,6 @@ static int f2fs_write_node_page(struct page *page,
1110 1104
1111 /* get old block addr of this node page */ 1105 /* get old block addr of this node page */
1112 nid = nid_of_node(page); 1106 nid = nid_of_node(page);
1113 nofs = ofs_of_node(page);
1114 BUG_ON(page->index != nid); 1107 BUG_ON(page->index != nid);
1115 1108
1116 get_node_info(sbi, nid, &ni); 1109 get_node_info(sbi, nid, &ni);
@@ -1571,7 +1564,7 @@ void flush_nat_entries(struct f2fs_sb_info *sbi)
1571 nid_t nid; 1564 nid_t nid;
1572 struct f2fs_nat_entry raw_ne; 1565 struct f2fs_nat_entry raw_ne;
1573 int offset = -1; 1566 int offset = -1;
1574 block_t old_blkaddr, new_blkaddr; 1567 block_t new_blkaddr;
1575 1568
1576 ne = list_entry(cur, struct nat_entry, list); 1569 ne = list_entry(cur, struct nat_entry, list);
1577 nid = nat_get_nid(ne); 1570 nid = nat_get_nid(ne);
@@ -1585,7 +1578,6 @@ void flush_nat_entries(struct f2fs_sb_info *sbi)
1585 offset = lookup_journal_in_cursum(sum, NAT_JOURNAL, nid, 1); 1578 offset = lookup_journal_in_cursum(sum, NAT_JOURNAL, nid, 1);
1586 if (offset >= 0) { 1579 if (offset >= 0) {
1587 raw_ne = nat_in_journal(sum, offset); 1580 raw_ne = nat_in_journal(sum, offset);
1588 old_blkaddr = le32_to_cpu(raw_ne.block_addr);
1589 goto flush_now; 1581 goto flush_now;
1590 } 1582 }
1591to_nat_page: 1583to_nat_page:
@@ -1607,7 +1599,6 @@ to_nat_page:
1607 1599
1608 BUG_ON(!nat_blk); 1600 BUG_ON(!nat_blk);
1609 raw_ne = nat_blk->entries[nid - start_nid]; 1601 raw_ne = nat_blk->entries[nid - start_nid];
1610 old_blkaddr = le32_to_cpu(raw_ne.block_addr);
1611flush_now: 1602flush_now:
1612 new_blkaddr = nat_get_blkaddr(ne); 1603 new_blkaddr = nat_get_blkaddr(ne);
1613 1604