Commit | Line | Data |
---|---|---|
0a8165d7 | 1 | /* |
39a53e0c JK |
2 | * fs/f2fs/f2fs.h |
3 | * | |
4 | * Copyright (c) 2012 Samsung Electronics Co., Ltd. | |
5 | * http://www.samsung.com/ | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License version 2 as | |
9 | * published by the Free Software Foundation. | |
10 | */ | |
11 | #ifndef _LINUX_F2FS_H | |
12 | #define _LINUX_F2FS_H | |
13 | ||
14 | #include <linux/types.h> | |
15 | #include <linux/page-flags.h> | |
16 | #include <linux/buffer_head.h> | |
39a53e0c JK |
17 | #include <linux/slab.h> |
18 | #include <linux/crc32.h> | |
19 | #include <linux/magic.h> | |
c2d715d1 | 20 | #include <linux/kobject.h> |
39a53e0c JK |
21 | |
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 | ||
a9841c4d JK |
41 | typedef u32 block_t; /* |
42 | * should not change u32, since it is the on-disk block | |
43 | * address format, __le32. | |
44 | */ | |
39a53e0c JK |
45 | typedef u32 nid_t; |
46 | ||
47 | struct f2fs_mount_info { | |
48 | unsigned int opt; | |
49 | }; | |
50 | ||
7e586fa0 JK |
51 | #define CRCPOLY_LE 0xedb88320 |
52 | ||
53 | static inline __u32 f2fs_crc32(void *buf, size_t len) | |
39a53e0c | 54 | { |
7e586fa0 JK |
55 | 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; | |
39a53e0c JK |
65 | } |
66 | ||
7e586fa0 | 67 | static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size) |
39a53e0c | 68 | { |
7e586fa0 | 69 | return f2fs_crc32(buf, buf_size) == blk_crc; |
39a53e0c JK |
70 | } |
71 | ||
72 | /* | |
73 | * For checkpoint manager | |
74 | */ | |
75 | enum { | |
76 | NAT_BITMAP, | |
77 | SIT_BITMAP | |
78 | }; | |
79 | ||
80 | /* for the list of orphan inodes */ | |
81 | struct 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 */ | |
87 | struct 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 */ | |
93 | struct 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 | ||
107 | static 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 | ||
114 | static 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 | ||
e9750824 NJ |
121 | /* |
122 | * 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 | ||
39a53e0c JK |
135 | /* |
136 | * 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 | */ | |
266e97a8 JK |
143 | enum { |
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. | |
39a53e0c | 149 | */ |
266e97a8 JK |
150 | }; |
151 | ||
39a53e0c JK |
152 | #define F2FS_LINK_MAX 32000 /* maximum link count per file */ |
153 | ||
154 | /* for in-memory extent cache entry */ | |
155 | struct 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 */ | |
111d2495 | 159 | unsigned int len; /* length of the extent */ |
39a53e0c JK |
160 | }; |
161 | ||
162 | /* | |
163 | * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. | |
164 | */ | |
165 | #define FADVISE_COLD_BIT 0x01 | |
354a3399 | 166 | #define FADVISE_LOST_PINO_BIT 0x02 |
39a53e0c JK |
167 | |
168 | struct 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 */ | |
6666e6aa | 173 | unsigned int i_pino; /* parent inode number */ |
39a53e0c JK |
174 | 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 */ | |
39a53e0c JK |
178 | 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 | ||
185 | static 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 | ||
195 | static 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 | ||
205 | struct f2fs_nm_info { | |
206 | block_t nat_blkaddr; /* base disk address of NAT */ | |
207 | nid_t max_nid; /* maximum possible node ids */ | |
39a53e0c JK |
208 | 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 | */ | |
233 | struct 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 | ||
243 | static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, | |
244 | struct page *ipage, struct page *npage, nid_t nid) | |
245 | { | |
d66d1f76 | 246 | memset(dn, 0, sizeof(*dn)); |
39a53e0c JK |
247 | dn->inode = inode; |
248 | dn->inode_page = ipage; | |
249 | dn->node_page = npage; | |
250 | dn->nid = nid; | |
39a53e0c JK |
251 | } |
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 | ||
270 | enum { | |
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 | ||
280 | struct 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 | */ | |
317 | enum count_type { | |
318 | F2FS_WRITEBACK, | |
319 | F2FS_DIRTY_DENTS, | |
320 | F2FS_DIRTY_NODES, | |
321 | F2FS_DIRTY_META, | |
322 | NR_COUNT_TYPE, | |
323 | }; | |
324 | ||
325 | /* | |
39936837 JK |
326 | * 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. | |
39a53e0c | 330 | */ |
39936837 | 331 | #define NR_GLOBAL_LOCKS 8 |
39a53e0c JK |
332 | |
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 | */ | |
344 | enum page_type { | |
345 | DATA, | |
346 | NODE, | |
347 | META, | |
348 | NR_PAGE_TYPE, | |
349 | META_FLUSH, | |
350 | }; | |
351 | ||
352 | struct f2fs_sb_info { | |
353 | struct super_block *sb; /* pointer to VFS super block */ | |
5e176d54 | 354 | struct proc_dir_entry *s_proc; /* proc entry */ |
39a53e0c JK |
355 | 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 */ | |
39936837 JK |
372 | 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 */ | |
39a53e0c | 375 | struct mutex writepages; /* mutex for writepages() */ |
39936837 | 376 | unsigned char next_lock_num; /* round-robin global locks */ |
39a53e0c | 377 | int por_doing; /* recovery is doing or not */ |
55008d84 | 378 | int on_build_free_nids; /* build_free_nids is doing */ |
39a53e0c JK |
379 | |
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 */ | |
39a53e0c JK |
388 | |
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 */ | |
5ec4e49f | 418 | unsigned int cur_victim_sec; /* current victim section num */ |
39a53e0c JK |
419 | |
420 | /* | |
421 | * for stat information. | |
422 | * one is for the LFS mode, and the other is for the SSR mode. | |
423 | */ | |
35b09d82 | 424 | #ifdef CONFIG_F2FS_STAT_FS |
39a53e0c JK |
425 | 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 */ | |
39a53e0c JK |
428 | int total_hit_ext, read_hit_ext; /* extent cache hit ratio */ |
429 | int bg_gc; /* background gc calls */ | |
35b09d82 NJ |
430 | unsigned int n_dirty_dirs; /* # of dir inodes */ |
431 | #endif | |
432 | unsigned int last_victim[2]; /* last victim segment # */ | |
39a53e0c | 433 | spinlock_t stat_lock; /* lock for stat operations */ |
b59d0bae NJ |
434 | |
435 | /* For sysfs suppport */ | |
436 | struct kobject s_kobj; | |
437 | struct completion s_kobj_unregister; | |
39a53e0c JK |
438 | }; |
439 | ||
440 | /* | |
441 | * Inline functions | |
442 | */ | |
443 | static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) | |
444 | { | |
445 | return container_of(inode, struct f2fs_inode_info, vfs_inode); | |
446 | } | |
447 | ||
448 | static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) | |
449 | { | |
450 | return sb->s_fs_info; | |
451 | } | |
452 | ||
453 | static 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 | ||
458 | static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) | |
459 | { | |
460 | return (struct f2fs_checkpoint *)(sbi->ckpt); | |
461 | } | |
462 | ||
45590710 GZ |
463 | static inline struct f2fs_node *F2FS_NODE(struct page *page) |
464 | { | |
465 | return (struct f2fs_node *)page_address(page); | |
466 | } | |
467 | ||
39a53e0c JK |
468 | static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) |
469 | { | |
470 | return (struct f2fs_nm_info *)(sbi->nm_info); | |
471 | } | |
472 | ||
473 | static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) | |
474 | { | |
475 | return (struct f2fs_sm_info *)(sbi->sm_info); | |
476 | } | |
477 | ||
478 | static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) | |
479 | { | |
480 | return (struct sit_info *)(SM_I(sbi)->sit_info); | |
481 | } | |
482 | ||
483 | static 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 | ||
488 | static 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 | ||
493 | static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi) | |
494 | { | |
495 | sbi->s_dirty = 1; | |
496 | } | |
497 | ||
498 | static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi) | |
499 | { | |
500 | sbi->s_dirty = 0; | |
501 | } | |
502 | ||
25ca923b JK |
503 | static 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 | ||
509 | static 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 | ||
516 | static 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 | ||
39936837 JK |
523 | static inline void mutex_lock_all(struct f2fs_sb_info *sbi) |
524 | { | |
bfe35965 PZ |
525 | 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 | } | |
39936837 JK |
536 | } |
537 | ||
538 | static inline void mutex_unlock_all(struct f2fs_sb_info *sbi) | |
39a53e0c | 539 | { |
39936837 JK |
540 | int i = 0; |
541 | for (; i < NR_GLOBAL_LOCKS; i++) | |
542 | mutex_unlock(&sbi->fs_lock[i]); | |
39a53e0c JK |
543 | } |
544 | ||
39936837 | 545 | static inline int mutex_lock_op(struct f2fs_sb_info *sbi) |
39a53e0c | 546 | { |
39936837 JK |
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 | ||
559 | static 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]); | |
39a53e0c JK |
565 | } |
566 | ||
567 | /* | |
568 | * Check whether the given nid is within node id range. | |
569 | */ | |
064e0823 | 570 | static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) |
39a53e0c | 571 | { |
064e0823 NJ |
572 | WARN_ON((nid >= NM_I(sbi)->max_nid)); |
573 | if (nid >= NM_I(sbi)->max_nid) | |
574 | return -EINVAL; | |
575 | return 0; | |
39a53e0c JK |
576 | } |
577 | ||
578 | #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 | |
579 | ||
580 | /* | |
581 | * Check whether the inode has blocks or not | |
582 | */ | |
583 | static 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 | ||
591 | static 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 | ||
610 | static 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 | ||
623 | static 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 | ||
629 | static inline void inode_inc_dirty_dents(struct inode *inode) | |
630 | { | |
631 | atomic_inc(&F2FS_I(inode)->dirty_dents); | |
632 | } | |
633 | ||
634 | static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) | |
635 | { | |
636 | atomic_dec(&sbi->nr_pages[count_type]); | |
637 | } | |
638 | ||
639 | static inline void inode_dec_dirty_dents(struct inode *inode) | |
640 | { | |
641 | atomic_dec(&F2FS_I(inode)->dirty_dents); | |
642 | } | |
643 | ||
644 | static inline int get_pages(struct f2fs_sb_info *sbi, int count_type) | |
645 | { | |
646 | return atomic_read(&sbi->nr_pages[count_type]); | |
647 | } | |
648 | ||
5ac206cf NJ |
649 | static 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 | ||
39a53e0c JK |
657 | static 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 | ||
666 | static 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 | ||
679 | static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) | |
680 | { | |
681 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); | |
25ca923b JK |
682 | int offset = (flag == NAT_BITMAP) ? |
683 | le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; | |
39a53e0c JK |
684 | return &ckpt->sit_nat_version_bitmap + offset; |
685 | } | |
686 | ||
687 | static 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 | ||
25ca923b | 693 | start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); |
39a53e0c JK |
694 | |
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 | ||
705 | static 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 | ||
710 | static 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 | ||
742 | static 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 | ||
759 | static 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 | ||
768 | static 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 | ||
776 | static 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 | ||
785 | static 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 | ||
794 | static 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 | ||
806 | static 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 | ||
816 | static 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 | ||
824 | static inline bool IS_INODE(struct page *page) | |
825 | { | |
45590710 | 826 | struct f2fs_node *p = F2FS_NODE(page); |
39a53e0c JK |
827 | return RAW_IS_INODE(p); |
828 | } | |
829 | ||
830 | static 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 | ||
835 | static inline block_t datablock_addr(struct page *node_page, | |
836 | unsigned int offset) | |
837 | { | |
838 | struct f2fs_node *raw_node; | |
839 | __le32 *addr_array; | |
45590710 | 840 | raw_node = F2FS_NODE(node_page); |
39a53e0c JK |
841 | addr_array = blkaddr_in_node(raw_node); |
842 | return le32_to_cpu(addr_array[offset]); | |
843 | } | |
844 | ||
845 | static 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 | ||
854 | static 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 | ||
866 | static 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 */ | |
879 | enum { | |
880 | FI_NEW_INODE, /* indicate newly allocated inode */ | |
b3783873 | 881 | FI_DIRTY_INODE, /* indicate inode is dirty or not */ |
39a53e0c JK |
882 | FI_INC_LINK, /* need to increment i_nlink */ |
883 | FI_ACL_MODE, /* indicate acl mode */ | |
884 | FI_NO_ALLOC, /* should not allocate any blocks */ | |
699489bb | 885 | FI_UPDATE_DIR, /* should update inode block for consistency */ |
74d0b917 | 886 | FI_DELAY_IPUT, /* used for the recovery */ |
39a53e0c JK |
887 | }; |
888 | ||
889 | static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag) | |
890 | { | |
891 | set_bit(flag, &fi->flags); | |
892 | } | |
893 | ||
894 | static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag) | |
895 | { | |
896 | return test_bit(flag, &fi->flags); | |
897 | } | |
898 | ||
899 | static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag) | |
900 | { | |
901 | clear_bit(flag, &fi->flags); | |
902 | } | |
903 | ||
904 | static 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 | ||
910 | static 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 | ||
77888c1e JK |
919 | static inline int f2fs_readonly(struct super_block *sb) |
920 | { | |
921 | return sb->s_flags & MS_RDONLY; | |
922 | } | |
923 | ||
39a53e0c JK |
924 | /* |
925 | * file.c | |
926 | */ | |
927 | int f2fs_sync_file(struct file *, loff_t, loff_t, int); | |
928 | void truncate_data_blocks(struct dnode_of_data *); | |
929 | void f2fs_truncate(struct inode *); | |
2d4d9fb5 | 930 | int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); |
39a53e0c JK |
931 | int f2fs_setattr(struct dentry *, struct iattr *); |
932 | int truncate_hole(struct inode *, pgoff_t, pgoff_t); | |
b292dcab | 933 | int truncate_data_blocks_range(struct dnode_of_data *, int); |
39a53e0c | 934 | long f2fs_ioctl(struct file *, unsigned int, unsigned long); |
e9750824 | 935 | long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long); |
39a53e0c JK |
936 | |
937 | /* | |
938 | * inode.c | |
939 | */ | |
940 | void f2fs_set_inode_flags(struct inode *); | |
39a53e0c JK |
941 | struct inode *f2fs_iget(struct super_block *, unsigned long); |
942 | void update_inode(struct inode *, struct page *); | |
39936837 | 943 | int update_inode_page(struct inode *); |
39a53e0c JK |
944 | int f2fs_write_inode(struct inode *, struct writeback_control *); |
945 | void f2fs_evict_inode(struct inode *); | |
946 | ||
947 | /* | |
948 | * namei.c | |
949 | */ | |
950 | struct dentry *f2fs_get_parent(struct dentry *child); | |
951 | ||
952 | /* | |
953 | * dir.c | |
954 | */ | |
955 | struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *, | |
956 | struct page **); | |
957 | struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **); | |
958 | ino_t f2fs_inode_by_name(struct inode *, struct qstr *); | |
959 | void f2fs_set_link(struct inode *, struct f2fs_dir_entry *, | |
960 | struct page *, struct inode *); | |
1cd14caf | 961 | int update_dent_inode(struct inode *, const struct qstr *); |
b7f7a5e0 | 962 | int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *); |
39a53e0c JK |
963 | void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *); |
964 | int f2fs_make_empty(struct inode *, struct inode *); | |
965 | bool f2fs_empty_dir(struct inode *); | |
966 | ||
b7f7a5e0 AV |
967 | static 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 | ||
39a53e0c JK |
973 | /* |
974 | * super.c | |
975 | */ | |
976 | int f2fs_sync_fs(struct super_block *, int); | |
a07ef784 NJ |
977 | extern __printf(3, 4) |
978 | void f2fs_msg(struct super_block *, const char *, const char *, ...); | |
39a53e0c JK |
979 | |
980 | /* | |
981 | * hash.c | |
982 | */ | |
9836b8b9 | 983 | f2fs_hash_t f2fs_dentry_hash(const char *, size_t); |
39a53e0c JK |
984 | |
985 | /* | |
986 | * node.c | |
987 | */ | |
988 | struct dnode_of_data; | |
989 | struct node_info; | |
990 | ||
991 | int is_checkpointed_node(struct f2fs_sb_info *, nid_t); | |
992 | void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *); | |
993 | int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int); | |
994 | int truncate_inode_blocks(struct inode *, pgoff_t); | |
995 | int remove_inode_page(struct inode *); | |
44a83ff6 | 996 | struct page *new_inode_page(struct inode *, const struct qstr *); |
8ae8f162 | 997 | struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *); |
39a53e0c JK |
998 | void ra_node_page(struct f2fs_sb_info *, nid_t); |
999 | struct page *get_node_page(struct f2fs_sb_info *, pgoff_t); | |
1000 | struct page *get_node_page_ra(struct page *, int); | |
1001 | void sync_inode_page(struct dnode_of_data *); | |
1002 | int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); | |
1003 | bool alloc_nid(struct f2fs_sb_info *, nid_t *); | |
1004 | void alloc_nid_done(struct f2fs_sb_info *, nid_t); | |
1005 | void alloc_nid_failed(struct f2fs_sb_info *, nid_t); | |
1006 | void recover_node_page(struct f2fs_sb_info *, struct page *, | |
1007 | struct f2fs_summary *, struct node_info *, block_t); | |
1008 | int recover_inode_page(struct f2fs_sb_info *, struct page *); | |
1009 | int restore_node_summary(struct f2fs_sb_info *, unsigned int, | |
1010 | struct f2fs_summary_block *); | |
1011 | void flush_nat_entries(struct f2fs_sb_info *); | |
1012 | int build_node_manager(struct f2fs_sb_info *); | |
1013 | void destroy_node_manager(struct f2fs_sb_info *); | |
6e6093a8 | 1014 | int __init create_node_manager_caches(void); |
39a53e0c JK |
1015 | void destroy_node_manager_caches(void); |
1016 | ||
1017 | /* | |
1018 | * segment.c | |
1019 | */ | |
1020 | void f2fs_balance_fs(struct f2fs_sb_info *); | |
1021 | void invalidate_blocks(struct f2fs_sb_info *, block_t); | |
39a53e0c JK |
1022 | void clear_prefree_segments(struct f2fs_sb_info *); |
1023 | int npages_for_summary_flush(struct f2fs_sb_info *); | |
1024 | void allocate_new_segments(struct f2fs_sb_info *); | |
1025 | struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); | |
3cd8a239 | 1026 | struct bio *f2fs_bio_alloc(struct block_device *, int); |
a569469e JX |
1027 | void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool); |
1028 | void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool); | |
577e3495 | 1029 | void write_meta_page(struct f2fs_sb_info *, struct page *); |
39a53e0c JK |
1030 | void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int, |
1031 | block_t, block_t *); | |
1032 | void write_data_page(struct inode *, struct page *, struct dnode_of_data*, | |
1033 | block_t, block_t *); | |
1034 | void rewrite_data_page(struct f2fs_sb_info *, struct page *, block_t); | |
1035 | void recover_data_page(struct f2fs_sb_info *, struct page *, | |
1036 | struct f2fs_summary *, block_t, block_t); | |
1037 | void rewrite_node_page(struct f2fs_sb_info *, struct page *, | |
1038 | struct f2fs_summary *, block_t, block_t); | |
1039 | void write_data_summaries(struct f2fs_sb_info *, block_t); | |
1040 | void write_node_summaries(struct f2fs_sb_info *, block_t); | |
1041 | int lookup_journal_in_cursum(struct f2fs_summary_block *, | |
1042 | int, unsigned int, int); | |
1043 | void flush_sit_entries(struct f2fs_sb_info *); | |
1044 | int build_segment_manager(struct f2fs_sb_info *); | |
39a53e0c JK |
1045 | void destroy_segment_manager(struct f2fs_sb_info *); |
1046 | ||
1047 | /* | |
1048 | * checkpoint.c | |
1049 | */ | |
1050 | struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t); | |
1051 | struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t); | |
1052 | long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); | |
cbd56e7d JK |
1053 | int acquire_orphan_inode(struct f2fs_sb_info *); |
1054 | void release_orphan_inode(struct f2fs_sb_info *); | |
39a53e0c JK |
1055 | void add_orphan_inode(struct f2fs_sb_info *, nid_t); |
1056 | void remove_orphan_inode(struct f2fs_sb_info *, nid_t); | |
1057 | int recover_orphan_inodes(struct f2fs_sb_info *); | |
1058 | int get_valid_checkpoint(struct f2fs_sb_info *); | |
1059 | void set_dirty_dir_page(struct inode *, struct page *); | |
5deb8267 | 1060 | void add_dirty_dir_inode(struct inode *); |
39a53e0c | 1061 | void remove_dirty_dir_inode(struct inode *); |
74d0b917 | 1062 | struct inode *check_dirty_dir_inode(struct f2fs_sb_info *, nid_t); |
39a53e0c | 1063 | void sync_dirty_dir_inodes(struct f2fs_sb_info *); |
43727527 | 1064 | void write_checkpoint(struct f2fs_sb_info *, bool); |
39a53e0c | 1065 | void init_orphan_info(struct f2fs_sb_info *); |
6e6093a8 | 1066 | int __init create_checkpoint_caches(void); |
39a53e0c JK |
1067 | void destroy_checkpoint_caches(void); |
1068 | ||
1069 | /* | |
1070 | * data.c | |
1071 | */ | |
1072 | int reserve_new_block(struct dnode_of_data *); | |
1073 | void update_extent_cache(block_t, struct dnode_of_data *); | |
c718379b | 1074 | struct page *find_data_page(struct inode *, pgoff_t, bool); |
39a53e0c | 1075 | struct page *get_lock_data_page(struct inode *, pgoff_t); |
64aa7ed9 | 1076 | struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool); |
39a53e0c JK |
1077 | int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int); |
1078 | int do_write_data_page(struct page *); | |
1079 | ||
1080 | /* | |
1081 | * gc.c | |
1082 | */ | |
1083 | int start_gc_thread(struct f2fs_sb_info *); | |
1084 | void stop_gc_thread(struct f2fs_sb_info *); | |
1085 | block_t start_bidx_of_node(unsigned int); | |
408e9375 | 1086 | int f2fs_gc(struct f2fs_sb_info *); |
39a53e0c | 1087 | void build_gc_manager(struct f2fs_sb_info *); |
6e6093a8 | 1088 | int __init create_gc_caches(void); |
39a53e0c JK |
1089 | void destroy_gc_caches(void); |
1090 | ||
1091 | /* | |
1092 | * recovery.c | |
1093 | */ | |
6ead1142 | 1094 | int recover_fsync_data(struct f2fs_sb_info *); |
39a53e0c JK |
1095 | bool space_for_roll_forward(struct f2fs_sb_info *); |
1096 | ||
1097 | /* | |
1098 | * debug.c | |
1099 | */ | |
1100 | #ifdef CONFIG_F2FS_STAT_FS | |
1101 | struct 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 | ||
963d4f7d GZ |
1129 | static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) |
1130 | { | |
1131 | return (struct f2fs_stat_info*)sbi->stat_info; | |
1132 | } | |
1133 | ||
39a53e0c JK |
1134 | #define stat_inc_call_count(si) ((si)->call_count++) |
1135 | ||
1136 | #define stat_inc_seg_count(sbi, type) \ | |
1137 | do { \ | |
963d4f7d | 1138 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
39a53e0c JK |
1139 | (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 { \ | |
963d4f7d | 1151 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
39a53e0c JK |
1152 | 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 { \ | |
963d4f7d | 1158 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
39a53e0c JK |
1159 | stat_inc_tot_blk_count(si, blks); \ |
1160 | si->node_blks += (blks); \ | |
1161 | } while (0) | |
1162 | ||
1163 | int f2fs_build_stats(struct f2fs_sb_info *); | |
1164 | void f2fs_destroy_stats(struct f2fs_sb_info *); | |
6e6093a8 | 1165 | void __init f2fs_create_root_stats(void); |
4589d25d | 1166 | void f2fs_destroy_root_stats(void); |
39a53e0c JK |
1167 | #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 | ||
1174 | static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } | |
1175 | static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } | |
6e6093a8 | 1176 | static inline void __init f2fs_create_root_stats(void) { } |
4589d25d | 1177 | static inline void f2fs_destroy_root_stats(void) { } |
39a53e0c JK |
1178 | #endif |
1179 | ||
1180 | extern const struct file_operations f2fs_dir_operations; | |
1181 | extern const struct file_operations f2fs_file_operations; | |
1182 | extern const struct inode_operations f2fs_file_inode_operations; | |
1183 | extern const struct address_space_operations f2fs_dblock_aops; | |
1184 | extern const struct address_space_operations f2fs_node_aops; | |
1185 | extern const struct address_space_operations f2fs_meta_aops; | |
1186 | extern const struct inode_operations f2fs_dir_inode_operations; | |
1187 | extern const struct inode_operations f2fs_symlink_inode_operations; | |
1188 | extern const struct inode_operations f2fs_special_inode_operations; | |
1189 | #endif |