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_invalidate_blocks(sbi, ni.blk_addr); in truncate_node()
910 dec_valid_node_count(sbi, dn->inode, dn->nid == dn->inode->i_ino); in truncate_node()
911 set_node_addr(sbi, &ni, NULL_ADDR, false); in truncate_node()
914 f2fs_remove_orphan_inode(sbi, dn->nid); in truncate_node()
915 dec_valid_inode_count(sbi); in truncate_node()
920 set_sbi_flag(sbi, SBI_IS_DIRTY); in truncate_node()
925 invalidate_mapping_pages(NODE_MAPPING(sbi), in truncate_node()
936 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); in truncate_dnode() local
944 page = f2fs_get_node_page(sbi, dn->nid); in truncate_dnode()
951 f2fs_err(sbi, "incorrect node reference, ino: %lu, nid: %u, ino_of_node: %u", in truncate_dnode()
953 set_sbi_flag(sbi, SBI_NEED_FSCK); in truncate_dnode()
954 f2fs_handle_error(sbi, ERROR_INVALID_NODE_REFERENCE); in truncate_dnode()
1116 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_truncate_inode_blocks() local
1132 page = f2fs_get_node_page(sbi, inode->i_ino); in f2fs_truncate_inode_blocks()
1192 f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR); in f2fs_truncate_inode_blocks()
1193 f2fs_err_ratelimited(sbi, 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_handle_error(sbi, ERROR_INVALID_BLKADDR); in f2fs_new_node_page()
1343 set_node_addr(sbi, &new_ni, NEW_ADDR, false); in f2fs_new_node_page()
1357 inc_valid_inode_count(sbi); in f2fs_new_node_page()
1373 struct f2fs_sb_info *sbi = F2FS_P_SB(page); in read_node_page() local
1376 .sbi = sbi, in read_node_page()
1386 if (!f2fs_inode_chksum_verify(sbi, page)) { in read_node_page()
1393 err = f2fs_get_node_info(sbi, folio->index, &ni, false); in read_node_page()
1408 f2fs_update_iostat(sbi, NULL, FS_NODE_READ_IO, F2FS_BLKSIZE); in read_node_page()
1416 void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid) in f2fs_ra_node_page() argument
1423 if (f2fs_check_nid_range(sbi, nid)) in f2fs_ra_node_page()
1426 apage = xa_load(&NODE_MAPPING(sbi)->i_pages, nid); in f2fs_ra_node_page()
1430 apage = f2fs_grab_cache_page(NODE_MAPPING(sbi), nid, false); in f2fs_ra_node_page()
1438 static struct page *__get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid, in __get_node_page() argument
1446 if (f2fs_check_nid_range(sbi, nid)) in __get_node_page()
1449 page = f2fs_grab_cache_page(NODE_MAPPING(sbi), nid, false); in __get_node_page()
1466 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { in __get_node_page()
1476 if (!f2fs_inode_chksum_verify(sbi, page)) { in __get_node_page()
1484 …f2fs_warn(sbi, "inconsistent node block, nid:%lu, node_footer[nid:%u,ino:%u,ofs:%u,cpver:%llu,blka… in __get_node_page()
1488 set_sbi_flag(sbi, SBI_NEED_FSCK); in __get_node_page()
1489 f2fs_handle_error(sbi, ERROR_INCONSISTENT_FOOTER); in __get_node_page()
1496 f2fs_handle_page_eio(sbi, page_folio(page), NODE); in __get_node_page()
1501 struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid) in f2fs_get_node_page() argument
1503 return __get_node_page(sbi, nid, NULL, 0); in f2fs_get_node_page()
1508 struct f2fs_sb_info *sbi = F2FS_P_SB(parent); in f2fs_get_node_page_ra() local
1511 return __get_node_page(sbi, nid, parent, start); in f2fs_get_node_page_ra()
1514 static void flush_inline_data(struct f2fs_sb_info *sbi, nid_t ino) in flush_inline_data() argument
1521 inode = ilookup(sbi->sb, ino); in flush_inline_data()
1550 static struct page *last_fsync_dnode(struct f2fs_sb_info *sbi, nid_t ino) in last_fsync_dnode() argument
1560 while ((nr_folios = filemap_get_folios_tag(NODE_MAPPING(sbi), &index, in last_fsync_dnode()
1568 if (unlikely(f2fs_cp_error(sbi))) { in last_fsync_dnode()
1581 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { in last_fsync_dnode()
1611 struct f2fs_sb_info *sbi = F2FS_P_SB(page); in __write_node_page() local
1616 .sbi = sbi, in __write_node_page()
1631 if (unlikely(f2fs_cp_error(sbi))) { in __write_node_page()
1633 if (F2FS_OPTION(sbi).errors == MOUNT_ERRORS_READONLY) in __write_node_page()
1636 dec_page_count(sbi, F2FS_DIRTY_NODES); in __write_node_page()
1641 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) in __write_node_page()
1644 if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED) && in __write_node_page()
1651 f2fs_bug_on(sbi, folio->index != nid); in __write_node_page()
1653 if (f2fs_get_node_info(sbi, nid, &ni, !do_balance)) in __write_node_page()
1657 if (!f2fs_down_read_trylock(&sbi->node_write)) in __write_node_page()
1660 f2fs_down_read(&sbi->node_write); in __write_node_page()
1666 dec_page_count(sbi, F2FS_DIRTY_NODES); in __write_node_page()
1667 f2fs_up_read(&sbi->node_write); in __write_node_page()
1673 !f2fs_is_valid_blkaddr(sbi, ni.blk_addr, in __write_node_page()
1675 f2fs_up_read(&sbi->node_write); in __write_node_page()
1679 if (atomic && !test_opt(sbi, NOBARRIER)) in __write_node_page()
1683 if (f2fs_in_warm_node_list(sbi, page)) { in __write_node_page()
1684 seq = f2fs_add_fsync_node_entry(sbi, page); in __write_node_page()
1693 set_node_addr(sbi, &ni, fio.new_blkaddr, is_fsync_dnode(page)); in __write_node_page()
1694 dec_page_count(sbi, F2FS_DIRTY_NODES); in __write_node_page()
1695 f2fs_up_read(&sbi->node_write); in __write_node_page()
1698 f2fs_submit_merged_write_cond(sbi, NULL, page, 0, NODE); in __write_node_page()
1704 if (unlikely(f2fs_cp_error(sbi))) { in __write_node_page()
1705 f2fs_submit_merged_write(sbi, NODE); in __write_node_page()
1712 f2fs_balance_fs(sbi, false); in __write_node_page()
1765 int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, in f2fs_fsync_node_pages() argument
1779 last_page = last_fsync_dnode(sbi, ino); in f2fs_fsync_node_pages()
1787 while ((nr_folios = filemap_get_folios_tag(NODE_MAPPING(sbi), &index, in f2fs_fsync_node_pages()
1796 if (unlikely(f2fs_cp_error(sbi))) { in f2fs_fsync_node_pages()
1810 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { in f2fs_fsync_node_pages()
1830 percpu_counter_inc(&sbi->rf_node_block_count); in f2fs_fsync_node_pages()
1836 f2fs_need_dentry_mark(sbi, ino)); in f2fs_fsync_node_pages()
1871 f2fs_debug(sbi, "Retry to write fsync mark: ino=%u, idx=%lx", in f2fs_fsync_node_pages()
1881 f2fs_submit_merged_write_cond(sbi, NULL, NULL, ino, NODE); in f2fs_fsync_node_pages()
1887 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_match_ino() local
1896 spin_lock(&sbi->inode_lock[DIRTY_META]); in f2fs_match_ino()
1898 spin_unlock(&sbi->inode_lock[DIRTY_META]); in f2fs_match_ino()
1911 struct f2fs_sb_info *sbi = F2FS_P_SB(page); in flush_dirty_inode() local
1915 inode = find_inode_nowait(sbi->sb, ino, f2fs_match_ino, NULL); in flush_dirty_inode()
1926 void f2fs_flush_inline_data(struct f2fs_sb_info *sbi) in f2fs_flush_inline_data() argument
1934 while ((nr_folios = filemap_get_folios_tag(NODE_MAPPING(sbi), &index, in f2fs_flush_inline_data()
1947 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { in f2fs_flush_inline_data()
1962 flush_inline_data(sbi, ino_of_node(page)); in f2fs_flush_inline_data()
1972 int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, in f2fs_sync_node_pages() argument
1988 while (!done && (nr_folios = filemap_get_folios_tag(NODE_MAPPING(sbi), in f2fs_sync_node_pages()
1998 if (atomic_read(&sbi->wb_sync_req[NODE]) && in f2fs_sync_node_pages()
2024 if (unlikely(page->mapping != NODE_MAPPING(sbi))) { in f2fs_sync_node_pages()
2043 flush_inline_data(sbi, ino_of_node(page)); in f2fs_sync_node_pages()
2079 if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED) && in f2fs_sync_node_pages()
2087 f2fs_submit_merged_write(sbi, NODE); in f2fs_sync_node_pages()
2089 if (unlikely(f2fs_cp_error(sbi))) in f2fs_sync_node_pages()
2094 int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, in f2fs_wait_on_node_pages_writeback() argument
2099 struct list_head *head = &sbi->fsync_node_list; in f2fs_wait_on_node_pages_writeback()
2104 spin_lock_irqsave(&sbi->fsync_node_lock, flags); in f2fs_wait_on_node_pages_writeback()
2106 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); in f2fs_wait_on_node_pages_writeback()
2111 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); in f2fs_wait_on_node_pages_writeback()
2117 spin_unlock_irqrestore(&sbi->fsync_node_lock, flags); in f2fs_wait_on_node_pages_writeback()
2124 return filemap_check_errors(NODE_MAPPING(sbi)); in f2fs_wait_on_node_pages_writeback()
2130 struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); in f2fs_write_node_pages() local
2134 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) in f2fs_write_node_pages()
2138 f2fs_balance_fs_bg(sbi, true); in f2fs_write_node_pages()
2142 get_pages(sbi, F2FS_DIRTY_NODES) < in f2fs_write_node_pages()
2143 nr_pages_to_skip(sbi, NODE)) in f2fs_write_node_pages()
2147 atomic_inc(&sbi->wb_sync_req[NODE]); in f2fs_write_node_pages()
2148 else if (atomic_read(&sbi->wb_sync_req[NODE])) { in f2fs_write_node_pages()
2157 diff = nr_pages_to_write(sbi, NODE, wbc); in f2fs_write_node_pages()
2159 f2fs_sync_node_pages(sbi, wbc, true, FS_NODE_IO); in f2fs_write_node_pages()
2164 atomic_dec(&sbi->wb_sync_req[NODE]); in f2fs_write_node_pages()
2168 wbc->pages_skipped += get_pages(sbi, F2FS_DIRTY_NODES); in f2fs_write_node_pages()
2210 static int __insert_free_nid(struct f2fs_sb_info *sbi, in __insert_free_nid() argument
2213 struct f2fs_nm_info *nm_i = NM_I(sbi); in __insert_free_nid()
2224 static void __remove_free_nid(struct f2fs_sb_info *sbi, in __remove_free_nid() argument
2227 struct f2fs_nm_info *nm_i = NM_I(sbi); in __remove_free_nid()
2229 f2fs_bug_on(sbi, state != i->state); in __remove_free_nid()
2236 static void __move_free_nid(struct f2fs_sb_info *sbi, struct free_nid *i, in __move_free_nid() argument
2239 struct f2fs_nm_info *nm_i = NM_I(sbi); in __move_free_nid()
2241 f2fs_bug_on(sbi, org_state != i->state); in __move_free_nid()
2258 bool f2fs_nat_bitmap_enabled(struct f2fs_sb_info *sbi) in f2fs_nat_bitmap_enabled() argument
2260 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_nat_bitmap_enabled()
2276 static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid, in update_free_nid_bitmap() argument
2279 struct f2fs_nm_info *nm_i = NM_I(sbi); in update_free_nid_bitmap()
2301 static bool add_free_nid(struct f2fs_sb_info *sbi, in add_free_nid() argument
2304 struct f2fs_nm_info *nm_i = NM_I(sbi); in add_free_nid()
2314 if (unlikely(f2fs_check_nid_range(sbi, nid))) in add_free_nid()
2360 err = __insert_free_nid(sbi, i); in add_free_nid()
2363 update_free_nid_bitmap(sbi, nid, ret, build); in add_free_nid()
2375 static void remove_free_nid(struct f2fs_sb_info *sbi, nid_t nid) in remove_free_nid() argument
2377 struct f2fs_nm_info *nm_i = NM_I(sbi); in remove_free_nid()
2384 __remove_free_nid(sbi, i, FREE_NID); in remove_free_nid()
2393 static int scan_nat_page(struct f2fs_sb_info *sbi, in scan_nat_page() argument
2396 struct f2fs_nm_info *nm_i = NM_I(sbi); in scan_nat_page()
2416 add_free_nid(sbi, start_nid, true, true); in scan_nat_page()
2418 spin_lock(&NM_I(sbi)->nid_list_lock); in scan_nat_page()
2419 update_free_nid_bitmap(sbi, start_nid, false, true); in scan_nat_page()
2420 spin_unlock(&NM_I(sbi)->nid_list_lock); in scan_nat_page()
2427 static void scan_curseg_cache(struct f2fs_sb_info *sbi) in scan_curseg_cache() argument
2429 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); in scan_curseg_cache()
2441 add_free_nid(sbi, nid, true, false); in scan_curseg_cache()
2443 remove_free_nid(sbi, nid); in scan_curseg_cache()
2448 static void scan_free_nid_bits(struct f2fs_sb_info *sbi) in scan_free_nid_bits() argument
2450 struct f2fs_nm_info *nm_i = NM_I(sbi); in scan_free_nid_bits()
2468 add_free_nid(sbi, nid, true, false); in scan_free_nid_bits()
2475 scan_curseg_cache(sbi); in scan_free_nid_bits()
2480 static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi, in __f2fs_build_free_nids() argument
2483 struct f2fs_nm_info *nm_i = NM_I(sbi); in __f2fs_build_free_nids()
2497 if (!sync && !f2fs_available_free_memory(sbi, FREE_NIDS)) in __f2fs_build_free_nids()
2502 scan_free_nid_bits(sbi); in __f2fs_build_free_nids()
2509 f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), FREE_NID_PAGES, in __f2fs_build_free_nids()
2517 struct page *page = get_current_nat_page(sbi, nid); in __f2fs_build_free_nids()
2522 ret = scan_nat_page(sbi, page, nid); in __f2fs_build_free_nids()
2530 f2fs_err(sbi, "NAT is corrupt, run fsck to fix it"); in __f2fs_build_free_nids()
2531 set_sbi_flag(sbi, SBI_NEED_FSCK); in __f2fs_build_free_nids()
2532 f2fs_handle_error(sbi, in __f2fs_build_free_nids()
2552 scan_curseg_cache(sbi); in __f2fs_build_free_nids()
2556 f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nm_i->next_scan_nid), in __f2fs_build_free_nids()
2562 int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount) in f2fs_build_free_nids() argument
2566 mutex_lock(&NM_I(sbi)->build_lock); in f2fs_build_free_nids()
2567 ret = __f2fs_build_free_nids(sbi, sync, mount); in f2fs_build_free_nids()
2568 mutex_unlock(&NM_I(sbi)->build_lock); in f2fs_build_free_nids()
2578 bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid) in f2fs_alloc_nid() argument
2580 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_alloc_nid()
2583 if (time_to_inject(sbi, FAULT_ALLOC_NID)) in f2fs_alloc_nid()
2595 f2fs_bug_on(sbi, list_empty(&nm_i->free_nid_list)); in f2fs_alloc_nid()
2600 __move_free_nid(sbi, i, FREE_NID, PREALLOC_NID); in f2fs_alloc_nid()
2603 update_free_nid_bitmap(sbi, *nid, false, false); in f2fs_alloc_nid()
2611 if (!f2fs_build_free_nids(sbi, true, false)) in f2fs_alloc_nid()
2619 void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid) in f2fs_alloc_nid_done() argument
2621 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_alloc_nid_done()
2626 f2fs_bug_on(sbi, !i); in f2fs_alloc_nid_done()
2627 __remove_free_nid(sbi, i, PREALLOC_NID); in f2fs_alloc_nid_done()
2636 void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid) in f2fs_alloc_nid_failed() argument
2638 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_alloc_nid_failed()
2647 f2fs_bug_on(sbi, !i); in f2fs_alloc_nid_failed()
2649 if (!f2fs_available_free_memory(sbi, FREE_NIDS)) { in f2fs_alloc_nid_failed()
2650 __remove_free_nid(sbi, i, PREALLOC_NID); in f2fs_alloc_nid_failed()
2653 __move_free_nid(sbi, i, PREALLOC_NID, FREE_NID); in f2fs_alloc_nid_failed()
2658 update_free_nid_bitmap(sbi, nid, true, false); in f2fs_alloc_nid_failed()
2666 int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink) in f2fs_try_to_free_nids() argument
2668 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_try_to_free_nids()
2686 __remove_free_nid(sbi, i, FREE_NID); in f2fs_try_to_free_nids()
2738 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); in f2fs_recover_xattr_data() local
2750 err = f2fs_get_node_info(sbi, prev_xnid, &ni, false); in f2fs_recover_xattr_data()
2754 f2fs_invalidate_blocks(sbi, ni.blk_addr); in f2fs_recover_xattr_data()
2755 dec_valid_node_count(sbi, inode, false); in f2fs_recover_xattr_data()
2756 set_node_addr(sbi, &ni, NULL_ADDR, false); in f2fs_recover_xattr_data()
2760 if (!f2fs_alloc_nid(sbi, &new_xnid)) in f2fs_recover_xattr_data()
2766 f2fs_alloc_nid_failed(sbi, new_xnid); in f2fs_recover_xattr_data()
2770 f2fs_alloc_nid_done(sbi, new_xnid); in f2fs_recover_xattr_data()
2784 int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page) in f2fs_recover_inode_page() argument
2792 err = f2fs_get_node_info(sbi, ino, &old_ni, false); in f2fs_recover_inode_page()
2799 ipage = f2fs_grab_cache_page(NODE_MAPPING(sbi), ino, false); in f2fs_recover_inode_page()
2806 remove_free_nid(sbi, ino); in f2fs_recover_inode_page()
2825 if (f2fs_sb_has_flexible_inline_xattr(sbi) && in f2fs_recover_inode_page()
2830 if (f2fs_sb_has_project_quota(sbi) && in f2fs_recover_inode_page()
2835 if (f2fs_sb_has_inode_crtime(sbi) && in f2fs_recover_inode_page()
2846 if (unlikely(inc_valid_node_count(sbi, NULL, true))) in f2fs_recover_inode_page()
2848 set_node_addr(sbi, &new_ni, NEW_ADDR, false); in f2fs_recover_inode_page()
2849 inc_valid_inode_count(sbi); in f2fs_recover_inode_page()
2855 int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, in f2fs_restore_node_summary() argument
2864 last_offset = BLKS_PER_SEG(sbi); in f2fs_restore_node_summary()
2865 addr = START_BLOCK(sbi, segno); in f2fs_restore_node_summary()
2872 f2fs_ra_meta_pages(sbi, addr, nrpages, META_POR, true); in f2fs_restore_node_summary()
2875 struct page *page = f2fs_get_tmp_page(sbi, idx); in f2fs_restore_node_summary()
2888 invalidate_mapping_pages(META_MAPPING(sbi), addr, in f2fs_restore_node_summary()
2894 static void remove_nats_in_journal(struct f2fs_sb_info *sbi) in remove_nats_in_journal() argument
2896 struct f2fs_nm_info *nm_i = NM_I(sbi); in remove_nats_in_journal()
2897 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); in remove_nats_in_journal()
2907 if (f2fs_check_nid_range(sbi, nid)) in remove_nats_in_journal()
2914 ne = __alloc_nat_entry(sbi, nid, true); in remove_nats_in_journal()
2970 static void update_nat_bits(struct f2fs_sb_info *sbi, nid_t start_nid, in update_nat_bits() argument
2973 struct f2fs_nm_info *nm_i = NM_I(sbi); in update_nat_bits()
2979 if (!is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG)) in update_nat_bits()
2994 void f2fs_enable_nat_bits(struct f2fs_sb_info *sbi) in f2fs_enable_nat_bits() argument
2996 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_enable_nat_bits()
3022 static int __flush_nat_entry_set(struct f2fs_sb_info *sbi, in __flush_nat_entry_set() argument
3025 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); in __flush_nat_entry_set()
3045 page = get_next_nat_page(sbi, start_nid); in __flush_nat_entry_set()
3050 f2fs_bug_on(sbi, !nat_blk); in __flush_nat_entry_set()
3059 f2fs_bug_on(sbi, nat_get_blkaddr(ne) == NEW_ADDR); in __flush_nat_entry_set()
3064 f2fs_bug_on(sbi, offset < 0); in __flush_nat_entry_set()
3072 __clear_nat_cache_dirty(NM_I(sbi), set, ne); in __flush_nat_entry_set()
3074 add_free_nid(sbi, nid, false, true); in __flush_nat_entry_set()
3076 spin_lock(&NM_I(sbi)->nid_list_lock); in __flush_nat_entry_set()
3077 update_free_nid_bitmap(sbi, nid, false, false); in __flush_nat_entry_set()
3078 spin_unlock(&NM_I(sbi)->nid_list_lock); in __flush_nat_entry_set()
3085 update_nat_bits(sbi, start_nid, page); in __flush_nat_entry_set()
3091 radix_tree_delete(&NM_I(sbi)->nat_set_root, set->set); in __flush_nat_entry_set()
3100 int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) in f2fs_flush_nat_entries() argument
3102 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_flush_nat_entries()
3103 struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA); in f2fs_flush_nat_entries()
3118 remove_nats_in_journal(sbi); in f2fs_flush_nat_entries()
3135 remove_nats_in_journal(sbi); in f2fs_flush_nat_entries()
3149 err = __flush_nat_entry_set(sbi, set, cpc); in f2fs_flush_nat_entries()
3160 static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) in __get_nat_bitmaps() argument
3162 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); in __get_nat_bitmaps()
3163 struct f2fs_nm_info *nm_i = NM_I(sbi); in __get_nat_bitmaps()
3170 nm_i->nat_bits = f2fs_kvzalloc(sbi, in __get_nat_bitmaps()
3178 if (!is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG)) in __get_nat_bitmaps()
3181 nat_bits_addr = __start_cp_addr(sbi) + BLKS_PER_SEG(sbi) - in __get_nat_bitmaps()
3186 page = f2fs_get_meta_page(sbi, nat_bits_addr++); in __get_nat_bitmaps()
3197 clear_ckpt_flags(sbi, CP_NAT_BITS_FLAG); in __get_nat_bitmaps()
3198 f2fs_notice(sbi, "Disable nat_bits due to incorrect cp_ver (%llu, %llu)", in __get_nat_bitmaps()
3203 f2fs_notice(sbi, "Found nat_bits in checkpoint"); in __get_nat_bitmaps()
3207 static inline void load_free_nid_bitmap(struct f2fs_sb_info *sbi) in load_free_nid_bitmap() argument
3209 struct f2fs_nm_info *nm_i = NM_I(sbi); in load_free_nid_bitmap()
3213 if (!is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG)) in load_free_nid_bitmap()
3226 spin_lock(&NM_I(sbi)->nid_list_lock); in load_free_nid_bitmap()
3228 update_free_nid_bitmap(sbi, nid, true, true); in load_free_nid_bitmap()
3229 spin_unlock(&NM_I(sbi)->nid_list_lock); in load_free_nid_bitmap()
3241 static int init_node_manager(struct f2fs_sb_info *sbi) in init_node_manager() argument
3243 struct f2fs_super_block *sb_raw = F2FS_RAW_SUPER(sbi); in init_node_manager()
3244 struct f2fs_nm_info *nm_i = NM_I(sbi); in init_node_manager()
3257 nm_i->available_nids = nm_i->max_nid - sbi->total_valid_node_count - in init_node_manager()
3277 nm_i->next_scan_nid = le32_to_cpu(sbi->ckpt->next_free_nid); in init_node_manager()
3278 nm_i->bitmap_size = __bitmap_size(sbi, NAT_BITMAP); in init_node_manager()
3279 version_bitmap = __bitmap_ptr(sbi, NAT_BITMAP); in init_node_manager()
3285 err = __get_nat_bitmaps(sbi); in init_node_manager()
3299 static int init_free_nid_cache(struct f2fs_sb_info *sbi) in init_free_nid_cache() argument
3301 struct f2fs_nm_info *nm_i = NM_I(sbi); in init_free_nid_cache()
3305 f2fs_kvzalloc(sbi, array_size(sizeof(unsigned char *), in init_free_nid_cache()
3312 nm_i->free_nid_bitmap[i] = f2fs_kvzalloc(sbi, in init_free_nid_cache()
3318 nm_i->nat_block_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks / 8, in init_free_nid_cache()
3324 f2fs_kvzalloc(sbi, array_size(sizeof(unsigned short), in init_free_nid_cache()
3332 int f2fs_build_node_manager(struct f2fs_sb_info *sbi) in f2fs_build_node_manager() argument
3336 sbi->nm_info = f2fs_kzalloc(sbi, sizeof(struct f2fs_nm_info), in f2fs_build_node_manager()
3338 if (!sbi->nm_info) in f2fs_build_node_manager()
3341 err = init_node_manager(sbi); in f2fs_build_node_manager()
3345 err = init_free_nid_cache(sbi); in f2fs_build_node_manager()
3350 load_free_nid_bitmap(sbi); in f2fs_build_node_manager()
3352 return f2fs_build_free_nids(sbi, true, true); in f2fs_build_node_manager()
3355 void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi) in f2fs_destroy_node_manager() argument
3357 struct f2fs_nm_info *nm_i = NM_I(sbi); in f2fs_destroy_node_manager()
3371 __remove_free_nid(sbi, i, FREE_NID); in f2fs_destroy_node_manager()
3376 f2fs_bug_on(sbi, nm_i->nid_cnt[FREE_NID]); in f2fs_destroy_node_manager()
3377 f2fs_bug_on(sbi, nm_i->nid_cnt[PREALLOC_NID]); in f2fs_destroy_node_manager()
3378 f2fs_bug_on(sbi, !list_empty(&nm_i->free_nid_list)); in f2fs_destroy_node_manager()
3396 f2fs_bug_on(sbi, nm_i->nat_cnt[TOTAL_NAT]); in f2fs_destroy_node_manager()
3408 f2fs_bug_on(sbi, !list_empty(&setvec[idx]->entry_list)); in f2fs_destroy_node_manager()
3430 sbi->nm_info = NULL; in f2fs_destroy_node_manager()