]>
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> |
39307a8e | 22 | #include <linux/vmalloc.h> |
740432f8 | 23 | #include <linux/bio.h> |
d0239e1b | 24 | #include <linux/blkdev.h> |
46f47e48 EB |
25 | #ifdef CONFIG_F2FS_FS_ENCRYPTION |
26 | #include <linux/fscrypt_supp.h> | |
27 | #else | |
28 | #include <linux/fscrypt_notsupp.h> | |
29 | #endif | |
43b6573b | 30 | #include <crypto/hash.h> |
39a53e0c | 31 | |
5d56b671 | 32 | #ifdef CONFIG_F2FS_CHECK_FS |
9850cf4a | 33 | #define f2fs_bug_on(sbi, condition) BUG_ON(condition) |
5d56b671 | 34 | #else |
9850cf4a JK |
35 | #define f2fs_bug_on(sbi, condition) \ |
36 | do { \ | |
37 | if (unlikely(condition)) { \ | |
38 | WARN_ON(1); \ | |
caf0047e | 39 | set_sbi_flag(sbi, SBI_NEED_FSCK); \ |
9850cf4a JK |
40 | } \ |
41 | } while (0) | |
5d56b671 JK |
42 | #endif |
43 | ||
2c63fead JK |
44 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
45 | enum { | |
46 | FAULT_KMALLOC, | |
c41f3cc3 | 47 | FAULT_PAGE_ALLOC, |
cb78942b JK |
48 | FAULT_ALLOC_NID, |
49 | FAULT_ORPHAN, | |
50 | FAULT_BLOCK, | |
51 | FAULT_DIR_DEPTH, | |
53aa6bbf | 52 | FAULT_EVICT_INODE, |
14b44d23 | 53 | FAULT_TRUNCATE, |
8b038c70 | 54 | FAULT_IO, |
0f348028 | 55 | FAULT_CHECKPOINT, |
2c63fead JK |
56 | FAULT_MAX, |
57 | }; | |
58 | ||
08796897 SY |
59 | struct f2fs_fault_info { |
60 | atomic_t inject_ops; | |
61 | unsigned int inject_rate; | |
62 | unsigned int inject_type; | |
63 | }; | |
64 | ||
2c63fead | 65 | extern char *fault_name[FAULT_MAX]; |
68afcf2d | 66 | #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) |
2c63fead JK |
67 | #endif |
68 | ||
39a53e0c JK |
69 | /* |
70 | * For mount options | |
71 | */ | |
72 | #define F2FS_MOUNT_BG_GC 0x00000001 | |
73 | #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 | |
74 | #define F2FS_MOUNT_DISCARD 0x00000004 | |
75 | #define F2FS_MOUNT_NOHEAP 0x00000008 | |
76 | #define F2FS_MOUNT_XATTR_USER 0x00000010 | |
77 | #define F2FS_MOUNT_POSIX_ACL 0x00000020 | |
78 | #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 | |
444c580f | 79 | #define F2FS_MOUNT_INLINE_XATTR 0x00000080 |
1001b347 | 80 | #define F2FS_MOUNT_INLINE_DATA 0x00000100 |
34d67deb CY |
81 | #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 |
82 | #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 | |
83 | #define F2FS_MOUNT_NOBARRIER 0x00000800 | |
d5053a34 | 84 | #define F2FS_MOUNT_FASTBOOT 0x00001000 |
89672159 | 85 | #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 |
6aefd93b | 86 | #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 |
343f40f0 | 87 | #define F2FS_MOUNT_DATA_FLUSH 0x00008000 |
73faec4d | 88 | #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 |
36abef4e JK |
89 | #define F2FS_MOUNT_ADAPTIVE 0x00020000 |
90 | #define F2FS_MOUNT_LFS 0x00040000 | |
39a53e0c | 91 | |
68afcf2d TK |
92 | #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) |
93 | #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) | |
94 | #define test_opt(sbi, option) ((sbi)->mount_opt.opt & F2FS_MOUNT_##option) | |
39a53e0c JK |
95 | |
96 | #define ver_after(a, b) (typecheck(unsigned long long, a) && \ | |
97 | typecheck(unsigned long long, b) && \ | |
98 | ((long long)((a) - (b)) > 0)) | |
99 | ||
a9841c4d JK |
100 | typedef u32 block_t; /* |
101 | * should not change u32, since it is the on-disk block | |
102 | * address format, __le32. | |
103 | */ | |
39a53e0c JK |
104 | typedef u32 nid_t; |
105 | ||
106 | struct f2fs_mount_info { | |
107 | unsigned int opt; | |
108 | }; | |
109 | ||
cde4de12 | 110 | #define F2FS_FEATURE_ENCRYPT 0x0001 |
0bfd7a09 | 111 | #define F2FS_FEATURE_BLKZONED 0x0002 |
cde4de12 | 112 | |
76f105a2 JK |
113 | #define F2FS_HAS_FEATURE(sb, mask) \ |
114 | ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) | |
115 | #define F2FS_SET_FEATURE(sb, mask) \ | |
c64ab12e | 116 | (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) |
76f105a2 | 117 | #define F2FS_CLEAR_FEATURE(sb, mask) \ |
c64ab12e | 118 | (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) |
76f105a2 | 119 | |
39a53e0c JK |
120 | /* |
121 | * For checkpoint manager | |
122 | */ | |
123 | enum { | |
124 | NAT_BITMAP, | |
125 | SIT_BITMAP | |
126 | }; | |
127 | ||
75ab4cb8 JK |
128 | enum { |
129 | CP_UMOUNT, | |
119ee914 | 130 | CP_FASTBOOT, |
75ab4cb8 | 131 | CP_SYNC, |
10027551 | 132 | CP_RECOVERY, |
4b2fecc8 | 133 | CP_DISCARD, |
75ab4cb8 JK |
134 | }; |
135 | ||
47b89808 | 136 | #define DEF_BATCHED_TRIM_SECTIONS 2048 |
bba681cb JK |
137 | #define BATCHED_TRIM_SEGMENTS(sbi) \ |
138 | (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) | |
a66cdd98 JK |
139 | #define BATCHED_TRIM_BLOCKS(sbi) \ |
140 | (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) | |
ad4d307f JK |
141 | #define MAX_DISCARD_BLOCKS(sbi) \ |
142 | ((1 << (sbi)->log_blocks_per_seg) * (sbi)->segs_per_sec) | |
15469963 | 143 | #define DISCARD_ISSUE_RATE 8 |
60b99b48 | 144 | #define DEF_CP_INTERVAL 60 /* 60 secs */ |
dcf25fe8 | 145 | #define DEF_IDLE_INTERVAL 5 /* 5 secs */ |
bba681cb | 146 | |
75ab4cb8 JK |
147 | struct cp_control { |
148 | int reason; | |
4b2fecc8 JK |
149 | __u64 trim_start; |
150 | __u64 trim_end; | |
151 | __u64 trim_minlen; | |
152 | __u64 trimmed; | |
75ab4cb8 JK |
153 | }; |
154 | ||
662befda | 155 | /* |
81c1a0f1 | 156 | * For CP/NAT/SIT/SSA readahead |
662befda CY |
157 | */ |
158 | enum { | |
159 | META_CP, | |
160 | META_NAT, | |
81c1a0f1 | 161 | META_SIT, |
4c521f49 JK |
162 | META_SSA, |
163 | META_POR, | |
662befda CY |
164 | }; |
165 | ||
6451e041 JK |
166 | /* for the list of ino */ |
167 | enum { | |
168 | ORPHAN_INO, /* for orphan ino list */ | |
fff04f90 JK |
169 | APPEND_INO, /* for append ino list */ |
170 | UPDATE_INO, /* for update ino list */ | |
6451e041 JK |
171 | MAX_INO_ENTRY, /* max. list */ |
172 | }; | |
173 | ||
174 | struct ino_entry { | |
39a53e0c JK |
175 | struct list_head list; /* list head */ |
176 | nid_t ino; /* inode number */ | |
177 | }; | |
178 | ||
2710fd7e | 179 | /* for the list of inodes to be GCed */ |
06292073 | 180 | struct inode_entry { |
39a53e0c JK |
181 | struct list_head list; /* list head */ |
182 | struct inode *inode; /* vfs inode pointer */ | |
183 | }; | |
184 | ||
a7eeb823 | 185 | /* for the bitmap indicate blocks to be discarded */ |
7fd9e544 JK |
186 | struct discard_entry { |
187 | struct list_head list; /* list head */ | |
a7eeb823 CY |
188 | block_t start_blkaddr; /* start blockaddr of current segment */ |
189 | unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ | |
7fd9e544 JK |
190 | }; |
191 | ||
15469963 JK |
192 | enum { |
193 | D_PREP, | |
194 | D_SUBMIT, | |
195 | D_DONE, | |
196 | }; | |
197 | ||
b01a9201 JK |
198 | struct discard_cmd { |
199 | struct list_head list; /* command list */ | |
200 | struct completion wait; /* compleation */ | |
c81abe34 | 201 | struct block_device *bdev; /* bdev */ |
b01a9201 | 202 | block_t lstart; /* logical start address */ |
c81abe34 | 203 | block_t start; /* actual start address in dev */ |
b01a9201 | 204 | block_t len; /* length */ |
15469963 | 205 | int state; /* state */ |
c81abe34 | 206 | int error; /* bio error */ |
275b66b0 CY |
207 | }; |
208 | ||
0b54fb84 | 209 | struct discard_cmd_control { |
15469963 | 210 | struct task_struct *f2fs_issue_discard; /* discard thread */ |
0b54fb84 JK |
211 | struct list_head discard_entry_list; /* 4KB discard entry list */ |
212 | int nr_discards; /* # of discards in the list */ | |
22d375dd CY |
213 | struct list_head discard_pend_list; /* store pending entries */ |
214 | struct list_head discard_wait_list; /* store on-flushing entries */ | |
15469963 JK |
215 | wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ |
216 | struct mutex cmd_lock; | |
0b54fb84 | 217 | int max_discards; /* max. discards to be issued */ |
8b8dd65f CY |
218 | atomic_t issued_discard; /* # of issued discard */ |
219 | atomic_t issing_discard; /* # of issing discard */ | |
5f32366a | 220 | atomic_t discard_cmd_cnt; /* # of cached cmd count */ |
275b66b0 CY |
221 | }; |
222 | ||
39a53e0c JK |
223 | /* for the list of fsync inodes, used only during recovery */ |
224 | struct fsync_inode_entry { | |
225 | struct list_head list; /* list head */ | |
226 | struct inode *inode; /* vfs inode pointer */ | |
c52e1b10 JK |
227 | block_t blkaddr; /* block address locating the last fsync */ |
228 | block_t last_dentry; /* block address locating the last dentry */ | |
39a53e0c JK |
229 | }; |
230 | ||
68afcf2d TK |
231 | #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) |
232 | #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) | |
39a53e0c | 233 | |
68afcf2d TK |
234 | #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) |
235 | #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) | |
236 | #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) | |
237 | #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) | |
39a53e0c | 238 | |
dfc08a12 CY |
239 | #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) |
240 | #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) | |
309cc2b6 | 241 | |
dfc08a12 | 242 | static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) |
39a53e0c | 243 | { |
dfc08a12 | 244 | int before = nats_in_cursum(journal); |
cac5a3d8 | 245 | |
dfc08a12 | 246 | journal->n_nats = cpu_to_le16(before + i); |
39a53e0c JK |
247 | return before; |
248 | } | |
249 | ||
dfc08a12 | 250 | static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) |
39a53e0c | 251 | { |
dfc08a12 | 252 | int before = sits_in_cursum(journal); |
cac5a3d8 | 253 | |
dfc08a12 | 254 | journal->n_sits = cpu_to_le16(before + i); |
39a53e0c JK |
255 | return before; |
256 | } | |
257 | ||
dfc08a12 CY |
258 | static inline bool __has_cursum_space(struct f2fs_journal *journal, |
259 | int size, int type) | |
184a5cd2 CY |
260 | { |
261 | if (type == NAT_JOURNAL) | |
dfc08a12 CY |
262 | return size <= MAX_NAT_JENTRIES(journal); |
263 | return size <= MAX_SIT_JENTRIES(journal); | |
184a5cd2 CY |
264 | } |
265 | ||
e9750824 NJ |
266 | /* |
267 | * ioctl commands | |
268 | */ | |
88b88a66 JK |
269 | #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS |
270 | #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS | |
d49f3e89 | 271 | #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION |
88b88a66 JK |
272 | |
273 | #define F2FS_IOCTL_MAGIC 0xf5 | |
274 | #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) | |
275 | #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) | |
02a1335f | 276 | #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) |
1e84371f JK |
277 | #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) |
278 | #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) | |
c1c1b583 | 279 | #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) |
456b88e4 | 280 | #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) |
d323d005 | 281 | #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) |
4dd6f977 JK |
282 | #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ |
283 | struct f2fs_move_range) | |
e9750824 | 284 | |
0b81d077 JK |
285 | #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY |
286 | #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY | |
287 | #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT | |
f424f664 | 288 | |
1abff93d JK |
289 | /* |
290 | * should be same as XFS_IOC_GOINGDOWN. | |
291 | * Flags for going down operation used by FS_IOC_GOINGDOWN | |
292 | */ | |
293 | #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ | |
294 | #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ | |
295 | #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ | |
296 | #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ | |
c912a829 | 297 | #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ |
1abff93d | 298 | |
e9750824 NJ |
299 | #if defined(__KERNEL__) && defined(CONFIG_COMPAT) |
300 | /* | |
301 | * ioctl commands in 32 bit emulation | |
302 | */ | |
04ef4b62 CY |
303 | #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS |
304 | #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS | |
305 | #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION | |
e9750824 NJ |
306 | #endif |
307 | ||
d323d005 CY |
308 | struct f2fs_defragment { |
309 | u64 start; | |
310 | u64 len; | |
311 | }; | |
312 | ||
4dd6f977 JK |
313 | struct f2fs_move_range { |
314 | u32 dst_fd; /* destination fd */ | |
315 | u64 pos_in; /* start position in src_fd */ | |
316 | u64 pos_out; /* start position in dst_fd */ | |
317 | u64 len; /* size to move */ | |
318 | }; | |
319 | ||
39a53e0c JK |
320 | /* |
321 | * For INODE and NODE manager | |
322 | */ | |
7b3cd7d6 JK |
323 | /* for directory operations */ |
324 | struct f2fs_dentry_ptr { | |
d8c6822a | 325 | struct inode *inode; |
7b3cd7d6 JK |
326 | const void *bitmap; |
327 | struct f2fs_dir_entry *dentry; | |
328 | __u8 (*filename)[F2FS_SLOT_LEN]; | |
329 | int max; | |
330 | }; | |
331 | ||
64c24ecb TK |
332 | static inline void make_dentry_ptr_block(struct inode *inode, |
333 | struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) | |
7b3cd7d6 | 334 | { |
d8c6822a | 335 | d->inode = inode; |
64c24ecb TK |
336 | d->max = NR_DENTRY_IN_BLOCK; |
337 | d->bitmap = &t->dentry_bitmap; | |
338 | d->dentry = t->dentry; | |
339 | d->filename = t->filename; | |
340 | } | |
d8c6822a | 341 | |
64c24ecb TK |
342 | static inline void make_dentry_ptr_inline(struct inode *inode, |
343 | struct f2fs_dentry_ptr *d, struct f2fs_inline_dentry *t) | |
344 | { | |
345 | d->inode = inode; | |
346 | d->max = NR_INLINE_DENTRY; | |
347 | d->bitmap = &t->dentry_bitmap; | |
348 | d->dentry = t->dentry; | |
349 | d->filename = t->filename; | |
7b3cd7d6 JK |
350 | } |
351 | ||
dbe6a5ff JK |
352 | /* |
353 | * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 | |
354 | * as its node offset to distinguish from index node blocks. | |
355 | * But some bits are used to mark the node block. | |
356 | */ | |
357 | #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ | |
358 | >> OFFSET_BIT_SHIFT) | |
266e97a8 JK |
359 | enum { |
360 | ALLOC_NODE, /* allocate a new node page if needed */ | |
361 | LOOKUP_NODE, /* look up a node without readahead */ | |
362 | LOOKUP_NODE_RA, /* | |
363 | * look up a node with readahead called | |
4f4124d0 | 364 | * by get_data_block. |
39a53e0c | 365 | */ |
266e97a8 JK |
366 | }; |
367 | ||
a6db67f0 | 368 | #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ |
39a53e0c | 369 | |
817202d9 CY |
370 | #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ |
371 | ||
13054c54 CY |
372 | /* vector size for gang look-up from extent cache that consists of radix tree */ |
373 | #define EXT_TREE_VEC_SIZE 64 | |
374 | ||
39a53e0c | 375 | /* for in-memory extent cache entry */ |
13054c54 CY |
376 | #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ |
377 | ||
378 | /* number of extent info in extent cache we try to shrink */ | |
379 | #define EXTENT_CACHE_SHRINK_NUMBER 128 | |
c11abd1a | 380 | |
39a53e0c | 381 | struct extent_info { |
13054c54 CY |
382 | unsigned int fofs; /* start offset in a file */ |
383 | u32 blk; /* start block address of the extent */ | |
384 | unsigned int len; /* length of the extent */ | |
385 | }; | |
386 | ||
387 | struct extent_node { | |
388 | struct rb_node rb_node; /* rb node located in rb-tree */ | |
389 | struct list_head list; /* node in global extent list of sbi */ | |
390 | struct extent_info ei; /* extent info */ | |
201ef5e0 | 391 | struct extent_tree *et; /* extent tree pointer */ |
13054c54 CY |
392 | }; |
393 | ||
394 | struct extent_tree { | |
395 | nid_t ino; /* inode number */ | |
396 | struct rb_root root; /* root of extent info rb-tree */ | |
62c8af65 | 397 | struct extent_node *cached_en; /* recently accessed extent node */ |
3e72f721 | 398 | struct extent_info largest; /* largested extent info */ |
137d09f0 | 399 | struct list_head list; /* to be used by sbi->zombie_list */ |
13054c54 | 400 | rwlock_t lock; /* protect extent info rb-tree */ |
68e35385 | 401 | atomic_t node_cnt; /* # of extent node in rb-tree*/ |
39a53e0c JK |
402 | }; |
403 | ||
003a3e1d JK |
404 | /* |
405 | * This structure is taken from ext4_map_blocks. | |
406 | * | |
407 | * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). | |
408 | */ | |
409 | #define F2FS_MAP_NEW (1 << BH_New) | |
410 | #define F2FS_MAP_MAPPED (1 << BH_Mapped) | |
7f63eb77 JK |
411 | #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) |
412 | #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ | |
413 | F2FS_MAP_UNWRITTEN) | |
003a3e1d JK |
414 | |
415 | struct f2fs_map_blocks { | |
416 | block_t m_pblk; | |
417 | block_t m_lblk; | |
418 | unsigned int m_len; | |
419 | unsigned int m_flags; | |
da85985c | 420 | pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ |
003a3e1d JK |
421 | }; |
422 | ||
e2b4e2bc CY |
423 | /* for flag in get_data_block */ |
424 | #define F2FS_GET_BLOCK_READ 0 | |
425 | #define F2FS_GET_BLOCK_DIO 1 | |
426 | #define F2FS_GET_BLOCK_FIEMAP 2 | |
427 | #define F2FS_GET_BLOCK_BMAP 3 | |
b439b103 | 428 | #define F2FS_GET_BLOCK_PRE_DIO 4 |
24b84912 | 429 | #define F2FS_GET_BLOCK_PRE_AIO 5 |
e2b4e2bc | 430 | |
39a53e0c JK |
431 | /* |
432 | * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. | |
433 | */ | |
434 | #define FADVISE_COLD_BIT 0x01 | |
354a3399 | 435 | #define FADVISE_LOST_PINO_BIT 0x02 |
cde4de12 | 436 | #define FADVISE_ENCRYPT_BIT 0x04 |
e7d55452 | 437 | #define FADVISE_ENC_NAME_BIT 0x08 |
26787236 | 438 | #define FADVISE_KEEP_SIZE_BIT 0x10 |
39a53e0c | 439 | |
b5492af7 JK |
440 | #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) |
441 | #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) | |
442 | #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) | |
443 | #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) | |
444 | #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) | |
445 | #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) | |
cde4de12 JK |
446 | #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) |
447 | #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) | |
448 | #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) | |
e7d55452 JK |
449 | #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) |
450 | #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) | |
26787236 JK |
451 | #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) |
452 | #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) | |
cde4de12 | 453 | |
ab9fa662 JK |
454 | #define DEF_DIR_LEVEL 0 |
455 | ||
39a53e0c JK |
456 | struct f2fs_inode_info { |
457 | struct inode vfs_inode; /* serve a vfs inode */ | |
458 | unsigned long i_flags; /* keep an inode flags for ioctl */ | |
459 | unsigned char i_advise; /* use to give file attribute hints */ | |
38431545 | 460 | unsigned char i_dir_level; /* use for dentry level for large dir */ |
39a53e0c | 461 | unsigned int i_current_depth; /* use only in directory structure */ |
6666e6aa | 462 | unsigned int i_pino; /* parent inode number */ |
39a53e0c JK |
463 | umode_t i_acl_mode; /* keep file acl mode temporarily */ |
464 | ||
465 | /* Use below internally in f2fs*/ | |
466 | unsigned long flags; /* use to pass per-file flags */ | |
d928bfbf | 467 | struct rw_semaphore i_sem; /* protect fi info */ |
204706c7 | 468 | atomic_t dirty_pages; /* # of dirty pages */ |
39a53e0c JK |
469 | f2fs_hash_t chash; /* hash value of given file name */ |
470 | unsigned int clevel; /* maximum level of given file name */ | |
88c5c13a | 471 | struct task_struct *task; /* lookup and create consistency */ |
39a53e0c | 472 | nid_t i_xattr_nid; /* node id that contains xattrs */ |
26de9b11 | 473 | loff_t last_disk_size; /* lastly written file size */ |
88b88a66 | 474 | |
0f18b462 JK |
475 | struct list_head dirty_list; /* dirty list for dirs and files */ |
476 | struct list_head gdirty_list; /* linked in global dirty list */ | |
88b88a66 JK |
477 | struct list_head inmem_pages; /* inmemory pages managed by f2fs */ |
478 | struct mutex inmem_lock; /* lock for inmemory pages */ | |
3e72f721 | 479 | struct extent_tree *extent_tree; /* cached extent_tree entry */ |
82e0a5aa | 480 | struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ |
39a53e0c JK |
481 | }; |
482 | ||
483 | static inline void get_extent_info(struct extent_info *ext, | |
bd933d4f | 484 | struct f2fs_extent *i_ext) |
39a53e0c | 485 | { |
bd933d4f CY |
486 | ext->fofs = le32_to_cpu(i_ext->fofs); |
487 | ext->blk = le32_to_cpu(i_ext->blk); | |
488 | ext->len = le32_to_cpu(i_ext->len); | |
39a53e0c JK |
489 | } |
490 | ||
491 | static inline void set_raw_extent(struct extent_info *ext, | |
492 | struct f2fs_extent *i_ext) | |
493 | { | |
39a53e0c | 494 | i_ext->fofs = cpu_to_le32(ext->fofs); |
4d0b0bd4 | 495 | i_ext->blk = cpu_to_le32(ext->blk); |
39a53e0c | 496 | i_ext->len = cpu_to_le32(ext->len); |
39a53e0c JK |
497 | } |
498 | ||
429511cd CY |
499 | static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, |
500 | u32 blk, unsigned int len) | |
501 | { | |
502 | ei->fofs = fofs; | |
503 | ei->blk = blk; | |
504 | ei->len = len; | |
505 | } | |
506 | ||
507 | static inline bool __is_extent_mergeable(struct extent_info *back, | |
508 | struct extent_info *front) | |
509 | { | |
510 | return (back->fofs + back->len == front->fofs && | |
511 | back->blk + back->len == front->blk); | |
512 | } | |
513 | ||
514 | static inline bool __is_back_mergeable(struct extent_info *cur, | |
515 | struct extent_info *back) | |
516 | { | |
517 | return __is_extent_mergeable(back, cur); | |
518 | } | |
519 | ||
520 | static inline bool __is_front_mergeable(struct extent_info *cur, | |
521 | struct extent_info *front) | |
522 | { | |
523 | return __is_extent_mergeable(cur, front); | |
524 | } | |
525 | ||
cac5a3d8 | 526 | extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); |
205b9822 JK |
527 | static inline void __try_update_largest_extent(struct inode *inode, |
528 | struct extent_tree *et, struct extent_node *en) | |
4abd3f5a | 529 | { |
205b9822 | 530 | if (en->ei.len > et->largest.len) { |
4abd3f5a | 531 | et->largest = en->ei; |
7c45729a | 532 | f2fs_mark_inode_dirty_sync(inode, true); |
205b9822 | 533 | } |
4abd3f5a CY |
534 | } |
535 | ||
b8559dc2 CY |
536 | enum nid_list { |
537 | FREE_NID_LIST, | |
538 | ALLOC_NID_LIST, | |
539 | MAX_NID_LIST, | |
540 | }; | |
541 | ||
39a53e0c JK |
542 | struct f2fs_nm_info { |
543 | block_t nat_blkaddr; /* base disk address of NAT */ | |
544 | nid_t max_nid; /* maximum possible node ids */ | |
04d47e67 | 545 | nid_t available_nids; /* # of available node ids */ |
39a53e0c | 546 | nid_t next_scan_nid; /* the next nid to be scanned */ |
cdfc41c1 | 547 | unsigned int ram_thresh; /* control the memory footprint */ |
ea1a29a0 | 548 | unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ |
2304cb0c | 549 | unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ |
39a53e0c JK |
550 | |
551 | /* NAT cache management */ | |
552 | struct radix_tree_root nat_root;/* root of the nat entry cache */ | |
309cc2b6 | 553 | struct radix_tree_root nat_set_root;/* root of the nat set cache */ |
b873b798 | 554 | struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ |
39a53e0c | 555 | struct list_head nat_entries; /* cached nat entry list (clean) */ |
309cc2b6 | 556 | unsigned int nat_cnt; /* the # of cached nat entries */ |
aec71382 | 557 | unsigned int dirty_nat_cnt; /* total num of nat entries in set */ |
22ad0b6a | 558 | unsigned int nat_blocks; /* # of nat blocks */ |
39a53e0c JK |
559 | |
560 | /* free node ids management */ | |
8a7ed66a | 561 | struct radix_tree_root free_nid_root;/* root of the free_nid cache */ |
b8559dc2 CY |
562 | struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ |
563 | unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ | |
564 | spinlock_t nid_list_lock; /* protect nid lists ops */ | |
39a53e0c | 565 | struct mutex build_lock; /* lock for build free nids */ |
4ac91242 CY |
566 | unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; |
567 | unsigned char *nat_block_bitmap; | |
586d1492 | 568 | unsigned short *free_nid_count; /* free nid count of NAT block */ |
39a53e0c JK |
569 | |
570 | /* for checkpoint */ | |
571 | char *nat_bitmap; /* NAT bitmap pointer */ | |
22ad0b6a JK |
572 | |
573 | unsigned int nat_bits_blocks; /* # of nat bits blocks */ | |
574 | unsigned char *nat_bits; /* NAT bits blocks */ | |
575 | unsigned char *full_nat_bits; /* full NAT pages */ | |
576 | unsigned char *empty_nat_bits; /* empty NAT pages */ | |
599a09b2 CY |
577 | #ifdef CONFIG_F2FS_CHECK_FS |
578 | char *nat_bitmap_mir; /* NAT bitmap mirror */ | |
579 | #endif | |
39a53e0c JK |
580 | int bitmap_size; /* bitmap size */ |
581 | }; | |
582 | ||
583 | /* | |
584 | * this structure is used as one of function parameters. | |
585 | * all the information are dedicated to a given direct node block determined | |
586 | * by the data offset in a file. | |
587 | */ | |
588 | struct dnode_of_data { | |
589 | struct inode *inode; /* vfs inode pointer */ | |
590 | struct page *inode_page; /* its inode page, NULL is possible */ | |
591 | struct page *node_page; /* cached direct node page */ | |
592 | nid_t nid; /* node id of the direct node block */ | |
593 | unsigned int ofs_in_node; /* data offset in the node page */ | |
594 | bool inode_page_locked; /* inode page is locked or not */ | |
93bae099 | 595 | bool node_changed; /* is node block changed */ |
3cf45747 CY |
596 | char cur_level; /* level of hole node page */ |
597 | char max_level; /* level of current page located */ | |
39a53e0c JK |
598 | block_t data_blkaddr; /* block address of the node block */ |
599 | }; | |
600 | ||
601 | static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, | |
602 | struct page *ipage, struct page *npage, nid_t nid) | |
603 | { | |
d66d1f76 | 604 | memset(dn, 0, sizeof(*dn)); |
39a53e0c JK |
605 | dn->inode = inode; |
606 | dn->inode_page = ipage; | |
607 | dn->node_page = npage; | |
608 | dn->nid = nid; | |
39a53e0c JK |
609 | } |
610 | ||
611 | /* | |
612 | * For SIT manager | |
613 | * | |
614 | * By default, there are 6 active log areas across the whole main area. | |
615 | * When considering hot and cold data separation to reduce cleaning overhead, | |
616 | * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, | |
617 | * respectively. | |
618 | * In the current design, you should not change the numbers intentionally. | |
619 | * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 | |
620 | * logs individually according to the underlying devices. (default: 6) | |
621 | * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for | |
622 | * data and 8 for node logs. | |
623 | */ | |
624 | #define NR_CURSEG_DATA_TYPE (3) | |
625 | #define NR_CURSEG_NODE_TYPE (3) | |
626 | #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) | |
627 | ||
628 | enum { | |
629 | CURSEG_HOT_DATA = 0, /* directory entry blocks */ | |
630 | CURSEG_WARM_DATA, /* data blocks */ | |
631 | CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ | |
632 | CURSEG_HOT_NODE, /* direct node blocks of directory files */ | |
633 | CURSEG_WARM_NODE, /* direct node blocks of normal files */ | |
634 | CURSEG_COLD_NODE, /* indirect node blocks */ | |
38aa0889 | 635 | NO_CHECK_TYPE, |
39a53e0c JK |
636 | }; |
637 | ||
6b4afdd7 | 638 | struct flush_cmd { |
6b4afdd7 | 639 | struct completion wait; |
721bd4d5 | 640 | struct llist_node llnode; |
6b4afdd7 JK |
641 | int ret; |
642 | }; | |
643 | ||
a688b9d9 GZ |
644 | struct flush_cmd_control { |
645 | struct task_struct *f2fs_issue_flush; /* flush thread */ | |
646 | wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ | |
8b8dd65f CY |
647 | atomic_t issued_flush; /* # of issued flushes */ |
648 | atomic_t issing_flush; /* # of issing flushes */ | |
721bd4d5 GZ |
649 | struct llist_head issue_list; /* list for command issue */ |
650 | struct llist_node *dispatch_list; /* list for command dispatch */ | |
a688b9d9 GZ |
651 | }; |
652 | ||
39a53e0c JK |
653 | struct f2fs_sm_info { |
654 | struct sit_info *sit_info; /* whole segment information */ | |
655 | struct free_segmap_info *free_info; /* free segment information */ | |
656 | struct dirty_seglist_info *dirty_info; /* dirty segment information */ | |
657 | struct curseg_info *curseg_array; /* active segment information */ | |
658 | ||
39a53e0c JK |
659 | block_t seg0_blkaddr; /* block address of 0'th segment */ |
660 | block_t main_blkaddr; /* start block address of main area */ | |
661 | block_t ssa_blkaddr; /* start block address of SSA area */ | |
662 | ||
663 | unsigned int segment_count; /* total # of segments */ | |
664 | unsigned int main_segments; /* # of segments in main area */ | |
665 | unsigned int reserved_segments; /* # of reserved segments */ | |
666 | unsigned int ovp_segments; /* # of overprovision segments */ | |
81eb8d6e JK |
667 | |
668 | /* a threshold to reclaim prefree segments */ | |
669 | unsigned int rec_prefree_segments; | |
7fd9e544 | 670 | |
bba681cb JK |
671 | /* for batched trimming */ |
672 | unsigned int trim_sections; /* # of sections to trim */ | |
673 | ||
184a5cd2 CY |
674 | struct list_head sit_entry_set; /* sit entry set list */ |
675 | ||
216fbd64 JK |
676 | unsigned int ipu_policy; /* in-place-update policy */ |
677 | unsigned int min_ipu_util; /* in-place-update threshold */ | |
c1ce1b02 | 678 | unsigned int min_fsync_blocks; /* threshold for fsync */ |
ef095d19 | 679 | unsigned int min_hot_blocks; /* threshold for hot block allocation */ |
6b4afdd7 JK |
680 | |
681 | /* for flush command control */ | |
b01a9201 | 682 | struct flush_cmd_control *fcc_info; |
a688b9d9 | 683 | |
0b54fb84 JK |
684 | /* for discard command control */ |
685 | struct discard_cmd_control *dcc_info; | |
39a53e0c JK |
686 | }; |
687 | ||
39a53e0c JK |
688 | /* |
689 | * For superblock | |
690 | */ | |
691 | /* | |
692 | * COUNT_TYPE for monitoring | |
693 | * | |
694 | * f2fs monitors the number of several block types such as on-writeback, | |
695 | * dirty dentry blocks, dirty node blocks, and dirty meta blocks. | |
696 | */ | |
36951b38 | 697 | #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) |
39a53e0c | 698 | enum count_type { |
39a53e0c | 699 | F2FS_DIRTY_DENTS, |
c227f912 | 700 | F2FS_DIRTY_DATA, |
39a53e0c JK |
701 | F2FS_DIRTY_NODES, |
702 | F2FS_DIRTY_META, | |
8dcf2ff7 | 703 | F2FS_INMEM_PAGES, |
0f18b462 | 704 | F2FS_DIRTY_IMETA, |
36951b38 CY |
705 | F2FS_WB_CP_DATA, |
706 | F2FS_WB_DATA, | |
39a53e0c JK |
707 | NR_COUNT_TYPE, |
708 | }; | |
709 | ||
39a53e0c | 710 | /* |
e1c42045 | 711 | * The below are the page types of bios used in submit_bio(). |
39a53e0c JK |
712 | * The available types are: |
713 | * DATA User data pages. It operates as async mode. | |
714 | * NODE Node pages. It operates as async mode. | |
715 | * META FS metadata pages such as SIT, NAT, CP. | |
716 | * NR_PAGE_TYPE The number of page types. | |
717 | * META_FLUSH Make sure the previous pages are written | |
718 | * with waiting the bio's completion | |
719 | * ... Only can be used with META. | |
720 | */ | |
7d5e5109 | 721 | #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) |
39a53e0c JK |
722 | enum page_type { |
723 | DATA, | |
724 | NODE, | |
725 | META, | |
726 | NR_PAGE_TYPE, | |
727 | META_FLUSH, | |
8ce67cb0 JK |
728 | INMEM, /* the below types are used by tracepoints only. */ |
729 | INMEM_DROP, | |
8c242db9 | 730 | INMEM_INVALIDATE, |
28bc106b | 731 | INMEM_REVOKE, |
8ce67cb0 JK |
732 | IPU, |
733 | OPU, | |
39a53e0c JK |
734 | }; |
735 | ||
458e6197 | 736 | struct f2fs_io_info { |
05ca3632 | 737 | struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ |
7e8f2308 | 738 | enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ |
04d328de | 739 | int op; /* contains REQ_OP_ */ |
ef295ecf | 740 | int op_flags; /* req_flag_bits */ |
7a9d7548 | 741 | block_t new_blkaddr; /* new block address to be written */ |
28bc106b | 742 | block_t old_blkaddr; /* old block address before Cow */ |
05ca3632 | 743 | struct page *page; /* page to be written */ |
4375a336 | 744 | struct page *encrypted_page; /* encrypted page */ |
d68f735b | 745 | bool submitted; /* indicate IO submission */ |
458e6197 JK |
746 | }; |
747 | ||
68afcf2d | 748 | #define is_read_io(rw) ((rw) == READ) |
1ff7bd3b | 749 | struct f2fs_bio_info { |
458e6197 | 750 | struct f2fs_sb_info *sbi; /* f2fs superblock */ |
1ff7bd3b JK |
751 | struct bio *bio; /* bios to merge */ |
752 | sector_t last_block_in_bio; /* last block number */ | |
458e6197 | 753 | struct f2fs_io_info fio; /* store buffered io info. */ |
df0f8dc0 | 754 | struct rw_semaphore io_rwsem; /* blocking op for bio */ |
1ff7bd3b JK |
755 | }; |
756 | ||
3c62be17 JK |
757 | #define FDEV(i) (sbi->devs[i]) |
758 | #define RDEV(i) (raw_super->devs[i]) | |
759 | struct f2fs_dev_info { | |
760 | struct block_device *bdev; | |
761 | char path[MAX_PATH_LEN]; | |
762 | unsigned int total_segments; | |
763 | block_t start_blk; | |
764 | block_t end_blk; | |
765 | #ifdef CONFIG_BLK_DEV_ZONED | |
766 | unsigned int nr_blkz; /* Total number of zones */ | |
767 | u8 *blkz_type; /* Array of zones type */ | |
768 | #endif | |
769 | }; | |
770 | ||
c227f912 CY |
771 | enum inode_type { |
772 | DIR_INODE, /* for dirty dir inode */ | |
773 | FILE_INODE, /* for dirty regular/symlink inode */ | |
0f18b462 | 774 | DIRTY_META, /* for all dirtied inode metadata */ |
c227f912 CY |
775 | NR_INODE_TYPE, |
776 | }; | |
777 | ||
67298804 CY |
778 | /* for inner inode cache management */ |
779 | struct inode_management { | |
780 | struct radix_tree_root ino_root; /* ino entry array */ | |
781 | spinlock_t ino_lock; /* for ino entry lock */ | |
782 | struct list_head ino_list; /* inode list head */ | |
783 | unsigned long ino_num; /* number of entries */ | |
784 | }; | |
785 | ||
caf0047e CY |
786 | /* For s_flag in struct f2fs_sb_info */ |
787 | enum { | |
788 | SBI_IS_DIRTY, /* dirty flag for checkpoint */ | |
789 | SBI_IS_CLOSE, /* specify unmounting */ | |
790 | SBI_NEED_FSCK, /* need fsck.f2fs to fix */ | |
791 | SBI_POR_DOING, /* recovery is doing or not */ | |
df728b0f | 792 | SBI_NEED_SB_WRITE, /* need to recover superblock */ |
bbf156f7 | 793 | SBI_NEED_CP, /* need to checkpoint */ |
caf0047e CY |
794 | }; |
795 | ||
6beceb54 JK |
796 | enum { |
797 | CP_TIME, | |
d0239e1b | 798 | REQ_TIME, |
6beceb54 JK |
799 | MAX_TIME, |
800 | }; | |
801 | ||
39a53e0c JK |
802 | struct f2fs_sb_info { |
803 | struct super_block *sb; /* pointer to VFS super block */ | |
5e176d54 | 804 | struct proc_dir_entry *s_proc; /* proc entry */ |
39a53e0c | 805 | struct f2fs_super_block *raw_super; /* raw super block pointer */ |
e8240f65 | 806 | int valid_super_block; /* valid super block no */ |
fadb2fb8 | 807 | unsigned long s_flag; /* flags for sbi */ |
39a53e0c | 808 | |
178053e2 | 809 | #ifdef CONFIG_BLK_DEV_ZONED |
178053e2 DLM |
810 | unsigned int blocks_per_blkz; /* F2FS blocks per zone */ |
811 | unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ | |
178053e2 DLM |
812 | #endif |
813 | ||
39a53e0c JK |
814 | /* for node-related operations */ |
815 | struct f2fs_nm_info *nm_info; /* node manager */ | |
816 | struct inode *node_inode; /* cache node blocks */ | |
817 | ||
818 | /* for segment-related operations */ | |
819 | struct f2fs_sm_info *sm_info; /* segment manager */ | |
1ff7bd3b JK |
820 | |
821 | /* for bio operations */ | |
924b720b | 822 | struct f2fs_bio_info read_io; /* for read bios */ |
1ff7bd3b | 823 | struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ |
7dfeaa32 | 824 | struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ |
0a595eba JK |
825 | int write_io_size_bits; /* Write IO size bits */ |
826 | mempool_t *write_io_dummy; /* Dummy pages */ | |
39a53e0c JK |
827 | |
828 | /* for checkpoint */ | |
829 | struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ | |
8508e44a | 830 | int cur_cp_pack; /* remain current cp pack */ |
aaec2b1d | 831 | spinlock_t cp_lock; /* for flag in ckpt */ |
39a53e0c | 832 | struct inode *meta_inode; /* cache meta blocks */ |
39936837 | 833 | struct mutex cp_mutex; /* checkpoint procedure lock */ |
b873b798 | 834 | struct rw_semaphore cp_rwsem; /* blocking FS operations */ |
b3582c68 | 835 | struct rw_semaphore node_write; /* locking node writes */ |
59c9081b | 836 | struct rw_semaphore node_change; /* locking node change */ |
fb51b5ef | 837 | wait_queue_head_t cp_wait; |
6beceb54 JK |
838 | unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ |
839 | long interval_time[MAX_TIME]; /* to store thresholds */ | |
39a53e0c | 840 | |
67298804 | 841 | struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ |
6451e041 JK |
842 | |
843 | /* for orphan inode, use 0'th array */ | |
0d47c1ad | 844 | unsigned int max_orphans; /* max orphan inodes */ |
39a53e0c | 845 | |
c227f912 CY |
846 | /* for inode management */ |
847 | struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ | |
848 | spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ | |
39a53e0c | 849 | |
13054c54 CY |
850 | /* for extent tree cache */ |
851 | struct radix_tree_root extent_tree_root;/* cache extent cache entries */ | |
5e8256ac | 852 | struct mutex extent_tree_lock; /* locking extent radix tree */ |
13054c54 CY |
853 | struct list_head extent_list; /* lru list for shrinker */ |
854 | spinlock_t extent_lock; /* locking extent lru list */ | |
7441ccef | 855 | atomic_t total_ext_tree; /* extent tree count */ |
137d09f0 | 856 | struct list_head zombie_list; /* extent zombie tree list */ |
74fd8d99 | 857 | atomic_t total_zombie_tree; /* extent zombie tree count */ |
13054c54 CY |
858 | atomic_t total_ext_node; /* extent info count */ |
859 | ||
e1c42045 | 860 | /* basic filesystem units */ |
39a53e0c JK |
861 | unsigned int log_sectors_per_block; /* log2 sectors per block */ |
862 | unsigned int log_blocksize; /* log2 block size */ | |
863 | unsigned int blocksize; /* block size */ | |
864 | unsigned int root_ino_num; /* root inode number*/ | |
865 | unsigned int node_ino_num; /* node inode number*/ | |
866 | unsigned int meta_ino_num; /* meta inode number*/ | |
867 | unsigned int log_blocks_per_seg; /* log2 blocks per segment */ | |
868 | unsigned int blocks_per_seg; /* blocks per segment */ | |
869 | unsigned int segs_per_sec; /* segments per section */ | |
870 | unsigned int secs_per_zone; /* sections per zone */ | |
871 | unsigned int total_sections; /* total section count */ | |
872 | unsigned int total_node_count; /* total node block count */ | |
873 | unsigned int total_valid_node_count; /* valid node block count */ | |
e0afc4d6 | 874 | loff_t max_file_blocks; /* max block index of file */ |
39a53e0c | 875 | int active_logs; /* # of active logs */ |
ab9fa662 | 876 | int dir_level; /* directory level */ |
39a53e0c JK |
877 | |
878 | block_t user_block_count; /* # of user blocks */ | |
879 | block_t total_valid_block_count; /* # of valid blocks */ | |
a66cdd98 | 880 | block_t discard_blks; /* discard command candidats */ |
39a53e0c JK |
881 | block_t last_valid_block_count; /* for recovery */ |
882 | u32 s_next_generation; /* for NFS support */ | |
523be8a6 JK |
883 | |
884 | /* # of pages, see count_type */ | |
35782b23 | 885 | atomic_t nr_pages[NR_COUNT_TYPE]; |
41382ec4 JK |
886 | /* # of allocated blocks */ |
887 | struct percpu_counter alloc_valid_block_count; | |
39a53e0c | 888 | |
687de7f1 JK |
889 | /* writeback control */ |
890 | atomic_t wb_sync_req; /* count # of WB_SYNC threads */ | |
891 | ||
513c5f37 JK |
892 | /* valid inode count */ |
893 | struct percpu_counter total_valid_inode_count; | |
894 | ||
39a53e0c JK |
895 | struct f2fs_mount_info mount_opt; /* mount options */ |
896 | ||
897 | /* for cleaning operations */ | |
898 | struct mutex gc_mutex; /* mutex for GC */ | |
899 | struct f2fs_gc_kthread *gc_thread; /* GC thread */ | |
5ec4e49f | 900 | unsigned int cur_victim_sec; /* current victim section num */ |
39a53e0c | 901 | |
e93b9865 HP |
902 | /* threshold for converting bg victims for fg */ |
903 | u64 fggc_threshold; | |
904 | ||
b1c57c1c JK |
905 | /* maximum # of trials to find a victim segment for SSR and GC */ |
906 | unsigned int max_victim_search; | |
907 | ||
39a53e0c JK |
908 | /* |
909 | * for stat information. | |
910 | * one is for the LFS mode, and the other is for the SSR mode. | |
911 | */ | |
35b09d82 | 912 | #ifdef CONFIG_F2FS_STAT_FS |
39a53e0c JK |
913 | struct f2fs_stat_info *stat_info; /* FS status information */ |
914 | unsigned int segment_count[2]; /* # of allocated segments */ | |
915 | unsigned int block_count[2]; /* # of allocated blocks */ | |
b9a2c252 | 916 | atomic_t inplace_count; /* # of inplace update */ |
5b7ee374 CY |
917 | atomic64_t total_hit_ext; /* # of lookup extent cache */ |
918 | atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ | |
919 | atomic64_t read_hit_largest; /* # of hit largest extent node */ | |
920 | atomic64_t read_hit_cached; /* # of hit cached extent node */ | |
d5e8f6c9 | 921 | atomic_t inline_xattr; /* # of inline_xattr inodes */ |
03e14d52 CY |
922 | atomic_t inline_inode; /* # of inline_data inodes */ |
923 | atomic_t inline_dir; /* # of inline_dentry inodes */ | |
26a28a0c | 924 | atomic_t aw_cnt; /* # of atomic writes */ |
648d50ba | 925 | atomic_t vw_cnt; /* # of volatile writes */ |
26a28a0c | 926 | atomic_t max_aw_cnt; /* max # of atomic writes */ |
648d50ba | 927 | atomic_t max_vw_cnt; /* max # of volatile writes */ |
39a53e0c | 928 | int bg_gc; /* background gc calls */ |
33fbd510 | 929 | unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ |
35b09d82 NJ |
930 | #endif |
931 | unsigned int last_victim[2]; /* last victim segment # */ | |
39a53e0c | 932 | spinlock_t stat_lock; /* lock for stat operations */ |
b59d0bae NJ |
933 | |
934 | /* For sysfs suppport */ | |
935 | struct kobject s_kobj; | |
936 | struct completion s_kobj_unregister; | |
2658e50d JK |
937 | |
938 | /* For shrinker support */ | |
939 | struct list_head s_list; | |
3c62be17 JK |
940 | int s_ndevs; /* number of devices */ |
941 | struct f2fs_dev_info *devs; /* for device list */ | |
2658e50d JK |
942 | struct mutex umount_mutex; |
943 | unsigned int shrinker_run_no; | |
8f1dbbbb SL |
944 | |
945 | /* For write statistics */ | |
946 | u64 sectors_written_start; | |
947 | u64 kbytes_written; | |
43b6573b KM |
948 | |
949 | /* Reference to checksum algorithm driver via cryptoapi */ | |
950 | struct crypto_shash *s_chksum_driver; | |
1ecc0c5c CY |
951 | |
952 | /* For fault injection */ | |
953 | #ifdef CONFIG_F2FS_FAULT_INJECTION | |
954 | struct f2fs_fault_info fault_info; | |
955 | #endif | |
39a53e0c JK |
956 | }; |
957 | ||
1ecc0c5c | 958 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
55523519 CY |
959 | #define f2fs_show_injection_info(type) \ |
960 | printk("%sF2FS-fs : inject %s in %s of %pF\n", \ | |
961 | KERN_INFO, fault_name[type], \ | |
962 | __func__, __builtin_return_address(0)) | |
1ecc0c5c CY |
963 | static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) |
964 | { | |
965 | struct f2fs_fault_info *ffi = &sbi->fault_info; | |
966 | ||
967 | if (!ffi->inject_rate) | |
968 | return false; | |
969 | ||
970 | if (!IS_FAULT_SET(ffi, type)) | |
971 | return false; | |
972 | ||
973 | atomic_inc(&ffi->inject_ops); | |
974 | if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { | |
975 | atomic_set(&ffi->inject_ops, 0); | |
1ecc0c5c CY |
976 | return true; |
977 | } | |
978 | return false; | |
979 | } | |
980 | #endif | |
981 | ||
8f1dbbbb SL |
982 | /* For write statistics. Suppose sector size is 512 bytes, |
983 | * and the return value is in kbytes. s is of struct f2fs_sb_info. | |
984 | */ | |
985 | #define BD_PART_WRITTEN(s) \ | |
68afcf2d TK |
986 | (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ |
987 | (s)->sectors_written_start) >> 1) | |
8f1dbbbb | 988 | |
6beceb54 JK |
989 | static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) |
990 | { | |
991 | sbi->last_time[type] = jiffies; | |
992 | } | |
993 | ||
994 | static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) | |
995 | { | |
996 | struct timespec ts = {sbi->interval_time[type], 0}; | |
997 | unsigned long interval = timespec_to_jiffies(&ts); | |
998 | ||
999 | return time_after(jiffies, sbi->last_time[type] + interval); | |
1000 | } | |
1001 | ||
d0239e1b JK |
1002 | static inline bool is_idle(struct f2fs_sb_info *sbi) |
1003 | { | |
1004 | struct block_device *bdev = sbi->sb->s_bdev; | |
1005 | struct request_queue *q = bdev_get_queue(bdev); | |
1006 | struct request_list *rl = &q->root_rl; | |
1007 | ||
1008 | if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) | |
1009 | return 0; | |
1010 | ||
1011 | return f2fs_time_over(sbi, REQ_TIME); | |
1012 | } | |
1013 | ||
39a53e0c JK |
1014 | /* |
1015 | * Inline functions | |
1016 | */ | |
43b6573b KM |
1017 | static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, |
1018 | unsigned int length) | |
1019 | { | |
1020 | SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); | |
1021 | u32 *ctx = (u32 *)shash_desc_ctx(shash); | |
1022 | int err; | |
1023 | ||
1024 | shash->tfm = sbi->s_chksum_driver; | |
1025 | shash->flags = 0; | |
1026 | *ctx = F2FS_SUPER_MAGIC; | |
1027 | ||
1028 | err = crypto_shash_update(shash, address, length); | |
1029 | BUG_ON(err); | |
1030 | ||
1031 | return *ctx; | |
1032 | } | |
1033 | ||
1034 | static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, | |
1035 | void *buf, size_t buf_size) | |
1036 | { | |
1037 | return f2fs_crc32(sbi, buf, buf_size) == blk_crc; | |
1038 | } | |
1039 | ||
39a53e0c JK |
1040 | static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) |
1041 | { | |
1042 | return container_of(inode, struct f2fs_inode_info, vfs_inode); | |
1043 | } | |
1044 | ||
1045 | static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) | |
1046 | { | |
1047 | return sb->s_fs_info; | |
1048 | } | |
1049 | ||
4081363f JK |
1050 | static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) |
1051 | { | |
1052 | return F2FS_SB(inode->i_sb); | |
1053 | } | |
1054 | ||
1055 | static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) | |
1056 | { | |
1057 | return F2FS_I_SB(mapping->host); | |
1058 | } | |
1059 | ||
1060 | static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) | |
1061 | { | |
1062 | return F2FS_M_SB(page->mapping); | |
1063 | } | |
1064 | ||
39a53e0c JK |
1065 | static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) |
1066 | { | |
1067 | return (struct f2fs_super_block *)(sbi->raw_super); | |
1068 | } | |
1069 | ||
1070 | static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) | |
1071 | { | |
1072 | return (struct f2fs_checkpoint *)(sbi->ckpt); | |
1073 | } | |
1074 | ||
45590710 GZ |
1075 | static inline struct f2fs_node *F2FS_NODE(struct page *page) |
1076 | { | |
1077 | return (struct f2fs_node *)page_address(page); | |
1078 | } | |
1079 | ||
58bfaf44 JK |
1080 | static inline struct f2fs_inode *F2FS_INODE(struct page *page) |
1081 | { | |
1082 | return &((struct f2fs_node *)page_address(page))->i; | |
1083 | } | |
1084 | ||
39a53e0c JK |
1085 | static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) |
1086 | { | |
1087 | return (struct f2fs_nm_info *)(sbi->nm_info); | |
1088 | } | |
1089 | ||
1090 | static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) | |
1091 | { | |
1092 | return (struct f2fs_sm_info *)(sbi->sm_info); | |
1093 | } | |
1094 | ||
1095 | static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) | |
1096 | { | |
1097 | return (struct sit_info *)(SM_I(sbi)->sit_info); | |
1098 | } | |
1099 | ||
1100 | static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) | |
1101 | { | |
1102 | return (struct free_segmap_info *)(SM_I(sbi)->free_info); | |
1103 | } | |
1104 | ||
1105 | static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) | |
1106 | { | |
1107 | return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); | |
1108 | } | |
1109 | ||
9df27d98 GZ |
1110 | static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) |
1111 | { | |
1112 | return sbi->meta_inode->i_mapping; | |
1113 | } | |
1114 | ||
4ef51a8f JK |
1115 | static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) |
1116 | { | |
1117 | return sbi->node_inode->i_mapping; | |
1118 | } | |
1119 | ||
caf0047e CY |
1120 | static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) |
1121 | { | |
fadb2fb8 | 1122 | return test_bit(type, &sbi->s_flag); |
caf0047e CY |
1123 | } |
1124 | ||
1125 | static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) | |
39a53e0c | 1126 | { |
fadb2fb8 | 1127 | set_bit(type, &sbi->s_flag); |
39a53e0c JK |
1128 | } |
1129 | ||
caf0047e | 1130 | static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) |
39a53e0c | 1131 | { |
fadb2fb8 | 1132 | clear_bit(type, &sbi->s_flag); |
39a53e0c JK |
1133 | } |
1134 | ||
d71b5564 JK |
1135 | static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) |
1136 | { | |
1137 | return le64_to_cpu(cp->checkpoint_ver); | |
1138 | } | |
1139 | ||
ced2c7ea KM |
1140 | static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) |
1141 | { | |
1142 | size_t crc_offset = le32_to_cpu(cp->checksum_offset); | |
1143 | return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); | |
1144 | } | |
1145 | ||
aaec2b1d | 1146 | static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) |
25ca923b JK |
1147 | { |
1148 | unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); | |
aaec2b1d | 1149 | |
25ca923b JK |
1150 | return ckpt_flags & f; |
1151 | } | |
1152 | ||
aaec2b1d | 1153 | static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) |
25ca923b | 1154 | { |
aaec2b1d CY |
1155 | return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); |
1156 | } | |
1157 | ||
1158 | static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) | |
1159 | { | |
1160 | unsigned int ckpt_flags; | |
1161 | ||
1162 | ckpt_flags = le32_to_cpu(cp->ckpt_flags); | |
25ca923b JK |
1163 | ckpt_flags |= f; |
1164 | cp->ckpt_flags = cpu_to_le32(ckpt_flags); | |
1165 | } | |
1166 | ||
aaec2b1d | 1167 | static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) |
25ca923b | 1168 | { |
aaec2b1d CY |
1169 | spin_lock(&sbi->cp_lock); |
1170 | __set_ckpt_flags(F2FS_CKPT(sbi), f); | |
1171 | spin_unlock(&sbi->cp_lock); | |
1172 | } | |
1173 | ||
1174 | static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) | |
1175 | { | |
1176 | unsigned int ckpt_flags; | |
1177 | ||
1178 | ckpt_flags = le32_to_cpu(cp->ckpt_flags); | |
25ca923b JK |
1179 | ckpt_flags &= (~f); |
1180 | cp->ckpt_flags = cpu_to_le32(ckpt_flags); | |
1181 | } | |
1182 | ||
aaec2b1d CY |
1183 | static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) |
1184 | { | |
1185 | spin_lock(&sbi->cp_lock); | |
1186 | __clear_ckpt_flags(F2FS_CKPT(sbi), f); | |
1187 | spin_unlock(&sbi->cp_lock); | |
1188 | } | |
1189 | ||
22ad0b6a JK |
1190 | static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) |
1191 | { | |
1192 | set_sbi_flag(sbi, SBI_NEED_FSCK); | |
1193 | ||
1194 | if (lock) | |
1195 | spin_lock(&sbi->cp_lock); | |
1196 | __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); | |
1197 | kfree(NM_I(sbi)->nat_bits); | |
1198 | NM_I(sbi)->nat_bits = NULL; | |
1199 | if (lock) | |
1200 | spin_unlock(&sbi->cp_lock); | |
1201 | } | |
1202 | ||
1203 | static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, | |
1204 | struct cp_control *cpc) | |
1205 | { | |
1206 | bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); | |
1207 | ||
1208 | return (cpc) ? (cpc->reason == CP_UMOUNT) && set : set; | |
1209 | } | |
1210 | ||
e479556b | 1211 | static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) |
39936837 | 1212 | { |
b873b798 | 1213 | down_read(&sbi->cp_rwsem); |
39936837 JK |
1214 | } |
1215 | ||
e479556b | 1216 | static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) |
39a53e0c | 1217 | { |
b873b798 | 1218 | up_read(&sbi->cp_rwsem); |
39a53e0c JK |
1219 | } |
1220 | ||
e479556b | 1221 | static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) |
39a53e0c | 1222 | { |
b873b798 | 1223 | down_write(&sbi->cp_rwsem); |
39936837 JK |
1224 | } |
1225 | ||
e479556b | 1226 | static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) |
39936837 | 1227 | { |
b873b798 | 1228 | up_write(&sbi->cp_rwsem); |
39a53e0c JK |
1229 | } |
1230 | ||
119ee914 JK |
1231 | static inline int __get_cp_reason(struct f2fs_sb_info *sbi) |
1232 | { | |
1233 | int reason = CP_SYNC; | |
1234 | ||
1235 | if (test_opt(sbi, FASTBOOT)) | |
1236 | reason = CP_FASTBOOT; | |
1237 | if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) | |
1238 | reason = CP_UMOUNT; | |
1239 | return reason; | |
1240 | } | |
1241 | ||
1242 | static inline bool __remain_node_summaries(int reason) | |
1243 | { | |
1244 | return (reason == CP_UMOUNT || reason == CP_FASTBOOT); | |
1245 | } | |
1246 | ||
1247 | static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) | |
1248 | { | |
aaec2b1d CY |
1249 | return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || |
1250 | is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); | |
119ee914 JK |
1251 | } |
1252 | ||
39a53e0c JK |
1253 | /* |
1254 | * Check whether the given nid is within node id range. | |
1255 | */ | |
064e0823 | 1256 | static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) |
39a53e0c | 1257 | { |
d6b7d4b3 CY |
1258 | if (unlikely(nid < F2FS_ROOT_INO(sbi))) |
1259 | return -EINVAL; | |
cfb271d4 | 1260 | if (unlikely(nid >= NM_I(sbi)->max_nid)) |
064e0823 NJ |
1261 | return -EINVAL; |
1262 | return 0; | |
39a53e0c JK |
1263 | } |
1264 | ||
1265 | #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 | |
1266 | ||
1267 | /* | |
1268 | * Check whether the inode has blocks or not | |
1269 | */ | |
1270 | static inline int F2FS_HAS_BLOCKS(struct inode *inode) | |
1271 | { | |
1272 | if (F2FS_I(inode)->i_xattr_nid) | |
6c311ec6 | 1273 | return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; |
39a53e0c | 1274 | else |
6c311ec6 | 1275 | return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; |
39a53e0c JK |
1276 | } |
1277 | ||
4bc8e9bc CY |
1278 | static inline bool f2fs_has_xattr_block(unsigned int ofs) |
1279 | { | |
1280 | return ofs == XATTR_NODE_OFFSET; | |
1281 | } | |
1282 | ||
8edd03c8 | 1283 | static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); |
39a53e0c | 1284 | static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, |
46008c6d | 1285 | struct inode *inode, blkcnt_t *count) |
39a53e0c | 1286 | { |
dd11a5df | 1287 | blkcnt_t diff; |
39a53e0c | 1288 | |
cb78942b | 1289 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
55523519 CY |
1290 | if (time_to_inject(sbi, FAULT_BLOCK)) { |
1291 | f2fs_show_injection_info(FAULT_BLOCK); | |
cb78942b | 1292 | return false; |
55523519 | 1293 | } |
cb78942b | 1294 | #endif |
dd11a5df JK |
1295 | /* |
1296 | * let's increase this in prior to actual block count change in order | |
1297 | * for f2fs_sync_file to avoid data races when deciding checkpoint. | |
1298 | */ | |
1299 | percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); | |
1300 | ||
2555a2d5 JK |
1301 | spin_lock(&sbi->stat_lock); |
1302 | sbi->total_valid_block_count += (block_t)(*count); | |
1303 | if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { | |
dd11a5df JK |
1304 | diff = sbi->total_valid_block_count - sbi->user_block_count; |
1305 | *count -= diff; | |
2555a2d5 | 1306 | sbi->total_valid_block_count = sbi->user_block_count; |
46008c6d CY |
1307 | if (!*count) { |
1308 | spin_unlock(&sbi->stat_lock); | |
dd11a5df | 1309 | percpu_counter_sub(&sbi->alloc_valid_block_count, diff); |
46008c6d CY |
1310 | return false; |
1311 | } | |
39a53e0c | 1312 | } |
39a53e0c | 1313 | spin_unlock(&sbi->stat_lock); |
41382ec4 | 1314 | |
2555a2d5 | 1315 | f2fs_i_blocks_write(inode, *count, true); |
39a53e0c JK |
1316 | return true; |
1317 | } | |
1318 | ||
da19b0dc | 1319 | static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, |
39a53e0c JK |
1320 | struct inode *inode, |
1321 | blkcnt_t count) | |
1322 | { | |
1323 | spin_lock(&sbi->stat_lock); | |
9850cf4a JK |
1324 | f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); |
1325 | f2fs_bug_on(sbi, inode->i_blocks < count); | |
39a53e0c JK |
1326 | sbi->total_valid_block_count -= (block_t)count; |
1327 | spin_unlock(&sbi->stat_lock); | |
2555a2d5 | 1328 | f2fs_i_blocks_write(inode, count, false); |
39a53e0c JK |
1329 | } |
1330 | ||
1331 | static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) | |
1332 | { | |
35782b23 | 1333 | atomic_inc(&sbi->nr_pages[count_type]); |
7c4abcbe | 1334 | |
36951b38 CY |
1335 | if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || |
1336 | count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) | |
7c4abcbe CY |
1337 | return; |
1338 | ||
caf0047e | 1339 | set_sbi_flag(sbi, SBI_IS_DIRTY); |
39a53e0c JK |
1340 | } |
1341 | ||
a7ffdbe2 | 1342 | static inline void inode_inc_dirty_pages(struct inode *inode) |
39a53e0c | 1343 | { |
204706c7 | 1344 | atomic_inc(&F2FS_I(inode)->dirty_pages); |
c227f912 CY |
1345 | inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? |
1346 | F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); | |
39a53e0c JK |
1347 | } |
1348 | ||
1349 | static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) | |
1350 | { | |
35782b23 | 1351 | atomic_dec(&sbi->nr_pages[count_type]); |
39a53e0c JK |
1352 | } |
1353 | ||
a7ffdbe2 | 1354 | static inline void inode_dec_dirty_pages(struct inode *inode) |
39a53e0c | 1355 | { |
5ac9f36f CY |
1356 | if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && |
1357 | !S_ISLNK(inode->i_mode)) | |
1fe54f9d JK |
1358 | return; |
1359 | ||
204706c7 | 1360 | atomic_dec(&F2FS_I(inode)->dirty_pages); |
c227f912 CY |
1361 | dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? |
1362 | F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); | |
39a53e0c JK |
1363 | } |
1364 | ||
523be8a6 | 1365 | static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) |
39a53e0c | 1366 | { |
35782b23 | 1367 | return atomic_read(&sbi->nr_pages[count_type]); |
39a53e0c JK |
1368 | } |
1369 | ||
204706c7 | 1370 | static inline int get_dirty_pages(struct inode *inode) |
f8b2c1f9 | 1371 | { |
204706c7 | 1372 | return atomic_read(&F2FS_I(inode)->dirty_pages); |
f8b2c1f9 JK |
1373 | } |
1374 | ||
5ac206cf NJ |
1375 | static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) |
1376 | { | |
3519e3f9 | 1377 | unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; |
523be8a6 JK |
1378 | unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> |
1379 | sbi->log_blocks_per_seg; | |
1380 | ||
1381 | return segs / sbi->segs_per_sec; | |
5ac206cf NJ |
1382 | } |
1383 | ||
39a53e0c JK |
1384 | static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) |
1385 | { | |
8b8343fa | 1386 | return sbi->total_valid_block_count; |
39a53e0c JK |
1387 | } |
1388 | ||
f83a2584 YH |
1389 | static inline block_t discard_blocks(struct f2fs_sb_info *sbi) |
1390 | { | |
1391 | return sbi->discard_blks; | |
1392 | } | |
1393 | ||
39a53e0c JK |
1394 | static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) |
1395 | { | |
1396 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); | |
1397 | ||
1398 | /* return NAT or SIT bitmap */ | |
1399 | if (flag == NAT_BITMAP) | |
1400 | return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); | |
1401 | else if (flag == SIT_BITMAP) | |
1402 | return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); | |
1403 | ||
1404 | return 0; | |
1405 | } | |
1406 | ||
55141486 WL |
1407 | static inline block_t __cp_payload(struct f2fs_sb_info *sbi) |
1408 | { | |
1409 | return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); | |
1410 | } | |
1411 | ||
39a53e0c JK |
1412 | static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) |
1413 | { | |
1414 | struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); | |
1dbe4152 CL |
1415 | int offset; |
1416 | ||
55141486 | 1417 | if (__cp_payload(sbi) > 0) { |
1dbe4152 CL |
1418 | if (flag == NAT_BITMAP) |
1419 | return &ckpt->sit_nat_version_bitmap; | |
1420 | else | |
65b85ccc | 1421 | return (unsigned char *)ckpt + F2FS_BLKSIZE; |
1dbe4152 CL |
1422 | } else { |
1423 | offset = (flag == NAT_BITMAP) ? | |
25ca923b | 1424 | le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; |
1dbe4152 CL |
1425 | return &ckpt->sit_nat_version_bitmap + offset; |
1426 | } | |
39a53e0c JK |
1427 | } |
1428 | ||
1429 | static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) | |
1430 | { | |
8508e44a | 1431 | block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); |
39a53e0c | 1432 | |
8508e44a | 1433 | if (sbi->cur_cp_pack == 2) |
39a53e0c | 1434 | start_addr += sbi->blocks_per_seg; |
8508e44a JK |
1435 | return start_addr; |
1436 | } | |
39a53e0c | 1437 | |
8508e44a JK |
1438 | static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) |
1439 | { | |
1440 | block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); | |
39a53e0c | 1441 | |
8508e44a JK |
1442 | if (sbi->cur_cp_pack == 1) |
1443 | start_addr += sbi->blocks_per_seg; | |
39a53e0c JK |
1444 | return start_addr; |
1445 | } | |
1446 | ||
8508e44a JK |
1447 | static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) |
1448 | { | |
1449 | sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; | |
1450 | } | |
1451 | ||
39a53e0c JK |
1452 | static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) |
1453 | { | |
1454 | return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); | |
1455 | } | |
1456 | ||
1457 | static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, | |
ef86d709 | 1458 | struct inode *inode) |
39a53e0c JK |
1459 | { |
1460 | block_t valid_block_count; | |
1461 | unsigned int valid_node_count; | |
1462 | ||
1463 | spin_lock(&sbi->stat_lock); | |
1464 | ||
ef86d709 | 1465 | valid_block_count = sbi->total_valid_block_count + 1; |
cfb271d4 | 1466 | if (unlikely(valid_block_count > sbi->user_block_count)) { |
39a53e0c JK |
1467 | spin_unlock(&sbi->stat_lock); |
1468 | return false; | |
1469 | } | |
1470 | ||
ef86d709 | 1471 | valid_node_count = sbi->total_valid_node_count + 1; |
cfb271d4 | 1472 | if (unlikely(valid_node_count > sbi->total_node_count)) { |
39a53e0c JK |
1473 | spin_unlock(&sbi->stat_lock); |
1474 | return false; | |
1475 | } | |
1476 | ||
1477 | if (inode) | |
8edd03c8 | 1478 | f2fs_i_blocks_write(inode, 1, true); |
ef86d709 | 1479 | |
ef86d709 GZ |
1480 | sbi->total_valid_node_count++; |
1481 | sbi->total_valid_block_count++; | |
39a53e0c JK |
1482 | spin_unlock(&sbi->stat_lock); |
1483 | ||
41382ec4 | 1484 | percpu_counter_inc(&sbi->alloc_valid_block_count); |
39a53e0c JK |
1485 | return true; |
1486 | } | |
1487 | ||
1488 | static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, | |
ef86d709 | 1489 | struct inode *inode) |
39a53e0c JK |
1490 | { |
1491 | spin_lock(&sbi->stat_lock); | |
1492 | ||
9850cf4a JK |
1493 | f2fs_bug_on(sbi, !sbi->total_valid_block_count); |
1494 | f2fs_bug_on(sbi, !sbi->total_valid_node_count); | |
1495 | f2fs_bug_on(sbi, !inode->i_blocks); | |
39a53e0c | 1496 | |
8edd03c8 | 1497 | f2fs_i_blocks_write(inode, 1, false); |
ef86d709 GZ |
1498 | sbi->total_valid_node_count--; |
1499 | sbi->total_valid_block_count--; | |
39a53e0c JK |
1500 | |
1501 | spin_unlock(&sbi->stat_lock); | |
1502 | } | |
1503 | ||
1504 | static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) | |
1505 | { | |
8b8343fa | 1506 | return sbi->total_valid_node_count; |
39a53e0c JK |
1507 | } |
1508 | ||
1509 | static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) | |
1510 | { | |
513c5f37 | 1511 | percpu_counter_inc(&sbi->total_valid_inode_count); |
39a53e0c JK |
1512 | } |
1513 | ||
0e80220a | 1514 | static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) |
39a53e0c | 1515 | { |
513c5f37 | 1516 | percpu_counter_dec(&sbi->total_valid_inode_count); |
39a53e0c JK |
1517 | } |
1518 | ||
513c5f37 | 1519 | static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) |
39a53e0c | 1520 | { |
513c5f37 | 1521 | return percpu_counter_sum_positive(&sbi->total_valid_inode_count); |
39a53e0c JK |
1522 | } |
1523 | ||
a56c7c6f JK |
1524 | static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, |
1525 | pgoff_t index, bool for_write) | |
1526 | { | |
c41f3cc3 JK |
1527 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
1528 | struct page *page = find_lock_page(mapping, index); | |
cac5a3d8 | 1529 | |
c41f3cc3 JK |
1530 | if (page) |
1531 | return page; | |
1532 | ||
55523519 CY |
1533 | if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { |
1534 | f2fs_show_injection_info(FAULT_PAGE_ALLOC); | |
c41f3cc3 | 1535 | return NULL; |
55523519 | 1536 | } |
c41f3cc3 | 1537 | #endif |
a56c7c6f JK |
1538 | if (!for_write) |
1539 | return grab_cache_page(mapping, index); | |
1540 | return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); | |
1541 | } | |
1542 | ||
6e2c64ad JK |
1543 | static inline void f2fs_copy_page(struct page *src, struct page *dst) |
1544 | { | |
1545 | char *src_kaddr = kmap(src); | |
1546 | char *dst_kaddr = kmap(dst); | |
1547 | ||
1548 | memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); | |
1549 | kunmap(dst); | |
1550 | kunmap(src); | |
1551 | } | |
1552 | ||
39a53e0c JK |
1553 | static inline void f2fs_put_page(struct page *page, int unlock) |
1554 | { | |
031fa8cc | 1555 | if (!page) |
39a53e0c JK |
1556 | return; |
1557 | ||
1558 | if (unlock) { | |
9850cf4a | 1559 | f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); |
39a53e0c JK |
1560 | unlock_page(page); |
1561 | } | |
09cbfeaf | 1562 | put_page(page); |
39a53e0c JK |
1563 | } |
1564 | ||
1565 | static inline void f2fs_put_dnode(struct dnode_of_data *dn) | |
1566 | { | |
1567 | if (dn->node_page) | |
1568 | f2fs_put_page(dn->node_page, 1); | |
1569 | if (dn->inode_page && dn->node_page != dn->inode_page) | |
1570 | f2fs_put_page(dn->inode_page, 0); | |
1571 | dn->node_page = NULL; | |
1572 | dn->inode_page = NULL; | |
1573 | } | |
1574 | ||
1575 | static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, | |
e8512d2e | 1576 | size_t size) |
39a53e0c | 1577 | { |
e8512d2e | 1578 | return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); |
39a53e0c JK |
1579 | } |
1580 | ||
7bd59381 GZ |
1581 | static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, |
1582 | gfp_t flags) | |
1583 | { | |
1584 | void *entry; | |
7bd59381 | 1585 | |
80c54505 JK |
1586 | entry = kmem_cache_alloc(cachep, flags); |
1587 | if (!entry) | |
1588 | entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); | |
7bd59381 GZ |
1589 | return entry; |
1590 | } | |
1591 | ||
740432f8 JK |
1592 | static inline struct bio *f2fs_bio_alloc(int npages) |
1593 | { | |
1594 | struct bio *bio; | |
1595 | ||
1596 | /* No failure on bio allocation */ | |
740432f8 | 1597 | bio = bio_alloc(GFP_NOIO, npages); |
80c54505 JK |
1598 | if (!bio) |
1599 | bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); | |
740432f8 JK |
1600 | return bio; |
1601 | } | |
1602 | ||
9be32d72 JK |
1603 | static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, |
1604 | unsigned long index, void *item) | |
1605 | { | |
1606 | while (radix_tree_insert(root, index, item)) | |
1607 | cond_resched(); | |
1608 | } | |
1609 | ||
39a53e0c JK |
1610 | #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) |
1611 | ||
1612 | static inline bool IS_INODE(struct page *page) | |
1613 | { | |
45590710 | 1614 | struct f2fs_node *p = F2FS_NODE(page); |
cac5a3d8 | 1615 | |
39a53e0c JK |
1616 | return RAW_IS_INODE(p); |
1617 | } | |
1618 | ||
1619 | static inline __le32 *blkaddr_in_node(struct f2fs_node *node) | |
1620 | { | |
1621 | return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; | |
1622 | } | |
1623 | ||
1624 | static inline block_t datablock_addr(struct page *node_page, | |
1625 | unsigned int offset) | |
1626 | { | |
1627 | struct f2fs_node *raw_node; | |
1628 | __le32 *addr_array; | |
cac5a3d8 | 1629 | |
45590710 | 1630 | raw_node = F2FS_NODE(node_page); |
39a53e0c JK |
1631 | addr_array = blkaddr_in_node(raw_node); |
1632 | return le32_to_cpu(addr_array[offset]); | |
1633 | } | |
1634 | ||
1635 | static inline int f2fs_test_bit(unsigned int nr, char *addr) | |
1636 | { | |
1637 | int mask; | |
1638 | ||
1639 | addr += (nr >> 3); | |
1640 | mask = 1 << (7 - (nr & 0x07)); | |
1641 | return mask & *addr; | |
1642 | } | |
1643 | ||
a66cdd98 JK |
1644 | static inline void f2fs_set_bit(unsigned int nr, char *addr) |
1645 | { | |
1646 | int mask; | |
1647 | ||
1648 | addr += (nr >> 3); | |
1649 | mask = 1 << (7 - (nr & 0x07)); | |
1650 | *addr |= mask; | |
1651 | } | |
1652 | ||
1653 | static inline void f2fs_clear_bit(unsigned int nr, char *addr) | |
1654 | { | |
1655 | int mask; | |
1656 | ||
1657 | addr += (nr >> 3); | |
1658 | mask = 1 << (7 - (nr & 0x07)); | |
1659 | *addr &= ~mask; | |
1660 | } | |
1661 | ||
52aca074 | 1662 | static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) |
39a53e0c JK |
1663 | { |
1664 | int mask; | |
1665 | int ret; | |
1666 | ||
1667 | addr += (nr >> 3); | |
1668 | mask = 1 << (7 - (nr & 0x07)); | |
1669 | ret = mask & *addr; | |
1670 | *addr |= mask; | |
1671 | return ret; | |
1672 | } | |
1673 | ||
52aca074 | 1674 | static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) |
39a53e0c JK |
1675 | { |
1676 | int mask; | |
1677 | int ret; | |
1678 | ||
1679 | addr += (nr >> 3); | |
1680 | mask = 1 << (7 - (nr & 0x07)); | |
1681 | ret = mask & *addr; | |
1682 | *addr &= ~mask; | |
1683 | return ret; | |
1684 | } | |
1685 | ||
c6ac4c0e GZ |
1686 | static inline void f2fs_change_bit(unsigned int nr, char *addr) |
1687 | { | |
1688 | int mask; | |
1689 | ||
1690 | addr += (nr >> 3); | |
1691 | mask = 1 << (7 - (nr & 0x07)); | |
1692 | *addr ^= mask; | |
1693 | } | |
1694 | ||
39a53e0c JK |
1695 | /* used for f2fs_inode_info->flags */ |
1696 | enum { | |
1697 | FI_NEW_INODE, /* indicate newly allocated inode */ | |
b3783873 | 1698 | FI_DIRTY_INODE, /* indicate inode is dirty or not */ |
26de9b11 | 1699 | FI_AUTO_RECOVER, /* indicate inode is recoverable */ |
ed57c27f | 1700 | FI_DIRTY_DIR, /* indicate directory has dirty pages */ |
39a53e0c JK |
1701 | FI_INC_LINK, /* need to increment i_nlink */ |
1702 | FI_ACL_MODE, /* indicate acl mode */ | |
1703 | FI_NO_ALLOC, /* should not allocate any blocks */ | |
c9b63bd0 | 1704 | FI_FREE_NID, /* free allocated nide */ |
c11abd1a | 1705 | FI_NO_EXTENT, /* not to use the extent cache */ |
444c580f | 1706 | FI_INLINE_XATTR, /* used for inline xattr */ |
1001b347 | 1707 | FI_INLINE_DATA, /* used for inline data*/ |
34d67deb | 1708 | FI_INLINE_DENTRY, /* used for inline dentry */ |
fff04f90 JK |
1709 | FI_APPEND_WRITE, /* inode has appended data */ |
1710 | FI_UPDATE_WRITE, /* inode has in-place-update data */ | |
88b88a66 JK |
1711 | FI_NEED_IPU, /* used for ipu per file */ |
1712 | FI_ATOMIC_FILE, /* indicate atomic file */ | |
5fe45743 | 1713 | FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ |
02a1335f | 1714 | FI_VOLATILE_FILE, /* indicate volatile file */ |
3c6c2beb | 1715 | FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ |
1e84371f | 1716 | FI_DROP_CACHE, /* drop dirty page cache */ |
b3d208f9 | 1717 | FI_DATA_EXIST, /* indicate data exists */ |
510022a8 | 1718 | FI_INLINE_DOTS, /* indicate inline dot dentries */ |
d323d005 | 1719 | FI_DO_DEFRAG, /* indicate defragment is running */ |
c227f912 | 1720 | FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ |
dc91de78 | 1721 | FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ |
ef095d19 | 1722 | FI_HOT_DATA, /* indicate file is hot */ |
39a53e0c JK |
1723 | }; |
1724 | ||
205b9822 JK |
1725 | static inline void __mark_inode_dirty_flag(struct inode *inode, |
1726 | int flag, bool set) | |
1727 | { | |
1728 | switch (flag) { | |
1729 | case FI_INLINE_XATTR: | |
1730 | case FI_INLINE_DATA: | |
1731 | case FI_INLINE_DENTRY: | |
1732 | if (set) | |
1733 | return; | |
1734 | case FI_DATA_EXIST: | |
1735 | case FI_INLINE_DOTS: | |
7c45729a | 1736 | f2fs_mark_inode_dirty_sync(inode, true); |
205b9822 JK |
1737 | } |
1738 | } | |
1739 | ||
91942321 | 1740 | static inline void set_inode_flag(struct inode *inode, int flag) |
39a53e0c | 1741 | { |
91942321 JK |
1742 | if (!test_bit(flag, &F2FS_I(inode)->flags)) |
1743 | set_bit(flag, &F2FS_I(inode)->flags); | |
205b9822 | 1744 | __mark_inode_dirty_flag(inode, flag, true); |
39a53e0c JK |
1745 | } |
1746 | ||
91942321 | 1747 | static inline int is_inode_flag_set(struct inode *inode, int flag) |
39a53e0c | 1748 | { |
91942321 | 1749 | return test_bit(flag, &F2FS_I(inode)->flags); |
39a53e0c JK |
1750 | } |
1751 | ||
91942321 | 1752 | static inline void clear_inode_flag(struct inode *inode, int flag) |
39a53e0c | 1753 | { |
91942321 JK |
1754 | if (test_bit(flag, &F2FS_I(inode)->flags)) |
1755 | clear_bit(flag, &F2FS_I(inode)->flags); | |
205b9822 | 1756 | __mark_inode_dirty_flag(inode, flag, false); |
39a53e0c JK |
1757 | } |
1758 | ||
91942321 | 1759 | static inline void set_acl_inode(struct inode *inode, umode_t mode) |
39a53e0c | 1760 | { |
91942321 JK |
1761 | F2FS_I(inode)->i_acl_mode = mode; |
1762 | set_inode_flag(inode, FI_ACL_MODE); | |
7c45729a | 1763 | f2fs_mark_inode_dirty_sync(inode, false); |
39a53e0c JK |
1764 | } |
1765 | ||
a1961246 | 1766 | static inline void f2fs_i_links_write(struct inode *inode, bool inc) |
39a53e0c | 1767 | { |
a1961246 JK |
1768 | if (inc) |
1769 | inc_nlink(inode); | |
1770 | else | |
1771 | drop_nlink(inode); | |
7c45729a | 1772 | f2fs_mark_inode_dirty_sync(inode, true); |
a1961246 JK |
1773 | } |
1774 | ||
8edd03c8 JK |
1775 | static inline void f2fs_i_blocks_write(struct inode *inode, |
1776 | blkcnt_t diff, bool add) | |
1777 | { | |
26de9b11 JK |
1778 | bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); |
1779 | bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); | |
1780 | ||
8edd03c8 JK |
1781 | inode->i_blocks = add ? inode->i_blocks + diff : |
1782 | inode->i_blocks - diff; | |
7c45729a | 1783 | f2fs_mark_inode_dirty_sync(inode, true); |
26de9b11 JK |
1784 | if (clean || recover) |
1785 | set_inode_flag(inode, FI_AUTO_RECOVER); | |
8edd03c8 JK |
1786 | } |
1787 | ||
fc9581c8 JK |
1788 | static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) |
1789 | { | |
26de9b11 JK |
1790 | bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); |
1791 | bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); | |
1792 | ||
fc9581c8 JK |
1793 | if (i_size_read(inode) == i_size) |
1794 | return; | |
1795 | ||
1796 | i_size_write(inode, i_size); | |
7c45729a | 1797 | f2fs_mark_inode_dirty_sync(inode, true); |
26de9b11 JK |
1798 | if (clean || recover) |
1799 | set_inode_flag(inode, FI_AUTO_RECOVER); | |
39a53e0c JK |
1800 | } |
1801 | ||
205b9822 | 1802 | static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) |
39a53e0c | 1803 | { |
205b9822 | 1804 | F2FS_I(inode)->i_current_depth = depth; |
7c45729a | 1805 | f2fs_mark_inode_dirty_sync(inode, true); |
39a53e0c JK |
1806 | } |
1807 | ||
205b9822 | 1808 | static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) |
444c580f | 1809 | { |
205b9822 | 1810 | F2FS_I(inode)->i_xattr_nid = xnid; |
7c45729a | 1811 | f2fs_mark_inode_dirty_sync(inode, true); |
205b9822 JK |
1812 | } |
1813 | ||
1814 | static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) | |
1815 | { | |
1816 | F2FS_I(inode)->i_pino = pino; | |
7c45729a | 1817 | f2fs_mark_inode_dirty_sync(inode, true); |
205b9822 JK |
1818 | } |
1819 | ||
91942321 | 1820 | static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) |
444c580f | 1821 | { |
205b9822 JK |
1822 | struct f2fs_inode_info *fi = F2FS_I(inode); |
1823 | ||
444c580f | 1824 | if (ri->i_inline & F2FS_INLINE_XATTR) |
205b9822 | 1825 | set_bit(FI_INLINE_XATTR, &fi->flags); |
1001b347 | 1826 | if (ri->i_inline & F2FS_INLINE_DATA) |
205b9822 | 1827 | set_bit(FI_INLINE_DATA, &fi->flags); |
34d67deb | 1828 | if (ri->i_inline & F2FS_INLINE_DENTRY) |
205b9822 | 1829 | set_bit(FI_INLINE_DENTRY, &fi->flags); |
b3d208f9 | 1830 | if (ri->i_inline & F2FS_DATA_EXIST) |
205b9822 | 1831 | set_bit(FI_DATA_EXIST, &fi->flags); |
510022a8 | 1832 | if (ri->i_inline & F2FS_INLINE_DOTS) |
205b9822 | 1833 | set_bit(FI_INLINE_DOTS, &fi->flags); |
444c580f JK |
1834 | } |
1835 | ||
91942321 | 1836 | static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) |
444c580f JK |
1837 | { |
1838 | ri->i_inline = 0; | |
1839 | ||
91942321 | 1840 | if (is_inode_flag_set(inode, FI_INLINE_XATTR)) |
444c580f | 1841 | ri->i_inline |= F2FS_INLINE_XATTR; |
91942321 | 1842 | if (is_inode_flag_set(inode, FI_INLINE_DATA)) |
1001b347 | 1843 | ri->i_inline |= F2FS_INLINE_DATA; |
91942321 | 1844 | if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) |
34d67deb | 1845 | ri->i_inline |= F2FS_INLINE_DENTRY; |
91942321 | 1846 | if (is_inode_flag_set(inode, FI_DATA_EXIST)) |
b3d208f9 | 1847 | ri->i_inline |= F2FS_DATA_EXIST; |
91942321 | 1848 | if (is_inode_flag_set(inode, FI_INLINE_DOTS)) |
510022a8 | 1849 | ri->i_inline |= F2FS_INLINE_DOTS; |
444c580f JK |
1850 | } |
1851 | ||
987c7c31 CY |
1852 | static inline int f2fs_has_inline_xattr(struct inode *inode) |
1853 | { | |
91942321 | 1854 | return is_inode_flag_set(inode, FI_INLINE_XATTR); |
987c7c31 CY |
1855 | } |
1856 | ||
81ca7350 | 1857 | static inline unsigned int addrs_per_inode(struct inode *inode) |
de93653f | 1858 | { |
81ca7350 | 1859 | if (f2fs_has_inline_xattr(inode)) |
de93653f JK |
1860 | return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; |
1861 | return DEF_ADDRS_PER_INODE; | |
1862 | } | |
1863 | ||
65985d93 JK |
1864 | static inline void *inline_xattr_addr(struct page *page) |
1865 | { | |
695fd1ed | 1866 | struct f2fs_inode *ri = F2FS_INODE(page); |
cac5a3d8 | 1867 | |
65985d93 JK |
1868 | return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - |
1869 | F2FS_INLINE_XATTR_ADDRS]); | |
1870 | } | |
1871 | ||
1872 | static inline int inline_xattr_size(struct inode *inode) | |
1873 | { | |
987c7c31 | 1874 | if (f2fs_has_inline_xattr(inode)) |
65985d93 JK |
1875 | return F2FS_INLINE_XATTR_ADDRS << 2; |
1876 | else | |
1877 | return 0; | |
1878 | } | |
1879 | ||
0dbdc2ae JK |
1880 | static inline int f2fs_has_inline_data(struct inode *inode) |
1881 | { | |
91942321 | 1882 | return is_inode_flag_set(inode, FI_INLINE_DATA); |
0dbdc2ae JK |
1883 | } |
1884 | ||
b3d208f9 JK |
1885 | static inline int f2fs_exist_data(struct inode *inode) |
1886 | { | |
91942321 | 1887 | return is_inode_flag_set(inode, FI_DATA_EXIST); |
b3d208f9 JK |
1888 | } |
1889 | ||
510022a8 JK |
1890 | static inline int f2fs_has_inline_dots(struct inode *inode) |
1891 | { | |
91942321 | 1892 | return is_inode_flag_set(inode, FI_INLINE_DOTS); |
510022a8 JK |
1893 | } |
1894 | ||
88b88a66 JK |
1895 | static inline bool f2fs_is_atomic_file(struct inode *inode) |
1896 | { | |
91942321 | 1897 | return is_inode_flag_set(inode, FI_ATOMIC_FILE); |
88b88a66 JK |
1898 | } |
1899 | ||
5fe45743 CY |
1900 | static inline bool f2fs_is_commit_atomic_write(struct inode *inode) |
1901 | { | |
1902 | return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); | |
1903 | } | |
1904 | ||
02a1335f JK |
1905 | static inline bool f2fs_is_volatile_file(struct inode *inode) |
1906 | { | |
91942321 | 1907 | return is_inode_flag_set(inode, FI_VOLATILE_FILE); |
02a1335f JK |
1908 | } |
1909 | ||
3c6c2beb JK |
1910 | static inline bool f2fs_is_first_block_written(struct inode *inode) |
1911 | { | |
91942321 | 1912 | return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); |
3c6c2beb JK |
1913 | } |
1914 | ||
1e84371f JK |
1915 | static inline bool f2fs_is_drop_cache(struct inode *inode) |
1916 | { | |
91942321 | 1917 | return is_inode_flag_set(inode, FI_DROP_CACHE); |
1e84371f JK |
1918 | } |
1919 | ||
1001b347 HL |
1920 | static inline void *inline_data_addr(struct page *page) |
1921 | { | |
695fd1ed | 1922 | struct f2fs_inode *ri = F2FS_INODE(page); |
cac5a3d8 | 1923 | |
1001b347 HL |
1924 | return (void *)&(ri->i_addr[1]); |
1925 | } | |
1926 | ||
34d67deb CY |
1927 | static inline int f2fs_has_inline_dentry(struct inode *inode) |
1928 | { | |
91942321 | 1929 | return is_inode_flag_set(inode, FI_INLINE_DENTRY); |
34d67deb CY |
1930 | } |
1931 | ||
9486ba44 JK |
1932 | static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) |
1933 | { | |
1934 | if (!f2fs_has_inline_dentry(dir)) | |
1935 | kunmap(page); | |
1936 | } | |
1937 | ||
b5492af7 JK |
1938 | static inline int is_file(struct inode *inode, int type) |
1939 | { | |
1940 | return F2FS_I(inode)->i_advise & type; | |
1941 | } | |
1942 | ||
1943 | static inline void set_file(struct inode *inode, int type) | |
1944 | { | |
1945 | F2FS_I(inode)->i_advise |= type; | |
7c45729a | 1946 | f2fs_mark_inode_dirty_sync(inode, true); |
b5492af7 JK |
1947 | } |
1948 | ||
1949 | static inline void clear_file(struct inode *inode, int type) | |
1950 | { | |
1951 | F2FS_I(inode)->i_advise &= ~type; | |
7c45729a | 1952 | f2fs_mark_inode_dirty_sync(inode, true); |
b5492af7 JK |
1953 | } |
1954 | ||
26787236 JK |
1955 | static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) |
1956 | { | |
1957 | if (dsync) { | |
1958 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); | |
1959 | bool ret; | |
1960 | ||
1961 | spin_lock(&sbi->inode_lock[DIRTY_META]); | |
1962 | ret = list_empty(&F2FS_I(inode)->gdirty_list); | |
1963 | spin_unlock(&sbi->inode_lock[DIRTY_META]); | |
1964 | return ret; | |
1965 | } | |
1966 | if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || | |
1967 | file_keep_isize(inode) || | |
1968 | i_size_read(inode) & PAGE_MASK) | |
1969 | return false; | |
1970 | return F2FS_I(inode)->last_disk_size == i_size_read(inode); | |
b5492af7 JK |
1971 | } |
1972 | ||
77888c1e JK |
1973 | static inline int f2fs_readonly(struct super_block *sb) |
1974 | { | |
1975 | return sb->s_flags & MS_RDONLY; | |
1976 | } | |
1977 | ||
1e968fdf JK |
1978 | static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) |
1979 | { | |
aaec2b1d | 1980 | return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); |
1e968fdf JK |
1981 | } |
1982 | ||
eaa693f4 JK |
1983 | static inline bool is_dot_dotdot(const struct qstr *str) |
1984 | { | |
1985 | if (str->len == 1 && str->name[0] == '.') | |
1986 | return true; | |
1987 | ||
1988 | if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') | |
1989 | return true; | |
1990 | ||
1991 | return false; | |
1992 | } | |
1993 | ||
3e72f721 JK |
1994 | static inline bool f2fs_may_extent_tree(struct inode *inode) |
1995 | { | |
3e72f721 | 1996 | if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || |
91942321 | 1997 | is_inode_flag_set(inode, FI_NO_EXTENT)) |
3e72f721 JK |
1998 | return false; |
1999 | ||
886f56f9 | 2000 | return S_ISREG(inode->i_mode); |
3e72f721 JK |
2001 | } |
2002 | ||
1ecc0c5c CY |
2003 | static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, |
2004 | size_t size, gfp_t flags) | |
0414b004 | 2005 | { |
2c63fead | 2006 | #ifdef CONFIG_F2FS_FAULT_INJECTION |
55523519 CY |
2007 | if (time_to_inject(sbi, FAULT_KMALLOC)) { |
2008 | f2fs_show_injection_info(FAULT_KMALLOC); | |
2c63fead | 2009 | return NULL; |
55523519 | 2010 | } |
2c63fead | 2011 | #endif |
0414b004 JK |
2012 | return kmalloc(size, flags); |
2013 | } | |
2014 | ||
39307a8e JK |
2015 | static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) |
2016 | { | |
2017 | void *ret; | |
2018 | ||
2019 | ret = kmalloc(size, flags | __GFP_NOWARN); | |
2020 | if (!ret) | |
2021 | ret = __vmalloc(size, flags, PAGE_KERNEL); | |
2022 | return ret; | |
2023 | } | |
2024 | ||
2025 | static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) | |
2026 | { | |
2027 | void *ret; | |
2028 | ||
2029 | ret = kzalloc(size, flags | __GFP_NOWARN); | |
2030 | if (!ret) | |
2031 | ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); | |
2032 | return ret; | |
2033 | } | |
2034 | ||
a6dda0e6 | 2035 | #define get_inode_mode(i) \ |
91942321 | 2036 | ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ |
a6dda0e6 CH |
2037 | (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) |
2038 | ||
39a53e0c JK |
2039 | /* |
2040 | * file.c | |
2041 | */ | |
cac5a3d8 DS |
2042 | int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); |
2043 | void truncate_data_blocks(struct dnode_of_data *dn); | |
2044 | int truncate_blocks(struct inode *inode, u64 from, bool lock); | |
2045 | int f2fs_truncate(struct inode *inode); | |
a528d35e DH |
2046 | int f2fs_getattr(const struct path *path, struct kstat *stat, |
2047 | u32 request_mask, unsigned int flags); | |
cac5a3d8 DS |
2048 | int f2fs_setattr(struct dentry *dentry, struct iattr *attr); |
2049 | int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); | |
2050 | int truncate_data_blocks_range(struct dnode_of_data *dn, int count); | |
2051 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); | |
2052 | long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | |
39a53e0c JK |
2053 | |
2054 | /* | |
2055 | * inode.c | |
2056 | */ | |
cac5a3d8 DS |
2057 | void f2fs_set_inode_flags(struct inode *inode); |
2058 | struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); | |
2059 | struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); | |
2060 | int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); | |
2061 | int update_inode(struct inode *inode, struct page *node_page); | |
2062 | int update_inode_page(struct inode *inode); | |
2063 | int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); | |
2064 | void f2fs_evict_inode(struct inode *inode); | |
2065 | void handle_failed_inode(struct inode *inode); | |
39a53e0c JK |
2066 | |
2067 | /* | |
2068 | * namei.c | |
2069 | */ | |
2070 | struct dentry *f2fs_get_parent(struct dentry *child); | |
2071 | ||
2072 | /* | |
2073 | * dir.c | |
2074 | */ | |
cac5a3d8 DS |
2075 | void set_de_type(struct f2fs_dir_entry *de, umode_t mode); |
2076 | unsigned char get_de_type(struct f2fs_dir_entry *de); | |
2077 | struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, | |
2078 | f2fs_hash_t namehash, int *max_slots, | |
2079 | struct f2fs_dentry_ptr *d); | |
2080 | int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, | |
2081 | unsigned int start_pos, struct fscrypt_str *fstr); | |
2082 | void do_make_empty_dir(struct inode *inode, struct inode *parent, | |
2083 | struct f2fs_dentry_ptr *d); | |
2084 | struct page *init_inode_metadata(struct inode *inode, struct inode *dir, | |
2085 | const struct qstr *new_name, | |
2086 | const struct qstr *orig_name, struct page *dpage); | |
2087 | void update_parent_metadata(struct inode *dir, struct inode *inode, | |
2088 | unsigned int current_depth); | |
2089 | int room_for_filename(const void *bitmap, int slots, int max_slots); | |
2090 | void f2fs_drop_nlink(struct inode *dir, struct inode *inode); | |
2091 | struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, | |
2092 | struct fscrypt_name *fname, struct page **res_page); | |
2093 | struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, | |
2094 | const struct qstr *child, struct page **res_page); | |
2095 | struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); | |
2096 | ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, | |
2097 | struct page **page); | |
2098 | void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, | |
2099 | struct page *page, struct inode *inode); | |
cac5a3d8 DS |
2100 | void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, |
2101 | const struct qstr *name, f2fs_hash_t name_hash, | |
2102 | unsigned int bit_pos); | |
2103 | int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, | |
2104 | const struct qstr *orig_name, | |
2105 | struct inode *inode, nid_t ino, umode_t mode); | |
2106 | int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, | |
2107 | struct inode *inode, nid_t ino, umode_t mode); | |
2108 | int __f2fs_add_link(struct inode *dir, const struct qstr *name, | |
2109 | struct inode *inode, nid_t ino, umode_t mode); | |
2110 | void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, | |
2111 | struct inode *dir, struct inode *inode); | |
2112 | int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); | |
2113 | bool f2fs_empty_dir(struct inode *dir); | |
39a53e0c | 2114 | |
b7f7a5e0 AV |
2115 | static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) |
2116 | { | |
2b0143b5 | 2117 | return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, |
510022a8 | 2118 | inode, inode->i_ino, inode->i_mode); |
b7f7a5e0 AV |
2119 | } |
2120 | ||
39a53e0c JK |
2121 | /* |
2122 | * super.c | |
2123 | */ | |
cac5a3d8 DS |
2124 | int f2fs_inode_dirtied(struct inode *inode, bool sync); |
2125 | void f2fs_inode_synced(struct inode *inode); | |
2126 | int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); | |
2127 | int f2fs_sync_fs(struct super_block *sb, int sync); | |
a07ef784 | 2128 | extern __printf(3, 4) |
cac5a3d8 | 2129 | void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); |
984ec63c | 2130 | int sanity_check_ckpt(struct f2fs_sb_info *sbi); |
39a53e0c JK |
2131 | |
2132 | /* | |
2133 | * hash.c | |
2134 | */ | |
cac5a3d8 | 2135 | f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info); |
39a53e0c JK |
2136 | |
2137 | /* | |
2138 | * node.c | |
2139 | */ | |
2140 | struct dnode_of_data; | |
2141 | struct node_info; | |
2142 | ||
cac5a3d8 DS |
2143 | bool available_free_memory(struct f2fs_sb_info *sbi, int type); |
2144 | int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); | |
2145 | bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); | |
2146 | bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); | |
2147 | void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); | |
2148 | pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); | |
2149 | int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); | |
2150 | int truncate_inode_blocks(struct inode *inode, pgoff_t from); | |
2151 | int truncate_xattr_node(struct inode *inode, struct page *page); | |
2152 | int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); | |
2153 | int remove_inode_page(struct inode *inode); | |
2154 | struct page *new_inode_page(struct inode *inode); | |
2155 | struct page *new_node_page(struct dnode_of_data *dn, | |
2156 | unsigned int ofs, struct page *ipage); | |
2157 | void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); | |
2158 | struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); | |
2159 | struct page *get_node_page_ra(struct page *parent, int start); | |
2160 | void move_node_page(struct page *node_page, int gc_type); | |
2161 | int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, | |
2162 | struct writeback_control *wbc, bool atomic); | |
2163 | int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc); | |
22ad0b6a | 2164 | void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); |
cac5a3d8 DS |
2165 | bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); |
2166 | void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); | |
2167 | void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); | |
2168 | int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); | |
2169 | void recover_inline_xattr(struct inode *inode, struct page *page); | |
d260081c | 2170 | int recover_xattr_data(struct inode *inode, struct page *page, |
cac5a3d8 DS |
2171 | block_t blkaddr); |
2172 | int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); | |
2173 | int restore_node_summary(struct f2fs_sb_info *sbi, | |
2174 | unsigned int segno, struct f2fs_summary_block *sum); | |
22ad0b6a | 2175 | void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); |
cac5a3d8 DS |
2176 | int build_node_manager(struct f2fs_sb_info *sbi); |
2177 | void destroy_node_manager(struct f2fs_sb_info *sbi); | |
6e6093a8 | 2178 | int __init create_node_manager_caches(void); |
39a53e0c JK |
2179 | void destroy_node_manager_caches(void); |
2180 | ||
2181 | /* | |
2182 | * segment.c | |
2183 | */ | |
cac5a3d8 DS |
2184 | void register_inmem_page(struct inode *inode, struct page *page); |
2185 | void drop_inmem_pages(struct inode *inode); | |
8c242db9 | 2186 | void drop_inmem_page(struct inode *inode, struct page *page); |
cac5a3d8 DS |
2187 | int commit_inmem_pages(struct inode *inode); |
2188 | void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); | |
2189 | void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); | |
2190 | int f2fs_issue_flush(struct f2fs_sb_info *sbi); | |
2191 | int create_flush_cmd_control(struct f2fs_sb_info *sbi); | |
2192 | void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); | |
2193 | void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); | |
2194 | bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); | |
2195 | void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); | |
d431413f | 2196 | void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); |
cac5a3d8 DS |
2197 | void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); |
2198 | void release_discard_addrs(struct f2fs_sb_info *sbi); | |
2199 | int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); | |
2200 | void allocate_new_segments(struct f2fs_sb_info *sbi); | |
2201 | int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); | |
2202 | bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); | |
2203 | struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); | |
2204 | void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); | |
2205 | void write_meta_page(struct f2fs_sb_info *sbi, struct page *page); | |
2206 | void write_node_page(unsigned int nid, struct f2fs_io_info *fio); | |
2207 | void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); | |
d1b3e72d | 2208 | int rewrite_data_page(struct f2fs_io_info *fio); |
cac5a3d8 DS |
2209 | void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, |
2210 | block_t old_blkaddr, block_t new_blkaddr, | |
2211 | bool recover_curseg, bool recover_newaddr); | |
2212 | void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, | |
2213 | block_t old_addr, block_t new_addr, | |
2214 | unsigned char version, bool recover_curseg, | |
2215 | bool recover_newaddr); | |
2216 | void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, | |
2217 | block_t old_blkaddr, block_t *new_blkaddr, | |
2218 | struct f2fs_summary *sum, int type); | |
2219 | void f2fs_wait_on_page_writeback(struct page *page, | |
2220 | enum page_type type, bool ordered); | |
2221 | void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, | |
2222 | block_t blkaddr); | |
2223 | void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); | |
2224 | void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); | |
2225 | int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, | |
2226 | unsigned int val, int alloc); | |
2227 | void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); | |
2228 | int build_segment_manager(struct f2fs_sb_info *sbi); | |
2229 | void destroy_segment_manager(struct f2fs_sb_info *sbi); | |
7fd9e544 JK |
2230 | int __init create_segment_manager_caches(void); |
2231 | void destroy_segment_manager_caches(void); | |
39a53e0c JK |
2232 | |
2233 | /* | |
2234 | * checkpoint.c | |
2235 | */ | |
cac5a3d8 DS |
2236 | void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); |
2237 | struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); | |
2238 | struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); | |
2239 | struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); | |
2240 | bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); | |
2241 | int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, | |
2242 | int type, bool sync); | |
2243 | void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); | |
2244 | long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, | |
2245 | long nr_to_write); | |
2246 | void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); | |
2247 | void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); | |
2248 | void release_ino_entry(struct f2fs_sb_info *sbi, bool all); | |
2249 | bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); | |
2250 | int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); | |
2251 | int acquire_orphan_inode(struct f2fs_sb_info *sbi); | |
2252 | void release_orphan_inode(struct f2fs_sb_info *sbi); | |
2253 | void add_orphan_inode(struct inode *inode); | |
2254 | void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); | |
2255 | int recover_orphan_inodes(struct f2fs_sb_info *sbi); | |
2256 | int get_valid_checkpoint(struct f2fs_sb_info *sbi); | |
2257 | void update_dirty_page(struct inode *inode, struct page *page); | |
2258 | void remove_dirty_inode(struct inode *inode); | |
2259 | int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); | |
2260 | int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); | |
2261 | void init_ino_entry_info(struct f2fs_sb_info *sbi); | |
6e6093a8 | 2262 | int __init create_checkpoint_caches(void); |
39a53e0c JK |
2263 | void destroy_checkpoint_caches(void); |
2264 | ||
2265 | /* | |
2266 | * data.c | |
2267 | */ | |
cac5a3d8 DS |
2268 | void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, |
2269 | int rw); | |
2270 | void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, | |
942fd319 JK |
2271 | struct inode *inode, nid_t ino, pgoff_t idx, |
2272 | enum page_type type, int rw); | |
cac5a3d8 DS |
2273 | void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi); |
2274 | int f2fs_submit_page_bio(struct f2fs_io_info *fio); | |
2275 | int f2fs_submit_page_mbio(struct f2fs_io_info *fio); | |
2276 | struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, | |
2277 | block_t blk_addr, struct bio *bio); | |
2278 | int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); | |
2279 | void set_data_blkaddr(struct dnode_of_data *dn); | |
2280 | void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); | |
2281 | int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); | |
2282 | int reserve_new_block(struct dnode_of_data *dn); | |
2283 | int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); | |
2284 | int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); | |
2285 | int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); | |
2286 | struct page *get_read_data_page(struct inode *inode, pgoff_t index, | |
2287 | int op_flags, bool for_write); | |
2288 | struct page *find_data_page(struct inode *inode, pgoff_t index); | |
2289 | struct page *get_lock_data_page(struct inode *inode, pgoff_t index, | |
2290 | bool for_write); | |
2291 | struct page *get_new_data_page(struct inode *inode, | |
2292 | struct page *ipage, pgoff_t index, bool new_i_size); | |
2293 | int do_write_data_page(struct f2fs_io_info *fio); | |
2294 | int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, | |
2295 | int create, int flag); | |
2296 | int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | |
2297 | u64 start, u64 len); | |
2298 | void f2fs_set_page_dirty_nobuffers(struct page *page); | |
2299 | void f2fs_invalidate_page(struct page *page, unsigned int offset, | |
2300 | unsigned int length); | |
2301 | int f2fs_release_page(struct page *page, gfp_t wait); | |
5b7a487c | 2302 | #ifdef CONFIG_MIGRATION |
cac5a3d8 DS |
2303 | int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, |
2304 | struct page *page, enum migrate_mode mode); | |
5b7a487c | 2305 | #endif |
39a53e0c JK |
2306 | |
2307 | /* | |
2308 | * gc.c | |
2309 | */ | |
cac5a3d8 DS |
2310 | int start_gc_thread(struct f2fs_sb_info *sbi); |
2311 | void stop_gc_thread(struct f2fs_sb_info *sbi); | |
2312 | block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); | |
2313 | int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background); | |
2314 | void build_gc_manager(struct f2fs_sb_info *sbi); | |
39a53e0c JK |
2315 | |
2316 | /* | |
2317 | * recovery.c | |
2318 | */ | |
cac5a3d8 DS |
2319 | int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); |
2320 | bool space_for_roll_forward(struct f2fs_sb_info *sbi); | |
39a53e0c JK |
2321 | |
2322 | /* | |
2323 | * debug.c | |
2324 | */ | |
2325 | #ifdef CONFIG_F2FS_STAT_FS | |
2326 | struct f2fs_stat_info { | |
2327 | struct list_head stat_list; | |
2328 | struct f2fs_sb_info *sbi; | |
39a53e0c JK |
2329 | int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; |
2330 | int main_area_segs, main_area_sections, main_area_zones; | |
5b7ee374 CY |
2331 | unsigned long long hit_largest, hit_cached, hit_rbtree; |
2332 | unsigned long long hit_total, total_ext; | |
c00ba554 | 2333 | int ext_tree, zombie_tree, ext_node; |
35782b23 JK |
2334 | int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; |
2335 | int inmem_pages; | |
0f18b462 | 2336 | unsigned int ndirty_dirs, ndirty_files, ndirty_all; |
b8559dc2 | 2337 | int nats, dirty_nats, sits, dirty_sits, free_nids, alloc_nids; |
39a53e0c | 2338 | int total_count, utilization; |
8b8dd65f CY |
2339 | int bg_gc, nr_wb_cp_data, nr_wb_data; |
2340 | int nr_flushing, nr_flushed, nr_discarding, nr_discarded; | |
5f32366a | 2341 | int nr_discard_cmd; |
a00861db | 2342 | int inline_xattr, inline_inode, inline_dir, append, update, orphans; |
648d50ba | 2343 | int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; |
f83a2584 | 2344 | unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; |
39a53e0c JK |
2345 | unsigned int bimodal, avg_vblocks; |
2346 | int util_free, util_valid, util_invalid; | |
2347 | int rsvd_segs, overp_segs; | |
2348 | int dirty_count, node_pages, meta_pages; | |
42190d2a | 2349 | int prefree_count, call_count, cp_count, bg_cp_count; |
39a53e0c | 2350 | int tot_segs, node_segs, data_segs, free_segs, free_secs; |
e1235983 | 2351 | int bg_node_segs, bg_data_segs; |
39a53e0c | 2352 | int tot_blks, data_blks, node_blks; |
e1235983 | 2353 | int bg_data_blks, bg_node_blks; |
39a53e0c JK |
2354 | int curseg[NR_CURSEG_TYPE]; |
2355 | int cursec[NR_CURSEG_TYPE]; | |
2356 | int curzone[NR_CURSEG_TYPE]; | |
2357 | ||
2358 | unsigned int segment_count[2]; | |
2359 | unsigned int block_count[2]; | |
b9a2c252 | 2360 | unsigned int inplace_count; |
9edcdabf | 2361 | unsigned long long base_mem, cache_mem, page_mem; |
39a53e0c JK |
2362 | }; |
2363 | ||
963d4f7d GZ |
2364 | static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) |
2365 | { | |
6c311ec6 | 2366 | return (struct f2fs_stat_info *)sbi->stat_info; |
963d4f7d GZ |
2367 | } |
2368 | ||
942e0be6 | 2369 | #define stat_inc_cp_count(si) ((si)->cp_count++) |
42190d2a | 2370 | #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) |
dcdfff65 JK |
2371 | #define stat_inc_call_count(si) ((si)->call_count++) |
2372 | #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) | |
33fbd510 CY |
2373 | #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) |
2374 | #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) | |
5b7ee374 CY |
2375 | #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) |
2376 | #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) | |
2377 | #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) | |
2378 | #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) | |
d5e8f6c9 CY |
2379 | #define stat_inc_inline_xattr(inode) \ |
2380 | do { \ | |
2381 | if (f2fs_has_inline_xattr(inode)) \ | |
2382 | (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ | |
2383 | } while (0) | |
2384 | #define stat_dec_inline_xattr(inode) \ | |
2385 | do { \ | |
2386 | if (f2fs_has_inline_xattr(inode)) \ | |
2387 | (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ | |
2388 | } while (0) | |
0dbdc2ae JK |
2389 | #define stat_inc_inline_inode(inode) \ |
2390 | do { \ | |
2391 | if (f2fs_has_inline_data(inode)) \ | |
03e14d52 | 2392 | (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ |
0dbdc2ae JK |
2393 | } while (0) |
2394 | #define stat_dec_inline_inode(inode) \ | |
2395 | do { \ | |
2396 | if (f2fs_has_inline_data(inode)) \ | |
03e14d52 | 2397 | (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ |
0dbdc2ae | 2398 | } while (0) |
3289c061 JK |
2399 | #define stat_inc_inline_dir(inode) \ |
2400 | do { \ | |
2401 | if (f2fs_has_inline_dentry(inode)) \ | |
03e14d52 | 2402 | (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ |
3289c061 JK |
2403 | } while (0) |
2404 | #define stat_dec_inline_dir(inode) \ | |
2405 | do { \ | |
2406 | if (f2fs_has_inline_dentry(inode)) \ | |
03e14d52 | 2407 | (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ |
3289c061 | 2408 | } while (0) |
dcdfff65 JK |
2409 | #define stat_inc_seg_type(sbi, curseg) \ |
2410 | ((sbi)->segment_count[(curseg)->alloc_type]++) | |
2411 | #define stat_inc_block_count(sbi, curseg) \ | |
2412 | ((sbi)->block_count[(curseg)->alloc_type]++) | |
b9a2c252 CL |
2413 | #define stat_inc_inplace_blocks(sbi) \ |
2414 | (atomic_inc(&(sbi)->inplace_count)) | |
26a28a0c | 2415 | #define stat_inc_atomic_write(inode) \ |
cac5a3d8 | 2416 | (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) |
26a28a0c | 2417 | #define stat_dec_atomic_write(inode) \ |
cac5a3d8 | 2418 | (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) |
26a28a0c JK |
2419 | #define stat_update_max_atomic_write(inode) \ |
2420 | do { \ | |
2421 | int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ | |
2422 | int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ | |
2423 | if (cur > max) \ | |
2424 | atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ | |
2425 | } while (0) | |
648d50ba CY |
2426 | #define stat_inc_volatile_write(inode) \ |
2427 | (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) | |
2428 | #define stat_dec_volatile_write(inode) \ | |
2429 | (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) | |
2430 | #define stat_update_max_volatile_write(inode) \ | |
2431 | do { \ | |
2432 | int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ | |
2433 | int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ | |
2434 | if (cur > max) \ | |
2435 | atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ | |
2436 | } while (0) | |
e1235983 | 2437 | #define stat_inc_seg_count(sbi, type, gc_type) \ |
39a53e0c | 2438 | do { \ |
963d4f7d | 2439 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
68afcf2d TK |
2440 | si->tot_segs++; \ |
2441 | if ((type) == SUM_TYPE_DATA) { \ | |
39a53e0c | 2442 | si->data_segs++; \ |
e1235983 CL |
2443 | si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ |
2444 | } else { \ | |
39a53e0c | 2445 | si->node_segs++; \ |
e1235983 CL |
2446 | si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ |
2447 | } \ | |
39a53e0c JK |
2448 | } while (0) |
2449 | ||
2450 | #define stat_inc_tot_blk_count(si, blks) \ | |
68afcf2d | 2451 | ((si)->tot_blks += (blks)) |
39a53e0c | 2452 | |
e1235983 | 2453 | #define stat_inc_data_blk_count(sbi, blks, gc_type) \ |
39a53e0c | 2454 | do { \ |
963d4f7d | 2455 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
39a53e0c JK |
2456 | stat_inc_tot_blk_count(si, blks); \ |
2457 | si->data_blks += (blks); \ | |
68afcf2d | 2458 | si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ |
39a53e0c JK |
2459 | } while (0) |
2460 | ||
e1235983 | 2461 | #define stat_inc_node_blk_count(sbi, blks, gc_type) \ |
39a53e0c | 2462 | do { \ |
963d4f7d | 2463 | struct f2fs_stat_info *si = F2FS_STAT(sbi); \ |
39a53e0c JK |
2464 | stat_inc_tot_blk_count(si, blks); \ |
2465 | si->node_blks += (blks); \ | |
68afcf2d | 2466 | si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ |
39a53e0c JK |
2467 | } while (0) |
2468 | ||
cac5a3d8 DS |
2469 | int f2fs_build_stats(struct f2fs_sb_info *sbi); |
2470 | void f2fs_destroy_stats(struct f2fs_sb_info *sbi); | |
787c7b8c | 2471 | int __init f2fs_create_root_stats(void); |
4589d25d | 2472 | void f2fs_destroy_root_stats(void); |
39a53e0c | 2473 | #else |
942e0be6 | 2474 | #define stat_inc_cp_count(si) |
42190d2a | 2475 | #define stat_inc_bg_cp_count(si) |
39a53e0c | 2476 | #define stat_inc_call_count(si) |
dcdfff65 | 2477 | #define stat_inc_bggc_count(si) |
33fbd510 CY |
2478 | #define stat_inc_dirty_inode(sbi, type) |
2479 | #define stat_dec_dirty_inode(sbi, type) | |
dcdfff65 | 2480 | #define stat_inc_total_hit(sb) |
029e13cc | 2481 | #define stat_inc_rbtree_node_hit(sb) |
91c481ff CY |
2482 | #define stat_inc_largest_node_hit(sbi) |
2483 | #define stat_inc_cached_node_hit(sbi) | |
d5e8f6c9 CY |
2484 | #define stat_inc_inline_xattr(inode) |
2485 | #define stat_dec_inline_xattr(inode) | |
0dbdc2ae JK |
2486 | #define stat_inc_inline_inode(inode) |
2487 | #define stat_dec_inline_inode(inode) | |
3289c061 JK |
2488 | #define stat_inc_inline_dir(inode) |
2489 | #define stat_dec_inline_dir(inode) | |
26a28a0c JK |
2490 | #define stat_inc_atomic_write(inode) |
2491 | #define stat_dec_atomic_write(inode) | |
2492 | #define stat_update_max_atomic_write(inode) | |
648d50ba CY |
2493 | #define stat_inc_volatile_write(inode) |
2494 | #define stat_dec_volatile_write(inode) | |
2495 | #define stat_update_max_volatile_write(inode) | |
dcdfff65 JK |
2496 | #define stat_inc_seg_type(sbi, curseg) |
2497 | #define stat_inc_block_count(sbi, curseg) | |
b9a2c252 | 2498 | #define stat_inc_inplace_blocks(sbi) |
e1235983 | 2499 | #define stat_inc_seg_count(sbi, type, gc_type) |
39a53e0c | 2500 | #define stat_inc_tot_blk_count(si, blks) |
e1235983 CL |
2501 | #define stat_inc_data_blk_count(sbi, blks, gc_type) |
2502 | #define stat_inc_node_blk_count(sbi, blks, gc_type) | |
39a53e0c JK |
2503 | |
2504 | static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } | |
2505 | static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } | |
787c7b8c | 2506 | static inline int __init f2fs_create_root_stats(void) { return 0; } |
4589d25d | 2507 | static inline void f2fs_destroy_root_stats(void) { } |
39a53e0c JK |
2508 | #endif |
2509 | ||
2510 | extern const struct file_operations f2fs_dir_operations; | |
2511 | extern const struct file_operations f2fs_file_operations; | |
2512 | extern const struct inode_operations f2fs_file_inode_operations; | |
2513 | extern const struct address_space_operations f2fs_dblock_aops; | |
2514 | extern const struct address_space_operations f2fs_node_aops; | |
2515 | extern const struct address_space_operations f2fs_meta_aops; | |
2516 | extern const struct inode_operations f2fs_dir_inode_operations; | |
2517 | extern const struct inode_operations f2fs_symlink_inode_operations; | |
cbaf042a | 2518 | extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; |
39a53e0c | 2519 | extern const struct inode_operations f2fs_special_inode_operations; |
29e7043f | 2520 | extern struct kmem_cache *inode_entry_slab; |
1001b347 | 2521 | |
e18c65b2 HL |
2522 | /* |
2523 | * inline.c | |
2524 | */ | |
cac5a3d8 DS |
2525 | bool f2fs_may_inline_data(struct inode *inode); |
2526 | bool f2fs_may_inline_dentry(struct inode *inode); | |
2527 | void read_inline_data(struct page *page, struct page *ipage); | |
bd4667cb | 2528 | void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); |
cac5a3d8 DS |
2529 | int f2fs_read_inline_data(struct inode *inode, struct page *page); |
2530 | int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); | |
2531 | int f2fs_convert_inline_inode(struct inode *inode); | |
2532 | int f2fs_write_inline_data(struct inode *inode, struct page *page); | |
2533 | bool recover_inline_data(struct inode *inode, struct page *npage); | |
2534 | struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, | |
2535 | struct fscrypt_name *fname, struct page **res_page); | |
2536 | int make_empty_inline_dir(struct inode *inode, struct inode *parent, | |
2537 | struct page *ipage); | |
2538 | int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, | |
2539 | const struct qstr *orig_name, | |
2540 | struct inode *inode, nid_t ino, umode_t mode); | |
2541 | void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, | |
2542 | struct inode *dir, struct inode *inode); | |
2543 | bool f2fs_empty_inline_dir(struct inode *dir); | |
2544 | int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, | |
2545 | struct fscrypt_str *fstr); | |
2546 | int f2fs_inline_data_fiemap(struct inode *inode, | |
2547 | struct fiemap_extent_info *fieinfo, | |
2548 | __u64 start, __u64 len); | |
cde4de12 | 2549 | |
2658e50d JK |
2550 | /* |
2551 | * shrinker.c | |
2552 | */ | |
cac5a3d8 DS |
2553 | unsigned long f2fs_shrink_count(struct shrinker *shrink, |
2554 | struct shrink_control *sc); | |
2555 | unsigned long f2fs_shrink_scan(struct shrinker *shrink, | |
2556 | struct shrink_control *sc); | |
2557 | void f2fs_join_shrinker(struct f2fs_sb_info *sbi); | |
2558 | void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); | |
2658e50d | 2559 | |
a28ef1f5 CY |
2560 | /* |
2561 | * extent_cache.c | |
2562 | */ | |
cac5a3d8 DS |
2563 | unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); |
2564 | bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); | |
2565 | void f2fs_drop_extent_tree(struct inode *inode); | |
2566 | unsigned int f2fs_destroy_extent_node(struct inode *inode); | |
2567 | void f2fs_destroy_extent_tree(struct inode *inode); | |
2568 | bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, | |
2569 | struct extent_info *ei); | |
2570 | void f2fs_update_extent_cache(struct dnode_of_data *dn); | |
19b2c30d | 2571 | void f2fs_update_extent_cache_range(struct dnode_of_data *dn, |
cac5a3d8 DS |
2572 | pgoff_t fofs, block_t blkaddr, unsigned int len); |
2573 | void init_extent_cache_info(struct f2fs_sb_info *sbi); | |
a28ef1f5 CY |
2574 | int __init create_extent_cache(void); |
2575 | void destroy_extent_cache(void); | |
2576 | ||
cde4de12 JK |
2577 | /* |
2578 | * crypto support | |
2579 | */ | |
0b81d077 | 2580 | static inline bool f2fs_encrypted_inode(struct inode *inode) |
cde4de12 | 2581 | { |
cde4de12 | 2582 | return file_is_encrypt(inode); |
cde4de12 JK |
2583 | } |
2584 | ||
2585 | static inline void f2fs_set_encrypted_inode(struct inode *inode) | |
2586 | { | |
2587 | #ifdef CONFIG_F2FS_FS_ENCRYPTION | |
2588 | file_set_encrypt(inode); | |
2589 | #endif | |
2590 | } | |
2591 | ||
2592 | static inline bool f2fs_bio_encrypted(struct bio *bio) | |
2593 | { | |
0b81d077 | 2594 | return bio->bi_private != NULL; |
cde4de12 JK |
2595 | } |
2596 | ||
2597 | static inline int f2fs_sb_has_crypto(struct super_block *sb) | |
2598 | { | |
cde4de12 | 2599 | return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); |
cde4de12 | 2600 | } |
f424f664 | 2601 | |
0bfd7a09 | 2602 | static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) |
52763a4b | 2603 | { |
0bfd7a09 | 2604 | return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); |
52763a4b JK |
2605 | } |
2606 | ||
178053e2 DLM |
2607 | #ifdef CONFIG_BLK_DEV_ZONED |
2608 | static inline int get_blkz_type(struct f2fs_sb_info *sbi, | |
3c62be17 | 2609 | struct block_device *bdev, block_t blkaddr) |
178053e2 DLM |
2610 | { |
2611 | unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; | |
3c62be17 | 2612 | int i; |
178053e2 | 2613 | |
3c62be17 JK |
2614 | for (i = 0; i < sbi->s_ndevs; i++) |
2615 | if (FDEV(i).bdev == bdev) | |
2616 | return FDEV(i).blkz_type[zno]; | |
2617 | return -EINVAL; | |
178053e2 DLM |
2618 | } |
2619 | #endif | |
2620 | ||
96ba2dec | 2621 | static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) |
52763a4b | 2622 | { |
96ba2dec DLM |
2623 | struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); |
2624 | ||
2625 | return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); | |
52763a4b JK |
2626 | } |
2627 | ||
2628 | static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) | |
2629 | { | |
2630 | clear_opt(sbi, ADAPTIVE); | |
2631 | clear_opt(sbi, LFS); | |
2632 | ||
2633 | switch (mt) { | |
2634 | case F2FS_MOUNT_ADAPTIVE: | |
2635 | set_opt(sbi, ADAPTIVE); | |
2636 | break; | |
2637 | case F2FS_MOUNT_LFS: | |
2638 | set_opt(sbi, LFS); | |
2639 | break; | |
2640 | } | |
2641 | } | |
2642 | ||
fcc85a4d JK |
2643 | static inline bool f2fs_may_encrypt(struct inode *inode) |
2644 | { | |
2645 | #ifdef CONFIG_F2FS_FS_ENCRYPTION | |
886f56f9 | 2646 | umode_t mode = inode->i_mode; |
fcc85a4d JK |
2647 | |
2648 | return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); | |
2649 | #else | |
2650 | return 0; | |
2651 | #endif | |
2652 | } | |
2653 | ||
39a53e0c | 2654 | #endif |