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/version.h>
18 #include <linux/slab.h>
19 #include <linux/crc32.h>
20 #include <linux/magic.h>
25 #define F2FS_MOUNT_BG_GC 0x00000001
26 #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
27 #define F2FS_MOUNT_DISCARD 0x00000004
28 #define F2FS_MOUNT_NOHEAP 0x00000008
29 #define F2FS_MOUNT_XATTR_USER 0x00000010
30 #define F2FS_MOUNT_POSIX_ACL 0x00000020
31 #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
33 #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
34 #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
35 #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
37 #define ver_after(a, b) (typecheck(unsigned long long, a) && \
38 typecheck(unsigned long long, b) && \
39 ((long long)((a) - (b)) > 0))
44 struct f2fs_mount_info {
48 static inline __u32 f2fs_crc32(void *buff, size_t len)
50 return crc32_le(F2FS_SUPER_MAGIC, buff, len);
53 static inline bool f2fs_crc_valid(__u32 blk_crc, void *buff, size_t buff_size)
55 return f2fs_crc32(buff, buff_size) == blk_crc;
59 * For checkpoint manager
66 /* for the list of orphan inodes */
67 struct orphan_inode_entry {
68 struct list_head list; /* list head */
69 nid_t ino; /* inode number */
72 /* for the list of directory inodes */
73 struct dir_inode_entry {
74 struct list_head list; /* list head */
75 struct inode *inode; /* vfs inode pointer */
78 /* for the list of fsync inodes, used only during recovery */
79 struct fsync_inode_entry {
80 struct list_head list; /* list head */
81 struct inode *inode; /* vfs inode pointer */
82 block_t blkaddr; /* block address locating the last inode */
85 #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats))
86 #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits))
88 #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne)
89 #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid)
90 #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se)
91 #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno)
93 static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
95 int before = nats_in_cursum(rs);
96 rs->n_nats = cpu_to_le16(before + i);
100 static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
102 int before = sits_in_cursum(rs);
103 rs->n_sits = cpu_to_le16(before + i);
108 * For INODE and NODE manager
110 #define XATTR_NODE_OFFSET (-1) /*
111 * store xattrs to one node block per
112 * file keeping -1 as its node offset to
113 * distinguish from index node blocks.
115 #define RDONLY_NODE 1 /*
116 * specify a read-only mode when getting
117 * a node block. 0 is read-write mode.
118 * used by get_dnode_of_data().
120 #define F2FS_LINK_MAX 32000 /* maximum link count per file */
122 /* for in-memory extent cache entry */
124 rwlock_t ext_lock; /* rwlock for consistency */
125 unsigned int fofs; /* start offset in a file */
126 u32 blk_addr; /* start block address of the extent */
127 unsigned int len; /* lenth of the extent */
131 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
133 #define FADVISE_COLD_BIT 0x01
135 struct f2fs_inode_info {
136 struct inode vfs_inode; /* serve a vfs inode */
137 unsigned long i_flags; /* keep an inode flags for ioctl */
138 unsigned char i_advise; /* use to give file attribute hints */
139 unsigned int i_current_depth; /* use only in directory structure */
140 umode_t i_acl_mode; /* keep file acl mode temporarily */
142 /* Use below internally in f2fs*/
143 unsigned long flags; /* use to pass per-file flags */
144 unsigned long long data_version;/* lastes version of data for fsync */
145 atomic_t dirty_dents; /* # of dirty dentry pages */
146 f2fs_hash_t chash; /* hash value of given file name */
147 unsigned int clevel; /* maximum level of given file name */
148 nid_t i_xattr_nid; /* node id that contains xattrs */
149 struct extent_info ext; /* in-memory extent cache entry */
152 static inline void get_extent_info(struct extent_info *ext,
153 struct f2fs_extent i_ext)
155 write_lock(&ext->ext_lock);
156 ext->fofs = le32_to_cpu(i_ext.fofs);
157 ext->blk_addr = le32_to_cpu(i_ext.blk_addr);
158 ext->len = le32_to_cpu(i_ext.len);
159 write_unlock(&ext->ext_lock);
162 static inline void set_raw_extent(struct extent_info *ext,
163 struct f2fs_extent *i_ext)
165 read_lock(&ext->ext_lock);
166 i_ext->fofs = cpu_to_le32(ext->fofs);
167 i_ext->blk_addr = cpu_to_le32(ext->blk_addr);
168 i_ext->len = cpu_to_le32(ext->len);
169 read_unlock(&ext->ext_lock);
172 struct f2fs_nm_info {
173 block_t nat_blkaddr; /* base disk address of NAT */
174 nid_t max_nid; /* maximum possible node ids */
175 nid_t init_scan_nid; /* the first nid to be scanned */
176 nid_t next_scan_nid; /* the next nid to be scanned */
178 /* NAT cache management */
179 struct radix_tree_root nat_root;/* root of the nat entry cache */
180 rwlock_t nat_tree_lock; /* protect nat_tree_lock */
181 unsigned int nat_cnt; /* the # of cached nat entries */
182 struct list_head nat_entries; /* cached nat entry list (clean) */
183 struct list_head dirty_nat_entries; /* cached nat entry list (dirty) */
185 /* free node ids management */
186 struct list_head free_nid_list; /* a list for free nids */
187 spinlock_t free_nid_list_lock; /* protect free nid list */
188 unsigned int fcnt; /* the number of free node id */
189 struct mutex build_lock; /* lock for build free nids */
192 char *nat_bitmap; /* NAT bitmap pointer */
193 int bitmap_size; /* bitmap size */
197 * this structure is used as one of function parameters.
198 * all the information are dedicated to a given direct node block determined
199 * by the data offset in a file.
201 struct dnode_of_data {
202 struct inode *inode; /* vfs inode pointer */
203 struct page *inode_page; /* its inode page, NULL is possible */
204 struct page *node_page; /* cached direct node page */
205 nid_t nid; /* node id of the direct node block */
206 unsigned int ofs_in_node; /* data offset in the node page */
207 bool inode_page_locked; /* inode page is locked or not */
208 block_t data_blkaddr; /* block address of the node block */
211 static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
212 struct page *ipage, struct page *npage, nid_t nid)
215 dn->inode_page = ipage;
216 dn->node_page = npage;
218 dn->inode_page_locked = 0;
224 * By default, there are 6 active log areas across the whole main area.
225 * When considering hot and cold data separation to reduce cleaning overhead,
226 * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
228 * In the current design, you should not change the numbers intentionally.
229 * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
230 * logs individually according to the underlying devices. (default: 6)
231 * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
232 * data and 8 for node logs.
234 #define NR_CURSEG_DATA_TYPE (3)
235 #define NR_CURSEG_NODE_TYPE (3)
236 #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
239 CURSEG_HOT_DATA = 0, /* directory entry blocks */
240 CURSEG_WARM_DATA, /* data blocks */
241 CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
242 CURSEG_HOT_NODE, /* direct node blocks of directory files */
243 CURSEG_WARM_NODE, /* direct node blocks of normal files */
244 CURSEG_COLD_NODE, /* indirect node blocks */
248 struct f2fs_sm_info {
249 struct sit_info *sit_info; /* whole segment information */
250 struct free_segmap_info *free_info; /* free segment information */
251 struct dirty_seglist_info *dirty_info; /* dirty segment information */
252 struct curseg_info *curseg_array; /* active segment information */
254 struct list_head wblist_head; /* list of under-writeback pages */
255 spinlock_t wblist_lock; /* lock for checkpoint */
257 block_t seg0_blkaddr; /* block address of 0'th segment */
258 block_t main_blkaddr; /* start block address of main area */
259 block_t ssa_blkaddr; /* start block address of SSA area */
261 unsigned int segment_count; /* total # of segments */
262 unsigned int main_segments; /* # of segments in main area */
263 unsigned int reserved_segments; /* # of reserved segments */
264 unsigned int ovp_segments; /* # of overprovision segments */
268 * For directory operation
270 #define NODE_DIR1_BLOCK (ADDRS_PER_INODE + 1)
271 #define NODE_DIR2_BLOCK (ADDRS_PER_INODE + 2)
272 #define NODE_IND1_BLOCK (ADDRS_PER_INODE + 3)
273 #define NODE_IND2_BLOCK (ADDRS_PER_INODE + 4)
274 #define NODE_DIND_BLOCK (ADDRS_PER_INODE + 5)
280 * COUNT_TYPE for monitoring
282 * f2fs monitors the number of several block types such as on-writeback,
283 * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
294 * FS_LOCK nesting subclasses for the lock validator:
296 * The locking order between these classes is
297 * RENAME -> DENTRY_OPS -> DATA_WRITE -> DATA_NEW
298 * -> DATA_TRUNC -> NODE_WRITE -> NODE_NEW -> NODE_TRUNC
301 RENAME, /* for renaming operations */
302 DENTRY_OPS, /* for directory operations */
303 DATA_WRITE, /* for data write */
304 DATA_NEW, /* for data allocation */
305 DATA_TRUNC, /* for data truncate */
306 NODE_NEW, /* for node allocation */
307 NODE_TRUNC, /* for node truncate */
308 NODE_WRITE, /* for node write */
313 * The below are the page types of bios used in submti_bio().
314 * The available types are:
315 * DATA User data pages. It operates as async mode.
316 * NODE Node pages. It operates as async mode.
317 * META FS metadata pages such as SIT, NAT, CP.
318 * NR_PAGE_TYPE The number of page types.
319 * META_FLUSH Make sure the previous pages are written
320 * with waiting the bio's completion
321 * ... Only can be used with META.
331 struct f2fs_sb_info {
332 struct super_block *sb; /* pointer to VFS super block */
333 struct buffer_head *raw_super_buf; /* buffer head of raw sb */
334 struct f2fs_super_block *raw_super; /* raw super block pointer */
335 int s_dirty; /* dirty flag for checkpoint */
337 /* for node-related operations */
338 struct f2fs_nm_info *nm_info; /* node manager */
339 struct inode *node_inode; /* cache node blocks */
341 /* for segment-related operations */
342 struct f2fs_sm_info *sm_info; /* segment manager */
343 struct bio *bio[NR_PAGE_TYPE]; /* bios to merge */
344 sector_t last_block_in_bio[NR_PAGE_TYPE]; /* last block number */
345 struct rw_semaphore bio_sem; /* IO semaphore */
348 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
349 struct inode *meta_inode; /* cache meta blocks */
350 struct mutex cp_mutex; /* for checkpoint procedure */
351 struct mutex fs_lock[NR_LOCK_TYPE]; /* for blocking FS operations */
352 struct mutex write_inode; /* mutex for write inode */
353 struct mutex writepages; /* mutex for writepages() */
354 int por_doing; /* recovery is doing or not */
356 /* for orphan inode management */
357 struct list_head orphan_inode_list; /* orphan inode list */
358 struct mutex orphan_inode_mutex; /* for orphan inode list */
359 unsigned int n_orphans; /* # of orphan inodes */
361 /* for directory inode management */
362 struct list_head dir_inode_list; /* dir inode list */
363 spinlock_t dir_inode_lock; /* for dir inode list lock */
364 unsigned int n_dirty_dirs; /* # of dir inodes */
366 /* basic file system units */
367 unsigned int log_sectors_per_block; /* log2 sectors per block */
368 unsigned int log_blocksize; /* log2 block size */
369 unsigned int blocksize; /* block size */
370 unsigned int root_ino_num; /* root inode number*/
371 unsigned int node_ino_num; /* node inode number*/
372 unsigned int meta_ino_num; /* meta inode number*/
373 unsigned int log_blocks_per_seg; /* log2 blocks per segment */
374 unsigned int blocks_per_seg; /* blocks per segment */
375 unsigned int segs_per_sec; /* segments per section */
376 unsigned int secs_per_zone; /* sections per zone */
377 unsigned int total_sections; /* total section count */
378 unsigned int total_node_count; /* total node block count */
379 unsigned int total_valid_node_count; /* valid node block count */
380 unsigned int total_valid_inode_count; /* valid inode count */
381 int active_logs; /* # of active logs */
383 block_t user_block_count; /* # of user blocks */
384 block_t total_valid_block_count; /* # of valid blocks */
385 block_t alloc_valid_block_count; /* # of allocated blocks */
386 block_t last_valid_block_count; /* for recovery */
387 u32 s_next_generation; /* for NFS support */
388 atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
390 struct f2fs_mount_info mount_opt; /* mount options */
392 /* for cleaning operations */
393 struct mutex gc_mutex; /* mutex for GC */
394 struct f2fs_gc_kthread *gc_thread; /* GC thread */
397 * for stat information.
398 * one is for the LFS mode, and the other is for the SSR mode.
400 struct f2fs_stat_info *stat_info; /* FS status information */
401 unsigned int segment_count[2]; /* # of allocated segments */
402 unsigned int block_count[2]; /* # of allocated blocks */
403 unsigned int last_victim[2]; /* last victim segment # */
404 int total_hit_ext, read_hit_ext; /* extent cache hit ratio */
405 int bg_gc; /* background gc calls */
406 spinlock_t stat_lock; /* lock for stat operations */
412 static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
414 return container_of(inode, struct f2fs_inode_info, vfs_inode);
417 static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
419 return sb->s_fs_info;
422 static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
424 return (struct f2fs_super_block *)(sbi->raw_super);
427 static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
429 return (struct f2fs_checkpoint *)(sbi->ckpt);
432 static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
434 return (struct f2fs_nm_info *)(sbi->nm_info);
437 static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
439 return (struct f2fs_sm_info *)(sbi->sm_info);
442 static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
444 return (struct sit_info *)(SM_I(sbi)->sit_info);
447 static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
449 return (struct free_segmap_info *)(SM_I(sbi)->free_info);
452 static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
454 return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
457 static inline void F2FS_SET_SB_DIRT(struct f2fs_sb_info *sbi)
462 static inline void F2FS_RESET_SB_DIRT(struct f2fs_sb_info *sbi)
467 static inline void mutex_lock_op(struct f2fs_sb_info *sbi, enum lock_type t)
469 mutex_lock_nested(&sbi->fs_lock[t], t);
472 static inline void mutex_unlock_op(struct f2fs_sb_info *sbi, enum lock_type t)
474 mutex_unlock(&sbi->fs_lock[t]);
478 * Check whether the given nid is within node id range.
480 static inline void check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
482 BUG_ON((nid >= NM_I(sbi)->max_nid));
485 #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
488 * Check whether the inode has blocks or not
490 static inline int F2FS_HAS_BLOCKS(struct inode *inode)
492 if (F2FS_I(inode)->i_xattr_nid)
493 return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1);
495 return (inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS);
498 static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
499 struct inode *inode, blkcnt_t count)
501 block_t valid_block_count;
503 spin_lock(&sbi->stat_lock);
505 sbi->total_valid_block_count + (block_t)count;
506 if (valid_block_count > sbi->user_block_count) {
507 spin_unlock(&sbi->stat_lock);
510 inode->i_blocks += count;
511 sbi->total_valid_block_count = valid_block_count;
512 sbi->alloc_valid_block_count += (block_t)count;
513 spin_unlock(&sbi->stat_lock);
517 static inline int dec_valid_block_count(struct f2fs_sb_info *sbi,
521 spin_lock(&sbi->stat_lock);
522 BUG_ON(sbi->total_valid_block_count < (block_t) count);
523 BUG_ON(inode->i_blocks < count);
524 inode->i_blocks -= count;
525 sbi->total_valid_block_count -= (block_t)count;
526 spin_unlock(&sbi->stat_lock);
530 static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
532 atomic_inc(&sbi->nr_pages[count_type]);
533 F2FS_SET_SB_DIRT(sbi);
536 static inline void inode_inc_dirty_dents(struct inode *inode)
538 atomic_inc(&F2FS_I(inode)->dirty_dents);
541 static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
543 atomic_dec(&sbi->nr_pages[count_type]);
546 static inline void inode_dec_dirty_dents(struct inode *inode)
548 atomic_dec(&F2FS_I(inode)->dirty_dents);
551 static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
553 return atomic_read(&sbi->nr_pages[count_type]);
556 static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
559 spin_lock(&sbi->stat_lock);
560 ret = sbi->total_valid_block_count;
561 spin_unlock(&sbi->stat_lock);
565 static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
567 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
569 /* return NAT or SIT bitmap */
570 if (flag == NAT_BITMAP)
571 return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
572 else if (flag == SIT_BITMAP)
573 return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
578 static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
580 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
581 int offset = (flag == NAT_BITMAP) ? ckpt->sit_ver_bitmap_bytesize : 0;
582 return &ckpt->sit_nat_version_bitmap + offset;
585 static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
588 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
589 unsigned long long ckpt_version = le64_to_cpu(ckpt->checkpoint_ver);
591 start_addr = le64_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
594 * odd numbered checkpoint should at cp segment 0
595 * and even segent must be at cp segment 1
597 if (!(ckpt_version & 1))
598 start_addr += sbi->blocks_per_seg;
603 static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
605 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
608 static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
612 block_t valid_block_count;
613 unsigned int valid_node_count;
615 spin_lock(&sbi->stat_lock);
617 valid_block_count = sbi->total_valid_block_count + (block_t)count;
618 sbi->alloc_valid_block_count += (block_t)count;
619 valid_node_count = sbi->total_valid_node_count + count;
621 if (valid_block_count > sbi->user_block_count) {
622 spin_unlock(&sbi->stat_lock);
626 if (valid_node_count > sbi->total_node_count) {
627 spin_unlock(&sbi->stat_lock);
632 inode->i_blocks += count;
633 sbi->total_valid_node_count = valid_node_count;
634 sbi->total_valid_block_count = valid_block_count;
635 spin_unlock(&sbi->stat_lock);
640 static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
644 spin_lock(&sbi->stat_lock);
646 BUG_ON(sbi->total_valid_block_count < count);
647 BUG_ON(sbi->total_valid_node_count < count);
648 BUG_ON(inode->i_blocks < count);
650 inode->i_blocks -= count;
651 sbi->total_valid_node_count -= count;
652 sbi->total_valid_block_count -= (block_t)count;
654 spin_unlock(&sbi->stat_lock);
657 static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
660 spin_lock(&sbi->stat_lock);
661 ret = sbi->total_valid_node_count;
662 spin_unlock(&sbi->stat_lock);
666 static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
668 spin_lock(&sbi->stat_lock);
669 BUG_ON(sbi->total_valid_inode_count == sbi->total_node_count);
670 sbi->total_valid_inode_count++;
671 spin_unlock(&sbi->stat_lock);
674 static inline int dec_valid_inode_count(struct f2fs_sb_info *sbi)
676 spin_lock(&sbi->stat_lock);
677 BUG_ON(!sbi->total_valid_inode_count);
678 sbi->total_valid_inode_count--;
679 spin_unlock(&sbi->stat_lock);
683 static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
686 spin_lock(&sbi->stat_lock);
687 ret = sbi->total_valid_inode_count;
688 spin_unlock(&sbi->stat_lock);
692 static inline void f2fs_put_page(struct page *page, int unlock)
694 if (!page || IS_ERR(page))
698 BUG_ON(!PageLocked(page));
701 page_cache_release(page);
704 static inline void f2fs_put_dnode(struct dnode_of_data *dn)
707 f2fs_put_page(dn->node_page, 1);
708 if (dn->inode_page && dn->node_page != dn->inode_page)
709 f2fs_put_page(dn->inode_page, 0);
710 dn->node_page = NULL;
711 dn->inode_page = NULL;
714 static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
715 size_t size, void (*ctor)(void *))
717 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, ctor);
720 #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
722 static inline bool IS_INODE(struct page *page)
724 struct f2fs_node *p = (struct f2fs_node *)page_address(page);
725 return RAW_IS_INODE(p);
728 static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
730 return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
733 static inline block_t datablock_addr(struct page *node_page,
736 struct f2fs_node *raw_node;
738 raw_node = (struct f2fs_node *)page_address(node_page);
739 addr_array = blkaddr_in_node(raw_node);
740 return le32_to_cpu(addr_array[offset]);
743 static inline int f2fs_test_bit(unsigned int nr, char *addr)
748 mask = 1 << (7 - (nr & 0x07));
752 static inline int f2fs_set_bit(unsigned int nr, char *addr)
758 mask = 1 << (7 - (nr & 0x07));
764 static inline int f2fs_clear_bit(unsigned int nr, char *addr)
770 mask = 1 << (7 - (nr & 0x07));
776 /* used for f2fs_inode_info->flags */
778 FI_NEW_INODE, /* indicate newly allocated inode */
779 FI_NEED_CP, /* need to do checkpoint during fsync */
780 FI_INC_LINK, /* need to increment i_nlink */
781 FI_ACL_MODE, /* indicate acl mode */
782 FI_NO_ALLOC, /* should not allocate any blocks */
785 static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
787 set_bit(flag, &fi->flags);
790 static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
792 return test_bit(flag, &fi->flags);
795 static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
797 clear_bit(flag, &fi->flags);
800 static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
802 fi->i_acl_mode = mode;
803 set_inode_flag(fi, FI_ACL_MODE);
806 static inline int cond_clear_inode_flag(struct f2fs_inode_info *fi, int flag)
808 if (is_inode_flag_set(fi, FI_ACL_MODE)) {
809 clear_inode_flag(fi, FI_ACL_MODE);
818 int f2fs_sync_file(struct file *, loff_t, loff_t, int);
819 void truncate_data_blocks(struct dnode_of_data *);
820 void f2fs_truncate(struct inode *);
821 int f2fs_setattr(struct dentry *, struct iattr *);
822 int truncate_hole(struct inode *, pgoff_t, pgoff_t);
823 long f2fs_ioctl(struct file *, unsigned int, unsigned long);
828 void f2fs_set_inode_flags(struct inode *);
829 struct inode *f2fs_iget_nowait(struct super_block *, unsigned long);
830 struct inode *f2fs_iget(struct super_block *, unsigned long);
831 void update_inode(struct inode *, struct page *);
832 int f2fs_write_inode(struct inode *, struct writeback_control *);
833 void f2fs_evict_inode(struct inode *);
838 struct dentry *f2fs_get_parent(struct dentry *child);
843 struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
845 struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
846 ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
847 void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
848 struct page *, struct inode *);
849 void init_dent_inode(struct dentry *, struct page *);
850 int f2fs_add_link(struct dentry *, struct inode *);
851 void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *);
852 int f2fs_make_empty(struct inode *, struct inode *);
853 bool f2fs_empty_dir(struct inode *);
858 int f2fs_sync_fs(struct super_block *, int);
863 f2fs_hash_t f2fs_dentry_hash(const char *, int);
868 struct dnode_of_data;
871 int is_checkpointed_node(struct f2fs_sb_info *, nid_t);
872 void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
873 int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
874 int truncate_inode_blocks(struct inode *, pgoff_t);
875 int remove_inode_page(struct inode *);
876 int new_inode_page(struct inode *, struct dentry *);
877 struct page *new_node_page(struct dnode_of_data *, unsigned int);
878 void ra_node_page(struct f2fs_sb_info *, nid_t);
879 struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
880 struct page *get_node_page_ra(struct page *, int);
881 void sync_inode_page(struct dnode_of_data *);
882 int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
883 bool alloc_nid(struct f2fs_sb_info *, nid_t *);
884 void alloc_nid_done(struct f2fs_sb_info *, nid_t);
885 void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
886 void recover_node_page(struct f2fs_sb_info *, struct page *,
887 struct f2fs_summary *, struct node_info *, block_t);
888 int recover_inode_page(struct f2fs_sb_info *, struct page *);
889 int restore_node_summary(struct f2fs_sb_info *, unsigned int,
890 struct f2fs_summary_block *);
891 void flush_nat_entries(struct f2fs_sb_info *);
892 int build_node_manager(struct f2fs_sb_info *);
893 void destroy_node_manager(struct f2fs_sb_info *);
894 int create_node_manager_caches(void);
895 void destroy_node_manager_caches(void);
900 void f2fs_balance_fs(struct f2fs_sb_info *);
901 void invalidate_blocks(struct f2fs_sb_info *, block_t);
902 void locate_dirty_segment(struct f2fs_sb_info *, unsigned int);
903 void clear_prefree_segments(struct f2fs_sb_info *);
904 int npages_for_summary_flush(struct f2fs_sb_info *);
905 void allocate_new_segments(struct f2fs_sb_info *);
906 struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
907 struct bio *f2fs_bio_alloc(struct block_device *, sector_t, int, gfp_t);
908 void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool sync);
909 int write_meta_page(struct f2fs_sb_info *, struct page *,
910 struct writeback_control *);
911 void write_node_page(struct f2fs_sb_info *, struct page *, unsigned int,
913 void write_data_page(struct inode *, struct page *, struct dnode_of_data*,
915 void rewrite_data_page(struct f2fs_sb_info *, struct page *, block_t);
916 void recover_data_page(struct f2fs_sb_info *, struct page *,
917 struct f2fs_summary *, block_t, block_t);
918 void rewrite_node_page(struct f2fs_sb_info *, struct page *,
919 struct f2fs_summary *, block_t, block_t);
920 void write_data_summaries(struct f2fs_sb_info *, block_t);
921 void write_node_summaries(struct f2fs_sb_info *, block_t);
922 int lookup_journal_in_cursum(struct f2fs_summary_block *,
923 int, unsigned int, int);
924 void flush_sit_entries(struct f2fs_sb_info *);
925 int build_segment_manager(struct f2fs_sb_info *);
926 void reset_victim_segmap(struct f2fs_sb_info *);
927 void destroy_segment_manager(struct f2fs_sb_info *);
932 struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
933 struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
934 long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
935 int check_orphan_space(struct f2fs_sb_info *);
936 void add_orphan_inode(struct f2fs_sb_info *, nid_t);
937 void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
938 int recover_orphan_inodes(struct f2fs_sb_info *);
939 int get_valid_checkpoint(struct f2fs_sb_info *);
940 void set_dirty_dir_page(struct inode *, struct page *);
941 void remove_dirty_dir_inode(struct inode *);
942 void sync_dirty_dir_inodes(struct f2fs_sb_info *);
943 void block_operations(struct f2fs_sb_info *);
944 void write_checkpoint(struct f2fs_sb_info *, bool, bool);
945 void init_orphan_info(struct f2fs_sb_info *);
946 int create_checkpoint_caches(void);
947 void destroy_checkpoint_caches(void);
952 int reserve_new_block(struct dnode_of_data *);
953 void update_extent_cache(block_t, struct dnode_of_data *);
954 struct page *find_data_page(struct inode *, pgoff_t);
955 struct page *get_lock_data_page(struct inode *, pgoff_t);
956 struct page *get_new_data_page(struct inode *, pgoff_t, bool);
957 int f2fs_readpage(struct f2fs_sb_info *, struct page *, block_t, int);
958 int do_write_data_page(struct page *);
963 int start_gc_thread(struct f2fs_sb_info *);
964 void stop_gc_thread(struct f2fs_sb_info *);
965 block_t start_bidx_of_node(unsigned int);
966 int f2fs_gc(struct f2fs_sb_info *, int);
967 void build_gc_manager(struct f2fs_sb_info *);
968 int create_gc_caches(void);
969 void destroy_gc_caches(void);
974 void recover_fsync_data(struct f2fs_sb_info *);
975 bool space_for_roll_forward(struct f2fs_sb_info *);
980 #ifdef CONFIG_F2FS_STAT_FS
981 struct f2fs_stat_info {
982 struct list_head stat_list;
983 struct f2fs_sb_info *sbi;
984 struct mutex stat_lock;
985 int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
986 int main_area_segs, main_area_sections, main_area_zones;
987 int hit_ext, total_ext;
988 int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
989 int nats, sits, fnids;
990 int total_count, utilization;
992 unsigned int valid_count, valid_node_count, valid_inode_count;
993 unsigned int bimodal, avg_vblocks;
994 int util_free, util_valid, util_invalid;
995 int rsvd_segs, overp_segs;
996 int dirty_count, node_pages, meta_pages;
997 int prefree_count, call_count;
998 int tot_segs, node_segs, data_segs, free_segs, free_secs;
999 int tot_blks, data_blks, node_blks;
1000 int curseg[NR_CURSEG_TYPE];
1001 int cursec[NR_CURSEG_TYPE];
1002 int curzone[NR_CURSEG_TYPE];
1004 unsigned int segment_count[2];
1005 unsigned int block_count[2];
1006 unsigned base_mem, cache_mem;
1009 #define stat_inc_call_count(si) ((si)->call_count++)
1011 #define stat_inc_seg_count(sbi, type) \
1013 struct f2fs_stat_info *si = sbi->stat_info; \
1015 if (type == SUM_TYPE_DATA) \
1021 #define stat_inc_tot_blk_count(si, blks) \
1022 (si->tot_blks += (blks))
1024 #define stat_inc_data_blk_count(sbi, blks) \
1026 struct f2fs_stat_info *si = sbi->stat_info; \
1027 stat_inc_tot_blk_count(si, blks); \
1028 si->data_blks += (blks); \
1031 #define stat_inc_node_blk_count(sbi, blks) \
1033 struct f2fs_stat_info *si = sbi->stat_info; \
1034 stat_inc_tot_blk_count(si, blks); \
1035 si->node_blks += (blks); \
1038 int f2fs_build_stats(struct f2fs_sb_info *);
1039 void f2fs_destroy_stats(struct f2fs_sb_info *);
1040 void destroy_root_stats(void);
1042 #define stat_inc_call_count(si)
1043 #define stat_inc_seg_count(si, type)
1044 #define stat_inc_tot_blk_count(si, blks)
1045 #define stat_inc_data_blk_count(si, blks)
1046 #define stat_inc_node_blk_count(sbi, blks)
1048 static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
1049 static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
1050 static inline void destroy_root_stats(void) { }
1053 extern const struct file_operations f2fs_dir_operations;
1054 extern const struct file_operations f2fs_file_operations;
1055 extern const struct inode_operations f2fs_file_inode_operations;
1056 extern const struct address_space_operations f2fs_dblock_aops;
1057 extern const struct address_space_operations f2fs_node_aops;
1058 extern const struct address_space_operations f2fs_meta_aops;
1059 extern const struct inode_operations f2fs_dir_inode_operations;
1060 extern const struct inode_operations f2fs_symlink_inode_operations;
1061 extern const struct inode_operations f2fs_special_inode_operations;