xref: /openbmc/linux/fs/f2fs/f2fs.h (revision 75ab4cb8301adb3a02a96c5c03c837ed941f1bc5)
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);					\
319850cf4aSJaegeuk Kim 			sbi->need_fsck = true;				\
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
496b4afdd7SJaegeuk Kim #define F2FS_MOUNT_FLUSH_MERGE		0x00000200
500f7b2abdSJaegeuk Kim #define F2FS_MOUNT_NOBARRIER		0x00000400
5139a53e0cSJaegeuk Kim 
5239a53e0cSJaegeuk Kim #define clear_opt(sbi, option)	(sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
5339a53e0cSJaegeuk Kim #define set_opt(sbi, option)	(sbi->mount_opt.opt |= F2FS_MOUNT_##option)
5439a53e0cSJaegeuk Kim #define test_opt(sbi, option)	(sbi->mount_opt.opt & F2FS_MOUNT_##option)
5539a53e0cSJaegeuk Kim 
5639a53e0cSJaegeuk Kim #define ver_after(a, b)	(typecheck(unsigned long long, a) &&		\
5739a53e0cSJaegeuk Kim 		typecheck(unsigned long long, b) &&			\
5839a53e0cSJaegeuk Kim 		((long long)((a) - (b)) > 0))
5939a53e0cSJaegeuk Kim 
60a9841c4dSJaegeuk Kim typedef u32 block_t;	/*
61a9841c4dSJaegeuk Kim 			 * should not change u32, since it is the on-disk block
62a9841c4dSJaegeuk Kim 			 * address format, __le32.
63a9841c4dSJaegeuk Kim 			 */
6439a53e0cSJaegeuk Kim typedef u32 nid_t;
6539a53e0cSJaegeuk Kim 
6639a53e0cSJaegeuk Kim struct f2fs_mount_info {
6739a53e0cSJaegeuk Kim 	unsigned int	opt;
6839a53e0cSJaegeuk Kim };
6939a53e0cSJaegeuk Kim 
707e586fa0SJaegeuk Kim #define CRCPOLY_LE 0xedb88320
717e586fa0SJaegeuk Kim 
727e586fa0SJaegeuk Kim static inline __u32 f2fs_crc32(void *buf, size_t len)
7339a53e0cSJaegeuk Kim {
747e586fa0SJaegeuk Kim 	unsigned char *p = (unsigned char *)buf;
757e586fa0SJaegeuk Kim 	__u32 crc = F2FS_SUPER_MAGIC;
767e586fa0SJaegeuk Kim 	int i;
777e586fa0SJaegeuk Kim 
787e586fa0SJaegeuk Kim 	while (len--) {
797e586fa0SJaegeuk Kim 		crc ^= *p++;
807e586fa0SJaegeuk Kim 		for (i = 0; i < 8; i++)
817e586fa0SJaegeuk Kim 			crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
827e586fa0SJaegeuk Kim 	}
837e586fa0SJaegeuk Kim 	return crc;
8439a53e0cSJaegeuk Kim }
8539a53e0cSJaegeuk Kim 
867e586fa0SJaegeuk Kim static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
8739a53e0cSJaegeuk Kim {
887e586fa0SJaegeuk Kim 	return f2fs_crc32(buf, buf_size) == blk_crc;
8939a53e0cSJaegeuk Kim }
9039a53e0cSJaegeuk Kim 
9139a53e0cSJaegeuk Kim /*
9239a53e0cSJaegeuk Kim  * For checkpoint manager
9339a53e0cSJaegeuk Kim  */
9439a53e0cSJaegeuk Kim enum {
9539a53e0cSJaegeuk Kim 	NAT_BITMAP,
9639a53e0cSJaegeuk Kim 	SIT_BITMAP
9739a53e0cSJaegeuk Kim };
9839a53e0cSJaegeuk Kim 
99*75ab4cb8SJaegeuk Kim enum {
100*75ab4cb8SJaegeuk Kim 	CP_UMOUNT,
101*75ab4cb8SJaegeuk Kim 	CP_SYNC,
102*75ab4cb8SJaegeuk Kim };
103*75ab4cb8SJaegeuk Kim 
104*75ab4cb8SJaegeuk Kim struct cp_control {
105*75ab4cb8SJaegeuk Kim 	int reason;
106*75ab4cb8SJaegeuk Kim };
107*75ab4cb8SJaegeuk Kim 
108662befdaSChao Yu /*
10981c1a0f1SChao Yu  * For CP/NAT/SIT/SSA readahead
110662befdaSChao Yu  */
111662befdaSChao Yu enum {
112662befdaSChao Yu 	META_CP,
113662befdaSChao Yu 	META_NAT,
11481c1a0f1SChao Yu 	META_SIT,
1154c521f49SJaegeuk Kim 	META_SSA,
1164c521f49SJaegeuk Kim 	META_POR,
117662befdaSChao Yu };
118662befdaSChao Yu 
1196451e041SJaegeuk Kim /* for the list of ino */
1206451e041SJaegeuk Kim enum {
1216451e041SJaegeuk Kim 	ORPHAN_INO,		/* for orphan ino list */
122fff04f90SJaegeuk Kim 	APPEND_INO,		/* for append ino list */
123fff04f90SJaegeuk Kim 	UPDATE_INO,		/* for update ino list */
1246451e041SJaegeuk Kim 	MAX_INO_ENTRY,		/* max. list */
1256451e041SJaegeuk Kim };
1266451e041SJaegeuk Kim 
1276451e041SJaegeuk Kim struct ino_entry {
12839a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
12939a53e0cSJaegeuk Kim 	nid_t ino;		/* inode number */
13039a53e0cSJaegeuk Kim };
13139a53e0cSJaegeuk Kim 
13239a53e0cSJaegeuk Kim /* for the list of directory inodes */
13339a53e0cSJaegeuk Kim struct dir_inode_entry {
13439a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
13539a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
13639a53e0cSJaegeuk Kim };
13739a53e0cSJaegeuk Kim 
1387fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */
1397fd9e544SJaegeuk Kim struct discard_entry {
1407fd9e544SJaegeuk Kim 	struct list_head list;	/* list head */
1417fd9e544SJaegeuk Kim 	block_t blkaddr;	/* block address to be discarded */
1427fd9e544SJaegeuk Kim 	int len;		/* # of consecutive blocks of the discard */
1437fd9e544SJaegeuk Kim };
1447fd9e544SJaegeuk Kim 
14539a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */
14639a53e0cSJaegeuk Kim struct fsync_inode_entry {
14739a53e0cSJaegeuk Kim 	struct list_head list;	/* list head */
14839a53e0cSJaegeuk Kim 	struct inode *inode;	/* vfs inode pointer */
149c52e1b10SJaegeuk Kim 	block_t blkaddr;	/* block address locating the last fsync */
150c52e1b10SJaegeuk Kim 	block_t last_dentry;	/* block address locating the last dentry */
151c52e1b10SJaegeuk Kim 	block_t last_inode;	/* block address locating the last inode */
15239a53e0cSJaegeuk Kim };
15339a53e0cSJaegeuk Kim 
15439a53e0cSJaegeuk Kim #define nats_in_cursum(sum)		(le16_to_cpu(sum->n_nats))
15539a53e0cSJaegeuk Kim #define sits_in_cursum(sum)		(le16_to_cpu(sum->n_sits))
15639a53e0cSJaegeuk Kim 
15739a53e0cSJaegeuk Kim #define nat_in_journal(sum, i)		(sum->nat_j.entries[i].ne)
15839a53e0cSJaegeuk Kim #define nid_in_journal(sum, i)		(sum->nat_j.entries[i].nid)
15939a53e0cSJaegeuk Kim #define sit_in_journal(sum, i)		(sum->sit_j.entries[i].se)
16039a53e0cSJaegeuk Kim #define segno_in_journal(sum, i)	(sum->sit_j.entries[i].segno)
16139a53e0cSJaegeuk Kim 
16239a53e0cSJaegeuk Kim static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
16339a53e0cSJaegeuk Kim {
16439a53e0cSJaegeuk Kim 	int before = nats_in_cursum(rs);
16539a53e0cSJaegeuk Kim 	rs->n_nats = cpu_to_le16(before + i);
16639a53e0cSJaegeuk Kim 	return before;
16739a53e0cSJaegeuk Kim }
16839a53e0cSJaegeuk Kim 
16939a53e0cSJaegeuk Kim static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
17039a53e0cSJaegeuk Kim {
17139a53e0cSJaegeuk Kim 	int before = sits_in_cursum(rs);
17239a53e0cSJaegeuk Kim 	rs->n_sits = cpu_to_le16(before + i);
17339a53e0cSJaegeuk Kim 	return before;
17439a53e0cSJaegeuk Kim }
17539a53e0cSJaegeuk Kim 
176184a5cd2SChao Yu static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size,
177184a5cd2SChao Yu 								int type)
178184a5cd2SChao Yu {
179184a5cd2SChao Yu 	if (type == NAT_JOURNAL)
180184a5cd2SChao Yu 		return nats_in_cursum(sum) + size <= NAT_JOURNAL_ENTRIES;
181184a5cd2SChao Yu 
182184a5cd2SChao Yu 	return sits_in_cursum(sum) + size <= SIT_JOURNAL_ENTRIES;
183184a5cd2SChao Yu }
184184a5cd2SChao Yu 
18539a53e0cSJaegeuk Kim /*
186e9750824SNamjae Jeon  * ioctl commands
187e9750824SNamjae Jeon  */
188e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS               FS_IOC_GETFLAGS
189e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS               FS_IOC_SETFLAGS
190e9750824SNamjae Jeon 
191e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
192e9750824SNamjae Jeon /*
193e9750824SNamjae Jeon  * ioctl commands in 32 bit emulation
194e9750824SNamjae Jeon  */
195e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS             FS_IOC32_GETFLAGS
196e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS             FS_IOC32_SETFLAGS
197e9750824SNamjae Jeon #endif
198e9750824SNamjae Jeon 
199e9750824SNamjae Jeon /*
20039a53e0cSJaegeuk Kim  * For INODE and NODE manager
20139a53e0cSJaegeuk Kim  */
202dbe6a5ffSJaegeuk Kim /*
203dbe6a5ffSJaegeuk Kim  * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
204dbe6a5ffSJaegeuk Kim  * as its node offset to distinguish from index node blocks.
205dbe6a5ffSJaegeuk Kim  * But some bits are used to mark the node block.
20639a53e0cSJaegeuk Kim  */
207dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET	((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
208dbe6a5ffSJaegeuk Kim 				>> OFFSET_BIT_SHIFT)
209266e97a8SJaegeuk Kim enum {
210266e97a8SJaegeuk Kim 	ALLOC_NODE,			/* allocate a new node page if needed */
211266e97a8SJaegeuk Kim 	LOOKUP_NODE,			/* look up a node without readahead */
212266e97a8SJaegeuk Kim 	LOOKUP_NODE_RA,			/*
213266e97a8SJaegeuk Kim 					 * look up a node with readahead called
2144f4124d0SChao Yu 					 * by get_data_block.
21539a53e0cSJaegeuk Kim 					 */
216266e97a8SJaegeuk Kim };
217266e97a8SJaegeuk Kim 
21839a53e0cSJaegeuk Kim #define F2FS_LINK_MAX		32000	/* maximum link count per file */
21939a53e0cSJaegeuk Kim 
220817202d9SChao Yu #define MAX_DIR_RA_PAGES	4	/* maximum ra pages of dir */
221817202d9SChao Yu 
22239a53e0cSJaegeuk Kim /* for in-memory extent cache entry */
223c11abd1aSJaegeuk Kim #define F2FS_MIN_EXTENT_LEN	16	/* minimum extent length */
224c11abd1aSJaegeuk Kim 
22539a53e0cSJaegeuk Kim struct extent_info {
22639a53e0cSJaegeuk Kim 	rwlock_t ext_lock;	/* rwlock for consistency */
22739a53e0cSJaegeuk Kim 	unsigned int fofs;	/* start offset in a file */
22839a53e0cSJaegeuk Kim 	u32 blk_addr;		/* start block address of the extent */
229111d2495SMasanari Iida 	unsigned int len;	/* length of the extent */
23039a53e0cSJaegeuk Kim };
23139a53e0cSJaegeuk Kim 
23239a53e0cSJaegeuk Kim /*
23339a53e0cSJaegeuk Kim  * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
23439a53e0cSJaegeuk Kim  */
23539a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT	0x01
236354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT	0x02
23739a53e0cSJaegeuk Kim 
238ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL		0
239ab9fa662SJaegeuk Kim 
24039a53e0cSJaegeuk Kim struct f2fs_inode_info {
24139a53e0cSJaegeuk Kim 	struct inode vfs_inode;		/* serve a vfs inode */
24239a53e0cSJaegeuk Kim 	unsigned long i_flags;		/* keep an inode flags for ioctl */
24339a53e0cSJaegeuk Kim 	unsigned char i_advise;		/* use to give file attribute hints */
24438431545SJaegeuk Kim 	unsigned char i_dir_level;	/* use for dentry level for large dir */
24539a53e0cSJaegeuk Kim 	unsigned int i_current_depth;	/* use only in directory structure */
2466666e6aaSJaegeuk Kim 	unsigned int i_pino;		/* parent inode number */
24739a53e0cSJaegeuk Kim 	umode_t i_acl_mode;		/* keep file acl mode temporarily */
24839a53e0cSJaegeuk Kim 
24939a53e0cSJaegeuk Kim 	/* Use below internally in f2fs*/
25039a53e0cSJaegeuk Kim 	unsigned long flags;		/* use to pass per-file flags */
251d928bfbfSJaegeuk Kim 	struct rw_semaphore i_sem;	/* protect fi info */
252a7ffdbe2SJaegeuk Kim 	atomic_t dirty_pages;		/* # of dirty pages */
25339a53e0cSJaegeuk Kim 	f2fs_hash_t chash;		/* hash value of given file name */
25439a53e0cSJaegeuk Kim 	unsigned int clevel;		/* maximum level of given file name */
25539a53e0cSJaegeuk Kim 	nid_t i_xattr_nid;		/* node id that contains xattrs */
256e518ff81SJaegeuk Kim 	unsigned long long xattr_ver;	/* cp version of xattr modification */
25739a53e0cSJaegeuk Kim 	struct extent_info ext;		/* in-memory extent cache entry */
258ed57c27fSJaegeuk Kim 	struct dir_inode_entry *dirty_dir;	/* the pointer of dirty dir */
25939a53e0cSJaegeuk Kim };
26039a53e0cSJaegeuk Kim 
26139a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext,
26239a53e0cSJaegeuk Kim 					struct f2fs_extent i_ext)
26339a53e0cSJaegeuk Kim {
26439a53e0cSJaegeuk Kim 	write_lock(&ext->ext_lock);
26539a53e0cSJaegeuk Kim 	ext->fofs = le32_to_cpu(i_ext.fofs);
26639a53e0cSJaegeuk Kim 	ext->blk_addr = le32_to_cpu(i_ext.blk_addr);
26739a53e0cSJaegeuk Kim 	ext->len = le32_to_cpu(i_ext.len);
26839a53e0cSJaegeuk Kim 	write_unlock(&ext->ext_lock);
26939a53e0cSJaegeuk Kim }
27039a53e0cSJaegeuk Kim 
27139a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext,
27239a53e0cSJaegeuk Kim 					struct f2fs_extent *i_ext)
27339a53e0cSJaegeuk Kim {
27439a53e0cSJaegeuk Kim 	read_lock(&ext->ext_lock);
27539a53e0cSJaegeuk Kim 	i_ext->fofs = cpu_to_le32(ext->fofs);
27639a53e0cSJaegeuk Kim 	i_ext->blk_addr = cpu_to_le32(ext->blk_addr);
27739a53e0cSJaegeuk Kim 	i_ext->len = cpu_to_le32(ext->len);
27839a53e0cSJaegeuk Kim 	read_unlock(&ext->ext_lock);
27939a53e0cSJaegeuk Kim }
28039a53e0cSJaegeuk Kim 
28139a53e0cSJaegeuk Kim struct f2fs_nm_info {
28239a53e0cSJaegeuk Kim 	block_t nat_blkaddr;		/* base disk address of NAT */
28339a53e0cSJaegeuk Kim 	nid_t max_nid;			/* maximum possible node ids */
2847ee0eeabSJaegeuk Kim 	nid_t available_nids;		/* maximum available node ids */
28539a53e0cSJaegeuk Kim 	nid_t next_scan_nid;		/* the next nid to be scanned */
286cdfc41c1SJaegeuk Kim 	unsigned int ram_thresh;	/* control the memory footprint */
28739a53e0cSJaegeuk Kim 
28839a53e0cSJaegeuk Kim 	/* NAT cache management */
28939a53e0cSJaegeuk Kim 	struct radix_tree_root nat_root;/* root of the nat entry cache */
29039a53e0cSJaegeuk Kim 	rwlock_t nat_tree_lock;		/* protect nat_tree_lock */
29139a53e0cSJaegeuk Kim 	unsigned int nat_cnt;		/* the # of cached nat entries */
29239a53e0cSJaegeuk Kim 	struct list_head nat_entries;	/* cached nat entry list (clean) */
29339a53e0cSJaegeuk Kim 	struct list_head dirty_nat_entries; /* cached nat entry list (dirty) */
294aec71382SChao Yu 	struct list_head nat_entry_set;	/* nat entry set list */
295aec71382SChao Yu 	unsigned int dirty_nat_cnt;	/* total num of nat entries in set */
29639a53e0cSJaegeuk Kim 
29739a53e0cSJaegeuk Kim 	/* free node ids management */
2988a7ed66aSJaegeuk Kim 	struct radix_tree_root free_nid_root;/* root of the free_nid cache */
29939a53e0cSJaegeuk Kim 	struct list_head free_nid_list;	/* a list for free nids */
30039a53e0cSJaegeuk Kim 	spinlock_t free_nid_list_lock;	/* protect free nid list */
30139a53e0cSJaegeuk Kim 	unsigned int fcnt;		/* the number of free node id */
30239a53e0cSJaegeuk Kim 	struct mutex build_lock;	/* lock for build free nids */
30339a53e0cSJaegeuk Kim 
30439a53e0cSJaegeuk Kim 	/* for checkpoint */
30539a53e0cSJaegeuk Kim 	char *nat_bitmap;		/* NAT bitmap pointer */
30639a53e0cSJaegeuk Kim 	int bitmap_size;		/* bitmap size */
30739a53e0cSJaegeuk Kim };
30839a53e0cSJaegeuk Kim 
30939a53e0cSJaegeuk Kim /*
31039a53e0cSJaegeuk Kim  * this structure is used as one of function parameters.
31139a53e0cSJaegeuk Kim  * all the information are dedicated to a given direct node block determined
31239a53e0cSJaegeuk Kim  * by the data offset in a file.
31339a53e0cSJaegeuk Kim  */
31439a53e0cSJaegeuk Kim struct dnode_of_data {
31539a53e0cSJaegeuk Kim 	struct inode *inode;		/* vfs inode pointer */
31639a53e0cSJaegeuk Kim 	struct page *inode_page;	/* its inode page, NULL is possible */
31739a53e0cSJaegeuk Kim 	struct page *node_page;		/* cached direct node page */
31839a53e0cSJaegeuk Kim 	nid_t nid;			/* node id of the direct node block */
31939a53e0cSJaegeuk Kim 	unsigned int ofs_in_node;	/* data offset in the node page */
32039a53e0cSJaegeuk Kim 	bool inode_page_locked;		/* inode page is locked or not */
32139a53e0cSJaegeuk Kim 	block_t	data_blkaddr;		/* block address of the node block */
32239a53e0cSJaegeuk Kim };
32339a53e0cSJaegeuk Kim 
32439a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
32539a53e0cSJaegeuk Kim 		struct page *ipage, struct page *npage, nid_t nid)
32639a53e0cSJaegeuk Kim {
327d66d1f76SJaegeuk Kim 	memset(dn, 0, sizeof(*dn));
32839a53e0cSJaegeuk Kim 	dn->inode = inode;
32939a53e0cSJaegeuk Kim 	dn->inode_page = ipage;
33039a53e0cSJaegeuk Kim 	dn->node_page = npage;
33139a53e0cSJaegeuk Kim 	dn->nid = nid;
33239a53e0cSJaegeuk Kim }
33339a53e0cSJaegeuk Kim 
33439a53e0cSJaegeuk Kim /*
33539a53e0cSJaegeuk Kim  * For SIT manager
33639a53e0cSJaegeuk Kim  *
33739a53e0cSJaegeuk Kim  * By default, there are 6 active log areas across the whole main area.
33839a53e0cSJaegeuk Kim  * When considering hot and cold data separation to reduce cleaning overhead,
33939a53e0cSJaegeuk Kim  * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
34039a53e0cSJaegeuk Kim  * respectively.
34139a53e0cSJaegeuk Kim  * In the current design, you should not change the numbers intentionally.
34239a53e0cSJaegeuk Kim  * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
34339a53e0cSJaegeuk Kim  * logs individually according to the underlying devices. (default: 6)
34439a53e0cSJaegeuk Kim  * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
34539a53e0cSJaegeuk Kim  * data and 8 for node logs.
34639a53e0cSJaegeuk Kim  */
34739a53e0cSJaegeuk Kim #define	NR_CURSEG_DATA_TYPE	(3)
34839a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE	(3)
34939a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE	(NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
35039a53e0cSJaegeuk Kim 
35139a53e0cSJaegeuk Kim enum {
35239a53e0cSJaegeuk Kim 	CURSEG_HOT_DATA	= 0,	/* directory entry blocks */
35339a53e0cSJaegeuk Kim 	CURSEG_WARM_DATA,	/* data blocks */
35439a53e0cSJaegeuk Kim 	CURSEG_COLD_DATA,	/* multimedia or GCed data blocks */
35539a53e0cSJaegeuk Kim 	CURSEG_HOT_NODE,	/* direct node blocks of directory files */
35639a53e0cSJaegeuk Kim 	CURSEG_WARM_NODE,	/* direct node blocks of normal files */
35739a53e0cSJaegeuk Kim 	CURSEG_COLD_NODE,	/* indirect node blocks */
35839a53e0cSJaegeuk Kim 	NO_CHECK_TYPE
35939a53e0cSJaegeuk Kim };
36039a53e0cSJaegeuk Kim 
3616b4afdd7SJaegeuk Kim struct flush_cmd {
3626b4afdd7SJaegeuk Kim 	struct completion wait;
363721bd4d5SGu Zheng 	struct llist_node llnode;
3646b4afdd7SJaegeuk Kim 	int ret;
3656b4afdd7SJaegeuk Kim };
3666b4afdd7SJaegeuk Kim 
367a688b9d9SGu Zheng struct flush_cmd_control {
368a688b9d9SGu Zheng 	struct task_struct *f2fs_issue_flush;	/* flush thread */
369a688b9d9SGu Zheng 	wait_queue_head_t flush_wait_queue;	/* waiting queue for wake-up */
370721bd4d5SGu Zheng 	struct llist_head issue_list;		/* list for command issue */
371721bd4d5SGu Zheng 	struct llist_node *dispatch_list;	/* list for command dispatch */
372a688b9d9SGu Zheng };
373a688b9d9SGu Zheng 
37439a53e0cSJaegeuk Kim struct f2fs_sm_info {
37539a53e0cSJaegeuk Kim 	struct sit_info *sit_info;		/* whole segment information */
37639a53e0cSJaegeuk Kim 	struct free_segmap_info *free_info;	/* free segment information */
37739a53e0cSJaegeuk Kim 	struct dirty_seglist_info *dirty_info;	/* dirty segment information */
37839a53e0cSJaegeuk Kim 	struct curseg_info *curseg_array;	/* active segment information */
37939a53e0cSJaegeuk Kim 
38039a53e0cSJaegeuk Kim 	block_t seg0_blkaddr;		/* block address of 0'th segment */
38139a53e0cSJaegeuk Kim 	block_t main_blkaddr;		/* start block address of main area */
38239a53e0cSJaegeuk Kim 	block_t ssa_blkaddr;		/* start block address of SSA area */
38339a53e0cSJaegeuk Kim 
38439a53e0cSJaegeuk Kim 	unsigned int segment_count;	/* total # of segments */
38539a53e0cSJaegeuk Kim 	unsigned int main_segments;	/* # of segments in main area */
38639a53e0cSJaegeuk Kim 	unsigned int reserved_segments;	/* # of reserved segments */
38739a53e0cSJaegeuk Kim 	unsigned int ovp_segments;	/* # of overprovision segments */
38881eb8d6eSJaegeuk Kim 
38981eb8d6eSJaegeuk Kim 	/* a threshold to reclaim prefree segments */
39081eb8d6eSJaegeuk Kim 	unsigned int rec_prefree_segments;
3917fd9e544SJaegeuk Kim 
3927fd9e544SJaegeuk Kim 	/* for small discard management */
3937fd9e544SJaegeuk Kim 	struct list_head discard_list;		/* 4KB discard list */
3947fd9e544SJaegeuk Kim 	int nr_discards;			/* # of discards in the list */
3957fd9e544SJaegeuk Kim 	int max_discards;			/* max. discards to be issued */
396216fbd64SJaegeuk Kim 
397184a5cd2SChao Yu 	struct list_head sit_entry_set;	/* sit entry set list */
398184a5cd2SChao Yu 
399216fbd64SJaegeuk Kim 	unsigned int ipu_policy;	/* in-place-update policy */
400216fbd64SJaegeuk Kim 	unsigned int min_ipu_util;	/* in-place-update threshold */
401c1ce1b02SJaegeuk Kim 	unsigned int min_fsync_blocks;	/* threshold for fsync */
4026b4afdd7SJaegeuk Kim 
4036b4afdd7SJaegeuk Kim 	/* for flush command control */
404a688b9d9SGu Zheng 	struct flush_cmd_control *cmd_control_info;
405a688b9d9SGu Zheng 
40639a53e0cSJaegeuk Kim };
40739a53e0cSJaegeuk Kim 
40839a53e0cSJaegeuk Kim /*
40939a53e0cSJaegeuk Kim  * For superblock
41039a53e0cSJaegeuk Kim  */
41139a53e0cSJaegeuk Kim /*
41239a53e0cSJaegeuk Kim  * COUNT_TYPE for monitoring
41339a53e0cSJaegeuk Kim  *
41439a53e0cSJaegeuk Kim  * f2fs monitors the number of several block types such as on-writeback,
41539a53e0cSJaegeuk Kim  * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
41639a53e0cSJaegeuk Kim  */
41739a53e0cSJaegeuk Kim enum count_type {
41839a53e0cSJaegeuk Kim 	F2FS_WRITEBACK,
41939a53e0cSJaegeuk Kim 	F2FS_DIRTY_DENTS,
42039a53e0cSJaegeuk Kim 	F2FS_DIRTY_NODES,
42139a53e0cSJaegeuk Kim 	F2FS_DIRTY_META,
42239a53e0cSJaegeuk Kim 	NR_COUNT_TYPE,
42339a53e0cSJaegeuk Kim };
42439a53e0cSJaegeuk Kim 
42539a53e0cSJaegeuk Kim /*
426e1c42045Sarter97  * The below are the page types of bios used in submit_bio().
42739a53e0cSJaegeuk Kim  * The available types are:
42839a53e0cSJaegeuk Kim  * DATA			User data pages. It operates as async mode.
42939a53e0cSJaegeuk Kim  * NODE			Node pages. It operates as async mode.
43039a53e0cSJaegeuk Kim  * META			FS metadata pages such as SIT, NAT, CP.
43139a53e0cSJaegeuk Kim  * NR_PAGE_TYPE		The number of page types.
43239a53e0cSJaegeuk Kim  * META_FLUSH		Make sure the previous pages are written
43339a53e0cSJaegeuk Kim  *			with waiting the bio's completion
43439a53e0cSJaegeuk Kim  * ...			Only can be used with META.
43539a53e0cSJaegeuk Kim  */
4367d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type)	((type) > META ? META : (type))
43739a53e0cSJaegeuk Kim enum page_type {
43839a53e0cSJaegeuk Kim 	DATA,
43939a53e0cSJaegeuk Kim 	NODE,
44039a53e0cSJaegeuk Kim 	META,
44139a53e0cSJaegeuk Kim 	NR_PAGE_TYPE,
44239a53e0cSJaegeuk Kim 	META_FLUSH,
44339a53e0cSJaegeuk Kim };
44439a53e0cSJaegeuk Kim 
445458e6197SJaegeuk Kim struct f2fs_io_info {
446458e6197SJaegeuk Kim 	enum page_type type;	/* contains DATA/NODE/META/META_FLUSH */
4477e8f2308SGu Zheng 	int rw;			/* contains R/RS/W/WS with REQ_META/REQ_PRIO */
448458e6197SJaegeuk Kim };
449458e6197SJaegeuk Kim 
45093dfe2acSJaegeuk Kim #define is_read_io(rw)	(((rw) & 1) == READ)
4511ff7bd3bSJaegeuk Kim struct f2fs_bio_info {
452458e6197SJaegeuk Kim 	struct f2fs_sb_info *sbi;	/* f2fs superblock */
4531ff7bd3bSJaegeuk Kim 	struct bio *bio;		/* bios to merge */
4541ff7bd3bSJaegeuk Kim 	sector_t last_block_in_bio;	/* last block number */
455458e6197SJaegeuk Kim 	struct f2fs_io_info fio;	/* store buffered io info. */
456df0f8dc0SChao Yu 	struct rw_semaphore io_rwsem;	/* blocking op for bio */
4571ff7bd3bSJaegeuk Kim };
4581ff7bd3bSJaegeuk Kim 
45939a53e0cSJaegeuk Kim struct f2fs_sb_info {
46039a53e0cSJaegeuk Kim 	struct super_block *sb;			/* pointer to VFS super block */
4615e176d54SJaegeuk Kim 	struct proc_dir_entry *s_proc;		/* proc entry */
46239a53e0cSJaegeuk Kim 	struct buffer_head *raw_super_buf;	/* buffer head of raw sb */
46339a53e0cSJaegeuk Kim 	struct f2fs_super_block *raw_super;	/* raw super block pointer */
46439a53e0cSJaegeuk Kim 	int s_dirty;				/* dirty flag for checkpoint */
4652ae4c673SJaegeuk Kim 	bool need_fsck;				/* need fsck.f2fs to fix */
46639a53e0cSJaegeuk Kim 
46739a53e0cSJaegeuk Kim 	/* for node-related operations */
46839a53e0cSJaegeuk Kim 	struct f2fs_nm_info *nm_info;		/* node manager */
46939a53e0cSJaegeuk Kim 	struct inode *node_inode;		/* cache node blocks */
47039a53e0cSJaegeuk Kim 
47139a53e0cSJaegeuk Kim 	/* for segment-related operations */
47239a53e0cSJaegeuk Kim 	struct f2fs_sm_info *sm_info;		/* segment manager */
4731ff7bd3bSJaegeuk Kim 
4741ff7bd3bSJaegeuk Kim 	/* for bio operations */
475924b720bSChao Yu 	struct f2fs_bio_info read_io;			/* for read bios */
4761ff7bd3bSJaegeuk Kim 	struct f2fs_bio_info write_io[NR_PAGE_TYPE];	/* for write bios */
4771b1f559fSJaegeuk Kim 	struct completion *wait_io;		/* for completion bios */
47839a53e0cSJaegeuk Kim 
47939a53e0cSJaegeuk Kim 	/* for checkpoint */
48039a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt;		/* raw checkpoint pointer */
48139a53e0cSJaegeuk Kim 	struct inode *meta_inode;		/* cache meta blocks */
48239936837SJaegeuk Kim 	struct mutex cp_mutex;			/* checkpoint procedure lock */
483e479556bSGu Zheng 	struct rw_semaphore cp_rwsem;		/* blocking FS operations */
484b3582c68SChao Yu 	struct rw_semaphore node_write;		/* locking node writes */
48539a53e0cSJaegeuk Kim 	struct mutex writepages;		/* mutex for writepages() */
486aabe5136SHaicheng Li 	bool por_doing;				/* recovery is doing or not */
487fb51b5efSChangman Lee 	wait_queue_head_t cp_wait;
48839a53e0cSJaegeuk Kim 
4896451e041SJaegeuk Kim 	/* for inode management */
49039efac41SJaegeuk Kim 	struct radix_tree_root ino_root[MAX_INO_ENTRY];	/* ino entry array */
4916451e041SJaegeuk Kim 	spinlock_t ino_lock[MAX_INO_ENTRY];		/* for ino entry lock */
4926451e041SJaegeuk Kim 	struct list_head ino_list[MAX_INO_ENTRY];	/* inode list head */
4936451e041SJaegeuk Kim 
4946451e041SJaegeuk Kim 	/* for orphan inode, use 0'th array */
49539a53e0cSJaegeuk Kim 	unsigned int n_orphans;			/* # of orphan inodes */
4960d47c1adSGu Zheng 	unsigned int max_orphans;		/* max orphan inodes */
49739a53e0cSJaegeuk Kim 
49839a53e0cSJaegeuk Kim 	/* for directory inode management */
49939a53e0cSJaegeuk Kim 	struct list_head dir_inode_list;	/* dir inode list */
50039a53e0cSJaegeuk Kim 	spinlock_t dir_inode_lock;		/* for dir inode list lock */
50139a53e0cSJaegeuk Kim 
50239a53e0cSJaegeuk Kim 	/* basic filesystem units */
50339a53e0cSJaegeuk Kim 	unsigned int log_sectors_per_block;	/* log2 sectors per block */
50439a53e0cSJaegeuk Kim 	unsigned int log_blocksize;		/* log2 block size */
50539a53e0cSJaegeuk Kim 	unsigned int blocksize;			/* block size */
50639a53e0cSJaegeuk Kim 	unsigned int root_ino_num;		/* root inode number*/
50739a53e0cSJaegeuk Kim 	unsigned int node_ino_num;		/* node inode number*/
50839a53e0cSJaegeuk Kim 	unsigned int meta_ino_num;		/* meta inode number*/
50939a53e0cSJaegeuk Kim 	unsigned int log_blocks_per_seg;	/* log2 blocks per segment */
51039a53e0cSJaegeuk Kim 	unsigned int blocks_per_seg;		/* blocks per segment */
51139a53e0cSJaegeuk Kim 	unsigned int segs_per_sec;		/* segments per section */
51239a53e0cSJaegeuk Kim 	unsigned int secs_per_zone;		/* sections per zone */
51339a53e0cSJaegeuk Kim 	unsigned int total_sections;		/* total section count */
51439a53e0cSJaegeuk Kim 	unsigned int total_node_count;		/* total node block count */
51539a53e0cSJaegeuk Kim 	unsigned int total_valid_node_count;	/* valid node block count */
51639a53e0cSJaegeuk Kim 	unsigned int total_valid_inode_count;	/* valid inode count */
51739a53e0cSJaegeuk Kim 	int active_logs;			/* # of active logs */
518ab9fa662SJaegeuk Kim 	int dir_level;				/* directory level */
51939a53e0cSJaegeuk Kim 
52039a53e0cSJaegeuk Kim 	block_t user_block_count;		/* # of user blocks */
52139a53e0cSJaegeuk Kim 	block_t total_valid_block_count;	/* # of valid blocks */
52239a53e0cSJaegeuk Kim 	block_t alloc_valid_block_count;	/* # of allocated blocks */
52339a53e0cSJaegeuk Kim 	block_t last_valid_block_count;		/* for recovery */
52439a53e0cSJaegeuk Kim 	u32 s_next_generation;			/* for NFS support */
52539a53e0cSJaegeuk Kim 	atomic_t nr_pages[NR_COUNT_TYPE];	/* # of pages, see count_type */
52639a53e0cSJaegeuk Kim 
52739a53e0cSJaegeuk Kim 	struct f2fs_mount_info mount_opt;	/* mount options */
52839a53e0cSJaegeuk Kim 
52939a53e0cSJaegeuk Kim 	/* for cleaning operations */
53039a53e0cSJaegeuk Kim 	struct mutex gc_mutex;			/* mutex for GC */
53139a53e0cSJaegeuk Kim 	struct f2fs_gc_kthread	*gc_thread;	/* GC thread */
5325ec4e49fSJaegeuk Kim 	unsigned int cur_victim_sec;		/* current victim section num */
53339a53e0cSJaegeuk Kim 
534b1c57c1cSJaegeuk Kim 	/* maximum # of trials to find a victim segment for SSR and GC */
535b1c57c1cSJaegeuk Kim 	unsigned int max_victim_search;
536b1c57c1cSJaegeuk Kim 
53739a53e0cSJaegeuk Kim 	/*
53839a53e0cSJaegeuk Kim 	 * for stat information.
53939a53e0cSJaegeuk Kim 	 * one is for the LFS mode, and the other is for the SSR mode.
54039a53e0cSJaegeuk Kim 	 */
54135b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS
54239a53e0cSJaegeuk Kim 	struct f2fs_stat_info *stat_info;	/* FS status information */
54339a53e0cSJaegeuk Kim 	unsigned int segment_count[2];		/* # of allocated segments */
54439a53e0cSJaegeuk Kim 	unsigned int block_count[2];		/* # of allocated blocks */
54539a53e0cSJaegeuk Kim 	int total_hit_ext, read_hit_ext;	/* extent cache hit ratio */
5460dbdc2aeSJaegeuk Kim 	int inline_inode;			/* # of inline_data inodes */
54739a53e0cSJaegeuk Kim 	int bg_gc;				/* background gc calls */
54835b09d82SNamjae Jeon 	unsigned int n_dirty_dirs;		/* # of dir inodes */
54935b09d82SNamjae Jeon #endif
55035b09d82SNamjae Jeon 	unsigned int last_victim[2];		/* last victim segment # */
55139a53e0cSJaegeuk Kim 	spinlock_t stat_lock;			/* lock for stat operations */
552b59d0baeSNamjae Jeon 
553b59d0baeSNamjae Jeon 	/* For sysfs suppport */
554b59d0baeSNamjae Jeon 	struct kobject s_kobj;
555b59d0baeSNamjae Jeon 	struct completion s_kobj_unregister;
55639a53e0cSJaegeuk Kim };
55739a53e0cSJaegeuk Kim 
55839a53e0cSJaegeuk Kim /*
55939a53e0cSJaegeuk Kim  * Inline functions
56039a53e0cSJaegeuk Kim  */
56139a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
56239a53e0cSJaegeuk Kim {
56339a53e0cSJaegeuk Kim 	return container_of(inode, struct f2fs_inode_info, vfs_inode);
56439a53e0cSJaegeuk Kim }
56539a53e0cSJaegeuk Kim 
56639a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
56739a53e0cSJaegeuk Kim {
56839a53e0cSJaegeuk Kim 	return sb->s_fs_info;
56939a53e0cSJaegeuk Kim }
57039a53e0cSJaegeuk Kim 
5714081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
5724081363fSJaegeuk Kim {
5734081363fSJaegeuk Kim 	return F2FS_SB(inode->i_sb);
5744081363fSJaegeuk Kim }
5754081363fSJaegeuk Kim 
5764081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
5774081363fSJaegeuk Kim {
5784081363fSJaegeuk Kim 	return F2FS_I_SB(mapping->host);
5794081363fSJaegeuk Kim }
5804081363fSJaegeuk Kim 
5814081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
5824081363fSJaegeuk Kim {
5834081363fSJaegeuk Kim 	return F2FS_M_SB(page->mapping);
5844081363fSJaegeuk Kim }
5854081363fSJaegeuk Kim 
58639a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
58739a53e0cSJaegeuk Kim {
58839a53e0cSJaegeuk Kim 	return (struct f2fs_super_block *)(sbi->raw_super);
58939a53e0cSJaegeuk Kim }
59039a53e0cSJaegeuk Kim 
59139a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
59239a53e0cSJaegeuk Kim {
59339a53e0cSJaegeuk Kim 	return (struct f2fs_checkpoint *)(sbi->ckpt);
59439a53e0cSJaegeuk Kim }
59539a53e0cSJaegeuk Kim 
59645590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page)
59745590710SGu Zheng {
59845590710SGu Zheng 	return (struct f2fs_node *)page_address(page);
59945590710SGu Zheng }
60045590710SGu Zheng 
60158bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page)
60258bfaf44SJaegeuk Kim {
60358bfaf44SJaegeuk Kim 	return &((struct f2fs_node *)page_address(page))->i;
60458bfaf44SJaegeuk Kim }
60558bfaf44SJaegeuk Kim 
60639a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
60739a53e0cSJaegeuk Kim {
60839a53e0cSJaegeuk Kim 	return (struct f2fs_nm_info *)(sbi->nm_info);
60939a53e0cSJaegeuk Kim }
61039a53e0cSJaegeuk Kim 
61139a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
61239a53e0cSJaegeuk Kim {
61339a53e0cSJaegeuk Kim 	return (struct f2fs_sm_info *)(sbi->sm_info);
61439a53e0cSJaegeuk Kim }
61539a53e0cSJaegeuk Kim 
61639a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
61739a53e0cSJaegeuk Kim {
61839a53e0cSJaegeuk Kim 	return (struct sit_info *)(SM_I(sbi)->sit_info);
61939a53e0cSJaegeuk Kim }
62039a53e0cSJaegeuk Kim 
62139a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
62239a53e0cSJaegeuk Kim {
62339a53e0cSJaegeuk Kim 	return (struct free_segmap_info *)(SM_I(sbi)->free_info);
62439a53e0cSJaegeuk Kim }
62539a53e0cSJaegeuk Kim 
62639a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
62739a53e0cSJaegeuk Kim {
62839a53e0cSJaegeuk Kim 	return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
62939a53e0cSJaegeuk Kim }
63039a53e0cSJaegeuk Kim 
6319df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
6329df27d98SGu Zheng {
6339df27d98SGu Zheng 	return sbi->meta_inode->i_mapping;
6349df27d98SGu Zheng }
6359df27d98SGu Zheng 
6364ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
6374ef51a8fSJaegeuk Kim {
6384ef51a8fSJaegeuk Kim 	return sbi->node_inode->i_mapping;
6394ef51a8fSJaegeuk Kim }
6404ef51a8fSJaegeuk Kim 
64139a53e0cSJaegeuk Kim static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
64239a53e0cSJaegeuk Kim {
64339a53e0cSJaegeuk Kim 	sbi->s_dirty = 1;
64439a53e0cSJaegeuk Kim }
64539a53e0cSJaegeuk Kim 
64639a53e0cSJaegeuk Kim static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
64739a53e0cSJaegeuk Kim {
64839a53e0cSJaegeuk Kim 	sbi->s_dirty = 0;
64939a53e0cSJaegeuk Kim }
65039a53e0cSJaegeuk Kim 
651d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
652d71b5564SJaegeuk Kim {
653d71b5564SJaegeuk Kim 	return le64_to_cpu(cp->checkpoint_ver);
654d71b5564SJaegeuk Kim }
655d71b5564SJaegeuk Kim 
65625ca923bSJaegeuk Kim static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
65725ca923bSJaegeuk Kim {
65825ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
65925ca923bSJaegeuk Kim 	return ckpt_flags & f;
66025ca923bSJaegeuk Kim }
66125ca923bSJaegeuk Kim 
66225ca923bSJaegeuk Kim static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
66325ca923bSJaegeuk Kim {
66425ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
66525ca923bSJaegeuk Kim 	ckpt_flags |= f;
66625ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
66725ca923bSJaegeuk Kim }
66825ca923bSJaegeuk Kim 
66925ca923bSJaegeuk Kim static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
67025ca923bSJaegeuk Kim {
67125ca923bSJaegeuk Kim 	unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
67225ca923bSJaegeuk Kim 	ckpt_flags &= (~f);
67325ca923bSJaegeuk Kim 	cp->ckpt_flags = cpu_to_le32(ckpt_flags);
67425ca923bSJaegeuk Kim }
67525ca923bSJaegeuk Kim 
676e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
67739a53e0cSJaegeuk Kim {
678e479556bSGu Zheng 	down_read(&sbi->cp_rwsem);
67939a53e0cSJaegeuk Kim }
68039a53e0cSJaegeuk Kim 
681e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
68239a53e0cSJaegeuk Kim {
683e479556bSGu Zheng 	up_read(&sbi->cp_rwsem);
68439936837SJaegeuk Kim }
68539936837SJaegeuk Kim 
686e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
68739936837SJaegeuk Kim {
6880daaad97SJaegeuk Kim 	f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex);
68939936837SJaegeuk Kim }
69039936837SJaegeuk Kim 
691e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
69239936837SJaegeuk Kim {
693e479556bSGu Zheng 	up_write(&sbi->cp_rwsem);
69439a53e0cSJaegeuk Kim }
69539a53e0cSJaegeuk Kim 
69639a53e0cSJaegeuk Kim /*
69739a53e0cSJaegeuk Kim  * Check whether the given nid is within node id range.
69839a53e0cSJaegeuk Kim  */
699064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
70039a53e0cSJaegeuk Kim {
701d6b7d4b3SChao Yu 	if (unlikely(nid < F2FS_ROOT_INO(sbi)))
702d6b7d4b3SChao Yu 		return -EINVAL;
703cfb271d4SChao Yu 	if (unlikely(nid >= NM_I(sbi)->max_nid))
704064e0823SNamjae Jeon 		return -EINVAL;
705064e0823SNamjae Jeon 	return 0;
70639a53e0cSJaegeuk Kim }
70739a53e0cSJaegeuk Kim 
70839a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS	1
70939a53e0cSJaegeuk Kim 
71039a53e0cSJaegeuk Kim /*
71139a53e0cSJaegeuk Kim  * Check whether the inode has blocks or not
71239a53e0cSJaegeuk Kim  */
71339a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode)
71439a53e0cSJaegeuk Kim {
71539a53e0cSJaegeuk Kim 	if (F2FS_I(inode)->i_xattr_nid)
7166c311ec6SChris Fries 		return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
71739a53e0cSJaegeuk Kim 	else
7186c311ec6SChris Fries 		return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
71939a53e0cSJaegeuk Kim }
72039a53e0cSJaegeuk Kim 
7214bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs)
7224bc8e9bcSChao Yu {
7234bc8e9bcSChao Yu 	return ofs == XATTR_NODE_OFFSET;
7244bc8e9bcSChao Yu }
7254bc8e9bcSChao Yu 
72639a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
72739a53e0cSJaegeuk Kim 				 struct inode *inode, blkcnt_t count)
72839a53e0cSJaegeuk Kim {
72939a53e0cSJaegeuk Kim 	block_t	valid_block_count;
73039a53e0cSJaegeuk Kim 
73139a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
73239a53e0cSJaegeuk Kim 	valid_block_count =
73339a53e0cSJaegeuk Kim 		sbi->total_valid_block_count + (block_t)count;
734cfb271d4SChao Yu 	if (unlikely(valid_block_count > sbi->user_block_count)) {
73539a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
73639a53e0cSJaegeuk Kim 		return false;
73739a53e0cSJaegeuk Kim 	}
73839a53e0cSJaegeuk Kim 	inode->i_blocks += count;
73939a53e0cSJaegeuk Kim 	sbi->total_valid_block_count = valid_block_count;
74039a53e0cSJaegeuk Kim 	sbi->alloc_valid_block_count += (block_t)count;
74139a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
74239a53e0cSJaegeuk Kim 	return true;
74339a53e0cSJaegeuk Kim }
74439a53e0cSJaegeuk Kim 
745da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
74639a53e0cSJaegeuk Kim 						struct inode *inode,
74739a53e0cSJaegeuk Kim 						blkcnt_t count)
74839a53e0cSJaegeuk Kim {
74939a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
7509850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
7519850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, inode->i_blocks < count);
75239a53e0cSJaegeuk Kim 	inode->i_blocks -= count;
75339a53e0cSJaegeuk Kim 	sbi->total_valid_block_count -= (block_t)count;
75439a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
75539a53e0cSJaegeuk Kim }
75639a53e0cSJaegeuk Kim 
75739a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
75839a53e0cSJaegeuk Kim {
75939a53e0cSJaegeuk Kim 	atomic_inc(&sbi->nr_pages[count_type]);
76039a53e0cSJaegeuk Kim 	F2FS_SET_SB_DIRT(sbi);
76139a53e0cSJaegeuk Kim }
76239a53e0cSJaegeuk Kim 
763a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode)
76439a53e0cSJaegeuk Kim {
765a7ffdbe2SJaegeuk Kim 	atomic_inc(&F2FS_I(inode)->dirty_pages);
766a7ffdbe2SJaegeuk Kim 	if (S_ISDIR(inode->i_mode))
7674081363fSJaegeuk Kim 		inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
76839a53e0cSJaegeuk Kim }
76939a53e0cSJaegeuk Kim 
77039a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
77139a53e0cSJaegeuk Kim {
77239a53e0cSJaegeuk Kim 	atomic_dec(&sbi->nr_pages[count_type]);
77339a53e0cSJaegeuk Kim }
77439a53e0cSJaegeuk Kim 
775a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode)
77639a53e0cSJaegeuk Kim {
777a7ffdbe2SJaegeuk Kim 	if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode))
7781fe54f9dSJaegeuk Kim 		return;
7791fe54f9dSJaegeuk Kim 
780a7ffdbe2SJaegeuk Kim 	atomic_dec(&F2FS_I(inode)->dirty_pages);
781a7ffdbe2SJaegeuk Kim 
782a7ffdbe2SJaegeuk Kim 	if (S_ISDIR(inode->i_mode))
7834081363fSJaegeuk Kim 		dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
78439a53e0cSJaegeuk Kim }
78539a53e0cSJaegeuk Kim 
78639a53e0cSJaegeuk Kim static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
78739a53e0cSJaegeuk Kim {
78839a53e0cSJaegeuk Kim 	return atomic_read(&sbi->nr_pages[count_type]);
78939a53e0cSJaegeuk Kim }
79039a53e0cSJaegeuk Kim 
791a7ffdbe2SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode)
792f8b2c1f9SJaegeuk Kim {
793a7ffdbe2SJaegeuk Kim 	return atomic_read(&F2FS_I(inode)->dirty_pages);
794f8b2c1f9SJaegeuk Kim }
795f8b2c1f9SJaegeuk Kim 
7965ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
7975ac206cfSNamjae Jeon {
7985ac206cfSNamjae Jeon 	unsigned int pages_per_sec = sbi->segs_per_sec *
7995ac206cfSNamjae Jeon 					(1 << sbi->log_blocks_per_seg);
8005ac206cfSNamjae Jeon 	return ((get_pages(sbi, block_type) + pages_per_sec - 1)
8015ac206cfSNamjae Jeon 			>> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
8025ac206cfSNamjae Jeon }
8035ac206cfSNamjae Jeon 
80439a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
80539a53e0cSJaegeuk Kim {
8068b8343faSJaegeuk Kim 	return sbi->total_valid_block_count;
80739a53e0cSJaegeuk Kim }
80839a53e0cSJaegeuk Kim 
80939a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
81039a53e0cSJaegeuk Kim {
81139a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
81239a53e0cSJaegeuk Kim 
81339a53e0cSJaegeuk Kim 	/* return NAT or SIT bitmap */
81439a53e0cSJaegeuk Kim 	if (flag == NAT_BITMAP)
81539a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
81639a53e0cSJaegeuk Kim 	else if (flag == SIT_BITMAP)
81739a53e0cSJaegeuk Kim 		return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
81839a53e0cSJaegeuk Kim 
81939a53e0cSJaegeuk Kim 	return 0;
82039a53e0cSJaegeuk Kim }
82139a53e0cSJaegeuk Kim 
82239a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
82339a53e0cSJaegeuk Kim {
82439a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
8251dbe4152SChangman Lee 	int offset;
8261dbe4152SChangman Lee 
8271dbe4152SChangman Lee 	if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload) > 0) {
8281dbe4152SChangman Lee 		if (flag == NAT_BITMAP)
8291dbe4152SChangman Lee 			return &ckpt->sit_nat_version_bitmap;
8301dbe4152SChangman Lee 		else
83165b85cccSJaegeuk Kim 			return (unsigned char *)ckpt + F2FS_BLKSIZE;
8321dbe4152SChangman Lee 	} else {
8331dbe4152SChangman Lee 		offset = (flag == NAT_BITMAP) ?
83425ca923bSJaegeuk Kim 			le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
83539a53e0cSJaegeuk Kim 		return &ckpt->sit_nat_version_bitmap + offset;
83639a53e0cSJaegeuk Kim 	}
8371dbe4152SChangman Lee }
83839a53e0cSJaegeuk Kim 
83939a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
84039a53e0cSJaegeuk Kim {
84139a53e0cSJaegeuk Kim 	block_t start_addr;
84239a53e0cSJaegeuk Kim 	struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
843d71b5564SJaegeuk Kim 	unsigned long long ckpt_version = cur_cp_version(ckpt);
84439a53e0cSJaegeuk Kim 
84525ca923bSJaegeuk Kim 	start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
84639a53e0cSJaegeuk Kim 
84739a53e0cSJaegeuk Kim 	/*
84839a53e0cSJaegeuk Kim 	 * odd numbered checkpoint should at cp segment 0
849e1c42045Sarter97 	 * and even segment must be at cp segment 1
85039a53e0cSJaegeuk Kim 	 */
85139a53e0cSJaegeuk Kim 	if (!(ckpt_version & 1))
85239a53e0cSJaegeuk Kim 		start_addr += sbi->blocks_per_seg;
85339a53e0cSJaegeuk Kim 
85439a53e0cSJaegeuk Kim 	return start_addr;
85539a53e0cSJaegeuk Kim }
85639a53e0cSJaegeuk Kim 
85739a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
85839a53e0cSJaegeuk Kim {
85939a53e0cSJaegeuk Kim 	return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
86039a53e0cSJaegeuk Kim }
86139a53e0cSJaegeuk Kim 
86239a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
863ef86d709SGu Zheng 						struct inode *inode)
86439a53e0cSJaegeuk Kim {
86539a53e0cSJaegeuk Kim 	block_t	valid_block_count;
86639a53e0cSJaegeuk Kim 	unsigned int valid_node_count;
86739a53e0cSJaegeuk Kim 
86839a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
86939a53e0cSJaegeuk Kim 
870ef86d709SGu Zheng 	valid_block_count = sbi->total_valid_block_count + 1;
871cfb271d4SChao Yu 	if (unlikely(valid_block_count > sbi->user_block_count)) {
87239a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
87339a53e0cSJaegeuk Kim 		return false;
87439a53e0cSJaegeuk Kim 	}
87539a53e0cSJaegeuk Kim 
876ef86d709SGu Zheng 	valid_node_count = sbi->total_valid_node_count + 1;
877cfb271d4SChao Yu 	if (unlikely(valid_node_count > sbi->total_node_count)) {
87839a53e0cSJaegeuk Kim 		spin_unlock(&sbi->stat_lock);
87939a53e0cSJaegeuk Kim 		return false;
88039a53e0cSJaegeuk Kim 	}
88139a53e0cSJaegeuk Kim 
88239a53e0cSJaegeuk Kim 	if (inode)
883ef86d709SGu Zheng 		inode->i_blocks++;
884ef86d709SGu Zheng 
885ef86d709SGu Zheng 	sbi->alloc_valid_block_count++;
886ef86d709SGu Zheng 	sbi->total_valid_node_count++;
887ef86d709SGu Zheng 	sbi->total_valid_block_count++;
88839a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
88939a53e0cSJaegeuk Kim 
89039a53e0cSJaegeuk Kim 	return true;
89139a53e0cSJaegeuk Kim }
89239a53e0cSJaegeuk Kim 
89339a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
894ef86d709SGu Zheng 						struct inode *inode)
89539a53e0cSJaegeuk Kim {
89639a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
89739a53e0cSJaegeuk Kim 
8989850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_block_count);
8999850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_node_count);
9009850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !inode->i_blocks);
90139a53e0cSJaegeuk Kim 
902ef86d709SGu Zheng 	inode->i_blocks--;
903ef86d709SGu Zheng 	sbi->total_valid_node_count--;
904ef86d709SGu Zheng 	sbi->total_valid_block_count--;
90539a53e0cSJaegeuk Kim 
90639a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
90739a53e0cSJaegeuk Kim }
90839a53e0cSJaegeuk Kim 
90939a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
91039a53e0cSJaegeuk Kim {
9118b8343faSJaegeuk Kim 	return sbi->total_valid_node_count;
91239a53e0cSJaegeuk Kim }
91339a53e0cSJaegeuk Kim 
91439a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
91539a53e0cSJaegeuk Kim {
91639a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
9179850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count);
91839a53e0cSJaegeuk Kim 	sbi->total_valid_inode_count++;
91939a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
92039a53e0cSJaegeuk Kim }
92139a53e0cSJaegeuk Kim 
9220e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
92339a53e0cSJaegeuk Kim {
92439a53e0cSJaegeuk Kim 	spin_lock(&sbi->stat_lock);
9259850cf4aSJaegeuk Kim 	f2fs_bug_on(sbi, !sbi->total_valid_inode_count);
92639a53e0cSJaegeuk Kim 	sbi->total_valid_inode_count--;
92739a53e0cSJaegeuk Kim 	spin_unlock(&sbi->stat_lock);
92839a53e0cSJaegeuk Kim }
92939a53e0cSJaegeuk Kim 
93039a53e0cSJaegeuk Kim static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
93139a53e0cSJaegeuk Kim {
9328b8343faSJaegeuk Kim 	return sbi->total_valid_inode_count;
93339a53e0cSJaegeuk Kim }
93439a53e0cSJaegeuk Kim 
93539a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock)
93639a53e0cSJaegeuk Kim {
937031fa8ccSJaegeuk Kim 	if (!page)
93839a53e0cSJaegeuk Kim 		return;
93939a53e0cSJaegeuk Kim 
94039a53e0cSJaegeuk Kim 	if (unlock) {
9419850cf4aSJaegeuk Kim 		f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
94239a53e0cSJaegeuk Kim 		unlock_page(page);
94339a53e0cSJaegeuk Kim 	}
94439a53e0cSJaegeuk Kim 	page_cache_release(page);
94539a53e0cSJaegeuk Kim }
94639a53e0cSJaegeuk Kim 
94739a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn)
94839a53e0cSJaegeuk Kim {
94939a53e0cSJaegeuk Kim 	if (dn->node_page)
95039a53e0cSJaegeuk Kim 		f2fs_put_page(dn->node_page, 1);
95139a53e0cSJaegeuk Kim 	if (dn->inode_page && dn->node_page != dn->inode_page)
95239a53e0cSJaegeuk Kim 		f2fs_put_page(dn->inode_page, 0);
95339a53e0cSJaegeuk Kim 	dn->node_page = NULL;
95439a53e0cSJaegeuk Kim 	dn->inode_page = NULL;
95539a53e0cSJaegeuk Kim }
95639a53e0cSJaegeuk Kim 
95739a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
958e8512d2eSGu Zheng 					size_t size)
95939a53e0cSJaegeuk Kim {
960e8512d2eSGu Zheng 	return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
96139a53e0cSJaegeuk Kim }
96239a53e0cSJaegeuk Kim 
9637bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
9647bd59381SGu Zheng 						gfp_t flags)
9657bd59381SGu Zheng {
9667bd59381SGu Zheng 	void *entry;
9677bd59381SGu Zheng retry:
9687bd59381SGu Zheng 	entry = kmem_cache_alloc(cachep, flags);
9697bd59381SGu Zheng 	if (!entry) {
9707bd59381SGu Zheng 		cond_resched();
9717bd59381SGu Zheng 		goto retry;
9727bd59381SGu Zheng 	}
9737bd59381SGu Zheng 
9747bd59381SGu Zheng 	return entry;
9757bd59381SGu Zheng }
9767bd59381SGu Zheng 
97739a53e0cSJaegeuk Kim #define RAW_IS_INODE(p)	((p)->footer.nid == (p)->footer.ino)
97839a53e0cSJaegeuk Kim 
97939a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page)
98039a53e0cSJaegeuk Kim {
98145590710SGu Zheng 	struct f2fs_node *p = F2FS_NODE(page);
98239a53e0cSJaegeuk Kim 	return RAW_IS_INODE(p);
98339a53e0cSJaegeuk Kim }
98439a53e0cSJaegeuk Kim 
98539a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
98639a53e0cSJaegeuk Kim {
98739a53e0cSJaegeuk Kim 	return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
98839a53e0cSJaegeuk Kim }
98939a53e0cSJaegeuk Kim 
99039a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page,
99139a53e0cSJaegeuk Kim 		unsigned int offset)
99239a53e0cSJaegeuk Kim {
99339a53e0cSJaegeuk Kim 	struct f2fs_node *raw_node;
99439a53e0cSJaegeuk Kim 	__le32 *addr_array;
99545590710SGu Zheng 	raw_node = F2FS_NODE(node_page);
99639a53e0cSJaegeuk Kim 	addr_array = blkaddr_in_node(raw_node);
99739a53e0cSJaegeuk Kim 	return le32_to_cpu(addr_array[offset]);
99839a53e0cSJaegeuk Kim }
99939a53e0cSJaegeuk Kim 
100039a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr)
100139a53e0cSJaegeuk Kim {
100239a53e0cSJaegeuk Kim 	int mask;
100339a53e0cSJaegeuk Kim 
100439a53e0cSJaegeuk Kim 	addr += (nr >> 3);
100539a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
100639a53e0cSJaegeuk Kim 	return mask & *addr;
100739a53e0cSJaegeuk Kim }
100839a53e0cSJaegeuk Kim 
100939a53e0cSJaegeuk Kim static inline int f2fs_set_bit(unsigned int nr, char *addr)
101039a53e0cSJaegeuk Kim {
101139a53e0cSJaegeuk Kim 	int mask;
101239a53e0cSJaegeuk Kim 	int ret;
101339a53e0cSJaegeuk Kim 
101439a53e0cSJaegeuk Kim 	addr += (nr >> 3);
101539a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
101639a53e0cSJaegeuk Kim 	ret = mask & *addr;
101739a53e0cSJaegeuk Kim 	*addr |= mask;
101839a53e0cSJaegeuk Kim 	return ret;
101939a53e0cSJaegeuk Kim }
102039a53e0cSJaegeuk Kim 
102139a53e0cSJaegeuk Kim static inline int f2fs_clear_bit(unsigned int nr, char *addr)
102239a53e0cSJaegeuk Kim {
102339a53e0cSJaegeuk Kim 	int mask;
102439a53e0cSJaegeuk Kim 	int ret;
102539a53e0cSJaegeuk Kim 
102639a53e0cSJaegeuk Kim 	addr += (nr >> 3);
102739a53e0cSJaegeuk Kim 	mask = 1 << (7 - (nr & 0x07));
102839a53e0cSJaegeuk Kim 	ret = mask & *addr;
102939a53e0cSJaegeuk Kim 	*addr &= ~mask;
103039a53e0cSJaegeuk Kim 	return ret;
103139a53e0cSJaegeuk Kim }
103239a53e0cSJaegeuk Kim 
103339a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */
103439a53e0cSJaegeuk Kim enum {
103539a53e0cSJaegeuk Kim 	FI_NEW_INODE,		/* indicate newly allocated inode */
1036b3783873SJaegeuk Kim 	FI_DIRTY_INODE,		/* indicate inode is dirty or not */
1037ed57c27fSJaegeuk Kim 	FI_DIRTY_DIR,		/* indicate directory has dirty pages */
103839a53e0cSJaegeuk Kim 	FI_INC_LINK,		/* need to increment i_nlink */
103939a53e0cSJaegeuk Kim 	FI_ACL_MODE,		/* indicate acl mode */
104039a53e0cSJaegeuk Kim 	FI_NO_ALLOC,		/* should not allocate any blocks */
1041699489bbSJaegeuk Kim 	FI_UPDATE_DIR,		/* should update inode block for consistency */
104274d0b917SJaegeuk Kim 	FI_DELAY_IPUT,		/* used for the recovery */
1043c11abd1aSJaegeuk Kim 	FI_NO_EXTENT,		/* not to use the extent cache */
1044444c580fSJaegeuk Kim 	FI_INLINE_XATTR,	/* used for inline xattr */
10451001b347SHuajun Li 	FI_INLINE_DATA,		/* used for inline data*/
1046fff04f90SJaegeuk Kim 	FI_APPEND_WRITE,	/* inode has appended data */
1047fff04f90SJaegeuk Kim 	FI_UPDATE_WRITE,	/* inode has in-place-update data */
1048ea1aa12cSJaegeuk Kim 	FI_NEED_IPU,		/* used fo ipu for fdatasync */
104939a53e0cSJaegeuk Kim };
105039a53e0cSJaegeuk Kim 
105139a53e0cSJaegeuk Kim static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
105239a53e0cSJaegeuk Kim {
105361e0f2d0SJaegeuk Kim 	if (!test_bit(flag, &fi->flags))
105439a53e0cSJaegeuk Kim 		set_bit(flag, &fi->flags);
105539a53e0cSJaegeuk Kim }
105639a53e0cSJaegeuk Kim 
105739a53e0cSJaegeuk Kim static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
105839a53e0cSJaegeuk Kim {
105939a53e0cSJaegeuk Kim 	return test_bit(flag, &fi->flags);
106039a53e0cSJaegeuk Kim }
106139a53e0cSJaegeuk Kim 
106239a53e0cSJaegeuk Kim static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
106339a53e0cSJaegeuk Kim {
106461e0f2d0SJaegeuk Kim 	if (test_bit(flag, &fi->flags))
106539a53e0cSJaegeuk Kim 		clear_bit(flag, &fi->flags);
106639a53e0cSJaegeuk Kim }
106739a53e0cSJaegeuk Kim 
106839a53e0cSJaegeuk Kim static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
106939a53e0cSJaegeuk Kim {
107039a53e0cSJaegeuk Kim 	fi->i_acl_mode = mode;
107139a53e0cSJaegeuk Kim 	set_inode_flag(fi, FI_ACL_MODE);
107239a53e0cSJaegeuk Kim }
107339a53e0cSJaegeuk Kim 
107439a53e0cSJaegeuk Kim static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag)
107539a53e0cSJaegeuk Kim {
107639a53e0cSJaegeuk Kim 	if (is_inode_flag_set(fi, FI_ACL_MODE)) {
107739a53e0cSJaegeuk Kim 		clear_inode_flag(fi, FI_ACL_MODE);
107839a53e0cSJaegeuk Kim 		return 1;
107939a53e0cSJaegeuk Kim 	}
108039a53e0cSJaegeuk Kim 	return 0;
108139a53e0cSJaegeuk Kim }
108239a53e0cSJaegeuk Kim 
1083444c580fSJaegeuk Kim static inline void get_inline_info(struct f2fs_inode_info *fi,
1084444c580fSJaegeuk Kim 					struct f2fs_inode *ri)
1085444c580fSJaegeuk Kim {
1086444c580fSJaegeuk Kim 	if (ri->i_inline & F2FS_INLINE_XATTR)
1087444c580fSJaegeuk Kim 		set_inode_flag(fi, FI_INLINE_XATTR);
10881001b347SHuajun Li 	if (ri->i_inline & F2FS_INLINE_DATA)
10891001b347SHuajun Li 		set_inode_flag(fi, FI_INLINE_DATA);
1090444c580fSJaegeuk Kim }
1091444c580fSJaegeuk Kim 
1092444c580fSJaegeuk Kim static inline void set_raw_inline(struct f2fs_inode_info *fi,
1093444c580fSJaegeuk Kim 					struct f2fs_inode *ri)
1094444c580fSJaegeuk Kim {
1095444c580fSJaegeuk Kim 	ri->i_inline = 0;
1096444c580fSJaegeuk Kim 
1097444c580fSJaegeuk Kim 	if (is_inode_flag_set(fi, FI_INLINE_XATTR))
1098444c580fSJaegeuk Kim 		ri->i_inline |= F2FS_INLINE_XATTR;
10991001b347SHuajun Li 	if (is_inode_flag_set(fi, FI_INLINE_DATA))
11001001b347SHuajun Li 		ri->i_inline |= F2FS_INLINE_DATA;
1101444c580fSJaegeuk Kim }
1102444c580fSJaegeuk Kim 
1103987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode)
1104987c7c31SChao Yu {
1105987c7c31SChao Yu 	return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR);
1106987c7c31SChao Yu }
1107987c7c31SChao Yu 
1108de93653fSJaegeuk Kim static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
1109de93653fSJaegeuk Kim {
1110987c7c31SChao Yu 	if (f2fs_has_inline_xattr(&fi->vfs_inode))
1111de93653fSJaegeuk Kim 		return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
1112de93653fSJaegeuk Kim 	return DEF_ADDRS_PER_INODE;
1113de93653fSJaegeuk Kim }
1114de93653fSJaegeuk Kim 
111565985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page)
111665985d93SJaegeuk Kim {
1117695fd1edSChao Yu 	struct f2fs_inode *ri = F2FS_INODE(page);
111865985d93SJaegeuk Kim 	return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
111965985d93SJaegeuk Kim 					F2FS_INLINE_XATTR_ADDRS]);
112065985d93SJaegeuk Kim }
112165985d93SJaegeuk Kim 
112265985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode)
112365985d93SJaegeuk Kim {
1124987c7c31SChao Yu 	if (f2fs_has_inline_xattr(inode))
112565985d93SJaegeuk Kim 		return F2FS_INLINE_XATTR_ADDRS << 2;
112665985d93SJaegeuk Kim 	else
112765985d93SJaegeuk Kim 		return 0;
112865985d93SJaegeuk Kim }
112965985d93SJaegeuk Kim 
11300dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode)
11310dbdc2aeSJaegeuk Kim {
11320dbdc2aeSJaegeuk Kim 	return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
11330dbdc2aeSJaegeuk Kim }
11340dbdc2aeSJaegeuk Kim 
11351001b347SHuajun Li static inline void *inline_data_addr(struct page *page)
11361001b347SHuajun Li {
1137695fd1edSChao Yu 	struct f2fs_inode *ri = F2FS_INODE(page);
11381001b347SHuajun Li 	return (void *)&(ri->i_addr[1]);
11391001b347SHuajun Li }
11401001b347SHuajun Li 
114177888c1eSJaegeuk Kim static inline int f2fs_readonly(struct super_block *sb)
114277888c1eSJaegeuk Kim {
114377888c1eSJaegeuk Kim 	return sb->s_flags & MS_RDONLY;
114477888c1eSJaegeuk Kim }
114577888c1eSJaegeuk Kim 
11461e968fdfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
11471e968fdfSJaegeuk Kim {
11481e968fdfSJaegeuk Kim 	return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
11491e968fdfSJaegeuk Kim }
11501e968fdfSJaegeuk Kim 
1151744602cfSJaegeuk Kim static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi)
1152744602cfSJaegeuk Kim {
1153744602cfSJaegeuk Kim 	set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1154744602cfSJaegeuk Kim 	sbi->sb->s_flags |= MS_RDONLY;
1155744602cfSJaegeuk Kim }
1156744602cfSJaegeuk Kim 
1157a6dda0e6SChristoph Hellwig #define get_inode_mode(i) \
1158a6dda0e6SChristoph Hellwig 	((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
1159a6dda0e6SChristoph Hellwig 	 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
1160a6dda0e6SChristoph Hellwig 
1161267378d4SChao Yu /* get offset of first page in next direct node */
1162267378d4SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, fi)				\
1163267378d4SChao Yu 	((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) :	\
1164267378d4SChao Yu 	(pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) /	\
1165267378d4SChao Yu 	ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi))
1166267378d4SChao Yu 
116739a53e0cSJaegeuk Kim /*
116839a53e0cSJaegeuk Kim  * file.c
116939a53e0cSJaegeuk Kim  */
117039a53e0cSJaegeuk Kim int f2fs_sync_file(struct file *, loff_t, loff_t, int);
117139a53e0cSJaegeuk Kim void truncate_data_blocks(struct dnode_of_data *);
1172764aa3e9SJaegeuk Kim int truncate_blocks(struct inode *, u64, bool);
117339a53e0cSJaegeuk Kim void f2fs_truncate(struct inode *);
11742d4d9fb5SJaegeuk Kim int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
117539a53e0cSJaegeuk Kim int f2fs_setattr(struct dentry *, struct iattr *);
117639a53e0cSJaegeuk Kim int truncate_hole(struct inode *, pgoff_t, pgoff_t);
1177b292dcabSJaegeuk Kim int truncate_data_blocks_range(struct dnode_of_data *, int);
117839a53e0cSJaegeuk Kim long f2fs_ioctl(struct file *, unsigned int, unsigned long);
1179e9750824SNamjae Jeon long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
118039a53e0cSJaegeuk Kim 
118139a53e0cSJaegeuk Kim /*
118239a53e0cSJaegeuk Kim  * inode.c
118339a53e0cSJaegeuk Kim  */
118439a53e0cSJaegeuk Kim void f2fs_set_inode_flags(struct inode *);
118539a53e0cSJaegeuk Kim struct inode *f2fs_iget(struct super_block *, unsigned long);
11864660f9c0SJaegeuk Kim int try_to_free_nats(struct f2fs_sb_info *, int);
118739a53e0cSJaegeuk Kim void update_inode(struct inode *, struct page *);
1188744602cfSJaegeuk Kim void update_inode_page(struct inode *);
118939a53e0cSJaegeuk Kim int f2fs_write_inode(struct inode *, struct writeback_control *);
119039a53e0cSJaegeuk Kim void f2fs_evict_inode(struct inode *);
119139a53e0cSJaegeuk Kim 
119239a53e0cSJaegeuk Kim /*
119339a53e0cSJaegeuk Kim  * namei.c
119439a53e0cSJaegeuk Kim  */
119539a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child);
119639a53e0cSJaegeuk Kim 
119739a53e0cSJaegeuk Kim /*
119839a53e0cSJaegeuk Kim  * dir.c
119939a53e0cSJaegeuk Kim  */
120039a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
120139a53e0cSJaegeuk Kim 							struct page **);
120239a53e0cSJaegeuk Kim struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
120339a53e0cSJaegeuk Kim ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
120439a53e0cSJaegeuk Kim void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
120539a53e0cSJaegeuk Kim 				struct page *, struct inode *);
12061cd14cafSJaegeuk Kim int update_dent_inode(struct inode *, const struct qstr *);
1207b7f7a5e0SAl Viro int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
120839a53e0cSJaegeuk Kim void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
1209b97a9b5dSJaegeuk Kim int f2fs_do_tmpfile(struct inode *, struct inode *);
121039a53e0cSJaegeuk Kim int f2fs_make_empty(struct inode *, struct inode *);
121139a53e0cSJaegeuk Kim bool f2fs_empty_dir(struct inode *);
121239a53e0cSJaegeuk Kim 
1213b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
1214b7f7a5e0SAl Viro {
1215b7f7a5e0SAl Viro 	return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
1216b7f7a5e0SAl Viro 				inode);
1217b7f7a5e0SAl Viro }
1218b7f7a5e0SAl Viro 
121939a53e0cSJaegeuk Kim /*
122039a53e0cSJaegeuk Kim  * super.c
122139a53e0cSJaegeuk Kim  */
122239a53e0cSJaegeuk Kim int f2fs_sync_fs(struct super_block *, int);
1223a07ef784SNamjae Jeon extern __printf(3, 4)
1224a07ef784SNamjae Jeon void f2fs_msg(struct super_block *, const char *, const char *, ...);
122539a53e0cSJaegeuk Kim 
122639a53e0cSJaegeuk Kim /*
122739a53e0cSJaegeuk Kim  * hash.c
122839a53e0cSJaegeuk Kim  */
1229eee6160fSGu Zheng f2fs_hash_t f2fs_dentry_hash(const struct qstr *);
123039a53e0cSJaegeuk Kim 
123139a53e0cSJaegeuk Kim /*
123239a53e0cSJaegeuk Kim  * node.c
123339a53e0cSJaegeuk Kim  */
123439a53e0cSJaegeuk Kim struct dnode_of_data;
123539a53e0cSJaegeuk Kim struct node_info;
123639a53e0cSJaegeuk Kim 
12376fb03f3aSJaegeuk Kim bool available_free_memory(struct f2fs_sb_info *, int);
123888bd02c9SJaegeuk Kim bool is_checkpointed_node(struct f2fs_sb_info *, nid_t);
123988bd02c9SJaegeuk Kim bool has_fsynced_inode(struct f2fs_sb_info *, nid_t);
124088bd02c9SJaegeuk Kim bool need_inode_block_update(struct f2fs_sb_info *, nid_t);
124139a53e0cSJaegeuk Kim void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
124239a53e0cSJaegeuk Kim int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
124339a53e0cSJaegeuk Kim int truncate_inode_blocks(struct inode *, pgoff_t);
12444f16fb0fSJaegeuk Kim int truncate_xattr_node(struct inode *, struct page *);
1245cfe58f9dSJaegeuk Kim int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
124658e674d6SGu Zheng void remove_inode_page(struct inode *);
1247a014e037SJaegeuk Kim struct page *new_inode_page(struct inode *);
12488ae8f162SJaegeuk Kim struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
124939a53e0cSJaegeuk Kim void ra_node_page(struct f2fs_sb_info *, nid_t);
125039a53e0cSJaegeuk Kim struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
125139a53e0cSJaegeuk Kim struct page *get_node_page_ra(struct page *, int);
125239a53e0cSJaegeuk Kim void sync_inode_page(struct dnode_of_data *);
125339a53e0cSJaegeuk Kim int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
125439a53e0cSJaegeuk Kim bool alloc_nid(struct f2fs_sb_info *, nid_t *);
125539a53e0cSJaegeuk Kim void alloc_nid_done(struct f2fs_sb_info *, nid_t);
125639a53e0cSJaegeuk Kim void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
125770cfed88SChao Yu void recover_inline_xattr(struct inode *, struct page *);
12581c35a90eSJaegeuk Kim void recover_xattr_data(struct inode *, struct page *, block_t);
125939a53e0cSJaegeuk Kim int recover_inode_page(struct f2fs_sb_info *, struct page *);
126039a53e0cSJaegeuk Kim int restore_node_summary(struct f2fs_sb_info *, unsigned int,
126139a53e0cSJaegeuk Kim 				struct f2fs_summary_block *);
126239a53e0cSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *);
126339a53e0cSJaegeuk Kim int build_node_manager(struct f2fs_sb_info *);
126439a53e0cSJaegeuk Kim void destroy_node_manager(struct f2fs_sb_info *);
12656e6093a8SNamjae Jeon int __init create_node_manager_caches(void);
126639a53e0cSJaegeuk Kim void destroy_node_manager_caches(void);
126739a53e0cSJaegeuk Kim 
126839a53e0cSJaegeuk Kim /*
126939a53e0cSJaegeuk Kim  * segment.c
127039a53e0cSJaegeuk Kim  */
127139a53e0cSJaegeuk Kim void f2fs_balance_fs(struct f2fs_sb_info *);
12724660f9c0SJaegeuk Kim void f2fs_balance_fs_bg(struct f2fs_sb_info *);
12736b4afdd7SJaegeuk Kim int f2fs_issue_flush(struct f2fs_sb_info *);
12742163d198SGu Zheng int create_flush_cmd_control(struct f2fs_sb_info *);
12752163d198SGu Zheng void destroy_flush_cmd_control(struct f2fs_sb_info *);
127639a53e0cSJaegeuk Kim void invalidate_blocks(struct f2fs_sb_info *, block_t);
12775e443818SJaegeuk Kim void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
127839a53e0cSJaegeuk Kim void clear_prefree_segments(struct f2fs_sb_info *);
1279cf2271e7SJaegeuk Kim void discard_next_dnode(struct f2fs_sb_info *, block_t);
128039a53e0cSJaegeuk Kim int npages_for_summary_flush(struct f2fs_sb_info *);
128139a53e0cSJaegeuk Kim void allocate_new_segments(struct f2fs_sb_info *);
128239a53e0cSJaegeuk Kim struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
1283577e3495SJaegeuk Kim void write_meta_page(struct f2fs_sb_info *, struct page *);
1284fb5566daSJaegeuk Kim void write_node_page(struct f2fs_sb_info *, struct page *,
1285fb5566daSJaegeuk Kim 		struct f2fs_io_info *, unsigned int, block_t, block_t *);
1286458e6197SJaegeuk Kim void write_data_page(struct page *, struct dnode_of_data *, block_t *,
1287458e6197SJaegeuk Kim 					struct f2fs_io_info *);
1288458e6197SJaegeuk Kim void rewrite_data_page(struct page *, block_t, struct f2fs_io_info *);
128939a53e0cSJaegeuk Kim void recover_data_page(struct f2fs_sb_info *, struct page *,
129039a53e0cSJaegeuk Kim 				struct f2fs_summary *, block_t, block_t);
1291bfad7c2dSJaegeuk Kim void allocate_data_block(struct f2fs_sb_info *, struct page *,
1292bfad7c2dSJaegeuk Kim 		block_t, block_t *, struct f2fs_summary *, int);
12935514f0aaSYuan Zhong void f2fs_wait_on_page_writeback(struct page *, enum page_type);
129439a53e0cSJaegeuk Kim void write_data_summaries(struct f2fs_sb_info *, block_t);
129539a53e0cSJaegeuk Kim void write_node_summaries(struct f2fs_sb_info *, block_t);
129639a53e0cSJaegeuk Kim int lookup_journal_in_cursum(struct f2fs_summary_block *,
129739a53e0cSJaegeuk Kim 					int, unsigned int, int);
129839a53e0cSJaegeuk Kim void flush_sit_entries(struct f2fs_sb_info *);
129939a53e0cSJaegeuk Kim int build_segment_manager(struct f2fs_sb_info *);
130039a53e0cSJaegeuk Kim void destroy_segment_manager(struct f2fs_sb_info *);
13017fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void);
13027fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void);
130339a53e0cSJaegeuk Kim 
130439a53e0cSJaegeuk Kim /*
130539a53e0cSJaegeuk Kim  * checkpoint.c
130639a53e0cSJaegeuk Kim  */
130739a53e0cSJaegeuk Kim struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
130839a53e0cSJaegeuk Kim struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
13094c521f49SJaegeuk Kim struct page *get_meta_page_ra(struct f2fs_sb_info *, pgoff_t);
13104c521f49SJaegeuk Kim int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int);
131139a53e0cSJaegeuk Kim long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
1312fff04f90SJaegeuk Kim void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
1313fff04f90SJaegeuk Kim void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
13146f12ac25SJaegeuk Kim void release_dirty_inode(struct f2fs_sb_info *);
1315fff04f90SJaegeuk Kim bool exist_written_data(struct f2fs_sb_info *, nid_t, int);
1316cbd56e7dSJaegeuk Kim int acquire_orphan_inode(struct f2fs_sb_info *);
1317cbd56e7dSJaegeuk Kim void release_orphan_inode(struct f2fs_sb_info *);
131839a53e0cSJaegeuk Kim void add_orphan_inode(struct f2fs_sb_info *, nid_t);
131939a53e0cSJaegeuk Kim void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
13208f99a946SChao Yu void recover_orphan_inodes(struct f2fs_sb_info *);
132139a53e0cSJaegeuk Kim int get_valid_checkpoint(struct f2fs_sb_info *);
1322a7ffdbe2SJaegeuk Kim void update_dirty_page(struct inode *, struct page *);
13235deb8267SJaegeuk Kim void add_dirty_dir_inode(struct inode *);
132439a53e0cSJaegeuk Kim void remove_dirty_dir_inode(struct inode *);
132539a53e0cSJaegeuk Kim void sync_dirty_dir_inodes(struct f2fs_sb_info *);
1326*75ab4cb8SJaegeuk Kim void write_checkpoint(struct f2fs_sb_info *, struct cp_control *);
13276451e041SJaegeuk Kim void init_ino_entry_info(struct f2fs_sb_info *);
13286e6093a8SNamjae Jeon int __init create_checkpoint_caches(void);
132939a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void);
133039a53e0cSJaegeuk Kim 
133139a53e0cSJaegeuk Kim /*
133239a53e0cSJaegeuk Kim  * data.c
133339a53e0cSJaegeuk Kim  */
1334458e6197SJaegeuk Kim void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
133593dfe2acSJaegeuk Kim int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *, block_t, int);
133693dfe2acSJaegeuk Kim void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *, block_t,
1337458e6197SJaegeuk Kim 						struct f2fs_io_info *);
133839a53e0cSJaegeuk Kim int reserve_new_block(struct dnode_of_data *);
1339b600965cSHuajun Li int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
134039a53e0cSJaegeuk Kim void update_extent_cache(block_t, struct dnode_of_data *);
1341c718379bSJaegeuk Kim struct page *find_data_page(struct inode *, pgoff_t, bool);
134239a53e0cSJaegeuk Kim struct page *get_lock_data_page(struct inode *, pgoff_t);
134364aa7ed9SJaegeuk Kim struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
1344458e6197SJaegeuk Kim int do_write_data_page(struct page *, struct f2fs_io_info *);
13459ab70134SJaegeuk Kim int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
134639a53e0cSJaegeuk Kim 
134739a53e0cSJaegeuk Kim /*
134839a53e0cSJaegeuk Kim  * gc.c
134939a53e0cSJaegeuk Kim  */
135039a53e0cSJaegeuk Kim int start_gc_thread(struct f2fs_sb_info *);
135139a53e0cSJaegeuk Kim void stop_gc_thread(struct f2fs_sb_info *);
1352de93653fSJaegeuk Kim block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
1353408e9375SJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *);
135439a53e0cSJaegeuk Kim void build_gc_manager(struct f2fs_sb_info *);
13556e6093a8SNamjae Jeon int __init create_gc_caches(void);
135639a53e0cSJaegeuk Kim void destroy_gc_caches(void);
135739a53e0cSJaegeuk Kim 
135839a53e0cSJaegeuk Kim /*
135939a53e0cSJaegeuk Kim  * recovery.c
136039a53e0cSJaegeuk Kim  */
13616ead1142SJaegeuk Kim int recover_fsync_data(struct f2fs_sb_info *);
136239a53e0cSJaegeuk Kim bool space_for_roll_forward(struct f2fs_sb_info *);
136339a53e0cSJaegeuk Kim 
136439a53e0cSJaegeuk Kim /*
136539a53e0cSJaegeuk Kim  * debug.c
136639a53e0cSJaegeuk Kim  */
136739a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS
136839a53e0cSJaegeuk Kim struct f2fs_stat_info {
136939a53e0cSJaegeuk Kim 	struct list_head stat_list;
137039a53e0cSJaegeuk Kim 	struct f2fs_sb_info *sbi;
137139a53e0cSJaegeuk Kim 	int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
137239a53e0cSJaegeuk Kim 	int main_area_segs, main_area_sections, main_area_zones;
137339a53e0cSJaegeuk Kim 	int hit_ext, total_ext;
137439a53e0cSJaegeuk Kim 	int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
137539a53e0cSJaegeuk Kim 	int nats, sits, fnids;
137639a53e0cSJaegeuk Kim 	int total_count, utilization;
13770dbdc2aeSJaegeuk Kim 	int bg_gc, inline_inode;
137839a53e0cSJaegeuk Kim 	unsigned int valid_count, valid_node_count, valid_inode_count;
137939a53e0cSJaegeuk Kim 	unsigned int bimodal, avg_vblocks;
138039a53e0cSJaegeuk Kim 	int util_free, util_valid, util_invalid;
138139a53e0cSJaegeuk Kim 	int rsvd_segs, overp_segs;
138239a53e0cSJaegeuk Kim 	int dirty_count, node_pages, meta_pages;
1383942e0be6SChangman Lee 	int prefree_count, call_count, cp_count;
138439a53e0cSJaegeuk Kim 	int tot_segs, node_segs, data_segs, free_segs, free_secs;
138539a53e0cSJaegeuk Kim 	int tot_blks, data_blks, node_blks;
138639a53e0cSJaegeuk Kim 	int curseg[NR_CURSEG_TYPE];
138739a53e0cSJaegeuk Kim 	int cursec[NR_CURSEG_TYPE];
138839a53e0cSJaegeuk Kim 	int curzone[NR_CURSEG_TYPE];
138939a53e0cSJaegeuk Kim 
139039a53e0cSJaegeuk Kim 	unsigned int segment_count[2];
139139a53e0cSJaegeuk Kim 	unsigned int block_count[2];
139239a53e0cSJaegeuk Kim 	unsigned base_mem, cache_mem;
139339a53e0cSJaegeuk Kim };
139439a53e0cSJaegeuk Kim 
1395963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
1396963d4f7dSGu Zheng {
1397963d4f7dSGu Zheng 	return (struct f2fs_stat_info *)sbi->stat_info;
1398963d4f7dSGu Zheng }
1399963d4f7dSGu Zheng 
1400942e0be6SChangman Lee #define stat_inc_cp_count(si)		((si)->cp_count++)
140139a53e0cSJaegeuk Kim #define stat_inc_call_count(si)		((si)->call_count++)
1402dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi)	((sbi)->bg_gc++)
1403dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi)		((sbi)->n_dirty_dirs++)
1404dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi)		((sbi)->n_dirty_dirs--)
1405dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb)		((F2FS_SB(sb))->total_hit_ext++)
1406dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb)		((F2FS_SB(sb))->read_hit_ext++)
14070dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode)					\
14080dbdc2aeSJaegeuk Kim 	do {								\
14090dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
14104081363fSJaegeuk Kim 			((F2FS_I_SB(inode))->inline_inode++);		\
14110dbdc2aeSJaegeuk Kim 	} while (0)
14120dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode)					\
14130dbdc2aeSJaegeuk Kim 	do {								\
14140dbdc2aeSJaegeuk Kim 		if (f2fs_has_inline_data(inode))			\
14154081363fSJaegeuk Kim 			((F2FS_I_SB(inode))->inline_inode--);		\
14160dbdc2aeSJaegeuk Kim 	} while (0)
14170dbdc2aeSJaegeuk Kim 
1418dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg)					\
1419dcdfff65SJaegeuk Kim 		((sbi)->segment_count[(curseg)->alloc_type]++)
1420dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg)				\
1421dcdfff65SJaegeuk Kim 		((sbi)->block_count[(curseg)->alloc_type]++)
142239a53e0cSJaegeuk Kim 
142339a53e0cSJaegeuk Kim #define stat_inc_seg_count(sbi, type)					\
142439a53e0cSJaegeuk Kim 	do {								\
1425963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
142639a53e0cSJaegeuk Kim 		(si)->tot_segs++;					\
142739a53e0cSJaegeuk Kim 		if (type == SUM_TYPE_DATA)				\
142839a53e0cSJaegeuk Kim 			si->data_segs++;				\
142939a53e0cSJaegeuk Kim 		else							\
143039a53e0cSJaegeuk Kim 			si->node_segs++;				\
143139a53e0cSJaegeuk Kim 	} while (0)
143239a53e0cSJaegeuk Kim 
143339a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks)				\
143439a53e0cSJaegeuk Kim 	(si->tot_blks += (blks))
143539a53e0cSJaegeuk Kim 
143639a53e0cSJaegeuk Kim #define stat_inc_data_blk_count(sbi, blks)				\
143739a53e0cSJaegeuk Kim 	do {								\
1438963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
143939a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
144039a53e0cSJaegeuk Kim 		si->data_blks += (blks);				\
144139a53e0cSJaegeuk Kim 	} while (0)
144239a53e0cSJaegeuk Kim 
144339a53e0cSJaegeuk Kim #define stat_inc_node_blk_count(sbi, blks)				\
144439a53e0cSJaegeuk Kim 	do {								\
1445963d4f7dSGu Zheng 		struct f2fs_stat_info *si = F2FS_STAT(sbi);		\
144639a53e0cSJaegeuk Kim 		stat_inc_tot_blk_count(si, blks);			\
144739a53e0cSJaegeuk Kim 		si->node_blks += (blks);				\
144839a53e0cSJaegeuk Kim 	} while (0)
144939a53e0cSJaegeuk Kim 
145039a53e0cSJaegeuk Kim int f2fs_build_stats(struct f2fs_sb_info *);
145139a53e0cSJaegeuk Kim void f2fs_destroy_stats(struct f2fs_sb_info *);
14526e6093a8SNamjae Jeon void __init f2fs_create_root_stats(void);
14534589d25dSNamjae Jeon void f2fs_destroy_root_stats(void);
145439a53e0cSJaegeuk Kim #else
1455942e0be6SChangman Lee #define stat_inc_cp_count(si)
145639a53e0cSJaegeuk Kim #define stat_inc_call_count(si)
1457dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si)
1458dcdfff65SJaegeuk Kim #define stat_inc_dirty_dir(sbi)
1459dcdfff65SJaegeuk Kim #define stat_dec_dirty_dir(sbi)
1460dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb)
1461dcdfff65SJaegeuk Kim #define stat_inc_read_hit(sb)
14620dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode)
14630dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode)
1464dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg)
1465dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg)
146639a53e0cSJaegeuk Kim #define stat_inc_seg_count(si, type)
146739a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks)
146839a53e0cSJaegeuk Kim #define stat_inc_data_blk_count(si, blks)
146939a53e0cSJaegeuk Kim #define stat_inc_node_blk_count(sbi, blks)
147039a53e0cSJaegeuk Kim 
147139a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
147239a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
14736e6093a8SNamjae Jeon static inline void __init f2fs_create_root_stats(void) { }
14744589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { }
147539a53e0cSJaegeuk Kim #endif
147639a53e0cSJaegeuk Kim 
147739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations;
147839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations;
147939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations;
148039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops;
148139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops;
148239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops;
148339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations;
148439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations;
148539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations;
14861001b347SHuajun Li 
1487e18c65b2SHuajun Li /*
1488e18c65b2SHuajun Li  * inline.c
1489e18c65b2SHuajun Li  */
1490e18c65b2SHuajun Li bool f2fs_may_inline(struct inode *);
1491e18c65b2SHuajun Li int f2fs_read_inline_data(struct inode *, struct page *);
1492b067ba1fSJaegeuk Kim int f2fs_convert_inline_data(struct inode *, pgoff_t, struct page *);
1493e18c65b2SHuajun Li int f2fs_write_inline_data(struct inode *, struct page *, unsigned int);
14948aa6f1c5SChao Yu void truncate_inline_data(struct inode *, u64);
14950342fd30SJaegeuk Kim bool recover_inline_data(struct inode *, struct page *);
149639a53e0cSJaegeuk Kim #endif
1497