xref: /openbmc/linux/fs/f2fs/f2fs.h (revision 1fe54f9dd3acfaa3ed4e1d1e3278fd0f1d1e98cd)
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
245d56b671SJaegeuk Kim #define f2fs_bug_on(condition)	BUG_ON(condition)
250daaad97SJaegeuk Kim #define f2fs_down_write(x, y)	down_write_nest_lock(x, y)
265d56b671SJaegeuk Kim #else
275d56b671SJaegeuk Kim #define f2fs_bug_on(condition)
280daaad97SJaegeuk Kim #define f2fs_down_write(x, y)	down_write(x)
295d56b671SJaegeuk Kim #endif
305d56b671SJaegeuk Kim 
3139a53e0cSJaegeuk Kim /*
3239a53e0cSJaegeuk Kim  * For mount options
3339a53e0cSJaegeuk Kim  */
3439a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC		0x00000001
3539a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD	0x00000002
3639a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD		0x00000004
3739a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP		0x00000008
3839a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER		0x00000010
3939a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL		0x00000020
4039a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY	0x00000040
41444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR		0x00000080
421001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA		0x00000100
4339a53e0cSJaegeuk Kim 
4439a53e0cSJaegeuk Kim #define clear_opt(sbi, option)	(sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
4539a53e0cSJaegeuk Kim #define set_opt(sbi, option)	(sbi->mount_opt.opt |= F2FS_MOUNT_##option)
4639a53e0cSJaegeuk Kim #define test_opt(sbi, option)	(sbi->mount_opt.opt & F2FS_MOUNT_##option)
4739a53e0cSJaegeuk Kim 
4839a53e0cSJaegeuk Kim #define ver_after(a, b)	(typecheck(unsigned long long, a) &&		\
4939a53e0cSJaegeuk Kim 		typecheck(unsigned long long, b) &&			\
5039a53e0cSJaegeuk Kim 		((long long)((a) - (b)) > 0))
5139a53e0cSJaegeuk Kim 
52a9841c4dSJaegeuk Kim typedef u32 block_t;	/*
53a9841c4dSJaegeuk Kim 			 * should not change u32, since it is the on-disk block
54a9841c4dSJaegeuk Kim 			 * address format, __le32.
55a9841c4dSJaegeuk Kim 			 */
5639a53e0cSJaegeuk Kim typedef u32 nid_t;
5739a53e0cSJaegeuk Kim 
5839a53e0cSJaegeuk Kim struct f2fs_mount_info {
5939a53e0cSJaegeuk Kim 	unsigned int	opt;
6039a53e0cSJaegeuk Kim };
6139a53e0cSJaegeuk Kim 
627e586fa0SJaegeuk Kim #define CRCPOLY_LE 0xedb88320
637e586fa0SJaegeuk Kim 
647e586fa0SJaegeuk Kim static inline __u32 f2fs_crc32(void *buf, size_t len)
6539a53e0cSJaegeuk Kim {
667e586fa0SJaegeuk Kim 	unsigned char *p = (unsigned char *)buf;
677e586fa0SJaegeuk Kim 	__u32 crc = F2FS_SUPER_MAGIC;
687e586fa0SJaegeuk Kim 	int i;
697e586fa0SJaegeuk Kim 
707e586fa0SJaegeuk Kim 	while (len--) {
717e586fa0SJaegeuk Kim 		crc ^= *p++;
727e586fa0SJaegeuk Kim 		for (i = 0; i < 8; i++)
737e586fa0SJaegeuk Kim 			crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
747e586fa0SJaegeuk Kim 	}
757e586fa0SJaegeuk Kim 	return crc;
7639a53e0cSJaegeuk Kim }
7739a53e0cSJaegeuk Kim 
787e586fa0SJaegeuk Kim static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
7939a53e0cSJaegeuk Kim {
807e586fa0SJaegeuk Kim 	return f2fs_crc32(buf, buf_size) == blk_crc;
8139a53e0cSJaegeuk Kim }
8239a53e0cSJaegeuk Kim 
8339a53e0cSJaegeuk Kim /*
8439a53e0cSJaegeuk Kim  * For checkpoint manager
8539a53e0cSJaegeuk Kim  */
8639a53e0cSJaegeuk Kim enum {
8739a53e0cSJaegeuk Kim 	NAT_BITMAP,
8839a53e0cSJaegeuk Kim 	SIT_BITMAP
8939a53e0cSJaegeuk Kim };
9039a53e0cSJaegeuk Kim 
9139a53e0cSJaegeuk Kim /* for the list of orphan inodes */
9239a53e0cSJaegeuk Kim struct orphan_inode_entry {
9339a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
9439a53e0cSJaegeuk Kim 	nid_t ino;		/* inode number */
9539a53e0cSJaegeuk Kim };
9639a53e0cSJaegeuk Kim 
9739a53e0cSJaegeuk Kim /* for the list of directory inodes */
9839a53e0cSJaegeuk Kim struct dir_inode_entry {
9939a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
10039a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
10139a53e0cSJaegeuk Kim };
10239a53e0cSJaegeuk Kim 
1037fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */
1047fd9e544SJaegeuk Kim struct discard_entry {
1057fd9e544SJaegeuk Kim 	struct list_head list;	/* list head */
1067fd9e544SJaegeuk Kim 	block_t blkaddr;	/* block address to be discarded */
1077fd9e544SJaegeuk Kim 	int len;		/* # of consecutive blocks of the discard */
1087fd9e544SJaegeuk Kim };
1097fd9e544SJaegeuk Kim 
11039a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */
11139a53e0cSJaegeuk Kim struct fsync_inode_entry {
11239a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
11339a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
11439a53e0cSJaegeuk Kim 	block_t blkaddr;	/* block address locating the last inode */
11539a53e0cSJaegeuk Kim };
11639a53e0cSJaegeuk Kim 
11739a53e0cSJaegeuk Kim #define nats_in_cursum(sum)		(le16_to_cpu(sum->n_nats))
11839a53e0cSJaegeuk Kim #define sits_in_cursum(sum)		(le16_to_cpu(sum->n_sits))
11939a53e0cSJaegeuk Kim 
12039a53e0cSJaegeuk Kim #define nat_in_journal(sum, i)		(sum->nat_j.entries[i].ne)
12139a53e0cSJaegeuk Kim #define nid_in_journal(sum, i)		(sum->nat_j.entries[i].nid)
12239a53e0cSJaegeuk Kim #define sit_in_journal(sum, i)		(sum->sit_j.entries[i].se)
12339a53e0cSJaegeuk Kim #define segno_in_journal(sum, i)	(sum->sit_j.entries[i].segno)
12439a53e0cSJaegeuk Kim 
12539a53e0cSJaegeuk Kim static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
12639a53e0cSJaegeuk Kim {
12739a53e0cSJaegeuk Kim 	int before = nats_in_cursum(rs);
12839a53e0cSJaegeuk Kim 	rs->n_nats = cpu_to_le16(before + i);
12939a53e0cSJaegeuk Kim 	return before;
13039a53e0cSJaegeuk Kim }
13139a53e0cSJaegeuk Kim 
13239a53e0cSJaegeuk Kim static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
13339a53e0cSJaegeuk Kim {
13439a53e0cSJaegeuk Kim 	int before = sits_in_cursum(rs);
13539a53e0cSJaegeuk Kim 	rs->n_sits = cpu_to_le16(before + i);
13639a53e0cSJaegeuk Kim 	return before;
13739a53e0cSJaegeuk Kim }
13839a53e0cSJaegeuk Kim 
13939a53e0cSJaegeuk Kim /*
140e9750824SNamjae Jeon  * ioctl commands
141e9750824SNamjae Jeon  */
142e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS               FS_IOC_GETFLAGS
143e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS               FS_IOC_SETFLAGS
144e9750824SNamjae Jeon 
145e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
146e9750824SNamjae Jeon /*
147e9750824SNamjae Jeon  * ioctl commands in 32 bit emulation
148e9750824SNamjae Jeon  */
149e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS             FS_IOC32_GETFLAGS
150e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS             FS_IOC32_SETFLAGS
151e9750824SNamjae Jeon #endif
152e9750824SNamjae Jeon 
153e9750824SNamjae Jeon /*
15439a53e0cSJaegeuk Kim  * For INODE and NODE manager
15539a53e0cSJaegeuk Kim  */
156dbe6a5ffSJaegeuk Kim /*
157dbe6a5ffSJaegeuk Kim  * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
158dbe6a5ffSJaegeuk Kim  * as its node offset to distinguish from index node blocks.
159dbe6a5ffSJaegeuk Kim  * But some bits are used to mark the node block.
16039a53e0cSJaegeuk Kim  */
161dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET	((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
162dbe6a5ffSJaegeuk Kim 				>> OFFSET_BIT_SHIFT)
163266e97a8SJaegeuk Kim enum {
164266e97a8SJaegeuk Kim 	ALLOC_NODE,			/* allocate a new node page if needed */
165266e97a8SJaegeuk Kim 	LOOKUP_NODE,			/* look up a node without readahead */
166266e97a8SJaegeuk Kim 	LOOKUP_NODE_RA,			/*
167266e97a8SJaegeuk Kim 					 * look up a node with readahead called
1684f4124d0SChao Yu 					 * by get_data_block.
16939a53e0cSJaegeuk Kim 					 */
170266e97a8SJaegeuk Kim };
171266e97a8SJaegeuk Kim 
17239a53e0cSJaegeuk Kim #define F2FS_LINK_MAX		32000	/* maximum link count per file */
17339a53e0cSJaegeuk Kim 
17439a53e0cSJaegeuk Kim /* for in-memory extent cache entry */
175c11abd1aSJaegeuk Kim #define F2FS_MIN_EXTENT_LEN	16	/* minimum extent length */
176c11abd1aSJaegeuk Kim 
17739a53e0cSJaegeuk Kim struct extent_info {
17839a53e0cSJaegeuk Kim 	rwlock_t ext_lock;	/* rwlock for consistency */
17939a53e0cSJaegeuk Kim 	unsigned int fofs;	/* start offset in a file */
18039a53e0cSJaegeuk Kim 	u32 blk_addr;		/* start block address of the extent */
181111d2495SMasanari Iida 	unsigned int len;	/* length of the extent */
18239a53e0cSJaegeuk Kim };
18339a53e0cSJaegeuk Kim 
18439a53e0cSJaegeuk Kim /*
18539a53e0cSJaegeuk Kim  * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
18639a53e0cSJaegeuk Kim  */
18739a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT	0x01
188354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT	0x02
18939a53e0cSJaegeuk Kim 
19039a53e0cSJaegeuk Kim struct f2fs_inode_info {
19139a53e0cSJaegeuk Kim 	struct inode vfs_inode;		/* serve a vfs inode */
19239a53e0cSJaegeuk Kim 	unsigned long i_flags;		/* keep an inode flags for ioctl */
19339a53e0cSJaegeuk Kim 	unsigned char i_advise;		/* use to give file attribute hints */
19439a53e0cSJaegeuk Kim 	unsigned int i_current_depth;	/* use only in directory structure */
1956666e6aaSJaegeuk Kim 	unsigned int i_pino;		/* parent inode number */
19639a53e0cSJaegeuk Kim 	umode_t i_acl_mode;		/* keep file acl mode temporarily */
19739a53e0cSJaegeuk Kim 
19839a53e0cSJaegeuk Kim 	/* Use below internally in f2fs*/
19939a53e0cSJaegeuk Kim 	unsigned long flags;		/* use to pass per-file flags */
20039a53e0cSJaegeuk Kim 	atomic_t dirty_dents;		/* # of dirty dentry pages */
20139a53e0cSJaegeuk Kim 	f2fs_hash_t chash;		/* hash value of given file name */
20239a53e0cSJaegeuk Kim 	unsigned int clevel;		/* maximum level of given file name */
20339a53e0cSJaegeuk Kim 	nid_t i_xattr_nid;		/* node id that contains xattrs */
204e518ff81SJaegeuk Kim 	unsigned long long xattr_ver;	/* cp version of xattr modification */
20539a53e0cSJaegeuk Kim 	struct extent_info ext;		/* in-memory extent cache entry */
20639a53e0cSJaegeuk Kim };
20739a53e0cSJaegeuk Kim 
20839a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext,
20939a53e0cSJaegeuk Kim 					struct f2fs_extent i_ext)
21039a53e0cSJaegeuk Kim {
21139a53e0cSJaegeuk Kim 	write_lock(&ext->ext_lock);
21239a53e0cSJaegeuk Kim 	ext->fofs = le32_to_cpu(i_ext.fofs);
21339a53e0cSJaegeuk Kim 	ext->blk_addr = le32_to_cpu(i_ext.blk_addr);
21439a53e0cSJaegeuk Kim 	ext->len = le32_to_cpu(i_ext.len);
21539a53e0cSJaegeuk Kim 	write_unlock(&ext->ext_lock);
21639a53e0cSJaegeuk Kim }
21739a53e0cSJaegeuk Kim 
21839a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext,
21939a53e0cSJaegeuk Kim 					struct f2fs_extent *i_ext)
22039a53e0cSJaegeuk Kim {
22139a53e0cSJaegeuk Kim 	read_lock(&ext->ext_lock);
22239a53e0cSJaegeuk Kim 	i_ext->fofs = cpu_to_le32(ext->fofs);
22339a53e0cSJaegeuk Kim 	i_ext->blk_addr = cpu_to_le32(ext->blk_addr);
22439a53e0cSJaegeuk Kim 	i_ext->len = cpu_to_le32(ext->len);
22539a53e0cSJaegeuk Kim 	read_unlock(&ext->ext_lock);
22639a53e0cSJaegeuk Kim }
22739a53e0cSJaegeuk Kim 
22839a53e0cSJaegeuk Kim struct f2fs_nm_info {
22939a53e0cSJaegeuk Kim 	block_t nat_blkaddr;		/* base disk address of NAT */
23039a53e0cSJaegeuk Kim 	nid_t max_nid;			/* maximum possible node ids */
23139a53e0cSJaegeuk Kim 	nid_t next_scan_nid;		/* the next nid to be scanned */
23239a53e0cSJaegeuk Kim 
23339a53e0cSJaegeuk Kim 	/* NAT cache management */
23439a53e0cSJaegeuk Kim 	struct radix_tree_root nat_root;/* root of the nat entry cache */
23539a53e0cSJaegeuk Kim 	rwlock_t nat_tree_lock;		/* protect nat_tree_lock */
23639a53e0cSJaegeuk Kim 	unsigned int nat_cnt;		/* the # of cached nat entries */
23739a53e0cSJaegeuk Kim 	struct list_head nat_entries;	/* cached nat entry list (clean) */
23839a53e0cSJaegeuk Kim 	struct list_head dirty_nat_entries; /* cached nat entry list (dirty) */
23939a53e0cSJaegeuk Kim 
24039a53e0cSJaegeuk Kim 	/* free node ids management */
24139a53e0cSJaegeuk Kim 	struct list_head free_nid_list;	/* a list for free nids */
24239a53e0cSJaegeuk Kim 	spinlock_t free_nid_list_lock;	/* protect free nid list */
24339a53e0cSJaegeuk Kim 	unsigned int fcnt;		/* the number of free node id */
24439a53e0cSJaegeuk Kim 	struct mutex build_lock;	/* lock for build free nids */
24539a53e0cSJaegeuk Kim 
24639a53e0cSJaegeuk Kim 	/* for checkpoint */
24739a53e0cSJaegeuk Kim 	char *nat_bitmap;		/* NAT bitmap pointer */
24839a53e0cSJaegeuk Kim 	int bitmap_size;		/* bitmap size */
24939a53e0cSJaegeuk Kim };
25039a53e0cSJaegeuk Kim 
25139a53e0cSJaegeuk Kim /*
25239a53e0cSJaegeuk Kim  * this structure is used as one of function parameters.
25339a53e0cSJaegeuk Kim  * all the information are dedicated to a given direct node block determined
25439a53e0cSJaegeuk Kim  * by the data offset in a file.
25539a53e0cSJaegeuk Kim  */
25639a53e0cSJaegeuk Kim struct dnode_of_data {
25739a53e0cSJaegeuk Kim 	struct inode *inode;		/* vfs inode pointer */
25839a53e0cSJaegeuk Kim 	struct page *inode_page;	/* its inode page, NULL is possible */
25939a53e0cSJaegeuk Kim 	struct page *node_page;		/* cached direct node page */
26039a53e0cSJaegeuk Kim 	nid_t nid;			/* node id of the direct node block */
26139a53e0cSJaegeuk Kim 	unsigned int ofs_in_node;	/* data offset in the node page */
26239a53e0cSJaegeuk Kim 	bool inode_page_locked;		/* inode page is locked or not */
26339a53e0cSJaegeuk Kim 	block_t	data_blkaddr;		/* block address of the node block */
26439a53e0cSJaegeuk Kim };
26539a53e0cSJaegeuk Kim 
26639a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
26739a53e0cSJaegeuk Kim 		struct page *ipage, struct page *npage, nid_t nid)
26839a53e0cSJaegeuk Kim {
269d66d1f76SJaegeuk Kim 	memset(dn, 0, sizeof(*dn));
27039a53e0cSJaegeuk Kim 	dn->inode = inode;
27139a53e0cSJaegeuk Kim 	dn->inode_page = ipage;
27239a53e0cSJaegeuk Kim 	dn->node_page = npage;
27339a53e0cSJaegeuk Kim 	dn->nid = nid;
27439a53e0cSJaegeuk Kim }
27539a53e0cSJaegeuk Kim 
27639a53e0cSJaegeuk Kim /*
27739a53e0cSJaegeuk Kim  * For SIT manager
27839a53e0cSJaegeuk Kim  *
27939a53e0cSJaegeuk Kim  * By default, there are 6 active log areas across the whole main area.
28039a53e0cSJaegeuk Kim  * When considering hot and cold data separation to reduce cleaning overhead,
28139a53e0cSJaegeuk Kim  * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
28239a53e0cSJaegeuk Kim  * respectively.
28339a53e0cSJaegeuk Kim  * In the current design, you should not change the numbers intentionally.
28439a53e0cSJaegeuk Kim  * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
28539a53e0cSJaegeuk Kim  * logs individually according to the underlying devices. (default: 6)
28639a53e0cSJaegeuk Kim  * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
28739a53e0cSJaegeuk Kim  * data and 8 for node logs.
28839a53e0cSJaegeuk Kim  */
28939a53e0cSJaegeuk Kim #define	NR_CURSEG_DATA_TYPE	(3)
29039a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE	(3)
29139a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
29239a53e0cSJaegeuk Kim 
29339a53e0cSJaegeuk Kim enum {
29439a53e0cSJaegeuk Kim 	CURSEG_HOT_DATA	= 0,	/* directory entry blocks */
29539a53e0cSJaegeuk Kim 	CURSEG_WARM_DATA,	/* data blocks */
29639a53e0cSJaegeuk Kim 	CURSEG_COLD_DATA,	/* multimedia or GCed data blocks */
29739a53e0cSJaegeuk Kim 	CURSEG_HOT_NODE,	/* direct node blocks of directory files */
29839a53e0cSJaegeuk Kim 	CURSEG_WARM_NODE,	/* direct node blocks of normal files */
29939a53e0cSJaegeuk Kim 	CURSEG_COLD_NODE,	/* indirect node blocks */
30039a53e0cSJaegeuk Kim 	NO_CHECK_TYPE
30139a53e0cSJaegeuk Kim };
30239a53e0cSJaegeuk Kim 
30339a53e0cSJaegeuk Kim struct f2fs_sm_info {
30439a53e0cSJaegeuk Kim 	struct sit_info *sit_info;		/* whole segment information */
30539a53e0cSJaegeuk Kim 	struct free_segmap_info *free_info;	/* free segment information */
30639a53e0cSJaegeuk Kim 	struct dirty_seglist_info *dirty_info;	/* dirty segment information */
30739a53e0cSJaegeuk Kim 	struct curseg_info *curseg_array;	/* active segment information */
30839a53e0cSJaegeuk Kim 
30939a53e0cSJaegeuk Kim 	struct list_head wblist_head;	/* list of under-writeback pages */
31039a53e0cSJaegeuk Kim 	spinlock_t wblist_lock;		/* lock for checkpoint */
31139a53e0cSJaegeuk Kim 
31239a53e0cSJaegeuk Kim 	block_t seg0_blkaddr;		/* block address of 0'th segment */
31339a53e0cSJaegeuk Kim 	block_t main_blkaddr;		/* start block address of main area */
31439a53e0cSJaegeuk Kim 	block_t ssa_blkaddr;		/* start block address of SSA area */
31539a53e0cSJaegeuk Kim 
31639a53e0cSJaegeuk Kim 	unsigned int segment_count;	/* total # of segments */
31739a53e0cSJaegeuk Kim 	unsigned int main_segments;	/* # of segments in main area */
31839a53e0cSJaegeuk Kim 	unsigned int reserved_segments;	/* # of reserved segments */
31939a53e0cSJaegeuk Kim 	unsigned int ovp_segments;	/* # of overprovision segments */
32081eb8d6eSJaegeuk Kim 
32181eb8d6eSJaegeuk Kim 	/* a threshold to reclaim prefree segments */
32281eb8d6eSJaegeuk Kim 	unsigned int rec_prefree_segments;
3237fd9e544SJaegeuk Kim 
3247fd9e544SJaegeuk Kim 	/* for small discard management */
3257fd9e544SJaegeuk Kim 	struct list_head discard_list;		/* 4KB discard list */
3267fd9e544SJaegeuk Kim 	int nr_discards;			/* # of discards in the list */
3277fd9e544SJaegeuk Kim 	int max_discards;			/* max. discards to be issued */
328216fbd64SJaegeuk Kim 
329216fbd64SJaegeuk Kim 	unsigned int ipu_policy;	/* in-place-update policy */
330216fbd64SJaegeuk Kim 	unsigned int min_ipu_util;	/* in-place-update threshold */
33139a53e0cSJaegeuk Kim };
33239a53e0cSJaegeuk Kim 
33339a53e0cSJaegeuk Kim /*
33439a53e0cSJaegeuk Kim  * For superblock
33539a53e0cSJaegeuk Kim  */
33639a53e0cSJaegeuk Kim /*
33739a53e0cSJaegeuk Kim  * COUNT_TYPE for monitoring
33839a53e0cSJaegeuk Kim  *
33939a53e0cSJaegeuk Kim  * f2fs monitors the number of several block types such as on-writeback,
34039a53e0cSJaegeuk Kim  * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
34139a53e0cSJaegeuk Kim  */
34239a53e0cSJaegeuk Kim enum count_type {
34339a53e0cSJaegeuk Kim 	F2FS_WRITEBACK,
34439a53e0cSJaegeuk Kim 	F2FS_DIRTY_DENTS,
34539a53e0cSJaegeuk Kim 	F2FS_DIRTY_NODES,
34639a53e0cSJaegeuk Kim 	F2FS_DIRTY_META,
34739a53e0cSJaegeuk Kim 	NR_COUNT_TYPE,
34839a53e0cSJaegeuk Kim };
34939a53e0cSJaegeuk Kim 
35039a53e0cSJaegeuk Kim /*
35139a53e0cSJaegeuk Kim  * The below are the page types of bios used in submti_bio().
35239a53e0cSJaegeuk Kim  * The available types are:
35339a53e0cSJaegeuk Kim  * DATA			User data pages. It operates as async mode.
35439a53e0cSJaegeuk Kim  * NODE			Node pages. It operates as async mode.
35539a53e0cSJaegeuk Kim  * META			FS metadata pages such as SIT, NAT, CP.
35639a53e0cSJaegeuk Kim  * NR_PAGE_TYPE		The number of page types.
35739a53e0cSJaegeuk Kim  * META_FLUSH		Make sure the previous pages are written
35839a53e0cSJaegeuk Kim  *			with waiting the bio's completion
35939a53e0cSJaegeuk Kim  * ...			Only can be used with META.
36039a53e0cSJaegeuk Kim  */
3617d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type)	((type) > META ? META : (type))
36239a53e0cSJaegeuk Kim enum page_type {
36339a53e0cSJaegeuk Kim 	DATA,
36439a53e0cSJaegeuk Kim 	NODE,
36539a53e0cSJaegeuk Kim 	META,
36639a53e0cSJaegeuk Kim 	NR_PAGE_TYPE,
36739a53e0cSJaegeuk Kim 	META_FLUSH,
36839a53e0cSJaegeuk Kim };
36939a53e0cSJaegeuk Kim 
370458e6197SJaegeuk Kim struct f2fs_io_info {
371458e6197SJaegeuk Kim 	enum page_type type;	/* contains DATA/NODE/META/META_FLUSH */
3727e8f2308SGu Zheng 	int rw;			/* contains R/RS/W/WS with REQ_META/REQ_PRIO */
373458e6197SJaegeuk Kim };
374458e6197SJaegeuk Kim 
37593dfe2acSJaegeuk Kim #define is_read_io(rw)	(((rw) & 1) == READ)
3761ff7bd3bSJaegeuk Kim struct f2fs_bio_info {
377458e6197SJaegeuk Kim 	struct f2fs_sb_info *sbi;	/* f2fs superblock */
3781ff7bd3bSJaegeuk Kim 	struct bio *bio;		/* bios to merge */
3791ff7bd3bSJaegeuk Kim 	sector_t last_block_in_bio;	/* last block number */
380458e6197SJaegeuk Kim 	struct f2fs_io_info fio;	/* store buffered io info. */
3811ff7bd3bSJaegeuk Kim 	struct mutex io_mutex;		/* mutex for bio */
3821ff7bd3bSJaegeuk Kim };
3831ff7bd3bSJaegeuk Kim 
38439a53e0cSJaegeuk Kim struct f2fs_sb_info {
38539a53e0cSJaegeuk Kim 	struct super_block *sb;			/* pointer to VFS super block */
3865e176d54SJaegeuk Kim 	struct proc_dir_entry *s_proc;		/* proc entry */
38739a53e0cSJaegeuk Kim 	struct buffer_head *raw_super_buf;	/* buffer head of raw sb */
38839a53e0cSJaegeuk Kim 	struct f2fs_super_block *raw_super;	/* raw super block pointer */
38939a53e0cSJaegeuk Kim 	int s_dirty;				/* dirty flag for checkpoint */
39039a53e0cSJaegeuk Kim 
39139a53e0cSJaegeuk Kim 	/* for node-related operations */
39239a53e0cSJaegeuk Kim 	struct f2fs_nm_info *nm_info;		/* node manager */
39339a53e0cSJaegeuk Kim 	struct inode *node_inode;		/* cache node blocks */
39439a53e0cSJaegeuk Kim 
39539a53e0cSJaegeuk Kim 	/* for segment-related operations */
39639a53e0cSJaegeuk Kim 	struct f2fs_sm_info *sm_info;		/* segment manager */
3971ff7bd3bSJaegeuk Kim 
3981ff7bd3bSJaegeuk Kim 	/* for bio operations */
399924b720bSChao Yu 	struct f2fs_bio_info read_io;			/* for read bios */
4001ff7bd3bSJaegeuk Kim 	struct f2fs_bio_info write_io[NR_PAGE_TYPE];	/* for write bios */
4011b1f559fSJaegeuk Kim 	struct completion *wait_io;		/* for completion bios */
40239a53e0cSJaegeuk Kim 
40339a53e0cSJaegeuk Kim 	/* for checkpoint */
40439a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
40539a53e0cSJaegeuk Kim 	struct inode *meta_inode;		/* cache meta blocks */
40639936837SJaegeuk Kim 	struct mutex cp_mutex;			/* checkpoint procedure lock */
407e479556bSGu Zheng 	struct rw_semaphore cp_rwsem;		/* blocking FS operations */
40839936837SJaegeuk Kim 	struct mutex node_write;		/* locking node writes */
40939a53e0cSJaegeuk Kim 	struct mutex writepages;		/* mutex for writepages() */
410aabe5136SHaicheng Li 	bool por_doing;				/* recovery is doing or not */
411aabe5136SHaicheng Li 	bool on_build_free_nids;		/* build_free_nids is doing */
412fb51b5efSChangman Lee 	wait_queue_head_t cp_wait;
41339a53e0cSJaegeuk Kim 
41439a53e0cSJaegeuk Kim 	/* for orphan inode management */
41539a53e0cSJaegeuk Kim 	struct list_head orphan_inode_list;	/* orphan inode list */
41617b692f6SGu Zheng 	spinlock_t orphan_inode_lock;		/* for orphan inode list */
41739a53e0cSJaegeuk Kim 	unsigned int n_orphans;			/* # of orphan inodes */
4180d47c1adSGu Zheng 	unsigned int max_orphans;		/* max orphan inodes */
41939a53e0cSJaegeuk Kim 
42039a53e0cSJaegeuk Kim 	/* for directory inode management */
42139a53e0cSJaegeuk Kim 	struct list_head dir_inode_list;	/* dir inode list */
42239a53e0cSJaegeuk Kim 	spinlock_t dir_inode_lock;		/* for dir inode list lock */
42339a53e0cSJaegeuk Kim 
42439a53e0cSJaegeuk Kim 	/* basic file system units */
42539a53e0cSJaegeuk Kim 	unsigned int log_sectors_per_block;	/* log2 sectors per block */
42639a53e0cSJaegeuk Kim 	unsigned int log_blocksize;		/* log2 block size */
42739a53e0cSJaegeuk Kim 	unsigned int blocksize;			/* block size */
42839a53e0cSJaegeuk Kim 	unsigned int root_ino_num;		/* root inode number*/
42939a53e0cSJaegeuk Kim 	unsigned int node_ino_num;		/* node inode number*/
43039a53e0cSJaegeuk Kim 	unsigned int meta_ino_num;		/* meta inode number*/
43139a53e0cSJaegeuk Kim 	unsigned int log_blocks_per_seg;	/* log2 blocks per segment */
43239a53e0cSJaegeuk Kim 	unsigned int blocks_per_seg;		/* blocks per segment */
43339a53e0cSJaegeuk Kim 	unsigned int segs_per_sec;		/* segments per section */
43439a53e0cSJaegeuk Kim 	unsigned int secs_per_zone;		/* sections per zone */
43539a53e0cSJaegeuk Kim 	unsigned int total_sections;		/* total section count */
43639a53e0cSJaegeuk Kim 	unsigned int total_node_count;		/* total node block count */
43739a53e0cSJaegeuk Kim 	unsigned int total_valid_node_count;	/* valid node block count */
43839a53e0cSJaegeuk Kim 	unsigned int total_valid_inode_count;	/* valid inode count */
43939a53e0cSJaegeuk Kim 	int active_logs;			/* # of active logs */
44039a53e0cSJaegeuk Kim 
44139a53e0cSJaegeuk Kim 	block_t user_block_count;		/* # of user blocks */
44239a53e0cSJaegeuk Kim 	block_t total_valid_block_count;	/* # of valid blocks */
44339a53e0cSJaegeuk Kim 	block_t alloc_valid_block_count;	/* # of allocated blocks */
44439a53e0cSJaegeuk Kim 	block_t last_valid_block_count;		/* for recovery */
44539a53e0cSJaegeuk Kim 	u32 s_next_generation;			/* for NFS support */
44639a53e0cSJaegeuk Kim 	atomic_t nr_pages[NR_COUNT_TYPE];	/* # of pages, see count_type */
44739a53e0cSJaegeuk Kim 
44839a53e0cSJaegeuk Kim 	struct f2fs_mount_info mount_opt;	/* mount options */
44939a53e0cSJaegeuk Kim 
45039a53e0cSJaegeuk Kim 	/* for cleaning operations */
45139a53e0cSJaegeuk Kim 	struct mutex gc_mutex;			/* mutex for GC */
45239a53e0cSJaegeuk Kim 	struct f2fs_gc_kthread	*gc_thread;	/* GC thread */
4535ec4e49fSJaegeuk Kim 	unsigned int cur_victim_sec;		/* current victim section num */
45439a53e0cSJaegeuk Kim 
455b1c57c1cSJaegeuk Kim 	/* maximum # of trials to find a victim segment for SSR and GC */
456b1c57c1cSJaegeuk Kim 	unsigned int max_victim_search;
457b1c57c1cSJaegeuk Kim 
45839a53e0cSJaegeuk Kim 	/*
45939a53e0cSJaegeuk Kim 	 * for stat information.
46039a53e0cSJaegeuk Kim 	 * one is for the LFS mode, and the other is for the SSR mode.
46139a53e0cSJaegeuk Kim 	 */
46235b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS
46339a53e0cSJaegeuk Kim 	struct f2fs_stat_info *stat_info;	/* FS status information */
46439a53e0cSJaegeuk Kim 	unsigned int segment_count[2];		/* # of allocated segments */
46539a53e0cSJaegeuk Kim 	unsigned int block_count[2];		/* # of allocated blocks */
46639a53e0cSJaegeuk Kim 	int total_hit_ext, read_hit_ext;	/* extent cache hit ratio */
4670dbdc2aeSJaegeuk Kim 	int inline_inode;			/* # of inline_data inodes */
46839a53e0cSJaegeuk Kim 	int bg_gc;				/* background gc calls */
46935b09d82SNamjae Jeon 	unsigned int n_dirty_dirs;		/* # of dir inodes */
47035b09d82SNamjae Jeon #endif
47135b09d82SNamjae Jeon 	unsigned int last_victim[2];		/* last victim segment # */
47239a53e0cSJaegeuk Kim 	spinlock_t stat_lock;			/* lock for stat operations */
473b59d0baeSNamjae Jeon 
474b59d0baeSNamjae Jeon 	/* For sysfs suppport */
475b59d0baeSNamjae Jeon 	struct kobject s_kobj;
476b59d0baeSNamjae Jeon 	struct completion s_kobj_unregister;
47739a53e0cSJaegeuk Kim };
47839a53e0cSJaegeuk Kim 
47939a53e0cSJaegeuk Kim /*
48039a53e0cSJaegeuk Kim  * Inline functions
48139a53e0cSJaegeuk Kim  */
48239a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
48339a53e0cSJaegeuk Kim {
48439a53e0cSJaegeuk Kim 	return container_of(inode, struct f2fs_inode_info, vfs_inode);
48539a53e0cSJaegeuk Kim }
48639a53e0cSJaegeuk Kim 
48739a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
48839a53e0cSJaegeuk Kim {
48939a53e0cSJaegeuk Kim 	return sb->s_fs_info;
49039a53e0cSJaegeuk Kim }
49139a53e0cSJaegeuk Kim 
49239a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
49339a53e0cSJaegeuk Kim {
49439a53e0cSJaegeuk Kim 	return (struct f2fs_super_block *)(sbi->raw_super);
49539a53e0cSJaegeuk Kim }
49639a53e0cSJaegeuk Kim 
49739a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
49839a53e0cSJaegeuk Kim {
49939a53e0cSJaegeuk Kim 	return (struct f2fs_checkpoint *)(sbi->ckpt);
50039a53e0cSJaegeuk Kim }
50139a53e0cSJaegeuk Kim 
50245590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page)
50345590710SGu Zheng {
50445590710SGu Zheng 	return (struct f2fs_node *)page_address(page);
50545590710SGu Zheng }
50645590710SGu Zheng 
50758bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page)
50858bfaf44SJaegeuk Kim {
50958bfaf44SJaegeuk Kim 	return &((struct f2fs_node *)page_address(page))->i;
51058bfaf44SJaegeuk Kim }
51158bfaf44SJaegeuk Kim 
51239a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
51339a53e0cSJaegeuk Kim {
51439a53e0cSJaegeuk Kim 	return (struct f2fs_nm_info *)(sbi->nm_info);
51539a53e0cSJaegeuk Kim }
51639a53e0cSJaegeuk Kim 
51739a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
51839a53e0cSJaegeuk Kim {
51939a53e0cSJaegeuk Kim 	return (struct f2fs_sm_info *)(sbi->sm_info);
52039a53e0cSJaegeuk Kim }
52139a53e0cSJaegeuk Kim 
52239a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
52339a53e0cSJaegeuk Kim {
52439a53e0cSJaegeuk Kim 	return (struct sit_info *)(SM_I(sbi)->sit_info);
52539a53e0cSJaegeuk Kim }
52639a53e0cSJaegeuk Kim 
52739a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
52839a53e0cSJaegeuk Kim {
52939a53e0cSJaegeuk Kim 	return (struct free_segmap_info *)(SM_I(sbi)->free_info);
53039a53e0cSJaegeuk Kim }
53139a53e0cSJaegeuk Kim 
53239a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
53339a53e0cSJaegeuk Kim {
53439a53e0cSJaegeuk Kim 	return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
53539a53e0cSJaegeuk Kim }
53639a53e0cSJaegeuk Kim 
5379df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
5389df27d98SGu Zheng {
5399df27d98SGu Zheng 	return sbi->meta_inode->i_mapping;
5409df27d98SGu Zheng }
5419df27d98SGu Zheng 
5424ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
5434ef51a8fSJaegeuk Kim {
5444ef51a8fSJaegeuk Kim 	return sbi->node_inode->i_mapping;
5454ef51a8fSJaegeuk Kim }
5464ef51a8fSJaegeuk Kim 
54739a53e0cSJaegeuk Kim static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
54839a53e0cSJaegeuk Kim {
54939a53e0cSJaegeuk Kim 	sbi->s_dirty = 1;
55039a53e0cSJaegeuk Kim }
55139a53e0cSJaegeuk Kim 
55239a53e0cSJaegeuk Kim static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
55339a53e0cSJaegeuk Kim {
55439a53e0cSJaegeuk Kim 	sbi->s_dirty = 0;
55539a53e0cSJaegeuk Kim }
55639a53e0cSJaegeuk Kim 
557d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
558d71b5564SJaegeuk Kim {
559d71b5564SJaegeuk Kim 	return le64_to_cpu(cp->checkpoint_ver);
560d71b5564SJaegeuk Kim }
561d71b5564SJaegeuk Kim 
56225ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
56325ca923bSJaegeuk Kim {
56425ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
56525ca923bSJaegeuk Kim 	return ckpt_flags & f;
56625ca923bSJaegeuk Kim }
56725ca923bSJaegeuk Kim 
56825ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
56925ca923bSJaegeuk Kim {
57025ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
57125ca923bSJaegeuk Kim 	ckpt_flags |= f;
57225ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
57325ca923bSJaegeuk Kim }
57425ca923bSJaegeuk Kim 
57525ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
57625ca923bSJaegeuk Kim {
57725ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
57825ca923bSJaegeuk Kim 	ckpt_flags &= (~f);
57925ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
58025ca923bSJaegeuk Kim }
58125ca923bSJaegeuk Kim 
582e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
58339a53e0cSJaegeuk Kim {
584e479556bSGu Zheng 	down_read(&sbi->cp_rwsem);
58539a53e0cSJaegeuk Kim }
58639a53e0cSJaegeuk Kim 
587e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
58839a53e0cSJaegeuk Kim {
589e479556bSGu Zheng 	up_read(&sbi->cp_rwsem);
59039936837SJaegeuk Kim }
59139936837SJaegeuk Kim 
592e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
59339936837SJaegeuk Kim {
5940daaad97SJaegeuk Kim 	f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex);
59539936837SJaegeuk Kim }
59639936837SJaegeuk Kim 
597e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
59839936837SJaegeuk Kim {
599e479556bSGu Zheng 	up_write(&sbi->cp_rwsem);
60039a53e0cSJaegeuk Kim }
60139a53e0cSJaegeuk Kim 
60239a53e0cSJaegeuk Kim /*
60339a53e0cSJaegeuk Kim  * Check whether the given nid is within node id range.
60439a53e0cSJaegeuk Kim  */
605064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
60639a53e0cSJaegeuk Kim {
607064e0823SNamjae Jeon 	WARN_ON((nid >= NM_I(sbi)->max_nid));
608cfb271d4SChao Yu 	if (unlikely(nid >= NM_I(sbi)->max_nid))
609064e0823SNamjae Jeon 		return -EINVAL;
610064e0823SNamjae Jeon 	return 0;
61139a53e0cSJaegeuk Kim }
61239a53e0cSJaegeuk Kim 
61339a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS	1
61439a53e0cSJaegeuk Kim 
61539a53e0cSJaegeuk Kim /*
61639a53e0cSJaegeuk Kim  * Check whether the inode has blocks or not
61739a53e0cSJaegeuk Kim  */
61839a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode)
61939a53e0cSJaegeuk Kim {
62039a53e0cSJaegeuk Kim 	if (F2FS_I(inode)->i_xattr_nid)
6216c311ec6SChris Fries 		return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
62239a53e0cSJaegeuk Kim 	else
6236c311ec6SChris Fries 		return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
62439a53e0cSJaegeuk Kim }
62539a53e0cSJaegeuk Kim 
62639a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
62739a53e0cSJaegeuk Kim 				 struct inode *inode, blkcnt_t count)
62839a53e0cSJaegeuk Kim {
62939a53e0cSJaegeuk Kim 	block_t	valid_block_count;
63039a53e0cSJaegeuk Kim 
63139a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
63239a53e0cSJaegeuk Kim 	valid_block_count =
63339a53e0cSJaegeuk Kim 		sbi->total_valid_block_count + (block_t)count;
634cfb271d4SChao Yu 	if (unlikely(valid_block_count > sbi->user_block_count)) {
63539a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
63639a53e0cSJaegeuk Kim 		return false;
63739a53e0cSJaegeuk Kim 	}
63839a53e0cSJaegeuk Kim 	inode->i_blocks += count;
63939a53e0cSJaegeuk Kim 	sbi->total_valid_block_count = valid_block_count;
64039a53e0cSJaegeuk Kim 	sbi->alloc_valid_block_count += (block_t)count;
64139a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
64239a53e0cSJaegeuk Kim 	return true;
64339a53e0cSJaegeuk Kim }
64439a53e0cSJaegeuk Kim 
645da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
64639a53e0cSJaegeuk Kim 						struct inode *inode,
64739a53e0cSJaegeuk Kim 						blkcnt_t count)
64839a53e0cSJaegeuk Kim {
64939a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
6505d56b671SJaegeuk Kim 	f2fs_bug_on(sbi->total_valid_block_count < (block_t) count);
6515d56b671SJaegeuk Kim 	f2fs_bug_on(inode->i_blocks < count);
65239a53e0cSJaegeuk Kim 	inode->i_blocks -= count;
65339a53e0cSJaegeuk Kim 	sbi->total_valid_block_count -= (block_t)count;
65439a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
65539a53e0cSJaegeuk Kim }
65639a53e0cSJaegeuk Kim 
65739a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
65839a53e0cSJaegeuk Kim {
65939a53e0cSJaegeuk Kim 	atomic_inc(&sbi->nr_pages[count_type]);
66039a53e0cSJaegeuk Kim 	F2FS_SET_SB_DIRT(sbi);
66139a53e0cSJaegeuk Kim }
66239a53e0cSJaegeuk Kim 
66339a53e0cSJaegeuk Kim static inline void inode_inc_dirty_dents(struct inode *inode)
66439a53e0cSJaegeuk Kim {
665*1fe54f9dSJaegeuk Kim 	inc_page_count(F2FS_SB(inode->i_sb), F2FS_DIRTY_DENTS);
66639a53e0cSJaegeuk Kim 	atomic_inc(&F2FS_I(inode)->dirty_dents);
66739a53e0cSJaegeuk Kim }
66839a53e0cSJaegeuk Kim 
66939a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
67039a53e0cSJaegeuk Kim {
67139a53e0cSJaegeuk Kim 	atomic_dec(&sbi->nr_pages[count_type]);
67239a53e0cSJaegeuk Kim }
67339a53e0cSJaegeuk Kim 
67439a53e0cSJaegeuk Kim static inline void inode_dec_dirty_dents(struct inode *inode)
67539a53e0cSJaegeuk Kim {
676*1fe54f9dSJaegeuk Kim 	if (!S_ISDIR(inode->i_mode))
677*1fe54f9dSJaegeuk Kim 		return;
678*1fe54f9dSJaegeuk Kim 
679*1fe54f9dSJaegeuk Kim 	dec_page_count(F2FS_SB(inode->i_sb), F2FS_DIRTY_DENTS);
68039a53e0cSJaegeuk Kim 	atomic_dec(&F2FS_I(inode)->dirty_dents);
68139a53e0cSJaegeuk Kim }
68239a53e0cSJaegeuk Kim 
68339a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
68439a53e0cSJaegeuk Kim {
68539a53e0cSJaegeuk Kim 	return atomic_read(&sbi->nr_pages[count_type]);
68639a53e0cSJaegeuk Kim }
68739a53e0cSJaegeuk Kim 
6885ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
6895ac206cfSNamjae Jeon {
6905ac206cfSNamjae Jeon 	unsigned int pages_per_sec = sbi->segs_per_sec *
6915ac206cfSNamjae Jeon 					(1 << sbi->log_blocks_per_seg);
6925ac206cfSNamjae Jeon 	return ((get_pages(sbi, block_type) + pages_per_sec - 1)
6935ac206cfSNamjae Jeon 			>> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
6945ac206cfSNamjae Jeon }
6955ac206cfSNamjae Jeon 
69639a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
69739a53e0cSJaegeuk Kim {
69839a53e0cSJaegeuk Kim 	block_t ret;
69939a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
70039a53e0cSJaegeuk Kim 	ret = sbi->total_valid_block_count;
70139a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
70239a53e0cSJaegeuk Kim 	return ret;
70339a53e0cSJaegeuk Kim }
70439a53e0cSJaegeuk Kim 
70539a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
70639a53e0cSJaegeuk Kim {
70739a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
70839a53e0cSJaegeuk Kim 
70939a53e0cSJaegeuk Kim 	/* return NAT or SIT bitmap */
71039a53e0cSJaegeuk Kim 	if (flag == NAT_BITMAP)
71139a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
71239a53e0cSJaegeuk Kim 	else if (flag == SIT_BITMAP)
71339a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
71439a53e0cSJaegeuk Kim 
71539a53e0cSJaegeuk Kim 	return 0;
71639a53e0cSJaegeuk Kim }
71739a53e0cSJaegeuk Kim 
71839a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
71939a53e0cSJaegeuk Kim {
72039a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
72125ca923bSJaegeuk Kim 	int offset = (flag == NAT_BITMAP) ?
72225ca923bSJaegeuk Kim 			le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
72339a53e0cSJaegeuk Kim 	return &ckpt->sit_nat_version_bitmap + offset;
72439a53e0cSJaegeuk Kim }
72539a53e0cSJaegeuk Kim 
72639a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
72739a53e0cSJaegeuk Kim {
72839a53e0cSJaegeuk Kim 	block_t start_addr;
72939a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
730d71b5564SJaegeuk Kim 	unsigned long long ckpt_version = cur_cp_version(ckpt);
73139a53e0cSJaegeuk Kim 
73225ca923bSJaegeuk Kim 	start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
73339a53e0cSJaegeuk Kim 
73439a53e0cSJaegeuk Kim 	/*
73539a53e0cSJaegeuk Kim 	 * odd numbered checkpoint should at cp segment 0
73639a53e0cSJaegeuk Kim 	 * and even segent must be at cp segment 1
73739a53e0cSJaegeuk Kim 	 */
73839a53e0cSJaegeuk Kim 	if (!(ckpt_version & 1))
73939a53e0cSJaegeuk Kim 		start_addr += sbi->blocks_per_seg;
74039a53e0cSJaegeuk Kim 
74139a53e0cSJaegeuk Kim 	return start_addr;
74239a53e0cSJaegeuk Kim }
74339a53e0cSJaegeuk Kim 
74439a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
74539a53e0cSJaegeuk Kim {
74639a53e0cSJaegeuk Kim 	return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
74739a53e0cSJaegeuk Kim }
74839a53e0cSJaegeuk Kim 
74939a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
750ef86d709SGu Zheng 						struct inode *inode)
75139a53e0cSJaegeuk Kim {
75239a53e0cSJaegeuk Kim 	block_t	valid_block_count;
75339a53e0cSJaegeuk Kim 	unsigned int valid_node_count;
75439a53e0cSJaegeuk Kim 
75539a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
75639a53e0cSJaegeuk Kim 
757ef86d709SGu Zheng 	valid_block_count = sbi->total_valid_block_count + 1;
758cfb271d4SChao Yu 	if (unlikely(valid_block_count > sbi->user_block_count)) {
75939a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
76039a53e0cSJaegeuk Kim 		return false;
76139a53e0cSJaegeuk Kim 	}
76239a53e0cSJaegeuk Kim 
763ef86d709SGu Zheng 	valid_node_count = sbi->total_valid_node_count + 1;
764cfb271d4SChao Yu 	if (unlikely(valid_node_count > sbi->total_node_count)) {
76539a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
76639a53e0cSJaegeuk Kim 		return false;
76739a53e0cSJaegeuk Kim 	}
76839a53e0cSJaegeuk Kim 
76939a53e0cSJaegeuk Kim 	if (inode)
770ef86d709SGu Zheng 		inode->i_blocks++;
771ef86d709SGu Zheng 
772ef86d709SGu Zheng 	sbi->alloc_valid_block_count++;
773ef86d709SGu Zheng 	sbi->total_valid_node_count++;
774ef86d709SGu Zheng 	sbi->total_valid_block_count++;
77539a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
77639a53e0cSJaegeuk Kim 
77739a53e0cSJaegeuk Kim 	return true;
77839a53e0cSJaegeuk Kim }
77939a53e0cSJaegeuk Kim 
78039a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
781ef86d709SGu Zheng 						struct inode *inode)
78239a53e0cSJaegeuk Kim {
78339a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
78439a53e0cSJaegeuk Kim 
785ef86d709SGu Zheng 	f2fs_bug_on(!sbi->total_valid_block_count);
786ef86d709SGu Zheng 	f2fs_bug_on(!sbi->total_valid_node_count);
787ef86d709SGu Zheng 	f2fs_bug_on(!inode->i_blocks);
78839a53e0cSJaegeuk Kim 
789ef86d709SGu Zheng 	inode->i_blocks--;
790ef86d709SGu Zheng 	sbi->total_valid_node_count--;
791ef86d709SGu Zheng 	sbi->total_valid_block_count--;
79239a53e0cSJaegeuk Kim 
79339a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
79439a53e0cSJaegeuk Kim }
79539a53e0cSJaegeuk Kim 
79639a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
79739a53e0cSJaegeuk Kim {
79839a53e0cSJaegeuk Kim 	unsigned int ret;
79939a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
80039a53e0cSJaegeuk Kim 	ret = sbi->total_valid_node_count;
80139a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
80239a53e0cSJaegeuk Kim 	return ret;
80339a53e0cSJaegeuk Kim }
80439a53e0cSJaegeuk Kim 
80539a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
80639a53e0cSJaegeuk Kim {
80739a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
8085d56b671SJaegeuk Kim 	f2fs_bug_on(sbi->total_valid_inode_count == sbi->total_node_count);
80939a53e0cSJaegeuk Kim 	sbi->total_valid_inode_count++;
81039a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
81139a53e0cSJaegeuk Kim }
81239a53e0cSJaegeuk Kim 
8130e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
81439a53e0cSJaegeuk Kim {
81539a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
8165d56b671SJaegeuk Kim 	f2fs_bug_on(!sbi->total_valid_inode_count);
81739a53e0cSJaegeuk Kim 	sbi->total_valid_inode_count--;
81839a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
81939a53e0cSJaegeuk Kim }
82039a53e0cSJaegeuk Kim 
82139a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
82239a53e0cSJaegeuk Kim {
82339a53e0cSJaegeuk Kim 	unsigned int ret;
82439a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
82539a53e0cSJaegeuk Kim 	ret = sbi->total_valid_inode_count;
82639a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
82739a53e0cSJaegeuk Kim 	return ret;
82839a53e0cSJaegeuk Kim }
82939a53e0cSJaegeuk Kim 
83039a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock)
83139a53e0cSJaegeuk Kim {
832031fa8ccSJaegeuk Kim 	if (!page)
83339a53e0cSJaegeuk Kim 		return;
83439a53e0cSJaegeuk Kim 
83539a53e0cSJaegeuk Kim 	if (unlock) {
8365d56b671SJaegeuk Kim 		f2fs_bug_on(!PageLocked(page));
83739a53e0cSJaegeuk Kim 		unlock_page(page);
83839a53e0cSJaegeuk Kim 	}
83939a53e0cSJaegeuk Kim 	page_cache_release(page);
84039a53e0cSJaegeuk Kim }
84139a53e0cSJaegeuk Kim 
84239a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn)
84339a53e0cSJaegeuk Kim {
84439a53e0cSJaegeuk Kim 	if (dn->node_page)
84539a53e0cSJaegeuk Kim 		f2fs_put_page(dn->node_page, 1);
84639a53e0cSJaegeuk Kim 	if (dn->inode_page && dn->node_page != dn->inode_page)
84739a53e0cSJaegeuk Kim 		f2fs_put_page(dn->inode_page, 0);
84839a53e0cSJaegeuk Kim 	dn->node_page = NULL;
84939a53e0cSJaegeuk Kim 	dn->inode_page = NULL;
85039a53e0cSJaegeuk Kim }
85139a53e0cSJaegeuk Kim 
85239a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
85339a53e0cSJaegeuk Kim 					size_t size, void (*ctor)(void *))
85439a53e0cSJaegeuk Kim {
85539a53e0cSJaegeuk Kim 	return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor);
85639a53e0cSJaegeuk Kim }
85739a53e0cSJaegeuk Kim 
8587bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
8597bd59381SGu Zheng 						gfp_t flags)
8607bd59381SGu Zheng {
8617bd59381SGu Zheng 	void *entry;
8627bd59381SGu Zheng retry:
8637bd59381SGu Zheng 	entry = kmem_cache_alloc(cachep, flags);
8647bd59381SGu Zheng 	if (!entry) {
8657bd59381SGu Zheng 		cond_resched();
8667bd59381SGu Zheng 		goto retry;
8677bd59381SGu Zheng 	}
8687bd59381SGu Zheng 
8697bd59381SGu Zheng 	return entry;
8707bd59381SGu Zheng }
8717bd59381SGu Zheng 
87239a53e0cSJaegeuk Kim #define RAW_IS_INODE(p)	((p)->footer.nid == (p)->footer.ino)
87339a53e0cSJaegeuk Kim 
87439a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page)
87539a53e0cSJaegeuk Kim {
87645590710SGu Zheng 	struct f2fs_node *p = F2FS_NODE(page);
87739a53e0cSJaegeuk Kim 	return RAW_IS_INODE(p);
87839a53e0cSJaegeuk Kim }
87939a53e0cSJaegeuk Kim 
88039a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
88139a53e0cSJaegeuk Kim {
88239a53e0cSJaegeuk Kim 	return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
88339a53e0cSJaegeuk Kim }
88439a53e0cSJaegeuk Kim 
88539a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page,
88639a53e0cSJaegeuk Kim 		unsigned int offset)
88739a53e0cSJaegeuk Kim {
88839a53e0cSJaegeuk Kim 	struct f2fs_node *raw_node;
88939a53e0cSJaegeuk Kim 	__le32 *addr_array;
89045590710SGu Zheng 	raw_node = F2FS_NODE(node_page);
89139a53e0cSJaegeuk Kim 	addr_array = blkaddr_in_node(raw_node);
89239a53e0cSJaegeuk Kim 	return le32_to_cpu(addr_array[offset]);
89339a53e0cSJaegeuk Kim }
89439a53e0cSJaegeuk Kim 
89539a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr)
89639a53e0cSJaegeuk Kim {
89739a53e0cSJaegeuk Kim 	int mask;
89839a53e0cSJaegeuk Kim 
89939a53e0cSJaegeuk Kim 	addr += (nr >> 3);
90039a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
90139a53e0cSJaegeuk Kim 	return mask & *addr;
90239a53e0cSJaegeuk Kim }
90339a53e0cSJaegeuk Kim 
90439a53e0cSJaegeuk Kim static inline int f2fs_set_bit(unsigned int nr, char *addr)
90539a53e0cSJaegeuk Kim {
90639a53e0cSJaegeuk Kim 	int mask;
90739a53e0cSJaegeuk Kim 	int ret;
90839a53e0cSJaegeuk Kim 
90939a53e0cSJaegeuk Kim 	addr += (nr >> 3);
91039a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
91139a53e0cSJaegeuk Kim 	ret = mask & *addr;
91239a53e0cSJaegeuk Kim 	*addr |= mask;
91339a53e0cSJaegeuk Kim 	return ret;
91439a53e0cSJaegeuk Kim }
91539a53e0cSJaegeuk Kim 
91639a53e0cSJaegeuk Kim static inline int f2fs_clear_bit(unsigned int nr, char *addr)
91739a53e0cSJaegeuk Kim {
91839a53e0cSJaegeuk Kim 	int mask;
91939a53e0cSJaegeuk Kim 	int ret;
92039a53e0cSJaegeuk Kim 
92139a53e0cSJaegeuk Kim 	addr += (nr >> 3);
92239a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
92339a53e0cSJaegeuk Kim 	ret = mask & *addr;
92439a53e0cSJaegeuk Kim 	*addr &= ~mask;
92539a53e0cSJaegeuk Kim 	return ret;
92639a53e0cSJaegeuk Kim }
92739a53e0cSJaegeuk Kim 
92839a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */
92939a53e0cSJaegeuk Kim enum {
93039a53e0cSJaegeuk Kim 	FI_NEW_INODE,		/* indicate newly allocated inode */
931b3783873SJaegeuk Kim 	FI_DIRTY_INODE,		/* indicate inode is dirty or not */
93239a53e0cSJaegeuk Kim 	FI_INC_LINK,		/* need to increment i_nlink */
93339a53e0cSJaegeuk Kim 	FI_ACL_MODE,		/* indicate acl mode */
93439a53e0cSJaegeuk Kim 	FI_NO_ALLOC,		/* should not allocate any blocks */
935699489bbSJaegeuk Kim 	FI_UPDATE_DIR,		/* should update inode block for consistency */
93674d0b917SJaegeuk Kim 	FI_DELAY_IPUT,		/* used for the recovery */
937c11abd1aSJaegeuk Kim 	FI_NO_EXTENT,		/* not to use the extent cache */
938444c580fSJaegeuk Kim 	FI_INLINE_XATTR,	/* used for inline xattr */
9391001b347SHuajun Li 	FI_INLINE_DATA,		/* used for inline data*/
94039a53e0cSJaegeuk Kim };
94139a53e0cSJaegeuk Kim 
94239a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
94339a53e0cSJaegeuk Kim {
94439a53e0cSJaegeuk Kim 	set_bit(flag, &fi->flags);
94539a53e0cSJaegeuk Kim }
94639a53e0cSJaegeuk Kim 
94739a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
94839a53e0cSJaegeuk Kim {
94939a53e0cSJaegeuk Kim 	return test_bit(flag, &fi->flags);
95039a53e0cSJaegeuk Kim }
95139a53e0cSJaegeuk Kim 
95239a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
95339a53e0cSJaegeuk Kim {
95439a53e0cSJaegeuk Kim 	clear_bit(flag, &fi->flags);
95539a53e0cSJaegeuk Kim }
95639a53e0cSJaegeuk Kim 
95739a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
95839a53e0cSJaegeuk Kim {
95939a53e0cSJaegeuk Kim 	fi->i_acl_mode = mode;
96039a53e0cSJaegeuk Kim 	set_inode_flag(fi, FI_ACL_MODE);
96139a53e0cSJaegeuk Kim }
96239a53e0cSJaegeuk Kim 
96339a53e0cSJaegeuk Kim static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag)
96439a53e0cSJaegeuk Kim {
96539a53e0cSJaegeuk Kim 	if (is_inode_flag_set(fi, FI_ACL_MODE)) {
96639a53e0cSJaegeuk Kim 		clear_inode_flag(fi, FI_ACL_MODE);
96739a53e0cSJaegeuk Kim 		return 1;
96839a53e0cSJaegeuk Kim 	}
96939a53e0cSJaegeuk Kim 	return 0;
97039a53e0cSJaegeuk Kim }
97139a53e0cSJaegeuk Kim 
972444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi,
973444c580fSJaegeuk Kim 					struct f2fs_inode *ri)
974444c580fSJaegeuk Kim {
975444c580fSJaegeuk Kim 	if (ri->i_inline & F2FS_INLINE_XATTR)
976444c580fSJaegeuk Kim 		set_inode_flag(fi, FI_INLINE_XATTR);
9771001b347SHuajun Li 	if (ri->i_inline & F2FS_INLINE_DATA)
9781001b347SHuajun Li 		set_inode_flag(fi, FI_INLINE_DATA);
979444c580fSJaegeuk Kim }
980444c580fSJaegeuk Kim 
981444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi,
982444c580fSJaegeuk Kim 					struct f2fs_inode *ri)
983444c580fSJaegeuk Kim {
984444c580fSJaegeuk Kim 	ri->i_inline = 0;
985444c580fSJaegeuk Kim 
986444c580fSJaegeuk Kim 	if (is_inode_flag_set(fi, FI_INLINE_XATTR))
987444c580fSJaegeuk Kim 		ri->i_inline |= F2FS_INLINE_XATTR;
9881001b347SHuajun Li 	if (is_inode_flag_set(fi, FI_INLINE_DATA))
9891001b347SHuajun Li 		ri->i_inline |= F2FS_INLINE_DATA;
990444c580fSJaegeuk Kim }
991444c580fSJaegeuk Kim 
992de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
993de93653fSJaegeuk Kim {
994de93653fSJaegeuk Kim 	if (is_inode_flag_set(fi, FI_INLINE_XATTR))
995de93653fSJaegeuk Kim 		return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
996de93653fSJaegeuk Kim 	return DEF_ADDRS_PER_INODE;
997de93653fSJaegeuk Kim }
998de93653fSJaegeuk Kim 
99965985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page)
100065985d93SJaegeuk Kim {
100165985d93SJaegeuk Kim 	struct f2fs_inode *ri;
100265985d93SJaegeuk Kim 	ri = (struct f2fs_inode *)page_address(page);
100365985d93SJaegeuk Kim 	return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
100465985d93SJaegeuk Kim 					F2FS_INLINE_XATTR_ADDRS]);
100565985d93SJaegeuk Kim }
100665985d93SJaegeuk Kim 
100765985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode)
100865985d93SJaegeuk Kim {
100965985d93SJaegeuk Kim 	if (is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR))
101065985d93SJaegeuk Kim 		return F2FS_INLINE_XATTR_ADDRS << 2;
101165985d93SJaegeuk Kim 	else
101265985d93SJaegeuk Kim 		return 0;
101365985d93SJaegeuk Kim }
101465985d93SJaegeuk Kim 
10150dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode)
10160dbdc2aeSJaegeuk Kim {
10170dbdc2aeSJaegeuk Kim 	return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
10180dbdc2aeSJaegeuk Kim }
10190dbdc2aeSJaegeuk Kim 
10201001b347SHuajun Li static inline void *inline_data_addr(struct page *page)
10211001b347SHuajun Li {
10221001b347SHuajun Li 	struct f2fs_inode *ri;
10231001b347SHuajun Li 	ri = (struct f2fs_inode *)page_address(page);
10241001b347SHuajun Li 	return (void *)&(ri->i_addr[1]);
10251001b347SHuajun Li }
10261001b347SHuajun Li 
102777888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb)
102877888c1eSJaegeuk Kim {
102977888c1eSJaegeuk Kim 	return sb->s_flags & MS_RDONLY;
103077888c1eSJaegeuk Kim }
103177888c1eSJaegeuk Kim 
1032744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi)
1033744602cfSJaegeuk Kim {
1034744602cfSJaegeuk Kim 	set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1035744602cfSJaegeuk Kim 	sbi->sb->s_flags |= MS_RDONLY;
1036744602cfSJaegeuk Kim }
1037744602cfSJaegeuk Kim 
1038a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \
1039a6dda0e6SChristoph Hellwig 	((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
1040a6dda0e6SChristoph Hellwig 	 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
1041a6dda0e6SChristoph Hellwig 
104239a53e0cSJaegeuk Kim /*
104339a53e0cSJaegeuk Kim  * file.c
104439a53e0cSJaegeuk Kim  */
104539a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int);
104639a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *);
10471e1bb4baSJaegeuk Kim int truncate_blocks(struct inode *, u64);
104839a53e0cSJaegeuk Kim void f2fs_truncate(struct inode *);
10492d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
105039a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *);
105139a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t);
1052b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int);
105339a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long);
1054e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
105539a53e0cSJaegeuk Kim 
105639a53e0cSJaegeuk Kim /*
105739a53e0cSJaegeuk Kim  * inode.c
105839a53e0cSJaegeuk Kim  */
105939a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *);
106039a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long);
10614660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int);
106239a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *);
1063744602cfSJaegeuk Kim void update_inode_page(struct inode *);
106439a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *);
106539a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *);
106639a53e0cSJaegeuk Kim 
106739a53e0cSJaegeuk Kim /*
106839a53e0cSJaegeuk Kim  * namei.c
106939a53e0cSJaegeuk Kim  */
107039a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child);
107139a53e0cSJaegeuk Kim 
107239a53e0cSJaegeuk Kim /*
107339a53e0cSJaegeuk Kim  * dir.c
107439a53e0cSJaegeuk Kim  */
107539a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
107639a53e0cSJaegeuk Kim 							struct page **);
107739a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
107839a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
107939a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
108039a53e0cSJaegeuk Kim 				struct page *, struct inode *);
10811cd14cafSJaegeuk Kim int update_dent_inode(struct inode *, const struct qstr *);
1082b7f7a5e0SAl Viro int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
108339a53e0cSJaegeuk Kim void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
108439a53e0cSJaegeuk Kim int f2fs_make_empty(struct inode *, struct inode *);
108539a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *);
108639a53e0cSJaegeuk Kim 
1087b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
1088b7f7a5e0SAl Viro {
1089b7f7a5e0SAl Viro 	return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
1090b7f7a5e0SAl Viro 				inode);
1091b7f7a5e0SAl Viro }
1092b7f7a5e0SAl Viro 
109339a53e0cSJaegeuk Kim /*
109439a53e0cSJaegeuk Kim  * super.c
109539a53e0cSJaegeuk Kim  */
109639a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int);
1097a07ef784SNamjae Jeon extern __printf(3, 4)
1098a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...);
109939a53e0cSJaegeuk Kim 
110039a53e0cSJaegeuk Kim /*
110139a53e0cSJaegeuk Kim  * hash.c
110239a53e0cSJaegeuk Kim  */
11039836b8b9SLeon Romanovsky f2fs_hash_t f2fs_dentry_hash(const char *, size_t);
110439a53e0cSJaegeuk Kim 
110539a53e0cSJaegeuk Kim /*
110639a53e0cSJaegeuk Kim  * node.c
110739a53e0cSJaegeuk Kim  */
110839a53e0cSJaegeuk Kim struct dnode_of_data;
110939a53e0cSJaegeuk Kim struct node_info;
111039a53e0cSJaegeuk Kim 
111139a53e0cSJaegeuk Kim int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
111239a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
111339a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
111439a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t);
11154f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *);
1116cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
111758e674d6SGu Zheng void remove_inode_page(struct inode *);
111844a83ff6SJaegeuk Kim struct page *new_inode_page(struct inode *, const struct qstr *);
11198ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
112039a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t);
112139a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
112239a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int);
112339a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *);
112439a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
112539a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *);
112639a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t);
112739a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
112839a53e0cSJaegeuk Kim void recover_node_page(struct f2fs_sb_info *, struct page *,
112939a53e0cSJaegeuk Kim 		struct f2fs_summary *, struct node_info *, block_t);
1130abb2366cSJaegeuk Kim bool recover_xattr_data(struct inode *, struct page *, block_t);
113139a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *);
113239a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int,
113339a53e0cSJaegeuk Kim 				struct f2fs_summary_block *);
113439a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *);
113539a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *);
113639a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *);
11376e6093a8SNamjae Jeon int __init create_node_manager_caches(void);
113839a53e0cSJaegeuk Kim void destroy_node_manager_caches(void);
113939a53e0cSJaegeuk Kim 
114039a53e0cSJaegeuk Kim /*
114139a53e0cSJaegeuk Kim  * segment.c
114239a53e0cSJaegeuk Kim  */
114339a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *);
11444660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *);
114539a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t);
11465e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
114739a53e0cSJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *);
114839a53e0cSJaegeuk Kim int npages_for_summary_flush(struct f2fs_sb_info *);
114939a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *);
115039a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
1151577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *);
1152fb5566daSJaegeuk Kim void write_node_page(struct f2fs_sb_info *, struct page *,
1153fb5566daSJaegeuk Kim 		struct f2fs_io_info *, unsigned int, block_t, block_t *);
1154458e6197SJaegeuk Kim void write_data_page(struct page *, struct dnode_of_data *, block_t *,
1155458e6197SJaegeuk Kim 					struct f2fs_io_info *);
1156458e6197SJaegeuk Kim void rewrite_data_page(struct page *, block_t, struct f2fs_io_info *);
115739a53e0cSJaegeuk Kim void recover_data_page(struct f2fs_sb_info *, struct page *,
115839a53e0cSJaegeuk Kim 				struct f2fs_summary *, block_t, block_t);
115939a53e0cSJaegeuk Kim void rewrite_node_page(struct f2fs_sb_info *, struct page *,
116039a53e0cSJaegeuk Kim 				struct f2fs_summary *, block_t, block_t);
1161bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *,
1162bfad7c2dSJaegeuk Kim 		block_t, block_t *, struct f2fs_summary *, int);
11635514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type);
116439a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t);
116539a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t);
116639a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *,
116739a53e0cSJaegeuk Kim 					int, unsigned int, int);
116839a53e0cSJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *);
116939a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *);
117039a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *);
11717fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void);
11727fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void);
117339a53e0cSJaegeuk Kim 
117439a53e0cSJaegeuk Kim /*
117539a53e0cSJaegeuk Kim  * checkpoint.c
117639a53e0cSJaegeuk Kim  */
117739a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
117839a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
117939a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
1180cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *);
1181cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *);
118239a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t);
118339a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
11848f99a946SChao Yu void recover_orphan_inodes(struct f2fs_sb_info *);
118539a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *);
118639a53e0cSJaegeuk Kim void set_dirty_dir_page(struct inode *, struct page *);
11875deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *);
118839a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *);
118974d0b917SJaegeuk Kim struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t);
119039a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *);
119143727527SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, bool);
119239a53e0cSJaegeuk Kim void init_orphan_info(struct f2fs_sb_info *);
11936e6093a8SNamjae Jeon int __init create_checkpoint_caches(void);
119439a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void);
119539a53e0cSJaegeuk Kim 
119639a53e0cSJaegeuk Kim /*
119739a53e0cSJaegeuk Kim  * data.c
119839a53e0cSJaegeuk Kim  */
1199458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
120093dfe2acSJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *, block_t, int);
120193dfe2acSJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *, block_t,
1202458e6197SJaegeuk Kim 						struct f2fs_io_info *);
120339a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *);
1204b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
120539a53e0cSJaegeuk Kim void update_extent_cache(block_t, struct dnode_of_data *);
1206c718379bSJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t, bool);
120739a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t);
120864aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
1209458e6197SJaegeuk Kim int do_write_data_page(struct page *, struct f2fs_io_info *);
121039a53e0cSJaegeuk Kim 
121139a53e0cSJaegeuk Kim /*
121239a53e0cSJaegeuk Kim  * gc.c
121339a53e0cSJaegeuk Kim  */
121439a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *);
121539a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *);
1216de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
1217408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *);
121839a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *);
12196e6093a8SNamjae Jeon int __init create_gc_caches(void);
122039a53e0cSJaegeuk Kim void destroy_gc_caches(void);
122139a53e0cSJaegeuk Kim 
122239a53e0cSJaegeuk Kim /*
122339a53e0cSJaegeuk Kim  * recovery.c
122439a53e0cSJaegeuk Kim  */
12256ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *);
122639a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *);
122739a53e0cSJaegeuk Kim 
122839a53e0cSJaegeuk Kim /*
122939a53e0cSJaegeuk Kim  * debug.c
123039a53e0cSJaegeuk Kim  */
123139a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS
123239a53e0cSJaegeuk Kim struct f2fs_stat_info {
123339a53e0cSJaegeuk Kim 	struct list_head stat_list;
123439a53e0cSJaegeuk Kim 	struct f2fs_sb_info *sbi;
123539a53e0cSJaegeuk Kim 	struct mutex stat_lock;
123639a53e0cSJaegeuk Kim 	int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
123739a53e0cSJaegeuk Kim 	int main_area_segs, main_area_sections, main_area_zones;
123839a53e0cSJaegeuk Kim 	int hit_ext, total_ext;
123939a53e0cSJaegeuk Kim 	int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
124039a53e0cSJaegeuk Kim 	int nats, sits, fnids;
124139a53e0cSJaegeuk Kim 	int total_count, utilization;
12420dbdc2aeSJaegeuk Kim 	int bg_gc, inline_inode;
124339a53e0cSJaegeuk Kim 	unsigned int valid_count, valid_node_count, valid_inode_count;
124439a53e0cSJaegeuk Kim 	unsigned int bimodal, avg_vblocks;
124539a53e0cSJaegeuk Kim 	int util_free, util_valid, util_invalid;
124639a53e0cSJaegeuk Kim 	int rsvd_segs, overp_segs;
124739a53e0cSJaegeuk Kim 	int dirty_count, node_pages, meta_pages;
124839a53e0cSJaegeuk Kim 	int prefree_count, call_count;
124939a53e0cSJaegeuk Kim 	int tot_segs, node_segs, data_segs, free_segs, free_secs;
125039a53e0cSJaegeuk Kim 	int tot_blks, data_blks, node_blks;
125139a53e0cSJaegeuk Kim 	int curseg[NR_CURSEG_TYPE];
125239a53e0cSJaegeuk Kim 	int cursec[NR_CURSEG_TYPE];
125339a53e0cSJaegeuk Kim 	int curzone[NR_CURSEG_TYPE];
125439a53e0cSJaegeuk Kim 
125539a53e0cSJaegeuk Kim 	unsigned int segment_count[2];
125639a53e0cSJaegeuk Kim 	unsigned int block_count[2];
125739a53e0cSJaegeuk Kim 	unsigned base_mem, cache_mem;
125839a53e0cSJaegeuk Kim };
125939a53e0cSJaegeuk Kim 
1260963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
1261963d4f7dSGu Zheng {
1262963d4f7dSGu Zheng 	return (struct f2fs_stat_info *)sbi->stat_info;
1263963d4f7dSGu Zheng }
1264963d4f7dSGu Zheng 
126539a53e0cSJaegeuk Kim #define stat_inc_call_count(si)		((si)->call_count++)
1266dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi)	((sbi)->bg_gc++)
1267dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi)		((sbi)->n_dirty_dirs++)
1268dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi)		((sbi)->n_dirty_dirs--)
1269dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb)		((F2FS_SB(sb))->total_hit_ext++)
1270dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb)		((F2FS_SB(sb))->read_hit_ext++)
12710dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode)					\
12720dbdc2aeSJaegeuk Kim 	do {								\
12730dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
12740dbdc2aeSJaegeuk Kim 			((F2FS_SB(inode->i_sb))->inline_inode++);	\
12750dbdc2aeSJaegeuk Kim 	} while (0)
12760dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode)					\
12770dbdc2aeSJaegeuk Kim 	do {								\
12780dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
12790dbdc2aeSJaegeuk Kim 			((F2FS_SB(inode->i_sb))->inline_inode--);	\
12800dbdc2aeSJaegeuk Kim 	} while (0)
12810dbdc2aeSJaegeuk Kim 
1282dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg)					\
1283dcdfff65SJaegeuk Kim 		((sbi)->segment_count[(curseg)->alloc_type]++)
1284dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg)				\
1285dcdfff65SJaegeuk Kim 		((sbi)->block_count[(curseg)->alloc_type]++)
128639a53e0cSJaegeuk Kim 
128739a53e0cSJaegeuk Kim #define stat_inc_seg_count(sbi, type)					\
128839a53e0cSJaegeuk Kim 	do {								\
1289963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
129039a53e0cSJaegeuk Kim 		(si)->tot_segs++;					\
129139a53e0cSJaegeuk Kim 		if (type == SUM_TYPE_DATA)				\
129239a53e0cSJaegeuk Kim 			si->data_segs++;				\
129339a53e0cSJaegeuk Kim 		else							\
129439a53e0cSJaegeuk Kim 			si->node_segs++;				\
129539a53e0cSJaegeuk Kim 	} while (0)
129639a53e0cSJaegeuk Kim 
129739a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks)				\
129839a53e0cSJaegeuk Kim 	(si->tot_blks += (blks))
129939a53e0cSJaegeuk Kim 
130039a53e0cSJaegeuk Kim #define stat_inc_data_blk_count(sbi, blks)				\
130139a53e0cSJaegeuk Kim 	do {								\
1302963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
130339a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
130439a53e0cSJaegeuk Kim 		si->data_blks += (blks);				\
130539a53e0cSJaegeuk Kim 	} while (0)
130639a53e0cSJaegeuk Kim 
130739a53e0cSJaegeuk Kim #define stat_inc_node_blk_count(sbi, blks)				\
130839a53e0cSJaegeuk Kim 	do {								\
1309963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
131039a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
131139a53e0cSJaegeuk Kim 		si->node_blks += (blks);				\
131239a53e0cSJaegeuk Kim 	} while (0)
131339a53e0cSJaegeuk Kim 
131439a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *);
131539a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *);
13166e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void);
13174589d25dSNamjae Jeon void f2fs_destroy_root_stats(void);
131839a53e0cSJaegeuk Kim #else
131939a53e0cSJaegeuk Kim #define stat_inc_call_count(si)
1320dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si)
1321dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi)
1322dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi)
1323dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb)
1324dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb)
13250dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode)
13260dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode)
1327dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg)
1328dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg)
132939a53e0cSJaegeuk Kim #define stat_inc_seg_count(si, type)
133039a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks)
133139a53e0cSJaegeuk Kim #define stat_inc_data_blk_count(si, blks)
133239a53e0cSJaegeuk Kim #define stat_inc_node_blk_count(sbi, blks)
133339a53e0cSJaegeuk Kim 
133439a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
133539a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
13366e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { }
13374589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { }
133839a53e0cSJaegeuk Kim #endif
133939a53e0cSJaegeuk Kim 
134039a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations;
134139a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations;
134239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations;
134339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops;
134439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops;
134539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops;
134639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations;
134739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations;
134839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations;
13491001b347SHuajun Li 
1350e18c65b2SHuajun Li /*
1351e18c65b2SHuajun Li  * inline.c
1352e18c65b2SHuajun Li  */
1353e18c65b2SHuajun Li bool f2fs_may_inline(struct inode *);
1354e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *);
13559e09fc85SJaegeuk Kim int f2fs_convert_inline_data(struct inode *, pgoff_t);
1356e18c65b2SHuajun Li int f2fs_write_inline_data(struct inode *, struct page *, unsigned int);
13571e1bb4baSJaegeuk Kim int recover_inline_data(struct inode *, struct page *);
135839a53e0cSJaegeuk Kim #endif
1359