blob: a955a59dfdbe390bbbf2109a6e9a1ec072006a49 [file] [log] [blame]
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +09001/*
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09002 * 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>
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090017#include <linux/slab.h>
18#include <linux/crc32.h>
19#include <linux/magic.h>
Jaegeuk Kimc2d715d2013-08-08 15:56:49 +090020#include <linux/kobject.h>
Gu Zhenge4795562013-09-27 18:08:30 +080021#include <linux/wait.h>
22#include <linux/sched.h>
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090023
24/*
25 * For mount options
26 */
27#define F2FS_MOUNT_BG_GC 0x00000001
28#define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
29#define F2FS_MOUNT_DISCARD 0x00000004
30#define F2FS_MOUNT_NOHEAP 0x00000008
31#define F2FS_MOUNT_XATTR_USER 0x00000010
32#define F2FS_MOUNT_POSIX_ACL 0x00000020
33#define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
Jaegeuk Kim444c5802013-08-08 15:16:22 +090034#define F2FS_MOUNT_INLINE_XATTR 0x00000080
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090035
36#define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
37#define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
38#define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
39
40#define ver_after(a, b) (typecheck(unsigned long long, a) && \
41 typecheck(unsigned long long, b) && \
42 ((long long)((a) - (b)) > 0))
43
Jaegeuk Kima9841c42013-05-24 12:41:04 +090044typedef u32 block_t; /*
45 * should not change u32, since it is the on-disk block
46 * address format, __le32.
47 */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090048typedef u32 nid_t;
49
50struct f2fs_mount_info {
51 unsigned int opt;
52};
53
Jaegeuk Kim7e586fa2013-06-19 20:47:19 +090054#define CRCPOLY_LE 0xedb88320
55
56static inline __u32 f2fs_crc32(void *buf, size_t len)
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090057{
Jaegeuk Kim7e586fa2013-06-19 20:47:19 +090058 unsigned char *p = (unsigned char *)buf;
59 __u32 crc = F2FS_SUPER_MAGIC;
60 int i;
61
62 while (len--) {
63 crc ^= *p++;
64 for (i = 0; i < 8; i++)
65 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
66 }
67 return crc;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090068}
69
Jaegeuk Kim7e586fa2013-06-19 20:47:19 +090070static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090071{
Jaegeuk Kim7e586fa2013-06-19 20:47:19 +090072 return f2fs_crc32(buf, buf_size) == blk_crc;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090073}
74
75/*
76 * For checkpoint manager
77 */
78enum {
79 NAT_BITMAP,
80 SIT_BITMAP
81};
82
83/* for the list of orphan inodes */
84struct orphan_inode_entry {
85 struct list_head list; /* list head */
86 nid_t ino; /* inode number */
87};
88
89/* for the list of directory inodes */
90struct dir_inode_entry {
91 struct list_head list; /* list head */
92 struct inode *inode; /* vfs inode pointer */
93};
94
95/* for the list of fsync inodes, used only during recovery */
96struct fsync_inode_entry {
97 struct list_head list; /* list head */
98 struct inode *inode; /* vfs inode pointer */
99 block_t blkaddr; /* block address locating the last inode */
100};
101
102#define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats))
103#define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits))
104
105#define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne)
106#define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid)
107#define sit_in_journal(sum, i) (sum->sit_j.entries[i].se)
108#define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno)
109
110static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
111{
112 int before = nats_in_cursum(rs);
113 rs->n_nats = cpu_to_le16(before + i);
114 return before;
115}
116
117static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
118{
119 int before = sits_in_cursum(rs);
120 rs->n_sits = cpu_to_le16(before + i);
121 return before;
122}
123
124/*
Namjae Jeone9750822013-02-04 23:41:41 +0900125 * ioctl commands
126 */
127#define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
128#define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
129
130#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
131/*
132 * ioctl commands in 32 bit emulation
133 */
134#define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
135#define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
136#endif
137
138/*
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900139 * For INODE and NODE manager
140 */
Jaegeuk Kimdbe6a5f2013-08-09 08:14:06 +0900141/*
142 * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
143 * as its node offset to distinguish from index node blocks.
144 * But some bits are used to mark the node block.
145 */
146#define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
147 >> OFFSET_BIT_SHIFT)
Jaegeuk Kim266e97a2013-02-26 13:10:46 +0900148enum {
149 ALLOC_NODE, /* allocate a new node page if needed */
150 LOOKUP_NODE, /* look up a node without readahead */
151 LOOKUP_NODE_RA, /*
152 * look up a node with readahead called
153 * by get_datablock_ro.
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900154 */
Jaegeuk Kim266e97a2013-02-26 13:10:46 +0900155};
156
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900157#define F2FS_LINK_MAX 32000 /* maximum link count per file */
158
159/* for in-memory extent cache entry */
160struct extent_info {
161 rwlock_t ext_lock; /* rwlock for consistency */
162 unsigned int fofs; /* start offset in a file */
163 u32 blk_addr; /* start block address of the extent */
Masanari Iida111d2492013-03-19 08:03:35 +0900164 unsigned int len; /* length of the extent */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900165};
166
167/*
168 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
169 */
170#define FADVISE_COLD_BIT 0x01
Jaegeuk Kim354a3392013-06-14 08:52:35 +0900171#define FADVISE_LOST_PINO_BIT 0x02
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900172
173struct f2fs_inode_info {
174 struct inode vfs_inode; /* serve a vfs inode */
175 unsigned long i_flags; /* keep an inode flags for ioctl */
176 unsigned char i_advise; /* use to give file attribute hints */
177 unsigned int i_current_depth; /* use only in directory structure */
Jaegeuk Kim6666e6a2012-12-10 17:52:48 +0900178 unsigned int i_pino; /* parent inode number */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900179 umode_t i_acl_mode; /* keep file acl mode temporarily */
180
181 /* Use below internally in f2fs*/
182 unsigned long flags; /* use to pass per-file flags */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900183 atomic_t dirty_dents; /* # of dirty dentry pages */
184 f2fs_hash_t chash; /* hash value of given file name */
185 unsigned int clevel; /* maximum level of given file name */
186 nid_t i_xattr_nid; /* node id that contains xattrs */
Jaegeuk Kime518ff82013-08-09 14:46:15 +0900187 unsigned long long xattr_ver; /* cp version of xattr modification */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900188 struct extent_info ext; /* in-memory extent cache entry */
189};
190
191static inline void get_extent_info(struct extent_info *ext,
192 struct f2fs_extent i_ext)
193{
194 write_lock(&ext->ext_lock);
195 ext->fofs = le32_to_cpu(i_ext.fofs);
196 ext->blk_addr = le32_to_cpu(i_ext.blk_addr);
197 ext->len = le32_to_cpu(i_ext.len);
198 write_unlock(&ext->ext_lock);
199}
200
201static inline void set_raw_extent(struct extent_info *ext,
202 struct f2fs_extent *i_ext)
203{
204 read_lock(&ext->ext_lock);
205 i_ext->fofs = cpu_to_le32(ext->fofs);
206 i_ext->blk_addr = cpu_to_le32(ext->blk_addr);
207 i_ext->len = cpu_to_le32(ext->len);
208 read_unlock(&ext->ext_lock);
209}
210
211struct f2fs_nm_info {
212 block_t nat_blkaddr; /* base disk address of NAT */
213 nid_t max_nid; /* maximum possible node ids */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900214 nid_t next_scan_nid; /* the next nid to be scanned */
215
216 /* NAT cache management */
217 struct radix_tree_root nat_root;/* root of the nat entry cache */
218 rwlock_t nat_tree_lock; /* protect nat_tree_lock */
219 unsigned int nat_cnt; /* the # of cached nat entries */
220 struct list_head nat_entries; /* cached nat entry list (clean) */
221 struct list_head dirty_nat_entries; /* cached nat entry list (dirty) */
222
223 /* free node ids management */
224 struct list_head free_nid_list; /* a list for free nids */
225 spinlock_t free_nid_list_lock; /* protect free nid list */
226 unsigned int fcnt; /* the number of free node id */
227 struct mutex build_lock; /* lock for build free nids */
228
229 /* for checkpoint */
230 char *nat_bitmap; /* NAT bitmap pointer */
231 int bitmap_size; /* bitmap size */
232};
233
234/*
235 * this structure is used as one of function parameters.
236 * all the information are dedicated to a given direct node block determined
237 * by the data offset in a file.
238 */
239struct dnode_of_data {
240 struct inode *inode; /* vfs inode pointer */
241 struct page *inode_page; /* its inode page, NULL is possible */
242 struct page *node_page; /* cached direct node page */
243 nid_t nid; /* node id of the direct node block */
244 unsigned int ofs_in_node; /* data offset in the node page */
245 bool inode_page_locked; /* inode page is locked or not */
246 block_t data_blkaddr; /* block address of the node block */
247};
248
249static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
250 struct page *ipage, struct page *npage, nid_t nid)
251{
Jaegeuk Kimd66d1f72013-01-03 08:57:21 +0900252 memset(dn, 0, sizeof(*dn));
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900253 dn->inode = inode;
254 dn->inode_page = ipage;
255 dn->node_page = npage;
256 dn->nid = nid;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900257}
258
259/*
260 * For SIT manager
261 *
262 * By default, there are 6 active log areas across the whole main area.
263 * When considering hot and cold data separation to reduce cleaning overhead,
264 * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
265 * respectively.
266 * In the current design, you should not change the numbers intentionally.
267 * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
268 * logs individually according to the underlying devices. (default: 6)
269 * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
270 * data and 8 for node logs.
271 */
272#define NR_CURSEG_DATA_TYPE (3)
273#define NR_CURSEG_NODE_TYPE (3)
274#define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
275
276enum {
277 CURSEG_HOT_DATA = 0, /* directory entry blocks */
278 CURSEG_WARM_DATA, /* data blocks */
279 CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
280 CURSEG_HOT_NODE, /* direct node blocks of directory files */
281 CURSEG_WARM_NODE, /* direct node blocks of normal files */
282 CURSEG_COLD_NODE, /* indirect node blocks */
283 NO_CHECK_TYPE
284};
285
286struct f2fs_sm_info {
287 struct sit_info *sit_info; /* whole segment information */
288 struct free_segmap_info *free_info; /* free segment information */
289 struct dirty_seglist_info *dirty_info; /* dirty segment information */
290 struct curseg_info *curseg_array; /* active segment information */
291
292 struct list_head wblist_head; /* list of under-writeback pages */
293 spinlock_t wblist_lock; /* lock for checkpoint */
294
295 block_t seg0_blkaddr; /* block address of 0'th segment */
296 block_t main_blkaddr; /* start block address of main area */
297 block_t ssa_blkaddr; /* start block address of SSA area */
298
299 unsigned int segment_count; /* total # of segments */
300 unsigned int main_segments; /* # of segments in main area */
301 unsigned int reserved_segments; /* # of reserved segments */
302 unsigned int ovp_segments; /* # of overprovision segments */
303};
304
305/*
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900306 * For superblock
307 */
308/*
309 * COUNT_TYPE for monitoring
310 *
311 * f2fs monitors the number of several block types such as on-writeback,
312 * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
313 */
314enum count_type {
315 F2FS_WRITEBACK,
316 F2FS_DIRTY_DENTS,
317 F2FS_DIRTY_NODES,
318 F2FS_DIRTY_META,
319 NR_COUNT_TYPE,
320};
321
322/*
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900323 * The below are the page types of bios used in submti_bio().
324 * The available types are:
325 * DATA User data pages. It operates as async mode.
326 * NODE Node pages. It operates as async mode.
327 * META FS metadata pages such as SIT, NAT, CP.
328 * NR_PAGE_TYPE The number of page types.
329 * META_FLUSH Make sure the previous pages are written
330 * with waiting the bio's completion
331 * ... Only can be used with META.
332 */
333enum page_type {
334 DATA,
335 NODE,
336 META,
337 NR_PAGE_TYPE,
338 META_FLUSH,
339};
340
341struct f2fs_sb_info {
342 struct super_block *sb; /* pointer to VFS super block */
Jaegeuk Kim5e176d52013-06-28 12:47:01 +0900343 struct proc_dir_entry *s_proc; /* proc entry */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900344 struct buffer_head *raw_super_buf; /* buffer head of raw sb */
345 struct f2fs_super_block *raw_super; /* raw super block pointer */
346 int s_dirty; /* dirty flag for checkpoint */
347
348 /* for node-related operations */
349 struct f2fs_nm_info *nm_info; /* node manager */
350 struct inode *node_inode; /* cache node blocks */
351
352 /* for segment-related operations */
353 struct f2fs_sm_info *sm_info; /* segment manager */
354 struct bio *bio[NR_PAGE_TYPE]; /* bios to merge */
355 sector_t last_block_in_bio[NR_PAGE_TYPE]; /* last block number */
356 struct rw_semaphore bio_sem; /* IO semaphore */
357
358 /* for checkpoint */
359 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
360 struct inode *meta_inode; /* cache meta blocks */
Jaegeuk Kim39936832012-11-22 16:21:29 +0900361 struct mutex cp_mutex; /* checkpoint procedure lock */
Gu Zhenge4795562013-09-27 18:08:30 +0800362 struct rw_semaphore cp_rwsem; /* blocking FS operations */
363 wait_queue_head_t cp_wait; /* checkpoint wait queue */
Jaegeuk Kim39936832012-11-22 16:21:29 +0900364 struct mutex node_write; /* locking node writes */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900365 struct mutex writepages; /* mutex for writepages() */
366 int por_doing; /* recovery is doing or not */
Jaegeuk Kim55008d82013-04-25 16:05:51 +0900367 int on_build_free_nids; /* build_free_nids is doing */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900368
369 /* for orphan inode management */
370 struct list_head orphan_inode_list; /* orphan inode list */
371 struct mutex orphan_inode_mutex; /* for orphan inode list */
372 unsigned int n_orphans; /* # of orphan inodes */
373
374 /* for directory inode management */
375 struct list_head dir_inode_list; /* dir inode list */
376 spinlock_t dir_inode_lock; /* for dir inode list lock */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900377
378 /* basic file system units */
379 unsigned int log_sectors_per_block; /* log2 sectors per block */
380 unsigned int log_blocksize; /* log2 block size */
381 unsigned int blocksize; /* block size */
382 unsigned int root_ino_num; /* root inode number*/
383 unsigned int node_ino_num; /* node inode number*/
384 unsigned int meta_ino_num; /* meta inode number*/
385 unsigned int log_blocks_per_seg; /* log2 blocks per segment */
386 unsigned int blocks_per_seg; /* blocks per segment */
387 unsigned int segs_per_sec; /* segments per section */
388 unsigned int secs_per_zone; /* sections per zone */
389 unsigned int total_sections; /* total section count */
390 unsigned int total_node_count; /* total node block count */
391 unsigned int total_valid_node_count; /* valid node block count */
392 unsigned int total_valid_inode_count; /* valid inode count */
393 int active_logs; /* # of active logs */
394
395 block_t user_block_count; /* # of user blocks */
396 block_t total_valid_block_count; /* # of valid blocks */
397 block_t alloc_valid_block_count; /* # of allocated blocks */
398 block_t last_valid_block_count; /* for recovery */
399 u32 s_next_generation; /* for NFS support */
400 atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
401
402 struct f2fs_mount_info mount_opt; /* mount options */
403
404 /* for cleaning operations */
405 struct mutex gc_mutex; /* mutex for GC */
406 struct f2fs_gc_kthread *gc_thread; /* GC thread */
Jaegeuk Kim5ec4e492013-03-31 13:26:03 +0900407 unsigned int cur_victim_sec; /* current victim section num */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900408
409 /*
410 * for stat information.
411 * one is for the LFS mode, and the other is for the SSR mode.
412 */
Namjae Jeon35b09d82013-05-23 22:57:53 +0900413#ifdef CONFIG_F2FS_STAT_FS
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900414 struct f2fs_stat_info *stat_info; /* FS status information */
415 unsigned int segment_count[2]; /* # of allocated segments */
416 unsigned int block_count[2]; /* # of allocated blocks */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900417 int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
418 int bg_gc; /* background gc calls */
Namjae Jeon35b09d82013-05-23 22:57:53 +0900419 unsigned int n_dirty_dirs; /* # of dir inodes */
420#endif
421 unsigned int last_victim[2]; /* last victim segment # */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900422 spinlock_t stat_lock; /* lock for stat operations */
Namjae Jeonb59d0ba2013-08-04 23:09:40 +0900423
424 /* For sysfs suppport */
425 struct kobject s_kobj;
426 struct completion s_kobj_unregister;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900427};
428
429/*
430 * Inline functions
431 */
432static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
433{
434 return container_of(inode, struct f2fs_inode_info, vfs_inode);
435}
436
437static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
438{
439 return sb->s_fs_info;
440}
441
442static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
443{
444 return (struct f2fs_super_block *)(sbi->raw_super);
445}
446
447static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
448{
449 return (struct f2fs_checkpoint *)(sbi->ckpt);
450}
451
Gu Zheng45590712013-07-15 17:57:38 +0800452static inline struct f2fs_node *F2FS_NODE(struct page *page)
453{
454 return (struct f2fs_node *)page_address(page);
455}
456
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900457static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
458{
459 return (struct f2fs_nm_info *)(sbi->nm_info);
460}
461
462static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
463{
464 return (struct f2fs_sm_info *)(sbi->sm_info);
465}
466
467static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
468{
469 return (struct sit_info *)(SM_I(sbi)->sit_info);
470}
471
472static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
473{
474 return (struct free_segmap_info *)(SM_I(sbi)->free_info);
475}
476
477static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
478{
479 return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
480}
481
482static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
483{
484 sbi->s_dirty = 1;
485}
486
487static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
488{
489 sbi->s_dirty = 0;
490}
491
Jaegeuk Kimd71b5562013-08-09 15:03:21 +0900492static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
493{
494 return le64_to_cpu(cp->checkpoint_ver);
495}
496
Jaegeuk Kim25ca9232012-11-28 16:12:41 +0900497static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
498{
499 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
500 return ckpt_flags & f;
501}
502
503static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
504{
505 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
506 ckpt_flags |= f;
507 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
508}
509
510static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
511{
512 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
513 ckpt_flags &= (~f);
514 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
515}
516
Gu Zhenge4795562013-09-27 18:08:30 +0800517static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900518{
Gu Zhenge4795562013-09-27 18:08:30 +0800519 /*
520 * If the checkpoint thread is waiting for cp_rwsem, add cuurent task
521 * into wait list to avoid the checkpoint thread starvation
522 */
523 while (!list_empty(&sbi->cp_rwsem.wait_list))
524 wait_event_interruptible(sbi->cp_wait,
525 list_empty(&sbi->cp_rwsem.wait_list));
526 down_read(&sbi->cp_rwsem);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900527}
528
Gu Zhenge4795562013-09-27 18:08:30 +0800529static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900530{
Gu Zhenge4795562013-09-27 18:08:30 +0800531 up_read(&sbi->cp_rwsem);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900532}
533
Gu Zhenge4795562013-09-27 18:08:30 +0800534static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
Jaegeuk Kim39936832012-11-22 16:21:29 +0900535{
Gu Zhenge4795562013-09-27 18:08:30 +0800536 down_write_nest_lock(&sbi->cp_rwsem, &sbi->cp_mutex);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900537}
538
Gu Zhenge4795562013-09-27 18:08:30 +0800539static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
Jaegeuk Kim39936832012-11-22 16:21:29 +0900540{
Gu Zhenge4795562013-09-27 18:08:30 +0800541 up_write(&sbi->cp_rwsem);
542
543 /* wake up all tasks blocked by checkpoint */
544 wake_up_all(&sbi->cp_wait);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900545}
546
547/*
548 * Check whether the given nid is within node id range.
549 */
Namjae Jeon064e0822013-03-17 17:27:20 +0900550static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900551{
Namjae Jeon064e0822013-03-17 17:27:20 +0900552 WARN_ON((nid >= NM_I(sbi)->max_nid));
553 if (nid >= NM_I(sbi)->max_nid)
554 return -EINVAL;
555 return 0;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900556}
557
558#define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
559
560/*
561 * Check whether the inode has blocks or not
562 */
563static inline int F2FS_HAS_BLOCKS(struct inode *inode)
564{
565 if (F2FS_I(inode)->i_xattr_nid)
566 return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1);
567 else
568 return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS);
569}
570
571static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
572 struct inode *inode, blkcnt_t count)
573{
574 block_t valid_block_count;
575
576 spin_lock(&sbi->stat_lock);
577 valid_block_count =
578 sbi->total_valid_block_count + (block_t)count;
579 if (valid_block_count > sbi->user_block_count) {
580 spin_unlock(&sbi->stat_lock);
581 return false;
582 }
583 inode->i_blocks += count;
584 sbi->total_valid_block_count = valid_block_count;
585 sbi->alloc_valid_block_count += (block_t)count;
586 spin_unlock(&sbi->stat_lock);
587 return true;
588}
589
590static inline int dec_valid_block_count(struct f2fs_sb_info *sbi,
591 struct inode *inode,
592 blkcnt_t count)
593{
594 spin_lock(&sbi->stat_lock);
595 BUG_ON(sbi->total_valid_block_count < (block_t) count);
596 BUG_ON(inode->i_blocks < count);
597 inode->i_blocks -= count;
598 sbi->total_valid_block_count -= (block_t)count;
599 spin_unlock(&sbi->stat_lock);
600 return 0;
601}
602
603static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
604{
605 atomic_inc(&sbi->nr_pages[count_type]);
606 F2FS_SET_SB_DIRT(sbi);
607}
608
609static inline void inode_inc_dirty_dents(struct inode *inode)
610{
611 atomic_inc(&F2FS_I(inode)->dirty_dents);
612}
613
614static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
615{
616 atomic_dec(&sbi->nr_pages[count_type]);
617}
618
619static inline void inode_dec_dirty_dents(struct inode *inode)
620{
621 atomic_dec(&F2FS_I(inode)->dirty_dents);
622}
623
624static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
625{
626 return atomic_read(&sbi->nr_pages[count_type]);
627}
628
Namjae Jeon5ac206c2013-02-02 23:52:59 +0900629static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
630{
631 unsigned int pages_per_sec = sbi->segs_per_sec *
632 (1 << sbi->log_blocks_per_seg);
633 return ((get_pages(sbi, block_type) + pages_per_sec - 1)
634 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
635}
636
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900637static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
638{
639 block_t ret;
640 spin_lock(&sbi->stat_lock);
641 ret = sbi->total_valid_block_count;
642 spin_unlock(&sbi->stat_lock);
643 return ret;
644}
645
646static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
647{
648 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
649
650 /* return NAT or SIT bitmap */
651 if (flag == NAT_BITMAP)
652 return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
653 else if (flag == SIT_BITMAP)
654 return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
655
656 return 0;
657}
658
659static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
660{
661 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
Jaegeuk Kim25ca9232012-11-28 16:12:41 +0900662 int offset = (flag == NAT_BITMAP) ?
663 le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900664 return &ckpt->sit_nat_version_bitmap + offset;
665}
666
667static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
668{
669 block_t start_addr;
670 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
Jaegeuk Kimd71b5562013-08-09 15:03:21 +0900671 unsigned long long ckpt_version = cur_cp_version(ckpt);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900672
Jaegeuk Kim25ca9232012-11-28 16:12:41 +0900673 start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900674
675 /*
676 * odd numbered checkpoint should at cp segment 0
677 * and even segent must be at cp segment 1
678 */
679 if (!(ckpt_version & 1))
680 start_addr += sbi->blocks_per_seg;
681
682 return start_addr;
683}
684
685static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
686{
687 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
688}
689
690static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
691 struct inode *inode,
692 unsigned int count)
693{
694 block_t valid_block_count;
695 unsigned int valid_node_count;
696
697 spin_lock(&sbi->stat_lock);
698
699 valid_block_count = sbi->total_valid_block_count + (block_t)count;
700 sbi->alloc_valid_block_count += (block_t)count;
701 valid_node_count = sbi->total_valid_node_count + count;
702
703 if (valid_block_count > sbi->user_block_count) {
704 spin_unlock(&sbi->stat_lock);
705 return false;
706 }
707
708 if (valid_node_count > sbi->total_node_count) {
709 spin_unlock(&sbi->stat_lock);
710 return false;
711 }
712
713 if (inode)
714 inode->i_blocks += count;
715 sbi->total_valid_node_count = valid_node_count;
716 sbi->total_valid_block_count = valid_block_count;
717 spin_unlock(&sbi->stat_lock);
718
719 return true;
720}
721
722static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
723 struct inode *inode,
724 unsigned int count)
725{
726 spin_lock(&sbi->stat_lock);
727
728 BUG_ON(sbi->total_valid_block_count < count);
729 BUG_ON(sbi->total_valid_node_count < count);
730 BUG_ON(inode->i_blocks < count);
731
732 inode->i_blocks -= count;
733 sbi->total_valid_node_count -= count;
734 sbi->total_valid_block_count -= (block_t)count;
735
736 spin_unlock(&sbi->stat_lock);
737}
738
739static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
740{
741 unsigned int ret;
742 spin_lock(&sbi->stat_lock);
743 ret = sbi->total_valid_node_count;
744 spin_unlock(&sbi->stat_lock);
745 return ret;
746}
747
748static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
749{
750 spin_lock(&sbi->stat_lock);
751 BUG_ON(sbi->total_valid_inode_count == sbi->total_node_count);
752 sbi->total_valid_inode_count++;
753 spin_unlock(&sbi->stat_lock);
754}
755
756static inline int dec_valid_inode_count(struct f2fs_sb_info *sbi)
757{
758 spin_lock(&sbi->stat_lock);
759 BUG_ON(!sbi->total_valid_inode_count);
760 sbi->total_valid_inode_count--;
761 spin_unlock(&sbi->stat_lock);
762 return 0;
763}
764
765static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
766{
767 unsigned int ret;
768 spin_lock(&sbi->stat_lock);
769 ret = sbi->total_valid_inode_count;
770 spin_unlock(&sbi->stat_lock);
771 return ret;
772}
773
774static inline void f2fs_put_page(struct page *page, int unlock)
775{
776 if (!page || IS_ERR(page))
777 return;
778
779 if (unlock) {
780 BUG_ON(!PageLocked(page));
781 unlock_page(page);
782 }
783 page_cache_release(page);
784}
785
786static inline void f2fs_put_dnode(struct dnode_of_data *dn)
787{
788 if (dn->node_page)
789 f2fs_put_page(dn->node_page, 1);
790 if (dn->inode_page && dn->node_page != dn->inode_page)
791 f2fs_put_page(dn->inode_page, 0);
792 dn->node_page = NULL;
793 dn->inode_page = NULL;
794}
795
796static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
797 size_t size, void (*ctor)(void *))
798{
799 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor);
800}
801
802#define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
803
804static inline bool IS_INODE(struct page *page)
805{
Gu Zheng45590712013-07-15 17:57:38 +0800806 struct f2fs_node *p = F2FS_NODE(page);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900807 return RAW_IS_INODE(p);
808}
809
810static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
811{
812 return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
813}
814
815static inline block_t datablock_addr(struct page *node_page,
816 unsigned int offset)
817{
818 struct f2fs_node *raw_node;
819 __le32 *addr_array;
Gu Zheng45590712013-07-15 17:57:38 +0800820 raw_node = F2FS_NODE(node_page);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900821 addr_array = blkaddr_in_node(raw_node);
822 return le32_to_cpu(addr_array[offset]);
823}
824
825static inline int f2fs_test_bit(unsigned int nr, char *addr)
826{
827 int mask;
828
829 addr += (nr >> 3);
830 mask = 1 << (7 - (nr & 0x07));
831 return mask & *addr;
832}
833
834static inline int f2fs_set_bit(unsigned int nr, char *addr)
835{
836 int mask;
837 int ret;
838
839 addr += (nr >> 3);
840 mask = 1 << (7 - (nr & 0x07));
841 ret = mask & *addr;
842 *addr |= mask;
843 return ret;
844}
845
846static inline int f2fs_clear_bit(unsigned int nr, char *addr)
847{
848 int mask;
849 int ret;
850
851 addr += (nr >> 3);
852 mask = 1 << (7 - (nr & 0x07));
853 ret = mask & *addr;
854 *addr &= ~mask;
855 return ret;
856}
857
858/* used for f2fs_inode_info->flags */
859enum {
860 FI_NEW_INODE, /* indicate newly allocated inode */
Jaegeuk Kimb3783872013-06-10 09:17:01 +0900861 FI_DIRTY_INODE, /* indicate inode is dirty or not */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900862 FI_INC_LINK, /* need to increment i_nlink */
863 FI_ACL_MODE, /* indicate acl mode */
864 FI_NO_ALLOC, /* should not allocate any blocks */
Jaegeuk Kim699489b2013-06-07 22:08:23 +0900865 FI_UPDATE_DIR, /* should update inode block for consistency */
Jaegeuk Kim74d0b912013-05-15 16:40:02 +0900866 FI_DELAY_IPUT, /* used for the recovery */
Jaegeuk Kim444c5802013-08-08 15:16:22 +0900867 FI_INLINE_XATTR, /* used for inline xattr */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900868};
869
870static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
871{
872 set_bit(flag, &fi->flags);
873}
874
875static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
876{
877 return test_bit(flag, &fi->flags);
878}
879
880static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
881{
882 clear_bit(flag, &fi->flags);
883}
884
885static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
886{
887 fi->i_acl_mode = mode;
888 set_inode_flag(fi, FI_ACL_MODE);
889}
890
891static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag)
892{
893 if (is_inode_flag_set(fi, FI_ACL_MODE)) {
894 clear_inode_flag(fi, FI_ACL_MODE);
895 return 1;
896 }
897 return 0;
898}
899
Jaegeuk Kim444c5802013-08-08 15:16:22 +0900900static inline void get_inline_info(struct f2fs_inode_info *fi,
901 struct f2fs_inode *ri)
902{
903 if (ri->i_inline & F2FS_INLINE_XATTR)
904 set_inode_flag(fi, FI_INLINE_XATTR);
905}
906
907static inline void set_raw_inline(struct f2fs_inode_info *fi,
908 struct f2fs_inode *ri)
909{
910 ri->i_inline = 0;
911
912 if (is_inode_flag_set(fi, FI_INLINE_XATTR))
913 ri->i_inline |= F2FS_INLINE_XATTR;
914}
915
Jaegeuk Kimde936532013-08-12 21:08:03 +0900916static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
917{
918 if (is_inode_flag_set(fi, FI_INLINE_XATTR))
919 return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
920 return DEF_ADDRS_PER_INODE;
921}
922
Jaegeuk Kim65985d92013-08-14 21:57:27 +0900923static inline void *inline_xattr_addr(struct page *page)
924{
925 struct f2fs_inode *ri;
926 ri = (struct f2fs_inode *)page_address(page);
927 return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
928 F2FS_INLINE_XATTR_ADDRS]);
929}
930
931static inline int inline_xattr_size(struct inode *inode)
932{
933 if (is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR))
934 return F2FS_INLINE_XATTR_ADDRS << 2;
935 else
936 return 0;
937}
938
Jaegeuk Kim77888c12013-05-20 20:28:47 +0900939static inline int f2fs_readonly(struct super_block *sb)
940{
941 return sb->s_flags & MS_RDONLY;
942}
943
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900944/*
945 * file.c
946 */
947int f2fs_sync_file(struct file *, loff_t, loff_t, int);
948void truncate_data_blocks(struct dnode_of_data *);
949void f2fs_truncate(struct inode *);
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +0900950int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900951int f2fs_setattr(struct dentry *, struct iattr *);
952int truncate_hole(struct inode *, pgoff_t, pgoff_t);
Jaegeuk Kimb292dcab2013-05-22 08:02:02 +0900953int truncate_data_blocks_range(struct dnode_of_data *, int);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900954long f2fs_ioctl(struct file *, unsigned int, unsigned long);
Namjae Jeone9750822013-02-04 23:41:41 +0900955long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900956
957/*
958 * inode.c
959 */
960void f2fs_set_inode_flags(struct inode *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900961struct inode *f2fs_iget(struct super_block *, unsigned long);
962void update_inode(struct inode *, struct page *);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900963int update_inode_page(struct inode *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900964int f2fs_write_inode(struct inode *, struct writeback_control *);
965void f2fs_evict_inode(struct inode *);
966
967/*
968 * namei.c
969 */
970struct dentry *f2fs_get_parent(struct dentry *child);
971
972/*
973 * dir.c
974 */
975struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
976 struct page **);
977struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
978ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
979void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
980 struct page *, struct inode *);
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900981int update_dent_inode(struct inode *, const struct qstr *);
Al Virob7f7a5e2013-01-25 16:15:43 -0500982int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900983void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
984int f2fs_make_empty(struct inode *, struct inode *);
985bool f2fs_empty_dir(struct inode *);
986
Al Virob7f7a5e2013-01-25 16:15:43 -0500987static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
988{
989 return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
990 inode);
991}
992
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900993/*
994 * super.c
995 */
996int f2fs_sync_fs(struct super_block *, int);
Namjae Jeona07ef782012-12-30 14:52:05 +0900997extern __printf(3, 4)
998void f2fs_msg(struct super_block *, const char *, const char *, ...);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900999
1000/*
1001 * hash.c
1002 */
Leon Romanovsky9836b8b2012-12-27 19:55:46 +02001003f2fs_hash_t f2fs_dentry_hash(const char *, size_t);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001004
1005/*
1006 * node.c
1007 */
1008struct dnode_of_data;
1009struct node_info;
1010
1011int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
1012void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
1013int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
1014int truncate_inode_blocks(struct inode *, pgoff_t);
Jaegeuk Kim4f16fb02013-08-14 20:40:06 +09001015int truncate_xattr_node(struct inode *, struct page *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001016int remove_inode_page(struct inode *);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +09001017struct page *new_inode_page(struct inode *, const struct qstr *);
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +09001018struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001019void ra_node_page(struct f2fs_sb_info *, nid_t);
1020struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
1021struct page *get_node_page_ra(struct page *, int);
1022void sync_inode_page(struct dnode_of_data *);
1023int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
1024bool alloc_nid(struct f2fs_sb_info *, nid_t *);
1025void alloc_nid_done(struct f2fs_sb_info *, nid_t);
1026void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
1027void recover_node_page(struct f2fs_sb_info *, struct page *,
1028 struct f2fs_summary *, struct node_info *, block_t);
1029int recover_inode_page(struct f2fs_sb_info *, struct page *);
1030int restore_node_summary(struct f2fs_sb_info *, unsigned int,
1031 struct f2fs_summary_block *);
1032void flush_nat_entries(struct f2fs_sb_info *);
1033int build_node_manager(struct f2fs_sb_info *);
1034void destroy_node_manager(struct f2fs_sb_info *);
Namjae Jeon6e6093a2013-01-17 00:08:30 +09001035int __init create_node_manager_caches(void);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001036void destroy_node_manager_caches(void);
1037
1038/*
1039 * segment.c
1040 */
1041void f2fs_balance_fs(struct f2fs_sb_info *);
1042void invalidate_blocks(struct f2fs_sb_info *, block_t);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001043void clear_prefree_segments(struct f2fs_sb_info *);
1044int npages_for_summary_flush(struct f2fs_sb_info *);
1045void allocate_new_segments(struct f2fs_sb_info *);
1046struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
Jaegeuk Kim3cd8a232012-12-10 09:26:05 +09001047struct bio *f2fs_bio_alloc(struct block_device *, int);
Jin Xua5694692013-08-05 20:02:04 +08001048void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool);
1049void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool);
Jaegeuk Kim577e3492013-01-24 19:56:11 +09001050void write_meta_page(struct f2fs_sb_info *, struct page *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001051void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int,
1052 block_t, block_t *);
1053void write_data_page(struct inode *, struct page *, struct dnode_of_data*,
1054 block_t, block_t *);
1055void rewrite_data_page(struct f2fs_sb_info *, struct page *, block_t);
1056void recover_data_page(struct f2fs_sb_info *, struct page *,
1057 struct f2fs_summary *, block_t, block_t);
1058void rewrite_node_page(struct f2fs_sb_info *, struct page *,
1059 struct f2fs_summary *, block_t, block_t);
1060void write_data_summaries(struct f2fs_sb_info *, block_t);
1061void write_node_summaries(struct f2fs_sb_info *, block_t);
1062int lookup_journal_in_cursum(struct f2fs_summary_block *,
1063 int, unsigned int, int);
1064void flush_sit_entries(struct f2fs_sb_info *);
1065int build_segment_manager(struct f2fs_sb_info *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001066void destroy_segment_manager(struct f2fs_sb_info *);
1067
1068/*
1069 * checkpoint.c
1070 */
1071struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
1072struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
1073long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +09001074int acquire_orphan_inode(struct f2fs_sb_info *);
1075void release_orphan_inode(struct f2fs_sb_info *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001076void add_orphan_inode(struct f2fs_sb_info *, nid_t);
1077void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
1078int recover_orphan_inodes(struct f2fs_sb_info *);
1079int get_valid_checkpoint(struct f2fs_sb_info *);
1080void set_dirty_dir_page(struct inode *, struct page *);
Jaegeuk Kim5deb8262013-06-05 17:42:45 +09001081void add_dirty_dir_inode(struct inode *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001082void remove_dirty_dir_inode(struct inode *);
Jaegeuk Kim74d0b912013-05-15 16:40:02 +09001083struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001084void sync_dirty_dir_inodes(struct f2fs_sb_info *);
Jaegeuk Kim43727522013-02-04 15:11:17 +09001085void write_checkpoint(struct f2fs_sb_info *, bool);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001086void init_orphan_info(struct f2fs_sb_info *);
Namjae Jeon6e6093a2013-01-17 00:08:30 +09001087int __init create_checkpoint_caches(void);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001088void destroy_checkpoint_caches(void);
1089
1090/*
1091 * data.c
1092 */
1093int reserve_new_block(struct dnode_of_data *);
1094void update_extent_cache(block_t, struct dnode_of_data *);
Jaegeuk Kimc718379b2013-04-24 13:19:56 +09001095struct page *find_data_page(struct inode *, pgoff_t, bool);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001096struct page *get_lock_data_page(struct inode *, pgoff_t);
Jaegeuk Kim64aa7ed2013-05-20 09:55:50 +09001097struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001098int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
1099int do_write_data_page(struct page *);
1100
1101/*
1102 * gc.c
1103 */
1104int start_gc_thread(struct f2fs_sb_info *);
1105void stop_gc_thread(struct f2fs_sb_info *);
Jaegeuk Kimde936532013-08-12 21:08:03 +09001106block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
Jaegeuk Kim408e9372013-01-03 17:55:52 +09001107int f2fs_gc(struct f2fs_sb_info *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001108void build_gc_manager(struct f2fs_sb_info *);
Namjae Jeon6e6093a2013-01-17 00:08:30 +09001109int __init create_gc_caches(void);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001110void destroy_gc_caches(void);
1111
1112/*
1113 * recovery.c
1114 */
Jaegeuk Kim6ead1142013-03-20 19:01:06 +09001115int recover_fsync_data(struct f2fs_sb_info *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001116bool space_for_roll_forward(struct f2fs_sb_info *);
1117
1118/*
1119 * debug.c
1120 */
1121#ifdef CONFIG_F2FS_STAT_FS
1122struct f2fs_stat_info {
1123 struct list_head stat_list;
1124 struct f2fs_sb_info *sbi;
1125 struct mutex stat_lock;
1126 int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
1127 int main_area_segs, main_area_sections, main_area_zones;
1128 int hit_ext, total_ext;
1129 int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
1130 int nats, sits, fnids;
1131 int total_count, utilization;
1132 int bg_gc;
1133 unsigned int valid_count, valid_node_count, valid_inode_count;
1134 unsigned int bimodal, avg_vblocks;
1135 int util_free, util_valid, util_invalid;
1136 int rsvd_segs, overp_segs;
1137 int dirty_count, node_pages, meta_pages;
1138 int prefree_count, call_count;
1139 int tot_segs, node_segs, data_segs, free_segs, free_secs;
1140 int tot_blks, data_blks, node_blks;
1141 int curseg[NR_CURSEG_TYPE];
1142 int cursec[NR_CURSEG_TYPE];
1143 int curzone[NR_CURSEG_TYPE];
1144
1145 unsigned int segment_count[2];
1146 unsigned int block_count[2];
1147 unsigned base_mem, cache_mem;
1148};
1149
Gu Zheng963d4f72013-07-12 14:47:11 +08001150static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
1151{
1152 return (struct f2fs_stat_info*)sbi->stat_info;
1153}
1154
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001155#define stat_inc_call_count(si) ((si)->call_count++)
1156
1157#define stat_inc_seg_count(sbi, type) \
1158 do { \
Gu Zheng963d4f72013-07-12 14:47:11 +08001159 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001160 (si)->tot_segs++; \
1161 if (type == SUM_TYPE_DATA) \
1162 si->data_segs++; \
1163 else \
1164 si->node_segs++; \
1165 } while (0)
1166
1167#define stat_inc_tot_blk_count(si, blks) \
1168 (si->tot_blks += (blks))
1169
1170#define stat_inc_data_blk_count(sbi, blks) \
1171 do { \
Gu Zheng963d4f72013-07-12 14:47:11 +08001172 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001173 stat_inc_tot_blk_count(si, blks); \
1174 si->data_blks += (blks); \
1175 } while (0)
1176
1177#define stat_inc_node_blk_count(sbi, blks) \
1178 do { \
Gu Zheng963d4f72013-07-12 14:47:11 +08001179 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001180 stat_inc_tot_blk_count(si, blks); \
1181 si->node_blks += (blks); \
1182 } while (0)
1183
1184int f2fs_build_stats(struct f2fs_sb_info *);
1185void f2fs_destroy_stats(struct f2fs_sb_info *);
Namjae Jeon6e6093a2013-01-17 00:08:30 +09001186void __init f2fs_create_root_stats(void);
Namjae Jeon4589d252013-01-15 19:58:47 +09001187void f2fs_destroy_root_stats(void);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001188#else
1189#define stat_inc_call_count(si)
1190#define stat_inc_seg_count(si, type)
1191#define stat_inc_tot_blk_count(si, blks)
1192#define stat_inc_data_blk_count(si, blks)
1193#define stat_inc_node_blk_count(sbi, blks)
1194
1195static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
1196static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
Namjae Jeon6e6093a2013-01-17 00:08:30 +09001197static inline void __init f2fs_create_root_stats(void) { }
Namjae Jeon4589d252013-01-15 19:58:47 +09001198static inline void f2fs_destroy_root_stats(void) { }
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001199#endif
1200
1201extern const struct file_operations f2fs_dir_operations;
1202extern const struct file_operations f2fs_file_operations;
1203extern const struct inode_operations f2fs_file_inode_operations;
1204extern const struct address_space_operations f2fs_dblock_aops;
1205extern const struct address_space_operations f2fs_node_aops;
1206extern const struct address_space_operations f2fs_meta_aops;
1207extern const struct inode_operations f2fs_dir_inode_operations;
1208extern const struct inode_operations f2fs_symlink_inode_operations;
1209extern const struct inode_operations f2fs_special_inode_operations;
1210#endif