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/f2fs.h
^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) #ifndef _LINUX_F2FS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #define _LINUX_F2FS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/page-flags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/magic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/kobject.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/cred.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/part_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <crypto/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/fscrypt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/fsverity.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #ifdef CONFIG_F2FS_CHECK_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #define f2fs_bug_on(sbi, condition)	BUG_ON(condition)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #define f2fs_bug_on(sbi, condition)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 		if (WARN_ON(condition))					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 			set_sbi_flag(sbi, SBI_NEED_FSCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	FAULT_KMALLOC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	FAULT_KVMALLOC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	FAULT_PAGE_ALLOC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 	FAULT_PAGE_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	FAULT_ALLOC_NID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	FAULT_ORPHAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	FAULT_BLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	FAULT_DIR_DEPTH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	FAULT_EVICT_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	FAULT_TRUNCATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	FAULT_READ_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	FAULT_CHECKPOINT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	FAULT_DISCARD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	FAULT_WRITE_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 	FAULT_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #ifdef CONFIG_F2FS_FAULT_INJECTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #define F2FS_ALL_FAULT_TYPE		((1 << FAULT_MAX) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) struct f2fs_fault_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	atomic_t inject_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	unsigned int inject_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	unsigned int inject_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) extern const char *f2fs_fault_name[FAULT_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define MIN_ROOT_RESERVED_BLOCKS (128 * 1024 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  * For mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) #define F2FS_MOUNT_DISABLE_ROLL_FORWARD	0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #define F2FS_MOUNT_DISCARD		0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #define F2FS_MOUNT_NOHEAP		0x00000008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) #define F2FS_MOUNT_XATTR_USER		0x00000010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #define F2FS_MOUNT_POSIX_ACL		0x00000020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY	0x00000040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) #define F2FS_MOUNT_INLINE_XATTR		0x00000080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #define F2FS_MOUNT_INLINE_DATA		0x00000100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) #define F2FS_MOUNT_INLINE_DENTRY	0x00000200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) #define F2FS_MOUNT_FLUSH_MERGE		0x00000400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) #define F2FS_MOUNT_NOBARRIER		0x00000800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #define F2FS_MOUNT_FASTBOOT		0x00001000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) #define F2FS_MOUNT_EXTENT_CACHE		0x00002000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) #define F2FS_MOUNT_DATA_FLUSH		0x00008000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #define F2FS_MOUNT_FAULT_INJECTION	0x00010000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) #define F2FS_MOUNT_USRQUOTA		0x00080000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #define F2FS_MOUNT_GRPQUOTA		0x00100000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #define F2FS_MOUNT_PRJQUOTA		0x00200000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) #define F2FS_MOUNT_QUOTA		0x00400000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) #define F2FS_MOUNT_INLINE_XATTR_SIZE	0x00800000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) #define F2FS_MOUNT_RESERVE_ROOT		0x01000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) #define F2FS_MOUNT_DISABLE_CHECKPOINT	0x02000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) #define F2FS_MOUNT_NORECOVERY		0x04000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) #define F2FS_MOUNT_ATGC			0x08000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) #define F2FS_MOUNT_MERGE_CHECKPOINT	0x10000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) #define	F2FS_MOUNT_GC_MERGE		0x20000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #define F2FS_MOUNT_COMPRESS_CACHE	0x40000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) #define F2FS_OPTION(sbi)	((sbi)->mount_opt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) #define clear_opt(sbi, option)	(F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) #define set_opt(sbi, option)	(F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) #define test_opt(sbi, option)	(F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) #define ver_after(a, b)	(typecheck(unsigned long long, a) &&		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		typecheck(unsigned long long, b) &&			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 		((long long)((a) - (b)) > 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) typedef u32 block_t;	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 			 * should not change u32, since it is the on-disk block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 			 * address format, __le32.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) typedef u32 nid_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) #define COMPRESS_EXT_NUM		16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123)  * An implementation of an rwsem that is explicitly unfair to readers. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124)  * prevents priority inversion when a low-priority reader acquires the read lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125)  * while sleeping on the write lock but the write lock is needed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)  * higher-priority clients.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) struct f2fs_rwsem {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130)         struct rw_semaphore internal_rwsem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131)         wait_queue_head_t read_waiters;
^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) struct f2fs_mount_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	unsigned int opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	int write_io_size_bits;		/* Write IO size bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	block_t root_reserved_blocks;	/* root reserved blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	kuid_t s_resuid;		/* reserved blocks for uid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	kgid_t s_resgid;		/* reserved blocks for gid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	int active_logs;		/* # of active logs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	int inline_xattr_size;		/* inline xattr size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) #ifdef CONFIG_F2FS_FAULT_INJECTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	struct f2fs_fault_info fault_info;	/* For fault injection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	/* Names of quota files with journalled quota */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	char *s_qf_names[MAXQUOTAS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	int s_jquota_fmt;			/* Format of quota to use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	/* For which write hints are passed down to block layer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	int whint_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	int alloc_mode;			/* segment allocation policy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	int fsync_mode;			/* fsync policy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	int fs_mode;			/* fs mode: LFS or ADAPTIVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	int bggc_mode;			/* bggc mode: off, on or sync */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	struct fscrypt_dummy_policy dummy_enc_policy; /* test dummy encryption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	block_t unusable_cap_perc;	/* percentage for cap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	block_t unusable_cap;		/* Amount of space allowed to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 					 * unusable when disabling checkpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	/* For compression */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	unsigned char compress_algorithm;	/* algorithm type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	unsigned char compress_log_size;	/* cluster log size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	unsigned char compress_level;		/* compress level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	bool compress_chksum;			/* compressed data chksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	unsigned char compress_ext_cnt;		/* extension count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	int compress_mode;			/* compression mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN];	/* extensions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) #define F2FS_FEATURE_ENCRYPT		0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) #define F2FS_FEATURE_BLKZONED		0x0002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) #define F2FS_FEATURE_ATOMIC_WRITE	0x0004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) #define F2FS_FEATURE_EXTRA_ATTR		0x0008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) #define F2FS_FEATURE_PRJQUOTA		0x0010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) #define F2FS_FEATURE_INODE_CHKSUM	0x0020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR	0x0040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) #define F2FS_FEATURE_QUOTA_INO		0x0080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) #define F2FS_FEATURE_INODE_CRTIME	0x0100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) #define F2FS_FEATURE_LOST_FOUND		0x0200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) #define F2FS_FEATURE_VERITY		0x0400
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) #define F2FS_FEATURE_SB_CHKSUM		0x0800
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) #define F2FS_FEATURE_CASEFOLD		0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) #define F2FS_FEATURE_COMPRESSION	0x2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) #define F2FS_FEATURE_RO			0x4000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) #define __F2FS_HAS_FEATURE(raw_super, mask)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	((raw_super->feature & cpu_to_le32(mask)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) #define F2FS_HAS_FEATURE(sbi, mask)	__F2FS_HAS_FEATURE(sbi->raw_super, mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) #define F2FS_SET_FEATURE(sbi, mask)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	(sbi->raw_super->feature |= cpu_to_le32(mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) #define F2FS_CLEAR_FEATURE(sbi, mask)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	(sbi->raw_super->feature &= ~cpu_to_le32(mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)  * Default values for user and/or group using reserved blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) #define	F2FS_DEF_RESUID		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) #define	F2FS_DEF_RESGID		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203)  * For checkpoint manager
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	NAT_BITMAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	SIT_BITMAP
^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) #define	CP_UMOUNT	0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) #define	CP_FASTBOOT	0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) #define	CP_SYNC		0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) #define	CP_RECOVERY	0x00000008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) #define	CP_DISCARD	0x00000010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) #define CP_TRIMMED	0x00000020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) #define CP_PAUSE	0x00000040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) #define CP_RESIZE 	0x00000080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) #define MAX_DISCARD_BLOCKS(sbi)		BLKS_PER_SEC(sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) #define DEF_MAX_DISCARD_REQUEST		8	/* issue 8 discards per round */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) #define DEF_MIN_DISCARD_ISSUE_TIME	50	/* 50 ms, if exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) #define DEF_MID_DISCARD_ISSUE_TIME	500	/* 500 ms, if device busy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) #define DEF_MAX_DISCARD_ISSUE_TIME	60000	/* 60 s, if no candidates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) #define DEF_DISCARD_URGENT_UTIL		80	/* do more discard over 80% */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) #define DEF_CP_INTERVAL			60	/* 60 secs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) #define DEF_IDLE_INTERVAL		5	/* 5 secs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) #define DEF_DISABLE_INTERVAL		5	/* 5 secs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) #define DEF_DISABLE_QUICK_INTERVAL	1	/* 1 secs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) #define DEF_UMOUNT_DISCARD_TIMEOUT	5	/* 5 secs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) struct cp_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	int reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	__u64 trim_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	__u64 trim_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	__u64 trim_minlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239)  * indicate meta/data type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	META_CP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	META_NAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	META_SIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	META_SSA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	META_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	META_POR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	DATA_GENERIC,		/* check range only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	DATA_GENERIC_ENHANCE,	/* strong check on range and segment bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	DATA_GENERIC_ENHANCE_READ,	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 					 * strong check on range and segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 					 * bitmap but no warning due to race
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 					 * condition of read on truncated area
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 					 * by extent_cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	META_GENERIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) /* for the list of ino */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	ORPHAN_INO,		/* for orphan ino list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	APPEND_INO,		/* for append ino list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	UPDATE_INO,		/* for update ino list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	TRANS_DIR_INO,		/* for trasactions dir ino list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	FLUSH_INO,		/* for multiple device flushing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	MAX_INO_ENTRY,		/* max. list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) struct ino_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	struct list_head list;		/* list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	nid_t ino;			/* inode number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	unsigned int dirty_device;	/* dirty device bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) /* for the list of inodes to be GCed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) struct inode_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	struct list_head list;	/* list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	struct inode *inode;	/* vfs inode pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) struct fsync_node_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	struct list_head list;	/* list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	struct page *page;	/* warm node page pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	unsigned int seq_id;	/* sequence id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) struct ckpt_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	struct completion wait;		/* completion for checkpoint done */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	struct llist_node llnode;	/* llist_node to be linked in wait queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	int ret;			/* return code of checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	ktime_t queue_time;		/* request queued time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) struct ckpt_req_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	struct task_struct *f2fs_issue_ckpt;	/* checkpoint task */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	int ckpt_thread_ioprio;			/* checkpoint merge thread ioprio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	wait_queue_head_t ckpt_wait_queue;	/* waiting queue for wake-up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	atomic_t issued_ckpt;		/* # of actually issued ckpts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	atomic_t total_ckpt;		/* # of total ckpts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	atomic_t queued_ckpt;		/* # of queued ckpts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	struct llist_head issue_list;	/* list for command issue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	spinlock_t stat_lock;		/* lock for below checkpoint time stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	unsigned int cur_time;		/* cur wait time in msec for currently issued checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	unsigned int peak_time;		/* peak wait time in msec until now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) /* for the bitmap indicate blocks to be discarded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) struct discard_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	struct list_head list;	/* list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	block_t start_blkaddr;	/* start blockaddr of current segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	unsigned char discard_map[SIT_VBLOCK_MAP_SIZE];	/* segment discard bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) /* default discard granularity of inner discard thread, unit: block count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) #define DEFAULT_DISCARD_GRANULARITY		16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) /* max discard pend list number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) #define MAX_PLIST_NUM		512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) #define plist_idx(blk_num)	((blk_num) >= MAX_PLIST_NUM ?		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 					(MAX_PLIST_NUM - 1) : ((blk_num) - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	D_PREP,			/* initial */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	D_PARTIAL,		/* partially submitted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	D_SUBMIT,		/* all submitted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	D_DONE,			/* finished */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) struct discard_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	block_t lstart;			/* logical start address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	block_t len;			/* length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	block_t start;			/* actual start address in dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) struct discard_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	struct rb_node rb_node;		/* rb node located in rb-tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 			block_t lstart;	/* logical start address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			block_t len;	/* length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 			block_t start;	/* actual start address in dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		struct discard_info di;	/* discard info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	struct list_head list;		/* command list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	struct completion wait;		/* compleation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	struct block_device *bdev;	/* bdev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	unsigned short ref;		/* reference count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	unsigned char state;		/* state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	unsigned char queued;		/* queued discard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	int error;			/* bio error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	spinlock_t lock;		/* for state/bio_ref updating */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	unsigned short bio_ref;		/* bio reference count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	DPOLICY_BG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	DPOLICY_FORCE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	DPOLICY_FSTRIM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	DPOLICY_UMOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	MAX_DPOLICY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) struct discard_policy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	int type;			/* type of discard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	unsigned int min_interval;	/* used for candidates exist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	unsigned int mid_interval;	/* used for device busy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	unsigned int max_interval;	/* used for candidates not exist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	unsigned int max_requests;	/* # of discards issued per round */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	unsigned int io_aware_gran;	/* minimum granularity discard not be aware of I/O */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	bool io_aware;			/* issue discard in idle time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	bool sync;			/* submit discard with REQ_SYNC flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	bool ordered;			/* issue discard by lba order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	bool timeout;			/* discard timeout for put_super */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	unsigned int granularity;	/* discard granularity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) struct discard_cmd_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	struct task_struct *f2fs_issue_discard;	/* discard thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	struct list_head entry_list;		/* 4KB discard entry list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	struct list_head wait_list;		/* store on-flushing entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	struct list_head fstrim_list;		/* in-flight discard from fstrim */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	wait_queue_head_t discard_wait_queue;	/* waiting queue for wake-up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	unsigned int discard_wake;		/* to wake up discard thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	struct mutex cmd_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	unsigned int nr_discards;		/* # of discards in the list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	unsigned int max_discards;		/* max. discards to be issued */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	unsigned int discard_granularity;	/* discard granularity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	unsigned int undiscard_blks;		/* # of undiscard blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	unsigned int next_pos;			/* next discard position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	atomic_t issued_discard;		/* # of issued discard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	atomic_t queued_discard;		/* # of queued discard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	atomic_t discard_cmd_cnt;		/* # of cached cmd count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	struct rb_root_cached root;		/* root of discard rb-tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	bool rbtree_check;			/* config for consistence check */
^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) /* for the list of fsync inodes, used only during recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) struct fsync_inode_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	struct list_head list;	/* list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	struct inode *inode;	/* vfs inode pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	block_t blkaddr;	/* block address locating the last fsync */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	block_t last_dentry;	/* block address locating the last dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) #define nats_in_cursum(jnl)		(le16_to_cpu((jnl)->n_nats))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) #define sits_in_cursum(jnl)		(le16_to_cpu((jnl)->n_sits))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) #define nat_in_journal(jnl, i)		((jnl)->nat_j.entries[i].ne)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) #define nid_in_journal(jnl, i)		((jnl)->nat_j.entries[i].nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) #define sit_in_journal(jnl, i)		((jnl)->sit_j.entries[i].se)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) #define segno_in_journal(jnl, i)	((jnl)->sit_j.entries[i].segno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) #define MAX_NAT_JENTRIES(jnl)	(NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) #define MAX_SIT_JENTRIES(jnl)	(SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	int before = nats_in_cursum(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	journal->n_nats = cpu_to_le16(before + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	return before;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	int before = sits_in_cursum(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	journal->n_sits = cpu_to_le16(before + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	return before;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) static inline bool __has_cursum_space(struct f2fs_journal *journal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 							int size, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	if (type == NAT_JOURNAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		return size <= MAX_NAT_JENTRIES(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	return size <= MAX_SIT_JENTRIES(journal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) /* for inline stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) #define DEF_INLINE_RESERVED_SIZE	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) static inline int get_extra_isize(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) static inline int get_inline_xattr_addrs(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) #define MAX_INLINE_DATA(inode)	(sizeof(__le32) *			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 				(CUR_ADDRS_PER_INODE(inode) -		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 				get_inline_xattr_addrs(inode) -	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 				DEF_INLINE_RESERVED_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) /* for inline dir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) #define NR_INLINE_DENTRY(inode)	(MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 				((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 				BITS_PER_BYTE + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) #define INLINE_DENTRY_BITMAP_SIZE(inode) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	DIV_ROUND_UP(NR_INLINE_DENTRY(inode), BITS_PER_BYTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) #define INLINE_RESERVED_SIZE(inode)	(MAX_INLINE_DATA(inode) - \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 				((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 				NR_INLINE_DENTRY(inode) + \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 				INLINE_DENTRY_BITMAP_SIZE(inode)))
^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)  * For INODE and NODE manager
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) /* for directory operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) struct f2fs_filename {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	 * The filename the user specified.  This is NULL for some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	 * filesystem-internal operations, e.g. converting an inline directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	 * to a non-inline one, or roll-forward recovering an encrypted dentry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	const struct qstr *usr_fname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	 * The on-disk filename.  For encrypted directories, this is encrypted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	 * This may be NULL for lookups in an encrypted dir without the key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	struct fscrypt_str disk_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	/* The dirhash of this filename */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	f2fs_hash_t hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) #ifdef CONFIG_FS_ENCRYPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	 * For lookups in encrypted directories: either the buffer backing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	 * disk_name, or a buffer that holds the decoded no-key name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	struct fscrypt_str crypto_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) #ifdef CONFIG_UNICODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	 * For casefolded directories: the casefolded name, but it's left NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	 * if the original name is not valid Unicode, if the directory is both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	 * casefolded and encrypted and its encryption key is unavailable, or if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	 * the filesystem is doing an internal operation where usr_fname is also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	 * NULL.  In all these cases we fall back to treating the name as an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	 * opaque byte sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	struct fscrypt_str cf_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) struct f2fs_dentry_ptr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	void *bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	struct f2fs_dir_entry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	__u8 (*filename)[F2FS_SLOT_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	int max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	int nr_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) static inline void make_dentry_ptr_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	d->inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	d->max = NR_DENTRY_IN_BLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	d->nr_bitmap = SIZE_OF_DENTRY_BITMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	d->bitmap = t->dentry_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	d->dentry = t->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	d->filename = t->filename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) static inline void make_dentry_ptr_inline(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 					struct f2fs_dentry_ptr *d, void *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	int entry_cnt = NR_INLINE_DENTRY(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	int reserved_size = INLINE_RESERVED_SIZE(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	d->inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	d->max = entry_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	d->nr_bitmap = bitmap_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	d->bitmap = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	d->dentry = t + bitmap_size + reserved_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	d->filename = t + bitmap_size + reserved_size +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 					SIZE_OF_DIR_ENTRY * entry_cnt;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542)  * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543)  * as its node offset to distinguish from index node blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544)  * But some bits are used to mark the node block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) #define XATTR_NODE_OFFSET	((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 				>> OFFSET_BIT_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	ALLOC_NODE,			/* allocate a new node page if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	LOOKUP_NODE,			/* look up a node without readahead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	LOOKUP_NODE_RA,			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 					 * look up a node with readahead called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 					 * by get_data_block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) #define DEFAULT_RETRY_IO_COUNT	8	/* maximum retry read IO count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) /* congestion wait timeout value, default: 20ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) #define	DEFAULT_IO_TIMEOUT	(msecs_to_jiffies(20))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) /* maximum retry quota flush count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) #define F2FS_LINK_MAX	0xffffffff	/* maximum link count per file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) #define MAX_DIR_RA_PAGES	4	/* maximum ra pages of dir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) /* for in-memory extent cache entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) #define F2FS_MIN_EXTENT_LEN	64	/* minimum extent length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) /* number of extent info in extent cache we try to shrink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) #define EXTENT_CACHE_SHRINK_NUMBER	128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) struct rb_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	struct rb_node rb_node;		/* rb node located in rb-tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 			unsigned int ofs;	/* start offset of the entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 			unsigned int len;	/* length of the entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		unsigned long long key;		/* 64-bits key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	} __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) struct extent_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	unsigned int fofs;		/* start offset in a file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	unsigned int len;		/* length of the extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	u32 blk;			/* start block address of the extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) struct extent_node {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	struct rb_node rb_node;		/* rb node located in rb-tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	struct extent_info ei;		/* extent info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	struct list_head list;		/* node in global extent list of sbi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	struct extent_tree *et;		/* extent tree pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) struct extent_tree {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	nid_t ino;			/* inode number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	struct rb_root_cached root;	/* root of extent info rb-tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	struct extent_node *cached_en;	/* recently accessed extent node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	struct extent_info largest;	/* largested extent info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	struct list_head list;		/* to be used by sbi->zombie_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	rwlock_t lock;			/* protect extent info rb-tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	atomic_t node_cnt;		/* # of extent node in rb-tree*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	bool largest_updated;		/* largest extent updated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611)  * This structure is taken from ext4_map_blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613)  * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) #define F2FS_MAP_NEW		(1 << BH_New)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) #define F2FS_MAP_MAPPED		(1 << BH_Mapped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) #define F2FS_MAP_UNWRITTEN	(1 << BH_Unwritten)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) #define F2FS_MAP_FLAGS		(F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 				F2FS_MAP_UNWRITTEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) struct f2fs_map_blocks {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	block_t m_pblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	block_t m_lblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	unsigned int m_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	unsigned int m_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	pgoff_t *m_next_pgofs;		/* point next possible non-hole pgofs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	pgoff_t *m_next_extent;		/* point to next possible extent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	int m_seg_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	bool m_may_create;		/* indicate it is from write path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) /* for flag in get_data_block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	F2FS_GET_BLOCK_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	F2FS_GET_BLOCK_FIEMAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	F2FS_GET_BLOCK_BMAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	F2FS_GET_BLOCK_DIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	F2FS_GET_BLOCK_PRE_DIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	F2FS_GET_BLOCK_PRE_AIO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	F2FS_GET_BLOCK_PRECACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644)  * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) #define FADVISE_COLD_BIT	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) #define FADVISE_LOST_PINO_BIT	0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) #define FADVISE_ENCRYPT_BIT	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) #define FADVISE_ENC_NAME_BIT	0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) #define FADVISE_KEEP_SIZE_BIT	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) #define FADVISE_HOT_BIT		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) #define FADVISE_VERITY_BIT	0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) #define FADVISE_MODIFIABLE_BITS	(FADVISE_COLD_BIT | FADVISE_HOT_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) #define file_is_cold(inode)	is_file(inode, FADVISE_COLD_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) #define file_set_cold(inode)	set_file(inode, FADVISE_COLD_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) #define file_clear_cold(inode)	clear_file(inode, FADVISE_COLD_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) #define file_wrong_pino(inode)	is_file(inode, FADVISE_LOST_PINO_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) #define file_lost_pino(inode)	set_file(inode, FADVISE_LOST_PINO_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) #define file_got_pino(inode)	clear_file(inode, FADVISE_LOST_PINO_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) #define file_is_encrypt(inode)	is_file(inode, FADVISE_ENCRYPT_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) #define file_set_encrypt(inode)	set_file(inode, FADVISE_ENCRYPT_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) #define file_enc_name(inode)	is_file(inode, FADVISE_ENC_NAME_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) #define file_keep_isize(inode)	is_file(inode, FADVISE_KEEP_SIZE_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) #define file_is_hot(inode)	is_file(inode, FADVISE_HOT_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) #define file_set_hot(inode)	set_file(inode, FADVISE_HOT_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) #define file_clear_hot(inode)	clear_file(inode, FADVISE_HOT_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) #define file_is_verity(inode)	is_file(inode, FADVISE_VERITY_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) #define file_set_verity(inode)	set_file(inode, FADVISE_VERITY_BIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) #define DEF_DIR_LEVEL		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	GC_FAILURE_PIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	GC_FAILURE_ATOMIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	MAX_GC_FAILURE
^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) /* used for f2fs_inode_info->flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	FI_NEW_INODE,		/* indicate newly allocated inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	FI_DIRTY_INODE,		/* indicate inode is dirty or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	FI_AUTO_RECOVER,	/* indicate inode is recoverable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	FI_DIRTY_DIR,		/* indicate directory has dirty pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	FI_INC_LINK,		/* need to increment i_nlink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	FI_ACL_MODE,		/* indicate acl mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	FI_NO_ALLOC,		/* should not allocate any blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	FI_FREE_NID,		/* free allocated nide */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	FI_NO_EXTENT,		/* not to use the extent cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	FI_INLINE_XATTR,	/* used for inline xattr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	FI_INLINE_DATA,		/* used for inline data*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	FI_INLINE_DENTRY,	/* used for inline dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	FI_APPEND_WRITE,	/* inode has appended data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	FI_UPDATE_WRITE,	/* inode has in-place-update data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	FI_NEED_IPU,		/* used for ipu per file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	FI_ATOMIC_FILE,		/* indicate atomic file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	FI_ATOMIC_COMMIT,	/* indicate the state of atomical committing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	FI_VOLATILE_FILE,	/* indicate volatile file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	FI_FIRST_BLOCK_WRITTEN,	/* indicate #0 data block was written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	FI_DROP_CACHE,		/* drop dirty page cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	FI_DATA_EXIST,		/* indicate data exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	FI_INLINE_DOTS,		/* indicate inline dot dentries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	FI_DO_DEFRAG,		/* indicate defragment is running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	FI_DIRTY_FILE,		/* indicate regular/symlink has dirty pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	FI_NO_PREALLOC,		/* indicate skipped preallocated blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	FI_HOT_DATA,		/* indicate file is hot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	FI_EXTRA_ATTR,		/* indicate file has extra attribute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	FI_PROJ_INHERIT,	/* indicate file inherits projectid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	FI_PIN_FILE,		/* indicate file should not be gced */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	FI_VERITY_IN_PROGRESS,	/* building fs-verity Merkle tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	FI_COMPRESSED_FILE,	/* indicate file's data can be compressed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	FI_COMPRESS_CORRUPT,	/* indicate compressed cluster is corrupted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	FI_MMAP_FILE,		/* indicate file was mmapped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	FI_ENABLE_COMPRESS,	/* enable compression in "user" compression mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	FI_COMPRESS_RELEASED,	/* compressed blocks were released */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	FI_ALIGNED_WRITE,	/* enable aligned write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	FI_MAX,			/* max flag, never be used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) struct f2fs_inode_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	struct inode vfs_inode;		/* serve a vfs inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	unsigned long i_flags;		/* keep an inode flags for ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	unsigned char i_advise;		/* use to give file attribute hints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	unsigned char i_dir_level;	/* use for dentry level for large dir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	unsigned int i_current_depth;	/* only for directory depth */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	/* for gc failure statistic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	unsigned int i_gc_failures[MAX_GC_FAILURE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	unsigned int i_pino;		/* parent inode number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	umode_t i_acl_mode;		/* keep file acl mode temporarily */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	/* Use below internally in f2fs*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	unsigned long flags[BITS_TO_LONGS(FI_MAX)];	/* use to pass per-file flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	struct f2fs_rwsem i_sem;	/* protect fi info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	atomic_t dirty_pages;		/* # of dirty pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	f2fs_hash_t chash;		/* hash value of given file name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	unsigned int clevel;		/* maximum level of given file name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	struct task_struct *task;	/* lookup and create consistency */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	struct task_struct *cp_task;	/* separate cp/wb IO stats*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	nid_t i_xattr_nid;		/* node id that contains xattrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	loff_t	last_disk_size;		/* lastly written file size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	spinlock_t i_size_lock;		/* protect last_disk_size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	struct dquot *i_dquot[MAXQUOTAS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	/* quota space reservation, managed internally by quota code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	qsize_t i_reserved_quota;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	struct list_head dirty_list;	/* dirty list for dirs and files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	struct list_head gdirty_list;	/* linked in global dirty list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	struct list_head inmem_ilist;	/* list for inmem inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	struct list_head inmem_pages;	/* inmemory pages managed by f2fs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	struct task_struct *inmem_task;	/* store inmemory task */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	struct mutex inmem_lock;	/* lock for inmemory pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	struct extent_tree *extent_tree;	/* cached extent_tree entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	/* avoid racing between foreground op and gc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	struct f2fs_rwsem i_gc_rwsem[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	struct f2fs_rwsem i_mmap_sem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	struct f2fs_rwsem i_xattr_sem; /* avoid racing between reading and changing EAs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	int i_extra_isize;		/* size of extra space located in i_addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	kprojid_t i_projid;		/* id for project quota */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	int i_inline_xattr_size;	/* inline xattr size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	struct timespec64 i_crtime;	/* inode creation time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	struct timespec64 i_disk_time[4];/* inode disk times */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	/* for file compress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	atomic_t i_compr_blocks;		/* # of compressed blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	unsigned char i_compress_algorithm;	/* algorithm type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	unsigned char i_log_cluster_size;	/* log of cluster size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	unsigned char i_compress_level;		/* compress level (lz4hc,zstd) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	unsigned short i_compress_flag;		/* compress flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	unsigned int i_cluster_size;		/* cluster size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) static inline void get_extent_info(struct extent_info *ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 					struct f2fs_extent *i_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	ext->fofs = le32_to_cpu(i_ext->fofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	ext->blk = le32_to_cpu(i_ext->blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	ext->len = le32_to_cpu(i_ext->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) static inline void set_raw_extent(struct extent_info *ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 					struct f2fs_extent *i_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	i_ext->fofs = cpu_to_le32(ext->fofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	i_ext->blk = cpu_to_le32(ext->blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	i_ext->len = cpu_to_le32(ext->len);
^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 inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 						u32 blk, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	ei->fofs = fofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	ei->blk = blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	ei->len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) static inline bool __is_discard_mergeable(struct discard_info *back,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 			struct discard_info *front, unsigned int max_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	return (back->lstart + back->len == front->lstart) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		(back->len + front->len <= max_len);
^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 inline bool __is_discard_back_mergeable(struct discard_info *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			struct discard_info *back, unsigned int max_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	return __is_discard_mergeable(back, cur, max_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) static inline bool __is_discard_front_mergeable(struct discard_info *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 			struct discard_info *front, unsigned int max_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	return __is_discard_mergeable(cur, front, max_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) static inline bool __is_extent_mergeable(struct extent_info *back,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 						struct extent_info *front)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	return (back->fofs + back->len == front->fofs &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			back->blk + back->len == front->blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) static inline bool __is_back_mergeable(struct extent_info *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 						struct extent_info *back)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	return __is_extent_mergeable(back, cur);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) static inline bool __is_front_mergeable(struct extent_info *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 						struct extent_info *front)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	return __is_extent_mergeable(cur, front);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) static inline void __try_update_largest_extent(struct extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 						struct extent_node *en)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	if (en->ei.len > et->largest.len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 		et->largest = en->ei;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		et->largest_updated = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860)  * For free nid management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) enum nid_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	FREE_NID,		/* newly added to free nid list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	PREALLOC_NID,		/* it is preallocated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	MAX_NID_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) enum nat_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	TOTAL_NAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	DIRTY_NAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	RECLAIMABLE_NAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	MAX_NAT_STATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) struct f2fs_nm_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	block_t nat_blkaddr;		/* base disk address of NAT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	nid_t max_nid;			/* maximum possible node ids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	nid_t available_nids;		/* # of available node ids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	nid_t next_scan_nid;		/* the next nid to be scanned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	unsigned int ram_thresh;	/* control the memory footprint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	unsigned int ra_nid_pages;	/* # of nid pages to be readaheaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	unsigned int dirty_nats_ratio;	/* control dirty nats ratio threshold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	/* NAT cache management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	struct radix_tree_root nat_root;/* root of the nat entry cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	struct radix_tree_root nat_set_root;/* root of the nat set cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	struct f2fs_rwsem nat_tree_lock;	/* protect nat entry tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	struct list_head nat_entries;	/* cached nat entry list (clean) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	spinlock_t nat_list_lock;	/* protect clean nat entry list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	unsigned int nat_cnt[MAX_NAT_STATE]; /* the # of cached nat entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	unsigned int nat_blocks;	/* # of nat blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	/* free node ids management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	struct radix_tree_root free_nid_root;/* root of the free_nid cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	struct list_head free_nid_list;		/* list for free nids excluding preallocated nids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	unsigned int nid_cnt[MAX_NID_STATE];	/* the number of free node id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	spinlock_t nid_list_lock;	/* protect nid lists ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	struct mutex build_lock;	/* lock for build free nids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	unsigned char **free_nid_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	unsigned char *nat_block_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	unsigned short *free_nid_count;	/* free nid count of NAT block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	/* for checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	char *nat_bitmap;		/* NAT bitmap pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	unsigned int nat_bits_blocks;	/* # of nat bits blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	unsigned char *nat_bits;	/* NAT bits blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	unsigned char *full_nat_bits;	/* full NAT pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	unsigned char *empty_nat_bits;	/* empty NAT pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) #ifdef CONFIG_F2FS_CHECK_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	char *nat_bitmap_mir;		/* NAT bitmap mirror */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	int bitmap_size;		/* bitmap size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917)  * this structure is used as one of function parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918)  * all the information are dedicated to a given direct node block determined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919)  * by the data offset in a file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) struct dnode_of_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	struct inode *inode;		/* vfs inode pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	struct page *inode_page;	/* its inode page, NULL is possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	struct page *node_page;		/* cached direct node page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	nid_t nid;			/* node id of the direct node block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	unsigned int ofs_in_node;	/* data offset in the node page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	bool inode_page_locked;		/* inode page is locked or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	bool node_changed;		/* is node block changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	char cur_level;			/* level of hole node page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	char max_level;			/* level of current page located */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	block_t	data_blkaddr;		/* block address of the node block */
^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) static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		struct page *ipage, struct page *npage, nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	memset(dn, 0, sizeof(*dn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	dn->inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	dn->inode_page = ipage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	dn->node_page = npage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	dn->nid = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945)  * For SIT manager
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947)  * By default, there are 6 active log areas across the whole main area.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948)  * When considering hot and cold data separation to reduce cleaning overhead,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949)  * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950)  * respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951)  * In the current design, you should not change the numbers intentionally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952)  * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953)  * logs individually according to the underlying devices. (default: 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954)  * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955)  * data and 8 for node logs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) #define	NR_CURSEG_DATA_TYPE	(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) #define NR_CURSEG_NODE_TYPE	(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) #define NR_CURSEG_INMEM_TYPE	(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) #define NR_CURSEG_RO_TYPE	(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) #define NR_CURSEG_PERSIST_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) #define NR_CURSEG_TYPE		(NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	CURSEG_HOT_DATA	= 0,	/* directory entry blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	CURSEG_WARM_DATA,	/* data blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	CURSEG_COLD_DATA,	/* multimedia or GCed data blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	CURSEG_HOT_NODE,	/* direct node blocks of directory files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	CURSEG_WARM_NODE,	/* direct node blocks of normal files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	CURSEG_COLD_NODE,	/* indirect node blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	NR_PERSISTENT_LOG,	/* number of persistent log */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	CURSEG_COLD_DATA_PINNED = NR_PERSISTENT_LOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 				/* pinned file that needs consecutive block address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	CURSEG_ALL_DATA_ATGC,	/* SSR alloctor in hot/warm/cold data area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	NO_CHECK_TYPE,		/* number of persistent & inmem log */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) struct flush_cmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	struct completion wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	struct llist_node llnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	nid_t ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) struct flush_cmd_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	struct task_struct *f2fs_issue_flush;	/* flush thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	wait_queue_head_t flush_wait_queue;	/* waiting queue for wake-up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	atomic_t issued_flush;			/* # of issued flushes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	atomic_t queued_flush;			/* # of queued flushes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	struct llist_head issue_list;		/* list for command issue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	struct llist_node *dispatch_list;	/* list for command dispatch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) struct f2fs_sm_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	struct sit_info *sit_info;		/* whole segment information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	struct free_segmap_info *free_info;	/* free segment information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	struct dirty_seglist_info *dirty_info;	/* dirty segment information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	struct curseg_info *curseg_array;	/* active segment information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	struct f2fs_rwsem curseg_lock;	/* for preventing curseg change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	block_t seg0_blkaddr;		/* block address of 0'th segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	block_t main_blkaddr;		/* start block address of main area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	block_t ssa_blkaddr;		/* start block address of SSA area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	unsigned int segment_count;	/* total # of segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	unsigned int main_segments;	/* # of segments in main area */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	unsigned int reserved_segments;	/* # of reserved segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	unsigned int additional_reserved_segments;/* reserved segs for IO align feature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	unsigned int ovp_segments;	/* # of overprovision segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	/* a threshold to reclaim prefree segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	unsigned int rec_prefree_segments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	/* for batched trimming */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	unsigned int trim_sections;		/* # of sections to trim */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	struct list_head sit_entry_set;	/* sit entry set list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	unsigned int ipu_policy;	/* in-place-update policy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	unsigned int min_ipu_util;	/* in-place-update threshold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	unsigned int min_fsync_blocks;	/* threshold for fsync */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	unsigned int min_seq_blocks;	/* threshold for sequential blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	unsigned int min_hot_blocks;	/* threshold for hot block allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	unsigned int min_ssr_sections;	/* threshold to trigger SSR allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	/* for flush command control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	struct flush_cmd_control *fcc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	/* for discard command control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	struct discard_cmd_control *dcc_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)  * For superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)  * COUNT_TYPE for monitoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)  * f2fs monitors the number of several block types such as on-writeback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)  * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) #define WB_DATA_TYPE(p)	(__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) enum count_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	F2FS_DIRTY_DENTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	F2FS_DIRTY_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	F2FS_DIRTY_QDATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	F2FS_DIRTY_NODES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	F2FS_DIRTY_META,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	F2FS_INMEM_PAGES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	F2FS_DIRTY_IMETA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	F2FS_WB_CP_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	F2FS_WB_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	F2FS_RD_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	F2FS_RD_NODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	F2FS_RD_META,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	F2FS_DIO_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	F2FS_DIO_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	NR_COUNT_TYPE,
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)  * The below are the page types of bios used in submit_bio().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)  * The available types are:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)  * DATA			User data pages. It operates as async mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)  * NODE			Node pages. It operates as async mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)  * META			FS metadata pages such as SIT, NAT, CP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)  * NR_PAGE_TYPE		The number of page types.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)  * META_FLUSH		Make sure the previous pages are written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)  *			with waiting the bio's completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)  * ...			Only can be used with META.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) #define PAGE_TYPE_OF_BIO(type)	((type) > META ? META : (type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) enum page_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	NODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	META,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	NR_PAGE_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	META_FLUSH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	INMEM,		/* the below types are used by tracepoints only. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	INMEM_DROP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	INMEM_INVALIDATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	INMEM_REVOKE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	IPU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	OPU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) enum temp_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	HOT = 0,	/* must be zero for meta bio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	WARM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	COLD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	NR_TEMP_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) enum need_lock_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	LOCK_REQ = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	LOCK_DONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	LOCK_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) enum cp_reason_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	CP_NO_NEEDED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	CP_NON_REGULAR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	CP_COMPRESSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	CP_HARDLINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	CP_SB_NEED_CP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	CP_WRONG_PINO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	CP_NO_SPC_ROLL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	CP_NODE_NEED_CP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	CP_FASTBOOT_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	CP_SPEC_LOG_NUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	CP_RECOVER_DIR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) enum iostat_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	/* WRITE IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	APP_DIRECT_IO,			/* app direct write IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	APP_BUFFERED_IO,		/* app buffered write IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	APP_WRITE_IO,			/* app write IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	APP_MAPPED_IO,			/* app mapped IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	FS_DATA_IO,			/* data IOs from kworker/fsync/reclaimer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	FS_NODE_IO,			/* node IOs from kworker/fsync/reclaimer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	FS_META_IO,			/* meta IOs from kworker/reclaimer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	FS_GC_DATA_IO,			/* data IOs from forground gc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	FS_GC_NODE_IO,			/* node IOs from forground gc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	FS_CP_DATA_IO,			/* data IOs from checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	FS_CP_NODE_IO,			/* node IOs from checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	FS_CP_META_IO,			/* meta IOs from checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	/* READ IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	APP_DIRECT_READ_IO,		/* app direct read IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	APP_BUFFERED_READ_IO,		/* app buffered read IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	APP_READ_IO,			/* app read IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	APP_MAPPED_READ_IO,		/* app mapped read IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	FS_DATA_READ_IO,		/* data read IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	FS_GDATA_READ_IO,		/* data read IOs from background gc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	FS_CDATA_READ_IO,		/* compressed data read IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	FS_NODE_READ_IO,		/* node read IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	FS_META_READ_IO,		/* meta read IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	/* other */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	FS_DISCARD,			/* discard */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	NR_IO_TYPE,
^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) struct f2fs_io_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	struct f2fs_sb_info *sbi;	/* f2fs_sb_info pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	nid_t ino;		/* inode number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	enum page_type type;	/* contains DATA/NODE/META/META_FLUSH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	enum temp_type temp;	/* contains HOT/WARM/COLD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	int op;			/* contains REQ_OP_ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	int op_flags;		/* req_flag_bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	block_t new_blkaddr;	/* new block address to be written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	block_t old_blkaddr;	/* old block address before Cow */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	struct page *page;	/* page to be written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	struct page *encrypted_page;	/* encrypted page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	struct page *compressed_page;	/* compressed page */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	struct list_head list;		/* serialize IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	bool submitted;		/* indicate IO submission */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 	int need_lock;		/* indicate we need to lock cp_rwsem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	bool in_list;		/* indicate fio is in io_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	bool is_por;		/* indicate IO is from recovery or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	bool retry;		/* need to reallocate block address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	int compr_blocks;	/* # of compressed block addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	bool encrypted;		/* indicate file is encrypted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	enum iostat_type io_type;	/* io type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 	struct writeback_control *io_wbc; /* writeback control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	struct bio **bio;		/* bio for ipu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	sector_t *last_block;		/* last block number in bio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	unsigned char version;		/* version of the node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) struct bio_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) #define is_read_io(rw) ((rw) == READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) struct f2fs_bio_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	struct f2fs_sb_info *sbi;	/* f2fs superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	struct bio *bio;		/* bios to merge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	sector_t last_block_in_bio;	/* last block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	struct f2fs_io_info fio;	/* store buffered io info. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	struct f2fs_rwsem io_rwsem;	/* blocking op for bio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	spinlock_t io_lock;		/* serialize DATA/NODE IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	struct list_head io_list;	/* track fios */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	struct list_head bio_list;	/* bio entry list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	struct f2fs_rwsem bio_list_lock;	/* lock to protect bio entry list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) #define FDEV(i)				(sbi->devs[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) #define RDEV(i)				(raw_super->devs[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) struct f2fs_dev_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	struct block_device *bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	char path[MAX_PATH_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	unsigned int total_segments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	block_t start_blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	block_t end_blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) #ifdef CONFIG_BLK_DEV_ZONED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 	unsigned int nr_blkz;		/* Total number of zones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	unsigned long *blkz_seq;	/* Bitmap indicating sequential zones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	block_t *zone_capacity_blocks;  /* Array of zone capacity in blks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) enum inode_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	DIR_INODE,			/* for dirty dir inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	FILE_INODE,			/* for dirty regular/symlink inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	DIRTY_META,			/* for all dirtied inode metadata */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	ATOMIC_FILE,			/* for all atomic files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	NR_INODE_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) /* for inner inode cache management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) struct inode_management {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	struct radix_tree_root ino_root;	/* ino entry array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	spinlock_t ino_lock;			/* for ino entry lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	struct list_head ino_list;		/* inode list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	unsigned long ino_num;			/* number of entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) /* for GC_AT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) struct atgc_management {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	bool atgc_enabled;			/* ATGC is enabled or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	struct rb_root_cached root;		/* root of victim rb-tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	struct list_head victim_list;		/* linked with all victim entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	unsigned int victim_count;		/* victim count in rb-tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	unsigned int candidate_ratio;		/* candidate ratio */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	unsigned int max_candidate_count;	/* max candidate count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	unsigned int age_weight;		/* age weight, vblock_weight = 100 - age_weight */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	unsigned long long age_threshold;	/* age threshold */
^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) /* For s_flag in struct f2fs_sb_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	SBI_IS_DIRTY,				/* dirty flag for checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	SBI_IS_CLOSE,				/* specify unmounting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	SBI_NEED_FSCK,				/* need fsck.f2fs to fix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	SBI_POR_DOING,				/* recovery is doing or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	SBI_NEED_SB_WRITE,			/* need to recover superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	SBI_NEED_CP,				/* need to checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	SBI_IS_SHUTDOWN,			/* shutdown by ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	SBI_IS_RECOVERED,			/* recovered orphan/data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	SBI_CP_DISABLED,			/* CP was disabled last mount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	SBI_CP_DISABLED_QUICK,			/* CP was disabled quickly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	SBI_QUOTA_NEED_FLUSH,			/* need to flush quota info in CP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	SBI_QUOTA_SKIP_FLUSH,			/* skip flushing quota in current CP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	SBI_QUOTA_NEED_REPAIR,			/* quota file may be corrupted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	SBI_IS_RESIZEFS,			/* resizefs is in process */
^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) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	CP_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	REQ_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	DISCARD_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	GC_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	DISABLE_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	UMOUNT_DISCARD_TIMEOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	MAX_TIME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	GC_NORMAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	GC_IDLE_CB,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	GC_IDLE_GREEDY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	GC_IDLE_AT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	GC_URGENT_HIGH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	GC_URGENT_LOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	MAX_GC_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	BGGC_MODE_ON,		/* background gc is on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	BGGC_MODE_OFF,		/* background gc is off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	BGGC_MODE_SYNC,		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 				 * background gc is on, migrating blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 				 * like foreground gc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	FS_MODE_ADAPTIVE,	/* use both lfs/ssr allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	FS_MODE_LFS,		/* use lfs allocation only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	WHINT_MODE_OFF,		/* not pass down write hints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	WHINT_MODE_USER,	/* try to pass down hints given by users */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	WHINT_MODE_FS,		/* pass down hints with F2FS policy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	ALLOC_MODE_DEFAULT,	/* stay default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 	ALLOC_MODE_REUSE,	/* reuse segments as much as possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) enum fsync_mode {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	FSYNC_MODE_POSIX,	/* fsync follows posix semantics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	FSYNC_MODE_STRICT,	/* fsync behaves in line with ext4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	FSYNC_MODE_NOBARRIER,	/* fsync behaves nobarrier based on posix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	COMPR_MODE_FS,		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 				 * automatically compress compression
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 				 * enabled files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	COMPR_MODE_USER,	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 				 * automatical compression is disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 				 * user can control the file compression
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 				 * using ioctls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) static inline int f2fs_test_bit(unsigned int nr, char *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) static inline void f2fs_set_bit(unsigned int nr, char *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) static inline void f2fs_clear_bit(unsigned int nr, char *addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)  * Layout of f2fs page.private:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)  * Layout A: lowest bit should be 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)  * | bit0 = 1 | bit1 | bit2 | ... | bit MAX | private data .... |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)  * bit 0	PAGE_PRIVATE_NOT_POINTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)  * bit 1	PAGE_PRIVATE_ATOMIC_WRITE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)  * bit 2	PAGE_PRIVATE_DUMMY_WRITE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)  * bit 3	PAGE_PRIVATE_ONGOING_MIGRATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)  * bit 4	PAGE_PRIVATE_INLINE_INODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)  * bit 5	PAGE_PRIVATE_REF_RESOURCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)  * bit 6-	f2fs private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)  * Layout B: lowest bit should be 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)  * page.private is a wrapped pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	PAGE_PRIVATE_NOT_POINTER,		/* private contains non-pointer data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	PAGE_PRIVATE_ATOMIC_WRITE,		/* data page from atomic write path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	PAGE_PRIVATE_DUMMY_WRITE,		/* data page for padding aligned IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	PAGE_PRIVATE_ONGOING_MIGRATION,		/* data page which is on-going migrating */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	PAGE_PRIVATE_INLINE_INODE,		/* inode page contains inline data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	PAGE_PRIVATE_REF_RESOURCE,		/* dirty page has referenced resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	PAGE_PRIVATE_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) #define PAGE_PRIVATE_GET_FUNC(name, flagname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) static inline bool page_private_##name(struct page *page) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	return PagePrivate(page) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		test_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 		test_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) #define PAGE_PRIVATE_SET_FUNC(name, flagname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) static inline void set_page_private_##name(struct page *page) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	if (!PagePrivate(page)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 		get_page(page); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		SetPagePrivate(page); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		set_page_private(page, 0); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	} \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	set_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) #define PAGE_PRIVATE_CLEAR_FUNC(name, flagname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) static inline void clear_page_private_##name(struct page *page) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	clear_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	if (page_private(page) == 1 << PAGE_PRIVATE_NOT_POINTER) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 		set_page_private(page, 0); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 		if (PagePrivate(page)) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 			ClearPagePrivate(page); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 			put_page(page); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		}\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	} \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) PAGE_PRIVATE_GET_FUNC(nonpointer, NOT_POINTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) PAGE_PRIVATE_GET_FUNC(reference, REF_RESOURCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) PAGE_PRIVATE_GET_FUNC(inline, INLINE_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) PAGE_PRIVATE_GET_FUNC(gcing, ONGOING_MIGRATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) PAGE_PRIVATE_GET_FUNC(atomic, ATOMIC_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) PAGE_PRIVATE_GET_FUNC(dummy, DUMMY_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) PAGE_PRIVATE_SET_FUNC(reference, REF_RESOURCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) PAGE_PRIVATE_SET_FUNC(inline, INLINE_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) PAGE_PRIVATE_SET_FUNC(gcing, ONGOING_MIGRATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) PAGE_PRIVATE_SET_FUNC(atomic, ATOMIC_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) PAGE_PRIVATE_SET_FUNC(dummy, DUMMY_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) PAGE_PRIVATE_CLEAR_FUNC(reference, REF_RESOURCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) PAGE_PRIVATE_CLEAR_FUNC(inline, INLINE_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) PAGE_PRIVATE_CLEAR_FUNC(gcing, ONGOING_MIGRATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) PAGE_PRIVATE_CLEAR_FUNC(atomic, ATOMIC_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) PAGE_PRIVATE_CLEAR_FUNC(dummy, DUMMY_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) static inline unsigned long get_page_private_data(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	unsigned long data = page_private(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 	if (!test_bit(PAGE_PRIVATE_NOT_POINTER, &data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 	return data >> PAGE_PRIVATE_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) static inline void set_page_private_data(struct page *page, unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	if (!PagePrivate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		get_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		SetPagePrivate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		set_page_private(page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	page_private(page) |= data << PAGE_PRIVATE_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) static inline void clear_page_private_data(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	page_private(page) &= (1 << PAGE_PRIVATE_MAX) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	if (page_private(page) == 1 << PAGE_PRIVATE_NOT_POINTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 		set_page_private(page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 		if (PagePrivate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 			ClearPagePrivate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 			put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) /* For compression */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) enum compress_algorithm_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	COMPRESS_LZO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	COMPRESS_LZ4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	COMPRESS_ZSTD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	COMPRESS_LZORLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	COMPRESS_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) enum compress_flag {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	COMPRESS_CHKSUM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	COMPRESS_MAX_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) #define	COMPRESS_WATERMARK			20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) #define	COMPRESS_PERCENT			20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) #define COMPRESS_DATA_RESERVED_SIZE		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) struct compress_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	__le32 clen;			/* compressed data size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	__le32 chksum;			/* compressed data chksum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	__le32 reserved[COMPRESS_DATA_RESERVED_SIZE];	/* reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	u8 cdata[];			/* compressed data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) #define COMPRESS_HEADER_SIZE	(sizeof(struct compress_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) #define F2FS_COMPRESSED_PAGE_MAGIC	0xF5F2C000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) #define	COMPRESS_LEVEL_OFFSET	8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) /* compress context */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) struct compress_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	struct inode *inode;		/* inode the context belong to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	pgoff_t cluster_idx;		/* cluster index number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	unsigned int cluster_size;	/* page count in cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	unsigned int log_cluster_size;	/* log of cluster size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	struct page **rpages;		/* pages store raw data in cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	unsigned int nr_rpages;		/* total page number in rpages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	struct page **cpages;		/* pages store compressed data in cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	unsigned int nr_cpages;		/* total page number in cpages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	void *rbuf;			/* virtual mapped address on rpages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	struct compress_data *cbuf;	/* virtual mapped address on cpages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	size_t rlen;			/* valid data length in rbuf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	size_t clen;			/* valid data length in cbuf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	void *private;			/* payload buffer for specified compression algorithm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	void *private2;			/* extra payload buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) /* compress context for write IO path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) struct compress_io_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	u32 magic;			/* magic number to indicate page is compressed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	struct inode *inode;		/* inode the context belong to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	struct page **rpages;		/* pages store raw data in cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	unsigned int nr_rpages;		/* total page number in rpages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	atomic_t pending_pages;		/* in-flight compressed page count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) /* Context for decompressing one cluster on the read IO path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) struct decompress_io_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 	u32 magic;			/* magic number to indicate page is compressed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	struct inode *inode;		/* inode the context belong to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	pgoff_t cluster_idx;		/* cluster index number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	unsigned int cluster_size;	/* page count in cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	unsigned int log_cluster_size;	/* log of cluster size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	struct page **rpages;		/* pages store raw data in cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	unsigned int nr_rpages;		/* total page number in rpages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	struct page **cpages;		/* pages store compressed data in cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	unsigned int nr_cpages;		/* total page number in cpages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	struct page **tpages;		/* temp pages to pad holes in cluster */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	void *rbuf;			/* virtual mapped address on rpages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	struct compress_data *cbuf;	/* virtual mapped address on cpages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 	size_t rlen;			/* valid data length in rbuf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	size_t clen;			/* valid data length in cbuf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	 * The number of compressed pages remaining to be read in this cluster.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	 * This is initially nr_cpages.  It is decremented by 1 each time a page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	 * has been read (or failed to be read).  When it reaches 0, the cluster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	 * is decompressed (or an error is reported).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	 * If an error occurs before all the pages have been submitted for I/O,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 	 * then this will never reach 0.  In this case the I/O submitter is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	 * responsible for calling f2fs_decompress_end_io() instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 	atomic_t remaining_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	 * Number of references to this decompress_io_ctx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	 * One reference is held for I/O completion.  This reference is dropped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	 * after the pagecache pages are updated and unlocked -- either after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	 * decompression (and verity if enabled), or after an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	 * In addition, each compressed page holds a reference while it is in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	 * bio.  These references are necessary prevent compressed pages from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	 * being freed while they are still in a bio.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	refcount_t refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	bool failed;			/* IO error occurred before decompression? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	bool need_verity;		/* need fs-verity verification after decompression? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	void *private;			/* payload buffer for specified decompression algorithm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	void *private2;			/* extra payload buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	struct work_struct verity_work;	/* work to verify the decompressed pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) #define NULL_CLUSTER			((unsigned int)(~0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) #define MIN_COMPRESS_LOG_SIZE		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) #define MAX_COMPRESS_LOG_SIZE		8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) #define MAX_COMPRESS_WINDOW_SIZE(log_size)	((PAGE_SIZE) << (log_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) struct f2fs_sb_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	struct super_block *sb;			/* pointer to VFS super block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	struct proc_dir_entry *s_proc;		/* proc entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	struct f2fs_super_block *raw_super;	/* raw super block pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	struct f2fs_rwsem sb_lock;		/* lock for raw super block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	int valid_super_block;			/* valid super block no */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	unsigned long s_flag;				/* flags for sbi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	struct mutex writepages;		/* mutex for writepages() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) #ifdef CONFIG_BLK_DEV_ZONED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	unsigned int blocks_per_blkz;		/* F2FS blocks per zone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	unsigned int log_blocks_per_blkz;	/* log2 F2FS blocks per zone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	/* for node-related operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	struct f2fs_nm_info *nm_info;		/* node manager */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	struct inode *node_inode;		/* cache node blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	/* for segment-related operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	struct f2fs_sm_info *sm_info;		/* segment manager */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	/* for bio operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	struct f2fs_bio_info *write_io[NR_PAGE_TYPE];	/* for write bios */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	/* keep migration IO order for LFS mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	struct f2fs_rwsem io_order_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	mempool_t *write_io_dummy;		/* Dummy pages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	/* for checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	int cur_cp_pack;			/* remain current cp pack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	spinlock_t cp_lock;			/* for flag in ckpt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	struct inode *meta_inode;		/* cache meta blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 	struct f2fs_rwsem cp_global_sem;	/* checkpoint procedure lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	struct f2fs_rwsem cp_rwsem;		/* blocking FS operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	struct f2fs_rwsem node_write;		/* locking node writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	struct f2fs_rwsem node_change;	/* locking node change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	wait_queue_head_t cp_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	unsigned long last_time[MAX_TIME];	/* to store time in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	long interval_time[MAX_TIME];		/* to store thresholds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	struct ckpt_req_control cprc_info;	/* for checkpoint request control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	struct inode_management im[MAX_INO_ENTRY];	/* manage inode cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	spinlock_t fsync_node_lock;		/* for node entry lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	struct list_head fsync_node_list;	/* node list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	unsigned int fsync_seg_id;		/* sequence id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	unsigned int fsync_node_num;		/* number of node entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 	/* for orphan inode, use 0'th array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	unsigned int max_orphans;		/* max orphan inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	/* for inode management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	struct list_head inode_list[NR_INODE_TYPE];	/* dirty inode list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	spinlock_t inode_lock[NR_INODE_TYPE];	/* for dirty inode list lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	struct mutex flush_lock;		/* for flush exclusion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 	/* for extent tree cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 	struct radix_tree_root extent_tree_root;/* cache extent cache entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	struct mutex extent_tree_lock;	/* locking extent radix tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	struct list_head extent_list;		/* lru list for shrinker */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	spinlock_t extent_lock;			/* locking extent lru list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	atomic_t total_ext_tree;		/* extent tree count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	struct list_head zombie_list;		/* extent zombie tree list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 	atomic_t total_zombie_tree;		/* extent zombie tree count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	atomic_t total_ext_node;		/* extent info count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	/* basic filesystem units */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	unsigned int log_sectors_per_block;	/* log2 sectors per block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	unsigned int log_blocksize;		/* log2 block size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	unsigned int blocksize;			/* block size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	unsigned int root_ino_num;		/* root inode number*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	unsigned int node_ino_num;		/* node inode number*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	unsigned int meta_ino_num;		/* meta inode number*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	unsigned int log_blocks_per_seg;	/* log2 blocks per segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	unsigned int blocks_per_seg;		/* blocks per segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	unsigned int segs_per_sec;		/* segments per section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 	unsigned int secs_per_zone;		/* sections per zone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	unsigned int total_sections;		/* total section count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	unsigned int total_node_count;		/* total node block count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	unsigned int total_valid_node_count;	/* valid node block count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	int dir_level;				/* directory level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	int readdir_ra;				/* readahead inode in readdir */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	u64 max_io_bytes;			/* max io bytes to merge IOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	block_t user_block_count;		/* # of user blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	block_t total_valid_block_count;	/* # of valid blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	block_t discard_blks;			/* discard command candidats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	block_t last_valid_block_count;		/* for recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	block_t reserved_blocks;		/* configurable reserved blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	block_t current_reserved_blocks;	/* current reserved blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	/* Additional tracking for no checkpoint mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	block_t unusable_block_count;		/* # of blocks saved by last cp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	unsigned int nquota_files;		/* # of quota sysfile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	struct f2fs_rwsem quota_sem;		/* blocking cp for flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	/* # of pages, see count_type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	atomic_t nr_pages[NR_COUNT_TYPE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	/* # of allocated blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	struct percpu_counter alloc_valid_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	/* writeback control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	atomic_t wb_sync_req[META];	/* count # of WB_SYNC threads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	/* valid inode count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	struct percpu_counter total_valid_inode_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	struct f2fs_mount_info mount_opt;	/* mount options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	/* for cleaning operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	struct f2fs_rwsem gc_lock;		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 						 * semaphore for GC, avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 						 * race between GC and GC or CP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 						 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	struct f2fs_gc_kthread	*gc_thread;	/* GC thread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	struct atgc_management am;		/* atgc management */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	unsigned int cur_victim_sec;		/* current victim section num */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	unsigned int gc_mode;			/* current GC state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	unsigned int next_victim_seg[2];	/* next segment in victim section */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	/* for skip statistic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	unsigned int atomic_files;		/* # of opened atomic file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	unsigned long long skipped_atomic_files[2];	/* FG_GC and BG_GC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	unsigned long long skipped_gc_rwsem;		/* FG_GC only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	/* threshold for gc trials on pinned files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	u64 gc_pin_file_threshold;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	struct f2fs_rwsem pin_sem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	/* maximum # of trials to find a victim segment for SSR and GC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	unsigned int max_victim_search;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	/* migration granularity of garbage collection, unit: segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	unsigned int migration_granularity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	atomic_t no_cp_fsync_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	 * for stat information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	 * one is for the LFS mode, and the other is for the SSR mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) #ifdef CONFIG_F2FS_STAT_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	struct f2fs_stat_info *stat_info;	/* FS status information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	atomic_t meta_count[META_MAX];		/* # of meta blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 	unsigned int segment_count[2];		/* # of allocated segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	unsigned int block_count[2];		/* # of allocated blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 	atomic_t inplace_count;		/* # of inplace update */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	atomic64_t total_hit_ext;		/* # of lookup extent cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	atomic64_t read_hit_rbtree;		/* # of hit rbtree extent node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	atomic64_t read_hit_largest;		/* # of hit largest extent node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 	atomic64_t read_hit_cached;		/* # of hit cached extent node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	atomic_t inline_xattr;			/* # of inline_xattr inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 	atomic_t inline_inode;			/* # of inline_data inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	atomic_t inline_dir;			/* # of inline_dentry inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	atomic_t compr_inode;			/* # of compressed inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	atomic64_t compr_blocks;		/* # of compressed blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	atomic_t vw_cnt;			/* # of volatile writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	atomic_t max_aw_cnt;			/* max # of atomic writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 	atomic_t max_vw_cnt;			/* max # of volatile writes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 	unsigned int io_skip_bggc;		/* skip background gc for in-flight IO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	unsigned int other_skip_bggc;		/* skip background gc for other reasons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	unsigned int ndirty_inode[NR_INODE_TYPE];	/* # of dirty inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 	spinlock_t stat_lock;			/* lock for stat operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 	/* For app/fs IO statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	spinlock_t iostat_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	unsigned long long rw_iostat[NR_IO_TYPE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 	unsigned long long prev_rw_iostat[NR_IO_TYPE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	bool iostat_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	unsigned long iostat_next_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	unsigned int iostat_period_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 	/* to attach REQ_META|REQ_FUA flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	unsigned int data_io_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	unsigned int node_io_flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	/* For sysfs suppport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	struct kobject s_kobj;			/* /sys/fs/f2fs/<devname> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	struct completion s_kobj_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	struct kobject s_stat_kobj;		/* /sys/fs/f2fs/<devname>/stat */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	struct completion s_stat_kobj_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	struct kobject s_feature_list_kobj;		/* /sys/fs/f2fs/<devname>/feature_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	struct completion s_feature_list_kobj_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	/* For shrinker support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	struct list_head s_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	int s_ndevs;				/* number of devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 	struct f2fs_dev_info *devs;		/* for device list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	unsigned int dirty_device;		/* for checkpoint data flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	spinlock_t dev_lock;			/* protect dirty_device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	struct mutex umount_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	unsigned int shrinker_run_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	/* For write statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 	u64 sectors_written_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 	u64 kbytes_written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	/* Reference to checksum algorithm driver via cryptoapi */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	struct crypto_shash *s_chksum_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	/* Precomputed FS UUID checksum for seeding other checksums */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	__u32 s_chksum_seed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	struct workqueue_struct *post_read_wq;	/* post read workqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	struct kmem_cache *inline_xattr_slab;	/* inline xattr entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	unsigned int inline_xattr_slab_size;	/* default inline xattr slab size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	/* For reclaimed segs statistics per each GC mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	unsigned int gc_segment_mode;		/* GC state for reclaimed segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	unsigned int gc_reclaimed_segs[MAX_GC_MODE];	/* Reclaimed segs for each mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) #ifdef CONFIG_F2FS_FS_COMPRESSION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	struct kmem_cache *page_array_slab;	/* page array entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	unsigned int page_array_slab_size;	/* default page array slab size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	/* For runtime compression statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	u64 compr_written_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	u64 compr_saved_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	u32 compr_new_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	/* For compressed block cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	struct inode *compress_inode;		/* cache compressed blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	unsigned int compress_percent;		/* cache page percentage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	unsigned int compress_watermark;	/* cache page watermark */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	atomic_t compress_page_hit;		/* cache hit count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) struct f2fs_private_dio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	void *orig_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 	bio_end_io_t *orig_end_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	bool write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) #ifdef CONFIG_F2FS_FAULT_INJECTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) #define f2fs_show_injection_info(sbi, type)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	printk_ratelimited("%sF2FS-fs (%s) : inject %s in %s of %pS\n",	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 		KERN_INFO, sbi->sb->s_id,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 		f2fs_fault_name[type],					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 		__func__, __builtin_return_address(0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 	if (!ffi->inject_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	if (!IS_FAULT_SET(ffi, type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	atomic_inc(&ffi->inject_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 		atomic_set(&ffi->inject_ops, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) #define f2fs_show_injection_info(sbi, type) do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812)  * Test if the mounted volume is a multi-device volume.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813)  *   - For a single regular disk volume, sbi->s_ndevs is 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)  *   - For a single zoned disk volume, sbi->s_ndevs is 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)  *   - For a multi-device volume, sbi->s_ndevs is always 2 or more.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	return sbi->s_ndevs > 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	sbi->last_time[type] = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	/* DISCARD_TIME and GC_TIME are based on REQ_TIME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 	if (type == REQ_TIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 		sbi->last_time[DISCARD_TIME] = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 		sbi->last_time[GC_TIME] = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	unsigned long interval = sbi->interval_time[type] * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 	return time_after(jiffies, sbi->last_time[type] + interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 						int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	unsigned long interval = sbi->interval_time[type] * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 	unsigned int wait_ms = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	long delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	delta = (sbi->last_time[type] + interval) - jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 	if (delta > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 		wait_ms = jiffies_to_msecs(delta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 	return wait_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857)  * Inline functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 			      const void *address, unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 		struct shash_desc shash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 		char ctx[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 	} desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	desc.shash.tfm = sbi->s_chksum_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	*(u32 *)desc.ctx = crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	err = crypto_shash_update(&desc.shash, address, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	BUG_ON(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 	return *(u32 *)desc.ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 			   unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 				  void *buf, size_t buf_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 	return f2fs_crc32(sbi, buf, buf_size) == blk_crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 			      const void *address, unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	return __f2fs_crc32(sbi, crc, address, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 	return container_of(inode, struct f2fs_inode_info, vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 	return sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	return F2FS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 	return F2FS_I_SB(mapping->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	return F2FS_M_SB(page_file_mapping(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 	return (struct f2fs_super_block *)(sbi->raw_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	return (struct f2fs_checkpoint *)(sbi->ckpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) static inline struct f2fs_node *F2FS_NODE(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 	return (struct f2fs_node *)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) static inline struct f2fs_inode *F2FS_INODE(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 	return &((struct f2fs_node *)page_address(page))->i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 	return (struct f2fs_nm_info *)(sbi->nm_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	return (struct f2fs_sm_info *)(sbi->sm_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 	return (struct sit_info *)(SM_I(sbi)->sit_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	return (struct free_segmap_info *)(SM_I(sbi)->free_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 	return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	return sbi->meta_inode->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 	return sbi->node_inode->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 	return test_bit(type, &sbi->s_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	set_bit(type, &sbi->s_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 	clear_bit(type, &sbi->s_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 	return le64_to_cpu(cp->checkpoint_ver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 	if (type < F2FS_MAX_QUOTAS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 		return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 	size_t crc_offset = le32_to_cpu(cp->checksum_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 	return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 	return ckpt_flags & f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 	return __is_set_ckpt_flags(F2FS_CKPT(sbi), f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 	unsigned int ckpt_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 	ckpt_flags = le32_to_cpu(cp->ckpt_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	ckpt_flags |= f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	spin_lock_irqsave(&sbi->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	__set_ckpt_flags(F2FS_CKPT(sbi), f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	spin_unlock_irqrestore(&sbi->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 	unsigned int ckpt_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 	ckpt_flags = le32_to_cpu(cp->ckpt_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 	ckpt_flags &= (~f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 	spin_lock_irqsave(&sbi->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 	__clear_ckpt_flags(F2FS_CKPT(sbi), f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 	spin_unlock_irqrestore(&sbi->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 	unsigned char *nat_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 	 * In order to re-enable nat_bits we need to call fsck.f2fs by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 	 * set_sbi_flag(sbi, SBI_NEED_FSCK). But it may give huge cost,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 	 * so let's rely on regular fsck or unclean shutdown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 	if (lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 		spin_lock_irqsave(&sbi->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	__clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 	nat_bits = NM_I(sbi)->nat_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 	NM_I(sbi)->nat_bits = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 	if (lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 		spin_unlock_irqrestore(&sbi->cp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 	kvfree(nat_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 					struct cp_control *cpc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) #define init_f2fs_rwsem(sem)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	static struct lock_class_key __key;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 	__init_f2fs_rwsem((sem), #sem, &__key);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) static inline void __init_f2fs_rwsem(struct f2fs_rwsem *sem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 		const char *sem_name, struct lock_class_key *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	__init_rwsem(&sem->internal_rwsem, sem_name, key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 	init_waitqueue_head(&sem->read_waiters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) static inline int f2fs_rwsem_is_locked(struct f2fs_rwsem *sem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 	return rwsem_is_locked(&sem->internal_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) static inline int f2fs_rwsem_is_contended(struct f2fs_rwsem *sem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	return rwsem_is_contended(&sem->internal_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) static inline void f2fs_down_read(struct f2fs_rwsem *sem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 	wait_event(sem->read_waiters, down_read_trylock(&sem->internal_rwsem));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) static inline int f2fs_down_read_trylock(struct f2fs_rwsem *sem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 	return down_read_trylock(&sem->internal_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) #ifdef CONFIG_DEBUG_LOCK_ALLOC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) static inline void f2fs_down_read_nested(struct f2fs_rwsem *sem, int subclass)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 	down_read_nested(&sem->internal_rwsem, subclass);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) #define f2fs_down_read_nested(sem, subclass) f2fs_down_read(sem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) static inline void f2fs_up_read(struct f2fs_rwsem *sem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 	up_read(&sem->internal_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) static inline void f2fs_down_write(struct f2fs_rwsem *sem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	down_write(&sem->internal_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) static inline int f2fs_down_write_trylock(struct f2fs_rwsem *sem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 	return down_write_trylock(&sem->internal_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) static inline void f2fs_up_write(struct f2fs_rwsem *sem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 	up_write(&sem->internal_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 	wake_up_all(&sem->read_waiters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	f2fs_down_read(&sbi->cp_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 	return f2fs_down_read_trylock(&sbi->cp_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 	f2fs_up_read(&sbi->cp_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 	f2fs_down_write(&sbi->cp_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	f2fs_up_write(&sbi->cp_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 	int reason = CP_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 	if (test_opt(sbi, FASTBOOT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 		reason = CP_FASTBOOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 	if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		reason = CP_UMOUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 	return reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) static inline bool __remain_node_summaries(int reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 	return (reason & (CP_UMOUNT | CP_FASTBOOT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 	return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 			is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200)  * Check whether the inode has blocks or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) static inline int F2FS_HAS_BLOCKS(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 	block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 	return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) static inline bool f2fs_has_xattr_block(unsigned int ofs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	return ofs == XATTR_NODE_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 					struct inode *inode, bool cap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 	if (!test_opt(sbi, RESERVE_ROOT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 	if (IS_NOQUOTA(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 	if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 	if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 					in_group_p(F2FS_OPTION(sbi).s_resgid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 	if (cap && capable(CAP_SYS_RESOURCE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 				 struct inode *inode, blkcnt_t *count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	blkcnt_t diff = 0, release = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 	block_t avail_user_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 	ret = dquot_reserve_block(inode, *count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 	if (time_to_inject(sbi, FAULT_BLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 		f2fs_show_injection_info(sbi, FAULT_BLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 		release = *count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 		goto release_quota;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 	 * let's increase this in prior to actual block count change in order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 	 * for f2fs_sync_file to avoid data races when deciding checkpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	percpu_counter_add(&sbi->alloc_valid_block_count, (*count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) 	spin_lock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 	sbi->total_valid_block_count += (block_t)(*count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 	avail_user_block_count = sbi->user_block_count -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) 					sbi->current_reserved_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) 	if (!__allow_reserved_blocks(sbi, inode, true))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) 		avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) 	if (F2FS_IO_ALIGNED(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) 		avail_user_block_count -= sbi->blocks_per_seg *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 				SM_I(sbi)->additional_reserved_segments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) 	if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) 		if (avail_user_block_count > sbi->unusable_block_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) 			avail_user_block_count -= sbi->unusable_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 			avail_user_block_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 		diff = sbi->total_valid_block_count - avail_user_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 		if (diff > *count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 			diff = *count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 		*count -= diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 		release = diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 		sbi->total_valid_block_count -= diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 		if (!*count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 			spin_unlock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 			goto enospc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) 	spin_unlock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) 	if (unlikely(release)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) 		percpu_counter_sub(&sbi->alloc_valid_block_count, release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) 		dquot_release_reservation_block(inode, release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) 	f2fs_i_blocks_write(inode, *count, true, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) enospc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) 	percpu_counter_sub(&sbi->alloc_valid_block_count, release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) release_quota:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 	dquot_release_reservation_block(inode, release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 	return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) __printf(2, 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) #define f2fs_err(sbi, fmt, ...)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 	f2fs_printk(sbi, KERN_ERR fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) #define f2fs_warn(sbi, fmt, ...)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 	f2fs_printk(sbi, KERN_WARNING fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) #define f2fs_notice(sbi, fmt, ...)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 	f2fs_printk(sbi, KERN_NOTICE fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) #define f2fs_info(sbi, fmt, ...)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 	f2fs_printk(sbi, KERN_INFO fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) #define f2fs_debug(sbi, fmt, ...)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) 	f2fs_printk(sbi, KERN_DEBUG fmt, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) 						struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) 						block_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) 	blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) 	spin_lock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) 	f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) 	sbi->total_valid_block_count -= (block_t)count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 	if (sbi->reserved_blocks &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 		sbi->current_reserved_blocks < sbi->reserved_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 		sbi->current_reserved_blocks = min(sbi->reserved_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 					sbi->current_reserved_blocks + count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 	spin_unlock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 	if (unlikely(inode->i_blocks < sectors)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 		f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 			  inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 			  (unsigned long long)inode->i_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 			  (unsigned long long)sectors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 		set_sbi_flag(sbi, SBI_NEED_FSCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 	f2fs_i_blocks_write(inode, count, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) 	atomic_inc(&sbi->nr_pages[count_type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 	if (count_type == F2FS_DIRTY_DENTS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 			count_type == F2FS_DIRTY_NODES ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 			count_type == F2FS_DIRTY_META ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 			count_type == F2FS_DIRTY_QDATA ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 			count_type == F2FS_DIRTY_IMETA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 		set_sbi_flag(sbi, SBI_IS_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) static inline void inode_inc_dirty_pages(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 	atomic_inc(&F2FS_I(inode)->dirty_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 	inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) 	if (IS_NOQUOTA(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 		inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 	atomic_dec(&sbi->nr_pages[count_type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) static inline void inode_dec_dirty_pages(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 	if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 			!S_ISLNK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	atomic_dec(&F2FS_I(inode)->dirty_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 	if (IS_NOQUOTA(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 		dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 	return atomic_read(&sbi->nr_pages[count_type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) static inline int get_dirty_pages(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	return atomic_read(&F2FS_I(inode)->dirty_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 	unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 	unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 						sbi->log_blocks_per_seg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 	return segs / sbi->segs_per_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	return sbi->total_valid_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) static inline block_t discard_blocks(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 	return sbi->discard_blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 	/* return NAT or SIT bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 	if (flag == NAT_BITMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 		return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 	else if (flag == SIT_BITMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 		return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 	return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 	void *tmp_ptr = &ckpt->sit_nat_version_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 	int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 	if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 		offset = (flag == SIT_BITMAP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 			le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 		 * if large_nat_bitmap feature is enabled, leave checksum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 		 * protection for all nat/sit bitmaps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 		return tmp_ptr + offset + sizeof(__le32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 	if (__cp_payload(sbi) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 		if (flag == NAT_BITMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 			return &ckpt->sit_nat_version_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 			return (unsigned char *)ckpt + F2FS_BLKSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 		offset = (flag == NAT_BITMAP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 			le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 		return tmp_ptr + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 	block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 	if (sbi->cur_cp_pack == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 		start_addr += sbi->blocks_per_seg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 	return start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 	block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 	if (sbi->cur_cp_pack == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 		start_addr += sbi->blocks_per_seg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 	return start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 	sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 	return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 					struct inode *inode, bool is_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 	block_t	valid_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 	unsigned int valid_node_count, user_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 	if (is_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 		if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 			err = dquot_alloc_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 		err = dquot_reserve_block(inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 	if (time_to_inject(sbi, FAULT_BLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 		f2fs_show_injection_info(sbi, FAULT_BLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 		goto enospc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 	spin_lock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) 	valid_block_count = sbi->total_valid_block_count +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) 					sbi->current_reserved_blocks + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) 	if (!__allow_reserved_blocks(sbi, inode, false))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) 		valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) 	if (F2FS_IO_ALIGNED(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) 		valid_block_count += sbi->blocks_per_seg *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) 				SM_I(sbi)->additional_reserved_segments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) 	user_block_count = sbi->user_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) 	if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) 		user_block_count -= sbi->unusable_block_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) 	if (unlikely(valid_block_count > user_block_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) 		spin_unlock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) 		goto enospc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) 	valid_node_count = sbi->total_valid_node_count + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) 	if (unlikely(valid_node_count > sbi->total_node_count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) 		spin_unlock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) 		goto enospc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) 	sbi->total_valid_node_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) 	sbi->total_valid_block_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) 	spin_unlock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) 	if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) 		if (is_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) 			f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) 			f2fs_i_blocks_write(inode, 1, true, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 	percpu_counter_inc(&sbi->alloc_valid_block_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) enospc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) 	if (is_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) 		if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) 			dquot_free_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) 		dquot_release_reservation_block(inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) 	return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) 					struct inode *inode, bool is_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) 	spin_lock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 	f2fs_bug_on(sbi, !sbi->total_valid_block_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) 	f2fs_bug_on(sbi, !sbi->total_valid_node_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) 	sbi->total_valid_node_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) 	sbi->total_valid_block_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) 	if (sbi->reserved_blocks &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) 		sbi->current_reserved_blocks < sbi->reserved_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) 		sbi->current_reserved_blocks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) 	spin_unlock(&sbi->stat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) 	if (is_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) 		dquot_free_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) 		if (unlikely(inode->i_blocks == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) 			f2fs_warn(sbi, "dec_valid_node_count: inconsistent i_blocks, ino:%lu, iblocks:%llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) 				  inode->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) 				  (unsigned long long)inode->i_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) 			set_sbi_flag(sbi, SBI_NEED_FSCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) 		f2fs_i_blocks_write(inode, 1, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) 	return sbi->total_valid_node_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) 	percpu_counter_inc(&sbi->total_valid_inode_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) 	percpu_counter_dec(&sbi->total_valid_inode_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) static inline s64 valid_inode_count(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) 	return percpu_counter_sum_positive(&sbi->total_valid_inode_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) 						pgoff_t index, bool for_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) 	if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) 		if (!for_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) 			page = find_get_page_flags(mapping, index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) 							FGP_LOCK | FGP_ACCESSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) 			page = find_lock_page(mapping, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 		if (page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 			return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) 		if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) 			f2fs_show_injection_info(F2FS_M_SB(mapping),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) 							FAULT_PAGE_ALLOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) 	if (!for_write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) 		return grab_cache_page(mapping, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) 	return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) static inline struct page *f2fs_pagecache_get_page(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) 				struct address_space *mapping, pgoff_t index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) 				int fgp_flags, gfp_t gfp_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) 	if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) 		f2fs_show_injection_info(F2FS_M_SB(mapping), FAULT_PAGE_GET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) 	return pagecache_get_page(mapping, index, fgp_flags, gfp_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) static inline void f2fs_copy_page(struct page *src, struct page *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) 	char *src_kaddr = kmap(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) 	char *dst_kaddr = kmap(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) 	memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 	kunmap(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 	kunmap(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) static inline void f2fs_put_page(struct page *page, int unlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 	if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 	if (unlock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 		f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) static inline void f2fs_put_dnode(struct dnode_of_data *dn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 	if (dn->node_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 		f2fs_put_page(dn->node_page, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 	if (dn->inode_page && dn->node_page != dn->inode_page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 		f2fs_put_page(dn->inode_page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 	dn->node_page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 	dn->inode_page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 					size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 	return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 						gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 	entry = kmem_cache_alloc(cachep, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 	if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 		entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 	return entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) static inline bool is_inflight_io(struct f2fs_sb_info *sbi, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 	if (get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_RD_NODE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 		get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 		get_pages(sbi, F2FS_WB_CP_DATA) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 		get_pages(sbi, F2FS_DIO_READ) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 		get_pages(sbi, F2FS_DIO_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 	if (type != DISCARD_TIME && SM_I(sbi) && SM_I(sbi)->dcc_info &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 			atomic_read(&SM_I(sbi)->dcc_info->queued_discard))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 	if (SM_I(sbi) && SM_I(sbi)->fcc_info &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 			atomic_read(&SM_I(sbi)->fcc_info->queued_flush))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) static inline bool is_idle(struct f2fs_sb_info *sbi, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) 	if (sbi->gc_mode == GC_URGENT_HIGH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) 	if (is_inflight_io(sbi, type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) 	if (sbi->gc_mode == GC_URGENT_LOW &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) 			(type == DISCARD_TIME || type == GC_TIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) 	return f2fs_time_over(sbi, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) 				unsigned long index, void *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) 	while (radix_tree_insert(root, index, item))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) #define RAW_IS_INODE(p)	((p)->footer.nid == (p)->footer.ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) static inline bool IS_INODE(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) 	struct f2fs_node *p = F2FS_NODE(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) 	return RAW_IS_INODE(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) static inline int offset_in_addr(struct f2fs_inode *i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 	return (i->i_inline & F2FS_EXTRA_ATTR) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) 			(le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) 	return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) static inline int f2fs_has_extra_attr(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) static inline block_t data_blkaddr(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) 			struct page *node_page, unsigned int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 	struct f2fs_node *raw_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) 	__le32 *addr_array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) 	int base = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) 	bool is_inode = IS_INODE(node_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 	raw_node = F2FS_NODE(node_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) 	if (is_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) 		if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) 			/* from GC path only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) 			base = offset_in_addr(&raw_node->i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) 		else if (f2fs_has_extra_attr(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) 			base = get_extra_isize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) 	addr_array = blkaddr_in_node(raw_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) 	return le32_to_cpu(addr_array[base + offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) static inline block_t f2fs_data_blkaddr(struct dnode_of_data *dn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 	return data_blkaddr(dn->inode, dn->node_page, dn->ofs_in_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) static inline int f2fs_test_bit(unsigned int nr, char *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) 	int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 	addr += (nr >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) 	mask = 1 << (7 - (nr & 0x07));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) 	return mask & *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) static inline void f2fs_set_bit(unsigned int nr, char *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) 	int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) 	addr += (nr >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) 	mask = 1 << (7 - (nr & 0x07));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) 	*addr |= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) static inline void f2fs_clear_bit(unsigned int nr, char *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) 	int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 	addr += (nr >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) 	mask = 1 << (7 - (nr & 0x07));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) 	*addr &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) 	int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) 	addr += (nr >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) 	mask = 1 << (7 - (nr & 0x07));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) 	ret = mask & *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) 	*addr |= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) 	int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) 	addr += (nr >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) 	mask = 1 << (7 - (nr & 0x07));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) 	ret = mask & *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) 	*addr &= ~mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) static inline void f2fs_change_bit(unsigned int nr, char *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) 	int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) 	addr += (nr >> 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) 	mask = 1 << (7 - (nr & 0x07));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) 	*addr ^= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846)  * On-disk inode flags (f2fs_inode::i_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) #define F2FS_COMPR_FL			0x00000004 /* Compress file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) #define F2FS_SYNC_FL			0x00000008 /* Synchronous updates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) #define F2FS_IMMUTABLE_FL		0x00000010 /* Immutable file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) #define F2FS_APPEND_FL			0x00000020 /* writes to file may only append */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) #define F2FS_NODUMP_FL			0x00000040 /* do not dump file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) #define F2FS_NOATIME_FL			0x00000080 /* do not update atime */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) #define F2FS_NOCOMP_FL			0x00000400 /* Don't compress */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) #define F2FS_INDEX_FL			0x00001000 /* hash-indexed directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) #define F2FS_DIRSYNC_FL			0x00010000 /* dirsync behaviour (directories only) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) #define F2FS_PROJINHERIT_FL		0x20000000 /* Create with parents projid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) #define F2FS_CASEFOLD_FL		0x40000000 /* Casefolded file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) /* Flags that should be inherited by new inodes from their parent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) 			   F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) 			   F2FS_CASEFOLD_FL | F2FS_COMPR_FL | F2FS_NOCOMP_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) /* Flags that are appropriate for regular files (all but dir-specific ones). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) #define F2FS_REG_FLMASK		(~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) 				F2FS_CASEFOLD_FL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) /* Flags that are appropriate for non-directories/regular files. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) #define F2FS_OTHER_FLMASK	(F2FS_NODUMP_FL | F2FS_NOATIME_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) 	if (S_ISDIR(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) 		return flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) 	else if (S_ISREG(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) 		return flags & F2FS_REG_FLMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) 		return flags & F2FS_OTHER_FLMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) static inline void __mark_inode_dirty_flag(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) 						int flag, bool set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) 	switch (flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 	case FI_INLINE_XATTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) 	case FI_INLINE_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) 	case FI_INLINE_DENTRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) 	case FI_NEW_INODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 		if (set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) 	case FI_DATA_EXIST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 	case FI_INLINE_DOTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) 	case FI_PIN_FILE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) 	case FI_COMPRESS_RELEASED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) 		f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) static inline void set_inode_flag(struct inode *inode, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) 	set_bit(flag, F2FS_I(inode)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) 	__mark_inode_dirty_flag(inode, flag, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) static inline int is_inode_flag_set(struct inode *inode, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) 	return test_bit(flag, F2FS_I(inode)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) static inline void clear_inode_flag(struct inode *inode, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 	clear_bit(flag, F2FS_I(inode)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 	__mark_inode_dirty_flag(inode, flag, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) static inline bool f2fs_verity_in_progress(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 	return IS_ENABLED(CONFIG_FS_VERITY) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 	       is_inode_flag_set(inode, FI_VERITY_IN_PROGRESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) static inline void set_acl_inode(struct inode *inode, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) 	F2FS_I(inode)->i_acl_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) 	set_inode_flag(inode, FI_ACL_MODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) 	f2fs_mark_inode_dirty_sync(inode, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) static inline void f2fs_i_links_write(struct inode *inode, bool inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) 	if (inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) 		inc_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) 		drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) static inline void f2fs_i_blocks_write(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) 					block_t diff, bool add, bool claim)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) 	bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 	bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) 	/* add = 1, claim = 1 should be dquot_reserve_block in pair */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947) 	if (add) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) 		if (claim)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) 			dquot_claim_block(inode, diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) 			dquot_alloc_block_nofail(inode, diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) 		dquot_free_block(inode, diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 	if (clean || recover)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) 		set_inode_flag(inode, FI_AUTO_RECOVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 	bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) 	bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) 	if (i_size_read(inode) == i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) 	i_size_write(inode, i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 	if (clean || recover)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) 		set_inode_flag(inode, FI_AUTO_RECOVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) 	F2FS_I(inode)->i_current_depth = depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) static inline void f2fs_i_gc_failures_write(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) 					unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) 	F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) 	F2FS_I(inode)->i_xattr_nid = xnid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) 	F2FS_I(inode)->i_pino = pino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002) 	struct f2fs_inode_info *fi = F2FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) 	if (ri->i_inline & F2FS_INLINE_XATTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005) 		set_bit(FI_INLINE_XATTR, fi->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) 	if (ri->i_inline & F2FS_INLINE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) 		set_bit(FI_INLINE_DATA, fi->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) 	if (ri->i_inline & F2FS_INLINE_DENTRY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) 		set_bit(FI_INLINE_DENTRY, fi->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) 	if (ri->i_inline & F2FS_DATA_EXIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) 		set_bit(FI_DATA_EXIST, fi->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) 	if (ri->i_inline & F2FS_INLINE_DOTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) 		set_bit(FI_INLINE_DOTS, fi->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) 	if (ri->i_inline & F2FS_EXTRA_ATTR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) 		set_bit(FI_EXTRA_ATTR, fi->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) 	if (ri->i_inline & F2FS_PIN_FILE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) 		set_bit(FI_PIN_FILE, fi->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) 	if (ri->i_inline & F2FS_COMPRESS_RELEASED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) 		set_bit(FI_COMPRESS_RELEASED, fi->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) 	ri->i_inline = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) 	if (is_inode_flag_set(inode, FI_INLINE_XATTR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) 		ri->i_inline |= F2FS_INLINE_XATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) 	if (is_inode_flag_set(inode, FI_INLINE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 		ri->i_inline |= F2FS_INLINE_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) 	if (is_inode_flag_set(inode, FI_INLINE_DENTRY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) 		ri->i_inline |= F2FS_INLINE_DENTRY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) 	if (is_inode_flag_set(inode, FI_DATA_EXIST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) 		ri->i_inline |= F2FS_DATA_EXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) 	if (is_inode_flag_set(inode, FI_INLINE_DOTS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) 		ri->i_inline |= F2FS_INLINE_DOTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) 	if (is_inode_flag_set(inode, FI_EXTRA_ATTR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) 		ri->i_inline |= F2FS_EXTRA_ATTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) 	if (is_inode_flag_set(inode, FI_PIN_FILE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) 		ri->i_inline |= F2FS_PIN_FILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) 	if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) 		ri->i_inline |= F2FS_COMPRESS_RELEASED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) static inline int f2fs_has_extra_attr(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) 	return is_inode_flag_set(inode, FI_EXTRA_ATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) static inline int f2fs_has_inline_xattr(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) 	return is_inode_flag_set(inode, FI_INLINE_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) static inline int f2fs_compressed_file(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) 	return S_ISREG(inode->i_mode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) 		is_inode_flag_set(inode, FI_COMPRESSED_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) static inline bool f2fs_need_compress_data(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) 	int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) 	if (!f2fs_compressed_file(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) 	if (compress_mode == COMPR_MODE_FS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) 	else if (compress_mode == COMPR_MODE_USER &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) 			is_inode_flag_set(inode, FI_ENABLE_COMPRESS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) static inline unsigned int addrs_per_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) 	unsigned int addrs = CUR_ADDRS_PER_INODE(inode) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) 				get_inline_xattr_addrs(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081) 	if (!f2fs_compressed_file(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) 		return addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) 	return ALIGN_DOWN(addrs, F2FS_I(inode)->i_cluster_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) static inline unsigned int addrs_per_block(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) 	if (!f2fs_compressed_file(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) 		return DEF_ADDRS_PER_BLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) 	return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, F2FS_I(inode)->i_cluster_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) static inline void *inline_xattr_addr(struct inode *inode, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) 	struct f2fs_inode *ri = F2FS_INODE(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) 	return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) 					get_inline_xattr_addrs(inode)]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) static inline int inline_xattr_size(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) 	if (f2fs_has_inline_xattr(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) 		return get_inline_xattr_addrs(inode) * sizeof(__le32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) static inline int f2fs_has_inline_data(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) 	return is_inode_flag_set(inode, FI_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) static inline int f2fs_exist_data(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) 	return is_inode_flag_set(inode, FI_DATA_EXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) static inline int f2fs_has_inline_dots(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) 	return is_inode_flag_set(inode, FI_INLINE_DOTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) static inline int f2fs_is_mmap_file(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) 	return is_inode_flag_set(inode, FI_MMAP_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) static inline bool f2fs_is_pinned_file(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) 	return is_inode_flag_set(inode, FI_PIN_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) static inline bool f2fs_is_atomic_file(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) 	return is_inode_flag_set(inode, FI_ATOMIC_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) static inline bool f2fs_is_commit_atomic_write(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) 	return is_inode_flag_set(inode, FI_ATOMIC_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) static inline bool f2fs_is_volatile_file(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) 	return is_inode_flag_set(inode, FI_VOLATILE_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) static inline bool f2fs_is_first_block_written(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 	return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) static inline bool f2fs_is_drop_cache(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) 	return is_inode_flag_set(inode, FI_DROP_CACHE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) static inline void *inline_data_addr(struct inode *inode, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) 	struct f2fs_inode *ri = F2FS_INODE(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) 	int extra_size = get_extra_isize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) 	return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) static inline int f2fs_has_inline_dentry(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) 	return is_inode_flag_set(inode, FI_INLINE_DENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) static inline int is_file(struct inode *inode, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) 	return F2FS_I(inode)->i_advise & type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) static inline void set_file(struct inode *inode, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) 	F2FS_I(inode)->i_advise |= type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) static inline void clear_file(struct inode *inode, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) 	F2FS_I(inode)->i_advise &= ~type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) static inline bool f2fs_is_time_consistent(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) 	if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) 	if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 	if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) 	if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) 						&F2FS_I(inode)->i_crtime))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) 	bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) 	if (dsync) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207) 		struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) 		spin_lock(&sbi->inode_lock[DIRTY_META]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 		ret = list_empty(&F2FS_I(inode)->gdirty_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) 		spin_unlock(&sbi->inode_lock[DIRTY_META]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) 	if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) 			file_keep_isize(inode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) 			i_size_read(inode) & ~PAGE_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) 	if (!f2fs_is_time_consistent(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) 	spin_lock(&F2FS_I(inode)->i_size_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) 	ret = F2FS_I(inode)->last_disk_size == i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) 	spin_unlock(&F2FS_I(inode)->i_size_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) static inline bool f2fs_readonly(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 	return sb_rdonly(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) 	return is_set_ckpt_flags(sbi, CP_ERROR_FLAG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) static inline bool is_dot_dotdot(const u8 *name, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) 	if (len == 1 && name[0] == '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) 	if (len == 2 && name[0] == '.' && name[1] == '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) 					size_t size, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) 	if (time_to_inject(sbi, FAULT_KMALLOC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) 		f2fs_show_injection_info(sbi, FAULT_KMALLOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) 	return kmalloc(size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) 					size_t size, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) 	return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) 					size_t size, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) 	if (time_to_inject(sbi, FAULT_KVMALLOC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) 		f2fs_show_injection_info(sbi, FAULT_KVMALLOC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) 	return kvmalloc(size, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) 					size_t size, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281) 	return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) static inline int get_extra_isize(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) 	return F2FS_I(inode)->i_extra_isize / sizeof(__le32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) static inline int get_inline_xattr_addrs(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) 	return F2FS_I(inode)->i_inline_xattr_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) #define f2fs_get_inode_mode(i) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) 	((is_inode_flag_set(i, FI_ACL_MODE)) ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296) 	 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) #define F2FS_TOTAL_EXTRA_ATTR_SIZE			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) 	(offsetof(struct f2fs_inode, i_extra_end) -	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) 	offsetof(struct f2fs_inode, i_extra_isize))	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) #define F2FS_OLD_ATTRIBUTE_SIZE	(offsetof(struct f2fs_inode, i_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) 		((offsetof(typeof(*(f2fs_inode)), field) +	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) 		sizeof((f2fs_inode)->field))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) 		<= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize)))	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) #define DEFAULT_IOSTAT_PERIOD_MS	3000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) #define MIN_IOSTAT_PERIOD_MS		100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) /* maximum period of iostat tracing is 1 day */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) #define MAX_IOSTAT_PERIOD_MS		8640000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) 	spin_lock(&sbi->iostat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) 	for (i = 0; i < NR_IO_TYPE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) 		sbi->rw_iostat[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) 		sbi->prev_rw_iostat[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) 	spin_unlock(&sbi->iostat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) extern void f2fs_record_iostat(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) 			enum iostat_type type, unsigned long long io_bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) 	if (!sbi->iostat_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) 	spin_lock(&sbi->iostat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) 	sbi->rw_iostat[type] += io_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) 	if (type == APP_WRITE_IO || type == APP_DIRECT_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) 		sbi->rw_iostat[APP_BUFFERED_IO] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) 			sbi->rw_iostat[APP_WRITE_IO] -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) 			sbi->rw_iostat[APP_DIRECT_IO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) 	if (type == APP_READ_IO || type == APP_DIRECT_READ_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) 		sbi->rw_iostat[APP_BUFFERED_READ_IO] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) 			sbi->rw_iostat[APP_READ_IO] -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) 			sbi->rw_iostat[APP_DIRECT_READ_IO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) 	spin_unlock(&sbi->iostat_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) 	f2fs_record_iostat(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) #define __is_large_section(sbi)		((sbi)->segs_per_sec > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) 					block_t blkaddr, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) static inline void verify_blkaddr(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) 					block_t blkaddr, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) 	if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) 		f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) 			 blkaddr, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) 		f2fs_bug_on(sbi, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) static inline bool __is_valid_data_blkaddr(block_t blkaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) 	if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) 			blkaddr == COMPRESS_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374)  * file.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) void f2fs_truncate_data_blocks(struct dnode_of_data *dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) int f2fs_truncate(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) int f2fs_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) 			u32 request_mask, unsigned int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) int f2fs_setattr(struct dentry *dentry, struct iattr *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) int f2fs_precache_extents(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) int f2fs_transfer_project_quota(struct inode *inode, kprojid_t kprojid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) int f2fs_pin_file_control(struct inode *inode, bool inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393)  * inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) void f2fs_set_inode_flags(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401) void f2fs_update_inode(struct inode *inode, struct page *node_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) void f2fs_update_inode_page(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) void f2fs_evict_inode(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) void f2fs_handle_failed_inode(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408)  * namei.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) 							bool hot, bool set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) struct dentry *f2fs_get_parent(struct dentry *child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415)  * dir.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) int f2fs_init_casefolded_name(const struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) 			      struct f2fs_filename *fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) int f2fs_setup_filename(struct inode *dir, const struct qstr *iname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) 			int lookup, struct f2fs_filename *fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) int f2fs_prepare_lookup(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) 			struct f2fs_filename *fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) void f2fs_free_filename(struct f2fs_filename *fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_ptr *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) 			const struct f2fs_filename *fname, int *max_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) 			unsigned int start_pos, struct fscrypt_str *fstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) 			struct f2fs_dentry_ptr *d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) 			const struct f2fs_filename *fname, struct page *dpage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) 			unsigned int current_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) void f2fs_drop_nlink(struct inode *dir, struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) 					 const struct f2fs_filename *fname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) 					 struct page **res_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) 			const struct qstr *child, struct page **res_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) 			struct page **page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) 			struct page *page, struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) bool f2fs_has_enough_room(struct inode *dir, struct page *ipage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) 			  const struct f2fs_filename *fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) 			const struct fscrypt_str *name, f2fs_hash_t name_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) 			unsigned int bit_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) 			struct inode *inode, nid_t ino, umode_t mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) int f2fs_add_dentry(struct inode *dir, const struct f2fs_filename *fname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) 			struct inode *inode, nid_t ino, umode_t mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) 			struct inode *inode, nid_t ino, umode_t mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) 			struct inode *dir, struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) int f2fs_do_tmpfile(struct inode *inode, struct inode *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) bool f2fs_empty_dir(struct inode *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) 	if (fscrypt_is_nokey_name(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) 		return -ENOKEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) 	return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) 				inode, inode->i_ino, inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472)  * super.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) int f2fs_inode_dirtied(struct inode *inode, bool sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) void f2fs_inode_synced(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) int f2fs_quota_sync(struct super_block *sb, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) loff_t max_file_blocks(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) void f2fs_quota_off_umount(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) int f2fs_sync_fs(struct super_block *sb, int sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485)  * hash.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) void f2fs_hash_filename(const struct inode *dir, struct f2fs_filename *fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490)  * node.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) struct node_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) 				struct node_info *ni, bool checkpoint_context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) int f2fs_truncate_xattr_node(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) 					unsigned int seq_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) int f2fs_remove_inode_page(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) struct page *f2fs_new_inode_page(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) struct page *f2fs_get_node_page_ra(struct page *parent, int start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) int f2fs_move_node_page(struct page *node_page, int gc_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) void f2fs_flush_inline_data(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) 			struct writeback_control *wbc, bool atomic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) 			unsigned int *seq_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) 			struct writeback_control *wbc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) 			bool do_balance, enum iostat_type io_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) int f2fs_recover_inline_xattr(struct inode *inode, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) int f2fs_recover_xattr_data(struct inode *inode, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) int f2fs_restore_node_summary(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) 			unsigned int segno, struct f2fs_summary_block *sum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) int f2fs_build_node_manager(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) int __init f2fs_create_node_manager_caches(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) void f2fs_destroy_node_manager_caches(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542)  * segment.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) bool f2fs_need_SSR(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) void f2fs_register_inmem_page(struct inode *inode, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) void f2fs_drop_inmem_pages(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) void f2fs_drop_inmem_page(struct inode *inode, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) int f2fs_commit_inmem_pages(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) int f2fs_flush_device_cache(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) 					struct cp_control *cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569) void f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) void f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) void f2fs_restore_inmem_curseg(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572) void f2fs_get_new_segment(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) 			unsigned int *newseg, bool new_sec, int dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575) 					unsigned int start, unsigned int end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) 					struct cp_control *cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) 					block_t blk_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) 						enum iostat_type io_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) void f2fs_outplace_write_data(struct dnode_of_data *dn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) 			struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) int f2fs_inplace_write_data(struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) 			block_t old_blkaddr, block_t new_blkaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) 			bool recover_curseg, bool recover_newaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) 			bool from_gc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) 			block_t old_addr, block_t new_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) 			unsigned char version, bool recover_curseg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) 			bool recover_newaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) 			block_t old_blkaddr, block_t *new_blkaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) 			struct f2fs_summary *sum, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) 			struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) void f2fs_wait_on_page_writeback(struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) 			enum page_type type, bool ordered, bool locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) 								block_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) 			unsigned int val, int alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) int f2fs_fix_curseg_write_pointer(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) int f2fs_check_write_pointer(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) int f2fs_build_segment_manager(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) int __init f2fs_create_segment_manager_caches(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) void f2fs_destroy_segment_manager_caches(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) int f2fs_rw_hint_to_seg_type(enum rw_hint hint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) 			enum page_type type, enum temp_type temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) 			unsigned int segno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) 			unsigned int segno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627)  * checkpoint.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630) struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) 					block_t blkaddr, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) 			int type, bool sync);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) 			long nr_to_write, enum iostat_type io_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) 					unsigned int devidx, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) 					unsigned int devidx, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) void f2fs_add_orphan_inode(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) void f2fs_update_dirty_page(struct inode *inode, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) void f2fs_remove_dirty_inode(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660) u64 f2fs_get_sectors_written(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) int __init f2fs_create_checkpoint_caches(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) void f2fs_destroy_checkpoint_caches(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) int f2fs_issue_checkpoint(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) void f2fs_stop_ckpt_thread(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671)  * data.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) int __init f2fs_init_bioset(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) void f2fs_destroy_bioset(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) int f2fs_init_bio_entry_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) void f2fs_destroy_bio_entry_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) void f2fs_submit_bio(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) 				struct bio *bio, enum page_type type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) 				struct inode *inode, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) 				nid_t ino, enum page_type type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) 					struct bio **bio, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) int f2fs_submit_page_bio(struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) int f2fs_merge_page_bio(struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) void f2fs_submit_page_write(struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) 			block_t blk_addr, struct bio *bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) void f2fs_set_data_blkaddr(struct dnode_of_data *dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) int f2fs_reserve_new_block(struct dnode_of_data *dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) 			int op_flags, bool for_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) 			bool for_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) struct page *f2fs_get_new_data_page(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) 			struct page *ipage, pgoff_t index, bool new_i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) int f2fs_do_write_data_page(struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) void f2fs_do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) 			int create, int flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) 			u64 start, u64 len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) int f2fs_encrypt_one_page(struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) int f2fs_write_single_data_page(struct page *page, int *submitted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) 				struct bio **bio, sector_t *last_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) 				struct writeback_control *wbc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) 				enum iostat_type io_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) 				int compr_blocks, bool allow_balance);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) void f2fs_invalidate_page(struct page *page, unsigned int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) 			unsigned int length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) int f2fs_release_page(struct page *page, gfp_t wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) #ifdef CONFIG_MIGRATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) int f2fs_migrate_page(struct address_space *mapping, struct page *newpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) 			struct page *page, enum migrate_mode mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) void f2fs_clear_page_cache_dirty_tag(struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) int f2fs_init_post_read_processing(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) void f2fs_destroy_post_read_processing(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) int f2fs_init_post_read_wq(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) void f2fs_destroy_post_read_wq(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735)  * gc.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) int f2fs_start_gc_thread(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, bool force,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) 			unsigned int segno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) void f2fs_build_gc_manager(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) int __init f2fs_create_garbage_collection_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) void f2fs_destroy_garbage_collection_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748)  * recovery.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) int __init f2fs_create_recovery_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) void f2fs_destroy_recovery_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756)  * debug.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) #ifdef CONFIG_F2FS_STAT_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) struct f2fs_stat_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) 	struct list_head stat_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) 	struct f2fs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) 	int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) 	int main_area_segs, main_area_sections, main_area_zones;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) 	unsigned long long hit_largest, hit_cached, hit_rbtree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) 	unsigned long long hit_total, total_ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) 	int ext_tree, zombie_tree, ext_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) 	int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) 	int ndirty_data, ndirty_qdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) 	int inmem_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) 	unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) 	int nats, dirty_nats, sits, dirty_sits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) 	int free_nids, avail_nids, alloc_nids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) 	int total_count, utilization;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774) 	int bg_gc, nr_wb_cp_data, nr_wb_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) 	int nr_rd_data, nr_rd_node, nr_rd_meta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) 	int nr_dio_read, nr_dio_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) 	unsigned int io_skip_bggc, other_skip_bggc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) 	int nr_flushing, nr_flushed, flush_list_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) 	int nr_discarding, nr_discarded;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) 	int nr_discard_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) 	unsigned int undiscard_blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) 	int nr_issued_ckpt, nr_total_ckpt, nr_queued_ckpt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) 	unsigned int cur_ckpt_time, peak_ckpt_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) 	int inline_xattr, inline_inode, inline_dir, append, update, orphans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) 	int compr_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) 	unsigned long long compr_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) 	int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) 	unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) 	unsigned int bimodal, avg_vblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790) 	int util_free, util_valid, util_invalid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) 	int rsvd_segs, overp_segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) 	int dirty_count, node_pages, meta_pages, compress_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) 	int compress_page_hit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) 	int prefree_count, call_count, cp_count, bg_cp_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) 	int tot_segs, node_segs, data_segs, free_segs, free_secs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) 	int bg_node_segs, bg_data_segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) 	int tot_blks, data_blks, node_blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) 	int bg_data_blks, bg_node_blks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) 	unsigned long long skipped_atomic_files[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) 	int curseg[NR_CURSEG_TYPE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) 	int cursec[NR_CURSEG_TYPE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) 	int curzone[NR_CURSEG_TYPE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) 	unsigned int dirty_seg[NR_CURSEG_TYPE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) 	unsigned int full_seg[NR_CURSEG_TYPE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) 	unsigned int valid_blks[NR_CURSEG_TYPE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) 	unsigned int meta_count[META_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) 	unsigned int segment_count[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) 	unsigned int block_count[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) 	unsigned int inplace_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) 	unsigned long long base_mem, cache_mem, page_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814) static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) 	return (struct f2fs_stat_info *)sbi->stat_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) #define stat_inc_cp_count(si)		((si)->cp_count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) #define stat_inc_bg_cp_count(si)	((si)->bg_cp_count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) #define stat_inc_call_count(si)		((si)->call_count++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822) #define stat_inc_bggc_count(si)		((si)->bg_gc++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) #define stat_io_skip_bggc_count(sbi)	((sbi)->io_skip_bggc++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) #define stat_other_skip_bggc_count(sbi)	((sbi)->other_skip_bggc++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) #define stat_inc_dirty_inode(sbi, type)	((sbi)->ndirty_inode[type]++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) #define stat_dec_dirty_inode(sbi, type)	((sbi)->ndirty_inode[type]--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) #define stat_inc_total_hit(sbi)		(atomic64_inc(&(sbi)->total_hit_ext))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) #define stat_inc_rbtree_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_rbtree))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) #define stat_inc_largest_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_largest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) #define stat_inc_cached_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_cached))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) #define stat_inc_inline_xattr(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) 		if (f2fs_has_inline_xattr(inode))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) 			(atomic_inc(&F2FS_I_SB(inode)->inline_xattr));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) #define stat_dec_inline_xattr(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) 		if (f2fs_has_inline_xattr(inode))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) 			(atomic_dec(&F2FS_I_SB(inode)->inline_xattr));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) #define stat_inc_inline_inode(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) 		if (f2fs_has_inline_data(inode))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) 			(atomic_inc(&F2FS_I_SB(inode)->inline_inode));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) #define stat_dec_inline_inode(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848) 		if (f2fs_has_inline_data(inode))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) 			(atomic_dec(&F2FS_I_SB(inode)->inline_inode));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) #define stat_inc_inline_dir(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) 		if (f2fs_has_inline_dentry(inode))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) 			(atomic_inc(&F2FS_I_SB(inode)->inline_dir));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) #define stat_dec_inline_dir(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) 		if (f2fs_has_inline_dentry(inode))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) 			(atomic_dec(&F2FS_I_SB(inode)->inline_dir));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) #define stat_inc_compr_inode(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) 		if (f2fs_compressed_file(inode))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) 			(atomic_inc(&F2FS_I_SB(inode)->compr_inode));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) #define stat_dec_compr_inode(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) 		if (f2fs_compressed_file(inode))			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) 			(atomic_dec(&F2FS_I_SB(inode)->compr_inode));	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) #define stat_add_compr_blocks(inode, blocks)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) 		(atomic64_add(blocks, &F2FS_I_SB(inode)->compr_blocks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) #define stat_sub_compr_blocks(inode, blocks)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) 		(atomic64_sub(blocks, &F2FS_I_SB(inode)->compr_blocks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) #define stat_inc_meta_count(sbi, blkaddr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) 		if (blkaddr < SIT_I(sbi)->sit_base_addr)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) 			atomic_inc(&(sbi)->meta_count[META_CP]);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) 		else if (blkaddr < NM_I(sbi)->nat_blkaddr)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) 			atomic_inc(&(sbi)->meta_count[META_SIT]);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) 		else if (blkaddr < SM_I(sbi)->ssa_blkaddr)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) 			atomic_inc(&(sbi)->meta_count[META_NAT]);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) 		else if (blkaddr < SM_I(sbi)->main_blkaddr)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) 			atomic_inc(&(sbi)->meta_count[META_SSA]);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) #define stat_inc_seg_type(sbi, curseg)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) 		((sbi)->segment_count[(curseg)->alloc_type]++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) #define stat_inc_block_count(sbi, curseg)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) 		((sbi)->block_count[(curseg)->alloc_type]++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) #define stat_inc_inplace_blocks(sbi)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) 		(atomic_inc(&(sbi)->inplace_count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) #define stat_update_max_atomic_write(inode)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) 		int cur = F2FS_I_SB(inode)->atomic_files;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) 		int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) 		if (cur > max)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) 			atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) #define stat_inc_volatile_write(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) 		(atomic_inc(&F2FS_I_SB(inode)->vw_cnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) #define stat_dec_volatile_write(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) 		(atomic_dec(&F2FS_I_SB(inode)->vw_cnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) #define stat_update_max_volatile_write(inode)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) 		int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) 		int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) 		if (cur > max)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) 			atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) #define stat_inc_seg_count(sbi, type, gc_type)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) 		si->tot_segs++;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) 		if ((type) == SUM_TYPE_DATA) {				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) 			si->data_segs++;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) 			si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) 		} else {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) 			si->node_segs++;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) 			si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) 		}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) #define stat_inc_tot_blk_count(si, blks)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) 	((si)->tot_blks += (blks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) #define stat_inc_data_blk_count(sbi, blks, gc_type)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) 		stat_inc_tot_blk_count(si, blks);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) 		si->data_blks += (blks);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) 		si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) #define stat_inc_node_blk_count(sbi, blks, gc_type)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) 		stat_inc_tot_blk_count(si, blks);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) 		si->node_blks += (blks);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) 		si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) int f2fs_build_stats(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) void f2fs_destroy_stats(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) void __init f2fs_create_root_stats(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) void f2fs_destroy_root_stats(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) void f2fs_update_sit_info(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) #define stat_inc_cp_count(si)				do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) #define stat_inc_bg_cp_count(si)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950) #define stat_inc_call_count(si)				do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) #define stat_inc_bggc_count(si)				do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) #define stat_io_skip_bggc_count(sbi)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953) #define stat_other_skip_bggc_count(sbi)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) #define stat_inc_dirty_inode(sbi, type)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) #define stat_dec_dirty_inode(sbi, type)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) #define stat_inc_total_hit(sbi)				do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) #define stat_inc_rbtree_node_hit(sbi)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) #define stat_inc_largest_node_hit(sbi)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) #define stat_inc_cached_node_hit(sbi)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) #define stat_inc_inline_xattr(inode)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) #define stat_dec_inline_xattr(inode)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) #define stat_inc_inline_inode(inode)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) #define stat_dec_inline_inode(inode)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) #define stat_inc_inline_dir(inode)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) #define stat_dec_inline_dir(inode)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) #define stat_inc_compr_inode(inode)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) #define stat_dec_compr_inode(inode)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) #define stat_add_compr_blocks(inode, blocks)		do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) #define stat_sub_compr_blocks(inode, blocks)		do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) #define stat_update_max_atomic_write(inode)		do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) #define stat_inc_volatile_write(inode)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972) #define stat_dec_volatile_write(inode)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) #define stat_update_max_volatile_write(inode)		do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) #define stat_inc_meta_count(sbi, blkaddr)		do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) #define stat_inc_seg_type(sbi, curseg)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) #define stat_inc_block_count(sbi, curseg)		do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) #define stat_inc_inplace_blocks(sbi)			do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) #define stat_inc_seg_count(sbi, type, gc_type)		do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) #define stat_inc_tot_blk_count(si, blks)		do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) #define stat_inc_data_blk_count(sbi, blks, gc_type)	do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) #define stat_inc_node_blk_count(sbi, blks, gc_type)	do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) static inline void __init f2fs_create_root_stats(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) static inline void f2fs_destroy_root_stats(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) static inline void f2fs_update_sit_info(struct f2fs_sb_info *sbi) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) extern const struct file_operations f2fs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) extern const struct file_operations f2fs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) extern const struct inode_operations f2fs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) extern const struct address_space_operations f2fs_dblock_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) extern const struct address_space_operations f2fs_node_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) extern const struct address_space_operations f2fs_meta_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) extern const struct inode_operations f2fs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) extern const struct inode_operations f2fs_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) extern const struct inode_operations f2fs_special_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) extern struct kmem_cache *f2fs_inode_entry_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003)  * inline.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005) bool f2fs_may_inline_data(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) bool f2fs_may_inline_dentry(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) void f2fs_do_read_inline_data(struct page *page, struct page *ipage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) void f2fs_truncate_inline_inode(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) 						struct page *ipage, u64 from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) int f2fs_read_inline_data(struct inode *inode, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) int f2fs_convert_inline_inode(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) int f2fs_write_inline_data(struct inode *inode, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) int f2fs_recover_inline_data(struct inode *inode, struct page *npage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) 					const struct f2fs_filename *fname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) 					struct page **res_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020) 			struct page *ipage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) 			struct inode *inode, nid_t ino, umode_t mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) 				struct page *page, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) 				struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) bool f2fs_empty_inline_dir(struct inode *dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) 			struct fscrypt_str *fstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) int f2fs_inline_data_fiemap(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) 			struct fiemap_extent_info *fieinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) 			__u64 start, __u64 len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034)  * shrinker.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) unsigned long f2fs_shrink_count(struct shrinker *shrink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) 			struct shrink_control *sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) unsigned long f2fs_shrink_scan(struct shrinker *shrink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) 			struct shrink_control *sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) void f2fs_join_shrinker(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) void f2fs_leave_shrinker(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044)  * extent_cache.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) struct rb_entry *f2fs_lookup_rb_tree(struct rb_root_cached *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) 				struct rb_entry *cached_re, unsigned int ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) struct rb_node **f2fs_lookup_rb_tree_ext(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) 				struct rb_root_cached *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) 				struct rb_node **parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) 				unsigned long long key, bool *left_most);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) 				struct rb_root_cached *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) 				struct rb_node **parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) 				unsigned int ofs, bool *leftmost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) 		struct rb_entry *cached_re, unsigned int ofs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) 		struct rb_entry **prev_entry, struct rb_entry **next_entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) 		struct rb_node ***insert_p, struct rb_node **insert_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) 		bool force, bool *leftmost);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) 				struct rb_root_cached *root, bool check_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) void f2fs_init_extent_tree(struct inode *inode, struct page *ipage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) void f2fs_drop_extent_tree(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066) unsigned int f2fs_destroy_extent_node(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) void f2fs_destroy_extent_tree(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) 			struct extent_info *ei);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) void f2fs_update_extent_cache(struct dnode_of_data *dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) 			pgoff_t fofs, block_t blkaddr, unsigned int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073) void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) int __init f2fs_create_extent_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) void f2fs_destroy_extent_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078)  * sysfs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) int __init f2fs_init_sysfs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) void f2fs_exit_sysfs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) int f2fs_register_sysfs(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) /* verity.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) extern const struct fsverity_operations f2fs_verityops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089)  * crypto support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) static inline bool f2fs_encrypted_file(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) 	return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) static inline void f2fs_set_encrypted_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) #ifdef CONFIG_FS_ENCRYPTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) 	file_set_encrypt(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) 	f2fs_set_inode_flags(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105)  * Returns true if the reads of the inode's data need to undergo some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106)  * postprocessing step, like decryption or authenticity verification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) static inline bool f2fs_post_read_required(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) 	return f2fs_encrypted_file(inode) || fsverity_active(inode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) 		f2fs_compressed_file(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115)  * compress.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) #ifdef CONFIG_F2FS_FS_COMPRESSION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) bool f2fs_is_compressed_page(struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) struct page *f2fs_compress_control_page(struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) int f2fs_prepare_compress_overwrite(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) 			struct page **pagep, pgoff_t index, void **fsdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) bool f2fs_compress_write_end(struct inode *inode, void *fsdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) 					pgoff_t index, unsigned copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124) int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) void f2fs_compress_write_end_io(struct bio *bio, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) bool f2fs_is_compress_backend_ready(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) int f2fs_init_compress_mempool(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) void f2fs_destroy_compress_mempool(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) void f2fs_decompress_cluster(struct decompress_io_ctx *dic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) void f2fs_end_read_compressed_page(struct page *page, bool failed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) 							block_t blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) bool f2fs_cluster_is_empty(struct compress_ctx *cc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) int f2fs_write_multi_pages(struct compress_ctx *cc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) 						int *submitted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) 						struct writeback_control *wbc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) 						enum iostat_type io_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140) int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) 				unsigned nr_pages, sector_t *last_block_in_bio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) 				bool is_readahead, bool for_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143) struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) void f2fs_decompress_end_io(struct decompress_io_ctx *dic, bool failed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) void f2fs_put_page_dic(struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) int f2fs_init_compress_ctx(struct compress_ctx *cc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) void f2fs_init_compress_info(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) int f2fs_init_compress_inode(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) void f2fs_destroy_compress_inode(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) int __init f2fs_init_compress_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) void f2fs_destroy_compress_cache(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) struct address_space *COMPRESS_MAPPING(struct f2fs_sb_info *sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) void f2fs_invalidate_compress_page(struct f2fs_sb_info *sbi, block_t blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157) void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) 						nid_t ino, block_t blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi, struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) 								block_t blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) void f2fs_invalidate_compress_pages(struct f2fs_sb_info *sbi, nid_t ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) #define inc_compr_inode_stat(inode)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) 		struct f2fs_sb_info *sbi = F2FS_I_SB(inode);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) 		sbi->compr_new_inode++;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) #define add_compr_block_stat(inode, blocks)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) 	do {								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) 		struct f2fs_sb_info *sbi = F2FS_I_SB(inode);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) 		int diff = F2FS_I(inode)->i_cluster_size - blocks;	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) 		sbi->compr_written_block += blocks;			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) 		sbi->compr_saved_block += diff;				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) static inline bool f2fs_is_compressed_page(struct page *page) { return false; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) static inline bool f2fs_is_compress_backend_ready(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) 	if (!f2fs_compressed_file(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) 	/* not support compression */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) static inline struct page *f2fs_compress_control_page(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) 	WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) 	return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) static inline int f2fs_init_compress_mempool(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) static inline void f2fs_destroy_compress_mempool(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) static inline void f2fs_decompress_cluster(struct decompress_io_ctx *dic) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) static inline void f2fs_end_read_compressed_page(struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) 						bool failed, block_t blkaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) 	WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) static inline void f2fs_put_page_dic(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) 	WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) static inline int f2fs_init_compress_inode(struct f2fs_sb_info *sbi) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) static inline void f2fs_destroy_compress_inode(struct f2fs_sb_info *sbi) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) static inline int __init f2fs_init_compress_cache(void) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) static inline void f2fs_destroy_compress_cache(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) static inline void f2fs_invalidate_compress_page(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) 				block_t blkaddr) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) static inline void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) 				struct page *page, nid_t ino, block_t blkaddr) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) static inline bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) 				struct page *page, block_t blkaddr) { return false; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) static inline void f2fs_invalidate_compress_pages(struct f2fs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) 							nid_t ino) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) #define inc_compr_inode_stat(inode)		do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) static inline void set_compress_context(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) 	F2FS_I(inode)->i_compress_algorithm =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) 			F2FS_OPTION(sbi).compress_algorithm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) 	F2FS_I(inode)->i_log_cluster_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) 			F2FS_OPTION(sbi).compress_log_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) 	F2FS_I(inode)->i_compress_flag =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) 			F2FS_OPTION(sbi).compress_chksum ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) 				1 << COMPRESS_CHKSUM : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) 	F2FS_I(inode)->i_cluster_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) 			1 << F2FS_I(inode)->i_log_cluster_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) 	if (F2FS_I(inode)->i_compress_algorithm == COMPRESS_LZ4 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231) 			F2FS_OPTION(sbi).compress_level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) 		F2FS_I(inode)->i_compress_flag |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) 				F2FS_OPTION(sbi).compress_level <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) 				COMPRESS_LEVEL_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) 	F2FS_I(inode)->i_flags |= F2FS_COMPR_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) 	set_inode_flag(inode, FI_COMPRESSED_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) 	stat_inc_compr_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) 	inc_compr_inode_stat(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) static inline bool f2fs_disable_compressed_file(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) 	struct f2fs_inode_info *fi = F2FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) 	if (!f2fs_compressed_file(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) 	if (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) 	fi->i_flags &= ~F2FS_COMPR_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) 	stat_dec_compr_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) 	clear_inode_flag(inode, FI_COMPRESSED_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) #define F2FS_FEATURE_FUNCS(name, flagname) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) static inline int f2fs_sb_has_##name(struct f2fs_sb_info *sbi) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) 	return F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_##flagname); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) F2FS_FEATURE_FUNCS(encrypt, ENCRYPT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265) F2FS_FEATURE_FUNCS(blkzoned, BLKZONED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) F2FS_FEATURE_FUNCS(verity, VERITY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) F2FS_FEATURE_FUNCS(casefold, CASEFOLD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) F2FS_FEATURE_FUNCS(compression, COMPRESSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) F2FS_FEATURE_FUNCS(readonly, RO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) static inline bool f2fs_may_extent_tree(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281) 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) 	if (!test_opt(sbi, EXTENT_CACHE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) 			is_inode_flag_set(inode, FI_NO_EXTENT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) 			(is_inode_flag_set(inode, FI_COMPRESSED_FILE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) 			 !f2fs_sb_has_readonly(sbi)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) 	 * for recovered files during mount do not create extents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291) 	 * if shrinker is not registered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) 	if (list_empty(&sbi->s_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) 	return S_ISREG(inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) #ifdef CONFIG_BLK_DEV_ZONED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) 				    block_t blkaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) 	unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) 	return test_bit(zno, FDEV(devi).blkz_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) 	return f2fs_sb_has_blkzoned(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) static inline bool f2fs_bdev_support_discard(struct block_device *bdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) 	return blk_queue_discard(bdev_get_queue(bdev)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) 	       bdev_is_zoned(bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) 	if (!f2fs_is_multi_device(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) 		return f2fs_bdev_support_discard(sbi->sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) 	for (i = 0; i < sbi->s_ndevs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) 		if (f2fs_bdev_support_discard(FDEV(i).bdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335) 	return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) 					f2fs_hw_should_discard(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) static inline bool f2fs_hw_is_readonly(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) 	if (!f2fs_is_multi_device(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) 		return bdev_read_only(sbi->sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) 	for (i = 0; i < sbi->s_ndevs; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) 		if (bdev_read_only(FDEV(i).bdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354) 	return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) static inline bool f2fs_may_compress(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) 	if (IS_SWAPFILE(inode) || f2fs_is_pinned_file(inode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) 				f2fs_is_atomic_file(inode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) 				f2fs_is_volatile_file(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) 	return S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) static inline void f2fs_i_compr_blocks_update(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) 						u64 blocks, bool add)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) 	int diff = F2FS_I(inode)->i_cluster_size - blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) 	struct f2fs_inode_info *fi = F2FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) 	/* don't update i_compr_blocks if saved blocks were released */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) 	if (!add && !atomic_read(&fi->i_compr_blocks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) 	if (add) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) 		atomic_add(diff, &fi->i_compr_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) 		stat_add_compr_blocks(inode, diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) 		atomic_sub(diff, &fi->i_compr_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) 		stat_sub_compr_blocks(inode, diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) 	f2fs_mark_inode_dirty_sync(inode, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) static inline int block_unaligned_IO(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) 				struct kiocb *iocb, struct iov_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) 	unsigned int i_blkbits = READ_ONCE(inode->i_blkbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) 	unsigned int blocksize_mask = (1 << i_blkbits) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) 	loff_t offset = iocb->ki_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) 	unsigned long align = offset | iov_iter_alignment(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) 	return align & blocksize_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) static inline int allow_outplace_dio(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) 				struct kiocb *iocb, struct iov_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) 	int rw = iov_iter_rw(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) 	return (f2fs_lfs_mode(sbi) && (rw == WRITE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) 				!block_unaligned_IO(inode, iocb, iter));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) static inline bool f2fs_force_buffered_io(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) 				struct kiocb *iocb, struct iov_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) 	int rw = iov_iter_rw(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) 	if (!fscrypt_dio_supported(iocb, iter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) 	if (fsverity_active(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417) 	if (f2fs_compressed_file(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) 	if (f2fs_is_multi_device(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) 	 * for blkzoned device, fallback direct IO to buffered IO, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) 	 * all IOs can be serialized by log-structured write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) 	if (f2fs_sb_has_blkzoned(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) 	if (f2fs_lfs_mode(sbi) && (rw == WRITE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) 		if (block_unaligned_IO(inode, iocb, iter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) 		if (F2FS_IO_ALIGNED(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) 	if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) static inline bool f2fs_need_verity(const struct inode *inode, pgoff_t idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) 	return fsverity_active(inode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) 	       idx < DIV_ROUND_UP(inode->i_size, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) #ifdef CONFIG_F2FS_FAULT_INJECTION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) 							unsigned int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) #define f2fs_build_fault_attr(sbi, rate, type)		do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) static inline bool is_journalled_quota(struct f2fs_sb_info *sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) 	if (f2fs_sb_has_quota_ino(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) 	if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) 		F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) 		F2FS_OPTION(sbi).s_qf_names[PRJQUOTA])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) #define EFSBADCRC	EBADMSG		/* Bad CRC detected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) #define EFSCORRUPTED	EUCLEAN		/* Filesystem is corrupted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) #endif /* _LINUX_F2FS_H */