blob: d8e386ceb0cdeade11c5c08fcb95fd5379baa47d [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>
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090021
22/*
23 * For mount options
24 */
25#define F2FS_MOUNT_BG_GC 0x00000001
26#define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
27#define F2FS_MOUNT_DISCARD 0x00000004
28#define F2FS_MOUNT_NOHEAP 0x00000008
29#define F2FS_MOUNT_XATTR_USER 0x00000010
30#define F2FS_MOUNT_POSIX_ACL 0x00000020
31#define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
32
33#define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
34#define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
35#define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
36
37#define ver_after(a, b) (typecheck(unsigned long long, a) && \
38 typecheck(unsigned long long, b) && \
39 ((long long)((a) - (b)) > 0))
40
Jaegeuk Kima9841c42013-05-24 12:41:04 +090041typedef u32 block_t; /*
42 * should not change u32, since it is the on-disk block
43 * address format, __le32.
44 */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090045typedef u32 nid_t;
46
47struct f2fs_mount_info {
48 unsigned int opt;
49};
50
Jaegeuk Kim7e586fa2013-06-19 20:47:19 +090051#define CRCPOLY_LE 0xedb88320
52
53static inline __u32 f2fs_crc32(void *buf, size_t len)
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090054{
Jaegeuk Kim7e586fa2013-06-19 20:47:19 +090055 unsigned char *p = (unsigned char *)buf;
56 __u32 crc = F2FS_SUPER_MAGIC;
57 int i;
58
59 while (len--) {
60 crc ^= *p++;
61 for (i = 0; i < 8; i++)
62 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
63 }
64 return crc;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090065}
66
Jaegeuk Kim7e586fa2013-06-19 20:47:19 +090067static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090068{
Jaegeuk Kim7e586fa2013-06-19 20:47:19 +090069 return f2fs_crc32(buf, buf_size) == blk_crc;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +090070}
71
72/*
73 * For checkpoint manager
74 */
75enum {
76 NAT_BITMAP,
77 SIT_BITMAP
78};
79
80/* for the list of orphan inodes */
81struct orphan_inode_entry {
82 struct list_head list; /* list head */
83 nid_t ino; /* inode number */
84};
85
86/* for the list of directory inodes */
87struct dir_inode_entry {
88 struct list_head list; /* list head */
89 struct inode *inode; /* vfs inode pointer */
90};
91
92/* for the list of fsync inodes, used only during recovery */
93struct fsync_inode_entry {
94 struct list_head list; /* list head */
95 struct inode *inode; /* vfs inode pointer */
96 block_t blkaddr; /* block address locating the last inode */
97};
98
99#define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats))
100#define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits))
101
102#define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne)
103#define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid)
104#define sit_in_journal(sum, i) (sum->sit_j.entries[i].se)
105#define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno)
106
107static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
108{
109 int before = nats_in_cursum(rs);
110 rs->n_nats = cpu_to_le16(before + i);
111 return before;
112}
113
114static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
115{
116 int before = sits_in_cursum(rs);
117 rs->n_sits = cpu_to_le16(before + i);
118 return before;
119}
120
121/*
Namjae Jeone9750822013-02-04 23:41:41 +0900122 * ioctl commands
123 */
124#define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
125#define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
126
127#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
128/*
129 * ioctl commands in 32 bit emulation
130 */
131#define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
132#define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
133#endif
134
135/*
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900136 * For INODE and NODE manager
137 */
138#define XATTR_NODE_OFFSET (-1) /*
139 * store xattrs to one node block per
140 * file keeping -1 as its node offset to
141 * distinguish from index node blocks.
142 */
Jaegeuk Kim266e97a2013-02-26 13:10:46 +0900143enum {
144 ALLOC_NODE, /* allocate a new node page if needed */
145 LOOKUP_NODE, /* look up a node without readahead */
146 LOOKUP_NODE_RA, /*
147 * look up a node with readahead called
148 * by get_datablock_ro.
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900149 */
Jaegeuk Kim266e97a2013-02-26 13:10:46 +0900150};
151
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900152#define F2FS_LINK_MAX 32000 /* maximum link count per file */
153
154/* for in-memory extent cache entry */
155struct extent_info {
156 rwlock_t ext_lock; /* rwlock for consistency */
157 unsigned int fofs; /* start offset in a file */
158 u32 blk_addr; /* start block address of the extent */
Masanari Iida111d2492013-03-19 08:03:35 +0900159 unsigned int len; /* length of the extent */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900160};
161
162/*
163 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
164 */
165#define FADVISE_COLD_BIT 0x01
Jaegeuk Kim354a3392013-06-14 08:52:35 +0900166#define FADVISE_LOST_PINO_BIT 0x02
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900167
168struct f2fs_inode_info {
169 struct inode vfs_inode; /* serve a vfs inode */
170 unsigned long i_flags; /* keep an inode flags for ioctl */
171 unsigned char i_advise; /* use to give file attribute hints */
172 unsigned int i_current_depth; /* use only in directory structure */
Jaegeuk Kim6666e6a2012-12-10 17:52:48 +0900173 unsigned int i_pino; /* parent inode number */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900174 umode_t i_acl_mode; /* keep file acl mode temporarily */
175
176 /* Use below internally in f2fs*/
177 unsigned long flags; /* use to pass per-file flags */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900178 atomic_t dirty_dents; /* # of dirty dentry pages */
179 f2fs_hash_t chash; /* hash value of given file name */
180 unsigned int clevel; /* maximum level of given file name */
181 nid_t i_xattr_nid; /* node id that contains xattrs */
182 struct extent_info ext; /* in-memory extent cache entry */
183};
184
185static inline void get_extent_info(struct extent_info *ext,
186 struct f2fs_extent i_ext)
187{
188 write_lock(&ext->ext_lock);
189 ext->fofs = le32_to_cpu(i_ext.fofs);
190 ext->blk_addr = le32_to_cpu(i_ext.blk_addr);
191 ext->len = le32_to_cpu(i_ext.len);
192 write_unlock(&ext->ext_lock);
193}
194
195static inline void set_raw_extent(struct extent_info *ext,
196 struct f2fs_extent *i_ext)
197{
198 read_lock(&ext->ext_lock);
199 i_ext->fofs = cpu_to_le32(ext->fofs);
200 i_ext->blk_addr = cpu_to_le32(ext->blk_addr);
201 i_ext->len = cpu_to_le32(ext->len);
202 read_unlock(&ext->ext_lock);
203}
204
205struct f2fs_nm_info {
206 block_t nat_blkaddr; /* base disk address of NAT */
207 nid_t max_nid; /* maximum possible node ids */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900208 nid_t next_scan_nid; /* the next nid to be scanned */
209
210 /* NAT cache management */
211 struct radix_tree_root nat_root;/* root of the nat entry cache */
212 rwlock_t nat_tree_lock; /* protect nat_tree_lock */
213 unsigned int nat_cnt; /* the # of cached nat entries */
214 struct list_head nat_entries; /* cached nat entry list (clean) */
215 struct list_head dirty_nat_entries; /* cached nat entry list (dirty) */
216
217 /* free node ids management */
218 struct list_head free_nid_list; /* a list for free nids */
219 spinlock_t free_nid_list_lock; /* protect free nid list */
220 unsigned int fcnt; /* the number of free node id */
221 struct mutex build_lock; /* lock for build free nids */
222
223 /* for checkpoint */
224 char *nat_bitmap; /* NAT bitmap pointer */
225 int bitmap_size; /* bitmap size */
226};
227
228/*
229 * this structure is used as one of function parameters.
230 * all the information are dedicated to a given direct node block determined
231 * by the data offset in a file.
232 */
233struct dnode_of_data {
234 struct inode *inode; /* vfs inode pointer */
235 struct page *inode_page; /* its inode page, NULL is possible */
236 struct page *node_page; /* cached direct node page */
237 nid_t nid; /* node id of the direct node block */
238 unsigned int ofs_in_node; /* data offset in the node page */
239 bool inode_page_locked; /* inode page is locked or not */
240 block_t data_blkaddr; /* block address of the node block */
241};
242
243static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
244 struct page *ipage, struct page *npage, nid_t nid)
245{
Jaegeuk Kimd66d1f72013-01-03 08:57:21 +0900246 memset(dn, 0, sizeof(*dn));
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900247 dn->inode = inode;
248 dn->inode_page = ipage;
249 dn->node_page = npage;
250 dn->nid = nid;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900251}
252
253/*
254 * For SIT manager
255 *
256 * By default, there are 6 active log areas across the whole main area.
257 * When considering hot and cold data separation to reduce cleaning overhead,
258 * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
259 * respectively.
260 * In the current design, you should not change the numbers intentionally.
261 * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
262 * logs individually according to the underlying devices. (default: 6)
263 * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
264 * data and 8 for node logs.
265 */
266#define NR_CURSEG_DATA_TYPE (3)
267#define NR_CURSEG_NODE_TYPE (3)
268#define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
269
270enum {
271 CURSEG_HOT_DATA = 0, /* directory entry blocks */
272 CURSEG_WARM_DATA, /* data blocks */
273 CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
274 CURSEG_HOT_NODE, /* direct node blocks of directory files */
275 CURSEG_WARM_NODE, /* direct node blocks of normal files */
276 CURSEG_COLD_NODE, /* indirect node blocks */
277 NO_CHECK_TYPE
278};
279
280struct f2fs_sm_info {
281 struct sit_info *sit_info; /* whole segment information */
282 struct free_segmap_info *free_info; /* free segment information */
283 struct dirty_seglist_info *dirty_info; /* dirty segment information */
284 struct curseg_info *curseg_array; /* active segment information */
285
286 struct list_head wblist_head; /* list of under-writeback pages */
287 spinlock_t wblist_lock; /* lock for checkpoint */
288
289 block_t seg0_blkaddr; /* block address of 0'th segment */
290 block_t main_blkaddr; /* start block address of main area */
291 block_t ssa_blkaddr; /* start block address of SSA area */
292
293 unsigned int segment_count; /* total # of segments */
294 unsigned int main_segments; /* # of segments in main area */
295 unsigned int reserved_segments; /* # of reserved segments */
296 unsigned int ovp_segments; /* # of overprovision segments */
297};
298
299/*
300 * For directory operation
301 */
302#define NODE_DIR1_BLOCK (ADDRS_PER_INODE + 1)
303#define NODE_DIR2_BLOCK (ADDRS_PER_INODE + 2)
304#define NODE_IND1_BLOCK (ADDRS_PER_INODE + 3)
305#define NODE_IND2_BLOCK (ADDRS_PER_INODE + 4)
306#define NODE_DIND_BLOCK (ADDRS_PER_INODE + 5)
307
308/*
309 * For superblock
310 */
311/*
312 * COUNT_TYPE for monitoring
313 *
314 * f2fs monitors the number of several block types such as on-writeback,
315 * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
316 */
317enum count_type {
318 F2FS_WRITEBACK,
319 F2FS_DIRTY_DENTS,
320 F2FS_DIRTY_NODES,
321 F2FS_DIRTY_META,
322 NR_COUNT_TYPE,
323};
324
325/*
Jaegeuk Kim39936832012-11-22 16:21:29 +0900326 * Uses as sbi->fs_lock[NR_GLOBAL_LOCKS].
327 * The checkpoint procedure blocks all the locks in this fs_lock array.
328 * Some FS operations grab free locks, and if there is no free lock,
329 * then wait to grab a lock in a round-robin manner.
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900330 */
Jaegeuk Kim39936832012-11-22 16:21:29 +0900331#define NR_GLOBAL_LOCKS 8
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900332
333/*
334 * The below are the page types of bios used in submti_bio().
335 * The available types are:
336 * DATA User data pages. It operates as async mode.
337 * NODE Node pages. It operates as async mode.
338 * META FS metadata pages such as SIT, NAT, CP.
339 * NR_PAGE_TYPE The number of page types.
340 * META_FLUSH Make sure the previous pages are written
341 * with waiting the bio's completion
342 * ... Only can be used with META.
343 */
344enum page_type {
345 DATA,
346 NODE,
347 META,
348 NR_PAGE_TYPE,
349 META_FLUSH,
350};
351
352struct f2fs_sb_info {
353 struct super_block *sb; /* pointer to VFS super block */
Jaegeuk Kim5e176d52013-06-28 12:47:01 +0900354 struct proc_dir_entry *s_proc; /* proc entry */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900355 struct buffer_head *raw_super_buf; /* buffer head of raw sb */
356 struct f2fs_super_block *raw_super; /* raw super block pointer */
357 int s_dirty; /* dirty flag for checkpoint */
358
359 /* for node-related operations */
360 struct f2fs_nm_info *nm_info; /* node manager */
361 struct inode *node_inode; /* cache node blocks */
362
363 /* for segment-related operations */
364 struct f2fs_sm_info *sm_info; /* segment manager */
365 struct bio *bio[NR_PAGE_TYPE]; /* bios to merge */
366 sector_t last_block_in_bio[NR_PAGE_TYPE]; /* last block number */
367 struct rw_semaphore bio_sem; /* IO semaphore */
368
369 /* for checkpoint */
370 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
371 struct inode *meta_inode; /* cache meta blocks */
Jaegeuk Kim39936832012-11-22 16:21:29 +0900372 struct mutex cp_mutex; /* checkpoint procedure lock */
373 struct mutex fs_lock[NR_GLOBAL_LOCKS]; /* blocking FS operations */
374 struct mutex node_write; /* locking node writes */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900375 struct mutex writepages; /* mutex for writepages() */
Jaegeuk Kim39936832012-11-22 16:21:29 +0900376 unsigned char next_lock_num; /* round-robin global locks */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900377 int por_doing; /* recovery is doing or not */
Jaegeuk Kim55008d82013-04-25 16:05:51 +0900378 int on_build_free_nids; /* build_free_nids is doing */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900379
380 /* for orphan inode management */
381 struct list_head orphan_inode_list; /* orphan inode list */
382 struct mutex orphan_inode_mutex; /* for orphan inode list */
383 unsigned int n_orphans; /* # of orphan inodes */
384
385 /* for directory inode management */
386 struct list_head dir_inode_list; /* dir inode list */
387 spinlock_t dir_inode_lock; /* for dir inode list lock */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900388
389 /* basic file system units */
390 unsigned int log_sectors_per_block; /* log2 sectors per block */
391 unsigned int log_blocksize; /* log2 block size */
392 unsigned int blocksize; /* block size */
393 unsigned int root_ino_num; /* root inode number*/
394 unsigned int node_ino_num; /* node inode number*/
395 unsigned int meta_ino_num; /* meta inode number*/
396 unsigned int log_blocks_per_seg; /* log2 blocks per segment */
397 unsigned int blocks_per_seg; /* blocks per segment */
398 unsigned int segs_per_sec; /* segments per section */
399 unsigned int secs_per_zone; /* sections per zone */
400 unsigned int total_sections; /* total section count */
401 unsigned int total_node_count; /* total node block count */
402 unsigned int total_valid_node_count; /* valid node block count */
403 unsigned int total_valid_inode_count; /* valid inode count */
404 int active_logs; /* # of active logs */
405
406 block_t user_block_count; /* # of user blocks */
407 block_t total_valid_block_count; /* # of valid blocks */
408 block_t alloc_valid_block_count; /* # of allocated blocks */
409 block_t last_valid_block_count; /* for recovery */
410 u32 s_next_generation; /* for NFS support */
411 atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
412
413 struct f2fs_mount_info mount_opt; /* mount options */
414
415 /* for cleaning operations */
416 struct mutex gc_mutex; /* mutex for GC */
417 struct f2fs_gc_kthread *gc_thread; /* GC thread */
Jaegeuk Kim5ec4e492013-03-31 13:26:03 +0900418 unsigned int cur_victim_sec; /* current victim section num */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900419
420 /*
421 * for stat information.
422 * one is for the LFS mode, and the other is for the SSR mode.
423 */
Namjae Jeon35b09d82013-05-23 22:57:53 +0900424#ifdef CONFIG_F2FS_STAT_FS
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900425 struct f2fs_stat_info *stat_info; /* FS status information */
426 unsigned int segment_count[2]; /* # of allocated segments */
427 unsigned int block_count[2]; /* # of allocated blocks */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900428 int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
429 int bg_gc; /* background gc calls */
Namjae Jeon35b09d82013-05-23 22:57:53 +0900430 unsigned int n_dirty_dirs; /* # of dir inodes */
431#endif
432 unsigned int last_victim[2]; /* last victim segment # */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900433 spinlock_t stat_lock; /* lock for stat operations */
Namjae Jeonb59d0ba2013-08-04 23:09:40 +0900434
435 /* For sysfs suppport */
436 struct kobject s_kobj;
437 struct completion s_kobj_unregister;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900438};
439
440/*
441 * Inline functions
442 */
443static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
444{
445 return container_of(inode, struct f2fs_inode_info, vfs_inode);
446}
447
448static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
449{
450 return sb->s_fs_info;
451}
452
453static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
454{
455 return (struct f2fs_super_block *)(sbi->raw_super);
456}
457
458static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
459{
460 return (struct f2fs_checkpoint *)(sbi->ckpt);
461}
462
Gu Zheng45590712013-07-15 17:57:38 +0800463static inline struct f2fs_node *F2FS_NODE(struct page *page)
464{
465 return (struct f2fs_node *)page_address(page);
466}
467
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900468static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
469{
470 return (struct f2fs_nm_info *)(sbi->nm_info);
471}
472
473static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
474{
475 return (struct f2fs_sm_info *)(sbi->sm_info);
476}
477
478static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
479{
480 return (struct sit_info *)(SM_I(sbi)->sit_info);
481}
482
483static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
484{
485 return (struct free_segmap_info *)(SM_I(sbi)->free_info);
486}
487
488static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
489{
490 return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
491}
492
493static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
494{
495 sbi->s_dirty = 1;
496}
497
498static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
499{
500 sbi->s_dirty = 0;
501}
502
Jaegeuk Kim25ca9232012-11-28 16:12:41 +0900503static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
504{
505 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
506 return ckpt_flags & f;
507}
508
509static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
510{
511 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
512 ckpt_flags |= f;
513 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
514}
515
516static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
517{
518 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
519 ckpt_flags &= (~f);
520 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
521}
522
Jaegeuk Kim39936832012-11-22 16:21:29 +0900523static inline void mutex_lock_all(struct f2fs_sb_info *sbi)
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900524{
Peter Zijlstrabfe35962013-05-16 20:03:12 +0200525 int i;
526
527 for (i = 0; i < NR_GLOBAL_LOCKS; i++) {
528 /*
529 * This is the only time we take multiple fs_lock[]
530 * instances; the order is immaterial since we
531 * always hold cp_mutex, which serializes multiple
532 * such operations.
533 */
534 mutex_lock_nest_lock(&sbi->fs_lock[i], &sbi->cp_mutex);
535 }
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900536}
537
Jaegeuk Kim39936832012-11-22 16:21:29 +0900538static inline void mutex_unlock_all(struct f2fs_sb_info *sbi)
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900539{
Jaegeuk Kim39936832012-11-22 16:21:29 +0900540 int i = 0;
541 for (; i < NR_GLOBAL_LOCKS; i++)
542 mutex_unlock(&sbi->fs_lock[i]);
543}
544
545static inline int mutex_lock_op(struct f2fs_sb_info *sbi)
546{
547 unsigned char next_lock = sbi->next_lock_num % NR_GLOBAL_LOCKS;
548 int i = 0;
549
550 for (; i < NR_GLOBAL_LOCKS; i++)
551 if (mutex_trylock(&sbi->fs_lock[i]))
552 return i;
553
554 mutex_lock(&sbi->fs_lock[next_lock]);
555 sbi->next_lock_num++;
556 return next_lock;
557}
558
559static inline void mutex_unlock_op(struct f2fs_sb_info *sbi, int ilock)
560{
561 if (ilock < 0)
562 return;
563 BUG_ON(ilock >= NR_GLOBAL_LOCKS);
564 mutex_unlock(&sbi->fs_lock[ilock]);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900565}
566
567/*
568 * Check whether the given nid is within node id range.
569 */
Namjae Jeon064e0822013-03-17 17:27:20 +0900570static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900571{
Namjae Jeon064e0822013-03-17 17:27:20 +0900572 WARN_ON((nid >= NM_I(sbi)->max_nid));
573 if (nid >= NM_I(sbi)->max_nid)
574 return -EINVAL;
575 return 0;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900576}
577
578#define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
579
580/*
581 * Check whether the inode has blocks or not
582 */
583static inline int F2FS_HAS_BLOCKS(struct inode *inode)
584{
585 if (F2FS_I(inode)->i_xattr_nid)
586 return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1);
587 else
588 return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS);
589}
590
591static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
592 struct inode *inode, blkcnt_t count)
593{
594 block_t valid_block_count;
595
596 spin_lock(&sbi->stat_lock);
597 valid_block_count =
598 sbi->total_valid_block_count + (block_t)count;
599 if (valid_block_count > sbi->user_block_count) {
600 spin_unlock(&sbi->stat_lock);
601 return false;
602 }
603 inode->i_blocks += count;
604 sbi->total_valid_block_count = valid_block_count;
605 sbi->alloc_valid_block_count += (block_t)count;
606 spin_unlock(&sbi->stat_lock);
607 return true;
608}
609
610static inline int dec_valid_block_count(struct f2fs_sb_info *sbi,
611 struct inode *inode,
612 blkcnt_t count)
613{
614 spin_lock(&sbi->stat_lock);
615 BUG_ON(sbi->total_valid_block_count < (block_t) count);
616 BUG_ON(inode->i_blocks < count);
617 inode->i_blocks -= count;
618 sbi->total_valid_block_count -= (block_t)count;
619 spin_unlock(&sbi->stat_lock);
620 return 0;
621}
622
623static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
624{
625 atomic_inc(&sbi->nr_pages[count_type]);
626 F2FS_SET_SB_DIRT(sbi);
627}
628
629static inline void inode_inc_dirty_dents(struct inode *inode)
630{
631 atomic_inc(&F2FS_I(inode)->dirty_dents);
632}
633
634static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
635{
636 atomic_dec(&sbi->nr_pages[count_type]);
637}
638
639static inline void inode_dec_dirty_dents(struct inode *inode)
640{
641 atomic_dec(&F2FS_I(inode)->dirty_dents);
642}
643
644static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
645{
646 return atomic_read(&sbi->nr_pages[count_type]);
647}
648
Namjae Jeon5ac206c2013-02-02 23:52:59 +0900649static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
650{
651 unsigned int pages_per_sec = sbi->segs_per_sec *
652 (1 << sbi->log_blocks_per_seg);
653 return ((get_pages(sbi, block_type) + pages_per_sec - 1)
654 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
655}
656
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900657static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
658{
659 block_t ret;
660 spin_lock(&sbi->stat_lock);
661 ret = sbi->total_valid_block_count;
662 spin_unlock(&sbi->stat_lock);
663 return ret;
664}
665
666static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
667{
668 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
669
670 /* return NAT or SIT bitmap */
671 if (flag == NAT_BITMAP)
672 return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
673 else if (flag == SIT_BITMAP)
674 return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
675
676 return 0;
677}
678
679static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
680{
681 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
Jaegeuk Kim25ca9232012-11-28 16:12:41 +0900682 int offset = (flag == NAT_BITMAP) ?
683 le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900684 return &ckpt->sit_nat_version_bitmap + offset;
685}
686
687static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
688{
689 block_t start_addr;
690 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
691 unsigned long long ckpt_version = le64_to_cpu(ckpt->checkpoint_ver);
692
Jaegeuk Kim25ca9232012-11-28 16:12:41 +0900693 start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900694
695 /*
696 * odd numbered checkpoint should at cp segment 0
697 * and even segent must be at cp segment 1
698 */
699 if (!(ckpt_version & 1))
700 start_addr += sbi->blocks_per_seg;
701
702 return start_addr;
703}
704
705static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
706{
707 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
708}
709
710static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
711 struct inode *inode,
712 unsigned int count)
713{
714 block_t valid_block_count;
715 unsigned int valid_node_count;
716
717 spin_lock(&sbi->stat_lock);
718
719 valid_block_count = sbi->total_valid_block_count + (block_t)count;
720 sbi->alloc_valid_block_count += (block_t)count;
721 valid_node_count = sbi->total_valid_node_count + count;
722
723 if (valid_block_count > sbi->user_block_count) {
724 spin_unlock(&sbi->stat_lock);
725 return false;
726 }
727
728 if (valid_node_count > sbi->total_node_count) {
729 spin_unlock(&sbi->stat_lock);
730 return false;
731 }
732
733 if (inode)
734 inode->i_blocks += count;
735 sbi->total_valid_node_count = valid_node_count;
736 sbi->total_valid_block_count = valid_block_count;
737 spin_unlock(&sbi->stat_lock);
738
739 return true;
740}
741
742static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
743 struct inode *inode,
744 unsigned int count)
745{
746 spin_lock(&sbi->stat_lock);
747
748 BUG_ON(sbi->total_valid_block_count < count);
749 BUG_ON(sbi->total_valid_node_count < count);
750 BUG_ON(inode->i_blocks < count);
751
752 inode->i_blocks -= count;
753 sbi->total_valid_node_count -= count;
754 sbi->total_valid_block_count -= (block_t)count;
755
756 spin_unlock(&sbi->stat_lock);
757}
758
759static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
760{
761 unsigned int ret;
762 spin_lock(&sbi->stat_lock);
763 ret = sbi->total_valid_node_count;
764 spin_unlock(&sbi->stat_lock);
765 return ret;
766}
767
768static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
769{
770 spin_lock(&sbi->stat_lock);
771 BUG_ON(sbi->total_valid_inode_count == sbi->total_node_count);
772 sbi->total_valid_inode_count++;
773 spin_unlock(&sbi->stat_lock);
774}
775
776static inline int dec_valid_inode_count(struct f2fs_sb_info *sbi)
777{
778 spin_lock(&sbi->stat_lock);
779 BUG_ON(!sbi->total_valid_inode_count);
780 sbi->total_valid_inode_count--;
781 spin_unlock(&sbi->stat_lock);
782 return 0;
783}
784
785static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
786{
787 unsigned int ret;
788 spin_lock(&sbi->stat_lock);
789 ret = sbi->total_valid_inode_count;
790 spin_unlock(&sbi->stat_lock);
791 return ret;
792}
793
794static inline void f2fs_put_page(struct page *page, int unlock)
795{
796 if (!page || IS_ERR(page))
797 return;
798
799 if (unlock) {
800 BUG_ON(!PageLocked(page));
801 unlock_page(page);
802 }
803 page_cache_release(page);
804}
805
806static inline void f2fs_put_dnode(struct dnode_of_data *dn)
807{
808 if (dn->node_page)
809 f2fs_put_page(dn->node_page, 1);
810 if (dn->inode_page && dn->node_page != dn->inode_page)
811 f2fs_put_page(dn->inode_page, 0);
812 dn->node_page = NULL;
813 dn->inode_page = NULL;
814}
815
816static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
817 size_t size, void (*ctor)(void *))
818{
819 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor);
820}
821
822#define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
823
824static inline bool IS_INODE(struct page *page)
825{
Gu Zheng45590712013-07-15 17:57:38 +0800826 struct f2fs_node *p = F2FS_NODE(page);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900827 return RAW_IS_INODE(p);
828}
829
830static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
831{
832 return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
833}
834
835static inline block_t datablock_addr(struct page *node_page,
836 unsigned int offset)
837{
838 struct f2fs_node *raw_node;
839 __le32 *addr_array;
Gu Zheng45590712013-07-15 17:57:38 +0800840 raw_node = F2FS_NODE(node_page);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900841 addr_array = blkaddr_in_node(raw_node);
842 return le32_to_cpu(addr_array[offset]);
843}
844
845static inline int f2fs_test_bit(unsigned int nr, char *addr)
846{
847 int mask;
848
849 addr += (nr >> 3);
850 mask = 1 << (7 - (nr & 0x07));
851 return mask & *addr;
852}
853
854static inline int f2fs_set_bit(unsigned int nr, char *addr)
855{
856 int mask;
857 int ret;
858
859 addr += (nr >> 3);
860 mask = 1 << (7 - (nr & 0x07));
861 ret = mask & *addr;
862 *addr |= mask;
863 return ret;
864}
865
866static inline int f2fs_clear_bit(unsigned int nr, char *addr)
867{
868 int mask;
869 int ret;
870
871 addr += (nr >> 3);
872 mask = 1 << (7 - (nr & 0x07));
873 ret = mask & *addr;
874 *addr &= ~mask;
875 return ret;
876}
877
878/* used for f2fs_inode_info->flags */
879enum {
880 FI_NEW_INODE, /* indicate newly allocated inode */
Jaegeuk Kimb3783872013-06-10 09:17:01 +0900881 FI_DIRTY_INODE, /* indicate inode is dirty or not */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900882 FI_INC_LINK, /* need to increment i_nlink */
883 FI_ACL_MODE, /* indicate acl mode */
884 FI_NO_ALLOC, /* should not allocate any blocks */
Jaegeuk Kim699489b2013-06-07 22:08:23 +0900885 FI_UPDATE_DIR, /* should update inode block for consistency */
Jaegeuk Kim74d0b912013-05-15 16:40:02 +0900886 FI_DELAY_IPUT, /* used for the recovery */
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900887};
888
889static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
890{
891 set_bit(flag, &fi->flags);
892}
893
894static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
895{
896 return test_bit(flag, &fi->flags);
897}
898
899static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
900{
901 clear_bit(flag, &fi->flags);
902}
903
904static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
905{
906 fi->i_acl_mode = mode;
907 set_inode_flag(fi, FI_ACL_MODE);
908}
909
910static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag)
911{
912 if (is_inode_flag_set(fi, FI_ACL_MODE)) {
913 clear_inode_flag(fi, FI_ACL_MODE);
914 return 1;
915 }
916 return 0;
917}
918
Jaegeuk Kim77888c12013-05-20 20:28:47 +0900919static inline int f2fs_readonly(struct super_block *sb)
920{
921 return sb->s_flags & MS_RDONLY;
922}
923
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900924/*
925 * file.c
926 */
927int f2fs_sync_file(struct file *, loff_t, loff_t, int);
928void truncate_data_blocks(struct dnode_of_data *);
929void f2fs_truncate(struct inode *);
Jaegeuk Kim2d4d9fb52013-06-07 16:33:07 +0900930int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900931int f2fs_setattr(struct dentry *, struct iattr *);
932int truncate_hole(struct inode *, pgoff_t, pgoff_t);
Jaegeuk Kimb292dcab2013-05-22 08:02:02 +0900933int truncate_data_blocks_range(struct dnode_of_data *, int);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900934long f2fs_ioctl(struct file *, unsigned int, unsigned long);
Namjae Jeone9750822013-02-04 23:41:41 +0900935long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900936
937/*
938 * inode.c
939 */
940void f2fs_set_inode_flags(struct inode *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900941struct inode *f2fs_iget(struct super_block *, unsigned long);
942void update_inode(struct inode *, struct page *);
Jaegeuk Kim39936832012-11-22 16:21:29 +0900943int update_inode_page(struct inode *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900944int f2fs_write_inode(struct inode *, struct writeback_control *);
945void f2fs_evict_inode(struct inode *);
946
947/*
948 * namei.c
949 */
950struct dentry *f2fs_get_parent(struct dentry *child);
951
952/*
953 * dir.c
954 */
955struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
956 struct page **);
957struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
958ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
959void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
960 struct page *, struct inode *);
Jaegeuk Kim1cd14ca2013-07-18 18:02:31 +0900961int update_dent_inode(struct inode *, const struct qstr *);
Al Virob7f7a5e2013-01-25 16:15:43 -0500962int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900963void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
964int f2fs_make_empty(struct inode *, struct inode *);
965bool f2fs_empty_dir(struct inode *);
966
Al Virob7f7a5e2013-01-25 16:15:43 -0500967static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
968{
969 return __f2fs_add_link(dentry->d_parent->d_inode, &dentry->d_name,
970 inode);
971}
972
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900973/*
974 * super.c
975 */
976int f2fs_sync_fs(struct super_block *, int);
Namjae Jeona07ef782012-12-30 14:52:05 +0900977extern __printf(3, 4)
978void f2fs_msg(struct super_block *, const char *, const char *, ...);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900979
980/*
981 * hash.c
982 */
Leon Romanovsky9836b8b2012-12-27 19:55:46 +0200983f2fs_hash_t f2fs_dentry_hash(const char *, size_t);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900984
985/*
986 * node.c
987 */
988struct dnode_of_data;
989struct node_info;
990
991int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
992void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
993int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
994int truncate_inode_blocks(struct inode *, pgoff_t);
995int remove_inode_page(struct inode *);
Jaegeuk Kim44a83ff2013-05-20 10:10:29 +0900996struct page *new_inode_page(struct inode *, const struct qstr *);
Jaegeuk Kim8ae8f162013-06-03 19:46:19 +0900997struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +0900998void ra_node_page(struct f2fs_sb_info *, nid_t);
999struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
1000struct page *get_node_page_ra(struct page *, int);
1001void sync_inode_page(struct dnode_of_data *);
1002int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
1003bool alloc_nid(struct f2fs_sb_info *, nid_t *);
1004void alloc_nid_done(struct f2fs_sb_info *, nid_t);
1005void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
1006void recover_node_page(struct f2fs_sb_info *, struct page *,
1007 struct f2fs_summary *, struct node_info *, block_t);
1008int recover_inode_page(struct f2fs_sb_info *, struct page *);
1009int restore_node_summary(struct f2fs_sb_info *, unsigned int,
1010 struct f2fs_summary_block *);
1011void flush_nat_entries(struct f2fs_sb_info *);
1012int build_node_manager(struct f2fs_sb_info *);
1013void destroy_node_manager(struct f2fs_sb_info *);
Namjae Jeon6e6093a2013-01-17 00:08:30 +09001014int __init create_node_manager_caches(void);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001015void destroy_node_manager_caches(void);
1016
1017/*
1018 * segment.c
1019 */
1020void f2fs_balance_fs(struct f2fs_sb_info *);
1021void invalidate_blocks(struct f2fs_sb_info *, block_t);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001022void clear_prefree_segments(struct f2fs_sb_info *);
1023int npages_for_summary_flush(struct f2fs_sb_info *);
1024void allocate_new_segments(struct f2fs_sb_info *);
1025struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
Jaegeuk Kim3cd8a232012-12-10 09:26:05 +09001026struct bio *f2fs_bio_alloc(struct block_device *, int);
Jin Xua5694692013-08-05 20:02:04 +08001027void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool);
1028void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool);
Jaegeuk Kim577e3492013-01-24 19:56:11 +09001029void write_meta_page(struct f2fs_sb_info *, struct page *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001030void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int,
1031 block_t, block_t *);
1032void write_data_page(struct inode *, struct page *, struct dnode_of_data*,
1033 block_t, block_t *);
1034void rewrite_data_page(struct f2fs_sb_info *, struct page *, block_t);
1035void recover_data_page(struct f2fs_sb_info *, struct page *,
1036 struct f2fs_summary *, block_t, block_t);
1037void rewrite_node_page(struct f2fs_sb_info *, struct page *,
1038 struct f2fs_summary *, block_t, block_t);
1039void write_data_summaries(struct f2fs_sb_info *, block_t);
1040void write_node_summaries(struct f2fs_sb_info *, block_t);
1041int lookup_journal_in_cursum(struct f2fs_summary_block *,
1042 int, unsigned int, int);
1043void flush_sit_entries(struct f2fs_sb_info *);
1044int build_segment_manager(struct f2fs_sb_info *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001045void destroy_segment_manager(struct f2fs_sb_info *);
1046
1047/*
1048 * checkpoint.c
1049 */
1050struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
1051struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
1052long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
Jaegeuk Kimcbd56e72013-07-30 11:36:53 +09001053int acquire_orphan_inode(struct f2fs_sb_info *);
1054void release_orphan_inode(struct f2fs_sb_info *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001055void add_orphan_inode(struct f2fs_sb_info *, nid_t);
1056void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
1057int recover_orphan_inodes(struct f2fs_sb_info *);
1058int get_valid_checkpoint(struct f2fs_sb_info *);
1059void set_dirty_dir_page(struct inode *, struct page *);
Jaegeuk Kim5deb8262013-06-05 17:42:45 +09001060void add_dirty_dir_inode(struct inode *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001061void remove_dirty_dir_inode(struct inode *);
Jaegeuk Kim74d0b912013-05-15 16:40:02 +09001062struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001063void sync_dirty_dir_inodes(struct f2fs_sb_info *);
Jaegeuk Kim43727522013-02-04 15:11:17 +09001064void write_checkpoint(struct f2fs_sb_info *, bool);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001065void init_orphan_info(struct f2fs_sb_info *);
Namjae Jeon6e6093a2013-01-17 00:08:30 +09001066int __init create_checkpoint_caches(void);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001067void destroy_checkpoint_caches(void);
1068
1069/*
1070 * data.c
1071 */
1072int reserve_new_block(struct dnode_of_data *);
1073void update_extent_cache(block_t, struct dnode_of_data *);
Jaegeuk Kimc718379b2013-04-24 13:19:56 +09001074struct page *find_data_page(struct inode *, pgoff_t, bool);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001075struct page *get_lock_data_page(struct inode *, pgoff_t);
Jaegeuk Kim64aa7ed2013-05-20 09:55:50 +09001076struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001077int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
1078int do_write_data_page(struct page *);
1079
1080/*
1081 * gc.c
1082 */
1083int start_gc_thread(struct f2fs_sb_info *);
1084void stop_gc_thread(struct f2fs_sb_info *);
1085block_t start_bidx_of_node(unsigned int);
Jaegeuk Kim408e9372013-01-03 17:55:52 +09001086int f2fs_gc(struct f2fs_sb_info *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001087void build_gc_manager(struct f2fs_sb_info *);
Namjae Jeon6e6093a2013-01-17 00:08:30 +09001088int __init create_gc_caches(void);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001089void destroy_gc_caches(void);
1090
1091/*
1092 * recovery.c
1093 */
Jaegeuk Kim6ead1142013-03-20 19:01:06 +09001094int recover_fsync_data(struct f2fs_sb_info *);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001095bool space_for_roll_forward(struct f2fs_sb_info *);
1096
1097/*
1098 * debug.c
1099 */
1100#ifdef CONFIG_F2FS_STAT_FS
1101struct f2fs_stat_info {
1102 struct list_head stat_list;
1103 struct f2fs_sb_info *sbi;
1104 struct mutex stat_lock;
1105 int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
1106 int main_area_segs, main_area_sections, main_area_zones;
1107 int hit_ext, total_ext;
1108 int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
1109 int nats, sits, fnids;
1110 int total_count, utilization;
1111 int bg_gc;
1112 unsigned int valid_count, valid_node_count, valid_inode_count;
1113 unsigned int bimodal, avg_vblocks;
1114 int util_free, util_valid, util_invalid;
1115 int rsvd_segs, overp_segs;
1116 int dirty_count, node_pages, meta_pages;
1117 int prefree_count, call_count;
1118 int tot_segs, node_segs, data_segs, free_segs, free_secs;
1119 int tot_blks, data_blks, node_blks;
1120 int curseg[NR_CURSEG_TYPE];
1121 int cursec[NR_CURSEG_TYPE];
1122 int curzone[NR_CURSEG_TYPE];
1123
1124 unsigned int segment_count[2];
1125 unsigned int block_count[2];
1126 unsigned base_mem, cache_mem;
1127};
1128
Gu Zheng963d4f72013-07-12 14:47:11 +08001129static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
1130{
1131 return (struct f2fs_stat_info*)sbi->stat_info;
1132}
1133
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001134#define stat_inc_call_count(si) ((si)->call_count++)
1135
1136#define stat_inc_seg_count(sbi, type) \
1137 do { \
Gu Zheng963d4f72013-07-12 14:47:11 +08001138 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001139 (si)->tot_segs++; \
1140 if (type == SUM_TYPE_DATA) \
1141 si->data_segs++; \
1142 else \
1143 si->node_segs++; \
1144 } while (0)
1145
1146#define stat_inc_tot_blk_count(si, blks) \
1147 (si->tot_blks += (blks))
1148
1149#define stat_inc_data_blk_count(sbi, blks) \
1150 do { \
Gu Zheng963d4f72013-07-12 14:47:11 +08001151 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001152 stat_inc_tot_blk_count(si, blks); \
1153 si->data_blks += (blks); \
1154 } while (0)
1155
1156#define stat_inc_node_blk_count(sbi, blks) \
1157 do { \
Gu Zheng963d4f72013-07-12 14:47:11 +08001158 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001159 stat_inc_tot_blk_count(si, blks); \
1160 si->node_blks += (blks); \
1161 } while (0)
1162
1163int f2fs_build_stats(struct f2fs_sb_info *);
1164void f2fs_destroy_stats(struct f2fs_sb_info *);
Namjae Jeon6e6093a2013-01-17 00:08:30 +09001165void __init f2fs_create_root_stats(void);
Namjae Jeon4589d252013-01-15 19:58:47 +09001166void f2fs_destroy_root_stats(void);
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001167#else
1168#define stat_inc_call_count(si)
1169#define stat_inc_seg_count(si, type)
1170#define stat_inc_tot_blk_count(si, blks)
1171#define stat_inc_data_blk_count(si, blks)
1172#define stat_inc_node_blk_count(sbi, blks)
1173
1174static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
1175static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
Namjae Jeon6e6093a2013-01-17 00:08:30 +09001176static inline void __init f2fs_create_root_stats(void) { }
Namjae Jeon4589d252013-01-15 19:58:47 +09001177static inline void f2fs_destroy_root_stats(void) { }
Jaegeuk Kim39a53e02012-11-28 13:37:31 +09001178#endif
1179
1180extern const struct file_operations f2fs_dir_operations;
1181extern const struct file_operations f2fs_file_operations;
1182extern const struct inode_operations f2fs_file_inode_operations;
1183extern const struct address_space_operations f2fs_dblock_aops;
1184extern const struct address_space_operations f2fs_node_aops;
1185extern const struct address_space_operations f2fs_meta_aops;
1186extern const struct inode_operations f2fs_dir_inode_operations;
1187extern const struct inode_operations f2fs_symlink_inode_operations;
1188extern const struct inode_operations f2fs_special_inode_operations;
1189#endif