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