f2fs: add f2fs_io_tracer support
[linux-2.6-block.git] / fs / f2fs / f2fs.h
CommitLineData
0a8165d7 1/*
39a53e0c
JK
2 * fs/f2fs/f2fs.h
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef _LINUX_F2FS_H
12#define _LINUX_F2FS_H
13
14#include <linux/types.h>
15#include <linux/page-flags.h>
16#include <linux/buffer_head.h>
39a53e0c
JK
17#include <linux/slab.h>
18#include <linux/crc32.h>
19#include <linux/magic.h>
c2d715d1 20#include <linux/kobject.h>
7bd59381 21#include <linux/sched.h>
39a53e0c 22
5d56b671 23#ifdef CONFIG_F2FS_CHECK_FS
9850cf4a 24#define f2fs_bug_on(sbi, condition) BUG_ON(condition)
0daaad97 25#define f2fs_down_write(x, y) down_write_nest_lock(x, y)
5d56b671 26#else
9850cf4a
JK
27#define f2fs_bug_on(sbi, condition) \
28 do { \
29 if (unlikely(condition)) { \
30 WARN_ON(1); \
31 sbi->need_fsck = true; \
32 } \
33 } while (0)
0daaad97 34#define f2fs_down_write(x, y) down_write(x)
5d56b671
JK
35#endif
36
39a53e0c
JK
37/*
38 * For mount options
39 */
40#define F2FS_MOUNT_BG_GC 0x00000001
41#define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
42#define F2FS_MOUNT_DISCARD 0x00000004
43#define F2FS_MOUNT_NOHEAP 0x00000008
44#define F2FS_MOUNT_XATTR_USER 0x00000010
45#define F2FS_MOUNT_POSIX_ACL 0x00000020
46#define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
444c580f 47#define F2FS_MOUNT_INLINE_XATTR 0x00000080
1001b347 48#define F2FS_MOUNT_INLINE_DATA 0x00000100
34d67deb
CY
49#define F2FS_MOUNT_INLINE_DENTRY 0x00000200
50#define F2FS_MOUNT_FLUSH_MERGE 0x00000400
51#define F2FS_MOUNT_NOBARRIER 0x00000800
d5053a34 52#define F2FS_MOUNT_FASTBOOT 0x00001000
39a53e0c
JK
53
54#define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
55#define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
56#define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
57
58#define ver_after(a, b) (typecheck(unsigned long long, a) && \
59 typecheck(unsigned long long, b) && \
60 ((long long)((a) - (b)) > 0))
61
a9841c4d
JK
62typedef u32 block_t; /*
63 * should not change u32, since it is the on-disk block
64 * address format, __le32.
65 */
39a53e0c
JK
66typedef u32 nid_t;
67
68struct f2fs_mount_info {
69 unsigned int opt;
70};
71
7e586fa0
JK
72#define CRCPOLY_LE 0xedb88320
73
74static inline __u32 f2fs_crc32(void *buf, size_t len)
39a53e0c 75{
7e586fa0
JK
76 unsigned char *p = (unsigned char *)buf;
77 __u32 crc = F2FS_SUPER_MAGIC;
78 int i;
79
80 while (len--) {
81 crc ^= *p++;
82 for (i = 0; i < 8; i++)
83 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
84 }
85 return crc;
39a53e0c
JK
86}
87
7e586fa0 88static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
39a53e0c 89{
7e586fa0 90 return f2fs_crc32(buf, buf_size) == blk_crc;
39a53e0c
JK
91}
92
93/*
94 * For checkpoint manager
95 */
96enum {
97 NAT_BITMAP,
98 SIT_BITMAP
99};
100
75ab4cb8
JK
101enum {
102 CP_UMOUNT,
103 CP_SYNC,
4b2fecc8 104 CP_DISCARD,
75ab4cb8
JK
105};
106
107struct cp_control {
108 int reason;
4b2fecc8
JK
109 __u64 trim_start;
110 __u64 trim_end;
111 __u64 trim_minlen;
112 __u64 trimmed;
75ab4cb8
JK
113};
114
662befda 115/*
81c1a0f1 116 * For CP/NAT/SIT/SSA readahead
662befda
CY
117 */
118enum {
119 META_CP,
120 META_NAT,
81c1a0f1 121 META_SIT,
4c521f49
JK
122 META_SSA,
123 META_POR,
662befda
CY
124};
125
6451e041
JK
126/* for the list of ino */
127enum {
128 ORPHAN_INO, /* for orphan ino list */
fff04f90
JK
129 APPEND_INO, /* for append ino list */
130 UPDATE_INO, /* for update ino list */
6451e041
JK
131 MAX_INO_ENTRY, /* max. list */
132};
133
134struct ino_entry {
39a53e0c
JK
135 struct list_head list; /* list head */
136 nid_t ino; /* inode number */
137};
138
139/* for the list of directory inodes */
140struct dir_inode_entry {
141 struct list_head list; /* list head */
142 struct inode *inode; /* vfs inode pointer */
143};
144
7fd9e544
JK
145/* for the list of blockaddresses to be discarded */
146struct discard_entry {
147 struct list_head list; /* list head */
148 block_t blkaddr; /* block address to be discarded */
149 int len; /* # of consecutive blocks of the discard */
150};
151
39a53e0c
JK
152/* for the list of fsync inodes, used only during recovery */
153struct fsync_inode_entry {
154 struct list_head list; /* list head */
155 struct inode *inode; /* vfs inode pointer */
c52e1b10
JK
156 block_t blkaddr; /* block address locating the last fsync */
157 block_t last_dentry; /* block address locating the last dentry */
158 block_t last_inode; /* block address locating the last inode */
39a53e0c
JK
159};
160
161#define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats))
162#define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits))
163
164#define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne)
165#define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid)
166#define sit_in_journal(sum, i) (sum->sit_j.entries[i].se)
167#define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno)
168
309cc2b6
JK
169#define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum))
170#define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum))
171
39a53e0c
JK
172static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
173{
174 int before = nats_in_cursum(rs);
175 rs->n_nats = cpu_to_le16(before + i);
176 return before;
177}
178
179static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
180{
181 int before = sits_in_cursum(rs);
182 rs->n_sits = cpu_to_le16(before + i);
183 return before;
184}
185
184a5cd2
CY
186static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size,
187 int type)
188{
189 if (type == NAT_JOURNAL)
309cc2b6
JK
190 return size <= MAX_NAT_JENTRIES(sum);
191 return size <= MAX_SIT_JENTRIES(sum);
184a5cd2
CY
192}
193
e9750824
NJ
194/*
195 * ioctl commands
196 */
88b88a66
JK
197#define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
198#define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
199
200#define F2FS_IOCTL_MAGIC 0xf5
201#define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
202#define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
02a1335f 203#define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
1e84371f
JK
204#define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)
205#define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
e9750824
NJ
206
207#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
208/*
209 * ioctl commands in 32 bit emulation
210 */
211#define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
212#define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
213#endif
214
39a53e0c
JK
215/*
216 * For INODE and NODE manager
217 */
7b3cd7d6
JK
218/* for directory operations */
219struct f2fs_dentry_ptr {
220 const void *bitmap;
221 struct f2fs_dir_entry *dentry;
222 __u8 (*filename)[F2FS_SLOT_LEN];
223 int max;
224};
225
226static inline void make_dentry_ptr(struct f2fs_dentry_ptr *d,
227 void *src, int type)
228{
229 if (type == 1) {
230 struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src;
231 d->max = NR_DENTRY_IN_BLOCK;
232 d->bitmap = &t->dentry_bitmap;
233 d->dentry = t->dentry;
234 d->filename = t->filename;
235 } else {
236 struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src;
237 d->max = NR_INLINE_DENTRY;
238 d->bitmap = &t->dentry_bitmap;
239 d->dentry = t->dentry;
240 d->filename = t->filename;
241 }
242}
243
dbe6a5ff
JK
244/*
245 * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
246 * as its node offset to distinguish from index node blocks.
247 * But some bits are used to mark the node block.
248 */
249#define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
250 >> OFFSET_BIT_SHIFT)
266e97a8
JK
251enum {
252 ALLOC_NODE, /* allocate a new node page if needed */
253 LOOKUP_NODE, /* look up a node without readahead */
254 LOOKUP_NODE_RA, /*
255 * look up a node with readahead called
4f4124d0 256 * by get_data_block.
39a53e0c 257 */
266e97a8
JK
258};
259
39a53e0c
JK
260#define F2FS_LINK_MAX 32000 /* maximum link count per file */
261
817202d9
CY
262#define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */
263
39a53e0c 264/* for in-memory extent cache entry */
c11abd1a
JK
265#define F2FS_MIN_EXTENT_LEN 16 /* minimum extent length */
266
39a53e0c
JK
267struct extent_info {
268 rwlock_t ext_lock; /* rwlock for consistency */
269 unsigned int fofs; /* start offset in a file */
270 u32 blk_addr; /* start block address of the extent */
111d2495 271 unsigned int len; /* length of the extent */
39a53e0c
JK
272};
273
274/*
275 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
276 */
277#define FADVISE_COLD_BIT 0x01
354a3399 278#define FADVISE_LOST_PINO_BIT 0x02
39a53e0c 279
ab9fa662
JK
280#define DEF_DIR_LEVEL 0
281
39a53e0c
JK
282struct f2fs_inode_info {
283 struct inode vfs_inode; /* serve a vfs inode */
284 unsigned long i_flags; /* keep an inode flags for ioctl */
285 unsigned char i_advise; /* use to give file attribute hints */
38431545 286 unsigned char i_dir_level; /* use for dentry level for large dir */
39a53e0c 287 unsigned int i_current_depth; /* use only in directory structure */
6666e6aa 288 unsigned int i_pino; /* parent inode number */
39a53e0c
JK
289 umode_t i_acl_mode; /* keep file acl mode temporarily */
290
291 /* Use below internally in f2fs*/
292 unsigned long flags; /* use to pass per-file flags */
d928bfbf 293 struct rw_semaphore i_sem; /* protect fi info */
a7ffdbe2 294 atomic_t dirty_pages; /* # of dirty pages */
39a53e0c
JK
295 f2fs_hash_t chash; /* hash value of given file name */
296 unsigned int clevel; /* maximum level of given file name */
297 nid_t i_xattr_nid; /* node id that contains xattrs */
e518ff81 298 unsigned long long xattr_ver; /* cp version of xattr modification */
39a53e0c 299 struct extent_info ext; /* in-memory extent cache entry */
ed57c27f 300 struct dir_inode_entry *dirty_dir; /* the pointer of dirty dir */
88b88a66 301
34ba94ba 302 struct radix_tree_root inmem_root; /* radix tree for inmem pages */
88b88a66
JK
303 struct list_head inmem_pages; /* inmemory pages managed by f2fs */
304 struct mutex inmem_lock; /* lock for inmemory pages */
39a53e0c
JK
305};
306
307static inline void get_extent_info(struct extent_info *ext,
308 struct f2fs_extent i_ext)
309{
310 write_lock(&ext->ext_lock);
311 ext->fofs = le32_to_cpu(i_ext.fofs);
312 ext->blk_addr = le32_to_cpu(i_ext.blk_addr);
313 ext->len = le32_to_cpu(i_ext.len);
314 write_unlock(&ext->ext_lock);
315}
316
317static inline void set_raw_extent(struct extent_info *ext,
318 struct f2fs_extent *i_ext)
319{
320 read_lock(&ext->ext_lock);
321 i_ext->fofs = cpu_to_le32(ext->fofs);
322 i_ext->blk_addr = cpu_to_le32(ext->blk_addr);
323 i_ext->len = cpu_to_le32(ext->len);
324 read_unlock(&ext->ext_lock);
325}
326
327struct f2fs_nm_info {
328 block_t nat_blkaddr; /* base disk address of NAT */
329 nid_t max_nid; /* maximum possible node ids */
7ee0eeab 330 nid_t available_nids; /* maximum available node ids */
39a53e0c 331 nid_t next_scan_nid; /* the next nid to be scanned */
cdfc41c1 332 unsigned int ram_thresh; /* control the memory footprint */
39a53e0c
JK
333
334 /* NAT cache management */
335 struct radix_tree_root nat_root;/* root of the nat entry cache */
309cc2b6 336 struct radix_tree_root nat_set_root;/* root of the nat set cache */
8b26ef98 337 struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */
39a53e0c 338 struct list_head nat_entries; /* cached nat entry list (clean) */
309cc2b6 339 unsigned int nat_cnt; /* the # of cached nat entries */
aec71382 340 unsigned int dirty_nat_cnt; /* total num of nat entries in set */
39a53e0c
JK
341
342 /* free node ids management */
8a7ed66a 343 struct radix_tree_root free_nid_root;/* root of the free_nid cache */
39a53e0c
JK
344 struct list_head free_nid_list; /* a list for free nids */
345 spinlock_t free_nid_list_lock; /* protect free nid list */
346 unsigned int fcnt; /* the number of free node id */
347 struct mutex build_lock; /* lock for build free nids */
348
349 /* for checkpoint */
350 char *nat_bitmap; /* NAT bitmap pointer */
351 int bitmap_size; /* bitmap size */
352};
353
354/*
355 * this structure is used as one of function parameters.
356 * all the information are dedicated to a given direct node block determined
357 * by the data offset in a file.
358 */
359struct dnode_of_data {
360 struct inode *inode; /* vfs inode pointer */
361 struct page *inode_page; /* its inode page, NULL is possible */
362 struct page *node_page; /* cached direct node page */
363 nid_t nid; /* node id of the direct node block */
364 unsigned int ofs_in_node; /* data offset in the node page */
365 bool inode_page_locked; /* inode page is locked or not */
366 block_t data_blkaddr; /* block address of the node block */
367};
368
369static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
370 struct page *ipage, struct page *npage, nid_t nid)
371{
d66d1f76 372 memset(dn, 0, sizeof(*dn));
39a53e0c
JK
373 dn->inode = inode;
374 dn->inode_page = ipage;
375 dn->node_page = npage;
376 dn->nid = nid;
39a53e0c
JK
377}
378
379/*
380 * For SIT manager
381 *
382 * By default, there are 6 active log areas across the whole main area.
383 * When considering hot and cold data separation to reduce cleaning overhead,
384 * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
385 * respectively.
386 * In the current design, you should not change the numbers intentionally.
387 * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
388 * logs individually according to the underlying devices. (default: 6)
389 * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
390 * data and 8 for node logs.
391 */
392#define NR_CURSEG_DATA_TYPE (3)
393#define NR_CURSEG_NODE_TYPE (3)
394#define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
395
396enum {
397 CURSEG_HOT_DATA = 0, /* directory entry blocks */
398 CURSEG_WARM_DATA, /* data blocks */
399 CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
400 CURSEG_HOT_NODE, /* direct node blocks of directory files */
401 CURSEG_WARM_NODE, /* direct node blocks of normal files */
402 CURSEG_COLD_NODE, /* indirect node blocks */
403 NO_CHECK_TYPE
404};
405
6b4afdd7 406struct flush_cmd {
6b4afdd7 407 struct completion wait;
721bd4d5 408 struct llist_node llnode;
6b4afdd7
JK
409 int ret;
410};
411
a688b9d9
GZ
412struct flush_cmd_control {
413 struct task_struct *f2fs_issue_flush; /* flush thread */
414 wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */
721bd4d5
GZ
415 struct llist_head issue_list; /* list for command issue */
416 struct llist_node *dispatch_list; /* list for command dispatch */
a688b9d9
GZ
417};
418
39a53e0c
JK
419struct f2fs_sm_info {
420 struct sit_info *sit_info; /* whole segment information */
421 struct free_segmap_info *free_info; /* free segment information */
422 struct dirty_seglist_info *dirty_info; /* dirty segment information */
423 struct curseg_info *curseg_array; /* active segment information */
424
39a53e0c
JK
425 block_t seg0_blkaddr; /* block address of 0'th segment */
426 block_t main_blkaddr; /* start block address of main area */
427 block_t ssa_blkaddr; /* start block address of SSA area */
428
429 unsigned int segment_count; /* total # of segments */
430 unsigned int main_segments; /* # of segments in main area */
431 unsigned int reserved_segments; /* # of reserved segments */
432 unsigned int ovp_segments; /* # of overprovision segments */
81eb8d6e
JK
433
434 /* a threshold to reclaim prefree segments */
435 unsigned int rec_prefree_segments;
7fd9e544
JK
436
437 /* for small discard management */
438 struct list_head discard_list; /* 4KB discard list */
439 int nr_discards; /* # of discards in the list */
440 int max_discards; /* max. discards to be issued */
216fbd64 441
184a5cd2
CY
442 struct list_head sit_entry_set; /* sit entry set list */
443
216fbd64
JK
444 unsigned int ipu_policy; /* in-place-update policy */
445 unsigned int min_ipu_util; /* in-place-update threshold */
c1ce1b02 446 unsigned int min_fsync_blocks; /* threshold for fsync */
6b4afdd7
JK
447
448 /* for flush command control */
a688b9d9
GZ
449 struct flush_cmd_control *cmd_control_info;
450
39a53e0c
JK
451};
452
39a53e0c
JK
453/*
454 * For superblock
455 */
456/*
457 * COUNT_TYPE for monitoring
458 *
459 * f2fs monitors the number of several block types such as on-writeback,
460 * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
461 */
462enum count_type {
463 F2FS_WRITEBACK,
464 F2FS_DIRTY_DENTS,
465 F2FS_DIRTY_NODES,
466 F2FS_DIRTY_META,
8dcf2ff7 467 F2FS_INMEM_PAGES,
39a53e0c
JK
468 NR_COUNT_TYPE,
469};
470
39a53e0c 471/*
e1c42045 472 * The below are the page types of bios used in submit_bio().
39a53e0c
JK
473 * The available types are:
474 * DATA User data pages. It operates as async mode.
475 * NODE Node pages. It operates as async mode.
476 * META FS metadata pages such as SIT, NAT, CP.
477 * NR_PAGE_TYPE The number of page types.
478 * META_FLUSH Make sure the previous pages are written
479 * with waiting the bio's completion
480 * ... Only can be used with META.
481 */
7d5e5109 482#define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type))
39a53e0c
JK
483enum page_type {
484 DATA,
485 NODE,
486 META,
487 NR_PAGE_TYPE,
488 META_FLUSH,
489};
490
458e6197 491struct f2fs_io_info {
7e8f2308
GZ
492 enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
493 int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */
cf04e8eb 494 block_t blk_addr; /* block address to be written */
458e6197
JK
495};
496
93dfe2ac 497#define is_read_io(rw) (((rw) & 1) == READ)
1ff7bd3b 498struct f2fs_bio_info {
458e6197 499 struct f2fs_sb_info *sbi; /* f2fs superblock */
1ff7bd3b
JK
500 struct bio *bio; /* bios to merge */
501 sector_t last_block_in_bio; /* last block number */
458e6197 502 struct f2fs_io_info fio; /* store buffered io info. */
df0f8dc0 503 struct rw_semaphore io_rwsem; /* blocking op for bio */
1ff7bd3b
JK
504};
505
67298804
CY
506/* for inner inode cache management */
507struct inode_management {
508 struct radix_tree_root ino_root; /* ino entry array */
509 spinlock_t ino_lock; /* for ino entry lock */
510 struct list_head ino_list; /* inode list head */
511 unsigned long ino_num; /* number of entries */
512};
513
39a53e0c
JK
514struct f2fs_sb_info {
515 struct super_block *sb; /* pointer to VFS super block */
5e176d54 516 struct proc_dir_entry *s_proc; /* proc entry */
39a53e0c
JK
517 struct buffer_head *raw_super_buf; /* buffer head of raw sb */
518 struct f2fs_super_block *raw_super; /* raw super block pointer */
519 int s_dirty; /* dirty flag for checkpoint */
2ae4c673 520 bool need_fsck; /* need fsck.f2fs to fix */
39a53e0c
JK
521
522 /* for node-related operations */
523 struct f2fs_nm_info *nm_info; /* node manager */
524 struct inode *node_inode; /* cache node blocks */
525
526 /* for segment-related operations */
527 struct f2fs_sm_info *sm_info; /* segment manager */
1ff7bd3b
JK
528
529 /* for bio operations */
924b720b 530 struct f2fs_bio_info read_io; /* for read bios */
1ff7bd3b 531 struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */
39a53e0c
JK
532
533 /* for checkpoint */
534 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
535 struct inode *meta_inode; /* cache meta blocks */
39936837 536 struct mutex cp_mutex; /* checkpoint procedure lock */
e479556b 537 struct rw_semaphore cp_rwsem; /* blocking FS operations */
b3582c68 538 struct rw_semaphore node_write; /* locking node writes */
39a53e0c 539 struct mutex writepages; /* mutex for writepages() */
aabe5136 540 bool por_doing; /* recovery is doing or not */
fb51b5ef 541 wait_queue_head_t cp_wait;
39a53e0c 542
67298804 543 struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
6451e041
JK
544
545 /* for orphan inode, use 0'th array */
0d47c1ad 546 unsigned int max_orphans; /* max orphan inodes */
39a53e0c
JK
547
548 /* for directory inode management */
549 struct list_head dir_inode_list; /* dir inode list */
550 spinlock_t dir_inode_lock; /* for dir inode list lock */
39a53e0c 551
e1c42045 552 /* basic filesystem units */
39a53e0c
JK
553 unsigned int log_sectors_per_block; /* log2 sectors per block */
554 unsigned int log_blocksize; /* log2 block size */
555 unsigned int blocksize; /* block size */
556 unsigned int root_ino_num; /* root inode number*/
557 unsigned int node_ino_num; /* node inode number*/
558 unsigned int meta_ino_num; /* meta inode number*/
559 unsigned int log_blocks_per_seg; /* log2 blocks per segment */
560 unsigned int blocks_per_seg; /* blocks per segment */
561 unsigned int segs_per_sec; /* segments per section */
562 unsigned int secs_per_zone; /* sections per zone */
563 unsigned int total_sections; /* total section count */
564 unsigned int total_node_count; /* total node block count */
565 unsigned int total_valid_node_count; /* valid node block count */
566 unsigned int total_valid_inode_count; /* valid inode count */
567 int active_logs; /* # of active logs */
ab9fa662 568 int dir_level; /* directory level */
39a53e0c
JK
569
570 block_t user_block_count; /* # of user blocks */
571 block_t total_valid_block_count; /* # of valid blocks */
572 block_t alloc_valid_block_count; /* # of allocated blocks */
573 block_t last_valid_block_count; /* for recovery */
574 u32 s_next_generation; /* for NFS support */
575 atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
576
577 struct f2fs_mount_info mount_opt; /* mount options */
578
579 /* for cleaning operations */
580 struct mutex gc_mutex; /* mutex for GC */
581 struct f2fs_gc_kthread *gc_thread; /* GC thread */
5ec4e49f 582 unsigned int cur_victim_sec; /* current victim section num */
39a53e0c 583
b1c57c1c
JK
584 /* maximum # of trials to find a victim segment for SSR and GC */
585 unsigned int max_victim_search;
586
39a53e0c
JK
587 /*
588 * for stat information.
589 * one is for the LFS mode, and the other is for the SSR mode.
590 */
35b09d82 591#ifdef CONFIG_F2FS_STAT_FS
39a53e0c
JK
592 struct f2fs_stat_info *stat_info; /* FS status information */
593 unsigned int segment_count[2]; /* # of allocated segments */
594 unsigned int block_count[2]; /* # of allocated blocks */
39a53e0c 595 int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
03e14d52
CY
596 atomic_t inline_inode; /* # of inline_data inodes */
597 atomic_t inline_dir; /* # of inline_dentry inodes */
39a53e0c 598 int bg_gc; /* background gc calls */
35b09d82
NJ
599 unsigned int n_dirty_dirs; /* # of dir inodes */
600#endif
601 unsigned int last_victim[2]; /* last victim segment # */
39a53e0c 602 spinlock_t stat_lock; /* lock for stat operations */
b59d0bae
NJ
603
604 /* For sysfs suppport */
605 struct kobject s_kobj;
606 struct completion s_kobj_unregister;
39a53e0c
JK
607};
608
609/*
610 * Inline functions
611 */
612static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
613{
614 return container_of(inode, struct f2fs_inode_info, vfs_inode);
615}
616
617static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
618{
619 return sb->s_fs_info;
620}
621
4081363f
JK
622static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
623{
624 return F2FS_SB(inode->i_sb);
625}
626
627static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
628{
629 return F2FS_I_SB(mapping->host);
630}
631
632static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
633{
634 return F2FS_M_SB(page->mapping);
635}
636
39a53e0c
JK
637static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
638{
639 return (struct f2fs_super_block *)(sbi->raw_super);
640}
641
642static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
643{
644 return (struct f2fs_checkpoint *)(sbi->ckpt);
645}
646
45590710
GZ
647static inline struct f2fs_node *F2FS_NODE(struct page *page)
648{
649 return (struct f2fs_node *)page_address(page);
650}
651
58bfaf44
JK
652static inline struct f2fs_inode *F2FS_INODE(struct page *page)
653{
654 return &((struct f2fs_node *)page_address(page))->i;
655}
656
39a53e0c
JK
657static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
658{
659 return (struct f2fs_nm_info *)(sbi->nm_info);
660}
661
662static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
663{
664 return (struct f2fs_sm_info *)(sbi->sm_info);
665}
666
667static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
668{
669 return (struct sit_info *)(SM_I(sbi)->sit_info);
670}
671
672static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
673{
674 return (struct free_segmap_info *)(SM_I(sbi)->free_info);
675}
676
677static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
678{
679 return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
680}
681
9df27d98
GZ
682static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
683{
684 return sbi->meta_inode->i_mapping;
685}
686
4ef51a8f
JK
687static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
688{
689 return sbi->node_inode->i_mapping;
690}
691
39a53e0c
JK
692static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
693{
694 sbi->s_dirty = 1;
695}
696
697static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
698{
699 sbi->s_dirty = 0;
700}
701
d71b5564
JK
702static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
703{
704 return le64_to_cpu(cp->checkpoint_ver);
705}
706
25ca923b
JK
707static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
708{
709 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
710 return ckpt_flags & f;
711}
712
713static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
714{
715 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
716 ckpt_flags |= f;
717 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
718}
719
720static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
721{
722 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
723 ckpt_flags &= (~f);
724 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
725}
726
e479556b 727static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
39936837 728{
e479556b 729 down_read(&sbi->cp_rwsem);
39936837
JK
730}
731
e479556b 732static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
39a53e0c 733{
e479556b 734 up_read(&sbi->cp_rwsem);
39a53e0c
JK
735}
736
e479556b 737static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
39a53e0c 738{
0daaad97 739 f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex);
39936837
JK
740}
741
e479556b 742static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
39936837 743{
e479556b 744 up_write(&sbi->cp_rwsem);
39a53e0c
JK
745}
746
747/*
748 * Check whether the given nid is within node id range.
749 */
064e0823 750static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
39a53e0c 751{
d6b7d4b3
CY
752 if (unlikely(nid < F2FS_ROOT_INO(sbi)))
753 return -EINVAL;
cfb271d4 754 if (unlikely(nid >= NM_I(sbi)->max_nid))
064e0823
NJ
755 return -EINVAL;
756 return 0;
39a53e0c
JK
757}
758
759#define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
760
761/*
762 * Check whether the inode has blocks or not
763 */
764static inline int F2FS_HAS_BLOCKS(struct inode *inode)
765{
766 if (F2FS_I(inode)->i_xattr_nid)
6c311ec6 767 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
39a53e0c 768 else
6c311ec6 769 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
39a53e0c
JK
770}
771
4bc8e9bc
CY
772static inline bool f2fs_has_xattr_block(unsigned int ofs)
773{
774 return ofs == XATTR_NODE_OFFSET;
775}
776
39a53e0c
JK
777static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
778 struct inode *inode, blkcnt_t count)
779{
780 block_t valid_block_count;
781
782 spin_lock(&sbi->stat_lock);
783 valid_block_count =
784 sbi->total_valid_block_count + (block_t)count;
cfb271d4 785 if (unlikely(valid_block_count > sbi->user_block_count)) {
39a53e0c
JK
786 spin_unlock(&sbi->stat_lock);
787 return false;
788 }
789 inode->i_blocks += count;
790 sbi->total_valid_block_count = valid_block_count;
791 sbi->alloc_valid_block_count += (block_t)count;
792 spin_unlock(&sbi->stat_lock);
793 return true;
794}
795
da19b0dc 796static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
39a53e0c
JK
797 struct inode *inode,
798 blkcnt_t count)
799{
800 spin_lock(&sbi->stat_lock);
9850cf4a
JK
801 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
802 f2fs_bug_on(sbi, inode->i_blocks < count);
39a53e0c
JK
803 inode->i_blocks -= count;
804 sbi->total_valid_block_count -= (block_t)count;
805 spin_unlock(&sbi->stat_lock);
39a53e0c
JK
806}
807
808static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
809{
810 atomic_inc(&sbi->nr_pages[count_type]);
811 F2FS_SET_SB_DIRT(sbi);
812}
813
a7ffdbe2 814static inline void inode_inc_dirty_pages(struct inode *inode)
39a53e0c 815{
a7ffdbe2
JK
816 atomic_inc(&F2FS_I(inode)->dirty_pages);
817 if (S_ISDIR(inode->i_mode))
818 inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
39a53e0c
JK
819}
820
821static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
822{
823 atomic_dec(&sbi->nr_pages[count_type]);
824}
825
a7ffdbe2 826static inline void inode_dec_dirty_pages(struct inode *inode)
39a53e0c 827{
a7ffdbe2 828 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode))
1fe54f9d
JK
829 return;
830
a7ffdbe2
JK
831 atomic_dec(&F2FS_I(inode)->dirty_pages);
832
833 if (S_ISDIR(inode->i_mode))
834 dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
39a53e0c
JK
835}
836
837static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
838{
839 return atomic_read(&sbi->nr_pages[count_type]);
840}
841
a7ffdbe2 842static inline int get_dirty_pages(struct inode *inode)
f8b2c1f9 843{
a7ffdbe2 844 return atomic_read(&F2FS_I(inode)->dirty_pages);
f8b2c1f9
JK
845}
846
5ac206cf
NJ
847static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
848{
849 unsigned int pages_per_sec = sbi->segs_per_sec *
850 (1 << sbi->log_blocks_per_seg);
851 return ((get_pages(sbi, block_type) + pages_per_sec - 1)
852 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
853}
854
39a53e0c
JK
855static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
856{
8b8343fa 857 return sbi->total_valid_block_count;
39a53e0c
JK
858}
859
860static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
861{
862 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
863
864 /* return NAT or SIT bitmap */
865 if (flag == NAT_BITMAP)
866 return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
867 else if (flag == SIT_BITMAP)
868 return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
869
870 return 0;
871}
872
873static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
874{
875 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1dbe4152
CL
876 int offset;
877
878 if (le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload) > 0) {
879 if (flag == NAT_BITMAP)
880 return &ckpt->sit_nat_version_bitmap;
881 else
65b85ccc 882 return (unsigned char *)ckpt + F2FS_BLKSIZE;
1dbe4152
CL
883 } else {
884 offset = (flag == NAT_BITMAP) ?
25ca923b 885 le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
1dbe4152
CL
886 return &ckpt->sit_nat_version_bitmap + offset;
887 }
39a53e0c
JK
888}
889
890static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
891{
892 block_t start_addr;
893 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
d71b5564 894 unsigned long long ckpt_version = cur_cp_version(ckpt);
39a53e0c 895
25ca923b 896 start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
39a53e0c
JK
897
898 /*
899 * odd numbered checkpoint should at cp segment 0
e1c42045 900 * and even segment must be at cp segment 1
39a53e0c
JK
901 */
902 if (!(ckpt_version & 1))
903 start_addr += sbi->blocks_per_seg;
904
905 return start_addr;
906}
907
908static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
909{
910 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
911}
912
913static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
ef86d709 914 struct inode *inode)
39a53e0c
JK
915{
916 block_t valid_block_count;
917 unsigned int valid_node_count;
918
919 spin_lock(&sbi->stat_lock);
920
ef86d709 921 valid_block_count = sbi->total_valid_block_count + 1;
cfb271d4 922 if (unlikely(valid_block_count > sbi->user_block_count)) {
39a53e0c
JK
923 spin_unlock(&sbi->stat_lock);
924 return false;
925 }
926
ef86d709 927 valid_node_count = sbi->total_valid_node_count + 1;
cfb271d4 928 if (unlikely(valid_node_count > sbi->total_node_count)) {
39a53e0c
JK
929 spin_unlock(&sbi->stat_lock);
930 return false;
931 }
932
933 if (inode)
ef86d709
GZ
934 inode->i_blocks++;
935
936 sbi->alloc_valid_block_count++;
937 sbi->total_valid_node_count++;
938 sbi->total_valid_block_count++;
39a53e0c
JK
939 spin_unlock(&sbi->stat_lock);
940
941 return true;
942}
943
944static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
ef86d709 945 struct inode *inode)
39a53e0c
JK
946{
947 spin_lock(&sbi->stat_lock);
948
9850cf4a
JK
949 f2fs_bug_on(sbi, !sbi->total_valid_block_count);
950 f2fs_bug_on(sbi, !sbi->total_valid_node_count);
951 f2fs_bug_on(sbi, !inode->i_blocks);
39a53e0c 952
ef86d709
GZ
953 inode->i_blocks--;
954 sbi->total_valid_node_count--;
955 sbi->total_valid_block_count--;
39a53e0c
JK
956
957 spin_unlock(&sbi->stat_lock);
958}
959
960static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
961{
8b8343fa 962 return sbi->total_valid_node_count;
39a53e0c
JK
963}
964
965static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
966{
967 spin_lock(&sbi->stat_lock);
9850cf4a 968 f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count);
39a53e0c
JK
969 sbi->total_valid_inode_count++;
970 spin_unlock(&sbi->stat_lock);
971}
972
0e80220a 973static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
39a53e0c
JK
974{
975 spin_lock(&sbi->stat_lock);
9850cf4a 976 f2fs_bug_on(sbi, !sbi->total_valid_inode_count);
39a53e0c
JK
977 sbi->total_valid_inode_count--;
978 spin_unlock(&sbi->stat_lock);
39a53e0c
JK
979}
980
981static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
982{
8b8343fa 983 return sbi->total_valid_inode_count;
39a53e0c
JK
984}
985
986static inline void f2fs_put_page(struct page *page, int unlock)
987{
031fa8cc 988 if (!page)
39a53e0c
JK
989 return;
990
991 if (unlock) {
9850cf4a 992 f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
39a53e0c
JK
993 unlock_page(page);
994 }
995 page_cache_release(page);
996}
997
998static inline void f2fs_put_dnode(struct dnode_of_data *dn)
999{
1000 if (dn->node_page)
1001 f2fs_put_page(dn->node_page, 1);
1002 if (dn->inode_page && dn->node_page != dn->inode_page)
1003 f2fs_put_page(dn->inode_page, 0);
1004 dn->node_page = NULL;
1005 dn->inode_page = NULL;
1006}
1007
1008static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
e8512d2e 1009 size_t size)
39a53e0c 1010{
e8512d2e 1011 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
39a53e0c
JK
1012}
1013
7bd59381
GZ
1014static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
1015 gfp_t flags)
1016{
1017 void *entry;
1018retry:
1019 entry = kmem_cache_alloc(cachep, flags);
1020 if (!entry) {
1021 cond_resched();
1022 goto retry;
1023 }
1024
1025 return entry;
1026}
1027
9be32d72
JK
1028static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
1029 unsigned long index, void *item)
1030{
1031 while (radix_tree_insert(root, index, item))
1032 cond_resched();
1033}
1034
39a53e0c
JK
1035#define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
1036
1037static inline bool IS_INODE(struct page *page)
1038{
45590710 1039 struct f2fs_node *p = F2FS_NODE(page);
39a53e0c
JK
1040 return RAW_IS_INODE(p);
1041}
1042
1043static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
1044{
1045 return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
1046}
1047
1048static inline block_t datablock_addr(struct page *node_page,
1049 unsigned int offset)
1050{
1051 struct f2fs_node *raw_node;
1052 __le32 *addr_array;
45590710 1053 raw_node = F2FS_NODE(node_page);
39a53e0c
JK
1054 addr_array = blkaddr_in_node(raw_node);
1055 return le32_to_cpu(addr_array[offset]);
1056}
1057
1058static inline int f2fs_test_bit(unsigned int nr, char *addr)
1059{
1060 int mask;
1061
1062 addr += (nr >> 3);
1063 mask = 1 << (7 - (nr & 0x07));
1064 return mask & *addr;
1065}
1066
52aca074 1067static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
39a53e0c
JK
1068{
1069 int mask;
1070 int ret;
1071
1072 addr += (nr >> 3);
1073 mask = 1 << (7 - (nr & 0x07));
1074 ret = mask & *addr;
1075 *addr |= mask;
1076 return ret;
1077}
1078
52aca074 1079static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
39a53e0c
JK
1080{
1081 int mask;
1082 int ret;
1083
1084 addr += (nr >> 3);
1085 mask = 1 << (7 - (nr & 0x07));
1086 ret = mask & *addr;
1087 *addr &= ~mask;
1088 return ret;
1089}
1090
c6ac4c0e
GZ
1091static inline void f2fs_change_bit(unsigned int nr, char *addr)
1092{
1093 int mask;
1094
1095 addr += (nr >> 3);
1096 mask = 1 << (7 - (nr & 0x07));
1097 *addr ^= mask;
1098}
1099
39a53e0c
JK
1100/* used for f2fs_inode_info->flags */
1101enum {
1102 FI_NEW_INODE, /* indicate newly allocated inode */
b3783873 1103 FI_DIRTY_INODE, /* indicate inode is dirty or not */
ed57c27f 1104 FI_DIRTY_DIR, /* indicate directory has dirty pages */
39a53e0c
JK
1105 FI_INC_LINK, /* need to increment i_nlink */
1106 FI_ACL_MODE, /* indicate acl mode */
1107 FI_NO_ALLOC, /* should not allocate any blocks */
699489bb 1108 FI_UPDATE_DIR, /* should update inode block for consistency */
74d0b917 1109 FI_DELAY_IPUT, /* used for the recovery */
c11abd1a 1110 FI_NO_EXTENT, /* not to use the extent cache */
444c580f 1111 FI_INLINE_XATTR, /* used for inline xattr */
1001b347 1112 FI_INLINE_DATA, /* used for inline data*/
34d67deb 1113 FI_INLINE_DENTRY, /* used for inline dentry */
fff04f90
JK
1114 FI_APPEND_WRITE, /* inode has appended data */
1115 FI_UPDATE_WRITE, /* inode has in-place-update data */
88b88a66
JK
1116 FI_NEED_IPU, /* used for ipu per file */
1117 FI_ATOMIC_FILE, /* indicate atomic file */
02a1335f 1118 FI_VOLATILE_FILE, /* indicate volatile file */
1e84371f 1119 FI_DROP_CACHE, /* drop dirty page cache */
b3d208f9 1120 FI_DATA_EXIST, /* indicate data exists */
39a53e0c
JK
1121};
1122
1123static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
1124{
61e0f2d0
JK
1125 if (!test_bit(flag, &fi->flags))
1126 set_bit(flag, &fi->flags);
39a53e0c
JK
1127}
1128
1129static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
1130{
1131 return test_bit(flag, &fi->flags);
1132}
1133
1134static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
1135{
61e0f2d0
JK
1136 if (test_bit(flag, &fi->flags))
1137 clear_bit(flag, &fi->flags);
39a53e0c
JK
1138}
1139
1140static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
1141{
1142 fi->i_acl_mode = mode;
1143 set_inode_flag(fi, FI_ACL_MODE);
1144}
1145
444c580f
JK
1146static inline void get_inline_info(struct f2fs_inode_info *fi,
1147 struct f2fs_inode *ri)
1148{
1149 if (ri->i_inline & F2FS_INLINE_XATTR)
1150 set_inode_flag(fi, FI_INLINE_XATTR);
1001b347
HL
1151 if (ri->i_inline & F2FS_INLINE_DATA)
1152 set_inode_flag(fi, FI_INLINE_DATA);
34d67deb
CY
1153 if (ri->i_inline & F2FS_INLINE_DENTRY)
1154 set_inode_flag(fi, FI_INLINE_DENTRY);
b3d208f9
JK
1155 if (ri->i_inline & F2FS_DATA_EXIST)
1156 set_inode_flag(fi, FI_DATA_EXIST);
444c580f
JK
1157}
1158
1159static inline void set_raw_inline(struct f2fs_inode_info *fi,
1160 struct f2fs_inode *ri)
1161{
1162 ri->i_inline = 0;
1163
1164 if (is_inode_flag_set(fi, FI_INLINE_XATTR))
1165 ri->i_inline |= F2FS_INLINE_XATTR;
1001b347
HL
1166 if (is_inode_flag_set(fi, FI_INLINE_DATA))
1167 ri->i_inline |= F2FS_INLINE_DATA;
34d67deb
CY
1168 if (is_inode_flag_set(fi, FI_INLINE_DENTRY))
1169 ri->i_inline |= F2FS_INLINE_DENTRY;
b3d208f9
JK
1170 if (is_inode_flag_set(fi, FI_DATA_EXIST))
1171 ri->i_inline |= F2FS_DATA_EXIST;
444c580f
JK
1172}
1173
987c7c31
CY
1174static inline int f2fs_has_inline_xattr(struct inode *inode)
1175{
1176 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR);
1177}
1178
de93653f
JK
1179static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
1180{
987c7c31 1181 if (f2fs_has_inline_xattr(&fi->vfs_inode))
de93653f
JK
1182 return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
1183 return DEF_ADDRS_PER_INODE;
1184}
1185
65985d93
JK
1186static inline void *inline_xattr_addr(struct page *page)
1187{
695fd1ed 1188 struct f2fs_inode *ri = F2FS_INODE(page);
65985d93
JK
1189 return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
1190 F2FS_INLINE_XATTR_ADDRS]);
1191}
1192
1193static inline int inline_xattr_size(struct inode *inode)
1194{
987c7c31 1195 if (f2fs_has_inline_xattr(inode))
65985d93
JK
1196 return F2FS_INLINE_XATTR_ADDRS << 2;
1197 else
1198 return 0;
1199}
1200
0dbdc2ae
JK
1201static inline int f2fs_has_inline_data(struct inode *inode)
1202{
1203 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
1204}
1205
b3d208f9
JK
1206static inline void f2fs_clear_inline_inode(struct inode *inode)
1207{
1208 clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
1209 clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST);
1210}
1211
1212static inline int f2fs_exist_data(struct inode *inode)
1213{
1214 return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST);
1215}
1216
88b88a66
JK
1217static inline bool f2fs_is_atomic_file(struct inode *inode)
1218{
1219 return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE);
1220}
1221
02a1335f
JK
1222static inline bool f2fs_is_volatile_file(struct inode *inode)
1223{
1224 return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE);
1225}
1226
1e84371f
JK
1227static inline bool f2fs_is_drop_cache(struct inode *inode)
1228{
1229 return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE);
1230}
1231
1001b347
HL
1232static inline void *inline_data_addr(struct page *page)
1233{
695fd1ed 1234 struct f2fs_inode *ri = F2FS_INODE(page);
1001b347
HL
1235 return (void *)&(ri->i_addr[1]);
1236}
1237
34d67deb
CY
1238static inline int f2fs_has_inline_dentry(struct inode *inode)
1239{
1240 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY);
1241}
1242
1243static inline void *inline_dentry_addr(struct page *page)
1244{
1245 struct f2fs_inode *ri = F2FS_INODE(page);
1246 return (void *)&(ri->i_addr[1]);
1247}
1248
9486ba44
JK
1249static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
1250{
1251 if (!f2fs_has_inline_dentry(dir))
1252 kunmap(page);
1253}
1254
77888c1e
JK
1255static inline int f2fs_readonly(struct super_block *sb)
1256{
1257 return sb->s_flags & MS_RDONLY;
1258}
1259
1e968fdf
JK
1260static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
1261{
1262 return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1263}
1264
744602cf
JK
1265static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi)
1266{
1267 set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1268 sbi->sb->s_flags |= MS_RDONLY;
1269}
1270
a6dda0e6
CH
1271#define get_inode_mode(i) \
1272 ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
1273 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
1274
267378d4
CY
1275/* get offset of first page in next direct node */
1276#define PGOFS_OF_NEXT_DNODE(pgofs, fi) \
1277 ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \
1278 (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \
1279 ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi))
1280
39a53e0c
JK
1281/*
1282 * file.c
1283 */
1284int f2fs_sync_file(struct file *, loff_t, loff_t, int);
1285void truncate_data_blocks(struct dnode_of_data *);
764aa3e9 1286int truncate_blocks(struct inode *, u64, bool);
39a53e0c 1287void f2fs_truncate(struct inode *);
2d4d9fb5 1288int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
39a53e0c
JK
1289int f2fs_setattr(struct dentry *, struct iattr *);
1290int truncate_hole(struct inode *, pgoff_t, pgoff_t);
b292dcab 1291int truncate_data_blocks_range(struct dnode_of_data *, int);
39a53e0c 1292long f2fs_ioctl(struct file *, unsigned int, unsigned long);
e9750824 1293long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
39a53e0c
JK
1294
1295/*
1296 * inode.c
1297 */
1298void f2fs_set_inode_flags(struct inode *);
39a53e0c 1299struct inode *f2fs_iget(struct super_block *, unsigned long);
4660f9c0 1300int try_to_free_nats(struct f2fs_sb_info *, int);
39a53e0c 1301void update_inode(struct inode *, struct page *);
744602cf 1302void update_inode_page(struct inode *);
39a53e0c
JK
1303int f2fs_write_inode(struct inode *, struct writeback_control *);
1304void f2fs_evict_inode(struct inode *);
44c16156 1305void handle_failed_inode(struct inode *);
39a53e0c
JK
1306
1307/*
1308 * namei.c
1309 */
1310struct dentry *f2fs_get_parent(struct dentry *child);
1311
1312/*
1313 * dir.c
1314 */
dbeacf02 1315extern unsigned char f2fs_filetype_table[F2FS_FT_MAX];
dbeacf02 1316void set_de_type(struct f2fs_dir_entry *, struct inode *);
7b3cd7d6
JK
1317struct f2fs_dir_entry *find_target_dentry(struct qstr *, int *,
1318 struct f2fs_dentry_ptr *);
1319bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *,
1320 unsigned int);
062a3e7b
JK
1321void do_make_empty_dir(struct inode *, struct inode *,
1322 struct f2fs_dentry_ptr *);
dbeacf02 1323struct page *init_inode_metadata(struct inode *, struct inode *,
bce8d112 1324 const struct qstr *, struct page *);
dbeacf02 1325void update_parent_metadata(struct inode *, struct inode *, unsigned int);
a82afa20 1326int room_for_filename(const void *, int, int);
dbeacf02 1327void f2fs_drop_nlink(struct inode *, struct inode *, struct page *);
39a53e0c
JK
1328struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
1329 struct page **);
1330struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
1331ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
1332void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
1333 struct page *, struct inode *);
1cd14caf 1334int update_dent_inode(struct inode *, const struct qstr *);
b7f7a5e0 1335int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
dbeacf02
CY
1336void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *,
1337 struct inode *);
b97a9b5d 1338int f2fs_do_tmpfile(struct inode *, struct inode *);
39a53e0c
JK
1339int f2fs_make_empty(struct inode *, struct inode *);
1340bool f2fs_empty_dir(struct inode *);
1341
b7f7a5e0
AV
1342static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
1343{
1344 return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
1345 inode);
1346}
1347
39a53e0c
JK
1348/*
1349 * super.c
1350 */
1351int f2fs_sync_fs(struct super_block *, int);
a07ef784
NJ
1352extern __printf(3, 4)
1353void f2fs_msg(struct super_block *, const char *, const char *, ...);
39a53e0c
JK
1354
1355/*
1356 * hash.c
1357 */
eee6160f 1358f2fs_hash_t f2fs_dentry_hash(const struct qstr *);
39a53e0c
JK
1359
1360/*
1361 * node.c
1362 */
1363struct dnode_of_data;
1364struct node_info;
1365
6fb03f3a 1366bool available_free_memory(struct f2fs_sb_info *, int);
88bd02c9
JK
1367bool is_checkpointed_node(struct f2fs_sb_info *, nid_t);
1368bool has_fsynced_inode(struct f2fs_sb_info *, nid_t);
1369bool need_inode_block_update(struct f2fs_sb_info *, nid_t);
39a53e0c
JK
1370void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
1371int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
1372int truncate_inode_blocks(struct inode *, pgoff_t);
4f16fb0f 1373int truncate_xattr_node(struct inode *, struct page *);
cfe58f9d 1374int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
58e674d6 1375void remove_inode_page(struct inode *);
a014e037 1376struct page *new_inode_page(struct inode *);
8ae8f162 1377struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
39a53e0c
JK
1378void ra_node_page(struct f2fs_sb_info *, nid_t);
1379struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
1380struct page *get_node_page_ra(struct page *, int);
1381void sync_inode_page(struct dnode_of_data *);
1382int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
1383bool alloc_nid(struct f2fs_sb_info *, nid_t *);
1384void alloc_nid_done(struct f2fs_sb_info *, nid_t);
1385void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
70cfed88 1386void recover_inline_xattr(struct inode *, struct page *);
1c35a90e 1387void recover_xattr_data(struct inode *, struct page *, block_t);
39a53e0c
JK
1388int recover_inode_page(struct f2fs_sb_info *, struct page *);
1389int restore_node_summary(struct f2fs_sb_info *, unsigned int,
1390 struct f2fs_summary_block *);
1391void flush_nat_entries(struct f2fs_sb_info *);
1392int build_node_manager(struct f2fs_sb_info *);
1393void destroy_node_manager(struct f2fs_sb_info *);
6e6093a8 1394int __init create_node_manager_caches(void);
39a53e0c
JK
1395void destroy_node_manager_caches(void);
1396
1397/*
1398 * segment.c
1399 */
88b88a66
JK
1400void register_inmem_page(struct inode *, struct page *);
1401void commit_inmem_pages(struct inode *, bool);
39a53e0c 1402void f2fs_balance_fs(struct f2fs_sb_info *);
4660f9c0 1403void f2fs_balance_fs_bg(struct f2fs_sb_info *);
6b4afdd7 1404int f2fs_issue_flush(struct f2fs_sb_info *);
2163d198
GZ
1405int create_flush_cmd_control(struct f2fs_sb_info *);
1406void destroy_flush_cmd_control(struct f2fs_sb_info *);
39a53e0c 1407void invalidate_blocks(struct f2fs_sb_info *, block_t);
5e443818 1408void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
39a53e0c 1409void clear_prefree_segments(struct f2fs_sb_info *);
4b2fecc8 1410void release_discard_addrs(struct f2fs_sb_info *);
cf2271e7 1411void discard_next_dnode(struct f2fs_sb_info *, block_t);
3fa06d7b 1412int npages_for_summary_flush(struct f2fs_sb_info *, bool);
39a53e0c 1413void allocate_new_segments(struct f2fs_sb_info *);
4b2fecc8 1414int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *);
39a53e0c 1415struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
577e3495 1416void write_meta_page(struct f2fs_sb_info *, struct page *);
fb5566da 1417void write_node_page(struct f2fs_sb_info *, struct page *,
cf04e8eb
JK
1418 unsigned int, struct f2fs_io_info *);
1419void write_data_page(struct page *, struct dnode_of_data *,
1420 struct f2fs_io_info *);
1421void rewrite_data_page(struct page *, struct f2fs_io_info *);
39a53e0c
JK
1422void recover_data_page(struct f2fs_sb_info *, struct page *,
1423 struct f2fs_summary *, block_t, block_t);
bfad7c2d
JK
1424void allocate_data_block(struct f2fs_sb_info *, struct page *,
1425 block_t, block_t *, struct f2fs_summary *, int);
5514f0aa 1426void f2fs_wait_on_page_writeback(struct page *, enum page_type);
39a53e0c
JK
1427void write_data_summaries(struct f2fs_sb_info *, block_t);
1428void write_node_summaries(struct f2fs_sb_info *, block_t);
1429int lookup_journal_in_cursum(struct f2fs_summary_block *,
1430 int, unsigned int, int);
4b2fecc8 1431void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *);
39a53e0c 1432int build_segment_manager(struct f2fs_sb_info *);
39a53e0c 1433void destroy_segment_manager(struct f2fs_sb_info *);
7fd9e544
JK
1434int __init create_segment_manager_caches(void);
1435void destroy_segment_manager_caches(void);
39a53e0c
JK
1436
1437/*
1438 * checkpoint.c
1439 */
1440struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
1441struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
4c521f49 1442int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int);
635aee1f 1443void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t);
39a53e0c 1444long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
fff04f90
JK
1445void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
1446void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
6f12ac25 1447void release_dirty_inode(struct f2fs_sb_info *);
fff04f90 1448bool exist_written_data(struct f2fs_sb_info *, nid_t, int);
cbd56e7d
JK
1449int acquire_orphan_inode(struct f2fs_sb_info *);
1450void release_orphan_inode(struct f2fs_sb_info *);
39a53e0c
JK
1451void add_orphan_inode(struct f2fs_sb_info *, nid_t);
1452void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
8f99a946 1453void recover_orphan_inodes(struct f2fs_sb_info *);
39a53e0c 1454int get_valid_checkpoint(struct f2fs_sb_info *);
a7ffdbe2 1455void update_dirty_page(struct inode *, struct page *);
5deb8267 1456void add_dirty_dir_inode(struct inode *);
39a53e0c
JK
1457void remove_dirty_dir_inode(struct inode *);
1458void sync_dirty_dir_inodes(struct f2fs_sb_info *);
75ab4cb8 1459void write_checkpoint(struct f2fs_sb_info *, struct cp_control *);
6451e041 1460void init_ino_entry_info(struct f2fs_sb_info *);
6e6093a8 1461int __init create_checkpoint_caches(void);
39a53e0c
JK
1462void destroy_checkpoint_caches(void);
1463
1464/*
1465 * data.c
1466 */
458e6197 1467void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
cf04e8eb
JK
1468int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *,
1469 struct f2fs_io_info *);
1470void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *,
458e6197 1471 struct f2fs_io_info *);
39a53e0c 1472int reserve_new_block(struct dnode_of_data *);
b600965c 1473int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
39a53e0c 1474void update_extent_cache(block_t, struct dnode_of_data *);
c718379b 1475struct page *find_data_page(struct inode *, pgoff_t, bool);
39a53e0c 1476struct page *get_lock_data_page(struct inode *, pgoff_t);
64aa7ed9 1477struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
458e6197 1478int do_write_data_page(struct page *, struct f2fs_io_info *);
9ab70134 1479int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
39a53e0c
JK
1480
1481/*
1482 * gc.c
1483 */
1484int start_gc_thread(struct f2fs_sb_info *);
1485void stop_gc_thread(struct f2fs_sb_info *);
de93653f 1486block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
408e9375 1487int f2fs_gc(struct f2fs_sb_info *);
39a53e0c 1488void build_gc_manager(struct f2fs_sb_info *);
6e6093a8 1489int __init create_gc_caches(void);
39a53e0c
JK
1490void destroy_gc_caches(void);
1491
1492/*
1493 * recovery.c
1494 */
6ead1142 1495int recover_fsync_data(struct f2fs_sb_info *);
39a53e0c
JK
1496bool space_for_roll_forward(struct f2fs_sb_info *);
1497
1498/*
1499 * debug.c
1500 */
1501#ifdef CONFIG_F2FS_STAT_FS
1502struct f2fs_stat_info {
1503 struct list_head stat_list;
1504 struct f2fs_sb_info *sbi;
39a53e0c
JK
1505 int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
1506 int main_area_segs, main_area_sections, main_area_zones;
1507 int hit_ext, total_ext;
1508 int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
1509 int nats, sits, fnids;
1510 int total_count, utilization;
8dcf2ff7 1511 int bg_gc, inline_inode, inline_dir, inmem_pages;
39a53e0c
JK
1512 unsigned int valid_count, valid_node_count, valid_inode_count;
1513 unsigned int bimodal, avg_vblocks;
1514 int util_free, util_valid, util_invalid;
1515 int rsvd_segs, overp_segs;
1516 int dirty_count, node_pages, meta_pages;
942e0be6 1517 int prefree_count, call_count, cp_count;
39a53e0c
JK
1518 int tot_segs, node_segs, data_segs, free_segs, free_secs;
1519 int tot_blks, data_blks, node_blks;
1520 int curseg[NR_CURSEG_TYPE];
1521 int cursec[NR_CURSEG_TYPE];
1522 int curzone[NR_CURSEG_TYPE];
1523
1524 unsigned int segment_count[2];
1525 unsigned int block_count[2];
1526 unsigned base_mem, cache_mem;
1527};
1528
963d4f7d
GZ
1529static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
1530{
6c311ec6 1531 return (struct f2fs_stat_info *)sbi->stat_info;
963d4f7d
GZ
1532}
1533
942e0be6 1534#define stat_inc_cp_count(si) ((si)->cp_count++)
dcdfff65
JK
1535#define stat_inc_call_count(si) ((si)->call_count++)
1536#define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
1537#define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++)
1538#define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--)
1539#define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++)
1540#define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++)
0dbdc2ae
JK
1541#define stat_inc_inline_inode(inode) \
1542 do { \
1543 if (f2fs_has_inline_data(inode)) \
03e14d52 1544 (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \
0dbdc2ae
JK
1545 } while (0)
1546#define stat_dec_inline_inode(inode) \
1547 do { \
1548 if (f2fs_has_inline_data(inode)) \
03e14d52 1549 (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \
0dbdc2ae 1550 } while (0)
3289c061
JK
1551#define stat_inc_inline_dir(inode) \
1552 do { \
1553 if (f2fs_has_inline_dentry(inode)) \
03e14d52 1554 (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \
3289c061
JK
1555 } while (0)
1556#define stat_dec_inline_dir(inode) \
1557 do { \
1558 if (f2fs_has_inline_dentry(inode)) \
03e14d52 1559 (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \
3289c061 1560 } while (0)
dcdfff65
JK
1561#define stat_inc_seg_type(sbi, curseg) \
1562 ((sbi)->segment_count[(curseg)->alloc_type]++)
1563#define stat_inc_block_count(sbi, curseg) \
1564 ((sbi)->block_count[(curseg)->alloc_type]++)
39a53e0c
JK
1565
1566#define stat_inc_seg_count(sbi, type) \
1567 do { \
963d4f7d 1568 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
39a53e0c
JK
1569 (si)->tot_segs++; \
1570 if (type == SUM_TYPE_DATA) \
1571 si->data_segs++; \
1572 else \
1573 si->node_segs++; \
1574 } while (0)
1575
1576#define stat_inc_tot_blk_count(si, blks) \
1577 (si->tot_blks += (blks))
1578
1579#define stat_inc_data_blk_count(sbi, blks) \
1580 do { \
963d4f7d 1581 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
39a53e0c
JK
1582 stat_inc_tot_blk_count(si, blks); \
1583 si->data_blks += (blks); \
1584 } while (0)
1585
1586#define stat_inc_node_blk_count(sbi, blks) \
1587 do { \
963d4f7d 1588 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
39a53e0c
JK
1589 stat_inc_tot_blk_count(si, blks); \
1590 si->node_blks += (blks); \
1591 } while (0)
1592
1593int f2fs_build_stats(struct f2fs_sb_info *);
1594void f2fs_destroy_stats(struct f2fs_sb_info *);
6e6093a8 1595void __init f2fs_create_root_stats(void);
4589d25d 1596void f2fs_destroy_root_stats(void);
39a53e0c 1597#else
942e0be6 1598#define stat_inc_cp_count(si)
39a53e0c 1599#define stat_inc_call_count(si)
dcdfff65
JK
1600#define stat_inc_bggc_count(si)
1601#define stat_inc_dirty_dir(sbi)
1602#define stat_dec_dirty_dir(sbi)
1603#define stat_inc_total_hit(sb)
1604#define stat_inc_read_hit(sb)
0dbdc2ae
JK
1605#define stat_inc_inline_inode(inode)
1606#define stat_dec_inline_inode(inode)
3289c061
JK
1607#define stat_inc_inline_dir(inode)
1608#define stat_dec_inline_dir(inode)
dcdfff65
JK
1609#define stat_inc_seg_type(sbi, curseg)
1610#define stat_inc_block_count(sbi, curseg)
39a53e0c
JK
1611#define stat_inc_seg_count(si, type)
1612#define stat_inc_tot_blk_count(si, blks)
1613#define stat_inc_data_blk_count(si, blks)
1614#define stat_inc_node_blk_count(sbi, blks)
1615
1616static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
1617static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
6e6093a8 1618static inline void __init f2fs_create_root_stats(void) { }
4589d25d 1619static inline void f2fs_destroy_root_stats(void) { }
39a53e0c
JK
1620#endif
1621
1622extern const struct file_operations f2fs_dir_operations;
1623extern const struct file_operations f2fs_file_operations;
1624extern const struct inode_operations f2fs_file_inode_operations;
1625extern const struct address_space_operations f2fs_dblock_aops;
1626extern const struct address_space_operations f2fs_node_aops;
1627extern const struct address_space_operations f2fs_meta_aops;
1628extern const struct inode_operations f2fs_dir_inode_operations;
1629extern const struct inode_operations f2fs_symlink_inode_operations;
1630extern const struct inode_operations f2fs_special_inode_operations;
1001b347 1631
e18c65b2
HL
1632/*
1633 * inline.c
1634 */
e18c65b2 1635bool f2fs_may_inline(struct inode *);
b3d208f9 1636void read_inline_data(struct page *, struct page *);
e18c65b2 1637int f2fs_read_inline_data(struct inode *, struct page *);
b3d208f9
JK
1638int f2fs_convert_inline_page(struct dnode_of_data *, struct page *);
1639int f2fs_convert_inline_inode(struct inode *);
1640int f2fs_write_inline_data(struct inode *, struct page *);
1641void truncate_inline_data(struct page *, u64);
0342fd30 1642bool recover_inline_data(struct inode *, struct page *);
201a05be
CY
1643struct f2fs_dir_entry *find_in_inline_dir(struct inode *, struct qstr *,
1644 struct page **);
1645struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **);
1646int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *);
1647int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *);
1648void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *,
1649 struct inode *, struct inode *);
1650bool f2fs_empty_inline_dir(struct inode *);
1651int f2fs_read_inline_dir(struct file *, struct dir_context *);
39a53e0c 1652#endif