xref: /openbmc/linux/fs/f2fs/f2fs.h (revision 0a595ebaaa6b53a2226d3fee2a2fd616ea5ba378)
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>
250b81d077SJaegeuk Kim #include <linux/fscrypto.h>
2643b6573bSKeith Mok #include <crypto/hash.h>
2739a53e0cSJaegeuk Kim 
285d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS
299850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition)	BUG_ON(condition)
305d56b671SJaegeuk Kim #else
319850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition)					\
329850cf4aSJaegeuk Kim 	do {								\
339850cf4aSJaegeuk Kim 		if (unlikely(condition)) {				\
349850cf4aSJaegeuk Kim 			WARN_ON(1);					\
35caf0047eSChao Yu 			set_sbi_flag(sbi, SBI_NEED_FSCK);		\
369850cf4aSJaegeuk Kim 		}							\
379850cf4aSJaegeuk Kim 	} while (0)
385d56b671SJaegeuk Kim #endif
395d56b671SJaegeuk Kim 
402c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION
412c63feadSJaegeuk Kim enum {
422c63feadSJaegeuk Kim 	FAULT_KMALLOC,
43c41f3cc3SJaegeuk Kim 	FAULT_PAGE_ALLOC,
44cb78942bSJaegeuk Kim 	FAULT_ALLOC_NID,
45cb78942bSJaegeuk Kim 	FAULT_ORPHAN,
46cb78942bSJaegeuk Kim 	FAULT_BLOCK,
47cb78942bSJaegeuk Kim 	FAULT_DIR_DEPTH,
4853aa6bbfSJaegeuk Kim 	FAULT_EVICT_INODE,
498b038c70SChao Yu 	FAULT_IO,
500f348028SChao Yu 	FAULT_CHECKPOINT,
512c63feadSJaegeuk Kim 	FAULT_MAX,
522c63feadSJaegeuk Kim };
532c63feadSJaegeuk Kim 
5408796897SSheng Yong struct f2fs_fault_info {
5508796897SSheng Yong 	atomic_t inject_ops;
5608796897SSheng Yong 	unsigned int inject_rate;
5708796897SSheng Yong 	unsigned int inject_type;
5808796897SSheng Yong };
5908796897SSheng Yong 
602c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX];
611ecc0c5cSChao Yu #define IS_FAULT_SET(fi, type) (fi->inject_type & (1 << (type)))
622c63feadSJaegeuk Kim #endif
632c63feadSJaegeuk Kim 
6439a53e0cSJaegeuk Kim /*
6539a53e0cSJaegeuk Kim  * For mount options
6639a53e0cSJaegeuk Kim  */
6739a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC		0x00000001
6839a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD	0x00000002
6939a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD		0x00000004
7039a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP		0x00000008
7139a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER		0x00000010
7239a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL		0x00000020
7339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY	0x00000040
74444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR		0x00000080
751001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA		0x00000100
7634d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY	0x00000200
7734d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE		0x00000400
7834d67debSChao Yu #define F2FS_MOUNT_NOBARRIER		0x00000800
79d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT		0x00001000
8089672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE		0x00002000
816aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC		0x00004000
82343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH		0x00008000
8373faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION	0x00010000
8436abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE		0x00020000
8536abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS			0x00040000
8639a53e0cSJaegeuk Kim 
8739a53e0cSJaegeuk Kim #define clear_opt(sbi, option)	(sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
8839a53e0cSJaegeuk Kim #define set_opt(sbi, option)	(sbi->mount_opt.opt |= F2FS_MOUNT_##option)
8939a53e0cSJaegeuk Kim #define test_opt(sbi, option)	(sbi->mount_opt.opt & F2FS_MOUNT_##option)
9039a53e0cSJaegeuk Kim 
9139a53e0cSJaegeuk Kim #define ver_after(a, b)	(typecheck(unsigned long long, a) &&		\
9239a53e0cSJaegeuk Kim 		typecheck(unsigned long long, b) &&			\
9339a53e0cSJaegeuk Kim 		((long long)((a) - (b)) > 0))
9439a53e0cSJaegeuk Kim 
95a9841c4dSJaegeuk Kim typedef u32 block_t;	/*
96a9841c4dSJaegeuk Kim 			 * should not change u32, since it is the on-disk block
97a9841c4dSJaegeuk Kim 			 * address format, __le32.
98a9841c4dSJaegeuk Kim 			 */
9939a53e0cSJaegeuk Kim typedef u32 nid_t;
10039a53e0cSJaegeuk Kim 
10139a53e0cSJaegeuk Kim struct f2fs_mount_info {
10239a53e0cSJaegeuk Kim 	unsigned int	opt;
10339a53e0cSJaegeuk Kim };
10439a53e0cSJaegeuk Kim 
105cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT	0x0001
1060bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED	0x0002
107cde4de12SJaegeuk Kim 
10876f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask)					\
10976f105a2SJaegeuk Kim 	((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
11076f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask)					\
11176f105a2SJaegeuk Kim 	F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)
11276f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask)					\
11376f105a2SJaegeuk Kim 	F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)
11476f105a2SJaegeuk Kim 
11539a53e0cSJaegeuk Kim /*
11639a53e0cSJaegeuk Kim  * For checkpoint manager
11739a53e0cSJaegeuk Kim  */
11839a53e0cSJaegeuk Kim enum {
11939a53e0cSJaegeuk Kim 	NAT_BITMAP,
12039a53e0cSJaegeuk Kim 	SIT_BITMAP
12139a53e0cSJaegeuk Kim };
12239a53e0cSJaegeuk Kim 
12375ab4cb8SJaegeuk Kim enum {
12475ab4cb8SJaegeuk Kim 	CP_UMOUNT,
125119ee914SJaegeuk Kim 	CP_FASTBOOT,
12675ab4cb8SJaegeuk Kim 	CP_SYNC,
12710027551SJaegeuk Kim 	CP_RECOVERY,
1284b2fecc8SJaegeuk Kim 	CP_DISCARD,
12975ab4cb8SJaegeuk Kim };
13075ab4cb8SJaegeuk Kim 
1312d9e9c32SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS	2
132bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi)	\
133bba681cbSJaegeuk Kim 		(SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
134a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi)	\
135a66cdd98SJaegeuk Kim 		(BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
13660b99b48SJaegeuk Kim #define DEF_CP_INTERVAL			60	/* 60 secs */
137dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL		5	/* 5 secs */
138bba681cbSJaegeuk Kim 
13975ab4cb8SJaegeuk Kim struct cp_control {
14075ab4cb8SJaegeuk Kim 	int reason;
1414b2fecc8SJaegeuk Kim 	__u64 trim_start;
1424b2fecc8SJaegeuk Kim 	__u64 trim_end;
1434b2fecc8SJaegeuk Kim 	__u64 trim_minlen;
1444b2fecc8SJaegeuk Kim 	__u64 trimmed;
14575ab4cb8SJaegeuk Kim };
14675ab4cb8SJaegeuk Kim 
147662befdaSChao Yu /*
14881c1a0f1SChao Yu  * For CP/NAT/SIT/SSA readahead
149662befdaSChao Yu  */
150662befdaSChao Yu enum {
151662befdaSChao Yu 	META_CP,
152662befdaSChao Yu 	META_NAT,
15381c1a0f1SChao Yu 	META_SIT,
1544c521f49SJaegeuk Kim 	META_SSA,
1554c521f49SJaegeuk Kim 	META_POR,
156662befdaSChao Yu };
157662befdaSChao Yu 
1586451e041SJaegeuk Kim /* for the list of ino */
1596451e041SJaegeuk Kim enum {
1606451e041SJaegeuk Kim 	ORPHAN_INO,		/* for orphan ino list */
161fff04f90SJaegeuk Kim 	APPEND_INO,		/* for append ino list */
162fff04f90SJaegeuk Kim 	UPDATE_INO,		/* for update ino list */
1636451e041SJaegeuk Kim 	MAX_INO_ENTRY,		/* max. list */
1646451e041SJaegeuk Kim };
1656451e041SJaegeuk Kim 
1666451e041SJaegeuk Kim struct ino_entry {
16739a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
16839a53e0cSJaegeuk Kim 	nid_t ino;		/* inode number */
16939a53e0cSJaegeuk Kim };
17039a53e0cSJaegeuk Kim 
1712710fd7eSChao Yu /* for the list of inodes to be GCed */
17206292073SChao Yu struct inode_entry {
17339a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
17439a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
17539a53e0cSJaegeuk Kim };
17639a53e0cSJaegeuk Kim 
1777fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */
1787fd9e544SJaegeuk Kim struct discard_entry {
1797fd9e544SJaegeuk Kim 	struct list_head list;	/* list head */
1807fd9e544SJaegeuk Kim 	block_t blkaddr;	/* block address to be discarded */
1817fd9e544SJaegeuk Kim 	int len;		/* # of consecutive blocks of the discard */
1827fd9e544SJaegeuk Kim };
1837fd9e544SJaegeuk Kim 
184275b66b0SChao Yu struct bio_entry {
185275b66b0SChao Yu 	struct list_head list;
186275b66b0SChao Yu 	struct bio *bio;
187275b66b0SChao Yu 	struct completion event;
188275b66b0SChao Yu 	int error;
189275b66b0SChao Yu };
190275b66b0SChao Yu 
19139a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */
19239a53e0cSJaegeuk Kim struct fsync_inode_entry {
19339a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
19439a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
195c52e1b10SJaegeuk Kim 	block_t blkaddr;	/* block address locating the last fsync */
196c52e1b10SJaegeuk Kim 	block_t last_dentry;	/* block address locating the last dentry */
19739a53e0cSJaegeuk Kim };
19839a53e0cSJaegeuk Kim 
199dfc08a12SChao Yu #define nats_in_cursum(jnl)		(le16_to_cpu(jnl->n_nats))
200dfc08a12SChao Yu #define sits_in_cursum(jnl)		(le16_to_cpu(jnl->n_sits))
20139a53e0cSJaegeuk Kim 
202dfc08a12SChao Yu #define nat_in_journal(jnl, i)		(jnl->nat_j.entries[i].ne)
203dfc08a12SChao Yu #define nid_in_journal(jnl, i)		(jnl->nat_j.entries[i].nid)
204dfc08a12SChao Yu #define sit_in_journal(jnl, i)		(jnl->sit_j.entries[i].se)
205dfc08a12SChao Yu #define segno_in_journal(jnl, i)	(jnl->sit_j.entries[i].segno)
20639a53e0cSJaegeuk Kim 
207dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl)	(NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl))
208dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl)	(SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl))
209309cc2b6SJaegeuk Kim 
210dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i)
21139a53e0cSJaegeuk Kim {
212dfc08a12SChao Yu 	int before = nats_in_cursum(journal);
213dfc08a12SChao Yu 	journal->n_nats = cpu_to_le16(before + i);
21439a53e0cSJaegeuk Kim 	return before;
21539a53e0cSJaegeuk Kim }
21639a53e0cSJaegeuk Kim 
217dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i)
21839a53e0cSJaegeuk Kim {
219dfc08a12SChao Yu 	int before = sits_in_cursum(journal);
220dfc08a12SChao Yu 	journal->n_sits = cpu_to_le16(before + i);
22139a53e0cSJaegeuk Kim 	return before;
22239a53e0cSJaegeuk Kim }
22339a53e0cSJaegeuk Kim 
224dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal,
225dfc08a12SChao Yu 							int size, int type)
226184a5cd2SChao Yu {
227184a5cd2SChao Yu 	if (type == NAT_JOURNAL)
228dfc08a12SChao Yu 		return size <= MAX_NAT_JENTRIES(journal);
229dfc08a12SChao Yu 	return size <= MAX_SIT_JENTRIES(journal);
230184a5cd2SChao Yu }
231184a5cd2SChao Yu 
23239a53e0cSJaegeuk Kim /*
233e9750824SNamjae Jeon  * ioctl commands
234e9750824SNamjae Jeon  */
235e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS		FS_IOC_GETFLAGS
236e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS		FS_IOC_SETFLAGS
237d49f3e89SChao Yu #define F2FS_IOC_GETVERSION		FS_IOC_GETVERSION
238e9750824SNamjae Jeon 
23988b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC		0xf5
24088b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE	_IO(F2FS_IOCTL_MAGIC, 1)
24188b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE	_IO(F2FS_IOCTL_MAGIC, 2)
24202a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 3)
2431e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 4)
2441e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 5)
245c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT	_IO(F2FS_IOCTL_MAGIC, 6)
246456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT	_IO(F2FS_IOCTL_MAGIC, 7)
247d323d005SChao Yu #define F2FS_IOC_DEFRAGMENT		_IO(F2FS_IOCTL_MAGIC, 8)
2484dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE		_IOWR(F2FS_IOCTL_MAGIC, 9,	\
2494dd6f977SJaegeuk Kim 						struct f2fs_move_range)
25088b88a66SJaegeuk Kim 
2510b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY	FS_IOC_SET_ENCRYPTION_POLICY
2520b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY	FS_IOC_GET_ENCRYPTION_POLICY
2530b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT	FS_IOC_GET_ENCRYPTION_PWSALT
254f424f664SJaegeuk Kim 
2551abff93dSJaegeuk Kim /*
2561abff93dSJaegeuk Kim  * should be same as XFS_IOC_GOINGDOWN.
2571abff93dSJaegeuk Kim  * Flags for going down operation used by FS_IOC_GOINGDOWN
2581abff93dSJaegeuk Kim  */
2591abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN	_IOR('X', 125, __u32)	/* Shutdown */
2601abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC	0x0	/* going down with full sync */
2611abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC	0x1	/* going down with metadata */
2621abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC		0x2	/* going down */
263c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH	0x3	/* going down with meta flush */
2641abff93dSJaegeuk Kim 
265e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
266e9750824SNamjae Jeon /*
267e9750824SNamjae Jeon  * ioctl commands in 32 bit emulation
268e9750824SNamjae Jeon  */
269e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS		FS_IOC32_GETFLAGS
270e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS		FS_IOC32_SETFLAGS
27104ef4b62SChao Yu #define F2FS_IOC32_GETVERSION		FS_IOC32_GETVERSION
272e9750824SNamjae Jeon #endif
273e9750824SNamjae Jeon 
274d323d005SChao Yu struct f2fs_defragment {
275d323d005SChao Yu 	u64 start;
276d323d005SChao Yu 	u64 len;
277d323d005SChao Yu };
278d323d005SChao Yu 
2794dd6f977SJaegeuk Kim struct f2fs_move_range {
2804dd6f977SJaegeuk Kim 	u32 dst_fd;		/* destination fd */
2814dd6f977SJaegeuk Kim 	u64 pos_in;		/* start position in src_fd */
2824dd6f977SJaegeuk Kim 	u64 pos_out;		/* start position in dst_fd */
2834dd6f977SJaegeuk Kim 	u64 len;		/* size to move */
2844dd6f977SJaegeuk Kim };
2854dd6f977SJaegeuk Kim 
286e9750824SNamjae Jeon /*
28739a53e0cSJaegeuk Kim  * For INODE and NODE manager
28839a53e0cSJaegeuk Kim  */
2897b3cd7d6SJaegeuk Kim /* for directory operations */
2907b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr {
291d8c6822aSJaegeuk Kim 	struct inode *inode;
2927b3cd7d6SJaegeuk Kim 	const void *bitmap;
2937b3cd7d6SJaegeuk Kim 	struct f2fs_dir_entry *dentry;
2947b3cd7d6SJaegeuk Kim 	__u8 (*filename)[F2FS_SLOT_LEN];
2957b3cd7d6SJaegeuk Kim 	int max;
2967b3cd7d6SJaegeuk Kim };
2977b3cd7d6SJaegeuk Kim 
298d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode,
299d8c6822aSJaegeuk Kim 		struct f2fs_dentry_ptr *d, void *src, int type)
3007b3cd7d6SJaegeuk Kim {
301d8c6822aSJaegeuk Kim 	d->inode = inode;
302d8c6822aSJaegeuk Kim 
3037b3cd7d6SJaegeuk Kim 	if (type == 1) {
3047b3cd7d6SJaegeuk Kim 		struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src;
3057b3cd7d6SJaegeuk Kim 		d->max = NR_DENTRY_IN_BLOCK;
3067b3cd7d6SJaegeuk Kim 		d->bitmap = &t->dentry_bitmap;
3077b3cd7d6SJaegeuk Kim 		d->dentry = t->dentry;
3087b3cd7d6SJaegeuk Kim 		d->filename = t->filename;
3097b3cd7d6SJaegeuk Kim 	} else {
3107b3cd7d6SJaegeuk Kim 		struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src;
3117b3cd7d6SJaegeuk Kim 		d->max = NR_INLINE_DENTRY;
3127b3cd7d6SJaegeuk Kim 		d->bitmap = &t->dentry_bitmap;
3137b3cd7d6SJaegeuk Kim 		d->dentry = t->dentry;
3147b3cd7d6SJaegeuk Kim 		d->filename = t->filename;
3157b3cd7d6SJaegeuk Kim 	}
3167b3cd7d6SJaegeuk Kim }
3177b3cd7d6SJaegeuk Kim 
318dbe6a5ffSJaegeuk Kim /*
319dbe6a5ffSJaegeuk Kim  * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
320dbe6a5ffSJaegeuk Kim  * as its node offset to distinguish from index node blocks.
321dbe6a5ffSJaegeuk Kim  * But some bits are used to mark the node block.
32239a53e0cSJaegeuk Kim  */
323dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET	((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
324dbe6a5ffSJaegeuk Kim 				>> OFFSET_BIT_SHIFT)
325266e97a8SJaegeuk Kim enum {
326266e97a8SJaegeuk Kim 	ALLOC_NODE,			/* allocate a new node page if needed */
327266e97a8SJaegeuk Kim 	LOOKUP_NODE,			/* look up a node without readahead */
328266e97a8SJaegeuk Kim 	LOOKUP_NODE_RA,			/*
329266e97a8SJaegeuk Kim 					 * look up a node with readahead called
3304f4124d0SChao Yu 					 * by get_data_block.
33139a53e0cSJaegeuk Kim 					 */
332266e97a8SJaegeuk Kim };
333266e97a8SJaegeuk Kim 
334a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX	0xffffffff	/* maximum link count per file */
33539a53e0cSJaegeuk Kim 
336817202d9SChao Yu #define MAX_DIR_RA_PAGES	4	/* maximum ra pages of dir */
337817202d9SChao Yu 
33813054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */
33913054c54SChao Yu #define EXT_TREE_VEC_SIZE	64
34013054c54SChao Yu 
34139a53e0cSJaegeuk Kim /* for in-memory extent cache entry */
34213054c54SChao Yu #define F2FS_MIN_EXTENT_LEN	64	/* minimum extent length */
34313054c54SChao Yu 
34413054c54SChao Yu /* number of extent info in extent cache we try to shrink */
34513054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER	128
346c11abd1aSJaegeuk Kim 
34739a53e0cSJaegeuk Kim struct extent_info {
34839a53e0cSJaegeuk Kim 	unsigned int fofs;		/* start offset in a file */
3494d0b0bd4SChao Yu 	u32 blk;			/* start block address of the extent */
350111d2495SMasanari Iida 	unsigned int len;		/* length of the extent */
35139a53e0cSJaegeuk Kim };
35239a53e0cSJaegeuk Kim 
35313054c54SChao Yu struct extent_node {
35413054c54SChao Yu 	struct rb_node rb_node;		/* rb node located in rb-tree */
35513054c54SChao Yu 	struct list_head list;		/* node in global extent list of sbi */
35613054c54SChao Yu 	struct extent_info ei;		/* extent info */
357201ef5e0SHou Pengyang 	struct extent_tree *et;		/* extent tree pointer */
35813054c54SChao Yu };
35913054c54SChao Yu 
36013054c54SChao Yu struct extent_tree {
36113054c54SChao Yu 	nid_t ino;			/* inode number */
36213054c54SChao Yu 	struct rb_root root;		/* root of extent info rb-tree */
36362c8af65SChao Yu 	struct extent_node *cached_en;	/* recently accessed extent node */
3643e72f721SJaegeuk Kim 	struct extent_info largest;	/* largested extent info */
365137d09f0SJaegeuk Kim 	struct list_head list;		/* to be used by sbi->zombie_list */
36613054c54SChao Yu 	rwlock_t lock;			/* protect extent info rb-tree */
36768e35385SChao Yu 	atomic_t node_cnt;		/* # of extent node in rb-tree*/
36813054c54SChao Yu };
36913054c54SChao Yu 
37039a53e0cSJaegeuk Kim /*
371003a3e1dSJaegeuk Kim  * This structure is taken from ext4_map_blocks.
372003a3e1dSJaegeuk Kim  *
373003a3e1dSJaegeuk Kim  * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
374003a3e1dSJaegeuk Kim  */
375003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW		(1 << BH_New)
376003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED		(1 << BH_Mapped)
3777f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN	(1 << BH_Unwritten)
3787f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS		(F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
3797f63eb77SJaegeuk Kim 				F2FS_MAP_UNWRITTEN)
380003a3e1dSJaegeuk Kim 
381003a3e1dSJaegeuk Kim struct f2fs_map_blocks {
382003a3e1dSJaegeuk Kim 	block_t m_pblk;
383003a3e1dSJaegeuk Kim 	block_t m_lblk;
384003a3e1dSJaegeuk Kim 	unsigned int m_len;
385003a3e1dSJaegeuk Kim 	unsigned int m_flags;
386da85985cSChao Yu 	pgoff_t *m_next_pgofs;		/* point next possible non-hole pgofs */
387003a3e1dSJaegeuk Kim };
388003a3e1dSJaegeuk Kim 
389e2b4e2bcSChao Yu /* for flag in get_data_block */
390e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ		0
391e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO		1
392e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP		2
393e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP		3
394b439b103SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_DIO		4
39524b84912SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_AIO		5
396e2b4e2bcSChao Yu 
397003a3e1dSJaegeuk Kim /*
39839a53e0cSJaegeuk Kim  * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
39939a53e0cSJaegeuk Kim  */
40039a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT	0x01
401354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT	0x02
402cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT	0x04
403e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT	0x08
40426787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT	0x10
40539a53e0cSJaegeuk Kim 
406b5492af7SJaegeuk Kim #define file_is_cold(inode)	is_file(inode, FADVISE_COLD_BIT)
407b5492af7SJaegeuk Kim #define file_wrong_pino(inode)	is_file(inode, FADVISE_LOST_PINO_BIT)
408b5492af7SJaegeuk Kim #define file_set_cold(inode)	set_file(inode, FADVISE_COLD_BIT)
409b5492af7SJaegeuk Kim #define file_lost_pino(inode)	set_file(inode, FADVISE_LOST_PINO_BIT)
410b5492af7SJaegeuk Kim #define file_clear_cold(inode)	clear_file(inode, FADVISE_COLD_BIT)
411b5492af7SJaegeuk Kim #define file_got_pino(inode)	clear_file(inode, FADVISE_LOST_PINO_BIT)
412cde4de12SJaegeuk Kim #define file_is_encrypt(inode)	is_file(inode, FADVISE_ENCRYPT_BIT)
413cde4de12SJaegeuk Kim #define file_set_encrypt(inode)	set_file(inode, FADVISE_ENCRYPT_BIT)
414cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT)
415e7d55452SJaegeuk Kim #define file_enc_name(inode)	is_file(inode, FADVISE_ENC_NAME_BIT)
416e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
41726787236SJaegeuk Kim #define file_keep_isize(inode)	is_file(inode, FADVISE_KEEP_SIZE_BIT)
41826787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT)
419cde4de12SJaegeuk Kim 
420ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL		0
421ab9fa662SJaegeuk Kim 
42239a53e0cSJaegeuk Kim struct f2fs_inode_info {
42339a53e0cSJaegeuk Kim 	struct inode vfs_inode;		/* serve a vfs inode */
42439a53e0cSJaegeuk Kim 	unsigned long i_flags;		/* keep an inode flags for ioctl */
42539a53e0cSJaegeuk Kim 	unsigned char i_advise;		/* use to give file attribute hints */
42638431545SJaegeuk Kim 	unsigned char i_dir_level;	/* use for dentry level for large dir */
42739a53e0cSJaegeuk Kim 	unsigned int i_current_depth;	/* use only in directory structure */
4286666e6aaSJaegeuk Kim 	unsigned int i_pino;		/* parent inode number */
42939a53e0cSJaegeuk Kim 	umode_t i_acl_mode;		/* keep file acl mode temporarily */
43039a53e0cSJaegeuk Kim 
43139a53e0cSJaegeuk Kim 	/* Use below internally in f2fs*/
43239a53e0cSJaegeuk Kim 	unsigned long flags;		/* use to pass per-file flags */
433d928bfbfSJaegeuk Kim 	struct rw_semaphore i_sem;	/* protect fi info */
434204706c7SJaegeuk Kim 	atomic_t dirty_pages;		/* # of dirty pages */
43539a53e0cSJaegeuk Kim 	f2fs_hash_t chash;		/* hash value of given file name */
43639a53e0cSJaegeuk Kim 	unsigned int clevel;		/* maximum level of given file name */
43739a53e0cSJaegeuk Kim 	nid_t i_xattr_nid;		/* node id that contains xattrs */
438e518ff81SJaegeuk Kim 	unsigned long long xattr_ver;	/* cp version of xattr modification */
43926de9b11SJaegeuk Kim 	loff_t	last_disk_size;		/* lastly written file size */
44088b88a66SJaegeuk Kim 
4410f18b462SJaegeuk Kim 	struct list_head dirty_list;	/* dirty list for dirs and files */
4420f18b462SJaegeuk Kim 	struct list_head gdirty_list;	/* linked in global dirty list */
44388b88a66SJaegeuk Kim 	struct list_head inmem_pages;	/* inmemory pages managed by f2fs */
44488b88a66SJaegeuk Kim 	struct mutex inmem_lock;	/* lock for inmemory pages */
4453e72f721SJaegeuk Kim 	struct extent_tree *extent_tree;	/* cached extent_tree entry */
44682e0a5aaSChao Yu 	struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */
44739a53e0cSJaegeuk Kim };
44839a53e0cSJaegeuk Kim 
44939a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext,
450bd933d4fSChao Yu 					struct f2fs_extent *i_ext)
45139a53e0cSJaegeuk Kim {
452bd933d4fSChao Yu 	ext->fofs = le32_to_cpu(i_ext->fofs);
453bd933d4fSChao Yu 	ext->blk = le32_to_cpu(i_ext->blk);
454bd933d4fSChao Yu 	ext->len = le32_to_cpu(i_ext->len);
45539a53e0cSJaegeuk Kim }
45639a53e0cSJaegeuk Kim 
45739a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext,
45839a53e0cSJaegeuk Kim 					struct f2fs_extent *i_ext)
45939a53e0cSJaegeuk Kim {
46039a53e0cSJaegeuk Kim 	i_ext->fofs = cpu_to_le32(ext->fofs);
4614d0b0bd4SChao Yu 	i_ext->blk = cpu_to_le32(ext->blk);
46239a53e0cSJaegeuk Kim 	i_ext->len = cpu_to_le32(ext->len);
46339a53e0cSJaegeuk Kim }
46439a53e0cSJaegeuk Kim 
465429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
466429511cdSChao Yu 						u32 blk, unsigned int len)
467429511cdSChao Yu {
468429511cdSChao Yu 	ei->fofs = fofs;
469429511cdSChao Yu 	ei->blk = blk;
470429511cdSChao Yu 	ei->len = len;
471429511cdSChao Yu }
472429511cdSChao Yu 
4730bdee482SChao Yu static inline bool __is_extent_same(struct extent_info *ei1,
4740bdee482SChao Yu 						struct extent_info *ei2)
4750bdee482SChao Yu {
4760bdee482SChao Yu 	return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk &&
4770bdee482SChao Yu 						ei1->len == ei2->len);
4780bdee482SChao Yu }
4790bdee482SChao Yu 
480429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back,
481429511cdSChao Yu 						struct extent_info *front)
482429511cdSChao Yu {
483429511cdSChao Yu 	return (back->fofs + back->len == front->fofs &&
484429511cdSChao Yu 			back->blk + back->len == front->blk);
485429511cdSChao Yu }
486429511cdSChao Yu 
487429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur,
488429511cdSChao Yu 						struct extent_info *back)
489429511cdSChao Yu {
490429511cdSChao Yu 	return __is_extent_mergeable(back, cur);
491429511cdSChao Yu }
492429511cdSChao Yu 
493429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur,
494429511cdSChao Yu 						struct extent_info *front)
495429511cdSChao Yu {
496429511cdSChao Yu 	return __is_extent_mergeable(cur, front);
497429511cdSChao Yu }
498429511cdSChao Yu 
4997c45729aSJaegeuk Kim extern void f2fs_mark_inode_dirty_sync(struct inode *, bool);
500205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode,
501205b9822SJaegeuk Kim 			struct extent_tree *et, struct extent_node *en)
5024abd3f5aSChao Yu {
503205b9822SJaegeuk Kim 	if (en->ei.len > et->largest.len) {
5044abd3f5aSChao Yu 		et->largest = en->ei;
5057c45729aSJaegeuk Kim 		f2fs_mark_inode_dirty_sync(inode, true);
506205b9822SJaegeuk Kim 	}
5074abd3f5aSChao Yu }
5084abd3f5aSChao Yu 
509b8559dc2SChao Yu enum nid_list {
510b8559dc2SChao Yu 	FREE_NID_LIST,
511b8559dc2SChao Yu 	ALLOC_NID_LIST,
512b8559dc2SChao Yu 	MAX_NID_LIST,
513b8559dc2SChao Yu };
514b8559dc2SChao Yu 
51539a53e0cSJaegeuk Kim struct f2fs_nm_info {
51639a53e0cSJaegeuk Kim 	block_t nat_blkaddr;		/* base disk address of NAT */
51739a53e0cSJaegeuk Kim 	nid_t max_nid;			/* maximum possible node ids */
51804d47e67SChao Yu 	nid_t available_nids;		/* # of available node ids */
51939a53e0cSJaegeuk Kim 	nid_t next_scan_nid;		/* the next nid to be scanned */
520cdfc41c1SJaegeuk Kim 	unsigned int ram_thresh;	/* control the memory footprint */
521ea1a29a0SChao Yu 	unsigned int ra_nid_pages;	/* # of nid pages to be readaheaded */
5222304cb0cSChao Yu 	unsigned int dirty_nats_ratio;	/* control dirty nats ratio threshold */
52339a53e0cSJaegeuk Kim 
52439a53e0cSJaegeuk Kim 	/* NAT cache management */
52539a53e0cSJaegeuk Kim 	struct radix_tree_root nat_root;/* root of the nat entry cache */
526309cc2b6SJaegeuk Kim 	struct radix_tree_root nat_set_root;/* root of the nat set cache */
527b873b798SJaegeuk Kim 	struct rw_semaphore nat_tree_lock;	/* protect nat_tree_lock */
52839a53e0cSJaegeuk Kim 	struct list_head nat_entries;	/* cached nat entry list (clean) */
529309cc2b6SJaegeuk Kim 	unsigned int nat_cnt;		/* the # of cached nat entries */
530aec71382SChao Yu 	unsigned int dirty_nat_cnt;	/* total num of nat entries in set */
53139a53e0cSJaegeuk Kim 
53239a53e0cSJaegeuk Kim 	/* free node ids management */
5338a7ed66aSJaegeuk Kim 	struct radix_tree_root free_nid_root;/* root of the free_nid cache */
534b8559dc2SChao Yu 	struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */
535b8559dc2SChao Yu 	unsigned int nid_cnt[MAX_NID_LIST];	/* the number of free node id */
536b8559dc2SChao Yu 	spinlock_t nid_list_lock;	/* protect nid lists ops */
53739a53e0cSJaegeuk Kim 	struct mutex build_lock;	/* lock for build free nids */
53839a53e0cSJaegeuk Kim 
53939a53e0cSJaegeuk Kim 	/* for checkpoint */
54039a53e0cSJaegeuk Kim 	char *nat_bitmap;		/* NAT bitmap pointer */
54139a53e0cSJaegeuk Kim 	int bitmap_size;		/* bitmap size */
54239a53e0cSJaegeuk Kim };
54339a53e0cSJaegeuk Kim 
54439a53e0cSJaegeuk Kim /*
54539a53e0cSJaegeuk Kim  * this structure is used as one of function parameters.
54639a53e0cSJaegeuk Kim  * all the information are dedicated to a given direct node block determined
54739a53e0cSJaegeuk Kim  * by the data offset in a file.
54839a53e0cSJaegeuk Kim  */
54939a53e0cSJaegeuk Kim struct dnode_of_data {
55039a53e0cSJaegeuk Kim 	struct inode *inode;		/* vfs inode pointer */
55139a53e0cSJaegeuk Kim 	struct page *inode_page;	/* its inode page, NULL is possible */
55239a53e0cSJaegeuk Kim 	struct page *node_page;		/* cached direct node page */
55339a53e0cSJaegeuk Kim 	nid_t nid;			/* node id of the direct node block */
55439a53e0cSJaegeuk Kim 	unsigned int ofs_in_node;	/* data offset in the node page */
55539a53e0cSJaegeuk Kim 	bool inode_page_locked;		/* inode page is locked or not */
55693bae099SJaegeuk Kim 	bool node_changed;		/* is node block changed */
5573cf45747SChao Yu 	char cur_level;			/* level of hole node page */
5583cf45747SChao Yu 	char max_level;			/* level of current page located */
55939a53e0cSJaegeuk Kim 	block_t	data_blkaddr;		/* block address of the node block */
56039a53e0cSJaegeuk Kim };
56139a53e0cSJaegeuk Kim 
56239a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
56339a53e0cSJaegeuk Kim 		struct page *ipage, struct page *npage, nid_t nid)
56439a53e0cSJaegeuk Kim {
565d66d1f76SJaegeuk Kim 	memset(dn, 0, sizeof(*dn));
56639a53e0cSJaegeuk Kim 	dn->inode = inode;
56739a53e0cSJaegeuk Kim 	dn->inode_page = ipage;
56839a53e0cSJaegeuk Kim 	dn->node_page = npage;
56939a53e0cSJaegeuk Kim 	dn->nid = nid;
57039a53e0cSJaegeuk Kim }
57139a53e0cSJaegeuk Kim 
57239a53e0cSJaegeuk Kim /*
57339a53e0cSJaegeuk Kim  * For SIT manager
57439a53e0cSJaegeuk Kim  *
57539a53e0cSJaegeuk Kim  * By default, there are 6 active log areas across the whole main area.
57639a53e0cSJaegeuk Kim  * When considering hot and cold data separation to reduce cleaning overhead,
57739a53e0cSJaegeuk Kim  * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
57839a53e0cSJaegeuk Kim  * respectively.
57939a53e0cSJaegeuk Kim  * In the current design, you should not change the numbers intentionally.
58039a53e0cSJaegeuk Kim  * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
58139a53e0cSJaegeuk Kim  * logs individually according to the underlying devices. (default: 6)
58239a53e0cSJaegeuk Kim  * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
58339a53e0cSJaegeuk Kim  * data and 8 for node logs.
58439a53e0cSJaegeuk Kim  */
58539a53e0cSJaegeuk Kim #define	NR_CURSEG_DATA_TYPE	(3)
58639a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE	(3)
58739a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
58839a53e0cSJaegeuk Kim 
58939a53e0cSJaegeuk Kim enum {
59039a53e0cSJaegeuk Kim 	CURSEG_HOT_DATA	= 0,	/* directory entry blocks */
59139a53e0cSJaegeuk Kim 	CURSEG_WARM_DATA,	/* data blocks */
59239a53e0cSJaegeuk Kim 	CURSEG_COLD_DATA,	/* multimedia or GCed data blocks */
59339a53e0cSJaegeuk Kim 	CURSEG_HOT_NODE,	/* direct node blocks of directory files */
59439a53e0cSJaegeuk Kim 	CURSEG_WARM_NODE,	/* direct node blocks of normal files */
59539a53e0cSJaegeuk Kim 	CURSEG_COLD_NODE,	/* indirect node blocks */
59638aa0889SJaegeuk Kim 	NO_CHECK_TYPE,
59739a53e0cSJaegeuk Kim };
59839a53e0cSJaegeuk Kim 
5996b4afdd7SJaegeuk Kim struct flush_cmd {
6006b4afdd7SJaegeuk Kim 	struct completion wait;
601721bd4d5SGu Zheng 	struct llist_node llnode;
6026b4afdd7SJaegeuk Kim 	int ret;
6036b4afdd7SJaegeuk Kim };
6046b4afdd7SJaegeuk Kim 
605a688b9d9SGu Zheng struct flush_cmd_control {
606a688b9d9SGu Zheng 	struct task_struct *f2fs_issue_flush;	/* flush thread */
607a688b9d9SGu Zheng 	wait_queue_head_t flush_wait_queue;	/* waiting queue for wake-up */
6080a87f664SJaegeuk Kim 	atomic_t submit_flush;			/* # of issued flushes */
609721bd4d5SGu Zheng 	struct llist_head issue_list;		/* list for command issue */
610721bd4d5SGu Zheng 	struct llist_node *dispatch_list;	/* list for command dispatch */
611a688b9d9SGu Zheng };
612a688b9d9SGu Zheng 
61339a53e0cSJaegeuk Kim struct f2fs_sm_info {
61439a53e0cSJaegeuk Kim 	struct sit_info *sit_info;		/* whole segment information */
61539a53e0cSJaegeuk Kim 	struct free_segmap_info *free_info;	/* free segment information */
61639a53e0cSJaegeuk Kim 	struct dirty_seglist_info *dirty_info;	/* dirty segment information */
61739a53e0cSJaegeuk Kim 	struct curseg_info *curseg_array;	/* active segment information */
61839a53e0cSJaegeuk Kim 
61939a53e0cSJaegeuk Kim 	block_t seg0_blkaddr;		/* block address of 0'th segment */
62039a53e0cSJaegeuk Kim 	block_t main_blkaddr;		/* start block address of main area */
62139a53e0cSJaegeuk Kim 	block_t ssa_blkaddr;		/* start block address of SSA area */
62239a53e0cSJaegeuk Kim 
62339a53e0cSJaegeuk Kim 	unsigned int segment_count;	/* total # of segments */
62439a53e0cSJaegeuk Kim 	unsigned int main_segments;	/* # of segments in main area */
62539a53e0cSJaegeuk Kim 	unsigned int reserved_segments;	/* # of reserved segments */
62639a53e0cSJaegeuk Kim 	unsigned int ovp_segments;	/* # of overprovision segments */
62781eb8d6eSJaegeuk Kim 
62881eb8d6eSJaegeuk Kim 	/* a threshold to reclaim prefree segments */
62981eb8d6eSJaegeuk Kim 	unsigned int rec_prefree_segments;
6307fd9e544SJaegeuk Kim 
6317fd9e544SJaegeuk Kim 	/* for small discard management */
6327fd9e544SJaegeuk Kim 	struct list_head discard_list;		/* 4KB discard list */
633275b66b0SChao Yu 	struct list_head wait_list;		/* linked with issued discard bio */
6347fd9e544SJaegeuk Kim 	int nr_discards;			/* # of discards in the list */
6357fd9e544SJaegeuk Kim 	int max_discards;			/* max. discards to be issued */
636216fbd64SJaegeuk Kim 
637bba681cbSJaegeuk Kim 	/* for batched trimming */
638bba681cbSJaegeuk Kim 	unsigned int trim_sections;		/* # of sections to trim */
639bba681cbSJaegeuk Kim 
640184a5cd2SChao Yu 	struct list_head sit_entry_set;	/* sit entry set list */
641184a5cd2SChao Yu 
642216fbd64SJaegeuk Kim 	unsigned int ipu_policy;	/* in-place-update policy */
643216fbd64SJaegeuk Kim 	unsigned int min_ipu_util;	/* in-place-update threshold */
644c1ce1b02SJaegeuk Kim 	unsigned int min_fsync_blocks;	/* threshold for fsync */
6456b4afdd7SJaegeuk Kim 
6466b4afdd7SJaegeuk Kim 	/* for flush command control */
647a688b9d9SGu Zheng 	struct flush_cmd_control *cmd_control_info;
648a688b9d9SGu Zheng 
64939a53e0cSJaegeuk Kim };
65039a53e0cSJaegeuk Kim 
65139a53e0cSJaegeuk Kim /*
65239a53e0cSJaegeuk Kim  * For superblock
65339a53e0cSJaegeuk Kim  */
65439a53e0cSJaegeuk Kim /*
65539a53e0cSJaegeuk Kim  * COUNT_TYPE for monitoring
65639a53e0cSJaegeuk Kim  *
65739a53e0cSJaegeuk Kim  * f2fs monitors the number of several block types such as on-writeback,
65839a53e0cSJaegeuk Kim  * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
65939a53e0cSJaegeuk Kim  */
66036951b38SChao Yu #define WB_DATA_TYPE(p)	(__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA)
66139a53e0cSJaegeuk Kim enum count_type {
66239a53e0cSJaegeuk Kim 	F2FS_DIRTY_DENTS,
663c227f912SChao Yu 	F2FS_DIRTY_DATA,
66439a53e0cSJaegeuk Kim 	F2FS_DIRTY_NODES,
66539a53e0cSJaegeuk Kim 	F2FS_DIRTY_META,
6668dcf2ff7SJaegeuk Kim 	F2FS_INMEM_PAGES,
6670f18b462SJaegeuk Kim 	F2FS_DIRTY_IMETA,
66836951b38SChao Yu 	F2FS_WB_CP_DATA,
66936951b38SChao Yu 	F2FS_WB_DATA,
67039a53e0cSJaegeuk Kim 	NR_COUNT_TYPE,
67139a53e0cSJaegeuk Kim };
67239a53e0cSJaegeuk Kim 
67339a53e0cSJaegeuk Kim /*
674e1c42045Sarter97  * The below are the page types of bios used in submit_bio().
67539a53e0cSJaegeuk Kim  * The available types are:
67639a53e0cSJaegeuk Kim  * DATA			User data pages. It operates as async mode.
67739a53e0cSJaegeuk Kim  * NODE			Node pages. It operates as async mode.
67839a53e0cSJaegeuk Kim  * META			FS metadata pages such as SIT, NAT, CP.
67939a53e0cSJaegeuk Kim  * NR_PAGE_TYPE		The number of page types.
68039a53e0cSJaegeuk Kim  * META_FLUSH		Make sure the previous pages are written
68139a53e0cSJaegeuk Kim  *			with waiting the bio's completion
68239a53e0cSJaegeuk Kim  * ...			Only can be used with META.
68339a53e0cSJaegeuk Kim  */
6847d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type)	((type) > META ? META : (type))
68539a53e0cSJaegeuk Kim enum page_type {
68639a53e0cSJaegeuk Kim 	DATA,
68739a53e0cSJaegeuk Kim 	NODE,
68839a53e0cSJaegeuk Kim 	META,
68939a53e0cSJaegeuk Kim 	NR_PAGE_TYPE,
69039a53e0cSJaegeuk Kim 	META_FLUSH,
6918ce67cb0SJaegeuk Kim 	INMEM,		/* the below types are used by tracepoints only. */
6928ce67cb0SJaegeuk Kim 	INMEM_DROP,
69328bc106bSChao Yu 	INMEM_REVOKE,
6948ce67cb0SJaegeuk Kim 	IPU,
6958ce67cb0SJaegeuk Kim 	OPU,
69639a53e0cSJaegeuk Kim };
69739a53e0cSJaegeuk Kim 
698458e6197SJaegeuk Kim struct f2fs_io_info {
69905ca3632SJaegeuk Kim 	struct f2fs_sb_info *sbi;	/* f2fs_sb_info pointer */
700458e6197SJaegeuk Kim 	enum page_type type;	/* contains DATA/NODE/META/META_FLUSH */
70104d328deSMike Christie 	int op;			/* contains REQ_OP_ */
702ef295ecfSChristoph Hellwig 	int op_flags;		/* req_flag_bits */
7037a9d7548SChao Yu 	block_t new_blkaddr;	/* new block address to be written */
70428bc106bSChao Yu 	block_t old_blkaddr;	/* old block address before Cow */
70505ca3632SJaegeuk Kim 	struct page *page;	/* page to be written */
7064375a336SJaegeuk Kim 	struct page *encrypted_page;	/* encrypted page */
707458e6197SJaegeuk Kim };
708458e6197SJaegeuk Kim 
70904d328deSMike Christie #define is_read_io(rw) (rw == READ)
7101ff7bd3bSJaegeuk Kim struct f2fs_bio_info {
711458e6197SJaegeuk Kim 	struct f2fs_sb_info *sbi;	/* f2fs superblock */
7121ff7bd3bSJaegeuk Kim 	struct bio *bio;		/* bios to merge */
7131ff7bd3bSJaegeuk Kim 	sector_t last_block_in_bio;	/* last block number */
714458e6197SJaegeuk Kim 	struct f2fs_io_info fio;	/* store buffered io info. */
715df0f8dc0SChao Yu 	struct rw_semaphore io_rwsem;	/* blocking op for bio */
7161ff7bd3bSJaegeuk Kim };
7171ff7bd3bSJaegeuk Kim 
7183c62be17SJaegeuk Kim #define FDEV(i)				(sbi->devs[i])
7193c62be17SJaegeuk Kim #define RDEV(i)				(raw_super->devs[i])
7203c62be17SJaegeuk Kim struct f2fs_dev_info {
7213c62be17SJaegeuk Kim 	struct block_device *bdev;
7223c62be17SJaegeuk Kim 	char path[MAX_PATH_LEN];
7233c62be17SJaegeuk Kim 	unsigned int total_segments;
7243c62be17SJaegeuk Kim 	block_t start_blk;
7253c62be17SJaegeuk Kim 	block_t end_blk;
7263c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED
7273c62be17SJaegeuk Kim 	unsigned int nr_blkz;			/* Total number of zones */
7283c62be17SJaegeuk Kim 	u8 *blkz_type;				/* Array of zones type */
7293c62be17SJaegeuk Kim #endif
7303c62be17SJaegeuk Kim };
7313c62be17SJaegeuk Kim 
732c227f912SChao Yu enum inode_type {
733c227f912SChao Yu 	DIR_INODE,			/* for dirty dir inode */
734c227f912SChao Yu 	FILE_INODE,			/* for dirty regular/symlink inode */
7350f18b462SJaegeuk Kim 	DIRTY_META,			/* for all dirtied inode metadata */
736c227f912SChao Yu 	NR_INODE_TYPE,
737c227f912SChao Yu };
738c227f912SChao Yu 
73967298804SChao Yu /* for inner inode cache management */
74067298804SChao Yu struct inode_management {
74167298804SChao Yu 	struct radix_tree_root ino_root;	/* ino entry array */
74267298804SChao Yu 	spinlock_t ino_lock;			/* for ino entry lock */
74367298804SChao Yu 	struct list_head ino_list;		/* inode list head */
74467298804SChao Yu 	unsigned long ino_num;			/* number of entries */
74567298804SChao Yu };
74667298804SChao Yu 
747caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */
748caf0047eSChao Yu enum {
749caf0047eSChao Yu 	SBI_IS_DIRTY,				/* dirty flag for checkpoint */
750caf0047eSChao Yu 	SBI_IS_CLOSE,				/* specify unmounting */
751caf0047eSChao Yu 	SBI_NEED_FSCK,				/* need fsck.f2fs to fix */
752caf0047eSChao Yu 	SBI_POR_DOING,				/* recovery is doing or not */
753df728b0fSJaegeuk Kim 	SBI_NEED_SB_WRITE,			/* need to recover superblock */
754bbf156f7SJaegeuk Kim 	SBI_NEED_CP,				/* need to checkpoint */
755caf0047eSChao Yu };
756caf0047eSChao Yu 
7576beceb54SJaegeuk Kim enum {
7586beceb54SJaegeuk Kim 	CP_TIME,
759d0239e1bSJaegeuk Kim 	REQ_TIME,
7606beceb54SJaegeuk Kim 	MAX_TIME,
7616beceb54SJaegeuk Kim };
7626beceb54SJaegeuk Kim 
763b5a7aef1SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION
764b5a7aef1SJaegeuk Kim #define F2FS_KEY_DESC_PREFIX "f2fs:"
765b5a7aef1SJaegeuk Kim #define F2FS_KEY_DESC_PREFIX_SIZE 5
766b5a7aef1SJaegeuk Kim #endif
76739a53e0cSJaegeuk Kim struct f2fs_sb_info {
76839a53e0cSJaegeuk Kim 	struct super_block *sb;			/* pointer to VFS super block */
7695e176d54SJaegeuk Kim 	struct proc_dir_entry *s_proc;		/* proc entry */
77039a53e0cSJaegeuk Kim 	struct f2fs_super_block *raw_super;	/* raw super block pointer */
771e8240f65SChao Yu 	int valid_super_block;			/* valid super block no */
772fadb2fb8SChao Yu 	unsigned long s_flag;				/* flags for sbi */
77339a53e0cSJaegeuk Kim 
774b5a7aef1SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION
775b5a7aef1SJaegeuk Kim 	u8 key_prefix[F2FS_KEY_DESC_PREFIX_SIZE];
776b5a7aef1SJaegeuk Kim 	u8 key_prefix_size;
777b5a7aef1SJaegeuk Kim #endif
778178053e2SDamien Le Moal 
779178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED
780178053e2SDamien Le Moal 	unsigned int blocks_per_blkz;		/* F2FS blocks per zone */
781178053e2SDamien Le Moal 	unsigned int log_blocks_per_blkz;	/* log2 F2FS blocks per zone */
782178053e2SDamien Le Moal #endif
783178053e2SDamien Le Moal 
78439a53e0cSJaegeuk Kim 	/* for node-related operations */
78539a53e0cSJaegeuk Kim 	struct f2fs_nm_info *nm_info;		/* node manager */
78639a53e0cSJaegeuk Kim 	struct inode *node_inode;		/* cache node blocks */
78739a53e0cSJaegeuk Kim 
78839a53e0cSJaegeuk Kim 	/* for segment-related operations */
78939a53e0cSJaegeuk Kim 	struct f2fs_sm_info *sm_info;		/* segment manager */
7901ff7bd3bSJaegeuk Kim 
7911ff7bd3bSJaegeuk Kim 	/* for bio operations */
792924b720bSChao Yu 	struct f2fs_bio_info read_io;			/* for read bios */
7931ff7bd3bSJaegeuk Kim 	struct f2fs_bio_info write_io[NR_PAGE_TYPE];	/* for write bios */
7947dfeaa32SJaegeuk Kim 	struct mutex wio_mutex[NODE + 1];	/* bio ordering for NODE/DATA */
795*0a595ebaSJaegeuk Kim 	int write_io_size_bits;			/* Write IO size bits */
796*0a595ebaSJaegeuk Kim 	mempool_t *write_io_dummy;		/* Dummy pages */
79739a53e0cSJaegeuk Kim 
79839a53e0cSJaegeuk Kim 	/* for checkpoint */
79939a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
8008508e44aSJaegeuk Kim 	int cur_cp_pack;			/* remain current cp pack */
801aaec2b1dSChao Yu 	spinlock_t cp_lock;			/* for flag in ckpt */
80239a53e0cSJaegeuk Kim 	struct inode *meta_inode;		/* cache meta blocks */
80339936837SJaegeuk Kim 	struct mutex cp_mutex;			/* checkpoint procedure lock */
804b873b798SJaegeuk Kim 	struct rw_semaphore cp_rwsem;		/* blocking FS operations */
805b3582c68SChao Yu 	struct rw_semaphore node_write;		/* locking node writes */
806fb51b5efSChangman Lee 	wait_queue_head_t cp_wait;
8076beceb54SJaegeuk Kim 	unsigned long last_time[MAX_TIME];	/* to store time in jiffies */
8086beceb54SJaegeuk Kim 	long interval_time[MAX_TIME];		/* to store thresholds */
80939a53e0cSJaegeuk Kim 
81067298804SChao Yu 	struct inode_management im[MAX_INO_ENTRY];      /* manage inode cache */
8116451e041SJaegeuk Kim 
8126451e041SJaegeuk Kim 	/* for orphan inode, use 0'th array */
8130d47c1adSGu Zheng 	unsigned int max_orphans;		/* max orphan inodes */
81439a53e0cSJaegeuk Kim 
815c227f912SChao Yu 	/* for inode management */
816c227f912SChao Yu 	struct list_head inode_list[NR_INODE_TYPE];	/* dirty inode list */
817c227f912SChao Yu 	spinlock_t inode_lock[NR_INODE_TYPE];	/* for dirty inode list lock */
81839a53e0cSJaegeuk Kim 
81913054c54SChao Yu 	/* for extent tree cache */
82013054c54SChao Yu 	struct radix_tree_root extent_tree_root;/* cache extent cache entries */
82113054c54SChao Yu 	struct rw_semaphore extent_tree_lock;	/* locking extent radix tree */
82213054c54SChao Yu 	struct list_head extent_list;		/* lru list for shrinker */
82313054c54SChao Yu 	spinlock_t extent_lock;			/* locking extent lru list */
8247441ccefSJaegeuk Kim 	atomic_t total_ext_tree;		/* extent tree count */
825137d09f0SJaegeuk Kim 	struct list_head zombie_list;		/* extent zombie tree list */
82674fd8d99SJaegeuk Kim 	atomic_t total_zombie_tree;		/* extent zombie tree count */
82713054c54SChao Yu 	atomic_t total_ext_node;		/* extent info count */
82813054c54SChao Yu 
82939a53e0cSJaegeuk Kim 	/* basic filesystem units */
83039a53e0cSJaegeuk Kim 	unsigned int log_sectors_per_block;	/* log2 sectors per block */
83139a53e0cSJaegeuk Kim 	unsigned int log_blocksize;		/* log2 block size */
83239a53e0cSJaegeuk Kim 	unsigned int blocksize;			/* block size */
83339a53e0cSJaegeuk Kim 	unsigned int root_ino_num;		/* root inode number*/
83439a53e0cSJaegeuk Kim 	unsigned int node_ino_num;		/* node inode number*/
83539a53e0cSJaegeuk Kim 	unsigned int meta_ino_num;		/* meta inode number*/
83639a53e0cSJaegeuk Kim 	unsigned int log_blocks_per_seg;	/* log2 blocks per segment */
83739a53e0cSJaegeuk Kim 	unsigned int blocks_per_seg;		/* blocks per segment */
83839a53e0cSJaegeuk Kim 	unsigned int segs_per_sec;		/* segments per section */
83939a53e0cSJaegeuk Kim 	unsigned int secs_per_zone;		/* sections per zone */
84039a53e0cSJaegeuk Kim 	unsigned int total_sections;		/* total section count */
84139a53e0cSJaegeuk Kim 	unsigned int total_node_count;		/* total node block count */
84239a53e0cSJaegeuk Kim 	unsigned int total_valid_node_count;	/* valid node block count */
843e0afc4d6SChao Yu 	loff_t max_file_blocks;			/* max block index of file */
84439a53e0cSJaegeuk Kim 	int active_logs;			/* # of active logs */
845ab9fa662SJaegeuk Kim 	int dir_level;				/* directory level */
84639a53e0cSJaegeuk Kim 
84739a53e0cSJaegeuk Kim 	block_t user_block_count;		/* # of user blocks */
84839a53e0cSJaegeuk Kim 	block_t total_valid_block_count;	/* # of valid blocks */
849a66cdd98SJaegeuk Kim 	block_t discard_blks;			/* discard command candidats */
85039a53e0cSJaegeuk Kim 	block_t last_valid_block_count;		/* for recovery */
85139a53e0cSJaegeuk Kim 	u32 s_next_generation;			/* for NFS support */
852523be8a6SJaegeuk Kim 
853523be8a6SJaegeuk Kim 	/* # of pages, see count_type */
85435782b23SJaegeuk Kim 	atomic_t nr_pages[NR_COUNT_TYPE];
85541382ec4SJaegeuk Kim 	/* # of allocated blocks */
85641382ec4SJaegeuk Kim 	struct percpu_counter alloc_valid_block_count;
85739a53e0cSJaegeuk Kim 
858513c5f37SJaegeuk Kim 	/* valid inode count */
859513c5f37SJaegeuk Kim 	struct percpu_counter total_valid_inode_count;
860513c5f37SJaegeuk Kim 
86139a53e0cSJaegeuk Kim 	struct f2fs_mount_info mount_opt;	/* mount options */
86239a53e0cSJaegeuk Kim 
86339a53e0cSJaegeuk Kim 	/* for cleaning operations */
86439a53e0cSJaegeuk Kim 	struct mutex gc_mutex;			/* mutex for GC */
86539a53e0cSJaegeuk Kim 	struct f2fs_gc_kthread	*gc_thread;	/* GC thread */
8665ec4e49fSJaegeuk Kim 	unsigned int cur_victim_sec;		/* current victim section num */
86739a53e0cSJaegeuk Kim 
868b1c57c1cSJaegeuk Kim 	/* maximum # of trials to find a victim segment for SSR and GC */
869b1c57c1cSJaegeuk Kim 	unsigned int max_victim_search;
870b1c57c1cSJaegeuk Kim 
87139a53e0cSJaegeuk Kim 	/*
87239a53e0cSJaegeuk Kim 	 * for stat information.
87339a53e0cSJaegeuk Kim 	 * one is for the LFS mode, and the other is for the SSR mode.
87439a53e0cSJaegeuk Kim 	 */
87535b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS
87639a53e0cSJaegeuk Kim 	struct f2fs_stat_info *stat_info;	/* FS status information */
87739a53e0cSJaegeuk Kim 	unsigned int segment_count[2];		/* # of allocated segments */
87839a53e0cSJaegeuk Kim 	unsigned int block_count[2];		/* # of allocated blocks */
879b9a2c252SChangman Lee 	atomic_t inplace_count;		/* # of inplace update */
8805b7ee374SChao Yu 	atomic64_t total_hit_ext;		/* # of lookup extent cache */
8815b7ee374SChao Yu 	atomic64_t read_hit_rbtree;		/* # of hit rbtree extent node */
8825b7ee374SChao Yu 	atomic64_t read_hit_largest;		/* # of hit largest extent node */
8835b7ee374SChao Yu 	atomic64_t read_hit_cached;		/* # of hit cached extent node */
884d5e8f6c9SChao Yu 	atomic_t inline_xattr;			/* # of inline_xattr inodes */
88503e14d52SChao Yu 	atomic_t inline_inode;			/* # of inline_data inodes */
88603e14d52SChao Yu 	atomic_t inline_dir;			/* # of inline_dentry inodes */
88739a53e0cSJaegeuk Kim 	int bg_gc;				/* background gc calls */
88833fbd510SChao Yu 	unsigned int ndirty_inode[NR_INODE_TYPE];	/* # of dirty inodes */
88935b09d82SNamjae Jeon #endif
89035b09d82SNamjae Jeon 	unsigned int last_victim[2];		/* last victim segment # */
89139a53e0cSJaegeuk Kim 	spinlock_t stat_lock;			/* lock for stat operations */
892b59d0baeSNamjae Jeon 
893b59d0baeSNamjae Jeon 	/* For sysfs suppport */
894b59d0baeSNamjae Jeon 	struct kobject s_kobj;
895b59d0baeSNamjae Jeon 	struct completion s_kobj_unregister;
8962658e50dSJaegeuk Kim 
8972658e50dSJaegeuk Kim 	/* For shrinker support */
8982658e50dSJaegeuk Kim 	struct list_head s_list;
8993c62be17SJaegeuk Kim 	int s_ndevs;				/* number of devices */
9003c62be17SJaegeuk Kim 	struct f2fs_dev_info *devs;		/* for device list */
9012658e50dSJaegeuk Kim 	struct mutex umount_mutex;
9022658e50dSJaegeuk Kim 	unsigned int shrinker_run_no;
9038f1dbbbbSShuoran Liu 
9048f1dbbbbSShuoran Liu 	/* For write statistics */
9058f1dbbbbSShuoran Liu 	u64 sectors_written_start;
9068f1dbbbbSShuoran Liu 	u64 kbytes_written;
90743b6573bSKeith Mok 
90843b6573bSKeith Mok 	/* Reference to checksum algorithm driver via cryptoapi */
90943b6573bSKeith Mok 	struct crypto_shash *s_chksum_driver;
9101ecc0c5cSChao Yu 
9111ecc0c5cSChao Yu 	/* For fault injection */
9121ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION
9131ecc0c5cSChao Yu 	struct f2fs_fault_info fault_info;
9141ecc0c5cSChao Yu #endif
91539a53e0cSJaegeuk Kim };
91639a53e0cSJaegeuk Kim 
9171ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION
9181ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
9191ecc0c5cSChao Yu {
9201ecc0c5cSChao Yu 	struct f2fs_fault_info *ffi = &sbi->fault_info;
9211ecc0c5cSChao Yu 
9221ecc0c5cSChao Yu 	if (!ffi->inject_rate)
9231ecc0c5cSChao Yu 		return false;
9241ecc0c5cSChao Yu 
9251ecc0c5cSChao Yu 	if (!IS_FAULT_SET(ffi, type))
9261ecc0c5cSChao Yu 		return false;
9271ecc0c5cSChao Yu 
9281ecc0c5cSChao Yu 	atomic_inc(&ffi->inject_ops);
9291ecc0c5cSChao Yu 	if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) {
9301ecc0c5cSChao Yu 		atomic_set(&ffi->inject_ops, 0);
9311ecc0c5cSChao Yu 		printk("%sF2FS-fs : inject %s in %pF\n",
9321ecc0c5cSChao Yu 				KERN_INFO,
9331ecc0c5cSChao Yu 				fault_name[type],
9341ecc0c5cSChao Yu 				__builtin_return_address(0));
9351ecc0c5cSChao Yu 		return true;
9361ecc0c5cSChao Yu 	}
9371ecc0c5cSChao Yu 	return false;
9381ecc0c5cSChao Yu }
9391ecc0c5cSChao Yu #endif
9401ecc0c5cSChao Yu 
9418f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes,
9428f1dbbbbSShuoran Liu  * and the return value is in kbytes. s is of struct f2fs_sb_info.
9438f1dbbbbSShuoran Liu  */
9448f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s)						 \
9458f1dbbbbSShuoran Liu (((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) -		 \
9468f1dbbbbSShuoran Liu 		s->sectors_written_start) >> 1)
9478f1dbbbbSShuoran Liu 
9486beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
9496beceb54SJaegeuk Kim {
9506beceb54SJaegeuk Kim 	sbi->last_time[type] = jiffies;
9516beceb54SJaegeuk Kim }
9526beceb54SJaegeuk Kim 
9536beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type)
9546beceb54SJaegeuk Kim {
9556beceb54SJaegeuk Kim 	struct timespec ts = {sbi->interval_time[type], 0};
9566beceb54SJaegeuk Kim 	unsigned long interval = timespec_to_jiffies(&ts);
9576beceb54SJaegeuk Kim 
9586beceb54SJaegeuk Kim 	return time_after(jiffies, sbi->last_time[type] + interval);
9596beceb54SJaegeuk Kim }
9606beceb54SJaegeuk Kim 
961d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi)
962d0239e1bSJaegeuk Kim {
963d0239e1bSJaegeuk Kim 	struct block_device *bdev = sbi->sb->s_bdev;
964d0239e1bSJaegeuk Kim 	struct request_queue *q = bdev_get_queue(bdev);
965d0239e1bSJaegeuk Kim 	struct request_list *rl = &q->root_rl;
966d0239e1bSJaegeuk Kim 
967d0239e1bSJaegeuk Kim 	if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC])
968d0239e1bSJaegeuk Kim 		return 0;
969d0239e1bSJaegeuk Kim 
970d0239e1bSJaegeuk Kim 	return f2fs_time_over(sbi, REQ_TIME);
971d0239e1bSJaegeuk Kim }
972d0239e1bSJaegeuk Kim 
97339a53e0cSJaegeuk Kim /*
97439a53e0cSJaegeuk Kim  * Inline functions
97539a53e0cSJaegeuk Kim  */
97643b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
97743b6573bSKeith Mok 			   unsigned int length)
97843b6573bSKeith Mok {
97943b6573bSKeith Mok 	SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver);
98043b6573bSKeith Mok 	u32 *ctx = (u32 *)shash_desc_ctx(shash);
98143b6573bSKeith Mok 	int err;
98243b6573bSKeith Mok 
98343b6573bSKeith Mok 	shash->tfm = sbi->s_chksum_driver;
98443b6573bSKeith Mok 	shash->flags = 0;
98543b6573bSKeith Mok 	*ctx = F2FS_SUPER_MAGIC;
98643b6573bSKeith Mok 
98743b6573bSKeith Mok 	err = crypto_shash_update(shash, address, length);
98843b6573bSKeith Mok 	BUG_ON(err);
98943b6573bSKeith Mok 
99043b6573bSKeith Mok 	return *ctx;
99143b6573bSKeith Mok }
99243b6573bSKeith Mok 
99343b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
99443b6573bSKeith Mok 				  void *buf, size_t buf_size)
99543b6573bSKeith Mok {
99643b6573bSKeith Mok 	return f2fs_crc32(sbi, buf, buf_size) == blk_crc;
99743b6573bSKeith Mok }
99843b6573bSKeith Mok 
99939a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
100039a53e0cSJaegeuk Kim {
100139a53e0cSJaegeuk Kim 	return container_of(inode, struct f2fs_inode_info, vfs_inode);
100239a53e0cSJaegeuk Kim }
100339a53e0cSJaegeuk Kim 
100439a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
100539a53e0cSJaegeuk Kim {
100639a53e0cSJaegeuk Kim 	return sb->s_fs_info;
100739a53e0cSJaegeuk Kim }
100839a53e0cSJaegeuk Kim 
10094081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
10104081363fSJaegeuk Kim {
10114081363fSJaegeuk Kim 	return F2FS_SB(inode->i_sb);
10124081363fSJaegeuk Kim }
10134081363fSJaegeuk Kim 
10144081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
10154081363fSJaegeuk Kim {
10164081363fSJaegeuk Kim 	return F2FS_I_SB(mapping->host);
10174081363fSJaegeuk Kim }
10184081363fSJaegeuk Kim 
10194081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
10204081363fSJaegeuk Kim {
10214081363fSJaegeuk Kim 	return F2FS_M_SB(page->mapping);
10224081363fSJaegeuk Kim }
10234081363fSJaegeuk Kim 
102439a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
102539a53e0cSJaegeuk Kim {
102639a53e0cSJaegeuk Kim 	return (struct f2fs_super_block *)(sbi->raw_super);
102739a53e0cSJaegeuk Kim }
102839a53e0cSJaegeuk Kim 
102939a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
103039a53e0cSJaegeuk Kim {
103139a53e0cSJaegeuk Kim 	return (struct f2fs_checkpoint *)(sbi->ckpt);
103239a53e0cSJaegeuk Kim }
103339a53e0cSJaegeuk Kim 
103445590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page)
103545590710SGu Zheng {
103645590710SGu Zheng 	return (struct f2fs_node *)page_address(page);
103745590710SGu Zheng }
103845590710SGu Zheng 
103958bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page)
104058bfaf44SJaegeuk Kim {
104158bfaf44SJaegeuk Kim 	return &((struct f2fs_node *)page_address(page))->i;
104258bfaf44SJaegeuk Kim }
104358bfaf44SJaegeuk Kim 
104439a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
104539a53e0cSJaegeuk Kim {
104639a53e0cSJaegeuk Kim 	return (struct f2fs_nm_info *)(sbi->nm_info);
104739a53e0cSJaegeuk Kim }
104839a53e0cSJaegeuk Kim 
104939a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
105039a53e0cSJaegeuk Kim {
105139a53e0cSJaegeuk Kim 	return (struct f2fs_sm_info *)(sbi->sm_info);
105239a53e0cSJaegeuk Kim }
105339a53e0cSJaegeuk Kim 
105439a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
105539a53e0cSJaegeuk Kim {
105639a53e0cSJaegeuk Kim 	return (struct sit_info *)(SM_I(sbi)->sit_info);
105739a53e0cSJaegeuk Kim }
105839a53e0cSJaegeuk Kim 
105939a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
106039a53e0cSJaegeuk Kim {
106139a53e0cSJaegeuk Kim 	return (struct free_segmap_info *)(SM_I(sbi)->free_info);
106239a53e0cSJaegeuk Kim }
106339a53e0cSJaegeuk Kim 
106439a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
106539a53e0cSJaegeuk Kim {
106639a53e0cSJaegeuk Kim 	return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
106739a53e0cSJaegeuk Kim }
106839a53e0cSJaegeuk Kim 
10699df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
10709df27d98SGu Zheng {
10719df27d98SGu Zheng 	return sbi->meta_inode->i_mapping;
10729df27d98SGu Zheng }
10739df27d98SGu Zheng 
10744ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
10754ef51a8fSJaegeuk Kim {
10764ef51a8fSJaegeuk Kim 	return sbi->node_inode->i_mapping;
10774ef51a8fSJaegeuk Kim }
10784ef51a8fSJaegeuk Kim 
1079caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
108039a53e0cSJaegeuk Kim {
1081fadb2fb8SChao Yu 	return test_bit(type, &sbi->s_flag);
108239a53e0cSJaegeuk Kim }
108339a53e0cSJaegeuk Kim 
1084caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
108539a53e0cSJaegeuk Kim {
1086fadb2fb8SChao Yu 	set_bit(type, &sbi->s_flag);
1087caf0047eSChao Yu }
1088caf0047eSChao Yu 
1089caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
1090caf0047eSChao Yu {
1091fadb2fb8SChao Yu 	clear_bit(type, &sbi->s_flag);
109239a53e0cSJaegeuk Kim }
109339a53e0cSJaegeuk Kim 
1094d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
1095d71b5564SJaegeuk Kim {
1096d71b5564SJaegeuk Kim 	return le64_to_cpu(cp->checkpoint_ver);
1097d71b5564SJaegeuk Kim }
1098d71b5564SJaegeuk Kim 
1099aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
110025ca923bSJaegeuk Kim {
110125ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
1102aaec2b1dSChao Yu 
110325ca923bSJaegeuk Kim 	return ckpt_flags & f;
110425ca923bSJaegeuk Kim }
110525ca923bSJaegeuk Kim 
1106aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
110725ca923bSJaegeuk Kim {
1108aaec2b1dSChao Yu 	return __is_set_ckpt_flags(F2FS_CKPT(sbi), f);
1109aaec2b1dSChao Yu }
1110aaec2b1dSChao Yu 
1111aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1112aaec2b1dSChao Yu {
1113aaec2b1dSChao Yu 	unsigned int ckpt_flags;
1114aaec2b1dSChao Yu 
1115aaec2b1dSChao Yu 	ckpt_flags = le32_to_cpu(cp->ckpt_flags);
111625ca923bSJaegeuk Kim 	ckpt_flags |= f;
111725ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
111825ca923bSJaegeuk Kim }
111925ca923bSJaegeuk Kim 
1120aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
112125ca923bSJaegeuk Kim {
1122aaec2b1dSChao Yu 	spin_lock(&sbi->cp_lock);
1123aaec2b1dSChao Yu 	__set_ckpt_flags(F2FS_CKPT(sbi), f);
1124aaec2b1dSChao Yu 	spin_unlock(&sbi->cp_lock);
1125aaec2b1dSChao Yu }
1126aaec2b1dSChao Yu 
1127aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1128aaec2b1dSChao Yu {
1129aaec2b1dSChao Yu 	unsigned int ckpt_flags;
1130aaec2b1dSChao Yu 
1131aaec2b1dSChao Yu 	ckpt_flags = le32_to_cpu(cp->ckpt_flags);
113225ca923bSJaegeuk Kim 	ckpt_flags &= (~f);
113325ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
113425ca923bSJaegeuk Kim }
113525ca923bSJaegeuk Kim 
1136aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
1137aaec2b1dSChao Yu {
1138aaec2b1dSChao Yu 	spin_lock(&sbi->cp_lock);
1139aaec2b1dSChao Yu 	__clear_ckpt_flags(F2FS_CKPT(sbi), f);
1140aaec2b1dSChao Yu 	spin_unlock(&sbi->cp_lock);
1141aaec2b1dSChao Yu }
1142aaec2b1dSChao Yu 
1143e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
114439a53e0cSJaegeuk Kim {
1145b873b798SJaegeuk Kim 	down_read(&sbi->cp_rwsem);
114639a53e0cSJaegeuk Kim }
114739a53e0cSJaegeuk Kim 
1148e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
114939a53e0cSJaegeuk Kim {
1150b873b798SJaegeuk Kim 	up_read(&sbi->cp_rwsem);
115139936837SJaegeuk Kim }
115239936837SJaegeuk Kim 
1153e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
115439936837SJaegeuk Kim {
1155b873b798SJaegeuk Kim 	down_write(&sbi->cp_rwsem);
115639936837SJaegeuk Kim }
115739936837SJaegeuk Kim 
1158e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
115939936837SJaegeuk Kim {
1160b873b798SJaegeuk Kim 	up_write(&sbi->cp_rwsem);
116139a53e0cSJaegeuk Kim }
116239a53e0cSJaegeuk Kim 
1163119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
1164119ee914SJaegeuk Kim {
1165119ee914SJaegeuk Kim 	int reason = CP_SYNC;
1166119ee914SJaegeuk Kim 
1167119ee914SJaegeuk Kim 	if (test_opt(sbi, FASTBOOT))
1168119ee914SJaegeuk Kim 		reason = CP_FASTBOOT;
1169119ee914SJaegeuk Kim 	if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
1170119ee914SJaegeuk Kim 		reason = CP_UMOUNT;
1171119ee914SJaegeuk Kim 	return reason;
1172119ee914SJaegeuk Kim }
1173119ee914SJaegeuk Kim 
1174119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason)
1175119ee914SJaegeuk Kim {
1176119ee914SJaegeuk Kim 	return (reason == CP_UMOUNT || reason == CP_FASTBOOT);
1177119ee914SJaegeuk Kim }
1178119ee914SJaegeuk Kim 
1179119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
1180119ee914SJaegeuk Kim {
1181aaec2b1dSChao Yu 	return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) ||
1182aaec2b1dSChao Yu 			is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG));
1183119ee914SJaegeuk Kim }
1184119ee914SJaegeuk Kim 
118539a53e0cSJaegeuk Kim /*
118639a53e0cSJaegeuk Kim  * Check whether the given nid is within node id range.
118739a53e0cSJaegeuk Kim  */
1188064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
118939a53e0cSJaegeuk Kim {
1190d6b7d4b3SChao Yu 	if (unlikely(nid < F2FS_ROOT_INO(sbi)))
1191d6b7d4b3SChao Yu 		return -EINVAL;
1192cfb271d4SChao Yu 	if (unlikely(nid >= NM_I(sbi)->max_nid))
1193064e0823SNamjae Jeon 		return -EINVAL;
1194064e0823SNamjae Jeon 	return 0;
119539a53e0cSJaegeuk Kim }
119639a53e0cSJaegeuk Kim 
119739a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS	1
119839a53e0cSJaegeuk Kim 
119939a53e0cSJaegeuk Kim /*
120039a53e0cSJaegeuk Kim  * Check whether the inode has blocks or not
120139a53e0cSJaegeuk Kim  */
120239a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode)
120339a53e0cSJaegeuk Kim {
120439a53e0cSJaegeuk Kim 	if (F2FS_I(inode)->i_xattr_nid)
12056c311ec6SChris Fries 		return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
120639a53e0cSJaegeuk Kim 	else
12076c311ec6SChris Fries 		return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
120839a53e0cSJaegeuk Kim }
120939a53e0cSJaegeuk Kim 
12104bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs)
12114bc8e9bcSChao Yu {
12124bc8e9bcSChao Yu 	return ofs == XATTR_NODE_OFFSET;
12134bc8e9bcSChao Yu }
12144bc8e9bcSChao Yu 
12158edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool);
121639a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
121746008c6dSChao Yu 				 struct inode *inode, blkcnt_t *count)
121839a53e0cSJaegeuk Kim {
1219dd11a5dfSJaegeuk Kim 	blkcnt_t diff;
1220dd11a5dfSJaegeuk Kim 
1221cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION
12221ecc0c5cSChao Yu 	if (time_to_inject(sbi, FAULT_BLOCK))
1223cb78942bSJaegeuk Kim 		return false;
1224cb78942bSJaegeuk Kim #endif
1225dd11a5dfSJaegeuk Kim 	/*
1226dd11a5dfSJaegeuk Kim 	 * let's increase this in prior to actual block count change in order
1227dd11a5dfSJaegeuk Kim 	 * for f2fs_sync_file to avoid data races when deciding checkpoint.
1228dd11a5dfSJaegeuk Kim 	 */
1229dd11a5dfSJaegeuk Kim 	percpu_counter_add(&sbi->alloc_valid_block_count, (*count));
1230cfb271d4SChao Yu 
123139a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
12322555a2d5SJaegeuk Kim 	sbi->total_valid_block_count += (block_t)(*count);
12332555a2d5SJaegeuk Kim 	if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) {
1234dd11a5dfSJaegeuk Kim 		diff = sbi->total_valid_block_count - sbi->user_block_count;
1235dd11a5dfSJaegeuk Kim 		*count -= diff;
12362555a2d5SJaegeuk Kim 		sbi->total_valid_block_count = sbi->user_block_count;
123746008c6dSChao Yu 		if (!*count) {
123839a53e0cSJaegeuk Kim 			spin_unlock(&sbi->stat_lock);
1239dd11a5dfSJaegeuk Kim 			percpu_counter_sub(&sbi->alloc_valid_block_count, diff);
124039a53e0cSJaegeuk Kim 			return false;
124139a53e0cSJaegeuk Kim 		}
124246008c6dSChao Yu 	}
124339a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
124441382ec4SJaegeuk Kim 
12452555a2d5SJaegeuk Kim 	f2fs_i_blocks_write(inode, *count, true);
124639a53e0cSJaegeuk Kim 	return true;
124739a53e0cSJaegeuk Kim }
124839a53e0cSJaegeuk Kim 
1249da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
125039a53e0cSJaegeuk Kim 						struct inode *inode,
125139a53e0cSJaegeuk Kim 						blkcnt_t count)
125239a53e0cSJaegeuk Kim {
125339a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
12549850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
12559850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, inode->i_blocks < count);
125639a53e0cSJaegeuk Kim 	sbi->total_valid_block_count -= (block_t)count;
125739a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
12582555a2d5SJaegeuk Kim 	f2fs_i_blocks_write(inode, count, false);
125939a53e0cSJaegeuk Kim }
126039a53e0cSJaegeuk Kim 
126139a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
126239a53e0cSJaegeuk Kim {
126335782b23SJaegeuk Kim 	atomic_inc(&sbi->nr_pages[count_type]);
12647c4abcbeSChao Yu 
126536951b38SChao Yu 	if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES ||
126636951b38SChao Yu 		count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA)
12677c4abcbeSChao Yu 		return;
12687c4abcbeSChao Yu 
1269caf0047eSChao Yu 	set_sbi_flag(sbi, SBI_IS_DIRTY);
127039a53e0cSJaegeuk Kim }
127139a53e0cSJaegeuk Kim 
1272a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode)
127339a53e0cSJaegeuk Kim {
1274204706c7SJaegeuk Kim 	atomic_inc(&F2FS_I(inode)->dirty_pages);
1275c227f912SChao Yu 	inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1276c227f912SChao Yu 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
127739a53e0cSJaegeuk Kim }
127839a53e0cSJaegeuk Kim 
127939a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
128039a53e0cSJaegeuk Kim {
128135782b23SJaegeuk Kim 	atomic_dec(&sbi->nr_pages[count_type]);
128239a53e0cSJaegeuk Kim }
128339a53e0cSJaegeuk Kim 
1284a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode)
128539a53e0cSJaegeuk Kim {
12865ac9f36fSChao Yu 	if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
12875ac9f36fSChao Yu 			!S_ISLNK(inode->i_mode))
12881fe54f9dSJaegeuk Kim 		return;
12891fe54f9dSJaegeuk Kim 
1290204706c7SJaegeuk Kim 	atomic_dec(&F2FS_I(inode)->dirty_pages);
1291c227f912SChao Yu 	dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1292c227f912SChao Yu 				F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
129339a53e0cSJaegeuk Kim }
129439a53e0cSJaegeuk Kim 
1295523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type)
129639a53e0cSJaegeuk Kim {
129735782b23SJaegeuk Kim 	return atomic_read(&sbi->nr_pages[count_type]);
129839a53e0cSJaegeuk Kim }
129939a53e0cSJaegeuk Kim 
1300204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode)
1301f8b2c1f9SJaegeuk Kim {
1302204706c7SJaegeuk Kim 	return atomic_read(&F2FS_I(inode)->dirty_pages);
1303f8b2c1f9SJaegeuk Kim }
1304f8b2c1f9SJaegeuk Kim 
13055ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
13065ac206cfSNamjae Jeon {
13073519e3f9SChao Yu 	unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg;
1308523be8a6SJaegeuk Kim 	unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >>
1309523be8a6SJaegeuk Kim 						sbi->log_blocks_per_seg;
1310523be8a6SJaegeuk Kim 
1311523be8a6SJaegeuk Kim 	return segs / sbi->segs_per_sec;
13125ac206cfSNamjae Jeon }
13135ac206cfSNamjae Jeon 
131439a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
131539a53e0cSJaegeuk Kim {
13168b8343faSJaegeuk Kim 	return sbi->total_valid_block_count;
131739a53e0cSJaegeuk Kim }
131839a53e0cSJaegeuk Kim 
1319f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi)
1320f83a2584SYunlei He {
1321f83a2584SYunlei He 	return sbi->discard_blks;
1322f83a2584SYunlei He }
1323f83a2584SYunlei He 
132439a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
132539a53e0cSJaegeuk Kim {
132639a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
132739a53e0cSJaegeuk Kim 
132839a53e0cSJaegeuk Kim 	/* return NAT or SIT bitmap */
132939a53e0cSJaegeuk Kim 	if (flag == NAT_BITMAP)
133039a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
133139a53e0cSJaegeuk Kim 	else if (flag == SIT_BITMAP)
133239a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
133339a53e0cSJaegeuk Kim 
133439a53e0cSJaegeuk Kim 	return 0;
133539a53e0cSJaegeuk Kim }
133639a53e0cSJaegeuk Kim 
133755141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
133855141486SWanpeng Li {
133955141486SWanpeng Li 	return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
134055141486SWanpeng Li }
134155141486SWanpeng Li 
134239a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
134339a53e0cSJaegeuk Kim {
134439a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
13451dbe4152SChangman Lee 	int offset;
13461dbe4152SChangman Lee 
134755141486SWanpeng Li 	if (__cp_payload(sbi) > 0) {
13481dbe4152SChangman Lee 		if (flag == NAT_BITMAP)
13491dbe4152SChangman Lee 			return &ckpt->sit_nat_version_bitmap;
13501dbe4152SChangman Lee 		else
135165b85cccSJaegeuk Kim 			return (unsigned char *)ckpt + F2FS_BLKSIZE;
13521dbe4152SChangman Lee 	} else {
13531dbe4152SChangman Lee 		offset = (flag == NAT_BITMAP) ?
135425ca923bSJaegeuk Kim 			le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
135539a53e0cSJaegeuk Kim 		return &ckpt->sit_nat_version_bitmap + offset;
135639a53e0cSJaegeuk Kim 	}
13571dbe4152SChangman Lee }
135839a53e0cSJaegeuk Kim 
135939a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
136039a53e0cSJaegeuk Kim {
13618508e44aSJaegeuk Kim 	block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
136239a53e0cSJaegeuk Kim 
13638508e44aSJaegeuk Kim 	if (sbi->cur_cp_pack == 2)
136439a53e0cSJaegeuk Kim 		start_addr += sbi->blocks_per_seg;
136539a53e0cSJaegeuk Kim 	return start_addr;
136639a53e0cSJaegeuk Kim }
136739a53e0cSJaegeuk Kim 
13688508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi)
13698508e44aSJaegeuk Kim {
13708508e44aSJaegeuk Kim 	block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
13718508e44aSJaegeuk Kim 
13728508e44aSJaegeuk Kim 	if (sbi->cur_cp_pack == 1)
13738508e44aSJaegeuk Kim 		start_addr += sbi->blocks_per_seg;
13748508e44aSJaegeuk Kim 	return start_addr;
13758508e44aSJaegeuk Kim }
13768508e44aSJaegeuk Kim 
13778508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi)
13788508e44aSJaegeuk Kim {
13798508e44aSJaegeuk Kim 	sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1;
13808508e44aSJaegeuk Kim }
13818508e44aSJaegeuk Kim 
138239a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
138339a53e0cSJaegeuk Kim {
138439a53e0cSJaegeuk Kim 	return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
138539a53e0cSJaegeuk Kim }
138639a53e0cSJaegeuk Kim 
138739a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
1388ef86d709SGu Zheng 						struct inode *inode)
138939a53e0cSJaegeuk Kim {
139039a53e0cSJaegeuk Kim 	block_t	valid_block_count;
139139a53e0cSJaegeuk Kim 	unsigned int valid_node_count;
139239a53e0cSJaegeuk Kim 
139339a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
139439a53e0cSJaegeuk Kim 
1395ef86d709SGu Zheng 	valid_block_count = sbi->total_valid_block_count + 1;
1396cfb271d4SChao Yu 	if (unlikely(valid_block_count > sbi->user_block_count)) {
139739a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
139839a53e0cSJaegeuk Kim 		return false;
139939a53e0cSJaegeuk Kim 	}
140039a53e0cSJaegeuk Kim 
1401ef86d709SGu Zheng 	valid_node_count = sbi->total_valid_node_count + 1;
1402cfb271d4SChao Yu 	if (unlikely(valid_node_count > sbi->total_node_count)) {
140339a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
140439a53e0cSJaegeuk Kim 		return false;
140539a53e0cSJaegeuk Kim 	}
140639a53e0cSJaegeuk Kim 
140739a53e0cSJaegeuk Kim 	if (inode)
14088edd03c8SJaegeuk Kim 		f2fs_i_blocks_write(inode, 1, true);
1409ef86d709SGu Zheng 
1410ef86d709SGu Zheng 	sbi->total_valid_node_count++;
1411ef86d709SGu Zheng 	sbi->total_valid_block_count++;
141239a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
141339a53e0cSJaegeuk Kim 
141441382ec4SJaegeuk Kim 	percpu_counter_inc(&sbi->alloc_valid_block_count);
141539a53e0cSJaegeuk Kim 	return true;
141639a53e0cSJaegeuk Kim }
141739a53e0cSJaegeuk Kim 
141839a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
1419ef86d709SGu Zheng 						struct inode *inode)
142039a53e0cSJaegeuk Kim {
142139a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
142239a53e0cSJaegeuk Kim 
14239850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_block_count);
14249850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_node_count);
14259850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !inode->i_blocks);
142639a53e0cSJaegeuk Kim 
14278edd03c8SJaegeuk Kim 	f2fs_i_blocks_write(inode, 1, false);
1428ef86d709SGu Zheng 	sbi->total_valid_node_count--;
1429ef86d709SGu Zheng 	sbi->total_valid_block_count--;
143039a53e0cSJaegeuk Kim 
143139a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
143239a53e0cSJaegeuk Kim }
143339a53e0cSJaegeuk Kim 
143439a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
143539a53e0cSJaegeuk Kim {
14368b8343faSJaegeuk Kim 	return sbi->total_valid_node_count;
143739a53e0cSJaegeuk Kim }
143839a53e0cSJaegeuk Kim 
143939a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
144039a53e0cSJaegeuk Kim {
1441513c5f37SJaegeuk Kim 	percpu_counter_inc(&sbi->total_valid_inode_count);
144239a53e0cSJaegeuk Kim }
144339a53e0cSJaegeuk Kim 
14440e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
144539a53e0cSJaegeuk Kim {
1446513c5f37SJaegeuk Kim 	percpu_counter_dec(&sbi->total_valid_inode_count);
144739a53e0cSJaegeuk Kim }
144839a53e0cSJaegeuk Kim 
1449513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi)
145039a53e0cSJaegeuk Kim {
1451513c5f37SJaegeuk Kim 	return percpu_counter_sum_positive(&sbi->total_valid_inode_count);
145239a53e0cSJaegeuk Kim }
145339a53e0cSJaegeuk Kim 
1454a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
1455a56c7c6fSJaegeuk Kim 						pgoff_t index, bool for_write)
1456a56c7c6fSJaegeuk Kim {
1457c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION
1458c41f3cc3SJaegeuk Kim 	struct page *page = find_lock_page(mapping, index);
1459c41f3cc3SJaegeuk Kim 	if (page)
1460c41f3cc3SJaegeuk Kim 		return page;
1461c41f3cc3SJaegeuk Kim 
14621ecc0c5cSChao Yu 	if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC))
1463c41f3cc3SJaegeuk Kim 		return NULL;
1464c41f3cc3SJaegeuk Kim #endif
1465a56c7c6fSJaegeuk Kim 	if (!for_write)
1466a56c7c6fSJaegeuk Kim 		return grab_cache_page(mapping, index);
1467a56c7c6fSJaegeuk Kim 	return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
1468a56c7c6fSJaegeuk Kim }
1469a56c7c6fSJaegeuk Kim 
14706e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst)
14716e2c64adSJaegeuk Kim {
14726e2c64adSJaegeuk Kim 	char *src_kaddr = kmap(src);
14736e2c64adSJaegeuk Kim 	char *dst_kaddr = kmap(dst);
14746e2c64adSJaegeuk Kim 
14756e2c64adSJaegeuk Kim 	memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
14766e2c64adSJaegeuk Kim 	kunmap(dst);
14776e2c64adSJaegeuk Kim 	kunmap(src);
14786e2c64adSJaegeuk Kim }
14796e2c64adSJaegeuk Kim 
148039a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock)
148139a53e0cSJaegeuk Kim {
1482031fa8ccSJaegeuk Kim 	if (!page)
148339a53e0cSJaegeuk Kim 		return;
148439a53e0cSJaegeuk Kim 
148539a53e0cSJaegeuk Kim 	if (unlock) {
14869850cf4aSJaegeuk Kim 		f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
148739a53e0cSJaegeuk Kim 		unlock_page(page);
148839a53e0cSJaegeuk Kim 	}
148909cbfeafSKirill A. Shutemov 	put_page(page);
149039a53e0cSJaegeuk Kim }
149139a53e0cSJaegeuk Kim 
149239a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn)
149339a53e0cSJaegeuk Kim {
149439a53e0cSJaegeuk Kim 	if (dn->node_page)
149539a53e0cSJaegeuk Kim 		f2fs_put_page(dn->node_page, 1);
149639a53e0cSJaegeuk Kim 	if (dn->inode_page && dn->node_page != dn->inode_page)
149739a53e0cSJaegeuk Kim 		f2fs_put_page(dn->inode_page, 0);
149839a53e0cSJaegeuk Kim 	dn->node_page = NULL;
149939a53e0cSJaegeuk Kim 	dn->inode_page = NULL;
150039a53e0cSJaegeuk Kim }
150139a53e0cSJaegeuk Kim 
150239a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
1503e8512d2eSGu Zheng 					size_t size)
150439a53e0cSJaegeuk Kim {
1505e8512d2eSGu Zheng 	return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
150639a53e0cSJaegeuk Kim }
150739a53e0cSJaegeuk Kim 
15087bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
15097bd59381SGu Zheng 						gfp_t flags)
15107bd59381SGu Zheng {
15117bd59381SGu Zheng 	void *entry;
15127bd59381SGu Zheng 
151380c54505SJaegeuk Kim 	entry = kmem_cache_alloc(cachep, flags);
151480c54505SJaegeuk Kim 	if (!entry)
151580c54505SJaegeuk Kim 		entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
15167bd59381SGu Zheng 	return entry;
15177bd59381SGu Zheng }
15187bd59381SGu Zheng 
1519740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages)
1520740432f8SJaegeuk Kim {
1521740432f8SJaegeuk Kim 	struct bio *bio;
1522740432f8SJaegeuk Kim 
1523740432f8SJaegeuk Kim 	/* No failure on bio allocation */
1524740432f8SJaegeuk Kim 	bio = bio_alloc(GFP_NOIO, npages);
152580c54505SJaegeuk Kim 	if (!bio)
152680c54505SJaegeuk Kim 		bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
1527740432f8SJaegeuk Kim 	return bio;
1528740432f8SJaegeuk Kim }
1529740432f8SJaegeuk Kim 
15309be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
15319be32d72SJaegeuk Kim 				unsigned long index, void *item)
15329be32d72SJaegeuk Kim {
15339be32d72SJaegeuk Kim 	while (radix_tree_insert(root, index, item))
15349be32d72SJaegeuk Kim 		cond_resched();
15359be32d72SJaegeuk Kim }
15369be32d72SJaegeuk Kim 
153739a53e0cSJaegeuk Kim #define RAW_IS_INODE(p)	((p)->footer.nid == (p)->footer.ino)
153839a53e0cSJaegeuk Kim 
153939a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page)
154039a53e0cSJaegeuk Kim {
154145590710SGu Zheng 	struct f2fs_node *p = F2FS_NODE(page);
154239a53e0cSJaegeuk Kim 	return RAW_IS_INODE(p);
154339a53e0cSJaegeuk Kim }
154439a53e0cSJaegeuk Kim 
154539a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
154639a53e0cSJaegeuk Kim {
154739a53e0cSJaegeuk Kim 	return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
154839a53e0cSJaegeuk Kim }
154939a53e0cSJaegeuk Kim 
155039a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page,
155139a53e0cSJaegeuk Kim 		unsigned int offset)
155239a53e0cSJaegeuk Kim {
155339a53e0cSJaegeuk Kim 	struct f2fs_node *raw_node;
155439a53e0cSJaegeuk Kim 	__le32 *addr_array;
155545590710SGu Zheng 	raw_node = F2FS_NODE(node_page);
155639a53e0cSJaegeuk Kim 	addr_array = blkaddr_in_node(raw_node);
155739a53e0cSJaegeuk Kim 	return le32_to_cpu(addr_array[offset]);
155839a53e0cSJaegeuk Kim }
155939a53e0cSJaegeuk Kim 
156039a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr)
156139a53e0cSJaegeuk Kim {
156239a53e0cSJaegeuk Kim 	int mask;
156339a53e0cSJaegeuk Kim 
156439a53e0cSJaegeuk Kim 	addr += (nr >> 3);
156539a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
156639a53e0cSJaegeuk Kim 	return mask & *addr;
156739a53e0cSJaegeuk Kim }
156839a53e0cSJaegeuk Kim 
1569a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr)
1570a66cdd98SJaegeuk Kim {
1571a66cdd98SJaegeuk Kim 	int mask;
1572a66cdd98SJaegeuk Kim 
1573a66cdd98SJaegeuk Kim 	addr += (nr >> 3);
1574a66cdd98SJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
1575a66cdd98SJaegeuk Kim 	*addr |= mask;
1576a66cdd98SJaegeuk Kim }
1577a66cdd98SJaegeuk Kim 
1578a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr)
1579a66cdd98SJaegeuk Kim {
1580a66cdd98SJaegeuk Kim 	int mask;
1581a66cdd98SJaegeuk Kim 
1582a66cdd98SJaegeuk Kim 	addr += (nr >> 3);
1583a66cdd98SJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
1584a66cdd98SJaegeuk Kim 	*addr &= ~mask;
1585a66cdd98SJaegeuk Kim }
1586a66cdd98SJaegeuk Kim 
158752aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
158839a53e0cSJaegeuk Kim {
158939a53e0cSJaegeuk Kim 	int mask;
159039a53e0cSJaegeuk Kim 	int ret;
159139a53e0cSJaegeuk Kim 
159239a53e0cSJaegeuk Kim 	addr += (nr >> 3);
159339a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
159439a53e0cSJaegeuk Kim 	ret = mask & *addr;
159539a53e0cSJaegeuk Kim 	*addr |= mask;
159639a53e0cSJaegeuk Kim 	return ret;
159739a53e0cSJaegeuk Kim }
159839a53e0cSJaegeuk Kim 
159952aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
160039a53e0cSJaegeuk Kim {
160139a53e0cSJaegeuk Kim 	int mask;
160239a53e0cSJaegeuk Kim 	int ret;
160339a53e0cSJaegeuk Kim 
160439a53e0cSJaegeuk Kim 	addr += (nr >> 3);
160539a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
160639a53e0cSJaegeuk Kim 	ret = mask & *addr;
160739a53e0cSJaegeuk Kim 	*addr &= ~mask;
160839a53e0cSJaegeuk Kim 	return ret;
160939a53e0cSJaegeuk Kim }
161039a53e0cSJaegeuk Kim 
1611c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr)
1612c6ac4c0eSGu Zheng {
1613c6ac4c0eSGu Zheng 	int mask;
1614c6ac4c0eSGu Zheng 
1615c6ac4c0eSGu Zheng 	addr += (nr >> 3);
1616c6ac4c0eSGu Zheng 	mask = 1 << (7 - (nr & 0x07));
1617c6ac4c0eSGu Zheng 	*addr ^= mask;
1618c6ac4c0eSGu Zheng }
1619c6ac4c0eSGu Zheng 
162039a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */
162139a53e0cSJaegeuk Kim enum {
162239a53e0cSJaegeuk Kim 	FI_NEW_INODE,		/* indicate newly allocated inode */
1623b3783873SJaegeuk Kim 	FI_DIRTY_INODE,		/* indicate inode is dirty or not */
162426de9b11SJaegeuk Kim 	FI_AUTO_RECOVER,	/* indicate inode is recoverable */
1625ed57c27fSJaegeuk Kim 	FI_DIRTY_DIR,		/* indicate directory has dirty pages */
162639a53e0cSJaegeuk Kim 	FI_INC_LINK,		/* need to increment i_nlink */
162739a53e0cSJaegeuk Kim 	FI_ACL_MODE,		/* indicate acl mode */
162839a53e0cSJaegeuk Kim 	FI_NO_ALLOC,		/* should not allocate any blocks */
1629c9b63bd0SJaegeuk Kim 	FI_FREE_NID,		/* free allocated nide */
1630c11abd1aSJaegeuk Kim 	FI_NO_EXTENT,		/* not to use the extent cache */
1631444c580fSJaegeuk Kim 	FI_INLINE_XATTR,	/* used for inline xattr */
16321001b347SHuajun Li 	FI_INLINE_DATA,		/* used for inline data*/
163334d67debSChao Yu 	FI_INLINE_DENTRY,	/* used for inline dentry */
1634fff04f90SJaegeuk Kim 	FI_APPEND_WRITE,	/* inode has appended data */
1635fff04f90SJaegeuk Kim 	FI_UPDATE_WRITE,	/* inode has in-place-update data */
163688b88a66SJaegeuk Kim 	FI_NEED_IPU,		/* used for ipu per file */
163788b88a66SJaegeuk Kim 	FI_ATOMIC_FILE,		/* indicate atomic file */
163802a1335fSJaegeuk Kim 	FI_VOLATILE_FILE,	/* indicate volatile file */
16393c6c2bebSJaegeuk Kim 	FI_FIRST_BLOCK_WRITTEN,	/* indicate #0 data block was written */
16401e84371fSJaegeuk Kim 	FI_DROP_CACHE,		/* drop dirty page cache */
1641b3d208f9SJaegeuk Kim 	FI_DATA_EXIST,		/* indicate data exists */
1642510022a8SJaegeuk Kim 	FI_INLINE_DOTS,		/* indicate inline dot dentries */
1643d323d005SChao Yu 	FI_DO_DEFRAG,		/* indicate defragment is running */
1644c227f912SChao Yu 	FI_DIRTY_FILE,		/* indicate regular/symlink has dirty pages */
164539a53e0cSJaegeuk Kim };
164639a53e0cSJaegeuk Kim 
1647205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode,
1648205b9822SJaegeuk Kim 						int flag, bool set)
164939a53e0cSJaegeuk Kim {
1650205b9822SJaegeuk Kim 	switch (flag) {
1651205b9822SJaegeuk Kim 	case FI_INLINE_XATTR:
1652205b9822SJaegeuk Kim 	case FI_INLINE_DATA:
1653205b9822SJaegeuk Kim 	case FI_INLINE_DENTRY:
1654205b9822SJaegeuk Kim 		if (set)
1655205b9822SJaegeuk Kim 			return;
1656205b9822SJaegeuk Kim 	case FI_DATA_EXIST:
1657205b9822SJaegeuk Kim 	case FI_INLINE_DOTS:
16587c45729aSJaegeuk Kim 		f2fs_mark_inode_dirty_sync(inode, true);
1659205b9822SJaegeuk Kim 	}
166039a53e0cSJaegeuk Kim }
166139a53e0cSJaegeuk Kim 
166291942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag)
166339a53e0cSJaegeuk Kim {
166491942321SJaegeuk Kim 	if (!test_bit(flag, &F2FS_I(inode)->flags))
166591942321SJaegeuk Kim 		set_bit(flag, &F2FS_I(inode)->flags);
1666205b9822SJaegeuk Kim 	__mark_inode_dirty_flag(inode, flag, true);
166739a53e0cSJaegeuk Kim }
166839a53e0cSJaegeuk Kim 
166991942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag)
167039a53e0cSJaegeuk Kim {
167191942321SJaegeuk Kim 	return test_bit(flag, &F2FS_I(inode)->flags);
167239a53e0cSJaegeuk Kim }
167339a53e0cSJaegeuk Kim 
167491942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag)
167539a53e0cSJaegeuk Kim {
167691942321SJaegeuk Kim 	if (test_bit(flag, &F2FS_I(inode)->flags))
167791942321SJaegeuk Kim 		clear_bit(flag, &F2FS_I(inode)->flags);
1678205b9822SJaegeuk Kim 	__mark_inode_dirty_flag(inode, flag, false);
167939a53e0cSJaegeuk Kim }
168039a53e0cSJaegeuk Kim 
168191942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode)
1682444c580fSJaegeuk Kim {
168391942321SJaegeuk Kim 	F2FS_I(inode)->i_acl_mode = mode;
168491942321SJaegeuk Kim 	set_inode_flag(inode, FI_ACL_MODE);
16857c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, false);
168639a53e0cSJaegeuk Kim }
168739a53e0cSJaegeuk Kim 
1688a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc)
1689a1961246SJaegeuk Kim {
1690a1961246SJaegeuk Kim 	if (inc)
1691a1961246SJaegeuk Kim 		inc_nlink(inode);
1692a1961246SJaegeuk Kim 	else
1693a1961246SJaegeuk Kim 		drop_nlink(inode);
16947c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
1695a1961246SJaegeuk Kim }
1696a1961246SJaegeuk Kim 
16978edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode,
16988edd03c8SJaegeuk Kim 					blkcnt_t diff, bool add)
16998edd03c8SJaegeuk Kim {
170026de9b11SJaegeuk Kim 	bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
170126de9b11SJaegeuk Kim 	bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
170226de9b11SJaegeuk Kim 
17038edd03c8SJaegeuk Kim 	inode->i_blocks = add ? inode->i_blocks + diff :
17048edd03c8SJaegeuk Kim 				inode->i_blocks - diff;
17057c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
170626de9b11SJaegeuk Kim 	if (clean || recover)
170726de9b11SJaegeuk Kim 		set_inode_flag(inode, FI_AUTO_RECOVER);
17088edd03c8SJaegeuk Kim }
17098edd03c8SJaegeuk Kim 
1710fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
1711fc9581c8SJaegeuk Kim {
171226de9b11SJaegeuk Kim 	bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
171326de9b11SJaegeuk Kim 	bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
171426de9b11SJaegeuk Kim 
1715fc9581c8SJaegeuk Kim 	if (i_size_read(inode) == i_size)
1716fc9581c8SJaegeuk Kim 		return;
1717fc9581c8SJaegeuk Kim 
1718fc9581c8SJaegeuk Kim 	i_size_write(inode, i_size);
17197c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
172026de9b11SJaegeuk Kim 	if (clean || recover)
172126de9b11SJaegeuk Kim 		set_inode_flag(inode, FI_AUTO_RECOVER);
172226de9b11SJaegeuk Kim }
172326de9b11SJaegeuk Kim 
1724205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth)
1725205b9822SJaegeuk Kim {
1726205b9822SJaegeuk Kim 	F2FS_I(inode)->i_current_depth = depth;
17277c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
1728205b9822SJaegeuk Kim }
1729205b9822SJaegeuk Kim 
1730205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid)
1731205b9822SJaegeuk Kim {
1732205b9822SJaegeuk Kim 	F2FS_I(inode)->i_xattr_nid = xnid;
17337c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
1734205b9822SJaegeuk Kim }
1735205b9822SJaegeuk Kim 
1736205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino)
1737205b9822SJaegeuk Kim {
1738205b9822SJaegeuk Kim 	F2FS_I(inode)->i_pino = pino;
17397c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
1740205b9822SJaegeuk Kim }
1741205b9822SJaegeuk Kim 
174291942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri)
1743444c580fSJaegeuk Kim {
1744205b9822SJaegeuk Kim 	struct f2fs_inode_info *fi = F2FS_I(inode);
1745205b9822SJaegeuk Kim 
1746444c580fSJaegeuk Kim 	if (ri->i_inline & F2FS_INLINE_XATTR)
1747205b9822SJaegeuk Kim 		set_bit(FI_INLINE_XATTR, &fi->flags);
17481001b347SHuajun Li 	if (ri->i_inline & F2FS_INLINE_DATA)
1749205b9822SJaegeuk Kim 		set_bit(FI_INLINE_DATA, &fi->flags);
175034d67debSChao Yu 	if (ri->i_inline & F2FS_INLINE_DENTRY)
1751205b9822SJaegeuk Kim 		set_bit(FI_INLINE_DENTRY, &fi->flags);
1752b3d208f9SJaegeuk Kim 	if (ri->i_inline & F2FS_DATA_EXIST)
1753205b9822SJaegeuk Kim 		set_bit(FI_DATA_EXIST, &fi->flags);
1754510022a8SJaegeuk Kim 	if (ri->i_inline & F2FS_INLINE_DOTS)
1755205b9822SJaegeuk Kim 		set_bit(FI_INLINE_DOTS, &fi->flags);
1756444c580fSJaegeuk Kim }
1757444c580fSJaegeuk Kim 
175891942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri)
1759444c580fSJaegeuk Kim {
1760444c580fSJaegeuk Kim 	ri->i_inline = 0;
1761444c580fSJaegeuk Kim 
176291942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_XATTR))
1763444c580fSJaegeuk Kim 		ri->i_inline |= F2FS_INLINE_XATTR;
176491942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_DATA))
17651001b347SHuajun Li 		ri->i_inline |= F2FS_INLINE_DATA;
176691942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_DENTRY))
176734d67debSChao Yu 		ri->i_inline |= F2FS_INLINE_DENTRY;
176891942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_DATA_EXIST))
1769b3d208f9SJaegeuk Kim 		ri->i_inline |= F2FS_DATA_EXIST;
177091942321SJaegeuk Kim 	if (is_inode_flag_set(inode, FI_INLINE_DOTS))
1771510022a8SJaegeuk Kim 		ri->i_inline |= F2FS_INLINE_DOTS;
1772444c580fSJaegeuk Kim }
1773444c580fSJaegeuk Kim 
1774987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode)
1775987c7c31SChao Yu {
177691942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_XATTR);
1777987c7c31SChao Yu }
1778987c7c31SChao Yu 
177981ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode)
1780de93653fSJaegeuk Kim {
178181ca7350SChao Yu 	if (f2fs_has_inline_xattr(inode))
1782de93653fSJaegeuk Kim 		return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
1783de93653fSJaegeuk Kim 	return DEF_ADDRS_PER_INODE;
1784de93653fSJaegeuk Kim }
1785de93653fSJaegeuk Kim 
178665985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page)
178765985d93SJaegeuk Kim {
1788695fd1edSChao Yu 	struct f2fs_inode *ri = F2FS_INODE(page);
178965985d93SJaegeuk Kim 	return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
179065985d93SJaegeuk Kim 					F2FS_INLINE_XATTR_ADDRS]);
179165985d93SJaegeuk Kim }
179265985d93SJaegeuk Kim 
179365985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode)
179465985d93SJaegeuk Kim {
1795987c7c31SChao Yu 	if (f2fs_has_inline_xattr(inode))
179665985d93SJaegeuk Kim 		return F2FS_INLINE_XATTR_ADDRS << 2;
179765985d93SJaegeuk Kim 	else
179865985d93SJaegeuk Kim 		return 0;
179965985d93SJaegeuk Kim }
180065985d93SJaegeuk Kim 
18010dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode)
18020dbdc2aeSJaegeuk Kim {
180391942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_DATA);
18040dbdc2aeSJaegeuk Kim }
18050dbdc2aeSJaegeuk Kim 
1806b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode)
1807b3d208f9SJaegeuk Kim {
180891942321SJaegeuk Kim 	clear_inode_flag(inode, FI_INLINE_DATA);
180991942321SJaegeuk Kim 	clear_inode_flag(inode, FI_DATA_EXIST);
1810b3d208f9SJaegeuk Kim }
1811b3d208f9SJaegeuk Kim 
1812b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode)
1813b3d208f9SJaegeuk Kim {
181491942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_DATA_EXIST);
1815b3d208f9SJaegeuk Kim }
1816b3d208f9SJaegeuk Kim 
1817510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode)
1818510022a8SJaegeuk Kim {
181991942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_DOTS);
1820510022a8SJaegeuk Kim }
1821510022a8SJaegeuk Kim 
182288b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode)
182388b88a66SJaegeuk Kim {
182491942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_ATOMIC_FILE);
182588b88a66SJaegeuk Kim }
182688b88a66SJaegeuk Kim 
182702a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode)
182802a1335fSJaegeuk Kim {
182991942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_VOLATILE_FILE);
183002a1335fSJaegeuk Kim }
183102a1335fSJaegeuk Kim 
18323c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode)
18333c6c2bebSJaegeuk Kim {
183491942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN);
18353c6c2bebSJaegeuk Kim }
18363c6c2bebSJaegeuk Kim 
18371e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode)
18381e84371fSJaegeuk Kim {
183991942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_DROP_CACHE);
18401e84371fSJaegeuk Kim }
18411e84371fSJaegeuk Kim 
18421001b347SHuajun Li static inline void *inline_data_addr(struct page *page)
18431001b347SHuajun Li {
1844695fd1edSChao Yu 	struct f2fs_inode *ri = F2FS_INODE(page);
18451001b347SHuajun Li 	return (void *)&(ri->i_addr[1]);
18461001b347SHuajun Li }
18471001b347SHuajun Li 
184834d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode)
184934d67debSChao Yu {
185091942321SJaegeuk Kim 	return is_inode_flag_set(inode, FI_INLINE_DENTRY);
185134d67debSChao Yu }
185234d67debSChao Yu 
18539486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
18549486ba44SJaegeuk Kim {
18559486ba44SJaegeuk Kim 	if (!f2fs_has_inline_dentry(dir))
18569486ba44SJaegeuk Kim 		kunmap(page);
18579486ba44SJaegeuk Kim }
18589486ba44SJaegeuk Kim 
1859b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type)
1860b5492af7SJaegeuk Kim {
1861b5492af7SJaegeuk Kim 	return F2FS_I(inode)->i_advise & type;
1862b5492af7SJaegeuk Kim }
1863b5492af7SJaegeuk Kim 
1864b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type)
1865b5492af7SJaegeuk Kim {
1866b5492af7SJaegeuk Kim 	F2FS_I(inode)->i_advise |= type;
18677c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
1868b5492af7SJaegeuk Kim }
1869b5492af7SJaegeuk Kim 
1870b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type)
1871b5492af7SJaegeuk Kim {
1872b5492af7SJaegeuk Kim 	F2FS_I(inode)->i_advise &= ~type;
18737c45729aSJaegeuk Kim 	f2fs_mark_inode_dirty_sync(inode, true);
1874b5492af7SJaegeuk Kim }
1875b5492af7SJaegeuk Kim 
187626787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
187726787236SJaegeuk Kim {
187826787236SJaegeuk Kim 	if (dsync) {
187926787236SJaegeuk Kim 		struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
188026787236SJaegeuk Kim 		bool ret;
188126787236SJaegeuk Kim 
188226787236SJaegeuk Kim 		spin_lock(&sbi->inode_lock[DIRTY_META]);
188326787236SJaegeuk Kim 		ret = list_empty(&F2FS_I(inode)->gdirty_list);
188426787236SJaegeuk Kim 		spin_unlock(&sbi->inode_lock[DIRTY_META]);
188526787236SJaegeuk Kim 		return ret;
188626787236SJaegeuk Kim 	}
188726787236SJaegeuk Kim 	if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) ||
188826787236SJaegeuk Kim 			file_keep_isize(inode) ||
188926787236SJaegeuk Kim 			i_size_read(inode) & PAGE_MASK)
189026787236SJaegeuk Kim 		return false;
189126787236SJaegeuk Kim 	return F2FS_I(inode)->last_disk_size == i_size_read(inode);
1892267378d4SChao Yu }
1893267378d4SChao Yu 
1894267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb)
1895267378d4SChao Yu {
1896267378d4SChao Yu 	return sb->s_flags & MS_RDONLY;
1897267378d4SChao Yu }
189839a53e0cSJaegeuk Kim 
189939a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
190039a53e0cSJaegeuk Kim {
1901aaec2b1dSChao Yu 	return is_set_ckpt_flags(sbi, CP_ERROR_FLAG);
190239a53e0cSJaegeuk Kim }
190339a53e0cSJaegeuk Kim 
1904eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str)
1905eaa693f4SJaegeuk Kim {
1906eaa693f4SJaegeuk Kim 	if (str->len == 1 && str->name[0] == '.')
1907eaa693f4SJaegeuk Kim 		return true;
1908eaa693f4SJaegeuk Kim 
1909eaa693f4SJaegeuk Kim 	if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
1910eaa693f4SJaegeuk Kim 		return true;
1911eaa693f4SJaegeuk Kim 
1912eaa693f4SJaegeuk Kim 	return false;
1913eaa693f4SJaegeuk Kim }
1914eaa693f4SJaegeuk Kim 
19153e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode)
19163e72f721SJaegeuk Kim {
19173e72f721SJaegeuk Kim 	if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) ||
191891942321SJaegeuk Kim 			is_inode_flag_set(inode, FI_NO_EXTENT))
19193e72f721SJaegeuk Kim 		return false;
19203e72f721SJaegeuk Kim 
1921886f56f9SAl Viro 	return S_ISREG(inode->i_mode);
19223e72f721SJaegeuk Kim }
19233e72f721SJaegeuk Kim 
19241ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
19251ecc0c5cSChao Yu 					size_t size, gfp_t flags)
19260414b004SJaegeuk Kim {
19272c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION
19281ecc0c5cSChao Yu 	if (time_to_inject(sbi, FAULT_KMALLOC))
19292c63feadSJaegeuk Kim 		return NULL;
19302c63feadSJaegeuk Kim #endif
19310414b004SJaegeuk Kim 	return kmalloc(size, flags);
19320414b004SJaegeuk Kim }
19330414b004SJaegeuk Kim 
193439307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags)
193539307a8eSJaegeuk Kim {
193639307a8eSJaegeuk Kim 	void *ret;
193739307a8eSJaegeuk Kim 
193839307a8eSJaegeuk Kim 	ret = kmalloc(size, flags | __GFP_NOWARN);
193939307a8eSJaegeuk Kim 	if (!ret)
194039307a8eSJaegeuk Kim 		ret = __vmalloc(size, flags, PAGE_KERNEL);
194139307a8eSJaegeuk Kim 	return ret;
194239307a8eSJaegeuk Kim }
194339307a8eSJaegeuk Kim 
194439307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags)
194539307a8eSJaegeuk Kim {
194639307a8eSJaegeuk Kim 	void *ret;
194739307a8eSJaegeuk Kim 
194839307a8eSJaegeuk Kim 	ret = kzalloc(size, flags | __GFP_NOWARN);
194939307a8eSJaegeuk Kim 	if (!ret)
195039307a8eSJaegeuk Kim 		ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
195139307a8eSJaegeuk Kim 	return ret;
195239307a8eSJaegeuk Kim }
195339307a8eSJaegeuk Kim 
195439a53e0cSJaegeuk Kim #define get_inode_mode(i) \
195591942321SJaegeuk Kim 	((is_inode_flag_set(i, FI_ACL_MODE)) ? \
195639a53e0cSJaegeuk Kim 	 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
195739a53e0cSJaegeuk Kim 
195839a53e0cSJaegeuk Kim /* get offset of first page in next direct node */
195981ca7350SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, inode)				\
196081ca7350SChao Yu 	((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) :	\
196181ca7350SChao Yu 	(pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) /	\
196281ca7350SChao Yu 	ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode))
19631e1bb4baSJaegeuk Kim 
196439a53e0cSJaegeuk Kim /*
19652d4d9fb5SJaegeuk Kim  * file.c
196639a53e0cSJaegeuk Kim  */
196739a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int);
1968b292dcabSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *);
1969764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool);
19709a449e9cSJaegeuk Kim int f2fs_truncate(struct inode *);
197139a53e0cSJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
197239a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *);
197339a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t);
1974e9750824SNamjae Jeon int truncate_data_blocks_range(struct dnode_of_data *, int);
197539a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long);
197639a53e0cSJaegeuk Kim long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
197739a53e0cSJaegeuk Kim 
197839a53e0cSJaegeuk Kim /*
197939a53e0cSJaegeuk Kim  * inode.c
198039a53e0cSJaegeuk Kim  */
198139a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *);
198239936837SJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long);
1983e8ea9b3dSJaegeuk Kim struct inode *f2fs_iget_retry(struct super_block *, unsigned long);
19844660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int);
198512719ae1SJaegeuk Kim int update_inode(struct inode *, struct page *);
198612719ae1SJaegeuk Kim int update_inode_page(struct inode *);
198739a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *);
198839a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *);
198944c16156SJaegeuk Kim void handle_failed_inode(struct inode *);
199039a53e0cSJaegeuk Kim 
199139a53e0cSJaegeuk Kim /*
199239a53e0cSJaegeuk Kim  * namei.c
199339a53e0cSJaegeuk Kim  */
199439a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child);
199539a53e0cSJaegeuk Kim 
199639a53e0cSJaegeuk Kim /*
199739a53e0cSJaegeuk Kim  * dir.c
199839a53e0cSJaegeuk Kim  */
1999510022a8SJaegeuk Kim void set_de_type(struct f2fs_dir_entry *, umode_t);
2000675f10bdSChao Yu unsigned char get_de_type(struct f2fs_dir_entry *);
20010b81d077SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *,
20026e22c691SJaegeuk Kim 			f2fs_hash_t, int *, struct f2fs_dentry_ptr *);
2003ed6bd4b1SChao Yu int f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *,
20040b81d077SJaegeuk Kim 			unsigned int, struct fscrypt_str *);
2005062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *,
2006062a3e7bSJaegeuk Kim 			struct f2fs_dentry_ptr *);
2007dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *,
20089421d570SChao Yu 		const struct qstr *, const struct qstr *, struct page *);
2009dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int);
2010a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int);
20119f7c45ccSJaegeuk Kim void f2fs_drop_nlink(struct inode *, struct inode *);
2012e7ba108aSShuoran Liu struct f2fs_dir_entry *__f2fs_find_entry(struct inode *, struct fscrypt_name *,
2013e7ba108aSShuoran Liu 							struct page **);
2014185de68fSAl Viro struct f2fs_dir_entry *f2fs_find_entry(struct inode *, const struct qstr *,
201539a53e0cSJaegeuk Kim 							struct page **);
201639a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
2017835c92d4SLinus Torvalds ino_t f2fs_inode_by_name(struct inode *, const struct qstr *, struct page **);
201839a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
201939a53e0cSJaegeuk Kim 				struct page *, struct inode *);
2020e7d55452SJaegeuk Kim int update_dent_inode(struct inode *, struct inode *, const struct qstr *);
2021510022a8SJaegeuk Kim void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *,
20223b4d732aSChao Yu 			const struct qstr *, f2fs_hash_t , unsigned int);
2023675f10bdSChao Yu int f2fs_add_regular_entry(struct inode *, const struct qstr *,
20249421d570SChao Yu 			const struct qstr *, struct inode *, nid_t, umode_t);
2025e7ba108aSShuoran Liu int __f2fs_do_add_link(struct inode *, struct fscrypt_name*, struct inode *,
2026e7ba108aSShuoran Liu 			nid_t, umode_t);
2027510022a8SJaegeuk Kim int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t,
2028510022a8SJaegeuk Kim 			umode_t);
2029dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *,
2030dbeacf02SChao Yu 							struct inode *);
2031b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *);
203239a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *);
203339a53e0cSJaegeuk Kim 
2034b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
2035b7f7a5e0SAl Viro {
20362b0143b5SDavid Howells 	return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name,
2037510022a8SJaegeuk Kim 				inode, inode->i_ino, inode->i_mode);
2038b7f7a5e0SAl Viro }
2039b7f7a5e0SAl Viro 
204039a53e0cSJaegeuk Kim /*
204139a53e0cSJaegeuk Kim  * super.c
204239a53e0cSJaegeuk Kim  */
20437c45729aSJaegeuk Kim int f2fs_inode_dirtied(struct inode *, bool);
20440f18b462SJaegeuk Kim void f2fs_inode_synced(struct inode *);
2045c5bda1c8SChao Yu int f2fs_commit_super(struct f2fs_sb_info *, bool);
204639a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int);
2047a07ef784SNamjae Jeon extern __printf(3, 4)
2048a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...);
2049984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi);
205039a53e0cSJaegeuk Kim 
205139a53e0cSJaegeuk Kim /*
205239a53e0cSJaegeuk Kim  * hash.c
205339a53e0cSJaegeuk Kim  */
2054eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *);
205539a53e0cSJaegeuk Kim 
205639a53e0cSJaegeuk Kim /*
205739a53e0cSJaegeuk Kim  * node.c
205839a53e0cSJaegeuk Kim  */
205939a53e0cSJaegeuk Kim struct dnode_of_data;
206039a53e0cSJaegeuk Kim struct node_info;
206139a53e0cSJaegeuk Kim 
20626fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int);
20632dcf51abSJaegeuk Kim int need_dentry_mark(struct f2fs_sb_info *, nid_t);
206488bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t);
206588bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t);
206639a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
20673cf45747SChao Yu pgoff_t get_next_page_offset(struct dnode_of_data *, pgoff_t);
206839a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
206939a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t);
20704f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *);
2071cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
207213ec7297SChao Yu int remove_inode_page(struct inode *);
2073a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *);
20748ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
207539a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t);
207639a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
207739a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int);
2078da011cc0SChao Yu void move_node_page(struct page *, int);
207926de9b11SJaegeuk Kim int fsync_node_pages(struct f2fs_sb_info *, struct inode *,
208026de9b11SJaegeuk Kim 			struct writeback_control *, bool);
208152681375SJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, struct writeback_control *);
20823a2ad567SChao Yu void build_free_nids(struct f2fs_sb_info *, bool);
208339a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *);
208439a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t);
208539a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
208631696580SChao Yu int try_to_free_nids(struct f2fs_sb_info *, int);
208770cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *);
20881c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t);
208939a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *);
209039a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int,
209139a53e0cSJaegeuk Kim 				struct f2fs_summary_block *);
209239a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *);
209339a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *);
209439a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *);
20956e6093a8SNamjae Jeon int __init create_node_manager_caches(void);
209639a53e0cSJaegeuk Kim void destroy_node_manager_caches(void);
209739a53e0cSJaegeuk Kim 
209839a53e0cSJaegeuk Kim /*
209939a53e0cSJaegeuk Kim  * segment.c
210039a53e0cSJaegeuk Kim  */
210188b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *);
210229b96b54SChao Yu void drop_inmem_pages(struct inode *);
210329b96b54SChao Yu int commit_inmem_pages(struct inode *);
21042c4db1a6SJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *, bool);
21054660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *);
21066b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *);
21072163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *);
21085eba8c5dSJaegeuk Kim void destroy_flush_cmd_control(struct f2fs_sb_info *, bool);
210939a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t);
21106e2c64adSJaegeuk Kim bool is_checkpointed_data(struct f2fs_sb_info *, block_t);
21115e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
2112275b66b0SChao Yu void f2fs_wait_all_discard_bio(struct f2fs_sb_info *);
2113836b5a63SJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *);
21144b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *);
21153fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool);
211639a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *);
21174b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *);
211839a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
2119381722d2SChao Yu void update_meta_page(struct f2fs_sb_info *, void *, block_t);
2120577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *);
212105ca3632SJaegeuk Kim void write_node_page(unsigned int, struct f2fs_io_info *);
212205ca3632SJaegeuk Kim void write_data_page(struct dnode_of_data *, struct f2fs_io_info *);
212305ca3632SJaegeuk Kim void rewrite_data_page(struct f2fs_io_info *);
21244356e48eSChao Yu void __f2fs_replace_block(struct f2fs_sb_info *, struct f2fs_summary *,
21254356e48eSChao Yu 					block_t, block_t, bool, bool);
2126528e3459SChao Yu void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *,
212728bc106bSChao Yu 				block_t, block_t, unsigned char, bool, bool);
2128bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *,
2129bfad7c2dSJaegeuk Kim 		block_t, block_t *, struct f2fs_summary *, int);
2130fec1d657SJaegeuk Kim void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool);
213108b39fbdSChao Yu void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t);
213239a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t);
213339a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t);
2134dfc08a12SChao Yu int lookup_journal_in_cursum(struct f2fs_journal *, int, unsigned int, int);
21354b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *);
213639a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *);
213739a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *);
21387fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void);
21397fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void);
214039a53e0cSJaegeuk Kim 
214139a53e0cSJaegeuk Kim /*
214239a53e0cSJaegeuk Kim  * checkpoint.c
214339a53e0cSJaegeuk Kim  */
214438f91ca8SJaegeuk Kim void f2fs_stop_checkpoint(struct f2fs_sb_info *, bool);
214539a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
214639a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
21472b947003SChao Yu struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t);
2148f0c9cadaSChao Yu bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int);
214926879fb1SChao Yu int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool);
2150635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t);
215139a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
2152a49324f1SChao Yu void add_ino_entry(struct f2fs_sb_info *, nid_t, int type);
2153a49324f1SChao Yu void remove_ino_entry(struct f2fs_sb_info *, nid_t, int type);
215474ef9241SJaegeuk Kim void release_ino_entry(struct f2fs_sb_info *, bool);
2155fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int);
21560f18b462SJaegeuk Kim int f2fs_sync_inode_meta(struct f2fs_sb_info *);
2157cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *);
2158cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *);
215967c3758dSJaegeuk Kim void add_orphan_inode(struct inode *);
216039a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
21618c14bfadSChao Yu int recover_orphan_inodes(struct f2fs_sb_info *);
216239a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *);
2163a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *);
2164c227f912SChao Yu void remove_dirty_inode(struct inode *);
21656d5a1495SChao Yu int sync_dirty_inodes(struct f2fs_sb_info *, enum inode_type);
2166c34f42e2SChao Yu int write_checkpoint(struct f2fs_sb_info *, struct cp_control *);
21676451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *);
21686e6093a8SNamjae Jeon int __init create_checkpoint_caches(void);
216939a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void);
217039a53e0cSJaegeuk Kim 
217139a53e0cSJaegeuk Kim /*
217239a53e0cSJaegeuk Kim  * data.c
217339a53e0cSJaegeuk Kim  */
2174458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
21750c3a5797SChao Yu void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *, struct inode *,
21760c3a5797SChao Yu 				struct page *, nid_t, enum page_type, int);
2177406657ddSChao Yu void f2fs_flush_merged_bios(struct f2fs_sb_info *);
217805ca3632SJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_io_info *);
2179*0a595ebaSJaegeuk Kim int f2fs_submit_page_mbio(struct f2fs_io_info *);
21803c62be17SJaegeuk Kim struct block_device *f2fs_target_device(struct f2fs_sb_info *,
21813c62be17SJaegeuk Kim 				block_t, struct bio *);
21823c62be17SJaegeuk Kim int f2fs_target_device_index(struct f2fs_sb_info *, block_t);
2183216a620aSChao Yu void set_data_blkaddr(struct dnode_of_data *);
2184f28b3434SChao Yu void f2fs_update_data_blkaddr(struct dnode_of_data *, block_t);
218546008c6dSChao Yu int reserve_new_blocks(struct dnode_of_data *, blkcnt_t);
218639a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *);
2187759af1c9SFan Li int f2fs_get_block(struct dnode_of_data *, pgoff_t);
2188a7de6086SJaegeuk Kim int f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *);
2189b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
2190a56c7c6fSJaegeuk Kim struct page *get_read_data_page(struct inode *, pgoff_t, int, bool);
219143f3eae1SJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t);
2192a56c7c6fSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t, bool);
219364aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
219405ca3632SJaegeuk Kim int do_write_data_page(struct f2fs_io_info *);
2195d323d005SChao Yu int f2fs_map_blocks(struct inode *, struct f2fs_map_blocks *, int, int);
21969ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
2197fe76b796SJaegeuk Kim void f2fs_set_page_dirty_nobuffers(struct page *);
2198487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int);
2199487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t);
22005b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION
22015b7a487cSWeichao Guo int f2fs_migrate_page(struct address_space *, struct page *, struct page *,
22025b7a487cSWeichao Guo 				enum migrate_mode);
22035b7a487cSWeichao Guo #endif
220439a53e0cSJaegeuk Kim 
220539a53e0cSJaegeuk Kim /*
220639a53e0cSJaegeuk Kim  * gc.c
220739a53e0cSJaegeuk Kim  */
220839a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *);
220939a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *);
221081ca7350SChao Yu block_t start_bidx_of_node(unsigned int, struct inode *);
22117702bdbeSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *, bool, bool);
221239a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *);
221339a53e0cSJaegeuk Kim 
221439a53e0cSJaegeuk Kim /*
221539a53e0cSJaegeuk Kim  * recovery.c
221639a53e0cSJaegeuk Kim  */
22176781eabbSJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *, bool);
221839a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *);
221939a53e0cSJaegeuk Kim 
222039a53e0cSJaegeuk Kim /*
222139a53e0cSJaegeuk Kim  * debug.c
222239a53e0cSJaegeuk Kim  */
222339a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS
222439a53e0cSJaegeuk Kim struct f2fs_stat_info {
222539a53e0cSJaegeuk Kim 	struct list_head stat_list;
222639a53e0cSJaegeuk Kim 	struct f2fs_sb_info *sbi;
222739a53e0cSJaegeuk Kim 	int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
222839a53e0cSJaegeuk Kim 	int main_area_segs, main_area_sections, main_area_zones;
22295b7ee374SChao Yu 	unsigned long long hit_largest, hit_cached, hit_rbtree;
22305b7ee374SChao Yu 	unsigned long long hit_total, total_ext;
2231c00ba554SJaegeuk Kim 	int ext_tree, zombie_tree, ext_node;
223235782b23SJaegeuk Kim 	int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta;
223335782b23SJaegeuk Kim 	int inmem_pages;
22340f18b462SJaegeuk Kim 	unsigned int ndirty_dirs, ndirty_files, ndirty_all;
2235b8559dc2SChao Yu 	int nats, dirty_nats, sits, dirty_sits, free_nids, alloc_nids;
223639a53e0cSJaegeuk Kim 	int total_count, utilization;
223736951b38SChao Yu 	int bg_gc, nr_wb_cp_data, nr_wb_data;
2238652be551SJaegeuk Kim 	int inline_xattr, inline_inode, inline_dir, orphans;
2239f83a2584SYunlei He 	unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks;
224039a53e0cSJaegeuk Kim 	unsigned int bimodal, avg_vblocks;
224139a53e0cSJaegeuk Kim 	int util_free, util_valid, util_invalid;
224239a53e0cSJaegeuk Kim 	int rsvd_segs, overp_segs;
224339a53e0cSJaegeuk Kim 	int dirty_count, node_pages, meta_pages;
224442190d2aSJaegeuk Kim 	int prefree_count, call_count, cp_count, bg_cp_count;
224539a53e0cSJaegeuk Kim 	int tot_segs, node_segs, data_segs, free_segs, free_secs;
2246e1235983SChangman Lee 	int bg_node_segs, bg_data_segs;
224739a53e0cSJaegeuk Kim 	int tot_blks, data_blks, node_blks;
2248e1235983SChangman Lee 	int bg_data_blks, bg_node_blks;
224939a53e0cSJaegeuk Kim 	int curseg[NR_CURSEG_TYPE];
225039a53e0cSJaegeuk Kim 	int cursec[NR_CURSEG_TYPE];
225139a53e0cSJaegeuk Kim 	int curzone[NR_CURSEG_TYPE];
225239a53e0cSJaegeuk Kim 
225339a53e0cSJaegeuk Kim 	unsigned int segment_count[2];
225439a53e0cSJaegeuk Kim 	unsigned int block_count[2];
2255b9a2c252SChangman Lee 	unsigned int inplace_count;
22569edcdabfSChao Yu 	unsigned long long base_mem, cache_mem, page_mem;
225739a53e0cSJaegeuk Kim };
225839a53e0cSJaegeuk Kim 
2259963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
2260963d4f7dSGu Zheng {
2261963d4f7dSGu Zheng 	return (struct f2fs_stat_info *)sbi->stat_info;
2262963d4f7dSGu Zheng }
2263963d4f7dSGu Zheng 
2264942e0be6SChangman Lee #define stat_inc_cp_count(si)		((si)->cp_count++)
226542190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si)	((si)->bg_cp_count++)
226639a53e0cSJaegeuk Kim #define stat_inc_call_count(si)		((si)->call_count++)
2267dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi)	((sbi)->bg_gc++)
226833fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type)	((sbi)->ndirty_inode[type]++)
226933fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type)	((sbi)->ndirty_inode[type]--)
22705b7ee374SChao Yu #define stat_inc_total_hit(sbi)		(atomic64_inc(&(sbi)->total_hit_ext))
22715b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_rbtree))
22725b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_largest))
22735b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi)	(atomic64_inc(&(sbi)->read_hit_cached))
2274d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode)					\
2275d5e8f6c9SChao Yu 	do {								\
2276d5e8f6c9SChao Yu 		if (f2fs_has_inline_xattr(inode))			\
2277d5e8f6c9SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_xattr));	\
2278d5e8f6c9SChao Yu 	} while (0)
2279d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode)					\
2280d5e8f6c9SChao Yu 	do {								\
2281d5e8f6c9SChao Yu 		if (f2fs_has_inline_xattr(inode))			\
2282d5e8f6c9SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_xattr));	\
2283d5e8f6c9SChao Yu 	} while (0)
22840dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode)					\
22850dbdc2aeSJaegeuk Kim 	do {								\
22860dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
228703e14d52SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_inode));	\
22880dbdc2aeSJaegeuk Kim 	} while (0)
22890dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode)					\
22900dbdc2aeSJaegeuk Kim 	do {								\
22910dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
229203e14d52SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_inode));	\
22930dbdc2aeSJaegeuk Kim 	} while (0)
22943289c061SJaegeuk Kim #define stat_inc_inline_dir(inode)					\
22953289c061SJaegeuk Kim 	do {								\
22963289c061SJaegeuk Kim 		if (f2fs_has_inline_dentry(inode))			\
229703e14d52SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_dir));	\
22983289c061SJaegeuk Kim 	} while (0)
22993289c061SJaegeuk Kim #define stat_dec_inline_dir(inode)					\
23003289c061SJaegeuk Kim 	do {								\
23013289c061SJaegeuk Kim 		if (f2fs_has_inline_dentry(inode))			\
230203e14d52SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_dir));	\
23033289c061SJaegeuk Kim 	} while (0)
2304dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg)					\
2305dcdfff65SJaegeuk Kim 		((sbi)->segment_count[(curseg)->alloc_type]++)
2306dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg)				\
2307dcdfff65SJaegeuk Kim 		((sbi)->block_count[(curseg)->alloc_type]++)
2308b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi)					\
2309b9a2c252SChangman Lee 		(atomic_inc(&(sbi)->inplace_count))
2310e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type)				\
231139a53e0cSJaegeuk Kim 	do {								\
2312963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
231339a53e0cSJaegeuk Kim 		(si)->tot_segs++;					\
2314e1235983SChangman Lee 		if (type == SUM_TYPE_DATA) {				\
231539a53e0cSJaegeuk Kim 			si->data_segs++;				\
2316e1235983SChangman Lee 			si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0;	\
2317e1235983SChangman Lee 		} else {						\
231839a53e0cSJaegeuk Kim 			si->node_segs++;				\
2319e1235983SChangman Lee 			si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0;	\
2320e1235983SChangman Lee 		}							\
232139a53e0cSJaegeuk Kim 	} while (0)
232239a53e0cSJaegeuk Kim 
232339a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks)				\
232439a53e0cSJaegeuk Kim 	(si->tot_blks += (blks))
232539a53e0cSJaegeuk Kim 
2326e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type)			\
232739a53e0cSJaegeuk Kim 	do {								\
2328963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
232939a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
233039a53e0cSJaegeuk Kim 		si->data_blks += (blks);				\
2331e1235983SChangman Lee 		si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0;	\
233239a53e0cSJaegeuk Kim 	} while (0)
233339a53e0cSJaegeuk Kim 
2334e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type)			\
233539a53e0cSJaegeuk Kim 	do {								\
2336963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
233739a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
233839a53e0cSJaegeuk Kim 		si->node_blks += (blks);				\
2339e1235983SChangman Lee 		si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0;	\
234039a53e0cSJaegeuk Kim 	} while (0)
234139a53e0cSJaegeuk Kim 
234239a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *);
234339a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *);
2344787c7b8cSChao Yu int __init f2fs_create_root_stats(void);
23454589d25dSNamjae Jeon void f2fs_destroy_root_stats(void);
234639a53e0cSJaegeuk Kim #else
2347942e0be6SChangman Lee #define stat_inc_cp_count(si)
234842190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si)
234939a53e0cSJaegeuk Kim #define stat_inc_call_count(si)
2350dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si)
235133fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type)
235233fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type)
2353dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb)
2354029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb)
235591c481ffSChao Yu #define stat_inc_largest_node_hit(sbi)
235691c481ffSChao Yu #define stat_inc_cached_node_hit(sbi)
2357d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode)
2358d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode)
23590dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode)
23600dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode)
23613289c061SJaegeuk Kim #define stat_inc_inline_dir(inode)
23623289c061SJaegeuk Kim #define stat_dec_inline_dir(inode)
2363dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg)
2364dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg)
2365b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi)
2366e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type)
236739a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks)
2368e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type)
2369e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type)
237039a53e0cSJaegeuk Kim 
237139a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
237239a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
2373787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; }
23744589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { }
237539a53e0cSJaegeuk Kim #endif
237639a53e0cSJaegeuk Kim 
237739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations;
237839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations;
237939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations;
238039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops;
238139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops;
238239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops;
238339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations;
238439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations;
2385cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
238639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations;
238729e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab;
23881001b347SHuajun Li 
2389e18c65b2SHuajun Li /*
2390e18c65b2SHuajun Li  * inline.c
2391e18c65b2SHuajun Li  */
239201b960e9SJaegeuk Kim bool f2fs_may_inline_data(struct inode *);
239301b960e9SJaegeuk Kim bool f2fs_may_inline_dentry(struct inode *);
2394b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *);
23950bfcfccaSChao Yu bool truncate_inline_inode(struct page *, u64);
2396e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *);
2397b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *);
2398b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *);
2399b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *);
24000342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *);
24016e22c691SJaegeuk Kim struct f2fs_dir_entry *find_in_inline_dir(struct inode *,
24020b81d077SJaegeuk Kim 				struct fscrypt_name *, struct page **);
2403201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *);
24049421d570SChao Yu int f2fs_add_inline_entry(struct inode *, const struct qstr *,
24059421d570SChao Yu 		const struct qstr *, struct inode *, nid_t, umode_t);
2406201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *,
2407201a05beSChao Yu 						struct inode *, struct inode *);
2408201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *);
2409d8c6822aSJaegeuk Kim int f2fs_read_inline_dir(struct file *, struct dir_context *,
24100b81d077SJaegeuk Kim 						struct fscrypt_str *);
241167f8cf3cSJaegeuk Kim int f2fs_inline_data_fiemap(struct inode *,
241267f8cf3cSJaegeuk Kim 		struct fiemap_extent_info *, __u64, __u64);
2413cde4de12SJaegeuk Kim 
2414cde4de12SJaegeuk Kim /*
24152658e50dSJaegeuk Kim  * shrinker.c
24162658e50dSJaegeuk Kim  */
24172658e50dSJaegeuk Kim unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *);
24182658e50dSJaegeuk Kim unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *);
24192658e50dSJaegeuk Kim void f2fs_join_shrinker(struct f2fs_sb_info *);
24202658e50dSJaegeuk Kim void f2fs_leave_shrinker(struct f2fs_sb_info *);
24212658e50dSJaegeuk Kim 
24222658e50dSJaegeuk Kim /*
2423a28ef1f5SChao Yu  * extent_cache.c
2424a28ef1f5SChao Yu  */
2425a28ef1f5SChao Yu unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int);
2426ed3d1256SJaegeuk Kim bool f2fs_init_extent_tree(struct inode *, struct f2fs_extent *);
24275f281fabSJaegeuk Kim void f2fs_drop_extent_tree(struct inode *);
2428a28ef1f5SChao Yu unsigned int f2fs_destroy_extent_node(struct inode *);
2429a28ef1f5SChao Yu void f2fs_destroy_extent_tree(struct inode *);
2430a28ef1f5SChao Yu bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *);
2431a28ef1f5SChao Yu void f2fs_update_extent_cache(struct dnode_of_data *);
243219b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
243319b2c30dSChao Yu 						pgoff_t, block_t, unsigned int);
2434a28ef1f5SChao Yu void init_extent_cache_info(struct f2fs_sb_info *);
2435a28ef1f5SChao Yu int __init create_extent_cache(void);
2436a28ef1f5SChao Yu void destroy_extent_cache(void);
2437a28ef1f5SChao Yu 
2438a28ef1f5SChao Yu /*
2439cde4de12SJaegeuk Kim  * crypto support
2440cde4de12SJaegeuk Kim  */
24410b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode)
2442cde4de12SJaegeuk Kim {
2443cde4de12SJaegeuk Kim 	return file_is_encrypt(inode);
2444cde4de12SJaegeuk Kim }
2445cde4de12SJaegeuk Kim 
2446cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode)
2447cde4de12SJaegeuk Kim {
2448cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION
2449cde4de12SJaegeuk Kim 	file_set_encrypt(inode);
2450cde4de12SJaegeuk Kim #endif
2451cde4de12SJaegeuk Kim }
2452cde4de12SJaegeuk Kim 
2453cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio)
2454cde4de12SJaegeuk Kim {
24550b81d077SJaegeuk Kim 	return bio->bi_private != NULL;
2456cde4de12SJaegeuk Kim }
2457cde4de12SJaegeuk Kim 
2458cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb)
2459cde4de12SJaegeuk Kim {
2460cde4de12SJaegeuk Kim 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT);
2461cde4de12SJaegeuk Kim }
2462f424f664SJaegeuk Kim 
24630bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb)
246452763a4bSJaegeuk Kim {
24650bfd7a09SDamien Le Moal 	return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED);
246652763a4bSJaegeuk Kim }
246752763a4bSJaegeuk Kim 
2468178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED
2469178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi,
24703c62be17SJaegeuk Kim 			struct block_device *bdev, block_t blkaddr)
2471178053e2SDamien Le Moal {
2472178053e2SDamien Le Moal 	unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz;
24733c62be17SJaegeuk Kim 	int i;
2474178053e2SDamien Le Moal 
24753c62be17SJaegeuk Kim 	for (i = 0; i < sbi->s_ndevs; i++)
24763c62be17SJaegeuk Kim 		if (FDEV(i).bdev == bdev)
24773c62be17SJaegeuk Kim 			return FDEV(i).blkz_type[zno];
24783c62be17SJaegeuk Kim 	return -EINVAL;
2479178053e2SDamien Le Moal }
2480178053e2SDamien Le Moal #endif
2481178053e2SDamien Le Moal 
248296ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
248396ba2decSDamien Le Moal {
248496ba2decSDamien Le Moal 	struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
248596ba2decSDamien Le Moal 
248696ba2decSDamien Le Moal 	return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb);
248752763a4bSJaegeuk Kim }
248852763a4bSJaegeuk Kim 
248952763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
249052763a4bSJaegeuk Kim {
249152763a4bSJaegeuk Kim 	clear_opt(sbi, ADAPTIVE);
249252763a4bSJaegeuk Kim 	clear_opt(sbi, LFS);
249352763a4bSJaegeuk Kim 
249452763a4bSJaegeuk Kim 	switch (mt) {
249552763a4bSJaegeuk Kim 	case F2FS_MOUNT_ADAPTIVE:
249652763a4bSJaegeuk Kim 		set_opt(sbi, ADAPTIVE);
249752763a4bSJaegeuk Kim 		break;
249852763a4bSJaegeuk Kim 	case F2FS_MOUNT_LFS:
249952763a4bSJaegeuk Kim 		set_opt(sbi, LFS);
250052763a4bSJaegeuk Kim 		break;
250152763a4bSJaegeuk Kim 	}
250252763a4bSJaegeuk Kim }
250352763a4bSJaegeuk Kim 
2504fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode)
2505fcc85a4dSJaegeuk Kim {
2506fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION
2507886f56f9SAl Viro 	umode_t mode = inode->i_mode;
2508fcc85a4dSJaegeuk Kim 
2509fcc85a4dSJaegeuk Kim 	return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
2510fcc85a4dSJaegeuk Kim #else
2511fcc85a4dSJaegeuk Kim 	return 0;
2512fcc85a4dSJaegeuk Kim #endif
2513fcc85a4dSJaegeuk Kim }
2514fcc85a4dSJaegeuk Kim 
25150b81d077SJaegeuk Kim #ifndef CONFIG_F2FS_FS_ENCRYPTION
25160b81d077SJaegeuk Kim #define fscrypt_set_d_op(i)
25170b81d077SJaegeuk Kim #define fscrypt_get_ctx			fscrypt_notsupp_get_ctx
25180b81d077SJaegeuk Kim #define fscrypt_release_ctx		fscrypt_notsupp_release_ctx
25190b81d077SJaegeuk Kim #define fscrypt_encrypt_page		fscrypt_notsupp_encrypt_page
25200b81d077SJaegeuk Kim #define fscrypt_decrypt_page		fscrypt_notsupp_decrypt_page
25210b81d077SJaegeuk Kim #define fscrypt_decrypt_bio_pages	fscrypt_notsupp_decrypt_bio_pages
25220b81d077SJaegeuk Kim #define fscrypt_pullback_bio_page	fscrypt_notsupp_pullback_bio_page
25230b81d077SJaegeuk Kim #define fscrypt_restore_control_page	fscrypt_notsupp_restore_control_page
25240b81d077SJaegeuk Kim #define fscrypt_zeroout_range		fscrypt_notsupp_zeroout_range
2525db717d8eSEric Biggers #define fscrypt_ioctl_set_policy	fscrypt_notsupp_ioctl_set_policy
2526db717d8eSEric Biggers #define fscrypt_ioctl_get_policy	fscrypt_notsupp_ioctl_get_policy
25270b81d077SJaegeuk Kim #define fscrypt_has_permitted_context	fscrypt_notsupp_has_permitted_context
25280b81d077SJaegeuk Kim #define fscrypt_inherit_context		fscrypt_notsupp_inherit_context
25290b81d077SJaegeuk Kim #define fscrypt_get_encryption_info	fscrypt_notsupp_get_encryption_info
25300b81d077SJaegeuk Kim #define fscrypt_put_encryption_info	fscrypt_notsupp_put_encryption_info
25310b81d077SJaegeuk Kim #define fscrypt_setup_filename		fscrypt_notsupp_setup_filename
25320b81d077SJaegeuk Kim #define fscrypt_free_filename		fscrypt_notsupp_free_filename
25330b81d077SJaegeuk Kim #define fscrypt_fname_encrypted_size	fscrypt_notsupp_fname_encrypted_size
25340b81d077SJaegeuk Kim #define fscrypt_fname_alloc_buffer	fscrypt_notsupp_fname_alloc_buffer
25350b81d077SJaegeuk Kim #define fscrypt_fname_free_buffer	fscrypt_notsupp_fname_free_buffer
25360b81d077SJaegeuk Kim #define fscrypt_fname_disk_to_usr	fscrypt_notsupp_fname_disk_to_usr
25370b81d077SJaegeuk Kim #define fscrypt_fname_usr_to_disk	fscrypt_notsupp_fname_usr_to_disk
253857e5055bSJaegeuk Kim #endif
253939a53e0cSJaegeuk Kim #endif
2540