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