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.
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/fscrypto.h>
27 #ifdef CONFIG_F2FS_CHECK_FS
28 #define f2fs_bug_on(sbi, condition) BUG_ON(condition)
30 #define f2fs_bug_on(sbi, condition) \
32 if (unlikely(condition)) { \
34 set_sbi_flag(sbi, SBI_NEED_FSCK); \
42 #define F2FS_MOUNT_BG_GC 0x00000001
43 #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
44 #define F2FS_MOUNT_DISCARD 0x00000004
45 #define F2FS_MOUNT_NOHEAP 0x00000008
46 #define F2FS_MOUNT_XATTR_USER 0x00000010
47 #define F2FS_MOUNT_POSIX_ACL 0x00000020
48 #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
49 #define F2FS_MOUNT_INLINE_XATTR 0x00000080
50 #define F2FS_MOUNT_INLINE_DATA 0x00000100
51 #define F2FS_MOUNT_INLINE_DENTRY 0x00000200
52 #define F2FS_MOUNT_FLUSH_MERGE 0x00000400
53 #define F2FS_MOUNT_NOBARRIER 0x00000800
54 #define F2FS_MOUNT_FASTBOOT 0x00001000
55 #define F2FS_MOUNT_EXTENT_CACHE 0x00002000
56 #define F2FS_MOUNT_FORCE_FG_GC 0x00004000
57 #define F2FS_MOUNT_DATA_FLUSH 0x00008000
59 #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
60 #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
61 #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
63 #define ver_after(a, b) (typecheck(unsigned long long, a) && \
64 typecheck(unsigned long long, b) && \
65 ((long long)((a) - (b)) > 0))
67 typedef u32 block_t; /*
68 * should not change u32, since it is the on-disk block
69 * address format, __le32.
73 struct f2fs_mount_info {
77 #define F2FS_FEATURE_ENCRYPT 0x0001
79 #define F2FS_HAS_FEATURE(sb, mask) \
80 ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
81 #define F2FS_SET_FEATURE(sb, mask) \
82 F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)
83 #define F2FS_CLEAR_FEATURE(sb, mask) \
84 F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)
86 #define CRCPOLY_LE 0xedb88320
88 static inline __u32 f2fs_crc32(void *buf, size_t len)
90 unsigned char *p = (unsigned char *)buf;
91 __u32 crc = F2FS_SUPER_MAGIC;
96 for (i = 0; i < 8; i++)
97 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
102 static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
104 return f2fs_crc32(buf, buf_size) == blk_crc;
108 * For checkpoint manager
123 #define DEF_BATCHED_TRIM_SECTIONS 32
124 #define BATCHED_TRIM_SEGMENTS(sbi) \
125 (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
126 #define BATCHED_TRIM_BLOCKS(sbi) \
127 (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
128 #define DEF_CP_INTERVAL 60 /* 60 secs */
129 #define DEF_IDLE_INTERVAL 120 /* 2 mins */
140 * For CP/NAT/SIT/SSA readahead
150 /* for the list of ino */
152 ORPHAN_INO, /* for orphan ino list */
153 APPEND_INO, /* for append ino list */
154 UPDATE_INO, /* for update ino list */
155 MAX_INO_ENTRY, /* max. list */
159 struct list_head list; /* list head */
160 nid_t ino; /* inode number */
163 /* for the list of inodes to be GCed */
165 struct list_head list; /* list head */
166 struct inode *inode; /* vfs inode pointer */
169 /* for the list of blockaddresses to be discarded */
170 struct discard_entry {
171 struct list_head list; /* list head */
172 block_t blkaddr; /* block address to be discarded */
173 int len; /* # of consecutive blocks of the discard */
176 /* for the list of fsync inodes, used only during recovery */
177 struct fsync_inode_entry {
178 struct list_head list; /* list head */
179 struct inode *inode; /* vfs inode pointer */
180 block_t blkaddr; /* block address locating the last fsync */
181 block_t last_dentry; /* block address locating the last dentry */
182 block_t last_inode; /* block address locating the last inode */
185 #define nats_in_cursum(jnl) (le16_to_cpu(jnl->n_nats))
186 #define sits_in_cursum(jnl) (le16_to_cpu(jnl->n_sits))
188 #define nat_in_journal(jnl, i) (jnl->nat_j.entries[i].ne)
189 #define nid_in_journal(jnl, i) (jnl->nat_j.entries[i].nid)
190 #define sit_in_journal(jnl, i) (jnl->sit_j.entries[i].se)
191 #define segno_in_journal(jnl, i) (jnl->sit_j.entries[i].segno)
193 #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl))
194 #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl))
196 static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i)
198 int before = nats_in_cursum(journal);
199 journal->n_nats = cpu_to_le16(before + i);
203 static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i)
205 int before = sits_in_cursum(journal);
206 journal->n_sits = cpu_to_le16(before + i);
210 static inline bool __has_cursum_space(struct f2fs_journal *journal,
213 if (type == NAT_JOURNAL)
214 return size <= MAX_NAT_JENTRIES(journal);
215 return size <= MAX_SIT_JENTRIES(journal);
221 #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
222 #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
223 #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION
225 #define F2FS_IOCTL_MAGIC 0xf5
226 #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
227 #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
228 #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
229 #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)
230 #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
231 #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6)
232 #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7)
233 #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8)
235 #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
236 #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
237 #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT
240 * should be same as XFS_IOC_GOINGDOWN.
241 * Flags for going down operation used by FS_IOC_GOINGDOWN
243 #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */
244 #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */
245 #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */
246 #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */
247 #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */
249 #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
251 * ioctl commands in 32 bit emulation
253 #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
254 #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
255 #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION
258 struct f2fs_defragment {
264 * For INODE and NODE manager
266 /* for directory operations */
267 struct f2fs_dentry_ptr {
270 struct f2fs_dir_entry *dentry;
271 __u8 (*filename)[F2FS_SLOT_LEN];
275 static inline void make_dentry_ptr(struct inode *inode,
276 struct f2fs_dentry_ptr *d, void *src, int type)
281 struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src;
282 d->max = NR_DENTRY_IN_BLOCK;
283 d->bitmap = &t->dentry_bitmap;
284 d->dentry = t->dentry;
285 d->filename = t->filename;
287 struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src;
288 d->max = NR_INLINE_DENTRY;
289 d->bitmap = &t->dentry_bitmap;
290 d->dentry = t->dentry;
291 d->filename = t->filename;
296 * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
297 * as its node offset to distinguish from index node blocks.
298 * But some bits are used to mark the node block.
300 #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
303 ALLOC_NODE, /* allocate a new node page if needed */
304 LOOKUP_NODE, /* look up a node without readahead */
306 * look up a node with readahead called
311 #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */
313 #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */
315 /* vector size for gang look-up from extent cache that consists of radix tree */
316 #define EXT_TREE_VEC_SIZE 64
318 /* for in-memory extent cache entry */
319 #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */
321 /* number of extent info in extent cache we try to shrink */
322 #define EXTENT_CACHE_SHRINK_NUMBER 128
325 unsigned int fofs; /* start offset in a file */
326 u32 blk; /* start block address of the extent */
327 unsigned int len; /* length of the extent */
331 struct rb_node rb_node; /* rb node located in rb-tree */
332 struct list_head list; /* node in global extent list of sbi */
333 struct extent_info ei; /* extent info */
334 struct extent_tree *et; /* extent tree pointer */
338 nid_t ino; /* inode number */
339 struct rb_root root; /* root of extent info rb-tree */
340 struct extent_node *cached_en; /* recently accessed extent node */
341 struct extent_info largest; /* largested extent info */
342 struct list_head list; /* to be used by sbi->zombie_list */
343 rwlock_t lock; /* protect extent info rb-tree */
344 atomic_t node_cnt; /* # of extent node in rb-tree*/
348 * This structure is taken from ext4_map_blocks.
350 * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
352 #define F2FS_MAP_NEW (1 << BH_New)
353 #define F2FS_MAP_MAPPED (1 << BH_Mapped)
354 #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten)
355 #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
358 struct f2fs_map_blocks {
362 unsigned int m_flags;
363 pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */
366 /* for flag in get_data_block */
367 #define F2FS_GET_BLOCK_READ 0
368 #define F2FS_GET_BLOCK_DIO 1
369 #define F2FS_GET_BLOCK_FIEMAP 2
370 #define F2FS_GET_BLOCK_BMAP 3
371 #define F2FS_GET_BLOCK_PRE_DIO 4
372 #define F2FS_GET_BLOCK_PRE_AIO 5
375 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
377 #define FADVISE_COLD_BIT 0x01
378 #define FADVISE_LOST_PINO_BIT 0x02
379 #define FADVISE_ENCRYPT_BIT 0x04
380 #define FADVISE_ENC_NAME_BIT 0x08
382 #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT)
383 #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT)
384 #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT)
385 #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT)
386 #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT)
387 #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT)
388 #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT)
389 #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT)
390 #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT)
391 #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT)
392 #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
394 #define DEF_DIR_LEVEL 0
396 struct f2fs_inode_info {
397 struct inode vfs_inode; /* serve a vfs inode */
398 unsigned long i_flags; /* keep an inode flags for ioctl */
399 unsigned char i_advise; /* use to give file attribute hints */
400 unsigned char i_dir_level; /* use for dentry level for large dir */
401 unsigned int i_current_depth; /* use only in directory structure */
402 unsigned int i_pino; /* parent inode number */
403 umode_t i_acl_mode; /* keep file acl mode temporarily */
405 /* Use below internally in f2fs*/
406 unsigned long flags; /* use to pass per-file flags */
407 struct rw_semaphore i_sem; /* protect fi info */
408 atomic_t dirty_pages; /* # of dirty pages */
409 f2fs_hash_t chash; /* hash value of given file name */
410 unsigned int clevel; /* maximum level of given file name */
411 nid_t i_xattr_nid; /* node id that contains xattrs */
412 unsigned long long xattr_ver; /* cp version of xattr modification */
414 struct list_head dirty_list; /* linked in global dirty list */
415 struct list_head inmem_pages; /* inmemory pages managed by f2fs */
416 struct mutex inmem_lock; /* lock for inmemory pages */
417 struct extent_tree *extent_tree; /* cached extent_tree entry */
420 static inline void get_extent_info(struct extent_info *ext,
421 struct f2fs_extent i_ext)
423 ext->fofs = le32_to_cpu(i_ext.fofs);
424 ext->blk = le32_to_cpu(i_ext.blk);
425 ext->len = le32_to_cpu(i_ext.len);
428 static inline void set_raw_extent(struct extent_info *ext,
429 struct f2fs_extent *i_ext)
431 i_ext->fofs = cpu_to_le32(ext->fofs);
432 i_ext->blk = cpu_to_le32(ext->blk);
433 i_ext->len = cpu_to_le32(ext->len);
436 static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
437 u32 blk, unsigned int len)
444 static inline bool __is_extent_same(struct extent_info *ei1,
445 struct extent_info *ei2)
447 return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk &&
448 ei1->len == ei2->len);
451 static inline bool __is_extent_mergeable(struct extent_info *back,
452 struct extent_info *front)
454 return (back->fofs + back->len == front->fofs &&
455 back->blk + back->len == front->blk);
458 static inline bool __is_back_mergeable(struct extent_info *cur,
459 struct extent_info *back)
461 return __is_extent_mergeable(back, cur);
464 static inline bool __is_front_mergeable(struct extent_info *cur,
465 struct extent_info *front)
467 return __is_extent_mergeable(cur, front);
470 static inline void __try_update_largest_extent(struct extent_tree *et,
471 struct extent_node *en)
473 if (en->ei.len > et->largest.len)
474 et->largest = en->ei;
477 struct f2fs_nm_info {
478 block_t nat_blkaddr; /* base disk address of NAT */
479 nid_t max_nid; /* maximum possible node ids */
480 nid_t available_nids; /* maximum available node ids */
481 nid_t next_scan_nid; /* the next nid to be scanned */
482 unsigned int ram_thresh; /* control the memory footprint */
483 unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */
484 unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */
486 /* NAT cache management */
487 struct radix_tree_root nat_root;/* root of the nat entry cache */
488 struct radix_tree_root nat_set_root;/* root of the nat set cache */
489 struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */
490 struct list_head nat_entries; /* cached nat entry list (clean) */
491 unsigned int nat_cnt; /* the # of cached nat entries */
492 unsigned int dirty_nat_cnt; /* total num of nat entries in set */
494 /* free node ids management */
495 struct radix_tree_root free_nid_root;/* root of the free_nid cache */
496 struct list_head free_nid_list; /* a list for free nids */
497 spinlock_t free_nid_list_lock; /* protect free nid list */
498 unsigned int fcnt; /* the number of free node id */
499 struct mutex build_lock; /* lock for build free nids */
502 char *nat_bitmap; /* NAT bitmap pointer */
503 int bitmap_size; /* bitmap size */
507 * this structure is used as one of function parameters.
508 * all the information are dedicated to a given direct node block determined
509 * by the data offset in a file.
511 struct dnode_of_data {
512 struct inode *inode; /* vfs inode pointer */
513 struct page *inode_page; /* its inode page, NULL is possible */
514 struct page *node_page; /* cached direct node page */
515 nid_t nid; /* node id of the direct node block */
516 unsigned int ofs_in_node; /* data offset in the node page */
517 bool inode_page_locked; /* inode page is locked or not */
518 bool node_changed; /* is node block changed */
519 char cur_level; /* level of hole node page */
520 char max_level; /* level of current page located */
521 block_t data_blkaddr; /* block address of the node block */
524 static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
525 struct page *ipage, struct page *npage, nid_t nid)
527 memset(dn, 0, sizeof(*dn));
529 dn->inode_page = ipage;
530 dn->node_page = npage;
537 * By default, there are 6 active log areas across the whole main area.
538 * When considering hot and cold data separation to reduce cleaning overhead,
539 * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
541 * In the current design, you should not change the numbers intentionally.
542 * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
543 * logs individually according to the underlying devices. (default: 6)
544 * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
545 * data and 8 for node logs.
547 #define NR_CURSEG_DATA_TYPE (3)
548 #define NR_CURSEG_NODE_TYPE (3)
549 #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
552 CURSEG_HOT_DATA = 0, /* directory entry blocks */
553 CURSEG_WARM_DATA, /* data blocks */
554 CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
555 CURSEG_HOT_NODE, /* direct node blocks of directory files */
556 CURSEG_WARM_NODE, /* direct node blocks of normal files */
557 CURSEG_COLD_NODE, /* indirect node blocks */
559 CURSEG_DIRECT_IO, /* to use for the direct IO path */
563 struct completion wait;
564 struct llist_node llnode;
568 struct flush_cmd_control {
569 struct task_struct *f2fs_issue_flush; /* flush thread */
570 wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */
571 struct llist_head issue_list; /* list for command issue */
572 struct llist_node *dispatch_list; /* list for command dispatch */
575 struct f2fs_sm_info {
576 struct sit_info *sit_info; /* whole segment information */
577 struct free_segmap_info *free_info; /* free segment information */
578 struct dirty_seglist_info *dirty_info; /* dirty segment information */
579 struct curseg_info *curseg_array; /* active segment information */
581 block_t seg0_blkaddr; /* block address of 0'th segment */
582 block_t main_blkaddr; /* start block address of main area */
583 block_t ssa_blkaddr; /* start block address of SSA area */
585 unsigned int segment_count; /* total # of segments */
586 unsigned int main_segments; /* # of segments in main area */
587 unsigned int reserved_segments; /* # of reserved segments */
588 unsigned int ovp_segments; /* # of overprovision segments */
590 /* a threshold to reclaim prefree segments */
591 unsigned int rec_prefree_segments;
593 /* for small discard management */
594 struct list_head discard_list; /* 4KB discard list */
595 int nr_discards; /* # of discards in the list */
596 int max_discards; /* max. discards to be issued */
598 /* for batched trimming */
599 unsigned int trim_sections; /* # of sections to trim */
601 struct list_head sit_entry_set; /* sit entry set list */
603 unsigned int ipu_policy; /* in-place-update policy */
604 unsigned int min_ipu_util; /* in-place-update threshold */
605 unsigned int min_fsync_blocks; /* threshold for fsync */
607 /* for flush command control */
608 struct flush_cmd_control *cmd_control_info;
616 * COUNT_TYPE for monitoring
618 * f2fs monitors the number of several block types such as on-writeback,
619 * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
632 * The below are the page types of bios used in submit_bio().
633 * The available types are:
634 * DATA User data pages. It operates as async mode.
635 * NODE Node pages. It operates as async mode.
636 * META FS metadata pages such as SIT, NAT, CP.
637 * NR_PAGE_TYPE The number of page types.
638 * META_FLUSH Make sure the previous pages are written
639 * with waiting the bio's completion
640 * ... Only can be used with META.
642 #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type))
649 INMEM, /* the below types are used by tracepoints only. */
656 struct f2fs_io_info {
657 struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */
658 enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
659 int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */
660 block_t new_blkaddr; /* new block address to be written */
661 block_t old_blkaddr; /* old block address before Cow */
662 struct page *page; /* page to be written */
663 struct page *encrypted_page; /* encrypted page */
666 #define is_read_io(rw) (((rw) & 1) == READ)
667 struct f2fs_bio_info {
668 struct f2fs_sb_info *sbi; /* f2fs superblock */
669 struct bio *bio; /* bios to merge */
670 sector_t last_block_in_bio; /* last block number */
671 struct f2fs_io_info fio; /* store buffered io info. */
672 struct rw_semaphore io_rwsem; /* blocking op for bio */
676 DIR_INODE, /* for dirty dir inode */
677 FILE_INODE, /* for dirty regular/symlink inode */
681 /* for inner inode cache management */
682 struct inode_management {
683 struct radix_tree_root ino_root; /* ino entry array */
684 spinlock_t ino_lock; /* for ino entry lock */
685 struct list_head ino_list; /* inode list head */
686 unsigned long ino_num; /* number of entries */
689 /* For s_flag in struct f2fs_sb_info */
691 SBI_IS_DIRTY, /* dirty flag for checkpoint */
692 SBI_IS_CLOSE, /* specify unmounting */
693 SBI_NEED_FSCK, /* need fsck.f2fs to fix */
694 SBI_POR_DOING, /* recovery is doing or not */
703 struct f2fs_sb_info {
704 struct super_block *sb; /* pointer to VFS super block */
705 struct proc_dir_entry *s_proc; /* proc entry */
706 struct f2fs_super_block *raw_super; /* raw super block pointer */
707 int valid_super_block; /* valid super block no */
708 int s_flag; /* flags for sbi */
710 /* for node-related operations */
711 struct f2fs_nm_info *nm_info; /* node manager */
712 struct inode *node_inode; /* cache node blocks */
714 /* for segment-related operations */
715 struct f2fs_sm_info *sm_info; /* segment manager */
717 /* for bio operations */
718 struct f2fs_bio_info read_io; /* for read bios */
719 struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */
722 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
723 struct inode *meta_inode; /* cache meta blocks */
724 struct mutex cp_mutex; /* checkpoint procedure lock */
725 struct rw_semaphore cp_rwsem; /* blocking FS operations */
726 struct rw_semaphore node_write; /* locking node writes */
727 struct mutex writepages; /* mutex for writepages() */
728 wait_queue_head_t cp_wait;
729 unsigned long last_time[MAX_TIME]; /* to store time in jiffies */
730 long interval_time[MAX_TIME]; /* to store thresholds */
732 struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
734 /* for orphan inode, use 0'th array */
735 unsigned int max_orphans; /* max orphan inodes */
737 /* for inode management */
738 struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */
739 spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */
741 /* for extent tree cache */
742 struct radix_tree_root extent_tree_root;/* cache extent cache entries */
743 struct rw_semaphore extent_tree_lock; /* locking extent radix tree */
744 struct list_head extent_list; /* lru list for shrinker */
745 spinlock_t extent_lock; /* locking extent lru list */
746 atomic_t total_ext_tree; /* extent tree count */
747 struct list_head zombie_list; /* extent zombie tree list */
748 atomic_t total_zombie_tree; /* extent zombie tree count */
749 atomic_t total_ext_node; /* extent info count */
751 /* basic filesystem units */
752 unsigned int log_sectors_per_block; /* log2 sectors per block */
753 unsigned int log_blocksize; /* log2 block size */
754 unsigned int blocksize; /* block size */
755 unsigned int root_ino_num; /* root inode number*/
756 unsigned int node_ino_num; /* node inode number*/
757 unsigned int meta_ino_num; /* meta inode number*/
758 unsigned int log_blocks_per_seg; /* log2 blocks per segment */
759 unsigned int blocks_per_seg; /* blocks per segment */
760 unsigned int segs_per_sec; /* segments per section */
761 unsigned int secs_per_zone; /* sections per zone */
762 unsigned int total_sections; /* total section count */
763 unsigned int total_node_count; /* total node block count */
764 unsigned int total_valid_node_count; /* valid node block count */
765 unsigned int total_valid_inode_count; /* valid inode count */
766 loff_t max_file_blocks; /* max block index of file */
767 int active_logs; /* # of active logs */
768 int dir_level; /* directory level */
770 block_t user_block_count; /* # of user blocks */
771 block_t total_valid_block_count; /* # of valid blocks */
772 block_t alloc_valid_block_count; /* # of allocated blocks */
773 block_t discard_blks; /* discard command candidats */
774 block_t last_valid_block_count; /* for recovery */
775 u32 s_next_generation; /* for NFS support */
776 atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
778 struct f2fs_mount_info mount_opt; /* mount options */
780 /* for cleaning operations */
781 struct mutex gc_mutex; /* mutex for GC */
782 struct f2fs_gc_kthread *gc_thread; /* GC thread */
783 unsigned int cur_victim_sec; /* current victim section num */
785 /* maximum # of trials to find a victim segment for SSR and GC */
786 unsigned int max_victim_search;
789 * for stat information.
790 * one is for the LFS mode, and the other is for the SSR mode.
792 #ifdef CONFIG_F2FS_STAT_FS
793 struct f2fs_stat_info *stat_info; /* FS status information */
794 unsigned int segment_count[2]; /* # of allocated segments */
795 unsigned int block_count[2]; /* # of allocated blocks */
796 atomic_t inplace_count; /* # of inplace update */
797 atomic64_t total_hit_ext; /* # of lookup extent cache */
798 atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */
799 atomic64_t read_hit_largest; /* # of hit largest extent node */
800 atomic64_t read_hit_cached; /* # of hit cached extent node */
801 atomic_t inline_xattr; /* # of inline_xattr inodes */
802 atomic_t inline_inode; /* # of inline_data inodes */
803 atomic_t inline_dir; /* # of inline_dentry inodes */
804 int bg_gc; /* background gc calls */
805 unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */
807 unsigned int last_victim[2]; /* last victim segment # */
808 spinlock_t stat_lock; /* lock for stat operations */
810 /* For sysfs suppport */
811 struct kobject s_kobj;
812 struct completion s_kobj_unregister;
814 /* For shrinker support */
815 struct list_head s_list;
816 struct mutex umount_mutex;
817 unsigned int shrinker_run_no;
819 /* For write statistics */
820 u64 sectors_written_start;
824 /* For write statistics. Suppose sector size is 512 bytes,
825 * and the return value is in kbytes. s is of struct f2fs_sb_info.
827 #define BD_PART_WRITTEN(s) \
828 (((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) - \
829 s->sectors_written_start) >> 1)
831 static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type)
833 sbi->last_time[type] = jiffies;
836 static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type)
838 struct timespec ts = {sbi->interval_time[type], 0};
839 unsigned long interval = timespec_to_jiffies(&ts);
841 return time_after(jiffies, sbi->last_time[type] + interval);
844 static inline bool is_idle(struct f2fs_sb_info *sbi)
846 struct block_device *bdev = sbi->sb->s_bdev;
847 struct request_queue *q = bdev_get_queue(bdev);
848 struct request_list *rl = &q->root_rl;
850 if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC])
853 return f2fs_time_over(sbi, REQ_TIME);
859 static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
861 return container_of(inode, struct f2fs_inode_info, vfs_inode);
864 static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
866 return sb->s_fs_info;
869 static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
871 return F2FS_SB(inode->i_sb);
874 static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
876 return F2FS_I_SB(mapping->host);
879 static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
881 return F2FS_M_SB(page->mapping);
884 static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
886 return (struct f2fs_super_block *)(sbi->raw_super);
889 static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
891 return (struct f2fs_checkpoint *)(sbi->ckpt);
894 static inline struct f2fs_node *F2FS_NODE(struct page *page)
896 return (struct f2fs_node *)page_address(page);
899 static inline struct f2fs_inode *F2FS_INODE(struct page *page)
901 return &((struct f2fs_node *)page_address(page))->i;
904 static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
906 return (struct f2fs_nm_info *)(sbi->nm_info);
909 static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
911 return (struct f2fs_sm_info *)(sbi->sm_info);
914 static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
916 return (struct sit_info *)(SM_I(sbi)->sit_info);
919 static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
921 return (struct free_segmap_info *)(SM_I(sbi)->free_info);
924 static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
926 return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
929 static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
931 return sbi->meta_inode->i_mapping;
934 static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
936 return sbi->node_inode->i_mapping;
939 static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
941 return sbi->s_flag & (0x01 << type);
944 static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
946 sbi->s_flag |= (0x01 << type);
949 static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
951 sbi->s_flag &= ~(0x01 << type);
954 static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
956 return le64_to_cpu(cp->checkpoint_ver);
959 static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
961 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
962 return ckpt_flags & f;
965 static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
967 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
969 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
972 static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
974 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
976 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
979 static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
981 down_read(&sbi->cp_rwsem);
984 static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
986 up_read(&sbi->cp_rwsem);
989 static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
991 down_write(&sbi->cp_rwsem);
994 static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
996 up_write(&sbi->cp_rwsem);
999 static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
1001 int reason = CP_SYNC;
1003 if (test_opt(sbi, FASTBOOT))
1004 reason = CP_FASTBOOT;
1005 if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
1010 static inline bool __remain_node_summaries(int reason)
1012 return (reason == CP_UMOUNT || reason == CP_FASTBOOT);
1015 static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
1017 return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) ||
1018 is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG));
1022 * Check whether the given nid is within node id range.
1024 static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
1026 if (unlikely(nid < F2FS_ROOT_INO(sbi)))
1028 if (unlikely(nid >= NM_I(sbi)->max_nid))
1033 #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
1036 * Check whether the inode has blocks or not
1038 static inline int F2FS_HAS_BLOCKS(struct inode *inode)
1040 if (F2FS_I(inode)->i_xattr_nid)
1041 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
1043 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
1046 static inline bool f2fs_has_xattr_block(unsigned int ofs)
1048 return ofs == XATTR_NODE_OFFSET;
1051 static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
1052 struct inode *inode, blkcnt_t count)
1054 block_t valid_block_count;
1056 spin_lock(&sbi->stat_lock);
1058 sbi->total_valid_block_count + (block_t)count;
1059 if (unlikely(valid_block_count > sbi->user_block_count)) {
1060 spin_unlock(&sbi->stat_lock);
1063 inode->i_blocks += count;
1064 sbi->total_valid_block_count = valid_block_count;
1065 sbi->alloc_valid_block_count += (block_t)count;
1066 spin_unlock(&sbi->stat_lock);
1070 static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
1071 struct inode *inode,
1074 spin_lock(&sbi->stat_lock);
1075 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
1076 f2fs_bug_on(sbi, inode->i_blocks < count);
1077 inode->i_blocks -= count;
1078 sbi->total_valid_block_count -= (block_t)count;
1079 spin_unlock(&sbi->stat_lock);
1082 static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
1084 atomic_inc(&sbi->nr_pages[count_type]);
1085 set_sbi_flag(sbi, SBI_IS_DIRTY);
1088 static inline void inode_inc_dirty_pages(struct inode *inode)
1090 atomic_inc(&F2FS_I(inode)->dirty_pages);
1091 inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1092 F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
1095 static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
1097 atomic_dec(&sbi->nr_pages[count_type]);
1100 static inline void inode_dec_dirty_pages(struct inode *inode)
1102 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
1103 !S_ISLNK(inode->i_mode))
1106 atomic_dec(&F2FS_I(inode)->dirty_pages);
1107 dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ?
1108 F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA);
1111 static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
1113 return atomic_read(&sbi->nr_pages[count_type]);
1116 static inline int get_dirty_pages(struct inode *inode)
1118 return atomic_read(&F2FS_I(inode)->dirty_pages);
1121 static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
1123 unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg;
1124 return ((get_pages(sbi, block_type) + pages_per_sec - 1)
1125 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
1128 static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
1130 return sbi->total_valid_block_count;
1133 static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
1135 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1137 /* return NAT or SIT bitmap */
1138 if (flag == NAT_BITMAP)
1139 return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
1140 else if (flag == SIT_BITMAP)
1141 return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
1146 static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
1148 return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
1151 static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
1153 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1156 if (__cp_payload(sbi) > 0) {
1157 if (flag == NAT_BITMAP)
1158 return &ckpt->sit_nat_version_bitmap;
1160 return (unsigned char *)ckpt + F2FS_BLKSIZE;
1162 offset = (flag == NAT_BITMAP) ?
1163 le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
1164 return &ckpt->sit_nat_version_bitmap + offset;
1168 static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
1171 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1172 unsigned long long ckpt_version = cur_cp_version(ckpt);
1174 start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
1177 * odd numbered checkpoint should at cp segment 0
1178 * and even segment must be at cp segment 1
1180 if (!(ckpt_version & 1))
1181 start_addr += sbi->blocks_per_seg;
1186 static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
1188 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
1191 static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
1192 struct inode *inode)
1194 block_t valid_block_count;
1195 unsigned int valid_node_count;
1197 spin_lock(&sbi->stat_lock);
1199 valid_block_count = sbi->total_valid_block_count + 1;
1200 if (unlikely(valid_block_count > sbi->user_block_count)) {
1201 spin_unlock(&sbi->stat_lock);
1205 valid_node_count = sbi->total_valid_node_count + 1;
1206 if (unlikely(valid_node_count > sbi->total_node_count)) {
1207 spin_unlock(&sbi->stat_lock);
1214 sbi->alloc_valid_block_count++;
1215 sbi->total_valid_node_count++;
1216 sbi->total_valid_block_count++;
1217 spin_unlock(&sbi->stat_lock);
1222 static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
1223 struct inode *inode)
1225 spin_lock(&sbi->stat_lock);
1227 f2fs_bug_on(sbi, !sbi->total_valid_block_count);
1228 f2fs_bug_on(sbi, !sbi->total_valid_node_count);
1229 f2fs_bug_on(sbi, !inode->i_blocks);
1232 sbi->total_valid_node_count--;
1233 sbi->total_valid_block_count--;
1235 spin_unlock(&sbi->stat_lock);
1238 static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
1240 return sbi->total_valid_node_count;
1243 static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
1245 spin_lock(&sbi->stat_lock);
1246 f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count);
1247 sbi->total_valid_inode_count++;
1248 spin_unlock(&sbi->stat_lock);
1251 static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
1253 spin_lock(&sbi->stat_lock);
1254 f2fs_bug_on(sbi, !sbi->total_valid_inode_count);
1255 sbi->total_valid_inode_count--;
1256 spin_unlock(&sbi->stat_lock);
1259 static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
1261 return sbi->total_valid_inode_count;
1264 static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
1265 pgoff_t index, bool for_write)
1268 return grab_cache_page(mapping, index);
1269 return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
1272 static inline void f2fs_copy_page(struct page *src, struct page *dst)
1274 char *src_kaddr = kmap(src);
1275 char *dst_kaddr = kmap(dst);
1277 memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
1282 static inline void f2fs_put_page(struct page *page, int unlock)
1288 f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
1291 page_cache_release(page);
1294 static inline void f2fs_put_dnode(struct dnode_of_data *dn)
1297 f2fs_put_page(dn->node_page, 1);
1298 if (dn->inode_page && dn->node_page != dn->inode_page)
1299 f2fs_put_page(dn->inode_page, 0);
1300 dn->node_page = NULL;
1301 dn->inode_page = NULL;
1304 static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
1307 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
1310 static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
1315 entry = kmem_cache_alloc(cachep, flags);
1317 entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
1321 static inline struct bio *f2fs_bio_alloc(int npages)
1325 /* No failure on bio allocation */
1326 bio = bio_alloc(GFP_NOIO, npages);
1328 bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
1332 static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
1333 unsigned long index, void *item)
1335 while (radix_tree_insert(root, index, item))
1339 #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
1341 static inline bool IS_INODE(struct page *page)
1343 struct f2fs_node *p = F2FS_NODE(page);
1344 return RAW_IS_INODE(p);
1347 static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
1349 return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
1352 static inline block_t datablock_addr(struct page *node_page,
1353 unsigned int offset)
1355 struct f2fs_node *raw_node;
1357 raw_node = F2FS_NODE(node_page);
1358 addr_array = blkaddr_in_node(raw_node);
1359 return le32_to_cpu(addr_array[offset]);
1362 static inline int f2fs_test_bit(unsigned int nr, char *addr)
1367 mask = 1 << (7 - (nr & 0x07));
1368 return mask & *addr;
1371 static inline void f2fs_set_bit(unsigned int nr, char *addr)
1376 mask = 1 << (7 - (nr & 0x07));
1380 static inline void f2fs_clear_bit(unsigned int nr, char *addr)
1385 mask = 1 << (7 - (nr & 0x07));
1389 static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
1395 mask = 1 << (7 - (nr & 0x07));
1401 static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
1407 mask = 1 << (7 - (nr & 0x07));
1413 static inline void f2fs_change_bit(unsigned int nr, char *addr)
1418 mask = 1 << (7 - (nr & 0x07));
1422 /* used for f2fs_inode_info->flags */
1424 FI_NEW_INODE, /* indicate newly allocated inode */
1425 FI_DIRTY_INODE, /* indicate inode is dirty or not */
1426 FI_DIRTY_DIR, /* indicate directory has dirty pages */
1427 FI_INC_LINK, /* need to increment i_nlink */
1428 FI_ACL_MODE, /* indicate acl mode */
1429 FI_NO_ALLOC, /* should not allocate any blocks */
1430 FI_FREE_NID, /* free allocated nide */
1431 FI_UPDATE_DIR, /* should update inode block for consistency */
1432 FI_DELAY_IPUT, /* used for the recovery */
1433 FI_NO_EXTENT, /* not to use the extent cache */
1434 FI_INLINE_XATTR, /* used for inline xattr */
1435 FI_INLINE_DATA, /* used for inline data*/
1436 FI_INLINE_DENTRY, /* used for inline dentry */
1437 FI_APPEND_WRITE, /* inode has appended data */
1438 FI_UPDATE_WRITE, /* inode has in-place-update data */
1439 FI_NEED_IPU, /* used for ipu per file */
1440 FI_ATOMIC_FILE, /* indicate atomic file */
1441 FI_VOLATILE_FILE, /* indicate volatile file */
1442 FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */
1443 FI_DROP_CACHE, /* drop dirty page cache */
1444 FI_DATA_EXIST, /* indicate data exists */
1445 FI_INLINE_DOTS, /* indicate inline dot dentries */
1446 FI_DO_DEFRAG, /* indicate defragment is running */
1447 FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */
1450 static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
1452 if (!test_bit(flag, &fi->flags))
1453 set_bit(flag, &fi->flags);
1456 static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
1458 return test_bit(flag, &fi->flags);
1461 static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
1463 if (test_bit(flag, &fi->flags))
1464 clear_bit(flag, &fi->flags);
1467 static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
1469 fi->i_acl_mode = mode;
1470 set_inode_flag(fi, FI_ACL_MODE);
1473 static inline void get_inline_info(struct f2fs_inode_info *fi,
1474 struct f2fs_inode *ri)
1476 if (ri->i_inline & F2FS_INLINE_XATTR)
1477 set_inode_flag(fi, FI_INLINE_XATTR);
1478 if (ri->i_inline & F2FS_INLINE_DATA)
1479 set_inode_flag(fi, FI_INLINE_DATA);
1480 if (ri->i_inline & F2FS_INLINE_DENTRY)
1481 set_inode_flag(fi, FI_INLINE_DENTRY);
1482 if (ri->i_inline & F2FS_DATA_EXIST)
1483 set_inode_flag(fi, FI_DATA_EXIST);
1484 if (ri->i_inline & F2FS_INLINE_DOTS)
1485 set_inode_flag(fi, FI_INLINE_DOTS);
1488 static inline void set_raw_inline(struct f2fs_inode_info *fi,
1489 struct f2fs_inode *ri)
1493 if (is_inode_flag_set(fi, FI_INLINE_XATTR))
1494 ri->i_inline |= F2FS_INLINE_XATTR;
1495 if (is_inode_flag_set(fi, FI_INLINE_DATA))
1496 ri->i_inline |= F2FS_INLINE_DATA;
1497 if (is_inode_flag_set(fi, FI_INLINE_DENTRY))
1498 ri->i_inline |= F2FS_INLINE_DENTRY;
1499 if (is_inode_flag_set(fi, FI_DATA_EXIST))
1500 ri->i_inline |= F2FS_DATA_EXIST;
1501 if (is_inode_flag_set(fi, FI_INLINE_DOTS))
1502 ri->i_inline |= F2FS_INLINE_DOTS;
1505 static inline int f2fs_has_inline_xattr(struct inode *inode)
1507 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR);
1510 static inline unsigned int addrs_per_inode(struct inode *inode)
1512 if (f2fs_has_inline_xattr(inode))
1513 return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
1514 return DEF_ADDRS_PER_INODE;
1517 static inline void *inline_xattr_addr(struct page *page)
1519 struct f2fs_inode *ri = F2FS_INODE(page);
1520 return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
1521 F2FS_INLINE_XATTR_ADDRS]);
1524 static inline int inline_xattr_size(struct inode *inode)
1526 if (f2fs_has_inline_xattr(inode))
1527 return F2FS_INLINE_XATTR_ADDRS << 2;
1532 static inline int f2fs_has_inline_data(struct inode *inode)
1534 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
1537 static inline void f2fs_clear_inline_inode(struct inode *inode)
1539 clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
1540 clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST);
1543 static inline int f2fs_exist_data(struct inode *inode)
1545 return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST);
1548 static inline int f2fs_has_inline_dots(struct inode *inode)
1550 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS);
1553 static inline bool f2fs_is_atomic_file(struct inode *inode)
1555 return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE);
1558 static inline bool f2fs_is_volatile_file(struct inode *inode)
1560 return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE);
1563 static inline bool f2fs_is_first_block_written(struct inode *inode)
1565 return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN);
1568 static inline bool f2fs_is_drop_cache(struct inode *inode)
1570 return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE);
1573 static inline void *inline_data_addr(struct page *page)
1575 struct f2fs_inode *ri = F2FS_INODE(page);
1576 return (void *)&(ri->i_addr[1]);
1579 static inline int f2fs_has_inline_dentry(struct inode *inode)
1581 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY);
1584 static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
1586 if (!f2fs_has_inline_dentry(dir))
1590 static inline int is_file(struct inode *inode, int type)
1592 return F2FS_I(inode)->i_advise & type;
1595 static inline void set_file(struct inode *inode, int type)
1597 F2FS_I(inode)->i_advise |= type;
1600 static inline void clear_file(struct inode *inode, int type)
1602 F2FS_I(inode)->i_advise &= ~type;
1605 static inline int f2fs_readonly(struct super_block *sb)
1607 return sb->s_flags & MS_RDONLY;
1610 static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
1612 return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1615 static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi)
1617 set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1618 sbi->sb->s_flags |= MS_RDONLY;
1621 static inline bool is_dot_dotdot(const struct qstr *str)
1623 if (str->len == 1 && str->name[0] == '.')
1626 if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
1632 static inline bool f2fs_may_extent_tree(struct inode *inode)
1634 if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) ||
1635 is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT))
1638 return S_ISREG(inode->i_mode);
1641 static inline void *f2fs_kvmalloc(size_t size, gfp_t flags)
1645 ret = kmalloc(size, flags | __GFP_NOWARN);
1647 ret = __vmalloc(size, flags, PAGE_KERNEL);
1651 static inline void *f2fs_kvzalloc(size_t size, gfp_t flags)
1655 ret = kzalloc(size, flags | __GFP_NOWARN);
1657 ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
1661 #define get_inode_mode(i) \
1662 ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
1663 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
1665 /* get offset of first page in next direct node */
1666 #define PGOFS_OF_NEXT_DNODE(pgofs, inode) \
1667 ((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) : \
1668 (pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) / \
1669 ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode))
1674 int f2fs_sync_file(struct file *, loff_t, loff_t, int);
1675 void truncate_data_blocks(struct dnode_of_data *);
1676 int truncate_blocks(struct inode *, u64, bool);
1677 int f2fs_truncate(struct inode *, bool);
1678 int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
1679 int f2fs_setattr(struct dentry *, struct iattr *);
1680 int truncate_hole(struct inode *, pgoff_t, pgoff_t);
1681 int truncate_data_blocks_range(struct dnode_of_data *, int);
1682 long f2fs_ioctl(struct file *, unsigned int, unsigned long);
1683 long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
1688 void f2fs_set_inode_flags(struct inode *);
1689 struct inode *f2fs_iget(struct super_block *, unsigned long);
1690 int try_to_free_nats(struct f2fs_sb_info *, int);
1691 int update_inode(struct inode *, struct page *);
1692 int update_inode_page(struct inode *);
1693 int f2fs_write_inode(struct inode *, struct writeback_control *);
1694 void f2fs_evict_inode(struct inode *);
1695 void handle_failed_inode(struct inode *);
1700 struct dentry *f2fs_get_parent(struct dentry *child);
1705 extern unsigned char f2fs_filetype_table[F2FS_FT_MAX];
1706 void set_de_type(struct f2fs_dir_entry *, umode_t);
1708 struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *,
1709 f2fs_hash_t, int *, struct f2fs_dentry_ptr *);
1710 bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *,
1711 unsigned int, struct fscrypt_str *);
1712 void do_make_empty_dir(struct inode *, struct inode *,
1713 struct f2fs_dentry_ptr *);
1714 struct page *init_inode_metadata(struct inode *, struct inode *,
1715 const struct qstr *, struct page *);
1716 void update_parent_metadata(struct inode *, struct inode *, unsigned int);
1717 int room_for_filename(const void *, int, int);
1718 void f2fs_drop_nlink(struct inode *, struct inode *, struct page *);
1719 struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
1721 struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
1722 ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
1723 void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
1724 struct page *, struct inode *);
1725 int update_dent_inode(struct inode *, struct inode *, const struct qstr *);
1726 void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *,
1727 const struct qstr *, f2fs_hash_t , unsigned int);
1728 int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t,
1730 void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *,
1732 int f2fs_do_tmpfile(struct inode *, struct inode *);
1733 bool f2fs_empty_dir(struct inode *);
1735 static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
1737 return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name,
1738 inode, inode->i_ino, inode->i_mode);
1744 int f2fs_commit_super(struct f2fs_sb_info *, bool);
1745 int f2fs_sync_fs(struct super_block *, int);
1746 extern __printf(3, 4)
1747 void f2fs_msg(struct super_block *, const char *, const char *, ...);
1748 int sanity_check_ckpt(struct f2fs_sb_info *sbi);
1753 f2fs_hash_t f2fs_dentry_hash(const struct qstr *);
1758 struct dnode_of_data;
1761 bool available_free_memory(struct f2fs_sb_info *, int);
1762 int need_dentry_mark(struct f2fs_sb_info *, nid_t);
1763 bool is_checkpointed_node(struct f2fs_sb_info *, nid_t);
1764 bool need_inode_block_update(struct f2fs_sb_info *, nid_t);
1765 void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
1766 pgoff_t get_next_page_offset(struct dnode_of_data *, pgoff_t);
1767 int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
1768 int truncate_inode_blocks(struct inode *, pgoff_t);
1769 int truncate_xattr_node(struct inode *, struct page *);
1770 int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
1771 int remove_inode_page(struct inode *);
1772 struct page *new_inode_page(struct inode *);
1773 struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
1774 void ra_node_page(struct f2fs_sb_info *, nid_t);
1775 struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
1776 struct page *get_node_page_ra(struct page *, int);
1777 void sync_inode_page(struct dnode_of_data *);
1778 int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
1779 bool alloc_nid(struct f2fs_sb_info *, nid_t *);
1780 void alloc_nid_done(struct f2fs_sb_info *, nid_t);
1781 void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
1782 int try_to_free_nids(struct f2fs_sb_info *, int);
1783 void recover_inline_xattr(struct inode *, struct page *);
1784 void recover_xattr_data(struct inode *, struct page *, block_t);
1785 int recover_inode_page(struct f2fs_sb_info *, struct page *);
1786 int restore_node_summary(struct f2fs_sb_info *, unsigned int,
1787 struct f2fs_summary_block *);
1788 void flush_nat_entries(struct f2fs_sb_info *);
1789 int build_node_manager(struct f2fs_sb_info *);
1790 void destroy_node_manager(struct f2fs_sb_info *);
1791 int __init create_node_manager_caches(void);
1792 void destroy_node_manager_caches(void);
1797 void register_inmem_page(struct inode *, struct page *);
1798 void drop_inmem_pages(struct inode *);
1799 int commit_inmem_pages(struct inode *);
1800 void f2fs_balance_fs(struct f2fs_sb_info *, bool);
1801 void f2fs_balance_fs_bg(struct f2fs_sb_info *);
1802 int f2fs_issue_flush(struct f2fs_sb_info *);
1803 int create_flush_cmd_control(struct f2fs_sb_info *);
1804 void destroy_flush_cmd_control(struct f2fs_sb_info *);
1805 void invalidate_blocks(struct f2fs_sb_info *, block_t);
1806 bool is_checkpointed_data(struct f2fs_sb_info *, block_t);
1807 void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
1808 void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *);
1809 void release_discard_addrs(struct f2fs_sb_info *);
1810 bool discard_next_dnode(struct f2fs_sb_info *, block_t);
1811 int npages_for_summary_flush(struct f2fs_sb_info *, bool);
1812 void allocate_new_segments(struct f2fs_sb_info *);
1813 int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *);
1814 struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
1815 void update_meta_page(struct f2fs_sb_info *, void *, block_t);
1816 void write_meta_page(struct f2fs_sb_info *, struct page *);
1817 void write_node_page(unsigned int, struct f2fs_io_info *);
1818 void write_data_page(struct dnode_of_data *, struct f2fs_io_info *);
1819 void rewrite_data_page(struct f2fs_io_info *);
1820 void __f2fs_replace_block(struct f2fs_sb_info *, struct f2fs_summary *,
1821 block_t, block_t, bool, bool);
1822 void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *,
1823 block_t, block_t, unsigned char, bool, bool);
1824 void allocate_data_block(struct f2fs_sb_info *, struct page *,
1825 block_t, block_t *, struct f2fs_summary *, int);
1826 void f2fs_wait_on_page_writeback(struct page *, enum page_type, bool);
1827 void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t);
1828 void write_data_summaries(struct f2fs_sb_info *, block_t);
1829 void write_node_summaries(struct f2fs_sb_info *, block_t);
1830 int lookup_journal_in_cursum(struct f2fs_journal *, int, unsigned int, int);
1831 void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *);
1832 int build_segment_manager(struct f2fs_sb_info *);
1833 void destroy_segment_manager(struct f2fs_sb_info *);
1834 int __init create_segment_manager_caches(void);
1835 void destroy_segment_manager_caches(void);
1840 struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
1841 struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
1842 struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t);
1843 bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int);
1844 int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool);
1845 void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t);
1846 long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
1847 void add_ino_entry(struct f2fs_sb_info *, nid_t, int type);
1848 void remove_ino_entry(struct f2fs_sb_info *, nid_t, int type);
1849 void release_ino_entry(struct f2fs_sb_info *);
1850 bool exist_written_data(struct f2fs_sb_info *, nid_t, int);
1851 int acquire_orphan_inode(struct f2fs_sb_info *);
1852 void release_orphan_inode(struct f2fs_sb_info *);
1853 void add_orphan_inode(struct f2fs_sb_info *, nid_t);
1854 void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
1855 int recover_orphan_inodes(struct f2fs_sb_info *);
1856 int get_valid_checkpoint(struct f2fs_sb_info *);
1857 void update_dirty_page(struct inode *, struct page *);
1858 void add_dirty_dir_inode(struct inode *);
1859 void remove_dirty_inode(struct inode *);
1860 int sync_dirty_inodes(struct f2fs_sb_info *, enum inode_type);
1861 int write_checkpoint(struct f2fs_sb_info *, struct cp_control *);
1862 void init_ino_entry_info(struct f2fs_sb_info *);
1863 int __init create_checkpoint_caches(void);
1864 void destroy_checkpoint_caches(void);
1869 void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
1870 void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *, struct inode *,
1871 struct page *, nid_t, enum page_type, int);
1872 void f2fs_flush_merged_bios(struct f2fs_sb_info *);
1873 int f2fs_submit_page_bio(struct f2fs_io_info *);
1874 void f2fs_submit_page_mbio(struct f2fs_io_info *);
1875 void set_data_blkaddr(struct dnode_of_data *);
1876 void f2fs_update_data_blkaddr(struct dnode_of_data *, block_t);
1877 int reserve_new_block(struct dnode_of_data *);
1878 int f2fs_get_block(struct dnode_of_data *, pgoff_t);
1879 ssize_t f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *);
1880 int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
1881 struct page *get_read_data_page(struct inode *, pgoff_t, int, bool);
1882 struct page *find_data_page(struct inode *, pgoff_t);
1883 struct page *get_lock_data_page(struct inode *, pgoff_t, bool);
1884 struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
1885 int do_write_data_page(struct f2fs_io_info *);
1886 int f2fs_map_blocks(struct inode *, struct f2fs_map_blocks *, int, int);
1887 int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
1888 void f2fs_invalidate_page(struct page *, unsigned int, unsigned int);
1889 int f2fs_release_page(struct page *, gfp_t);
1894 int start_gc_thread(struct f2fs_sb_info *);
1895 void stop_gc_thread(struct f2fs_sb_info *);
1896 block_t start_bidx_of_node(unsigned int, struct inode *);
1897 int f2fs_gc(struct f2fs_sb_info *, bool);
1898 void build_gc_manager(struct f2fs_sb_info *);
1903 int recover_fsync_data(struct f2fs_sb_info *);
1904 bool space_for_roll_forward(struct f2fs_sb_info *);
1909 #ifdef CONFIG_F2FS_STAT_FS
1910 struct f2fs_stat_info {
1911 struct list_head stat_list;
1912 struct f2fs_sb_info *sbi;
1913 int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
1914 int main_area_segs, main_area_sections, main_area_zones;
1915 unsigned long long hit_largest, hit_cached, hit_rbtree;
1916 unsigned long long hit_total, total_ext;
1917 int ext_tree, zombie_tree, ext_node;
1918 int ndirty_node, ndirty_meta;
1919 int ndirty_dent, ndirty_dirs, ndirty_data, ndirty_files;
1920 int nats, dirty_nats, sits, dirty_sits, fnids;
1921 int total_count, utilization;
1922 int bg_gc, inmem_pages, wb_pages;
1923 int inline_xattr, inline_inode, inline_dir;
1924 unsigned int valid_count, valid_node_count, valid_inode_count;
1925 unsigned int bimodal, avg_vblocks;
1926 int util_free, util_valid, util_invalid;
1927 int rsvd_segs, overp_segs;
1928 int dirty_count, node_pages, meta_pages;
1929 int prefree_count, call_count, cp_count, bg_cp_count;
1930 int tot_segs, node_segs, data_segs, free_segs, free_secs;
1931 int bg_node_segs, bg_data_segs;
1932 int tot_blks, data_blks, node_blks;
1933 int bg_data_blks, bg_node_blks;
1934 int curseg[NR_CURSEG_TYPE];
1935 int cursec[NR_CURSEG_TYPE];
1936 int curzone[NR_CURSEG_TYPE];
1938 unsigned int segment_count[2];
1939 unsigned int block_count[2];
1940 unsigned int inplace_count;
1941 unsigned long long base_mem, cache_mem, page_mem;
1944 static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
1946 return (struct f2fs_stat_info *)sbi->stat_info;
1949 #define stat_inc_cp_count(si) ((si)->cp_count++)
1950 #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++)
1951 #define stat_inc_call_count(si) ((si)->call_count++)
1952 #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
1953 #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++)
1954 #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--)
1955 #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext))
1956 #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree))
1957 #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest))
1958 #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached))
1959 #define stat_inc_inline_xattr(inode) \
1961 if (f2fs_has_inline_xattr(inode)) \
1962 (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \
1964 #define stat_dec_inline_xattr(inode) \
1966 if (f2fs_has_inline_xattr(inode)) \
1967 (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \
1969 #define stat_inc_inline_inode(inode) \
1971 if (f2fs_has_inline_data(inode)) \
1972 (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \
1974 #define stat_dec_inline_inode(inode) \
1976 if (f2fs_has_inline_data(inode)) \
1977 (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \
1979 #define stat_inc_inline_dir(inode) \
1981 if (f2fs_has_inline_dentry(inode)) \
1982 (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \
1984 #define stat_dec_inline_dir(inode) \
1986 if (f2fs_has_inline_dentry(inode)) \
1987 (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \
1989 #define stat_inc_seg_type(sbi, curseg) \
1990 ((sbi)->segment_count[(curseg)->alloc_type]++)
1991 #define stat_inc_block_count(sbi, curseg) \
1992 ((sbi)->block_count[(curseg)->alloc_type]++)
1993 #define stat_inc_inplace_blocks(sbi) \
1994 (atomic_inc(&(sbi)->inplace_count))
1995 #define stat_inc_seg_count(sbi, type, gc_type) \
1997 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
1999 if (type == SUM_TYPE_DATA) { \
2001 si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \
2004 si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \
2008 #define stat_inc_tot_blk_count(si, blks) \
2009 (si->tot_blks += (blks))
2011 #define stat_inc_data_blk_count(sbi, blks, gc_type) \
2013 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
2014 stat_inc_tot_blk_count(si, blks); \
2015 si->data_blks += (blks); \
2016 si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \
2019 #define stat_inc_node_blk_count(sbi, blks, gc_type) \
2021 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
2022 stat_inc_tot_blk_count(si, blks); \
2023 si->node_blks += (blks); \
2024 si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \
2027 int f2fs_build_stats(struct f2fs_sb_info *);
2028 void f2fs_destroy_stats(struct f2fs_sb_info *);
2029 int __init f2fs_create_root_stats(void);
2030 void f2fs_destroy_root_stats(void);
2032 #define stat_inc_cp_count(si)
2033 #define stat_inc_bg_cp_count(si)
2034 #define stat_inc_call_count(si)
2035 #define stat_inc_bggc_count(si)
2036 #define stat_inc_dirty_inode(sbi, type)
2037 #define stat_dec_dirty_inode(sbi, type)
2038 #define stat_inc_total_hit(sb)
2039 #define stat_inc_rbtree_node_hit(sb)
2040 #define stat_inc_largest_node_hit(sbi)
2041 #define stat_inc_cached_node_hit(sbi)
2042 #define stat_inc_inline_xattr(inode)
2043 #define stat_dec_inline_xattr(inode)
2044 #define stat_inc_inline_inode(inode)
2045 #define stat_dec_inline_inode(inode)
2046 #define stat_inc_inline_dir(inode)
2047 #define stat_dec_inline_dir(inode)
2048 #define stat_inc_seg_type(sbi, curseg)
2049 #define stat_inc_block_count(sbi, curseg)
2050 #define stat_inc_inplace_blocks(sbi)
2051 #define stat_inc_seg_count(sbi, type, gc_type)
2052 #define stat_inc_tot_blk_count(si, blks)
2053 #define stat_inc_data_blk_count(sbi, blks, gc_type)
2054 #define stat_inc_node_blk_count(sbi, blks, gc_type)
2056 static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
2057 static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
2058 static inline int __init f2fs_create_root_stats(void) { return 0; }
2059 static inline void f2fs_destroy_root_stats(void) { }
2062 extern const struct file_operations f2fs_dir_operations;
2063 extern const struct file_operations f2fs_file_operations;
2064 extern const struct inode_operations f2fs_file_inode_operations;
2065 extern const struct address_space_operations f2fs_dblock_aops;
2066 extern const struct address_space_operations f2fs_node_aops;
2067 extern const struct address_space_operations f2fs_meta_aops;
2068 extern const struct inode_operations f2fs_dir_inode_operations;
2069 extern const struct inode_operations f2fs_symlink_inode_operations;
2070 extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
2071 extern const struct inode_operations f2fs_special_inode_operations;
2072 extern struct kmem_cache *inode_entry_slab;
2077 bool f2fs_may_inline_data(struct inode *);
2078 bool f2fs_may_inline_dentry(struct inode *);
2079 void read_inline_data(struct page *, struct page *);
2080 bool truncate_inline_inode(struct page *, u64);
2081 int f2fs_read_inline_data(struct inode *, struct page *);
2082 int f2fs_convert_inline_page(struct dnode_of_data *, struct page *);
2083 int f2fs_convert_inline_inode(struct inode *);
2084 int f2fs_write_inline_data(struct inode *, struct page *);
2085 bool recover_inline_data(struct inode *, struct page *);
2086 struct f2fs_dir_entry *find_in_inline_dir(struct inode *,
2087 struct fscrypt_name *, struct page **);
2088 struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **);
2089 int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *);
2090 int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *,
2092 void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *,
2093 struct inode *, struct inode *);
2094 bool f2fs_empty_inline_dir(struct inode *);
2095 int f2fs_read_inline_dir(struct file *, struct dir_context *,
2096 struct fscrypt_str *);
2097 int f2fs_inline_data_fiemap(struct inode *,
2098 struct fiemap_extent_info *, __u64, __u64);
2103 unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *);
2104 unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *);
2105 void f2fs_join_shrinker(struct f2fs_sb_info *);
2106 void f2fs_leave_shrinker(struct f2fs_sb_info *);
2111 unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int);
2112 bool f2fs_init_extent_tree(struct inode *, struct f2fs_extent *);
2113 unsigned int f2fs_destroy_extent_node(struct inode *);
2114 void f2fs_destroy_extent_tree(struct inode *);
2115 bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *);
2116 void f2fs_update_extent_cache(struct dnode_of_data *);
2117 void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
2118 pgoff_t, block_t, unsigned int);
2119 void init_extent_cache_info(struct f2fs_sb_info *);
2120 int __init create_extent_cache(void);
2121 void destroy_extent_cache(void);
2126 static inline bool f2fs_encrypted_inode(struct inode *inode)
2128 return file_is_encrypt(inode);
2131 static inline void f2fs_set_encrypted_inode(struct inode *inode)
2133 #ifdef CONFIG_F2FS_FS_ENCRYPTION
2134 file_set_encrypt(inode);
2138 static inline bool f2fs_bio_encrypted(struct bio *bio)
2140 return bio->bi_private != NULL;
2143 static inline int f2fs_sb_has_crypto(struct super_block *sb)
2145 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT);
2148 static inline bool f2fs_may_encrypt(struct inode *inode)
2150 #ifdef CONFIG_F2FS_FS_ENCRYPTION
2151 umode_t mode = inode->i_mode;
2153 return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
2159 #ifndef CONFIG_F2FS_FS_ENCRYPTION
2160 #define fscrypt_set_d_op(i)
2161 #define fscrypt_get_ctx fscrypt_notsupp_get_ctx
2162 #define fscrypt_release_ctx fscrypt_notsupp_release_ctx
2163 #define fscrypt_encrypt_page fscrypt_notsupp_encrypt_page
2164 #define fscrypt_decrypt_page fscrypt_notsupp_decrypt_page
2165 #define fscrypt_decrypt_bio_pages fscrypt_notsupp_decrypt_bio_pages
2166 #define fscrypt_pullback_bio_page fscrypt_notsupp_pullback_bio_page
2167 #define fscrypt_restore_control_page fscrypt_notsupp_restore_control_page
2168 #define fscrypt_zeroout_range fscrypt_notsupp_zeroout_range
2169 #define fscrypt_process_policy fscrypt_notsupp_process_policy
2170 #define fscrypt_get_policy fscrypt_notsupp_get_policy
2171 #define fscrypt_has_permitted_context fscrypt_notsupp_has_permitted_context
2172 #define fscrypt_inherit_context fscrypt_notsupp_inherit_context
2173 #define fscrypt_get_encryption_info fscrypt_notsupp_get_encryption_info
2174 #define fscrypt_put_encryption_info fscrypt_notsupp_put_encryption_info
2175 #define fscrypt_setup_filename fscrypt_notsupp_setup_filename
2176 #define fscrypt_free_filename fscrypt_notsupp_free_filename
2177 #define fscrypt_fname_encrypted_size fscrypt_notsupp_fname_encrypted_size
2178 #define fscrypt_fname_alloc_buffer fscrypt_notsupp_fname_alloc_buffer
2179 #define fscrypt_fname_free_buffer fscrypt_notsupp_fname_free_buffer
2180 #define fscrypt_fname_disk_to_usr fscrypt_notsupp_fname_disk_to_usr
2181 #define fscrypt_fname_usr_to_disk fscrypt_notsupp_fname_usr_to_disk