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.c80
1 files changed, 37 insertions, 43 deletions
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index d3d90d284631..45378196e19a 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -237,7 +237,7 @@ retry:
237 nat_get_blkaddr(e) != NULL_ADDR && 237 nat_get_blkaddr(e) != NULL_ADDR &&
238 new_blkaddr == NEW_ADDR); 238 new_blkaddr == NEW_ADDR);
239 239
240 /* increament version no as node is removed */ 240 /* increment version no as node is removed */
241 if (nat_get_blkaddr(e) != NEW_ADDR && new_blkaddr == NULL_ADDR) { 241 if (nat_get_blkaddr(e) != NEW_ADDR && new_blkaddr == NULL_ADDR) {
242 unsigned char version = nat_get_version(e); 242 unsigned char version = nat_get_version(e);
243 nat_set_version(e, inc_node_version(version)); 243 nat_set_version(e, inc_node_version(version));
@@ -274,7 +274,7 @@ int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink)
274} 274}
275 275
276/* 276/*
277 * This function returns always success 277 * This function always returns success
278 */ 278 */
279void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni) 279void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni)
280{ 280{
@@ -650,7 +650,7 @@ static int truncate_partial_nodes(struct dnode_of_data *dn,
650 650
651 /* get indirect nodes in the path */ 651 /* get indirect nodes in the path */
652 for (i = 0; i < idx + 1; i++) { 652 for (i = 0; i < idx + 1; i++) {
653 /* refernece count'll be increased */ 653 /* reference count'll be increased */
654 pages[i] = get_node_page(sbi, nid[i]); 654 pages[i] = get_node_page(sbi, nid[i]);
655 if (IS_ERR(pages[i])) { 655 if (IS_ERR(pages[i])) {
656 err = PTR_ERR(pages[i]); 656 err = PTR_ERR(pages[i]);
@@ -823,22 +823,26 @@ int truncate_xattr_node(struct inode *inode, struct page *page)
823 */ 823 */
824void remove_inode_page(struct inode *inode) 824void remove_inode_page(struct inode *inode)
825{ 825{
826 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
827 struct page *page;
828 nid_t ino = inode->i_ino;
829 struct dnode_of_data dn; 826 struct dnode_of_data dn;
830 827
831 page = get_node_page(sbi, ino); 828 set_new_dnode(&dn, inode, NULL, NULL, inode->i_ino);
832 if (IS_ERR(page)) 829 if (get_dnode_of_data(&dn, 0, LOOKUP_NODE))
833 return; 830 return;
834 831
835 if (truncate_xattr_node(inode, page)) { 832 if (truncate_xattr_node(inode, dn.inode_page)) {
836 f2fs_put_page(page, 1); 833 f2fs_put_dnode(&dn);
837 return; 834 return;
838 } 835 }
839 /* 0 is possible, after f2fs_new_inode() is failed */ 836
837 /* remove potential inline_data blocks */
838 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
839 S_ISLNK(inode->i_mode))
840 truncate_data_blocks_range(&dn, 1);
841
842 /* 0 is possible, after f2fs_new_inode() has failed */
840 f2fs_bug_on(inode->i_blocks != 0 && inode->i_blocks != 1); 843 f2fs_bug_on(inode->i_blocks != 0 && inode->i_blocks != 1);
841 set_new_dnode(&dn, inode, page, page, ino); 844
845 /* will put inode & node pages */
842 truncate_node(&dn); 846 truncate_node(&dn);
843} 847}
844 848
@@ -1129,8 +1133,11 @@ continue_unlock:
1129 set_fsync_mark(page, 0); 1133 set_fsync_mark(page, 0);
1130 set_dentry_mark(page, 0); 1134 set_dentry_mark(page, 0);
1131 } 1135 }
1132 NODE_MAPPING(sbi)->a_ops->writepage(page, wbc); 1136
1133 wrote++; 1137 if (NODE_MAPPING(sbi)->a_ops->writepage(page, wbc))
1138 unlock_page(page);
1139 else
1140 wrote++;
1134 1141
1135 if (--wbc->nr_to_write == 0) 1142 if (--wbc->nr_to_write == 0)
1136 break; 1143 break;
@@ -1212,6 +1219,8 @@ static int f2fs_write_node_page(struct page *page,
1212 1219
1213 if (unlikely(sbi->por_doing)) 1220 if (unlikely(sbi->por_doing))
1214 goto redirty_out; 1221 goto redirty_out;
1222 if (unlikely(f2fs_cp_error(sbi)))
1223 goto redirty_out;
1215 1224
1216 f2fs_wait_on_page_writeback(page, NODE); 1225 f2fs_wait_on_page_writeback(page, NODE);
1217 1226
@@ -1540,15 +1549,6 @@ void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid)
1540 kmem_cache_free(free_nid_slab, i); 1549 kmem_cache_free(free_nid_slab, i);
1541} 1550}
1542 1551
1543void recover_node_page(struct f2fs_sb_info *sbi, struct page *page,
1544 struct f2fs_summary *sum, struct node_info *ni,
1545 block_t new_blkaddr)
1546{
1547 rewrite_node_page(sbi, page, sum, ni->blk_addr, new_blkaddr);
1548 set_node_addr(sbi, ni, new_blkaddr, false);
1549 clear_node_page_dirty(page);
1550}
1551
1552void recover_inline_xattr(struct inode *inode, struct page *page) 1552void recover_inline_xattr(struct inode *inode, struct page *page)
1553{ 1553{
1554 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); 1554 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
@@ -1557,40 +1557,33 @@ void recover_inline_xattr(struct inode *inode, struct page *page)
1557 struct page *ipage; 1557 struct page *ipage;
1558 struct f2fs_inode *ri; 1558 struct f2fs_inode *ri;
1559 1559
1560 if (!f2fs_has_inline_xattr(inode))
1561 return;
1562
1563 if (!IS_INODE(page))
1564 return;
1565
1566 ri = F2FS_INODE(page);
1567 if (!(ri->i_inline & F2FS_INLINE_XATTR))
1568 return;
1569
1570 ipage = get_node_page(sbi, inode->i_ino); 1560 ipage = get_node_page(sbi, inode->i_ino);
1571 f2fs_bug_on(IS_ERR(ipage)); 1561 f2fs_bug_on(IS_ERR(ipage));
1572 1562
1563 ri = F2FS_INODE(page);
1564 if (!(ri->i_inline & F2FS_INLINE_XATTR)) {
1565 clear_inode_flag(F2FS_I(inode), FI_INLINE_XATTR);
1566 goto update_inode;
1567 }
1568
1573 dst_addr = inline_xattr_addr(ipage); 1569 dst_addr = inline_xattr_addr(ipage);
1574 src_addr = inline_xattr_addr(page); 1570 src_addr = inline_xattr_addr(page);
1575 inline_size = inline_xattr_size(inode); 1571 inline_size = inline_xattr_size(inode);
1576 1572
1577 f2fs_wait_on_page_writeback(ipage, NODE); 1573 f2fs_wait_on_page_writeback(ipage, NODE);
1578 memcpy(dst_addr, src_addr, inline_size); 1574 memcpy(dst_addr, src_addr, inline_size);
1579 1575update_inode:
1580 update_inode(inode, ipage); 1576 update_inode(inode, ipage);
1581 f2fs_put_page(ipage, 1); 1577 f2fs_put_page(ipage, 1);
1582} 1578}
1583 1579
1584bool recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr) 1580void recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr)
1585{ 1581{
1586 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); 1582 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
1587 nid_t prev_xnid = F2FS_I(inode)->i_xattr_nid; 1583 nid_t prev_xnid = F2FS_I(inode)->i_xattr_nid;
1588 nid_t new_xnid = nid_of_node(page); 1584 nid_t new_xnid = nid_of_node(page);
1589 struct node_info ni; 1585 struct node_info ni;
1590 1586
1591 if (!f2fs_has_xattr_block(ofs_of_node(page)))
1592 return false;
1593
1594 /* 1: invalidate the previous xattr nid */ 1587 /* 1: invalidate the previous xattr nid */
1595 if (!prev_xnid) 1588 if (!prev_xnid)
1596 goto recover_xnid; 1589 goto recover_xnid;
@@ -1618,7 +1611,6 @@ recover_xnid:
1618 set_node_addr(sbi, &ni, blkaddr, false); 1611 set_node_addr(sbi, &ni, blkaddr, false);
1619 1612
1620 update_inode_page(inode); 1613 update_inode_page(inode);
1621 return true;
1622} 1614}
1623 1615
1624int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page) 1616int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page)
@@ -1637,7 +1629,7 @@ int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page)
1637 if (!ipage) 1629 if (!ipage)
1638 return -ENOMEM; 1630 return -ENOMEM;
1639 1631
1640 /* Should not use this inode from free nid list */ 1632 /* Should not use this inode from free nid list */
1641 remove_free_nid(NM_I(sbi), ino); 1633 remove_free_nid(NM_I(sbi), ino);
1642 1634
1643 SetPageUptodate(ipage); 1635 SetPageUptodate(ipage);
@@ -1651,6 +1643,7 @@ int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page)
1651 dst->i_blocks = cpu_to_le64(1); 1643 dst->i_blocks = cpu_to_le64(1);
1652 dst->i_links = cpu_to_le32(1); 1644 dst->i_links = cpu_to_le32(1);
1653 dst->i_xattr_nid = 0; 1645 dst->i_xattr_nid = 0;
1646 dst->i_inline = src->i_inline & F2FS_INLINE_XATTR;
1654 1647
1655 new_ni = old_ni; 1648 new_ni = old_ni;
1656 new_ni.ino = ino; 1649 new_ni.ino = ino;
@@ -1659,13 +1652,14 @@ int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page)
1659 WARN_ON(1); 1652 WARN_ON(1);
1660 set_node_addr(sbi, &new_ni, NEW_ADDR, false); 1653 set_node_addr(sbi, &new_ni, NEW_ADDR, false);
1661 inc_valid_inode_count(sbi); 1654 inc_valid_inode_count(sbi);
1655 set_page_dirty(ipage);
1662 f2fs_put_page(ipage, 1); 1656 f2fs_put_page(ipage, 1);
1663 return 0; 1657 return 0;
1664} 1658}
1665 1659
1666/* 1660/*
1667 * ra_sum_pages() merge contiguous pages into one bio and submit. 1661 * ra_sum_pages() merge contiguous pages into one bio and submit.
1668 * these pre-readed pages are alloced in bd_inode's mapping tree. 1662 * these pre-read pages are allocated in bd_inode's mapping tree.
1669 */ 1663 */
1670static int ra_sum_pages(struct f2fs_sb_info *sbi, struct page **pages, 1664static int ra_sum_pages(struct f2fs_sb_info *sbi, struct page **pages,
1671 int start, int nrpages) 1665 int start, int nrpages)
@@ -1709,7 +1703,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi,
1709 for (i = 0; !err && i < last_offset; i += nrpages, addr += nrpages) { 1703 for (i = 0; !err && i < last_offset; i += nrpages, addr += nrpages) {
1710 nrpages = min(last_offset - i, bio_blocks); 1704 nrpages = min(last_offset - i, bio_blocks);
1711 1705
1712 /* read ahead node pages */ 1706 /* readahead node pages */
1713 nrpages = ra_sum_pages(sbi, pages, addr, nrpages); 1707 nrpages = ra_sum_pages(sbi, pages, addr, nrpages);
1714 if (!nrpages) 1708 if (!nrpages)
1715 return -ENOMEM; 1709 return -ENOMEM;
@@ -1967,7 +1961,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi)
1967 nm_i->max_nid = NAT_ENTRY_PER_BLOCK * nat_blocks; 1961 nm_i->max_nid = NAT_ENTRY_PER_BLOCK * nat_blocks;
1968 1962
1969 /* not used nids: 0, node, meta, (and root counted as valid node) */ 1963 /* not used nids: 0, node, meta, (and root counted as valid node) */
1970 nm_i->available_nids = nm_i->max_nid - 3; 1964 nm_i->available_nids = nm_i->max_nid - F2FS_RESERVED_NODE_NUM;
1971 nm_i->fcnt = 0; 1965 nm_i->fcnt = 0;
1972 nm_i->nat_cnt = 0; 1966 nm_i->nat_cnt = 0;
1973 nm_i->ram_thresh = DEF_RAM_THRESHOLD; 1967 nm_i->ram_thresh = DEF_RAM_THRESHOLD;