f2fs: change reclaim rate in percentage
[deliverable/linux.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
JK
23#ifdef CONFIG_F2FS_CHECK_FS
24#define f2fs_bug_on(condition) BUG_ON(condition)
0daaad97 25#define f2fs_down_write(x, y) down_write_nest_lock(x, y)
5d56b671
JK
26#else
27#define f2fs_bug_on(condition)
0daaad97 28#define f2fs_down_write(x, y) down_write(x)
5d56b671
JK
29#endif
30
39a53e0c
JK
31/*
32 * For mount options
33 */
34#define F2FS_MOUNT_BG_GC 0x00000001
35#define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
36#define F2FS_MOUNT_DISCARD 0x00000004
37#define F2FS_MOUNT_NOHEAP 0x00000008
38#define F2FS_MOUNT_XATTR_USER 0x00000010
39#define F2FS_MOUNT_POSIX_ACL 0x00000020
40#define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
444c580f 41#define F2FS_MOUNT_INLINE_XATTR 0x00000080
1001b347 42#define F2FS_MOUNT_INLINE_DATA 0x00000100
39a53e0c
JK
43
44#define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
45#define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
46#define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
47
48#define ver_after(a, b) (typecheck(unsigned long long, a) && \
49 typecheck(unsigned long long, b) && \
50 ((long long)((a) - (b)) > 0))
51
a9841c4d
JK
52typedef u32 block_t; /*
53 * should not change u32, since it is the on-disk block
54 * address format, __le32.
55 */
39a53e0c
JK
56typedef u32 nid_t;
57
58struct f2fs_mount_info {
59 unsigned int opt;
60};
61
7e586fa0
JK
62#define CRCPOLY_LE 0xedb88320
63
64static inline __u32 f2fs_crc32(void *buf, size_t len)
39a53e0c 65{
7e586fa0
JK
66 unsigned char *p = (unsigned char *)buf;
67 __u32 crc = F2FS_SUPER_MAGIC;
68 int i;
69
70 while (len--) {
71 crc ^= *p++;
72 for (i = 0; i < 8; i++)
73 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
74 }
75 return crc;
39a53e0c
JK
76}
77
7e586fa0 78static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
39a53e0c 79{
7e586fa0 80 return f2fs_crc32(buf, buf_size) == blk_crc;
39a53e0c
JK
81}
82
83/*
84 * For checkpoint manager
85 */
86enum {
87 NAT_BITMAP,
88 SIT_BITMAP
89};
90
662befda 91/*
81c1a0f1 92 * For CP/NAT/SIT/SSA readahead
662befda
CY
93 */
94enum {
95 META_CP,
96 META_NAT,
81c1a0f1
CY
97 META_SIT,
98 META_SSA
662befda
CY
99};
100
39a53e0c
JK
101/* for the list of orphan inodes */
102struct orphan_inode_entry {
103 struct list_head list; /* list head */
104 nid_t ino; /* inode number */
105};
106
107/* for the list of directory inodes */
108struct dir_inode_entry {
109 struct list_head list; /* list head */
110 struct inode *inode; /* vfs inode pointer */
111};
112
7fd9e544
JK
113/* for the list of blockaddresses to be discarded */
114struct discard_entry {
115 struct list_head list; /* list head */
116 block_t blkaddr; /* block address to be discarded */
117 int len; /* # of consecutive blocks of the discard */
118};
119
39a53e0c
JK
120/* for the list of fsync inodes, used only during recovery */
121struct fsync_inode_entry {
122 struct list_head list; /* list head */
123 struct inode *inode; /* vfs inode pointer */
124 block_t blkaddr; /* block address locating the last inode */
125};
126
127#define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats))
128#define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits))
129
130#define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne)
131#define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid)
132#define sit_in_journal(sum, i) (sum->sit_j.entries[i].se)
133#define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno)
134
135static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
136{
137 int before = nats_in_cursum(rs);
138 rs->n_nats = cpu_to_le16(before + i);
139 return before;
140}
141
142static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
143{
144 int before = sits_in_cursum(rs);
145 rs->n_sits = cpu_to_le16(before + i);
146 return before;
147}
148
e9750824
NJ
149/*
150 * ioctl commands
151 */
152#define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
153#define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
154
155#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
156/*
157 * ioctl commands in 32 bit emulation
158 */
159#define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
160#define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
161#endif
162
39a53e0c
JK
163/*
164 * For INODE and NODE manager
165 */
dbe6a5ff
JK
166/*
167 * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
168 * as its node offset to distinguish from index node blocks.
169 * But some bits are used to mark the node block.
170 */
171#define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
172 >> OFFSET_BIT_SHIFT)
266e97a8
JK
173enum {
174 ALLOC_NODE, /* allocate a new node page if needed */
175 LOOKUP_NODE, /* look up a node without readahead */
176 LOOKUP_NODE_RA, /*
177 * look up a node with readahead called
4f4124d0 178 * by get_data_block.
39a53e0c 179 */
266e97a8
JK
180};
181
39a53e0c
JK
182#define F2FS_LINK_MAX 32000 /* maximum link count per file */
183
184/* for in-memory extent cache entry */
c11abd1a
JK
185#define F2FS_MIN_EXTENT_LEN 16 /* minimum extent length */
186
39a53e0c
JK
187struct extent_info {
188 rwlock_t ext_lock; /* rwlock for consistency */
189 unsigned int fofs; /* start offset in a file */
190 u32 blk_addr; /* start block address of the extent */
111d2495 191 unsigned int len; /* length of the extent */
39a53e0c
JK
192};
193
194/*
195 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
196 */
197#define FADVISE_COLD_BIT 0x01
354a3399 198#define FADVISE_LOST_PINO_BIT 0x02
39a53e0c 199
ab9fa662
JK
200#define DEF_DIR_LEVEL 0
201
39a53e0c
JK
202struct f2fs_inode_info {
203 struct inode vfs_inode; /* serve a vfs inode */
204 unsigned long i_flags; /* keep an inode flags for ioctl */
205 unsigned char i_advise; /* use to give file attribute hints */
38431545 206 unsigned char i_dir_level; /* use for dentry level for large dir */
39a53e0c 207 unsigned int i_current_depth; /* use only in directory structure */
6666e6aa 208 unsigned int i_pino; /* parent inode number */
39a53e0c
JK
209 umode_t i_acl_mode; /* keep file acl mode temporarily */
210
211 /* Use below internally in f2fs*/
212 unsigned long flags; /* use to pass per-file flags */
39a53e0c
JK
213 atomic_t dirty_dents; /* # of dirty dentry pages */
214 f2fs_hash_t chash; /* hash value of given file name */
215 unsigned int clevel; /* maximum level of given file name */
216 nid_t i_xattr_nid; /* node id that contains xattrs */
e518ff81 217 unsigned long long xattr_ver; /* cp version of xattr modification */
39a53e0c
JK
218 struct extent_info ext; /* in-memory extent cache entry */
219};
220
221static inline void get_extent_info(struct extent_info *ext,
222 struct f2fs_extent i_ext)
223{
224 write_lock(&ext->ext_lock);
225 ext->fofs = le32_to_cpu(i_ext.fofs);
226 ext->blk_addr = le32_to_cpu(i_ext.blk_addr);
227 ext->len = le32_to_cpu(i_ext.len);
228 write_unlock(&ext->ext_lock);
229}
230
231static inline void set_raw_extent(struct extent_info *ext,
232 struct f2fs_extent *i_ext)
233{
234 read_lock(&ext->ext_lock);
235 i_ext->fofs = cpu_to_le32(ext->fofs);
236 i_ext->blk_addr = cpu_to_le32(ext->blk_addr);
237 i_ext->len = cpu_to_le32(ext->len);
238 read_unlock(&ext->ext_lock);
239}
240
241struct f2fs_nm_info {
242 block_t nat_blkaddr; /* base disk address of NAT */
243 nid_t max_nid; /* maximum possible node ids */
39a53e0c 244 nid_t next_scan_nid; /* the next nid to be scanned */
cdfc41c1 245 unsigned int ram_thresh; /* control the memory footprint */
39a53e0c
JK
246
247 /* NAT cache management */
248 struct radix_tree_root nat_root;/* root of the nat entry cache */
249 rwlock_t nat_tree_lock; /* protect nat_tree_lock */
250 unsigned int nat_cnt; /* the # of cached nat entries */
251 struct list_head nat_entries; /* cached nat entry list (clean) */
252 struct list_head dirty_nat_entries; /* cached nat entry list (dirty) */
253
254 /* free node ids management */
8a7ed66a 255 struct radix_tree_root free_nid_root;/* root of the free_nid cache */
39a53e0c
JK
256 struct list_head free_nid_list; /* a list for free nids */
257 spinlock_t free_nid_list_lock; /* protect free nid list */
258 unsigned int fcnt; /* the number of free node id */
259 struct mutex build_lock; /* lock for build free nids */
260
261 /* for checkpoint */
262 char *nat_bitmap; /* NAT bitmap pointer */
263 int bitmap_size; /* bitmap size */
264};
265
266/*
267 * this structure is used as one of function parameters.
268 * all the information are dedicated to a given direct node block determined
269 * by the data offset in a file.
270 */
271struct dnode_of_data {
272 struct inode *inode; /* vfs inode pointer */
273 struct page *inode_page; /* its inode page, NULL is possible */
274 struct page *node_page; /* cached direct node page */
275 nid_t nid; /* node id of the direct node block */
276 unsigned int ofs_in_node; /* data offset in the node page */
277 bool inode_page_locked; /* inode page is locked or not */
278 block_t data_blkaddr; /* block address of the node block */
279};
280
281static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
282 struct page *ipage, struct page *npage, nid_t nid)
283{
d66d1f76 284 memset(dn, 0, sizeof(*dn));
39a53e0c
JK
285 dn->inode = inode;
286 dn->inode_page = ipage;
287 dn->node_page = npage;
288 dn->nid = nid;
39a53e0c
JK
289}
290
291/*
292 * For SIT manager
293 *
294 * By default, there are 6 active log areas across the whole main area.
295 * When considering hot and cold data separation to reduce cleaning overhead,
296 * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
297 * respectively.
298 * In the current design, you should not change the numbers intentionally.
299 * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
300 * logs individually according to the underlying devices. (default: 6)
301 * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
302 * data and 8 for node logs.
303 */
304#define NR_CURSEG_DATA_TYPE (3)
305#define NR_CURSEG_NODE_TYPE (3)
306#define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
307
308enum {
309 CURSEG_HOT_DATA = 0, /* directory entry blocks */
310 CURSEG_WARM_DATA, /* data blocks */
311 CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
312 CURSEG_HOT_NODE, /* direct node blocks of directory files */
313 CURSEG_WARM_NODE, /* direct node blocks of normal files */
314 CURSEG_COLD_NODE, /* indirect node blocks */
315 NO_CHECK_TYPE
316};
317
318struct f2fs_sm_info {
319 struct sit_info *sit_info; /* whole segment information */
320 struct free_segmap_info *free_info; /* free segment information */
321 struct dirty_seglist_info *dirty_info; /* dirty segment information */
322 struct curseg_info *curseg_array; /* active segment information */
323
324 struct list_head wblist_head; /* list of under-writeback pages */
325 spinlock_t wblist_lock; /* lock for checkpoint */
326
327 block_t seg0_blkaddr; /* block address of 0'th segment */
328 block_t main_blkaddr; /* start block address of main area */
329 block_t ssa_blkaddr; /* start block address of SSA area */
330
331 unsigned int segment_count; /* total # of segments */
332 unsigned int main_segments; /* # of segments in main area */
333 unsigned int reserved_segments; /* # of reserved segments */
334 unsigned int ovp_segments; /* # of overprovision segments */
81eb8d6e
JK
335
336 /* a threshold to reclaim prefree segments */
337 unsigned int rec_prefree_segments;
7fd9e544
JK
338
339 /* for small discard management */
340 struct list_head discard_list; /* 4KB discard list */
341 int nr_discards; /* # of discards in the list */
342 int max_discards; /* max. discards to be issued */
216fbd64
JK
343
344 unsigned int ipu_policy; /* in-place-update policy */
345 unsigned int min_ipu_util; /* in-place-update threshold */
39a53e0c
JK
346};
347
39a53e0c
JK
348/*
349 * For superblock
350 */
351/*
352 * COUNT_TYPE for monitoring
353 *
354 * f2fs monitors the number of several block types such as on-writeback,
355 * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
356 */
357enum count_type {
358 F2FS_WRITEBACK,
359 F2FS_DIRTY_DENTS,
360 F2FS_DIRTY_NODES,
361 F2FS_DIRTY_META,
362 NR_COUNT_TYPE,
363};
364
39a53e0c
JK
365/*
366 * The below are the page types of bios used in submti_bio().
367 * The available types are:
368 * DATA User data pages. It operates as async mode.
369 * NODE Node pages. It operates as async mode.
370 * META FS metadata pages such as SIT, NAT, CP.
371 * NR_PAGE_TYPE The number of page types.
372 * META_FLUSH Make sure the previous pages are written
373 * with waiting the bio's completion
374 * ... Only can be used with META.
375 */
7d5e5109 376#define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type))
39a53e0c
JK
377enum page_type {
378 DATA,
379 NODE,
380 META,
381 NR_PAGE_TYPE,
382 META_FLUSH,
383};
384
458e6197 385struct f2fs_io_info {
7e8f2308
GZ
386 enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
387 int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */
458e6197
JK
388};
389
93dfe2ac 390#define is_read_io(rw) (((rw) & 1) == READ)
1ff7bd3b 391struct f2fs_bio_info {
458e6197 392 struct f2fs_sb_info *sbi; /* f2fs superblock */
1ff7bd3b
JK
393 struct bio *bio; /* bios to merge */
394 sector_t last_block_in_bio; /* last block number */
458e6197 395 struct f2fs_io_info fio; /* store buffered io info. */
1ff7bd3b
JK
396 struct mutex io_mutex; /* mutex for bio */
397};
398
39a53e0c
JK
399struct f2fs_sb_info {
400 struct super_block *sb; /* pointer to VFS super block */
5e176d54 401 struct proc_dir_entry *s_proc; /* proc entry */
39a53e0c
JK
402 struct buffer_head *raw_super_buf; /* buffer head of raw sb */
403 struct f2fs_super_block *raw_super; /* raw super block pointer */
404 int s_dirty; /* dirty flag for checkpoint */
405
406 /* for node-related operations */
407 struct f2fs_nm_info *nm_info; /* node manager */
408 struct inode *node_inode; /* cache node blocks */
409
410 /* for segment-related operations */
411 struct f2fs_sm_info *sm_info; /* segment manager */
1ff7bd3b
JK
412
413 /* for bio operations */
924b720b 414 struct f2fs_bio_info read_io; /* for read bios */
1ff7bd3b 415 struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */
1b1f559f 416 struct completion *wait_io; /* for completion bios */
39a53e0c
JK
417
418 /* for checkpoint */
419 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
420 struct inode *meta_inode; /* cache meta blocks */
39936837 421 struct mutex cp_mutex; /* checkpoint procedure lock */
e479556b 422 struct rw_semaphore cp_rwsem; /* blocking FS operations */
39936837 423 struct mutex node_write; /* locking node writes */
39a53e0c 424 struct mutex writepages; /* mutex for writepages() */
aabe5136 425 bool por_doing; /* recovery is doing or not */
fb51b5ef 426 wait_queue_head_t cp_wait;
39a53e0c
JK
427
428 /* for orphan inode management */
429 struct list_head orphan_inode_list; /* orphan inode list */
17b692f6 430 spinlock_t orphan_inode_lock; /* for orphan inode list */
39a53e0c 431 unsigned int n_orphans; /* # of orphan inodes */
0d47c1ad 432 unsigned int max_orphans; /* max orphan inodes */
39a53e0c
JK
433
434 /* for directory inode management */
435 struct list_head dir_inode_list; /* dir inode list */
436 spinlock_t dir_inode_lock; /* for dir inode list lock */
39a53e0c
JK
437
438 /* basic file system units */
439 unsigned int log_sectors_per_block; /* log2 sectors per block */
440 unsigned int log_blocksize; /* log2 block size */
441 unsigned int blocksize; /* block size */
442 unsigned int root_ino_num; /* root inode number*/
443 unsigned int node_ino_num; /* node inode number*/
444 unsigned int meta_ino_num; /* meta inode number*/
445 unsigned int log_blocks_per_seg; /* log2 blocks per segment */
446 unsigned int blocks_per_seg; /* blocks per segment */
447 unsigned int segs_per_sec; /* segments per section */
448 unsigned int secs_per_zone; /* sections per zone */
449 unsigned int total_sections; /* total section count */
450 unsigned int total_node_count; /* total node block count */
451 unsigned int total_valid_node_count; /* valid node block count */
452 unsigned int total_valid_inode_count; /* valid inode count */
453 int active_logs; /* # of active logs */
ab9fa662 454 int dir_level; /* directory level */
39a53e0c
JK
455
456 block_t user_block_count; /* # of user blocks */
457 block_t total_valid_block_count; /* # of valid blocks */
458 block_t alloc_valid_block_count; /* # of allocated blocks */
459 block_t last_valid_block_count; /* for recovery */
460 u32 s_next_generation; /* for NFS support */
461 atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
462
463 struct f2fs_mount_info mount_opt; /* mount options */
464
465 /* for cleaning operations */
466 struct mutex gc_mutex; /* mutex for GC */
467 struct f2fs_gc_kthread *gc_thread; /* GC thread */
5ec4e49f 468 unsigned int cur_victim_sec; /* current victim section num */
39a53e0c 469
b1c57c1c
JK
470 /* maximum # of trials to find a victim segment for SSR and GC */
471 unsigned int max_victim_search;
472
39a53e0c
JK
473 /*
474 * for stat information.
475 * one is for the LFS mode, and the other is for the SSR mode.
476 */
35b09d82 477#ifdef CONFIG_F2FS_STAT_FS
39a53e0c
JK
478 struct f2fs_stat_info *stat_info; /* FS status information */
479 unsigned int segment_count[2]; /* # of allocated segments */
480 unsigned int block_count[2]; /* # of allocated blocks */
39a53e0c 481 int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
0dbdc2ae 482 int inline_inode; /* # of inline_data inodes */
39a53e0c 483 int bg_gc; /* background gc calls */
35b09d82
NJ
484 unsigned int n_dirty_dirs; /* # of dir inodes */
485#endif
486 unsigned int last_victim[2]; /* last victim segment # */
39a53e0c 487 spinlock_t stat_lock; /* lock for stat operations */
b59d0bae
NJ
488
489 /* For sysfs suppport */
490 struct kobject s_kobj;
491 struct completion s_kobj_unregister;
39a53e0c
JK
492};
493
494/*
495 * Inline functions
496 */
497static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
498{
499 return container_of(inode, struct f2fs_inode_info, vfs_inode);
500}
501
502static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
503{
504 return sb->s_fs_info;
505}
506
507static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
508{
509 return (struct f2fs_super_block *)(sbi->raw_super);
510}
511
512static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
513{
514 return (struct f2fs_checkpoint *)(sbi->ckpt);
515}
516
45590710
GZ
517static inline struct f2fs_node *F2FS_NODE(struct page *page)
518{
519 return (struct f2fs_node *)page_address(page);
520}
521
58bfaf44
JK
522static inline struct f2fs_inode *F2FS_INODE(struct page *page)
523{
524 return &((struct f2fs_node *)page_address(page))->i;
525}
526
39a53e0c
JK
527static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
528{
529 return (struct f2fs_nm_info *)(sbi->nm_info);
530}
531
532static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
533{
534 return (struct f2fs_sm_info *)(sbi->sm_info);
535}
536
537static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
538{
539 return (struct sit_info *)(SM_I(sbi)->sit_info);
540}
541
542static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
543{
544 return (struct free_segmap_info *)(SM_I(sbi)->free_info);
545}
546
547static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
548{
549 return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
550}
551
9df27d98
GZ
552static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
553{
554 return sbi->meta_inode->i_mapping;
555}
556
4ef51a8f
JK
557static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
558{
559 return sbi->node_inode->i_mapping;
560}
561
39a53e0c
JK
562static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
563{
564 sbi->s_dirty = 1;
565}
566
567static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
568{
569 sbi->s_dirty = 0;
570}
571
d71b5564
JK
572static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
573{
574 return le64_to_cpu(cp->checkpoint_ver);
575}
576
25ca923b
JK
577static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
578{
579 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
580 return ckpt_flags & f;
581}
582
583static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
584{
585 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
586 ckpt_flags |= f;
587 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
588}
589
590static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
591{
592 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
593 ckpt_flags &= (~f);
594 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
595}
596
e479556b 597static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
39936837 598{
e479556b 599 down_read(&sbi->cp_rwsem);
39936837
JK
600}
601
e479556b 602static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
39a53e0c 603{
e479556b 604 up_read(&sbi->cp_rwsem);
39a53e0c
JK
605}
606
e479556b 607static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
39a53e0c 608{
0daaad97 609 f2fs_down_write(&sbi->cp_rwsem, &sbi->cp_mutex);
39936837
JK
610}
611
e479556b 612static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
39936837 613{
e479556b 614 up_write(&sbi->cp_rwsem);
39a53e0c
JK
615}
616
617/*
618 * Check whether the given nid is within node id range.
619 */
064e0823 620static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
39a53e0c 621{
064e0823 622 WARN_ON((nid >= NM_I(sbi)->max_nid));
cfb271d4 623 if (unlikely(nid >= NM_I(sbi)->max_nid))
064e0823
NJ
624 return -EINVAL;
625 return 0;
39a53e0c
JK
626}
627
628#define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
629
630/*
631 * Check whether the inode has blocks or not
632 */
633static inline int F2FS_HAS_BLOCKS(struct inode *inode)
634{
635 if (F2FS_I(inode)->i_xattr_nid)
6c311ec6 636 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
39a53e0c 637 else
6c311ec6 638 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
39a53e0c
JK
639}
640
4bc8e9bc
CY
641static inline bool f2fs_has_xattr_block(unsigned int ofs)
642{
643 return ofs == XATTR_NODE_OFFSET;
644}
645
39a53e0c
JK
646static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
647 struct inode *inode, blkcnt_t count)
648{
649 block_t valid_block_count;
650
651 spin_lock(&sbi->stat_lock);
652 valid_block_count =
653 sbi->total_valid_block_count + (block_t)count;
cfb271d4 654 if (unlikely(valid_block_count > sbi->user_block_count)) {
39a53e0c
JK
655 spin_unlock(&sbi->stat_lock);
656 return false;
657 }
658 inode->i_blocks += count;
659 sbi->total_valid_block_count = valid_block_count;
660 sbi->alloc_valid_block_count += (block_t)count;
661 spin_unlock(&sbi->stat_lock);
662 return true;
663}
664
da19b0dc 665static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
39a53e0c
JK
666 struct inode *inode,
667 blkcnt_t count)
668{
669 spin_lock(&sbi->stat_lock);
5d56b671
JK
670 f2fs_bug_on(sbi->total_valid_block_count < (block_t) count);
671 f2fs_bug_on(inode->i_blocks < count);
39a53e0c
JK
672 inode->i_blocks -= count;
673 sbi->total_valid_block_count -= (block_t)count;
674 spin_unlock(&sbi->stat_lock);
39a53e0c
JK
675}
676
677static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
678{
679 atomic_inc(&sbi->nr_pages[count_type]);
680 F2FS_SET_SB_DIRT(sbi);
681}
682
683static inline void inode_inc_dirty_dents(struct inode *inode)
684{
1fe54f9d 685 inc_page_count(F2FS_SB(inode->i_sb), F2FS_DIRTY_DENTS);
39a53e0c
JK
686 atomic_inc(&F2FS_I(inode)->dirty_dents);
687}
688
689static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
690{
691 atomic_dec(&sbi->nr_pages[count_type]);
692}
693
694static inline void inode_dec_dirty_dents(struct inode *inode)
695{
1fe54f9d
JK
696 if (!S_ISDIR(inode->i_mode))
697 return;
698
699 dec_page_count(F2FS_SB(inode->i_sb), F2FS_DIRTY_DENTS);
39a53e0c
JK
700 atomic_dec(&F2FS_I(inode)->dirty_dents);
701}
702
703static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
704{
705 return atomic_read(&sbi->nr_pages[count_type]);
706}
707
f8b2c1f9
JK
708static inline int get_dirty_dents(struct inode *inode)
709{
710 return atomic_read(&F2FS_I(inode)->dirty_dents);
711}
712
5ac206cf
NJ
713static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
714{
715 unsigned int pages_per_sec = sbi->segs_per_sec *
716 (1 << sbi->log_blocks_per_seg);
717 return ((get_pages(sbi, block_type) + pages_per_sec - 1)
718 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
719}
720
39a53e0c
JK
721static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
722{
8b8343fa 723 return sbi->total_valid_block_count;
39a53e0c
JK
724}
725
726static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
727{
728 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
729
730 /* return NAT or SIT bitmap */
731 if (flag == NAT_BITMAP)
732 return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
733 else if (flag == SIT_BITMAP)
734 return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
735
736 return 0;
737}
738
739static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
740{
741 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
25ca923b
JK
742 int offset = (flag == NAT_BITMAP) ?
743 le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
39a53e0c
JK
744 return &ckpt->sit_nat_version_bitmap + offset;
745}
746
747static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
748{
749 block_t start_addr;
750 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
d71b5564 751 unsigned long long ckpt_version = cur_cp_version(ckpt);
39a53e0c 752
25ca923b 753 start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
39a53e0c
JK
754
755 /*
756 * odd numbered checkpoint should at cp segment 0
757 * and even segent must be at cp segment 1
758 */
759 if (!(ckpt_version & 1))
760 start_addr += sbi->blocks_per_seg;
761
762 return start_addr;
763}
764
765static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
766{
767 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
768}
769
770static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
ef86d709 771 struct inode *inode)
39a53e0c
JK
772{
773 block_t valid_block_count;
774 unsigned int valid_node_count;
775
776 spin_lock(&sbi->stat_lock);
777
ef86d709 778 valid_block_count = sbi->total_valid_block_count + 1;
cfb271d4 779 if (unlikely(valid_block_count > sbi->user_block_count)) {
39a53e0c
JK
780 spin_unlock(&sbi->stat_lock);
781 return false;
782 }
783
ef86d709 784 valid_node_count = sbi->total_valid_node_count + 1;
cfb271d4 785 if (unlikely(valid_node_count > sbi->total_node_count)) {
39a53e0c
JK
786 spin_unlock(&sbi->stat_lock);
787 return false;
788 }
789
790 if (inode)
ef86d709
GZ
791 inode->i_blocks++;
792
793 sbi->alloc_valid_block_count++;
794 sbi->total_valid_node_count++;
795 sbi->total_valid_block_count++;
39a53e0c
JK
796 spin_unlock(&sbi->stat_lock);
797
798 return true;
799}
800
801static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
ef86d709 802 struct inode *inode)
39a53e0c
JK
803{
804 spin_lock(&sbi->stat_lock);
805
ef86d709
GZ
806 f2fs_bug_on(!sbi->total_valid_block_count);
807 f2fs_bug_on(!sbi->total_valid_node_count);
808 f2fs_bug_on(!inode->i_blocks);
39a53e0c 809
ef86d709
GZ
810 inode->i_blocks--;
811 sbi->total_valid_node_count--;
812 sbi->total_valid_block_count--;
39a53e0c
JK
813
814 spin_unlock(&sbi->stat_lock);
815}
816
817static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
818{
8b8343fa 819 return sbi->total_valid_node_count;
39a53e0c
JK
820}
821
822static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
823{
824 spin_lock(&sbi->stat_lock);
5d56b671 825 f2fs_bug_on(sbi->total_valid_inode_count == sbi->total_node_count);
39a53e0c
JK
826 sbi->total_valid_inode_count++;
827 spin_unlock(&sbi->stat_lock);
828}
829
0e80220a 830static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
39a53e0c
JK
831{
832 spin_lock(&sbi->stat_lock);
5d56b671 833 f2fs_bug_on(!sbi->total_valid_inode_count);
39a53e0c
JK
834 sbi->total_valid_inode_count--;
835 spin_unlock(&sbi->stat_lock);
39a53e0c
JK
836}
837
838static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
839{
8b8343fa 840 return sbi->total_valid_inode_count;
39a53e0c
JK
841}
842
843static inline void f2fs_put_page(struct page *page, int unlock)
844{
031fa8cc 845 if (!page)
39a53e0c
JK
846 return;
847
848 if (unlock) {
5d56b671 849 f2fs_bug_on(!PageLocked(page));
39a53e0c
JK
850 unlock_page(page);
851 }
852 page_cache_release(page);
853}
854
855static inline void f2fs_put_dnode(struct dnode_of_data *dn)
856{
857 if (dn->node_page)
858 f2fs_put_page(dn->node_page, 1);
859 if (dn->inode_page && dn->node_page != dn->inode_page)
860 f2fs_put_page(dn->inode_page, 0);
861 dn->node_page = NULL;
862 dn->inode_page = NULL;
863}
864
865static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
e8512d2e 866 size_t size)
39a53e0c 867{
e8512d2e 868 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
39a53e0c
JK
869}
870
7bd59381
GZ
871static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
872 gfp_t flags)
873{
874 void *entry;
875retry:
876 entry = kmem_cache_alloc(cachep, flags);
877 if (!entry) {
878 cond_resched();
879 goto retry;
880 }
881
882 return entry;
883}
884
39a53e0c
JK
885#define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
886
887static inline bool IS_INODE(struct page *page)
888{
45590710 889 struct f2fs_node *p = F2FS_NODE(page);
39a53e0c
JK
890 return RAW_IS_INODE(p);
891}
892
893static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
894{
895 return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
896}
897
898static inline block_t datablock_addr(struct page *node_page,
899 unsigned int offset)
900{
901 struct f2fs_node *raw_node;
902 __le32 *addr_array;
45590710 903 raw_node = F2FS_NODE(node_page);
39a53e0c
JK
904 addr_array = blkaddr_in_node(raw_node);
905 return le32_to_cpu(addr_array[offset]);
906}
907
908static inline int f2fs_test_bit(unsigned int nr, char *addr)
909{
910 int mask;
911
912 addr += (nr >> 3);
913 mask = 1 << (7 - (nr & 0x07));
914 return mask & *addr;
915}
916
917static inline int f2fs_set_bit(unsigned int nr, char *addr)
918{
919 int mask;
920 int ret;
921
922 addr += (nr >> 3);
923 mask = 1 << (7 - (nr & 0x07));
924 ret = mask & *addr;
925 *addr |= mask;
926 return ret;
927}
928
929static inline int f2fs_clear_bit(unsigned int nr, char *addr)
930{
931 int mask;
932 int ret;
933
934 addr += (nr >> 3);
935 mask = 1 << (7 - (nr & 0x07));
936 ret = mask & *addr;
937 *addr &= ~mask;
938 return ret;
939}
940
941/* used for f2fs_inode_info->flags */
942enum {
943 FI_NEW_INODE, /* indicate newly allocated inode */
b3783873 944 FI_DIRTY_INODE, /* indicate inode is dirty or not */
39a53e0c
JK
945 FI_INC_LINK, /* need to increment i_nlink */
946 FI_ACL_MODE, /* indicate acl mode */
947 FI_NO_ALLOC, /* should not allocate any blocks */
699489bb 948 FI_UPDATE_DIR, /* should update inode block for consistency */
74d0b917 949 FI_DELAY_IPUT, /* used for the recovery */
c11abd1a 950 FI_NO_EXTENT, /* not to use the extent cache */
444c580f 951 FI_INLINE_XATTR, /* used for inline xattr */
1001b347 952 FI_INLINE_DATA, /* used for inline data*/
39a53e0c
JK
953};
954
955static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
956{
957 set_bit(flag, &fi->flags);
958}
959
960static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
961{
962 return test_bit(flag, &fi->flags);
963}
964
965static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
966{
967 clear_bit(flag, &fi->flags);
968}
969
970static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
971{
972 fi->i_acl_mode = mode;
973 set_inode_flag(fi, FI_ACL_MODE);
974}
975
976static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag)
977{
978 if (is_inode_flag_set(fi, FI_ACL_MODE)) {
979 clear_inode_flag(fi, FI_ACL_MODE);
980 return 1;
981 }
982 return 0;
983}
984
444c580f
JK
985static inline void get_inline_info(struct f2fs_inode_info *fi,
986 struct f2fs_inode *ri)
987{
988 if (ri->i_inline & F2FS_INLINE_XATTR)
989 set_inode_flag(fi, FI_INLINE_XATTR);
1001b347
HL
990 if (ri->i_inline & F2FS_INLINE_DATA)
991 set_inode_flag(fi, FI_INLINE_DATA);
444c580f
JK
992}
993
994static inline void set_raw_inline(struct f2fs_inode_info *fi,
995 struct f2fs_inode *ri)
996{
997 ri->i_inline = 0;
998
999 if (is_inode_flag_set(fi, FI_INLINE_XATTR))
1000 ri->i_inline |= F2FS_INLINE_XATTR;
1001b347
HL
1001 if (is_inode_flag_set(fi, FI_INLINE_DATA))
1002 ri->i_inline |= F2FS_INLINE_DATA;
444c580f
JK
1003}
1004
987c7c31
CY
1005static inline int f2fs_has_inline_xattr(struct inode *inode)
1006{
1007 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR);
1008}
1009
de93653f
JK
1010static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
1011{
987c7c31 1012 if (f2fs_has_inline_xattr(&fi->vfs_inode))
de93653f
JK
1013 return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
1014 return DEF_ADDRS_PER_INODE;
1015}
1016
65985d93
JK
1017static inline void *inline_xattr_addr(struct page *page)
1018{
695fd1ed 1019 struct f2fs_inode *ri = F2FS_INODE(page);
65985d93
JK
1020 return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
1021 F2FS_INLINE_XATTR_ADDRS]);
1022}
1023
1024static inline int inline_xattr_size(struct inode *inode)
1025{
987c7c31 1026 if (f2fs_has_inline_xattr(inode))
65985d93
JK
1027 return F2FS_INLINE_XATTR_ADDRS << 2;
1028 else
1029 return 0;
1030}
1031
0dbdc2ae
JK
1032static inline int f2fs_has_inline_data(struct inode *inode)
1033{
1034 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
1035}
1036
1001b347
HL
1037static inline void *inline_data_addr(struct page *page)
1038{
695fd1ed 1039 struct f2fs_inode *ri = F2FS_INODE(page);
1001b347
HL
1040 return (void *)&(ri->i_addr[1]);
1041}
1042
77888c1e
JK
1043static inline int f2fs_readonly(struct super_block *sb)
1044{
1045 return sb->s_flags & MS_RDONLY;
1046}
1047
744602cf
JK
1048static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi)
1049{
1050 set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1051 sbi->sb->s_flags |= MS_RDONLY;
1052}
1053
a6dda0e6
CH
1054#define get_inode_mode(i) \
1055 ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
1056 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
1057
39a53e0c
JK
1058/*
1059 * file.c
1060 */
1061int f2fs_sync_file(struct file *, loff_t, loff_t, int);
1062void truncate_data_blocks(struct dnode_of_data *);
1e1bb4ba 1063int truncate_blocks(struct inode *, u64);
39a53e0c 1064void f2fs_truncate(struct inode *);
2d4d9fb5 1065int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
39a53e0c
JK
1066int f2fs_setattr(struct dentry *, struct iattr *);
1067int truncate_hole(struct inode *, pgoff_t, pgoff_t);
b292dcab 1068int truncate_data_blocks_range(struct dnode_of_data *, int);
39a53e0c 1069long f2fs_ioctl(struct file *, unsigned int, unsigned long);
e9750824 1070long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
39a53e0c
JK
1071
1072/*
1073 * inode.c
1074 */
1075void f2fs_set_inode_flags(struct inode *);
39a53e0c 1076struct inode *f2fs_iget(struct super_block *, unsigned long);
4660f9c0 1077int try_to_free_nats(struct f2fs_sb_info *, int);
39a53e0c 1078void update_inode(struct inode *, struct page *);
744602cf 1079void update_inode_page(struct inode *);
39a53e0c
JK
1080int f2fs_write_inode(struct inode *, struct writeback_control *);
1081void f2fs_evict_inode(struct inode *);
1082
1083/*
1084 * namei.c
1085 */
1086struct dentry *f2fs_get_parent(struct dentry *child);
1087
1088/*
1089 * dir.c
1090 */
1091struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
1092 struct page **);
1093struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
1094ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
1095void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
1096 struct page *, struct inode *);
1cd14caf 1097int update_dent_inode(struct inode *, const struct qstr *);
b7f7a5e0 1098int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
39a53e0c
JK
1099void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
1100int f2fs_make_empty(struct inode *, struct inode *);
1101bool f2fs_empty_dir(struct inode *);
1102
b7f7a5e0
AV
1103static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
1104{
1105 return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
1106 inode);
1107}
1108
39a53e0c
JK
1109/*
1110 * super.c
1111 */
1112int f2fs_sync_fs(struct super_block *, int);
a07ef784
NJ
1113extern __printf(3, 4)
1114void f2fs_msg(struct super_block *, const char *, const char *, ...);
39a53e0c
JK
1115
1116/*
1117 * hash.c
1118 */
9836b8b9 1119f2fs_hash_t f2fs_dentry_hash(const char *, size_t);
39a53e0c
JK
1120
1121/*
1122 * node.c
1123 */
1124struct dnode_of_data;
1125struct node_info;
1126
1127int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
1128void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
1129int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
1130int truncate_inode_blocks(struct inode *, pgoff_t);
4f16fb0f 1131int truncate_xattr_node(struct inode *, struct page *);
cfe58f9d 1132int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
58e674d6 1133void remove_inode_page(struct inode *);
44a83ff6 1134struct page *new_inode_page(struct inode *, const struct qstr *);
8ae8f162 1135struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
39a53e0c
JK
1136void ra_node_page(struct f2fs_sb_info *, nid_t);
1137struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
1138struct page *get_node_page_ra(struct page *, int);
1139void sync_inode_page(struct dnode_of_data *);
1140int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
1141bool alloc_nid(struct f2fs_sb_info *, nid_t *);
1142void alloc_nid_done(struct f2fs_sb_info *, nid_t);
1143void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
1144void recover_node_page(struct f2fs_sb_info *, struct page *,
1145 struct f2fs_summary *, struct node_info *, block_t);
abb2366c 1146bool recover_xattr_data(struct inode *, struct page *, block_t);
39a53e0c
JK
1147int recover_inode_page(struct f2fs_sb_info *, struct page *);
1148int restore_node_summary(struct f2fs_sb_info *, unsigned int,
1149 struct f2fs_summary_block *);
1150void flush_nat_entries(struct f2fs_sb_info *);
1151int build_node_manager(struct f2fs_sb_info *);
1152void destroy_node_manager(struct f2fs_sb_info *);
6e6093a8 1153int __init create_node_manager_caches(void);
39a53e0c
JK
1154void destroy_node_manager_caches(void);
1155
1156/*
1157 * segment.c
1158 */
1159void f2fs_balance_fs(struct f2fs_sb_info *);
4660f9c0 1160void f2fs_balance_fs_bg(struct f2fs_sb_info *);
39a53e0c 1161void invalidate_blocks(struct f2fs_sb_info *, block_t);
5e443818 1162void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
39a53e0c
JK
1163void clear_prefree_segments(struct f2fs_sb_info *);
1164int npages_for_summary_flush(struct f2fs_sb_info *);
1165void allocate_new_segments(struct f2fs_sb_info *);
1166struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
577e3495 1167void write_meta_page(struct f2fs_sb_info *, struct page *);
fb5566da
JK
1168void write_node_page(struct f2fs_sb_info *, struct page *,
1169 struct f2fs_io_info *, unsigned int, block_t, block_t *);
458e6197
JK
1170void write_data_page(struct page *, struct dnode_of_data *, block_t *,
1171 struct f2fs_io_info *);
1172void rewrite_data_page(struct page *, block_t, struct f2fs_io_info *);
39a53e0c
JK
1173void recover_data_page(struct f2fs_sb_info *, struct page *,
1174 struct f2fs_summary *, block_t, block_t);
1175void rewrite_node_page(struct f2fs_sb_info *, struct page *,
1176 struct f2fs_summary *, block_t, block_t);
bfad7c2d
JK
1177void allocate_data_block(struct f2fs_sb_info *, struct page *,
1178 block_t, block_t *, struct f2fs_summary *, int);
5514f0aa 1179void f2fs_wait_on_page_writeback(struct page *, enum page_type);
39a53e0c
JK
1180void write_data_summaries(struct f2fs_sb_info *, block_t);
1181void write_node_summaries(struct f2fs_sb_info *, block_t);
1182int lookup_journal_in_cursum(struct f2fs_summary_block *,
1183 int, unsigned int, int);
1184void flush_sit_entries(struct f2fs_sb_info *);
1185int build_segment_manager(struct f2fs_sb_info *);
39a53e0c 1186void destroy_segment_manager(struct f2fs_sb_info *);
7fd9e544
JK
1187int __init create_segment_manager_caches(void);
1188void destroy_segment_manager_caches(void);
39a53e0c
JK
1189
1190/*
1191 * checkpoint.c
1192 */
1193struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
1194struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
662befda 1195int ra_meta_pages(struct f2fs_sb_info *, int, int, int);
39a53e0c 1196long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
cbd56e7d
JK
1197int acquire_orphan_inode(struct f2fs_sb_info *);
1198void release_orphan_inode(struct f2fs_sb_info *);
39a53e0c
JK
1199void add_orphan_inode(struct f2fs_sb_info *, nid_t);
1200void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
8f99a946 1201void recover_orphan_inodes(struct f2fs_sb_info *);
39a53e0c
JK
1202int get_valid_checkpoint(struct f2fs_sb_info *);
1203void set_dirty_dir_page(struct inode *, struct page *);
5deb8267 1204void add_dirty_dir_inode(struct inode *);
39a53e0c 1205void remove_dirty_dir_inode(struct inode *);
74d0b917 1206struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t);
39a53e0c 1207void sync_dirty_dir_inodes(struct f2fs_sb_info *);
43727527 1208void write_checkpoint(struct f2fs_sb_info *, bool);
39a53e0c 1209void init_orphan_info(struct f2fs_sb_info *);
6e6093a8 1210int __init create_checkpoint_caches(void);
39a53e0c
JK
1211void destroy_checkpoint_caches(void);
1212
1213/*
1214 * data.c
1215 */
458e6197 1216void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
93dfe2ac
JK
1217int f2fs_submit_page_bio(struct f2fs_sb_info *, struct page *, block_t, int);
1218void f2fs_submit_page_mbio(struct f2fs_sb_info *, struct page *, block_t,
458e6197 1219 struct f2fs_io_info *);
39a53e0c 1220int reserve_new_block(struct dnode_of_data *);
b600965c 1221int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
39a53e0c 1222void update_extent_cache(block_t, struct dnode_of_data *);
c718379b 1223struct page *find_data_page(struct inode *, pgoff_t, bool);
39a53e0c 1224struct page *get_lock_data_page(struct inode *, pgoff_t);
64aa7ed9 1225struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
458e6197 1226int do_write_data_page(struct page *, struct f2fs_io_info *);
39a53e0c
JK
1227
1228/*
1229 * gc.c
1230 */
1231int start_gc_thread(struct f2fs_sb_info *);
1232void stop_gc_thread(struct f2fs_sb_info *);
de93653f 1233block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
408e9375 1234int f2fs_gc(struct f2fs_sb_info *);
39a53e0c 1235void build_gc_manager(struct f2fs_sb_info *);
6e6093a8 1236int __init create_gc_caches(void);
39a53e0c
JK
1237void destroy_gc_caches(void);
1238
1239/*
1240 * recovery.c
1241 */
6ead1142 1242int recover_fsync_data(struct f2fs_sb_info *);
39a53e0c
JK
1243bool space_for_roll_forward(struct f2fs_sb_info *);
1244
1245/*
1246 * debug.c
1247 */
1248#ifdef CONFIG_F2FS_STAT_FS
1249struct f2fs_stat_info {
1250 struct list_head stat_list;
1251 struct f2fs_sb_info *sbi;
1252 struct mutex stat_lock;
1253 int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
1254 int main_area_segs, main_area_sections, main_area_zones;
1255 int hit_ext, total_ext;
1256 int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
1257 int nats, sits, fnids;
1258 int total_count, utilization;
0dbdc2ae 1259 int bg_gc, inline_inode;
39a53e0c
JK
1260 unsigned int valid_count, valid_node_count, valid_inode_count;
1261 unsigned int bimodal, avg_vblocks;
1262 int util_free, util_valid, util_invalid;
1263 int rsvd_segs, overp_segs;
1264 int dirty_count, node_pages, meta_pages;
942e0be6 1265 int prefree_count, call_count, cp_count;
39a53e0c
JK
1266 int tot_segs, node_segs, data_segs, free_segs, free_secs;
1267 int tot_blks, data_blks, node_blks;
1268 int curseg[NR_CURSEG_TYPE];
1269 int cursec[NR_CURSEG_TYPE];
1270 int curzone[NR_CURSEG_TYPE];
1271
1272 unsigned int segment_count[2];
1273 unsigned int block_count[2];
1274 unsigned base_mem, cache_mem;
1275};
1276
963d4f7d
GZ
1277static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
1278{
6c311ec6 1279 return (struct f2fs_stat_info *)sbi->stat_info;
963d4f7d
GZ
1280}
1281
942e0be6 1282#define stat_inc_cp_count(si) ((si)->cp_count++)
dcdfff65
JK
1283#define stat_inc_call_count(si) ((si)->call_count++)
1284#define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
1285#define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++)
1286#define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--)
1287#define stat_inc_total_hit(sb) ((F2FS_SB(sb))->total_hit_ext++)
1288#define stat_inc_read_hit(sb) ((F2FS_SB(sb))->read_hit_ext++)
0dbdc2ae
JK
1289#define stat_inc_inline_inode(inode) \
1290 do { \
1291 if (f2fs_has_inline_data(inode)) \
1292 ((F2FS_SB(inode->i_sb))->inline_inode++); \
1293 } while (0)
1294#define stat_dec_inline_inode(inode) \
1295 do { \
1296 if (f2fs_has_inline_data(inode)) \
1297 ((F2FS_SB(inode->i_sb))->inline_inode--); \
1298 } while (0)
1299
dcdfff65
JK
1300#define stat_inc_seg_type(sbi, curseg) \
1301 ((sbi)->segment_count[(curseg)->alloc_type]++)
1302#define stat_inc_block_count(sbi, curseg) \
1303 ((sbi)->block_count[(curseg)->alloc_type]++)
39a53e0c
JK
1304
1305#define stat_inc_seg_count(sbi, type) \
1306 do { \
963d4f7d 1307 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
39a53e0c
JK
1308 (si)->tot_segs++; \
1309 if (type == SUM_TYPE_DATA) \
1310 si->data_segs++; \
1311 else \
1312 si->node_segs++; \
1313 } while (0)
1314
1315#define stat_inc_tot_blk_count(si, blks) \
1316 (si->tot_blks += (blks))
1317
1318#define stat_inc_data_blk_count(sbi, blks) \
1319 do { \
963d4f7d 1320 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
39a53e0c
JK
1321 stat_inc_tot_blk_count(si, blks); \
1322 si->data_blks += (blks); \
1323 } while (0)
1324
1325#define stat_inc_node_blk_count(sbi, blks) \
1326 do { \
963d4f7d 1327 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
39a53e0c
JK
1328 stat_inc_tot_blk_count(si, blks); \
1329 si->node_blks += (blks); \
1330 } while (0)
1331
1332int f2fs_build_stats(struct f2fs_sb_info *);
1333void f2fs_destroy_stats(struct f2fs_sb_info *);
6e6093a8 1334void __init f2fs_create_root_stats(void);
4589d25d 1335void f2fs_destroy_root_stats(void);
39a53e0c 1336#else
942e0be6 1337#define stat_inc_cp_count(si)
39a53e0c 1338#define stat_inc_call_count(si)
dcdfff65
JK
1339#define stat_inc_bggc_count(si)
1340#define stat_inc_dirty_dir(sbi)
1341#define stat_dec_dirty_dir(sbi)
1342#define stat_inc_total_hit(sb)
1343#define stat_inc_read_hit(sb)
0dbdc2ae
JK
1344#define stat_inc_inline_inode(inode)
1345#define stat_dec_inline_inode(inode)
dcdfff65
JK
1346#define stat_inc_seg_type(sbi, curseg)
1347#define stat_inc_block_count(sbi, curseg)
39a53e0c
JK
1348#define stat_inc_seg_count(si, type)
1349#define stat_inc_tot_blk_count(si, blks)
1350#define stat_inc_data_blk_count(si, blks)
1351#define stat_inc_node_blk_count(sbi, blks)
1352
1353static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
1354static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
6e6093a8 1355static inline void __init f2fs_create_root_stats(void) { }
4589d25d 1356static inline void f2fs_destroy_root_stats(void) { }
39a53e0c
JK
1357#endif
1358
1359extern const struct file_operations f2fs_dir_operations;
1360extern const struct file_operations f2fs_file_operations;
1361extern const struct inode_operations f2fs_file_inode_operations;
1362extern const struct address_space_operations f2fs_dblock_aops;
1363extern const struct address_space_operations f2fs_node_aops;
1364extern const struct address_space_operations f2fs_meta_aops;
1365extern const struct inode_operations f2fs_dir_inode_operations;
1366extern const struct inode_operations f2fs_symlink_inode_operations;
1367extern const struct inode_operations f2fs_special_inode_operations;
1001b347 1368
e18c65b2
HL
1369/*
1370 * inline.c
1371 */
e18c65b2
HL
1372bool f2fs_may_inline(struct inode *);
1373int f2fs_read_inline_data(struct inode *, struct page *);
9e09fc85 1374int f2fs_convert_inline_data(struct inode *, pgoff_t);
e18c65b2 1375int f2fs_write_inline_data(struct inode *, struct page *, unsigned int);
1e1bb4ba 1376int recover_inline_data(struct inode *, struct page *);
39a53e0c 1377#endif
This page took 0.139652 seconds and 5 git commands to generate.