Lines Matching full:sbi
33 int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) in f2fs_check_nid_range() argument
35 if (unlikely(nid < F2FS_ROOT_INO(sbi) || nid >= NM_I(sbi)->max_nid)) { in f2fs_check_nid_range()
36 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_check_nid_range()
37 f2fs_warn(sbi, "%s: out-of-range nid=%x, run fsck to fix.", in f2fs_check_nid_range()
39 f2fs_handle_error(sbi, ERROR_CORRUPTED_INODE); in f2fs_check_nid_range()
45 bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type) in f2fs_available_free_memory() argument
47 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_available_free_memory()
48 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; in f2fs_available_free_memory()
73 if (excess_cached_nats(sbi)) in f2fs_available_free_memory()
76 if (sbi->sb->s_bdi->wb.dirty_exceeded) in f2fs_available_free_memory()
78 mem_size = get_pages(sbi, F2FS_DIRTY_DENTS); in f2fs_available_free_memory()
84 mem_size += sbi->im[i].ino_num * in f2fs_available_free_memory()
91 struct extent_tree_info *eti = &sbi->extent_tree[etype]; in f2fs_available_free_memory()
110 res = (free_ram > avail_ram * sbi->compress_watermark / 100) && in f2fs_available_free_memory()
111 (COMPRESS_MAPPING(sbi)->nrpages < in f2fs_available_free_memory()
112 free_ram * sbi->compress_percent / 100); in f2fs_available_free_memory()
117 if (!sbi->sb->s_bdi->wb.dirty_exceeded) in f2fs_available_free_memory()
133 static struct page *get_current_nat_page(struct f2fs_sb_info *sbi, nid_t nid) in get_current_nat_page() argument
135 return f2fs_get_meta_page_retry(sbi, current_nat_addr(sbi, nid)); in get_current_nat_page()
138 static struct page *get_next_nat_page(struct f2fs_sb_info *sbi, nid_t nid) in get_next_nat_page() argument
145 struct f2fs_nm_info *nm_i = NM_I(sbi); in get_next_nat_page()
147 dst_off = next_nat_addr(sbi, current_nat_addr(sbi, nid)); in get_next_nat_page()
150 src_page = get_current_nat_page(sbi, nid); in get_next_nat_page()
153 dst_page = f2fs_grab_meta_page(sbi, dst_off); in get_next_nat_page()
154 f2fs_bug_on(sbi, PageDirty(src_page)); in get_next_nat_page()
167 static struct nat_entry *__alloc_nat_entry(struct f2fs_sb_info *sbi, in __alloc_nat_entry() argument
173 GFP_F2FS_ZERO, no_fail, sbi); in __alloc_nat_entry()
313 bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page) in f2fs_in_warm_node_list() argument
315 return NODE_MAPPING(sbi) == page->mapping && in f2fs_in_warm_node_list()
319 void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi) in f2fs_init_fsync_node_info() argument
321 spin_lock_init(&sbi->fsync_node_lock); in f2fs_init_fsync_node_info()
322 INIT_LIST_HEAD(&sbi->fsync_node_list); in f2fs_init_fsync_node_info()
323 sbi->fsync_seg_id = 0; in f2fs_init_fsync_node_info()
324 sbi->fsync_node_num = 0; in f2fs_init_fsync_node_info()
327 static unsigned int f2fs_add_fsync_node_entry(struct f2fs_sb_info *sbi, in f2fs_add_fsync_node_entry() argument
341 spin_lock_irqsave(&sbi->fsync_node_lock, flags); in f2fs_add_fsync_node_entry()
342 list_add_tail(&fn->list, &sbi->fsync_node_list); in f2fs_add_fsync_node_entry()
343 fn->seq_id = sbi->fsync_seg_id++; in f2fs_add_fsync_node_entry()
345 sbi->fsync_node_num++; in f2fs_add_fsync_node_entry()
346 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); in f2fs_add_fsync_node_entry()
351 void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page) in f2fs_del_fsync_node_entry() argument
356 spin_lock_irqsave(&sbi->fsync_node_lock, flags); in f2fs_del_fsync_node_entry()
357 list_for_each_entry(fn, &sbi->fsync_node_list, list) { in f2fs_del_fsync_node_entry()
360 sbi->fsync_node_num--; in f2fs_del_fsync_node_entry()
361 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); in f2fs_del_fsync_node_entry()
367 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); in f2fs_del_fsync_node_entry()
368 f2fs_bug_on(sbi, 1); in f2fs_del_fsync_node_entry()
371 void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi) in f2fs_reset_fsync_node_info() argument
375 spin_lock_irqsave(&sbi->fsync_node_lock, flags); in f2fs_reset_fsync_node_info()
376 sbi->fsync_seg_id = 0; in f2fs_reset_fsync_node_info()
377 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); in f2fs_reset_fsync_node_info()
380 int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid) in f2fs_need_dentry_mark() argument
382 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_need_dentry_mark()
397 bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid) in f2fs_is_checkpointed_node() argument
399 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_is_checkpointed_node()
411 bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino) in f2fs_need_inode_block_update() argument
413 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_need_inode_block_update()
428 static void cache_nat_entry(struct f2fs_sb_info *sbi, nid_t nid, in cache_nat_entry() argument
431 struct f2fs_nm_info *nm_i = NM_I(sbi); in cache_nat_entry()
435 if (f2fs_rwsem_is_locked(&sbi->cp_global_sem)) in cache_nat_entry()
438 new = __alloc_nat_entry(sbi, nid, false); in cache_nat_entry()
447 f2fs_bug_on(sbi, nat_get_ino(e) != le32_to_cpu(ne->ino) || in cache_nat_entry()
456 static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni, in set_node_addr() argument
459 struct f2fs_nm_info *nm_i = NM_I(sbi); in set_node_addr()
461 struct nat_entry *new = __alloc_nat_entry(sbi, ni->nid, true); in set_node_addr()
468 f2fs_bug_on(sbi, ni->blk_addr == NEW_ADDR); in set_node_addr()
476 f2fs_bug_on(sbi, ni->blk_addr != NULL_ADDR); in set_node_addr()
483 f2fs_bug_on(sbi, nat_get_blkaddr(e) != ni->blk_addr); in set_node_addr()
484 f2fs_bug_on(sbi, nat_get_blkaddr(e) == NULL_ADDR && in set_node_addr()
486 f2fs_bug_on(sbi, nat_get_blkaddr(e) == NEW_ADDR && in set_node_addr()
488 f2fs_bug_on(sbi, __is_valid_data_blkaddr(nat_get_blkaddr(e)) && in set_node_addr()
515 int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink) in f2fs_try_to_free_nats() argument
517 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_try_to_free_nats()
546 int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, in f2fs_get_node_info() argument
549 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_get_node_info()
550 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); in f2fs_get_node_info()
580 if (!f2fs_rwsem_is_locked(&sbi->cp_global_sem) || checkpoint_context) { in f2fs_get_node_info()
600 index = current_nat_addr(sbi, nid); in f2fs_get_node_info()
603 page = f2fs_get_meta_page(sbi, index); in f2fs_get_node_info()
614 !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE)) in f2fs_get_node_info()
618 cache_nat_entry(sbi, nid, &ne); in f2fs_get_node_info()
627 struct f2fs_sb_info *sbi = F2FS_P_SB(parent); in f2fs_ra_node_pages() local
639 f2fs_ra_node_page(sbi, nid); in f2fs_ra_node_pages()
763 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); in f2fs_get_dnode_of_data() local
780 npage[0] = f2fs_get_node_page(sbi, nids[0]); in f2fs_get_dnode_of_data()
804 if (!f2fs_alloc_nid(sbi, &(nids[i]))) { in f2fs_get_dnode_of_data()
812 f2fs_alloc_nid_failed(sbi, nids[i]); in f2fs_get_dnode_of_data()
818 f2fs_alloc_nid_done(sbi, nids[i]); in f2fs_get_dnode_of_data()
836 npage[i] = f2fs_get_node_page(sbi, nids[i]); in f2fs_get_dnode_of_data()
854 f2fs_sb_has_readonly(sbi)) { in f2fs_get_dnode_of_data()
899 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); in truncate_node() local
904 err = f2fs_get_node_info(sbi, dn->nid, &ni, false); in truncate_node()
909 !f2fs_is_valid_blkaddr(sbi, ni.blk_addr, DATA_GENERIC_ENHANCE)) { in truncate_node()
910 f2fs_err_ratelimited(sbi, in truncate_node()
913 set_sbi_flag(sbi, SBI_NEED_FSCK); in truncate_node()
914 f2fs_handle_error(sbi, ERROR_INCONSISTENT_NAT); in truncate_node()
919 f2fs_invalidate_blocks(sbi, ni.blk_addr); in truncate_node()
920 dec_valid_node_count(sbi, dn->inode, dn->nid == dn->inode->i_ino); in truncate_node()
921 set_node_addr(sbi, &ni, NULL_ADDR, false); in truncate_node()
924 f2fs_remove_orphan_inode(sbi, dn->nid); in truncate_node()
925 dec_valid_inode_count(sbi); in truncate_node()
930 set_sbi_flag(sbi, SBI_IS_DIRTY); in truncate_node()
935 invalidate_mapping_pages(NODE_MAPPING(sbi), in truncate_node()
946 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); in truncate_dnode() local
954 page = f2fs_get_node_page(sbi, dn->nid); in truncate_dnode()
961 f2fs_err(sbi, "incorrect node reference, ino: %lu, nid: %u, ino_of_node: %u", in truncate_dnode()
963 set_sbi_flag(sbi, SBI_NEED_FSCK); in truncate_dnode()
964 f2fs_handle_error(sbi, ERROR_INVALID_NODE_REFERENCE); in truncate_dnode()
1126 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_truncate_inode_blocks() local
1142 page = f2fs_get_node_page(sbi, inode->i_ino); in f2fs_truncate_inode_blocks()
1205 BUG_ON(page->mapping != NODE_MAPPING(sbi)); in f2fs_truncate_inode_blocks()
1224 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_truncate_xattr_node() local
1233 npage = f2fs_get_node_page(sbi, nid); in f2fs_truncate_xattr_node()
1309 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); in f2fs_new_node_page() local
1317 page = f2fs_grab_cache_page(NODE_MAPPING(sbi), dn->nid, false); in f2fs_new_node_page()
1321 if (unlikely((err = inc_valid_node_count(sbi, dn->inode, !ofs)))) in f2fs_new_node_page()
1325 err = f2fs_get_node_info(sbi, dn->nid, &new_ni, false); in f2fs_new_node_page()
1327 dec_valid_node_count(sbi, dn->inode, !ofs); in f2fs_new_node_page()
1332 dec_valid_node_count(sbi, dn->inode, !ofs); in f2fs_new_node_page()
1333 set_sbi_flag(sbi, SBI_NEED_FSCK); in f2fs_new_node_page()
1334 f2fs_warn_ratelimited(sbi, in f2fs_new_node_page()
1339 f2fs_handle_error(sbi, ERROR_INCONSISTENT_NAT); in f2fs_new_node_page()
1348 set_node_addr(sbi, &new_ni, NEW_ADDR, false); in f2fs_new_node_page()
1362 inc_valid_inode_count(sbi); in f2fs_new_node_page()
1377 struct f2fs_sb_info *sbi = F2FS_P_SB(page); in read_node_page() local
1380 .sbi = sbi, in read_node_page()
1390 if (!f2fs_inode_chksum_verify(sbi, page)) { in read_node_page()
1397 err = f2fs_get_node_info(sbi, page->index, &ni, false); in read_node_page()
1412 f2fs_update_iostat(sbi, NULL, FS_NODE_READ_IO, F2FS_BLKSIZE); in read_node_page()
1420 void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid) in f2fs_ra_node_page() argument
1427 if (f2fs_check_nid_range(sbi, nid)) in f2fs_ra_node_page()
1430 apage = xa_load(&NODE_MAPPING(sbi)->i_pages, nid); in f2fs_ra_node_page()
1434 apage = f2fs_grab_cache_page(NODE_MAPPING(sbi), nid, false); in f2fs_ra_node_page()
1442 static struct page *__get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid, in __get_node_page() argument
1450 if (f2fs_check_nid_range(sbi, nid)) in __get_node_page()
1453 page = f2fs_grab_cache_page(NODE_MAPPING(sbi), nid, false); in __get_node_page()
1470 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { in __get_node_page()
1480 if (!f2fs_inode_chksum_verify(sbi, page)) { in __get_node_page()
1488 …f2fs_warn(sbi, "inconsistent node block, nid:%lu, node_footer[nid:%u,ino:%u,ofs:%u,cpver:%llu,blka… in __get_node_page()
1492 set_sbi_flag(sbi, SBI_NEED_FSCK); in __get_node_page()
1493 f2fs_handle_error(sbi, ERROR_INCONSISTENT_FOOTER); in __get_node_page()
1500 f2fs_handle_page_eio(sbi, page->index, NODE); in __get_node_page()
1505 struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid) in f2fs_get_node_page() argument
1507 return __get_node_page(sbi, nid, NULL, 0); in f2fs_get_node_page()
1512 struct f2fs_sb_info *sbi = F2FS_P_SB(parent); in f2fs_get_node_page_ra() local
1515 return __get_node_page(sbi, nid, parent, start); in f2fs_get_node_page_ra()
1518 static void flush_inline_data(struct f2fs_sb_info *sbi, nid_t ino) in flush_inline_data() argument
1525 inode = ilookup(sbi->sb, ino); in flush_inline_data()
1554 static struct page *last_fsync_dnode(struct f2fs_sb_info *sbi, nid_t ino) in last_fsync_dnode() argument
1564 while ((nr_folios = filemap_get_folios_tag(NODE_MAPPING(sbi), &index, in last_fsync_dnode()
1572 if (unlikely(f2fs_cp_error(sbi))) { in last_fsync_dnode()
1585 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { in last_fsync_dnode()
1615 struct f2fs_sb_info *sbi = F2FS_P_SB(page); in __write_node_page() local
1619 .sbi = sbi, in __write_node_page()
1634 if (unlikely(f2fs_cp_error(sbi))) { in __write_node_page()
1636 if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY) in __write_node_page()
1639 dec_page_count(sbi, F2FS_DIRTY_NODES); in __write_node_page()
1644 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) in __write_node_page()
1647 if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED) && in __write_node_page()
1654 f2fs_bug_on(sbi, page->index != nid); in __write_node_page()
1656 if (f2fs_get_node_info(sbi, nid, &ni, !do_balance)) in __write_node_page()
1660 if (!f2fs_down_read_trylock(&sbi->node_write)) in __write_node_page()
1663 f2fs_down_read(&sbi->node_write); in __write_node_page()
1669 dec_page_count(sbi, F2FS_DIRTY_NODES); in __write_node_page()
1670 f2fs_up_read(&sbi->node_write); in __write_node_page()
1676 !f2fs_is_valid_blkaddr(sbi, ni.blk_addr, in __write_node_page()
1678 f2fs_up_read(&sbi->node_write); in __write_node_page()
1682 if (atomic && !test_opt(sbi, NOBARRIER) && !f2fs_sb_has_blkzoned(sbi)) in __write_node_page()
1686 if (f2fs_in_warm_node_list(sbi, page)) { in __write_node_page()
1687 seq = f2fs_add_fsync_node_entry(sbi, page); in __write_node_page()
1696 set_node_addr(sbi, &ni, fio.new_blkaddr, is_fsync_dnode(page)); in __write_node_page()
1697 dec_page_count(sbi, F2FS_DIRTY_NODES); in __write_node_page()
1698 f2fs_up_read(&sbi->node_write); in __write_node_page()
1701 f2fs_submit_merged_write_cond(sbi, NULL, page, 0, NODE); in __write_node_page()
1707 if (unlikely(f2fs_cp_error(sbi))) { in __write_node_page()
1708 f2fs_submit_merged_write(sbi, NODE); in __write_node_page()
1715 f2fs_balance_fs(sbi, false); in __write_node_page()
1768 int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, in f2fs_fsync_node_pages() argument
1782 last_page = last_fsync_dnode(sbi, ino); in f2fs_fsync_node_pages()
1790 while ((nr_folios = filemap_get_folios_tag(NODE_MAPPING(sbi), &index, in f2fs_fsync_node_pages()
1799 if (unlikely(f2fs_cp_error(sbi))) { in f2fs_fsync_node_pages()
1813 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { in f2fs_fsync_node_pages()
1833 percpu_counter_inc(&sbi->rf_node_block_count); in f2fs_fsync_node_pages()
1839 f2fs_need_dentry_mark(sbi, ino)); in f2fs_fsync_node_pages()
1874 f2fs_debug(sbi, "Retry to write fsync mark: ino=%u, idx=%lx", in f2fs_fsync_node_pages()
1884 f2fs_submit_merged_write_cond(sbi, NULL, NULL, ino, NODE); in f2fs_fsync_node_pages()
1890 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_match_ino() local
1899 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_match_ino()
1901 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_match_ino()
1914 struct f2fs_sb_info *sbi = F2FS_P_SB(page); in flush_dirty_inode() local
1918 inode = find_inode_nowait(sbi->sb, ino, f2fs_match_ino, NULL); in flush_dirty_inode()
1929 void f2fs_flush_inline_data(struct f2fs_sb_info *sbi) in f2fs_flush_inline_data() argument
1937 while ((nr_folios = filemap_get_folios_tag(NODE_MAPPING(sbi), &index, in f2fs_flush_inline_data()
1950 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { in f2fs_flush_inline_data()
1965 flush_inline_data(sbi, ino_of_node(page)); in f2fs_flush_inline_data()
1975 int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, in f2fs_sync_node_pages() argument
1991 while (!done && (nr_folios = filemap_get_folios_tag(NODE_MAPPING(sbi), in f2fs_sync_node_pages()
2001 if (atomic_read(&sbi->wb_sync_req[NODE]) && in f2fs_sync_node_pages()
2027 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { in f2fs_sync_node_pages()
2046 flush_inline_data(sbi, ino_of_node(page)); in f2fs_sync_node_pages()
2082 if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED) && in f2fs_sync_node_pages()
2090 f2fs_submit_merged_write(sbi, NODE); in f2fs_sync_node_pages()
2092 if (unlikely(f2fs_cp_error(sbi))) in f2fs_sync_node_pages()
2097 int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, in f2fs_wait_on_node_pages_writeback() argument
2102 struct list_head *head = &sbi->fsync_node_list; in f2fs_wait_on_node_pages_writeback()
2107 spin_lock_irqsave(&sbi->fsync_node_lock, flags); in f2fs_wait_on_node_pages_writeback()
2109 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); in f2fs_wait_on_node_pages_writeback()
2114 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); in f2fs_wait_on_node_pages_writeback()
2120 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); in f2fs_wait_on_node_pages_writeback()
2127 return filemap_check_errors(NODE_MAPPING(sbi)); in f2fs_wait_on_node_pages_writeback()
2133 struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); in f2fs_write_node_pages() local
2137 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) in f2fs_write_node_pages()
2141 f2fs_balance_fs_bg(sbi, true); in f2fs_write_node_pages()
2145 get_pages(sbi, F2FS_DIRTY_NODES) < in f2fs_write_node_pages()
2146 nr_pages_to_skip(sbi, NODE)) in f2fs_write_node_pages()
2150 atomic_inc(&sbi->wb_sync_req[NODE]); in f2fs_write_node_pages()
2151 else if (atomic_read(&sbi->wb_sync_req[NODE])) { in f2fs_write_node_pages()
2160 diff = nr_pages_to_write(sbi, NODE, wbc); in f2fs_write_node_pages()
2162 f2fs_sync_node_pages(sbi, wbc, true, FS_NODE_IO); in f2fs_write_node_pages()
2167 atomic_dec(&sbi->wb_sync_req[NODE]); in f2fs_write_node_pages()
2171 wbc->pages_skipped += get_pages(sbi, F2FS_DIRTY_NODES); in f2fs_write_node_pages()
2213 static int __insert_free_nid(struct f2fs_sb_info *sbi, in __insert_free_nid() argument
2216 struct f2fs_nm_info *nm_i = NM_I(sbi); in __insert_free_nid()
2227 static void __remove_free_nid(struct f2fs_sb_info *sbi, in __remove_free_nid() argument
2230 struct f2fs_nm_info *nm_i = NM_I(sbi); in __remove_free_nid()
2232 f2fs_bug_on(sbi, state != i->state); in __remove_free_nid()
2239 static void __move_free_nid(struct f2fs_sb_info *sbi, struct free_nid *i, in __move_free_nid() argument
2242 struct f2fs_nm_info *nm_i = NM_I(sbi); in __move_free_nid()
2244 f2fs_bug_on(sbi, org_state != i->state); in __move_free_nid()
2261 bool f2fs_nat_bitmap_enabled(struct f2fs_sb_info *sbi) in f2fs_nat_bitmap_enabled() argument
2263 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_nat_bitmap_enabled()
2279 static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid, in update_free_nid_bitmap() argument
2282 struct f2fs_nm_info *nm_i = NM_I(sbi); in update_free_nid_bitmap()
2304 static bool add_free_nid(struct f2fs_sb_info *sbi, in add_free_nid() argument
2307 struct f2fs_nm_info *nm_i = NM_I(sbi); in add_free_nid()
2317 if (unlikely(f2fs_check_nid_range(sbi, nid))) in add_free_nid()
2363 err = __insert_free_nid(sbi, i); in add_free_nid()
2366 update_free_nid_bitmap(sbi, nid, ret, build); in add_free_nid()
2378 static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid) in remove_free_nid() argument
2380 struct f2fs_nm_info *nm_i = NM_I(sbi); in remove_free_nid()
2387 __remove_free_nid(sbi, i, FREE_NID); in remove_free_nid()
2396 static int scan_nat_page(struct f2fs_sb_info *sbi, in scan_nat_page() argument
2399 struct f2fs_nm_info *nm_i = NM_I(sbi); in scan_nat_page()
2419 add_free_nid(sbi, start_nid, true, true); in scan_nat_page()
2421 spin_lock(&NM_I(sbi)->nid_list_lock); in scan_nat_page()
2422 update_free_nid_bitmap(sbi, start_nid, false, true); in scan_nat_page()
2423 spin_unlock(&NM_I(sbi)->nid_list_lock); in scan_nat_page()
2430 static void scan_curseg_cache(struct f2fs_sb_info *sbi) in scan_curseg_cache() argument
2432 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); in scan_curseg_cache()
2444 add_free_nid(sbi, nid, true, false); in scan_curseg_cache()
2446 remove_free_nid(sbi, nid); in scan_curseg_cache()
2451 static void scan_free_nid_bits(struct f2fs_sb_info *sbi) in scan_free_nid_bits() argument
2453 struct f2fs_nm_info *nm_i = NM_I(sbi); in scan_free_nid_bits()
2471 add_free_nid(sbi, nid, true, false); in scan_free_nid_bits()
2478 scan_curseg_cache(sbi); in scan_free_nid_bits()
2483 static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi, in __f2fs_build_free_nids() argument
2486 struct f2fs_nm_info *nm_i = NM_I(sbi); in __f2fs_build_free_nids()
2500 if (!sync && !f2fs_available_free_memory(sbi, FREE_NIDS)) in __f2fs_build_free_nids()
2505 scan_free_nid_bits(sbi); in __f2fs_build_free_nids()
2512 f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), FREE_NID_PAGES, in __f2fs_build_free_nids()
2520 struct page *page = get_current_nat_page(sbi, nid); in __f2fs_build_free_nids()
2525 ret = scan_nat_page(sbi, page, nid); in __f2fs_build_free_nids()
2533 f2fs_err(sbi, "NAT is corrupt, run fsck to fix it"); in __f2fs_build_free_nids()
2534 set_sbi_flag(sbi, SBI_NEED_FSCK); in __f2fs_build_free_nids()
2535 f2fs_handle_error(sbi, in __f2fs_build_free_nids()
2555 scan_curseg_cache(sbi); in __f2fs_build_free_nids()
2559 f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nm_i->next_scan_nid), in __f2fs_build_free_nids()
2565 int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) in f2fs_build_free_nids() argument
2569 mutex_lock(&NM_I(sbi)->build_lock); in f2fs_build_free_nids()
2570 ret = __f2fs_build_free_nids(sbi, sync, mount); in f2fs_build_free_nids()
2571 mutex_unlock(&NM_I(sbi)->build_lock); in f2fs_build_free_nids()
2581 bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid) in f2fs_alloc_nid() argument
2583 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_alloc_nid()
2586 if (time_to_inject(sbi, FAULT_ALLOC_NID)) in f2fs_alloc_nid()
2598 f2fs_bug_on(sbi, list_empty(&nm_i->free_nid_list)); in f2fs_alloc_nid()
2603 __move_free_nid(sbi, i, FREE_NID, PREALLOC_NID); in f2fs_alloc_nid()
2606 update_free_nid_bitmap(sbi, *nid, false, false); in f2fs_alloc_nid()
2614 if (!f2fs_build_free_nids(sbi, true, false)) in f2fs_alloc_nid()
2622 void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid) in f2fs_alloc_nid_done() argument
2624 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_alloc_nid_done()
2629 f2fs_bug_on(sbi, !i); in f2fs_alloc_nid_done()
2630 __remove_free_nid(sbi, i, PREALLOC_NID); in f2fs_alloc_nid_done()
2639 void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid) in f2fs_alloc_nid_failed() argument
2641 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_alloc_nid_failed()
2650 f2fs_bug_on(sbi, !i); in f2fs_alloc_nid_failed()
2652 if (!f2fs_available_free_memory(sbi, FREE_NIDS)) { in f2fs_alloc_nid_failed()
2653 __remove_free_nid(sbi, i, PREALLOC_NID); in f2fs_alloc_nid_failed()
2656 __move_free_nid(sbi, i, PREALLOC_NID, FREE_NID); in f2fs_alloc_nid_failed()
2661 update_free_nid_bitmap(sbi, nid, true, false); in f2fs_alloc_nid_failed()
2669 int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink) in f2fs_try_to_free_nids() argument
2671 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_try_to_free_nids()
2689 __remove_free_nid(sbi, i, FREE_NID); in f2fs_try_to_free_nids()
2741 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_recover_xattr_data() local
2753 err = f2fs_get_node_info(sbi, prev_xnid, &ni, false); in f2fs_recover_xattr_data()
2757 f2fs_invalidate_blocks(sbi, ni.blk_addr); in f2fs_recover_xattr_data()
2758 dec_valid_node_count(sbi, inode, false); in f2fs_recover_xattr_data()
2759 set_node_addr(sbi, &ni, NULL_ADDR, false); in f2fs_recover_xattr_data()
2763 if (!f2fs_alloc_nid(sbi, &new_xnid)) in f2fs_recover_xattr_data()
2769 f2fs_alloc_nid_failed(sbi, new_xnid); in f2fs_recover_xattr_data()
2773 f2fs_alloc_nid_done(sbi, new_xnid); in f2fs_recover_xattr_data()
2787 int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page) in f2fs_recover_inode_page() argument
2795 err = f2fs_get_node_info(sbi, ino, &old_ni, false); in f2fs_recover_inode_page()
2802 ipage = f2fs_grab_cache_page(NODE_MAPPING(sbi), ino, false); in f2fs_recover_inode_page()
2809 remove_free_nid(sbi, ino); in f2fs_recover_inode_page()
2828 if (f2fs_sb_has_flexible_inline_xattr(sbi) && in f2fs_recover_inode_page()
2833 if (f2fs_sb_has_project_quota(sbi) && in f2fs_recover_inode_page()
2838 if (f2fs_sb_has_inode_crtime(sbi) && in f2fs_recover_inode_page()
2849 if (unlikely(inc_valid_node_count(sbi, NULL, true))) in f2fs_recover_inode_page()
2851 set_node_addr(sbi, &new_ni, NEW_ADDR, false); in f2fs_recover_inode_page()
2852 inc_valid_inode_count(sbi); in f2fs_recover_inode_page()
2858 int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, in f2fs_restore_node_summary() argument
2867 last_offset = BLKS_PER_SEG(sbi); in f2fs_restore_node_summary()
2868 addr = START_BLOCK(sbi, segno); in f2fs_restore_node_summary()
2875 f2fs_ra_meta_pages(sbi, addr, nrpages, META_POR, true); in f2fs_restore_node_summary()
2878 struct page *page = f2fs_get_tmp_page(sbi, idx); in f2fs_restore_node_summary()
2891 invalidate_mapping_pages(META_MAPPING(sbi), addr, in f2fs_restore_node_summary()
2897 static void remove_nats_in_journal(struct f2fs_sb_info *sbi) in remove_nats_in_journal() argument
2899 struct f2fs_nm_info *nm_i = NM_I(sbi); in remove_nats_in_journal()
2900 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); in remove_nats_in_journal()
2910 if (f2fs_check_nid_range(sbi, nid)) in remove_nats_in_journal()
2917 ne = __alloc_nat_entry(sbi, nid, true); in remove_nats_in_journal()
2973 static void update_nat_bits(struct f2fs_sb_info *sbi, nid_t start_nid, in update_nat_bits() argument
2976 struct f2fs_nm_info *nm_i = NM_I(sbi); in update_nat_bits()
2982 if (!is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG)) in update_nat_bits()
2997 void f2fs_enable_nat_bits(struct f2fs_sb_info *sbi) in f2fs_enable_nat_bits() argument
2999 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_enable_nat_bits()
3025 static int __flush_nat_entry_set(struct f2fs_sb_info *sbi, in __flush_nat_entry_set() argument
3028 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); in __flush_nat_entry_set()
3048 page = get_next_nat_page(sbi, start_nid); in __flush_nat_entry_set()
3053 f2fs_bug_on(sbi, !nat_blk); in __flush_nat_entry_set()
3062 f2fs_bug_on(sbi, nat_get_blkaddr(ne) == NEW_ADDR); in __flush_nat_entry_set()
3067 f2fs_bug_on(sbi, offset < 0); in __flush_nat_entry_set()
3075 __clear_nat_cache_dirty(NM_I(sbi), set, ne); in __flush_nat_entry_set()
3077 add_free_nid(sbi, nid, false, true); in __flush_nat_entry_set()
3079 spin_lock(&NM_I(sbi)->nid_list_lock); in __flush_nat_entry_set()
3080 update_free_nid_bitmap(sbi, nid, false, false); in __flush_nat_entry_set()
3081 spin_unlock(&NM_I(sbi)->nid_list_lock); in __flush_nat_entry_set()
3088 update_nat_bits(sbi, start_nid, page); in __flush_nat_entry_set()
3094 radix_tree_delete(&NM_I(sbi)->nat_set_root, set->set); in __flush_nat_entry_set()
3103 int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) in f2fs_flush_nat_entries() argument
3105 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_flush_nat_entries()
3106 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); in f2fs_flush_nat_entries()
3121 remove_nats_in_journal(sbi); in f2fs_flush_nat_entries()
3138 remove_nats_in_journal(sbi); in f2fs_flush_nat_entries()
3152 err = __flush_nat_entry_set(sbi, set, cpc); in f2fs_flush_nat_entries()
3163 static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) in __get_nat_bitmaps() argument
3165 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); in __get_nat_bitmaps()
3166 struct f2fs_nm_info *nm_i = NM_I(sbi); in __get_nat_bitmaps()
3173 nm_i->nat_bits = f2fs_kvzalloc(sbi, in __get_nat_bitmaps()
3181 if (!is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG)) in __get_nat_bitmaps()
3184 nat_bits_addr = __start_cp_addr(sbi) + BLKS_PER_SEG(sbi) - in __get_nat_bitmaps()
3189 page = f2fs_get_meta_page(sbi, nat_bits_addr++); in __get_nat_bitmaps()
3200 clear_ckpt_flags(sbi, CP_NAT_BITS_FLAG); in __get_nat_bitmaps()
3201 f2fs_notice(sbi, "Disable nat_bits due to incorrect cp_ver (%llu, %llu)", in __get_nat_bitmaps()
3206 f2fs_notice(sbi, "Found nat_bits in checkpoint"); in __get_nat_bitmaps()
3210 static inline void load_free_nid_bitmap(struct f2fs_sb_info *sbi) in load_free_nid_bitmap() argument
3212 struct f2fs_nm_info *nm_i = NM_I(sbi); in load_free_nid_bitmap()
3216 if (!is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG)) in load_free_nid_bitmap()
3229 spin_lock(&NM_I(sbi)->nid_list_lock); in load_free_nid_bitmap()
3231 update_free_nid_bitmap(sbi, nid, true, true); in load_free_nid_bitmap()
3232 spin_unlock(&NM_I(sbi)->nid_list_lock); in load_free_nid_bitmap()
3244 static int init_node_manager(struct f2fs_sb_info *sbi) in init_node_manager() argument
3246 struct f2fs_super_block *sb_raw = F2FS_RAW_SUPER(sbi); in init_node_manager()
3247 struct f2fs_nm_info *nm_i = NM_I(sbi); in init_node_manager()
3260 nm_i->available_nids = nm_i->max_nid - sbi->total_valid_node_count - in init_node_manager()
3280 nm_i->next_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid); in init_node_manager()
3281 nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP); in init_node_manager()
3282 version_bitmap = __bitmap_ptr(sbi, NAT_BITMAP); in init_node_manager()
3288 err = __get_nat_bitmaps(sbi); in init_node_manager()
3302 static int init_free_nid_cache(struct f2fs_sb_info *sbi) in init_free_nid_cache() argument
3304 struct f2fs_nm_info *nm_i = NM_I(sbi); in init_free_nid_cache()
3308 f2fs_kvzalloc(sbi, array_size(sizeof(unsigned char *), in init_free_nid_cache()
3315 nm_i->free_nid_bitmap[i] = f2fs_kvzalloc(sbi, in init_free_nid_cache()
3321 nm_i->nat_block_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks / 8, in init_free_nid_cache()
3327 f2fs_kvzalloc(sbi, array_size(sizeof(unsigned short), in init_free_nid_cache()
3335 int f2fs_build_node_manager(struct f2fs_sb_info *sbi) in f2fs_build_node_manager() argument
3339 sbi->nm_info = f2fs_kzalloc(sbi, sizeof(struct f2fs_nm_info), in f2fs_build_node_manager()
3341 if (!sbi->nm_info) in f2fs_build_node_manager()
3344 err = init_node_manager(sbi); in f2fs_build_node_manager()
3348 err = init_free_nid_cache(sbi); in f2fs_build_node_manager()
3353 load_free_nid_bitmap(sbi); in f2fs_build_node_manager()
3355 return f2fs_build_free_nids(sbi, true, true); in f2fs_build_node_manager()
3358 void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi) in f2fs_destroy_node_manager() argument
3360 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_destroy_node_manager()
3374 __remove_free_nid(sbi, i, FREE_NID); in f2fs_destroy_node_manager()
3379 f2fs_bug_on(sbi, nm_i->nid_cnt[FREE_NID]); in f2fs_destroy_node_manager()
3380 f2fs_bug_on(sbi, nm_i->nid_cnt[PREALLOC_NID]); in f2fs_destroy_node_manager()
3381 f2fs_bug_on(sbi, !list_empty(&nm_i->free_nid_list)); in f2fs_destroy_node_manager()
3399 f2fs_bug_on(sbi, nm_i->nat_cnt[TOTAL_NAT]); in f2fs_destroy_node_manager()
3411 f2fs_bug_on(sbi, !list_empty(&setvec[idx]->entry_list)); in f2fs_destroy_node_manager()
3433 sbi->nm_info = NULL; in f2fs_destroy_node_manager()