xref: /openbmc/linux/fs/f2fs/f2fs.h (revision 3b4d732a568432039af71809f9cad69565f00bed)
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>
2239a53e0cSJaegeuk Kim 
235d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS
249850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition)	BUG_ON(condition)
250daaad97SJaegeuk Kim #define f2fs_down_write(x, y)	down_write_nest_lock(x, y)
265d56b671SJaegeuk Kim #else
279850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition)					\
289850cf4aSJaegeuk Kim 	do {								\
299850cf4aSJaegeuk Kim 		if (unlikely(condition)) {				\
309850cf4aSJaegeuk Kim 			WARN_ON(1);					\
31caf0047eSChao Yu 			set_sbi_flag(sbi, SBI_NEED_FSCK);		\
329850cf4aSJaegeuk Kim 		}							\
339850cf4aSJaegeuk Kim 	} while (0)
340daaad97SJaegeuk Kim #define f2fs_down_write(x, y)	down_write(x)
355d56b671SJaegeuk Kim #endif
365d56b671SJaegeuk Kim 
3739a53e0cSJaegeuk Kim /*
3839a53e0cSJaegeuk Kim  * For mount options
3939a53e0cSJaegeuk Kim  */
4039a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC		0x00000001
4139a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD	0x00000002
4239a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD		0x00000004
4339a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP		0x00000008
4439a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER		0x00000010
4539a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL		0x00000020
4639a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY	0x00000040
47444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR		0x00000080
481001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA		0x00000100
4934d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY	0x00000200
5034d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE		0x00000400
5134d67debSChao Yu #define F2FS_MOUNT_NOBARRIER		0x00000800
52d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT		0x00001000
5339a53e0cSJaegeuk Kim 
5439a53e0cSJaegeuk Kim #define clear_opt(sbi, option)	(sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
5539a53e0cSJaegeuk Kim #define set_opt(sbi, option)	(sbi->mount_opt.opt |= F2FS_MOUNT_##option)
5639a53e0cSJaegeuk Kim #define test_opt(sbi, option)	(sbi->mount_opt.opt & F2FS_MOUNT_##option)
5739a53e0cSJaegeuk Kim 
5839a53e0cSJaegeuk Kim #define ver_after(a, b)	(typecheck(unsigned long long, a) &&		\
5939a53e0cSJaegeuk Kim 		typecheck(unsigned long long, b) &&			\
6039a53e0cSJaegeuk Kim 		((long long)((a) - (b)) > 0))
6139a53e0cSJaegeuk Kim 
62a9841c4dSJaegeuk Kim typedef u32 block_t;	/*
63a9841c4dSJaegeuk Kim 			 * should not change u32, since it is the on-disk block
64a9841c4dSJaegeuk Kim 			 * address format, __le32.
65a9841c4dSJaegeuk Kim 			 */
6639a53e0cSJaegeuk Kim typedef u32 nid_t;
6739a53e0cSJaegeuk Kim 
6839a53e0cSJaegeuk Kim struct f2fs_mount_info {
6939a53e0cSJaegeuk Kim 	unsigned int	opt;
7039a53e0cSJaegeuk Kim };
7139a53e0cSJaegeuk Kim 
727e586fa0SJaegeuk Kim #define CRCPOLY_LE 0xedb88320
737e586fa0SJaegeuk Kim 
747e586fa0SJaegeuk Kim static inline __u32 f2fs_crc32(void *buf, size_t len)
7539a53e0cSJaegeuk Kim {
767e586fa0SJaegeuk Kim 	unsigned char *p = (unsigned char *)buf;
777e586fa0SJaegeuk Kim 	__u32 crc = F2FS_SUPER_MAGIC;
787e586fa0SJaegeuk Kim 	int i;
797e586fa0SJaegeuk Kim 
807e586fa0SJaegeuk Kim 	while (len--) {
817e586fa0SJaegeuk Kim 		crc ^= *p++;
827e586fa0SJaegeuk Kim 		for (i = 0; i < 8; i++)
837e586fa0SJaegeuk Kim 			crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
847e586fa0SJaegeuk Kim 	}
857e586fa0SJaegeuk Kim 	return crc;
8639a53e0cSJaegeuk Kim }
8739a53e0cSJaegeuk Kim 
887e586fa0SJaegeuk Kim static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
8939a53e0cSJaegeuk Kim {
907e586fa0SJaegeuk Kim 	return f2fs_crc32(buf, buf_size) == blk_crc;
9139a53e0cSJaegeuk Kim }
9239a53e0cSJaegeuk Kim 
9339a53e0cSJaegeuk Kim /*
9439a53e0cSJaegeuk Kim  * For checkpoint manager
9539a53e0cSJaegeuk Kim  */
9639a53e0cSJaegeuk Kim enum {
9739a53e0cSJaegeuk Kim 	NAT_BITMAP,
9839a53e0cSJaegeuk Kim 	SIT_BITMAP
9939a53e0cSJaegeuk Kim };
10039a53e0cSJaegeuk Kim 
10175ab4cb8SJaegeuk Kim enum {
10275ab4cb8SJaegeuk Kim 	CP_UMOUNT,
103119ee914SJaegeuk Kim 	CP_FASTBOOT,
10475ab4cb8SJaegeuk Kim 	CP_SYNC,
1054b2fecc8SJaegeuk Kim 	CP_DISCARD,
10675ab4cb8SJaegeuk Kim };
10775ab4cb8SJaegeuk Kim 
108bba681cbSJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS	32
109bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi)	\
110bba681cbSJaegeuk Kim 		(SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
111bba681cbSJaegeuk Kim 
11275ab4cb8SJaegeuk Kim struct cp_control {
11375ab4cb8SJaegeuk Kim 	int reason;
1144b2fecc8SJaegeuk Kim 	__u64 trim_start;
1154b2fecc8SJaegeuk Kim 	__u64 trim_end;
1164b2fecc8SJaegeuk Kim 	__u64 trim_minlen;
1174b2fecc8SJaegeuk Kim 	__u64 trimmed;
11875ab4cb8SJaegeuk Kim };
11975ab4cb8SJaegeuk Kim 
120662befdaSChao Yu /*
12181c1a0f1SChao Yu  * For CP/NAT/SIT/SSA readahead
122662befdaSChao Yu  */
123662befdaSChao Yu enum {
124662befdaSChao Yu 	META_CP,
125662befdaSChao Yu 	META_NAT,
12681c1a0f1SChao Yu 	META_SIT,
1274c521f49SJaegeuk Kim 	META_SSA,
1284c521f49SJaegeuk Kim 	META_POR,
129662befdaSChao Yu };
130662befdaSChao Yu 
1316451e041SJaegeuk Kim /* for the list of ino */
1326451e041SJaegeuk Kim enum {
1336451e041SJaegeuk Kim 	ORPHAN_INO,		/* for orphan ino list */
134fff04f90SJaegeuk Kim 	APPEND_INO,		/* for append ino list */
135fff04f90SJaegeuk Kim 	UPDATE_INO,		/* for update ino list */
1366451e041SJaegeuk Kim 	MAX_INO_ENTRY,		/* max. list */
1376451e041SJaegeuk Kim };
1386451e041SJaegeuk Kim 
1396451e041SJaegeuk Kim struct ino_entry {
14039a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
14139a53e0cSJaegeuk Kim 	nid_t ino;		/* inode number */
14239a53e0cSJaegeuk Kim };
14339a53e0cSJaegeuk Kim 
14406292073SChao Yu /*
14506292073SChao Yu  * for the list of directory inodes or gc inodes.
14606292073SChao Yu  * NOTE: there are two slab users for this structure, if we add/modify/delete
14706292073SChao Yu  * fields in structure for one of slab users, it may affect fields or size of
14806292073SChao Yu  * other one, in this condition, it's better to split both of slab and related
14906292073SChao Yu  * data structure.
15006292073SChao Yu  */
15106292073SChao Yu struct inode_entry {
15239a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
15339a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
15439a53e0cSJaegeuk Kim };
15539a53e0cSJaegeuk Kim 
1567fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */
1577fd9e544SJaegeuk Kim struct discard_entry {
1587fd9e544SJaegeuk Kim 	struct list_head list;	/* list head */
1597fd9e544SJaegeuk Kim 	block_t blkaddr;	/* block address to be discarded */
1607fd9e544SJaegeuk Kim 	int len;		/* # of consecutive blocks of the discard */
1617fd9e544SJaegeuk Kim };
1627fd9e544SJaegeuk Kim 
16339a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */
16439a53e0cSJaegeuk Kim struct fsync_inode_entry {
16539a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
16639a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
167c52e1b10SJaegeuk Kim 	block_t blkaddr;	/* block address locating the last fsync */
168c52e1b10SJaegeuk Kim 	block_t last_dentry;	/* block address locating the last dentry */
169c52e1b10SJaegeuk Kim 	block_t last_inode;	/* block address locating the last inode */
17039a53e0cSJaegeuk Kim };
17139a53e0cSJaegeuk Kim 
17239a53e0cSJaegeuk Kim #define nats_in_cursum(sum)		(le16_to_cpu(sum->n_nats))
17339a53e0cSJaegeuk Kim #define sits_in_cursum(sum)		(le16_to_cpu(sum->n_sits))
17439a53e0cSJaegeuk Kim 
17539a53e0cSJaegeuk Kim #define nat_in_journal(sum, i)		(sum->nat_j.entries[i].ne)
17639a53e0cSJaegeuk Kim #define nid_in_journal(sum, i)		(sum->nat_j.entries[i].nid)
17739a53e0cSJaegeuk Kim #define sit_in_journal(sum, i)		(sum->sit_j.entries[i].se)
17839a53e0cSJaegeuk Kim #define segno_in_journal(sum, i)	(sum->sit_j.entries[i].segno)
17939a53e0cSJaegeuk Kim 
180309cc2b6SJaegeuk Kim #define MAX_NAT_JENTRIES(sum)	(NAT_JOURNAL_ENTRIES - nats_in_cursum(sum))
181309cc2b6SJaegeuk Kim #define MAX_SIT_JENTRIES(sum)	(SIT_JOURNAL_ENTRIES - sits_in_cursum(sum))
182309cc2b6SJaegeuk Kim 
18339a53e0cSJaegeuk Kim static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
18439a53e0cSJaegeuk Kim {
18539a53e0cSJaegeuk Kim 	int before = nats_in_cursum(rs);
18639a53e0cSJaegeuk Kim 	rs->n_nats = cpu_to_le16(before + i);
18739a53e0cSJaegeuk Kim 	return before;
18839a53e0cSJaegeuk Kim }
18939a53e0cSJaegeuk Kim 
19039a53e0cSJaegeuk Kim static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
19139a53e0cSJaegeuk Kim {
19239a53e0cSJaegeuk Kim 	int before = sits_in_cursum(rs);
19339a53e0cSJaegeuk Kim 	rs->n_sits = cpu_to_le16(before + i);
19439a53e0cSJaegeuk Kim 	return before;
19539a53e0cSJaegeuk Kim }
19639a53e0cSJaegeuk Kim 
197184a5cd2SChao Yu static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size,
198184a5cd2SChao Yu 								int type)
199184a5cd2SChao Yu {
200184a5cd2SChao Yu 	if (type == NAT_JOURNAL)
201309cc2b6SJaegeuk Kim 		return size <= MAX_NAT_JENTRIES(sum);
202309cc2b6SJaegeuk Kim 	return size <= MAX_SIT_JENTRIES(sum);
203184a5cd2SChao Yu }
204184a5cd2SChao Yu 
20539a53e0cSJaegeuk Kim /*
206e9750824SNamjae Jeon  * ioctl commands
207e9750824SNamjae Jeon  */
208e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS		FS_IOC_GETFLAGS
209e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS		FS_IOC_SETFLAGS
210d49f3e89SChao Yu #define F2FS_IOC_GETVERSION		FS_IOC_GETVERSION
211e9750824SNamjae Jeon 
21288b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC		0xf5
21388b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE	_IO(F2FS_IOCTL_MAGIC, 1)
21488b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE	_IO(F2FS_IOCTL_MAGIC, 2)
21502a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 3)
2161e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 4)
2171e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE	_IO(F2FS_IOCTL_MAGIC, 5)
21888b88a66SJaegeuk Kim 
219e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
220e9750824SNamjae Jeon /*
221e9750824SNamjae Jeon  * ioctl commands in 32 bit emulation
222e9750824SNamjae Jeon  */
223e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS             FS_IOC32_GETFLAGS
224e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS             FS_IOC32_SETFLAGS
225e9750824SNamjae Jeon #endif
226e9750824SNamjae Jeon 
227e9750824SNamjae Jeon /*
22839a53e0cSJaegeuk Kim  * For INODE and NODE manager
22939a53e0cSJaegeuk Kim  */
2307b3cd7d6SJaegeuk Kim /* for directory operations */
2317b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr {
2327b3cd7d6SJaegeuk Kim 	const void *bitmap;
2337b3cd7d6SJaegeuk Kim 	struct f2fs_dir_entry *dentry;
2347b3cd7d6SJaegeuk Kim 	__u8 (*filename)[F2FS_SLOT_LEN];
2357b3cd7d6SJaegeuk Kim 	int max;
2367b3cd7d6SJaegeuk Kim };
2377b3cd7d6SJaegeuk Kim 
2387b3cd7d6SJaegeuk Kim static inline void make_dentry_ptr(struct f2fs_dentry_ptr *d,
2397b3cd7d6SJaegeuk Kim 					void *src, int type)
2407b3cd7d6SJaegeuk Kim {
2417b3cd7d6SJaegeuk Kim 	if (type == 1) {
2427b3cd7d6SJaegeuk Kim 		struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src;
2437b3cd7d6SJaegeuk Kim 		d->max = NR_DENTRY_IN_BLOCK;
2447b3cd7d6SJaegeuk Kim 		d->bitmap = &t->dentry_bitmap;
2457b3cd7d6SJaegeuk Kim 		d->dentry = t->dentry;
2467b3cd7d6SJaegeuk Kim 		d->filename = t->filename;
2477b3cd7d6SJaegeuk Kim 	} else {
2487b3cd7d6SJaegeuk Kim 		struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src;
2497b3cd7d6SJaegeuk Kim 		d->max = NR_INLINE_DENTRY;
2507b3cd7d6SJaegeuk Kim 		d->bitmap = &t->dentry_bitmap;
2517b3cd7d6SJaegeuk Kim 		d->dentry = t->dentry;
2527b3cd7d6SJaegeuk Kim 		d->filename = t->filename;
2537b3cd7d6SJaegeuk Kim 	}
2547b3cd7d6SJaegeuk Kim }
2557b3cd7d6SJaegeuk Kim 
256dbe6a5ffSJaegeuk Kim /*
257dbe6a5ffSJaegeuk Kim  * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
258dbe6a5ffSJaegeuk Kim  * as its node offset to distinguish from index node blocks.
259dbe6a5ffSJaegeuk Kim  * But some bits are used to mark the node block.
26039a53e0cSJaegeuk Kim  */
261dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET	((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
262dbe6a5ffSJaegeuk Kim 				>> OFFSET_BIT_SHIFT)
263266e97a8SJaegeuk Kim enum {
264266e97a8SJaegeuk Kim 	ALLOC_NODE,			/* allocate a new node page if needed */
265266e97a8SJaegeuk Kim 	LOOKUP_NODE,			/* look up a node without readahead */
266266e97a8SJaegeuk Kim 	LOOKUP_NODE_RA,			/*
267266e97a8SJaegeuk Kim 					 * look up a node with readahead called
2684f4124d0SChao Yu 					 * by get_data_block.
26939a53e0cSJaegeuk Kim 					 */
270266e97a8SJaegeuk Kim };
271266e97a8SJaegeuk Kim 
27239a53e0cSJaegeuk Kim #define F2FS_LINK_MAX		32000	/* maximum link count per file */
27339a53e0cSJaegeuk Kim 
274817202d9SChao Yu #define MAX_DIR_RA_PAGES	4	/* maximum ra pages of dir */
275817202d9SChao Yu 
27639a53e0cSJaegeuk Kim /* for in-memory extent cache entry */
277c11abd1aSJaegeuk Kim #define F2FS_MIN_EXTENT_LEN	16	/* minimum extent length */
278c11abd1aSJaegeuk Kim 
27939a53e0cSJaegeuk Kim struct extent_info {
28039a53e0cSJaegeuk Kim 	rwlock_t ext_lock;	/* rwlock for consistency */
28139a53e0cSJaegeuk Kim 	unsigned int fofs;	/* start offset in a file */
28239a53e0cSJaegeuk Kim 	u32 blk_addr;		/* start block address of the extent */
283111d2495SMasanari Iida 	unsigned int len;	/* length of the extent */
28439a53e0cSJaegeuk Kim };
28539a53e0cSJaegeuk Kim 
28639a53e0cSJaegeuk Kim /*
28739a53e0cSJaegeuk Kim  * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
28839a53e0cSJaegeuk Kim  */
28939a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT	0x01
290354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT	0x02
29139a53e0cSJaegeuk Kim 
292ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL		0
293ab9fa662SJaegeuk Kim 
29439a53e0cSJaegeuk Kim struct f2fs_inode_info {
29539a53e0cSJaegeuk Kim 	struct inode vfs_inode;		/* serve a vfs inode */
29639a53e0cSJaegeuk Kim 	unsigned long i_flags;		/* keep an inode flags for ioctl */
29739a53e0cSJaegeuk Kim 	unsigned char i_advise;		/* use to give file attribute hints */
29838431545SJaegeuk Kim 	unsigned char i_dir_level;	/* use for dentry level for large dir */
29939a53e0cSJaegeuk Kim 	unsigned int i_current_depth;	/* use only in directory structure */
3006666e6aaSJaegeuk Kim 	unsigned int i_pino;		/* parent inode number */
30139a53e0cSJaegeuk Kim 	umode_t i_acl_mode;		/* keep file acl mode temporarily */
30239a53e0cSJaegeuk Kim 
30339a53e0cSJaegeuk Kim 	/* Use below internally in f2fs*/
30439a53e0cSJaegeuk Kim 	unsigned long flags;		/* use to pass per-file flags */
305d928bfbfSJaegeuk Kim 	struct rw_semaphore i_sem;	/* protect fi info */
306a7ffdbe2SJaegeuk Kim 	atomic_t dirty_pages;		/* # of dirty pages */
30739a53e0cSJaegeuk Kim 	f2fs_hash_t chash;		/* hash value of given file name */
30839a53e0cSJaegeuk Kim 	unsigned int clevel;		/* maximum level of given file name */
30939a53e0cSJaegeuk Kim 	nid_t i_xattr_nid;		/* node id that contains xattrs */
310e518ff81SJaegeuk Kim 	unsigned long long xattr_ver;	/* cp version of xattr modification */
31139a53e0cSJaegeuk Kim 	struct extent_info ext;		/* in-memory extent cache entry */
31206292073SChao Yu 	struct inode_entry *dirty_dir;	/* the pointer of dirty dir */
31388b88a66SJaegeuk Kim 
31434ba94baSJaegeuk Kim 	struct radix_tree_root inmem_root;	/* radix tree for inmem pages */
31588b88a66SJaegeuk Kim 	struct list_head inmem_pages;	/* inmemory pages managed by f2fs */
31688b88a66SJaegeuk Kim 	struct mutex inmem_lock;	/* lock for inmemory pages */
31739a53e0cSJaegeuk Kim };
31839a53e0cSJaegeuk Kim 
31939a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext,
32039a53e0cSJaegeuk Kim 					struct f2fs_extent i_ext)
32139a53e0cSJaegeuk Kim {
32239a53e0cSJaegeuk Kim 	write_lock(&ext->ext_lock);
32339a53e0cSJaegeuk Kim 	ext->fofs = le32_to_cpu(i_ext.fofs);
32439a53e0cSJaegeuk Kim 	ext->blk_addr = le32_to_cpu(i_ext.blk_addr);
32539a53e0cSJaegeuk Kim 	ext->len = le32_to_cpu(i_ext.len);
32639a53e0cSJaegeuk Kim 	write_unlock(&ext->ext_lock);
32739a53e0cSJaegeuk Kim }
32839a53e0cSJaegeuk Kim 
32939a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext,
33039a53e0cSJaegeuk Kim 					struct f2fs_extent *i_ext)
33139a53e0cSJaegeuk Kim {
33239a53e0cSJaegeuk Kim 	read_lock(&ext->ext_lock);
33339a53e0cSJaegeuk Kim 	i_ext->fofs = cpu_to_le32(ext->fofs);
33439a53e0cSJaegeuk Kim 	i_ext->blk_addr = cpu_to_le32(ext->blk_addr);
33539a53e0cSJaegeuk Kim 	i_ext->len = cpu_to_le32(ext->len);
33639a53e0cSJaegeuk Kim 	read_unlock(&ext->ext_lock);
33739a53e0cSJaegeuk Kim }
33839a53e0cSJaegeuk Kim 
33939a53e0cSJaegeuk Kim struct f2fs_nm_info {
34039a53e0cSJaegeuk Kim 	block_t nat_blkaddr;		/* base disk address of NAT */
34139a53e0cSJaegeuk Kim 	nid_t max_nid;			/* maximum possible node ids */
3427ee0eeabSJaegeuk Kim 	nid_t available_nids;		/* maximum available node ids */
34339a53e0cSJaegeuk Kim 	nid_t next_scan_nid;		/* the next nid to be scanned */
344cdfc41c1SJaegeuk Kim 	unsigned int ram_thresh;	/* control the memory footprint */
34539a53e0cSJaegeuk Kim 
34639a53e0cSJaegeuk Kim 	/* NAT cache management */
34739a53e0cSJaegeuk Kim 	struct radix_tree_root nat_root;/* root of the nat entry cache */
348309cc2b6SJaegeuk Kim 	struct radix_tree_root nat_set_root;/* root of the nat set cache */
3498b26ef98SJaegeuk Kim 	struct rw_semaphore nat_tree_lock;	/* protect nat_tree_lock */
35039a53e0cSJaegeuk Kim 	struct list_head nat_entries;	/* cached nat entry list (clean) */
351309cc2b6SJaegeuk Kim 	unsigned int nat_cnt;		/* the # of cached nat entries */
352aec71382SChao Yu 	unsigned int dirty_nat_cnt;	/* total num of nat entries in set */
35339a53e0cSJaegeuk Kim 
35439a53e0cSJaegeuk Kim 	/* free node ids management */
3558a7ed66aSJaegeuk Kim 	struct radix_tree_root free_nid_root;/* root of the free_nid cache */
35639a53e0cSJaegeuk Kim 	struct list_head free_nid_list;	/* a list for free nids */
35739a53e0cSJaegeuk Kim 	spinlock_t free_nid_list_lock;	/* protect free nid list */
35839a53e0cSJaegeuk Kim 	unsigned int fcnt;		/* the number of free node id */
35939a53e0cSJaegeuk Kim 	struct mutex build_lock;	/* lock for build free nids */
36039a53e0cSJaegeuk Kim 
36139a53e0cSJaegeuk Kim 	/* for checkpoint */
36239a53e0cSJaegeuk Kim 	char *nat_bitmap;		/* NAT bitmap pointer */
36339a53e0cSJaegeuk Kim 	int bitmap_size;		/* bitmap size */
36439a53e0cSJaegeuk Kim };
36539a53e0cSJaegeuk Kim 
36639a53e0cSJaegeuk Kim /*
36739a53e0cSJaegeuk Kim  * this structure is used as one of function parameters.
36839a53e0cSJaegeuk Kim  * all the information are dedicated to a given direct node block determined
36939a53e0cSJaegeuk Kim  * by the data offset in a file.
37039a53e0cSJaegeuk Kim  */
37139a53e0cSJaegeuk Kim struct dnode_of_data {
37239a53e0cSJaegeuk Kim 	struct inode *inode;		/* vfs inode pointer */
37339a53e0cSJaegeuk Kim 	struct page *inode_page;	/* its inode page, NULL is possible */
37439a53e0cSJaegeuk Kim 	struct page *node_page;		/* cached direct node page */
37539a53e0cSJaegeuk Kim 	nid_t nid;			/* node id of the direct node block */
37639a53e0cSJaegeuk Kim 	unsigned int ofs_in_node;	/* data offset in the node page */
37739a53e0cSJaegeuk Kim 	bool inode_page_locked;		/* inode page is locked or not */
37839a53e0cSJaegeuk Kim 	block_t	data_blkaddr;		/* block address of the node block */
37939a53e0cSJaegeuk Kim };
38039a53e0cSJaegeuk Kim 
38139a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
38239a53e0cSJaegeuk Kim 		struct page *ipage, struct page *npage, nid_t nid)
38339a53e0cSJaegeuk Kim {
384d66d1f76SJaegeuk Kim 	memset(dn, 0, sizeof(*dn));
38539a53e0cSJaegeuk Kim 	dn->inode = inode;
38639a53e0cSJaegeuk Kim 	dn->inode_page = ipage;
38739a53e0cSJaegeuk Kim 	dn->node_page = npage;
38839a53e0cSJaegeuk Kim 	dn->nid = nid;
38939a53e0cSJaegeuk Kim }
39039a53e0cSJaegeuk Kim 
39139a53e0cSJaegeuk Kim /*
39239a53e0cSJaegeuk Kim  * For SIT manager
39339a53e0cSJaegeuk Kim  *
39439a53e0cSJaegeuk Kim  * By default, there are 6 active log areas across the whole main area.
39539a53e0cSJaegeuk Kim  * When considering hot and cold data separation to reduce cleaning overhead,
39639a53e0cSJaegeuk Kim  * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
39739a53e0cSJaegeuk Kim  * respectively.
39839a53e0cSJaegeuk Kim  * In the current design, you should not change the numbers intentionally.
39939a53e0cSJaegeuk Kim  * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
40039a53e0cSJaegeuk Kim  * logs individually according to the underlying devices. (default: 6)
40139a53e0cSJaegeuk Kim  * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
40239a53e0cSJaegeuk Kim  * data and 8 for node logs.
40339a53e0cSJaegeuk Kim  */
40439a53e0cSJaegeuk Kim #define	NR_CURSEG_DATA_TYPE	(3)
40539a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE	(3)
40639a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
40739a53e0cSJaegeuk Kim 
40839a53e0cSJaegeuk Kim enum {
40939a53e0cSJaegeuk Kim 	CURSEG_HOT_DATA	= 0,	/* directory entry blocks */
41039a53e0cSJaegeuk Kim 	CURSEG_WARM_DATA,	/* data blocks */
41139a53e0cSJaegeuk Kim 	CURSEG_COLD_DATA,	/* multimedia or GCed data blocks */
41239a53e0cSJaegeuk Kim 	CURSEG_HOT_NODE,	/* direct node blocks of directory files */
41339a53e0cSJaegeuk Kim 	CURSEG_WARM_NODE,	/* direct node blocks of normal files */
41439a53e0cSJaegeuk Kim 	CURSEG_COLD_NODE,	/* indirect node blocks */
41538aa0889SJaegeuk Kim 	NO_CHECK_TYPE,
41638aa0889SJaegeuk Kim 	CURSEG_DIRECT_IO,	/* to use for the direct IO path */
41739a53e0cSJaegeuk Kim };
41839a53e0cSJaegeuk Kim 
4196b4afdd7SJaegeuk Kim struct flush_cmd {
4206b4afdd7SJaegeuk Kim 	struct completion wait;
421721bd4d5SGu Zheng 	struct llist_node llnode;
4226b4afdd7SJaegeuk Kim 	int ret;
4236b4afdd7SJaegeuk Kim };
4246b4afdd7SJaegeuk Kim 
425a688b9d9SGu Zheng struct flush_cmd_control {
426a688b9d9SGu Zheng 	struct task_struct *f2fs_issue_flush;	/* flush thread */
427a688b9d9SGu Zheng 	wait_queue_head_t flush_wait_queue;	/* waiting queue for wake-up */
428721bd4d5SGu Zheng 	struct llist_head issue_list;		/* list for command issue */
429721bd4d5SGu Zheng 	struct llist_node *dispatch_list;	/* list for command dispatch */
430a688b9d9SGu Zheng };
431a688b9d9SGu Zheng 
43239a53e0cSJaegeuk Kim struct f2fs_sm_info {
43339a53e0cSJaegeuk Kim 	struct sit_info *sit_info;		/* whole segment information */
43439a53e0cSJaegeuk Kim 	struct free_segmap_info *free_info;	/* free segment information */
43539a53e0cSJaegeuk Kim 	struct dirty_seglist_info *dirty_info;	/* dirty segment information */
43639a53e0cSJaegeuk Kim 	struct curseg_info *curseg_array;	/* active segment information */
43739a53e0cSJaegeuk Kim 
43839a53e0cSJaegeuk Kim 	block_t seg0_blkaddr;		/* block address of 0'th segment */
43939a53e0cSJaegeuk Kim 	block_t main_blkaddr;		/* start block address of main area */
44039a53e0cSJaegeuk Kim 	block_t ssa_blkaddr;		/* start block address of SSA area */
44139a53e0cSJaegeuk Kim 
44239a53e0cSJaegeuk Kim 	unsigned int segment_count;	/* total # of segments */
44339a53e0cSJaegeuk Kim 	unsigned int main_segments;	/* # of segments in main area */
44439a53e0cSJaegeuk Kim 	unsigned int reserved_segments;	/* # of reserved segments */
44539a53e0cSJaegeuk Kim 	unsigned int ovp_segments;	/* # of overprovision segments */
44681eb8d6eSJaegeuk Kim 
44781eb8d6eSJaegeuk Kim 	/* a threshold to reclaim prefree segments */
44881eb8d6eSJaegeuk Kim 	unsigned int rec_prefree_segments;
4497fd9e544SJaegeuk Kim 
4507fd9e544SJaegeuk Kim 	/* for small discard management */
4517fd9e544SJaegeuk Kim 	struct list_head discard_list;		/* 4KB discard list */
4527fd9e544SJaegeuk Kim 	int nr_discards;			/* # of discards in the list */
4537fd9e544SJaegeuk Kim 	int max_discards;			/* max. discards to be issued */
454216fbd64SJaegeuk Kim 
455bba681cbSJaegeuk Kim 	/* for batched trimming */
456bba681cbSJaegeuk Kim 	unsigned int trim_sections;		/* # of sections to trim */
457bba681cbSJaegeuk Kim 
458184a5cd2SChao Yu 	struct list_head sit_entry_set;	/* sit entry set list */
459184a5cd2SChao Yu 
460216fbd64SJaegeuk Kim 	unsigned int ipu_policy;	/* in-place-update policy */
461216fbd64SJaegeuk Kim 	unsigned int min_ipu_util;	/* in-place-update threshold */
462c1ce1b02SJaegeuk Kim 	unsigned int min_fsync_blocks;	/* threshold for fsync */
4636b4afdd7SJaegeuk Kim 
4646b4afdd7SJaegeuk Kim 	/* for flush command control */
465a688b9d9SGu Zheng 	struct flush_cmd_control *cmd_control_info;
466a688b9d9SGu Zheng 
46739a53e0cSJaegeuk Kim };
46839a53e0cSJaegeuk Kim 
46939a53e0cSJaegeuk Kim /*
47039a53e0cSJaegeuk Kim  * For superblock
47139a53e0cSJaegeuk Kim  */
47239a53e0cSJaegeuk Kim /*
47339a53e0cSJaegeuk Kim  * COUNT_TYPE for monitoring
47439a53e0cSJaegeuk Kim  *
47539a53e0cSJaegeuk Kim  * f2fs monitors the number of several block types such as on-writeback,
47639a53e0cSJaegeuk Kim  * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
47739a53e0cSJaegeuk Kim  */
47839a53e0cSJaegeuk Kim enum count_type {
47939a53e0cSJaegeuk Kim 	F2FS_WRITEBACK,
48039a53e0cSJaegeuk Kim 	F2FS_DIRTY_DENTS,
48139a53e0cSJaegeuk Kim 	F2FS_DIRTY_NODES,
48239a53e0cSJaegeuk Kim 	F2FS_DIRTY_META,
4838dcf2ff7SJaegeuk Kim 	F2FS_INMEM_PAGES,
48439a53e0cSJaegeuk Kim 	NR_COUNT_TYPE,
48539a53e0cSJaegeuk Kim };
48639a53e0cSJaegeuk Kim 
48739a53e0cSJaegeuk Kim /*
488e1c42045Sarter97  * The below are the page types of bios used in submit_bio().
48939a53e0cSJaegeuk Kim  * The available types are:
49039a53e0cSJaegeuk Kim  * DATA			User data pages. It operates as async mode.
49139a53e0cSJaegeuk Kim  * NODE			Node pages. It operates as async mode.
49239a53e0cSJaegeuk Kim  * META			FS metadata pages such as SIT, NAT, CP.
49339a53e0cSJaegeuk Kim  * NR_PAGE_TYPE		The number of page types.
49439a53e0cSJaegeuk Kim  * META_FLUSH		Make sure the previous pages are written
49539a53e0cSJaegeuk Kim  *			with waiting the bio's completion
49639a53e0cSJaegeuk Kim  * ...			Only can be used with META.
49739a53e0cSJaegeuk Kim  */
4987d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type)	((type) > META ? META : (type))
49939a53e0cSJaegeuk Kim enum page_type {
50039a53e0cSJaegeuk Kim 	DATA,
50139a53e0cSJaegeuk Kim 	NODE,
50239a53e0cSJaegeuk Kim 	META,
50339a53e0cSJaegeuk Kim 	NR_PAGE_TYPE,
50439a53e0cSJaegeuk Kim 	META_FLUSH,
50539a53e0cSJaegeuk Kim };
50639a53e0cSJaegeuk Kim 
507458e6197SJaegeuk Kim struct f2fs_io_info {
508458e6197SJaegeuk Kim 	enum page_type type;	/* contains DATA/NODE/META/META_FLUSH */
5097e8f2308SGu Zheng 	int rw;			/* contains R/RS/W/WS with REQ_META/REQ_PRIO */
510cf04e8ebSJaegeuk Kim 	block_t blk_addr;	/* block address to be written */
511458e6197SJaegeuk Kim };
512458e6197SJaegeuk Kim 
51393dfe2acSJaegeuk Kim #define is_read_io(rw)	(((rw) & 1) == READ)
5141ff7bd3bSJaegeuk Kim struct f2fs_bio_info {
515458e6197SJaegeuk Kim 	struct f2fs_sb_info *sbi;	/* f2fs superblock */
5161ff7bd3bSJaegeuk Kim 	struct bio *bio;		/* bios to merge */
5171ff7bd3bSJaegeuk Kim 	sector_t last_block_in_bio;	/* last block number */
518458e6197SJaegeuk Kim 	struct f2fs_io_info fio;	/* store buffered io info. */
519df0f8dc0SChao Yu 	struct rw_semaphore io_rwsem;	/* blocking op for bio */
5201ff7bd3bSJaegeuk Kim };
5211ff7bd3bSJaegeuk Kim 
52267298804SChao Yu /* for inner inode cache management */
52367298804SChao Yu struct inode_management {
52467298804SChao Yu 	struct radix_tree_root ino_root;	/* ino entry array */
52567298804SChao Yu 	spinlock_t ino_lock;			/* for ino entry lock */
52667298804SChao Yu 	struct list_head ino_list;		/* inode list head */
52767298804SChao Yu 	unsigned long ino_num;			/* number of entries */
52867298804SChao Yu };
52967298804SChao Yu 
530caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */
531caf0047eSChao Yu enum {
532caf0047eSChao Yu 	SBI_IS_DIRTY,				/* dirty flag for checkpoint */
533caf0047eSChao Yu 	SBI_IS_CLOSE,				/* specify unmounting */
534caf0047eSChao Yu 	SBI_NEED_FSCK,				/* need fsck.f2fs to fix */
535caf0047eSChao Yu 	SBI_POR_DOING,				/* recovery is doing or not */
536caf0047eSChao Yu };
537caf0047eSChao Yu 
53839a53e0cSJaegeuk Kim struct f2fs_sb_info {
53939a53e0cSJaegeuk Kim 	struct super_block *sb;			/* pointer to VFS super block */
5405e176d54SJaegeuk Kim 	struct proc_dir_entry *s_proc;		/* proc entry */
54139a53e0cSJaegeuk Kim 	struct buffer_head *raw_super_buf;	/* buffer head of raw sb */
54239a53e0cSJaegeuk Kim 	struct f2fs_super_block *raw_super;	/* raw super block pointer */
543caf0047eSChao Yu 	int s_flag;				/* flags for sbi */
54439a53e0cSJaegeuk Kim 
54539a53e0cSJaegeuk Kim 	/* for node-related operations */
54639a53e0cSJaegeuk Kim 	struct f2fs_nm_info *nm_info;		/* node manager */
54739a53e0cSJaegeuk Kim 	struct inode *node_inode;		/* cache node blocks */
54839a53e0cSJaegeuk Kim 
54939a53e0cSJaegeuk Kim 	/* for segment-related operations */
55039a53e0cSJaegeuk Kim 	struct f2fs_sm_info *sm_info;		/* segment manager */
5511ff7bd3bSJaegeuk Kim 
5521ff7bd3bSJaegeuk Kim 	/* for bio operations */
553924b720bSChao Yu 	struct f2fs_bio_info read_io;			/* for read bios */
5541ff7bd3bSJaegeuk Kim 	struct f2fs_bio_info write_io[NR_PAGE_TYPE];	/* for write bios */
55539a53e0cSJaegeuk Kim 
55639a53e0cSJaegeuk Kim 	/* for checkpoint */
55739a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
55839a53e0cSJaegeuk Kim 	struct inode *meta_inode;		/* cache meta blocks */
55939936837SJaegeuk Kim 	struct mutex cp_mutex;			/* checkpoint procedure lock */
560e479556bSGu Zheng 	struct rw_semaphore cp_rwsem;		/* blocking FS operations */
561b3582c68SChao Yu 	struct rw_semaphore node_write;		/* locking node writes */
56239a53e0cSJaegeuk Kim 	struct mutex writepages;		/* mutex for writepages() */
563fb51b5efSChangman Lee 	wait_queue_head_t cp_wait;
56439a53e0cSJaegeuk Kim 
56567298804SChao Yu 	struct inode_management im[MAX_INO_ENTRY];      /* manage inode cache */
5666451e041SJaegeuk Kim 
5676451e041SJaegeuk Kim 	/* for orphan inode, use 0'th array */
5680d47c1adSGu Zheng 	unsigned int max_orphans;		/* max orphan inodes */
56939a53e0cSJaegeuk Kim 
57039a53e0cSJaegeuk Kim 	/* for directory inode management */
57139a53e0cSJaegeuk Kim 	struct list_head dir_inode_list;	/* dir inode list */
57239a53e0cSJaegeuk Kim 	spinlock_t dir_inode_lock;		/* for dir inode list lock */
57339a53e0cSJaegeuk Kim 
57439a53e0cSJaegeuk Kim 	/* basic filesystem units */
57539a53e0cSJaegeuk Kim 	unsigned int log_sectors_per_block;	/* log2 sectors per block */
57639a53e0cSJaegeuk Kim 	unsigned int log_blocksize;		/* log2 block size */
57739a53e0cSJaegeuk Kim 	unsigned int blocksize;			/* block size */
57839a53e0cSJaegeuk Kim 	unsigned int root_ino_num;		/* root inode number*/
57939a53e0cSJaegeuk Kim 	unsigned int node_ino_num;		/* node inode number*/
58039a53e0cSJaegeuk Kim 	unsigned int meta_ino_num;		/* meta inode number*/
58139a53e0cSJaegeuk Kim 	unsigned int log_blocks_per_seg;	/* log2 blocks per segment */
58239a53e0cSJaegeuk Kim 	unsigned int blocks_per_seg;		/* blocks per segment */
58339a53e0cSJaegeuk Kim 	unsigned int segs_per_sec;		/* segments per section */
58439a53e0cSJaegeuk Kim 	unsigned int secs_per_zone;		/* sections per zone */
58539a53e0cSJaegeuk Kim 	unsigned int total_sections;		/* total section count */
58639a53e0cSJaegeuk Kim 	unsigned int total_node_count;		/* total node block count */
58739a53e0cSJaegeuk Kim 	unsigned int total_valid_node_count;	/* valid node block count */
58839a53e0cSJaegeuk Kim 	unsigned int total_valid_inode_count;	/* valid inode count */
58939a53e0cSJaegeuk Kim 	int active_logs;			/* # of active logs */
590ab9fa662SJaegeuk Kim 	int dir_level;				/* directory level */
59139a53e0cSJaegeuk Kim 
59239a53e0cSJaegeuk Kim 	block_t user_block_count;		/* # of user blocks */
59339a53e0cSJaegeuk Kim 	block_t total_valid_block_count;	/* # of valid blocks */
59439a53e0cSJaegeuk Kim 	block_t alloc_valid_block_count;	/* # of allocated blocks */
59539a53e0cSJaegeuk Kim 	block_t last_valid_block_count;		/* for recovery */
59639a53e0cSJaegeuk Kim 	u32 s_next_generation;			/* for NFS support */
59739a53e0cSJaegeuk Kim 	atomic_t nr_pages[NR_COUNT_TYPE];	/* # of pages, see count_type */
59839a53e0cSJaegeuk Kim 
59939a53e0cSJaegeuk Kim 	struct f2fs_mount_info mount_opt;	/* mount options */
60039a53e0cSJaegeuk Kim 
60139a53e0cSJaegeuk Kim 	/* for cleaning operations */
60239a53e0cSJaegeuk Kim 	struct mutex gc_mutex;			/* mutex for GC */
60339a53e0cSJaegeuk Kim 	struct f2fs_gc_kthread	*gc_thread;	/* GC thread */
6045ec4e49fSJaegeuk Kim 	unsigned int cur_victim_sec;		/* current victim section num */
60539a53e0cSJaegeuk Kim 
606b1c57c1cSJaegeuk Kim 	/* maximum # of trials to find a victim segment for SSR and GC */
607b1c57c1cSJaegeuk Kim 	unsigned int max_victim_search;
608b1c57c1cSJaegeuk Kim 
60939a53e0cSJaegeuk Kim 	/*
61039a53e0cSJaegeuk Kim 	 * for stat information.
61139a53e0cSJaegeuk Kim 	 * one is for the LFS mode, and the other is for the SSR mode.
61239a53e0cSJaegeuk Kim 	 */
61335b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS
61439a53e0cSJaegeuk Kim 	struct f2fs_stat_info *stat_info;	/* FS status information */
61539a53e0cSJaegeuk Kim 	unsigned int segment_count[2];		/* # of allocated segments */
61639a53e0cSJaegeuk Kim 	unsigned int block_count[2];		/* # of allocated blocks */
617b9a2c252SChangman Lee 	atomic_t inplace_count;		/* # of inplace update */
61839a53e0cSJaegeuk Kim 	int total_hit_ext, read_hit_ext;	/* extent cache hit ratio */
61903e14d52SChao Yu 	atomic_t inline_inode;			/* # of inline_data inodes */
62003e14d52SChao Yu 	atomic_t inline_dir;			/* # of inline_dentry inodes */
62139a53e0cSJaegeuk Kim 	int bg_gc;				/* background gc calls */
62235b09d82SNamjae Jeon 	unsigned int n_dirty_dirs;		/* # of dir inodes */
62335b09d82SNamjae Jeon #endif
62435b09d82SNamjae Jeon 	unsigned int last_victim[2];		/* last victim segment # */
62539a53e0cSJaegeuk Kim 	spinlock_t stat_lock;			/* lock for stat operations */
626b59d0baeSNamjae Jeon 
627b59d0baeSNamjae Jeon 	/* For sysfs suppport */
628b59d0baeSNamjae Jeon 	struct kobject s_kobj;
629b59d0baeSNamjae Jeon 	struct completion s_kobj_unregister;
63039a53e0cSJaegeuk Kim };
63139a53e0cSJaegeuk Kim 
63239a53e0cSJaegeuk Kim /*
63339a53e0cSJaegeuk Kim  * Inline functions
63439a53e0cSJaegeuk Kim  */
63539a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
63639a53e0cSJaegeuk Kim {
63739a53e0cSJaegeuk Kim 	return container_of(inode, struct f2fs_inode_info, vfs_inode);
63839a53e0cSJaegeuk Kim }
63939a53e0cSJaegeuk Kim 
64039a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
64139a53e0cSJaegeuk Kim {
64239a53e0cSJaegeuk Kim 	return sb->s_fs_info;
64339a53e0cSJaegeuk Kim }
64439a53e0cSJaegeuk Kim 
6454081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
6464081363fSJaegeuk Kim {
6474081363fSJaegeuk Kim 	return F2FS_SB(inode->i_sb);
6484081363fSJaegeuk Kim }
6494081363fSJaegeuk Kim 
6504081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
6514081363fSJaegeuk Kim {
6524081363fSJaegeuk Kim 	return F2FS_I_SB(mapping->host);
6534081363fSJaegeuk Kim }
6544081363fSJaegeuk Kim 
6554081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
6564081363fSJaegeuk Kim {
6574081363fSJaegeuk Kim 	return F2FS_M_SB(page->mapping);
6584081363fSJaegeuk Kim }
6594081363fSJaegeuk Kim 
66039a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
66139a53e0cSJaegeuk Kim {
66239a53e0cSJaegeuk Kim 	return (struct f2fs_super_block *)(sbi->raw_super);
66339a53e0cSJaegeuk Kim }
66439a53e0cSJaegeuk Kim 
66539a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
66639a53e0cSJaegeuk Kim {
66739a53e0cSJaegeuk Kim 	return (struct f2fs_checkpoint *)(sbi->ckpt);
66839a53e0cSJaegeuk Kim }
66939a53e0cSJaegeuk Kim 
67045590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page)
67145590710SGu Zheng {
67245590710SGu Zheng 	return (struct f2fs_node *)page_address(page);
67345590710SGu Zheng }
67445590710SGu Zheng 
67558bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page)
67658bfaf44SJaegeuk Kim {
67758bfaf44SJaegeuk Kim 	return &((struct f2fs_node *)page_address(page))->i;
67858bfaf44SJaegeuk Kim }
67958bfaf44SJaegeuk Kim 
68039a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
68139a53e0cSJaegeuk Kim {
68239a53e0cSJaegeuk Kim 	return (struct f2fs_nm_info *)(sbi->nm_info);
68339a53e0cSJaegeuk Kim }
68439a53e0cSJaegeuk Kim 
68539a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
68639a53e0cSJaegeuk Kim {
68739a53e0cSJaegeuk Kim 	return (struct f2fs_sm_info *)(sbi->sm_info);
68839a53e0cSJaegeuk Kim }
68939a53e0cSJaegeuk Kim 
69039a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
69139a53e0cSJaegeuk Kim {
69239a53e0cSJaegeuk Kim 	return (struct sit_info *)(SM_I(sbi)->sit_info);
69339a53e0cSJaegeuk Kim }
69439a53e0cSJaegeuk Kim 
69539a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
69639a53e0cSJaegeuk Kim {
69739a53e0cSJaegeuk Kim 	return (struct free_segmap_info *)(SM_I(sbi)->free_info);
69839a53e0cSJaegeuk Kim }
69939a53e0cSJaegeuk Kim 
70039a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
70139a53e0cSJaegeuk Kim {
70239a53e0cSJaegeuk Kim 	return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
70339a53e0cSJaegeuk Kim }
70439a53e0cSJaegeuk Kim 
7059df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
7069df27d98SGu Zheng {
7079df27d98SGu Zheng 	return sbi->meta_inode->i_mapping;
7089df27d98SGu Zheng }
7099df27d98SGu Zheng 
7104ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
7114ef51a8fSJaegeuk Kim {
7124ef51a8fSJaegeuk Kim 	return sbi->node_inode->i_mapping;
7134ef51a8fSJaegeuk Kim }
7144ef51a8fSJaegeuk Kim 
715caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
71639a53e0cSJaegeuk Kim {
717caf0047eSChao Yu 	return sbi->s_flag & (0x01 << type);
71839a53e0cSJaegeuk Kim }
71939a53e0cSJaegeuk Kim 
720caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
72139a53e0cSJaegeuk Kim {
722caf0047eSChao Yu 	sbi->s_flag |= (0x01 << type);
723caf0047eSChao Yu }
724caf0047eSChao Yu 
725caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
726caf0047eSChao Yu {
727caf0047eSChao Yu 	sbi->s_flag &= ~(0x01 << type);
72839a53e0cSJaegeuk Kim }
72939a53e0cSJaegeuk Kim 
730d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
731d71b5564SJaegeuk Kim {
732d71b5564SJaegeuk Kim 	return le64_to_cpu(cp->checkpoint_ver);
733d71b5564SJaegeuk Kim }
734d71b5564SJaegeuk Kim 
73525ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
73625ca923bSJaegeuk Kim {
73725ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
73825ca923bSJaegeuk Kim 	return ckpt_flags & f;
73925ca923bSJaegeuk Kim }
74025ca923bSJaegeuk Kim 
74125ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
74225ca923bSJaegeuk Kim {
74325ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
74425ca923bSJaegeuk Kim 	ckpt_flags |= f;
74525ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
74625ca923bSJaegeuk Kim }
74725ca923bSJaegeuk Kim 
74825ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
74925ca923bSJaegeuk Kim {
75025ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
75125ca923bSJaegeuk Kim 	ckpt_flags &= (~f);
75225ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
75325ca923bSJaegeuk Kim }
75425ca923bSJaegeuk Kim 
755e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
75639a53e0cSJaegeuk Kim {
757e479556bSGu Zheng 	down_read(&sbi->cp_rwsem);
75839a53e0cSJaegeuk Kim }
75939a53e0cSJaegeuk Kim 
760e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
76139a53e0cSJaegeuk Kim {
762e479556bSGu Zheng 	up_read(&sbi->cp_rwsem);
76339936837SJaegeuk Kim }
76439936837SJaegeuk Kim 
765e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
76639936837SJaegeuk Kim {
7670daaad97SJaegeuk Kim 	f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex);
76839936837SJaegeuk Kim }
76939936837SJaegeuk Kim 
770e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
77139936837SJaegeuk Kim {
772e479556bSGu Zheng 	up_write(&sbi->cp_rwsem);
77339a53e0cSJaegeuk Kim }
77439a53e0cSJaegeuk Kim 
775119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
776119ee914SJaegeuk Kim {
777119ee914SJaegeuk Kim 	int reason = CP_SYNC;
778119ee914SJaegeuk Kim 
779119ee914SJaegeuk Kim 	if (test_opt(sbi, FASTBOOT))
780119ee914SJaegeuk Kim 		reason = CP_FASTBOOT;
781119ee914SJaegeuk Kim 	if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
782119ee914SJaegeuk Kim 		reason = CP_UMOUNT;
783119ee914SJaegeuk Kim 	return reason;
784119ee914SJaegeuk Kim }
785119ee914SJaegeuk Kim 
786119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason)
787119ee914SJaegeuk Kim {
788119ee914SJaegeuk Kim 	return (reason == CP_UMOUNT || reason == CP_FASTBOOT);
789119ee914SJaegeuk Kim }
790119ee914SJaegeuk Kim 
791119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
792119ee914SJaegeuk Kim {
793119ee914SJaegeuk Kim 	return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) ||
794119ee914SJaegeuk Kim 			is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG));
795119ee914SJaegeuk Kim }
796119ee914SJaegeuk Kim 
79739a53e0cSJaegeuk Kim /*
79839a53e0cSJaegeuk Kim  * Check whether the given nid is within node id range.
79939a53e0cSJaegeuk Kim  */
800064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
80139a53e0cSJaegeuk Kim {
802d6b7d4b3SChao Yu 	if (unlikely(nid < F2FS_ROOT_INO(sbi)))
803d6b7d4b3SChao Yu 		return -EINVAL;
804cfb271d4SChao Yu 	if (unlikely(nid >= NM_I(sbi)->max_nid))
805064e0823SNamjae Jeon 		return -EINVAL;
806064e0823SNamjae Jeon 	return 0;
80739a53e0cSJaegeuk Kim }
80839a53e0cSJaegeuk Kim 
80939a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS	1
81039a53e0cSJaegeuk Kim 
81139a53e0cSJaegeuk Kim /*
81239a53e0cSJaegeuk Kim  * Check whether the inode has blocks or not
81339a53e0cSJaegeuk Kim  */
81439a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode)
81539a53e0cSJaegeuk Kim {
81639a53e0cSJaegeuk Kim 	if (F2FS_I(inode)->i_xattr_nid)
8176c311ec6SChris Fries 		return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
81839a53e0cSJaegeuk Kim 	else
8196c311ec6SChris Fries 		return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
82039a53e0cSJaegeuk Kim }
82139a53e0cSJaegeuk Kim 
8224bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs)
8234bc8e9bcSChao Yu {
8244bc8e9bcSChao Yu 	return ofs == XATTR_NODE_OFFSET;
8254bc8e9bcSChao Yu }
8264bc8e9bcSChao Yu 
82739a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
82839a53e0cSJaegeuk Kim 				 struct inode *inode, blkcnt_t count)
82939a53e0cSJaegeuk Kim {
83039a53e0cSJaegeuk Kim 	block_t	valid_block_count;
83139a53e0cSJaegeuk Kim 
83239a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
83339a53e0cSJaegeuk Kim 	valid_block_count =
83439a53e0cSJaegeuk Kim 		sbi->total_valid_block_count + (block_t)count;
835cfb271d4SChao Yu 	if (unlikely(valid_block_count > sbi->user_block_count)) {
83639a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
83739a53e0cSJaegeuk Kim 		return false;
83839a53e0cSJaegeuk Kim 	}
83939a53e0cSJaegeuk Kim 	inode->i_blocks += count;
84039a53e0cSJaegeuk Kim 	sbi->total_valid_block_count = valid_block_count;
84139a53e0cSJaegeuk Kim 	sbi->alloc_valid_block_count += (block_t)count;
84239a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
84339a53e0cSJaegeuk Kim 	return true;
84439a53e0cSJaegeuk Kim }
84539a53e0cSJaegeuk Kim 
846da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
84739a53e0cSJaegeuk Kim 						struct inode *inode,
84839a53e0cSJaegeuk Kim 						blkcnt_t count)
84939a53e0cSJaegeuk Kim {
85039a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
8519850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
8529850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, inode->i_blocks < count);
85339a53e0cSJaegeuk Kim 	inode->i_blocks -= count;
85439a53e0cSJaegeuk Kim 	sbi->total_valid_block_count -= (block_t)count;
85539a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
85639a53e0cSJaegeuk Kim }
85739a53e0cSJaegeuk Kim 
85839a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
85939a53e0cSJaegeuk Kim {
86039a53e0cSJaegeuk Kim 	atomic_inc(&sbi->nr_pages[count_type]);
861caf0047eSChao Yu 	set_sbi_flag(sbi, SBI_IS_DIRTY);
86239a53e0cSJaegeuk Kim }
86339a53e0cSJaegeuk Kim 
864a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode)
86539a53e0cSJaegeuk Kim {
866a7ffdbe2SJaegeuk Kim 	atomic_inc(&F2FS_I(inode)->dirty_pages);
867a7ffdbe2SJaegeuk Kim 	if (S_ISDIR(inode->i_mode))
8684081363fSJaegeuk Kim 		inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
86939a53e0cSJaegeuk Kim }
87039a53e0cSJaegeuk Kim 
87139a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
87239a53e0cSJaegeuk Kim {
87339a53e0cSJaegeuk Kim 	atomic_dec(&sbi->nr_pages[count_type]);
87439a53e0cSJaegeuk Kim }
87539a53e0cSJaegeuk Kim 
876a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode)
87739a53e0cSJaegeuk Kim {
878a7ffdbe2SJaegeuk Kim 	if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode))
8791fe54f9dSJaegeuk Kim 		return;
8801fe54f9dSJaegeuk Kim 
881a7ffdbe2SJaegeuk Kim 	atomic_dec(&F2FS_I(inode)->dirty_pages);
882a7ffdbe2SJaegeuk Kim 
883a7ffdbe2SJaegeuk Kim 	if (S_ISDIR(inode->i_mode))
8844081363fSJaegeuk Kim 		dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
88539a53e0cSJaegeuk Kim }
88639a53e0cSJaegeuk Kim 
88739a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
88839a53e0cSJaegeuk Kim {
88939a53e0cSJaegeuk Kim 	return atomic_read(&sbi->nr_pages[count_type]);
89039a53e0cSJaegeuk Kim }
89139a53e0cSJaegeuk Kim 
892a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode)
893f8b2c1f9SJaegeuk Kim {
894a7ffdbe2SJaegeuk Kim 	return atomic_read(&F2FS_I(inode)->dirty_pages);
895f8b2c1f9SJaegeuk Kim }
896f8b2c1f9SJaegeuk Kim 
8975ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
8985ac206cfSNamjae Jeon {
8995ac206cfSNamjae Jeon 	unsigned int pages_per_sec = sbi->segs_per_sec *
9005ac206cfSNamjae Jeon 					(1 << sbi->log_blocks_per_seg);
9015ac206cfSNamjae Jeon 	return ((get_pages(sbi, block_type) + pages_per_sec - 1)
9025ac206cfSNamjae Jeon 			>> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
9035ac206cfSNamjae Jeon }
9045ac206cfSNamjae Jeon 
90539a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
90639a53e0cSJaegeuk Kim {
9078b8343faSJaegeuk Kim 	return sbi->total_valid_block_count;
90839a53e0cSJaegeuk Kim }
90939a53e0cSJaegeuk Kim 
91039a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
91139a53e0cSJaegeuk Kim {
91239a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
91339a53e0cSJaegeuk Kim 
91439a53e0cSJaegeuk Kim 	/* return NAT or SIT bitmap */
91539a53e0cSJaegeuk Kim 	if (flag == NAT_BITMAP)
91639a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
91739a53e0cSJaegeuk Kim 	else if (flag == SIT_BITMAP)
91839a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
91939a53e0cSJaegeuk Kim 
92039a53e0cSJaegeuk Kim 	return 0;
92139a53e0cSJaegeuk Kim }
92239a53e0cSJaegeuk Kim 
92339a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
92439a53e0cSJaegeuk Kim {
92539a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
9261dbe4152SChangman Lee 	int offset;
9271dbe4152SChangman Lee 
9281dbe4152SChangman Lee 	if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload) > 0) {
9291dbe4152SChangman Lee 		if (flag == NAT_BITMAP)
9301dbe4152SChangman Lee 			return &ckpt->sit_nat_version_bitmap;
9311dbe4152SChangman Lee 		else
93265b85cccSJaegeuk Kim 			return (unsigned char *)ckpt + F2FS_BLKSIZE;
9331dbe4152SChangman Lee 	} else {
9341dbe4152SChangman Lee 		offset = (flag == NAT_BITMAP) ?
93525ca923bSJaegeuk Kim 			le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
93639a53e0cSJaegeuk Kim 		return &ckpt->sit_nat_version_bitmap + offset;
93739a53e0cSJaegeuk Kim 	}
9381dbe4152SChangman Lee }
93939a53e0cSJaegeuk Kim 
94039a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
94139a53e0cSJaegeuk Kim {
94239a53e0cSJaegeuk Kim 	block_t start_addr;
94339a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
944d71b5564SJaegeuk Kim 	unsigned long long ckpt_version = cur_cp_version(ckpt);
94539a53e0cSJaegeuk Kim 
94625ca923bSJaegeuk Kim 	start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
94739a53e0cSJaegeuk Kim 
94839a53e0cSJaegeuk Kim 	/*
94939a53e0cSJaegeuk Kim 	 * odd numbered checkpoint should at cp segment 0
950e1c42045Sarter97 	 * and even segment must be at cp segment 1
95139a53e0cSJaegeuk Kim 	 */
95239a53e0cSJaegeuk Kim 	if (!(ckpt_version & 1))
95339a53e0cSJaegeuk Kim 		start_addr += sbi->blocks_per_seg;
95439a53e0cSJaegeuk Kim 
95539a53e0cSJaegeuk Kim 	return start_addr;
95639a53e0cSJaegeuk Kim }
95739a53e0cSJaegeuk Kim 
95839a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
95939a53e0cSJaegeuk Kim {
96039a53e0cSJaegeuk Kim 	return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
96139a53e0cSJaegeuk Kim }
96239a53e0cSJaegeuk Kim 
96339a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
964ef86d709SGu Zheng 						struct inode *inode)
96539a53e0cSJaegeuk Kim {
96639a53e0cSJaegeuk Kim 	block_t	valid_block_count;
96739a53e0cSJaegeuk Kim 	unsigned int valid_node_count;
96839a53e0cSJaegeuk Kim 
96939a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
97039a53e0cSJaegeuk Kim 
971ef86d709SGu Zheng 	valid_block_count = sbi->total_valid_block_count + 1;
972cfb271d4SChao Yu 	if (unlikely(valid_block_count > sbi->user_block_count)) {
97339a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
97439a53e0cSJaegeuk Kim 		return false;
97539a53e0cSJaegeuk Kim 	}
97639a53e0cSJaegeuk Kim 
977ef86d709SGu Zheng 	valid_node_count = sbi->total_valid_node_count + 1;
978cfb271d4SChao Yu 	if (unlikely(valid_node_count > sbi->total_node_count)) {
97939a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
98039a53e0cSJaegeuk Kim 		return false;
98139a53e0cSJaegeuk Kim 	}
98239a53e0cSJaegeuk Kim 
98339a53e0cSJaegeuk Kim 	if (inode)
984ef86d709SGu Zheng 		inode->i_blocks++;
985ef86d709SGu Zheng 
986ef86d709SGu Zheng 	sbi->alloc_valid_block_count++;
987ef86d709SGu Zheng 	sbi->total_valid_node_count++;
988ef86d709SGu Zheng 	sbi->total_valid_block_count++;
98939a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
99039a53e0cSJaegeuk Kim 
99139a53e0cSJaegeuk Kim 	return true;
99239a53e0cSJaegeuk Kim }
99339a53e0cSJaegeuk Kim 
99439a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
995ef86d709SGu Zheng 						struct inode *inode)
99639a53e0cSJaegeuk Kim {
99739a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
99839a53e0cSJaegeuk Kim 
9999850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_block_count);
10009850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_node_count);
10019850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !inode->i_blocks);
100239a53e0cSJaegeuk Kim 
1003ef86d709SGu Zheng 	inode->i_blocks--;
1004ef86d709SGu Zheng 	sbi->total_valid_node_count--;
1005ef86d709SGu Zheng 	sbi->total_valid_block_count--;
100639a53e0cSJaegeuk Kim 
100739a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
100839a53e0cSJaegeuk Kim }
100939a53e0cSJaegeuk Kim 
101039a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
101139a53e0cSJaegeuk Kim {
10128b8343faSJaegeuk Kim 	return sbi->total_valid_node_count;
101339a53e0cSJaegeuk Kim }
101439a53e0cSJaegeuk Kim 
101539a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
101639a53e0cSJaegeuk Kim {
101739a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
10189850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count);
101939a53e0cSJaegeuk Kim 	sbi->total_valid_inode_count++;
102039a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
102139a53e0cSJaegeuk Kim }
102239a53e0cSJaegeuk Kim 
10230e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
102439a53e0cSJaegeuk Kim {
102539a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
10269850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_inode_count);
102739a53e0cSJaegeuk Kim 	sbi->total_valid_inode_count--;
102839a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
102939a53e0cSJaegeuk Kim }
103039a53e0cSJaegeuk Kim 
103139a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
103239a53e0cSJaegeuk Kim {
10338b8343faSJaegeuk Kim 	return sbi->total_valid_inode_count;
103439a53e0cSJaegeuk Kim }
103539a53e0cSJaegeuk Kim 
103639a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock)
103739a53e0cSJaegeuk Kim {
1038031fa8ccSJaegeuk Kim 	if (!page)
103939a53e0cSJaegeuk Kim 		return;
104039a53e0cSJaegeuk Kim 
104139a53e0cSJaegeuk Kim 	if (unlock) {
10429850cf4aSJaegeuk Kim 		f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
104339a53e0cSJaegeuk Kim 		unlock_page(page);
104439a53e0cSJaegeuk Kim 	}
104539a53e0cSJaegeuk Kim 	page_cache_release(page);
104639a53e0cSJaegeuk Kim }
104739a53e0cSJaegeuk Kim 
104839a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn)
104939a53e0cSJaegeuk Kim {
105039a53e0cSJaegeuk Kim 	if (dn->node_page)
105139a53e0cSJaegeuk Kim 		f2fs_put_page(dn->node_page, 1);
105239a53e0cSJaegeuk Kim 	if (dn->inode_page && dn->node_page != dn->inode_page)
105339a53e0cSJaegeuk Kim 		f2fs_put_page(dn->inode_page, 0);
105439a53e0cSJaegeuk Kim 	dn->node_page = NULL;
105539a53e0cSJaegeuk Kim 	dn->inode_page = NULL;
105639a53e0cSJaegeuk Kim }
105739a53e0cSJaegeuk Kim 
105839a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
1059e8512d2eSGu Zheng 					size_t size)
106039a53e0cSJaegeuk Kim {
1061e8512d2eSGu Zheng 	return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
106239a53e0cSJaegeuk Kim }
106339a53e0cSJaegeuk Kim 
10647bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
10657bd59381SGu Zheng 						gfp_t flags)
10667bd59381SGu Zheng {
10677bd59381SGu Zheng 	void *entry;
10687bd59381SGu Zheng retry:
10697bd59381SGu Zheng 	entry = kmem_cache_alloc(cachep, flags);
10707bd59381SGu Zheng 	if (!entry) {
10717bd59381SGu Zheng 		cond_resched();
10727bd59381SGu Zheng 		goto retry;
10737bd59381SGu Zheng 	}
10747bd59381SGu Zheng 
10757bd59381SGu Zheng 	return entry;
10767bd59381SGu Zheng }
10777bd59381SGu Zheng 
10789be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
10799be32d72SJaegeuk Kim 				unsigned long index, void *item)
10809be32d72SJaegeuk Kim {
10819be32d72SJaegeuk Kim 	while (radix_tree_insert(root, index, item))
10829be32d72SJaegeuk Kim 		cond_resched();
10839be32d72SJaegeuk Kim }
10849be32d72SJaegeuk Kim 
108539a53e0cSJaegeuk Kim #define RAW_IS_INODE(p)	((p)->footer.nid == (p)->footer.ino)
108639a53e0cSJaegeuk Kim 
108739a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page)
108839a53e0cSJaegeuk Kim {
108945590710SGu Zheng 	struct f2fs_node *p = F2FS_NODE(page);
109039a53e0cSJaegeuk Kim 	return RAW_IS_INODE(p);
109139a53e0cSJaegeuk Kim }
109239a53e0cSJaegeuk Kim 
109339a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
109439a53e0cSJaegeuk Kim {
109539a53e0cSJaegeuk Kim 	return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
109639a53e0cSJaegeuk Kim }
109739a53e0cSJaegeuk Kim 
109839a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page,
109939a53e0cSJaegeuk Kim 		unsigned int offset)
110039a53e0cSJaegeuk Kim {
110139a53e0cSJaegeuk Kim 	struct f2fs_node *raw_node;
110239a53e0cSJaegeuk Kim 	__le32 *addr_array;
110345590710SGu Zheng 	raw_node = F2FS_NODE(node_page);
110439a53e0cSJaegeuk Kim 	addr_array = blkaddr_in_node(raw_node);
110539a53e0cSJaegeuk Kim 	return le32_to_cpu(addr_array[offset]);
110639a53e0cSJaegeuk Kim }
110739a53e0cSJaegeuk Kim 
110839a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr)
110939a53e0cSJaegeuk Kim {
111039a53e0cSJaegeuk Kim 	int mask;
111139a53e0cSJaegeuk Kim 
111239a53e0cSJaegeuk Kim 	addr += (nr >> 3);
111339a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
111439a53e0cSJaegeuk Kim 	return mask & *addr;
111539a53e0cSJaegeuk Kim }
111639a53e0cSJaegeuk Kim 
111752aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
111839a53e0cSJaegeuk Kim {
111939a53e0cSJaegeuk Kim 	int mask;
112039a53e0cSJaegeuk Kim 	int ret;
112139a53e0cSJaegeuk Kim 
112239a53e0cSJaegeuk Kim 	addr += (nr >> 3);
112339a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
112439a53e0cSJaegeuk Kim 	ret = mask & *addr;
112539a53e0cSJaegeuk Kim 	*addr |= mask;
112639a53e0cSJaegeuk Kim 	return ret;
112739a53e0cSJaegeuk Kim }
112839a53e0cSJaegeuk Kim 
112952aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
113039a53e0cSJaegeuk Kim {
113139a53e0cSJaegeuk Kim 	int mask;
113239a53e0cSJaegeuk Kim 	int ret;
113339a53e0cSJaegeuk Kim 
113439a53e0cSJaegeuk Kim 	addr += (nr >> 3);
113539a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
113639a53e0cSJaegeuk Kim 	ret = mask & *addr;
113739a53e0cSJaegeuk Kim 	*addr &= ~mask;
113839a53e0cSJaegeuk Kim 	return ret;
113939a53e0cSJaegeuk Kim }
114039a53e0cSJaegeuk Kim 
1141c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr)
1142c6ac4c0eSGu Zheng {
1143c6ac4c0eSGu Zheng 	int mask;
1144c6ac4c0eSGu Zheng 
1145c6ac4c0eSGu Zheng 	addr += (nr >> 3);
1146c6ac4c0eSGu Zheng 	mask = 1 << (7 - (nr & 0x07));
1147c6ac4c0eSGu Zheng 	*addr ^= mask;
1148c6ac4c0eSGu Zheng }
1149c6ac4c0eSGu Zheng 
115039a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */
115139a53e0cSJaegeuk Kim enum {
115239a53e0cSJaegeuk Kim 	FI_NEW_INODE,		/* indicate newly allocated inode */
1153b3783873SJaegeuk Kim 	FI_DIRTY_INODE,		/* indicate inode is dirty or not */
1154ed57c27fSJaegeuk Kim 	FI_DIRTY_DIR,		/* indicate directory has dirty pages */
115539a53e0cSJaegeuk Kim 	FI_INC_LINK,		/* need to increment i_nlink */
115639a53e0cSJaegeuk Kim 	FI_ACL_MODE,		/* indicate acl mode */
115739a53e0cSJaegeuk Kim 	FI_NO_ALLOC,		/* should not allocate any blocks */
1158699489bbSJaegeuk Kim 	FI_UPDATE_DIR,		/* should update inode block for consistency */
115974d0b917SJaegeuk Kim 	FI_DELAY_IPUT,		/* used for the recovery */
1160c11abd1aSJaegeuk Kim 	FI_NO_EXTENT,		/* not to use the extent cache */
1161444c580fSJaegeuk Kim 	FI_INLINE_XATTR,	/* used for inline xattr */
11621001b347SHuajun Li 	FI_INLINE_DATA,		/* used for inline data*/
116334d67debSChao Yu 	FI_INLINE_DENTRY,	/* used for inline dentry */
1164fff04f90SJaegeuk Kim 	FI_APPEND_WRITE,	/* inode has appended data */
1165fff04f90SJaegeuk Kim 	FI_UPDATE_WRITE,	/* inode has in-place-update data */
116688b88a66SJaegeuk Kim 	FI_NEED_IPU,		/* used for ipu per file */
116788b88a66SJaegeuk Kim 	FI_ATOMIC_FILE,		/* indicate atomic file */
116802a1335fSJaegeuk Kim 	FI_VOLATILE_FILE,	/* indicate volatile file */
11691e84371fSJaegeuk Kim 	FI_DROP_CACHE,		/* drop dirty page cache */
1170b3d208f9SJaegeuk Kim 	FI_DATA_EXIST,		/* indicate data exists */
117139a53e0cSJaegeuk Kim };
117239a53e0cSJaegeuk Kim 
117339a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
117439a53e0cSJaegeuk Kim {
117561e0f2d0SJaegeuk Kim 	if (!test_bit(flag, &fi->flags))
117639a53e0cSJaegeuk Kim 		set_bit(flag, &fi->flags);
117739a53e0cSJaegeuk Kim }
117839a53e0cSJaegeuk Kim 
117939a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
118039a53e0cSJaegeuk Kim {
118139a53e0cSJaegeuk Kim 	return test_bit(flag, &fi->flags);
118239a53e0cSJaegeuk Kim }
118339a53e0cSJaegeuk Kim 
118439a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
118539a53e0cSJaegeuk Kim {
118661e0f2d0SJaegeuk Kim 	if (test_bit(flag, &fi->flags))
118739a53e0cSJaegeuk Kim 		clear_bit(flag, &fi->flags);
118839a53e0cSJaegeuk Kim }
118939a53e0cSJaegeuk Kim 
119039a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
119139a53e0cSJaegeuk Kim {
119239a53e0cSJaegeuk Kim 	fi->i_acl_mode = mode;
119339a53e0cSJaegeuk Kim 	set_inode_flag(fi, FI_ACL_MODE);
119439a53e0cSJaegeuk Kim }
119539a53e0cSJaegeuk Kim 
1196444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi,
1197444c580fSJaegeuk Kim 					struct f2fs_inode *ri)
1198444c580fSJaegeuk Kim {
1199444c580fSJaegeuk Kim 	if (ri->i_inline & F2FS_INLINE_XATTR)
1200444c580fSJaegeuk Kim 		set_inode_flag(fi, FI_INLINE_XATTR);
12011001b347SHuajun Li 	if (ri->i_inline & F2FS_INLINE_DATA)
12021001b347SHuajun Li 		set_inode_flag(fi, FI_INLINE_DATA);
120334d67debSChao Yu 	if (ri->i_inline & F2FS_INLINE_DENTRY)
120434d67debSChao Yu 		set_inode_flag(fi, FI_INLINE_DENTRY);
1205b3d208f9SJaegeuk Kim 	if (ri->i_inline & F2FS_DATA_EXIST)
1206b3d208f9SJaegeuk Kim 		set_inode_flag(fi, FI_DATA_EXIST);
1207444c580fSJaegeuk Kim }
1208444c580fSJaegeuk Kim 
1209444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi,
1210444c580fSJaegeuk Kim 					struct f2fs_inode *ri)
1211444c580fSJaegeuk Kim {
1212444c580fSJaegeuk Kim 	ri->i_inline = 0;
1213444c580fSJaegeuk Kim 
1214444c580fSJaegeuk Kim 	if (is_inode_flag_set(fi, FI_INLINE_XATTR))
1215444c580fSJaegeuk Kim 		ri->i_inline |= F2FS_INLINE_XATTR;
12161001b347SHuajun Li 	if (is_inode_flag_set(fi, FI_INLINE_DATA))
12171001b347SHuajun Li 		ri->i_inline |= F2FS_INLINE_DATA;
121834d67debSChao Yu 	if (is_inode_flag_set(fi, FI_INLINE_DENTRY))
121934d67debSChao Yu 		ri->i_inline |= F2FS_INLINE_DENTRY;
1220b3d208f9SJaegeuk Kim 	if (is_inode_flag_set(fi, FI_DATA_EXIST))
1221b3d208f9SJaegeuk Kim 		ri->i_inline |= F2FS_DATA_EXIST;
1222444c580fSJaegeuk Kim }
1223444c580fSJaegeuk Kim 
1224987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode)
1225987c7c31SChao Yu {
1226987c7c31SChao Yu 	return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR);
1227987c7c31SChao Yu }
1228987c7c31SChao Yu 
1229de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
1230de93653fSJaegeuk Kim {
1231987c7c31SChao Yu 	if (f2fs_has_inline_xattr(&fi->vfs_inode))
1232de93653fSJaegeuk Kim 		return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
1233de93653fSJaegeuk Kim 	return DEF_ADDRS_PER_INODE;
1234de93653fSJaegeuk Kim }
1235de93653fSJaegeuk Kim 
123665985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page)
123765985d93SJaegeuk Kim {
1238695fd1edSChao Yu 	struct f2fs_inode *ri = F2FS_INODE(page);
123965985d93SJaegeuk Kim 	return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
124065985d93SJaegeuk Kim 					F2FS_INLINE_XATTR_ADDRS]);
124165985d93SJaegeuk Kim }
124265985d93SJaegeuk Kim 
124365985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode)
124465985d93SJaegeuk Kim {
1245987c7c31SChao Yu 	if (f2fs_has_inline_xattr(inode))
124665985d93SJaegeuk Kim 		return F2FS_INLINE_XATTR_ADDRS << 2;
124765985d93SJaegeuk Kim 	else
124865985d93SJaegeuk Kim 		return 0;
124965985d93SJaegeuk Kim }
125065985d93SJaegeuk Kim 
12510dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode)
12520dbdc2aeSJaegeuk Kim {
12530dbdc2aeSJaegeuk Kim 	return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
12540dbdc2aeSJaegeuk Kim }
12550dbdc2aeSJaegeuk Kim 
1256b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode)
1257b3d208f9SJaegeuk Kim {
1258b3d208f9SJaegeuk Kim 	clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
1259b3d208f9SJaegeuk Kim 	clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST);
1260b3d208f9SJaegeuk Kim }
1261b3d208f9SJaegeuk Kim 
1262b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode)
1263b3d208f9SJaegeuk Kim {
1264b3d208f9SJaegeuk Kim 	return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST);
1265b3d208f9SJaegeuk Kim }
1266b3d208f9SJaegeuk Kim 
126788b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode)
126888b88a66SJaegeuk Kim {
126988b88a66SJaegeuk Kim 	return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE);
127088b88a66SJaegeuk Kim }
127188b88a66SJaegeuk Kim 
127202a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode)
127302a1335fSJaegeuk Kim {
127402a1335fSJaegeuk Kim 	return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE);
127502a1335fSJaegeuk Kim }
127602a1335fSJaegeuk Kim 
12771e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode)
12781e84371fSJaegeuk Kim {
12791e84371fSJaegeuk Kim 	return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE);
12801e84371fSJaegeuk Kim }
12811e84371fSJaegeuk Kim 
12821001b347SHuajun Li static inline void *inline_data_addr(struct page *page)
12831001b347SHuajun Li {
1284695fd1edSChao Yu 	struct f2fs_inode *ri = F2FS_INODE(page);
12851001b347SHuajun Li 	return (void *)&(ri->i_addr[1]);
12861001b347SHuajun Li }
12871001b347SHuajun Li 
128834d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode)
128934d67debSChao Yu {
129034d67debSChao Yu 	return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY);
129134d67debSChao Yu }
129234d67debSChao Yu 
12939486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
12949486ba44SJaegeuk Kim {
12959486ba44SJaegeuk Kim 	if (!f2fs_has_inline_dentry(dir))
12969486ba44SJaegeuk Kim 		kunmap(page);
12979486ba44SJaegeuk Kim }
12989486ba44SJaegeuk Kim 
129977888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb)
130077888c1eSJaegeuk Kim {
130177888c1eSJaegeuk Kim 	return sb->s_flags & MS_RDONLY;
130277888c1eSJaegeuk Kim }
130377888c1eSJaegeuk Kim 
13041e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
13051e968fdfSJaegeuk Kim {
13061e968fdfSJaegeuk Kim 	return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
13071e968fdfSJaegeuk Kim }
13081e968fdfSJaegeuk Kim 
1309744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi)
1310744602cfSJaegeuk Kim {
1311744602cfSJaegeuk Kim 	set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1312744602cfSJaegeuk Kim 	sbi->sb->s_flags |= MS_RDONLY;
1313744602cfSJaegeuk Kim }
1314744602cfSJaegeuk Kim 
1315a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \
1316a6dda0e6SChristoph Hellwig 	((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
1317a6dda0e6SChristoph Hellwig 	 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
1318a6dda0e6SChristoph Hellwig 
1319267378d4SChao Yu /* get offset of first page in next direct node */
1320267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi)				\
1321267378d4SChao Yu 	((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) :	\
1322267378d4SChao Yu 	(pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) /	\
1323267378d4SChao Yu 	ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi))
1324267378d4SChao Yu 
132539a53e0cSJaegeuk Kim /*
132639a53e0cSJaegeuk Kim  * file.c
132739a53e0cSJaegeuk Kim  */
132839a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int);
132939a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *);
1330764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool);
133139a53e0cSJaegeuk Kim void f2fs_truncate(struct inode *);
13322d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
133339a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *);
133439a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t);
1335b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int);
133639a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long);
1337e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
133839a53e0cSJaegeuk Kim 
133939a53e0cSJaegeuk Kim /*
134039a53e0cSJaegeuk Kim  * inode.c
134139a53e0cSJaegeuk Kim  */
134239a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *);
134339a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long);
13444660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int);
134539a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *);
1346744602cfSJaegeuk Kim void update_inode_page(struct inode *);
134739a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *);
134839a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *);
134944c16156SJaegeuk Kim void handle_failed_inode(struct inode *);
135039a53e0cSJaegeuk Kim 
135139a53e0cSJaegeuk Kim /*
135239a53e0cSJaegeuk Kim  * namei.c
135339a53e0cSJaegeuk Kim  */
135439a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child);
135539a53e0cSJaegeuk Kim 
135639a53e0cSJaegeuk Kim /*
135739a53e0cSJaegeuk Kim  * dir.c
135839a53e0cSJaegeuk Kim  */
1359dbeacf02SChao Yu extern unsigned char f2fs_filetype_table[F2FS_FT_MAX];
1360dbeacf02SChao Yu void set_de_type(struct f2fs_dir_entry *, struct inode *);
13617b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *find_target_dentry(struct qstr *, int *,
13627b3cd7d6SJaegeuk Kim 			struct f2fs_dentry_ptr *);
13637b3cd7d6SJaegeuk Kim bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *,
13647b3cd7d6SJaegeuk Kim 			unsigned int);
1365062a3e7bSJaegeuk Kim void do_make_empty_dir(struct inode *, struct inode *,
1366062a3e7bSJaegeuk Kim 			struct f2fs_dentry_ptr *);
1367dbeacf02SChao Yu struct page *init_inode_metadata(struct inode *, struct inode *,
1368bce8d112SJaegeuk Kim 			const struct qstr *, struct page *);
1369dbeacf02SChao Yu void update_parent_metadata(struct inode *, struct inode *, unsigned int);
1370a82afa20SJaegeuk Kim int room_for_filename(const void *, int, int);
1371dbeacf02SChao Yu void f2fs_drop_nlink(struct inode *, struct inode *, struct page *);
137239a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
137339a53e0cSJaegeuk Kim 							struct page **);
137439a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
137539a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
137639a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
137739a53e0cSJaegeuk Kim 				struct page *, struct inode *);
13781cd14cafSJaegeuk Kim int update_dent_inode(struct inode *, const struct qstr *);
1379*3b4d732aSChao Yu void f2fs_update_dentry(struct inode *, struct f2fs_dentry_ptr *,
1380*3b4d732aSChao Yu 			const struct qstr *, f2fs_hash_t , unsigned int);
1381b7f7a5e0SAl Viro int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
1382dbeacf02SChao Yu void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *,
1383dbeacf02SChao Yu 							struct inode *);
1384b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *);
138539a53e0cSJaegeuk Kim int f2fs_make_empty(struct inode *, struct inode *);
138639a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *);
138739a53e0cSJaegeuk Kim 
1388b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
1389b7f7a5e0SAl Viro {
1390b7f7a5e0SAl Viro 	return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
1391b7f7a5e0SAl Viro 				inode);
1392b7f7a5e0SAl Viro }
1393b7f7a5e0SAl Viro 
139439a53e0cSJaegeuk Kim /*
139539a53e0cSJaegeuk Kim  * super.c
139639a53e0cSJaegeuk Kim  */
139739a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int);
1398a07ef784SNamjae Jeon extern __printf(3, 4)
1399a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...);
140039a53e0cSJaegeuk Kim 
140139a53e0cSJaegeuk Kim /*
140239a53e0cSJaegeuk Kim  * hash.c
140339a53e0cSJaegeuk Kim  */
1404eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *);
140539a53e0cSJaegeuk Kim 
140639a53e0cSJaegeuk Kim /*
140739a53e0cSJaegeuk Kim  * node.c
140839a53e0cSJaegeuk Kim  */
140939a53e0cSJaegeuk Kim struct dnode_of_data;
141039a53e0cSJaegeuk Kim struct node_info;
141139a53e0cSJaegeuk Kim 
14126fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int);
141388bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t);
141488bd02c9SJaegeuk Kim bool has_fsynced_inode(struct f2fs_sb_info *, nid_t);
141588bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t);
141639a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
141739a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
141839a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t);
14194f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *);
1420cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
142158e674d6SGu Zheng void remove_inode_page(struct inode *);
1422a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *);
14238ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
142439a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t);
142539a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
142639a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int);
142739a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *);
142839a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
142939a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *);
143039a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t);
143139a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
143270cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *);
14331c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t);
143439a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *);
143539a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int,
143639a53e0cSJaegeuk Kim 				struct f2fs_summary_block *);
143739a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *);
143839a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *);
143939a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *);
14406e6093a8SNamjae Jeon int __init create_node_manager_caches(void);
144139a53e0cSJaegeuk Kim void destroy_node_manager_caches(void);
144239a53e0cSJaegeuk Kim 
144339a53e0cSJaegeuk Kim /*
144439a53e0cSJaegeuk Kim  * segment.c
144539a53e0cSJaegeuk Kim  */
144688b88a66SJaegeuk Kim void register_inmem_page(struct inode *, struct page *);
144788b88a66SJaegeuk Kim void commit_inmem_pages(struct inode *, bool);
144839a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *);
14494660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *);
14506b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *);
14512163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *);
14522163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *);
145339a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t);
14545e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
145539a53e0cSJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *);
14564b2fecc8SJaegeuk Kim void release_discard_addrs(struct f2fs_sb_info *);
1457cf2271e7SJaegeuk Kim void discard_next_dnode(struct f2fs_sb_info *, block_t);
14583fa06d7bSChao Yu int npages_for_summary_flush(struct f2fs_sb_info *, bool);
145939a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *);
14604b2fecc8SJaegeuk Kim int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *);
146139a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
1462577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *);
1463fb5566daSJaegeuk Kim void write_node_page(struct f2fs_sb_info *, struct page *,
1464cf04e8ebSJaegeuk Kim 				unsigned int, struct f2fs_io_info *);
1465cf04e8ebSJaegeuk Kim void write_data_page(struct page *, struct dnode_of_data *,
1466458e6197SJaegeuk Kim 			struct f2fs_io_info *);
1467cf04e8ebSJaegeuk Kim void rewrite_data_page(struct page *, struct f2fs_io_info *);
146839a53e0cSJaegeuk Kim void recover_data_page(struct f2fs_sb_info *, struct page *,
146939a53e0cSJaegeuk Kim 				struct f2fs_summary *, block_t, block_t);
1470bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *,
1471bfad7c2dSJaegeuk Kim 		block_t, block_t *, struct f2fs_summary *, int);
14725514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type);
147339a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t);
147439a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t);
147539a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *,
147639a53e0cSJaegeuk Kim 					int, unsigned int, int);
14774b2fecc8SJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *);
147839a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *);
147939a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *);
14807fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void);
14817fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void);
148239a53e0cSJaegeuk Kim 
148339a53e0cSJaegeuk Kim /*
148439a53e0cSJaegeuk Kim  * checkpoint.c
148539a53e0cSJaegeuk Kim  */
148639a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
148739a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
14884c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int);
1489635aee1fSChao Yu void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t);
149039a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
1491fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
1492fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
14936f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *);
1494fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int);
1495cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *);
1496cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *);
149739a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t);
149839a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
14998f99a946SChao Yu void recover_orphan_inodes(struct f2fs_sb_info *);
150039a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *);
1501a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *);
15025deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *);
150339a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *);
150439a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *);
150575ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *);
15066451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *);
15076e6093a8SNamjae Jeon int __init create_checkpoint_caches(void);
150839a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void);
150939a53e0cSJaegeuk Kim 
151039a53e0cSJaegeuk Kim /*
151139a53e0cSJaegeuk Kim  * data.c
151239a53e0cSJaegeuk Kim  */
1513458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
1514cf04e8ebSJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *,
1515cf04e8ebSJaegeuk Kim 						struct f2fs_io_info *);
1516cf04e8ebSJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *,
1517458e6197SJaegeuk Kim 						struct f2fs_io_info *);
151839a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *);
1519b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
1520e1509cf2SJaegeuk Kim void update_extent_cache(struct dnode_of_data *);
1521c718379bSJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t, bool);
152239a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t);
152364aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
1524458e6197SJaegeuk Kim int do_write_data_page(struct page *, struct f2fs_io_info *);
15259ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
1526487261f3SChao Yu void f2fs_invalidate_page(struct page *, unsigned int, unsigned int);
1527487261f3SChao Yu int f2fs_release_page(struct page *, gfp_t);
152839a53e0cSJaegeuk Kim 
152939a53e0cSJaegeuk Kim /*
153039a53e0cSJaegeuk Kim  * gc.c
153139a53e0cSJaegeuk Kim  */
153239a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *);
153339a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *);
1534de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
1535408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *);
153639a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *);
153739a53e0cSJaegeuk Kim 
153839a53e0cSJaegeuk Kim /*
153939a53e0cSJaegeuk Kim  * recovery.c
154039a53e0cSJaegeuk Kim  */
15416ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *);
154239a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *);
154339a53e0cSJaegeuk Kim 
154439a53e0cSJaegeuk Kim /*
154539a53e0cSJaegeuk Kim  * debug.c
154639a53e0cSJaegeuk Kim  */
154739a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS
154839a53e0cSJaegeuk Kim struct f2fs_stat_info {
154939a53e0cSJaegeuk Kim 	struct list_head stat_list;
155039a53e0cSJaegeuk Kim 	struct f2fs_sb_info *sbi;
155139a53e0cSJaegeuk Kim 	int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
155239a53e0cSJaegeuk Kim 	int main_area_segs, main_area_sections, main_area_zones;
155339a53e0cSJaegeuk Kim 	int hit_ext, total_ext;
155439a53e0cSJaegeuk Kim 	int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
1555dd4e4b59SJaegeuk Kim 	int nats, dirty_nats, sits, dirty_sits, fnids;
155639a53e0cSJaegeuk Kim 	int total_count, utilization;
1557d24bdcbfSJaegeuk Kim 	int bg_gc, inline_inode, inline_dir, inmem_pages, wb_pages;
155839a53e0cSJaegeuk Kim 	unsigned int valid_count, valid_node_count, valid_inode_count;
155939a53e0cSJaegeuk Kim 	unsigned int bimodal, avg_vblocks;
156039a53e0cSJaegeuk Kim 	int util_free, util_valid, util_invalid;
156139a53e0cSJaegeuk Kim 	int rsvd_segs, overp_segs;
156239a53e0cSJaegeuk Kim 	int dirty_count, node_pages, meta_pages;
1563942e0be6SChangman Lee 	int prefree_count, call_count, cp_count;
156439a53e0cSJaegeuk Kim 	int tot_segs, node_segs, data_segs, free_segs, free_secs;
156539a53e0cSJaegeuk Kim 	int tot_blks, data_blks, node_blks;
156639a53e0cSJaegeuk Kim 	int curseg[NR_CURSEG_TYPE];
156739a53e0cSJaegeuk Kim 	int cursec[NR_CURSEG_TYPE];
156839a53e0cSJaegeuk Kim 	int curzone[NR_CURSEG_TYPE];
156939a53e0cSJaegeuk Kim 
157039a53e0cSJaegeuk Kim 	unsigned int segment_count[2];
157139a53e0cSJaegeuk Kim 	unsigned int block_count[2];
1572b9a2c252SChangman Lee 	unsigned int inplace_count;
15736f0aacbcSJaegeuk Kim 	unsigned base_mem, cache_mem, page_mem;
157439a53e0cSJaegeuk Kim };
157539a53e0cSJaegeuk Kim 
1576963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
1577963d4f7dSGu Zheng {
1578963d4f7dSGu Zheng 	return (struct f2fs_stat_info *)sbi->stat_info;
1579963d4f7dSGu Zheng }
1580963d4f7dSGu Zheng 
1581942e0be6SChangman Lee #define stat_inc_cp_count(si)		((si)->cp_count++)
158239a53e0cSJaegeuk Kim #define stat_inc_call_count(si)		((si)->call_count++)
1583dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi)	((sbi)->bg_gc++)
1584dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi)		((sbi)->n_dirty_dirs++)
1585dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi)		((sbi)->n_dirty_dirs--)
1586dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb)		((F2FS_SB(sb))->total_hit_ext++)
1587dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb)		((F2FS_SB(sb))->read_hit_ext++)
15880dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode)					\
15890dbdc2aeSJaegeuk Kim 	do {								\
15900dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
159103e14d52SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_inode));	\
15920dbdc2aeSJaegeuk Kim 	} while (0)
15930dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode)					\
15940dbdc2aeSJaegeuk Kim 	do {								\
15950dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
159603e14d52SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_inode));	\
15970dbdc2aeSJaegeuk Kim 	} while (0)
15983289c061SJaegeuk Kim #define stat_inc_inline_dir(inode)					\
15993289c061SJaegeuk Kim 	do {								\
16003289c061SJaegeuk Kim 		if (f2fs_has_inline_dentry(inode))			\
160103e14d52SChao Yu 			(atomic_inc(&F2FS_I_SB(inode)->inline_dir));	\
16023289c061SJaegeuk Kim 	} while (0)
16033289c061SJaegeuk Kim #define stat_dec_inline_dir(inode)					\
16043289c061SJaegeuk Kim 	do {								\
16053289c061SJaegeuk Kim 		if (f2fs_has_inline_dentry(inode))			\
160603e14d52SChao Yu 			(atomic_dec(&F2FS_I_SB(inode)->inline_dir));	\
16073289c061SJaegeuk Kim 	} while (0)
1608dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg)					\
1609dcdfff65SJaegeuk Kim 		((sbi)->segment_count[(curseg)->alloc_type]++)
1610dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg)				\
1611dcdfff65SJaegeuk Kim 		((sbi)->block_count[(curseg)->alloc_type]++)
1612b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi)					\
1613b9a2c252SChangman Lee 		(atomic_inc(&(sbi)->inplace_count))
161439a53e0cSJaegeuk Kim #define stat_inc_seg_count(sbi, type)					\
161539a53e0cSJaegeuk Kim 	do {								\
1616963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
161739a53e0cSJaegeuk Kim 		(si)->tot_segs++;					\
161839a53e0cSJaegeuk Kim 		if (type == SUM_TYPE_DATA)				\
161939a53e0cSJaegeuk Kim 			si->data_segs++;				\
162039a53e0cSJaegeuk Kim 		else							\
162139a53e0cSJaegeuk Kim 			si->node_segs++;				\
162239a53e0cSJaegeuk Kim 	} while (0)
162339a53e0cSJaegeuk Kim 
162439a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks)				\
162539a53e0cSJaegeuk Kim 	(si->tot_blks += (blks))
162639a53e0cSJaegeuk Kim 
162739a53e0cSJaegeuk Kim #define stat_inc_data_blk_count(sbi, blks)				\
162839a53e0cSJaegeuk Kim 	do {								\
1629963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
163039a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
163139a53e0cSJaegeuk Kim 		si->data_blks += (blks);				\
163239a53e0cSJaegeuk Kim 	} while (0)
163339a53e0cSJaegeuk Kim 
163439a53e0cSJaegeuk Kim #define stat_inc_node_blk_count(sbi, blks)				\
163539a53e0cSJaegeuk Kim 	do {								\
1636963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
163739a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
163839a53e0cSJaegeuk Kim 		si->node_blks += (blks);				\
163939a53e0cSJaegeuk Kim 	} while (0)
164039a53e0cSJaegeuk Kim 
164139a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *);
164239a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *);
16436e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void);
16444589d25dSNamjae Jeon void f2fs_destroy_root_stats(void);
164539a53e0cSJaegeuk Kim #else
1646942e0be6SChangman Lee #define stat_inc_cp_count(si)
164739a53e0cSJaegeuk Kim #define stat_inc_call_count(si)
1648dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si)
1649dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi)
1650dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi)
1651dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb)
1652dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb)
16530dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode)
16540dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode)
16553289c061SJaegeuk Kim #define stat_inc_inline_dir(inode)
16563289c061SJaegeuk Kim #define stat_dec_inline_dir(inode)
1657dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg)
1658dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg)
1659b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi)
166039a53e0cSJaegeuk Kim #define stat_inc_seg_count(si, type)
166139a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks)
166239a53e0cSJaegeuk Kim #define stat_inc_data_blk_count(si, blks)
166339a53e0cSJaegeuk Kim #define stat_inc_node_blk_count(sbi, blks)
166439a53e0cSJaegeuk Kim 
166539a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
166639a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
16676e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { }
16684589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { }
166939a53e0cSJaegeuk Kim #endif
167039a53e0cSJaegeuk Kim 
167139a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations;
167239a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations;
167339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations;
167439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops;
167539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops;
167639a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops;
167739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations;
167839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations;
167939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations;
168029e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab;
16811001b347SHuajun Li 
1682e18c65b2SHuajun Li /*
1683e18c65b2SHuajun Li  * inline.c
1684e18c65b2SHuajun Li  */
1685e18c65b2SHuajun Li bool f2fs_may_inline(struct inode *);
1686b3d208f9SJaegeuk Kim void read_inline_data(struct page *, struct page *);
1687e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *);
1688b3d208f9SJaegeuk Kim int f2fs_convert_inline_page(struct dnode_of_data *, struct page *);
1689b3d208f9SJaegeuk Kim int f2fs_convert_inline_inode(struct inode *);
1690b3d208f9SJaegeuk Kim int f2fs_write_inline_data(struct inode *, struct page *);
16910342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *);
1692201a05beSChao Yu struct f2fs_dir_entry *find_in_inline_dir(struct inode *, struct qstr *,
1693201a05beSChao Yu 							struct page **);
1694201a05beSChao Yu struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **);
1695201a05beSChao Yu int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *);
1696201a05beSChao Yu int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *);
1697201a05beSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *,
1698201a05beSChao Yu 						struct inode *, struct inode *);
1699201a05beSChao Yu bool f2fs_empty_inline_dir(struct inode *);
1700201a05beSChao Yu int f2fs_read_inline_dir(struct file *, struct dir_context *);
170139a53e0cSJaegeuk Kim #endif
1702