Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * fs/f2fs/checkpoint.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *             http://www.samsung.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/mpage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/f2fs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/pagevec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include "f2fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include "node.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include "segment.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <trace/events/f2fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #define DEFAULT_CHECKPOINT_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) static struct kmem_cache *ino_entry_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) struct kmem_cache *f2fs_inode_entry_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 	f2fs_build_fault_attr(sbi, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 	set_ckpt_flags(sbi, CP_ERROR_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 	if (!end_io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 		f2fs_flush_merged_writes(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  * We guarantee no failure on the returned page.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	struct address_space *mapping = META_MAPPING(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) repeat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	page = f2fs_grab_cache_page(mapping, index, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	if (!page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 		goto repeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	f2fs_wait_on_page_writeback(page, META, true, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	if (!PageUptodate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 		SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 							bool is_meta)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	struct address_space *mapping = META_MAPPING(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 	struct f2fs_io_info fio = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 		.sbi = sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 		.type = META,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 		.op = REQ_OP_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 		.op_flags = REQ_META | REQ_PRIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 		.old_blkaddr = index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 		.new_blkaddr = index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 		.encrypted_page = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 		.is_por = !is_meta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	if (unlikely(!is_meta))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 		fio.op_flags &= ~REQ_META;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) repeat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	page = f2fs_grab_cache_page(mapping, index, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	if (!page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 		goto repeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	if (PageUptodate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	fio.page = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	err = f2fs_submit_page_bio(&fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 		f2fs_put_page(page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 		return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	f2fs_update_iostat(sbi, FS_META_READ_IO, F2FS_BLKSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	if (unlikely(page->mapping != mapping)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 		f2fs_put_page(page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 		goto repeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	if (unlikely(!PageUptodate(page))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		f2fs_put_page(page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 		return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 	return __get_meta_page(sbi, index, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	page = __get_meta_page(sbi, index, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		if (PTR_ERR(page) == -EIO &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 				++count <= DEFAULT_RETRY_IO_COUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 			goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 		f2fs_stop_checkpoint(sbi, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) /* for POR only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	return __get_meta_page(sbi, index, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 							int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	struct seg_entry *se;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	unsigned int segno, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	bool exist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	if (type != DATA_GENERIC_ENHANCE && type != DATA_GENERIC_ENHANCE_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	segno = GET_SEGNO(sbi, blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	se = get_seg_entry(sbi, segno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	exist = f2fs_test_bit(offset, se->cur_valid_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	if (!exist && type == DATA_GENERIC_ENHANCE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 			 blkaddr, exist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		set_sbi_flag(sbi, SBI_NEED_FSCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	return exist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 					block_t blkaddr, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	case META_NAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	case META_SIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 		if (unlikely(blkaddr >= SIT_BLK_CNT(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	case META_SSA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 		if (unlikely(blkaddr >= MAIN_BLKADDR(sbi) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 			blkaddr < SM_I(sbi)->ssa_blkaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	case META_CP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		if (unlikely(blkaddr >= SIT_I(sbi)->sit_base_addr ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 			blkaddr < __start_cp_addr(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	case META_POR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 			blkaddr < MAIN_BLKADDR(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	case DATA_GENERIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	case DATA_GENERIC_ENHANCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	case DATA_GENERIC_ENHANCE_READ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 				blkaddr < MAIN_BLKADDR(sbi))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 			f2fs_warn(sbi, "access invalid blkaddr:%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 				  blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 			set_sbi_flag(sbi, SBI_NEED_FSCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 			WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 			return __is_bitmap_valid(sbi, blkaddr, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	case META_GENERIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		if (unlikely(blkaddr < SEG0_BLKADDR(sbi) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 			blkaddr >= MAIN_BLKADDR(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210)  * Readahead CP/NAT/SIT/SSA/POR pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 							int type, bool sync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	block_t blkno = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	struct f2fs_io_info fio = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		.sbi = sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		.type = META,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		.op = REQ_OP_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		.op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 		.encrypted_page = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		.in_list = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		.is_por = (type == META_POR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	struct blk_plug plug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	if (unlikely(type == META_POR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 		fio.op_flags &= ~REQ_META;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	blk_start_plug(&plug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	for (; nrpages-- > 0; blkno++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		if (!f2fs_is_valid_blkaddr(sbi, blkno, type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		case META_NAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 			if (unlikely(blkno >=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 					NAT_BLOCK_OFFSET(NM_I(sbi)->max_nid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 				blkno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 			/* get nat block addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 			fio.new_blkaddr = current_nat_addr(sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 					blkno * NAT_ENTRY_PER_BLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		case META_SIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 			if (unlikely(blkno >= TOTAL_SEGS(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 			/* get sit block addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 			fio.new_blkaddr = current_sit_addr(sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 					blkno * SIT_ENTRY_PER_BLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		case META_SSA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		case META_CP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		case META_POR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 			fio.new_blkaddr = blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		page = f2fs_grab_cache_page(META_MAPPING(sbi),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 						fio.new_blkaddr, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 		if (PageUptodate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 			f2fs_put_page(page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		fio.page = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		err = f2fs_submit_page_bio(&fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		f2fs_put_page(page, err ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			f2fs_update_iostat(sbi, FS_META_READ_IO, F2FS_BLKSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	blk_finish_plug(&plug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	return blkno - start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	bool readahead = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	page = find_get_page(META_MAPPING(sbi), index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	if (!page || !PageUptodate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		readahead = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	f2fs_put_page(page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	if (readahead)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		f2fs_ra_meta_pages(sbi, index, BIO_MAX_PAGES, META_POR, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) static int __f2fs_write_meta_page(struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 				struct writeback_control *wbc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 				enum iostat_type io_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	struct f2fs_sb_info *sbi = F2FS_P_SB(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	trace_f2fs_writepage(page, META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		goto redirty_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		goto redirty_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	if (wbc->for_reclaim && page->index < GET_SUM_BLOCK(sbi, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		goto redirty_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	f2fs_do_write_meta_page(sbi, page, io_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	dec_page_count(sbi, F2FS_DIRTY_META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	if (wbc->for_reclaim)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		f2fs_submit_merged_write_cond(sbi, NULL, page, 0, META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		f2fs_submit_merged_write(sbi, META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) redirty_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	redirty_page_for_writepage(wbc, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	return AOP_WRITEPAGE_ACTIVATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) static int f2fs_write_meta_page(struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 				struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	return __f2fs_write_meta_page(page, wbc, FS_META_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) static int f2fs_write_meta_pages(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 				struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	struct f2fs_sb_info *sbi = F2FS_M_SB(mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	long diff, written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		goto skip_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	/* collect a number of dirty meta pages and write together */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	if (wbc->sync_mode != WB_SYNC_ALL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			get_pages(sbi, F2FS_DIRTY_META) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 					nr_pages_to_skip(sbi, META))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		goto skip_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	/* if locked failed, cp will flush dirty pages instead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	if (!f2fs_down_write_trylock(&sbi->cp_global_sem))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		goto skip_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	trace_f2fs_writepages(mapping->host, wbc, META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	diff = nr_pages_to_write(sbi, META, wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	written = f2fs_sync_meta_pages(sbi, META, wbc->nr_to_write, FS_META_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	f2fs_up_write(&sbi->cp_global_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	wbc->nr_to_write = max((long)0, wbc->nr_to_write - written - diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) skip_write:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	wbc->pages_skipped += get_pages(sbi, F2FS_DIRTY_META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	trace_f2fs_writepages(mapping->host, wbc, META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 				long nr_to_write, enum iostat_type io_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	struct address_space *mapping = META_MAPPING(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	pgoff_t index = 0, prev = ULONG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	struct pagevec pvec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	long nwritten = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	int nr_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	struct writeback_control wbc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		.for_reclaim = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	struct blk_plug plug;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	pagevec_init(&pvec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	blk_start_plug(&plug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	while ((nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 				PAGECACHE_TAG_DIRTY))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		for (i = 0; i < nr_pages; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			struct page *page = pvec.pages[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			if (prev == ULONG_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 				prev = page->index - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			if (nr_to_write != LONG_MAX && page->index != prev + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 				pagevec_release(&pvec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 				goto stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 			lock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 			if (unlikely(page->mapping != mapping)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) continue_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 				unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 			if (!PageDirty(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 				/* someone wrote it for us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 				goto continue_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 			f2fs_wait_on_page_writeback(page, META, true, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 			if (!clear_page_dirty_for_io(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 				goto continue_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 			if (__f2fs_write_meta_page(page, &wbc, io_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 				unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 			nwritten++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 			prev = page->index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 			if (unlikely(nwritten >= nr_to_write))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		pagevec_release(&pvec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) stop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	if (nwritten)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		f2fs_submit_merged_write(sbi, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	blk_finish_plug(&plug);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	return nwritten;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) static int f2fs_set_meta_page_dirty(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	trace_f2fs_set_page_dirty(page, META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	if (!PageUptodate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	if (!PageDirty(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 		__set_page_dirty_nobuffers(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		inc_page_count(F2FS_P_SB(page), F2FS_DIRTY_META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		set_page_private_reference(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) const struct address_space_operations f2fs_meta_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	.writepage	= f2fs_write_meta_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	.writepages	= f2fs_write_meta_pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	.set_page_dirty	= f2fs_set_meta_page_dirty,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	.invalidatepage = f2fs_invalidate_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	.releasepage	= f2fs_release_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) #ifdef CONFIG_MIGRATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	.migratepage    = f2fs_migrate_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) static void __add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 						unsigned int devidx, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	struct inode_management *im = &sbi->im[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	struct ino_entry *e, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	tmp = f2fs_kmem_cache_alloc(ino_entry_slab, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	spin_lock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	e = radix_tree_lookup(&im->ino_root, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	if (!e) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		e = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		if (unlikely(radix_tree_insert(&im->ino_root, ino, e)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 			f2fs_bug_on(sbi, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		memset(e, 0, sizeof(struct ino_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		e->ino = ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		list_add_tail(&e->list, &im->ino_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		if (type != ORPHAN_INO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			im->ino_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	if (type == FLUSH_INO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		f2fs_set_bit(devidx, (char *)&e->dirty_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	spin_unlock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	radix_tree_preload_end();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	if (e != tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		kmem_cache_free(ino_entry_slab, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) static void __remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	struct inode_management *im = &sbi->im[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	struct ino_entry *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	spin_lock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	e = radix_tree_lookup(&im->ino_root, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	if (e) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		list_del(&e->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		radix_tree_delete(&im->ino_root, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		im->ino_num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		spin_unlock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		kmem_cache_free(ino_entry_slab, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	spin_unlock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	/* add new dirty ino entry into list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	__add_ino_entry(sbi, ino, 0, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	/* remove dirty ino entry from list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	__remove_ino_entry(sbi, ino, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) /* mode should be APPEND_INO, UPDATE_INO or TRANS_DIR_INO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	struct inode_management *im = &sbi->im[mode];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	struct ino_entry *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	spin_lock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	e = radix_tree_lookup(&im->ino_root, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	spin_unlock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	return e ? true : false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	struct ino_entry *e, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	for (i = all ? ORPHAN_INO : APPEND_INO; i < MAX_INO_ENTRY; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		struct inode_management *im = &sbi->im[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		spin_lock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		list_for_each_entry_safe(e, tmp, &im->ino_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 			list_del(&e->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 			radix_tree_delete(&im->ino_root, e->ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 			kmem_cache_free(ino_entry_slab, e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 			im->ino_num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		spin_unlock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 					unsigned int devidx, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	__add_ino_entry(sbi, ino, devidx, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 					unsigned int devidx, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	struct inode_management *im = &sbi->im[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	struct ino_entry *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	bool is_dirty = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	spin_lock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	e = radix_tree_lookup(&im->ino_root, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	if (e && f2fs_test_bit(devidx, (char *)&e->dirty_device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		is_dirty = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	spin_unlock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	return is_dirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	struct inode_management *im = &sbi->im[ORPHAN_INO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	spin_lock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	if (time_to_inject(sbi, FAULT_ORPHAN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		spin_unlock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		f2fs_show_injection_info(sbi, FAULT_ORPHAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	if (unlikely(im->ino_num >= sbi->max_orphans))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		err = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		im->ino_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	spin_unlock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	struct inode_management *im = &sbi->im[ORPHAN_INO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	spin_lock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	f2fs_bug_on(sbi, im->ino_num == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	im->ino_num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	spin_unlock(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) void f2fs_add_orphan_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	/* add new orphan ino entry into list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	__add_ino_entry(F2FS_I_SB(inode), inode->i_ino, 0, ORPHAN_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	f2fs_update_inode_page(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	/* remove orphan entry from orphan list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	__remove_ino_entry(sbi, ino, ORPHAN_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	struct node_info ni;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	inode = f2fs_iget_retry(sbi->sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		 * there should be a bug that we can't find the entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		 * to orphan inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		f2fs_bug_on(sbi, PTR_ERR(inode) == -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	err = dquot_initialize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	clear_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	/* truncate all the data during iput */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	err = f2fs_get_node_info(sbi, ino, &ni, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	/* ENOMEM was fully retried in f2fs_evict_inode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	if (ni.blk_addr != NULL_ADDR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	set_sbi_flag(sbi, SBI_NEED_FSCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	f2fs_warn(sbi, "%s: orphan failed (ino=%x), run fsck to fix.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		  __func__, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	block_t start_blk, orphan_blocks, i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	unsigned int s_flags = sbi->sb->s_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	int quota_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	if (!is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	if (bdev_read_only(sbi->sb->s_bdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		f2fs_info(sbi, "write access unavailable, skipping orphan cleanup");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	if (s_flags & SB_RDONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		f2fs_info(sbi, "orphan cleanup on readonly fs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		sbi->sb->s_flags &= ~SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	/* Needed for iput() to work correctly and not trash data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	sbi->sb->s_flags |= SB_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	 * Turn on quotas which were not enabled for read-only mounts if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	 * filesystem has quota feature, so that they are updated correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	quota_enabled = f2fs_enable_quota_files(sbi, s_flags & SB_RDONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	start_blk = __start_cp_addr(sbi) + 1 + __cp_payload(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	orphan_blocks = __start_sum_addr(sbi) - 1 - __cp_payload(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	f2fs_ra_meta_pages(sbi, start_blk, orphan_blocks, META_CP, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	for (i = 0; i < orphan_blocks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		struct f2fs_orphan_block *orphan_blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		page = f2fs_get_meta_page(sbi, start_blk + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 			err = PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		orphan_blk = (struct f2fs_orphan_block *)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		for (j = 0; j < le32_to_cpu(orphan_blk->entry_count); j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 			nid_t ino = le32_to_cpu(orphan_blk->ino[j]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 			err = recover_orphan_inode(sbi, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 			if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 				f2fs_put_page(page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 		f2fs_put_page(page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	/* clear Orphan Flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	clear_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	set_sbi_flag(sbi, SBI_IS_RECOVERED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	/* Turn quotas off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	if (quota_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		f2fs_quota_off_umount(sbi->sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	sbi->sb->s_flags = s_flags; /* Restore SB_RDONLY status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	struct f2fs_orphan_block *orphan_blk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	unsigned int nentries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	unsigned short index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	unsigned short orphan_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	struct ino_entry *orphan = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	struct inode_management *im = &sbi->im[ORPHAN_INO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	orphan_blocks = GET_ORPHAN_BLOCKS(im->ino_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	 * we don't need to do spin_lock(&im->ino_lock) here, since all the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	 * orphan inode operations are covered under f2fs_lock_op().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	 * And, spin_lock should be avoided due to page operations below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	head = &im->ino_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	/* loop for each orphan inode entry and write them in Jornal block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	list_for_each_entry(orphan, head, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		if (!page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 			page = f2fs_grab_meta_page(sbi, start_blk++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 			orphan_blk =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 				(struct f2fs_orphan_block *)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 			memset(orphan_blk, 0, sizeof(*orphan_blk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		orphan_blk->ino[nentries++] = cpu_to_le32(orphan->ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		if (nentries == F2FS_ORPHANS_PER_BLOCK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 			 * an orphan block is full of 1020 entries,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			 * then we need to flush current orphan blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 			 * and bring another one in memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 			orphan_blk->blk_addr = cpu_to_le16(index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 			orphan_blk->blk_count = cpu_to_le16(orphan_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 			orphan_blk->entry_count = cpu_to_le32(nentries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 			set_page_dirty(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 			f2fs_put_page(page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 			index++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 			nentries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 			page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		orphan_blk->blk_addr = cpu_to_le16(index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		orphan_blk->blk_count = cpu_to_le16(orphan_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 		orphan_blk->entry_count = cpu_to_le32(nentries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		set_page_dirty(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		f2fs_put_page(page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) static __u32 f2fs_checkpoint_chksum(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 						struct f2fs_checkpoint *ckpt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	unsigned int chksum_ofs = le32_to_cpu(ckpt->checksum_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	__u32 chksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	chksum = f2fs_crc32(sbi, ckpt, chksum_ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	if (chksum_ofs < CP_CHKSUM_OFFSET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		chksum_ofs += sizeof(chksum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		chksum = f2fs_chksum(sbi, chksum, (__u8 *)ckpt + chksum_ofs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 						F2FS_BLKSIZE - chksum_ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	return chksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		struct f2fs_checkpoint **cp_block, struct page **cp_page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		unsigned long long *version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	size_t crc_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	__u32 crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	*cp_page = f2fs_get_meta_page(sbi, cp_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	if (IS_ERR(*cp_page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		return PTR_ERR(*cp_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	*cp_block = (struct f2fs_checkpoint *)page_address(*cp_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	crc_offset = le32_to_cpu((*cp_block)->checksum_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	if (crc_offset < CP_MIN_CHKSUM_OFFSET ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 			crc_offset > CP_CHKSUM_OFFSET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		f2fs_put_page(*cp_page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		f2fs_warn(sbi, "invalid crc_offset: %zu", crc_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	crc = f2fs_checkpoint_chksum(sbi, *cp_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	if (crc != cur_cp_crc(*cp_block)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		f2fs_put_page(*cp_page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		f2fs_warn(sbi, "invalid crc value");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	*version = cur_cp_version(*cp_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) static struct page *validate_checkpoint(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 				block_t cp_addr, unsigned long long *version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	struct page *cp_page_1 = NULL, *cp_page_2 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	struct f2fs_checkpoint *cp_block = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	unsigned long long cur_version = 0, pre_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	unsigned int cp_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	err = get_checkpoint_version(sbi, cp_addr, &cp_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 					&cp_page_1, version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	cp_blocks = le32_to_cpu(cp_block->cp_pack_total_block_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	if (cp_blocks > sbi->blocks_per_seg || cp_blocks <= F2FS_CP_PACKS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		f2fs_warn(sbi, "invalid cp_pack_total_block_count:%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 			  le32_to_cpu(cp_block->cp_pack_total_block_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		goto invalid_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	pre_version = *version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	cp_addr += cp_blocks - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	err = get_checkpoint_version(sbi, cp_addr, &cp_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 					&cp_page_2, version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		goto invalid_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	cur_version = *version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	if (cur_version == pre_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		*version = cur_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		f2fs_put_page(cp_page_2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		return cp_page_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	f2fs_put_page(cp_page_2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) invalid_cp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	f2fs_put_page(cp_page_1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	struct f2fs_checkpoint *cp_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	struct f2fs_super_block *fsb = sbi->raw_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	struct page *cp1, *cp2, *cur_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	unsigned long blk_size = sbi->blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	unsigned long long cp1_version = 0, cp2_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	unsigned long long cp_start_blk_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	unsigned int cp_blks = 1 + __cp_payload(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	block_t cp_blk_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	sbi->ckpt = f2fs_kvzalloc(sbi, array_size(blk_size, cp_blks),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 				  GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	if (!sbi->ckpt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	 * Finding out valid cp block involves read both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	 * sets( cp pack 1 and cp pack 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	cp_start_blk_no = le32_to_cpu(fsb->cp_blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	cp1 = validate_checkpoint(sbi, cp_start_blk_no, &cp1_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	/* The second checkpoint pack should start at the next segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	cp_start_blk_no += ((unsigned long long)1) <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 				le32_to_cpu(fsb->log_blocks_per_seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	cp2 = validate_checkpoint(sbi, cp_start_blk_no, &cp2_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	if (cp1 && cp2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		if (ver_after(cp2_version, cp1_version))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 			cur_page = cp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			cur_page = cp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	} else if (cp1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		cur_page = cp1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	} else if (cp2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		cur_page = cp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		err = -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		goto fail_no_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	cp_block = (struct f2fs_checkpoint *)page_address(cur_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	memcpy(sbi->ckpt, cp_block, blk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	if (cur_page == cp1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		sbi->cur_cp_pack = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		sbi->cur_cp_pack = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	/* Sanity checking of checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	if (f2fs_sanity_check_ckpt(sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		err = -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 		goto free_fail_no_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	if (cp_blks <= 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	cp_blk_no = le32_to_cpu(fsb->cp_blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	if (cur_page == cp2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		cp_blk_no += 1 << le32_to_cpu(fsb->log_blocks_per_seg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	for (i = 1; i < cp_blks; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		void *sit_bitmap_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		unsigned char *ckpt = (unsigned char *)sbi->ckpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		cur_page = f2fs_get_meta_page(sbi, cp_blk_no + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		if (IS_ERR(cur_page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 			err = PTR_ERR(cur_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			goto free_fail_no_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		sit_bitmap_ptr = page_address(cur_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		memcpy(ckpt + i * blk_size, sit_bitmap_ptr, blk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		f2fs_put_page(cur_page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	f2fs_put_page(cp1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	f2fs_put_page(cp2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) free_fail_no_cp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	f2fs_put_page(cp1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	f2fs_put_page(cp2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) fail_no_cp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	kvfree(sbi->ckpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) static void __add_dirty_inode(struct inode *inode, enum inode_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	int flag = (type == DIR_INODE) ? FI_DIRTY_DIR : FI_DIRTY_FILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	if (is_inode_flag_set(inode, flag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	set_inode_flag(inode, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	if (!f2fs_is_volatile_file(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		list_add_tail(&F2FS_I(inode)->dirty_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 						&sbi->inode_list[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	stat_inc_dirty_inode(sbi, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) static void __remove_dirty_inode(struct inode *inode, enum inode_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	int flag = (type == DIR_INODE) ? FI_DIRTY_DIR : FI_DIRTY_FILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	if (get_dirty_pages(inode) || !is_inode_flag_set(inode, flag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	list_del_init(&F2FS_I(inode)->dirty_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	clear_inode_flag(inode, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	stat_dec_dirty_inode(F2FS_I_SB(inode), type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) void f2fs_update_dirty_page(struct inode *inode, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 			!S_ISLNK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	spin_lock(&sbi->inode_lock[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	if (type != FILE_INODE || test_opt(sbi, DATA_FLUSH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 		__add_dirty_inode(inode, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	inode_inc_dirty_pages(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	spin_unlock(&sbi->inode_lock[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	set_page_private_reference(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) void f2fs_remove_dirty_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	enum inode_type type = S_ISDIR(inode->i_mode) ? DIR_INODE : FILE_INODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 			!S_ISLNK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	if (type == FILE_INODE && !test_opt(sbi, DATA_FLUSH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	spin_lock(&sbi->inode_lock[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	__remove_dirty_inode(inode, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	spin_unlock(&sbi->inode_lock[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	struct f2fs_inode_info *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	bool is_dir = (type == DIR_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	unsigned long ino = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	trace_f2fs_sync_dirty_inodes_enter(sbi->sb, is_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 				get_pages(sbi, is_dir ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	if (unlikely(f2fs_cp_error(sbi))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		trace_f2fs_sync_dirty_inodes_exit(sbi->sb, is_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 				get_pages(sbi, is_dir ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	spin_lock(&sbi->inode_lock[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	head = &sbi->inode_list[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	if (list_empty(head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		spin_unlock(&sbi->inode_lock[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		trace_f2fs_sync_dirty_inodes_exit(sbi->sb, is_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 				get_pages(sbi, is_dir ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	fi = list_first_entry(head, struct f2fs_inode_info, dirty_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	inode = igrab(&fi->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	spin_unlock(&sbi->inode_lock[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 		unsigned long cur_ino = inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		F2FS_I(inode)->cp_task = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		filemap_fdatawrite(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		F2FS_I(inode)->cp_task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		/* We need to give cpu to another writers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		if (ino == cur_ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 			cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 			ino = cur_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		 * We should submit bio, since it exists several
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		 * wribacking dentry pages in the freeing inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		f2fs_submit_merged_write(sbi, DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	struct list_head *head = &sbi->inode_list[DIRTY_META];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	struct f2fs_inode_info *fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	s64 total = get_pages(sbi, F2FS_DIRTY_IMETA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	while (total--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		spin_lock(&sbi->inode_lock[DIRTY_META]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 		if (list_empty(head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 			spin_unlock(&sbi->inode_lock[DIRTY_META]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		fi = list_first_entry(head, struct f2fs_inode_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 							gdirty_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		inode = igrab(&fi->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		spin_unlock(&sbi->inode_lock[DIRTY_META]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 		if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 			sync_inode_metadata(inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 			/* it's on eviction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 			if (is_inode_flag_set(inode, FI_DIRTY_INODE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 				f2fs_update_inode_page(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 			iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) static void __prepare_cp_block(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	struct f2fs_nm_info *nm_i = NM_I(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	nid_t last_nid = nm_i->next_scan_nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	next_free_nid(sbi, &last_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	ckpt->valid_node_count = cpu_to_le32(valid_node_count(sbi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	ckpt->valid_inode_count = cpu_to_le32(valid_inode_count(sbi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	ckpt->next_free_nid = cpu_to_le32(last_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) static bool __need_flush_quota(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	if (!is_journalled_quota(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	if (!f2fs_down_write_trylock(&sbi->quota_sem))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	} else if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	} else if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_FLUSH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 		clear_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 		ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	} else if (get_pages(sbi, F2FS_DIRTY_QDATA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 		ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	f2fs_up_write(&sbi->quota_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)  * Freeze all the FS-operations for checkpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) static int block_operations(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	struct writeback_control wbc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 		.sync_mode = WB_SYNC_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		.nr_to_write = LONG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		.for_reclaim = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	int err = 0, cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	 * Let's flush inline_data in dirty node pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	f2fs_flush_inline_data(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) retry_flush_quotas:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	f2fs_lock_all(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	if (__need_flush_quota(sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		int locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 		if (++cnt > DEFAULT_RETRY_QUOTA_FLUSH_COUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 			set_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 			set_sbi_flag(sbi, SBI_QUOTA_NEED_FLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 			goto retry_flush_dents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 		f2fs_unlock_all(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 		/* only failed during mount/umount/freeze/quotactl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		locked = down_read_trylock(&sbi->sb->s_umount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		f2fs_quota_sync(sbi->sb, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		if (locked)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 			up_read(&sbi->sb->s_umount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		goto retry_flush_quotas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) retry_flush_dents:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	/* write all the dirty dentry pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	if (get_pages(sbi, F2FS_DIRTY_DENTS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		f2fs_unlock_all(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		err = f2fs_sync_dirty_inodes(sbi, DIR_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 		goto retry_flush_quotas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	 * POR: we should ensure that there are no dirty node pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	 * until finishing nat/sit flush. inode->i_blocks can be updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	f2fs_down_write(&sbi->node_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	if (get_pages(sbi, F2FS_DIRTY_IMETA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 		f2fs_up_write(&sbi->node_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 		f2fs_unlock_all(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 		err = f2fs_sync_inode_meta(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 		goto retry_flush_quotas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) retry_flush_nodes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	f2fs_down_write(&sbi->node_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	if (get_pages(sbi, F2FS_DIRTY_NODES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 		f2fs_up_write(&sbi->node_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 		atomic_inc(&sbi->wb_sync_req[NODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		err = f2fs_sync_node_pages(sbi, &wbc, false, FS_CP_NODE_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 		atomic_dec(&sbi->wb_sync_req[NODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 		if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 			f2fs_up_write(&sbi->node_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 			f2fs_unlock_all(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 		goto retry_flush_nodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	 * sbi->node_change is used only for AIO write_begin path which produces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	 * dirty node blocks and some checkpoint values by block allocation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	__prepare_cp_block(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	f2fs_up_write(&sbi->node_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) static void unblock_operations(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	f2fs_up_write(&sbi->node_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	f2fs_unlock_all(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 	for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 		if (!get_pages(sbi, type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		if (unlikely(f2fs_cp_error(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		if (type == F2FS_DIRTY_META)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 			f2fs_sync_meta_pages(sbi, META, LONG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 							FS_CP_META_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		else if (type == F2FS_WB_CP_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 			f2fs_submit_merged_write(sbi, DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		prepare_to_wait(&sbi->cp_wait, &wait, TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 		io_schedule_timeout(DEFAULT_IO_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	finish_wait(&sbi->cp_wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	spin_lock_irqsave(&sbi->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	if ((cpc->reason & CP_UMOUNT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 			le32_to_cpu(ckpt->cp_pack_total_block_count) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 			sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 		disable_nat_bits(sbi, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	if (cpc->reason & CP_TRIMMED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		__set_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 		__clear_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	if (cpc->reason & CP_UMOUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		__set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		__clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	if (cpc->reason & CP_FASTBOOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		__set_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		__clear_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 	if (orphan_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		__set_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 		__clear_ckpt_flags(ckpt, CP_ORPHAN_PRESENT_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	if (is_sbi_flag_set(sbi, SBI_NEED_FSCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		__set_ckpt_flags(ckpt, CP_FSCK_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	if (is_sbi_flag_set(sbi, SBI_IS_RESIZEFS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 		__set_ckpt_flags(ckpt, CP_RESIZEFS_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		__clear_ckpt_flags(ckpt, CP_RESIZEFS_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	if (is_sbi_flag_set(sbi, SBI_CP_DISABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 		__set_ckpt_flags(ckpt, CP_DISABLED_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		__clear_ckpt_flags(ckpt, CP_DISABLED_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	if (is_sbi_flag_set(sbi, SBI_CP_DISABLED_QUICK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 		__set_ckpt_flags(ckpt, CP_DISABLED_QUICK_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		__clear_ckpt_flags(ckpt, CP_DISABLED_QUICK_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	if (is_sbi_flag_set(sbi, SBI_QUOTA_SKIP_FLUSH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 		__set_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 		__clear_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	if (is_sbi_flag_set(sbi, SBI_QUOTA_NEED_REPAIR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		__set_ckpt_flags(ckpt, CP_QUOTA_NEED_FSCK_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	/* set this flag to activate crc|cp_ver for recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	__set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	__clear_ckpt_flags(ckpt, CP_NOCRC_RECOVERY_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	spin_unlock_irqrestore(&sbi->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) static void commit_checkpoint(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	void *src, block_t blk_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	struct writeback_control wbc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		.for_reclaim = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	 * pagevec_lookup_tag and lock_page again will take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	 * some extra time. Therefore, f2fs_update_meta_pages and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	 * f2fs_sync_meta_pages are combined in this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	struct page *page = f2fs_grab_meta_page(sbi, blk_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	f2fs_wait_on_page_writeback(page, META, true, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	memcpy(page_address(page), src, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	set_page_dirty(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	if (unlikely(!clear_page_dirty_for_io(page)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 		f2fs_bug_on(sbi, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 	/* writeout cp pack 2 page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	err = __f2fs_write_meta_page(page, &wbc, FS_CP_META_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	if (unlikely(err && f2fs_cp_error(sbi))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 		f2fs_put_page(page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	f2fs_bug_on(sbi, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	f2fs_put_page(page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	/* submit checkpoint (with barrier if NOBARRIER is not set) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	f2fs_submit_merged_write(sbi, META_FLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) static inline u64 get_sectors_written(struct block_device *bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	return (u64)part_stat_read(bdev->bd_part, sectors[STAT_WRITE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) u64 f2fs_get_sectors_written(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	if (f2fs_is_multi_device(sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		u64 sectors = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		for (i = 0; i < sbi->s_ndevs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 			sectors += get_sectors_written(FDEV(i).bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		return sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	return get_sectors_written(sbi->sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	struct f2fs_nm_info *nm_i = NM_I(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	block_t start_blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	unsigned int data_sum_blocks, orphan_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	__u32 crc32 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	int cp_payload_blks = __cp_payload(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	struct curseg_info *seg_i = CURSEG_I(sbi, CURSEG_HOT_NODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	u64 kbytes_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	/* Flush all the NAT/SIT pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	/* start to update checkpoint, cp ver is already updated previously */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi, true));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	ckpt->free_segment_count = cpu_to_le32(free_segments(sbi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 		ckpt->cur_node_segno[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 			cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		ckpt->cur_node_blkoff[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 			cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_NODE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 		ckpt->alloc_type[i + CURSEG_HOT_NODE] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 				curseg_alloc_type(sbi, i + CURSEG_HOT_NODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 		ckpt->cur_data_segno[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 			cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		ckpt->cur_data_blkoff[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 			cpu_to_le16(curseg_blkoff(sbi, i + CURSEG_HOT_DATA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		ckpt->alloc_type[i + CURSEG_HOT_DATA] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 				curseg_alloc_type(sbi, i + CURSEG_HOT_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	/* 2 cp + n data seg summary + orphan inode blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	data_sum_blocks = f2fs_npages_for_summary_flush(sbi, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	spin_lock_irqsave(&sbi->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	if (data_sum_blocks < NR_CURSEG_DATA_TYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 		__set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 		__clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	spin_unlock_irqrestore(&sbi->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	orphan_blocks = GET_ORPHAN_BLOCKS(orphan_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 			orphan_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	if (__remain_node_summaries(cpc->reason))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 		ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 				cp_payload_blks + data_sum_blocks +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 				orphan_blocks + NR_CURSEG_NODE_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 				cp_payload_blks + data_sum_blocks +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 				orphan_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	/* update ckpt flag for checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	update_ckpt_flags(sbi, cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	/* update SIT/NAT bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	get_sit_bitmap(sbi, __bitmap_ptr(sbi, SIT_BITMAP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	get_nat_bitmap(sbi, __bitmap_ptr(sbi, NAT_BITMAP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 	crc32 = f2fs_checkpoint_chksum(sbi, ckpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	*((__le32 *)((unsigned char *)ckpt +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 				le32_to_cpu(ckpt->checksum_offset)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 				= cpu_to_le32(crc32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	start_blk = __start_cp_next_addr(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	/* write nat bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	if (enabled_nat_bits(sbi, cpc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 		__u64 cp_ver = cur_cp_version(ckpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 		block_t blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 		cp_ver |= ((__u64)crc32 << 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 		*(__le64 *)nm_i->nat_bits = cpu_to_le64(cp_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 		blk = start_blk + sbi->blocks_per_seg - nm_i->nat_bits_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 		for (i = 0; i < nm_i->nat_bits_blocks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 			f2fs_update_meta_page(sbi, nm_i->nat_bits +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 					(i << F2FS_BLKSIZE_BITS), blk + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	/* write out checkpoint buffer at block 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	f2fs_update_meta_page(sbi, ckpt, start_blk++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	for (i = 1; i < 1 + cp_payload_blks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		f2fs_update_meta_page(sbi, (char *)ckpt + i * F2FS_BLKSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 							start_blk++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	if (orphan_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 		write_orphan_inodes(sbi, start_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 		start_blk += orphan_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	f2fs_write_data_summaries(sbi, start_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	start_blk += data_sum_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	/* Record write statistics in the hot node summary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	kbytes_written = sbi->kbytes_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	kbytes_written += (f2fs_get_sectors_written(sbi) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 				sbi->sectors_written_start) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	seg_i->journal->info.kbytes_written = cpu_to_le64(kbytes_written);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	if (__remain_node_summaries(cpc->reason)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 		f2fs_write_node_summaries(sbi, start_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 		start_blk += NR_CURSEG_NODE_TYPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	/* update user_block_counts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	sbi->last_valid_block_count = sbi->total_valid_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	percpu_counter_set(&sbi->alloc_valid_block_count, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	/* Here, we have one bio having CP pack except cp pack 2 page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_CP_META_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	/* Wait for all dirty meta pages to be submitted for IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	f2fs_wait_on_all_pages(sbi, F2FS_DIRTY_META);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 	/* wait for previous submitted meta pages writeback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	/* flush all device cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	err = f2fs_flush_device_cache(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	/* barrier and flush checkpoint cp pack 2 page if it can */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	commit_checkpoint(sbi, ckpt, start_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	 * invalidate intermediate page cache borrowed from meta inode which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	 * used for migration of encrypted, verity or compressed inode's blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	if (f2fs_sb_has_encrypt(sbi) || f2fs_sb_has_verity(sbi) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 		f2fs_sb_has_compression(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 		invalidate_mapping_pages(META_MAPPING(sbi),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 				MAIN_BLKADDR(sbi), MAX_BLKADDR(sbi) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	f2fs_release_ino_entry(sbi, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	f2fs_reset_fsync_node_info(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	clear_sbi_flag(sbi, SBI_IS_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	clear_sbi_flag(sbi, SBI_NEED_CP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	clear_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	spin_lock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	sbi->unusable_block_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	spin_unlock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	__set_cp_next_pack(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	 * redirty superblock if metadata like node page or inode cache is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	 * updated during writing checkpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	if (get_pages(sbi, F2FS_DIRTY_NODES) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 			get_pages(sbi, F2FS_DIRTY_IMETA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		set_sbi_flag(sbi, SBI_IS_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	f2fs_bug_on(sbi, get_pages(sbi, F2FS_DIRTY_DENTS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	return unlikely(f2fs_cp_error(sbi)) ? -EIO : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	unsigned long long ckpt_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	if (f2fs_readonly(sbi->sb) || f2fs_hw_is_readonly(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 		return -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 		if (cpc->reason != CP_PAUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 		f2fs_warn(sbi, "Start checkpoint disabled!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 	if (cpc->reason != CP_RESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 		f2fs_down_write(&sbi->cp_global_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 		((cpc->reason & CP_FASTBOOT) || (cpc->reason & CP_SYNC) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 		((cpc->reason & CP_DISCARD) && !sbi->discard_blks)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	if (unlikely(f2fs_cp_error(sbi))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "start block_ops");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	err = block_operations(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish block_ops");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	f2fs_flush_merged_writes(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	/* this is the case of multiple fstrims without any changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	if (cpc->reason & CP_DISCARD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 		if (!f2fs_exist_trim_candidates(sbi, cpc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 			unblock_operations(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 		if (NM_I(sbi)->nat_cnt[DIRTY_NAT] == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 				SIT_I(sbi)->dirty_sentries == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 				prefree_segments(sbi) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 			f2fs_flush_sit_entries(sbi, cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 			f2fs_clear_prefree_segments(sbi, cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 			unblock_operations(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	 * update checkpoint pack index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	 * Increase the version number so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	 * SIT entries and seg summaries are written at correct place
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	ckpt_ver = cur_cp_version(ckpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	ckpt->checkpoint_ver = cpu_to_le64(++ckpt_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	/* write cached NAT/SIT entries to NAT/SIT area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	err = f2fs_flush_nat_entries(sbi, cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 		goto stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	f2fs_flush_sit_entries(sbi, cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	/* save inmem log status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	f2fs_save_inmem_curseg(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	err = do_checkpoint(sbi, cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		f2fs_release_discard_addrs(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 		f2fs_clear_prefree_segments(sbi, cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	f2fs_restore_inmem_curseg(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) stop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	unblock_operations(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	stat_inc_cp_count(sbi->stat_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	if (cpc->reason & CP_RECOVERY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 		f2fs_notice(sbi, "checkpoint: version = %llx", ckpt_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	/* update CP_TIME to trigger checkpoint periodically */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	f2fs_update_time(sbi, CP_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish checkpoint");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	if (cpc->reason != CP_RESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 		f2fs_up_write(&sbi->cp_global_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	for (i = 0; i < MAX_INO_ENTRY; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		struct inode_management *im = &sbi->im[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 		INIT_RADIX_TREE(&im->ino_root, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 		spin_lock_init(&im->ino_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		INIT_LIST_HEAD(&im->ino_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 		im->ino_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	sbi->max_orphans = (sbi->blocks_per_seg - F2FS_CP_PACKS -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 			NR_CURSEG_PERSIST_TYPE - __cp_payload(sbi)) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 				F2FS_ORPHANS_PER_BLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) int __init f2fs_create_checkpoint_caches(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	ino_entry_slab = f2fs_kmem_cache_create("f2fs_ino_entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 			sizeof(struct ino_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	if (!ino_entry_slab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	f2fs_inode_entry_slab = f2fs_kmem_cache_create("f2fs_inode_entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 			sizeof(struct inode_entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	if (!f2fs_inode_entry_slab) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 		kmem_cache_destroy(ino_entry_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) void f2fs_destroy_checkpoint_caches(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	kmem_cache_destroy(ino_entry_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	kmem_cache_destroy(f2fs_inode_entry_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) static int __write_checkpoint_sync(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	struct cp_control cpc = { .reason = CP_SYNC, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	f2fs_down_write(&sbi->gc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	err = f2fs_write_checkpoint(sbi, &cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	f2fs_up_write(&sbi->gc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) static void __checkpoint_and_complete_reqs(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	struct ckpt_req_control *cprc = &sbi->cprc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	struct ckpt_req *req, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	struct llist_node *dispatch_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	u64 sum_diff = 0, diff, count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	dispatch_list = llist_del_all(&cprc->issue_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 	if (!dispatch_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 	dispatch_list = llist_reverse_order(dispatch_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 	ret = __write_checkpoint_sync(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	atomic_inc(&cprc->issued_ckpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	llist_for_each_entry_safe(req, next, dispatch_list, llnode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 		diff = (u64)ktime_ms_delta(ktime_get(), req->queue_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 		req->ret = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		complete(&req->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 		sum_diff += diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	atomic_sub(count, &cprc->queued_ckpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	atomic_add(count, &cprc->total_ckpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	spin_lock(&cprc->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	cprc->cur_time = (unsigned int)div64_u64(sum_diff, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	if (cprc->peak_time < cprc->cur_time)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 		cprc->peak_time = cprc->cur_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	spin_unlock(&cprc->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) static int issue_checkpoint_thread(void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	struct f2fs_sb_info *sbi = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	struct ckpt_req_control *cprc = &sbi->cprc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	wait_queue_head_t *q = &cprc->ckpt_wait_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) repeat:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	if (kthread_should_stop())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	if (!llist_empty(&cprc->issue_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 		__checkpoint_and_complete_reqs(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	wait_event_interruptible(*q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 		kthread_should_stop() || !llist_empty(&cprc->issue_list));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	goto repeat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) static void flush_remained_ckpt_reqs(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 		struct ckpt_req *wait_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	struct ckpt_req_control *cprc = &sbi->cprc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	if (!llist_empty(&cprc->issue_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 		__checkpoint_and_complete_reqs(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 		/* already dispatched by issue_checkpoint_thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 		if (wait_req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 			wait_for_completion(&wait_req->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) static void init_ckpt_req(struct ckpt_req *req)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	memset(req, 0, sizeof(struct ckpt_req));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	init_completion(&req->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	req->queue_time = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) int f2fs_issue_checkpoint(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	struct ckpt_req_control *cprc = &sbi->cprc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 	struct ckpt_req req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	struct cp_control cpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 	cpc.reason = __get_cp_reason(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	if (!test_opt(sbi, MERGE_CHECKPOINT) || cpc.reason != CP_SYNC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 		int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 		f2fs_down_write(&sbi->gc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 		ret = f2fs_write_checkpoint(sbi, &cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 		f2fs_up_write(&sbi->gc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	if (!cprc->f2fs_issue_ckpt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 		return __write_checkpoint_sync(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	init_ckpt_req(&req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	llist_add(&req.llnode, &cprc->issue_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	atomic_inc(&cprc->queued_ckpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	 * update issue_list before we wake up issue_checkpoint thread,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	 * this smp_mb() pairs with another barrier in ___wait_event(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	 * see more details in comments of waitqueue_active().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	if (waitqueue_active(&cprc->ckpt_wait_queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 		wake_up(&cprc->ckpt_wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	if (cprc->f2fs_issue_ckpt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 		wait_for_completion(&req.wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 		flush_remained_ckpt_reqs(sbi, &req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 	return req.ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	dev_t dev = sbi->sb->s_bdev->bd_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	struct ckpt_req_control *cprc = &sbi->cprc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	if (cprc->f2fs_issue_ckpt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	cprc->f2fs_issue_ckpt = kthread_run(issue_checkpoint_thread, sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 			"f2fs_ckpt-%u:%u", MAJOR(dev), MINOR(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	if (IS_ERR(cprc->f2fs_issue_ckpt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 		cprc->f2fs_issue_ckpt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	set_task_ioprio(cprc->f2fs_issue_ckpt, cprc->ckpt_thread_ioprio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) void f2fs_stop_ckpt_thread(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	struct ckpt_req_control *cprc = &sbi->cprc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 	if (cprc->f2fs_issue_ckpt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 		struct task_struct *ckpt_task = cprc->f2fs_issue_ckpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 		cprc->f2fs_issue_ckpt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 		kthread_stop(ckpt_task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 		flush_remained_ckpt_reqs(sbi, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	struct ckpt_req_control *cprc = &sbi->cprc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 	atomic_set(&cprc->issued_ckpt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	atomic_set(&cprc->total_ckpt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	atomic_set(&cprc->queued_ckpt, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	cprc->ckpt_thread_ioprio = DEFAULT_CHECKPOINT_IOPRIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	init_waitqueue_head(&cprc->ckpt_wait_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	init_llist_head(&cprc->issue_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	spin_lock_init(&cprc->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) }