xref: /openbmc/linux/fs/f2fs/f2fs.h (revision 853137cef46ccc490e6fd4b160a1c252d6459842)
10a8165d7SJaegeuk Kim /*
239a53e0cSJaegeuk Kim  * fs/f2fs/f2fs.h
339a53e0cSJaegeuk Kim  *
439a53e0cSJaegeuk Kim  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
539a53e0cSJaegeuk Kim  *             http://www.samsung.com/
639a53e0cSJaegeuk Kim  *
739a53e0cSJaegeuk Kim  * This program is free software; you can redistribute it and/or modify
839a53e0cSJaegeuk Kim  * it under the terms of the GNU General Public License version 2 as
939a53e0cSJaegeuk Kim  * published by the Free Software Foundation.
1039a53e0cSJaegeuk Kim  */
1139a53e0cSJaegeuk Kim #ifndef _LINUX_F2FS_H
1239a53e0cSJaegeuk Kim #define _LINUX_F2FS_H
1339a53e0cSJaegeuk Kim 
1439a53e0cSJaegeuk Kim #include <linux/types.h>
1539a53e0cSJaegeuk Kim #include <linux/page-flags.h>
1639a53e0cSJaegeuk Kim #include <linux/buffer_head.h>
1739a53e0cSJaegeuk Kim #include <linux/slab.h>
1839a53e0cSJaegeuk Kim #include <linux/crc32.h>
1939a53e0cSJaegeuk Kim #include <linux/magic.h>
20c2d715d1SJaegeuk Kim #include <linux/kobject.h>
217bd59381SGu Zheng #include <linux/sched.h>
227c2e5963SJaegeuk Kim #include <linux/cred.h>
2339307a8eSJaegeuk Kim #include <linux/vmalloc.h>
24740432f8SJaegeuk Kim #include <linux/bio.h>
25d0239e1bSJaegeuk Kim #include <linux/blkdev.h>
260abd675eSChao Yu #include <linux/quotaops.h>
2743b6573bSKeith Mok #include <crypto/hash.h>
2839a53e0cSJaegeuk Kim 
29734f0d24SDave Chinner #define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_F2FS_FS_ENCRYPTION)
30734f0d24SDave Chinner #include <linux/fscrypt.h>
31734f0d24SDave Chinner 
325d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS
339850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition)	BUG_ON(condition)
345d56b671SJaegeuk Kim #else
359850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition)					\
369850cf4aSJaegeuk Kim 	do {								\
379850cf4aSJaegeuk Kim 		if (unlikely(condition)) {				\
389850cf4aSJaegeuk Kim 			WARN_ON(1);					\
39caf0047eSChao Yu 			set_sbi_flag(sbi, SBI_NEED_FSCK);		\
409850cf4aSJaegeuk Kim 		}							\
419850cf4aSJaegeuk Kim 	} while (0)
425d56b671SJaegeuk Kim #endif
435d56b671SJaegeuk Kim 
442c63feadSJaegeuk Kim enum {
452c63feadSJaegeuk Kim 	FAULT_KMALLOC,
46628b3d14SChao Yu 	FAULT_KVMALLOC,
47c41f3cc3SJaegeuk Kim 	FAULT_PAGE_ALLOC,
4801eccef7SChao Yu 	FAULT_PAGE_GET,
49d62fe971SChao Yu 	FAULT_ALLOC_BIO,
50cb78942bSJaegeuk Kim 	FAULT_ALLOC_NID,
51cb78942bSJaegeuk Kim 	FAULT_ORPHAN,
52cb78942bSJaegeuk Kim 	FAULT_BLOCK,
53cb78942bSJaegeuk Kim 	FAULT_DIR_DEPTH,
5453aa6bbfSJaegeuk Kim 	FAULT_EVICT_INODE,
5514b44d23SJaegeuk Kim 	FAULT_TRUNCATE,
568b038c70SChao Yu 	FAULT_IO,
570f348028SChao Yu 	FAULT_CHECKPOINT,
58b83dcfe6SChao Yu 	FAULT_DISCARD,
592c63feadSJaegeuk Kim 	FAULT_MAX,
602c63feadSJaegeuk Kim };
612c63feadSJaegeuk Kim 
627fa750a1SArnd Bergmann #ifdef CONFIG_F2FS_FAULT_INJECTION
63d494500aSChao Yu #define F2FS_ALL_FAULT_TYPE		((1 << FAULT_MAX) - 1)
64d494500aSChao Yu 
6508796897SSheng Yong struct f2fs_fault_info {
6608796897SSheng Yong 	atomic_t inject_ops;
6708796897SSheng Yong 	unsigned int inject_rate;
6808796897SSheng Yong 	unsigned int inject_type;
6908796897SSheng Yong };
7008796897SSheng Yong 
712d3a5856SGao Xiang extern char *f2fs_fault_name[FAULT_MAX];
7268afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
732c63feadSJaegeuk Kim #endif
742c63feadSJaegeuk Kim 
7539a53e0cSJaegeuk Kim /*
7639a53e0cSJaegeuk Kim  * For mount options
7739a53e0cSJaegeuk Kim  */
7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC		0x00000001
7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD	0x00000002
8039a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD		0x00000004
8139a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP		0x00000008
8239a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER		0x00000010
8339a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL		0x00000020
8439a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY	0x00000040
85444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR		0x00000080
861001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA		0x00000100
8734d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY	0x00000200
8834d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE		0x00000400
8934d67debSChao Yu #define F2FS_MOUNT_NOBARRIER		0x00000800
90d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT		0x00001000
9189672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE		0x00002000
926aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC		0x00004000
93343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH		0x00008000
9473faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION	0x00010000
9536abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE		0x00020000
9636abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS			0x00040000
970abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA		0x00080000
980abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA		0x00100000
995c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA		0x00200000
1004b2414d0SChao Yu #define F2FS_MOUNT_QUOTA		0x00400000
1016afc662eSChao Yu #define F2FS_MOUNT_INLINE_XATTR_SIZE	0x00800000
1027e65be49SJaegeuk Kim #define F2FS_MOUNT_RESERVE_ROOT		0x01000000
10339a53e0cSJaegeuk Kim 
10463189b78SChao Yu #define F2FS_OPTION(sbi)	((sbi)->mount_opt)
10563189b78SChao Yu #define clear_opt(sbi, option)	(F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option)
10663189b78SChao Yu #define set_opt(sbi, option)	(F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option)
10763189b78SChao Yu #define test_opt(sbi, option)	(F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option)
10839a53e0cSJaegeuk Kim 
10939a53e0cSJaegeuk Kim #define ver_after(a, b)	(typecheck(unsigned long long, a) &&		\
11039a53e0cSJaegeuk Kim 		typecheck(unsigned long long, b) &&			\
11139a53e0cSJaegeuk Kim 		((long long)((a) - (b)) > 0))
11239a53e0cSJaegeuk Kim 
113a9841c4dSJaegeuk Kim typedef u32 block_t;	/*
114a9841c4dSJaegeuk Kim 			 * should not change u32, since it is the on-disk block
115a9841c4dSJaegeuk Kim 			 * address format, __le32.
116a9841c4dSJaegeuk Kim 			 */
11739a53e0cSJaegeuk Kim typedef u32 nid_t;
11839a53e0cSJaegeuk Kim 
11939a53e0cSJaegeuk Kim struct f2fs_mount_info {
12039a53e0cSJaegeuk Kim 	unsigned int opt;
12163189b78SChao Yu 	int write_io_size_bits;		/* Write IO size bits */
12263189b78SChao Yu 	block_t root_reserved_blocks;	/* root reserved blocks */
12363189b78SChao Yu 	kuid_t s_resuid;		/* reserved blocks for uid */
12463189b78SChao Yu 	kgid_t s_resgid;		/* reserved blocks for gid */
12563189b78SChao Yu 	int active_logs;		/* # of active logs */
12663189b78SChao Yu 	int inline_xattr_size;		/* inline xattr size */
12763189b78SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION
12863189b78SChao Yu 	struct f2fs_fault_info fault_info;	/* For fault injection */
12963189b78SChao Yu #endif
13063189b78SChao Yu #ifdef CONFIG_QUOTA
13163189b78SChao Yu 	/* Names of quota files with journalled quota */
13263189b78SChao Yu 	char *s_qf_names[MAXQUOTAS];
13363189b78SChao Yu 	int s_jquota_fmt;			/* Format of quota to use */
13463189b78SChao Yu #endif
13563189b78SChao Yu 	/* For which write hints are passed down to block layer */
13663189b78SChao Yu 	int whint_mode;
13763189b78SChao Yu 	int alloc_mode;			/* segment allocation policy */
13863189b78SChao Yu 	int fsync_mode;			/* fsync policy */
139ff62af20SSheng Yong 	bool test_dummy_encryption;	/* test dummy encryption */
14039a53e0cSJaegeuk Kim };
14139a53e0cSJaegeuk Kim 
142cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT		0x0001
1430bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED		0x0002
144e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE	0x0004
1457a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR		0x0008
1465c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA		0x0010
147704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM	0x0020
1486afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR	0x0040
149234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO		0x0080
1501c1d35dfSChao Yu #define F2FS_FEATURE_INODE_CRTIME	0x0100
151b7c409deSSheng Yong #define F2FS_FEATURE_LOST_FOUND		0x0200
15253fedcc0SEric Biggers #define F2FS_FEATURE_VERITY		0x0400	/* reserved */
153cde4de12SJaegeuk Kim 
15476f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask)					\
15576f105a2SJaegeuk Kim 	((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
15676f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask)					\
157c64ab12eSDongOh Shin 	(F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask))
15876f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask)					\
159c64ab12eSDongOh Shin 	(F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask))
16076f105a2SJaegeuk Kim 
16139a53e0cSJaegeuk Kim /*
1627c2e5963SJaegeuk Kim  * Default values for user and/or group using reserved blocks
1637c2e5963SJaegeuk Kim  */
1647c2e5963SJaegeuk Kim #define	F2FS_DEF_RESUID		0
1657c2e5963SJaegeuk Kim #define	F2FS_DEF_RESGID		0
1667c2e5963SJaegeuk Kim 
1677c2e5963SJaegeuk Kim /*
16839a53e0cSJaegeuk Kim  * For checkpoint manager
16939a53e0cSJaegeuk Kim  */
17039a53e0cSJaegeuk Kim enum {
17139a53e0cSJaegeuk Kim 	NAT_BITMAP,
17239a53e0cSJaegeuk Kim 	SIT_BITMAP
17339a53e0cSJaegeuk Kim };
17439a53e0cSJaegeuk Kim 
175c473f1a9SChao Yu #define	CP_UMOUNT	0x00000001
176c473f1a9SChao Yu #define	CP_FASTBOOT	0x00000002
177c473f1a9SChao Yu #define	CP_SYNC		0x00000004
178c473f1a9SChao Yu #define	CP_RECOVERY	0x00000008
179c473f1a9SChao Yu #define	CP_DISCARD	0x00000010
1801f43e2adSChao Yu #define CP_TRIMMED	0x00000020
18175ab4cb8SJaegeuk Kim 
1824ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi)		BLKS_PER_SEC(sbi)
183ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST		8	/* issue 8 discards per round */
184969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME	50	/* 50 ms, if exists */
185f9d1dcedSYunlei He #define DEF_MID_DISCARD_ISSUE_TIME	500	/* 500 ms, if device busy */
186969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME	60000	/* 60 s, if no candidates */
1878bb4f253SJaegeuk Kim #define DEF_DISCARD_URGENT_UTIL		80	/* do more discard over 80% */
18860b99b48SJaegeuk Kim #define DEF_CP_INTERVAL			60	/* 60 secs */
189dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL		5	/* 5 secs */
190bba681cbSJaegeuk Kim 
19175ab4cb8SJaegeuk Kim struct cp_control {
19275ab4cb8SJaegeuk Kim 	int reason;
1934b2fecc8SJaegeuk Kim 	__u64 trim_start;
1944b2fecc8SJaegeuk Kim 	__u64 trim_end;
1954b2fecc8SJaegeuk Kim 	__u64 trim_minlen;
19675ab4cb8SJaegeuk Kim };
19775ab4cb8SJaegeuk Kim 
198662befdaSChao Yu /*
199e1da7872SChao Yu  * indicate meta/data type
200662befdaSChao Yu  */
201662befdaSChao Yu enum {
202662befdaSChao Yu 	META_CP,
203662befdaSChao Yu 	META_NAT,
20481c1a0f1SChao Yu 	META_SIT,
2054c521f49SJaegeuk Kim 	META_SSA,
2064c521f49SJaegeuk Kim 	META_POR,
207e1da7872SChao Yu 	DATA_GENERIC,
208e1da7872SChao Yu 	META_GENERIC,
209662befdaSChao Yu };
210662befdaSChao Yu 
2116451e041SJaegeuk Kim /* for the list of ino */
2126451e041SJaegeuk Kim enum {
2136451e041SJaegeuk Kim 	ORPHAN_INO,		/* for orphan ino list */
214fff04f90SJaegeuk Kim 	APPEND_INO,		/* for append ino list */
215fff04f90SJaegeuk Kim 	UPDATE_INO,		/* for update ino list */
2160a007b97SJaegeuk Kim 	TRANS_DIR_INO,		/* for trasactions dir ino list */
21739d787beSChao Yu 	FLUSH_INO,		/* for multiple device flushing */
2186451e041SJaegeuk Kim 	MAX_INO_ENTRY,		/* max. list */
2196451e041SJaegeuk Kim };
2206451e041SJaegeuk Kim 
2216451e041SJaegeuk Kim struct ino_entry {
22239a53e0cSJaegeuk Kim 	struct list_head list;		/* list head */
22339a53e0cSJaegeuk Kim 	nid_t ino;			/* inode number */
22439d787beSChao Yu 	unsigned int dirty_device;	/* dirty device bitmap */
22539a53e0cSJaegeuk Kim };
22639a53e0cSJaegeuk Kim 
2272710fd7eSChao Yu /* for the list of inodes to be GCed */
22806292073SChao Yu struct inode_entry {
22939a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
23039a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
23139a53e0cSJaegeuk Kim };
23239a53e0cSJaegeuk Kim 
23350fa53ecSChao Yu struct fsync_node_entry {
23450fa53ecSChao Yu 	struct list_head list;	/* list head */
23550fa53ecSChao Yu 	struct page *page;	/* warm node page pointer */
23650fa53ecSChao Yu 	unsigned int seq_id;	/* sequence id */
23750fa53ecSChao Yu };
23850fa53ecSChao Yu 
239a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */
2407fd9e544SJaegeuk Kim struct discard_entry {
2417fd9e544SJaegeuk Kim 	struct list_head list;	/* list head */
242a7eeb823SChao Yu 	block_t start_blkaddr;	/* start blockaddr of current segment */
243a7eeb823SChao Yu 	unsigned char discard_map[SIT_VBLOCK_MAP_SIZE];	/* segment discard bitmap */
2447fd9e544SJaegeuk Kim };
2457fd9e544SJaegeuk Kim 
246969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */
247969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY		16
248969d1b18SChao Yu 
249ba48a33eSChao Yu /* max discard pend list number */
250ba48a33eSChao Yu #define MAX_PLIST_NUM		512
251ba48a33eSChao Yu #define plist_idx(blk_num)	((blk_num) >= MAX_PLIST_NUM ?		\
252ba48a33eSChao Yu 					(MAX_PLIST_NUM - 1) : (blk_num - 1))
253ba48a33eSChao Yu 
25415469963SJaegeuk Kim enum {
25535ec7d57SChao Yu 	D_PREP,			/* initial */
25635ec7d57SChao Yu 	D_PARTIAL,		/* partially submitted */
25735ec7d57SChao Yu 	D_SUBMIT,		/* all submitted */
25835ec7d57SChao Yu 	D_DONE,			/* finished */
25915469963SJaegeuk Kim };
26015469963SJaegeuk Kim 
261004b6862SChao Yu struct discard_info {
262b01a9201SJaegeuk Kim 	block_t lstart;			/* logical start address */
263b01a9201SJaegeuk Kim 	block_t len;			/* length */
264004b6862SChao Yu 	block_t start;			/* actual start address in dev */
265004b6862SChao Yu };
266004b6862SChao Yu 
267b01a9201SJaegeuk Kim struct discard_cmd {
268004b6862SChao Yu 	struct rb_node rb_node;		/* rb node located in rb-tree */
269004b6862SChao Yu 	union {
270004b6862SChao Yu 		struct {
271004b6862SChao Yu 			block_t lstart;	/* logical start address */
272004b6862SChao Yu 			block_t len;	/* length */
273004b6862SChao Yu 			block_t start;	/* actual start address in dev */
274004b6862SChao Yu 		};
275004b6862SChao Yu 		struct discard_info di;	/* discard info */
276004b6862SChao Yu 
277004b6862SChao Yu 	};
278b01a9201SJaegeuk Kim 	struct list_head list;		/* command list */
279b01a9201SJaegeuk Kim 	struct completion wait;		/* compleation */
280c81abe34SJaegeuk Kim 	struct block_device *bdev;	/* bdev */
281ec9895adSChao Yu 	unsigned short ref;		/* reference count */
2829a744b92SChao Yu 	unsigned char state;		/* state */
28335ec7d57SChao Yu 	unsigned char issuing;		/* issuing discard */
284c81abe34SJaegeuk Kim 	int error;			/* bio error */
28535ec7d57SChao Yu 	spinlock_t lock;		/* for state/bio_ref updating */
28635ec7d57SChao Yu 	unsigned short bio_ref;		/* bio reference count */
287275b66b0SChao Yu };
288275b66b0SChao Yu 
28978997b56SChao Yu enum {
29078997b56SChao Yu 	DPOLICY_BG,
29178997b56SChao Yu 	DPOLICY_FORCE,
29278997b56SChao Yu 	DPOLICY_FSTRIM,
29378997b56SChao Yu 	DPOLICY_UMOUNT,
29478997b56SChao Yu 	MAX_DPOLICY,
29578997b56SChao Yu };
29678997b56SChao Yu 
297ecc9aa00SChao Yu struct discard_policy {
29878997b56SChao Yu 	int type;			/* type of discard */
299ecc9aa00SChao Yu 	unsigned int min_interval;	/* used for candidates exist */
300f9d1dcedSYunlei He 	unsigned int mid_interval;	/* used for device busy */
301ecc9aa00SChao Yu 	unsigned int max_interval;	/* used for candidates not exist */
302ecc9aa00SChao Yu 	unsigned int max_requests;	/* # of discards issued per round */
303ecc9aa00SChao Yu 	unsigned int io_aware_gran;	/* minimum granularity discard not be aware of I/O */
304ecc9aa00SChao Yu 	bool io_aware;			/* issue discard in idle time */
305ecc9aa00SChao Yu 	bool sync;			/* submit discard with REQ_SYNC flag */
30620ee4382SChao Yu 	bool ordered;			/* issue discard by lba order */
30778997b56SChao Yu 	unsigned int granularity;	/* discard granularity */
308ecc9aa00SChao Yu };
309ecc9aa00SChao Yu 
3100b54fb84SJaegeuk Kim struct discard_cmd_control {
31115469963SJaegeuk Kim 	struct task_struct *f2fs_issue_discard;	/* discard thread */
31246f84c2cSChao Yu 	struct list_head entry_list;		/* 4KB discard entry list */
313ba48a33eSChao Yu 	struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */
31446f84c2cSChao Yu 	struct list_head wait_list;		/* store on-flushing entries */
3158412663dSChao Yu 	struct list_head fstrim_list;		/* in-flight discard from fstrim */
31615469963SJaegeuk Kim 	wait_queue_head_t discard_wait_queue;	/* waiting queue for wake-up */
317969d1b18SChao Yu 	unsigned int discard_wake;		/* to wake up discard thread */
31815469963SJaegeuk Kim 	struct mutex cmd_lock;
319d618ebafSChao Yu 	unsigned int nr_discards;		/* # of discards in the list */
320d618ebafSChao Yu 	unsigned int max_discards;		/* max. discards to be issued */
321969d1b18SChao Yu 	unsigned int discard_granularity;	/* discard granularity */
322d84d1cbdSChao Yu 	unsigned int undiscard_blks;		/* # of undiscard blocks */
32320ee4382SChao Yu 	unsigned int next_pos;			/* next discard position */
3248b8dd65fSChao Yu 	atomic_t issued_discard;		/* # of issued discard */
3258b8dd65fSChao Yu 	atomic_t issing_discard;		/* # of issing discard */
3265f32366aSChao Yu 	atomic_t discard_cmd_cnt;		/* # of cached cmd count */
327004b6862SChao Yu 	struct rb_root root;			/* root of discard rb-tree */
32867fce70bSChao Yu 	bool rbtree_check;			/* config for consistence check */
32939a53e0cSJaegeuk Kim };
33039a53e0cSJaegeuk Kim 
33139a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */
33239a53e0cSJaegeuk Kim struct fsync_inode_entry {
33339a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
33439a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
335c52e1b10SJaegeuk Kim 	block_t blkaddr;	/* block address locating the last fsync */
336c52e1b10SJaegeuk Kim 	block_t last_dentry;	/* block address locating the last dentry */
33739a53e0cSJaegeuk Kim };
33839a53e0cSJaegeuk Kim 
33968afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl)		(le16_to_cpu((jnl)->n_nats))
34068afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl)		(le16_to_cpu((jnl)->n_sits))
34139a53e0cSJaegeuk Kim 
34268afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i)		((jnl)->nat_j.entries[i].ne)
34368afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i)		((jnl)->nat_j.entries[i].nid)
34468afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i)		((jnl)->sit_j.entries[i].se)
34568afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i)	((jnl)->sit_j.entries[i].segno)
34639a53e0cSJaegeuk Kim 
347dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl)	(NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl))
348dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl)	(SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl))
349309cc2b6SJaegeuk Kim 
350dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i)
35139a53e0cSJaegeuk Kim {
352dfc08a12SChao Yu 	int before = nats_in_cursum(journal);
353cac5a3d8SDongOh Shin 
354dfc08a12SChao Yu 	journal->n_nats = cpu_to_le16(before + i);
35539a53e0cSJaegeuk Kim 	return before;
35639a53e0cSJaegeuk Kim }
35739a53e0cSJaegeuk Kim 
358dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i)
35939a53e0cSJaegeuk Kim {
360dfc08a12SChao Yu 	int before = sits_in_cursum(journal);
361cac5a3d8SDongOh Shin 
362dfc08a12SChao Yu 	journal->n_sits = cpu_to_le16(before + i);
36339a53e0cSJaegeuk Kim 	return before;
36439a53e0cSJaegeuk Kim }
36539a53e0cSJaegeuk Kim 
366dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal,
367dfc08a12SChao Yu 							int size, int type)
368184a5cd2SChao Yu {
369184a5cd2SChao Yu 	if (type == NAT_JOURNAL)
370dfc08a12SChao Yu 		return size <= MAX_NAT_JENTRIES(journal);
371dfc08a12SChao Yu 	return size <= MAX_SIT_JENTRIES(journal);
372184a5cd2SChao Yu }
373184a5cd2SChao Yu 
37439a53e0cSJaegeuk Kim /*
375e9750824SNamjae Jeon  * ioctl commands
376e9750824SNamjae Jeon  */
377e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS		FS_IOC_GETFLAGS
378e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS		FS_IOC_SETFLAGS
379d49f3e89SChao Yu #define F2FS_IOC_GETVERSION		FS_IOC_GETVERSION
380e9750824SNamjae Jeon 
38188b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC		0xf5
38288b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE	_IO(F2FS_IOCTL_MAGIC, 1)
38388b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE	_IO(F2FS_IOCTL_MAGIC, 2)
38402a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 3)
3851e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 4)
3861e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 5)
387d07efb50SJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT	_IOW(F2FS_IOCTL_MAGIC, 6, __u32)
388456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT	_IO(F2FS_IOCTL_MAGIC, 7)
389d07efb50SJaegeuk Kim #define F2FS_IOC_DEFRAGMENT		_IOWR(F2FS_IOCTL_MAGIC, 8,	\
390d07efb50SJaegeuk Kim 						struct f2fs_defragment)
3914dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE		_IOWR(F2FS_IOCTL_MAGIC, 9,	\
3924dd6f977SJaegeuk Kim 						struct f2fs_move_range)
393e066b83cSJaegeuk Kim #define F2FS_IOC_FLUSH_DEVICE		_IOW(F2FS_IOCTL_MAGIC, 10,	\
394e066b83cSJaegeuk Kim 						struct f2fs_flush_device)
39534dc77adSJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT_RANGE	_IOW(F2FS_IOCTL_MAGIC, 11,	\
39634dc77adSJaegeuk Kim 						struct f2fs_gc_range)
397e65ef207SJaegeuk Kim #define F2FS_IOC_GET_FEATURES		_IOR(F2FS_IOCTL_MAGIC, 12, __u32)
3981ad71a27SJaegeuk Kim #define F2FS_IOC_SET_PIN_FILE		_IOW(F2FS_IOCTL_MAGIC, 13, __u32)
3991ad71a27SJaegeuk Kim #define F2FS_IOC_GET_PIN_FILE		_IOR(F2FS_IOCTL_MAGIC, 14, __u32)
400c4020b2dSChao Yu #define F2FS_IOC_PRECACHE_EXTENTS	_IO(F2FS_IOCTL_MAGIC, 15)
40188b88a66SJaegeuk Kim 
4020b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY	FS_IOC_SET_ENCRYPTION_POLICY
4030b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY	FS_IOC_GET_ENCRYPTION_POLICY
4040b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT	FS_IOC_GET_ENCRYPTION_PWSALT
405f424f664SJaegeuk Kim 
4061abff93dSJaegeuk Kim /*
4071abff93dSJaegeuk Kim  * should be same as XFS_IOC_GOINGDOWN.
4081abff93dSJaegeuk Kim  * Flags for going down operation used by FS_IOC_GOINGDOWN
4091abff93dSJaegeuk Kim  */
4101abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN	_IOR('X', 125, __u32)	/* Shutdown */
4111abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC	0x0	/* going down with full sync */
4121abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC	0x1	/* going down with metadata */
4131abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC		0x2	/* going down */
414c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH	0x3	/* going down with meta flush */
4151abff93dSJaegeuk Kim 
416e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
417e9750824SNamjae Jeon /*
418e9750824SNamjae Jeon  * ioctl commands in 32 bit emulation
419e9750824SNamjae Jeon  */
420e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS		FS_IOC32_GETFLAGS
421e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS		FS_IOC32_SETFLAGS
42204ef4b62SChao Yu #define F2FS_IOC32_GETVERSION		FS_IOC32_GETVERSION
423e9750824SNamjae Jeon #endif
424e9750824SNamjae Jeon 
4252c1d0305SChao Yu #define F2FS_IOC_FSGETXATTR		FS_IOC_FSGETXATTR
4262c1d0305SChao Yu #define F2FS_IOC_FSSETXATTR		FS_IOC_FSSETXATTR
4272c1d0305SChao Yu 
42834dc77adSJaegeuk Kim struct f2fs_gc_range {
42934dc77adSJaegeuk Kim 	u32 sync;
43034dc77adSJaegeuk Kim 	u64 start;
43134dc77adSJaegeuk Kim 	u64 len;
43234dc77adSJaegeuk Kim };
43334dc77adSJaegeuk Kim 
434d323d005SChao Yu struct f2fs_defragment {
435d323d005SChao Yu 	u64 start;
436d323d005SChao Yu 	u64 len;
437d323d005SChao Yu };
438d323d005SChao Yu 
4394dd6f977SJaegeuk Kim struct f2fs_move_range {
4404dd6f977SJaegeuk Kim 	u32 dst_fd;		/* destination fd */
4414dd6f977SJaegeuk Kim 	u64 pos_in;		/* start position in src_fd */
4424dd6f977SJaegeuk Kim 	u64 pos_out;		/* start position in dst_fd */
4434dd6f977SJaegeuk Kim 	u64 len;		/* size to move */
4444dd6f977SJaegeuk Kim };
4454dd6f977SJaegeuk Kim 
446e066b83cSJaegeuk Kim struct f2fs_flush_device {
447e066b83cSJaegeuk Kim 	u32 dev_num;		/* device number to flush */
448e066b83cSJaegeuk Kim 	u32 segments;		/* # of segments to flush */
449e066b83cSJaegeuk Kim };
450e066b83cSJaegeuk Kim 
451f2470371SChao Yu /* for inline stuff */
452f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE	1
4536afc662eSChao Yu #define DEF_MIN_INLINE_SIZE		1
4547a2af766SChao Yu static inline int get_extra_isize(struct inode *inode);
4556afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode);
4567a2af766SChao Yu #define MAX_INLINE_DATA(inode)	(sizeof(__le32) *			\
4577a2af766SChao Yu 				(CUR_ADDRS_PER_INODE(inode) -		\
458b323fd28SChao Yu 				get_inline_xattr_addrs(inode) -	\
4596afc662eSChao Yu 				DEF_INLINE_RESERVED_SIZE))
460f2470371SChao Yu 
461f2470371SChao Yu /* for inline dir */
462f2470371SChao Yu #define NR_INLINE_DENTRY(inode)	(MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \
463f2470371SChao Yu 				((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
464f2470371SChao Yu 				BITS_PER_BYTE + 1))
465f2470371SChao Yu #define INLINE_DENTRY_BITMAP_SIZE(inode)	((NR_INLINE_DENTRY(inode) + \
466f2470371SChao Yu 					BITS_PER_BYTE - 1) / BITS_PER_BYTE)
467f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode)	(MAX_INLINE_DATA(inode) - \
468f2470371SChao Yu 				((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
469f2470371SChao Yu 				NR_INLINE_DENTRY(inode) + \
470f2470371SChao Yu 				INLINE_DENTRY_BITMAP_SIZE(inode)))
471f2470371SChao Yu 
472e9750824SNamjae Jeon /*
47339a53e0cSJaegeuk Kim  * For INODE and NODE manager
47439a53e0cSJaegeuk Kim  */
4757b3cd7d6SJaegeuk Kim /* for directory operations */
4767b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr {
477d8c6822aSJaegeuk Kim 	struct inode *inode;
47876a9dd85SChao Yu 	void *bitmap;
4797b3cd7d6SJaegeuk Kim 	struct f2fs_dir_entry *dentry;
4807b3cd7d6SJaegeuk Kim 	__u8 (*filename)[F2FS_SLOT_LEN];
4817b3cd7d6SJaegeuk Kim 	int max;
48276a9dd85SChao Yu 	int nr_bitmap;
4837b3cd7d6SJaegeuk Kim };
4847b3cd7d6SJaegeuk Kim 
48564c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode,
48664c24ecbSTomohiro Kusumi 		struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t)
4877b3cd7d6SJaegeuk Kim {
488d8c6822aSJaegeuk Kim 	d->inode = inode;
4897b3cd7d6SJaegeuk Kim 	d->max = NR_DENTRY_IN_BLOCK;
49076a9dd85SChao Yu 	d->nr_bitmap = SIZE_OF_DENTRY_BITMAP;
491c79d1520SYunlong Song 	d->bitmap = t->dentry_bitmap;
4927b3cd7d6SJaegeuk Kim 	d->dentry = t->dentry;
4937b3cd7d6SJaegeuk Kim 	d->filename = t->filename;
49464c24ecbSTomohiro Kusumi }
495cac5a3d8SDongOh Shin 
49664c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode,
497f2470371SChao Yu 					struct f2fs_dentry_ptr *d, void *t)
49864c24ecbSTomohiro Kusumi {
499f2470371SChao Yu 	int entry_cnt = NR_INLINE_DENTRY(inode);
500f2470371SChao Yu 	int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode);
501f2470371SChao Yu 	int reserved_size = INLINE_RESERVED_SIZE(inode);
502f2470371SChao Yu 
50364c24ecbSTomohiro Kusumi 	d->inode = inode;
504f2470371SChao Yu 	d->max = entry_cnt;
505f2470371SChao Yu 	d->nr_bitmap = bitmap_size;
506f2470371SChao Yu 	d->bitmap = t;
507f2470371SChao Yu 	d->dentry = t + bitmap_size + reserved_size;
508f2470371SChao Yu 	d->filename = t + bitmap_size + reserved_size +
509f2470371SChao Yu 					SIZE_OF_DIR_ENTRY * entry_cnt;
5107b3cd7d6SJaegeuk Kim }
5117b3cd7d6SJaegeuk Kim 
512dbe6a5ffSJaegeuk Kim /*
513dbe6a5ffSJaegeuk Kim  * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
514dbe6a5ffSJaegeuk Kim  * as its node offset to distinguish from index node blocks.
515dbe6a5ffSJaegeuk Kim  * But some bits are used to mark the node block.
51639a53e0cSJaegeuk Kim  */
517dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET	((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
518dbe6a5ffSJaegeuk Kim 				>> OFFSET_BIT_SHIFT)
519266e97a8SJaegeuk Kim enum {
520266e97a8SJaegeuk Kim 	ALLOC_NODE,			/* allocate a new node page if needed */
521266e97a8SJaegeuk Kim 	LOOKUP_NODE,			/* look up a node without readahead */
522266e97a8SJaegeuk Kim 	LOOKUP_NODE_RA,			/*
523266e97a8SJaegeuk Kim 					 * look up a node with readahead called
5244f4124d0SChao Yu 					 * by get_data_block.
52539a53e0cSJaegeuk Kim 					 */
526266e97a8SJaegeuk Kim };
527266e97a8SJaegeuk Kim 
5287735730dSChao Yu #define DEFAULT_RETRY_IO_COUNT	8	/* maximum retry read IO count */
5297735730dSChao Yu 
530a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX	0xffffffff	/* maximum link count per file */
53139a53e0cSJaegeuk Kim 
532817202d9SChao Yu #define MAX_DIR_RA_PAGES	4	/* maximum ra pages of dir */
533817202d9SChao Yu 
53439a53e0cSJaegeuk Kim /* for in-memory extent cache entry */
53513054c54SChao Yu #define F2FS_MIN_EXTENT_LEN	64	/* minimum extent length */
53613054c54SChao Yu 
53713054c54SChao Yu /* number of extent info in extent cache we try to shrink */
53813054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER	128
539c11abd1aSJaegeuk Kim 
54054c2258cSChao Yu struct rb_entry {
54154c2258cSChao Yu 	struct rb_node rb_node;		/* rb node located in rb-tree */
54254c2258cSChao Yu 	unsigned int ofs;		/* start offset of the entry */
54354c2258cSChao Yu 	unsigned int len;		/* length of the entry */
54454c2258cSChao Yu };
54554c2258cSChao Yu 
54639a53e0cSJaegeuk Kim struct extent_info {
54739a53e0cSJaegeuk Kim 	unsigned int fofs;		/* start offset in a file */
548111d2495SMasanari Iida 	unsigned int len;		/* length of the extent */
54954c2258cSChao Yu 	u32 blk;			/* start block address of the extent */
55039a53e0cSJaegeuk Kim };
55139a53e0cSJaegeuk Kim 
55213054c54SChao Yu struct extent_node {
55354c2258cSChao Yu 	struct rb_node rb_node;
55454c2258cSChao Yu 	union {
55554c2258cSChao Yu 		struct {
55654c2258cSChao Yu 			unsigned int fofs;
55754c2258cSChao Yu 			unsigned int len;
55854c2258cSChao Yu 			u32 blk;
55954c2258cSChao Yu 		};
56013054c54SChao Yu 		struct extent_info ei;	/* extent info */
56154c2258cSChao Yu 
56254c2258cSChao Yu 	};
56354c2258cSChao Yu 	struct list_head list;		/* node in global extent list of sbi */
564201ef5e0SHou Pengyang 	struct extent_tree *et;		/* extent tree pointer */
56513054c54SChao Yu };
56613054c54SChao Yu 
56713054c54SChao Yu struct extent_tree {
56813054c54SChao Yu 	nid_t ino;			/* inode number */
56913054c54SChao Yu 	struct rb_root root;		/* root of extent info rb-tree */
57062c8af65SChao Yu 	struct extent_node *cached_en;	/* recently accessed extent node */
5713e72f721SJaegeuk Kim 	struct extent_info largest;	/* largested extent info */
572137d09f0SJaegeuk Kim 	struct list_head list;		/* to be used by sbi->zombie_list */
57313054c54SChao Yu 	rwlock_t lock;			/* protect extent info rb-tree */
57468e35385SChao Yu 	atomic_t node_cnt;		/* # of extent node in rb-tree*/
57513054c54SChao Yu };
57613054c54SChao Yu 
57739a53e0cSJaegeuk Kim /*
578003a3e1dSJaegeuk Kim  * This structure is taken from ext4_map_blocks.
579003a3e1dSJaegeuk Kim  *
580003a3e1dSJaegeuk Kim  * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
581003a3e1dSJaegeuk Kim  */
582003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW		(1 << BH_New)
583003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED		(1 << BH_Mapped)
5847f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN	(1 << BH_Unwritten)
5857f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS		(F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
5867f63eb77SJaegeuk Kim 				F2FS_MAP_UNWRITTEN)
587003a3e1dSJaegeuk Kim 
588003a3e1dSJaegeuk Kim struct f2fs_map_blocks {
589003a3e1dSJaegeuk Kim 	block_t m_pblk;
590003a3e1dSJaegeuk Kim 	block_t m_lblk;
591003a3e1dSJaegeuk Kim 	unsigned int m_len;
592003a3e1dSJaegeuk Kim 	unsigned int m_flags;
593da85985cSChao Yu 	pgoff_t *m_next_pgofs;		/* point next possible non-hole pgofs */
594c4020b2dSChao Yu 	pgoff_t *m_next_extent;		/* point to next possible extent */
595d5097be5SHyunchul Lee 	int m_seg_type;
596003a3e1dSJaegeuk Kim };
597003a3e1dSJaegeuk Kim 
598e2b4e2bcSChao Yu /* for flag in get_data_block */
599f2220c7fSQiuyang Sun enum {
600f2220c7fSQiuyang Sun 	F2FS_GET_BLOCK_DEFAULT,
601f2220c7fSQiuyang Sun 	F2FS_GET_BLOCK_FIEMAP,
602f2220c7fSQiuyang Sun 	F2FS_GET_BLOCK_BMAP,
603f2220c7fSQiuyang Sun 	F2FS_GET_BLOCK_PRE_DIO,
604f2220c7fSQiuyang Sun 	F2FS_GET_BLOCK_PRE_AIO,
605c4020b2dSChao Yu 	F2FS_GET_BLOCK_PRECACHE,
606f2220c7fSQiuyang Sun };
607e2b4e2bcSChao Yu 
608003a3e1dSJaegeuk Kim /*
60939a53e0cSJaegeuk Kim  * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
61039a53e0cSJaegeuk Kim  */
61139a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT	0x01
612354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT	0x02
613cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT	0x04
614e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT	0x08
61526787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT	0x10
616b6a06cbbSChao Yu #define FADVISE_HOT_BIT		0x20
61753fedcc0SEric Biggers #define FADVISE_VERITY_BIT	0x40	/* reserved */
61839a53e0cSJaegeuk Kim 
619797c1cb5SChao Yu #define FADVISE_MODIFIABLE_BITS	(FADVISE_COLD_BIT | FADVISE_HOT_BIT)
620797c1cb5SChao Yu 
621b5492af7SJaegeuk Kim #define file_is_cold(inode)	is_file(inode, FADVISE_COLD_BIT)
622b5492af7SJaegeuk Kim #define file_wrong_pino(inode)	is_file(inode, FADVISE_LOST_PINO_BIT)
623b5492af7SJaegeuk Kim #define file_set_cold(inode)	set_file(inode, FADVISE_COLD_BIT)
624b5492af7SJaegeuk Kim #define file_lost_pino(inode)	set_file(inode, FADVISE_LOST_PINO_BIT)
625b5492af7SJaegeuk Kim #define file_clear_cold(inode)	clear_file(inode, FADVISE_COLD_BIT)
626b5492af7SJaegeuk Kim #define file_got_pino(inode)	clear_file(inode, FADVISE_LOST_PINO_BIT)
627cde4de12SJaegeuk Kim #define file_is_encrypt(inode)	is_file(inode, FADVISE_ENCRYPT_BIT)
628cde4de12SJaegeuk Kim #define file_set_encrypt(inode)	set_file(inode, FADVISE_ENCRYPT_BIT)
629cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT)
630e7d55452SJaegeuk Kim #define file_enc_name(inode)	is_file(inode, FADVISE_ENC_NAME_BIT)
631e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
63226787236SJaegeuk Kim #define file_keep_isize(inode)	is_file(inode, FADVISE_KEEP_SIZE_BIT)
63326787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT)
634b6a06cbbSChao Yu #define file_is_hot(inode)	is_file(inode, FADVISE_HOT_BIT)
635b6a06cbbSChao Yu #define file_set_hot(inode)	set_file(inode, FADVISE_HOT_BIT)
636b6a06cbbSChao Yu #define file_clear_hot(inode)	clear_file(inode, FADVISE_HOT_BIT)
637cde4de12SJaegeuk Kim 
638ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL		0
639ab9fa662SJaegeuk Kim 
6402ef79ecbSChao Yu enum {
6412ef79ecbSChao Yu 	GC_FAILURE_PIN,
6422ef79ecbSChao Yu 	GC_FAILURE_ATOMIC,
6432ef79ecbSChao Yu 	MAX_GC_FAILURE
6442ef79ecbSChao Yu };
6452ef79ecbSChao Yu 
64639a53e0cSJaegeuk Kim struct f2fs_inode_info {
64739a53e0cSJaegeuk Kim 	struct inode vfs_inode;		/* serve a vfs inode */
64839a53e0cSJaegeuk Kim 	unsigned long i_flags;		/* keep an inode flags for ioctl */
64939a53e0cSJaegeuk Kim 	unsigned char i_advise;		/* use to give file attribute hints */
65038431545SJaegeuk Kim 	unsigned char i_dir_level;	/* use for dentry level for large dir */
6511ad71a27SJaegeuk Kim 	unsigned int i_current_depth;	/* only for directory depth */
6522ef79ecbSChao Yu 	/* for gc failure statistic */
6532ef79ecbSChao Yu 	unsigned int i_gc_failures[MAX_GC_FAILURE];
6546666e6aaSJaegeuk Kim 	unsigned int i_pino;		/* parent inode number */
65539a53e0cSJaegeuk Kim 	umode_t i_acl_mode;		/* keep file acl mode temporarily */
65639a53e0cSJaegeuk Kim 
65739a53e0cSJaegeuk Kim 	/* Use below internally in f2fs*/
65839a53e0cSJaegeuk Kim 	unsigned long flags;		/* use to pass per-file flags */
659d928bfbfSJaegeuk Kim 	struct rw_semaphore i_sem;	/* protect fi info */
660204706c7SJaegeuk Kim 	atomic_t dirty_pages;		/* # of dirty pages */
66139a53e0cSJaegeuk Kim 	f2fs_hash_t chash;		/* hash value of given file name */
66239a53e0cSJaegeuk Kim 	unsigned int clevel;		/* maximum level of given file name */
66388c5c13aSJaegeuk Kim 	struct task_struct *task;	/* lookup and create consistency */
664b0af6d49SChao Yu 	struct task_struct *cp_task;	/* separate cp/wb IO stats*/
66539a53e0cSJaegeuk Kim 	nid_t i_xattr_nid;		/* node id that contains xattrs */
66626de9b11SJaegeuk Kim 	loff_t	last_disk_size;		/* lastly written file size */
66788b88a66SJaegeuk Kim 
6680abd675eSChao Yu #ifdef CONFIG_QUOTA
6690abd675eSChao Yu 	struct dquot *i_dquot[MAXQUOTAS];
6700abd675eSChao Yu 
6710abd675eSChao Yu 	/* quota space reservation, managed internally by quota code */
6720abd675eSChao Yu 	qsize_t i_reserved_quota;
6730abd675eSChao Yu #endif
6740f18b462SJaegeuk Kim 	struct list_head dirty_list;	/* dirty list for dirs and files */
6750f18b462SJaegeuk Kim 	struct list_head gdirty_list;	/* linked in global dirty list */
67657864ae5SJaegeuk Kim 	struct list_head inmem_ilist;	/* list for inmem inodes */
67788b88a66SJaegeuk Kim 	struct list_head inmem_pages;	/* inmemory pages managed by f2fs */
6787a10f017SJaegeuk Kim 	struct task_struct *inmem_task;	/* store inmemory task */
67988b88a66SJaegeuk Kim 	struct mutex inmem_lock;	/* lock for inmemory pages */
6803e72f721SJaegeuk Kim 	struct extent_tree *extent_tree;	/* cached extent_tree entry */
681b2532c69SChao Yu 
682b2532c69SChao Yu 	/* avoid racing between foreground op and gc */
683b2532c69SChao Yu 	struct rw_semaphore i_gc_rwsem[2];
6845a3a2d83SQiuyang Sun 	struct rw_semaphore i_mmap_sem;
68527161f13SYunlei He 	struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */
686f2470371SChao Yu 
6877a2af766SChao Yu 	int i_extra_isize;		/* size of extra space located in i_addr */
6885c57132eSChao Yu 	kprojid_t i_projid;		/* id for project quota */
6896afc662eSChao Yu 	int i_inline_xattr_size;	/* inline xattr size */
69024b81dfcSArnd Bergmann 	struct timespec64 i_crtime;	/* inode creation time */
69124b81dfcSArnd Bergmann 	struct timespec64 i_disk_time[4];/* inode disk times */
69239a53e0cSJaegeuk Kim };
69339a53e0cSJaegeuk Kim 
69439a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext,
695bd933d4fSChao Yu 					struct f2fs_extent *i_ext)
69639a53e0cSJaegeuk Kim {
697bd933d4fSChao Yu 	ext->fofs = le32_to_cpu(i_ext->fofs);
698bd933d4fSChao Yu 	ext->blk = le32_to_cpu(i_ext->blk);
699bd933d4fSChao Yu 	ext->len = le32_to_cpu(i_ext->len);
70039a53e0cSJaegeuk Kim }
70139a53e0cSJaegeuk Kim 
70239a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext,
70339a53e0cSJaegeuk Kim 					struct f2fs_extent *i_ext)
70439a53e0cSJaegeuk Kim {
70539a53e0cSJaegeuk Kim 	i_ext->fofs = cpu_to_le32(ext->fofs);
7064d0b0bd4SChao Yu 	i_ext->blk = cpu_to_le32(ext->blk);
70739a53e0cSJaegeuk Kim 	i_ext->len = cpu_to_le32(ext->len);
70839a53e0cSJaegeuk Kim }
70939a53e0cSJaegeuk Kim 
710429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
711429511cdSChao Yu 						u32 blk, unsigned int len)
712429511cdSChao Yu {
713429511cdSChao Yu 	ei->fofs = fofs;
714429511cdSChao Yu 	ei->blk = blk;
715429511cdSChao Yu 	ei->len = len;
716429511cdSChao Yu }
717429511cdSChao Yu 
718004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back,
71935ec7d57SChao Yu 			struct discard_info *front, unsigned int max_len)
720004b6862SChao Yu {
7219a997188SJaegeuk Kim 	return (back->lstart + back->len == front->lstart) &&
72235ec7d57SChao Yu 		(back->len + front->len <= max_len);
723004b6862SChao Yu }
724004b6862SChao Yu 
725004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur,
72635ec7d57SChao Yu 			struct discard_info *back, unsigned int max_len)
727004b6862SChao Yu {
72835ec7d57SChao Yu 	return __is_discard_mergeable(back, cur, max_len);
729004b6862SChao Yu }
730004b6862SChao Yu 
731004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur,
73235ec7d57SChao Yu 			struct discard_info *front, unsigned int max_len)
733004b6862SChao Yu {
73435ec7d57SChao Yu 	return __is_discard_mergeable(cur, front, max_len);
735004b6862SChao Yu }
736004b6862SChao Yu 
737429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back,
738429511cdSChao Yu 						struct extent_info *front)
739429511cdSChao Yu {
740429511cdSChao Yu 	return (back->fofs + back->len == front->fofs &&
741429511cdSChao Yu 			back->blk + back->len == front->blk);
742429511cdSChao Yu }
743429511cdSChao Yu 
744429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur,
745429511cdSChao Yu 						struct extent_info *back)
746429511cdSChao Yu {
747429511cdSChao Yu 	return __is_extent_mergeable(back, cur);
748429511cdSChao Yu }
749429511cdSChao Yu 
750429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur,
751429511cdSChao Yu 						struct extent_info *front)
752429511cdSChao Yu {
753429511cdSChao Yu 	return __is_extent_mergeable(cur, front);
754429511cdSChao Yu }
755429511cdSChao Yu 
756cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync);
757205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode,
758205b9822SJaegeuk Kim 			struct extent_tree *et, struct extent_node *en)
7594abd3f5aSChao Yu {
760205b9822SJaegeuk Kim 	if (en->ei.len > et->largest.len) {
7614abd3f5aSChao Yu 		et->largest = en->ei;
7627c45729aSJaegeuk Kim 		f2fs_mark_inode_dirty_sync(inode, true);
763205b9822SJaegeuk Kim 	}
7644abd3f5aSChao Yu }
7654abd3f5aSChao Yu 
7669a4ffdf5SChao Yu /*
7679a4ffdf5SChao Yu  * For free nid management
7689a4ffdf5SChao Yu  */
7699a4ffdf5SChao Yu enum nid_state {
7709a4ffdf5SChao Yu 	FREE_NID,		/* newly added to free nid list */
7719a4ffdf5SChao Yu 	PREALLOC_NID,		/* it is preallocated */
7729a4ffdf5SChao Yu 	MAX_NID_STATE,
773b8559dc2SChao Yu };
774b8559dc2SChao Yu 
77539a53e0cSJaegeuk Kim struct f2fs_nm_info {
77639a53e0cSJaegeuk Kim 	block_t nat_blkaddr;		/* base disk address of NAT */
77739a53e0cSJaegeuk Kim 	nid_t max_nid;			/* maximum possible node ids */
77804d47e67SChao Yu 	nid_t available_nids;		/* # of available node ids */
77939a53e0cSJaegeuk Kim 	nid_t next_scan_nid;		/* the next nid to be scanned */
780cdfc41c1SJaegeuk Kim 	unsigned int ram_thresh;	/* control the memory footprint */
781ea1a29a0SChao Yu 	unsigned int ra_nid_pages;	/* # of nid pages to be readaheaded */
7822304cb0cSChao Yu 	unsigned int dirty_nats_ratio;	/* control dirty nats ratio threshold */
78339a53e0cSJaegeuk Kim 
78439a53e0cSJaegeuk Kim 	/* NAT cache management */
78539a53e0cSJaegeuk Kim 	struct radix_tree_root nat_root;/* root of the nat entry cache */
786309cc2b6SJaegeuk Kim 	struct radix_tree_root nat_set_root;/* root of the nat set cache */
787b873b798SJaegeuk Kim 	struct rw_semaphore nat_tree_lock;	/* protect nat_tree_lock */
78839a53e0cSJaegeuk Kim 	struct list_head nat_entries;	/* cached nat entry list (clean) */
78922969158SChao Yu 	spinlock_t nat_list_lock;	/* protect clean nat entry list */
790309cc2b6SJaegeuk Kim 	unsigned int nat_cnt;		/* the # of cached nat entries */
791aec71382SChao Yu 	unsigned int dirty_nat_cnt;	/* total num of nat entries in set */
79222ad0b6aSJaegeuk Kim 	unsigned int nat_blocks;	/* # of nat blocks */
79339a53e0cSJaegeuk Kim 
79439a53e0cSJaegeuk Kim 	/* free node ids management */
7958a7ed66aSJaegeuk Kim 	struct radix_tree_root free_nid_root;/* root of the free_nid cache */
7969a4ffdf5SChao Yu 	struct list_head free_nid_list;		/* list for free nids excluding preallocated nids */
7979a4ffdf5SChao Yu 	unsigned int nid_cnt[MAX_NID_STATE];	/* the number of free node id */
798b8559dc2SChao Yu 	spinlock_t nid_list_lock;	/* protect nid lists ops */
79939a53e0cSJaegeuk Kim 	struct mutex build_lock;	/* lock for build free nids */
800bb1105e4SJaegeuk Kim 	unsigned char **free_nid_bitmap;
8014ac91242SChao Yu 	unsigned char *nat_block_bitmap;
802586d1492SChao Yu 	unsigned short *free_nid_count;	/* free nid count of NAT block */
80339a53e0cSJaegeuk Kim 
80439a53e0cSJaegeuk Kim 	/* for checkpoint */
80539a53e0cSJaegeuk Kim 	char *nat_bitmap;		/* NAT bitmap pointer */
80622ad0b6aSJaegeuk Kim 
80722ad0b6aSJaegeuk Kim 	unsigned int nat_bits_blocks;	/* # of nat bits blocks */
80822ad0b6aSJaegeuk Kim 	unsigned char *nat_bits;	/* NAT bits blocks */
80922ad0b6aSJaegeuk Kim 	unsigned char *full_nat_bits;	/* full NAT pages */
81022ad0b6aSJaegeuk Kim 	unsigned char *empty_nat_bits;	/* empty NAT pages */
811599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS
812599a09b2SChao Yu 	char *nat_bitmap_mir;		/* NAT bitmap mirror */
813599a09b2SChao Yu #endif
81439a53e0cSJaegeuk Kim 	int bitmap_size;		/* bitmap size */
81539a53e0cSJaegeuk Kim };
81639a53e0cSJaegeuk Kim 
81739a53e0cSJaegeuk Kim /*
81839a53e0cSJaegeuk Kim  * this structure is used as one of function parameters.
81939a53e0cSJaegeuk Kim  * all the information are dedicated to a given direct node block determined
82039a53e0cSJaegeuk Kim  * by the data offset in a file.
82139a53e0cSJaegeuk Kim  */
82239a53e0cSJaegeuk Kim struct dnode_of_data {
82339a53e0cSJaegeuk Kim 	struct inode *inode;		/* vfs inode pointer */
82439a53e0cSJaegeuk Kim 	struct page *inode_page;	/* its inode page, NULL is possible */
82539a53e0cSJaegeuk Kim 	struct page *node_page;		/* cached direct node page */
82639a53e0cSJaegeuk Kim 	nid_t nid;			/* node id of the direct node block */
82739a53e0cSJaegeuk Kim 	unsigned int ofs_in_node;	/* data offset in the node page */
82839a53e0cSJaegeuk Kim 	bool inode_page_locked;		/* inode page is locked or not */
82993bae099SJaegeuk Kim 	bool node_changed;		/* is node block changed */
8303cf45747SChao Yu 	char cur_level;			/* level of hole node page */
8313cf45747SChao Yu 	char max_level;			/* level of current page located */
83239a53e0cSJaegeuk Kim 	block_t	data_blkaddr;		/* block address of the node block */
83339a53e0cSJaegeuk Kim };
83439a53e0cSJaegeuk Kim 
83539a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
83639a53e0cSJaegeuk Kim 		struct page *ipage, struct page *npage, nid_t nid)
83739a53e0cSJaegeuk Kim {
838d66d1f76SJaegeuk Kim 	memset(dn, 0, sizeof(*dn));
83939a53e0cSJaegeuk Kim 	dn->inode = inode;
84039a53e0cSJaegeuk Kim 	dn->inode_page = ipage;
84139a53e0cSJaegeuk Kim 	dn->node_page = npage;
84239a53e0cSJaegeuk Kim 	dn->nid = nid;
84339a53e0cSJaegeuk Kim }
84439a53e0cSJaegeuk Kim 
84539a53e0cSJaegeuk Kim /*
84639a53e0cSJaegeuk Kim  * For SIT manager
84739a53e0cSJaegeuk Kim  *
84839a53e0cSJaegeuk Kim  * By default, there are 6 active log areas across the whole main area.
84939a53e0cSJaegeuk Kim  * When considering hot and cold data separation to reduce cleaning overhead,
85039a53e0cSJaegeuk Kim  * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
85139a53e0cSJaegeuk Kim  * respectively.
85239a53e0cSJaegeuk Kim  * In the current design, you should not change the numbers intentionally.
85339a53e0cSJaegeuk Kim  * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
85439a53e0cSJaegeuk Kim  * logs individually according to the underlying devices. (default: 6)
85539a53e0cSJaegeuk Kim  * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
85639a53e0cSJaegeuk Kim  * data and 8 for node logs.
85739a53e0cSJaegeuk Kim  */
85839a53e0cSJaegeuk Kim #define	NR_CURSEG_DATA_TYPE	(3)
85939a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE	(3)
86039a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
86139a53e0cSJaegeuk Kim 
86239a53e0cSJaegeuk Kim enum {
86339a53e0cSJaegeuk Kim 	CURSEG_HOT_DATA	= 0,	/* directory entry blocks */
86439a53e0cSJaegeuk Kim 	CURSEG_WARM_DATA,	/* data blocks */
86539a53e0cSJaegeuk Kim 	CURSEG_COLD_DATA,	/* multimedia or GCed data blocks */
86639a53e0cSJaegeuk Kim 	CURSEG_HOT_NODE,	/* direct node blocks of directory files */
86739a53e0cSJaegeuk Kim 	CURSEG_WARM_NODE,	/* direct node blocks of normal files */
86839a53e0cSJaegeuk Kim 	CURSEG_COLD_NODE,	/* indirect node blocks */
86938aa0889SJaegeuk Kim 	NO_CHECK_TYPE,
87039a53e0cSJaegeuk Kim };
87139a53e0cSJaegeuk Kim 
8726b4afdd7SJaegeuk Kim struct flush_cmd {
8736b4afdd7SJaegeuk Kim 	struct completion wait;
874721bd4d5SGu Zheng 	struct llist_node llnode;
87539d787beSChao Yu 	nid_t ino;
8766b4afdd7SJaegeuk Kim 	int ret;
8776b4afdd7SJaegeuk Kim };
8786b4afdd7SJaegeuk Kim 
879a688b9d9SGu Zheng struct flush_cmd_control {
880a688b9d9SGu Zheng 	struct task_struct *f2fs_issue_flush;	/* flush thread */
881a688b9d9SGu Zheng 	wait_queue_head_t flush_wait_queue;	/* waiting queue for wake-up */
8828b8dd65fSChao Yu 	atomic_t issued_flush;			/* # of issued flushes */
8838b8dd65fSChao Yu 	atomic_t issing_flush;			/* # of issing flushes */
884721bd4d5SGu Zheng 	struct llist_head issue_list;		/* list for command issue */
885721bd4d5SGu Zheng 	struct llist_node *dispatch_list;	/* list for command dispatch */
886a688b9d9SGu Zheng };
887a688b9d9SGu Zheng 
88839a53e0cSJaegeuk Kim struct f2fs_sm_info {
88939a53e0cSJaegeuk Kim 	struct sit_info *sit_info;		/* whole segment information */
89039a53e0cSJaegeuk Kim 	struct free_segmap_info *free_info;	/* free segment information */
89139a53e0cSJaegeuk Kim 	struct dirty_seglist_info *dirty_info;	/* dirty segment information */
89239a53e0cSJaegeuk Kim 	struct curseg_info *curseg_array;	/* active segment information */
89339a53e0cSJaegeuk Kim 
8942b60311dSChao Yu 	struct rw_semaphore curseg_lock;	/* for preventing curseg change */
8952b60311dSChao Yu 
89639a53e0cSJaegeuk Kim 	block_t seg0_blkaddr;		/* block address of 0'th segment */
89739a53e0cSJaegeuk Kim 	block_t main_blkaddr;		/* start block address of main area */
89839a53e0cSJaegeuk Kim 	block_t ssa_blkaddr;		/* start block address of SSA area */
89939a53e0cSJaegeuk Kim 
90039a53e0cSJaegeuk Kim 	unsigned int segment_count;	/* total # of segments */
90139a53e0cSJaegeuk Kim 	unsigned int main_segments;	/* # of segments in main area */
90239a53e0cSJaegeuk Kim 	unsigned int reserved_segments;	/* # of reserved segments */
90339a53e0cSJaegeuk Kim 	unsigned int ovp_segments;	/* # of overprovision segments */
90481eb8d6eSJaegeuk Kim 
90581eb8d6eSJaegeuk Kim 	/* a threshold to reclaim prefree segments */
90681eb8d6eSJaegeuk Kim 	unsigned int rec_prefree_segments;
9077fd9e544SJaegeuk Kim 
908bba681cbSJaegeuk Kim 	/* for batched trimming */
909bba681cbSJaegeuk Kim 	unsigned int trim_sections;		/* # of sections to trim */
910bba681cbSJaegeuk Kim 
911184a5cd2SChao Yu 	struct list_head sit_entry_set;	/* sit entry set list */
912184a5cd2SChao Yu 
913216fbd64SJaegeuk Kim 	unsigned int ipu_policy;	/* in-place-update policy */
914216fbd64SJaegeuk Kim 	unsigned int min_ipu_util;	/* in-place-update threshold */
915c1ce1b02SJaegeuk Kim 	unsigned int min_fsync_blocks;	/* threshold for fsync */
916*853137ceSJaegeuk Kim 	unsigned int min_seq_blocks;	/* threshold for sequential blocks */
917ef095d19SJaegeuk Kim 	unsigned int min_hot_blocks;	/* threshold for hot block allocation */
918a2a12b67SChao Yu 	unsigned int min_ssr_sections;	/* threshold to trigger SSR allocation */
9196b4afdd7SJaegeuk Kim 
9206b4afdd7SJaegeuk Kim 	/* for flush command control */
921b01a9201SJaegeuk Kim 	struct flush_cmd_control *fcc_info;
922a688b9d9SGu Zheng 
9230b54fb84SJaegeuk Kim 	/* for discard command control */
9240b54fb84SJaegeuk Kim 	struct discard_cmd_control *dcc_info;
92539a53e0cSJaegeuk Kim };
92639a53e0cSJaegeuk Kim 
92739a53e0cSJaegeuk Kim /*
92839a53e0cSJaegeuk Kim  * For superblock
92939a53e0cSJaegeuk Kim  */
93039a53e0cSJaegeuk Kim /*
93139a53e0cSJaegeuk Kim  * COUNT_TYPE for monitoring
93239a53e0cSJaegeuk Kim  *
93339a53e0cSJaegeuk Kim  * f2fs monitors the number of several block types such as on-writeback,
93439a53e0cSJaegeuk Kim  * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
93539a53e0cSJaegeuk Kim  */
93636951b38SChao Yu #define WB_DATA_TYPE(p)	(__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA)
93739a53e0cSJaegeuk Kim enum count_type {
93839a53e0cSJaegeuk Kim 	F2FS_DIRTY_DENTS,
939c227f912SChao Yu 	F2FS_DIRTY_DATA,
9402c8a4a28SJaegeuk Kim 	F2FS_DIRTY_QDATA,
94139a53e0cSJaegeuk Kim 	F2FS_DIRTY_NODES,
94239a53e0cSJaegeuk Kim 	F2FS_DIRTY_META,
9438dcf2ff7SJaegeuk Kim 	F2FS_INMEM_PAGES,
9440f18b462SJaegeuk Kim 	F2FS_DIRTY_IMETA,
94536951b38SChao Yu 	F2FS_WB_CP_DATA,
94636951b38SChao Yu 	F2FS_WB_DATA,
94739a53e0cSJaegeuk Kim 	NR_COUNT_TYPE,
94839a53e0cSJaegeuk Kim };
94939a53e0cSJaegeuk Kim 
95039a53e0cSJaegeuk Kim /*
951e1c42045Sarter97  * The below are the page types of bios used in submit_bio().
95239a53e0cSJaegeuk Kim  * The available types are:
95339a53e0cSJaegeuk Kim  * DATA			User data pages. It operates as async mode.
95439a53e0cSJaegeuk Kim  * NODE			Node pages. It operates as async mode.
95539a53e0cSJaegeuk Kim  * META			FS metadata pages such as SIT, NAT, CP.
95639a53e0cSJaegeuk Kim  * NR_PAGE_TYPE		The number of page types.
95739a53e0cSJaegeuk Kim  * META_FLUSH		Make sure the previous pages are written
95839a53e0cSJaegeuk Kim  *			with waiting the bio's completion
95939a53e0cSJaegeuk Kim  * ...			Only can be used with META.
96039a53e0cSJaegeuk Kim  */
9617d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type)	((type) > META ? META : (type))
96239a53e0cSJaegeuk Kim enum page_type {
96339a53e0cSJaegeuk Kim 	DATA,
96439a53e0cSJaegeuk Kim 	NODE,
96539a53e0cSJaegeuk Kim 	META,
96639a53e0cSJaegeuk Kim 	NR_PAGE_TYPE,
96739a53e0cSJaegeuk Kim 	META_FLUSH,
9688ce67cb0SJaegeuk Kim 	INMEM,		/* the below types are used by tracepoints only. */
9698ce67cb0SJaegeuk Kim 	INMEM_DROP,
9708c242db9SJaegeuk Kim 	INMEM_INVALIDATE,
97128bc106bSChao Yu 	INMEM_REVOKE,
9728ce67cb0SJaegeuk Kim 	IPU,
9738ce67cb0SJaegeuk Kim 	OPU,
97439a53e0cSJaegeuk Kim };
97539a53e0cSJaegeuk Kim 
976a912b54dSJaegeuk Kim enum temp_type {
977a912b54dSJaegeuk Kim 	HOT = 0,	/* must be zero for meta bio */
978a912b54dSJaegeuk Kim 	WARM,
979a912b54dSJaegeuk Kim 	COLD,
980a912b54dSJaegeuk Kim 	NR_TEMP_TYPE,
981a912b54dSJaegeuk Kim };
982a912b54dSJaegeuk Kim 
983cc15620bSJaegeuk Kim enum need_lock_type {
984cc15620bSJaegeuk Kim 	LOCK_REQ = 0,
985cc15620bSJaegeuk Kim 	LOCK_DONE,
986cc15620bSJaegeuk Kim 	LOCK_RETRY,
987cc15620bSJaegeuk Kim };
988cc15620bSJaegeuk Kim 
989a5fd5050SChao Yu enum cp_reason_type {
990a5fd5050SChao Yu 	CP_NO_NEEDED,
991a5fd5050SChao Yu 	CP_NON_REGULAR,
992a5fd5050SChao Yu 	CP_HARDLINK,
993a5fd5050SChao Yu 	CP_SB_NEED_CP,
994a5fd5050SChao Yu 	CP_WRONG_PINO,
995a5fd5050SChao Yu 	CP_NO_SPC_ROLL,
996a5fd5050SChao Yu 	CP_NODE_NEED_CP,
997a5fd5050SChao Yu 	CP_FASTBOOT_MODE,
998a5fd5050SChao Yu 	CP_SPEC_LOG_NUM,
9990a007b97SJaegeuk Kim 	CP_RECOVER_DIR,
1000a5fd5050SChao Yu };
1001a5fd5050SChao Yu 
1002b0af6d49SChao Yu enum iostat_type {
1003b0af6d49SChao Yu 	APP_DIRECT_IO,			/* app direct IOs */
1004b0af6d49SChao Yu 	APP_BUFFERED_IO,		/* app buffered IOs */
1005b0af6d49SChao Yu 	APP_WRITE_IO,			/* app write IOs */
1006b0af6d49SChao Yu 	APP_MAPPED_IO,			/* app mapped IOs */
1007b0af6d49SChao Yu 	FS_DATA_IO,			/* data IOs from kworker/fsync/reclaimer */
1008b0af6d49SChao Yu 	FS_NODE_IO,			/* node IOs from kworker/fsync/reclaimer */
1009b0af6d49SChao Yu 	FS_META_IO,			/* meta IOs from kworker/reclaimer */
1010b0af6d49SChao Yu 	FS_GC_DATA_IO,			/* data IOs from forground gc */
1011b0af6d49SChao Yu 	FS_GC_NODE_IO,			/* node IOs from forground gc */
1012b0af6d49SChao Yu 	FS_CP_DATA_IO,			/* data IOs from checkpoint */
1013b0af6d49SChao Yu 	FS_CP_NODE_IO,			/* node IOs from checkpoint */
1014b0af6d49SChao Yu 	FS_CP_META_IO,			/* meta IOs from checkpoint */
1015b0af6d49SChao Yu 	FS_DISCARD,			/* discard */
1016b0af6d49SChao Yu 	NR_IO_TYPE,
1017b0af6d49SChao Yu };
1018b0af6d49SChao Yu 
1019458e6197SJaegeuk Kim struct f2fs_io_info {
102005ca3632SJaegeuk Kim 	struct f2fs_sb_info *sbi;	/* f2fs_sb_info pointer */
102139d787beSChao Yu 	nid_t ino;		/* inode number */
1022458e6197SJaegeuk Kim 	enum page_type type;	/* contains DATA/NODE/META/META_FLUSH */
1023a912b54dSJaegeuk Kim 	enum temp_type temp;	/* contains HOT/WARM/COLD */
102404d328deSMike Christie 	int op;			/* contains REQ_OP_ */
1025ef295ecfSChristoph Hellwig 	int op_flags;		/* req_flag_bits */
10267a9d7548SChao Yu 	block_t new_blkaddr;	/* new block address to be written */
102728bc106bSChao Yu 	block_t old_blkaddr;	/* old block address before Cow */
102805ca3632SJaegeuk Kim 	struct page *page;	/* page to be written */
10294375a336SJaegeuk Kim 	struct page *encrypted_page;	/* encrypted page */
1030fb830fc5SChao Yu 	struct list_head list;		/* serialize IOs */
1031d68f735bSJaegeuk Kim 	bool submitted;		/* indicate IO submission */
1032cc15620bSJaegeuk Kim 	int need_lock;		/* indicate we need to lock cp_rwsem */
1033fb830fc5SChao Yu 	bool in_list;		/* indicate fio is in io_list */
10340833721eSYunlei He 	bool is_meta;		/* indicate borrow meta inode mapping or not */
1035fe16efe6SChao Yu 	bool retry;		/* need to reallocate block address */
1036b0af6d49SChao Yu 	enum iostat_type io_type;	/* io type */
1037578c6478SYufen Yu 	struct writeback_control *io_wbc; /* writeback control */
10387735730dSChao Yu 	unsigned char version;		/* version of the node */
1039458e6197SJaegeuk Kim };
1040458e6197SJaegeuk Kim 
104168afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ)
10421ff7bd3bSJaegeuk Kim struct f2fs_bio_info {
1043458e6197SJaegeuk Kim 	struct f2fs_sb_info *sbi;	/* f2fs superblock */
10441ff7bd3bSJaegeuk Kim 	struct bio *bio;		/* bios to merge */
10451ff7bd3bSJaegeuk Kim 	sector_t last_block_in_bio;	/* last block number */
1046458e6197SJaegeuk Kim 	struct f2fs_io_info fio;	/* store buffered io info. */
1047df0f8dc0SChao Yu 	struct rw_semaphore io_rwsem;	/* blocking op for bio */
1048fb830fc5SChao Yu 	spinlock_t io_lock;		/* serialize DATA/NODE IOs */
1049fb830fc5SChao Yu 	struct list_head io_list;	/* track fios */
10501ff7bd3bSJaegeuk Kim };
10511ff7bd3bSJaegeuk Kim 
10523c62be17SJaegeuk Kim #define FDEV(i)				(sbi->devs[i])
10533c62be17SJaegeuk Kim #define RDEV(i)				(raw_super->devs[i])
10543c62be17SJaegeuk Kim struct f2fs_dev_info {
10553c62be17SJaegeuk Kim 	struct block_device *bdev;
10563c62be17SJaegeuk Kim 	char path[MAX_PATH_LEN];
10573c62be17SJaegeuk Kim 	unsigned int total_segments;
10583c62be17SJaegeuk Kim 	block_t start_blk;
10593c62be17SJaegeuk Kim 	block_t end_blk;
10603c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED
10613c62be17SJaegeuk Kim 	unsigned int nr_blkz;			/* Total number of zones */
10623c62be17SJaegeuk Kim 	u8 *blkz_type;				/* Array of zones type */
10633c62be17SJaegeuk Kim #endif
10643c62be17SJaegeuk Kim };
10653c62be17SJaegeuk Kim 
1066c227f912SChao Yu enum inode_type {
1067c227f912SChao Yu 	DIR_INODE,			/* for dirty dir inode */
1068c227f912SChao Yu 	FILE_INODE,			/* for dirty regular/symlink inode */
10690f18b462SJaegeuk Kim 	DIRTY_META,			/* for all dirtied inode metadata */
107057864ae5SJaegeuk Kim 	ATOMIC_FILE,			/* for all atomic files */
1071c227f912SChao Yu 	NR_INODE_TYPE,
1072c227f912SChao Yu };
1073c227f912SChao Yu 
107467298804SChao Yu /* for inner inode cache management */
107567298804SChao Yu struct inode_management {
107667298804SChao Yu 	struct radix_tree_root ino_root;	/* ino entry array */
107767298804SChao Yu 	spinlock_t ino_lock;			/* for ino entry lock */
107867298804SChao Yu 	struct list_head ino_list;		/* inode list head */
107967298804SChao Yu 	unsigned long ino_num;			/* number of entries */
108067298804SChao Yu };
108167298804SChao Yu 
1082caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */
1083caf0047eSChao Yu enum {
1084caf0047eSChao Yu 	SBI_IS_DIRTY,				/* dirty flag for checkpoint */
1085caf0047eSChao Yu 	SBI_IS_CLOSE,				/* specify unmounting */
1086caf0047eSChao Yu 	SBI_NEED_FSCK,				/* need fsck.f2fs to fix */
1087caf0047eSChao Yu 	SBI_POR_DOING,				/* recovery is doing or not */
1088df728b0fSJaegeuk Kim 	SBI_NEED_SB_WRITE,			/* need to recover superblock */
1089bbf156f7SJaegeuk Kim 	SBI_NEED_CP,				/* need to checkpoint */
109083a3bfdbSJaegeuk Kim 	SBI_IS_SHUTDOWN,			/* shutdown by ioctl */
1091caf0047eSChao Yu };
1092caf0047eSChao Yu 
10936beceb54SJaegeuk Kim enum {
10946beceb54SJaegeuk Kim 	CP_TIME,
1095d0239e1bSJaegeuk Kim 	REQ_TIME,
10966beceb54SJaegeuk Kim 	MAX_TIME,
10976beceb54SJaegeuk Kim };
10986beceb54SJaegeuk Kim 
10990cdd3195SHyunchul Lee enum {
11005b0e9539SJaegeuk Kim 	GC_NORMAL,
11015b0e9539SJaegeuk Kim 	GC_IDLE_CB,
11025b0e9539SJaegeuk Kim 	GC_IDLE_GREEDY,
11035b0e9539SJaegeuk Kim 	GC_URGENT,
11045b0e9539SJaegeuk Kim };
11055b0e9539SJaegeuk Kim 
11065b0e9539SJaegeuk Kim enum {
11070cdd3195SHyunchul Lee 	WHINT_MODE_OFF,		/* not pass down write hints */
11080cdd3195SHyunchul Lee 	WHINT_MODE_USER,	/* try to pass down hints given by users */
1109f2e703f9SHyunchul Lee 	WHINT_MODE_FS,		/* pass down hints with F2FS policy */
11100cdd3195SHyunchul Lee };
11110cdd3195SHyunchul Lee 
111207939627SJaegeuk Kim enum {
111307939627SJaegeuk Kim 	ALLOC_MODE_DEFAULT,	/* stay default */
111407939627SJaegeuk Kim 	ALLOC_MODE_REUSE,	/* reuse segments as much as possible */
111507939627SJaegeuk Kim };
111607939627SJaegeuk Kim 
111793cf93f1SJunling Zheng enum fsync_mode {
111893cf93f1SJunling Zheng 	FSYNC_MODE_POSIX,	/* fsync follows posix semantics */
111993cf93f1SJunling Zheng 	FSYNC_MODE_STRICT,	/* fsync behaves in line with ext4 */
1120d6290814SJaegeuk Kim 	FSYNC_MODE_NOBARRIER,	/* fsync behaves nobarrier based on posix */
112193cf93f1SJunling Zheng };
112293cf93f1SJunling Zheng 
1123ff62af20SSheng Yong #ifdef CONFIG_F2FS_FS_ENCRYPTION
1124ff62af20SSheng Yong #define DUMMY_ENCRYPTION_ENABLED(sbi) \
1125ff62af20SSheng Yong 			(unlikely(F2FS_OPTION(sbi).test_dummy_encryption))
1126ff62af20SSheng Yong #else
1127ff62af20SSheng Yong #define DUMMY_ENCRYPTION_ENABLED(sbi) (0)
1128ff62af20SSheng Yong #endif
1129ff62af20SSheng Yong 
113039a53e0cSJaegeuk Kim struct f2fs_sb_info {
113139a53e0cSJaegeuk Kim 	struct super_block *sb;			/* pointer to VFS super block */
11325e176d54SJaegeuk Kim 	struct proc_dir_entry *s_proc;		/* proc entry */
113339a53e0cSJaegeuk Kim 	struct f2fs_super_block *raw_super;	/* raw super block pointer */
1134846ae671SChao Yu 	struct rw_semaphore sb_lock;		/* lock for raw super block */
1135e8240f65SChao Yu 	int valid_super_block;			/* valid super block no */
1136fadb2fb8SChao Yu 	unsigned long s_flag;				/* flags for sbi */
1137*853137ceSJaegeuk Kim 	struct mutex writepages;		/* mutex for writepages() */
113839a53e0cSJaegeuk Kim 
1139178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED
1140178053e2SDamien Le Moal 	unsigned int blocks_per_blkz;		/* F2FS blocks per zone */
1141178053e2SDamien Le Moal 	unsigned int log_blocks_per_blkz;	/* log2 F2FS blocks per zone */
1142178053e2SDamien Le Moal #endif
1143178053e2SDamien Le Moal 
114439a53e0cSJaegeuk Kim 	/* for node-related operations */
114539a53e0cSJaegeuk Kim 	struct f2fs_nm_info *nm_info;		/* node manager */
114639a53e0cSJaegeuk Kim 	struct inode *node_inode;		/* cache node blocks */
114739a53e0cSJaegeuk Kim 
114839a53e0cSJaegeuk Kim 	/* for segment-related operations */
114939a53e0cSJaegeuk Kim 	struct f2fs_sm_info *sm_info;		/* segment manager */
11501ff7bd3bSJaegeuk Kim 
11511ff7bd3bSJaegeuk Kim 	/* for bio operations */
1152a912b54dSJaegeuk Kim 	struct f2fs_bio_info *write_io[NR_PAGE_TYPE];	/* for write bios */
1153e41e6d75SChao Yu 	struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE];
1154e41e6d75SChao Yu 						/* bio ordering for NODE/DATA */
1155107a805dSChao Yu 	/* keep migration IO order for LFS mode */
1156107a805dSChao Yu 	struct rw_semaphore io_order_lock;
11570a595ebaSJaegeuk Kim 	mempool_t *write_io_dummy;		/* Dummy pages */
115839a53e0cSJaegeuk Kim 
115939a53e0cSJaegeuk Kim 	/* for checkpoint */
116039a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
11618508e44aSJaegeuk Kim 	int cur_cp_pack;			/* remain current cp pack */
1162aaec2b1dSChao Yu 	spinlock_t cp_lock;			/* for flag in ckpt */
116339a53e0cSJaegeuk Kim 	struct inode *meta_inode;		/* cache meta blocks */
116439936837SJaegeuk Kim 	struct mutex cp_mutex;			/* checkpoint procedure lock */
1165b873b798SJaegeuk Kim 	struct rw_semaphore cp_rwsem;		/* blocking FS operations */
1166b3582c68SChao Yu 	struct rw_semaphore node_write;		/* locking node writes */
116759c9081bSYunlei He 	struct rw_semaphore node_change;	/* locking node change */
1168fb51b5efSChangman Lee 	wait_queue_head_t cp_wait;
11696beceb54SJaegeuk Kim 	unsigned long last_time[MAX_TIME];	/* to store time in jiffies */
11706beceb54SJaegeuk Kim 	long interval_time[MAX_TIME];		/* to store thresholds */
117139a53e0cSJaegeuk Kim 
117267298804SChao Yu 	struct inode_management im[MAX_INO_ENTRY];      /* manage inode cache */
11736451e041SJaegeuk Kim 
117450fa53ecSChao Yu 	spinlock_t fsync_node_lock;		/* for node entry lock */
117550fa53ecSChao Yu 	struct list_head fsync_node_list;	/* node list head */
117650fa53ecSChao Yu 	unsigned int fsync_seg_id;		/* sequence id */
117750fa53ecSChao Yu 	unsigned int fsync_node_num;		/* number of node entries */
117850fa53ecSChao Yu 
11796451e041SJaegeuk Kim 	/* for orphan inode, use 0'th array */
11800d47c1adSGu Zheng 	unsigned int max_orphans;		/* max orphan inodes */
118139a53e0cSJaegeuk Kim 
1182c227f912SChao Yu 	/* for inode management */
1183c227f912SChao Yu 	struct list_head inode_list[NR_INODE_TYPE];	/* dirty inode list */
1184c227f912SChao Yu 	spinlock_t inode_lock[NR_INODE_TYPE];	/* for dirty inode list lock */
118539a53e0cSJaegeuk Kim 
118613054c54SChao Yu 	/* for extent tree cache */
118713054c54SChao Yu 	struct radix_tree_root extent_tree_root;/* cache extent cache entries */
11885e8256acSYunlei He 	struct mutex extent_tree_lock;	/* locking extent radix tree */
118913054c54SChao Yu 	struct list_head extent_list;		/* lru list for shrinker */
119013054c54SChao Yu 	spinlock_t extent_lock;			/* locking extent lru list */
11917441ccefSJaegeuk Kim 	atomic_t total_ext_tree;		/* extent tree count */
1192137d09f0SJaegeuk Kim 	struct list_head zombie_list;		/* extent zombie tree list */
119374fd8d99SJaegeuk Kim 	atomic_t total_zombie_tree;		/* extent zombie tree count */
119413054c54SChao Yu 	atomic_t total_ext_node;		/* extent info count */
119513054c54SChao Yu 
119639a53e0cSJaegeuk Kim 	/* basic filesystem units */
119739a53e0cSJaegeuk Kim 	unsigned int log_sectors_per_block;	/* log2 sectors per block */
119839a53e0cSJaegeuk Kim 	unsigned int log_blocksize;		/* log2 block size */
119939a53e0cSJaegeuk Kim 	unsigned int blocksize;			/* block size */
120039a53e0cSJaegeuk Kim 	unsigned int root_ino_num;		/* root inode number*/
120139a53e0cSJaegeuk Kim 	unsigned int node_ino_num;		/* node inode number*/
120239a53e0cSJaegeuk Kim 	unsigned int meta_ino_num;		/* meta inode number*/
120339a53e0cSJaegeuk Kim 	unsigned int log_blocks_per_seg;	/* log2 blocks per segment */
120439a53e0cSJaegeuk Kim 	unsigned int blocks_per_seg;		/* blocks per segment */
120539a53e0cSJaegeuk Kim 	unsigned int segs_per_sec;		/* segments per section */
120639a53e0cSJaegeuk Kim 	unsigned int secs_per_zone;		/* sections per zone */
120739a53e0cSJaegeuk Kim 	unsigned int total_sections;		/* total section count */
120839a53e0cSJaegeuk Kim 	unsigned int total_node_count;		/* total node block count */
120939a53e0cSJaegeuk Kim 	unsigned int total_valid_node_count;	/* valid node block count */
1210e0afc4d6SChao Yu 	loff_t max_file_blocks;			/* max block index of file */
1211ab9fa662SJaegeuk Kim 	int dir_level;				/* directory level */
1212a2a12b67SChao Yu 	unsigned int trigger_ssr_threshold;	/* threshold to trigger ssr */
1213f6df8f23SSheng Yong 	int readdir_ra;				/* readahead inode in readdir */
121439a53e0cSJaegeuk Kim 
121539a53e0cSJaegeuk Kim 	block_t user_block_count;		/* # of user blocks */
121639a53e0cSJaegeuk Kim 	block_t total_valid_block_count;	/* # of valid blocks */
1217a66cdd98SJaegeuk Kim 	block_t discard_blks;			/* discard command candidats */
121839a53e0cSJaegeuk Kim 	block_t last_valid_block_count;		/* for recovery */
1219daeb433eSChao Yu 	block_t reserved_blocks;		/* configurable reserved blocks */
122080d42145SYunlong Song 	block_t current_reserved_blocks;	/* current reserved blocks */
1221daeb433eSChao Yu 
1222292c196aSChao Yu 	unsigned int nquota_files;		/* # of quota sysfile */
1223292c196aSChao Yu 
122439a53e0cSJaegeuk Kim 	u32 s_next_generation;			/* for NFS support */
1225523be8a6SJaegeuk Kim 
1226523be8a6SJaegeuk Kim 	/* # of pages, see count_type */
122735782b23SJaegeuk Kim 	atomic_t nr_pages[NR_COUNT_TYPE];
122841382ec4SJaegeuk Kim 	/* # of allocated blocks */
122941382ec4SJaegeuk Kim 	struct percpu_counter alloc_valid_block_count;
123039a53e0cSJaegeuk Kim 
1231687de7f1SJaegeuk Kim 	/* writeback control */
1232c29fd0c0SChao Yu 	atomic_t wb_sync_req[META];	/* count # of WB_SYNC threads */
1233687de7f1SJaegeuk Kim 
1234513c5f37SJaegeuk Kim 	/* valid inode count */
1235513c5f37SJaegeuk Kim 	struct percpu_counter total_valid_inode_count;
1236513c5f37SJaegeuk Kim 
123739a53e0cSJaegeuk Kim 	struct f2fs_mount_info mount_opt;	/* mount options */
123839a53e0cSJaegeuk Kim 
123939a53e0cSJaegeuk Kim 	/* for cleaning operations */
124039a53e0cSJaegeuk Kim 	struct mutex gc_mutex;			/* mutex for GC */
124139a53e0cSJaegeuk Kim 	struct f2fs_gc_kthread	*gc_thread;	/* GC thread */
12425ec4e49fSJaegeuk Kim 	unsigned int cur_victim_sec;		/* current victim section num */
12435b0e9539SJaegeuk Kim 	unsigned int gc_mode;			/* current GC state */
12442ef79ecbSChao Yu 	/* for skip statistic */
12452ef79ecbSChao Yu 	unsigned long long skipped_atomic_files[2];	/* FG_GC and BG_GC */
124639a53e0cSJaegeuk Kim 
12471ad71a27SJaegeuk Kim 	/* threshold for gc trials on pinned files */
12481ad71a27SJaegeuk Kim 	u64 gc_pin_file_threshold;
12491ad71a27SJaegeuk Kim 
1250b1c57c1cSJaegeuk Kim 	/* maximum # of trials to find a victim segment for SSR and GC */
1251b1c57c1cSJaegeuk Kim 	unsigned int max_victim_search;
1252b1c57c1cSJaegeuk Kim 
125339a53e0cSJaegeuk Kim 	/*
125439a53e0cSJaegeuk Kim 	 * for stat information.
125539a53e0cSJaegeuk Kim 	 * one is for the LFS mode, and the other is for the SSR mode.
125639a53e0cSJaegeuk Kim 	 */
125735b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS
125839a53e0cSJaegeuk Kim 	struct f2fs_stat_info *stat_info;	/* FS status information */
125939a53e0cSJaegeuk Kim 	unsigned int segment_count[2];		/* # of allocated segments */
126039a53e0cSJaegeuk Kim 	unsigned int block_count[2];		/* # of allocated blocks */
1261b9a2c252SChangman Lee 	atomic_t inplace_count;		/* # of inplace update */
12625b7ee374SChao Yu 	atomic64_t total_hit_ext;		/* # of lookup extent cache */
12635b7ee374SChao Yu 	atomic64_t read_hit_rbtree;		/* # of hit rbtree extent node */
12645b7ee374SChao Yu 	atomic64_t read_hit_largest;		/* # of hit largest extent node */
12655b7ee374SChao Yu 	atomic64_t read_hit_cached;		/* # of hit cached extent node */
1266d5e8f6c9SChao Yu 	atomic_t inline_xattr;			/* # of inline_xattr inodes */
126703e14d52SChao Yu 	atomic_t inline_inode;			/* # of inline_data inodes */
126803e14d52SChao Yu 	atomic_t inline_dir;			/* # of inline_dentry inodes */
126926a28a0cSJaegeuk Kim 	atomic_t aw_cnt;			/* # of atomic writes */
1270648d50baSChao Yu 	atomic_t vw_cnt;			/* # of volatile writes */
127126a28a0cSJaegeuk Kim 	atomic_t max_aw_cnt;			/* max # of atomic writes */
1272648d50baSChao Yu 	atomic_t max_vw_cnt;			/* max # of volatile writes */
127339a53e0cSJaegeuk Kim 	int bg_gc;				/* background gc calls */
127433fbd510SChao Yu 	unsigned int ndirty_inode[NR_INODE_TYPE];	/* # of dirty inodes */
127535b09d82SNamjae Jeon #endif
127639a53e0cSJaegeuk Kim 	spinlock_t stat_lock;			/* lock for stat operations */
1277b59d0baeSNamjae Jeon 
1278b0af6d49SChao Yu 	/* For app/fs IO statistics */
1279b0af6d49SChao Yu 	spinlock_t iostat_lock;
1280b0af6d49SChao Yu 	unsigned long long write_iostat[NR_IO_TYPE];
1281b0af6d49SChao Yu 	bool iostat_enable;
1282b0af6d49SChao Yu 
1283b59d0baeSNamjae Jeon 	/* For sysfs suppport */
1284b59d0baeSNamjae Jeon 	struct kobject s_kobj;
1285b59d0baeSNamjae Jeon 	struct completion s_kobj_unregister;
12862658e50dSJaegeuk Kim 
12872658e50dSJaegeuk Kim 	/* For shrinker support */
12882658e50dSJaegeuk Kim 	struct list_head s_list;
12893c62be17SJaegeuk Kim 	int s_ndevs;				/* number of devices */
12903c62be17SJaegeuk Kim 	struct f2fs_dev_info *devs;		/* for device list */
12911228b482SChao Yu 	unsigned int dirty_device;		/* for checkpoint data flush */
12921228b482SChao Yu 	spinlock_t dev_lock;			/* protect dirty_device */
12932658e50dSJaegeuk Kim 	struct mutex umount_mutex;
12942658e50dSJaegeuk Kim 	unsigned int shrinker_run_no;
12958f1dbbbbSShuoran Liu 
12968f1dbbbbSShuoran Liu 	/* For write statistics */
12978f1dbbbbSShuoran Liu 	u64 sectors_written_start;
12988f1dbbbbSShuoran Liu 	u64 kbytes_written;
129943b6573bSKeith Mok 
130043b6573bSKeith Mok 	/* Reference to checksum algorithm driver via cryptoapi */
130143b6573bSKeith Mok 	struct crypto_shash *s_chksum_driver;
13021ecc0c5cSChao Yu 
1303704956ecSChao Yu 	/* Precomputed FS UUID checksum for seeding other checksums */
1304704956ecSChao Yu 	__u32 s_chksum_seed;
130539a53e0cSJaegeuk Kim };
130639a53e0cSJaegeuk Kim 
13071ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION
130855523519SChao Yu #define f2fs_show_injection_info(type)				\
130955523519SChao Yu 	printk("%sF2FS-fs : inject %s in %s of %pF\n",		\
13102d3a5856SGao Xiang 		KERN_INFO, f2fs_fault_name[type],		\
131155523519SChao Yu 		__func__, __builtin_return_address(0))
13121ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
13131ecc0c5cSChao Yu {
131463189b78SChao Yu 	struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
13151ecc0c5cSChao Yu 
13161ecc0c5cSChao Yu 	if (!ffi->inject_rate)
13171ecc0c5cSChao Yu 		return false;
13181ecc0c5cSChao Yu 
13191ecc0c5cSChao Yu 	if (!IS_FAULT_SET(ffi, type))
13201ecc0c5cSChao Yu 		return false;
13211ecc0c5cSChao Yu 
13221ecc0c5cSChao Yu 	atomic_inc(&ffi->inject_ops);
13231ecc0c5cSChao Yu 	if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) {
13241ecc0c5cSChao Yu 		atomic_set(&ffi->inject_ops, 0);
13251ecc0c5cSChao Yu 		return true;
13261ecc0c5cSChao Yu 	}
13271ecc0c5cSChao Yu 	return false;
13281ecc0c5cSChao Yu }
13297fa750a1SArnd Bergmann #else
13307fa750a1SArnd Bergmann #define f2fs_show_injection_info(type) do { } while (0)
13317fa750a1SArnd Bergmann static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
13327fa750a1SArnd Bergmann {
13337fa750a1SArnd Bergmann 	return false;
13347fa750a1SArnd Bergmann }
13351ecc0c5cSChao Yu #endif
13361ecc0c5cSChao Yu 
13378f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes,
13388f1dbbbbSShuoran Liu  * and the return value is in kbytes. s is of struct f2fs_sb_info.
13398f1dbbbbSShuoran Liu  */
13408f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s)						 \
134168afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) -		 \
134268afcf2dSTomohiro Kusumi 		(s)->sectors_written_start) >> 1)
13438f1dbbbbSShuoran Liu 
13446beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
13456beceb54SJaegeuk Kim {
13466beceb54SJaegeuk Kim 	sbi->last_time[type] = jiffies;
13476beceb54SJaegeuk Kim }
13486beceb54SJaegeuk Kim 
13496beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type)
13506beceb54SJaegeuk Kim {
13516bccfa19SArnd Bergmann 	unsigned long interval = sbi->interval_time[type] * HZ;
13526beceb54SJaegeuk Kim 
13536beceb54SJaegeuk Kim 	return time_after(jiffies, sbi->last_time[type] + interval);
13546beceb54SJaegeuk Kim }
13556beceb54SJaegeuk Kim 
1356d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi)
1357d0239e1bSJaegeuk Kim {
1358d0239e1bSJaegeuk Kim 	struct block_device *bdev = sbi->sb->s_bdev;
1359d0239e1bSJaegeuk Kim 	struct request_queue *q = bdev_get_queue(bdev);
1360d0239e1bSJaegeuk Kim 	struct request_list *rl = &q->root_rl;
1361d0239e1bSJaegeuk Kim 
1362d0239e1bSJaegeuk Kim 	if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC])
13636e45f2a5SGustavo A. R. Silva 		return false;
1364d0239e1bSJaegeuk Kim 
1365d0239e1bSJaegeuk Kim 	return f2fs_time_over(sbi, REQ_TIME);
1366d0239e1bSJaegeuk Kim }
1367d0239e1bSJaegeuk Kim 
136839a53e0cSJaegeuk Kim /*
136939a53e0cSJaegeuk Kim  * Inline functions
137039a53e0cSJaegeuk Kim  */
1371416d2dbbSChao Yu static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc,
1372704956ecSChao Yu 			      const void *address, unsigned int length)
1373704956ecSChao Yu {
1374704956ecSChao Yu 	struct {
1375704956ecSChao Yu 		struct shash_desc shash;
1376704956ecSChao Yu 		char ctx[4];
1377704956ecSChao Yu 	} desc;
1378704956ecSChao Yu 	int err;
1379704956ecSChao Yu 
1380704956ecSChao Yu 	BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx));
1381704956ecSChao Yu 
1382704956ecSChao Yu 	desc.shash.tfm = sbi->s_chksum_driver;
1383704956ecSChao Yu 	desc.shash.flags = 0;
1384704956ecSChao Yu 	*(u32 *)desc.ctx = crc;
1385704956ecSChao Yu 
1386704956ecSChao Yu 	err = crypto_shash_update(&desc.shash, address, length);
1387704956ecSChao Yu 	BUG_ON(err);
1388704956ecSChao Yu 
1389704956ecSChao Yu 	return *(u32 *)desc.ctx;
1390704956ecSChao Yu }
1391704956ecSChao Yu 
1392416d2dbbSChao Yu static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
1393416d2dbbSChao Yu 			   unsigned int length)
1394416d2dbbSChao Yu {
1395416d2dbbSChao Yu 	return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length);
1396416d2dbbSChao Yu }
1397416d2dbbSChao Yu 
1398416d2dbbSChao Yu static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
1399416d2dbbSChao Yu 				  void *buf, size_t buf_size)
1400416d2dbbSChao Yu {
1401416d2dbbSChao Yu 	return f2fs_crc32(sbi, buf, buf_size) == blk_crc;
1402416d2dbbSChao Yu }
1403416d2dbbSChao Yu 
1404416d2dbbSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc,
1405416d2dbbSChao Yu 			      const void *address, unsigned int length)
1406416d2dbbSChao Yu {
1407416d2dbbSChao Yu 	return __f2fs_crc32(sbi, crc, address, length);
1408416d2dbbSChao Yu }
1409416d2dbbSChao Yu 
141039a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
141139a53e0cSJaegeuk Kim {
141239a53e0cSJaegeuk Kim 	return container_of(inode, struct f2fs_inode_info, vfs_inode);
141339a53e0cSJaegeuk Kim }
141439a53e0cSJaegeuk Kim 
141539a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
141639a53e0cSJaegeuk Kim {
141739a53e0cSJaegeuk Kim 	return sb->s_fs_info;
141839a53e0cSJaegeuk Kim }
141939a53e0cSJaegeuk Kim 
14204081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
14214081363fSJaegeuk Kim {
14224081363fSJaegeuk Kim 	return F2FS_SB(inode->i_sb);
14234081363fSJaegeuk Kim }
14244081363fSJaegeuk Kim 
14254081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
14264081363fSJaegeuk Kim {
14274081363fSJaegeuk Kim 	return F2FS_I_SB(mapping->host);
14284081363fSJaegeuk Kim }
14294081363fSJaegeuk Kim 
14304081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
14314081363fSJaegeuk Kim {
14324081363fSJaegeuk Kim 	return F2FS_M_SB(page->mapping);
14334081363fSJaegeuk Kim }
14344081363fSJaegeuk Kim 
143539a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
143639a53e0cSJaegeuk Kim {
143739a53e0cSJaegeuk Kim 	return (struct f2fs_super_block *)(sbi->raw_super);
143839a53e0cSJaegeuk Kim }
143939a53e0cSJaegeuk Kim 
144039a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
144139a53e0cSJaegeuk Kim {
144239a53e0cSJaegeuk Kim 	return (struct f2fs_checkpoint *)(sbi->ckpt);
144339a53e0cSJaegeuk Kim }
144439a53e0cSJaegeuk Kim 
144545590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page)
144645590710SGu Zheng {
144745590710SGu Zheng 	return (struct f2fs_node *)page_address(page);
144845590710SGu Zheng }
144945590710SGu Zheng 
145058bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page)
145158bfaf44SJaegeuk Kim {
145258bfaf44SJaegeuk Kim 	return &((struct f2fs_node *)page_address(page))->i;
145358bfaf44SJaegeuk Kim }
145458bfaf44SJaegeuk Kim 
145539a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
145639a53e0cSJaegeuk Kim {
145739a53e0cSJaegeuk Kim 	return (struct f2fs_nm_info *)(sbi->nm_info);
145839a53e0cSJaegeuk Kim }
145939a53e0cSJaegeuk Kim 
146039a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
146139a53e0cSJaegeuk Kim {
146239a53e0cSJaegeuk Kim 	return (struct f2fs_sm_info *)(sbi->sm_info);
146339a53e0cSJaegeuk Kim }
146439a53e0cSJaegeuk Kim 
146539a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
146639a53e0cSJaegeuk Kim {
146739a53e0cSJaegeuk Kim 	return (struct sit_info *)(SM_I(sbi)->sit_info);
146839a53e0cSJaegeuk Kim }
146939a53e0cSJaegeuk Kim 
147039a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
147139a53e0cSJaegeuk Kim {
147239a53e0cSJaegeuk Kim 	return (struct free_segmap_info *)(SM_I(sbi)->free_info);
147339a53e0cSJaegeuk Kim }
147439a53e0cSJaegeuk Kim 
147539a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
147639a53e0cSJaegeuk Kim {
147739a53e0cSJaegeuk Kim 	return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
147839a53e0cSJaegeuk Kim }
147939a53e0cSJaegeuk Kim 
14809df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
14819df27d98SGu Zheng {
14829df27d98SGu Zheng 	return sbi->meta_inode->i_mapping;
14839df27d98SGu Zheng }
14849df27d98SGu Zheng 
14854ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
14864ef51a8fSJaegeuk Kim {
14874ef51a8fSJaegeuk Kim 	return sbi->node_inode->i_mapping;
14884ef51a8fSJaegeuk Kim }
14894ef51a8fSJaegeuk Kim 
1490caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
149139a53e0cSJaegeuk Kim {
1492fadb2fb8SChao Yu 	return test_bit(type, &sbi->s_flag);
149339a53e0cSJaegeuk Kim }
149439a53e0cSJaegeuk Kim 
1495caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
149639a53e0cSJaegeuk Kim {
1497fadb2fb8SChao Yu 	set_bit(type, &sbi->s_flag);
1498caf0047eSChao Yu }
1499caf0047eSChao Yu 
1500caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
1501caf0047eSChao Yu {
1502fadb2fb8SChao Yu 	clear_bit(type, &sbi->s_flag);
150339a53e0cSJaegeuk Kim }
150439a53e0cSJaegeuk Kim 
1505d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
1506d71b5564SJaegeuk Kim {
1507d71b5564SJaegeuk Kim 	return le64_to_cpu(cp->checkpoint_ver);
1508d71b5564SJaegeuk Kim }
1509d71b5564SJaegeuk Kim 
1510ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type)
1511ea676733SJaegeuk Kim {
1512ea676733SJaegeuk Kim 	if (type < F2FS_MAX_QUOTAS)
1513ea676733SJaegeuk Kim 		return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]);
1514ea676733SJaegeuk Kim 	return 0;
1515ea676733SJaegeuk Kim }
1516ea676733SJaegeuk Kim 
1517ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp)
1518ced2c7eaSKinglong Mee {
1519ced2c7eaSKinglong Mee 	size_t crc_offset = le32_to_cpu(cp->checksum_offset);
1520ced2c7eaSKinglong Mee 	return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset)));
1521ced2c7eaSKinglong Mee }
1522ced2c7eaSKinglong Mee 
1523aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
152425ca923bSJaegeuk Kim {
152525ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
1526aaec2b1dSChao Yu 
152725ca923bSJaegeuk Kim 	return ckpt_flags & f;
152825ca923bSJaegeuk Kim }
152925ca923bSJaegeuk Kim 
1530aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
153125ca923bSJaegeuk Kim {
1532aaec2b1dSChao Yu 	return __is_set_ckpt_flags(F2FS_CKPT(sbi), f);
1533aaec2b1dSChao Yu }
1534aaec2b1dSChao Yu 
1535aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1536aaec2b1dSChao Yu {
1537aaec2b1dSChao Yu 	unsigned int ckpt_flags;
1538aaec2b1dSChao Yu 
1539aaec2b1dSChao Yu 	ckpt_flags = le32_to_cpu(cp->ckpt_flags);
154025ca923bSJaegeuk Kim 	ckpt_flags |= f;
154125ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
154225ca923bSJaegeuk Kim }
154325ca923bSJaegeuk Kim 
1544aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
154525ca923bSJaegeuk Kim {
1546d1aa2453SChao Yu 	unsigned long flags;
1547d1aa2453SChao Yu 
1548d1aa2453SChao Yu 	spin_lock_irqsave(&sbi->cp_lock, flags);
1549aaec2b1dSChao Yu 	__set_ckpt_flags(F2FS_CKPT(sbi), f);
1550d1aa2453SChao Yu 	spin_unlock_irqrestore(&sbi->cp_lock, flags);
1551aaec2b1dSChao Yu }
1552aaec2b1dSChao Yu 
1553aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1554aaec2b1dSChao Yu {
1555aaec2b1dSChao Yu 	unsigned int ckpt_flags;
1556aaec2b1dSChao Yu 
1557aaec2b1dSChao Yu 	ckpt_flags = le32_to_cpu(cp->ckpt_flags);
155825ca923bSJaegeuk Kim 	ckpt_flags &= (~f);
155925ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
156025ca923bSJaegeuk Kim }
156125ca923bSJaegeuk Kim 
1562aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
1563aaec2b1dSChao Yu {
1564d1aa2453SChao Yu 	unsigned long flags;
1565d1aa2453SChao Yu 
1566d1aa2453SChao Yu 	spin_lock_irqsave(&sbi->cp_lock, flags);
1567aaec2b1dSChao Yu 	__clear_ckpt_flags(F2FS_CKPT(sbi), f);
1568d1aa2453SChao Yu 	spin_unlock_irqrestore(&sbi->cp_lock, flags);
1569aaec2b1dSChao Yu }
1570aaec2b1dSChao Yu 
157122ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock)
157222ad0b6aSJaegeuk Kim {
1573d1aa2453SChao Yu 	unsigned long flags;
1574d1aa2453SChao Yu 
157522ad0b6aSJaegeuk Kim 	set_sbi_flag(sbi, SBI_NEED_FSCK);
157622ad0b6aSJaegeuk Kim 
157722ad0b6aSJaegeuk Kim 	if (lock)
1578d1aa2453SChao Yu 		spin_lock_irqsave(&sbi->cp_lock, flags);
157922ad0b6aSJaegeuk Kim 	__clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG);
158022ad0b6aSJaegeuk Kim 	kfree(NM_I(sbi)->nat_bits);
158122ad0b6aSJaegeuk Kim 	NM_I(sbi)->nat_bits = NULL;
158222ad0b6aSJaegeuk Kim 	if (lock)
1583d1aa2453SChao Yu 		spin_unlock_irqrestore(&sbi->cp_lock, flags);
158422ad0b6aSJaegeuk Kim }
158522ad0b6aSJaegeuk Kim 
158622ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
158722ad0b6aSJaegeuk Kim 					struct cp_control *cpc)
158822ad0b6aSJaegeuk Kim {
158922ad0b6aSJaegeuk Kim 	bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG);
159022ad0b6aSJaegeuk Kim 
1591c473f1a9SChao Yu 	return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set;
159222ad0b6aSJaegeuk Kim }
159322ad0b6aSJaegeuk Kim 
1594e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
159539a53e0cSJaegeuk Kim {
1596b873b798SJaegeuk Kim 	down_read(&sbi->cp_rwsem);
159739a53e0cSJaegeuk Kim }
159839a53e0cSJaegeuk Kim 
1599cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi)
1600cc15620bSJaegeuk Kim {
1601cc15620bSJaegeuk Kim 	return down_read_trylock(&sbi->cp_rwsem);
1602cc15620bSJaegeuk Kim }
1603cc15620bSJaegeuk Kim 
1604e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
160539a53e0cSJaegeuk Kim {
1606b873b798SJaegeuk Kim 	up_read(&sbi->cp_rwsem);
160739936837SJaegeuk Kim }
160839936837SJaegeuk Kim 
1609e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
161039936837SJaegeuk Kim {
1611b873b798SJaegeuk Kim 	down_write(&sbi->cp_rwsem);
161239936837SJaegeuk Kim }
161339936837SJaegeuk Kim 
1614e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
161539936837SJaegeuk Kim {
1616b873b798SJaegeuk Kim 	up_write(&sbi->cp_rwsem);
161739a53e0cSJaegeuk Kim }
161839a53e0cSJaegeuk Kim 
1619119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
1620119ee914SJaegeuk Kim {
1621119ee914SJaegeuk Kim 	int reason = CP_SYNC;
1622119ee914SJaegeuk Kim 
1623119ee914SJaegeuk Kim 	if (test_opt(sbi, FASTBOOT))
1624119ee914SJaegeuk Kim 		reason = CP_FASTBOOT;
1625119ee914SJaegeuk Kim 	if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
1626119ee914SJaegeuk Kim 		reason = CP_UMOUNT;
1627119ee914SJaegeuk Kim 	return reason;
1628119ee914SJaegeuk Kim }
1629119ee914SJaegeuk Kim 
1630119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason)
1631119ee914SJaegeuk Kim {
1632c473f1a9SChao Yu 	return (reason & (CP_UMOUNT | CP_FASTBOOT));
1633119ee914SJaegeuk Kim }
1634119ee914SJaegeuk Kim 
1635119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
1636119ee914SJaegeuk Kim {
1637aaec2b1dSChao Yu 	return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) ||
1638aaec2b1dSChao Yu 			is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG));
1639119ee914SJaegeuk Kim }
1640119ee914SJaegeuk Kim 
164139a53e0cSJaegeuk Kim /*
164239a53e0cSJaegeuk Kim  * Check whether the inode has blocks or not
164339a53e0cSJaegeuk Kim  */
164439a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode)
164539a53e0cSJaegeuk Kim {
16460eb0adadSChao Yu 	block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0;
16470eb0adadSChao Yu 
1648000519f2SChao Yu 	return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block;
164939a53e0cSJaegeuk Kim }
165039a53e0cSJaegeuk Kim 
16514bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs)
16524bc8e9bcSChao Yu {
16534bc8e9bcSChao Yu 	return ofs == XATTR_NODE_OFFSET;
16544bc8e9bcSChao Yu }
16554bc8e9bcSChao Yu 
1656d8a9a229SJaegeuk Kim static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi,
1657a90a0884SJaegeuk Kim 					struct inode *inode, bool cap)
16587c2e5963SJaegeuk Kim {
1659d8a9a229SJaegeuk Kim 	if (!inode)
1660d8a9a229SJaegeuk Kim 		return true;
16617c2e5963SJaegeuk Kim 	if (!test_opt(sbi, RESERVE_ROOT))
16627c2e5963SJaegeuk Kim 		return false;
1663d8a9a229SJaegeuk Kim 	if (IS_NOQUOTA(inode))
1664d8a9a229SJaegeuk Kim 		return true;
166563189b78SChao Yu 	if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid()))
16667c2e5963SJaegeuk Kim 		return true;
166763189b78SChao Yu 	if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) &&
166863189b78SChao Yu 					in_group_p(F2FS_OPTION(sbi).s_resgid))
16697c2e5963SJaegeuk Kim 		return true;
1670a90a0884SJaegeuk Kim 	if (cap && capable(CAP_SYS_RESOURCE))
1671162b27aeSJaegeuk Kim 		return true;
16727c2e5963SJaegeuk Kim 	return false;
16737c2e5963SJaegeuk Kim }
16747c2e5963SJaegeuk Kim 
16750abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool);
16760abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
167746008c6dSChao Yu 				 struct inode *inode, blkcnt_t *count)
167839a53e0cSJaegeuk Kim {
16790abd675eSChao Yu 	blkcnt_t diff = 0, release = 0;
1680daeb433eSChao Yu 	block_t avail_user_block_count;
16810abd675eSChao Yu 	int ret;
16820abd675eSChao Yu 
16830abd675eSChao Yu 	ret = dquot_reserve_block(inode, *count);
16840abd675eSChao Yu 	if (ret)
16850abd675eSChao Yu 		return ret;
1686dd11a5dfSJaegeuk Kim 
168755523519SChao Yu 	if (time_to_inject(sbi, FAULT_BLOCK)) {
168855523519SChao Yu 		f2fs_show_injection_info(FAULT_BLOCK);
16890abd675eSChao Yu 		release = *count;
16900abd675eSChao Yu 		goto enospc;
169155523519SChao Yu 	}
16927fa750a1SArnd Bergmann 
1693dd11a5dfSJaegeuk Kim 	/*
1694dd11a5dfSJaegeuk Kim 	 * let's increase this in prior to actual block count change in order
1695dd11a5dfSJaegeuk Kim 	 * for f2fs_sync_file to avoid data races when deciding checkpoint.
1696dd11a5dfSJaegeuk Kim 	 */
1697dd11a5dfSJaegeuk Kim 	percpu_counter_add(&sbi->alloc_valid_block_count, (*count));
169839a53e0cSJaegeuk Kim 
169939a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
17002555a2d5SJaegeuk Kim 	sbi->total_valid_block_count += (block_t)(*count);
170180d42145SYunlong Song 	avail_user_block_count = sbi->user_block_count -
170280d42145SYunlong Song 					sbi->current_reserved_blocks;
17037e65be49SJaegeuk Kim 
1704a90a0884SJaegeuk Kim 	if (!__allow_reserved_blocks(sbi, inode, true))
170563189b78SChao Yu 		avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks;
17067e65be49SJaegeuk Kim 
1707daeb433eSChao Yu 	if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
1708daeb433eSChao Yu 		diff = sbi->total_valid_block_count - avail_user_block_count;
17097e65be49SJaegeuk Kim 		if (diff > *count)
17107e65be49SJaegeuk Kim 			diff = *count;
1711dd11a5dfSJaegeuk Kim 		*count -= diff;
17120abd675eSChao Yu 		release = diff;
17137e65be49SJaegeuk Kim 		sbi->total_valid_block_count -= diff;
171446008c6dSChao Yu 		if (!*count) {
171539a53e0cSJaegeuk Kim 			spin_unlock(&sbi->stat_lock);
17160abd675eSChao Yu 			goto enospc;
171739a53e0cSJaegeuk Kim 		}
171846008c6dSChao Yu 	}
171939a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
172041382ec4SJaegeuk Kim 
172136b877afSDaniel Rosenberg 	if (unlikely(release)) {
172236b877afSDaniel Rosenberg 		percpu_counter_sub(&sbi->alloc_valid_block_count, release);
17230abd675eSChao Yu 		dquot_release_reservation_block(inode, release);
172436b877afSDaniel Rosenberg 	}
17250abd675eSChao Yu 	f2fs_i_blocks_write(inode, *count, true, true);
17260abd675eSChao Yu 	return 0;
17270abd675eSChao Yu 
17280abd675eSChao Yu enospc:
172936b877afSDaniel Rosenberg 	percpu_counter_sub(&sbi->alloc_valid_block_count, release);
17300abd675eSChao Yu 	dquot_release_reservation_block(inode, release);
17310abd675eSChao Yu 	return -ENOSPC;
173239a53e0cSJaegeuk Kim }
173339a53e0cSJaegeuk Kim 
1734da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
173539a53e0cSJaegeuk Kim 						struct inode *inode,
17360eb0adadSChao Yu 						block_t count)
173739a53e0cSJaegeuk Kim {
17380eb0adadSChao Yu 	blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK;
17390eb0adadSChao Yu 
174039a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
17419850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
17420eb0adadSChao Yu 	f2fs_bug_on(sbi, inode->i_blocks < sectors);
174339a53e0cSJaegeuk Kim 	sbi->total_valid_block_count -= (block_t)count;
174480d42145SYunlong Song 	if (sbi->reserved_blocks &&
174580d42145SYunlong Song 		sbi->current_reserved_blocks < sbi->reserved_blocks)
174680d42145SYunlong Song 		sbi->current_reserved_blocks = min(sbi->reserved_blocks,
174780d42145SYunlong Song 					sbi->current_reserved_blocks + count);
174839a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
17490abd675eSChao Yu 	f2fs_i_blocks_write(inode, count, false, true);
175039a53e0cSJaegeuk Kim }
175139a53e0cSJaegeuk Kim 
175239a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
175339a53e0cSJaegeuk Kim {
175435782b23SJaegeuk Kim 	atomic_inc(&sbi->nr_pages[count_type]);
17557c4abcbeSChao Yu 
175636951b38SChao Yu 	if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES ||
175736951b38SChao Yu 		count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA)
17587c4abcbeSChao Yu 		return;
17597c4abcbeSChao Yu 
1760caf0047eSChao Yu 	set_sbi_flag(sbi, SBI_IS_DIRTY);
176139a53e0cSJaegeuk Kim }
176239a53e0cSJaegeuk Kim 
1763a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode)
176439a53e0cSJaegeuk Kim {
1765204706c7SJaegeuk Kim 	atomic_inc(&F2FS_I(inode)->dirty_pages);
1766c227f912SChao Yu 	inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1767c227f912SChao Yu 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
17682c8a4a28SJaegeuk Kim 	if (IS_NOQUOTA(inode))
17692c8a4a28SJaegeuk Kim 		inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
177039a53e0cSJaegeuk Kim }
177139a53e0cSJaegeuk Kim 
177239a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
177339a53e0cSJaegeuk Kim {
177435782b23SJaegeuk Kim 	atomic_dec(&sbi->nr_pages[count_type]);
177539a53e0cSJaegeuk Kim }
177639a53e0cSJaegeuk Kim 
1777a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode)
177839a53e0cSJaegeuk Kim {
17795ac9f36fSChao Yu 	if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
17805ac9f36fSChao Yu 			!S_ISLNK(inode->i_mode))
17811fe54f9dSJaegeuk Kim 		return;
17821fe54f9dSJaegeuk Kim 
1783204706c7SJaegeuk Kim 	atomic_dec(&F2FS_I(inode)->dirty_pages);
1784c227f912SChao Yu 	dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1785c227f912SChao Yu 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
17862c8a4a28SJaegeuk Kim 	if (IS_NOQUOTA(inode))
17872c8a4a28SJaegeuk Kim 		dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
178839a53e0cSJaegeuk Kim }
178939a53e0cSJaegeuk Kim 
1790523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type)
179139a53e0cSJaegeuk Kim {
179235782b23SJaegeuk Kim 	return atomic_read(&sbi->nr_pages[count_type]);
179339a53e0cSJaegeuk Kim }
179439a53e0cSJaegeuk Kim 
1795204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode)
1796f8b2c1f9SJaegeuk Kim {
1797204706c7SJaegeuk Kim 	return atomic_read(&F2FS_I(inode)->dirty_pages);
1798f8b2c1f9SJaegeuk Kim }
1799f8b2c1f9SJaegeuk Kim 
18005ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
18015ac206cfSNamjae Jeon {
18023519e3f9SChao Yu 	unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg;
1803523be8a6SJaegeuk Kim 	unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >>
1804523be8a6SJaegeuk Kim 						sbi->log_blocks_per_seg;
1805523be8a6SJaegeuk Kim 
1806523be8a6SJaegeuk Kim 	return segs / sbi->segs_per_sec;
18075ac206cfSNamjae Jeon }
18085ac206cfSNamjae Jeon 
180939a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
181039a53e0cSJaegeuk Kim {
18118b8343faSJaegeuk Kim 	return sbi->total_valid_block_count;
181239a53e0cSJaegeuk Kim }
181339a53e0cSJaegeuk Kim 
1814f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi)
1815f83a2584SYunlei He {
1816f83a2584SYunlei He 	return sbi->discard_blks;
1817f83a2584SYunlei He }
1818f83a2584SYunlei He 
181939a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
182039a53e0cSJaegeuk Kim {
182139a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
182239a53e0cSJaegeuk Kim 
182339a53e0cSJaegeuk Kim 	/* return NAT or SIT bitmap */
182439a53e0cSJaegeuk Kim 	if (flag == NAT_BITMAP)
182539a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
182639a53e0cSJaegeuk Kim 	else if (flag == SIT_BITMAP)
182739a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
182839a53e0cSJaegeuk Kim 
182939a53e0cSJaegeuk Kim 	return 0;
183039a53e0cSJaegeuk Kim }
183139a53e0cSJaegeuk Kim 
183255141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
183355141486SWanpeng Li {
183455141486SWanpeng Li 	return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
183555141486SWanpeng Li }
183655141486SWanpeng Li 
183739a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
183839a53e0cSJaegeuk Kim {
183939a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
18401dbe4152SChangman Lee 	int offset;
18411dbe4152SChangman Lee 
1842199bc3feSChao Yu 	if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) {
1843199bc3feSChao Yu 		offset = (flag == SIT_BITMAP) ?
1844199bc3feSChao Yu 			le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0;
1845199bc3feSChao Yu 		return &ckpt->sit_nat_version_bitmap + offset;
1846199bc3feSChao Yu 	}
1847199bc3feSChao Yu 
184855141486SWanpeng Li 	if (__cp_payload(sbi) > 0) {
18491dbe4152SChangman Lee 		if (flag == NAT_BITMAP)
18501dbe4152SChangman Lee 			return &ckpt->sit_nat_version_bitmap;
18511dbe4152SChangman Lee 		else
185265b85cccSJaegeuk Kim 			return (unsigned char *)ckpt + F2FS_BLKSIZE;
18531dbe4152SChangman Lee 	} else {
18541dbe4152SChangman Lee 		offset = (flag == NAT_BITMAP) ?
185525ca923bSJaegeuk Kim 			le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
185639a53e0cSJaegeuk Kim 		return &ckpt->sit_nat_version_bitmap + offset;
185739a53e0cSJaegeuk Kim 	}
18581dbe4152SChangman Lee }
185939a53e0cSJaegeuk Kim 
186039a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
186139a53e0cSJaegeuk Kim {
18628508e44aSJaegeuk Kim 	block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
186339a53e0cSJaegeuk Kim 
18648508e44aSJaegeuk Kim 	if (sbi->cur_cp_pack == 2)
186539a53e0cSJaegeuk Kim 		start_addr += sbi->blocks_per_seg;
186639a53e0cSJaegeuk Kim 	return start_addr;
186739a53e0cSJaegeuk Kim }
186839a53e0cSJaegeuk Kim 
18698508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi)
18708508e44aSJaegeuk Kim {
18718508e44aSJaegeuk Kim 	block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
18728508e44aSJaegeuk Kim 
18738508e44aSJaegeuk Kim 	if (sbi->cur_cp_pack == 1)
18748508e44aSJaegeuk Kim 		start_addr += sbi->blocks_per_seg;
18758508e44aSJaegeuk Kim 	return start_addr;
18768508e44aSJaegeuk Kim }
18778508e44aSJaegeuk Kim 
18788508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi)
18798508e44aSJaegeuk Kim {
18808508e44aSJaegeuk Kim 	sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1;
18818508e44aSJaegeuk Kim }
18828508e44aSJaegeuk Kim 
188339a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
188439a53e0cSJaegeuk Kim {
188539a53e0cSJaegeuk Kim 	return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
188639a53e0cSJaegeuk Kim }
188739a53e0cSJaegeuk Kim 
18880abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
1889000519f2SChao Yu 					struct inode *inode, bool is_inode)
189039a53e0cSJaegeuk Kim {
189139a53e0cSJaegeuk Kim 	block_t	valid_block_count;
189239a53e0cSJaegeuk Kim 	unsigned int valid_node_count;
18930abd675eSChao Yu 	bool quota = inode && !is_inode;
18940abd675eSChao Yu 
18950abd675eSChao Yu 	if (quota) {
18960abd675eSChao Yu 		int ret = dquot_reserve_block(inode, 1);
18970abd675eSChao Yu 		if (ret)
18980abd675eSChao Yu 			return ret;
18990abd675eSChao Yu 	}
190039a53e0cSJaegeuk Kim 
1901812c6056SChao Yu 	if (time_to_inject(sbi, FAULT_BLOCK)) {
1902812c6056SChao Yu 		f2fs_show_injection_info(FAULT_BLOCK);
1903812c6056SChao Yu 		goto enospc;
1904812c6056SChao Yu 	}
1905812c6056SChao Yu 
190639a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
190739a53e0cSJaegeuk Kim 
19087e65be49SJaegeuk Kim 	valid_block_count = sbi->total_valid_block_count +
19097e65be49SJaegeuk Kim 					sbi->current_reserved_blocks + 1;
19107e65be49SJaegeuk Kim 
1911a90a0884SJaegeuk Kim 	if (!__allow_reserved_blocks(sbi, inode, false))
191263189b78SChao Yu 		valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks;
19137e65be49SJaegeuk Kim 
19147e65be49SJaegeuk Kim 	if (unlikely(valid_block_count > sbi->user_block_count)) {
191539a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
19160abd675eSChao Yu 		goto enospc;
191739a53e0cSJaegeuk Kim 	}
191839a53e0cSJaegeuk Kim 
1919ef86d709SGu Zheng 	valid_node_count = sbi->total_valid_node_count + 1;
1920cfb271d4SChao Yu 	if (unlikely(valid_node_count > sbi->total_node_count)) {
192139a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
19220abd675eSChao Yu 		goto enospc;
192339a53e0cSJaegeuk Kim 	}
192439a53e0cSJaegeuk Kim 
1925ef86d709SGu Zheng 	sbi->total_valid_node_count++;
1926ef86d709SGu Zheng 	sbi->total_valid_block_count++;
192739a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
192839a53e0cSJaegeuk Kim 
19290abd675eSChao Yu 	if (inode) {
19300abd675eSChao Yu 		if (is_inode)
19310abd675eSChao Yu 			f2fs_mark_inode_dirty_sync(inode, true);
19320abd675eSChao Yu 		else
19330abd675eSChao Yu 			f2fs_i_blocks_write(inode, 1, true, true);
19340abd675eSChao Yu 	}
19350abd675eSChao Yu 
193641382ec4SJaegeuk Kim 	percpu_counter_inc(&sbi->alloc_valid_block_count);
19370abd675eSChao Yu 	return 0;
19380abd675eSChao Yu 
19390abd675eSChao Yu enospc:
19400abd675eSChao Yu 	if (quota)
19410abd675eSChao Yu 		dquot_release_reservation_block(inode, 1);
19420abd675eSChao Yu 	return -ENOSPC;
194339a53e0cSJaegeuk Kim }
194439a53e0cSJaegeuk Kim 
194539a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
1946000519f2SChao Yu 					struct inode *inode, bool is_inode)
194739a53e0cSJaegeuk Kim {
194839a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
194939a53e0cSJaegeuk Kim 
19509850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_block_count);
19519850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_node_count);
1952000519f2SChao Yu 	f2fs_bug_on(sbi, !is_inode && !inode->i_blocks);
195339a53e0cSJaegeuk Kim 
1954ef86d709SGu Zheng 	sbi->total_valid_node_count--;
1955ef86d709SGu Zheng 	sbi->total_valid_block_count--;
195680d42145SYunlong Song 	if (sbi->reserved_blocks &&
195780d42145SYunlong Song 		sbi->current_reserved_blocks < sbi->reserved_blocks)
195880d42145SYunlong Song 		sbi->current_reserved_blocks++;
195939a53e0cSJaegeuk Kim 
196039a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
19610abd675eSChao Yu 
19620abd675eSChao Yu 	if (!is_inode)
19630abd675eSChao Yu 		f2fs_i_blocks_write(inode, 1, false, true);
196439a53e0cSJaegeuk Kim }
196539a53e0cSJaegeuk Kim 
196639a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
196739a53e0cSJaegeuk Kim {
19688b8343faSJaegeuk Kim 	return sbi->total_valid_node_count;
196939a53e0cSJaegeuk Kim }
197039a53e0cSJaegeuk Kim 
197139a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
197239a53e0cSJaegeuk Kim {
1973513c5f37SJaegeuk Kim 	percpu_counter_inc(&sbi->total_valid_inode_count);
197439a53e0cSJaegeuk Kim }
197539a53e0cSJaegeuk Kim 
19760e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
197739a53e0cSJaegeuk Kim {
1978513c5f37SJaegeuk Kim 	percpu_counter_dec(&sbi->total_valid_inode_count);
197939a53e0cSJaegeuk Kim }
198039a53e0cSJaegeuk Kim 
1981513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi)
198239a53e0cSJaegeuk Kim {
1983513c5f37SJaegeuk Kim 	return percpu_counter_sum_positive(&sbi->total_valid_inode_count);
198439a53e0cSJaegeuk Kim }
198539a53e0cSJaegeuk Kim 
1986a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
1987a56c7c6fSJaegeuk Kim 						pgoff_t index, bool for_write)
1988a56c7c6fSJaegeuk Kim {
198982cf4f13SChao Yu 	struct page *page;
1990cac5a3d8SDongOh Shin 
19917fa750a1SArnd Bergmann 	if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) {
199282cf4f13SChao Yu 		if (!for_write)
199382cf4f13SChao Yu 			page = find_get_page_flags(mapping, index,
199482cf4f13SChao Yu 							FGP_LOCK | FGP_ACCESSED);
199582cf4f13SChao Yu 		else
199682cf4f13SChao Yu 			page = find_lock_page(mapping, index);
1997c41f3cc3SJaegeuk Kim 		if (page)
1998c41f3cc3SJaegeuk Kim 			return page;
1999c41f3cc3SJaegeuk Kim 
200055523519SChao Yu 		if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) {
200155523519SChao Yu 			f2fs_show_injection_info(FAULT_PAGE_ALLOC);
2002c41f3cc3SJaegeuk Kim 			return NULL;
200355523519SChao Yu 		}
20047fa750a1SArnd Bergmann 	}
20057fa750a1SArnd Bergmann 
2006a56c7c6fSJaegeuk Kim 	if (!for_write)
2007a56c7c6fSJaegeuk Kim 		return grab_cache_page(mapping, index);
2008a56c7c6fSJaegeuk Kim 	return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
2009a56c7c6fSJaegeuk Kim }
2010a56c7c6fSJaegeuk Kim 
201101eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page(
201201eccef7SChao Yu 				struct address_space *mapping, pgoff_t index,
201301eccef7SChao Yu 				int fgp_flags, gfp_t gfp_mask)
201401eccef7SChao Yu {
201501eccef7SChao Yu 	if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) {
201601eccef7SChao Yu 		f2fs_show_injection_info(FAULT_PAGE_GET);
201701eccef7SChao Yu 		return NULL;
201801eccef7SChao Yu 	}
20197fa750a1SArnd Bergmann 
202001eccef7SChao Yu 	return pagecache_get_page(mapping, index, fgp_flags, gfp_mask);
202101eccef7SChao Yu }
202201eccef7SChao Yu 
20236e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst)
20246e2c64adSJaegeuk Kim {
20256e2c64adSJaegeuk Kim 	char *src_kaddr = kmap(src);
20266e2c64adSJaegeuk Kim 	char *dst_kaddr = kmap(dst);
20276e2c64adSJaegeuk Kim 
20286e2c64adSJaegeuk Kim 	memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
20296e2c64adSJaegeuk Kim 	kunmap(dst);
20306e2c64adSJaegeuk Kim 	kunmap(src);
20316e2c64adSJaegeuk Kim }
20326e2c64adSJaegeuk Kim 
203339a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock)
203439a53e0cSJaegeuk Kim {
2035031fa8ccSJaegeuk Kim 	if (!page)
203639a53e0cSJaegeuk Kim 		return;
203739a53e0cSJaegeuk Kim 
203839a53e0cSJaegeuk Kim 	if (unlock) {
20399850cf4aSJaegeuk Kim 		f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
204039a53e0cSJaegeuk Kim 		unlock_page(page);
204139a53e0cSJaegeuk Kim 	}
204209cbfeafSKirill A. Shutemov 	put_page(page);
204339a53e0cSJaegeuk Kim }
204439a53e0cSJaegeuk Kim 
204539a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn)
204639a53e0cSJaegeuk Kim {
204739a53e0cSJaegeuk Kim 	if (dn->node_page)
204839a53e0cSJaegeuk Kim 		f2fs_put_page(dn->node_page, 1);
204939a53e0cSJaegeuk Kim 	if (dn->inode_page && dn->node_page != dn->inode_page)
205039a53e0cSJaegeuk Kim 		f2fs_put_page(dn->inode_page, 0);
205139a53e0cSJaegeuk Kim 	dn->node_page = NULL;
205239a53e0cSJaegeuk Kim 	dn->inode_page = NULL;
205339a53e0cSJaegeuk Kim }
205439a53e0cSJaegeuk Kim 
205539a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
2056e8512d2eSGu Zheng 					size_t size)
205739a53e0cSJaegeuk Kim {
2058e8512d2eSGu Zheng 	return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
205939a53e0cSJaegeuk Kim }
206039a53e0cSJaegeuk Kim 
20617bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
20627bd59381SGu Zheng 						gfp_t flags)
20637bd59381SGu Zheng {
20647bd59381SGu Zheng 	void *entry;
20657bd59381SGu Zheng 
206680c54505SJaegeuk Kim 	entry = kmem_cache_alloc(cachep, flags);
206780c54505SJaegeuk Kim 	if (!entry)
206880c54505SJaegeuk Kim 		entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
20697bd59381SGu Zheng 	return entry;
20707bd59381SGu Zheng }
20717bd59381SGu Zheng 
2072d62fe971SChao Yu static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi,
2073d62fe971SChao Yu 						int npages, bool no_fail)
2074740432f8SJaegeuk Kim {
2075740432f8SJaegeuk Kim 	struct bio *bio;
2076740432f8SJaegeuk Kim 
2077d62fe971SChao Yu 	if (no_fail) {
2078740432f8SJaegeuk Kim 		/* No failure on bio allocation */
2079740432f8SJaegeuk Kim 		bio = bio_alloc(GFP_NOIO, npages);
208080c54505SJaegeuk Kim 		if (!bio)
208180c54505SJaegeuk Kim 			bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
2082740432f8SJaegeuk Kim 		return bio;
2083740432f8SJaegeuk Kim 	}
2084d62fe971SChao Yu 	if (time_to_inject(sbi, FAULT_ALLOC_BIO)) {
2085d62fe971SChao Yu 		f2fs_show_injection_info(FAULT_ALLOC_BIO);
2086d62fe971SChao Yu 		return NULL;
2087d62fe971SChao Yu 	}
20887fa750a1SArnd Bergmann 
2089d62fe971SChao Yu 	return bio_alloc(GFP_KERNEL, npages);
2090d62fe971SChao Yu }
2091740432f8SJaegeuk Kim 
20929be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
20939be32d72SJaegeuk Kim 				unsigned long index, void *item)
20949be32d72SJaegeuk Kim {
20959be32d72SJaegeuk Kim 	while (radix_tree_insert(root, index, item))
20969be32d72SJaegeuk Kim 		cond_resched();
20979be32d72SJaegeuk Kim }
20989be32d72SJaegeuk Kim 
209939a53e0cSJaegeuk Kim #define RAW_IS_INODE(p)	((p)->footer.nid == (p)->footer.ino)
210039a53e0cSJaegeuk Kim 
210139a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page)
210239a53e0cSJaegeuk Kim {
210345590710SGu Zheng 	struct f2fs_node *p = F2FS_NODE(page);
2104cac5a3d8SDongOh Shin 
210539a53e0cSJaegeuk Kim 	return RAW_IS_INODE(p);
210639a53e0cSJaegeuk Kim }
210739a53e0cSJaegeuk Kim 
21087a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i)
21097a2af766SChao Yu {
21107a2af766SChao Yu 	return (i->i_inline & F2FS_EXTRA_ATTR) ?
21117a2af766SChao Yu 			(le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0;
21127a2af766SChao Yu }
21137a2af766SChao Yu 
211439a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
211539a53e0cSJaegeuk Kim {
211639a53e0cSJaegeuk Kim 	return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
211739a53e0cSJaegeuk Kim }
211839a53e0cSJaegeuk Kim 
21197a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode);
21207a2af766SChao Yu static inline block_t datablock_addr(struct inode *inode,
21217a2af766SChao Yu 			struct page *node_page, unsigned int offset)
212239a53e0cSJaegeuk Kim {
212339a53e0cSJaegeuk Kim 	struct f2fs_node *raw_node;
212439a53e0cSJaegeuk Kim 	__le32 *addr_array;
21257a2af766SChao Yu 	int base = 0;
21267a2af766SChao Yu 	bool is_inode = IS_INODE(node_page);
2127cac5a3d8SDongOh Shin 
212845590710SGu Zheng 	raw_node = F2FS_NODE(node_page);
21297a2af766SChao Yu 
21307a2af766SChao Yu 	/* from GC path only */
2131979f492fSLiFan 	if (is_inode) {
2132979f492fSLiFan 		if (!inode)
21337a2af766SChao Yu 			base = offset_in_addr(&raw_node->i);
2134979f492fSLiFan 		else if (f2fs_has_extra_attr(inode))
21357a2af766SChao Yu 			base = get_extra_isize(inode);
21367a2af766SChao Yu 	}
21377a2af766SChao Yu 
213839a53e0cSJaegeuk Kim 	addr_array = blkaddr_in_node(raw_node);
21397a2af766SChao Yu 	return le32_to_cpu(addr_array[base + offset]);
214039a53e0cSJaegeuk Kim }
214139a53e0cSJaegeuk Kim 
214239a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr)
214339a53e0cSJaegeuk Kim {
214439a53e0cSJaegeuk Kim 	int mask;
214539a53e0cSJaegeuk Kim 
214639a53e0cSJaegeuk Kim 	addr += (nr >> 3);
214739a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
214839a53e0cSJaegeuk Kim 	return mask & *addr;
214939a53e0cSJaegeuk Kim }
215039a53e0cSJaegeuk Kim 
2151a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr)
2152a66cdd98SJaegeuk Kim {
2153a66cdd98SJaegeuk Kim 	int mask;
2154a66cdd98SJaegeuk Kim 
2155a66cdd98SJaegeuk Kim 	addr += (nr >> 3);
2156a66cdd98SJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
2157a66cdd98SJaegeuk Kim 	*addr |= mask;
2158a66cdd98SJaegeuk Kim }
2159a66cdd98SJaegeuk Kim 
2160a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr)
2161a66cdd98SJaegeuk Kim {
2162a66cdd98SJaegeuk Kim 	int mask;
2163a66cdd98SJaegeuk Kim 
2164a66cdd98SJaegeuk Kim 	addr += (nr >> 3);
2165a66cdd98SJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
2166a66cdd98SJaegeuk Kim 	*addr &= ~mask;
2167a66cdd98SJaegeuk Kim }
2168a66cdd98SJaegeuk Kim 
216952aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
217039a53e0cSJaegeuk Kim {
217139a53e0cSJaegeuk Kim 	int mask;
217239a53e0cSJaegeuk Kim 	int ret;
217339a53e0cSJaegeuk Kim 
217439a53e0cSJaegeuk Kim 	addr += (nr >> 3);
217539a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
217639a53e0cSJaegeuk Kim 	ret = mask & *addr;
217739a53e0cSJaegeuk Kim 	*addr |= mask;
217839a53e0cSJaegeuk Kim 	return ret;
217939a53e0cSJaegeuk Kim }
218039a53e0cSJaegeuk Kim 
218152aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
218239a53e0cSJaegeuk Kim {
218339a53e0cSJaegeuk Kim 	int mask;
218439a53e0cSJaegeuk Kim 	int ret;
218539a53e0cSJaegeuk Kim 
218639a53e0cSJaegeuk Kim 	addr += (nr >> 3);
218739a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
218839a53e0cSJaegeuk Kim 	ret = mask & *addr;
218939a53e0cSJaegeuk Kim 	*addr &= ~mask;
219039a53e0cSJaegeuk Kim 	return ret;
219139a53e0cSJaegeuk Kim }
219239a53e0cSJaegeuk Kim 
2193c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr)
2194c6ac4c0eSGu Zheng {
2195c6ac4c0eSGu Zheng 	int mask;
2196c6ac4c0eSGu Zheng 
2197c6ac4c0eSGu Zheng 	addr += (nr >> 3);
2198c6ac4c0eSGu Zheng 	mask = 1 << (7 - (nr & 0x07));
2199c6ac4c0eSGu Zheng 	*addr ^= mask;
2200c6ac4c0eSGu Zheng }
2201c6ac4c0eSGu Zheng 
220259c84408SChao Yu /*
220359c84408SChao Yu  * Inode flags
220459c84408SChao Yu  */
220559c84408SChao Yu #define F2FS_SECRM_FL			0x00000001 /* Secure deletion */
220659c84408SChao Yu #define F2FS_UNRM_FL			0x00000002 /* Undelete */
220759c84408SChao Yu #define F2FS_COMPR_FL			0x00000004 /* Compress file */
220859c84408SChao Yu #define F2FS_SYNC_FL			0x00000008 /* Synchronous updates */
220959c84408SChao Yu #define F2FS_IMMUTABLE_FL		0x00000010 /* Immutable file */
221059c84408SChao Yu #define F2FS_APPEND_FL			0x00000020 /* writes to file may only append */
221159c84408SChao Yu #define F2FS_NODUMP_FL			0x00000040 /* do not dump file */
221259c84408SChao Yu #define F2FS_NOATIME_FL			0x00000080 /* do not update atime */
221359c84408SChao Yu /* Reserved for compression usage... */
221459c84408SChao Yu #define F2FS_DIRTY_FL			0x00000100
221559c84408SChao Yu #define F2FS_COMPRBLK_FL		0x00000200 /* One or more compressed clusters */
221659c84408SChao Yu #define F2FS_NOCOMPR_FL			0x00000400 /* Don't compress */
221759c84408SChao Yu #define F2FS_ENCRYPT_FL			0x00000800 /* encrypted file */
221859c84408SChao Yu /* End compression flags --- maybe not all used */
221959c84408SChao Yu #define F2FS_INDEX_FL			0x00001000 /* hash-indexed directory */
222059c84408SChao Yu #define F2FS_IMAGIC_FL			0x00002000 /* AFS directory */
222159c84408SChao Yu #define F2FS_JOURNAL_DATA_FL		0x00004000 /* file data should be journaled */
222259c84408SChao Yu #define F2FS_NOTAIL_FL			0x00008000 /* file tail should not be merged */
222359c84408SChao Yu #define F2FS_DIRSYNC_FL			0x00010000 /* dirsync behaviour (directories only) */
222459c84408SChao Yu #define F2FS_TOPDIR_FL			0x00020000 /* Top of directory hierarchies*/
222559c84408SChao Yu #define F2FS_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
222659c84408SChao Yu #define F2FS_EXTENTS_FL			0x00080000 /* Inode uses extents */
222759c84408SChao Yu #define F2FS_EA_INODE_FL	        0x00200000 /* Inode used for large EA */
222859c84408SChao Yu #define F2FS_EOFBLOCKS_FL		0x00400000 /* Blocks allocated beyond EOF */
222959c84408SChao Yu #define F2FS_INLINE_DATA_FL		0x10000000 /* Inode has inline data. */
223059c84408SChao Yu #define F2FS_PROJINHERIT_FL		0x20000000 /* Create with parents projid */
223159c84408SChao Yu #define F2FS_RESERVED_FL		0x80000000 /* reserved for ext4 lib */
223259c84408SChao Yu 
223359c84408SChao Yu #define F2FS_FL_USER_VISIBLE		0x304BDFFF /* User visible flags */
223459c84408SChao Yu #define F2FS_FL_USER_MODIFIABLE		0x204BC0FF /* User modifiable flags */
223559c84408SChao Yu 
223659c84408SChao Yu /* Flags we can manipulate with through F2FS_IOC_FSSETXATTR */
223759c84408SChao Yu #define F2FS_FL_XFLAG_VISIBLE		(F2FS_SYNC_FL | \
223859c84408SChao Yu 					 F2FS_IMMUTABLE_FL | \
223959c84408SChao Yu 					 F2FS_APPEND_FL | \
224059c84408SChao Yu 					 F2FS_NODUMP_FL | \
224159c84408SChao Yu 					 F2FS_NOATIME_FL | \
224259c84408SChao Yu 					 F2FS_PROJINHERIT_FL)
224359c84408SChao Yu 
224459c84408SChao Yu /* Flags that should be inherited by new inodes from their parent. */
224559c84408SChao Yu #define F2FS_FL_INHERITED (F2FS_SECRM_FL | F2FS_UNRM_FL | F2FS_COMPR_FL |\
224659c84408SChao Yu 			   F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL |\
224759c84408SChao Yu 			   F2FS_NOCOMPR_FL | F2FS_JOURNAL_DATA_FL |\
224859c84408SChao Yu 			   F2FS_NOTAIL_FL | F2FS_DIRSYNC_FL |\
224959c84408SChao Yu 			   F2FS_PROJINHERIT_FL)
225059c84408SChao Yu 
225159c84408SChao Yu /* Flags that are appropriate for regular files (all but dir-specific ones). */
225259c84408SChao Yu #define F2FS_REG_FLMASK		(~(F2FS_DIRSYNC_FL | F2FS_TOPDIR_FL))
225359c84408SChao Yu 
225459c84408SChao Yu /* Flags that are appropriate for non-directories/regular files. */
225559c84408SChao Yu #define F2FS_OTHER_FLMASK	(F2FS_NODUMP_FL | F2FS_NOATIME_FL)
22565c57132eSChao Yu 
22575c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags)
22585c57132eSChao Yu {
22595c57132eSChao Yu 	if (S_ISDIR(mode))
22605c57132eSChao Yu 		return flags;
22615c57132eSChao Yu 	else if (S_ISREG(mode))
22625c57132eSChao Yu 		return flags & F2FS_REG_FLMASK;
22635c57132eSChao Yu 	else
22645c57132eSChao Yu 		return flags & F2FS_OTHER_FLMASK;
22655c57132eSChao Yu }
22665c57132eSChao Yu 
226739a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */
226839a53e0cSJaegeuk Kim enum {
226939a53e0cSJaegeuk Kim 	FI_NEW_INODE,		/* indicate newly allocated inode */
2270b3783873SJaegeuk Kim 	FI_DIRTY_INODE,		/* indicate inode is dirty or not */
227126de9b11SJaegeuk Kim 	FI_AUTO_RECOVER,	/* indicate inode is recoverable */
2272ed57c27fSJaegeuk Kim 	FI_DIRTY_DIR,		/* indicate directory has dirty pages */
227339a53e0cSJaegeuk Kim 	FI_INC_LINK,		/* need to increment i_nlink */
227439a53e0cSJaegeuk Kim 	FI_ACL_MODE,		/* indicate acl mode */
227539a53e0cSJaegeuk Kim 	FI_NO_ALLOC,		/* should not allocate any blocks */
2276c9b63bd0SJaegeuk Kim 	FI_FREE_NID,		/* free allocated nide */
2277c11abd1aSJaegeuk Kim 	FI_NO_EXTENT,		/* not to use the extent cache */
2278444c580fSJaegeuk Kim 	FI_INLINE_XATTR,	/* used for inline xattr */
22791001b347SHuajun Li 	FI_INLINE_DATA,		/* used for inline data*/
228034d67debSChao Yu 	FI_INLINE_DENTRY,	/* used for inline dentry */
2281fff04f90SJaegeuk Kim 	FI_APPEND_WRITE,	/* inode has appended data */
2282fff04f90SJaegeuk Kim 	FI_UPDATE_WRITE,	/* inode has in-place-update data */
228388b88a66SJaegeuk Kim 	FI_NEED_IPU,		/* used for ipu per file */
228488b88a66SJaegeuk Kim 	FI_ATOMIC_FILE,		/* indicate atomic file */
22855fe45743SChao Yu 	FI_ATOMIC_COMMIT,	/* indicate the state of atomical committing */
228602a1335fSJaegeuk Kim 	FI_VOLATILE_FILE,	/* indicate volatile file */
22873c6c2bebSJaegeuk Kim 	FI_FIRST_BLOCK_WRITTEN,	/* indicate #0 data block was written */
22881e84371fSJaegeuk Kim 	FI_DROP_CACHE,		/* drop dirty page cache */
2289b3d208f9SJaegeuk Kim 	FI_DATA_EXIST,		/* indicate data exists */
2290510022a8SJaegeuk Kim 	FI_INLINE_DOTS,		/* indicate inline dot dentries */
2291d323d005SChao Yu 	FI_DO_DEFRAG,		/* indicate defragment is running */
2292c227f912SChao Yu 	FI_DIRTY_FILE,		/* indicate regular/symlink has dirty pages */
2293dc91de78SJaegeuk Kim 	FI_NO_PREALLOC,		/* indicate skipped preallocated blocks */
2294ef095d19SJaegeuk Kim 	FI_HOT_DATA,		/* indicate file is hot */
22957a2af766SChao Yu 	FI_EXTRA_ATTR,		/* indicate file has extra attribute */
22965c57132eSChao Yu 	FI_PROJ_INHERIT,	/* indicate file inherits projectid */
22971ad71a27SJaegeuk Kim 	FI_PIN_FILE,		/* indicate file should not be gced */
22982ef79ecbSChao Yu 	FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */
229939a53e0cSJaegeuk Kim };
230039a53e0cSJaegeuk Kim 
2301205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode,
2302205b9822SJaegeuk Kim 						int flag, bool set)
230339a53e0cSJaegeuk Kim {
2304205b9822SJaegeuk Kim 	switch (flag) {
2305205b9822SJaegeuk Kim 	case FI_INLINE_XATTR:
2306205b9822SJaegeuk Kim 	case FI_INLINE_DATA:
2307205b9822SJaegeuk Kim 	case FI_INLINE_DENTRY:
23089ac1e2d8SDaeho Jeong 	case FI_NEW_INODE:
2309205b9822SJaegeuk Kim 		if (set)
2310205b9822SJaegeuk Kim 			return;
2311205b9822SJaegeuk Kim 	case FI_DATA_EXIST:
2312205b9822SJaegeuk Kim 	case FI_INLINE_DOTS:
23131ad71a27SJaegeuk Kim 	case FI_PIN_FILE:
23147c45729aSJaegeuk Kim 		f2fs_mark_inode_dirty_sync(inode, true);
2315205b9822SJaegeuk Kim 	}
231639a53e0cSJaegeuk Kim }
231739a53e0cSJaegeuk Kim 
231891942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag)
231939a53e0cSJaegeuk Kim {
232091942321SJaegeuk Kim 	if (!test_bit(flag, &F2FS_I(inode)->flags))
232191942321SJaegeuk Kim 		set_bit(flag, &F2FS_I(inode)->flags);
2322205b9822SJaegeuk Kim 	__mark_inode_dirty_flag(inode, flag, true);
232339a53e0cSJaegeuk Kim }
232439a53e0cSJaegeuk Kim 
232591942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag)
232639a53e0cSJaegeuk Kim {
232791942321SJaegeuk Kim 	return test_bit(flag, &F2FS_I(inode)->flags);
232839a53e0cSJaegeuk Kim }
232939a53e0cSJaegeuk Kim 
233091942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag)
233139a53e0cSJaegeuk Kim {
233291942321SJaegeuk Kim 	if (test_bit(flag, &F2FS_I(inode)->flags))
233391942321SJaegeuk Kim 		clear_bit(flag, &F2FS_I(inode)->flags);
2334205b9822SJaegeuk Kim 	__mark_inode_dirty_flag(inode, flag, false);
233539a53e0cSJaegeuk Kim }
233639a53e0cSJaegeuk Kim 
233791942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode)
2338444c580fSJaegeuk Kim {
233991942321SJaegeuk Kim 	F2FS_I(inode)->i_acl_mode = mode;
234091942321SJaegeuk Kim 	set_inode_flag(inode, FI_ACL_MODE);
23417c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, false);
234239a53e0cSJaegeuk Kim }
234339a53e0cSJaegeuk Kim 
2344a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc)
2345a1961246SJaegeuk Kim {
2346a1961246SJaegeuk Kim 	if (inc)
2347a1961246SJaegeuk Kim 		inc_nlink(inode);
2348a1961246SJaegeuk Kim 	else
2349a1961246SJaegeuk Kim 		drop_nlink(inode);
23507c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2351a1961246SJaegeuk Kim }
2352a1961246SJaegeuk Kim 
23538edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode,
23540abd675eSChao Yu 					block_t diff, bool add, bool claim)
23558edd03c8SJaegeuk Kim {
235626de9b11SJaegeuk Kim 	bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
235726de9b11SJaegeuk Kim 	bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
235826de9b11SJaegeuk Kim 
23590abd675eSChao Yu 	/* add = 1, claim = 1 should be dquot_reserve_block in pair */
23600abd675eSChao Yu 	if (add) {
23610abd675eSChao Yu 		if (claim)
23620abd675eSChao Yu 			dquot_claim_block(inode, diff);
23630abd675eSChao Yu 		else
23640abd675eSChao Yu 			dquot_alloc_block_nofail(inode, diff);
23650abd675eSChao Yu 	} else {
23660abd675eSChao Yu 		dquot_free_block(inode, diff);
23670abd675eSChao Yu 	}
23680abd675eSChao Yu 
23697c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
237026de9b11SJaegeuk Kim 	if (clean || recover)
237126de9b11SJaegeuk Kim 		set_inode_flag(inode, FI_AUTO_RECOVER);
23728edd03c8SJaegeuk Kim }
23738edd03c8SJaegeuk Kim 
2374fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
2375fc9581c8SJaegeuk Kim {
237626de9b11SJaegeuk Kim 	bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
237726de9b11SJaegeuk Kim 	bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
237826de9b11SJaegeuk Kim 
2379fc9581c8SJaegeuk Kim 	if (i_size_read(inode) == i_size)
2380fc9581c8SJaegeuk Kim 		return;
2381fc9581c8SJaegeuk Kim 
2382fc9581c8SJaegeuk Kim 	i_size_write(inode, i_size);
23837c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
238426de9b11SJaegeuk Kim 	if (clean || recover)
238526de9b11SJaegeuk Kim 		set_inode_flag(inode, FI_AUTO_RECOVER);
238626de9b11SJaegeuk Kim }
238726de9b11SJaegeuk Kim 
2388205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth)
2389205b9822SJaegeuk Kim {
2390205b9822SJaegeuk Kim 	F2FS_I(inode)->i_current_depth = depth;
23917c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2392205b9822SJaegeuk Kim }
2393205b9822SJaegeuk Kim 
23941ad71a27SJaegeuk Kim static inline void f2fs_i_gc_failures_write(struct inode *inode,
23951ad71a27SJaegeuk Kim 					unsigned int count)
23961ad71a27SJaegeuk Kim {
23972ef79ecbSChao Yu 	F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count;
23981ad71a27SJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
23991ad71a27SJaegeuk Kim }
24001ad71a27SJaegeuk Kim 
2401205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid)
2402205b9822SJaegeuk Kim {
2403205b9822SJaegeuk Kim 	F2FS_I(inode)->i_xattr_nid = xnid;
24047c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2405205b9822SJaegeuk Kim }
2406205b9822SJaegeuk Kim 
2407205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino)
2408205b9822SJaegeuk Kim {
2409205b9822SJaegeuk Kim 	F2FS_I(inode)->i_pino = pino;
24107c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2411205b9822SJaegeuk Kim }
2412205b9822SJaegeuk Kim 
241391942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri)
2414444c580fSJaegeuk Kim {
2415205b9822SJaegeuk Kim 	struct f2fs_inode_info *fi = F2FS_I(inode);
2416205b9822SJaegeuk Kim 
2417444c580fSJaegeuk Kim 	if (ri->i_inline & F2FS_INLINE_XATTR)
2418205b9822SJaegeuk Kim 		set_bit(FI_INLINE_XATTR, &fi->flags);
24191001b347SHuajun Li 	if (ri->i_inline & F2FS_INLINE_DATA)
2420205b9822SJaegeuk Kim 		set_bit(FI_INLINE_DATA, &fi->flags);
242134d67debSChao Yu 	if (ri->i_inline & F2FS_INLINE_DENTRY)
2422205b9822SJaegeuk Kim 		set_bit(FI_INLINE_DENTRY, &fi->flags);
2423b3d208f9SJaegeuk Kim 	if (ri->i_inline & F2FS_DATA_EXIST)
2424205b9822SJaegeuk Kim 		set_bit(FI_DATA_EXIST, &fi->flags);
2425510022a8SJaegeuk Kim 	if (ri->i_inline & F2FS_INLINE_DOTS)
2426205b9822SJaegeuk Kim 		set_bit(FI_INLINE_DOTS, &fi->flags);
24277a2af766SChao Yu 	if (ri->i_inline & F2FS_EXTRA_ATTR)
24287a2af766SChao Yu 		set_bit(FI_EXTRA_ATTR, &fi->flags);
24291ad71a27SJaegeuk Kim 	if (ri->i_inline & F2FS_PIN_FILE)
24301ad71a27SJaegeuk Kim 		set_bit(FI_PIN_FILE, &fi->flags);
2431444c580fSJaegeuk Kim }
2432444c580fSJaegeuk Kim 
243391942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri)
2434444c580fSJaegeuk Kim {
2435444c580fSJaegeuk Kim 	ri->i_inline = 0;
2436444c580fSJaegeuk Kim 
243791942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_XATTR))
2438444c580fSJaegeuk Kim 		ri->i_inline |= F2FS_INLINE_XATTR;
243991942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_DATA))
24401001b347SHuajun Li 		ri->i_inline |= F2FS_INLINE_DATA;
244191942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_DENTRY))
244234d67debSChao Yu 		ri->i_inline |= F2FS_INLINE_DENTRY;
244391942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_DATA_EXIST))
2444b3d208f9SJaegeuk Kim 		ri->i_inline |= F2FS_DATA_EXIST;
244591942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_DOTS))
2446510022a8SJaegeuk Kim 		ri->i_inline |= F2FS_INLINE_DOTS;
24477a2af766SChao Yu 	if (is_inode_flag_set(inode, FI_EXTRA_ATTR))
24487a2af766SChao Yu 		ri->i_inline |= F2FS_EXTRA_ATTR;
24491ad71a27SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_PIN_FILE))
24501ad71a27SJaegeuk Kim 		ri->i_inline |= F2FS_PIN_FILE;
24517a2af766SChao Yu }
24527a2af766SChao Yu 
24537a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode)
24547a2af766SChao Yu {
24557a2af766SChao Yu 	return is_inode_flag_set(inode, FI_EXTRA_ATTR);
2456444c580fSJaegeuk Kim }
2457444c580fSJaegeuk Kim 
2458987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode)
2459987c7c31SChao Yu {
246091942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_XATTR);
2461987c7c31SChao Yu }
2462987c7c31SChao Yu 
246381ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode)
2464de93653fSJaegeuk Kim {
2465b323fd28SChao Yu 	return CUR_ADDRS_PER_INODE(inode) - get_inline_xattr_addrs(inode);
2466de93653fSJaegeuk Kim }
2467de93653fSJaegeuk Kim 
24686afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page)
246965985d93SJaegeuk Kim {
2470695fd1edSChao Yu 	struct f2fs_inode *ri = F2FS_INODE(page);
2471cac5a3d8SDongOh Shin 
247265985d93SJaegeuk Kim 	return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
2473b323fd28SChao Yu 					get_inline_xattr_addrs(inode)]);
247465985d93SJaegeuk Kim }
247565985d93SJaegeuk Kim 
247665985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode)
247765985d93SJaegeuk Kim {
24786afc662eSChao Yu 	return get_inline_xattr_addrs(inode) * sizeof(__le32);
247965985d93SJaegeuk Kim }
248065985d93SJaegeuk Kim 
24810dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode)
24820dbdc2aeSJaegeuk Kim {
248391942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_DATA);
24840dbdc2aeSJaegeuk Kim }
24850dbdc2aeSJaegeuk Kim 
2486b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode)
2487b3d208f9SJaegeuk Kim {
248891942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_DATA_EXIST);
2489b3d208f9SJaegeuk Kim }
2490b3d208f9SJaegeuk Kim 
2491510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode)
2492510022a8SJaegeuk Kim {
249391942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_DOTS);
2494510022a8SJaegeuk Kim }
2495510022a8SJaegeuk Kim 
24961ad71a27SJaegeuk Kim static inline bool f2fs_is_pinned_file(struct inode *inode)
24971ad71a27SJaegeuk Kim {
24981ad71a27SJaegeuk Kim 	return is_inode_flag_set(inode, FI_PIN_FILE);
24991ad71a27SJaegeuk Kim }
25001ad71a27SJaegeuk Kim 
250188b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode)
250288b88a66SJaegeuk Kim {
250391942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_ATOMIC_FILE);
250488b88a66SJaegeuk Kim }
250588b88a66SJaegeuk Kim 
25065fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode)
25075fe45743SChao Yu {
25085fe45743SChao Yu 	return is_inode_flag_set(inode, FI_ATOMIC_COMMIT);
25095fe45743SChao Yu }
25105fe45743SChao Yu 
251102a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode)
251202a1335fSJaegeuk Kim {
251391942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_VOLATILE_FILE);
251402a1335fSJaegeuk Kim }
251502a1335fSJaegeuk Kim 
25163c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode)
25173c6c2bebSJaegeuk Kim {
251891942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN);
25193c6c2bebSJaegeuk Kim }
25203c6c2bebSJaegeuk Kim 
25211e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode)
25221e84371fSJaegeuk Kim {
252391942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_DROP_CACHE);
25241e84371fSJaegeuk Kim }
25251e84371fSJaegeuk Kim 
2526f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page)
25271001b347SHuajun Li {
2528695fd1edSChao Yu 	struct f2fs_inode *ri = F2FS_INODE(page);
25297a2af766SChao Yu 	int extra_size = get_extra_isize(inode);
2530cac5a3d8SDongOh Shin 
25317a2af766SChao Yu 	return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]);
25321001b347SHuajun Li }
25331001b347SHuajun Li 
253434d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode)
253534d67debSChao Yu {
253691942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_DENTRY);
253734d67debSChao Yu }
253834d67debSChao Yu 
2539b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type)
2540b5492af7SJaegeuk Kim {
2541b5492af7SJaegeuk Kim 	return F2FS_I(inode)->i_advise & type;
2542b5492af7SJaegeuk Kim }
2543b5492af7SJaegeuk Kim 
2544b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type)
2545b5492af7SJaegeuk Kim {
2546b5492af7SJaegeuk Kim 	F2FS_I(inode)->i_advise |= type;
25477c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2548b5492af7SJaegeuk Kim }
2549b5492af7SJaegeuk Kim 
2550b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type)
2551b5492af7SJaegeuk Kim {
2552b5492af7SJaegeuk Kim 	F2FS_I(inode)->i_advise &= ~type;
25537c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2554b5492af7SJaegeuk Kim }
2555b5492af7SJaegeuk Kim 
255626787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
255726787236SJaegeuk Kim {
2558a0d00fadSChao Yu 	bool ret;
2559a0d00fadSChao Yu 
256026787236SJaegeuk Kim 	if (dsync) {
256126787236SJaegeuk Kim 		struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
256226787236SJaegeuk Kim 
256326787236SJaegeuk Kim 		spin_lock(&sbi->inode_lock[DIRTY_META]);
256426787236SJaegeuk Kim 		ret = list_empty(&F2FS_I(inode)->gdirty_list);
256526787236SJaegeuk Kim 		spin_unlock(&sbi->inode_lock[DIRTY_META]);
256626787236SJaegeuk Kim 		return ret;
256726787236SJaegeuk Kim 	}
256826787236SJaegeuk Kim 	if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) ||
256926787236SJaegeuk Kim 			file_keep_isize(inode) ||
2570235831d7SJunling Zheng 			i_size_read(inode) & ~PAGE_MASK)
257126787236SJaegeuk Kim 		return false;
2572a0d00fadSChao Yu 
257324b81dfcSArnd Bergmann 	if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime))
2574214c2461SJaegeuk Kim 		return false;
257524b81dfcSArnd Bergmann 	if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime))
2576214c2461SJaegeuk Kim 		return false;
257724b81dfcSArnd Bergmann 	if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime))
2578214c2461SJaegeuk Kim 		return false;
257924b81dfcSArnd Bergmann 	if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3,
2580214c2461SJaegeuk Kim 						&F2FS_I(inode)->i_crtime))
2581214c2461SJaegeuk Kim 		return false;
2582214c2461SJaegeuk Kim 
2583a0d00fadSChao Yu 	down_read(&F2FS_I(inode)->i_sem);
2584a0d00fadSChao Yu 	ret = F2FS_I(inode)->last_disk_size == i_size_read(inode);
2585a0d00fadSChao Yu 	up_read(&F2FS_I(inode)->i_sem);
2586a0d00fadSChao Yu 
2587a0d00fadSChao Yu 	return ret;
2588267378d4SChao Yu }
2589267378d4SChao Yu 
2590deeedd71SChao Yu static inline bool f2fs_readonly(struct super_block *sb)
259177888c1eSJaegeuk Kim {
2592deeedd71SChao Yu 	return sb_rdonly(sb);
259377888c1eSJaegeuk Kim }
259477888c1eSJaegeuk Kim 
2595744602cfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
2596744602cfSJaegeuk Kim {
2597aaec2b1dSChao Yu 	return is_set_ckpt_flags(sbi, CP_ERROR_FLAG);
2598744602cfSJaegeuk Kim }
2599744602cfSJaegeuk Kim 
2600eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str)
2601eaa693f4SJaegeuk Kim {
2602eaa693f4SJaegeuk Kim 	if (str->len == 1 && str->name[0] == '.')
2603eaa693f4SJaegeuk Kim 		return true;
2604eaa693f4SJaegeuk Kim 
2605eaa693f4SJaegeuk Kim 	if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
2606eaa693f4SJaegeuk Kim 		return true;
2607eaa693f4SJaegeuk Kim 
2608eaa693f4SJaegeuk Kim 	return false;
2609eaa693f4SJaegeuk Kim }
2610eaa693f4SJaegeuk Kim 
26113e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode)
26123e72f721SJaegeuk Kim {
26133e72f721SJaegeuk Kim 	if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) ||
261491942321SJaegeuk Kim 			is_inode_flag_set(inode, FI_NO_EXTENT))
26153e72f721SJaegeuk Kim 		return false;
26163e72f721SJaegeuk Kim 
2617886f56f9SAl Viro 	return S_ISREG(inode->i_mode);
26183e72f721SJaegeuk Kim }
26193e72f721SJaegeuk Kim 
26201ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
26211ecc0c5cSChao Yu 					size_t size, gfp_t flags)
26220414b004SJaegeuk Kim {
262355523519SChao Yu 	if (time_to_inject(sbi, FAULT_KMALLOC)) {
262455523519SChao Yu 		f2fs_show_injection_info(FAULT_KMALLOC);
26252c63feadSJaegeuk Kim 		return NULL;
262655523519SChao Yu 	}
26277fa750a1SArnd Bergmann 
26280414b004SJaegeuk Kim 	return kmalloc(size, flags);
26290414b004SJaegeuk Kim }
26300414b004SJaegeuk Kim 
2631acbf054dSChao Yu static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi,
2632acbf054dSChao Yu 					size_t size, gfp_t flags)
2633acbf054dSChao Yu {
2634acbf054dSChao Yu 	return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO);
2635acbf054dSChao Yu }
2636acbf054dSChao Yu 
2637628b3d14SChao Yu static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi,
2638628b3d14SChao Yu 					size_t size, gfp_t flags)
2639628b3d14SChao Yu {
2640628b3d14SChao Yu 	if (time_to_inject(sbi, FAULT_KVMALLOC)) {
2641628b3d14SChao Yu 		f2fs_show_injection_info(FAULT_KVMALLOC);
2642628b3d14SChao Yu 		return NULL;
2643628b3d14SChao Yu 	}
26447fa750a1SArnd Bergmann 
2645628b3d14SChao Yu 	return kvmalloc(size, flags);
2646628b3d14SChao Yu }
2647628b3d14SChao Yu 
2648628b3d14SChao Yu static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi,
2649628b3d14SChao Yu 					size_t size, gfp_t flags)
2650628b3d14SChao Yu {
2651628b3d14SChao Yu 	return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO);
2652628b3d14SChao Yu }
2653628b3d14SChao Yu 
26547a2af766SChao Yu static inline int get_extra_isize(struct inode *inode)
2655f2470371SChao Yu {
26567a2af766SChao Yu 	return F2FS_I(inode)->i_extra_isize / sizeof(__le32);
2657f2470371SChao Yu }
2658f2470371SChao Yu 
26596afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode)
26606afc662eSChao Yu {
26616afc662eSChao Yu 	return F2FS_I(inode)->i_inline_xattr_size;
26626afc662eSChao Yu }
26636afc662eSChao Yu 
26644d57b86dSChao Yu #define f2fs_get_inode_mode(i) \
266591942321SJaegeuk Kim 	((is_inode_flag_set(i, FI_ACL_MODE)) ? \
2666a6dda0e6SChristoph Hellwig 	 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
2667a6dda0e6SChristoph Hellwig 
26687a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE			\
26697a2af766SChao Yu 	(offsetof(struct f2fs_inode, i_extra_end) -	\
26707a2af766SChao Yu 	offsetof(struct f2fs_inode, i_extra_isize))	\
26717a2af766SChao Yu 
26725c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE	(offsetof(struct f2fs_inode, i_addr))
26735c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field)		\
26745c57132eSChao Yu 		((offsetof(typeof(*f2fs_inode), field) +	\
26755c57132eSChao Yu 		sizeof((f2fs_inode)->field))			\
26765c57132eSChao Yu 		<= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize))	\
26775c57132eSChao Yu 
2678b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi)
2679b0af6d49SChao Yu {
2680b0af6d49SChao Yu 	int i;
2681b0af6d49SChao Yu 
2682b0af6d49SChao Yu 	spin_lock(&sbi->iostat_lock);
2683b0af6d49SChao Yu 	for (i = 0; i < NR_IO_TYPE; i++)
2684b0af6d49SChao Yu 		sbi->write_iostat[i] = 0;
2685b0af6d49SChao Yu 	spin_unlock(&sbi->iostat_lock);
2686b0af6d49SChao Yu }
2687b0af6d49SChao Yu 
2688b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
2689b0af6d49SChao Yu 			enum iostat_type type, unsigned long long io_bytes)
2690b0af6d49SChao Yu {
2691b0af6d49SChao Yu 	if (!sbi->iostat_enable)
2692b0af6d49SChao Yu 		return;
2693b0af6d49SChao Yu 	spin_lock(&sbi->iostat_lock);
2694b0af6d49SChao Yu 	sbi->write_iostat[type] += io_bytes;
2695b0af6d49SChao Yu 
2696b0af6d49SChao Yu 	if (type == APP_WRITE_IO || type == APP_DIRECT_IO)
2697b0af6d49SChao Yu 		sbi->write_iostat[APP_BUFFERED_IO] =
2698b0af6d49SChao Yu 			sbi->write_iostat[APP_WRITE_IO] -
2699b0af6d49SChao Yu 			sbi->write_iostat[APP_DIRECT_IO];
2700b0af6d49SChao Yu 	spin_unlock(&sbi->iostat_lock);
2701b0af6d49SChao Yu }
2702b0af6d49SChao Yu 
2703c9b60788SChao Yu #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO(fio->type) == META &&	\
2704c9b60788SChao Yu 				(!is_read_io(fio->op) || fio->is_meta))
2705c9b60788SChao Yu 
2706e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
2707e1da7872SChao Yu 					block_t blkaddr, int type);
2708e1da7872SChao Yu void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
2709e1da7872SChao Yu static inline void verify_blkaddr(struct f2fs_sb_info *sbi,
2710e1da7872SChao Yu 					block_t blkaddr, int type)
2711e1da7872SChao Yu {
2712e1da7872SChao Yu 	if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) {
2713e1da7872SChao Yu 		f2fs_msg(sbi->sb, KERN_ERR,
2714e1da7872SChao Yu 			"invalid blkaddr: %u, type: %d, run fsck to fix.",
2715e1da7872SChao Yu 			blkaddr, type);
2716e1da7872SChao Yu 		f2fs_bug_on(sbi, 1);
2717e1da7872SChao Yu 	}
2718e1da7872SChao Yu }
2719e1da7872SChao Yu 
2720e1da7872SChao Yu static inline bool __is_valid_data_blkaddr(block_t blkaddr)
27217b525dd0SChao Yu {
27227b525dd0SChao Yu 	if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR)
27237b525dd0SChao Yu 		return false;
27247b525dd0SChao Yu 	return true;
27257b525dd0SChao Yu }
27267b525dd0SChao Yu 
2727e1da7872SChao Yu static inline bool is_valid_data_blkaddr(struct f2fs_sb_info *sbi,
2728e1da7872SChao Yu 						block_t blkaddr)
2729e1da7872SChao Yu {
2730e1da7872SChao Yu 	if (!__is_valid_data_blkaddr(blkaddr))
2731e1da7872SChao Yu 		return false;
2732e1da7872SChao Yu 	verify_blkaddr(sbi, blkaddr, DATA_GENERIC);
2733e1da7872SChao Yu 	return true;
2734e1da7872SChao Yu }
2735e1da7872SChao Yu 
273639a53e0cSJaegeuk Kim /*
273739a53e0cSJaegeuk Kim  * file.c
273839a53e0cSJaegeuk Kim  */
2739cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
27404d57b86dSChao Yu void f2fs_truncate_data_blocks(struct dnode_of_data *dn);
27414d57b86dSChao Yu int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock);
2742cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode);
2743a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat,
2744a528d35eSDavid Howells 			u32 request_mask, unsigned int flags);
2745cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr);
27464d57b86dSChao Yu int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end);
27474d57b86dSChao Yu void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count);
2748c4020b2dSChao Yu int f2fs_precache_extents(struct inode *inode);
2749cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
2750cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
27511ad71a27SJaegeuk Kim int f2fs_pin_file_control(struct inode *inode, bool inc);
275239a53e0cSJaegeuk Kim 
275339a53e0cSJaegeuk Kim /*
275439a53e0cSJaegeuk Kim  * inode.c
275539a53e0cSJaegeuk Kim  */
2756cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode);
2757704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page);
2758704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page);
2759cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
2760cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
27614d57b86dSChao Yu int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
27624d57b86dSChao Yu void f2fs_update_inode(struct inode *inode, struct page *node_page);
27634d57b86dSChao Yu void f2fs_update_inode_page(struct inode *inode);
2764cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
2765cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode);
27664d57b86dSChao Yu void f2fs_handle_failed_inode(struct inode *inode);
276739a53e0cSJaegeuk Kim 
276839a53e0cSJaegeuk Kim /*
276939a53e0cSJaegeuk Kim  * namei.c
277039a53e0cSJaegeuk Kim  */
27714d57b86dSChao Yu int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
2772b6a06cbbSChao Yu 							bool hot, bool set);
277339a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child);
277439a53e0cSJaegeuk Kim 
277539a53e0cSJaegeuk Kim /*
277639a53e0cSJaegeuk Kim  * dir.c
277739a53e0cSJaegeuk Kim  */
27784d57b86dSChao Yu unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de);
27794d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname,
2780cac5a3d8SDongOh Shin 			f2fs_hash_t namehash, int *max_slots,
2781cac5a3d8SDongOh Shin 			struct f2fs_dentry_ptr *d);
2782cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
2783cac5a3d8SDongOh Shin 			unsigned int start_pos, struct fscrypt_str *fstr);
27844d57b86dSChao Yu void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent,
2785cac5a3d8SDongOh Shin 			struct f2fs_dentry_ptr *d);
27864d57b86dSChao Yu struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
2787cac5a3d8SDongOh Shin 			const struct qstr *new_name,
2788cac5a3d8SDongOh Shin 			const struct qstr *orig_name, struct page *dpage);
27894d57b86dSChao Yu void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode,
2790cac5a3d8SDongOh Shin 			unsigned int current_depth);
27914d57b86dSChao Yu int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots);
2792cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode);
2793cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
2794cac5a3d8SDongOh Shin 			struct fscrypt_name *fname, struct page **res_page);
2795cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
2796cac5a3d8SDongOh Shin 			const struct qstr *child, struct page **res_page);
2797cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p);
2798cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
2799cac5a3d8SDongOh Shin 			struct page **page);
2800cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
2801cac5a3d8SDongOh Shin 			struct page *page, struct inode *inode);
2802cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
2803cac5a3d8SDongOh Shin 			const struct qstr *name, f2fs_hash_t name_hash,
2804cac5a3d8SDongOh Shin 			unsigned int bit_pos);
2805cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name,
2806cac5a3d8SDongOh Shin 			const struct qstr *orig_name,
2807cac5a3d8SDongOh Shin 			struct inode *inode, nid_t ino, umode_t mode);
28084d57b86dSChao Yu int f2fs_add_dentry(struct inode *dir, struct fscrypt_name *fname,
2809cac5a3d8SDongOh Shin 			struct inode *inode, nid_t ino, umode_t mode);
28104d57b86dSChao Yu int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
2811cac5a3d8SDongOh Shin 			struct inode *inode, nid_t ino, umode_t mode);
2812cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
2813cac5a3d8SDongOh Shin 			struct inode *dir, struct inode *inode);
2814cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir);
2815cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir);
281639a53e0cSJaegeuk Kim 
2817b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
2818b7f7a5e0SAl Viro {
28194d57b86dSChao Yu 	return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name,
2820510022a8SJaegeuk Kim 				inode, inode->i_ino, inode->i_mode);
2821b7f7a5e0SAl Viro }
2822b7f7a5e0SAl Viro 
282339a53e0cSJaegeuk Kim /*
282439a53e0cSJaegeuk Kim  * super.c
282539a53e0cSJaegeuk Kim  */
2826cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync);
2827cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode);
2828ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly);
28294b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb);
2830cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover);
2831cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync);
2832a07ef784SNamjae Jeon extern __printf(3, 4)
2833cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
28344d57b86dSChao Yu int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi);
283539a53e0cSJaegeuk Kim 
283639a53e0cSJaegeuk Kim /*
283739a53e0cSJaegeuk Kim  * hash.c
283839a53e0cSJaegeuk Kim  */
28396332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info,
28406332cd32SJaegeuk Kim 				struct fscrypt_name *fname);
284139a53e0cSJaegeuk Kim 
284239a53e0cSJaegeuk Kim /*
284339a53e0cSJaegeuk Kim  * node.c
284439a53e0cSJaegeuk Kim  */
284539a53e0cSJaegeuk Kim struct dnode_of_data;
284639a53e0cSJaegeuk Kim struct node_info;
284739a53e0cSJaegeuk Kim 
28484d57b86dSChao Yu int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid);
28494d57b86dSChao Yu bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type);
285050fa53ecSChao Yu bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page);
285150fa53ecSChao Yu void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi);
285250fa53ecSChao Yu void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page);
285350fa53ecSChao Yu void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi);
28544d57b86dSChao Yu int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid);
28554d57b86dSChao Yu bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid);
28564d57b86dSChao Yu bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino);
28577735730dSChao Yu int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid,
28584d57b86dSChao Yu 						struct node_info *ni);
28594d57b86dSChao Yu pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs);
28604d57b86dSChao Yu int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode);
28614d57b86dSChao Yu int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from);
28624d57b86dSChao Yu int f2fs_truncate_xattr_node(struct inode *inode);
286350fa53ecSChao Yu int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi,
286450fa53ecSChao Yu 					unsigned int seq_id);
28654d57b86dSChao Yu int f2fs_remove_inode_page(struct inode *inode);
28664d57b86dSChao Yu struct page *f2fs_new_inode_page(struct inode *inode);
28674d57b86dSChao Yu struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs);
28684d57b86dSChao Yu void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid);
28694d57b86dSChao Yu struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid);
28704d57b86dSChao Yu struct page *f2fs_get_node_page_ra(struct page *parent, int start);
28714d57b86dSChao Yu void f2fs_move_node_page(struct page *node_page, int gc_type);
28724d57b86dSChao Yu int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
287350fa53ecSChao Yu 			struct writeback_control *wbc, bool atomic,
287450fa53ecSChao Yu 			unsigned int *seq_id);
28754d57b86dSChao Yu int f2fs_sync_node_pages(struct f2fs_sb_info *sbi,
28764d57b86dSChao Yu 			struct writeback_control *wbc,
2877b0af6d49SChao Yu 			bool do_balance, enum iostat_type io_type);
2878e2374015SChao Yu int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount);
28794d57b86dSChao Yu bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid);
28804d57b86dSChao Yu void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
28814d57b86dSChao Yu void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
28824d57b86dSChao Yu int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
28834d57b86dSChao Yu void f2fs_recover_inline_xattr(struct inode *inode, struct page *page);
28844d57b86dSChao Yu int f2fs_recover_xattr_data(struct inode *inode, struct page *page);
28854d57b86dSChao Yu int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page);
28867735730dSChao Yu int f2fs_restore_node_summary(struct f2fs_sb_info *sbi,
2887cac5a3d8SDongOh Shin 			unsigned int segno, struct f2fs_summary_block *sum);
28884d57b86dSChao Yu void f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
28894d57b86dSChao Yu int f2fs_build_node_manager(struct f2fs_sb_info *sbi);
28904d57b86dSChao Yu void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi);
28914d57b86dSChao Yu int __init f2fs_create_node_manager_caches(void);
28924d57b86dSChao Yu void f2fs_destroy_node_manager_caches(void);
289339a53e0cSJaegeuk Kim 
289439a53e0cSJaegeuk Kim /*
289539a53e0cSJaegeuk Kim  * segment.c
289639a53e0cSJaegeuk Kim  */
28974d57b86dSChao Yu bool f2fs_need_SSR(struct f2fs_sb_info *sbi);
28984d57b86dSChao Yu void f2fs_register_inmem_page(struct inode *inode, struct page *page);
28994d57b86dSChao Yu void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure);
29004d57b86dSChao Yu void f2fs_drop_inmem_pages(struct inode *inode);
29014d57b86dSChao Yu void f2fs_drop_inmem_page(struct inode *inode, struct page *page);
29024d57b86dSChao Yu int f2fs_commit_inmem_pages(struct inode *inode);
2903cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need);
2904cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi);
290539d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino);
29064d57b86dSChao Yu int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi);
29071228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi);
29084d57b86dSChao Yu void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free);
29094d57b86dSChao Yu void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr);
29104d57b86dSChao Yu bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
29114d57b86dSChao Yu void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi);
29124d57b86dSChao Yu void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi);
2913cf5c759fSChao Yu bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi);
29144d57b86dSChao Yu void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,
29154d57b86dSChao Yu 					struct cp_control *cpc);
29164d57b86dSChao Yu void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi);
29174d57b86dSChao Yu int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
29184d57b86dSChao Yu void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
2919cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
29204d57b86dSChao Yu bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi,
29214d57b86dSChao Yu 					struct cp_control *cpc);
29224d57b86dSChao Yu struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno);
29234d57b86dSChao Yu void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src,
29244d57b86dSChao Yu 					block_t blk_addr);
29254d57b86dSChao Yu void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page,
2926b0af6d49SChao Yu 						enum iostat_type io_type);
29274d57b86dSChao Yu void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio);
29284d57b86dSChao Yu void f2fs_outplace_write_data(struct dnode_of_data *dn,
29294d57b86dSChao Yu 			struct f2fs_io_info *fio);
29304d57b86dSChao Yu int f2fs_inplace_write_data(struct f2fs_io_info *fio);
29314d57b86dSChao Yu void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
2932cac5a3d8SDongOh Shin 			block_t old_blkaddr, block_t new_blkaddr,
2933cac5a3d8SDongOh Shin 			bool recover_curseg, bool recover_newaddr);
2934cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
2935cac5a3d8SDongOh Shin 			block_t old_addr, block_t new_addr,
2936cac5a3d8SDongOh Shin 			unsigned char version, bool recover_curseg,
2937cac5a3d8SDongOh Shin 			bool recover_newaddr);
29384d57b86dSChao Yu void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
2939cac5a3d8SDongOh Shin 			block_t old_blkaddr, block_t *new_blkaddr,
2940fb830fc5SChao Yu 			struct f2fs_summary *sum, int type,
2941fb830fc5SChao Yu 			struct f2fs_io_info *fio, bool add_list);
2942cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page,
2943cac5a3d8SDongOh Shin 			enum page_type type, bool ordered);
2944d4c759eeSJaegeuk Kim void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr);
29454d57b86dSChao Yu void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
29464d57b86dSChao Yu void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
29474d57b86dSChao Yu int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
2948cac5a3d8SDongOh Shin 			unsigned int val, int alloc);
29494d57b86dSChao Yu void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
29504d57b86dSChao Yu int f2fs_build_segment_manager(struct f2fs_sb_info *sbi);
29514d57b86dSChao Yu void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi);
29524d57b86dSChao Yu int __init f2fs_create_segment_manager_caches(void);
29534d57b86dSChao Yu void f2fs_destroy_segment_manager_caches(void);
29544d57b86dSChao Yu int f2fs_rw_hint_to_seg_type(enum rw_hint hint);
29554d57b86dSChao Yu enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi,
29564d57b86dSChao Yu 			enum page_type type, enum temp_type temp);
295739a53e0cSJaegeuk Kim 
295839a53e0cSJaegeuk Kim /*
295939a53e0cSJaegeuk Kim  * checkpoint.c
296039a53e0cSJaegeuk Kim  */
2961cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io);
29624d57b86dSChao Yu struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
29634d57b86dSChao Yu struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
29647735730dSChao Yu struct page *f2fs_get_meta_page_nofail(struct f2fs_sb_info *sbi, pgoff_t index);
29654d57b86dSChao Yu struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index);
2966e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
29674d57b86dSChao Yu 					block_t blkaddr, int type);
29684d57b86dSChao Yu int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
2969cac5a3d8SDongOh Shin 			int type, bool sync);
29704d57b86dSChao Yu void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index);
29714d57b86dSChao Yu long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
2972b0af6d49SChao Yu 			long nr_to_write, enum iostat_type io_type);
29734d57b86dSChao Yu void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
29744d57b86dSChao Yu void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
29754d57b86dSChao Yu void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all);
29764d57b86dSChao Yu bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode);
29774d57b86dSChao Yu void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
297839d787beSChao Yu 					unsigned int devidx, int type);
29794d57b86dSChao Yu bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
298039d787beSChao Yu 					unsigned int devidx, int type);
2981cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi);
29824d57b86dSChao Yu int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi);
29834d57b86dSChao Yu void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi);
29844d57b86dSChao Yu void f2fs_add_orphan_inode(struct inode *inode);
29854d57b86dSChao Yu void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino);
29864d57b86dSChao Yu int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi);
29874d57b86dSChao Yu int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi);
29884d57b86dSChao Yu void f2fs_update_dirty_page(struct inode *inode, struct page *page);
29894d57b86dSChao Yu void f2fs_remove_dirty_inode(struct inode *inode);
29904d57b86dSChao Yu int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type);
299150fa53ecSChao Yu void f2fs_wait_on_all_pages_writeback(struct f2fs_sb_info *sbi);
29924d57b86dSChao Yu int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc);
29934d57b86dSChao Yu void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi);
29944d57b86dSChao Yu int __init f2fs_create_checkpoint_caches(void);
29954d57b86dSChao Yu void f2fs_destroy_checkpoint_caches(void);
299639a53e0cSJaegeuk Kim 
299739a53e0cSJaegeuk Kim /*
299839a53e0cSJaegeuk Kim  * data.c
299939a53e0cSJaegeuk Kim  */
30006dbb1796SEric Biggers int f2fs_init_post_read_processing(void);
30016dbb1796SEric Biggers void f2fs_destroy_post_read_processing(void);
3002b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
3003b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
3004942fd319SJaegeuk Kim 				struct inode *inode, nid_t ino, pgoff_t idx,
3005b9109b0eSJaegeuk Kim 				enum page_type type);
3006b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
3007cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio);
3008fe16efe6SChao Yu void f2fs_submit_page_write(struct f2fs_io_info *fio);
3009cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
3010cac5a3d8SDongOh Shin 			block_t blk_addr, struct bio *bio);
3011cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
30124d57b86dSChao Yu void f2fs_set_data_blkaddr(struct dnode_of_data *dn);
3013cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr);
30144d57b86dSChao Yu int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count);
30154d57b86dSChao Yu int f2fs_reserve_new_block(struct dnode_of_data *dn);
3016cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index);
3017cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from);
3018cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index);
30194d57b86dSChao Yu struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index,
3020cac5a3d8SDongOh Shin 			int op_flags, bool for_write);
30214d57b86dSChao Yu struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index);
30224d57b86dSChao Yu struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index,
3023cac5a3d8SDongOh Shin 			bool for_write);
30244d57b86dSChao Yu struct page *f2fs_get_new_data_page(struct inode *inode,
3025cac5a3d8SDongOh Shin 			struct page *ipage, pgoff_t index, bool new_i_size);
30264d57b86dSChao Yu int f2fs_do_write_data_page(struct f2fs_io_info *fio);
3027cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
3028cac5a3d8SDongOh Shin 			int create, int flag);
3029cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3030cac5a3d8SDongOh Shin 			u64 start, u64 len);
30314d57b86dSChao Yu bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio);
30324d57b86dSChao Yu bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio);
3033cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset,
3034cac5a3d8SDongOh Shin 			unsigned int length);
3035cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait);
30365b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION
3037cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage,
3038cac5a3d8SDongOh Shin 			struct page *page, enum migrate_mode mode);
30395b7a487cSWeichao Guo #endif
3040b91050a8SHyunchul Lee bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len);
30414d57b86dSChao Yu void f2fs_clear_radix_tree_dirty_tag(struct page *page);
304239a53e0cSJaegeuk Kim 
304339a53e0cSJaegeuk Kim /*
304439a53e0cSJaegeuk Kim  * gc.c
304539a53e0cSJaegeuk Kim  */
30464d57b86dSChao Yu int f2fs_start_gc_thread(struct f2fs_sb_info *sbi);
30474d57b86dSChao Yu void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi);
30484d57b86dSChao Yu block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode);
3049e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background,
3050e066b83cSJaegeuk Kim 			unsigned int segno);
30514d57b86dSChao Yu void f2fs_build_gc_manager(struct f2fs_sb_info *sbi);
305239a53e0cSJaegeuk Kim 
305339a53e0cSJaegeuk Kim /*
305439a53e0cSJaegeuk Kim  * recovery.c
305539a53e0cSJaegeuk Kim  */
30564d57b86dSChao Yu int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only);
30574d57b86dSChao Yu bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi);
305839a53e0cSJaegeuk Kim 
305939a53e0cSJaegeuk Kim /*
306039a53e0cSJaegeuk Kim  * debug.c
306139a53e0cSJaegeuk Kim  */
306239a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS
306339a53e0cSJaegeuk Kim struct f2fs_stat_info {
306439a53e0cSJaegeuk Kim 	struct list_head stat_list;
306539a53e0cSJaegeuk Kim 	struct f2fs_sb_info *sbi;
306639a53e0cSJaegeuk Kim 	int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
306739a53e0cSJaegeuk Kim 	int main_area_segs, main_area_sections, main_area_zones;
30685b7ee374SChao Yu 	unsigned long long hit_largest, hit_cached, hit_rbtree;
30695b7ee374SChao Yu 	unsigned long long hit_total, total_ext;
3070c00ba554SJaegeuk Kim 	int ext_tree, zombie_tree, ext_node;
30712c8a4a28SJaegeuk Kim 	int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta;
30722c8a4a28SJaegeuk Kim 	int ndirty_data, ndirty_qdata;
307335782b23SJaegeuk Kim 	int inmem_pages;
30742c8a4a28SJaegeuk Kim 	unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all;
30755b0ef73cSJaegeuk Kim 	int nats, dirty_nats, sits, dirty_sits;
30765b0ef73cSJaegeuk Kim 	int free_nids, avail_nids, alloc_nids;
307739a53e0cSJaegeuk Kim 	int total_count, utilization;
30788b8dd65fSChao Yu 	int bg_gc, nr_wb_cp_data, nr_wb_data;
307914d8d5f7SChao Yu 	int nr_flushing, nr_flushed, flush_list_empty;
308014d8d5f7SChao Yu 	int nr_discarding, nr_discarded;
30815f32366aSChao Yu 	int nr_discard_cmd;
3082d84d1cbdSChao Yu 	unsigned int undiscard_blks;
3083a00861dbSJaegeuk Kim 	int inline_xattr, inline_inode, inline_dir, append, update, orphans;
3084648d50baSChao Yu 	int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt;
3085f83a2584SYunlei He 	unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks;
308639a53e0cSJaegeuk Kim 	unsigned int bimodal, avg_vblocks;
308739a53e0cSJaegeuk Kim 	int util_free, util_valid, util_invalid;
308839a53e0cSJaegeuk Kim 	int rsvd_segs, overp_segs;
308939a53e0cSJaegeuk Kim 	int dirty_count, node_pages, meta_pages;
309042190d2aSJaegeuk Kim 	int prefree_count, call_count, cp_count, bg_cp_count;
309139a53e0cSJaegeuk Kim 	int tot_segs, node_segs, data_segs, free_segs, free_secs;
3092e1235983SChangman Lee 	int bg_node_segs, bg_data_segs;
309339a53e0cSJaegeuk Kim 	int tot_blks, data_blks, node_blks;
3094e1235983SChangman Lee 	int bg_data_blks, bg_node_blks;
30952ef79ecbSChao Yu 	unsigned long long skipped_atomic_files[2];
309639a53e0cSJaegeuk Kim 	int curseg[NR_CURSEG_TYPE];
309739a53e0cSJaegeuk Kim 	int cursec[NR_CURSEG_TYPE];
309839a53e0cSJaegeuk Kim 	int curzone[NR_CURSEG_TYPE];
309939a53e0cSJaegeuk Kim 
310039a53e0cSJaegeuk Kim 	unsigned int segment_count[2];
310139a53e0cSJaegeuk Kim 	unsigned int block_count[2];
3102b9a2c252SChangman Lee 	unsigned int inplace_count;
31039edcdabfSChao Yu 	unsigned long long base_mem, cache_mem, page_mem;
310439a53e0cSJaegeuk Kim };
310539a53e0cSJaegeuk Kim 
3106963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
3107963d4f7dSGu Zheng {
3108963d4f7dSGu Zheng 	return (struct f2fs_stat_info *)sbi->stat_info;
3109963d4f7dSGu Zheng }
3110963d4f7dSGu Zheng 
3111942e0be6SChangman Lee #define stat_inc_cp_count(si)		((si)->cp_count++)
311242190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si)	((si)->bg_cp_count++)
311339a53e0cSJaegeuk Kim #define stat_inc_call_count(si)		((si)->call_count++)
3114dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi)	((sbi)->bg_gc++)
311533fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type)	((sbi)->ndirty_inode[type]++)
311633fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type)	((sbi)->ndirty_inode[type]--)
31175b7ee374SChao Yu #define stat_inc_total_hit(sbi)		(atomic64_inc(&(sbi)->total_hit_ext))
31185b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_rbtree))
31195b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_largest))
31205b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_cached))
3121d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode)					\
3122d5e8f6c9SChao Yu 	do {								\
3123d5e8f6c9SChao Yu 		if (f2fs_has_inline_xattr(inode))			\
3124d5e8f6c9SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_xattr));	\
3125d5e8f6c9SChao Yu 	} while (0)
3126d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode)					\
3127d5e8f6c9SChao Yu 	do {								\
3128d5e8f6c9SChao Yu 		if (f2fs_has_inline_xattr(inode))			\
3129d5e8f6c9SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_xattr));	\
3130d5e8f6c9SChao Yu 	} while (0)
31310dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode)					\
31320dbdc2aeSJaegeuk Kim 	do {								\
31330dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
313403e14d52SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_inode));	\
31350dbdc2aeSJaegeuk Kim 	} while (0)
31360dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode)					\
31370dbdc2aeSJaegeuk Kim 	do {								\
31380dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
313903e14d52SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_inode));	\
31400dbdc2aeSJaegeuk Kim 	} while (0)
31413289c061SJaegeuk Kim #define stat_inc_inline_dir(inode)					\
31423289c061SJaegeuk Kim 	do {								\
31433289c061SJaegeuk Kim 		if (f2fs_has_inline_dentry(inode))			\
314403e14d52SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_dir));	\
31453289c061SJaegeuk Kim 	} while (0)
31463289c061SJaegeuk Kim #define stat_dec_inline_dir(inode)					\
31473289c061SJaegeuk Kim 	do {								\
31483289c061SJaegeuk Kim 		if (f2fs_has_inline_dentry(inode))			\
314903e14d52SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_dir));	\
31503289c061SJaegeuk Kim 	} while (0)
3151dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg)					\
3152dcdfff65SJaegeuk Kim 		((sbi)->segment_count[(curseg)->alloc_type]++)
3153dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg)				\
3154dcdfff65SJaegeuk Kim 		((sbi)->block_count[(curseg)->alloc_type]++)
3155b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi)					\
3156b9a2c252SChangman Lee 		(atomic_inc(&(sbi)->inplace_count))
315726a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode)					\
3158cac5a3d8SDongOh Shin 		(atomic_inc(&F2FS_I_SB(inode)->aw_cnt))
315926a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode)					\
3160cac5a3d8SDongOh Shin 		(atomic_dec(&F2FS_I_SB(inode)->aw_cnt))
316126a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode)				\
316226a28a0cSJaegeuk Kim 	do {								\
316326a28a0cSJaegeuk Kim 		int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt);	\
316426a28a0cSJaegeuk Kim 		int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt);	\
316526a28a0cSJaegeuk Kim 		if (cur > max)						\
316626a28a0cSJaegeuk Kim 			atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur);	\
316726a28a0cSJaegeuk Kim 	} while (0)
3168648d50baSChao Yu #define stat_inc_volatile_write(inode)					\
3169648d50baSChao Yu 		(atomic_inc(&F2FS_I_SB(inode)->vw_cnt))
3170648d50baSChao Yu #define stat_dec_volatile_write(inode)					\
3171648d50baSChao Yu 		(atomic_dec(&F2FS_I_SB(inode)->vw_cnt))
3172648d50baSChao Yu #define stat_update_max_volatile_write(inode)				\
3173648d50baSChao Yu 	do {								\
3174648d50baSChao Yu 		int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt);	\
3175648d50baSChao Yu 		int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt);	\
3176648d50baSChao Yu 		if (cur > max)						\
3177648d50baSChao Yu 			atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur);	\
3178648d50baSChao Yu 	} while (0)
3179e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type)				\
318039a53e0cSJaegeuk Kim 	do {								\
3181963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
318268afcf2dSTomohiro Kusumi 		si->tot_segs++;						\
318368afcf2dSTomohiro Kusumi 		if ((type) == SUM_TYPE_DATA) {				\
318439a53e0cSJaegeuk Kim 			si->data_segs++;				\
3185e1235983SChangman Lee 			si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0;	\
3186e1235983SChangman Lee 		} else {						\
318739a53e0cSJaegeuk Kim 			si->node_segs++;				\
3188e1235983SChangman Lee 			si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0;	\
3189e1235983SChangman Lee 		}							\
319039a53e0cSJaegeuk Kim 	} while (0)
319139a53e0cSJaegeuk Kim 
319239a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks)				\
319368afcf2dSTomohiro Kusumi 	((si)->tot_blks += (blks))
319439a53e0cSJaegeuk Kim 
3195e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type)			\
319639a53e0cSJaegeuk Kim 	do {								\
3197963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
319839a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
319939a53e0cSJaegeuk Kim 		si->data_blks += (blks);				\
320068afcf2dSTomohiro Kusumi 		si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0;	\
320139a53e0cSJaegeuk Kim 	} while (0)
320239a53e0cSJaegeuk Kim 
3203e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type)			\
320439a53e0cSJaegeuk Kim 	do {								\
3205963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
320639a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
320739a53e0cSJaegeuk Kim 		si->node_blks += (blks);				\
320868afcf2dSTomohiro Kusumi 		si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0;	\
320939a53e0cSJaegeuk Kim 	} while (0)
321039a53e0cSJaegeuk Kim 
3211cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi);
3212cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi);
3213787c7b8cSChao Yu int __init f2fs_create_root_stats(void);
32144589d25dSNamjae Jeon void f2fs_destroy_root_stats(void);
321539a53e0cSJaegeuk Kim #else
3216d66450e7SArnd Bergmann #define stat_inc_cp_count(si)				do { } while (0)
3217d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si)			do { } while (0)
3218d66450e7SArnd Bergmann #define stat_inc_call_count(si)				do { } while (0)
3219d66450e7SArnd Bergmann #define stat_inc_bggc_count(si)				do { } while (0)
3220d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type)			do { } while (0)
3221d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type)			do { } while (0)
3222d66450e7SArnd Bergmann #define stat_inc_total_hit(sb)				do { } while (0)
3223d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb)			do { } while (0)
3224d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi)			do { } while (0)
3225d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi)			do { } while (0)
3226d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode)			do { } while (0)
3227d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode)			do { } while (0)
3228d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode)			do { } while (0)
3229d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode)			do { } while (0)
3230d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode)			do { } while (0)
3231d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode)			do { } while (0)
3232d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode)			do { } while (0)
3233d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode)			do { } while (0)
3234d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode)		do { } while (0)
3235d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode)			do { } while (0)
3236d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode)			do { } while (0)
3237d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode)		do { } while (0)
3238d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg)			do { } while (0)
3239d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg)		do { } while (0)
3240d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi)			do { } while (0)
3241d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type)		do { } while (0)
3242d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks)		do { } while (0)
3243d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type)	do { } while (0)
3244d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type)	do { } while (0)
324539a53e0cSJaegeuk Kim 
324639a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
324739a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
3248787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; }
32494589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { }
325039a53e0cSJaegeuk Kim #endif
325139a53e0cSJaegeuk Kim 
325239a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations;
325339a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations;
325439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations;
325539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops;
325639a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops;
325739a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops;
325839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations;
325939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations;
3260cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
326139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations;
32624d57b86dSChao Yu extern struct kmem_cache *f2fs_inode_entry_slab;
32631001b347SHuajun Li 
3264e18c65b2SHuajun Li /*
3265e18c65b2SHuajun Li  * inline.c
3266e18c65b2SHuajun Li  */
3267cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode);
3268cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode);
32694d57b86dSChao Yu void f2fs_do_read_inline_data(struct page *page, struct page *ipage);
32704d57b86dSChao Yu void f2fs_truncate_inline_inode(struct inode *inode,
32714d57b86dSChao Yu 						struct page *ipage, u64 from);
3272cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page);
3273cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page);
3274cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode);
3275cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page);
32764d57b86dSChao Yu bool f2fs_recover_inline_data(struct inode *inode, struct page *npage);
32774d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir,
3278cac5a3d8SDongOh Shin 			struct fscrypt_name *fname, struct page **res_page);
32794d57b86dSChao Yu int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent,
3280cac5a3d8SDongOh Shin 			struct page *ipage);
3281cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
3282cac5a3d8SDongOh Shin 			const struct qstr *orig_name,
3283cac5a3d8SDongOh Shin 			struct inode *inode, nid_t ino, umode_t mode);
32844d57b86dSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry,
32854d57b86dSChao Yu 				struct page *page, struct inode *dir,
32864d57b86dSChao Yu 				struct inode *inode);
3287cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir);
3288cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
3289cac5a3d8SDongOh Shin 			struct fscrypt_str *fstr);
3290cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode,
3291cac5a3d8SDongOh Shin 			struct fiemap_extent_info *fieinfo,
3292cac5a3d8SDongOh Shin 			__u64 start, __u64 len);
3293cde4de12SJaegeuk Kim 
3294cde4de12SJaegeuk Kim /*
32952658e50dSJaegeuk Kim  * shrinker.c
32962658e50dSJaegeuk Kim  */
3297cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink,
3298cac5a3d8SDongOh Shin 			struct shrink_control *sc);
3299cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink,
3300cac5a3d8SDongOh Shin 			struct shrink_control *sc);
3301cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi);
3302cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi);
33032658e50dSJaegeuk Kim 
33042658e50dSJaegeuk Kim /*
3305a28ef1f5SChao Yu  * extent_cache.c
3306a28ef1f5SChao Yu  */
33074d57b86dSChao Yu struct rb_entry *f2fs_lookup_rb_tree(struct rb_root *root,
3308004b6862SChao Yu 				struct rb_entry *cached_re, unsigned int ofs);
33094d57b86dSChao Yu struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi,
3310004b6862SChao Yu 				struct rb_root *root, struct rb_node **parent,
3311004b6862SChao Yu 				unsigned int ofs);
33124d57b86dSChao Yu struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root *root,
3313004b6862SChao Yu 		struct rb_entry *cached_re, unsigned int ofs,
3314004b6862SChao Yu 		struct rb_entry **prev_entry, struct rb_entry **next_entry,
3315004b6862SChao Yu 		struct rb_node ***insert_p, struct rb_node **insert_parent,
3316004b6862SChao Yu 		bool force);
33174d57b86dSChao Yu bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi,
3318df0f6b44SChao Yu 						struct rb_root *root);
3319cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink);
3320cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext);
3321cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode);
3322cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode);
3323cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode);
3324cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs,
3325cac5a3d8SDongOh Shin 			struct extent_info *ei);
3326cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn);
332719b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
3328cac5a3d8SDongOh Shin 			pgoff_t fofs, block_t blkaddr, unsigned int len);
33294d57b86dSChao Yu void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi);
33304d57b86dSChao Yu int __init f2fs_create_extent_cache(void);
33314d57b86dSChao Yu void f2fs_destroy_extent_cache(void);
3332a28ef1f5SChao Yu 
3333a28ef1f5SChao Yu /*
33348ceffcb2SChao Yu  * sysfs.c
33358ceffcb2SChao Yu  */
3336dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void);
3337dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void);
3338dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi);
3339dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi);
33408ceffcb2SChao Yu 
33418ceffcb2SChao Yu /*
3342cde4de12SJaegeuk Kim  * crypto support
3343cde4de12SJaegeuk Kim  */
33440b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode)
3345cde4de12SJaegeuk Kim {
3346cde4de12SJaegeuk Kim 	return file_is_encrypt(inode);
3347cde4de12SJaegeuk Kim }
3348cde4de12SJaegeuk Kim 
33491958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode)
33501958593eSJaegeuk Kim {
33511958593eSJaegeuk Kim 	return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode);
33521958593eSJaegeuk Kim }
33531958593eSJaegeuk Kim 
3354cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode)
3355cde4de12SJaegeuk Kim {
3356cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION
3357cde4de12SJaegeuk Kim 	file_set_encrypt(inode);
33582ee6a576SEric Biggers 	inode->i_flags |= S_ENCRYPTED;
3359cde4de12SJaegeuk Kim #endif
3360cde4de12SJaegeuk Kim }
3361cde4de12SJaegeuk Kim 
33626dbb1796SEric Biggers /*
33636dbb1796SEric Biggers  * Returns true if the reads of the inode's data need to undergo some
33646dbb1796SEric Biggers  * postprocessing step, like decryption or authenticity verification.
33656dbb1796SEric Biggers  */
33666dbb1796SEric Biggers static inline bool f2fs_post_read_required(struct inode *inode)
3367cde4de12SJaegeuk Kim {
33686dbb1796SEric Biggers 	return f2fs_encrypted_file(inode);
3369cde4de12SJaegeuk Kim }
3370cde4de12SJaegeuk Kim 
3371ccd31cb2SSheng Yong #define F2FS_FEATURE_FUNCS(name, flagname) \
3372ccd31cb2SSheng Yong static inline int f2fs_sb_has_##name(struct super_block *sb) \
3373ccd31cb2SSheng Yong { \
3374ccd31cb2SSheng Yong 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_##flagname); \
3375cde4de12SJaegeuk Kim }
3376f424f664SJaegeuk Kim 
3377ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(encrypt, ENCRYPT);
3378ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(blkzoned, BLKZONED);
3379ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR);
3380ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA);
3381ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM);
3382ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR);
3383ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO);
3384ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME);
3385b7c409deSSheng Yong F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND);
33861c1d35dfSChao Yu 
3387178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED
3388178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi,
33893c62be17SJaegeuk Kim 			struct block_device *bdev, block_t blkaddr)
3390178053e2SDamien Le Moal {
3391178053e2SDamien Le Moal 	unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz;
33923c62be17SJaegeuk Kim 	int i;
3393178053e2SDamien Le Moal 
33943c62be17SJaegeuk Kim 	for (i = 0; i < sbi->s_ndevs; i++)
33953c62be17SJaegeuk Kim 		if (FDEV(i).bdev == bdev)
33963c62be17SJaegeuk Kim 			return FDEV(i).blkz_type[zno];
33973c62be17SJaegeuk Kim 	return -EINVAL;
3398178053e2SDamien Le Moal }
3399178053e2SDamien Le Moal #endif
3400178053e2SDamien Le Moal 
340196ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
340296ba2decSDamien Le Moal {
340396ba2decSDamien Le Moal 	struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
340496ba2decSDamien Le Moal 
3405ccd31cb2SSheng Yong 	return blk_queue_discard(q) || f2fs_sb_has_blkzoned(sbi->sb);
340652763a4bSJaegeuk Kim }
340752763a4bSJaegeuk Kim 
340852763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
340952763a4bSJaegeuk Kim {
341052763a4bSJaegeuk Kim 	clear_opt(sbi, ADAPTIVE);
341152763a4bSJaegeuk Kim 	clear_opt(sbi, LFS);
341252763a4bSJaegeuk Kim 
341352763a4bSJaegeuk Kim 	switch (mt) {
341452763a4bSJaegeuk Kim 	case F2FS_MOUNT_ADAPTIVE:
341552763a4bSJaegeuk Kim 		set_opt(sbi, ADAPTIVE);
341652763a4bSJaegeuk Kim 		break;
341752763a4bSJaegeuk Kim 	case F2FS_MOUNT_LFS:
341852763a4bSJaegeuk Kim 		set_opt(sbi, LFS);
341952763a4bSJaegeuk Kim 		break;
342052763a4bSJaegeuk Kim 	}
342152763a4bSJaegeuk Kim }
342252763a4bSJaegeuk Kim 
3423fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode)
3424fcc85a4dSJaegeuk Kim {
3425fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION
3426886f56f9SAl Viro 	umode_t mode = inode->i_mode;
3427fcc85a4dSJaegeuk Kim 
3428fcc85a4dSJaegeuk Kim 	return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
3429fcc85a4dSJaegeuk Kim #else
34306e45f2a5SGustavo A. R. Silva 	return false;
3431fcc85a4dSJaegeuk Kim #endif
3432fcc85a4dSJaegeuk Kim }
3433fcc85a4dSJaegeuk Kim 
3434b91050a8SHyunchul Lee static inline bool f2fs_force_buffered_io(struct inode *inode, int rw)
3435b91050a8SHyunchul Lee {
34366dbb1796SEric Biggers 	return (f2fs_post_read_required(inode) ||
3437b91050a8SHyunchul Lee 			(rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
3438b91050a8SHyunchul Lee 			F2FS_I_SB(inode)->s_ndevs);
3439b91050a8SHyunchul Lee }
3440b91050a8SHyunchul Lee 
344183a3bfdbSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION
3442d494500aSChao Yu extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,
3443d494500aSChao Yu 							unsigned int type);
344483a3bfdbSJaegeuk Kim #else
3445d494500aSChao Yu #define f2fs_build_fault_attr(sbi, rate, type)		do { } while (0)
344683a3bfdbSJaegeuk Kim #endif
344783a3bfdbSJaegeuk Kim 
344839a53e0cSJaegeuk Kim #endif
3449