f2fs: inject kmalloc failure
[deliverable/linux.git] / fs / f2fs / f2fs.h
CommitLineData
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>
0b81d077 25#include <linux/fscrypto.h>
43b6573b 26#include <crypto/hash.h>
39a53e0c 27
5d56b671 28#ifdef CONFIG_F2FS_CHECK_FS
9850cf4a 29#define f2fs_bug_on(sbi, condition) BUG_ON(condition)
5d56b671 30#else
9850cf4a
JK
31#define f2fs_bug_on(sbi, condition) \
32 do { \
33 if (unlikely(condition)) { \
34 WARN_ON(1); \
caf0047e 35 set_sbi_flag(sbi, SBI_NEED_FSCK); \
9850cf4a
JK
36 } \
37 } while (0)
5d56b671
JK
38#endif
39
2c63fead
JK
40#ifdef CONFIG_F2FS_FAULT_INJECTION
41enum {
42 FAULT_KMALLOC,
43 FAULT_MAX,
44};
45
46extern u32 f2fs_fault_rate;
47extern atomic_t f2fs_ops;
48extern char *fault_name[FAULT_MAX];
49
50static inline bool time_to_inject(int type)
51{
52 atomic_inc(&f2fs_ops);
53 if (f2fs_fault_rate && (atomic_read(&f2fs_ops) >= f2fs_fault_rate)) {
54 atomic_set(&f2fs_ops, 0);
55 printk("%sF2FS-fs : inject %s in %pF\n",
56 KERN_INFO,
57 fault_name[type],
58 __builtin_return_address(0));
59 return true;
60 }
61 return false;
62}
63#endif
64
39a53e0c
JK
65/*
66 * For mount options
67 */
68#define F2FS_MOUNT_BG_GC 0x00000001
69#define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
70#define F2FS_MOUNT_DISCARD 0x00000004
71#define F2FS_MOUNT_NOHEAP 0x00000008
72#define F2FS_MOUNT_XATTR_USER 0x00000010
73#define F2FS_MOUNT_POSIX_ACL 0x00000020
74#define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
444c580f 75#define F2FS_MOUNT_INLINE_XATTR 0x00000080
1001b347 76#define F2FS_MOUNT_INLINE_DATA 0x00000100
34d67deb
CY
77#define F2FS_MOUNT_INLINE_DENTRY 0x00000200
78#define F2FS_MOUNT_FLUSH_MERGE 0x00000400
79#define F2FS_MOUNT_NOBARRIER 0x00000800
d5053a34 80#define F2FS_MOUNT_FASTBOOT 0x00001000
89672159 81#define F2FS_MOUNT_EXTENT_CACHE 0x00002000
6aefd93b 82#define F2FS_MOUNT_FORCE_FG_GC 0x00004000
343f40f0 83#define F2FS_MOUNT_DATA_FLUSH 0x00008000
73faec4d 84#define F2FS_MOUNT_FAULT_INJECTION 0x00010000
39a53e0c
JK
85
86#define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
87#define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
88#define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
89
90#define ver_after(a, b) (typecheck(unsigned long long, a) && \
91 typecheck(unsigned long long, b) && \
92 ((long long)((a) - (b)) > 0))
93
a9841c4d
JK
94typedef u32 block_t; /*
95 * should not change u32, since it is the on-disk block
96 * address format, __le32.
97 */
39a53e0c
JK
98typedef u32 nid_t;
99
100struct f2fs_mount_info {
101 unsigned int opt;
102};
103
cde4de12
JK
104#define F2FS_FEATURE_ENCRYPT 0x0001
105
76f105a2
JK
106#define F2FS_HAS_FEATURE(sb, mask) \
107 ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
108#define F2FS_SET_FEATURE(sb, mask) \
109 F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)
110#define F2FS_CLEAR_FEATURE(sb, mask) \
111 F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)
112
39a53e0c
JK
113/*
114 * For checkpoint manager
115 */
116enum {
117 NAT_BITMAP,
118 SIT_BITMAP
119};
120
75ab4cb8
JK
121enum {
122 CP_UMOUNT,
119ee914 123 CP_FASTBOOT,
75ab4cb8 124 CP_SYNC,
10027551 125 CP_RECOVERY,
4b2fecc8 126 CP_DISCARD,
75ab4cb8
JK
127};
128
bba681cb
JK
129#define DEF_BATCHED_TRIM_SECTIONS 32
130#define BATCHED_TRIM_SEGMENTS(sbi) \
131 (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
a66cdd98
JK
132#define BATCHED_TRIM_BLOCKS(sbi) \
133 (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
60b99b48 134#define DEF_CP_INTERVAL 60 /* 60 secs */
d0239e1b 135#define DEF_IDLE_INTERVAL 120 /* 2 mins */
bba681cb 136
75ab4cb8
JK
137struct cp_control {
138 int reason;
4b2fecc8
JK
139 __u64 trim_start;
140 __u64 trim_end;
141 __u64 trim_minlen;
142 __u64 trimmed;
75ab4cb8
JK
143};
144
662befda 145/*
81c1a0f1 146 * For CP/NAT/SIT/SSA readahead
662befda
CY
147 */
148enum {
149 META_CP,
150 META_NAT,
81c1a0f1 151 META_SIT,
4c521f49
JK
152 META_SSA,
153 META_POR,
662befda
CY
154};
155
6451e041
JK
156/* for the list of ino */
157enum {
158 ORPHAN_INO, /* for orphan ino list */
fff04f90
JK
159 APPEND_INO, /* for append ino list */
160 UPDATE_INO, /* for update ino list */
6451e041
JK
161 MAX_INO_ENTRY, /* max. list */
162};
163
164struct ino_entry {
39a53e0c
JK
165 struct list_head list; /* list head */
166 nid_t ino; /* inode number */
167};
168
2710fd7e 169/* for the list of inodes to be GCed */
06292073 170struct inode_entry {
39a53e0c
JK
171 struct list_head list; /* list head */
172 struct inode *inode; /* vfs inode pointer */
173};
174
7fd9e544
JK
175/* for the list of blockaddresses to be discarded */
176struct discard_entry {
177 struct list_head list; /* list head */
178 block_t blkaddr; /* block address to be discarded */
179 int len; /* # of consecutive blocks of the discard */
180};
181
39a53e0c
JK
182/* for the list of fsync inodes, used only during recovery */
183struct fsync_inode_entry {
184 struct list_head list; /* list head */
185 struct inode *inode; /* vfs inode pointer */
c52e1b10
JK
186 block_t blkaddr; /* block address locating the last fsync */
187 block_t last_dentry; /* block address locating the last dentry */
39a53e0c
JK
188};
189
dfc08a12
CY
190#define nats_in_cursum(jnl) (le16_to_cpu(jnl->n_nats))
191#define sits_in_cursum(jnl) (le16_to_cpu(jnl->n_sits))
39a53e0c 192
dfc08a12
CY
193#define nat_in_journal(jnl, i) (jnl->nat_j.entries[i].ne)
194#define nid_in_journal(jnl, i) (jnl->nat_j.entries[i].nid)
195#define sit_in_journal(jnl, i) (jnl->sit_j.entries[i].se)
196#define segno_in_journal(jnl, i) (jnl->sit_j.entries[i].segno)
39a53e0c 197
dfc08a12
CY
198#define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl))
199#define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl))
309cc2b6 200
dfc08a12 201static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i)
39a53e0c 202{
dfc08a12
CY
203 int before = nats_in_cursum(journal);
204 journal->n_nats = cpu_to_le16(before + i);
39a53e0c
JK
205 return before;
206}
207
dfc08a12 208static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i)
39a53e0c 209{
dfc08a12
CY
210 int before = sits_in_cursum(journal);
211 journal->n_sits = cpu_to_le16(before + i);
39a53e0c
JK
212 return before;
213}
214
dfc08a12
CY
215static inline bool __has_cursum_space(struct f2fs_journal *journal,
216 int size, int type)
184a5cd2
CY
217{
218 if (type == NAT_JOURNAL)
dfc08a12
CY
219 return size <= MAX_NAT_JENTRIES(journal);
220 return size <= MAX_SIT_JENTRIES(journal);
184a5cd2
CY
221}
222
e9750824
NJ
223/*
224 * ioctl commands
225 */
88b88a66
JK
226#define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
227#define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
d49f3e89 228#define F2FS_IOC_GETVERSION FS_IOC_GETVERSION
88b88a66
JK
229
230#define F2FS_IOCTL_MAGIC 0xf5
231#define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
232#define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
02a1335f 233#define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
1e84371f
JK
234#define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)
235#define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
c1c1b583 236#define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6)
456b88e4 237#define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7)
d323d005 238#define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8)
e9750824 239
0b81d077
JK
240#define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
241#define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
242#define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT
f424f664 243
1abff93d
JK
244/*
245 * should be same as XFS_IOC_GOINGDOWN.
246 * Flags for going down operation used by FS_IOC_GOINGDOWN
247 */
248#define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */
249#define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */
250#define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */
251#define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */
c912a829 252#define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */
1abff93d 253
e9750824
NJ
254#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
255/*
256 * ioctl commands in 32 bit emulation
257 */
04ef4b62
CY
258#define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
259#define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
260#define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION
e9750824
NJ
261#endif
262
d323d005
CY
263struct f2fs_defragment {
264 u64 start;
265 u64 len;
266};
267
39a53e0c
JK
268/*
269 * For INODE and NODE manager
270 */
7b3cd7d6
JK
271/* for directory operations */
272struct f2fs_dentry_ptr {
d8c6822a 273 struct inode *inode;
7b3cd7d6
JK
274 const void *bitmap;
275 struct f2fs_dir_entry *dentry;
276 __u8 (*filename)[F2FS_SLOT_LEN];
277 int max;
278};
279
d8c6822a
JK
280static inline void make_dentry_ptr(struct inode *inode,
281 struct f2fs_dentry_ptr *d, void *src, int type)
7b3cd7d6 282{
d8c6822a
JK
283 d->inode = inode;
284
7b3cd7d6
JK
285 if (type == 1) {
286 struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src;
287 d->max = NR_DENTRY_IN_BLOCK;
288 d->bitmap = &t->dentry_bitmap;
289 d->dentry = t->dentry;
290 d->filename = t->filename;
291 } else {
292 struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src;
293 d->max = NR_INLINE_DENTRY;
294 d->bitmap = &t->dentry_bitmap;
295 d->dentry = t->dentry;
296 d->filename = t->filename;
297 }
298}
299
dbe6a5ff
JK
300/*
301 * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
302 * as its node offset to distinguish from index node blocks.
303 * But some bits are used to mark the node block.
304 */
305#define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
306 >> OFFSET_BIT_SHIFT)
266e97a8
JK
307enum {
308 ALLOC_NODE, /* allocate a new node page if needed */
309 LOOKUP_NODE, /* look up a node without readahead */
310 LOOKUP_NODE_RA, /*
311 * look up a node with readahead called
4f4124d0 312 * by get_data_block.
39a53e0c 313 */
266e97a8
JK
314};
315
a6db67f0 316#define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */
39a53e0c 317
817202d9
CY
318#define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */
319
13054c54
CY
320/* vector size for gang look-up from extent cache that consists of radix tree */
321#define EXT_TREE_VEC_SIZE 64
322
39a53e0c 323/* for in-memory extent cache entry */
13054c54
CY
324#define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */
325
326/* number of extent info in extent cache we try to shrink */
327#define EXTENT_CACHE_SHRINK_NUMBER 128
c11abd1a 328
39a53e0c 329struct extent_info {
13054c54
CY
330 unsigned int fofs; /* start offset in a file */
331 u32 blk; /* start block address of the extent */
332 unsigned int len; /* length of the extent */
333};
334
335struct extent_node {
336 struct rb_node rb_node; /* rb node located in rb-tree */
337 struct list_head list; /* node in global extent list of sbi */
338 struct extent_info ei; /* extent info */
201ef5e0 339 struct extent_tree *et; /* extent tree pointer */
13054c54
CY
340};
341
342struct extent_tree {
343 nid_t ino; /* inode number */
344 struct rb_root root; /* root of extent info rb-tree */
62c8af65 345 struct extent_node *cached_en; /* recently accessed extent node */
3e72f721 346 struct extent_info largest; /* largested extent info */
137d09f0 347 struct list_head list; /* to be used by sbi->zombie_list */
13054c54 348 rwlock_t lock; /* protect extent info rb-tree */
68e35385 349 atomic_t node_cnt; /* # of extent node in rb-tree*/
39a53e0c
JK
350};
351
003a3e1d
JK
352/*
353 * This structure is taken from ext4_map_blocks.
354 *
355 * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
356 */
357#define F2FS_MAP_NEW (1 << BH_New)
358#define F2FS_MAP_MAPPED (1 << BH_Mapped)
7f63eb77
JK
359#define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten)
360#define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
361 F2FS_MAP_UNWRITTEN)
003a3e1d
JK
362
363struct f2fs_map_blocks {
364 block_t m_pblk;
365 block_t m_lblk;
366 unsigned int m_len;
367 unsigned int m_flags;
da85985c 368 pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */
003a3e1d
JK
369};
370
e2b4e2bc
CY
371/* for flag in get_data_block */
372#define F2FS_GET_BLOCK_READ 0
373#define F2FS_GET_BLOCK_DIO 1
374#define F2FS_GET_BLOCK_FIEMAP 2
375#define F2FS_GET_BLOCK_BMAP 3
b439b103 376#define F2FS_GET_BLOCK_PRE_DIO 4
24b84912 377#define F2FS_GET_BLOCK_PRE_AIO 5
e2b4e2bc 378
39a53e0c
JK
379/*
380 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
381 */
382#define FADVISE_COLD_BIT 0x01
354a3399 383#define FADVISE_LOST_PINO_BIT 0x02
cde4de12 384#define FADVISE_ENCRYPT_BIT 0x04
e7d55452 385#define FADVISE_ENC_NAME_BIT 0x08
39a53e0c 386
b5492af7
JK
387#define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT)
388#define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT)
389#define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT)
390#define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT)
391#define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT)
392#define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT)
cde4de12
JK
393#define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT)
394#define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT)
395#define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT)
e7d55452
JK
396#define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT)
397#define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
cde4de12 398
ab9fa662
JK
399#define DEF_DIR_LEVEL 0
400
39a53e0c
JK
401struct f2fs_inode_info {
402 struct inode vfs_inode; /* serve a vfs inode */
403 unsigned long i_flags; /* keep an inode flags for ioctl */
404 unsigned char i_advise; /* use to give file attribute hints */
38431545 405 unsigned char i_dir_level; /* use for dentry level for large dir */
39a53e0c 406 unsigned int i_current_depth; /* use only in directory structure */
6666e6aa 407 unsigned int i_pino; /* parent inode number */
39a53e0c
JK
408 umode_t i_acl_mode; /* keep file acl mode temporarily */
409
410 /* Use below internally in f2fs*/
411 unsigned long flags; /* use to pass per-file flags */
d928bfbf 412 struct rw_semaphore i_sem; /* protect fi info */
a7ffdbe2 413 atomic_t dirty_pages; /* # of dirty pages */
39a53e0c
JK
414 f2fs_hash_t chash; /* hash value of given file name */
415 unsigned int clevel; /* maximum level of given file name */
416 nid_t i_xattr_nid; /* node id that contains xattrs */
e518ff81 417 unsigned long long xattr_ver; /* cp version of xattr modification */
88b88a66 418
2710fd7e 419 struct list_head dirty_list; /* linked in global dirty list */
88b88a66
JK
420 struct list_head inmem_pages; /* inmemory pages managed by f2fs */
421 struct mutex inmem_lock; /* lock for inmemory pages */
3e72f721 422 struct extent_tree *extent_tree; /* cached extent_tree entry */
39a53e0c
JK
423};
424
425static inline void get_extent_info(struct extent_info *ext,
426 struct f2fs_extent i_ext)
427{
39a53e0c 428 ext->fofs = le32_to_cpu(i_ext.fofs);
4d0b0bd4 429 ext->blk = le32_to_cpu(i_ext.blk);
39a53e0c 430 ext->len = le32_to_cpu(i_ext.len);
39a53e0c
JK
431}
432
433static inline void set_raw_extent(struct extent_info *ext,
434 struct f2fs_extent *i_ext)
435{
39a53e0c 436 i_ext->fofs = cpu_to_le32(ext->fofs);
4d0b0bd4 437 i_ext->blk = cpu_to_le32(ext->blk);
39a53e0c 438 i_ext->len = cpu_to_le32(ext->len);
39a53e0c
JK
439}
440
429511cd
CY
441static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
442 u32 blk, unsigned int len)
443{
444 ei->fofs = fofs;
445 ei->blk = blk;
446 ei->len = len;
447}
448
0bdee482
CY
449static inline bool __is_extent_same(struct extent_info *ei1,
450 struct extent_info *ei2)
451{
452 return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk &&
453 ei1->len == ei2->len);
454}
455
429511cd
CY
456static inline bool __is_extent_mergeable(struct extent_info *back,
457 struct extent_info *front)
458{
459 return (back->fofs + back->len == front->fofs &&
460 back->blk + back->len == front->blk);
461}
462
463static inline bool __is_back_mergeable(struct extent_info *cur,
464 struct extent_info *back)
465{
466 return __is_extent_mergeable(back, cur);
467}
468
469static inline bool __is_front_mergeable(struct extent_info *cur,
470 struct extent_info *front)
471{
472 return __is_extent_mergeable(cur, front);
473}
474
4abd3f5a
CY
475static inline void __try_update_largest_extent(struct extent_tree *et,
476 struct extent_node *en)
477{
478 if (en->ei.len > et->largest.len)
479 et->largest = en->ei;
480}
481
39a53e0c
JK
482struct f2fs_nm_info {
483 block_t nat_blkaddr; /* base disk address of NAT */
484 nid_t max_nid; /* maximum possible node ids */
7ee0eeab 485 nid_t available_nids; /* maximum available node ids */
39a53e0c 486 nid_t next_scan_nid; /* the next nid to be scanned */
cdfc41c1 487 unsigned int ram_thresh; /* control the memory footprint */
ea1a29a0 488 unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */
2304cb0c 489 unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */
39a53e0c
JK
490
491 /* NAT cache management */
492 struct radix_tree_root nat_root;/* root of the nat entry cache */
309cc2b6 493 struct radix_tree_root nat_set_root;/* root of the nat set cache */
8b26ef98 494 struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */
39a53e0c 495 struct list_head nat_entries; /* cached nat entry list (clean) */
309cc2b6 496 unsigned int nat_cnt; /* the # of cached nat entries */
aec71382 497 unsigned int dirty_nat_cnt; /* total num of nat entries in set */
39a53e0c
JK
498
499 /* free node ids management */
8a7ed66a 500 struct radix_tree_root free_nid_root;/* root of the free_nid cache */
39a53e0c
JK
501 struct list_head free_nid_list; /* a list for free nids */
502 spinlock_t free_nid_list_lock; /* protect free nid list */
503 unsigned int fcnt; /* the number of free node id */
504 struct mutex build_lock; /* lock for build free nids */
505
506 /* for checkpoint */
507 char *nat_bitmap; /* NAT bitmap pointer */
508 int bitmap_size; /* bitmap size */
509};
510
511/*
512 * this structure is used as one of function parameters.
513 * all the information are dedicated to a given direct node block determined
514 * by the data offset in a file.
515 */
516struct dnode_of_data {
517 struct inode *inode; /* vfs inode pointer */
518 struct page *inode_page; /* its inode page, NULL is possible */
519 struct page *node_page; /* cached direct node page */
520 nid_t nid; /* node id of the direct node block */
521 unsigned int ofs_in_node; /* data offset in the node page */
522 bool inode_page_locked; /* inode page is locked or not */
93bae099 523 bool node_changed; /* is node block changed */
3cf45747
CY
524 char cur_level; /* level of hole node page */
525 char max_level; /* level of current page located */
39a53e0c
JK
526 block_t data_blkaddr; /* block address of the node block */
527};
528
529static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
530 struct page *ipage, struct page *npage, nid_t nid)
531{
d66d1f76 532 memset(dn, 0, sizeof(*dn));
39a53e0c
JK
533 dn->inode = inode;
534 dn->inode_page = ipage;
535 dn->node_page = npage;
536 dn->nid = nid;
39a53e0c
JK
537}
538
539/*
540 * For SIT manager
541 *
542 * By default, there are 6 active log areas across the whole main area.
543 * When considering hot and cold data separation to reduce cleaning overhead,
544 * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
545 * respectively.
546 * In the current design, you should not change the numbers intentionally.
547 * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
548 * logs individually according to the underlying devices. (default: 6)
549 * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
550 * data and 8 for node logs.
551 */
552#define NR_CURSEG_DATA_TYPE (3)
553#define NR_CURSEG_NODE_TYPE (3)
554#define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
555
556enum {
557 CURSEG_HOT_DATA = 0, /* directory entry blocks */
558 CURSEG_WARM_DATA, /* data blocks */
559 CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
560 CURSEG_HOT_NODE, /* direct node blocks of directory files */
561 CURSEG_WARM_NODE, /* direct node blocks of normal files */
562 CURSEG_COLD_NODE, /* indirect node blocks */
38aa0889
JK
563 NO_CHECK_TYPE,
564 CURSEG_DIRECT_IO, /* to use for the direct IO path */
39a53e0c
JK
565};
566
6b4afdd7 567struct flush_cmd {
6b4afdd7 568 struct completion wait;
721bd4d5 569 struct llist_node llnode;
6b4afdd7
JK
570 int ret;
571};
572
a688b9d9
GZ
573struct flush_cmd_control {
574 struct task_struct *f2fs_issue_flush; /* flush thread */
575 wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */
721bd4d5
GZ
576 struct llist_head issue_list; /* list for command issue */
577 struct llist_node *dispatch_list; /* list for command dispatch */
a688b9d9
GZ
578};
579
39a53e0c
JK
580struct f2fs_sm_info {
581 struct sit_info *sit_info; /* whole segment information */
582 struct free_segmap_info *free_info; /* free segment information */
583 struct dirty_seglist_info *dirty_info; /* dirty segment information */
584 struct curseg_info *curseg_array; /* active segment information */
585
39a53e0c
JK
586 block_t seg0_blkaddr; /* block address of 0'th segment */
587 block_t main_blkaddr; /* start block address of main area */
588 block_t ssa_blkaddr; /* start block address of SSA area */
589
590 unsigned int segment_count; /* total # of segments */
591 unsigned int main_segments; /* # of segments in main area */
592 unsigned int reserved_segments; /* # of reserved segments */
593 unsigned int ovp_segments; /* # of overprovision segments */
81eb8d6e
JK
594
595 /* a threshold to reclaim prefree segments */
596 unsigned int rec_prefree_segments;
7fd9e544
JK
597
598 /* for small discard management */
599 struct list_head discard_list; /* 4KB discard list */
600 int nr_discards; /* # of discards in the list */
601 int max_discards; /* max. discards to be issued */
216fbd64 602
bba681cb
JK
603 /* for batched trimming */
604 unsigned int trim_sections; /* # of sections to trim */
605
184a5cd2
CY
606 struct list_head sit_entry_set; /* sit entry set list */
607
216fbd64
JK
608 unsigned int ipu_policy; /* in-place-update policy */
609 unsigned int min_ipu_util; /* in-place-update threshold */
c1ce1b02 610 unsigned int min_fsync_blocks; /* threshold for fsync */
6b4afdd7
JK
611
612 /* for flush command control */
a688b9d9
GZ
613 struct flush_cmd_control *cmd_control_info;
614
39a53e0c
JK
615};
616
39a53e0c
JK
617/*
618 * For superblock
619 */
620/*
621 * COUNT_TYPE for monitoring
622 *
623 * f2fs monitors the number of several block types such as on-writeback,
624 * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
625 */
626enum count_type {
627 F2FS_WRITEBACK,
628 F2FS_DIRTY_DENTS,
c227f912 629 F2FS_DIRTY_DATA,
39a53e0c
JK
630 F2FS_DIRTY_NODES,
631 F2FS_DIRTY_META,
8dcf2ff7 632 F2FS_INMEM_PAGES,
39a53e0c
JK
633 NR_COUNT_TYPE,
634};
635
39a53e0c 636/*
e1c42045 637 * The below are the page types of bios used in submit_bio().
39a53e0c
JK
638 * The available types are:
639 * DATA User data pages. It operates as async mode.
640 * NODE Node pages. It operates as async mode.
641 * META FS metadata pages such as SIT, NAT, CP.
642 * NR_PAGE_TYPE The number of page types.
643 * META_FLUSH Make sure the previous pages are written
644 * with waiting the bio's completion
645 * ... Only can be used with META.
646 */
7d5e5109 647#define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type))
39a53e0c
JK
648enum page_type {
649 DATA,
650 NODE,
651 META,
652 NR_PAGE_TYPE,
653 META_FLUSH,
8ce67cb0
JK
654 INMEM, /* the below types are used by tracepoints only. */
655 INMEM_DROP,
28bc106b 656 INMEM_REVOKE,
8ce67cb0
JK
657 IPU,
658 OPU,
39a53e0c
JK
659};
660
458e6197 661struct f2fs_io_info {
05ca3632 662 struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */
7e8f2308
GZ
663 enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
664 int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */
7a9d7548 665 block_t new_blkaddr; /* new block address to be written */
28bc106b 666 block_t old_blkaddr; /* old block address before Cow */
05ca3632 667 struct page *page; /* page to be written */
4375a336 668 struct page *encrypted_page; /* encrypted page */
458e6197
JK
669};
670
93dfe2ac 671#define is_read_io(rw) (((rw) & 1) == READ)
1ff7bd3b 672struct f2fs_bio_info {
458e6197 673 struct f2fs_sb_info *sbi; /* f2fs superblock */
1ff7bd3b
JK
674 struct bio *bio; /* bios to merge */
675 sector_t last_block_in_bio; /* last block number */
458e6197 676 struct f2fs_io_info fio; /* store buffered io info. */
df0f8dc0 677 struct rw_semaphore io_rwsem; /* blocking op for bio */
1ff7bd3b
JK
678};
679
c227f912
CY
680enum inode_type {
681 DIR_INODE, /* for dirty dir inode */
682 FILE_INODE, /* for dirty regular/symlink inode */
683 NR_INODE_TYPE,
684};
685
67298804
CY
686/* for inner inode cache management */
687struct inode_management {
688 struct radix_tree_root ino_root; /* ino entry array */
689 spinlock_t ino_lock; /* for ino entry lock */
690 struct list_head ino_list; /* inode list head */
691 unsigned long ino_num; /* number of entries */
692};
693
caf0047e
CY
694/* For s_flag in struct f2fs_sb_info */
695enum {
696 SBI_IS_DIRTY, /* dirty flag for checkpoint */
697 SBI_IS_CLOSE, /* specify unmounting */
698 SBI_NEED_FSCK, /* need fsck.f2fs to fix */
699 SBI_POR_DOING, /* recovery is doing or not */
df728b0f 700 SBI_NEED_SB_WRITE, /* need to recover superblock */
caf0047e
CY
701};
702
6beceb54
JK
703enum {
704 CP_TIME,
d0239e1b 705 REQ_TIME,
6beceb54
JK
706 MAX_TIME,
707};
708
39a53e0c
JK
709struct f2fs_sb_info {
710 struct super_block *sb; /* pointer to VFS super block */
5e176d54 711 struct proc_dir_entry *s_proc; /* proc entry */
39a53e0c 712 struct f2fs_super_block *raw_super; /* raw super block pointer */
e8240f65 713 int valid_super_block; /* valid super block no */
caf0047e 714 int s_flag; /* flags for sbi */
39a53e0c
JK
715
716 /* for node-related operations */
717 struct f2fs_nm_info *nm_info; /* node manager */
718 struct inode *node_inode; /* cache node blocks */
719
720 /* for segment-related operations */
721 struct f2fs_sm_info *sm_info; /* segment manager */
1ff7bd3b
JK
722
723 /* for bio operations */
924b720b 724 struct f2fs_bio_info read_io; /* for read bios */
1ff7bd3b 725 struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */
39a53e0c
JK
726
727 /* for checkpoint */
728 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
729 struct inode *meta_inode; /* cache meta blocks */
39936837 730 struct mutex cp_mutex; /* checkpoint procedure lock */
e479556b 731 struct rw_semaphore cp_rwsem; /* blocking FS operations */
b3582c68 732 struct rw_semaphore node_write; /* locking node writes */
5463e7c1 733 struct mutex writepages; /* mutex for writepages() */
fb51b5ef 734 wait_queue_head_t cp_wait;
6beceb54
JK
735 unsigned long last_time[MAX_TIME]; /* to store time in jiffies */
736 long interval_time[MAX_TIME]; /* to store thresholds */
39a53e0c 737
67298804 738 struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
6451e041
JK
739
740 /* for orphan inode, use 0'th array */
0d47c1ad 741 unsigned int max_orphans; /* max orphan inodes */
39a53e0c 742
c227f912
CY
743 /* for inode management */
744 struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */
745 spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */
39a53e0c 746
13054c54
CY
747 /* for extent tree cache */
748 struct radix_tree_root extent_tree_root;/* cache extent cache entries */
749 struct rw_semaphore extent_tree_lock; /* locking extent radix tree */
750 struct list_head extent_list; /* lru list for shrinker */
751 spinlock_t extent_lock; /* locking extent lru list */
7441ccef 752 atomic_t total_ext_tree; /* extent tree count */
137d09f0 753 struct list_head zombie_list; /* extent zombie tree list */
74fd8d99 754 atomic_t total_zombie_tree; /* extent zombie tree count */
13054c54
CY
755 atomic_t total_ext_node; /* extent info count */
756
e1c42045 757 /* basic filesystem units */
39a53e0c
JK
758 unsigned int log_sectors_per_block; /* log2 sectors per block */
759 unsigned int log_blocksize; /* log2 block size */
760 unsigned int blocksize; /* block size */
761 unsigned int root_ino_num; /* root inode number*/
762 unsigned int node_ino_num; /* node inode number*/
763 unsigned int meta_ino_num; /* meta inode number*/
764 unsigned int log_blocks_per_seg; /* log2 blocks per segment */
765 unsigned int blocks_per_seg; /* blocks per segment */
766 unsigned int segs_per_sec; /* segments per section */
767 unsigned int secs_per_zone; /* sections per zone */
768 unsigned int total_sections; /* total section count */
769 unsigned int total_node_count; /* total node block count */
770 unsigned int total_valid_node_count; /* valid node block count */
771 unsigned int total_valid_inode_count; /* valid inode count */
e0afc4d6 772 loff_t max_file_blocks; /* max block index of file */
39a53e0c 773 int active_logs; /* # of active logs */
ab9fa662 774 int dir_level; /* directory level */
39a53e0c
JK
775
776 block_t user_block_count; /* # of user blocks */
777 block_t total_valid_block_count; /* # of valid blocks */
778 block_t alloc_valid_block_count; /* # of allocated blocks */
a66cdd98 779 block_t discard_blks; /* discard command candidats */
39a53e0c
JK
780 block_t last_valid_block_count; /* for recovery */
781 u32 s_next_generation; /* for NFS support */
782 atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
783
784 struct f2fs_mount_info mount_opt; /* mount options */
785
786 /* for cleaning operations */
787 struct mutex gc_mutex; /* mutex for GC */
788 struct f2fs_gc_kthread *gc_thread; /* GC thread */
5ec4e49f 789 unsigned int cur_victim_sec; /* current victim section num */
39a53e0c 790
b1c57c1c
JK
791 /* maximum # of trials to find a victim segment for SSR and GC */
792 unsigned int max_victim_search;
793
39a53e0c
JK
794 /*
795 * for stat information.
796 * one is for the LFS mode, and the other is for the SSR mode.
797 */
35b09d82 798#ifdef CONFIG_F2FS_STAT_FS
39a53e0c
JK
799 struct f2fs_stat_info *stat_info; /* FS status information */
800 unsigned int segment_count[2]; /* # of allocated segments */
801 unsigned int block_count[2]; /* # of allocated blocks */
b9a2c252 802 atomic_t inplace_count; /* # of inplace update */
5b7ee374
CY
803 atomic64_t total_hit_ext; /* # of lookup extent cache */
804 atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */
805 atomic64_t read_hit_largest; /* # of hit largest extent node */
806 atomic64_t read_hit_cached; /* # of hit cached extent node */
d5e8f6c9 807 atomic_t inline_xattr; /* # of inline_xattr inodes */
03e14d52
CY
808 atomic_t inline_inode; /* # of inline_data inodes */
809 atomic_t inline_dir; /* # of inline_dentry inodes */
39a53e0c 810 int bg_gc; /* background gc calls */
33fbd510 811 unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */
35b09d82
NJ
812#endif
813 unsigned int last_victim[2]; /* last victim segment # */
39a53e0c 814 spinlock_t stat_lock; /* lock for stat operations */
b59d0bae
NJ
815
816 /* For sysfs suppport */
817 struct kobject s_kobj;
818 struct completion s_kobj_unregister;
2658e50d
JK
819
820 /* For shrinker support */
821 struct list_head s_list;
822 struct mutex umount_mutex;
823 unsigned int shrinker_run_no;
8f1dbbbb
SL
824
825 /* For write statistics */
826 u64 sectors_written_start;
827 u64 kbytes_written;
43b6573b
KM
828
829 /* Reference to checksum algorithm driver via cryptoapi */
830 struct crypto_shash *s_chksum_driver;
39a53e0c
JK
831};
832
8f1dbbbb
SL
833/* For write statistics. Suppose sector size is 512 bytes,
834 * and the return value is in kbytes. s is of struct f2fs_sb_info.
835 */
836#define BD_PART_WRITTEN(s) \
837(((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) - \
838 s->sectors_written_start) >> 1)
839
6beceb54
JK
840static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
841{
842 sbi->last_time[type] = jiffies;
843}
844
845static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type)
846{
847 struct timespec ts = {sbi->interval_time[type], 0};
848 unsigned long interval = timespec_to_jiffies(&ts);
849
850 return time_after(jiffies, sbi->last_time[type] + interval);
851}
852
d0239e1b
JK
853static inline bool is_idle(struct f2fs_sb_info *sbi)
854{
855 struct block_device *bdev = sbi->sb->s_bdev;
856 struct request_queue *q = bdev_get_queue(bdev);
857 struct request_list *rl = &q->root_rl;
858
859 if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC])
860 return 0;
861
862 return f2fs_time_over(sbi, REQ_TIME);
863}
864
39a53e0c
JK
865/*
866 * Inline functions
867 */
43b6573b
KM
868static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
869 unsigned int length)
870{
871 SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver);
872 u32 *ctx = (u32 *)shash_desc_ctx(shash);
873 int err;
874
875 shash->tfm = sbi->s_chksum_driver;
876 shash->flags = 0;
877 *ctx = F2FS_SUPER_MAGIC;
878
879 err = crypto_shash_update(shash, address, length);
880 BUG_ON(err);
881
882 return *ctx;
883}
884
885static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
886 void *buf, size_t buf_size)
887{
888 return f2fs_crc32(sbi, buf, buf_size) == blk_crc;
889}
890
39a53e0c
JK
891static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
892{
893 return container_of(inode, struct f2fs_inode_info, vfs_inode);
894}
895
896static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
897{
898 return sb->s_fs_info;
899}
900
4081363f
JK
901static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
902{
903 return F2FS_SB(inode->i_sb);
904}
905
906static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
907{
908 return F2FS_I_SB(mapping->host);
909}
910
911static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
912{
913 return F2FS_M_SB(page->mapping);
914}
915
39a53e0c
JK
916static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
917{
918 return (struct f2fs_super_block *)(sbi->raw_super);
919}
920
921static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
922{
923 return (struct f2fs_checkpoint *)(sbi->ckpt);
924}
925
45590710
GZ
926static inline struct f2fs_node *F2FS_NODE(struct page *page)
927{
928 return (struct f2fs_node *)page_address(page);
929}
930
58bfaf44
JK
931static inline struct f2fs_inode *F2FS_INODE(struct page *page)
932{
933 return &((struct f2fs_node *)page_address(page))->i;
934}
935
39a53e0c
JK
936static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
937{
938 return (struct f2fs_nm_info *)(sbi->nm_info);
939}
940
941static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
942{
943 return (struct f2fs_sm_info *)(sbi->sm_info);
944}
945
946static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
947{
948 return (struct sit_info *)(SM_I(sbi)->sit_info);
949}
950
951static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
952{
953 return (struct free_segmap_info *)(SM_I(sbi)->free_info);
954}
955
956static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
957{
958 return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
959}
960
9df27d98
GZ
961static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
962{
963 return sbi->meta_inode->i_mapping;
964}
965
4ef51a8f
JK
966static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
967{
968 return sbi->node_inode->i_mapping;
969}
970
caf0047e
CY
971static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
972{
973 return sbi->s_flag & (0x01 << type);
974}
975
976static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
39a53e0c 977{
caf0047e 978 sbi->s_flag |= (0x01 << type);
39a53e0c
JK
979}
980
caf0047e 981static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
39a53e0c 982{
caf0047e 983 sbi->s_flag &= ~(0x01 << type);
39a53e0c
JK
984}
985
d71b5564
JK
986static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
987{
988 return le64_to_cpu(cp->checkpoint_ver);
989}
990
25ca923b
JK
991static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
992{
993 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
994 return ckpt_flags & f;
995}
996
997static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
998{
999 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
1000 ckpt_flags |= f;
1001 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
1002}
1003
1004static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1005{
1006 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
1007 ckpt_flags &= (~f);
1008 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
1009}
1010
e479556b 1011static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
39936837 1012{
e479556b 1013 down_read(&sbi->cp_rwsem);
39936837
JK
1014}
1015
e479556b 1016static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
39a53e0c 1017{
e479556b 1018 up_read(&sbi->cp_rwsem);
39a53e0c
JK
1019}
1020
e479556b 1021static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
39a53e0c 1022{
59692b7c 1023 down_write(&sbi->cp_rwsem);
39936837
JK
1024}
1025
e479556b 1026static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
39936837 1027{
e479556b 1028 up_write(&sbi->cp_rwsem);
39a53e0c
JK
1029}
1030
119ee914
JK
1031static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
1032{
1033 int reason = CP_SYNC;
1034
1035 if (test_opt(sbi, FASTBOOT))
1036 reason = CP_FASTBOOT;
1037 if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
1038 reason = CP_UMOUNT;
1039 return reason;
1040}
1041
1042static inline bool __remain_node_summaries(int reason)
1043{
1044 return (reason == CP_UMOUNT || reason == CP_FASTBOOT);
1045}
1046
1047static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
1048{
1049 return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) ||
1050 is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG));
1051}
1052
39a53e0c
JK
1053/*
1054 * Check whether the given nid is within node id range.
1055 */
064e0823 1056static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
39a53e0c 1057{
d6b7d4b3
CY
1058 if (unlikely(nid < F2FS_ROOT_INO(sbi)))
1059 return -EINVAL;
cfb271d4 1060 if (unlikely(nid >= NM_I(sbi)->max_nid))
064e0823
NJ
1061 return -EINVAL;
1062 return 0;
39a53e0c
JK
1063}
1064
1065#define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
1066
1067/*
1068 * Check whether the inode has blocks or not
1069 */
1070static inline int F2FS_HAS_BLOCKS(struct inode *inode)
1071{
1072 if (F2FS_I(inode)->i_xattr_nid)
6c311ec6 1073 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
39a53e0c 1074 else
6c311ec6 1075 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
39a53e0c
JK
1076}
1077
4bc8e9bc
CY
1078static inline bool f2fs_has_xattr_block(unsigned int ofs)
1079{
1080 return ofs == XATTR_NODE_OFFSET;
1081}
1082
39a53e0c
JK
1083static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
1084 struct inode *inode, blkcnt_t count)
1085{
1086 block_t valid_block_count;
1087
1088 spin_lock(&sbi->stat_lock);
1089 valid_block_count =
1090 sbi->total_valid_block_count + (block_t)count;
cfb271d4 1091 if (unlikely(valid_block_count > sbi->user_block_count)) {
39a53e0c
JK
1092 spin_unlock(&sbi->stat_lock);
1093 return false;
1094 }
1095 inode->i_blocks += count;
1096 sbi->total_valid_block_count = valid_block_count;
1097 sbi->alloc_valid_block_count += (block_t)count;
1098 spin_unlock(&sbi->stat_lock);
1099 return true;
1100}
1101
da19b0dc 1102static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
39a53e0c
JK
1103 struct inode *inode,
1104 blkcnt_t count)
1105{
1106 spin_lock(&sbi->stat_lock);
9850cf4a
JK
1107 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
1108 f2fs_bug_on(sbi, inode->i_blocks < count);
39a53e0c
JK
1109 inode->i_blocks -= count;
1110 sbi->total_valid_block_count -= (block_t)count;
1111 spin_unlock(&sbi->stat_lock);
39a53e0c
JK
1112}
1113
1114static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
1115{
1116 atomic_inc(&sbi->nr_pages[count_type]);
caf0047e 1117 set_sbi_flag(sbi, SBI_IS_DIRTY);
39a53e0c
JK
1118}
1119
a7ffdbe2 1120static inline void inode_inc_dirty_pages(struct inode *inode)
39a53e0c 1121{
a7ffdbe2 1122 atomic_inc(&F2FS_I(inode)->dirty_pages);
c227f912
CY
1123 inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1124 F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
39a53e0c
JK
1125}
1126
1127static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
1128{
1129 atomic_dec(&sbi->nr_pages[count_type]);
1130}
1131
a7ffdbe2 1132static inline void inode_dec_dirty_pages(struct inode *inode)
39a53e0c 1133{
5ac9f36f
CY
1134 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
1135 !S_ISLNK(inode->i_mode))
1fe54f9d
JK
1136 return;
1137
a7ffdbe2 1138 atomic_dec(&F2FS_I(inode)->dirty_pages);
c227f912
CY
1139 dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1140 F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
39a53e0c
JK
1141}
1142
1143static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
1144{
1145 return atomic_read(&sbi->nr_pages[count_type]);
1146}
1147
a7ffdbe2 1148static inline int get_dirty_pages(struct inode *inode)
f8b2c1f9 1149{
a7ffdbe2 1150 return atomic_read(&F2FS_I(inode)->dirty_pages);
f8b2c1f9
JK
1151}
1152
5ac206cf
NJ
1153static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
1154{
3519e3f9 1155 unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg;
5ac206cf
NJ
1156 return ((get_pages(sbi, block_type) + pages_per_sec - 1)
1157 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
1158}
1159
39a53e0c
JK
1160static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
1161{
8b8343fa 1162 return sbi->total_valid_block_count;
39a53e0c
JK
1163}
1164
1165static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
1166{
1167 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1168
1169 /* return NAT or SIT bitmap */
1170 if (flag == NAT_BITMAP)
1171 return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
1172 else if (flag == SIT_BITMAP)
1173 return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
1174
1175 return 0;
1176}
1177
55141486
WL
1178static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
1179{
1180 return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
1181}
1182
39a53e0c
JK
1183static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
1184{
1185 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1dbe4152
CL
1186 int offset;
1187
55141486 1188 if (__cp_payload(sbi) > 0) {
1dbe4152
CL
1189 if (flag == NAT_BITMAP)
1190 return &ckpt->sit_nat_version_bitmap;
1191 else
65b85ccc 1192 return (unsigned char *)ckpt + F2FS_BLKSIZE;
1dbe4152
CL
1193 } else {
1194 offset = (flag == NAT_BITMAP) ?
25ca923b 1195 le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
1dbe4152
CL
1196 return &ckpt->sit_nat_version_bitmap + offset;
1197 }
39a53e0c
JK
1198}
1199
1200static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
1201{
1202 block_t start_addr;
1203 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
d71b5564 1204 unsigned long long ckpt_version = cur_cp_version(ckpt);
39a53e0c 1205
25ca923b 1206 start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
39a53e0c
JK
1207
1208 /*
1209 * odd numbered checkpoint should at cp segment 0
e1c42045 1210 * and even segment must be at cp segment 1
39a53e0c
JK
1211 */
1212 if (!(ckpt_version & 1))
1213 start_addr += sbi->blocks_per_seg;
1214
1215 return start_addr;
1216}
1217
1218static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
1219{
1220 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
1221}
1222
1223static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
ef86d709 1224 struct inode *inode)
39a53e0c
JK
1225{
1226 block_t valid_block_count;
1227 unsigned int valid_node_count;
1228
1229 spin_lock(&sbi->stat_lock);
1230
ef86d709 1231 valid_block_count = sbi->total_valid_block_count + 1;
cfb271d4 1232 if (unlikely(valid_block_count > sbi->user_block_count)) {
39a53e0c
JK
1233 spin_unlock(&sbi->stat_lock);
1234 return false;
1235 }
1236
ef86d709 1237 valid_node_count = sbi->total_valid_node_count + 1;
cfb271d4 1238 if (unlikely(valid_node_count > sbi->total_node_count)) {
39a53e0c
JK
1239 spin_unlock(&sbi->stat_lock);
1240 return false;
1241 }
1242
1243 if (inode)
ef86d709
GZ
1244 inode->i_blocks++;
1245
1246 sbi->alloc_valid_block_count++;
1247 sbi->total_valid_node_count++;
1248 sbi->total_valid_block_count++;
39a53e0c
JK
1249 spin_unlock(&sbi->stat_lock);
1250
1251 return true;
1252}
1253
1254static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
ef86d709 1255 struct inode *inode)
39a53e0c
JK
1256{
1257 spin_lock(&sbi->stat_lock);
1258
9850cf4a
JK
1259 f2fs_bug_on(sbi, !sbi->total_valid_block_count);
1260 f2fs_bug_on(sbi, !sbi->total_valid_node_count);
1261 f2fs_bug_on(sbi, !inode->i_blocks);
39a53e0c 1262
ef86d709
GZ
1263 inode->i_blocks--;
1264 sbi->total_valid_node_count--;
1265 sbi->total_valid_block_count--;
39a53e0c
JK
1266
1267 spin_unlock(&sbi->stat_lock);
1268}
1269
1270static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
1271{
8b8343fa 1272 return sbi->total_valid_node_count;
39a53e0c
JK
1273}
1274
1275static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
1276{
1277 spin_lock(&sbi->stat_lock);
9850cf4a 1278 f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count);
39a53e0c
JK
1279 sbi->total_valid_inode_count++;
1280 spin_unlock(&sbi->stat_lock);
1281}
1282
0e80220a 1283static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
39a53e0c
JK
1284{
1285 spin_lock(&sbi->stat_lock);
9850cf4a 1286 f2fs_bug_on(sbi, !sbi->total_valid_inode_count);
39a53e0c
JK
1287 sbi->total_valid_inode_count--;
1288 spin_unlock(&sbi->stat_lock);
39a53e0c
JK
1289}
1290
1291static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
1292{
8b8343fa 1293 return sbi->total_valid_inode_count;
39a53e0c
JK
1294}
1295
a56c7c6f
JK
1296static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
1297 pgoff_t index, bool for_write)
1298{
1299 if (!for_write)
1300 return grab_cache_page(mapping, index);
1301 return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
1302}
1303
6e2c64ad
JK
1304static inline void f2fs_copy_page(struct page *src, struct page *dst)
1305{
1306 char *src_kaddr = kmap(src);
1307 char *dst_kaddr = kmap(dst);
1308
1309 memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
1310 kunmap(dst);
1311 kunmap(src);
1312}
1313
39a53e0c
JK
1314static inline void f2fs_put_page(struct page *page, int unlock)
1315{
031fa8cc 1316 if (!page)
39a53e0c
JK
1317 return;
1318
1319 if (unlock) {
9850cf4a 1320 f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
39a53e0c
JK
1321 unlock_page(page);
1322 }
09cbfeaf 1323 put_page(page);
39a53e0c
JK
1324}
1325
1326static inline void f2fs_put_dnode(struct dnode_of_data *dn)
1327{
1328 if (dn->node_page)
1329 f2fs_put_page(dn->node_page, 1);
1330 if (dn->inode_page && dn->node_page != dn->inode_page)
1331 f2fs_put_page(dn->inode_page, 0);
1332 dn->node_page = NULL;
1333 dn->inode_page = NULL;
1334}
1335
1336static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
e8512d2e 1337 size_t size)
39a53e0c 1338{
e8512d2e 1339 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
39a53e0c
JK
1340}
1341
7bd59381
GZ
1342static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
1343 gfp_t flags)
1344{
1345 void *entry;
7bd59381 1346
80c54505
JK
1347 entry = kmem_cache_alloc(cachep, flags);
1348 if (!entry)
1349 entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
7bd59381
GZ
1350 return entry;
1351}
1352
740432f8
JK
1353static inline struct bio *f2fs_bio_alloc(int npages)
1354{
1355 struct bio *bio;
1356
1357 /* No failure on bio allocation */
740432f8 1358 bio = bio_alloc(GFP_NOIO, npages);
80c54505
JK
1359 if (!bio)
1360 bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
740432f8
JK
1361 return bio;
1362}
1363
9be32d72
JK
1364static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
1365 unsigned long index, void *item)
1366{
1367 while (radix_tree_insert(root, index, item))
1368 cond_resched();
1369}
1370
39a53e0c
JK
1371#define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
1372
1373static inline bool IS_INODE(struct page *page)
1374{
45590710 1375 struct f2fs_node *p = F2FS_NODE(page);
39a53e0c
JK
1376 return RAW_IS_INODE(p);
1377}
1378
1379static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
1380{
1381 return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
1382}
1383
1384static inline block_t datablock_addr(struct page *node_page,
1385 unsigned int offset)
1386{
1387 struct f2fs_node *raw_node;
1388 __le32 *addr_array;
45590710 1389 raw_node = F2FS_NODE(node_page);
39a53e0c
JK
1390 addr_array = blkaddr_in_node(raw_node);
1391 return le32_to_cpu(addr_array[offset]);
1392}
1393
1394static inline int f2fs_test_bit(unsigned int nr, char *addr)
1395{
1396 int mask;
1397
1398 addr += (nr >> 3);
1399 mask = 1 << (7 - (nr & 0x07));
1400 return mask & *addr;
1401}
1402
a66cdd98
JK
1403static inline void f2fs_set_bit(unsigned int nr, char *addr)
1404{
1405 int mask;
1406
1407 addr += (nr >> 3);
1408 mask = 1 << (7 - (nr & 0x07));
1409 *addr |= mask;
1410}
1411
1412static inline void f2fs_clear_bit(unsigned int nr, char *addr)
1413{
1414 int mask;
1415
1416 addr += (nr >> 3);
1417 mask = 1 << (7 - (nr & 0x07));
1418 *addr &= ~mask;
1419}
1420
52aca074 1421static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
39a53e0c
JK
1422{
1423 int mask;
1424 int ret;
1425
1426 addr += (nr >> 3);
1427 mask = 1 << (7 - (nr & 0x07));
1428 ret = mask & *addr;
1429 *addr |= mask;
1430 return ret;
1431}
1432
52aca074 1433static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
39a53e0c
JK
1434{
1435 int mask;
1436 int ret;
1437
1438 addr += (nr >> 3);
1439 mask = 1 << (7 - (nr & 0x07));
1440 ret = mask & *addr;
1441 *addr &= ~mask;
1442 return ret;
1443}
1444
c6ac4c0e
GZ
1445static inline void f2fs_change_bit(unsigned int nr, char *addr)
1446{
1447 int mask;
1448
1449 addr += (nr >> 3);
1450 mask = 1 << (7 - (nr & 0x07));
1451 *addr ^= mask;
1452}
1453
39a53e0c
JK
1454/* used for f2fs_inode_info->flags */
1455enum {
1456 FI_NEW_INODE, /* indicate newly allocated inode */
b3783873 1457 FI_DIRTY_INODE, /* indicate inode is dirty or not */
ed57c27f 1458 FI_DIRTY_DIR, /* indicate directory has dirty pages */
39a53e0c
JK
1459 FI_INC_LINK, /* need to increment i_nlink */
1460 FI_ACL_MODE, /* indicate acl mode */
1461 FI_NO_ALLOC, /* should not allocate any blocks */
c9b63bd0 1462 FI_FREE_NID, /* free allocated nide */
699489bb 1463 FI_UPDATE_DIR, /* should update inode block for consistency */
74d0b917 1464 FI_DELAY_IPUT, /* used for the recovery */
c11abd1a 1465 FI_NO_EXTENT, /* not to use the extent cache */
444c580f 1466 FI_INLINE_XATTR, /* used for inline xattr */
1001b347 1467 FI_INLINE_DATA, /* used for inline data*/
34d67deb 1468 FI_INLINE_DENTRY, /* used for inline dentry */
fff04f90
JK
1469 FI_APPEND_WRITE, /* inode has appended data */
1470 FI_UPDATE_WRITE, /* inode has in-place-update data */
88b88a66
JK
1471 FI_NEED_IPU, /* used for ipu per file */
1472 FI_ATOMIC_FILE, /* indicate atomic file */
02a1335f 1473 FI_VOLATILE_FILE, /* indicate volatile file */
3c6c2beb 1474 FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */
1e84371f 1475 FI_DROP_CACHE, /* drop dirty page cache */
b3d208f9 1476 FI_DATA_EXIST, /* indicate data exists */
510022a8 1477 FI_INLINE_DOTS, /* indicate inline dot dentries */
d323d005 1478 FI_DO_DEFRAG, /* indicate defragment is running */
c227f912 1479 FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */
39a53e0c
JK
1480};
1481
1482static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
1483{
61e0f2d0
JK
1484 if (!test_bit(flag, &fi->flags))
1485 set_bit(flag, &fi->flags);
39a53e0c
JK
1486}
1487
1488static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
1489{
1490 return test_bit(flag, &fi->flags);
1491}
1492
1493static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
1494{
61e0f2d0
JK
1495 if (test_bit(flag, &fi->flags))
1496 clear_bit(flag, &fi->flags);
39a53e0c
JK
1497}
1498
1499static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
1500{
1501 fi->i_acl_mode = mode;
1502 set_inode_flag(fi, FI_ACL_MODE);
1503}
1504
444c580f
JK
1505static inline void get_inline_info(struct f2fs_inode_info *fi,
1506 struct f2fs_inode *ri)
1507{
1508 if (ri->i_inline & F2FS_INLINE_XATTR)
1509 set_inode_flag(fi, FI_INLINE_XATTR);
1001b347
HL
1510 if (ri->i_inline & F2FS_INLINE_DATA)
1511 set_inode_flag(fi, FI_INLINE_DATA);
34d67deb
CY
1512 if (ri->i_inline & F2FS_INLINE_DENTRY)
1513 set_inode_flag(fi, FI_INLINE_DENTRY);
b3d208f9
JK
1514 if (ri->i_inline & F2FS_DATA_EXIST)
1515 set_inode_flag(fi, FI_DATA_EXIST);
510022a8
JK
1516 if (ri->i_inline & F2FS_INLINE_DOTS)
1517 set_inode_flag(fi, FI_INLINE_DOTS);
444c580f
JK
1518}
1519
1520static inline void set_raw_inline(struct f2fs_inode_info *fi,
1521 struct f2fs_inode *ri)
1522{
1523 ri->i_inline = 0;
1524
1525 if (is_inode_flag_set(fi, FI_INLINE_XATTR))
1526 ri->i_inline |= F2FS_INLINE_XATTR;
1001b347
HL
1527 if (is_inode_flag_set(fi, FI_INLINE_DATA))
1528 ri->i_inline |= F2FS_INLINE_DATA;
34d67deb
CY
1529 if (is_inode_flag_set(fi, FI_INLINE_DENTRY))
1530 ri->i_inline |= F2FS_INLINE_DENTRY;
b3d208f9
JK
1531 if (is_inode_flag_set(fi, FI_DATA_EXIST))
1532 ri->i_inline |= F2FS_DATA_EXIST;
510022a8
JK
1533 if (is_inode_flag_set(fi, FI_INLINE_DOTS))
1534 ri->i_inline |= F2FS_INLINE_DOTS;
444c580f
JK
1535}
1536
987c7c31
CY
1537static inline int f2fs_has_inline_xattr(struct inode *inode)
1538{
1539 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR);
1540}
1541
81ca7350 1542static inline unsigned int addrs_per_inode(struct inode *inode)
de93653f 1543{
81ca7350 1544 if (f2fs_has_inline_xattr(inode))
de93653f
JK
1545 return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
1546 return DEF_ADDRS_PER_INODE;
1547}
1548
65985d93
JK
1549static inline void *inline_xattr_addr(struct page *page)
1550{
695fd1ed 1551 struct f2fs_inode *ri = F2FS_INODE(page);
65985d93
JK
1552 return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
1553 F2FS_INLINE_XATTR_ADDRS]);
1554}
1555
1556static inline int inline_xattr_size(struct inode *inode)
1557{
987c7c31 1558 if (f2fs_has_inline_xattr(inode))
65985d93
JK
1559 return F2FS_INLINE_XATTR_ADDRS << 2;
1560 else
1561 return 0;
1562}
1563
0dbdc2ae
JK
1564static inline int f2fs_has_inline_data(struct inode *inode)
1565{
1566 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
1567}
1568
b3d208f9
JK
1569static inline void f2fs_clear_inline_inode(struct inode *inode)
1570{
1571 clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
1572 clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST);
1573}
1574
1575static inline int f2fs_exist_data(struct inode *inode)
1576{
1577 return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST);
1578}
1579
510022a8
JK
1580static inline int f2fs_has_inline_dots(struct inode *inode)
1581{
1582 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS);
1583}
1584
88b88a66
JK
1585static inline bool f2fs_is_atomic_file(struct inode *inode)
1586{
1587 return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE);
1588}
1589
02a1335f
JK
1590static inline bool f2fs_is_volatile_file(struct inode *inode)
1591{
1592 return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE);
1593}
1594
3c6c2beb
JK
1595static inline bool f2fs_is_first_block_written(struct inode *inode)
1596{
1597 return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN);
1598}
1599
1e84371f
JK
1600static inline bool f2fs_is_drop_cache(struct inode *inode)
1601{
1602 return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE);
1603}
1604
1001b347
HL
1605static inline void *inline_data_addr(struct page *page)
1606{
695fd1ed 1607 struct f2fs_inode *ri = F2FS_INODE(page);
1001b347
HL
1608 return (void *)&(ri->i_addr[1]);
1609}
1610
34d67deb
CY
1611static inline int f2fs_has_inline_dentry(struct inode *inode)
1612{
1613 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY);
1614}
1615
9486ba44
JK
1616static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
1617{
1618 if (!f2fs_has_inline_dentry(dir))
1619 kunmap(page);
1620}
1621
b5492af7
JK
1622static inline int is_file(struct inode *inode, int type)
1623{
1624 return F2FS_I(inode)->i_advise & type;
1625}
1626
1627static inline void set_file(struct inode *inode, int type)
1628{
1629 F2FS_I(inode)->i_advise |= type;
1630}
1631
1632static inline void clear_file(struct inode *inode, int type)
1633{
1634 F2FS_I(inode)->i_advise &= ~type;
1635}
1636
77888c1e
JK
1637static inline int f2fs_readonly(struct super_block *sb)
1638{
1639 return sb->s_flags & MS_RDONLY;
1640}
1641
1e968fdf
JK
1642static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
1643{
1644 return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1645}
1646
744602cf
JK
1647static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi)
1648{
1649 set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1650 sbi->sb->s_flags |= MS_RDONLY;
1651}
1652
eaa693f4
JK
1653static inline bool is_dot_dotdot(const struct qstr *str)
1654{
1655 if (str->len == 1 && str->name[0] == '.')
1656 return true;
1657
1658 if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
1659 return true;
1660
1661 return false;
1662}
1663
3e72f721
JK
1664static inline bool f2fs_may_extent_tree(struct inode *inode)
1665{
3e72f721
JK
1666 if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) ||
1667 is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT))
1668 return false;
1669
886f56f9 1670 return S_ISREG(inode->i_mode);
3e72f721
JK
1671}
1672
0414b004
JK
1673static inline void *f2fs_kmalloc(size_t size, gfp_t flags)
1674{
2c63fead
JK
1675#ifdef CONFIG_F2FS_FAULT_INJECTION
1676 if (time_to_inject(FAULT_KMALLOC))
1677 return NULL;
1678#endif
0414b004
JK
1679 return kmalloc(size, flags);
1680}
1681
39307a8e
JK
1682static inline void *f2fs_kvmalloc(size_t size, gfp_t flags)
1683{
1684 void *ret;
1685
1686 ret = kmalloc(size, flags | __GFP_NOWARN);
1687 if (!ret)
1688 ret = __vmalloc(size, flags, PAGE_KERNEL);
1689 return ret;
1690}
1691
1692static inline void *f2fs_kvzalloc(size_t size, gfp_t flags)
1693{
1694 void *ret;
1695
1696 ret = kzalloc(size, flags | __GFP_NOWARN);
1697 if (!ret)
1698 ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
1699 return ret;
1700}
1701
a6dda0e6
CH
1702#define get_inode_mode(i) \
1703 ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
1704 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
1705
267378d4 1706/* get offset of first page in next direct node */
81ca7350
CY
1707#define PGOFS_OF_NEXT_DNODE(pgofs, inode) \
1708 ((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) : \
1709 (pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) / \
1710 ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode))
267378d4 1711
39a53e0c
JK
1712/*
1713 * file.c
1714 */
1715int f2fs_sync_file(struct file *, loff_t, loff_t, int);
1716void truncate_data_blocks(struct dnode_of_data *);
764aa3e9 1717int truncate_blocks(struct inode *, u64, bool);
b0154891 1718int f2fs_truncate(struct inode *, bool);
2d4d9fb5 1719int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
39a53e0c
JK
1720int f2fs_setattr(struct dentry *, struct iattr *);
1721int truncate_hole(struct inode *, pgoff_t, pgoff_t);
b292dcab 1722int truncate_data_blocks_range(struct dnode_of_data *, int);
39a53e0c 1723long f2fs_ioctl(struct file *, unsigned int, unsigned long);
e9750824 1724long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
39a53e0c
JK
1725
1726/*
1727 * inode.c
1728 */
1729void f2fs_set_inode_flags(struct inode *);
39a53e0c 1730struct inode *f2fs_iget(struct super_block *, unsigned long);
4660f9c0 1731int try_to_free_nats(struct f2fs_sb_info *, int);
12719ae1
JK
1732int update_inode(struct inode *, struct page *);
1733int update_inode_page(struct inode *);
39a53e0c
JK
1734int f2fs_write_inode(struct inode *, struct writeback_control *);
1735void f2fs_evict_inode(struct inode *);
44c16156 1736void handle_failed_inode(struct inode *);
39a53e0c
JK
1737
1738/*
1739 * namei.c
1740 */
1741struct dentry *f2fs_get_parent(struct dentry *child);
1742
1743/*
1744 * dir.c
1745 */
dbeacf02 1746extern unsigned char f2fs_filetype_table[F2FS_FT_MAX];
510022a8 1747void set_de_type(struct f2fs_dir_entry *, umode_t);
675f10bd 1748unsigned char get_de_type(struct f2fs_dir_entry *);
0b81d077 1749struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *,
6e22c691 1750 f2fs_hash_t, int *, struct f2fs_dentry_ptr *);
7b3cd7d6 1751bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *,
0b81d077 1752 unsigned int, struct fscrypt_str *);
062a3e7b
JK
1753void do_make_empty_dir(struct inode *, struct inode *,
1754 struct f2fs_dentry_ptr *);
dbeacf02 1755struct page *init_inode_metadata(struct inode *, struct inode *,
bce8d112 1756 const struct qstr *, struct page *);
dbeacf02 1757void update_parent_metadata(struct inode *, struct inode *, unsigned int);
a82afa20 1758int room_for_filename(const void *, int, int);
dbeacf02 1759void f2fs_drop_nlink(struct inode *, struct inode *, struct page *);
39a53e0c
JK
1760struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
1761 struct page **);
1762struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
1763ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
1764void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
1765 struct page *, struct inode *);
e7d55452 1766int update_dent_inode(struct inode *, struct inode *, const struct qstr *);
510022a8 1767void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *,
3b4d732a 1768 const struct qstr *, f2fs_hash_t , unsigned int);
675f10bd
CY
1769int f2fs_add_regular_entry(struct inode *, const struct qstr *,
1770 struct inode *, nid_t, umode_t);
510022a8
JK
1771int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t,
1772 umode_t);
dbeacf02
CY
1773void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *,
1774 struct inode *);
b97a9b5d 1775int f2fs_do_tmpfile(struct inode *, struct inode *);
39a53e0c
JK
1776bool f2fs_empty_dir(struct inode *);
1777
b7f7a5e0
AV
1778static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
1779{
2b0143b5 1780 return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name,
510022a8 1781 inode, inode->i_ino, inode->i_mode);
b7f7a5e0
AV
1782}
1783
39a53e0c
JK
1784/*
1785 * super.c
1786 */
c5bda1c8 1787int f2fs_commit_super(struct f2fs_sb_info *, bool);
39a53e0c 1788int f2fs_sync_fs(struct super_block *, int);
a07ef784
NJ
1789extern __printf(3, 4)
1790void f2fs_msg(struct super_block *, const char *, const char *, ...);
984ec63c 1791int sanity_check_ckpt(struct f2fs_sb_info *sbi);
39a53e0c
JK
1792
1793/*
1794 * hash.c
1795 */
eee6160f 1796f2fs_hash_t f2fs_dentry_hash(const struct qstr *);
39a53e0c
JK
1797
1798/*
1799 * node.c
1800 */
1801struct dnode_of_data;
1802struct node_info;
1803
6fb03f3a 1804bool available_free_memory(struct f2fs_sb_info *, int);
2dcf51ab 1805int need_dentry_mark(struct f2fs_sb_info *, nid_t);
88bd02c9 1806bool is_checkpointed_node(struct f2fs_sb_info *, nid_t);
88bd02c9 1807bool need_inode_block_update(struct f2fs_sb_info *, nid_t);
39a53e0c 1808void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
3cf45747 1809pgoff_t get_next_page_offset(struct dnode_of_data *, pgoff_t);
39a53e0c
JK
1810int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
1811int truncate_inode_blocks(struct inode *, pgoff_t);
4f16fb0f 1812int truncate_xattr_node(struct inode *, struct page *);
cfe58f9d 1813int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
13ec7297 1814int remove_inode_page(struct inode *);
a014e037 1815struct page *new_inode_page(struct inode *);
8ae8f162 1816struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
39a53e0c
JK
1817void ra_node_page(struct f2fs_sb_info *, nid_t);
1818struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
1819struct page *get_node_page_ra(struct page *, int);
1820void sync_inode_page(struct dnode_of_data *);
da011cc0 1821void move_node_page(struct page *, int);
608514de
JK
1822int fsync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *,
1823 bool);
52681375 1824int sync_node_pages(struct f2fs_sb_info *, struct writeback_control *);
39a53e0c
JK
1825bool alloc_nid(struct f2fs_sb_info *, nid_t *);
1826void alloc_nid_done(struct f2fs_sb_info *, nid_t);
1827void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
31696580 1828int try_to_free_nids(struct f2fs_sb_info *, int);
70cfed88 1829void recover_inline_xattr(struct inode *, struct page *);
1c35a90e 1830void recover_xattr_data(struct inode *, struct page *, block_t);
39a53e0c
JK
1831int recover_inode_page(struct f2fs_sb_info *, struct page *);
1832int restore_node_summary(struct f2fs_sb_info *, unsigned int,
1833 struct f2fs_summary_block *);
1834void flush_nat_entries(struct f2fs_sb_info *);
1835int build_node_manager(struct f2fs_sb_info *);
1836void destroy_node_manager(struct f2fs_sb_info *);
6e6093a8 1837int __init create_node_manager_caches(void);
39a53e0c
JK
1838void destroy_node_manager_caches(void);
1839
1840/*
1841 * segment.c
1842 */
88b88a66 1843void register_inmem_page(struct inode *, struct page *);
29b96b54
CY
1844void drop_inmem_pages(struct inode *);
1845int commit_inmem_pages(struct inode *);
2c4db1a6 1846void f2fs_balance_fs(struct f2fs_sb_info *, bool);
4660f9c0 1847void f2fs_balance_fs_bg(struct f2fs_sb_info *);
6b4afdd7 1848int f2fs_issue_flush(struct f2fs_sb_info *);
2163d198
GZ
1849int create_flush_cmd_control(struct f2fs_sb_info *);
1850void destroy_flush_cmd_control(struct f2fs_sb_info *);
39a53e0c 1851void invalidate_blocks(struct f2fs_sb_info *, block_t);
6e2c64ad 1852bool is_checkpointed_data(struct f2fs_sb_info *, block_t);
5e443818 1853void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
836b5a63 1854void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *);
4b2fecc8 1855void release_discard_addrs(struct f2fs_sb_info *);
e90c2d28 1856bool discard_next_dnode(struct f2fs_sb_info *, block_t);
3fa06d7b 1857int npages_for_summary_flush(struct f2fs_sb_info *, bool);
39a53e0c 1858void allocate_new_segments(struct f2fs_sb_info *);
4b2fecc8 1859int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *);
39a53e0c 1860struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
381722d2 1861void update_meta_page(struct f2fs_sb_info *, void *, block_t);
577e3495 1862void write_meta_page(struct f2fs_sb_info *, struct page *);
05ca3632
JK
1863void write_node_page(unsigned int, struct f2fs_io_info *);
1864void write_data_page(struct dnode_of_data *, struct f2fs_io_info *);
1865void rewrite_data_page(struct f2fs_io_info *);
4356e48e
CY
1866void __f2fs_replace_block(struct f2fs_sb_info *, struct f2fs_summary *,
1867 block_t, block_t, bool, bool);
528e3459 1868void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *,
28bc106b 1869 block_t, block_t, unsigned char, bool, bool);
bfad7c2d
JK
1870void allocate_data_block(struct f2fs_sb_info *, struct page *,
1871 block_t, block_t *, struct f2fs_summary *, int);
fec1d657 1872void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool);
08b39fbd 1873void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t);
39a53e0c
JK
1874void write_data_summaries(struct f2fs_sb_info *, block_t);
1875void write_node_summaries(struct f2fs_sb_info *, block_t);
dfc08a12 1876int lookup_journal_in_cursum(struct f2fs_journal *, int, unsigned int, int);
4b2fecc8 1877void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *);
39a53e0c 1878int build_segment_manager(struct f2fs_sb_info *);
39a53e0c 1879void destroy_segment_manager(struct f2fs_sb_info *);
7fd9e544
JK
1880int __init create_segment_manager_caches(void);
1881void destroy_segment_manager_caches(void);
39a53e0c
JK
1882
1883/*
1884 * checkpoint.c
1885 */
1886struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
1887struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
2b947003 1888struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t);
f0c9cada 1889bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int);
26879fb1 1890int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool);
635aee1f 1891void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t);
39a53e0c 1892long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
a49324f1
CY
1893void add_ino_entry(struct f2fs_sb_info *, nid_t, int type);
1894void remove_ino_entry(struct f2fs_sb_info *, nid_t, int type);
1895void release_ino_entry(struct f2fs_sb_info *);
fff04f90 1896bool exist_written_data(struct f2fs_sb_info *, nid_t, int);
cbd56e7d
JK
1897int acquire_orphan_inode(struct f2fs_sb_info *);
1898void release_orphan_inode(struct f2fs_sb_info *);
39a53e0c
JK
1899void add_orphan_inode(struct f2fs_sb_info *, nid_t);
1900void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
8c14bfad 1901int recover_orphan_inodes(struct f2fs_sb_info *);
39a53e0c 1902int get_valid_checkpoint(struct f2fs_sb_info *);
a7ffdbe2 1903void update_dirty_page(struct inode *, struct page *);
5deb8267 1904void add_dirty_dir_inode(struct inode *);
c227f912 1905void remove_dirty_inode(struct inode *);
6d5a1495 1906int sync_dirty_inodes(struct f2fs_sb_info *, enum inode_type);
c34f42e2 1907int write_checkpoint(struct f2fs_sb_info *, struct cp_control *);
6451e041 1908void init_ino_entry_info(struct f2fs_sb_info *);
6e6093a8 1909int __init create_checkpoint_caches(void);
39a53e0c
JK
1910void destroy_checkpoint_caches(void);
1911
1912/*
1913 * data.c
1914 */
458e6197 1915void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
0c3a5797
CY
1916void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *, struct inode *,
1917 struct page *, nid_t, enum page_type, int);
406657dd 1918void f2fs_flush_merged_bios(struct f2fs_sb_info *);
05ca3632
JK
1919int f2fs_submit_page_bio(struct f2fs_io_info *);
1920void f2fs_submit_page_mbio(struct f2fs_io_info *);
216a620a 1921void set_data_blkaddr(struct dnode_of_data *);
f28b3434 1922void f2fs_update_data_blkaddr(struct dnode_of_data *, block_t);
39a53e0c 1923int reserve_new_block(struct dnode_of_data *);
759af1c9 1924int f2fs_get_block(struct dnode_of_data *, pgoff_t);
b439b103 1925ssize_t f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *);
b600965c 1926int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
a56c7c6f 1927struct page *get_read_data_page(struct inode *, pgoff_t, int, bool);
43f3eae1 1928struct page *find_data_page(struct inode *, pgoff_t);
a56c7c6f 1929struct page *get_lock_data_page(struct inode *, pgoff_t, bool);
64aa7ed9 1930struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
05ca3632 1931int do_write_data_page(struct f2fs_io_info *);
d323d005 1932int f2fs_map_blocks(struct inode *, struct f2fs_map_blocks *, int, int);
9ab70134 1933int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
487261f3
CY
1934void f2fs_invalidate_page(struct page *, unsigned int, unsigned int);
1935int f2fs_release_page(struct page *, gfp_t);
39a53e0c
JK
1936
1937/*
1938 * gc.c
1939 */
1940int start_gc_thread(struct f2fs_sb_info *);
1941void stop_gc_thread(struct f2fs_sb_info *);
81ca7350 1942block_t start_bidx_of_node(unsigned int, struct inode *);
d530d4d8 1943int f2fs_gc(struct f2fs_sb_info *, bool);
39a53e0c 1944void build_gc_manager(struct f2fs_sb_info *);
39a53e0c
JK
1945
1946/*
1947 * recovery.c
1948 */
6781eabb 1949int recover_fsync_data(struct f2fs_sb_info *, bool);
39a53e0c
JK
1950bool space_for_roll_forward(struct f2fs_sb_info *);
1951
1952/*
1953 * debug.c
1954 */
1955#ifdef CONFIG_F2FS_STAT_FS
1956struct f2fs_stat_info {
1957 struct list_head stat_list;
1958 struct f2fs_sb_info *sbi;
39a53e0c
JK
1959 int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
1960 int main_area_segs, main_area_sections, main_area_zones;
5b7ee374
CY
1961 unsigned long long hit_largest, hit_cached, hit_rbtree;
1962 unsigned long long hit_total, total_ext;
c00ba554 1963 int ext_tree, zombie_tree, ext_node;
33fbd510
CY
1964 int ndirty_node, ndirty_meta;
1965 int ndirty_dent, ndirty_dirs, ndirty_data, ndirty_files;
dd4e4b59 1966 int nats, dirty_nats, sits, dirty_sits, fnids;
39a53e0c 1967 int total_count, utilization;
d5e8f6c9
CY
1968 int bg_gc, inmem_pages, wb_pages;
1969 int inline_xattr, inline_inode, inline_dir;
39a53e0c
JK
1970 unsigned int valid_count, valid_node_count, valid_inode_count;
1971 unsigned int bimodal, avg_vblocks;
1972 int util_free, util_valid, util_invalid;
1973 int rsvd_segs, overp_segs;
1974 int dirty_count, node_pages, meta_pages;
42190d2a 1975 int prefree_count, call_count, cp_count, bg_cp_count;
39a53e0c 1976 int tot_segs, node_segs, data_segs, free_segs, free_secs;
e1235983 1977 int bg_node_segs, bg_data_segs;
39a53e0c 1978 int tot_blks, data_blks, node_blks;
e1235983 1979 int bg_data_blks, bg_node_blks;
39a53e0c
JK
1980 int curseg[NR_CURSEG_TYPE];
1981 int cursec[NR_CURSEG_TYPE];
1982 int curzone[NR_CURSEG_TYPE];
1983
1984 unsigned int segment_count[2];
1985 unsigned int block_count[2];
b9a2c252 1986 unsigned int inplace_count;
9edcdabf 1987 unsigned long long base_mem, cache_mem, page_mem;
39a53e0c
JK
1988};
1989
963d4f7d
GZ
1990static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
1991{
6c311ec6 1992 return (struct f2fs_stat_info *)sbi->stat_info;
963d4f7d
GZ
1993}
1994
942e0be6 1995#define stat_inc_cp_count(si) ((si)->cp_count++)
42190d2a 1996#define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++)
dcdfff65
JK
1997#define stat_inc_call_count(si) ((si)->call_count++)
1998#define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
33fbd510
CY
1999#define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++)
2000#define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--)
5b7ee374
CY
2001#define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext))
2002#define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree))
2003#define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest))
2004#define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached))
d5e8f6c9
CY
2005#define stat_inc_inline_xattr(inode) \
2006 do { \
2007 if (f2fs_has_inline_xattr(inode)) \
2008 (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \
2009 } while (0)
2010#define stat_dec_inline_xattr(inode) \
2011 do { \
2012 if (f2fs_has_inline_xattr(inode)) \
2013 (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \
2014 } while (0)
0dbdc2ae
JK
2015#define stat_inc_inline_inode(inode) \
2016 do { \
2017 if (f2fs_has_inline_data(inode)) \
03e14d52 2018 (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \
0dbdc2ae
JK
2019 } while (0)
2020#define stat_dec_inline_inode(inode) \
2021 do { \
2022 if (f2fs_has_inline_data(inode)) \
03e14d52 2023 (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \
0dbdc2ae 2024 } while (0)
3289c061
JK
2025#define stat_inc_inline_dir(inode) \
2026 do { \
2027 if (f2fs_has_inline_dentry(inode)) \
03e14d52 2028 (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \
3289c061
JK
2029 } while (0)
2030#define stat_dec_inline_dir(inode) \
2031 do { \
2032 if (f2fs_has_inline_dentry(inode)) \
03e14d52 2033 (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \
3289c061 2034 } while (0)
dcdfff65
JK
2035#define stat_inc_seg_type(sbi, curseg) \
2036 ((sbi)->segment_count[(curseg)->alloc_type]++)
2037#define stat_inc_block_count(sbi, curseg) \
2038 ((sbi)->block_count[(curseg)->alloc_type]++)
b9a2c252
CL
2039#define stat_inc_inplace_blocks(sbi) \
2040 (atomic_inc(&(sbi)->inplace_count))
e1235983 2041#define stat_inc_seg_count(sbi, type, gc_type) \
39a53e0c 2042 do { \
963d4f7d 2043 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
39a53e0c 2044 (si)->tot_segs++; \
e1235983 2045 if (type == SUM_TYPE_DATA) { \
39a53e0c 2046 si->data_segs++; \
e1235983
CL
2047 si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \
2048 } else { \
39a53e0c 2049 si->node_segs++; \
e1235983
CL
2050 si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \
2051 } \
39a53e0c
JK
2052 } while (0)
2053
2054#define stat_inc_tot_blk_count(si, blks) \
2055 (si->tot_blks += (blks))
2056
e1235983 2057#define stat_inc_data_blk_count(sbi, blks, gc_type) \
39a53e0c 2058 do { \
963d4f7d 2059 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
39a53e0c
JK
2060 stat_inc_tot_blk_count(si, blks); \
2061 si->data_blks += (blks); \
e1235983 2062 si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \
39a53e0c
JK
2063 } while (0)
2064
e1235983 2065#define stat_inc_node_blk_count(sbi, blks, gc_type) \
39a53e0c 2066 do { \
963d4f7d 2067 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
39a53e0c
JK
2068 stat_inc_tot_blk_count(si, blks); \
2069 si->node_blks += (blks); \
e1235983 2070 si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \
39a53e0c
JK
2071 } while (0)
2072
2073int f2fs_build_stats(struct f2fs_sb_info *);
2074void f2fs_destroy_stats(struct f2fs_sb_info *);
787c7b8c 2075int __init f2fs_create_root_stats(void);
4589d25d 2076void f2fs_destroy_root_stats(void);
39a53e0c 2077#else
942e0be6 2078#define stat_inc_cp_count(si)
42190d2a 2079#define stat_inc_bg_cp_count(si)
39a53e0c 2080#define stat_inc_call_count(si)
dcdfff65 2081#define stat_inc_bggc_count(si)
33fbd510
CY
2082#define stat_inc_dirty_inode(sbi, type)
2083#define stat_dec_dirty_inode(sbi, type)
dcdfff65 2084#define stat_inc_total_hit(sb)
029e13cc 2085#define stat_inc_rbtree_node_hit(sb)
91c481ff
CY
2086#define stat_inc_largest_node_hit(sbi)
2087#define stat_inc_cached_node_hit(sbi)
d5e8f6c9
CY
2088#define stat_inc_inline_xattr(inode)
2089#define stat_dec_inline_xattr(inode)
0dbdc2ae
JK
2090#define stat_inc_inline_inode(inode)
2091#define stat_dec_inline_inode(inode)
3289c061
JK
2092#define stat_inc_inline_dir(inode)
2093#define stat_dec_inline_dir(inode)
dcdfff65
JK
2094#define stat_inc_seg_type(sbi, curseg)
2095#define stat_inc_block_count(sbi, curseg)
b9a2c252 2096#define stat_inc_inplace_blocks(sbi)
e1235983 2097#define stat_inc_seg_count(sbi, type, gc_type)
39a53e0c 2098#define stat_inc_tot_blk_count(si, blks)
e1235983
CL
2099#define stat_inc_data_blk_count(sbi, blks, gc_type)
2100#define stat_inc_node_blk_count(sbi, blks, gc_type)
39a53e0c
JK
2101
2102static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
2103static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
787c7b8c 2104static inline int __init f2fs_create_root_stats(void) { return 0; }
4589d25d 2105static inline void f2fs_destroy_root_stats(void) { }
39a53e0c
JK
2106#endif
2107
2108extern const struct file_operations f2fs_dir_operations;
2109extern const struct file_operations f2fs_file_operations;
2110extern const struct inode_operations f2fs_file_inode_operations;
2111extern const struct address_space_operations f2fs_dblock_aops;
2112extern const struct address_space_operations f2fs_node_aops;
2113extern const struct address_space_operations f2fs_meta_aops;
2114extern const struct inode_operations f2fs_dir_inode_operations;
2115extern const struct inode_operations f2fs_symlink_inode_operations;
cbaf042a 2116extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
39a53e0c 2117extern const struct inode_operations f2fs_special_inode_operations;
29e7043f 2118extern struct kmem_cache *inode_entry_slab;
1001b347 2119
e18c65b2
HL
2120/*
2121 * inline.c
2122 */
01b960e9
JK
2123bool f2fs_may_inline_data(struct inode *);
2124bool f2fs_may_inline_dentry(struct inode *);
b3d208f9 2125void read_inline_data(struct page *, struct page *);
0bfcfcca 2126bool truncate_inline_inode(struct page *, u64);
e18c65b2 2127int f2fs_read_inline_data(struct inode *, struct page *);
b3d208f9
JK
2128int f2fs_convert_inline_page(struct dnode_of_data *, struct page *);
2129int f2fs_convert_inline_inode(struct inode *);
2130int f2fs_write_inline_data(struct inode *, struct page *);
0342fd30 2131bool recover_inline_data(struct inode *, struct page *);
6e22c691 2132struct f2fs_dir_entry *find_in_inline_dir(struct inode *,
0b81d077 2133 struct fscrypt_name *, struct page **);
201a05be
CY
2134struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **);
2135int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *);
510022a8
JK
2136int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *,
2137 nid_t, umode_t);
201a05be
CY
2138void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *,
2139 struct inode *, struct inode *);
2140bool f2fs_empty_inline_dir(struct inode *);
d8c6822a 2141int f2fs_read_inline_dir(struct file *, struct dir_context *,
0b81d077 2142 struct fscrypt_str *);
67f8cf3c
JK
2143int f2fs_inline_data_fiemap(struct inode *,
2144 struct fiemap_extent_info *, __u64, __u64);
cde4de12 2145
2658e50d
JK
2146/*
2147 * shrinker.c
2148 */
2149unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *);
2150unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *);
2151void f2fs_join_shrinker(struct f2fs_sb_info *);
2152void f2fs_leave_shrinker(struct f2fs_sb_info *);
2153
a28ef1f5
CY
2154/*
2155 * extent_cache.c
2156 */
2157unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int);
ed3d1256 2158bool f2fs_init_extent_tree(struct inode *, struct f2fs_extent *);
a28ef1f5
CY
2159unsigned int f2fs_destroy_extent_node(struct inode *);
2160void f2fs_destroy_extent_tree(struct inode *);
2161bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *);
2162void f2fs_update_extent_cache(struct dnode_of_data *);
19b2c30d
CY
2163void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
2164 pgoff_t, block_t, unsigned int);
a28ef1f5
CY
2165void init_extent_cache_info(struct f2fs_sb_info *);
2166int __init create_extent_cache(void);
2167void destroy_extent_cache(void);
2168
cde4de12
JK
2169/*
2170 * crypto support
2171 */
0b81d077 2172static inline bool f2fs_encrypted_inode(struct inode *inode)
cde4de12 2173{
cde4de12 2174 return file_is_encrypt(inode);
cde4de12
JK
2175}
2176
2177static inline void f2fs_set_encrypted_inode(struct inode *inode)
2178{
2179#ifdef CONFIG_F2FS_FS_ENCRYPTION
2180 file_set_encrypt(inode);
2181#endif
2182}
2183
2184static inline bool f2fs_bio_encrypted(struct bio *bio)
2185{
0b81d077 2186 return bio->bi_private != NULL;
cde4de12
JK
2187}
2188
2189static inline int f2fs_sb_has_crypto(struct super_block *sb)
2190{
cde4de12 2191 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT);
cde4de12 2192}
f424f664 2193
fcc85a4d
JK
2194static inline bool f2fs_may_encrypt(struct inode *inode)
2195{
2196#ifdef CONFIG_F2FS_FS_ENCRYPTION
886f56f9 2197 umode_t mode = inode->i_mode;
fcc85a4d
JK
2198
2199 return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
2200#else
2201 return 0;
2202#endif
2203}
2204
0b81d077
JK
2205#ifndef CONFIG_F2FS_FS_ENCRYPTION
2206#define fscrypt_set_d_op(i)
2207#define fscrypt_get_ctx fscrypt_notsupp_get_ctx
2208#define fscrypt_release_ctx fscrypt_notsupp_release_ctx
2209#define fscrypt_encrypt_page fscrypt_notsupp_encrypt_page
2210#define fscrypt_decrypt_page fscrypt_notsupp_decrypt_page
2211#define fscrypt_decrypt_bio_pages fscrypt_notsupp_decrypt_bio_pages
2212#define fscrypt_pullback_bio_page fscrypt_notsupp_pullback_bio_page
2213#define fscrypt_restore_control_page fscrypt_notsupp_restore_control_page
2214#define fscrypt_zeroout_range fscrypt_notsupp_zeroout_range
2215#define fscrypt_process_policy fscrypt_notsupp_process_policy
2216#define fscrypt_get_policy fscrypt_notsupp_get_policy
2217#define fscrypt_has_permitted_context fscrypt_notsupp_has_permitted_context
2218#define fscrypt_inherit_context fscrypt_notsupp_inherit_context
2219#define fscrypt_get_encryption_info fscrypt_notsupp_get_encryption_info
2220#define fscrypt_put_encryption_info fscrypt_notsupp_put_encryption_info
2221#define fscrypt_setup_filename fscrypt_notsupp_setup_filename
2222#define fscrypt_free_filename fscrypt_notsupp_free_filename
2223#define fscrypt_fname_encrypted_size fscrypt_notsupp_fname_encrypted_size
2224#define fscrypt_fname_alloc_buffer fscrypt_notsupp_fname_alloc_buffer
2225#define fscrypt_fname_free_buffer fscrypt_notsupp_fname_free_buffer
2226#define fscrypt_fname_disk_to_usr fscrypt_notsupp_fname_disk_to_usr
2227#define fscrypt_fname_usr_to_disk fscrypt_notsupp_fname_usr_to_disk
57e5055b 2228#endif
39a53e0c 2229#endif
This page took 0.359184 seconds and 5 git commands to generate.