xref: /openbmc/linux/fs/f2fs/f2fs.h (revision 292c196a3695e57980dc79dea3863462fa4831c4)
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>
2239307a8eSJaegeuk Kim #include <linux/vmalloc.h>
23740432f8SJaegeuk Kim #include <linux/bio.h>
24d0239e1bSJaegeuk Kim #include <linux/blkdev.h>
250abd675eSChao Yu #include <linux/quotaops.h>
2643b6573bSKeith Mok #include <crypto/hash.h>
2739a53e0cSJaegeuk Kim 
28734f0d24SDave Chinner #define __FS_HAS_ENCRYPTION IS_ENABLED(CONFIG_F2FS_FS_ENCRYPTION)
29734f0d24SDave Chinner #include <linux/fscrypt.h>
30734f0d24SDave Chinner 
315d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS
329850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition)	BUG_ON(condition)
335d56b671SJaegeuk Kim #else
349850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition)					\
359850cf4aSJaegeuk Kim 	do {								\
369850cf4aSJaegeuk Kim 		if (unlikely(condition)) {				\
379850cf4aSJaegeuk Kim 			WARN_ON(1);					\
38caf0047eSChao Yu 			set_sbi_flag(sbi, SBI_NEED_FSCK);		\
399850cf4aSJaegeuk Kim 		}							\
409850cf4aSJaegeuk Kim 	} while (0)
415d56b671SJaegeuk Kim #endif
425d56b671SJaegeuk Kim 
432c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION
442c63feadSJaegeuk Kim enum {
452c63feadSJaegeuk Kim 	FAULT_KMALLOC,
46c41f3cc3SJaegeuk Kim 	FAULT_PAGE_ALLOC,
4701eccef7SChao Yu 	FAULT_PAGE_GET,
48d62fe971SChao Yu 	FAULT_ALLOC_BIO,
49cb78942bSJaegeuk Kim 	FAULT_ALLOC_NID,
50cb78942bSJaegeuk Kim 	FAULT_ORPHAN,
51cb78942bSJaegeuk Kim 	FAULT_BLOCK,
52cb78942bSJaegeuk Kim 	FAULT_DIR_DEPTH,
5353aa6bbfSJaegeuk Kim 	FAULT_EVICT_INODE,
5414b44d23SJaegeuk Kim 	FAULT_TRUNCATE,
558b038c70SChao Yu 	FAULT_IO,
560f348028SChao Yu 	FAULT_CHECKPOINT,
572c63feadSJaegeuk Kim 	FAULT_MAX,
582c63feadSJaegeuk Kim };
592c63feadSJaegeuk Kim 
6008796897SSheng Yong struct f2fs_fault_info {
6108796897SSheng Yong 	atomic_t inject_ops;
6208796897SSheng Yong 	unsigned int inject_rate;
6308796897SSheng Yong 	unsigned int inject_type;
6408796897SSheng Yong };
6508796897SSheng Yong 
662c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX];
6768afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
682c63feadSJaegeuk Kim #endif
692c63feadSJaegeuk Kim 
7039a53e0cSJaegeuk Kim /*
7139a53e0cSJaegeuk Kim  * For mount options
7239a53e0cSJaegeuk Kim  */
7339a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC		0x00000001
7439a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD	0x00000002
7539a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD		0x00000004
7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP		0x00000008
7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER		0x00000010
7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL		0x00000020
7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY	0x00000040
80444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR		0x00000080
811001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA		0x00000100
8234d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY	0x00000200
8334d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE		0x00000400
8434d67debSChao Yu #define F2FS_MOUNT_NOBARRIER		0x00000800
85d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT		0x00001000
8689672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE		0x00002000
876aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC		0x00004000
88343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH		0x00008000
8973faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION	0x00010000
9036abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE		0x00020000
9136abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS			0x00040000
920abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA		0x00080000
930abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA		0x00100000
945c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA		0x00200000
954b2414d0SChao Yu #define F2FS_MOUNT_QUOTA		0x00400000
966afc662eSChao Yu #define F2FS_MOUNT_INLINE_XATTR_SIZE	0x00800000
9739a53e0cSJaegeuk Kim 
9868afcf2dSTomohiro Kusumi #define clear_opt(sbi, option)	((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option)
9968afcf2dSTomohiro Kusumi #define set_opt(sbi, option)	((sbi)->mount_opt.opt |= F2FS_MOUNT_##option)
10068afcf2dSTomohiro Kusumi #define test_opt(sbi, option)	((sbi)->mount_opt.opt & F2FS_MOUNT_##option)
10139a53e0cSJaegeuk Kim 
10239a53e0cSJaegeuk Kim #define ver_after(a, b)	(typecheck(unsigned long long, a) &&		\
10339a53e0cSJaegeuk Kim 		typecheck(unsigned long long, b) &&			\
10439a53e0cSJaegeuk Kim 		((long long)((a) - (b)) > 0))
10539a53e0cSJaegeuk Kim 
106a9841c4dSJaegeuk Kim typedef u32 block_t;	/*
107a9841c4dSJaegeuk Kim 			 * should not change u32, since it is the on-disk block
108a9841c4dSJaegeuk Kim 			 * address format, __le32.
109a9841c4dSJaegeuk Kim 			 */
11039a53e0cSJaegeuk Kim typedef u32 nid_t;
11139a53e0cSJaegeuk Kim 
11239a53e0cSJaegeuk Kim struct f2fs_mount_info {
11339a53e0cSJaegeuk Kim 	unsigned int	opt;
11439a53e0cSJaegeuk Kim };
11539a53e0cSJaegeuk Kim 
116cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT		0x0001
1170bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED		0x0002
118e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE	0x0004
1197a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR		0x0008
1205c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA		0x0010
121704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM	0x0020
1226afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR	0x0040
123234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO		0x0080
124cde4de12SJaegeuk Kim 
12576f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask)					\
12676f105a2SJaegeuk Kim 	((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
12776f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask)					\
128c64ab12eSDongOh Shin 	(F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask))
12976f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask)					\
130c64ab12eSDongOh Shin 	(F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask))
13176f105a2SJaegeuk Kim 
13239a53e0cSJaegeuk Kim /*
13339a53e0cSJaegeuk Kim  * For checkpoint manager
13439a53e0cSJaegeuk Kim  */
13539a53e0cSJaegeuk Kim enum {
13639a53e0cSJaegeuk Kim 	NAT_BITMAP,
13739a53e0cSJaegeuk Kim 	SIT_BITMAP
13839a53e0cSJaegeuk Kim };
13939a53e0cSJaegeuk Kim 
140c473f1a9SChao Yu #define	CP_UMOUNT	0x00000001
141c473f1a9SChao Yu #define	CP_FASTBOOT	0x00000002
142c473f1a9SChao Yu #define	CP_SYNC		0x00000004
143c473f1a9SChao Yu #define	CP_RECOVERY	0x00000008
144c473f1a9SChao Yu #define	CP_DISCARD	0x00000010
1451f43e2adSChao Yu #define CP_TRIMMED	0x00000020
14675ab4cb8SJaegeuk Kim 
14747b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS	2048
148bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi)	\
1494ddb1a4dSJaegeuk Kim 		(GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections))
150a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi)	\
151a66cdd98SJaegeuk Kim 		(BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
1524ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi)		BLKS_PER_SEC(sbi)
153ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST		8	/* issue 8 discards per round */
154969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME	50	/* 50 ms, if exists */
155969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME	60000	/* 60 s, if no candidates */
15660b99b48SJaegeuk Kim #define DEF_CP_INTERVAL			60	/* 60 secs */
157dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL		5	/* 5 secs */
158bba681cbSJaegeuk Kim 
15975ab4cb8SJaegeuk Kim struct cp_control {
16075ab4cb8SJaegeuk Kim 	int reason;
1614b2fecc8SJaegeuk Kim 	__u64 trim_start;
1624b2fecc8SJaegeuk Kim 	__u64 trim_end;
1634b2fecc8SJaegeuk Kim 	__u64 trim_minlen;
16475ab4cb8SJaegeuk Kim };
16575ab4cb8SJaegeuk Kim 
166662befdaSChao Yu /*
16781c1a0f1SChao Yu  * For CP/NAT/SIT/SSA readahead
168662befdaSChao Yu  */
169662befdaSChao Yu enum {
170662befdaSChao Yu 	META_CP,
171662befdaSChao Yu 	META_NAT,
17281c1a0f1SChao Yu 	META_SIT,
1734c521f49SJaegeuk Kim 	META_SSA,
1744c521f49SJaegeuk Kim 	META_POR,
175662befdaSChao Yu };
176662befdaSChao Yu 
1776451e041SJaegeuk Kim /* for the list of ino */
1786451e041SJaegeuk Kim enum {
1796451e041SJaegeuk Kim 	ORPHAN_INO,		/* for orphan ino list */
180fff04f90SJaegeuk Kim 	APPEND_INO,		/* for append ino list */
181fff04f90SJaegeuk Kim 	UPDATE_INO,		/* for update ino list */
18239d787beSChao Yu 	FLUSH_INO,		/* for multiple device flushing */
1836451e041SJaegeuk Kim 	MAX_INO_ENTRY,		/* max. list */
1846451e041SJaegeuk Kim };
1856451e041SJaegeuk Kim 
1866451e041SJaegeuk Kim struct ino_entry {
18739a53e0cSJaegeuk Kim 	struct list_head list;		/* list head */
18839a53e0cSJaegeuk Kim 	nid_t ino;			/* inode number */
18939d787beSChao Yu 	unsigned int dirty_device;	/* dirty device bitmap */
19039a53e0cSJaegeuk Kim };
19139a53e0cSJaegeuk Kim 
1922710fd7eSChao Yu /* for the list of inodes to be GCed */
19306292073SChao Yu struct inode_entry {
19439a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
19539a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
19639a53e0cSJaegeuk Kim };
19739a53e0cSJaegeuk Kim 
198a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */
1997fd9e544SJaegeuk Kim struct discard_entry {
2007fd9e544SJaegeuk Kim 	struct list_head list;	/* list head */
201a7eeb823SChao Yu 	block_t start_blkaddr;	/* start blockaddr of current segment */
202a7eeb823SChao Yu 	unsigned char discard_map[SIT_VBLOCK_MAP_SIZE];	/* segment discard bitmap */
2037fd9e544SJaegeuk Kim };
2047fd9e544SJaegeuk Kim 
205969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */
206969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY		16
207969d1b18SChao Yu 
208ba48a33eSChao Yu /* max discard pend list number */
209ba48a33eSChao Yu #define MAX_PLIST_NUM		512
210ba48a33eSChao Yu #define plist_idx(blk_num)	((blk_num) >= MAX_PLIST_NUM ?		\
211ba48a33eSChao Yu 					(MAX_PLIST_NUM - 1) : (blk_num - 1))
212ba48a33eSChao Yu 
21315469963SJaegeuk Kim enum {
21415469963SJaegeuk Kim 	D_PREP,
21515469963SJaegeuk Kim 	D_SUBMIT,
21615469963SJaegeuk Kim 	D_DONE,
21715469963SJaegeuk Kim };
21815469963SJaegeuk Kim 
219004b6862SChao Yu struct discard_info {
220b01a9201SJaegeuk Kim 	block_t lstart;			/* logical start address */
221b01a9201SJaegeuk Kim 	block_t len;			/* length */
222004b6862SChao Yu 	block_t start;			/* actual start address in dev */
223004b6862SChao Yu };
224004b6862SChao Yu 
225b01a9201SJaegeuk Kim struct discard_cmd {
226004b6862SChao Yu 	struct rb_node rb_node;		/* rb node located in rb-tree */
227004b6862SChao Yu 	union {
228004b6862SChao Yu 		struct {
229004b6862SChao Yu 			block_t lstart;	/* logical start address */
230004b6862SChao Yu 			block_t len;	/* length */
231004b6862SChao Yu 			block_t start;	/* actual start address in dev */
232004b6862SChao Yu 		};
233004b6862SChao Yu 		struct discard_info di;	/* discard info */
234004b6862SChao Yu 
235004b6862SChao Yu 	};
236b01a9201SJaegeuk Kim 	struct list_head list;		/* command list */
237b01a9201SJaegeuk Kim 	struct completion wait;		/* compleation */
238c81abe34SJaegeuk Kim 	struct block_device *bdev;	/* bdev */
239ec9895adSChao Yu 	unsigned short ref;		/* reference count */
2409a744b92SChao Yu 	unsigned char state;		/* state */
241c81abe34SJaegeuk Kim 	int error;			/* bio error */
242275b66b0SChao Yu };
243275b66b0SChao Yu 
24478997b56SChao Yu enum {
24578997b56SChao Yu 	DPOLICY_BG,
24678997b56SChao Yu 	DPOLICY_FORCE,
24778997b56SChao Yu 	DPOLICY_FSTRIM,
24878997b56SChao Yu 	DPOLICY_UMOUNT,
24978997b56SChao Yu 	MAX_DPOLICY,
25078997b56SChao Yu };
25178997b56SChao Yu 
252ecc9aa00SChao Yu struct discard_policy {
25378997b56SChao Yu 	int type;			/* type of discard */
254ecc9aa00SChao Yu 	unsigned int min_interval;	/* used for candidates exist */
255ecc9aa00SChao Yu 	unsigned int max_interval;	/* used for candidates not exist */
256ecc9aa00SChao Yu 	unsigned int max_requests;	/* # of discards issued per round */
257ecc9aa00SChao Yu 	unsigned int io_aware_gran;	/* minimum granularity discard not be aware of I/O */
258ecc9aa00SChao Yu 	bool io_aware;			/* issue discard in idle time */
259ecc9aa00SChao Yu 	bool sync;			/* submit discard with REQ_SYNC flag */
26078997b56SChao Yu 	unsigned int granularity;	/* discard granularity */
261ecc9aa00SChao Yu };
262ecc9aa00SChao Yu 
2630b54fb84SJaegeuk Kim struct discard_cmd_control {
26415469963SJaegeuk Kim 	struct task_struct *f2fs_issue_discard;	/* discard thread */
26546f84c2cSChao Yu 	struct list_head entry_list;		/* 4KB discard entry list */
266ba48a33eSChao Yu 	struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */
267969d1b18SChao Yu 	unsigned char pend_list_tag[MAX_PLIST_NUM];/* tag for pending entries */
26846f84c2cSChao Yu 	struct list_head wait_list;		/* store on-flushing entries */
2698412663dSChao Yu 	struct list_head fstrim_list;		/* in-flight discard from fstrim */
27015469963SJaegeuk Kim 	wait_queue_head_t discard_wait_queue;	/* waiting queue for wake-up */
271969d1b18SChao Yu 	unsigned int discard_wake;		/* to wake up discard thread */
27215469963SJaegeuk Kim 	struct mutex cmd_lock;
273d618ebafSChao Yu 	unsigned int nr_discards;		/* # of discards in the list */
274d618ebafSChao Yu 	unsigned int max_discards;		/* max. discards to be issued */
275969d1b18SChao Yu 	unsigned int discard_granularity;	/* discard granularity */
276d84d1cbdSChao Yu 	unsigned int undiscard_blks;		/* # of undiscard blocks */
2778b8dd65fSChao Yu 	atomic_t issued_discard;		/* # of issued discard */
2788b8dd65fSChao Yu 	atomic_t issing_discard;		/* # of issing discard */
2795f32366aSChao Yu 	atomic_t discard_cmd_cnt;		/* # of cached cmd count */
280004b6862SChao Yu 	struct rb_root root;			/* root of discard rb-tree */
28139a53e0cSJaegeuk Kim };
28239a53e0cSJaegeuk Kim 
28339a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */
28439a53e0cSJaegeuk Kim struct fsync_inode_entry {
28539a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
28639a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
287c52e1b10SJaegeuk Kim 	block_t blkaddr;	/* block address locating the last fsync */
288c52e1b10SJaegeuk Kim 	block_t last_dentry;	/* block address locating the last dentry */
28939a53e0cSJaegeuk Kim };
29039a53e0cSJaegeuk Kim 
29168afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl)		(le16_to_cpu((jnl)->n_nats))
29268afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl)		(le16_to_cpu((jnl)->n_sits))
29339a53e0cSJaegeuk Kim 
29468afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i)		((jnl)->nat_j.entries[i].ne)
29568afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i)		((jnl)->nat_j.entries[i].nid)
29668afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i)		((jnl)->sit_j.entries[i].se)
29768afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i)	((jnl)->sit_j.entries[i].segno)
29839a53e0cSJaegeuk Kim 
299dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl)	(NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl))
300dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl)	(SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl))
301309cc2b6SJaegeuk Kim 
302dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i)
30339a53e0cSJaegeuk Kim {
304dfc08a12SChao Yu 	int before = nats_in_cursum(journal);
305cac5a3d8SDongOh Shin 
306dfc08a12SChao Yu 	journal->n_nats = cpu_to_le16(before + i);
30739a53e0cSJaegeuk Kim 	return before;
30839a53e0cSJaegeuk Kim }
30939a53e0cSJaegeuk Kim 
310dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i)
31139a53e0cSJaegeuk Kim {
312dfc08a12SChao Yu 	int before = sits_in_cursum(journal);
313cac5a3d8SDongOh Shin 
314dfc08a12SChao Yu 	journal->n_sits = cpu_to_le16(before + i);
31539a53e0cSJaegeuk Kim 	return before;
31639a53e0cSJaegeuk Kim }
31739a53e0cSJaegeuk Kim 
318dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal,
319dfc08a12SChao Yu 							int size, int type)
320184a5cd2SChao Yu {
321184a5cd2SChao Yu 	if (type == NAT_JOURNAL)
322dfc08a12SChao Yu 		return size <= MAX_NAT_JENTRIES(journal);
323dfc08a12SChao Yu 	return size <= MAX_SIT_JENTRIES(journal);
324184a5cd2SChao Yu }
325184a5cd2SChao Yu 
32639a53e0cSJaegeuk Kim /*
327e9750824SNamjae Jeon  * ioctl commands
328e9750824SNamjae Jeon  */
329e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS		FS_IOC_GETFLAGS
330e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS		FS_IOC_SETFLAGS
331d49f3e89SChao Yu #define F2FS_IOC_GETVERSION		FS_IOC_GETVERSION
332e9750824SNamjae Jeon 
33388b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC		0xf5
33488b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE	_IO(F2FS_IOCTL_MAGIC, 1)
33588b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE	_IO(F2FS_IOCTL_MAGIC, 2)
33602a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 3)
3371e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 4)
3381e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 5)
339d07efb50SJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT	_IOW(F2FS_IOCTL_MAGIC, 6, __u32)
340456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT	_IO(F2FS_IOCTL_MAGIC, 7)
341d07efb50SJaegeuk Kim #define F2FS_IOC_DEFRAGMENT		_IOWR(F2FS_IOCTL_MAGIC, 8,	\
342d07efb50SJaegeuk Kim 						struct f2fs_defragment)
3434dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE		_IOWR(F2FS_IOCTL_MAGIC, 9,	\
3444dd6f977SJaegeuk Kim 						struct f2fs_move_range)
345e066b83cSJaegeuk Kim #define F2FS_IOC_FLUSH_DEVICE		_IOW(F2FS_IOCTL_MAGIC, 10,	\
346e066b83cSJaegeuk Kim 						struct f2fs_flush_device)
34734dc77adSJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT_RANGE	_IOW(F2FS_IOCTL_MAGIC, 11,	\
34834dc77adSJaegeuk Kim 						struct f2fs_gc_range)
349e65ef207SJaegeuk Kim #define F2FS_IOC_GET_FEATURES		_IOR(F2FS_IOCTL_MAGIC, 12, __u32)
35088b88a66SJaegeuk Kim 
3510b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY	FS_IOC_SET_ENCRYPTION_POLICY
3520b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY	FS_IOC_GET_ENCRYPTION_POLICY
3530b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT	FS_IOC_GET_ENCRYPTION_PWSALT
354f424f664SJaegeuk Kim 
3551abff93dSJaegeuk Kim /*
3561abff93dSJaegeuk Kim  * should be same as XFS_IOC_GOINGDOWN.
3571abff93dSJaegeuk Kim  * Flags for going down operation used by FS_IOC_GOINGDOWN
3581abff93dSJaegeuk Kim  */
3591abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN	_IOR('X', 125, __u32)	/* Shutdown */
3601abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC	0x0	/* going down with full sync */
3611abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC	0x1	/* going down with metadata */
3621abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC		0x2	/* going down */
363c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH	0x3	/* going down with meta flush */
3641abff93dSJaegeuk Kim 
365e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
366e9750824SNamjae Jeon /*
367e9750824SNamjae Jeon  * ioctl commands in 32 bit emulation
368e9750824SNamjae Jeon  */
369e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS		FS_IOC32_GETFLAGS
370e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS		FS_IOC32_SETFLAGS
37104ef4b62SChao Yu #define F2FS_IOC32_GETVERSION		FS_IOC32_GETVERSION
372e9750824SNamjae Jeon #endif
373e9750824SNamjae Jeon 
3742c1d0305SChao Yu #define F2FS_IOC_FSGETXATTR		FS_IOC_FSGETXATTR
3752c1d0305SChao Yu #define F2FS_IOC_FSSETXATTR		FS_IOC_FSSETXATTR
3762c1d0305SChao Yu 
37734dc77adSJaegeuk Kim struct f2fs_gc_range {
37834dc77adSJaegeuk Kim 	u32 sync;
37934dc77adSJaegeuk Kim 	u64 start;
38034dc77adSJaegeuk Kim 	u64 len;
38134dc77adSJaegeuk Kim };
38234dc77adSJaegeuk Kim 
383d323d005SChao Yu struct f2fs_defragment {
384d323d005SChao Yu 	u64 start;
385d323d005SChao Yu 	u64 len;
386d323d005SChao Yu };
387d323d005SChao Yu 
3884dd6f977SJaegeuk Kim struct f2fs_move_range {
3894dd6f977SJaegeuk Kim 	u32 dst_fd;		/* destination fd */
3904dd6f977SJaegeuk Kim 	u64 pos_in;		/* start position in src_fd */
3914dd6f977SJaegeuk Kim 	u64 pos_out;		/* start position in dst_fd */
3924dd6f977SJaegeuk Kim 	u64 len;		/* size to move */
3934dd6f977SJaegeuk Kim };
3944dd6f977SJaegeuk Kim 
395e066b83cSJaegeuk Kim struct f2fs_flush_device {
396e066b83cSJaegeuk Kim 	u32 dev_num;		/* device number to flush */
397e066b83cSJaegeuk Kim 	u32 segments;		/* # of segments to flush */
398e066b83cSJaegeuk Kim };
399e066b83cSJaegeuk Kim 
400f2470371SChao Yu /* for inline stuff */
401f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE	1
4026afc662eSChao Yu #define DEF_MIN_INLINE_SIZE		1
4037a2af766SChao Yu static inline int get_extra_isize(struct inode *inode);
4046afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode);
4056afc662eSChao Yu #define F2FS_INLINE_XATTR_ADDRS(inode)	get_inline_xattr_addrs(inode)
4067a2af766SChao Yu #define MAX_INLINE_DATA(inode)	(sizeof(__le32) *			\
4077a2af766SChao Yu 				(CUR_ADDRS_PER_INODE(inode) -		\
4086afc662eSChao Yu 				F2FS_INLINE_XATTR_ADDRS(inode) -	\
4096afc662eSChao Yu 				DEF_INLINE_RESERVED_SIZE))
410f2470371SChao Yu 
411f2470371SChao Yu /* for inline dir */
412f2470371SChao Yu #define NR_INLINE_DENTRY(inode)	(MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \
413f2470371SChao Yu 				((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
414f2470371SChao Yu 				BITS_PER_BYTE + 1))
415f2470371SChao Yu #define INLINE_DENTRY_BITMAP_SIZE(inode)	((NR_INLINE_DENTRY(inode) + \
416f2470371SChao Yu 					BITS_PER_BYTE - 1) / BITS_PER_BYTE)
417f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode)	(MAX_INLINE_DATA(inode) - \
418f2470371SChao Yu 				((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
419f2470371SChao Yu 				NR_INLINE_DENTRY(inode) + \
420f2470371SChao Yu 				INLINE_DENTRY_BITMAP_SIZE(inode)))
421f2470371SChao Yu 
422e9750824SNamjae Jeon /*
42339a53e0cSJaegeuk Kim  * For INODE and NODE manager
42439a53e0cSJaegeuk Kim  */
4257b3cd7d6SJaegeuk Kim /* for directory operations */
4267b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr {
427d8c6822aSJaegeuk Kim 	struct inode *inode;
42876a9dd85SChao Yu 	void *bitmap;
4297b3cd7d6SJaegeuk Kim 	struct f2fs_dir_entry *dentry;
4307b3cd7d6SJaegeuk Kim 	__u8 (*filename)[F2FS_SLOT_LEN];
4317b3cd7d6SJaegeuk Kim 	int max;
43276a9dd85SChao Yu 	int nr_bitmap;
4337b3cd7d6SJaegeuk Kim };
4347b3cd7d6SJaegeuk Kim 
43564c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode,
43664c24ecbSTomohiro Kusumi 		struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t)
4377b3cd7d6SJaegeuk Kim {
438d8c6822aSJaegeuk Kim 	d->inode = inode;
4397b3cd7d6SJaegeuk Kim 	d->max = NR_DENTRY_IN_BLOCK;
44076a9dd85SChao Yu 	d->nr_bitmap = SIZE_OF_DENTRY_BITMAP;
4417b3cd7d6SJaegeuk Kim 	d->bitmap = &t->dentry_bitmap;
4427b3cd7d6SJaegeuk Kim 	d->dentry = t->dentry;
4437b3cd7d6SJaegeuk Kim 	d->filename = t->filename;
44464c24ecbSTomohiro Kusumi }
445cac5a3d8SDongOh Shin 
44664c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode,
447f2470371SChao Yu 					struct f2fs_dentry_ptr *d, void *t)
44864c24ecbSTomohiro Kusumi {
449f2470371SChao Yu 	int entry_cnt = NR_INLINE_DENTRY(inode);
450f2470371SChao Yu 	int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode);
451f2470371SChao Yu 	int reserved_size = INLINE_RESERVED_SIZE(inode);
452f2470371SChao Yu 
45364c24ecbSTomohiro Kusumi 	d->inode = inode;
454f2470371SChao Yu 	d->max = entry_cnt;
455f2470371SChao Yu 	d->nr_bitmap = bitmap_size;
456f2470371SChao Yu 	d->bitmap = t;
457f2470371SChao Yu 	d->dentry = t + bitmap_size + reserved_size;
458f2470371SChao Yu 	d->filename = t + bitmap_size + reserved_size +
459f2470371SChao Yu 					SIZE_OF_DIR_ENTRY * entry_cnt;
4607b3cd7d6SJaegeuk Kim }
4617b3cd7d6SJaegeuk Kim 
462dbe6a5ffSJaegeuk Kim /*
463dbe6a5ffSJaegeuk Kim  * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
464dbe6a5ffSJaegeuk Kim  * as its node offset to distinguish from index node blocks.
465dbe6a5ffSJaegeuk Kim  * But some bits are used to mark the node block.
46639a53e0cSJaegeuk Kim  */
467dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET	((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
468dbe6a5ffSJaegeuk Kim 				>> OFFSET_BIT_SHIFT)
469266e97a8SJaegeuk Kim enum {
470266e97a8SJaegeuk Kim 	ALLOC_NODE,			/* allocate a new node page if needed */
471266e97a8SJaegeuk Kim 	LOOKUP_NODE,			/* look up a node without readahead */
472266e97a8SJaegeuk Kim 	LOOKUP_NODE_RA,			/*
473266e97a8SJaegeuk Kim 					 * look up a node with readahead called
4744f4124d0SChao Yu 					 * by get_data_block.
47539a53e0cSJaegeuk Kim 					 */
476266e97a8SJaegeuk Kim };
477266e97a8SJaegeuk Kim 
478a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX	0xffffffff	/* maximum link count per file */
47939a53e0cSJaegeuk Kim 
480817202d9SChao Yu #define MAX_DIR_RA_PAGES	4	/* maximum ra pages of dir */
481817202d9SChao Yu 
48213054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */
48313054c54SChao Yu #define EXT_TREE_VEC_SIZE	64
48413054c54SChao Yu 
48539a53e0cSJaegeuk Kim /* for in-memory extent cache entry */
48613054c54SChao Yu #define F2FS_MIN_EXTENT_LEN	64	/* minimum extent length */
48713054c54SChao Yu 
48813054c54SChao Yu /* number of extent info in extent cache we try to shrink */
48913054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER	128
490c11abd1aSJaegeuk Kim 
49154c2258cSChao Yu struct rb_entry {
49254c2258cSChao Yu 	struct rb_node rb_node;		/* rb node located in rb-tree */
49354c2258cSChao Yu 	unsigned int ofs;		/* start offset of the entry */
49454c2258cSChao Yu 	unsigned int len;		/* length of the entry */
49554c2258cSChao Yu };
49654c2258cSChao Yu 
49739a53e0cSJaegeuk Kim struct extent_info {
49839a53e0cSJaegeuk Kim 	unsigned int fofs;		/* start offset in a file */
499111d2495SMasanari Iida 	unsigned int len;		/* length of the extent */
50054c2258cSChao Yu 	u32 blk;			/* start block address of the extent */
50139a53e0cSJaegeuk Kim };
50239a53e0cSJaegeuk Kim 
50313054c54SChao Yu struct extent_node {
50454c2258cSChao Yu 	struct rb_node rb_node;
50554c2258cSChao Yu 	union {
50654c2258cSChao Yu 		struct {
50754c2258cSChao Yu 			unsigned int fofs;
50854c2258cSChao Yu 			unsigned int len;
50954c2258cSChao Yu 			u32 blk;
51054c2258cSChao Yu 		};
51113054c54SChao Yu 		struct extent_info ei;	/* extent info */
51254c2258cSChao Yu 
51354c2258cSChao Yu 	};
51454c2258cSChao Yu 	struct list_head list;		/* node in global extent list of sbi */
515201ef5e0SHou Pengyang 	struct extent_tree *et;		/* extent tree pointer */
51613054c54SChao Yu };
51713054c54SChao Yu 
51813054c54SChao Yu struct extent_tree {
51913054c54SChao Yu 	nid_t ino;			/* inode number */
52013054c54SChao Yu 	struct rb_root root;		/* root of extent info rb-tree */
52162c8af65SChao Yu 	struct extent_node *cached_en;	/* recently accessed extent node */
5223e72f721SJaegeuk Kim 	struct extent_info largest;	/* largested extent info */
523137d09f0SJaegeuk Kim 	struct list_head list;		/* to be used by sbi->zombie_list */
52413054c54SChao Yu 	rwlock_t lock;			/* protect extent info rb-tree */
52568e35385SChao Yu 	atomic_t node_cnt;		/* # of extent node in rb-tree*/
52613054c54SChao Yu };
52713054c54SChao Yu 
52839a53e0cSJaegeuk Kim /*
529003a3e1dSJaegeuk Kim  * This structure is taken from ext4_map_blocks.
530003a3e1dSJaegeuk Kim  *
531003a3e1dSJaegeuk Kim  * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
532003a3e1dSJaegeuk Kim  */
533003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW		(1 << BH_New)
534003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED		(1 << BH_Mapped)
5357f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN	(1 << BH_Unwritten)
5367f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS		(F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
5377f63eb77SJaegeuk Kim 				F2FS_MAP_UNWRITTEN)
538003a3e1dSJaegeuk Kim 
539003a3e1dSJaegeuk Kim struct f2fs_map_blocks {
540003a3e1dSJaegeuk Kim 	block_t m_pblk;
541003a3e1dSJaegeuk Kim 	block_t m_lblk;
542003a3e1dSJaegeuk Kim 	unsigned int m_len;
543003a3e1dSJaegeuk Kim 	unsigned int m_flags;
544da85985cSChao Yu 	pgoff_t *m_next_pgofs;		/* point next possible non-hole pgofs */
545003a3e1dSJaegeuk Kim };
546003a3e1dSJaegeuk Kim 
547e2b4e2bcSChao Yu /* for flag in get_data_block */
548f2220c7fSQiuyang Sun enum {
549f2220c7fSQiuyang Sun 	F2FS_GET_BLOCK_DEFAULT,
550f2220c7fSQiuyang Sun 	F2FS_GET_BLOCK_FIEMAP,
551f2220c7fSQiuyang Sun 	F2FS_GET_BLOCK_BMAP,
552f2220c7fSQiuyang Sun 	F2FS_GET_BLOCK_PRE_DIO,
553f2220c7fSQiuyang Sun 	F2FS_GET_BLOCK_PRE_AIO,
554f2220c7fSQiuyang Sun };
555e2b4e2bcSChao Yu 
556003a3e1dSJaegeuk Kim /*
55739a53e0cSJaegeuk Kim  * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
55839a53e0cSJaegeuk Kim  */
55939a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT	0x01
560354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT	0x02
561cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT	0x04
562e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT	0x08
56326787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT	0x10
56439a53e0cSJaegeuk Kim 
565b5492af7SJaegeuk Kim #define file_is_cold(inode)	is_file(inode, FADVISE_COLD_BIT)
566b5492af7SJaegeuk Kim #define file_wrong_pino(inode)	is_file(inode, FADVISE_LOST_PINO_BIT)
567b5492af7SJaegeuk Kim #define file_set_cold(inode)	set_file(inode, FADVISE_COLD_BIT)
568b5492af7SJaegeuk Kim #define file_lost_pino(inode)	set_file(inode, FADVISE_LOST_PINO_BIT)
569b5492af7SJaegeuk Kim #define file_clear_cold(inode)	clear_file(inode, FADVISE_COLD_BIT)
570b5492af7SJaegeuk Kim #define file_got_pino(inode)	clear_file(inode, FADVISE_LOST_PINO_BIT)
571cde4de12SJaegeuk Kim #define file_is_encrypt(inode)	is_file(inode, FADVISE_ENCRYPT_BIT)
572cde4de12SJaegeuk Kim #define file_set_encrypt(inode)	set_file(inode, FADVISE_ENCRYPT_BIT)
573cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT)
574e7d55452SJaegeuk Kim #define file_enc_name(inode)	is_file(inode, FADVISE_ENC_NAME_BIT)
575e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
57626787236SJaegeuk Kim #define file_keep_isize(inode)	is_file(inode, FADVISE_KEEP_SIZE_BIT)
57726787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT)
578cde4de12SJaegeuk Kim 
579ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL		0
580ab9fa662SJaegeuk Kim 
58139a53e0cSJaegeuk Kim struct f2fs_inode_info {
58239a53e0cSJaegeuk Kim 	struct inode vfs_inode;		/* serve a vfs inode */
58339a53e0cSJaegeuk Kim 	unsigned long i_flags;		/* keep an inode flags for ioctl */
58439a53e0cSJaegeuk Kim 	unsigned char i_advise;		/* use to give file attribute hints */
58538431545SJaegeuk Kim 	unsigned char i_dir_level;	/* use for dentry level for large dir */
58639a53e0cSJaegeuk Kim 	unsigned int i_current_depth;	/* use only in directory structure */
5876666e6aaSJaegeuk Kim 	unsigned int i_pino;		/* parent inode number */
58839a53e0cSJaegeuk Kim 	umode_t i_acl_mode;		/* keep file acl mode temporarily */
58939a53e0cSJaegeuk Kim 
59039a53e0cSJaegeuk Kim 	/* Use below internally in f2fs*/
59139a53e0cSJaegeuk Kim 	unsigned long flags;		/* use to pass per-file flags */
592d928bfbfSJaegeuk Kim 	struct rw_semaphore i_sem;	/* protect fi info */
593204706c7SJaegeuk Kim 	atomic_t dirty_pages;		/* # of dirty pages */
59439a53e0cSJaegeuk Kim 	f2fs_hash_t chash;		/* hash value of given file name */
59539a53e0cSJaegeuk Kim 	unsigned int clevel;		/* maximum level of given file name */
59688c5c13aSJaegeuk Kim 	struct task_struct *task;	/* lookup and create consistency */
597b0af6d49SChao Yu 	struct task_struct *cp_task;	/* separate cp/wb IO stats*/
59839a53e0cSJaegeuk Kim 	nid_t i_xattr_nid;		/* node id that contains xattrs */
59926de9b11SJaegeuk Kim 	loff_t	last_disk_size;		/* lastly written file size */
60088b88a66SJaegeuk Kim 
6010abd675eSChao Yu #ifdef CONFIG_QUOTA
6020abd675eSChao Yu 	struct dquot *i_dquot[MAXQUOTAS];
6030abd675eSChao Yu 
6040abd675eSChao Yu 	/* quota space reservation, managed internally by quota code */
6050abd675eSChao Yu 	qsize_t i_reserved_quota;
6060abd675eSChao Yu #endif
6070f18b462SJaegeuk Kim 	struct list_head dirty_list;	/* dirty list for dirs and files */
6080f18b462SJaegeuk Kim 	struct list_head gdirty_list;	/* linked in global dirty list */
60957864ae5SJaegeuk Kim 	struct list_head inmem_ilist;	/* list for inmem inodes */
61088b88a66SJaegeuk Kim 	struct list_head inmem_pages;	/* inmemory pages managed by f2fs */
6117a10f017SJaegeuk Kim 	struct task_struct *inmem_task;	/* store inmemory task */
61288b88a66SJaegeuk Kim 	struct mutex inmem_lock;	/* lock for inmemory pages */
6133e72f721SJaegeuk Kim 	struct extent_tree *extent_tree;	/* cached extent_tree entry */
61482e0a5aaSChao Yu 	struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */
6155a3a2d83SQiuyang Sun 	struct rw_semaphore i_mmap_sem;
61627161f13SYunlei He 	struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */
617f2470371SChao Yu 
6187a2af766SChao Yu 	int i_extra_isize;		/* size of extra space located in i_addr */
6195c57132eSChao Yu 	kprojid_t i_projid;		/* id for project quota */
6206afc662eSChao Yu 	int i_inline_xattr_size;	/* inline xattr size */
62139a53e0cSJaegeuk Kim };
62239a53e0cSJaegeuk Kim 
62339a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext,
624bd933d4fSChao Yu 					struct f2fs_extent *i_ext)
62539a53e0cSJaegeuk Kim {
626bd933d4fSChao Yu 	ext->fofs = le32_to_cpu(i_ext->fofs);
627bd933d4fSChao Yu 	ext->blk = le32_to_cpu(i_ext->blk);
628bd933d4fSChao Yu 	ext->len = le32_to_cpu(i_ext->len);
62939a53e0cSJaegeuk Kim }
63039a53e0cSJaegeuk Kim 
63139a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext,
63239a53e0cSJaegeuk Kim 					struct f2fs_extent *i_ext)
63339a53e0cSJaegeuk Kim {
63439a53e0cSJaegeuk Kim 	i_ext->fofs = cpu_to_le32(ext->fofs);
6354d0b0bd4SChao Yu 	i_ext->blk = cpu_to_le32(ext->blk);
63639a53e0cSJaegeuk Kim 	i_ext->len = cpu_to_le32(ext->len);
63739a53e0cSJaegeuk Kim }
63839a53e0cSJaegeuk Kim 
639429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
640429511cdSChao Yu 						u32 blk, unsigned int len)
641429511cdSChao Yu {
642429511cdSChao Yu 	ei->fofs = fofs;
643429511cdSChao Yu 	ei->blk = blk;
644429511cdSChao Yu 	ei->len = len;
645429511cdSChao Yu }
646429511cdSChao Yu 
647004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back,
648004b6862SChao Yu 						struct discard_info *front)
649004b6862SChao Yu {
650004b6862SChao Yu 	return back->lstart + back->len == front->lstart;
651004b6862SChao Yu }
652004b6862SChao Yu 
653004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur,
654004b6862SChao Yu 						struct discard_info *back)
655004b6862SChao Yu {
656004b6862SChao Yu 	return __is_discard_mergeable(back, cur);
657004b6862SChao Yu }
658004b6862SChao Yu 
659004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur,
660004b6862SChao Yu 						struct discard_info *front)
661004b6862SChao Yu {
662004b6862SChao Yu 	return __is_discard_mergeable(cur, front);
663004b6862SChao Yu }
664004b6862SChao Yu 
665429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back,
666429511cdSChao Yu 						struct extent_info *front)
667429511cdSChao Yu {
668429511cdSChao Yu 	return (back->fofs + back->len == front->fofs &&
669429511cdSChao Yu 			back->blk + back->len == front->blk);
670429511cdSChao Yu }
671429511cdSChao Yu 
672429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur,
673429511cdSChao Yu 						struct extent_info *back)
674429511cdSChao Yu {
675429511cdSChao Yu 	return __is_extent_mergeable(back, cur);
676429511cdSChao Yu }
677429511cdSChao Yu 
678429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur,
679429511cdSChao Yu 						struct extent_info *front)
680429511cdSChao Yu {
681429511cdSChao Yu 	return __is_extent_mergeable(cur, front);
682429511cdSChao Yu }
683429511cdSChao Yu 
684cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync);
685205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode,
686205b9822SJaegeuk Kim 			struct extent_tree *et, struct extent_node *en)
6874abd3f5aSChao Yu {
688205b9822SJaegeuk Kim 	if (en->ei.len > et->largest.len) {
6894abd3f5aSChao Yu 		et->largest = en->ei;
6907c45729aSJaegeuk Kim 		f2fs_mark_inode_dirty_sync(inode, true);
691205b9822SJaegeuk Kim 	}
6924abd3f5aSChao Yu }
6934abd3f5aSChao Yu 
6949a4ffdf5SChao Yu /*
6959a4ffdf5SChao Yu  * For free nid management
6969a4ffdf5SChao Yu  */
6979a4ffdf5SChao Yu enum nid_state {
6989a4ffdf5SChao Yu 	FREE_NID,		/* newly added to free nid list */
6999a4ffdf5SChao Yu 	PREALLOC_NID,		/* it is preallocated */
7009a4ffdf5SChao Yu 	MAX_NID_STATE,
701b8559dc2SChao Yu };
702b8559dc2SChao Yu 
70339a53e0cSJaegeuk Kim struct f2fs_nm_info {
70439a53e0cSJaegeuk Kim 	block_t nat_blkaddr;		/* base disk address of NAT */
70539a53e0cSJaegeuk Kim 	nid_t max_nid;			/* maximum possible node ids */
70604d47e67SChao Yu 	nid_t available_nids;		/* # of available node ids */
70739a53e0cSJaegeuk Kim 	nid_t next_scan_nid;		/* the next nid to be scanned */
708cdfc41c1SJaegeuk Kim 	unsigned int ram_thresh;	/* control the memory footprint */
709ea1a29a0SChao Yu 	unsigned int ra_nid_pages;	/* # of nid pages to be readaheaded */
7102304cb0cSChao Yu 	unsigned int dirty_nats_ratio;	/* control dirty nats ratio threshold */
71139a53e0cSJaegeuk Kim 
71239a53e0cSJaegeuk Kim 	/* NAT cache management */
71339a53e0cSJaegeuk Kim 	struct radix_tree_root nat_root;/* root of the nat entry cache */
714309cc2b6SJaegeuk Kim 	struct radix_tree_root nat_set_root;/* root of the nat set cache */
715b873b798SJaegeuk Kim 	struct rw_semaphore nat_tree_lock;	/* protect nat_tree_lock */
71639a53e0cSJaegeuk Kim 	struct list_head nat_entries;	/* cached nat entry list (clean) */
717309cc2b6SJaegeuk Kim 	unsigned int nat_cnt;		/* the # of cached nat entries */
718aec71382SChao Yu 	unsigned int dirty_nat_cnt;	/* total num of nat entries in set */
71922ad0b6aSJaegeuk Kim 	unsigned int nat_blocks;	/* # of nat blocks */
72039a53e0cSJaegeuk Kim 
72139a53e0cSJaegeuk Kim 	/* free node ids management */
7228a7ed66aSJaegeuk Kim 	struct radix_tree_root free_nid_root;/* root of the free_nid cache */
7239a4ffdf5SChao Yu 	struct list_head free_nid_list;		/* list for free nids excluding preallocated nids */
7249a4ffdf5SChao Yu 	unsigned int nid_cnt[MAX_NID_STATE];	/* the number of free node id */
725b8559dc2SChao Yu 	spinlock_t nid_list_lock;	/* protect nid lists ops */
72639a53e0cSJaegeuk Kim 	struct mutex build_lock;	/* lock for build free nids */
7274ac91242SChao Yu 	unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE];
7284ac91242SChao Yu 	unsigned char *nat_block_bitmap;
729586d1492SChao Yu 	unsigned short *free_nid_count;	/* free nid count of NAT block */
73039a53e0cSJaegeuk Kim 
73139a53e0cSJaegeuk Kim 	/* for checkpoint */
73239a53e0cSJaegeuk Kim 	char *nat_bitmap;		/* NAT bitmap pointer */
73322ad0b6aSJaegeuk Kim 
73422ad0b6aSJaegeuk Kim 	unsigned int nat_bits_blocks;	/* # of nat bits blocks */
73522ad0b6aSJaegeuk Kim 	unsigned char *nat_bits;	/* NAT bits blocks */
73622ad0b6aSJaegeuk Kim 	unsigned char *full_nat_bits;	/* full NAT pages */
73722ad0b6aSJaegeuk Kim 	unsigned char *empty_nat_bits;	/* empty NAT pages */
738599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS
739599a09b2SChao Yu 	char *nat_bitmap_mir;		/* NAT bitmap mirror */
740599a09b2SChao Yu #endif
74139a53e0cSJaegeuk Kim 	int bitmap_size;		/* bitmap size */
74239a53e0cSJaegeuk Kim };
74339a53e0cSJaegeuk Kim 
74439a53e0cSJaegeuk Kim /*
74539a53e0cSJaegeuk Kim  * this structure is used as one of function parameters.
74639a53e0cSJaegeuk Kim  * all the information are dedicated to a given direct node block determined
74739a53e0cSJaegeuk Kim  * by the data offset in a file.
74839a53e0cSJaegeuk Kim  */
74939a53e0cSJaegeuk Kim struct dnode_of_data {
75039a53e0cSJaegeuk Kim 	struct inode *inode;		/* vfs inode pointer */
75139a53e0cSJaegeuk Kim 	struct page *inode_page;	/* its inode page, NULL is possible */
75239a53e0cSJaegeuk Kim 	struct page *node_page;		/* cached direct node page */
75339a53e0cSJaegeuk Kim 	nid_t nid;			/* node id of the direct node block */
75439a53e0cSJaegeuk Kim 	unsigned int ofs_in_node;	/* data offset in the node page */
75539a53e0cSJaegeuk Kim 	bool inode_page_locked;		/* inode page is locked or not */
75693bae099SJaegeuk Kim 	bool node_changed;		/* is node block changed */
7573cf45747SChao Yu 	char cur_level;			/* level of hole node page */
7583cf45747SChao Yu 	char max_level;			/* level of current page located */
75939a53e0cSJaegeuk Kim 	block_t	data_blkaddr;		/* block address of the node block */
76039a53e0cSJaegeuk Kim };
76139a53e0cSJaegeuk Kim 
76239a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
76339a53e0cSJaegeuk Kim 		struct page *ipage, struct page *npage, nid_t nid)
76439a53e0cSJaegeuk Kim {
765d66d1f76SJaegeuk Kim 	memset(dn, 0, sizeof(*dn));
76639a53e0cSJaegeuk Kim 	dn->inode = inode;
76739a53e0cSJaegeuk Kim 	dn->inode_page = ipage;
76839a53e0cSJaegeuk Kim 	dn->node_page = npage;
76939a53e0cSJaegeuk Kim 	dn->nid = nid;
77039a53e0cSJaegeuk Kim }
77139a53e0cSJaegeuk Kim 
77239a53e0cSJaegeuk Kim /*
77339a53e0cSJaegeuk Kim  * For SIT manager
77439a53e0cSJaegeuk Kim  *
77539a53e0cSJaegeuk Kim  * By default, there are 6 active log areas across the whole main area.
77639a53e0cSJaegeuk Kim  * When considering hot and cold data separation to reduce cleaning overhead,
77739a53e0cSJaegeuk Kim  * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
77839a53e0cSJaegeuk Kim  * respectively.
77939a53e0cSJaegeuk Kim  * In the current design, you should not change the numbers intentionally.
78039a53e0cSJaegeuk Kim  * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
78139a53e0cSJaegeuk Kim  * logs individually according to the underlying devices. (default: 6)
78239a53e0cSJaegeuk Kim  * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
78339a53e0cSJaegeuk Kim  * data and 8 for node logs.
78439a53e0cSJaegeuk Kim  */
78539a53e0cSJaegeuk Kim #define	NR_CURSEG_DATA_TYPE	(3)
78639a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE	(3)
78739a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
78839a53e0cSJaegeuk Kim 
78939a53e0cSJaegeuk Kim enum {
79039a53e0cSJaegeuk Kim 	CURSEG_HOT_DATA	= 0,	/* directory entry blocks */
79139a53e0cSJaegeuk Kim 	CURSEG_WARM_DATA,	/* data blocks */
79239a53e0cSJaegeuk Kim 	CURSEG_COLD_DATA,	/* multimedia or GCed data blocks */
79339a53e0cSJaegeuk Kim 	CURSEG_HOT_NODE,	/* direct node blocks of directory files */
79439a53e0cSJaegeuk Kim 	CURSEG_WARM_NODE,	/* direct node blocks of normal files */
79539a53e0cSJaegeuk Kim 	CURSEG_COLD_NODE,	/* indirect node blocks */
79638aa0889SJaegeuk Kim 	NO_CHECK_TYPE,
79739a53e0cSJaegeuk Kim };
79839a53e0cSJaegeuk Kim 
7996b4afdd7SJaegeuk Kim struct flush_cmd {
8006b4afdd7SJaegeuk Kim 	struct completion wait;
801721bd4d5SGu Zheng 	struct llist_node llnode;
80239d787beSChao Yu 	nid_t ino;
8036b4afdd7SJaegeuk Kim 	int ret;
8046b4afdd7SJaegeuk Kim };
8056b4afdd7SJaegeuk Kim 
806a688b9d9SGu Zheng struct flush_cmd_control {
807a688b9d9SGu Zheng 	struct task_struct *f2fs_issue_flush;	/* flush thread */
808a688b9d9SGu Zheng 	wait_queue_head_t flush_wait_queue;	/* waiting queue for wake-up */
8098b8dd65fSChao Yu 	atomic_t issued_flush;			/* # of issued flushes */
8108b8dd65fSChao Yu 	atomic_t issing_flush;			/* # of issing flushes */
811721bd4d5SGu Zheng 	struct llist_head issue_list;		/* list for command issue */
812721bd4d5SGu Zheng 	struct llist_node *dispatch_list;	/* list for command dispatch */
813a688b9d9SGu Zheng };
814a688b9d9SGu Zheng 
81539a53e0cSJaegeuk Kim struct f2fs_sm_info {
81639a53e0cSJaegeuk Kim 	struct sit_info *sit_info;		/* whole segment information */
81739a53e0cSJaegeuk Kim 	struct free_segmap_info *free_info;	/* free segment information */
81839a53e0cSJaegeuk Kim 	struct dirty_seglist_info *dirty_info;	/* dirty segment information */
81939a53e0cSJaegeuk Kim 	struct curseg_info *curseg_array;	/* active segment information */
82039a53e0cSJaegeuk Kim 
8212b60311dSChao Yu 	struct rw_semaphore curseg_lock;	/* for preventing curseg change */
8222b60311dSChao Yu 
82339a53e0cSJaegeuk Kim 	block_t seg0_blkaddr;		/* block address of 0'th segment */
82439a53e0cSJaegeuk Kim 	block_t main_blkaddr;		/* start block address of main area */
82539a53e0cSJaegeuk Kim 	block_t ssa_blkaddr;		/* start block address of SSA area */
82639a53e0cSJaegeuk Kim 
82739a53e0cSJaegeuk Kim 	unsigned int segment_count;	/* total # of segments */
82839a53e0cSJaegeuk Kim 	unsigned int main_segments;	/* # of segments in main area */
82939a53e0cSJaegeuk Kim 	unsigned int reserved_segments;	/* # of reserved segments */
83039a53e0cSJaegeuk Kim 	unsigned int ovp_segments;	/* # of overprovision segments */
83181eb8d6eSJaegeuk Kim 
83281eb8d6eSJaegeuk Kim 	/* a threshold to reclaim prefree segments */
83381eb8d6eSJaegeuk Kim 	unsigned int rec_prefree_segments;
8347fd9e544SJaegeuk Kim 
835bba681cbSJaegeuk Kim 	/* for batched trimming */
836bba681cbSJaegeuk Kim 	unsigned int trim_sections;		/* # of sections to trim */
837bba681cbSJaegeuk Kim 
838184a5cd2SChao Yu 	struct list_head sit_entry_set;	/* sit entry set list */
839184a5cd2SChao Yu 
840216fbd64SJaegeuk Kim 	unsigned int ipu_policy;	/* in-place-update policy */
841216fbd64SJaegeuk Kim 	unsigned int min_ipu_util;	/* in-place-update threshold */
842c1ce1b02SJaegeuk Kim 	unsigned int min_fsync_blocks;	/* threshold for fsync */
843ef095d19SJaegeuk Kim 	unsigned int min_hot_blocks;	/* threshold for hot block allocation */
844a2a12b67SChao Yu 	unsigned int min_ssr_sections;	/* threshold to trigger SSR allocation */
8456b4afdd7SJaegeuk Kim 
8466b4afdd7SJaegeuk Kim 	/* for flush command control */
847b01a9201SJaegeuk Kim 	struct flush_cmd_control *fcc_info;
848a688b9d9SGu Zheng 
8490b54fb84SJaegeuk Kim 	/* for discard command control */
8500b54fb84SJaegeuk Kim 	struct discard_cmd_control *dcc_info;
85139a53e0cSJaegeuk Kim };
85239a53e0cSJaegeuk Kim 
85339a53e0cSJaegeuk Kim /*
85439a53e0cSJaegeuk Kim  * For superblock
85539a53e0cSJaegeuk Kim  */
85639a53e0cSJaegeuk Kim /*
85739a53e0cSJaegeuk Kim  * COUNT_TYPE for monitoring
85839a53e0cSJaegeuk Kim  *
85939a53e0cSJaegeuk Kim  * f2fs monitors the number of several block types such as on-writeback,
86039a53e0cSJaegeuk Kim  * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
86139a53e0cSJaegeuk Kim  */
86236951b38SChao Yu #define WB_DATA_TYPE(p)	(__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA)
86339a53e0cSJaegeuk Kim enum count_type {
86439a53e0cSJaegeuk Kim 	F2FS_DIRTY_DENTS,
865c227f912SChao Yu 	F2FS_DIRTY_DATA,
8662c8a4a28SJaegeuk Kim 	F2FS_DIRTY_QDATA,
86739a53e0cSJaegeuk Kim 	F2FS_DIRTY_NODES,
86839a53e0cSJaegeuk Kim 	F2FS_DIRTY_META,
8698dcf2ff7SJaegeuk Kim 	F2FS_INMEM_PAGES,
8700f18b462SJaegeuk Kim 	F2FS_DIRTY_IMETA,
87136951b38SChao Yu 	F2FS_WB_CP_DATA,
87236951b38SChao Yu 	F2FS_WB_DATA,
87339a53e0cSJaegeuk Kim 	NR_COUNT_TYPE,
87439a53e0cSJaegeuk Kim };
87539a53e0cSJaegeuk Kim 
87639a53e0cSJaegeuk Kim /*
877e1c42045Sarter97  * The below are the page types of bios used in submit_bio().
87839a53e0cSJaegeuk Kim  * The available types are:
87939a53e0cSJaegeuk Kim  * DATA			User data pages. It operates as async mode.
88039a53e0cSJaegeuk Kim  * NODE			Node pages. It operates as async mode.
88139a53e0cSJaegeuk Kim  * META			FS metadata pages such as SIT, NAT, CP.
88239a53e0cSJaegeuk Kim  * NR_PAGE_TYPE		The number of page types.
88339a53e0cSJaegeuk Kim  * META_FLUSH		Make sure the previous pages are written
88439a53e0cSJaegeuk Kim  *			with waiting the bio's completion
88539a53e0cSJaegeuk Kim  * ...			Only can be used with META.
88639a53e0cSJaegeuk Kim  */
8877d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type)	((type) > META ? META : (type))
88839a53e0cSJaegeuk Kim enum page_type {
88939a53e0cSJaegeuk Kim 	DATA,
89039a53e0cSJaegeuk Kim 	NODE,
89139a53e0cSJaegeuk Kim 	META,
89239a53e0cSJaegeuk Kim 	NR_PAGE_TYPE,
89339a53e0cSJaegeuk Kim 	META_FLUSH,
8948ce67cb0SJaegeuk Kim 	INMEM,		/* the below types are used by tracepoints only. */
8958ce67cb0SJaegeuk Kim 	INMEM_DROP,
8968c242db9SJaegeuk Kim 	INMEM_INVALIDATE,
89728bc106bSChao Yu 	INMEM_REVOKE,
8988ce67cb0SJaegeuk Kim 	IPU,
8998ce67cb0SJaegeuk Kim 	OPU,
90039a53e0cSJaegeuk Kim };
90139a53e0cSJaegeuk Kim 
902a912b54dSJaegeuk Kim enum temp_type {
903a912b54dSJaegeuk Kim 	HOT = 0,	/* must be zero for meta bio */
904a912b54dSJaegeuk Kim 	WARM,
905a912b54dSJaegeuk Kim 	COLD,
906a912b54dSJaegeuk Kim 	NR_TEMP_TYPE,
907a912b54dSJaegeuk Kim };
908a912b54dSJaegeuk Kim 
909cc15620bSJaegeuk Kim enum need_lock_type {
910cc15620bSJaegeuk Kim 	LOCK_REQ = 0,
911cc15620bSJaegeuk Kim 	LOCK_DONE,
912cc15620bSJaegeuk Kim 	LOCK_RETRY,
913cc15620bSJaegeuk Kim };
914cc15620bSJaegeuk Kim 
915a5fd5050SChao Yu enum cp_reason_type {
916a5fd5050SChao Yu 	CP_NO_NEEDED,
917a5fd5050SChao Yu 	CP_NON_REGULAR,
918a5fd5050SChao Yu 	CP_HARDLINK,
919a5fd5050SChao Yu 	CP_SB_NEED_CP,
920a5fd5050SChao Yu 	CP_WRONG_PINO,
921a5fd5050SChao Yu 	CP_NO_SPC_ROLL,
922a5fd5050SChao Yu 	CP_NODE_NEED_CP,
923a5fd5050SChao Yu 	CP_FASTBOOT_MODE,
924a5fd5050SChao Yu 	CP_SPEC_LOG_NUM,
925a5fd5050SChao Yu };
926a5fd5050SChao Yu 
927b0af6d49SChao Yu enum iostat_type {
928b0af6d49SChao Yu 	APP_DIRECT_IO,			/* app direct IOs */
929b0af6d49SChao Yu 	APP_BUFFERED_IO,		/* app buffered IOs */
930b0af6d49SChao Yu 	APP_WRITE_IO,			/* app write IOs */
931b0af6d49SChao Yu 	APP_MAPPED_IO,			/* app mapped IOs */
932b0af6d49SChao Yu 	FS_DATA_IO,			/* data IOs from kworker/fsync/reclaimer */
933b0af6d49SChao Yu 	FS_NODE_IO,			/* node IOs from kworker/fsync/reclaimer */
934b0af6d49SChao Yu 	FS_META_IO,			/* meta IOs from kworker/reclaimer */
935b0af6d49SChao Yu 	FS_GC_DATA_IO,			/* data IOs from forground gc */
936b0af6d49SChao Yu 	FS_GC_NODE_IO,			/* node IOs from forground gc */
937b0af6d49SChao Yu 	FS_CP_DATA_IO,			/* data IOs from checkpoint */
938b0af6d49SChao Yu 	FS_CP_NODE_IO,			/* node IOs from checkpoint */
939b0af6d49SChao Yu 	FS_CP_META_IO,			/* meta IOs from checkpoint */
940b0af6d49SChao Yu 	FS_DISCARD,			/* discard */
941b0af6d49SChao Yu 	NR_IO_TYPE,
942b0af6d49SChao Yu };
943b0af6d49SChao Yu 
944458e6197SJaegeuk Kim struct f2fs_io_info {
94505ca3632SJaegeuk Kim 	struct f2fs_sb_info *sbi;	/* f2fs_sb_info pointer */
94639d787beSChao Yu 	nid_t ino;		/* inode number */
947458e6197SJaegeuk Kim 	enum page_type type;	/* contains DATA/NODE/META/META_FLUSH */
948a912b54dSJaegeuk Kim 	enum temp_type temp;	/* contains HOT/WARM/COLD */
94904d328deSMike Christie 	int op;			/* contains REQ_OP_ */
950ef295ecfSChristoph Hellwig 	int op_flags;		/* req_flag_bits */
9517a9d7548SChao Yu 	block_t new_blkaddr;	/* new block address to be written */
95228bc106bSChao Yu 	block_t old_blkaddr;	/* old block address before Cow */
95305ca3632SJaegeuk Kim 	struct page *page;	/* page to be written */
9544375a336SJaegeuk Kim 	struct page *encrypted_page;	/* encrypted page */
955fb830fc5SChao Yu 	struct list_head list;		/* serialize IOs */
956d68f735bSJaegeuk Kim 	bool submitted;		/* indicate IO submission */
957cc15620bSJaegeuk Kim 	int need_lock;		/* indicate we need to lock cp_rwsem */
958fb830fc5SChao Yu 	bool in_list;		/* indicate fio is in io_list */
959b0af6d49SChao Yu 	enum iostat_type io_type;	/* io type */
960458e6197SJaegeuk Kim };
961458e6197SJaegeuk Kim 
96268afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ)
9631ff7bd3bSJaegeuk Kim struct f2fs_bio_info {
964458e6197SJaegeuk Kim 	struct f2fs_sb_info *sbi;	/* f2fs superblock */
9651ff7bd3bSJaegeuk Kim 	struct bio *bio;		/* bios to merge */
9661ff7bd3bSJaegeuk Kim 	sector_t last_block_in_bio;	/* last block number */
967458e6197SJaegeuk Kim 	struct f2fs_io_info fio;	/* store buffered io info. */
968df0f8dc0SChao Yu 	struct rw_semaphore io_rwsem;	/* blocking op for bio */
969fb830fc5SChao Yu 	spinlock_t io_lock;		/* serialize DATA/NODE IOs */
970fb830fc5SChao Yu 	struct list_head io_list;	/* track fios */
9711ff7bd3bSJaegeuk Kim };
9721ff7bd3bSJaegeuk Kim 
9733c62be17SJaegeuk Kim #define FDEV(i)				(sbi->devs[i])
9743c62be17SJaegeuk Kim #define RDEV(i)				(raw_super->devs[i])
9753c62be17SJaegeuk Kim struct f2fs_dev_info {
9763c62be17SJaegeuk Kim 	struct block_device *bdev;
9773c62be17SJaegeuk Kim 	char path[MAX_PATH_LEN];
9783c62be17SJaegeuk Kim 	unsigned int total_segments;
9793c62be17SJaegeuk Kim 	block_t start_blk;
9803c62be17SJaegeuk Kim 	block_t end_blk;
9813c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED
9823c62be17SJaegeuk Kim 	unsigned int nr_blkz;			/* Total number of zones */
9833c62be17SJaegeuk Kim 	u8 *blkz_type;				/* Array of zones type */
9843c62be17SJaegeuk Kim #endif
9853c62be17SJaegeuk Kim };
9863c62be17SJaegeuk Kim 
987c227f912SChao Yu enum inode_type {
988c227f912SChao Yu 	DIR_INODE,			/* for dirty dir inode */
989c227f912SChao Yu 	FILE_INODE,			/* for dirty regular/symlink inode */
9900f18b462SJaegeuk Kim 	DIRTY_META,			/* for all dirtied inode metadata */
99157864ae5SJaegeuk Kim 	ATOMIC_FILE,			/* for all atomic files */
992c227f912SChao Yu 	NR_INODE_TYPE,
993c227f912SChao Yu };
994c227f912SChao Yu 
99567298804SChao Yu /* for inner inode cache management */
99667298804SChao Yu struct inode_management {
99767298804SChao Yu 	struct radix_tree_root ino_root;	/* ino entry array */
99867298804SChao Yu 	spinlock_t ino_lock;			/* for ino entry lock */
99967298804SChao Yu 	struct list_head ino_list;		/* inode list head */
100067298804SChao Yu 	unsigned long ino_num;			/* number of entries */
100167298804SChao Yu };
100267298804SChao Yu 
1003caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */
1004caf0047eSChao Yu enum {
1005caf0047eSChao Yu 	SBI_IS_DIRTY,				/* dirty flag for checkpoint */
1006caf0047eSChao Yu 	SBI_IS_CLOSE,				/* specify unmounting */
1007caf0047eSChao Yu 	SBI_NEED_FSCK,				/* need fsck.f2fs to fix */
1008caf0047eSChao Yu 	SBI_POR_DOING,				/* recovery is doing or not */
1009df728b0fSJaegeuk Kim 	SBI_NEED_SB_WRITE,			/* need to recover superblock */
1010bbf156f7SJaegeuk Kim 	SBI_NEED_CP,				/* need to checkpoint */
1011caf0047eSChao Yu };
1012caf0047eSChao Yu 
10136beceb54SJaegeuk Kim enum {
10146beceb54SJaegeuk Kim 	CP_TIME,
1015d0239e1bSJaegeuk Kim 	REQ_TIME,
10166beceb54SJaegeuk Kim 	MAX_TIME,
10176beceb54SJaegeuk Kim };
10186beceb54SJaegeuk Kim 
101939a53e0cSJaegeuk Kim struct f2fs_sb_info {
102039a53e0cSJaegeuk Kim 	struct super_block *sb;			/* pointer to VFS super block */
10215e176d54SJaegeuk Kim 	struct proc_dir_entry *s_proc;		/* proc entry */
102239a53e0cSJaegeuk Kim 	struct f2fs_super_block *raw_super;	/* raw super block pointer */
1023e8240f65SChao Yu 	int valid_super_block;			/* valid super block no */
1024fadb2fb8SChao Yu 	unsigned long s_flag;				/* flags for sbi */
102539a53e0cSJaegeuk Kim 
1026178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED
1027178053e2SDamien Le Moal 	unsigned int blocks_per_blkz;		/* F2FS blocks per zone */
1028178053e2SDamien Le Moal 	unsigned int log_blocks_per_blkz;	/* log2 F2FS blocks per zone */
1029178053e2SDamien Le Moal #endif
1030178053e2SDamien Le Moal 
103139a53e0cSJaegeuk Kim 	/* for node-related operations */
103239a53e0cSJaegeuk Kim 	struct f2fs_nm_info *nm_info;		/* node manager */
103339a53e0cSJaegeuk Kim 	struct inode *node_inode;		/* cache node blocks */
103439a53e0cSJaegeuk Kim 
103539a53e0cSJaegeuk Kim 	/* for segment-related operations */
103639a53e0cSJaegeuk Kim 	struct f2fs_sm_info *sm_info;		/* segment manager */
10371ff7bd3bSJaegeuk Kim 
10381ff7bd3bSJaegeuk Kim 	/* for bio operations */
1039a912b54dSJaegeuk Kim 	struct f2fs_bio_info *write_io[NR_PAGE_TYPE];	/* for write bios */
1040e41e6d75SChao Yu 	struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE];
1041e41e6d75SChao Yu 						/* bio ordering for NODE/DATA */
10420a595ebaSJaegeuk Kim 	int write_io_size_bits;			/* Write IO size bits */
10430a595ebaSJaegeuk Kim 	mempool_t *write_io_dummy;		/* Dummy pages */
104439a53e0cSJaegeuk Kim 
104539a53e0cSJaegeuk Kim 	/* for checkpoint */
104639a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
10478508e44aSJaegeuk Kim 	int cur_cp_pack;			/* remain current cp pack */
1048aaec2b1dSChao Yu 	spinlock_t cp_lock;			/* for flag in ckpt */
104939a53e0cSJaegeuk Kim 	struct inode *meta_inode;		/* cache meta blocks */
105039936837SJaegeuk Kim 	struct mutex cp_mutex;			/* checkpoint procedure lock */
1051b873b798SJaegeuk Kim 	struct rw_semaphore cp_rwsem;		/* blocking FS operations */
1052b3582c68SChao Yu 	struct rw_semaphore node_write;		/* locking node writes */
105359c9081bSYunlei He 	struct rw_semaphore node_change;	/* locking node change */
1054fb51b5efSChangman Lee 	wait_queue_head_t cp_wait;
10556beceb54SJaegeuk Kim 	unsigned long last_time[MAX_TIME];	/* to store time in jiffies */
10566beceb54SJaegeuk Kim 	long interval_time[MAX_TIME];		/* to store thresholds */
105739a53e0cSJaegeuk Kim 
105867298804SChao Yu 	struct inode_management im[MAX_INO_ENTRY];      /* manage inode cache */
10596451e041SJaegeuk Kim 
10606451e041SJaegeuk Kim 	/* for orphan inode, use 0'th array */
10610d47c1adSGu Zheng 	unsigned int max_orphans;		/* max orphan inodes */
106239a53e0cSJaegeuk Kim 
1063c227f912SChao Yu 	/* for inode management */
1064c227f912SChao Yu 	struct list_head inode_list[NR_INODE_TYPE];	/* dirty inode list */
1065c227f912SChao Yu 	spinlock_t inode_lock[NR_INODE_TYPE];	/* for dirty inode list lock */
106639a53e0cSJaegeuk Kim 
106713054c54SChao Yu 	/* for extent tree cache */
106813054c54SChao Yu 	struct radix_tree_root extent_tree_root;/* cache extent cache entries */
10695e8256acSYunlei He 	struct mutex extent_tree_lock;	/* locking extent radix tree */
107013054c54SChao Yu 	struct list_head extent_list;		/* lru list for shrinker */
107113054c54SChao Yu 	spinlock_t extent_lock;			/* locking extent lru list */
10727441ccefSJaegeuk Kim 	atomic_t total_ext_tree;		/* extent tree count */
1073137d09f0SJaegeuk Kim 	struct list_head zombie_list;		/* extent zombie tree list */
107474fd8d99SJaegeuk Kim 	atomic_t total_zombie_tree;		/* extent zombie tree count */
107513054c54SChao Yu 	atomic_t total_ext_node;		/* extent info count */
107613054c54SChao Yu 
107739a53e0cSJaegeuk Kim 	/* basic filesystem units */
107839a53e0cSJaegeuk Kim 	unsigned int log_sectors_per_block;	/* log2 sectors per block */
107939a53e0cSJaegeuk Kim 	unsigned int log_blocksize;		/* log2 block size */
108039a53e0cSJaegeuk Kim 	unsigned int blocksize;			/* block size */
108139a53e0cSJaegeuk Kim 	unsigned int root_ino_num;		/* root inode number*/
108239a53e0cSJaegeuk Kim 	unsigned int node_ino_num;		/* node inode number*/
108339a53e0cSJaegeuk Kim 	unsigned int meta_ino_num;		/* meta inode number*/
108439a53e0cSJaegeuk Kim 	unsigned int log_blocks_per_seg;	/* log2 blocks per segment */
108539a53e0cSJaegeuk Kim 	unsigned int blocks_per_seg;		/* blocks per segment */
108639a53e0cSJaegeuk Kim 	unsigned int segs_per_sec;		/* segments per section */
108739a53e0cSJaegeuk Kim 	unsigned int secs_per_zone;		/* sections per zone */
108839a53e0cSJaegeuk Kim 	unsigned int total_sections;		/* total section count */
108939a53e0cSJaegeuk Kim 	unsigned int total_node_count;		/* total node block count */
109039a53e0cSJaegeuk Kim 	unsigned int total_valid_node_count;	/* valid node block count */
1091e0afc4d6SChao Yu 	loff_t max_file_blocks;			/* max block index of file */
109239a53e0cSJaegeuk Kim 	int active_logs;			/* # of active logs */
1093ab9fa662SJaegeuk Kim 	int dir_level;				/* directory level */
10946afc662eSChao Yu 	int inline_xattr_size;			/* inline xattr size */
1095a2a12b67SChao Yu 	unsigned int trigger_ssr_threshold;	/* threshold to trigger ssr */
109639a53e0cSJaegeuk Kim 
109739a53e0cSJaegeuk Kim 	block_t user_block_count;		/* # of user blocks */
109839a53e0cSJaegeuk Kim 	block_t total_valid_block_count;	/* # of valid blocks */
1099a66cdd98SJaegeuk Kim 	block_t discard_blks;			/* discard command candidats */
110039a53e0cSJaegeuk Kim 	block_t last_valid_block_count;		/* for recovery */
1101daeb433eSChao Yu 	block_t reserved_blocks;		/* configurable reserved blocks */
110280d42145SYunlong Song 	block_t current_reserved_blocks;	/* current reserved blocks */
1103daeb433eSChao Yu 
1104*292c196aSChao Yu 	unsigned int nquota_files;		/* # of quota sysfile */
1105*292c196aSChao Yu 
110639a53e0cSJaegeuk Kim 	u32 s_next_generation;			/* for NFS support */
1107523be8a6SJaegeuk Kim 
1108523be8a6SJaegeuk Kim 	/* # of pages, see count_type */
110935782b23SJaegeuk Kim 	atomic_t nr_pages[NR_COUNT_TYPE];
111041382ec4SJaegeuk Kim 	/* # of allocated blocks */
111141382ec4SJaegeuk Kim 	struct percpu_counter alloc_valid_block_count;
111239a53e0cSJaegeuk Kim 
1113687de7f1SJaegeuk Kim 	/* writeback control */
1114687de7f1SJaegeuk Kim 	atomic_t wb_sync_req;			/* count # of WB_SYNC threads */
1115687de7f1SJaegeuk Kim 
1116513c5f37SJaegeuk Kim 	/* valid inode count */
1117513c5f37SJaegeuk Kim 	struct percpu_counter total_valid_inode_count;
1118513c5f37SJaegeuk Kim 
111939a53e0cSJaegeuk Kim 	struct f2fs_mount_info mount_opt;	/* mount options */
112039a53e0cSJaegeuk Kim 
112139a53e0cSJaegeuk Kim 	/* for cleaning operations */
112239a53e0cSJaegeuk Kim 	struct mutex gc_mutex;			/* mutex for GC */
112339a53e0cSJaegeuk Kim 	struct f2fs_gc_kthread	*gc_thread;	/* GC thread */
11245ec4e49fSJaegeuk Kim 	unsigned int cur_victim_sec;		/* current victim section num */
112539a53e0cSJaegeuk Kim 
1126e93b9865SHou Pengyang 	/* threshold for converting bg victims for fg */
1127e93b9865SHou Pengyang 	u64 fggc_threshold;
1128e93b9865SHou Pengyang 
1129b1c57c1cSJaegeuk Kim 	/* maximum # of trials to find a victim segment for SSR and GC */
1130b1c57c1cSJaegeuk Kim 	unsigned int max_victim_search;
1131b1c57c1cSJaegeuk Kim 
113239a53e0cSJaegeuk Kim 	/*
113339a53e0cSJaegeuk Kim 	 * for stat information.
113439a53e0cSJaegeuk Kim 	 * one is for the LFS mode, and the other is for the SSR mode.
113539a53e0cSJaegeuk Kim 	 */
113635b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS
113739a53e0cSJaegeuk Kim 	struct f2fs_stat_info *stat_info;	/* FS status information */
113839a53e0cSJaegeuk Kim 	unsigned int segment_count[2];		/* # of allocated segments */
113939a53e0cSJaegeuk Kim 	unsigned int block_count[2];		/* # of allocated blocks */
1140b9a2c252SChangman Lee 	atomic_t inplace_count;		/* # of inplace update */
11415b7ee374SChao Yu 	atomic64_t total_hit_ext;		/* # of lookup extent cache */
11425b7ee374SChao Yu 	atomic64_t read_hit_rbtree;		/* # of hit rbtree extent node */
11435b7ee374SChao Yu 	atomic64_t read_hit_largest;		/* # of hit largest extent node */
11445b7ee374SChao Yu 	atomic64_t read_hit_cached;		/* # of hit cached extent node */
1145d5e8f6c9SChao Yu 	atomic_t inline_xattr;			/* # of inline_xattr inodes */
114603e14d52SChao Yu 	atomic_t inline_inode;			/* # of inline_data inodes */
114703e14d52SChao Yu 	atomic_t inline_dir;			/* # of inline_dentry inodes */
114826a28a0cSJaegeuk Kim 	atomic_t aw_cnt;			/* # of atomic writes */
1149648d50baSChao Yu 	atomic_t vw_cnt;			/* # of volatile writes */
115026a28a0cSJaegeuk Kim 	atomic_t max_aw_cnt;			/* max # of atomic writes */
1151648d50baSChao Yu 	atomic_t max_vw_cnt;			/* max # of volatile writes */
115239a53e0cSJaegeuk Kim 	int bg_gc;				/* background gc calls */
115333fbd510SChao Yu 	unsigned int ndirty_inode[NR_INODE_TYPE];	/* # of dirty inodes */
115435b09d82SNamjae Jeon #endif
115539a53e0cSJaegeuk Kim 	spinlock_t stat_lock;			/* lock for stat operations */
1156b59d0baeSNamjae Jeon 
1157b0af6d49SChao Yu 	/* For app/fs IO statistics */
1158b0af6d49SChao Yu 	spinlock_t iostat_lock;
1159b0af6d49SChao Yu 	unsigned long long write_iostat[NR_IO_TYPE];
1160b0af6d49SChao Yu 	bool iostat_enable;
1161b0af6d49SChao Yu 
1162b59d0baeSNamjae Jeon 	/* For sysfs suppport */
1163b59d0baeSNamjae Jeon 	struct kobject s_kobj;
1164b59d0baeSNamjae Jeon 	struct completion s_kobj_unregister;
11652658e50dSJaegeuk Kim 
11662658e50dSJaegeuk Kim 	/* For shrinker support */
11672658e50dSJaegeuk Kim 	struct list_head s_list;
11683c62be17SJaegeuk Kim 	int s_ndevs;				/* number of devices */
11693c62be17SJaegeuk Kim 	struct f2fs_dev_info *devs;		/* for device list */
11701228b482SChao Yu 	unsigned int dirty_device;		/* for checkpoint data flush */
11711228b482SChao Yu 	spinlock_t dev_lock;			/* protect dirty_device */
11722658e50dSJaegeuk Kim 	struct mutex umount_mutex;
11732658e50dSJaegeuk Kim 	unsigned int shrinker_run_no;
11748f1dbbbbSShuoran Liu 
11758f1dbbbbSShuoran Liu 	/* For write statistics */
11768f1dbbbbSShuoran Liu 	u64 sectors_written_start;
11778f1dbbbbSShuoran Liu 	u64 kbytes_written;
117843b6573bSKeith Mok 
117943b6573bSKeith Mok 	/* Reference to checksum algorithm driver via cryptoapi */
118043b6573bSKeith Mok 	struct crypto_shash *s_chksum_driver;
11811ecc0c5cSChao Yu 
1182704956ecSChao Yu 	/* Precomputed FS UUID checksum for seeding other checksums */
1183704956ecSChao Yu 	__u32 s_chksum_seed;
1184704956ecSChao Yu 
11851ecc0c5cSChao Yu 	/* For fault injection */
11861ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION
11871ecc0c5cSChao Yu 	struct f2fs_fault_info fault_info;
11881ecc0c5cSChao Yu #endif
11894b2414d0SChao Yu 
11904b2414d0SChao Yu #ifdef CONFIG_QUOTA
11914b2414d0SChao Yu 	/* Names of quota files with journalled quota */
11924b2414d0SChao Yu 	char *s_qf_names[MAXQUOTAS];
11934b2414d0SChao Yu 	int s_jquota_fmt;			/* Format of quota to use */
11944b2414d0SChao Yu #endif
119539a53e0cSJaegeuk Kim };
119639a53e0cSJaegeuk Kim 
11971ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION
119855523519SChao Yu #define f2fs_show_injection_info(type)				\
119955523519SChao Yu 	printk("%sF2FS-fs : inject %s in %s of %pF\n",		\
120055523519SChao Yu 		KERN_INFO, fault_name[type],			\
120155523519SChao Yu 		__func__, __builtin_return_address(0))
12021ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
12031ecc0c5cSChao Yu {
12041ecc0c5cSChao Yu 	struct f2fs_fault_info *ffi = &sbi->fault_info;
12051ecc0c5cSChao Yu 
12061ecc0c5cSChao Yu 	if (!ffi->inject_rate)
12071ecc0c5cSChao Yu 		return false;
12081ecc0c5cSChao Yu 
12091ecc0c5cSChao Yu 	if (!IS_FAULT_SET(ffi, type))
12101ecc0c5cSChao Yu 		return false;
12111ecc0c5cSChao Yu 
12121ecc0c5cSChao Yu 	atomic_inc(&ffi->inject_ops);
12131ecc0c5cSChao Yu 	if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) {
12141ecc0c5cSChao Yu 		atomic_set(&ffi->inject_ops, 0);
12151ecc0c5cSChao Yu 		return true;
12161ecc0c5cSChao Yu 	}
12171ecc0c5cSChao Yu 	return false;
12181ecc0c5cSChao Yu }
12191ecc0c5cSChao Yu #endif
12201ecc0c5cSChao Yu 
12218f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes,
12228f1dbbbbSShuoran Liu  * and the return value is in kbytes. s is of struct f2fs_sb_info.
12238f1dbbbbSShuoran Liu  */
12248f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s)						 \
122568afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) -		 \
122668afcf2dSTomohiro Kusumi 		(s)->sectors_written_start) >> 1)
12278f1dbbbbSShuoran Liu 
12286beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
12296beceb54SJaegeuk Kim {
12306beceb54SJaegeuk Kim 	sbi->last_time[type] = jiffies;
12316beceb54SJaegeuk Kim }
12326beceb54SJaegeuk Kim 
12336beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type)
12346beceb54SJaegeuk Kim {
12356bccfa19SArnd Bergmann 	unsigned long interval = sbi->interval_time[type] * HZ;
12366beceb54SJaegeuk Kim 
12376beceb54SJaegeuk Kim 	return time_after(jiffies, sbi->last_time[type] + interval);
12386beceb54SJaegeuk Kim }
12396beceb54SJaegeuk Kim 
1240d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi)
1241d0239e1bSJaegeuk Kim {
1242d0239e1bSJaegeuk Kim 	struct block_device *bdev = sbi->sb->s_bdev;
1243d0239e1bSJaegeuk Kim 	struct request_queue *q = bdev_get_queue(bdev);
1244d0239e1bSJaegeuk Kim 	struct request_list *rl = &q->root_rl;
1245d0239e1bSJaegeuk Kim 
1246d0239e1bSJaegeuk Kim 	if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC])
1247d0239e1bSJaegeuk Kim 		return 0;
1248d0239e1bSJaegeuk Kim 
1249d0239e1bSJaegeuk Kim 	return f2fs_time_over(sbi, REQ_TIME);
1250d0239e1bSJaegeuk Kim }
1251d0239e1bSJaegeuk Kim 
125239a53e0cSJaegeuk Kim /*
125339a53e0cSJaegeuk Kim  * Inline functions
125439a53e0cSJaegeuk Kim  */
125543b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
125643b6573bSKeith Mok 			   unsigned int length)
125743b6573bSKeith Mok {
125843b6573bSKeith Mok 	SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver);
125943b6573bSKeith Mok 	u32 *ctx = (u32 *)shash_desc_ctx(shash);
1260d41519a6SDavid Miller 	u32 retval;
126143b6573bSKeith Mok 	int err;
126243b6573bSKeith Mok 
126343b6573bSKeith Mok 	shash->tfm = sbi->s_chksum_driver;
126443b6573bSKeith Mok 	shash->flags = 0;
126543b6573bSKeith Mok 	*ctx = F2FS_SUPER_MAGIC;
126643b6573bSKeith Mok 
126743b6573bSKeith Mok 	err = crypto_shash_update(shash, address, length);
126843b6573bSKeith Mok 	BUG_ON(err);
126943b6573bSKeith Mok 
1270d41519a6SDavid Miller 	retval = *ctx;
1271d41519a6SDavid Miller 	barrier_data(ctx);
1272d41519a6SDavid Miller 	return retval;
127343b6573bSKeith Mok }
127443b6573bSKeith Mok 
127543b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
127643b6573bSKeith Mok 				  void *buf, size_t buf_size)
127743b6573bSKeith Mok {
127843b6573bSKeith Mok 	return f2fs_crc32(sbi, buf, buf_size) == blk_crc;
127943b6573bSKeith Mok }
128043b6573bSKeith Mok 
1281704956ecSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc,
1282704956ecSChao Yu 			      const void *address, unsigned int length)
1283704956ecSChao Yu {
1284704956ecSChao Yu 	struct {
1285704956ecSChao Yu 		struct shash_desc shash;
1286704956ecSChao Yu 		char ctx[4];
1287704956ecSChao Yu 	} desc;
1288704956ecSChao Yu 	int err;
1289704956ecSChao Yu 
1290704956ecSChao Yu 	BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx));
1291704956ecSChao Yu 
1292704956ecSChao Yu 	desc.shash.tfm = sbi->s_chksum_driver;
1293704956ecSChao Yu 	desc.shash.flags = 0;
1294704956ecSChao Yu 	*(u32 *)desc.ctx = crc;
1295704956ecSChao Yu 
1296704956ecSChao Yu 	err = crypto_shash_update(&desc.shash, address, length);
1297704956ecSChao Yu 	BUG_ON(err);
1298704956ecSChao Yu 
1299704956ecSChao Yu 	return *(u32 *)desc.ctx;
1300704956ecSChao Yu }
1301704956ecSChao Yu 
130239a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
130339a53e0cSJaegeuk Kim {
130439a53e0cSJaegeuk Kim 	return container_of(inode, struct f2fs_inode_info, vfs_inode);
130539a53e0cSJaegeuk Kim }
130639a53e0cSJaegeuk Kim 
130739a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
130839a53e0cSJaegeuk Kim {
130939a53e0cSJaegeuk Kim 	return sb->s_fs_info;
131039a53e0cSJaegeuk Kim }
131139a53e0cSJaegeuk Kim 
13124081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
13134081363fSJaegeuk Kim {
13144081363fSJaegeuk Kim 	return F2FS_SB(inode->i_sb);
13154081363fSJaegeuk Kim }
13164081363fSJaegeuk Kim 
13174081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
13184081363fSJaegeuk Kim {
13194081363fSJaegeuk Kim 	return F2FS_I_SB(mapping->host);
13204081363fSJaegeuk Kim }
13214081363fSJaegeuk Kim 
13224081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
13234081363fSJaegeuk Kim {
13244081363fSJaegeuk Kim 	return F2FS_M_SB(page->mapping);
13254081363fSJaegeuk Kim }
13264081363fSJaegeuk Kim 
132739a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
132839a53e0cSJaegeuk Kim {
132939a53e0cSJaegeuk Kim 	return (struct f2fs_super_block *)(sbi->raw_super);
133039a53e0cSJaegeuk Kim }
133139a53e0cSJaegeuk Kim 
133239a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
133339a53e0cSJaegeuk Kim {
133439a53e0cSJaegeuk Kim 	return (struct f2fs_checkpoint *)(sbi->ckpt);
133539a53e0cSJaegeuk Kim }
133639a53e0cSJaegeuk Kim 
133745590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page)
133845590710SGu Zheng {
133945590710SGu Zheng 	return (struct f2fs_node *)page_address(page);
134045590710SGu Zheng }
134145590710SGu Zheng 
134258bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page)
134358bfaf44SJaegeuk Kim {
134458bfaf44SJaegeuk Kim 	return &((struct f2fs_node *)page_address(page))->i;
134558bfaf44SJaegeuk Kim }
134658bfaf44SJaegeuk Kim 
134739a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
134839a53e0cSJaegeuk Kim {
134939a53e0cSJaegeuk Kim 	return (struct f2fs_nm_info *)(sbi->nm_info);
135039a53e0cSJaegeuk Kim }
135139a53e0cSJaegeuk Kim 
135239a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
135339a53e0cSJaegeuk Kim {
135439a53e0cSJaegeuk Kim 	return (struct f2fs_sm_info *)(sbi->sm_info);
135539a53e0cSJaegeuk Kim }
135639a53e0cSJaegeuk Kim 
135739a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
135839a53e0cSJaegeuk Kim {
135939a53e0cSJaegeuk Kim 	return (struct sit_info *)(SM_I(sbi)->sit_info);
136039a53e0cSJaegeuk Kim }
136139a53e0cSJaegeuk Kim 
136239a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
136339a53e0cSJaegeuk Kim {
136439a53e0cSJaegeuk Kim 	return (struct free_segmap_info *)(SM_I(sbi)->free_info);
136539a53e0cSJaegeuk Kim }
136639a53e0cSJaegeuk Kim 
136739a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
136839a53e0cSJaegeuk Kim {
136939a53e0cSJaegeuk Kim 	return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
137039a53e0cSJaegeuk Kim }
137139a53e0cSJaegeuk Kim 
13729df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
13739df27d98SGu Zheng {
13749df27d98SGu Zheng 	return sbi->meta_inode->i_mapping;
13759df27d98SGu Zheng }
13769df27d98SGu Zheng 
13774ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
13784ef51a8fSJaegeuk Kim {
13794ef51a8fSJaegeuk Kim 	return sbi->node_inode->i_mapping;
13804ef51a8fSJaegeuk Kim }
13814ef51a8fSJaegeuk Kim 
1382caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
138339a53e0cSJaegeuk Kim {
1384fadb2fb8SChao Yu 	return test_bit(type, &sbi->s_flag);
138539a53e0cSJaegeuk Kim }
138639a53e0cSJaegeuk Kim 
1387caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
138839a53e0cSJaegeuk Kim {
1389fadb2fb8SChao Yu 	set_bit(type, &sbi->s_flag);
1390caf0047eSChao Yu }
1391caf0047eSChao Yu 
1392caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
1393caf0047eSChao Yu {
1394fadb2fb8SChao Yu 	clear_bit(type, &sbi->s_flag);
139539a53e0cSJaegeuk Kim }
139639a53e0cSJaegeuk Kim 
1397d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
1398d71b5564SJaegeuk Kim {
1399d71b5564SJaegeuk Kim 	return le64_to_cpu(cp->checkpoint_ver);
1400d71b5564SJaegeuk Kim }
1401d71b5564SJaegeuk Kim 
1402ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type)
1403ea676733SJaegeuk Kim {
1404ea676733SJaegeuk Kim 	if (type < F2FS_MAX_QUOTAS)
1405ea676733SJaegeuk Kim 		return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]);
1406ea676733SJaegeuk Kim 	return 0;
1407ea676733SJaegeuk Kim }
1408ea676733SJaegeuk Kim 
1409ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp)
1410ced2c7eaSKinglong Mee {
1411ced2c7eaSKinglong Mee 	size_t crc_offset = le32_to_cpu(cp->checksum_offset);
1412ced2c7eaSKinglong Mee 	return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset)));
1413ced2c7eaSKinglong Mee }
1414ced2c7eaSKinglong Mee 
1415aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
141625ca923bSJaegeuk Kim {
141725ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
1418aaec2b1dSChao Yu 
141925ca923bSJaegeuk Kim 	return ckpt_flags & f;
142025ca923bSJaegeuk Kim }
142125ca923bSJaegeuk Kim 
1422aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
142325ca923bSJaegeuk Kim {
1424aaec2b1dSChao Yu 	return __is_set_ckpt_flags(F2FS_CKPT(sbi), f);
1425aaec2b1dSChao Yu }
1426aaec2b1dSChao Yu 
1427aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1428aaec2b1dSChao Yu {
1429aaec2b1dSChao Yu 	unsigned int ckpt_flags;
1430aaec2b1dSChao Yu 
1431aaec2b1dSChao Yu 	ckpt_flags = le32_to_cpu(cp->ckpt_flags);
143225ca923bSJaegeuk Kim 	ckpt_flags |= f;
143325ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
143425ca923bSJaegeuk Kim }
143525ca923bSJaegeuk Kim 
1436aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
143725ca923bSJaegeuk Kim {
1438d1aa2453SChao Yu 	unsigned long flags;
1439d1aa2453SChao Yu 
1440d1aa2453SChao Yu 	spin_lock_irqsave(&sbi->cp_lock, flags);
1441aaec2b1dSChao Yu 	__set_ckpt_flags(F2FS_CKPT(sbi), f);
1442d1aa2453SChao Yu 	spin_unlock_irqrestore(&sbi->cp_lock, flags);
1443aaec2b1dSChao Yu }
1444aaec2b1dSChao Yu 
1445aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1446aaec2b1dSChao Yu {
1447aaec2b1dSChao Yu 	unsigned int ckpt_flags;
1448aaec2b1dSChao Yu 
1449aaec2b1dSChao Yu 	ckpt_flags = le32_to_cpu(cp->ckpt_flags);
145025ca923bSJaegeuk Kim 	ckpt_flags &= (~f);
145125ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
145225ca923bSJaegeuk Kim }
145325ca923bSJaegeuk Kim 
1454aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
1455aaec2b1dSChao Yu {
1456d1aa2453SChao Yu 	unsigned long flags;
1457d1aa2453SChao Yu 
1458d1aa2453SChao Yu 	spin_lock_irqsave(&sbi->cp_lock, flags);
1459aaec2b1dSChao Yu 	__clear_ckpt_flags(F2FS_CKPT(sbi), f);
1460d1aa2453SChao Yu 	spin_unlock_irqrestore(&sbi->cp_lock, flags);
1461aaec2b1dSChao Yu }
1462aaec2b1dSChao Yu 
146322ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock)
146422ad0b6aSJaegeuk Kim {
1465d1aa2453SChao Yu 	unsigned long flags;
1466d1aa2453SChao Yu 
146722ad0b6aSJaegeuk Kim 	set_sbi_flag(sbi, SBI_NEED_FSCK);
146822ad0b6aSJaegeuk Kim 
146922ad0b6aSJaegeuk Kim 	if (lock)
1470d1aa2453SChao Yu 		spin_lock_irqsave(&sbi->cp_lock, flags);
147122ad0b6aSJaegeuk Kim 	__clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG);
147222ad0b6aSJaegeuk Kim 	kfree(NM_I(sbi)->nat_bits);
147322ad0b6aSJaegeuk Kim 	NM_I(sbi)->nat_bits = NULL;
147422ad0b6aSJaegeuk Kim 	if (lock)
1475d1aa2453SChao Yu 		spin_unlock_irqrestore(&sbi->cp_lock, flags);
147622ad0b6aSJaegeuk Kim }
147722ad0b6aSJaegeuk Kim 
147822ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
147922ad0b6aSJaegeuk Kim 					struct cp_control *cpc)
148022ad0b6aSJaegeuk Kim {
148122ad0b6aSJaegeuk Kim 	bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG);
148222ad0b6aSJaegeuk Kim 
1483c473f1a9SChao Yu 	return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set;
148422ad0b6aSJaegeuk Kim }
148522ad0b6aSJaegeuk Kim 
1486e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
148739a53e0cSJaegeuk Kim {
1488b873b798SJaegeuk Kim 	down_read(&sbi->cp_rwsem);
148939a53e0cSJaegeuk Kim }
149039a53e0cSJaegeuk Kim 
1491cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi)
1492cc15620bSJaegeuk Kim {
1493cc15620bSJaegeuk Kim 	return down_read_trylock(&sbi->cp_rwsem);
1494cc15620bSJaegeuk Kim }
1495cc15620bSJaegeuk Kim 
1496e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
149739a53e0cSJaegeuk Kim {
1498b873b798SJaegeuk Kim 	up_read(&sbi->cp_rwsem);
149939936837SJaegeuk Kim }
150039936837SJaegeuk Kim 
1501e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
150239936837SJaegeuk Kim {
1503b873b798SJaegeuk Kim 	down_write(&sbi->cp_rwsem);
150439936837SJaegeuk Kim }
150539936837SJaegeuk Kim 
1506e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
150739936837SJaegeuk Kim {
1508b873b798SJaegeuk Kim 	up_write(&sbi->cp_rwsem);
150939a53e0cSJaegeuk Kim }
151039a53e0cSJaegeuk Kim 
1511119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
1512119ee914SJaegeuk Kim {
1513119ee914SJaegeuk Kim 	int reason = CP_SYNC;
1514119ee914SJaegeuk Kim 
1515119ee914SJaegeuk Kim 	if (test_opt(sbi, FASTBOOT))
1516119ee914SJaegeuk Kim 		reason = CP_FASTBOOT;
1517119ee914SJaegeuk Kim 	if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
1518119ee914SJaegeuk Kim 		reason = CP_UMOUNT;
1519119ee914SJaegeuk Kim 	return reason;
1520119ee914SJaegeuk Kim }
1521119ee914SJaegeuk Kim 
1522119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason)
1523119ee914SJaegeuk Kim {
1524c473f1a9SChao Yu 	return (reason & (CP_UMOUNT | CP_FASTBOOT));
1525119ee914SJaegeuk Kim }
1526119ee914SJaegeuk Kim 
1527119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
1528119ee914SJaegeuk Kim {
1529aaec2b1dSChao Yu 	return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) ||
1530aaec2b1dSChao Yu 			is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG));
1531119ee914SJaegeuk Kim }
1532119ee914SJaegeuk Kim 
153339a53e0cSJaegeuk Kim /*
153439a53e0cSJaegeuk Kim  * Check whether the given nid is within node id range.
153539a53e0cSJaegeuk Kim  */
1536064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
153739a53e0cSJaegeuk Kim {
1538d6b7d4b3SChao Yu 	if (unlikely(nid < F2FS_ROOT_INO(sbi)))
1539d6b7d4b3SChao Yu 		return -EINVAL;
1540cfb271d4SChao Yu 	if (unlikely(nid >= NM_I(sbi)->max_nid))
1541064e0823SNamjae Jeon 		return -EINVAL;
1542064e0823SNamjae Jeon 	return 0;
154339a53e0cSJaegeuk Kim }
154439a53e0cSJaegeuk Kim 
154539a53e0cSJaegeuk Kim /*
154639a53e0cSJaegeuk Kim  * Check whether the inode has blocks or not
154739a53e0cSJaegeuk Kim  */
154839a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode)
154939a53e0cSJaegeuk Kim {
15500eb0adadSChao Yu 	block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0;
15510eb0adadSChao Yu 
1552000519f2SChao Yu 	return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block;
155339a53e0cSJaegeuk Kim }
155439a53e0cSJaegeuk Kim 
15554bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs)
15564bc8e9bcSChao Yu {
15574bc8e9bcSChao Yu 	return ofs == XATTR_NODE_OFFSET;
15584bc8e9bcSChao Yu }
15594bc8e9bcSChao Yu 
15600abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool);
15610abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
156246008c6dSChao Yu 				 struct inode *inode, blkcnt_t *count)
156339a53e0cSJaegeuk Kim {
15640abd675eSChao Yu 	blkcnt_t diff = 0, release = 0;
1565daeb433eSChao Yu 	block_t avail_user_block_count;
15660abd675eSChao Yu 	int ret;
15670abd675eSChao Yu 
15680abd675eSChao Yu 	ret = dquot_reserve_block(inode, *count);
15690abd675eSChao Yu 	if (ret)
15700abd675eSChao Yu 		return ret;
1571dd11a5dfSJaegeuk Kim 
1572cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION
157355523519SChao Yu 	if (time_to_inject(sbi, FAULT_BLOCK)) {
157455523519SChao Yu 		f2fs_show_injection_info(FAULT_BLOCK);
15750abd675eSChao Yu 		release = *count;
15760abd675eSChao Yu 		goto enospc;
157755523519SChao Yu 	}
1578cb78942bSJaegeuk Kim #endif
1579dd11a5dfSJaegeuk Kim 	/*
1580dd11a5dfSJaegeuk Kim 	 * let's increase this in prior to actual block count change in order
1581dd11a5dfSJaegeuk Kim 	 * for f2fs_sync_file to avoid data races when deciding checkpoint.
1582dd11a5dfSJaegeuk Kim 	 */
1583dd11a5dfSJaegeuk Kim 	percpu_counter_add(&sbi->alloc_valid_block_count, (*count));
1584cfb271d4SChao Yu 
158539a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
15862555a2d5SJaegeuk Kim 	sbi->total_valid_block_count += (block_t)(*count);
158780d42145SYunlong Song 	avail_user_block_count = sbi->user_block_count -
158880d42145SYunlong Song 					sbi->current_reserved_blocks;
1589daeb433eSChao Yu 	if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
1590daeb433eSChao Yu 		diff = sbi->total_valid_block_count - avail_user_block_count;
1591dd11a5dfSJaegeuk Kim 		*count -= diff;
15920abd675eSChao Yu 		release = diff;
1593daeb433eSChao Yu 		sbi->total_valid_block_count = avail_user_block_count;
159446008c6dSChao Yu 		if (!*count) {
159539a53e0cSJaegeuk Kim 			spin_unlock(&sbi->stat_lock);
1596dd11a5dfSJaegeuk Kim 			percpu_counter_sub(&sbi->alloc_valid_block_count, diff);
15970abd675eSChao Yu 			goto enospc;
159839a53e0cSJaegeuk Kim 		}
159946008c6dSChao Yu 	}
160039a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
160141382ec4SJaegeuk Kim 
16020abd675eSChao Yu 	if (release)
16030abd675eSChao Yu 		dquot_release_reservation_block(inode, release);
16040abd675eSChao Yu 	f2fs_i_blocks_write(inode, *count, true, true);
16050abd675eSChao Yu 	return 0;
16060abd675eSChao Yu 
16070abd675eSChao Yu enospc:
16080abd675eSChao Yu 	dquot_release_reservation_block(inode, release);
16090abd675eSChao Yu 	return -ENOSPC;
161039a53e0cSJaegeuk Kim }
161139a53e0cSJaegeuk Kim 
1612da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
161339a53e0cSJaegeuk Kim 						struct inode *inode,
16140eb0adadSChao Yu 						block_t count)
161539a53e0cSJaegeuk Kim {
16160eb0adadSChao Yu 	blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK;
16170eb0adadSChao Yu 
161839a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
16199850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
16200eb0adadSChao Yu 	f2fs_bug_on(sbi, inode->i_blocks < sectors);
162139a53e0cSJaegeuk Kim 	sbi->total_valid_block_count -= (block_t)count;
162280d42145SYunlong Song 	if (sbi->reserved_blocks &&
162380d42145SYunlong Song 		sbi->current_reserved_blocks < sbi->reserved_blocks)
162480d42145SYunlong Song 		sbi->current_reserved_blocks = min(sbi->reserved_blocks,
162580d42145SYunlong Song 					sbi->current_reserved_blocks + count);
162639a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
16270abd675eSChao Yu 	f2fs_i_blocks_write(inode, count, false, true);
162839a53e0cSJaegeuk Kim }
162939a53e0cSJaegeuk Kim 
163039a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
163139a53e0cSJaegeuk Kim {
163235782b23SJaegeuk Kim 	atomic_inc(&sbi->nr_pages[count_type]);
16337c4abcbeSChao Yu 
163436951b38SChao Yu 	if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES ||
163536951b38SChao Yu 		count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA)
16367c4abcbeSChao Yu 		return;
16377c4abcbeSChao Yu 
1638caf0047eSChao Yu 	set_sbi_flag(sbi, SBI_IS_DIRTY);
163939a53e0cSJaegeuk Kim }
164039a53e0cSJaegeuk Kim 
1641a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode)
164239a53e0cSJaegeuk Kim {
1643204706c7SJaegeuk Kim 	atomic_inc(&F2FS_I(inode)->dirty_pages);
1644c227f912SChao Yu 	inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1645c227f912SChao Yu 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
16462c8a4a28SJaegeuk Kim 	if (IS_NOQUOTA(inode))
16472c8a4a28SJaegeuk Kim 		inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
164839a53e0cSJaegeuk Kim }
164939a53e0cSJaegeuk Kim 
165039a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
165139a53e0cSJaegeuk Kim {
165235782b23SJaegeuk Kim 	atomic_dec(&sbi->nr_pages[count_type]);
165339a53e0cSJaegeuk Kim }
165439a53e0cSJaegeuk Kim 
1655a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode)
165639a53e0cSJaegeuk Kim {
16575ac9f36fSChao Yu 	if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
16585ac9f36fSChao Yu 			!S_ISLNK(inode->i_mode))
16591fe54f9dSJaegeuk Kim 		return;
16601fe54f9dSJaegeuk Kim 
1661204706c7SJaegeuk Kim 	atomic_dec(&F2FS_I(inode)->dirty_pages);
1662c227f912SChao Yu 	dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1663c227f912SChao Yu 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
16642c8a4a28SJaegeuk Kim 	if (IS_NOQUOTA(inode))
16652c8a4a28SJaegeuk Kim 		dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA);
166639a53e0cSJaegeuk Kim }
166739a53e0cSJaegeuk Kim 
1668523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type)
166939a53e0cSJaegeuk Kim {
167035782b23SJaegeuk Kim 	return atomic_read(&sbi->nr_pages[count_type]);
167139a53e0cSJaegeuk Kim }
167239a53e0cSJaegeuk Kim 
1673204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode)
1674f8b2c1f9SJaegeuk Kim {
1675204706c7SJaegeuk Kim 	return atomic_read(&F2FS_I(inode)->dirty_pages);
1676f8b2c1f9SJaegeuk Kim }
1677f8b2c1f9SJaegeuk Kim 
16785ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
16795ac206cfSNamjae Jeon {
16803519e3f9SChao Yu 	unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg;
1681523be8a6SJaegeuk Kim 	unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >>
1682523be8a6SJaegeuk Kim 						sbi->log_blocks_per_seg;
1683523be8a6SJaegeuk Kim 
1684523be8a6SJaegeuk Kim 	return segs / sbi->segs_per_sec;
16855ac206cfSNamjae Jeon }
16865ac206cfSNamjae Jeon 
168739a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
168839a53e0cSJaegeuk Kim {
16898b8343faSJaegeuk Kim 	return sbi->total_valid_block_count;
169039a53e0cSJaegeuk Kim }
169139a53e0cSJaegeuk Kim 
1692f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi)
1693f83a2584SYunlei He {
1694f83a2584SYunlei He 	return sbi->discard_blks;
1695f83a2584SYunlei He }
1696f83a2584SYunlei He 
169739a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
169839a53e0cSJaegeuk Kim {
169939a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
170039a53e0cSJaegeuk Kim 
170139a53e0cSJaegeuk Kim 	/* return NAT or SIT bitmap */
170239a53e0cSJaegeuk Kim 	if (flag == NAT_BITMAP)
170339a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
170439a53e0cSJaegeuk Kim 	else if (flag == SIT_BITMAP)
170539a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
170639a53e0cSJaegeuk Kim 
170739a53e0cSJaegeuk Kim 	return 0;
170839a53e0cSJaegeuk Kim }
170939a53e0cSJaegeuk Kim 
171055141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
171155141486SWanpeng Li {
171255141486SWanpeng Li 	return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
171355141486SWanpeng Li }
171455141486SWanpeng Li 
171539a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
171639a53e0cSJaegeuk Kim {
171739a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
17181dbe4152SChangman Lee 	int offset;
17191dbe4152SChangman Lee 
172055141486SWanpeng Li 	if (__cp_payload(sbi) > 0) {
17211dbe4152SChangman Lee 		if (flag == NAT_BITMAP)
17221dbe4152SChangman Lee 			return &ckpt->sit_nat_version_bitmap;
17231dbe4152SChangman Lee 		else
172465b85cccSJaegeuk Kim 			return (unsigned char *)ckpt + F2FS_BLKSIZE;
17251dbe4152SChangman Lee 	} else {
17261dbe4152SChangman Lee 		offset = (flag == NAT_BITMAP) ?
172725ca923bSJaegeuk Kim 			le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
172839a53e0cSJaegeuk Kim 		return &ckpt->sit_nat_version_bitmap + offset;
172939a53e0cSJaegeuk Kim 	}
17301dbe4152SChangman Lee }
173139a53e0cSJaegeuk Kim 
173239a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
173339a53e0cSJaegeuk Kim {
17348508e44aSJaegeuk Kim 	block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
173539a53e0cSJaegeuk Kim 
17368508e44aSJaegeuk Kim 	if (sbi->cur_cp_pack == 2)
173739a53e0cSJaegeuk Kim 		start_addr += sbi->blocks_per_seg;
173839a53e0cSJaegeuk Kim 	return start_addr;
173939a53e0cSJaegeuk Kim }
174039a53e0cSJaegeuk Kim 
17418508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi)
17428508e44aSJaegeuk Kim {
17438508e44aSJaegeuk Kim 	block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
17448508e44aSJaegeuk Kim 
17458508e44aSJaegeuk Kim 	if (sbi->cur_cp_pack == 1)
17468508e44aSJaegeuk Kim 		start_addr += sbi->blocks_per_seg;
17478508e44aSJaegeuk Kim 	return start_addr;
17488508e44aSJaegeuk Kim }
17498508e44aSJaegeuk Kim 
17508508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi)
17518508e44aSJaegeuk Kim {
17528508e44aSJaegeuk Kim 	sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1;
17538508e44aSJaegeuk Kim }
17548508e44aSJaegeuk Kim 
175539a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
175639a53e0cSJaegeuk Kim {
175739a53e0cSJaegeuk Kim 	return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
175839a53e0cSJaegeuk Kim }
175939a53e0cSJaegeuk Kim 
17600abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
1761000519f2SChao Yu 					struct inode *inode, bool is_inode)
176239a53e0cSJaegeuk Kim {
176339a53e0cSJaegeuk Kim 	block_t	valid_block_count;
176439a53e0cSJaegeuk Kim 	unsigned int valid_node_count;
17650abd675eSChao Yu 	bool quota = inode && !is_inode;
17660abd675eSChao Yu 
17670abd675eSChao Yu 	if (quota) {
17680abd675eSChao Yu 		int ret = dquot_reserve_block(inode, 1);
17690abd675eSChao Yu 		if (ret)
17700abd675eSChao Yu 			return ret;
17710abd675eSChao Yu 	}
177239a53e0cSJaegeuk Kim 
1773812c6056SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION
1774812c6056SChao Yu 	if (time_to_inject(sbi, FAULT_BLOCK)) {
1775812c6056SChao Yu 		f2fs_show_injection_info(FAULT_BLOCK);
1776812c6056SChao Yu 		goto enospc;
1777812c6056SChao Yu 	}
1778812c6056SChao Yu #endif
1779812c6056SChao Yu 
178039a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
178139a53e0cSJaegeuk Kim 
1782ef86d709SGu Zheng 	valid_block_count = sbi->total_valid_block_count + 1;
178380d42145SYunlong Song 	if (unlikely(valid_block_count + sbi->current_reserved_blocks >
1784daeb433eSChao Yu 						sbi->user_block_count)) {
178539a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
17860abd675eSChao Yu 		goto enospc;
178739a53e0cSJaegeuk Kim 	}
178839a53e0cSJaegeuk Kim 
1789ef86d709SGu Zheng 	valid_node_count = sbi->total_valid_node_count + 1;
1790cfb271d4SChao Yu 	if (unlikely(valid_node_count > sbi->total_node_count)) {
179139a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
17920abd675eSChao Yu 		goto enospc;
179339a53e0cSJaegeuk Kim 	}
179439a53e0cSJaegeuk Kim 
1795ef86d709SGu Zheng 	sbi->total_valid_node_count++;
1796ef86d709SGu Zheng 	sbi->total_valid_block_count++;
179739a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
179839a53e0cSJaegeuk Kim 
17990abd675eSChao Yu 	if (inode) {
18000abd675eSChao Yu 		if (is_inode)
18010abd675eSChao Yu 			f2fs_mark_inode_dirty_sync(inode, true);
18020abd675eSChao Yu 		else
18030abd675eSChao Yu 			f2fs_i_blocks_write(inode, 1, true, true);
18040abd675eSChao Yu 	}
18050abd675eSChao Yu 
180641382ec4SJaegeuk Kim 	percpu_counter_inc(&sbi->alloc_valid_block_count);
18070abd675eSChao Yu 	return 0;
18080abd675eSChao Yu 
18090abd675eSChao Yu enospc:
18100abd675eSChao Yu 	if (quota)
18110abd675eSChao Yu 		dquot_release_reservation_block(inode, 1);
18120abd675eSChao Yu 	return -ENOSPC;
181339a53e0cSJaegeuk Kim }
181439a53e0cSJaegeuk Kim 
181539a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
1816000519f2SChao Yu 					struct inode *inode, bool is_inode)
181739a53e0cSJaegeuk Kim {
181839a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
181939a53e0cSJaegeuk Kim 
18209850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_block_count);
18219850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_node_count);
1822000519f2SChao Yu 	f2fs_bug_on(sbi, !is_inode && !inode->i_blocks);
182339a53e0cSJaegeuk Kim 
1824ef86d709SGu Zheng 	sbi->total_valid_node_count--;
1825ef86d709SGu Zheng 	sbi->total_valid_block_count--;
182680d42145SYunlong Song 	if (sbi->reserved_blocks &&
182780d42145SYunlong Song 		sbi->current_reserved_blocks < sbi->reserved_blocks)
182880d42145SYunlong Song 		sbi->current_reserved_blocks++;
182939a53e0cSJaegeuk Kim 
183039a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
18310abd675eSChao Yu 
18320abd675eSChao Yu 	if (!is_inode)
18330abd675eSChao Yu 		f2fs_i_blocks_write(inode, 1, false, true);
183439a53e0cSJaegeuk Kim }
183539a53e0cSJaegeuk Kim 
183639a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
183739a53e0cSJaegeuk Kim {
18388b8343faSJaegeuk Kim 	return sbi->total_valid_node_count;
183939a53e0cSJaegeuk Kim }
184039a53e0cSJaegeuk Kim 
184139a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
184239a53e0cSJaegeuk Kim {
1843513c5f37SJaegeuk Kim 	percpu_counter_inc(&sbi->total_valid_inode_count);
184439a53e0cSJaegeuk Kim }
184539a53e0cSJaegeuk Kim 
18460e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
184739a53e0cSJaegeuk Kim {
1848513c5f37SJaegeuk Kim 	percpu_counter_dec(&sbi->total_valid_inode_count);
184939a53e0cSJaegeuk Kim }
185039a53e0cSJaegeuk Kim 
1851513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi)
185239a53e0cSJaegeuk Kim {
1853513c5f37SJaegeuk Kim 	return percpu_counter_sum_positive(&sbi->total_valid_inode_count);
185439a53e0cSJaegeuk Kim }
185539a53e0cSJaegeuk Kim 
1856a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
1857a56c7c6fSJaegeuk Kim 						pgoff_t index, bool for_write)
1858a56c7c6fSJaegeuk Kim {
1859c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION
1860c41f3cc3SJaegeuk Kim 	struct page *page = find_lock_page(mapping, index);
1861cac5a3d8SDongOh Shin 
1862c41f3cc3SJaegeuk Kim 	if (page)
1863c41f3cc3SJaegeuk Kim 		return page;
1864c41f3cc3SJaegeuk Kim 
186555523519SChao Yu 	if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) {
186655523519SChao Yu 		f2fs_show_injection_info(FAULT_PAGE_ALLOC);
1867c41f3cc3SJaegeuk Kim 		return NULL;
186855523519SChao Yu 	}
1869c41f3cc3SJaegeuk Kim #endif
1870a56c7c6fSJaegeuk Kim 	if (!for_write)
1871a56c7c6fSJaegeuk Kim 		return grab_cache_page(mapping, index);
1872a56c7c6fSJaegeuk Kim 	return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
1873a56c7c6fSJaegeuk Kim }
1874a56c7c6fSJaegeuk Kim 
187501eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page(
187601eccef7SChao Yu 				struct address_space *mapping, pgoff_t index,
187701eccef7SChao Yu 				int fgp_flags, gfp_t gfp_mask)
187801eccef7SChao Yu {
187901eccef7SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION
188001eccef7SChao Yu 	if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) {
188101eccef7SChao Yu 		f2fs_show_injection_info(FAULT_PAGE_GET);
188201eccef7SChao Yu 		return NULL;
188301eccef7SChao Yu 	}
188401eccef7SChao Yu #endif
188501eccef7SChao Yu 	return pagecache_get_page(mapping, index, fgp_flags, gfp_mask);
188601eccef7SChao Yu }
188701eccef7SChao Yu 
18886e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst)
18896e2c64adSJaegeuk Kim {
18906e2c64adSJaegeuk Kim 	char *src_kaddr = kmap(src);
18916e2c64adSJaegeuk Kim 	char *dst_kaddr = kmap(dst);
18926e2c64adSJaegeuk Kim 
18936e2c64adSJaegeuk Kim 	memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
18946e2c64adSJaegeuk Kim 	kunmap(dst);
18956e2c64adSJaegeuk Kim 	kunmap(src);
18966e2c64adSJaegeuk Kim }
18976e2c64adSJaegeuk Kim 
189839a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock)
189939a53e0cSJaegeuk Kim {
1900031fa8ccSJaegeuk Kim 	if (!page)
190139a53e0cSJaegeuk Kim 		return;
190239a53e0cSJaegeuk Kim 
190339a53e0cSJaegeuk Kim 	if (unlock) {
19049850cf4aSJaegeuk Kim 		f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
190539a53e0cSJaegeuk Kim 		unlock_page(page);
190639a53e0cSJaegeuk Kim 	}
190709cbfeafSKirill A. Shutemov 	put_page(page);
190839a53e0cSJaegeuk Kim }
190939a53e0cSJaegeuk Kim 
191039a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn)
191139a53e0cSJaegeuk Kim {
191239a53e0cSJaegeuk Kim 	if (dn->node_page)
191339a53e0cSJaegeuk Kim 		f2fs_put_page(dn->node_page, 1);
191439a53e0cSJaegeuk Kim 	if (dn->inode_page && dn->node_page != dn->inode_page)
191539a53e0cSJaegeuk Kim 		f2fs_put_page(dn->inode_page, 0);
191639a53e0cSJaegeuk Kim 	dn->node_page = NULL;
191739a53e0cSJaegeuk Kim 	dn->inode_page = NULL;
191839a53e0cSJaegeuk Kim }
191939a53e0cSJaegeuk Kim 
192039a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
1921e8512d2eSGu Zheng 					size_t size)
192239a53e0cSJaegeuk Kim {
1923e8512d2eSGu Zheng 	return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
192439a53e0cSJaegeuk Kim }
192539a53e0cSJaegeuk Kim 
19267bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
19277bd59381SGu Zheng 						gfp_t flags)
19287bd59381SGu Zheng {
19297bd59381SGu Zheng 	void *entry;
19307bd59381SGu Zheng 
193180c54505SJaegeuk Kim 	entry = kmem_cache_alloc(cachep, flags);
193280c54505SJaegeuk Kim 	if (!entry)
193380c54505SJaegeuk Kim 		entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
19347bd59381SGu Zheng 	return entry;
19357bd59381SGu Zheng }
19367bd59381SGu Zheng 
1937d62fe971SChao Yu static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi,
1938d62fe971SChao Yu 						int npages, bool no_fail)
1939740432f8SJaegeuk Kim {
1940740432f8SJaegeuk Kim 	struct bio *bio;
1941740432f8SJaegeuk Kim 
1942d62fe971SChao Yu 	if (no_fail) {
1943740432f8SJaegeuk Kim 		/* No failure on bio allocation */
1944740432f8SJaegeuk Kim 		bio = bio_alloc(GFP_NOIO, npages);
194580c54505SJaegeuk Kim 		if (!bio)
194680c54505SJaegeuk Kim 			bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
1947740432f8SJaegeuk Kim 		return bio;
1948740432f8SJaegeuk Kim 	}
1949d62fe971SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION
1950d62fe971SChao Yu 	if (time_to_inject(sbi, FAULT_ALLOC_BIO)) {
1951d62fe971SChao Yu 		f2fs_show_injection_info(FAULT_ALLOC_BIO);
1952d62fe971SChao Yu 		return NULL;
1953d62fe971SChao Yu 	}
1954d62fe971SChao Yu #endif
1955d62fe971SChao Yu 	return bio_alloc(GFP_KERNEL, npages);
1956d62fe971SChao Yu }
1957740432f8SJaegeuk Kim 
19589be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
19599be32d72SJaegeuk Kim 				unsigned long index, void *item)
19609be32d72SJaegeuk Kim {
19619be32d72SJaegeuk Kim 	while (radix_tree_insert(root, index, item))
19629be32d72SJaegeuk Kim 		cond_resched();
19639be32d72SJaegeuk Kim }
19649be32d72SJaegeuk Kim 
196539a53e0cSJaegeuk Kim #define RAW_IS_INODE(p)	((p)->footer.nid == (p)->footer.ino)
196639a53e0cSJaegeuk Kim 
196739a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page)
196839a53e0cSJaegeuk Kim {
196945590710SGu Zheng 	struct f2fs_node *p = F2FS_NODE(page);
1970cac5a3d8SDongOh Shin 
197139a53e0cSJaegeuk Kim 	return RAW_IS_INODE(p);
197239a53e0cSJaegeuk Kim }
197339a53e0cSJaegeuk Kim 
19747a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i)
19757a2af766SChao Yu {
19767a2af766SChao Yu 	return (i->i_inline & F2FS_EXTRA_ATTR) ?
19777a2af766SChao Yu 			(le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0;
19787a2af766SChao Yu }
19797a2af766SChao Yu 
198039a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
198139a53e0cSJaegeuk Kim {
198239a53e0cSJaegeuk Kim 	return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
198339a53e0cSJaegeuk Kim }
198439a53e0cSJaegeuk Kim 
19857a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode);
19867a2af766SChao Yu static inline block_t datablock_addr(struct inode *inode,
19877a2af766SChao Yu 			struct page *node_page, unsigned int offset)
198839a53e0cSJaegeuk Kim {
198939a53e0cSJaegeuk Kim 	struct f2fs_node *raw_node;
199039a53e0cSJaegeuk Kim 	__le32 *addr_array;
19917a2af766SChao Yu 	int base = 0;
19927a2af766SChao Yu 	bool is_inode = IS_INODE(node_page);
1993cac5a3d8SDongOh Shin 
199445590710SGu Zheng 	raw_node = F2FS_NODE(node_page);
19957a2af766SChao Yu 
19967a2af766SChao Yu 	/* from GC path only */
19977a2af766SChao Yu 	if (!inode) {
19987a2af766SChao Yu 		if (is_inode)
19997a2af766SChao Yu 			base = offset_in_addr(&raw_node->i);
20007a2af766SChao Yu 	} else if (f2fs_has_extra_attr(inode) && is_inode) {
20017a2af766SChao Yu 		base = get_extra_isize(inode);
20027a2af766SChao Yu 	}
20037a2af766SChao Yu 
200439a53e0cSJaegeuk Kim 	addr_array = blkaddr_in_node(raw_node);
20057a2af766SChao Yu 	return le32_to_cpu(addr_array[base + offset]);
200639a53e0cSJaegeuk Kim }
200739a53e0cSJaegeuk Kim 
200839a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr)
200939a53e0cSJaegeuk Kim {
201039a53e0cSJaegeuk Kim 	int mask;
201139a53e0cSJaegeuk Kim 
201239a53e0cSJaegeuk Kim 	addr += (nr >> 3);
201339a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
201439a53e0cSJaegeuk Kim 	return mask & *addr;
201539a53e0cSJaegeuk Kim }
201639a53e0cSJaegeuk Kim 
2017a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr)
2018a66cdd98SJaegeuk Kim {
2019a66cdd98SJaegeuk Kim 	int mask;
2020a66cdd98SJaegeuk Kim 
2021a66cdd98SJaegeuk Kim 	addr += (nr >> 3);
2022a66cdd98SJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
2023a66cdd98SJaegeuk Kim 	*addr |= mask;
2024a66cdd98SJaegeuk Kim }
2025a66cdd98SJaegeuk Kim 
2026a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr)
2027a66cdd98SJaegeuk Kim {
2028a66cdd98SJaegeuk Kim 	int mask;
2029a66cdd98SJaegeuk Kim 
2030a66cdd98SJaegeuk Kim 	addr += (nr >> 3);
2031a66cdd98SJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
2032a66cdd98SJaegeuk Kim 	*addr &= ~mask;
2033a66cdd98SJaegeuk Kim }
2034a66cdd98SJaegeuk Kim 
203552aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
203639a53e0cSJaegeuk Kim {
203739a53e0cSJaegeuk Kim 	int mask;
203839a53e0cSJaegeuk Kim 	int ret;
203939a53e0cSJaegeuk Kim 
204039a53e0cSJaegeuk Kim 	addr += (nr >> 3);
204139a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
204239a53e0cSJaegeuk Kim 	ret = mask & *addr;
204339a53e0cSJaegeuk Kim 	*addr |= mask;
204439a53e0cSJaegeuk Kim 	return ret;
204539a53e0cSJaegeuk Kim }
204639a53e0cSJaegeuk Kim 
204752aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
204839a53e0cSJaegeuk Kim {
204939a53e0cSJaegeuk Kim 	int mask;
205039a53e0cSJaegeuk Kim 	int ret;
205139a53e0cSJaegeuk Kim 
205239a53e0cSJaegeuk Kim 	addr += (nr >> 3);
205339a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
205439a53e0cSJaegeuk Kim 	ret = mask & *addr;
205539a53e0cSJaegeuk Kim 	*addr &= ~mask;
205639a53e0cSJaegeuk Kim 	return ret;
205739a53e0cSJaegeuk Kim }
205839a53e0cSJaegeuk Kim 
2059c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr)
2060c6ac4c0eSGu Zheng {
2061c6ac4c0eSGu Zheng 	int mask;
2062c6ac4c0eSGu Zheng 
2063c6ac4c0eSGu Zheng 	addr += (nr >> 3);
2064c6ac4c0eSGu Zheng 	mask = 1 << (7 - (nr & 0x07));
2065c6ac4c0eSGu Zheng 	*addr ^= mask;
2066c6ac4c0eSGu Zheng }
2067c6ac4c0eSGu Zheng 
20685c57132eSChao Yu #define F2FS_REG_FLMASK		(~(FS_DIRSYNC_FL | FS_TOPDIR_FL))
20695c57132eSChao Yu #define F2FS_OTHER_FLMASK	(FS_NODUMP_FL | FS_NOATIME_FL)
20705c57132eSChao Yu #define F2FS_FL_INHERITED	(FS_PROJINHERIT_FL)
20715c57132eSChao Yu 
20725c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags)
20735c57132eSChao Yu {
20745c57132eSChao Yu 	if (S_ISDIR(mode))
20755c57132eSChao Yu 		return flags;
20765c57132eSChao Yu 	else if (S_ISREG(mode))
20775c57132eSChao Yu 		return flags & F2FS_REG_FLMASK;
20785c57132eSChao Yu 	else
20795c57132eSChao Yu 		return flags & F2FS_OTHER_FLMASK;
20805c57132eSChao Yu }
20815c57132eSChao Yu 
208239a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */
208339a53e0cSJaegeuk Kim enum {
208439a53e0cSJaegeuk Kim 	FI_NEW_INODE,		/* indicate newly allocated inode */
2085b3783873SJaegeuk Kim 	FI_DIRTY_INODE,		/* indicate inode is dirty or not */
208626de9b11SJaegeuk Kim 	FI_AUTO_RECOVER,	/* indicate inode is recoverable */
2087ed57c27fSJaegeuk Kim 	FI_DIRTY_DIR,		/* indicate directory has dirty pages */
208839a53e0cSJaegeuk Kim 	FI_INC_LINK,		/* need to increment i_nlink */
208939a53e0cSJaegeuk Kim 	FI_ACL_MODE,		/* indicate acl mode */
209039a53e0cSJaegeuk Kim 	FI_NO_ALLOC,		/* should not allocate any blocks */
2091c9b63bd0SJaegeuk Kim 	FI_FREE_NID,		/* free allocated nide */
2092c11abd1aSJaegeuk Kim 	FI_NO_EXTENT,		/* not to use the extent cache */
2093444c580fSJaegeuk Kim 	FI_INLINE_XATTR,	/* used for inline xattr */
20941001b347SHuajun Li 	FI_INLINE_DATA,		/* used for inline data*/
209534d67debSChao Yu 	FI_INLINE_DENTRY,	/* used for inline dentry */
2096fff04f90SJaegeuk Kim 	FI_APPEND_WRITE,	/* inode has appended data */
2097fff04f90SJaegeuk Kim 	FI_UPDATE_WRITE,	/* inode has in-place-update data */
209888b88a66SJaegeuk Kim 	FI_NEED_IPU,		/* used for ipu per file */
209988b88a66SJaegeuk Kim 	FI_ATOMIC_FILE,		/* indicate atomic file */
21005fe45743SChao Yu 	FI_ATOMIC_COMMIT,	/* indicate the state of atomical committing */
210102a1335fSJaegeuk Kim 	FI_VOLATILE_FILE,	/* indicate volatile file */
21023c6c2bebSJaegeuk Kim 	FI_FIRST_BLOCK_WRITTEN,	/* indicate #0 data block was written */
21031e84371fSJaegeuk Kim 	FI_DROP_CACHE,		/* drop dirty page cache */
2104b3d208f9SJaegeuk Kim 	FI_DATA_EXIST,		/* indicate data exists */
2105510022a8SJaegeuk Kim 	FI_INLINE_DOTS,		/* indicate inline dot dentries */
2106d323d005SChao Yu 	FI_DO_DEFRAG,		/* indicate defragment is running */
2107c227f912SChao Yu 	FI_DIRTY_FILE,		/* indicate regular/symlink has dirty pages */
2108dc91de78SJaegeuk Kim 	FI_NO_PREALLOC,		/* indicate skipped preallocated blocks */
2109ef095d19SJaegeuk Kim 	FI_HOT_DATA,		/* indicate file is hot */
21107a2af766SChao Yu 	FI_EXTRA_ATTR,		/* indicate file has extra attribute */
21115c57132eSChao Yu 	FI_PROJ_INHERIT,	/* indicate file inherits projectid */
211239a53e0cSJaegeuk Kim };
211339a53e0cSJaegeuk Kim 
2114205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode,
2115205b9822SJaegeuk Kim 						int flag, bool set)
211639a53e0cSJaegeuk Kim {
2117205b9822SJaegeuk Kim 	switch (flag) {
2118205b9822SJaegeuk Kim 	case FI_INLINE_XATTR:
2119205b9822SJaegeuk Kim 	case FI_INLINE_DATA:
2120205b9822SJaegeuk Kim 	case FI_INLINE_DENTRY:
2121205b9822SJaegeuk Kim 		if (set)
2122205b9822SJaegeuk Kim 			return;
2123205b9822SJaegeuk Kim 	case FI_DATA_EXIST:
2124205b9822SJaegeuk Kim 	case FI_INLINE_DOTS:
21257c45729aSJaegeuk Kim 		f2fs_mark_inode_dirty_sync(inode, true);
2126205b9822SJaegeuk Kim 	}
212739a53e0cSJaegeuk Kim }
212839a53e0cSJaegeuk Kim 
212991942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag)
213039a53e0cSJaegeuk Kim {
213191942321SJaegeuk Kim 	if (!test_bit(flag, &F2FS_I(inode)->flags))
213291942321SJaegeuk Kim 		set_bit(flag, &F2FS_I(inode)->flags);
2133205b9822SJaegeuk Kim 	__mark_inode_dirty_flag(inode, flag, true);
213439a53e0cSJaegeuk Kim }
213539a53e0cSJaegeuk Kim 
213691942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag)
213739a53e0cSJaegeuk Kim {
213891942321SJaegeuk Kim 	return test_bit(flag, &F2FS_I(inode)->flags);
213939a53e0cSJaegeuk Kim }
214039a53e0cSJaegeuk Kim 
214191942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag)
214239a53e0cSJaegeuk Kim {
214391942321SJaegeuk Kim 	if (test_bit(flag, &F2FS_I(inode)->flags))
214491942321SJaegeuk Kim 		clear_bit(flag, &F2FS_I(inode)->flags);
2145205b9822SJaegeuk Kim 	__mark_inode_dirty_flag(inode, flag, false);
214639a53e0cSJaegeuk Kim }
214739a53e0cSJaegeuk Kim 
214891942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode)
2149444c580fSJaegeuk Kim {
215091942321SJaegeuk Kim 	F2FS_I(inode)->i_acl_mode = mode;
215191942321SJaegeuk Kim 	set_inode_flag(inode, FI_ACL_MODE);
21527c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, false);
215339a53e0cSJaegeuk Kim }
215439a53e0cSJaegeuk Kim 
2155a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc)
2156a1961246SJaegeuk Kim {
2157a1961246SJaegeuk Kim 	if (inc)
2158a1961246SJaegeuk Kim 		inc_nlink(inode);
2159a1961246SJaegeuk Kim 	else
2160a1961246SJaegeuk Kim 		drop_nlink(inode);
21617c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2162a1961246SJaegeuk Kim }
2163a1961246SJaegeuk Kim 
21648edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode,
21650abd675eSChao Yu 					block_t diff, bool add, bool claim)
21668edd03c8SJaegeuk Kim {
216726de9b11SJaegeuk Kim 	bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
216826de9b11SJaegeuk Kim 	bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
216926de9b11SJaegeuk Kim 
21700abd675eSChao Yu 	/* add = 1, claim = 1 should be dquot_reserve_block in pair */
21710abd675eSChao Yu 	if (add) {
21720abd675eSChao Yu 		if (claim)
21730abd675eSChao Yu 			dquot_claim_block(inode, diff);
21740abd675eSChao Yu 		else
21750abd675eSChao Yu 			dquot_alloc_block_nofail(inode, diff);
21760abd675eSChao Yu 	} else {
21770abd675eSChao Yu 		dquot_free_block(inode, diff);
21780abd675eSChao Yu 	}
21790abd675eSChao Yu 
21807c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
218126de9b11SJaegeuk Kim 	if (clean || recover)
218226de9b11SJaegeuk Kim 		set_inode_flag(inode, FI_AUTO_RECOVER);
21838edd03c8SJaegeuk Kim }
21848edd03c8SJaegeuk Kim 
2185fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
2186fc9581c8SJaegeuk Kim {
218726de9b11SJaegeuk Kim 	bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
218826de9b11SJaegeuk Kim 	bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
218926de9b11SJaegeuk Kim 
2190fc9581c8SJaegeuk Kim 	if (i_size_read(inode) == i_size)
2191fc9581c8SJaegeuk Kim 		return;
2192fc9581c8SJaegeuk Kim 
2193fc9581c8SJaegeuk Kim 	i_size_write(inode, i_size);
21947c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
219526de9b11SJaegeuk Kim 	if (clean || recover)
219626de9b11SJaegeuk Kim 		set_inode_flag(inode, FI_AUTO_RECOVER);
219726de9b11SJaegeuk Kim }
219826de9b11SJaegeuk Kim 
2199205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth)
2200205b9822SJaegeuk Kim {
2201205b9822SJaegeuk Kim 	F2FS_I(inode)->i_current_depth = depth;
22027c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2203205b9822SJaegeuk Kim }
2204205b9822SJaegeuk Kim 
2205205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid)
2206205b9822SJaegeuk Kim {
2207205b9822SJaegeuk Kim 	F2FS_I(inode)->i_xattr_nid = xnid;
22087c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2209205b9822SJaegeuk Kim }
2210205b9822SJaegeuk Kim 
2211205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino)
2212205b9822SJaegeuk Kim {
2213205b9822SJaegeuk Kim 	F2FS_I(inode)->i_pino = pino;
22147c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2215205b9822SJaegeuk Kim }
2216205b9822SJaegeuk Kim 
221791942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri)
2218444c580fSJaegeuk Kim {
2219205b9822SJaegeuk Kim 	struct f2fs_inode_info *fi = F2FS_I(inode);
2220205b9822SJaegeuk Kim 
2221444c580fSJaegeuk Kim 	if (ri->i_inline & F2FS_INLINE_XATTR)
2222205b9822SJaegeuk Kim 		set_bit(FI_INLINE_XATTR, &fi->flags);
22231001b347SHuajun Li 	if (ri->i_inline & F2FS_INLINE_DATA)
2224205b9822SJaegeuk Kim 		set_bit(FI_INLINE_DATA, &fi->flags);
222534d67debSChao Yu 	if (ri->i_inline & F2FS_INLINE_DENTRY)
2226205b9822SJaegeuk Kim 		set_bit(FI_INLINE_DENTRY, &fi->flags);
2227b3d208f9SJaegeuk Kim 	if (ri->i_inline & F2FS_DATA_EXIST)
2228205b9822SJaegeuk Kim 		set_bit(FI_DATA_EXIST, &fi->flags);
2229510022a8SJaegeuk Kim 	if (ri->i_inline & F2FS_INLINE_DOTS)
2230205b9822SJaegeuk Kim 		set_bit(FI_INLINE_DOTS, &fi->flags);
22317a2af766SChao Yu 	if (ri->i_inline & F2FS_EXTRA_ATTR)
22327a2af766SChao Yu 		set_bit(FI_EXTRA_ATTR, &fi->flags);
2233444c580fSJaegeuk Kim }
2234444c580fSJaegeuk Kim 
223591942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri)
2236444c580fSJaegeuk Kim {
2237444c580fSJaegeuk Kim 	ri->i_inline = 0;
2238444c580fSJaegeuk Kim 
223991942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_XATTR))
2240444c580fSJaegeuk Kim 		ri->i_inline |= F2FS_INLINE_XATTR;
224191942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_DATA))
22421001b347SHuajun Li 		ri->i_inline |= F2FS_INLINE_DATA;
224391942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_DENTRY))
224434d67debSChao Yu 		ri->i_inline |= F2FS_INLINE_DENTRY;
224591942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_DATA_EXIST))
2246b3d208f9SJaegeuk Kim 		ri->i_inline |= F2FS_DATA_EXIST;
224791942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_DOTS))
2248510022a8SJaegeuk Kim 		ri->i_inline |= F2FS_INLINE_DOTS;
22497a2af766SChao Yu 	if (is_inode_flag_set(inode, FI_EXTRA_ATTR))
22507a2af766SChao Yu 		ri->i_inline |= F2FS_EXTRA_ATTR;
22517a2af766SChao Yu }
22527a2af766SChao Yu 
22537a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode)
22547a2af766SChao Yu {
22557a2af766SChao Yu 	return is_inode_flag_set(inode, FI_EXTRA_ATTR);
2256444c580fSJaegeuk Kim }
2257444c580fSJaegeuk Kim 
2258987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode)
2259987c7c31SChao Yu {
226091942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_XATTR);
2261987c7c31SChao Yu }
2262987c7c31SChao Yu 
226381ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode)
2264de93653fSJaegeuk Kim {
22656afc662eSChao Yu 	return CUR_ADDRS_PER_INODE(inode) - F2FS_INLINE_XATTR_ADDRS(inode);
2266de93653fSJaegeuk Kim }
2267de93653fSJaegeuk Kim 
22686afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page)
226965985d93SJaegeuk Kim {
2270695fd1edSChao Yu 	struct f2fs_inode *ri = F2FS_INODE(page);
2271cac5a3d8SDongOh Shin 
227265985d93SJaegeuk Kim 	return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
22736afc662eSChao Yu 					F2FS_INLINE_XATTR_ADDRS(inode)]);
227465985d93SJaegeuk Kim }
227565985d93SJaegeuk Kim 
227665985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode)
227765985d93SJaegeuk Kim {
22786afc662eSChao Yu 	return get_inline_xattr_addrs(inode) * sizeof(__le32);
227965985d93SJaegeuk Kim }
228065985d93SJaegeuk Kim 
22810dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode)
22820dbdc2aeSJaegeuk Kim {
228391942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_DATA);
22840dbdc2aeSJaegeuk Kim }
22850dbdc2aeSJaegeuk Kim 
2286b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode)
2287b3d208f9SJaegeuk Kim {
228891942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_DATA_EXIST);
2289b3d208f9SJaegeuk Kim }
2290b3d208f9SJaegeuk Kim 
2291510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode)
2292510022a8SJaegeuk Kim {
229391942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_DOTS);
2294510022a8SJaegeuk Kim }
2295510022a8SJaegeuk Kim 
229688b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode)
229788b88a66SJaegeuk Kim {
229891942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_ATOMIC_FILE);
229988b88a66SJaegeuk Kim }
230088b88a66SJaegeuk Kim 
23015fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode)
23025fe45743SChao Yu {
23035fe45743SChao Yu 	return is_inode_flag_set(inode, FI_ATOMIC_COMMIT);
23045fe45743SChao Yu }
23055fe45743SChao Yu 
230602a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode)
230702a1335fSJaegeuk Kim {
230891942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_VOLATILE_FILE);
230902a1335fSJaegeuk Kim }
231002a1335fSJaegeuk Kim 
23113c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode)
23123c6c2bebSJaegeuk Kim {
231391942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN);
23143c6c2bebSJaegeuk Kim }
23153c6c2bebSJaegeuk Kim 
23161e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode)
23171e84371fSJaegeuk Kim {
231891942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_DROP_CACHE);
23191e84371fSJaegeuk Kim }
23201e84371fSJaegeuk Kim 
2321f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page)
23221001b347SHuajun Li {
2323695fd1edSChao Yu 	struct f2fs_inode *ri = F2FS_INODE(page);
23247a2af766SChao Yu 	int extra_size = get_extra_isize(inode);
2325cac5a3d8SDongOh Shin 
23267a2af766SChao Yu 	return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]);
23271001b347SHuajun Li }
23281001b347SHuajun Li 
232934d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode)
233034d67debSChao Yu {
233191942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_DENTRY);
233234d67debSChao Yu }
233334d67debSChao Yu 
23349486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
23359486ba44SJaegeuk Kim {
23369486ba44SJaegeuk Kim 	if (!f2fs_has_inline_dentry(dir))
23379486ba44SJaegeuk Kim 		kunmap(page);
23389486ba44SJaegeuk Kim }
23399486ba44SJaegeuk Kim 
2340b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type)
2341b5492af7SJaegeuk Kim {
2342b5492af7SJaegeuk Kim 	return F2FS_I(inode)->i_advise & type;
2343b5492af7SJaegeuk Kim }
2344b5492af7SJaegeuk Kim 
2345b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type)
2346b5492af7SJaegeuk Kim {
2347b5492af7SJaegeuk Kim 	F2FS_I(inode)->i_advise |= type;
23487c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2349b5492af7SJaegeuk Kim }
2350b5492af7SJaegeuk Kim 
2351b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type)
2352b5492af7SJaegeuk Kim {
2353b5492af7SJaegeuk Kim 	F2FS_I(inode)->i_advise &= ~type;
23547c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
2355b5492af7SJaegeuk Kim }
2356b5492af7SJaegeuk Kim 
235726787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
235826787236SJaegeuk Kim {
2359a0d00fadSChao Yu 	bool ret;
2360a0d00fadSChao Yu 
236126787236SJaegeuk Kim 	if (dsync) {
236226787236SJaegeuk Kim 		struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
236326787236SJaegeuk Kim 
236426787236SJaegeuk Kim 		spin_lock(&sbi->inode_lock[DIRTY_META]);
236526787236SJaegeuk Kim 		ret = list_empty(&F2FS_I(inode)->gdirty_list);
236626787236SJaegeuk Kim 		spin_unlock(&sbi->inode_lock[DIRTY_META]);
236726787236SJaegeuk Kim 		return ret;
236826787236SJaegeuk Kim 	}
236926787236SJaegeuk Kim 	if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) ||
237026787236SJaegeuk Kim 			file_keep_isize(inode) ||
237126787236SJaegeuk Kim 			i_size_read(inode) & PAGE_MASK)
237226787236SJaegeuk Kim 		return false;
2373a0d00fadSChao Yu 
2374a0d00fadSChao Yu 	down_read(&F2FS_I(inode)->i_sem);
2375a0d00fadSChao Yu 	ret = F2FS_I(inode)->last_disk_size == i_size_read(inode);
2376a0d00fadSChao Yu 	up_read(&F2FS_I(inode)->i_sem);
2377a0d00fadSChao Yu 
2378a0d00fadSChao Yu 	return ret;
2379267378d4SChao Yu }
2380267378d4SChao Yu 
2381267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb)
2382267378d4SChao Yu {
23831751e8a6SLinus Torvalds 	return sb->s_flags & SB_RDONLY;
238477888c1eSJaegeuk Kim }
238577888c1eSJaegeuk Kim 
2386744602cfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
2387744602cfSJaegeuk Kim {
2388aaec2b1dSChao Yu 	return is_set_ckpt_flags(sbi, CP_ERROR_FLAG);
2389744602cfSJaegeuk Kim }
2390744602cfSJaegeuk Kim 
2391eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str)
2392eaa693f4SJaegeuk Kim {
2393eaa693f4SJaegeuk Kim 	if (str->len == 1 && str->name[0] == '.')
2394eaa693f4SJaegeuk Kim 		return true;
2395eaa693f4SJaegeuk Kim 
2396eaa693f4SJaegeuk Kim 	if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
2397eaa693f4SJaegeuk Kim 		return true;
2398eaa693f4SJaegeuk Kim 
2399eaa693f4SJaegeuk Kim 	return false;
2400eaa693f4SJaegeuk Kim }
2401eaa693f4SJaegeuk Kim 
24023e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode)
24033e72f721SJaegeuk Kim {
24043e72f721SJaegeuk Kim 	if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) ||
240591942321SJaegeuk Kim 			is_inode_flag_set(inode, FI_NO_EXTENT))
24063e72f721SJaegeuk Kim 		return false;
24073e72f721SJaegeuk Kim 
2408886f56f9SAl Viro 	return S_ISREG(inode->i_mode);
24093e72f721SJaegeuk Kim }
24103e72f721SJaegeuk Kim 
24111ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
24121ecc0c5cSChao Yu 					size_t size, gfp_t flags)
24130414b004SJaegeuk Kim {
24142c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION
241555523519SChao Yu 	if (time_to_inject(sbi, FAULT_KMALLOC)) {
241655523519SChao Yu 		f2fs_show_injection_info(FAULT_KMALLOC);
24172c63feadSJaegeuk Kim 		return NULL;
241855523519SChao Yu 	}
24192c63feadSJaegeuk Kim #endif
24200414b004SJaegeuk Kim 	return kmalloc(size, flags);
24210414b004SJaegeuk Kim }
24220414b004SJaegeuk Kim 
24237a2af766SChao Yu static inline int get_extra_isize(struct inode *inode)
2424f2470371SChao Yu {
24257a2af766SChao Yu 	return F2FS_I(inode)->i_extra_isize / sizeof(__le32);
2426f2470371SChao Yu }
2427f2470371SChao Yu 
24286afc662eSChao Yu static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb);
24296afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode)
24306afc662eSChao Yu {
24316afc662eSChao Yu 	return F2FS_I(inode)->i_inline_xattr_size;
24326afc662eSChao Yu }
24336afc662eSChao Yu 
2434a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \
243591942321SJaegeuk Kim 	((is_inode_flag_set(i, FI_ACL_MODE)) ? \
2436a6dda0e6SChristoph Hellwig 	 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
2437a6dda0e6SChristoph Hellwig 
24387a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE			\
24397a2af766SChao Yu 	(offsetof(struct f2fs_inode, i_extra_end) -	\
24407a2af766SChao Yu 	offsetof(struct f2fs_inode, i_extra_isize))	\
24417a2af766SChao Yu 
24425c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE	(offsetof(struct f2fs_inode, i_addr))
24435c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field)		\
24445c57132eSChao Yu 		((offsetof(typeof(*f2fs_inode), field) +	\
24455c57132eSChao Yu 		sizeof((f2fs_inode)->field))			\
24465c57132eSChao Yu 		<= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize))	\
24475c57132eSChao Yu 
2448b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi)
2449b0af6d49SChao Yu {
2450b0af6d49SChao Yu 	int i;
2451b0af6d49SChao Yu 
2452b0af6d49SChao Yu 	spin_lock(&sbi->iostat_lock);
2453b0af6d49SChao Yu 	for (i = 0; i < NR_IO_TYPE; i++)
2454b0af6d49SChao Yu 		sbi->write_iostat[i] = 0;
2455b0af6d49SChao Yu 	spin_unlock(&sbi->iostat_lock);
2456b0af6d49SChao Yu }
2457b0af6d49SChao Yu 
2458b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
2459b0af6d49SChao Yu 			enum iostat_type type, unsigned long long io_bytes)
2460b0af6d49SChao Yu {
2461b0af6d49SChao Yu 	if (!sbi->iostat_enable)
2462b0af6d49SChao Yu 		return;
2463b0af6d49SChao Yu 	spin_lock(&sbi->iostat_lock);
2464b0af6d49SChao Yu 	sbi->write_iostat[type] += io_bytes;
2465b0af6d49SChao Yu 
2466b0af6d49SChao Yu 	if (type == APP_WRITE_IO || type == APP_DIRECT_IO)
2467b0af6d49SChao Yu 		sbi->write_iostat[APP_BUFFERED_IO] =
2468b0af6d49SChao Yu 			sbi->write_iostat[APP_WRITE_IO] -
2469b0af6d49SChao Yu 			sbi->write_iostat[APP_DIRECT_IO];
2470b0af6d49SChao Yu 	spin_unlock(&sbi->iostat_lock);
2471b0af6d49SChao Yu }
2472b0af6d49SChao Yu 
247339a53e0cSJaegeuk Kim /*
247439a53e0cSJaegeuk Kim  * file.c
247539a53e0cSJaegeuk Kim  */
2476cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
2477cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn);
2478cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock);
2479cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode);
2480a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat,
2481a528d35eSDavid Howells 			u32 request_mask, unsigned int flags);
2482cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr);
2483cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end);
2484cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count);
2485cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
2486cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
248739a53e0cSJaegeuk Kim 
248839a53e0cSJaegeuk Kim /*
248939a53e0cSJaegeuk Kim  * inode.c
249039a53e0cSJaegeuk Kim  */
2491cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode);
2492704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page);
2493704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page);
2494cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
2495cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
2496cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
2497cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page);
2498cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode);
2499cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
2500cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode);
2501cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode);
250239a53e0cSJaegeuk Kim 
250339a53e0cSJaegeuk Kim /*
250439a53e0cSJaegeuk Kim  * namei.c
250539a53e0cSJaegeuk Kim  */
250639a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child);
250739a53e0cSJaegeuk Kim 
250839a53e0cSJaegeuk Kim /*
250939a53e0cSJaegeuk Kim  * dir.c
251039a53e0cSJaegeuk Kim  */
2511cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode);
2512cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de);
2513cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname,
2514cac5a3d8SDongOh Shin 			f2fs_hash_t namehash, int *max_slots,
2515cac5a3d8SDongOh Shin 			struct f2fs_dentry_ptr *d);
2516cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
2517cac5a3d8SDongOh Shin 			unsigned int start_pos, struct fscrypt_str *fstr);
2518cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent,
2519cac5a3d8SDongOh Shin 			struct f2fs_dentry_ptr *d);
2520cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
2521cac5a3d8SDongOh Shin 			const struct qstr *new_name,
2522cac5a3d8SDongOh Shin 			const struct qstr *orig_name, struct page *dpage);
2523cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode,
2524cac5a3d8SDongOh Shin 			unsigned int current_depth);
2525cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots);
2526cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode);
2527cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
2528cac5a3d8SDongOh Shin 			struct fscrypt_name *fname, struct page **res_page);
2529cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
2530cac5a3d8SDongOh Shin 			const struct qstr *child, struct page **res_page);
2531cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p);
2532cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
2533cac5a3d8SDongOh Shin 			struct page **page);
2534cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
2535cac5a3d8SDongOh Shin 			struct page *page, struct inode *inode);
2536cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
2537cac5a3d8SDongOh Shin 			const struct qstr *name, f2fs_hash_t name_hash,
2538cac5a3d8SDongOh Shin 			unsigned int bit_pos);
2539cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name,
2540cac5a3d8SDongOh Shin 			const struct qstr *orig_name,
2541cac5a3d8SDongOh Shin 			struct inode *inode, nid_t ino, umode_t mode);
2542cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname,
2543cac5a3d8SDongOh Shin 			struct inode *inode, nid_t ino, umode_t mode);
2544cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name,
2545cac5a3d8SDongOh Shin 			struct inode *inode, nid_t ino, umode_t mode);
2546cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
2547cac5a3d8SDongOh Shin 			struct inode *dir, struct inode *inode);
2548cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir);
2549cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir);
255039a53e0cSJaegeuk Kim 
2551b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
2552b7f7a5e0SAl Viro {
25532b0143b5SDavid Howells 	return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name,
2554510022a8SJaegeuk Kim 				inode, inode->i_ino, inode->i_mode);
2555b7f7a5e0SAl Viro }
2556b7f7a5e0SAl Viro 
255739a53e0cSJaegeuk Kim /*
255839a53e0cSJaegeuk Kim  * super.c
255939a53e0cSJaegeuk Kim  */
2560cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync);
2561cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode);
2562ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly);
25634b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb);
2564cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover);
2565cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync);
2566a07ef784SNamjae Jeon extern __printf(3, 4)
2567cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
2568984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi);
256939a53e0cSJaegeuk Kim 
257039a53e0cSJaegeuk Kim /*
257139a53e0cSJaegeuk Kim  * hash.c
257239a53e0cSJaegeuk Kim  */
25736332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info,
25746332cd32SJaegeuk Kim 				struct fscrypt_name *fname);
257539a53e0cSJaegeuk Kim 
257639a53e0cSJaegeuk Kim /*
257739a53e0cSJaegeuk Kim  * node.c
257839a53e0cSJaegeuk Kim  */
257939a53e0cSJaegeuk Kim struct dnode_of_data;
258039a53e0cSJaegeuk Kim struct node_info;
258139a53e0cSJaegeuk Kim 
2582cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type);
2583cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid);
2584cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid);
2585cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino);
2586cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni);
2587cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs);
2588cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode);
2589cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from);
25909c77f754SJaegeuk Kim int truncate_xattr_node(struct inode *inode);
2591cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino);
2592cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode);
2593cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode);
25945f4ce6abSYunlei He struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs);
2595cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid);
2596cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid);
2597cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start);
2598cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type);
2599cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
2600cac5a3d8SDongOh Shin 			struct writeback_control *wbc, bool atomic);
2601401db79fSYunlong Song int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc,
2602b0af6d49SChao Yu 			bool do_balance, enum iostat_type io_type);
260322ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount);
2604cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid);
2605cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
2606cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
2607cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
2608cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page);
2609d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page,
2610cac5a3d8SDongOh Shin 			block_t blkaddr);
2611cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page);
2612cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi,
2613cac5a3d8SDongOh Shin 			unsigned int segno, struct f2fs_summary_block *sum);
261422ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2615cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi);
2616cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi);
26176e6093a8SNamjae Jeon int __init create_node_manager_caches(void);
261839a53e0cSJaegeuk Kim void destroy_node_manager_caches(void);
261939a53e0cSJaegeuk Kim 
262039a53e0cSJaegeuk Kim /*
262139a53e0cSJaegeuk Kim  * segment.c
262239a53e0cSJaegeuk Kim  */
2623b3a97a2aSJaegeuk Kim bool need_SSR(struct f2fs_sb_info *sbi);
2624cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page);
262557864ae5SJaegeuk Kim void drop_inmem_pages_all(struct f2fs_sb_info *sbi);
2626cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode);
26278c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page);
2628cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode);
2629cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need);
2630cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi);
263139d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino);
2632cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi);
26331228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi);
2634cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free);
2635cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr);
2636cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
263778997b56SChao Yu void init_discard_policy(struct discard_policy *dpolicy, int discard_type,
263878997b56SChao Yu 						unsigned int granularity);
2639cce13252SChao Yu void stop_discard_thread(struct f2fs_sb_info *sbi);
2640cf5c759fSChao Yu bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi);
2641cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2642cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi);
2643cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
2644cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi);
2645cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
2646cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2647cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno);
2648cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr);
2649b0af6d49SChao Yu void write_meta_page(struct f2fs_sb_info *sbi, struct page *page,
2650b0af6d49SChao Yu 						enum iostat_type io_type);
2651cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio);
2652cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio);
2653d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio);
2654cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
2655cac5a3d8SDongOh Shin 			block_t old_blkaddr, block_t new_blkaddr,
2656cac5a3d8SDongOh Shin 			bool recover_curseg, bool recover_newaddr);
2657cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
2658cac5a3d8SDongOh Shin 			block_t old_addr, block_t new_addr,
2659cac5a3d8SDongOh Shin 			unsigned char version, bool recover_curseg,
2660cac5a3d8SDongOh Shin 			bool recover_newaddr);
2661cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
2662cac5a3d8SDongOh Shin 			block_t old_blkaddr, block_t *new_blkaddr,
2663fb830fc5SChao Yu 			struct f2fs_summary *sum, int type,
2664fb830fc5SChao Yu 			struct f2fs_io_info *fio, bool add_list);
2665cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page,
2666cac5a3d8SDongOh Shin 			enum page_type type, bool ordered);
2667d4c759eeSJaegeuk Kim void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr);
2668cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
2669cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
2670cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
2671cac5a3d8SDongOh Shin 			unsigned int val, int alloc);
2672cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2673cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi);
2674cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi);
26757fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void);
26767fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void);
267739a53e0cSJaegeuk Kim 
267839a53e0cSJaegeuk Kim /*
267939a53e0cSJaegeuk Kim  * checkpoint.c
268039a53e0cSJaegeuk Kim  */
2681cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io);
2682cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
2683cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
2684cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index);
2685cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type);
2686cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
2687cac5a3d8SDongOh Shin 			int type, bool sync);
2688cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index);
2689cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
2690b0af6d49SChao Yu 			long nr_to_write, enum iostat_type io_type);
2691cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
2692cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
2693cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all);
2694cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode);
269539d787beSChao Yu void set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
269639d787beSChao Yu 					unsigned int devidx, int type);
269739d787beSChao Yu bool is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino,
269839d787beSChao Yu 					unsigned int devidx, int type);
2699cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi);
2700cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi);
2701cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi);
2702cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode);
2703cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino);
2704cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi);
2705cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi);
2706cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page);
2707cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode);
2708cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type);
2709cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2710cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi);
27116e6093a8SNamjae Jeon int __init create_checkpoint_caches(void);
271239a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void);
271339a53e0cSJaegeuk Kim 
271439a53e0cSJaegeuk Kim /*
271539a53e0cSJaegeuk Kim  * data.c
271639a53e0cSJaegeuk Kim  */
2717b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
2718b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
2719942fd319SJaegeuk Kim 				struct inode *inode, nid_t ino, pgoff_t idx,
2720b9109b0eSJaegeuk Kim 				enum page_type type);
2721b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
2722cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio);
2723b9109b0eSJaegeuk Kim int f2fs_submit_page_write(struct f2fs_io_info *fio);
2724cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
2725cac5a3d8SDongOh Shin 			block_t blk_addr, struct bio *bio);
2726cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
2727cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn);
2728cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr);
2729cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count);
2730cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn);
2731cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index);
2732cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from);
2733cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index);
2734cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index,
2735cac5a3d8SDongOh Shin 			int op_flags, bool for_write);
2736cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index);
2737cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index,
2738cac5a3d8SDongOh Shin 			bool for_write);
2739cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode,
2740cac5a3d8SDongOh Shin 			struct page *ipage, pgoff_t index, bool new_i_size);
2741cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio);
2742cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
2743cac5a3d8SDongOh Shin 			int create, int flag);
2744cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2745cac5a3d8SDongOh Shin 			u64 start, u64 len);
2746cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page);
2747b0af6d49SChao Yu int __f2fs_write_data_pages(struct address_space *mapping,
2748b0af6d49SChao Yu 						struct writeback_control *wbc,
2749b0af6d49SChao Yu 						enum iostat_type io_type);
2750cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset,
2751cac5a3d8SDongOh Shin 			unsigned int length);
2752cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait);
27535b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION
2754cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage,
2755cac5a3d8SDongOh Shin 			struct page *page, enum migrate_mode mode);
27565b7a487cSWeichao Guo #endif
275739a53e0cSJaegeuk Kim 
275839a53e0cSJaegeuk Kim /*
275939a53e0cSJaegeuk Kim  * gc.c
276039a53e0cSJaegeuk Kim  */
2761cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi);
2762cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi);
2763cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode);
2764e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background,
2765e066b83cSJaegeuk Kim 			unsigned int segno);
2766cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi);
276739a53e0cSJaegeuk Kim 
276839a53e0cSJaegeuk Kim /*
276939a53e0cSJaegeuk Kim  * recovery.c
277039a53e0cSJaegeuk Kim  */
2771cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only);
2772cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi);
277339a53e0cSJaegeuk Kim 
277439a53e0cSJaegeuk Kim /*
277539a53e0cSJaegeuk Kim  * debug.c
277639a53e0cSJaegeuk Kim  */
277739a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS
277839a53e0cSJaegeuk Kim struct f2fs_stat_info {
277939a53e0cSJaegeuk Kim 	struct list_head stat_list;
278039a53e0cSJaegeuk Kim 	struct f2fs_sb_info *sbi;
278139a53e0cSJaegeuk Kim 	int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
278239a53e0cSJaegeuk Kim 	int main_area_segs, main_area_sections, main_area_zones;
27835b7ee374SChao Yu 	unsigned long long hit_largest, hit_cached, hit_rbtree;
27845b7ee374SChao Yu 	unsigned long long hit_total, total_ext;
2785c00ba554SJaegeuk Kim 	int ext_tree, zombie_tree, ext_node;
27862c8a4a28SJaegeuk Kim 	int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta;
27872c8a4a28SJaegeuk Kim 	int ndirty_data, ndirty_qdata;
278835782b23SJaegeuk Kim 	int inmem_pages;
27892c8a4a28SJaegeuk Kim 	unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all;
27905b0ef73cSJaegeuk Kim 	int nats, dirty_nats, sits, dirty_sits;
27915b0ef73cSJaegeuk Kim 	int free_nids, avail_nids, alloc_nids;
279239a53e0cSJaegeuk Kim 	int total_count, utilization;
27938b8dd65fSChao Yu 	int bg_gc, nr_wb_cp_data, nr_wb_data;
279414d8d5f7SChao Yu 	int nr_flushing, nr_flushed, flush_list_empty;
279514d8d5f7SChao Yu 	int nr_discarding, nr_discarded;
27965f32366aSChao Yu 	int nr_discard_cmd;
2797d84d1cbdSChao Yu 	unsigned int undiscard_blks;
2798a00861dbSJaegeuk Kim 	int inline_xattr, inline_inode, inline_dir, append, update, orphans;
2799648d50baSChao Yu 	int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt;
2800f83a2584SYunlei He 	unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks;
280139a53e0cSJaegeuk Kim 	unsigned int bimodal, avg_vblocks;
280239a53e0cSJaegeuk Kim 	int util_free, util_valid, util_invalid;
280339a53e0cSJaegeuk Kim 	int rsvd_segs, overp_segs;
280439a53e0cSJaegeuk Kim 	int dirty_count, node_pages, meta_pages;
280542190d2aSJaegeuk Kim 	int prefree_count, call_count, cp_count, bg_cp_count;
280639a53e0cSJaegeuk Kim 	int tot_segs, node_segs, data_segs, free_segs, free_secs;
2807e1235983SChangman Lee 	int bg_node_segs, bg_data_segs;
280839a53e0cSJaegeuk Kim 	int tot_blks, data_blks, node_blks;
2809e1235983SChangman Lee 	int bg_data_blks, bg_node_blks;
281039a53e0cSJaegeuk Kim 	int curseg[NR_CURSEG_TYPE];
281139a53e0cSJaegeuk Kim 	int cursec[NR_CURSEG_TYPE];
281239a53e0cSJaegeuk Kim 	int curzone[NR_CURSEG_TYPE];
281339a53e0cSJaegeuk Kim 
281439a53e0cSJaegeuk Kim 	unsigned int segment_count[2];
281539a53e0cSJaegeuk Kim 	unsigned int block_count[2];
2816b9a2c252SChangman Lee 	unsigned int inplace_count;
28179edcdabfSChao Yu 	unsigned long long base_mem, cache_mem, page_mem;
281839a53e0cSJaegeuk Kim };
281939a53e0cSJaegeuk Kim 
2820963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
2821963d4f7dSGu Zheng {
2822963d4f7dSGu Zheng 	return (struct f2fs_stat_info *)sbi->stat_info;
2823963d4f7dSGu Zheng }
2824963d4f7dSGu Zheng 
2825942e0be6SChangman Lee #define stat_inc_cp_count(si)		((si)->cp_count++)
282642190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si)	((si)->bg_cp_count++)
282739a53e0cSJaegeuk Kim #define stat_inc_call_count(si)		((si)->call_count++)
2828dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi)	((sbi)->bg_gc++)
282933fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type)	((sbi)->ndirty_inode[type]++)
283033fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type)	((sbi)->ndirty_inode[type]--)
28315b7ee374SChao Yu #define stat_inc_total_hit(sbi)		(atomic64_inc(&(sbi)->total_hit_ext))
28325b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_rbtree))
28335b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_largest))
28345b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_cached))
2835d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode)					\
2836d5e8f6c9SChao Yu 	do {								\
2837d5e8f6c9SChao Yu 		if (f2fs_has_inline_xattr(inode))			\
2838d5e8f6c9SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_xattr));	\
2839d5e8f6c9SChao Yu 	} while (0)
2840d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode)					\
2841d5e8f6c9SChao Yu 	do {								\
2842d5e8f6c9SChao Yu 		if (f2fs_has_inline_xattr(inode))			\
2843d5e8f6c9SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_xattr));	\
2844d5e8f6c9SChao Yu 	} while (0)
28450dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode)					\
28460dbdc2aeSJaegeuk Kim 	do {								\
28470dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
284803e14d52SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_inode));	\
28490dbdc2aeSJaegeuk Kim 	} while (0)
28500dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode)					\
28510dbdc2aeSJaegeuk Kim 	do {								\
28520dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
285303e14d52SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_inode));	\
28540dbdc2aeSJaegeuk Kim 	} while (0)
28553289c061SJaegeuk Kim #define stat_inc_inline_dir(inode)					\
28563289c061SJaegeuk Kim 	do {								\
28573289c061SJaegeuk Kim 		if (f2fs_has_inline_dentry(inode))			\
285803e14d52SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_dir));	\
28593289c061SJaegeuk Kim 	} while (0)
28603289c061SJaegeuk Kim #define stat_dec_inline_dir(inode)					\
28613289c061SJaegeuk Kim 	do {								\
28623289c061SJaegeuk Kim 		if (f2fs_has_inline_dentry(inode))			\
286303e14d52SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_dir));	\
28643289c061SJaegeuk Kim 	} while (0)
2865dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg)					\
2866dcdfff65SJaegeuk Kim 		((sbi)->segment_count[(curseg)->alloc_type]++)
2867dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg)				\
2868dcdfff65SJaegeuk Kim 		((sbi)->block_count[(curseg)->alloc_type]++)
2869b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi)					\
2870b9a2c252SChangman Lee 		(atomic_inc(&(sbi)->inplace_count))
287126a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode)					\
2872cac5a3d8SDongOh Shin 		(atomic_inc(&F2FS_I_SB(inode)->aw_cnt))
287326a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode)					\
2874cac5a3d8SDongOh Shin 		(atomic_dec(&F2FS_I_SB(inode)->aw_cnt))
287526a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode)				\
287626a28a0cSJaegeuk Kim 	do {								\
287726a28a0cSJaegeuk Kim 		int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt);	\
287826a28a0cSJaegeuk Kim 		int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt);	\
287926a28a0cSJaegeuk Kim 		if (cur > max)						\
288026a28a0cSJaegeuk Kim 			atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur);	\
288126a28a0cSJaegeuk Kim 	} while (0)
2882648d50baSChao Yu #define stat_inc_volatile_write(inode)					\
2883648d50baSChao Yu 		(atomic_inc(&F2FS_I_SB(inode)->vw_cnt))
2884648d50baSChao Yu #define stat_dec_volatile_write(inode)					\
2885648d50baSChao Yu 		(atomic_dec(&F2FS_I_SB(inode)->vw_cnt))
2886648d50baSChao Yu #define stat_update_max_volatile_write(inode)				\
2887648d50baSChao Yu 	do {								\
2888648d50baSChao Yu 		int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt);	\
2889648d50baSChao Yu 		int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt);	\
2890648d50baSChao Yu 		if (cur > max)						\
2891648d50baSChao Yu 			atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur);	\
2892648d50baSChao Yu 	} while (0)
2893e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type)				\
289439a53e0cSJaegeuk Kim 	do {								\
2895963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
289668afcf2dSTomohiro Kusumi 		si->tot_segs++;						\
289768afcf2dSTomohiro Kusumi 		if ((type) == SUM_TYPE_DATA) {				\
289839a53e0cSJaegeuk Kim 			si->data_segs++;				\
2899e1235983SChangman Lee 			si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0;	\
2900e1235983SChangman Lee 		} else {						\
290139a53e0cSJaegeuk Kim 			si->node_segs++;				\
2902e1235983SChangman Lee 			si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0;	\
2903e1235983SChangman Lee 		}							\
290439a53e0cSJaegeuk Kim 	} while (0)
290539a53e0cSJaegeuk Kim 
290639a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks)				\
290768afcf2dSTomohiro Kusumi 	((si)->tot_blks += (blks))
290839a53e0cSJaegeuk Kim 
2909e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type)			\
291039a53e0cSJaegeuk Kim 	do {								\
2911963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
291239a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
291339a53e0cSJaegeuk Kim 		si->data_blks += (blks);				\
291468afcf2dSTomohiro Kusumi 		si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0;	\
291539a53e0cSJaegeuk Kim 	} while (0)
291639a53e0cSJaegeuk Kim 
2917e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type)			\
291839a53e0cSJaegeuk Kim 	do {								\
2919963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
292039a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
292139a53e0cSJaegeuk Kim 		si->node_blks += (blks);				\
292268afcf2dSTomohiro Kusumi 		si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0;	\
292339a53e0cSJaegeuk Kim 	} while (0)
292439a53e0cSJaegeuk Kim 
2925cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi);
2926cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi);
2927787c7b8cSChao Yu int __init f2fs_create_root_stats(void);
29284589d25dSNamjae Jeon void f2fs_destroy_root_stats(void);
292939a53e0cSJaegeuk Kim #else
2930d66450e7SArnd Bergmann #define stat_inc_cp_count(si)				do { } while (0)
2931d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si)			do { } while (0)
2932d66450e7SArnd Bergmann #define stat_inc_call_count(si)				do { } while (0)
2933d66450e7SArnd Bergmann #define stat_inc_bggc_count(si)				do { } while (0)
2934d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type)			do { } while (0)
2935d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type)			do { } while (0)
2936d66450e7SArnd Bergmann #define stat_inc_total_hit(sb)				do { } while (0)
2937d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb)			do { } while (0)
2938d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi)			do { } while (0)
2939d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi)			do { } while (0)
2940d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode)			do { } while (0)
2941d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode)			do { } while (0)
2942d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode)			do { } while (0)
2943d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode)			do { } while (0)
2944d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode)			do { } while (0)
2945d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode)			do { } while (0)
2946d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode)			do { } while (0)
2947d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode)			do { } while (0)
2948d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode)		do { } while (0)
2949d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode)			do { } while (0)
2950d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode)			do { } while (0)
2951d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode)		do { } while (0)
2952d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg)			do { } while (0)
2953d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg)		do { } while (0)
2954d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi)			do { } while (0)
2955d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type)		do { } while (0)
2956d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks)		do { } while (0)
2957d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type)	do { } while (0)
2958d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type)	do { } while (0)
295939a53e0cSJaegeuk Kim 
296039a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
296139a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
2962787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; }
29634589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { }
296439a53e0cSJaegeuk Kim #endif
296539a53e0cSJaegeuk Kim 
296639a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations;
296739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations;
296839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations;
296939a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops;
297039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops;
297139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops;
297239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations;
297339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations;
2974cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
297539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations;
297629e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab;
29771001b347SHuajun Li 
2978e18c65b2SHuajun Li /*
2979e18c65b2SHuajun Li  * inline.c
2980e18c65b2SHuajun Li  */
2981cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode);
2982cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode);
2983cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage);
2984bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from);
2985cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page);
2986cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page);
2987cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode);
2988cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page);
2989cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage);
2990cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir,
2991cac5a3d8SDongOh Shin 			struct fscrypt_name *fname, struct page **res_page);
2992cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent,
2993cac5a3d8SDongOh Shin 			struct page *ipage);
2994cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
2995cac5a3d8SDongOh Shin 			const struct qstr *orig_name,
2996cac5a3d8SDongOh Shin 			struct inode *inode, nid_t ino, umode_t mode);
2997cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
2998cac5a3d8SDongOh Shin 			struct inode *dir, struct inode *inode);
2999cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir);
3000cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
3001cac5a3d8SDongOh Shin 			struct fscrypt_str *fstr);
3002cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode,
3003cac5a3d8SDongOh Shin 			struct fiemap_extent_info *fieinfo,
3004cac5a3d8SDongOh Shin 			__u64 start, __u64 len);
3005cde4de12SJaegeuk Kim 
3006cde4de12SJaegeuk Kim /*
30072658e50dSJaegeuk Kim  * shrinker.c
30082658e50dSJaegeuk Kim  */
3009cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink,
3010cac5a3d8SDongOh Shin 			struct shrink_control *sc);
3011cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink,
3012cac5a3d8SDongOh Shin 			struct shrink_control *sc);
3013cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi);
3014cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi);
30152658e50dSJaegeuk Kim 
30162658e50dSJaegeuk Kim /*
3017a28ef1f5SChao Yu  * extent_cache.c
3018a28ef1f5SChao Yu  */
3019004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root,
3020004b6862SChao Yu 				struct rb_entry *cached_re, unsigned int ofs);
3021004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi,
3022004b6862SChao Yu 				struct rb_root *root, struct rb_node **parent,
3023004b6862SChao Yu 				unsigned int ofs);
3024004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root,
3025004b6862SChao Yu 		struct rb_entry *cached_re, unsigned int ofs,
3026004b6862SChao Yu 		struct rb_entry **prev_entry, struct rb_entry **next_entry,
3027004b6862SChao Yu 		struct rb_node ***insert_p, struct rb_node **insert_parent,
3028004b6862SChao Yu 		bool force);
3029df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi,
3030df0f6b44SChao Yu 						struct rb_root *root);
3031cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink);
3032cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext);
3033cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode);
3034cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode);
3035cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode);
3036cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs,
3037cac5a3d8SDongOh Shin 			struct extent_info *ei);
3038cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn);
303919b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
3040cac5a3d8SDongOh Shin 			pgoff_t fofs, block_t blkaddr, unsigned int len);
3041cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi);
3042a28ef1f5SChao Yu int __init create_extent_cache(void);
3043a28ef1f5SChao Yu void destroy_extent_cache(void);
3044a28ef1f5SChao Yu 
3045a28ef1f5SChao Yu /*
30468ceffcb2SChao Yu  * sysfs.c
30478ceffcb2SChao Yu  */
3048dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void);
3049dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void);
3050dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi);
3051dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi);
30528ceffcb2SChao Yu 
30538ceffcb2SChao Yu /*
3054cde4de12SJaegeuk Kim  * crypto support
3055cde4de12SJaegeuk Kim  */
30560b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode)
3057cde4de12SJaegeuk Kim {
3058cde4de12SJaegeuk Kim 	return file_is_encrypt(inode);
3059cde4de12SJaegeuk Kim }
3060cde4de12SJaegeuk Kim 
30611958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode)
30621958593eSJaegeuk Kim {
30631958593eSJaegeuk Kim 	return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode);
30641958593eSJaegeuk Kim }
30651958593eSJaegeuk Kim 
3066cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode)
3067cde4de12SJaegeuk Kim {
3068cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION
3069cde4de12SJaegeuk Kim 	file_set_encrypt(inode);
30702ee6a576SEric Biggers 	inode->i_flags |= S_ENCRYPTED;
3071cde4de12SJaegeuk Kim #endif
3072cde4de12SJaegeuk Kim }
3073cde4de12SJaegeuk Kim 
3074cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio)
3075cde4de12SJaegeuk Kim {
30760b81d077SJaegeuk Kim 	return bio->bi_private != NULL;
3077cde4de12SJaegeuk Kim }
3078cde4de12SJaegeuk Kim 
3079cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb)
3080cde4de12SJaegeuk Kim {
3081cde4de12SJaegeuk Kim 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT);
3082cde4de12SJaegeuk Kim }
3083f424f664SJaegeuk Kim 
30840bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb)
308552763a4bSJaegeuk Kim {
30860bfd7a09SDamien Le Moal 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED);
308752763a4bSJaegeuk Kim }
308852763a4bSJaegeuk Kim 
30897a2af766SChao Yu static inline int f2fs_sb_has_extra_attr(struct super_block *sb)
30907a2af766SChao Yu {
30917a2af766SChao Yu 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_EXTRA_ATTR);
30927a2af766SChao Yu }
30937a2af766SChao Yu 
30945c57132eSChao Yu static inline int f2fs_sb_has_project_quota(struct super_block *sb)
30955c57132eSChao Yu {
30965c57132eSChao Yu 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_PRJQUOTA);
30975c57132eSChao Yu }
30985c57132eSChao Yu 
3099704956ecSChao Yu static inline int f2fs_sb_has_inode_chksum(struct super_block *sb)
3100704956ecSChao Yu {
3101704956ecSChao Yu 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CHKSUM);
3102704956ecSChao Yu }
3103704956ecSChao Yu 
31046afc662eSChao Yu static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb)
31056afc662eSChao Yu {
31066afc662eSChao Yu 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_FLEXIBLE_INLINE_XATTR);
31076afc662eSChao Yu }
31086afc662eSChao Yu 
3109234a9689SJaegeuk Kim static inline int f2fs_sb_has_quota_ino(struct super_block *sb)
3110234a9689SJaegeuk Kim {
3111234a9689SJaegeuk Kim 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_QUOTA_INO);
3112234a9689SJaegeuk Kim }
3113234a9689SJaegeuk Kim 
3114178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED
3115178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi,
31163c62be17SJaegeuk Kim 			struct block_device *bdev, block_t blkaddr)
3117178053e2SDamien Le Moal {
3118178053e2SDamien Le Moal 	unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz;
31193c62be17SJaegeuk Kim 	int i;
3120178053e2SDamien Le Moal 
31213c62be17SJaegeuk Kim 	for (i = 0; i < sbi->s_ndevs; i++)
31223c62be17SJaegeuk Kim 		if (FDEV(i).bdev == bdev)
31233c62be17SJaegeuk Kim 			return FDEV(i).blkz_type[zno];
31243c62be17SJaegeuk Kim 	return -EINVAL;
3125178053e2SDamien Le Moal }
3126178053e2SDamien Le Moal #endif
3127178053e2SDamien Le Moal 
312896ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
312996ba2decSDamien Le Moal {
313096ba2decSDamien Le Moal 	struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
313196ba2decSDamien Le Moal 
313296ba2decSDamien Le Moal 	return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb);
313352763a4bSJaegeuk Kim }
313452763a4bSJaegeuk Kim 
313552763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
313652763a4bSJaegeuk Kim {
313752763a4bSJaegeuk Kim 	clear_opt(sbi, ADAPTIVE);
313852763a4bSJaegeuk Kim 	clear_opt(sbi, LFS);
313952763a4bSJaegeuk Kim 
314052763a4bSJaegeuk Kim 	switch (mt) {
314152763a4bSJaegeuk Kim 	case F2FS_MOUNT_ADAPTIVE:
314252763a4bSJaegeuk Kim 		set_opt(sbi, ADAPTIVE);
314352763a4bSJaegeuk Kim 		break;
314452763a4bSJaegeuk Kim 	case F2FS_MOUNT_LFS:
314552763a4bSJaegeuk Kim 		set_opt(sbi, LFS);
314652763a4bSJaegeuk Kim 		break;
314752763a4bSJaegeuk Kim 	}
314852763a4bSJaegeuk Kim }
314952763a4bSJaegeuk Kim 
3150fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode)
3151fcc85a4dSJaegeuk Kim {
3152fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION
3153886f56f9SAl Viro 	umode_t mode = inode->i_mode;
3154fcc85a4dSJaegeuk Kim 
3155fcc85a4dSJaegeuk Kim 	return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
3156fcc85a4dSJaegeuk Kim #else
3157fcc85a4dSJaegeuk Kim 	return 0;
3158fcc85a4dSJaegeuk Kim #endif
3159fcc85a4dSJaegeuk Kim }
3160fcc85a4dSJaegeuk Kim 
316139a53e0cSJaegeuk Kim #endif
3162