f2fs: Fix use of number of devices
[linux-stable.git] / fs / f2fs / f2fs.h
blob406d93b51a0bcc5ef9a41fc4e5201f4e4ca0df5d
1 /*
2 * fs/f2fs/f2fs.h
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
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.
11 #ifndef _LINUX_F2FS_H
12 #define _LINUX_F2FS_H
14 #include <linux/types.h>
15 #include <linux/page-flags.h>
16 #include <linux/buffer_head.h>
17 #include <linux/slab.h>
18 #include <linux/crc32.h>
19 #include <linux/magic.h>
20 #include <linux/kobject.h>
21 #include <linux/sched.h>
22 #include <linux/vmalloc.h>
23 #include <linux/bio.h>
24 #include <linux/blkdev.h>
25 #include <linux/quotaops.h>
26 #ifdef CONFIG_F2FS_FS_ENCRYPTION
27 #include <linux/fscrypt_supp.h>
28 #else
29 #include <linux/fscrypt_notsupp.h>
30 #endif
31 #include <crypto/hash.h>
33 #ifdef CONFIG_F2FS_CHECK_FS
34 #define f2fs_bug_on(sbi, condition) BUG_ON(condition)
35 #else
36 #define f2fs_bug_on(sbi, condition) \
37 do { \
38 if (unlikely(condition)) { \
39 WARN_ON(1); \
40 set_sbi_flag(sbi, SBI_NEED_FSCK); \
41 } \
42 } while (0)
43 #endif
45 #ifdef CONFIG_F2FS_FAULT_INJECTION
46 enum {
47 FAULT_KMALLOC,
48 FAULT_PAGE_ALLOC,
49 FAULT_ALLOC_NID,
50 FAULT_ORPHAN,
51 FAULT_BLOCK,
52 FAULT_DIR_DEPTH,
53 FAULT_EVICT_INODE,
54 FAULT_TRUNCATE,
55 FAULT_IO,
56 FAULT_CHECKPOINT,
57 FAULT_MAX,
60 struct f2fs_fault_info {
61 atomic_t inject_ops;
62 unsigned int inject_rate;
63 unsigned int inject_type;
66 extern char *fault_name[FAULT_MAX];
67 #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type)))
68 #endif
71 * For mount options
73 #define F2FS_MOUNT_BG_GC 0x00000001
74 #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
75 #define F2FS_MOUNT_DISCARD 0x00000004
76 #define F2FS_MOUNT_NOHEAP 0x00000008
77 #define F2FS_MOUNT_XATTR_USER 0x00000010
78 #define F2FS_MOUNT_POSIX_ACL 0x00000020
79 #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
80 #define F2FS_MOUNT_INLINE_XATTR 0x00000080
81 #define F2FS_MOUNT_INLINE_DATA 0x00000100
82 #define F2FS_MOUNT_INLINE_DENTRY 0x00000200
83 #define F2FS_MOUNT_FLUSH_MERGE 0x00000400
84 #define F2FS_MOUNT_NOBARRIER 0x00000800
85 #define F2FS_MOUNT_FASTBOOT 0x00001000
86 #define F2FS_MOUNT_EXTENT_CACHE 0x00002000
87 #define F2FS_MOUNT_FORCE_FG_GC 0x00004000
88 #define F2FS_MOUNT_DATA_FLUSH 0x00008000
89 #define F2FS_MOUNT_FAULT_INJECTION 0x00010000
90 #define F2FS_MOUNT_ADAPTIVE 0x00020000
91 #define F2FS_MOUNT_LFS 0x00040000
92 #define F2FS_MOUNT_USRQUOTA 0x00080000
93 #define F2FS_MOUNT_GRPQUOTA 0x00100000
94 #define F2FS_MOUNT_PRJQUOTA 0x00200000
95 #define F2FS_MOUNT_QUOTA 0x00400000
97 #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option)
98 #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option)
99 #define test_opt(sbi, option) ((sbi)->mount_opt.opt & F2FS_MOUNT_##option)
101 #define ver_after(a, b) (typecheck(unsigned long long, a) && \
102 typecheck(unsigned long long, b) && \
103 ((long long)((a) - (b)) > 0))
105 typedef u32 block_t; /*
106 * should not change u32, since it is the on-disk block
107 * address format, __le32.
109 typedef u32 nid_t;
111 struct f2fs_mount_info {
112 unsigned int opt;
115 #define F2FS_FEATURE_ENCRYPT 0x0001
116 #define F2FS_FEATURE_BLKZONED 0x0002
117 #define F2FS_FEATURE_ATOMIC_WRITE 0x0004
118 #define F2FS_FEATURE_EXTRA_ATTR 0x0008
119 #define F2FS_FEATURE_PRJQUOTA 0x0010
120 #define F2FS_FEATURE_INODE_CHKSUM 0x0020
122 #define F2FS_HAS_FEATURE(sb, mask) \
123 ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
124 #define F2FS_SET_FEATURE(sb, mask) \
125 (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask))
126 #define F2FS_CLEAR_FEATURE(sb, mask) \
127 (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask))
130 * For checkpoint manager
132 enum {
133 NAT_BITMAP,
134 SIT_BITMAP
137 #define CP_UMOUNT 0x00000001
138 #define CP_FASTBOOT 0x00000002
139 #define CP_SYNC 0x00000004
140 #define CP_RECOVERY 0x00000008
141 #define CP_DISCARD 0x00000010
142 #define CP_TRIMMED 0x00000020
144 #define DEF_BATCHED_TRIM_SECTIONS 2048
145 #define BATCHED_TRIM_SEGMENTS(sbi) \
146 (GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections))
147 #define BATCHED_TRIM_BLOCKS(sbi) \
148 (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
149 #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi)
150 #define DISCARD_ISSUE_RATE 8
151 #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */
152 #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */
153 #define DEF_CP_INTERVAL 60 /* 60 secs */
154 #define DEF_IDLE_INTERVAL 5 /* 5 secs */
156 struct cp_control {
157 int reason;
158 __u64 trim_start;
159 __u64 trim_end;
160 __u64 trim_minlen;
161 __u64 trimmed;
165 * indicate meta/data type
167 enum {
168 META_CP,
169 META_NAT,
170 META_SIT,
171 META_SSA,
172 META_POR,
173 DATA_GENERIC,
174 META_GENERIC,
177 /* for the list of ino */
178 enum {
179 ORPHAN_INO, /* for orphan ino list */
180 APPEND_INO, /* for append ino list */
181 UPDATE_INO, /* for update ino list */
182 MAX_INO_ENTRY, /* max. list */
185 struct ino_entry {
186 struct list_head list; /* list head */
187 nid_t ino; /* inode number */
190 /* for the list of inodes to be GCed */
191 struct inode_entry {
192 struct list_head list; /* list head */
193 struct inode *inode; /* vfs inode pointer */
196 /* for the bitmap indicate blocks to be discarded */
197 struct discard_entry {
198 struct list_head list; /* list head */
199 block_t start_blkaddr; /* start blockaddr of current segment */
200 unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */
203 /* default discard granularity of inner discard thread, unit: block count */
204 #define DEFAULT_DISCARD_GRANULARITY 16
206 /* max discard pend list number */
207 #define MAX_PLIST_NUM 512
208 #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \
209 (MAX_PLIST_NUM - 1) : (blk_num - 1))
211 #define P_ACTIVE 0x01
212 #define P_TRIM 0x02
213 #define plist_issue(tag) (((tag) & P_ACTIVE) || ((tag) & P_TRIM))
215 enum {
216 D_PREP,
217 D_SUBMIT,
218 D_DONE,
221 struct discard_info {
222 block_t lstart; /* logical start address */
223 block_t len; /* length */
224 block_t start; /* actual start address in dev */
227 struct discard_cmd {
228 struct rb_node rb_node; /* rb node located in rb-tree */
229 union {
230 struct {
231 block_t lstart; /* logical start address */
232 block_t len; /* length */
233 block_t start; /* actual start address in dev */
235 struct discard_info di; /* discard info */
238 struct list_head list; /* command list */
239 struct completion wait; /* compleation */
240 struct block_device *bdev; /* bdev */
241 unsigned short ref; /* reference count */
242 unsigned char state; /* state */
243 int error; /* bio error */
246 struct discard_cmd_control {
247 struct task_struct *f2fs_issue_discard; /* discard thread */
248 struct list_head entry_list; /* 4KB discard entry list */
249 struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */
250 unsigned char pend_list_tag[MAX_PLIST_NUM];/* tag for pending entries */
251 struct list_head wait_list; /* store on-flushing entries */
252 wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */
253 unsigned int discard_wake; /* to wake up discard thread */
254 struct mutex cmd_lock;
255 unsigned int nr_discards; /* # of discards in the list */
256 unsigned int max_discards; /* max. discards to be issued */
257 unsigned int discard_granularity; /* discard granularity */
258 unsigned int undiscard_blks; /* # of undiscard blocks */
259 atomic_t issued_discard; /* # of issued discard */
260 atomic_t issing_discard; /* # of issing discard */
261 atomic_t discard_cmd_cnt; /* # of cached cmd count */
262 struct rb_root root; /* root of discard rb-tree */
265 /* for the list of fsync inodes, used only during recovery */
266 struct fsync_inode_entry {
267 struct list_head list; /* list head */
268 struct inode *inode; /* vfs inode pointer */
269 block_t blkaddr; /* block address locating the last fsync */
270 block_t last_dentry; /* block address locating the last dentry */
273 #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats))
274 #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits))
276 #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne)
277 #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid)
278 #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se)
279 #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno)
281 #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl))
282 #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl))
284 static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i)
286 int before = nats_in_cursum(journal);
288 journal->n_nats = cpu_to_le16(before + i);
289 return before;
292 static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i)
294 int before = sits_in_cursum(journal);
296 journal->n_sits = cpu_to_le16(before + i);
297 return before;
300 static inline bool __has_cursum_space(struct f2fs_journal *journal,
301 int size, int type)
303 if (type == NAT_JOURNAL)
304 return size <= MAX_NAT_JENTRIES(journal);
305 return size <= MAX_SIT_JENTRIES(journal);
309 * ioctl commands
311 #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
312 #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
313 #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION
315 #define F2FS_IOCTL_MAGIC 0xf5
316 #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
317 #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
318 #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
319 #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)
320 #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
321 #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32)
322 #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7)
323 #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \
324 struct f2fs_defragment)
325 #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \
326 struct f2fs_move_range)
327 #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \
328 struct f2fs_flush_device)
329 #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \
330 struct f2fs_gc_range)
331 #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32)
333 #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
334 #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
335 #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT
338 * should be same as XFS_IOC_GOINGDOWN.
339 * Flags for going down operation used by FS_IOC_GOINGDOWN
341 #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */
342 #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */
343 #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */
344 #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */
345 #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */
347 #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
349 * ioctl commands in 32 bit emulation
351 #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
352 #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
353 #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION
354 #endif
356 #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR
357 #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR
359 struct f2fs_gc_range {
360 u32 sync;
361 u64 start;
362 u64 len;
365 struct f2fs_defragment {
366 u64 start;
367 u64 len;
370 struct f2fs_move_range {
371 u32 dst_fd; /* destination fd */
372 u64 pos_in; /* start position in src_fd */
373 u64 pos_out; /* start position in dst_fd */
374 u64 len; /* size to move */
377 struct f2fs_flush_device {
378 u32 dev_num; /* device number to flush */
379 u32 segments; /* # of segments to flush */
382 /* for inline stuff */
383 #define DEF_INLINE_RESERVED_SIZE 1
384 static inline int get_extra_isize(struct inode *inode);
385 #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \
386 (CUR_ADDRS_PER_INODE(inode) - \
387 DEF_INLINE_RESERVED_SIZE - \
388 F2FS_INLINE_XATTR_ADDRS))
390 /* for inline dir */
391 #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \
392 ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
393 BITS_PER_BYTE + 1))
394 #define INLINE_DENTRY_BITMAP_SIZE(inode) ((NR_INLINE_DENTRY(inode) + \
395 BITS_PER_BYTE - 1) / BITS_PER_BYTE)
396 #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \
397 ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \
398 NR_INLINE_DENTRY(inode) + \
399 INLINE_DENTRY_BITMAP_SIZE(inode)))
402 * For INODE and NODE manager
404 /* for directory operations */
405 struct f2fs_dentry_ptr {
406 struct inode *inode;
407 void *bitmap;
408 struct f2fs_dir_entry *dentry;
409 __u8 (*filename)[F2FS_SLOT_LEN];
410 int max;
411 int nr_bitmap;
414 static inline void make_dentry_ptr_block(struct inode *inode,
415 struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t)
417 d->inode = inode;
418 d->max = NR_DENTRY_IN_BLOCK;
419 d->nr_bitmap = SIZE_OF_DENTRY_BITMAP;
420 d->bitmap = &t->dentry_bitmap;
421 d->dentry = t->dentry;
422 d->filename = t->filename;
425 static inline void make_dentry_ptr_inline(struct inode *inode,
426 struct f2fs_dentry_ptr *d, void *t)
428 int entry_cnt = NR_INLINE_DENTRY(inode);
429 int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode);
430 int reserved_size = INLINE_RESERVED_SIZE(inode);
432 d->inode = inode;
433 d->max = entry_cnt;
434 d->nr_bitmap = bitmap_size;
435 d->bitmap = t;
436 d->dentry = t + bitmap_size + reserved_size;
437 d->filename = t + bitmap_size + reserved_size +
438 SIZE_OF_DIR_ENTRY * entry_cnt;
442 * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
443 * as its node offset to distinguish from index node blocks.
444 * But some bits are used to mark the node block.
446 #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
447 >> OFFSET_BIT_SHIFT)
448 enum {
449 ALLOC_NODE, /* allocate a new node page if needed */
450 LOOKUP_NODE, /* look up a node without readahead */
451 LOOKUP_NODE_RA, /*
452 * look up a node with readahead called
453 * by get_data_block.
457 #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */
459 #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */
461 /* vector size for gang look-up from extent cache that consists of radix tree */
462 #define EXT_TREE_VEC_SIZE 64
464 /* for in-memory extent cache entry */
465 #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */
467 /* number of extent info in extent cache we try to shrink */
468 #define EXTENT_CACHE_SHRINK_NUMBER 128
470 struct rb_entry {
471 struct rb_node rb_node; /* rb node located in rb-tree */
472 unsigned int ofs; /* start offset of the entry */
473 unsigned int len; /* length of the entry */
476 struct extent_info {
477 unsigned int fofs; /* start offset in a file */
478 unsigned int len; /* length of the extent */
479 u32 blk; /* start block address of the extent */
482 struct extent_node {
483 struct rb_node rb_node;
484 union {
485 struct {
486 unsigned int fofs;
487 unsigned int len;
488 u32 blk;
490 struct extent_info ei; /* extent info */
493 struct list_head list; /* node in global extent list of sbi */
494 struct extent_tree *et; /* extent tree pointer */
497 struct extent_tree {
498 nid_t ino; /* inode number */
499 struct rb_root root; /* root of extent info rb-tree */
500 struct extent_node *cached_en; /* recently accessed extent node */
501 struct extent_info largest; /* largested extent info */
502 struct list_head list; /* to be used by sbi->zombie_list */
503 rwlock_t lock; /* protect extent info rb-tree */
504 atomic_t node_cnt; /* # of extent node in rb-tree*/
508 * This structure is taken from ext4_map_blocks.
510 * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
512 #define F2FS_MAP_NEW (1 << BH_New)
513 #define F2FS_MAP_MAPPED (1 << BH_Mapped)
514 #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten)
515 #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
516 F2FS_MAP_UNWRITTEN)
518 struct f2fs_map_blocks {
519 block_t m_pblk;
520 block_t m_lblk;
521 unsigned int m_len;
522 unsigned int m_flags;
523 pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */
526 /* for flag in get_data_block */
527 enum {
528 F2FS_GET_BLOCK_DEFAULT,
529 F2FS_GET_BLOCK_FIEMAP,
530 F2FS_GET_BLOCK_BMAP,
531 F2FS_GET_BLOCK_PRE_DIO,
532 F2FS_GET_BLOCK_PRE_AIO,
536 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
538 #define FADVISE_COLD_BIT 0x01
539 #define FADVISE_LOST_PINO_BIT 0x02
540 #define FADVISE_ENCRYPT_BIT 0x04
541 #define FADVISE_ENC_NAME_BIT 0x08
542 #define FADVISE_KEEP_SIZE_BIT 0x10
544 #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT)
545 #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT)
546 #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT)
547 #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT)
548 #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT)
549 #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT)
550 #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT)
551 #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT)
552 #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT)
553 #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT)
554 #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
555 #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT)
556 #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT)
558 #define DEF_DIR_LEVEL 0
560 struct f2fs_inode_info {
561 struct inode vfs_inode; /* serve a vfs inode */
562 unsigned long i_flags; /* keep an inode flags for ioctl */
563 unsigned char i_advise; /* use to give file attribute hints */
564 unsigned char i_dir_level; /* use for dentry level for large dir */
565 unsigned int i_current_depth; /* use only in directory structure */
566 unsigned int i_pino; /* parent inode number */
567 umode_t i_acl_mode; /* keep file acl mode temporarily */
569 /* Use below internally in f2fs*/
570 unsigned long flags; /* use to pass per-file flags */
571 struct rw_semaphore i_sem; /* protect fi info */
572 atomic_t dirty_pages; /* # of dirty pages */
573 f2fs_hash_t chash; /* hash value of given file name */
574 unsigned int clevel; /* maximum level of given file name */
575 struct task_struct *task; /* lookup and create consistency */
576 struct task_struct *cp_task; /* separate cp/wb IO stats*/
577 nid_t i_xattr_nid; /* node id that contains xattrs */
578 loff_t last_disk_size; /* lastly written file size */
580 #ifdef CONFIG_QUOTA
581 struct dquot *i_dquot[MAXQUOTAS];
583 /* quota space reservation, managed internally by quota code */
584 qsize_t i_reserved_quota;
585 #endif
586 struct list_head dirty_list; /* dirty list for dirs and files */
587 struct list_head gdirty_list; /* linked in global dirty list */
588 struct list_head inmem_pages; /* inmemory pages managed by f2fs */
589 struct task_struct *inmem_task; /* store inmemory task */
590 struct mutex inmem_lock; /* lock for inmemory pages */
591 struct extent_tree *extent_tree; /* cached extent_tree entry */
592 struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */
593 struct rw_semaphore i_mmap_sem;
594 struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */
596 int i_extra_isize; /* size of extra space located in i_addr */
597 kprojid_t i_projid; /* id for project quota */
600 static inline void get_extent_info(struct extent_info *ext,
601 struct f2fs_extent *i_ext)
603 ext->fofs = le32_to_cpu(i_ext->fofs);
604 ext->blk = le32_to_cpu(i_ext->blk);
605 ext->len = le32_to_cpu(i_ext->len);
608 static inline void set_raw_extent(struct extent_info *ext,
609 struct f2fs_extent *i_ext)
611 i_ext->fofs = cpu_to_le32(ext->fofs);
612 i_ext->blk = cpu_to_le32(ext->blk);
613 i_ext->len = cpu_to_le32(ext->len);
616 static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
617 u32 blk, unsigned int len)
619 ei->fofs = fofs;
620 ei->blk = blk;
621 ei->len = len;
624 static inline bool __is_discard_mergeable(struct discard_info *back,
625 struct discard_info *front)
627 return back->lstart + back->len == front->lstart;
630 static inline bool __is_discard_back_mergeable(struct discard_info *cur,
631 struct discard_info *back)
633 return __is_discard_mergeable(back, cur);
636 static inline bool __is_discard_front_mergeable(struct discard_info *cur,
637 struct discard_info *front)
639 return __is_discard_mergeable(cur, front);
642 static inline bool __is_extent_mergeable(struct extent_info *back,
643 struct extent_info *front)
645 return (back->fofs + back->len == front->fofs &&
646 back->blk + back->len == front->blk);
649 static inline bool __is_back_mergeable(struct extent_info *cur,
650 struct extent_info *back)
652 return __is_extent_mergeable(back, cur);
655 static inline bool __is_front_mergeable(struct extent_info *cur,
656 struct extent_info *front)
658 return __is_extent_mergeable(cur, front);
661 extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync);
662 static inline void __try_update_largest_extent(struct inode *inode,
663 struct extent_tree *et, struct extent_node *en)
665 if (en->ei.len > et->largest.len) {
666 et->largest = en->ei;
667 f2fs_mark_inode_dirty_sync(inode, true);
671 enum nid_list {
672 FREE_NID_LIST,
673 ALLOC_NID_LIST,
674 MAX_NID_LIST,
677 struct f2fs_nm_info {
678 block_t nat_blkaddr; /* base disk address of NAT */
679 nid_t max_nid; /* maximum possible node ids */
680 nid_t available_nids; /* # of available node ids */
681 nid_t next_scan_nid; /* the next nid to be scanned */
682 unsigned int ram_thresh; /* control the memory footprint */
683 unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */
684 unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */
686 /* NAT cache management */
687 struct radix_tree_root nat_root;/* root of the nat entry cache */
688 struct radix_tree_root nat_set_root;/* root of the nat set cache */
689 struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */
690 struct list_head nat_entries; /* cached nat entry list (clean) */
691 unsigned int nat_cnt; /* the # of cached nat entries */
692 unsigned int dirty_nat_cnt; /* total num of nat entries in set */
693 unsigned int nat_blocks; /* # of nat blocks */
695 /* free node ids management */
696 struct radix_tree_root free_nid_root;/* root of the free_nid cache */
697 struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */
698 unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */
699 spinlock_t nid_list_lock; /* protect nid lists ops */
700 struct mutex build_lock; /* lock for build free nids */
701 unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE];
702 unsigned char *nat_block_bitmap;
703 unsigned short *free_nid_count; /* free nid count of NAT block */
705 /* for checkpoint */
706 char *nat_bitmap; /* NAT bitmap pointer */
708 unsigned int nat_bits_blocks; /* # of nat bits blocks */
709 unsigned char *nat_bits; /* NAT bits blocks */
710 unsigned char *full_nat_bits; /* full NAT pages */
711 unsigned char *empty_nat_bits; /* empty NAT pages */
712 #ifdef CONFIG_F2FS_CHECK_FS
713 char *nat_bitmap_mir; /* NAT bitmap mirror */
714 #endif
715 int bitmap_size; /* bitmap size */
719 * this structure is used as one of function parameters.
720 * all the information are dedicated to a given direct node block determined
721 * by the data offset in a file.
723 struct dnode_of_data {
724 struct inode *inode; /* vfs inode pointer */
725 struct page *inode_page; /* its inode page, NULL is possible */
726 struct page *node_page; /* cached direct node page */
727 nid_t nid; /* node id of the direct node block */
728 unsigned int ofs_in_node; /* data offset in the node page */
729 bool inode_page_locked; /* inode page is locked or not */
730 bool node_changed; /* is node block changed */
731 char cur_level; /* level of hole node page */
732 char max_level; /* level of current page located */
733 block_t data_blkaddr; /* block address of the node block */
736 static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
737 struct page *ipage, struct page *npage, nid_t nid)
739 memset(dn, 0, sizeof(*dn));
740 dn->inode = inode;
741 dn->inode_page = ipage;
742 dn->node_page = npage;
743 dn->nid = nid;
747 * For SIT manager
749 * By default, there are 6 active log areas across the whole main area.
750 * When considering hot and cold data separation to reduce cleaning overhead,
751 * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
752 * respectively.
753 * In the current design, you should not change the numbers intentionally.
754 * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
755 * logs individually according to the underlying devices. (default: 6)
756 * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
757 * data and 8 for node logs.
759 #define NR_CURSEG_DATA_TYPE (3)
760 #define NR_CURSEG_NODE_TYPE (3)
761 #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
763 enum {
764 CURSEG_HOT_DATA = 0, /* directory entry blocks */
765 CURSEG_WARM_DATA, /* data blocks */
766 CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
767 CURSEG_HOT_NODE, /* direct node blocks of directory files */
768 CURSEG_WARM_NODE, /* direct node blocks of normal files */
769 CURSEG_COLD_NODE, /* indirect node blocks */
770 NO_CHECK_TYPE,
773 struct flush_cmd {
774 struct completion wait;
775 struct llist_node llnode;
776 int ret;
779 struct flush_cmd_control {
780 struct task_struct *f2fs_issue_flush; /* flush thread */
781 wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */
782 atomic_t issued_flush; /* # of issued flushes */
783 atomic_t issing_flush; /* # of issing flushes */
784 struct llist_head issue_list; /* list for command issue */
785 struct llist_node *dispatch_list; /* list for command dispatch */
788 struct f2fs_sm_info {
789 struct sit_info *sit_info; /* whole segment information */
790 struct free_segmap_info *free_info; /* free segment information */
791 struct dirty_seglist_info *dirty_info; /* dirty segment information */
792 struct curseg_info *curseg_array; /* active segment information */
794 block_t seg0_blkaddr; /* block address of 0'th segment */
795 block_t main_blkaddr; /* start block address of main area */
796 block_t ssa_blkaddr; /* start block address of SSA area */
798 unsigned int segment_count; /* total # of segments */
799 unsigned int main_segments; /* # of segments in main area */
800 unsigned int reserved_segments; /* # of reserved segments */
801 unsigned int ovp_segments; /* # of overprovision segments */
803 /* a threshold to reclaim prefree segments */
804 unsigned int rec_prefree_segments;
806 /* for batched trimming */
807 unsigned int trim_sections; /* # of sections to trim */
809 struct list_head sit_entry_set; /* sit entry set list */
811 unsigned int ipu_policy; /* in-place-update policy */
812 unsigned int min_ipu_util; /* in-place-update threshold */
813 unsigned int min_fsync_blocks; /* threshold for fsync */
814 unsigned int min_hot_blocks; /* threshold for hot block allocation */
816 /* for flush command control */
817 struct flush_cmd_control *fcc_info;
819 /* for discard command control */
820 struct discard_cmd_control *dcc_info;
824 * For superblock
827 * COUNT_TYPE for monitoring
829 * f2fs monitors the number of several block types such as on-writeback,
830 * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
832 #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA)
833 enum count_type {
834 F2FS_DIRTY_DENTS,
835 F2FS_DIRTY_DATA,
836 F2FS_DIRTY_NODES,
837 F2FS_DIRTY_META,
838 F2FS_INMEM_PAGES,
839 F2FS_DIRTY_IMETA,
840 F2FS_WB_CP_DATA,
841 F2FS_WB_DATA,
842 NR_COUNT_TYPE,
846 * The below are the page types of bios used in submit_bio().
847 * The available types are:
848 * DATA User data pages. It operates as async mode.
849 * NODE Node pages. It operates as async mode.
850 * META FS metadata pages such as SIT, NAT, CP.
851 * NR_PAGE_TYPE The number of page types.
852 * META_FLUSH Make sure the previous pages are written
853 * with waiting the bio's completion
854 * ... Only can be used with META.
856 #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type))
857 enum page_type {
858 DATA,
859 NODE,
860 META,
861 NR_PAGE_TYPE,
862 META_FLUSH,
863 INMEM, /* the below types are used by tracepoints only. */
864 INMEM_DROP,
865 INMEM_INVALIDATE,
866 INMEM_REVOKE,
867 IPU,
868 OPU,
871 enum temp_type {
872 HOT = 0, /* must be zero for meta bio */
873 WARM,
874 COLD,
875 NR_TEMP_TYPE,
878 enum need_lock_type {
879 LOCK_REQ = 0,
880 LOCK_DONE,
881 LOCK_RETRY,
884 enum iostat_type {
885 APP_DIRECT_IO, /* app direct IOs */
886 APP_BUFFERED_IO, /* app buffered IOs */
887 APP_WRITE_IO, /* app write IOs */
888 APP_MAPPED_IO, /* app mapped IOs */
889 FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */
890 FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */
891 FS_META_IO, /* meta IOs from kworker/reclaimer */
892 FS_GC_DATA_IO, /* data IOs from forground gc */
893 FS_GC_NODE_IO, /* node IOs from forground gc */
894 FS_CP_DATA_IO, /* data IOs from checkpoint */
895 FS_CP_NODE_IO, /* node IOs from checkpoint */
896 FS_CP_META_IO, /* meta IOs from checkpoint */
897 FS_DISCARD, /* discard */
898 NR_IO_TYPE,
901 struct f2fs_io_info {
902 struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */
903 enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
904 enum temp_type temp; /* contains HOT/WARM/COLD */
905 int op; /* contains REQ_OP_ */
906 int op_flags; /* req_flag_bits */
907 block_t new_blkaddr; /* new block address to be written */
908 block_t old_blkaddr; /* old block address before Cow */
909 struct page *page; /* page to be written */
910 struct page *encrypted_page; /* encrypted page */
911 struct list_head list; /* serialize IOs */
912 bool submitted; /* indicate IO submission */
913 int need_lock; /* indicate we need to lock cp_rwsem */
914 bool in_list; /* indicate fio is in io_list */
915 bool is_meta; /* indicate borrow meta inode mapping or not */
916 enum iostat_type io_type; /* io type */
919 #define is_read_io(rw) ((rw) == READ)
920 struct f2fs_bio_info {
921 struct f2fs_sb_info *sbi; /* f2fs superblock */
922 struct bio *bio; /* bios to merge */
923 sector_t last_block_in_bio; /* last block number */
924 struct f2fs_io_info fio; /* store buffered io info. */
925 struct rw_semaphore io_rwsem; /* blocking op for bio */
926 spinlock_t io_lock; /* serialize DATA/NODE IOs */
927 struct list_head io_list; /* track fios */
930 #define FDEV(i) (sbi->devs[i])
931 #define RDEV(i) (raw_super->devs[i])
932 struct f2fs_dev_info {
933 struct block_device *bdev;
934 char path[MAX_PATH_LEN];
935 unsigned int total_segments;
936 block_t start_blk;
937 block_t end_blk;
938 #ifdef CONFIG_BLK_DEV_ZONED
939 unsigned int nr_blkz; /* Total number of zones */
940 u8 *blkz_type; /* Array of zones type */
941 #endif
944 enum inode_type {
945 DIR_INODE, /* for dirty dir inode */
946 FILE_INODE, /* for dirty regular/symlink inode */
947 DIRTY_META, /* for all dirtied inode metadata */
948 NR_INODE_TYPE,
951 /* for inner inode cache management */
952 struct inode_management {
953 struct radix_tree_root ino_root; /* ino entry array */
954 spinlock_t ino_lock; /* for ino entry lock */
955 struct list_head ino_list; /* inode list head */
956 unsigned long ino_num; /* number of entries */
959 /* For s_flag in struct f2fs_sb_info */
960 enum {
961 SBI_IS_DIRTY, /* dirty flag for checkpoint */
962 SBI_IS_CLOSE, /* specify unmounting */
963 SBI_NEED_FSCK, /* need fsck.f2fs to fix */
964 SBI_POR_DOING, /* recovery is doing or not */
965 SBI_NEED_SB_WRITE, /* need to recover superblock */
966 SBI_NEED_CP, /* need to checkpoint */
969 enum {
970 CP_TIME,
971 REQ_TIME,
972 MAX_TIME,
975 struct f2fs_sb_info {
976 struct super_block *sb; /* pointer to VFS super block */
977 struct proc_dir_entry *s_proc; /* proc entry */
978 struct f2fs_super_block *raw_super; /* raw super block pointer */
979 int valid_super_block; /* valid super block no */
980 unsigned long s_flag; /* flags for sbi */
982 #ifdef CONFIG_BLK_DEV_ZONED
983 unsigned int blocks_per_blkz; /* F2FS blocks per zone */
984 unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */
985 #endif
987 /* for node-related operations */
988 struct f2fs_nm_info *nm_info; /* node manager */
989 struct inode *node_inode; /* cache node blocks */
991 /* for segment-related operations */
992 struct f2fs_sm_info *sm_info; /* segment manager */
994 /* for bio operations */
995 struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */
996 struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE];
997 /* bio ordering for NODE/DATA */
998 int write_io_size_bits; /* Write IO size bits */
999 mempool_t *write_io_dummy; /* Dummy pages */
1001 /* for checkpoint */
1002 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
1003 int cur_cp_pack; /* remain current cp pack */
1004 spinlock_t cp_lock; /* for flag in ckpt */
1005 struct inode *meta_inode; /* cache meta blocks */
1006 struct mutex cp_mutex; /* checkpoint procedure lock */
1007 struct rw_semaphore cp_rwsem; /* blocking FS operations */
1008 struct rw_semaphore node_write; /* locking node writes */
1009 struct rw_semaphore node_change; /* locking node change */
1010 wait_queue_head_t cp_wait;
1011 unsigned long last_time[MAX_TIME]; /* to store time in jiffies */
1012 long interval_time[MAX_TIME]; /* to store thresholds */
1014 struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
1016 /* for orphan inode, use 0'th array */
1017 unsigned int max_orphans; /* max orphan inodes */
1019 /* for inode management */
1020 struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */
1021 spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */
1023 /* for extent tree cache */
1024 struct radix_tree_root extent_tree_root;/* cache extent cache entries */
1025 struct mutex extent_tree_lock; /* locking extent radix tree */
1026 struct list_head extent_list; /* lru list for shrinker */
1027 spinlock_t extent_lock; /* locking extent lru list */
1028 atomic_t total_ext_tree; /* extent tree count */
1029 struct list_head zombie_list; /* extent zombie tree list */
1030 atomic_t total_zombie_tree; /* extent zombie tree count */
1031 atomic_t total_ext_node; /* extent info count */
1033 /* basic filesystem units */
1034 unsigned int log_sectors_per_block; /* log2 sectors per block */
1035 unsigned int log_blocksize; /* log2 block size */
1036 unsigned int blocksize; /* block size */
1037 unsigned int root_ino_num; /* root inode number*/
1038 unsigned int node_ino_num; /* node inode number*/
1039 unsigned int meta_ino_num; /* meta inode number*/
1040 unsigned int log_blocks_per_seg; /* log2 blocks per segment */
1041 unsigned int blocks_per_seg; /* blocks per segment */
1042 unsigned int segs_per_sec; /* segments per section */
1043 unsigned int secs_per_zone; /* sections per zone */
1044 unsigned int total_sections; /* total section count */
1045 unsigned int total_node_count; /* total node block count */
1046 unsigned int total_valid_node_count; /* valid node block count */
1047 loff_t max_file_blocks; /* max block index of file */
1048 int active_logs; /* # of active logs */
1049 int dir_level; /* directory level */
1051 block_t user_block_count; /* # of user blocks */
1052 block_t total_valid_block_count; /* # of valid blocks */
1053 block_t discard_blks; /* discard command candidats */
1054 block_t last_valid_block_count; /* for recovery */
1055 block_t reserved_blocks; /* configurable reserved blocks */
1057 u32 s_next_generation; /* for NFS support */
1059 /* # of pages, see count_type */
1060 atomic_t nr_pages[NR_COUNT_TYPE];
1061 /* # of allocated blocks */
1062 struct percpu_counter alloc_valid_block_count;
1064 /* writeback control */
1065 atomic_t wb_sync_req; /* count # of WB_SYNC threads */
1067 /* valid inode count */
1068 struct percpu_counter total_valid_inode_count;
1070 struct f2fs_mount_info mount_opt; /* mount options */
1072 /* for cleaning operations */
1073 struct mutex gc_mutex; /* mutex for GC */
1074 struct f2fs_gc_kthread *gc_thread; /* GC thread */
1075 unsigned int cur_victim_sec; /* current victim section num */
1077 /* threshold for converting bg victims for fg */
1078 u64 fggc_threshold;
1080 /* maximum # of trials to find a victim segment for SSR and GC */
1081 unsigned int max_victim_search;
1084 * for stat information.
1085 * one is for the LFS mode, and the other is for the SSR mode.
1087 #ifdef CONFIG_F2FS_STAT_FS
1088 struct f2fs_stat_info *stat_info; /* FS status information */
1089 unsigned int segment_count[2]; /* # of allocated segments */
1090 unsigned int block_count[2]; /* # of allocated blocks */
1091 atomic_t inplace_count; /* # of inplace update */
1092 atomic64_t total_hit_ext; /* # of lookup extent cache */
1093 atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */
1094 atomic64_t read_hit_largest; /* # of hit largest extent node */
1095 atomic64_t read_hit_cached; /* # of hit cached extent node */
1096 atomic_t inline_xattr; /* # of inline_xattr inodes */
1097 atomic_t inline_inode; /* # of inline_data inodes */
1098 atomic_t inline_dir; /* # of inline_dentry inodes */
1099 atomic_t aw_cnt; /* # of atomic writes */
1100 atomic_t vw_cnt; /* # of volatile writes */
1101 atomic_t max_aw_cnt; /* max # of atomic writes */
1102 atomic_t max_vw_cnt; /* max # of volatile writes */
1103 int bg_gc; /* background gc calls */
1104 unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */
1105 #endif
1106 spinlock_t stat_lock; /* lock for stat operations */
1108 /* For app/fs IO statistics */
1109 spinlock_t iostat_lock;
1110 unsigned long long write_iostat[NR_IO_TYPE];
1111 bool iostat_enable;
1113 /* For sysfs suppport */
1114 struct kobject s_kobj;
1115 struct completion s_kobj_unregister;
1117 /* For shrinker support */
1118 struct list_head s_list;
1119 int s_ndevs; /* number of devices */
1120 struct f2fs_dev_info *devs; /* for device list */
1121 struct mutex umount_mutex;
1122 unsigned int shrinker_run_no;
1124 /* For write statistics */
1125 u64 sectors_written_start;
1126 u64 kbytes_written;
1128 /* Reference to checksum algorithm driver via cryptoapi */
1129 struct crypto_shash *s_chksum_driver;
1131 /* Precomputed FS UUID checksum for seeding other checksums */
1132 __u32 s_chksum_seed;
1134 /* For fault injection */
1135 #ifdef CONFIG_F2FS_FAULT_INJECTION
1136 struct f2fs_fault_info fault_info;
1137 #endif
1139 #ifdef CONFIG_QUOTA
1140 /* Names of quota files with journalled quota */
1141 char *s_qf_names[MAXQUOTAS];
1142 int s_jquota_fmt; /* Format of quota to use */
1143 #endif
1146 #ifdef CONFIG_F2FS_FAULT_INJECTION
1147 #define f2fs_show_injection_info(type) \
1148 printk("%sF2FS-fs : inject %s in %s of %pF\n", \
1149 KERN_INFO, fault_name[type], \
1150 __func__, __builtin_return_address(0))
1151 static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type)
1153 struct f2fs_fault_info *ffi = &sbi->fault_info;
1155 if (!ffi->inject_rate)
1156 return false;
1158 if (!IS_FAULT_SET(ffi, type))
1159 return false;
1161 atomic_inc(&ffi->inject_ops);
1162 if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) {
1163 atomic_set(&ffi->inject_ops, 0);
1164 return true;
1166 return false;
1168 #endif
1171 * Test if the mounted volume is a multi-device volume.
1172 * - For a single regular disk volume, sbi->s_ndevs is 0.
1173 * - For a single zoned disk volume, sbi->s_ndevs is 1.
1174 * - For a multi-device volume, sbi->s_ndevs is always 2 or more.
1176 static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi)
1178 return sbi->s_ndevs > 1;
1181 /* For write statistics. Suppose sector size is 512 bytes,
1182 * and the return value is in kbytes. s is of struct f2fs_sb_info.
1184 #define BD_PART_WRITTEN(s) \
1185 (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \
1186 (s)->sectors_written_start) >> 1)
1188 static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
1190 sbi->last_time[type] = jiffies;
1193 static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type)
1195 struct timespec ts = {sbi->interval_time[type], 0};
1196 unsigned long interval = timespec_to_jiffies(&ts);
1198 return time_after(jiffies, sbi->last_time[type] + interval);
1201 static inline bool is_idle(struct f2fs_sb_info *sbi)
1203 struct block_device *bdev = sbi->sb->s_bdev;
1204 struct request_queue *q = bdev_get_queue(bdev);
1205 struct request_list *rl = &q->root_rl;
1207 if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC])
1208 return 0;
1210 return f2fs_time_over(sbi, REQ_TIME);
1214 * Inline functions
1216 static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address,
1217 unsigned int length)
1219 SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver);
1220 u32 *ctx = (u32 *)shash_desc_ctx(shash);
1221 u32 retval;
1222 int err;
1224 shash->tfm = sbi->s_chksum_driver;
1225 shash->flags = 0;
1226 *ctx = F2FS_SUPER_MAGIC;
1228 err = crypto_shash_update(shash, address, length);
1229 BUG_ON(err);
1231 retval = *ctx;
1232 barrier_data(ctx);
1233 return retval;
1236 static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc,
1237 void *buf, size_t buf_size)
1239 return f2fs_crc32(sbi, buf, buf_size) == blk_crc;
1242 static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc,
1243 const void *address, unsigned int length)
1245 struct {
1246 struct shash_desc shash;
1247 char ctx[4];
1248 } desc;
1249 int err;
1251 BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx));
1253 desc.shash.tfm = sbi->s_chksum_driver;
1254 desc.shash.flags = 0;
1255 *(u32 *)desc.ctx = crc;
1257 err = crypto_shash_update(&desc.shash, address, length);
1258 BUG_ON(err);
1260 return *(u32 *)desc.ctx;
1263 static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
1265 return container_of(inode, struct f2fs_inode_info, vfs_inode);
1268 static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
1270 return sb->s_fs_info;
1273 static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
1275 return F2FS_SB(inode->i_sb);
1278 static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
1280 return F2FS_I_SB(mapping->host);
1283 static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
1285 return F2FS_M_SB(page->mapping);
1288 static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
1290 return (struct f2fs_super_block *)(sbi->raw_super);
1293 static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
1295 return (struct f2fs_checkpoint *)(sbi->ckpt);
1298 static inline struct f2fs_node *F2FS_NODE(struct page *page)
1300 return (struct f2fs_node *)page_address(page);
1303 static inline struct f2fs_inode *F2FS_INODE(struct page *page)
1305 return &((struct f2fs_node *)page_address(page))->i;
1308 static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
1310 return (struct f2fs_nm_info *)(sbi->nm_info);
1313 static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
1315 return (struct f2fs_sm_info *)(sbi->sm_info);
1318 static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
1320 return (struct sit_info *)(SM_I(sbi)->sit_info);
1323 static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
1325 return (struct free_segmap_info *)(SM_I(sbi)->free_info);
1328 static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
1330 return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
1333 static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
1335 return sbi->meta_inode->i_mapping;
1338 static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
1340 return sbi->node_inode->i_mapping;
1343 static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
1345 return test_bit(type, &sbi->s_flag);
1348 static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
1350 set_bit(type, &sbi->s_flag);
1353 static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
1355 clear_bit(type, &sbi->s_flag);
1358 static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
1360 return le64_to_cpu(cp->checkpoint_ver);
1363 static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp)
1365 size_t crc_offset = le32_to_cpu(cp->checksum_offset);
1366 return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset)));
1369 static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1371 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
1373 return ckpt_flags & f;
1376 static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
1378 return __is_set_ckpt_flags(F2FS_CKPT(sbi), f);
1381 static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1383 unsigned int ckpt_flags;
1385 ckpt_flags = le32_to_cpu(cp->ckpt_flags);
1386 ckpt_flags |= f;
1387 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
1390 static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
1392 unsigned long flags;
1394 spin_lock_irqsave(&sbi->cp_lock, flags);
1395 __set_ckpt_flags(F2FS_CKPT(sbi), f);
1396 spin_unlock_irqrestore(&sbi->cp_lock, flags);
1399 static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1401 unsigned int ckpt_flags;
1403 ckpt_flags = le32_to_cpu(cp->ckpt_flags);
1404 ckpt_flags &= (~f);
1405 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
1408 static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
1410 unsigned long flags;
1412 spin_lock_irqsave(&sbi->cp_lock, flags);
1413 __clear_ckpt_flags(F2FS_CKPT(sbi), f);
1414 spin_unlock_irqrestore(&sbi->cp_lock, flags);
1417 static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock)
1419 unsigned long flags;
1421 set_sbi_flag(sbi, SBI_NEED_FSCK);
1423 if (lock)
1424 spin_lock_irqsave(&sbi->cp_lock, flags);
1425 __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG);
1426 kfree(NM_I(sbi)->nat_bits);
1427 NM_I(sbi)->nat_bits = NULL;
1428 if (lock)
1429 spin_unlock_irqrestore(&sbi->cp_lock, flags);
1432 static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
1433 struct cp_control *cpc)
1435 bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG);
1437 return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set;
1440 static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
1442 down_read(&sbi->cp_rwsem);
1445 static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi)
1447 return down_read_trylock(&sbi->cp_rwsem);
1450 static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
1452 up_read(&sbi->cp_rwsem);
1455 static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
1457 down_write(&sbi->cp_rwsem);
1460 static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
1462 up_write(&sbi->cp_rwsem);
1465 static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
1467 int reason = CP_SYNC;
1469 if (test_opt(sbi, FASTBOOT))
1470 reason = CP_FASTBOOT;
1471 if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
1472 reason = CP_UMOUNT;
1473 return reason;
1476 static inline bool __remain_node_summaries(int reason)
1478 return (reason & (CP_UMOUNT | CP_FASTBOOT));
1481 static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
1483 return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) ||
1484 is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG));
1488 * Check whether the inode has blocks or not
1490 static inline int F2FS_HAS_BLOCKS(struct inode *inode)
1492 block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0;
1494 return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block;
1497 static inline bool f2fs_has_xattr_block(unsigned int ofs)
1499 return ofs == XATTR_NODE_OFFSET;
1502 static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool);
1503 static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
1504 struct inode *inode, blkcnt_t *count)
1506 blkcnt_t diff = 0, release = 0;
1507 block_t avail_user_block_count;
1508 int ret;
1510 ret = dquot_reserve_block(inode, *count);
1511 if (ret)
1512 return ret;
1514 #ifdef CONFIG_F2FS_FAULT_INJECTION
1515 if (time_to_inject(sbi, FAULT_BLOCK)) {
1516 f2fs_show_injection_info(FAULT_BLOCK);
1517 release = *count;
1518 goto enospc;
1520 #endif
1522 * let's increase this in prior to actual block count change in order
1523 * for f2fs_sync_file to avoid data races when deciding checkpoint.
1525 percpu_counter_add(&sbi->alloc_valid_block_count, (*count));
1527 spin_lock(&sbi->stat_lock);
1528 sbi->total_valid_block_count += (block_t)(*count);
1529 avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks;
1530 if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
1531 diff = sbi->total_valid_block_count - avail_user_block_count;
1532 *count -= diff;
1533 release = diff;
1534 sbi->total_valid_block_count = avail_user_block_count;
1535 if (!*count) {
1536 spin_unlock(&sbi->stat_lock);
1537 percpu_counter_sub(&sbi->alloc_valid_block_count, diff);
1538 goto enospc;
1541 spin_unlock(&sbi->stat_lock);
1543 if (release)
1544 dquot_release_reservation_block(inode, release);
1545 f2fs_i_blocks_write(inode, *count, true, true);
1546 return 0;
1548 enospc:
1549 dquot_release_reservation_block(inode, release);
1550 return -ENOSPC;
1553 static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
1554 struct inode *inode,
1555 block_t count)
1557 blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK;
1559 spin_lock(&sbi->stat_lock);
1560 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
1561 f2fs_bug_on(sbi, inode->i_blocks < sectors);
1562 sbi->total_valid_block_count -= (block_t)count;
1563 spin_unlock(&sbi->stat_lock);
1564 f2fs_i_blocks_write(inode, count, false, true);
1567 static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
1569 atomic_inc(&sbi->nr_pages[count_type]);
1571 if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES ||
1572 count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA)
1573 return;
1575 set_sbi_flag(sbi, SBI_IS_DIRTY);
1578 static inline void inode_inc_dirty_pages(struct inode *inode)
1580 atomic_inc(&F2FS_I(inode)->dirty_pages);
1581 inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1582 F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
1585 static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
1587 atomic_dec(&sbi->nr_pages[count_type]);
1590 static inline void inode_dec_dirty_pages(struct inode *inode)
1592 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
1593 !S_ISLNK(inode->i_mode))
1594 return;
1596 atomic_dec(&F2FS_I(inode)->dirty_pages);
1597 dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1598 F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
1601 static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type)
1603 return atomic_read(&sbi->nr_pages[count_type]);
1606 static inline int get_dirty_pages(struct inode *inode)
1608 return atomic_read(&F2FS_I(inode)->dirty_pages);
1611 static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
1613 unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg;
1614 unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >>
1615 sbi->log_blocks_per_seg;
1617 return segs / sbi->segs_per_sec;
1620 static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
1622 return sbi->total_valid_block_count;
1625 static inline block_t discard_blocks(struct f2fs_sb_info *sbi)
1627 return sbi->discard_blks;
1630 static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
1632 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1634 /* return NAT or SIT bitmap */
1635 if (flag == NAT_BITMAP)
1636 return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
1637 else if (flag == SIT_BITMAP)
1638 return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
1640 return 0;
1643 static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
1645 return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
1648 static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
1650 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1651 int offset;
1653 if (__cp_payload(sbi) > 0) {
1654 if (flag == NAT_BITMAP)
1655 return &ckpt->sit_nat_version_bitmap;
1656 else
1657 return (unsigned char *)ckpt + F2FS_BLKSIZE;
1658 } else {
1659 offset = (flag == NAT_BITMAP) ?
1660 le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
1661 return &ckpt->sit_nat_version_bitmap + offset;
1665 static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
1667 block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
1669 if (sbi->cur_cp_pack == 2)
1670 start_addr += sbi->blocks_per_seg;
1671 return start_addr;
1674 static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi)
1676 block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
1678 if (sbi->cur_cp_pack == 1)
1679 start_addr += sbi->blocks_per_seg;
1680 return start_addr;
1683 static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi)
1685 sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1;
1688 static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
1690 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
1693 static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
1694 struct inode *inode, bool is_inode)
1696 block_t valid_block_count;
1697 unsigned int valid_node_count;
1698 bool quota = inode && !is_inode;
1700 if (quota) {
1701 int ret = dquot_reserve_block(inode, 1);
1702 if (ret)
1703 return ret;
1706 spin_lock(&sbi->stat_lock);
1708 valid_block_count = sbi->total_valid_block_count + 1;
1709 if (unlikely(valid_block_count + sbi->reserved_blocks >
1710 sbi->user_block_count)) {
1711 spin_unlock(&sbi->stat_lock);
1712 goto enospc;
1715 valid_node_count = sbi->total_valid_node_count + 1;
1716 if (unlikely(valid_node_count > sbi->total_node_count)) {
1717 spin_unlock(&sbi->stat_lock);
1718 goto enospc;
1721 sbi->total_valid_node_count++;
1722 sbi->total_valid_block_count++;
1723 spin_unlock(&sbi->stat_lock);
1725 if (inode) {
1726 if (is_inode)
1727 f2fs_mark_inode_dirty_sync(inode, true);
1728 else
1729 f2fs_i_blocks_write(inode, 1, true, true);
1732 percpu_counter_inc(&sbi->alloc_valid_block_count);
1733 return 0;
1735 enospc:
1736 if (quota)
1737 dquot_release_reservation_block(inode, 1);
1738 return -ENOSPC;
1741 static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
1742 struct inode *inode, bool is_inode)
1744 spin_lock(&sbi->stat_lock);
1746 f2fs_bug_on(sbi, !sbi->total_valid_block_count);
1747 f2fs_bug_on(sbi, !sbi->total_valid_node_count);
1748 f2fs_bug_on(sbi, !is_inode && !inode->i_blocks);
1750 sbi->total_valid_node_count--;
1751 sbi->total_valid_block_count--;
1753 spin_unlock(&sbi->stat_lock);
1755 if (!is_inode)
1756 f2fs_i_blocks_write(inode, 1, false, true);
1759 static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
1761 return sbi->total_valid_node_count;
1764 static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
1766 percpu_counter_inc(&sbi->total_valid_inode_count);
1769 static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
1771 percpu_counter_dec(&sbi->total_valid_inode_count);
1774 static inline s64 valid_inode_count(struct f2fs_sb_info *sbi)
1776 return percpu_counter_sum_positive(&sbi->total_valid_inode_count);
1779 static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
1780 pgoff_t index, bool for_write)
1782 #ifdef CONFIG_F2FS_FAULT_INJECTION
1783 struct page *page;
1785 if (!for_write)
1786 page = find_get_page_flags(mapping, index,
1787 FGP_LOCK | FGP_ACCESSED);
1788 else
1789 page = find_lock_page(mapping, index);
1790 if (page)
1791 return page;
1793 if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) {
1794 f2fs_show_injection_info(FAULT_PAGE_ALLOC);
1795 return NULL;
1797 #endif
1798 if (!for_write)
1799 return grab_cache_page(mapping, index);
1800 return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
1803 static inline void f2fs_copy_page(struct page *src, struct page *dst)
1805 char *src_kaddr = kmap(src);
1806 char *dst_kaddr = kmap(dst);
1808 memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
1809 kunmap(dst);
1810 kunmap(src);
1813 static inline void f2fs_put_page(struct page *page, int unlock)
1815 if (!page)
1816 return;
1818 if (unlock) {
1819 f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
1820 unlock_page(page);
1822 put_page(page);
1825 static inline void f2fs_put_dnode(struct dnode_of_data *dn)
1827 if (dn->node_page)
1828 f2fs_put_page(dn->node_page, 1);
1829 if (dn->inode_page && dn->node_page != dn->inode_page)
1830 f2fs_put_page(dn->inode_page, 0);
1831 dn->node_page = NULL;
1832 dn->inode_page = NULL;
1835 static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
1836 size_t size)
1838 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
1841 static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
1842 gfp_t flags)
1844 void *entry;
1846 entry = kmem_cache_alloc(cachep, flags);
1847 if (!entry)
1848 entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
1849 return entry;
1852 static inline struct bio *f2fs_bio_alloc(int npages)
1854 struct bio *bio;
1856 /* No failure on bio allocation */
1857 bio = bio_alloc(GFP_NOIO, npages);
1858 if (!bio)
1859 bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
1860 return bio;
1863 static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
1864 unsigned long index, void *item)
1866 while (radix_tree_insert(root, index, item))
1867 cond_resched();
1870 #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
1872 static inline bool IS_INODE(struct page *page)
1874 struct f2fs_node *p = F2FS_NODE(page);
1876 return RAW_IS_INODE(p);
1879 static inline int offset_in_addr(struct f2fs_inode *i)
1881 return (i->i_inline & F2FS_EXTRA_ATTR) ?
1882 (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0;
1885 static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
1887 return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
1890 static inline int f2fs_has_extra_attr(struct inode *inode);
1891 static inline block_t datablock_addr(struct inode *inode,
1892 struct page *node_page, unsigned int offset)
1894 struct f2fs_node *raw_node;
1895 __le32 *addr_array;
1896 int base = 0;
1897 bool is_inode = IS_INODE(node_page);
1899 raw_node = F2FS_NODE(node_page);
1901 /* from GC path only */
1902 if (!inode) {
1903 if (is_inode)
1904 base = offset_in_addr(&raw_node->i);
1905 } else if (f2fs_has_extra_attr(inode) && is_inode) {
1906 base = get_extra_isize(inode);
1909 addr_array = blkaddr_in_node(raw_node);
1910 return le32_to_cpu(addr_array[base + offset]);
1913 static inline int f2fs_test_bit(unsigned int nr, char *addr)
1915 int mask;
1917 addr += (nr >> 3);
1918 mask = 1 << (7 - (nr & 0x07));
1919 return mask & *addr;
1922 static inline void f2fs_set_bit(unsigned int nr, char *addr)
1924 int mask;
1926 addr += (nr >> 3);
1927 mask = 1 << (7 - (nr & 0x07));
1928 *addr |= mask;
1931 static inline void f2fs_clear_bit(unsigned int nr, char *addr)
1933 int mask;
1935 addr += (nr >> 3);
1936 mask = 1 << (7 - (nr & 0x07));
1937 *addr &= ~mask;
1940 static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
1942 int mask;
1943 int ret;
1945 addr += (nr >> 3);
1946 mask = 1 << (7 - (nr & 0x07));
1947 ret = mask & *addr;
1948 *addr |= mask;
1949 return ret;
1952 static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
1954 int mask;
1955 int ret;
1957 addr += (nr >> 3);
1958 mask = 1 << (7 - (nr & 0x07));
1959 ret = mask & *addr;
1960 *addr &= ~mask;
1961 return ret;
1964 static inline void f2fs_change_bit(unsigned int nr, char *addr)
1966 int mask;
1968 addr += (nr >> 3);
1969 mask = 1 << (7 - (nr & 0x07));
1970 *addr ^= mask;
1973 #define F2FS_REG_FLMASK (~(FS_DIRSYNC_FL | FS_TOPDIR_FL))
1974 #define F2FS_OTHER_FLMASK (FS_NODUMP_FL | FS_NOATIME_FL)
1975 #define F2FS_FL_INHERITED (FS_PROJINHERIT_FL)
1977 static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags)
1979 if (S_ISDIR(mode))
1980 return flags;
1981 else if (S_ISREG(mode))
1982 return flags & F2FS_REG_FLMASK;
1983 else
1984 return flags & F2FS_OTHER_FLMASK;
1987 /* used for f2fs_inode_info->flags */
1988 enum {
1989 FI_NEW_INODE, /* indicate newly allocated inode */
1990 FI_DIRTY_INODE, /* indicate inode is dirty or not */
1991 FI_AUTO_RECOVER, /* indicate inode is recoverable */
1992 FI_DIRTY_DIR, /* indicate directory has dirty pages */
1993 FI_INC_LINK, /* need to increment i_nlink */
1994 FI_ACL_MODE, /* indicate acl mode */
1995 FI_NO_ALLOC, /* should not allocate any blocks */
1996 FI_FREE_NID, /* free allocated nide */
1997 FI_NO_EXTENT, /* not to use the extent cache */
1998 FI_INLINE_XATTR, /* used for inline xattr */
1999 FI_INLINE_DATA, /* used for inline data*/
2000 FI_INLINE_DENTRY, /* used for inline dentry */
2001 FI_APPEND_WRITE, /* inode has appended data */
2002 FI_UPDATE_WRITE, /* inode has in-place-update data */
2003 FI_NEED_IPU, /* used for ipu per file */
2004 FI_ATOMIC_FILE, /* indicate atomic file */
2005 FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */
2006 FI_VOLATILE_FILE, /* indicate volatile file */
2007 FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */
2008 FI_DROP_CACHE, /* drop dirty page cache */
2009 FI_DATA_EXIST, /* indicate data exists */
2010 FI_INLINE_DOTS, /* indicate inline dot dentries */
2011 FI_DO_DEFRAG, /* indicate defragment is running */
2012 FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */
2013 FI_NO_PREALLOC, /* indicate skipped preallocated blocks */
2014 FI_HOT_DATA, /* indicate file is hot */
2015 FI_EXTRA_ATTR, /* indicate file has extra attribute */
2016 FI_PROJ_INHERIT, /* indicate file inherits projectid */
2019 static inline void __mark_inode_dirty_flag(struct inode *inode,
2020 int flag, bool set)
2022 switch (flag) {
2023 case FI_INLINE_XATTR:
2024 case FI_INLINE_DATA:
2025 case FI_INLINE_DENTRY:
2026 if (set)
2027 return;
2028 case FI_DATA_EXIST:
2029 case FI_INLINE_DOTS:
2030 f2fs_mark_inode_dirty_sync(inode, true);
2034 static inline void set_inode_flag(struct inode *inode, int flag)
2036 if (!test_bit(flag, &F2FS_I(inode)->flags))
2037 set_bit(flag, &F2FS_I(inode)->flags);
2038 __mark_inode_dirty_flag(inode, flag, true);
2041 static inline int is_inode_flag_set(struct inode *inode, int flag)
2043 return test_bit(flag, &F2FS_I(inode)->flags);
2046 static inline void clear_inode_flag(struct inode *inode, int flag)
2048 if (test_bit(flag, &F2FS_I(inode)->flags))
2049 clear_bit(flag, &F2FS_I(inode)->flags);
2050 __mark_inode_dirty_flag(inode, flag, false);
2053 static inline void set_acl_inode(struct inode *inode, umode_t mode)
2055 F2FS_I(inode)->i_acl_mode = mode;
2056 set_inode_flag(inode, FI_ACL_MODE);
2057 f2fs_mark_inode_dirty_sync(inode, false);
2060 static inline void f2fs_i_links_write(struct inode *inode, bool inc)
2062 if (inc)
2063 inc_nlink(inode);
2064 else
2065 drop_nlink(inode);
2066 f2fs_mark_inode_dirty_sync(inode, true);
2069 static inline void f2fs_i_blocks_write(struct inode *inode,
2070 block_t diff, bool add, bool claim)
2072 bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
2073 bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
2075 /* add = 1, claim = 1 should be dquot_reserve_block in pair */
2076 if (add) {
2077 if (claim)
2078 dquot_claim_block(inode, diff);
2079 else
2080 dquot_alloc_block_nofail(inode, diff);
2081 } else {
2082 dquot_free_block(inode, diff);
2085 f2fs_mark_inode_dirty_sync(inode, true);
2086 if (clean || recover)
2087 set_inode_flag(inode, FI_AUTO_RECOVER);
2090 static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size)
2092 bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
2093 bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
2095 if (i_size_read(inode) == i_size)
2096 return;
2098 i_size_write(inode, i_size);
2099 f2fs_mark_inode_dirty_sync(inode, true);
2100 if (clean || recover)
2101 set_inode_flag(inode, FI_AUTO_RECOVER);
2104 static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth)
2106 F2FS_I(inode)->i_current_depth = depth;
2107 f2fs_mark_inode_dirty_sync(inode, true);
2110 static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid)
2112 F2FS_I(inode)->i_xattr_nid = xnid;
2113 f2fs_mark_inode_dirty_sync(inode, true);
2116 static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino)
2118 F2FS_I(inode)->i_pino = pino;
2119 f2fs_mark_inode_dirty_sync(inode, true);
2122 static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri)
2124 struct f2fs_inode_info *fi = F2FS_I(inode);
2126 if (ri->i_inline & F2FS_INLINE_XATTR)
2127 set_bit(FI_INLINE_XATTR, &fi->flags);
2128 if (ri->i_inline & F2FS_INLINE_DATA)
2129 set_bit(FI_INLINE_DATA, &fi->flags);
2130 if (ri->i_inline & F2FS_INLINE_DENTRY)
2131 set_bit(FI_INLINE_DENTRY, &fi->flags);
2132 if (ri->i_inline & F2FS_DATA_EXIST)
2133 set_bit(FI_DATA_EXIST, &fi->flags);
2134 if (ri->i_inline & F2FS_INLINE_DOTS)
2135 set_bit(FI_INLINE_DOTS, &fi->flags);
2136 if (ri->i_inline & F2FS_EXTRA_ATTR)
2137 set_bit(FI_EXTRA_ATTR, &fi->flags);
2140 static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri)
2142 ri->i_inline = 0;
2144 if (is_inode_flag_set(inode, FI_INLINE_XATTR))
2145 ri->i_inline |= F2FS_INLINE_XATTR;
2146 if (is_inode_flag_set(inode, FI_INLINE_DATA))
2147 ri->i_inline |= F2FS_INLINE_DATA;
2148 if (is_inode_flag_set(inode, FI_INLINE_DENTRY))
2149 ri->i_inline |= F2FS_INLINE_DENTRY;
2150 if (is_inode_flag_set(inode, FI_DATA_EXIST))
2151 ri->i_inline |= F2FS_DATA_EXIST;
2152 if (is_inode_flag_set(inode, FI_INLINE_DOTS))
2153 ri->i_inline |= F2FS_INLINE_DOTS;
2154 if (is_inode_flag_set(inode, FI_EXTRA_ATTR))
2155 ri->i_inline |= F2FS_EXTRA_ATTR;
2158 static inline int f2fs_has_extra_attr(struct inode *inode)
2160 return is_inode_flag_set(inode, FI_EXTRA_ATTR);
2163 static inline int f2fs_has_inline_xattr(struct inode *inode)
2165 return is_inode_flag_set(inode, FI_INLINE_XATTR);
2168 static inline unsigned int addrs_per_inode(struct inode *inode)
2170 if (f2fs_has_inline_xattr(inode))
2171 return CUR_ADDRS_PER_INODE(inode) - F2FS_INLINE_XATTR_ADDRS;
2172 return CUR_ADDRS_PER_INODE(inode);
2175 static inline void *inline_xattr_addr(struct page *page)
2177 struct f2fs_inode *ri = F2FS_INODE(page);
2179 return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
2180 F2FS_INLINE_XATTR_ADDRS]);
2183 static inline int inline_xattr_size(struct inode *inode)
2185 if (f2fs_has_inline_xattr(inode))
2186 return F2FS_INLINE_XATTR_ADDRS << 2;
2187 else
2188 return 0;
2191 static inline int f2fs_has_inline_data(struct inode *inode)
2193 return is_inode_flag_set(inode, FI_INLINE_DATA);
2196 static inline int f2fs_exist_data(struct inode *inode)
2198 return is_inode_flag_set(inode, FI_DATA_EXIST);
2201 static inline int f2fs_has_inline_dots(struct inode *inode)
2203 return is_inode_flag_set(inode, FI_INLINE_DOTS);
2206 static inline bool f2fs_is_atomic_file(struct inode *inode)
2208 return is_inode_flag_set(inode, FI_ATOMIC_FILE);
2211 static inline bool f2fs_is_commit_atomic_write(struct inode *inode)
2213 return is_inode_flag_set(inode, FI_ATOMIC_COMMIT);
2216 static inline bool f2fs_is_volatile_file(struct inode *inode)
2218 return is_inode_flag_set(inode, FI_VOLATILE_FILE);
2221 static inline bool f2fs_is_first_block_written(struct inode *inode)
2223 return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN);
2226 static inline bool f2fs_is_drop_cache(struct inode *inode)
2228 return is_inode_flag_set(inode, FI_DROP_CACHE);
2231 static inline void *inline_data_addr(struct inode *inode, struct page *page)
2233 struct f2fs_inode *ri = F2FS_INODE(page);
2234 int extra_size = get_extra_isize(inode);
2236 return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]);
2239 static inline int f2fs_has_inline_dentry(struct inode *inode)
2241 return is_inode_flag_set(inode, FI_INLINE_DENTRY);
2244 static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
2246 if (!f2fs_has_inline_dentry(dir))
2247 kunmap(page);
2250 static inline int is_file(struct inode *inode, int type)
2252 return F2FS_I(inode)->i_advise & type;
2255 static inline void set_file(struct inode *inode, int type)
2257 F2FS_I(inode)->i_advise |= type;
2258 f2fs_mark_inode_dirty_sync(inode, true);
2261 static inline void clear_file(struct inode *inode, int type)
2263 F2FS_I(inode)->i_advise &= ~type;
2264 f2fs_mark_inode_dirty_sync(inode, true);
2267 static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync)
2269 if (dsync) {
2270 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
2271 bool ret;
2273 spin_lock(&sbi->inode_lock[DIRTY_META]);
2274 ret = list_empty(&F2FS_I(inode)->gdirty_list);
2275 spin_unlock(&sbi->inode_lock[DIRTY_META]);
2276 return ret;
2278 if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) ||
2279 file_keep_isize(inode) ||
2280 i_size_read(inode) & PAGE_MASK)
2281 return false;
2282 return F2FS_I(inode)->last_disk_size == i_size_read(inode);
2285 static inline int f2fs_readonly(struct super_block *sb)
2287 return sb->s_flags & MS_RDONLY;
2290 static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
2292 return is_set_ckpt_flags(sbi, CP_ERROR_FLAG);
2295 static inline bool is_dot_dotdot(const struct qstr *str)
2297 if (str->len == 1 && str->name[0] == '.')
2298 return true;
2300 if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
2301 return true;
2303 return false;
2306 static inline bool f2fs_may_extent_tree(struct inode *inode)
2308 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
2310 if (!test_opt(sbi, EXTENT_CACHE) ||
2311 is_inode_flag_set(inode, FI_NO_EXTENT))
2312 return false;
2315 * for recovered files during mount do not create extents
2316 * if shrinker is not registered.
2318 if (list_empty(&sbi->s_list))
2319 return false;
2321 return S_ISREG(inode->i_mode);
2324 static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
2325 size_t size, gfp_t flags)
2327 #ifdef CONFIG_F2FS_FAULT_INJECTION
2328 if (time_to_inject(sbi, FAULT_KMALLOC)) {
2329 f2fs_show_injection_info(FAULT_KMALLOC);
2330 return NULL;
2332 #endif
2333 return kmalloc(size, flags);
2336 static inline int get_extra_isize(struct inode *inode)
2338 return F2FS_I(inode)->i_extra_isize / sizeof(__le32);
2341 #define get_inode_mode(i) \
2342 ((is_inode_flag_set(i, FI_ACL_MODE)) ? \
2343 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
2345 #define F2FS_TOTAL_EXTRA_ATTR_SIZE \
2346 (offsetof(struct f2fs_inode, i_extra_end) - \
2347 offsetof(struct f2fs_inode, i_extra_isize)) \
2349 #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr))
2350 #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \
2351 ((offsetof(typeof(*f2fs_inode), field) + \
2352 sizeof((f2fs_inode)->field)) \
2353 <= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize)) \
2355 static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi)
2357 int i;
2359 spin_lock(&sbi->iostat_lock);
2360 for (i = 0; i < NR_IO_TYPE; i++)
2361 sbi->write_iostat[i] = 0;
2362 spin_unlock(&sbi->iostat_lock);
2365 static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi,
2366 enum iostat_type type, unsigned long long io_bytes)
2368 if (!sbi->iostat_enable)
2369 return;
2370 spin_lock(&sbi->iostat_lock);
2371 sbi->write_iostat[type] += io_bytes;
2373 if (type == APP_WRITE_IO || type == APP_DIRECT_IO)
2374 sbi->write_iostat[APP_BUFFERED_IO] =
2375 sbi->write_iostat[APP_WRITE_IO] -
2376 sbi->write_iostat[APP_DIRECT_IO];
2377 spin_unlock(&sbi->iostat_lock);
2380 #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO(fio->type) == META && \
2381 (!is_read_io(fio->op) || fio->is_meta))
2383 bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
2384 block_t blkaddr, int type);
2385 void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
2386 static inline void verify_blkaddr(struct f2fs_sb_info *sbi,
2387 block_t blkaddr, int type)
2389 if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) {
2390 f2fs_msg(sbi->sb, KERN_ERR,
2391 "invalid blkaddr: %u, type: %d, run fsck to fix.",
2392 blkaddr, type);
2393 f2fs_bug_on(sbi, 1);
2397 static inline bool __is_valid_data_blkaddr(block_t blkaddr)
2399 if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR)
2400 return false;
2401 return true;
2404 static inline bool is_valid_data_blkaddr(struct f2fs_sb_info *sbi,
2405 block_t blkaddr)
2407 if (!__is_valid_data_blkaddr(blkaddr))
2408 return false;
2409 verify_blkaddr(sbi, blkaddr, DATA_GENERIC);
2410 return true;
2414 * file.c
2416 int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync);
2417 void truncate_data_blocks(struct dnode_of_data *dn);
2418 int truncate_blocks(struct inode *inode, u64 from, bool lock);
2419 int f2fs_truncate(struct inode *inode);
2420 int f2fs_getattr(const struct path *path, struct kstat *stat,
2421 u32 request_mask, unsigned int flags);
2422 int f2fs_setattr(struct dentry *dentry, struct iattr *attr);
2423 int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end);
2424 int truncate_data_blocks_range(struct dnode_of_data *dn, int count);
2425 long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
2426 long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2429 * inode.c
2431 void f2fs_set_inode_flags(struct inode *inode);
2432 bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page);
2433 void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page);
2434 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
2435 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
2436 int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
2437 int update_inode(struct inode *inode, struct page *node_page);
2438 int update_inode_page(struct inode *inode);
2439 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
2440 void f2fs_evict_inode(struct inode *inode);
2441 void handle_failed_inode(struct inode *inode);
2444 * namei.c
2446 struct dentry *f2fs_get_parent(struct dentry *child);
2449 * dir.c
2451 void set_de_type(struct f2fs_dir_entry *de, umode_t mode);
2452 unsigned char get_de_type(struct f2fs_dir_entry *de);
2453 struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname,
2454 f2fs_hash_t namehash, int *max_slots,
2455 struct f2fs_dentry_ptr *d);
2456 int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
2457 unsigned int start_pos, struct fscrypt_str *fstr);
2458 void do_make_empty_dir(struct inode *inode, struct inode *parent,
2459 struct f2fs_dentry_ptr *d);
2460 struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
2461 const struct qstr *new_name,
2462 const struct qstr *orig_name, struct page *dpage);
2463 void update_parent_metadata(struct inode *dir, struct inode *inode,
2464 unsigned int current_depth);
2465 int room_for_filename(const void *bitmap, int slots, int max_slots);
2466 void f2fs_drop_nlink(struct inode *dir, struct inode *inode);
2467 struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir,
2468 struct fscrypt_name *fname, struct page **res_page);
2469 struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir,
2470 const struct qstr *child, struct page **res_page);
2471 struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p);
2472 ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr,
2473 struct page **page);
2474 void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,
2475 struct page *page, struct inode *inode);
2476 void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d,
2477 const struct qstr *name, f2fs_hash_t name_hash,
2478 unsigned int bit_pos);
2479 int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name,
2480 const struct qstr *orig_name,
2481 struct inode *inode, nid_t ino, umode_t mode);
2482 int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname,
2483 struct inode *inode, nid_t ino, umode_t mode);
2484 int __f2fs_add_link(struct inode *dir, const struct qstr *name,
2485 struct inode *inode, nid_t ino, umode_t mode);
2486 void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
2487 struct inode *dir, struct inode *inode);
2488 int f2fs_do_tmpfile(struct inode *inode, struct inode *dir);
2489 bool f2fs_empty_dir(struct inode *dir);
2491 static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
2493 return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name,
2494 inode, inode->i_ino, inode->i_mode);
2498 * super.c
2500 int f2fs_inode_dirtied(struct inode *inode, bool sync);
2501 void f2fs_inode_synced(struct inode *inode);
2502 void f2fs_enable_quota_files(struct f2fs_sb_info *sbi);
2503 void f2fs_quota_off_umount(struct super_block *sb);
2504 int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover);
2505 int f2fs_sync_fs(struct super_block *sb, int sync);
2506 extern __printf(3, 4)
2507 void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...);
2508 int sanity_check_ckpt(struct f2fs_sb_info *sbi);
2511 * hash.c
2513 f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info,
2514 struct fscrypt_name *fname);
2517 * node.c
2519 struct dnode_of_data;
2520 struct node_info;
2522 int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid);
2523 bool available_free_memory(struct f2fs_sb_info *sbi, int type);
2524 int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid);
2525 bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid);
2526 bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino);
2527 void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni);
2528 pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs);
2529 int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode);
2530 int truncate_inode_blocks(struct inode *inode, pgoff_t from);
2531 int truncate_xattr_node(struct inode *inode, struct page *page);
2532 int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino);
2533 int remove_inode_page(struct inode *inode);
2534 struct page *new_inode_page(struct inode *inode);
2535 struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs);
2536 void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid);
2537 struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid);
2538 struct page *get_node_page_ra(struct page *parent, int start);
2539 void move_node_page(struct page *node_page, int gc_type);
2540 int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
2541 struct writeback_control *wbc, bool atomic);
2542 int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc,
2543 bool do_balance, enum iostat_type io_type);
2544 void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount);
2545 bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid);
2546 void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid);
2547 void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid);
2548 int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink);
2549 void recover_inline_xattr(struct inode *inode, struct page *page);
2550 int recover_xattr_data(struct inode *inode, struct page *page,
2551 block_t blkaddr);
2552 int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page);
2553 int restore_node_summary(struct f2fs_sb_info *sbi,
2554 unsigned int segno, struct f2fs_summary_block *sum);
2555 void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2556 int build_node_manager(struct f2fs_sb_info *sbi);
2557 void destroy_node_manager(struct f2fs_sb_info *sbi);
2558 int __init create_node_manager_caches(void);
2559 void destroy_node_manager_caches(void);
2562 * segment.c
2564 bool need_SSR(struct f2fs_sb_info *sbi);
2565 void register_inmem_page(struct inode *inode, struct page *page);
2566 void drop_inmem_pages(struct inode *inode);
2567 void drop_inmem_page(struct inode *inode, struct page *page);
2568 int commit_inmem_pages(struct inode *inode);
2569 void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need);
2570 void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi);
2571 int f2fs_issue_flush(struct f2fs_sb_info *sbi);
2572 int create_flush_cmd_control(struct f2fs_sb_info *sbi);
2573 void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free);
2574 void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr);
2575 bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
2576 void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new);
2577 void stop_discard_thread(struct f2fs_sb_info *sbi);
2578 void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi, bool umount);
2579 void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2580 void release_discard_addrs(struct f2fs_sb_info *sbi);
2581 int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
2582 void allocate_new_segments(struct f2fs_sb_info *sbi);
2583 int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range);
2584 bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2585 struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno);
2586 void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr);
2587 void write_meta_page(struct f2fs_sb_info *sbi, struct page *page,
2588 enum iostat_type io_type);
2589 void write_node_page(unsigned int nid, struct f2fs_io_info *fio);
2590 void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio);
2591 int rewrite_data_page(struct f2fs_io_info *fio);
2592 void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
2593 block_t old_blkaddr, block_t new_blkaddr,
2594 bool recover_curseg, bool recover_newaddr);
2595 void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
2596 block_t old_addr, block_t new_addr,
2597 unsigned char version, bool recover_curseg,
2598 bool recover_newaddr);
2599 void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
2600 block_t old_blkaddr, block_t *new_blkaddr,
2601 struct f2fs_summary *sum, int type,
2602 struct f2fs_io_info *fio, bool add_list);
2603 void f2fs_wait_on_page_writeback(struct page *page,
2604 enum page_type type, bool ordered);
2605 void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr);
2606 void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
2607 void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk);
2608 int lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
2609 unsigned int val, int alloc);
2610 void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2611 int build_segment_manager(struct f2fs_sb_info *sbi);
2612 void destroy_segment_manager(struct f2fs_sb_info *sbi);
2613 int __init create_segment_manager_caches(void);
2614 void destroy_segment_manager_caches(void);
2617 * checkpoint.c
2619 void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io);
2620 struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
2621 struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
2622 struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index);
2623 bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
2624 block_t blkaddr, int type);
2625 int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
2626 int type, bool sync);
2627 void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index);
2628 long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type,
2629 long nr_to_write, enum iostat_type io_type);
2630 void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
2631 void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type);
2632 void release_ino_entry(struct f2fs_sb_info *sbi, bool all);
2633 bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode);
2634 int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi);
2635 int acquire_orphan_inode(struct f2fs_sb_info *sbi);
2636 void release_orphan_inode(struct f2fs_sb_info *sbi);
2637 void add_orphan_inode(struct inode *inode);
2638 void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino);
2639 int recover_orphan_inodes(struct f2fs_sb_info *sbi);
2640 int get_valid_checkpoint(struct f2fs_sb_info *sbi);
2641 void update_dirty_page(struct inode *inode, struct page *page);
2642 void remove_dirty_inode(struct inode *inode);
2643 int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type);
2644 int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2645 void init_ino_entry_info(struct f2fs_sb_info *sbi);
2646 int __init create_checkpoint_caches(void);
2647 void destroy_checkpoint_caches(void);
2650 * data.c
2652 void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
2653 void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
2654 struct inode *inode, nid_t ino, pgoff_t idx,
2655 enum page_type type);
2656 void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
2657 int f2fs_submit_page_bio(struct f2fs_io_info *fio);
2658 int f2fs_submit_page_write(struct f2fs_io_info *fio);
2659 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
2660 block_t blk_addr, struct bio *bio);
2661 int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
2662 void set_data_blkaddr(struct dnode_of_data *dn);
2663 void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr);
2664 int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count);
2665 int reserve_new_block(struct dnode_of_data *dn);
2666 int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index);
2667 int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from);
2668 int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index);
2669 struct page *get_read_data_page(struct inode *inode, pgoff_t index,
2670 int op_flags, bool for_write);
2671 struct page *find_data_page(struct inode *inode, pgoff_t index);
2672 struct page *get_lock_data_page(struct inode *inode, pgoff_t index,
2673 bool for_write);
2674 struct page *get_new_data_page(struct inode *inode,
2675 struct page *ipage, pgoff_t index, bool new_i_size);
2676 int do_write_data_page(struct f2fs_io_info *fio);
2677 int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
2678 int create, int flag);
2679 int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2680 u64 start, u64 len);
2681 void f2fs_set_page_dirty_nobuffers(struct page *page);
2682 int __f2fs_write_data_pages(struct address_space *mapping,
2683 struct writeback_control *wbc,
2684 enum iostat_type io_type);
2685 void f2fs_invalidate_page(struct page *page, unsigned int offset,
2686 unsigned int length);
2687 int f2fs_release_page(struct page *page, gfp_t wait);
2688 #ifdef CONFIG_MIGRATION
2689 int f2fs_migrate_page(struct address_space *mapping, struct page *newpage,
2690 struct page *page, enum migrate_mode mode);
2691 #endif
2694 * gc.c
2696 int start_gc_thread(struct f2fs_sb_info *sbi);
2697 void stop_gc_thread(struct f2fs_sb_info *sbi);
2698 block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode);
2699 int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background,
2700 unsigned int segno);
2701 void build_gc_manager(struct f2fs_sb_info *sbi);
2704 * recovery.c
2706 int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only);
2707 bool space_for_roll_forward(struct f2fs_sb_info *sbi);
2710 * debug.c
2712 #ifdef CONFIG_F2FS_STAT_FS
2713 struct f2fs_stat_info {
2714 struct list_head stat_list;
2715 struct f2fs_sb_info *sbi;
2716 int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
2717 int main_area_segs, main_area_sections, main_area_zones;
2718 unsigned long long hit_largest, hit_cached, hit_rbtree;
2719 unsigned long long hit_total, total_ext;
2720 int ext_tree, zombie_tree, ext_node;
2721 int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta;
2722 int inmem_pages;
2723 unsigned int ndirty_dirs, ndirty_files, ndirty_all;
2724 int nats, dirty_nats, sits, dirty_sits;
2725 int free_nids, avail_nids, alloc_nids;
2726 int total_count, utilization;
2727 int bg_gc, nr_wb_cp_data, nr_wb_data;
2728 int nr_flushing, nr_flushed, nr_discarding, nr_discarded;
2729 int nr_discard_cmd;
2730 unsigned int undiscard_blks;
2731 int inline_xattr, inline_inode, inline_dir, append, update, orphans;
2732 int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt;
2733 unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks;
2734 unsigned int bimodal, avg_vblocks;
2735 int util_free, util_valid, util_invalid;
2736 int rsvd_segs, overp_segs;
2737 int dirty_count, node_pages, meta_pages;
2738 int prefree_count, call_count, cp_count, bg_cp_count;
2739 int tot_segs, node_segs, data_segs, free_segs, free_secs;
2740 int bg_node_segs, bg_data_segs;
2741 int tot_blks, data_blks, node_blks;
2742 int bg_data_blks, bg_node_blks;
2743 int curseg[NR_CURSEG_TYPE];
2744 int cursec[NR_CURSEG_TYPE];
2745 int curzone[NR_CURSEG_TYPE];
2747 unsigned int segment_count[2];
2748 unsigned int block_count[2];
2749 unsigned int inplace_count;
2750 unsigned long long base_mem, cache_mem, page_mem;
2753 static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
2755 return (struct f2fs_stat_info *)sbi->stat_info;
2758 #define stat_inc_cp_count(si) ((si)->cp_count++)
2759 #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++)
2760 #define stat_inc_call_count(si) ((si)->call_count++)
2761 #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
2762 #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++)
2763 #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--)
2764 #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext))
2765 #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree))
2766 #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest))
2767 #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached))
2768 #define stat_inc_inline_xattr(inode) \
2769 do { \
2770 if (f2fs_has_inline_xattr(inode)) \
2771 (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \
2772 } while (0)
2773 #define stat_dec_inline_xattr(inode) \
2774 do { \
2775 if (f2fs_has_inline_xattr(inode)) \
2776 (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \
2777 } while (0)
2778 #define stat_inc_inline_inode(inode) \
2779 do { \
2780 if (f2fs_has_inline_data(inode)) \
2781 (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \
2782 } while (0)
2783 #define stat_dec_inline_inode(inode) \
2784 do { \
2785 if (f2fs_has_inline_data(inode)) \
2786 (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \
2787 } while (0)
2788 #define stat_inc_inline_dir(inode) \
2789 do { \
2790 if (f2fs_has_inline_dentry(inode)) \
2791 (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \
2792 } while (0)
2793 #define stat_dec_inline_dir(inode) \
2794 do { \
2795 if (f2fs_has_inline_dentry(inode)) \
2796 (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \
2797 } while (0)
2798 #define stat_inc_seg_type(sbi, curseg) \
2799 ((sbi)->segment_count[(curseg)->alloc_type]++)
2800 #define stat_inc_block_count(sbi, curseg) \
2801 ((sbi)->block_count[(curseg)->alloc_type]++)
2802 #define stat_inc_inplace_blocks(sbi) \
2803 (atomic_inc(&(sbi)->inplace_count))
2804 #define stat_inc_atomic_write(inode) \
2805 (atomic_inc(&F2FS_I_SB(inode)->aw_cnt))
2806 #define stat_dec_atomic_write(inode) \
2807 (atomic_dec(&F2FS_I_SB(inode)->aw_cnt))
2808 #define stat_update_max_atomic_write(inode) \
2809 do { \
2810 int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \
2811 int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \
2812 if (cur > max) \
2813 atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \
2814 } while (0)
2815 #define stat_inc_volatile_write(inode) \
2816 (atomic_inc(&F2FS_I_SB(inode)->vw_cnt))
2817 #define stat_dec_volatile_write(inode) \
2818 (atomic_dec(&F2FS_I_SB(inode)->vw_cnt))
2819 #define stat_update_max_volatile_write(inode) \
2820 do { \
2821 int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \
2822 int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \
2823 if (cur > max) \
2824 atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \
2825 } while (0)
2826 #define stat_inc_seg_count(sbi, type, gc_type) \
2827 do { \
2828 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
2829 si->tot_segs++; \
2830 if ((type) == SUM_TYPE_DATA) { \
2831 si->data_segs++; \
2832 si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \
2833 } else { \
2834 si->node_segs++; \
2835 si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \
2837 } while (0)
2839 #define stat_inc_tot_blk_count(si, blks) \
2840 ((si)->tot_blks += (blks))
2842 #define stat_inc_data_blk_count(sbi, blks, gc_type) \
2843 do { \
2844 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
2845 stat_inc_tot_blk_count(si, blks); \
2846 si->data_blks += (blks); \
2847 si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \
2848 } while (0)
2850 #define stat_inc_node_blk_count(sbi, blks, gc_type) \
2851 do { \
2852 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
2853 stat_inc_tot_blk_count(si, blks); \
2854 si->node_blks += (blks); \
2855 si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \
2856 } while (0)
2858 int f2fs_build_stats(struct f2fs_sb_info *sbi);
2859 void f2fs_destroy_stats(struct f2fs_sb_info *sbi);
2860 int __init f2fs_create_root_stats(void);
2861 void f2fs_destroy_root_stats(void);
2862 #else
2863 #define stat_inc_cp_count(si) do { } while (0)
2864 #define stat_inc_bg_cp_count(si) do { } while (0)
2865 #define stat_inc_call_count(si) do { } while (0)
2866 #define stat_inc_bggc_count(si) do { } while (0)
2867 #define stat_inc_dirty_inode(sbi, type) do { } while (0)
2868 #define stat_dec_dirty_inode(sbi, type) do { } while (0)
2869 #define stat_inc_total_hit(sb) do { } while (0)
2870 #define stat_inc_rbtree_node_hit(sb) do { } while (0)
2871 #define stat_inc_largest_node_hit(sbi) do { } while (0)
2872 #define stat_inc_cached_node_hit(sbi) do { } while (0)
2873 #define stat_inc_inline_xattr(inode) do { } while (0)
2874 #define stat_dec_inline_xattr(inode) do { } while (0)
2875 #define stat_inc_inline_inode(inode) do { } while (0)
2876 #define stat_dec_inline_inode(inode) do { } while (0)
2877 #define stat_inc_inline_dir(inode) do { } while (0)
2878 #define stat_dec_inline_dir(inode) do { } while (0)
2879 #define stat_inc_atomic_write(inode) do { } while (0)
2880 #define stat_dec_atomic_write(inode) do { } while (0)
2881 #define stat_update_max_atomic_write(inode) do { } while (0)
2882 #define stat_inc_volatile_write(inode) do { } while (0)
2883 #define stat_dec_volatile_write(inode) do { } while (0)
2884 #define stat_update_max_volatile_write(inode) do { } while (0)
2885 #define stat_inc_seg_type(sbi, curseg) do { } while (0)
2886 #define stat_inc_block_count(sbi, curseg) do { } while (0)
2887 #define stat_inc_inplace_blocks(sbi) do { } while (0)
2888 #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0)
2889 #define stat_inc_tot_blk_count(si, blks) do { } while (0)
2890 #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0)
2891 #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0)
2893 static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
2894 static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
2895 static inline int __init f2fs_create_root_stats(void) { return 0; }
2896 static inline void f2fs_destroy_root_stats(void) { }
2897 #endif
2899 extern const struct file_operations f2fs_dir_operations;
2900 extern const struct file_operations f2fs_file_operations;
2901 extern const struct inode_operations f2fs_file_inode_operations;
2902 extern const struct address_space_operations f2fs_dblock_aops;
2903 extern const struct address_space_operations f2fs_node_aops;
2904 extern const struct address_space_operations f2fs_meta_aops;
2905 extern const struct inode_operations f2fs_dir_inode_operations;
2906 extern const struct inode_operations f2fs_symlink_inode_operations;
2907 extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
2908 extern const struct inode_operations f2fs_special_inode_operations;
2909 extern struct kmem_cache *inode_entry_slab;
2912 * inline.c
2914 bool f2fs_may_inline_data(struct inode *inode);
2915 bool f2fs_may_inline_dentry(struct inode *inode);
2916 void read_inline_data(struct page *page, struct page *ipage);
2917 void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from);
2918 int f2fs_read_inline_data(struct inode *inode, struct page *page);
2919 int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page);
2920 int f2fs_convert_inline_inode(struct inode *inode);
2921 int f2fs_write_inline_data(struct inode *inode, struct page *page);
2922 bool recover_inline_data(struct inode *inode, struct page *npage);
2923 struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir,
2924 struct fscrypt_name *fname, struct page **res_page);
2925 int make_empty_inline_dir(struct inode *inode, struct inode *parent,
2926 struct page *ipage);
2927 int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
2928 const struct qstr *orig_name,
2929 struct inode *inode, nid_t ino, umode_t mode);
2930 void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,
2931 struct inode *dir, struct inode *inode);
2932 bool f2fs_empty_inline_dir(struct inode *dir);
2933 int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx,
2934 struct fscrypt_str *fstr);
2935 int f2fs_inline_data_fiemap(struct inode *inode,
2936 struct fiemap_extent_info *fieinfo,
2937 __u64 start, __u64 len);
2940 * shrinker.c
2942 unsigned long f2fs_shrink_count(struct shrinker *shrink,
2943 struct shrink_control *sc);
2944 unsigned long f2fs_shrink_scan(struct shrinker *shrink,
2945 struct shrink_control *sc);
2946 void f2fs_join_shrinker(struct f2fs_sb_info *sbi);
2947 void f2fs_leave_shrinker(struct f2fs_sb_info *sbi);
2950 * extent_cache.c
2952 struct rb_entry *__lookup_rb_tree(struct rb_root *root,
2953 struct rb_entry *cached_re, unsigned int ofs);
2954 struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi,
2955 struct rb_root *root, struct rb_node **parent,
2956 unsigned int ofs);
2957 struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root,
2958 struct rb_entry *cached_re, unsigned int ofs,
2959 struct rb_entry **prev_entry, struct rb_entry **next_entry,
2960 struct rb_node ***insert_p, struct rb_node **insert_parent,
2961 bool force);
2962 bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi,
2963 struct rb_root *root);
2964 unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink);
2965 bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext);
2966 void f2fs_drop_extent_tree(struct inode *inode);
2967 unsigned int f2fs_destroy_extent_node(struct inode *inode);
2968 void f2fs_destroy_extent_tree(struct inode *inode);
2969 bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs,
2970 struct extent_info *ei);
2971 void f2fs_update_extent_cache(struct dnode_of_data *dn);
2972 void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
2973 pgoff_t fofs, block_t blkaddr, unsigned int len);
2974 void init_extent_cache_info(struct f2fs_sb_info *sbi);
2975 int __init create_extent_cache(void);
2976 void destroy_extent_cache(void);
2979 * sysfs.c
2981 int __init f2fs_init_sysfs(void);
2982 void f2fs_exit_sysfs(void);
2983 int f2fs_register_sysfs(struct f2fs_sb_info *sbi);
2984 void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi);
2987 * crypto support
2989 static inline bool f2fs_encrypted_inode(struct inode *inode)
2991 return file_is_encrypt(inode);
2994 static inline bool f2fs_encrypted_file(struct inode *inode)
2996 return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode);
2999 static inline void f2fs_set_encrypted_inode(struct inode *inode)
3001 #ifdef CONFIG_F2FS_FS_ENCRYPTION
3002 file_set_encrypt(inode);
3003 #endif
3006 static inline bool f2fs_bio_encrypted(struct bio *bio)
3008 return bio->bi_private != NULL;
3011 static inline int f2fs_sb_has_crypto(struct super_block *sb)
3013 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT);
3016 static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb)
3018 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED);
3021 static inline int f2fs_sb_has_extra_attr(struct super_block *sb)
3023 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_EXTRA_ATTR);
3026 static inline int f2fs_sb_has_project_quota(struct super_block *sb)
3028 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_PRJQUOTA);
3031 static inline int f2fs_sb_has_inode_chksum(struct super_block *sb)
3033 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CHKSUM);
3036 #ifdef CONFIG_BLK_DEV_ZONED
3037 static inline int get_blkz_type(struct f2fs_sb_info *sbi,
3038 struct block_device *bdev, block_t blkaddr)
3040 unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz;
3041 int i;
3043 for (i = 0; i < sbi->s_ndevs; i++)
3044 if (FDEV(i).bdev == bdev)
3045 return FDEV(i).blkz_type[zno];
3046 return -EINVAL;
3048 #endif
3050 static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
3052 struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
3054 return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb);
3057 static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
3059 clear_opt(sbi, ADAPTIVE);
3060 clear_opt(sbi, LFS);
3062 switch (mt) {
3063 case F2FS_MOUNT_ADAPTIVE:
3064 set_opt(sbi, ADAPTIVE);
3065 break;
3066 case F2FS_MOUNT_LFS:
3067 set_opt(sbi, LFS);
3068 break;
3072 static inline bool f2fs_may_encrypt(struct inode *inode)
3074 #ifdef CONFIG_F2FS_FS_ENCRYPTION
3075 umode_t mode = inode->i_mode;
3077 return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
3078 #else
3079 return 0;
3080 #endif
3083 #endif