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>
25 #ifdef CONFIG_F2FS_CHECK_FS
26 #define f2fs_bug_on(sbi, condition) BUG_ON(condition)
28 #define f2fs_bug_on(sbi, condition) \
30 if (unlikely(condition)) { \
32 set_sbi_flag(sbi, SBI_NEED_FSCK); \
40 #define F2FS_MOUNT_BG_GC 0x00000001
41 #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002
42 #define F2FS_MOUNT_DISCARD 0x00000004
43 #define F2FS_MOUNT_NOHEAP 0x00000008
44 #define F2FS_MOUNT_XATTR_USER 0x00000010
45 #define F2FS_MOUNT_POSIX_ACL 0x00000020
46 #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040
47 #define F2FS_MOUNT_INLINE_XATTR 0x00000080
48 #define F2FS_MOUNT_INLINE_DATA 0x00000100
49 #define F2FS_MOUNT_INLINE_DENTRY 0x00000200
50 #define F2FS_MOUNT_FLUSH_MERGE 0x00000400
51 #define F2FS_MOUNT_NOBARRIER 0x00000800
52 #define F2FS_MOUNT_FASTBOOT 0x00001000
53 #define F2FS_MOUNT_EXTENT_CACHE 0x00002000
54 #define F2FS_MOUNT_FORCE_FG_GC 0x00004000
56 #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
57 #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option)
58 #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option)
60 #define ver_after(a, b) (typecheck(unsigned long long, a) && \
61 typecheck(unsigned long long, b) && \
62 ((long long)((a) - (b)) > 0))
64 typedef u32 block_t; /*
65 * should not change u32, since it is the on-disk block
66 * address format, __le32.
70 struct f2fs_mount_info {
74 #define F2FS_FEATURE_ENCRYPT 0x0001
76 #define F2FS_HAS_FEATURE(sb, mask) \
77 ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0)
78 #define F2FS_SET_FEATURE(sb, mask) \
79 F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)
80 #define F2FS_CLEAR_FEATURE(sb, mask) \
81 F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)
83 #define CRCPOLY_LE 0xedb88320
85 static inline __u32 f2fs_crc32(void *buf, size_t len)
87 unsigned char *p = (unsigned char *)buf;
88 __u32 crc = F2FS_SUPER_MAGIC;
93 for (i = 0; i < 8; i++)
94 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
99 static inline bool f2fs_crc_valid(__u32 blk_crc, void *buf, size_t buf_size)
101 return f2fs_crc32(buf, buf_size) == blk_crc;
105 * For checkpoint manager
120 #define DEF_BATCHED_TRIM_SECTIONS 32
121 #define BATCHED_TRIM_SEGMENTS(sbi) \
122 (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
123 #define BATCHED_TRIM_BLOCKS(sbi) \
124 (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
125 #define DEF_CP_INTERVAL 60 /* 60 secs */
136 * For CP/NAT/SIT/SSA readahead
146 /* for the list of ino */
148 ORPHAN_INO, /* for orphan ino list */
149 APPEND_INO, /* for append ino list */
150 UPDATE_INO, /* for update ino list */
151 MAX_INO_ENTRY, /* max. list */
155 struct list_head list; /* list head */
156 nid_t ino; /* inode number */
160 * for the list of directory inodes or gc inodes.
161 * NOTE: there are two slab users for this structure, if we add/modify/delete
162 * fields in structure for one of slab users, it may affect fields or size of
163 * other one, in this condition, it's better to split both of slab and related
167 struct list_head list; /* list head */
168 struct inode *inode; /* vfs inode pointer */
171 /* for the list of blockaddresses to be discarded */
172 struct discard_entry {
173 struct list_head list; /* list head */
174 block_t blkaddr; /* block address to be discarded */
175 int len; /* # of consecutive blocks of the discard */
178 /* for the list of fsync inodes, used only during recovery */
179 struct fsync_inode_entry {
180 struct list_head list; /* list head */
181 struct inode *inode; /* vfs inode pointer */
182 block_t blkaddr; /* block address locating the last fsync */
183 block_t last_dentry; /* block address locating the last dentry */
184 block_t last_inode; /* block address locating the last inode */
187 #define nats_in_cursum(sum) (le16_to_cpu(sum->n_nats))
188 #define sits_in_cursum(sum) (le16_to_cpu(sum->n_sits))
190 #define nat_in_journal(sum, i) (sum->nat_j.entries[i].ne)
191 #define nid_in_journal(sum, i) (sum->nat_j.entries[i].nid)
192 #define sit_in_journal(sum, i) (sum->sit_j.entries[i].se)
193 #define segno_in_journal(sum, i) (sum->sit_j.entries[i].segno)
195 #define MAX_NAT_JENTRIES(sum) (NAT_JOURNAL_ENTRIES - nats_in_cursum(sum))
196 #define MAX_SIT_JENTRIES(sum) (SIT_JOURNAL_ENTRIES - sits_in_cursum(sum))
198 static inline int update_nats_in_cursum(struct f2fs_summary_block *rs, int i)
200 int before = nats_in_cursum(rs);
201 rs->n_nats = cpu_to_le16(before + i);
205 static inline int update_sits_in_cursum(struct f2fs_summary_block *rs, int i)
207 int before = sits_in_cursum(rs);
208 rs->n_sits = cpu_to_le16(before + i);
212 static inline bool __has_cursum_space(struct f2fs_summary_block *sum, int size,
215 if (type == NAT_JOURNAL)
216 return size <= MAX_NAT_JENTRIES(sum);
217 return size <= MAX_SIT_JENTRIES(sum);
223 #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS
224 #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS
225 #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION
227 #define F2FS_IOCTL_MAGIC 0xf5
228 #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
229 #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
230 #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
231 #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)
232 #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
233 #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6)
234 #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7)
236 #define F2FS_IOC_SET_ENCRYPTION_POLICY \
237 _IOR('f', 19, struct f2fs_encryption_policy)
238 #define F2FS_IOC_GET_ENCRYPTION_PWSALT \
239 _IOW('f', 20, __u8[16])
240 #define F2FS_IOC_GET_ENCRYPTION_POLICY \
241 _IOW('f', 21, struct f2fs_encryption_policy)
244 * should be same as XFS_IOC_GOINGDOWN.
245 * Flags for going down operation used by FS_IOC_GOINGDOWN
247 #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */
248 #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */
249 #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */
250 #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */
251 #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */
253 #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
255 * ioctl commands in 32 bit emulation
257 #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS
258 #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS
262 * For INODE and NODE manager
264 /* for directory operations */
270 struct f2fs_filename {
271 const struct qstr *usr_fname;
272 struct f2fs_str disk_name;
274 #ifdef CONFIG_F2FS_FS_ENCRYPTION
275 struct f2fs_str crypto_buf;
279 #define FSTR_INIT(n, l) { .name = n, .len = l }
280 #define FSTR_TO_QSTR(f) QSTR_INIT((f)->name, (f)->len)
281 #define fname_name(p) ((p)->disk_name.name)
282 #define fname_len(p) ((p)->disk_name.len)
284 struct f2fs_dentry_ptr {
287 struct f2fs_dir_entry *dentry;
288 __u8 (*filename)[F2FS_SLOT_LEN];
292 static inline void make_dentry_ptr(struct inode *inode,
293 struct f2fs_dentry_ptr *d, void *src, int type)
298 struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src;
299 d->max = NR_DENTRY_IN_BLOCK;
300 d->bitmap = &t->dentry_bitmap;
301 d->dentry = t->dentry;
302 d->filename = t->filename;
304 struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src;
305 d->max = NR_INLINE_DENTRY;
306 d->bitmap = &t->dentry_bitmap;
307 d->dentry = t->dentry;
308 d->filename = t->filename;
313 * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1
314 * as its node offset to distinguish from index node blocks.
315 * But some bits are used to mark the node block.
317 #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \
320 ALLOC_NODE, /* allocate a new node page if needed */
321 LOOKUP_NODE, /* look up a node without readahead */
323 * look up a node with readahead called
328 #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */
330 #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */
332 /* vector size for gang look-up from extent cache that consists of radix tree */
333 #define EXT_TREE_VEC_SIZE 64
335 /* for in-memory extent cache entry */
336 #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */
338 /* number of extent info in extent cache we try to shrink */
339 #define EXTENT_CACHE_SHRINK_NUMBER 128
342 unsigned int fofs; /* start offset in a file */
343 u32 blk; /* start block address of the extent */
344 unsigned int len; /* length of the extent */
348 struct rb_node rb_node; /* rb node located in rb-tree */
349 struct list_head list; /* node in global extent list of sbi */
350 struct extent_info ei; /* extent info */
354 nid_t ino; /* inode number */
355 struct rb_root root; /* root of extent info rb-tree */
356 struct extent_node *cached_en; /* recently accessed extent node */
357 struct extent_info largest; /* largested extent info */
358 rwlock_t lock; /* protect extent info rb-tree */
359 atomic_t refcount; /* reference count of rb-tree */
360 unsigned int count; /* # of extent node in rb-tree*/
364 * This structure is taken from ext4_map_blocks.
366 * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks().
368 #define F2FS_MAP_NEW (1 << BH_New)
369 #define F2FS_MAP_MAPPED (1 << BH_Mapped)
370 #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten)
371 #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\
374 struct f2fs_map_blocks {
378 unsigned int m_flags;
381 /* for flag in get_data_block */
382 #define F2FS_GET_BLOCK_READ 0
383 #define F2FS_GET_BLOCK_DIO 1
384 #define F2FS_GET_BLOCK_FIEMAP 2
385 #define F2FS_GET_BLOCK_BMAP 3
388 * i_advise uses FADVISE_XXX_BIT. We can add additional hints later.
390 #define FADVISE_COLD_BIT 0x01
391 #define FADVISE_LOST_PINO_BIT 0x02
392 #define FADVISE_ENCRYPT_BIT 0x04
393 #define FADVISE_ENC_NAME_BIT 0x08
395 #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT)
396 #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT)
397 #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT)
398 #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT)
399 #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT)
400 #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT)
401 #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT)
402 #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT)
403 #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT)
404 #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT)
405 #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT)
407 /* Encryption algorithms */
408 #define F2FS_ENCRYPTION_MODE_INVALID 0
409 #define F2FS_ENCRYPTION_MODE_AES_256_XTS 1
410 #define F2FS_ENCRYPTION_MODE_AES_256_GCM 2
411 #define F2FS_ENCRYPTION_MODE_AES_256_CBC 3
412 #define F2FS_ENCRYPTION_MODE_AES_256_CTS 4
414 #include "f2fs_crypto.h"
416 #define DEF_DIR_LEVEL 0
418 struct f2fs_inode_info {
419 struct inode vfs_inode; /* serve a vfs inode */
420 unsigned long i_flags; /* keep an inode flags for ioctl */
421 unsigned char i_advise; /* use to give file attribute hints */
422 unsigned char i_dir_level; /* use for dentry level for large dir */
423 unsigned int i_current_depth; /* use only in directory structure */
424 unsigned int i_pino; /* parent inode number */
425 umode_t i_acl_mode; /* keep file acl mode temporarily */
427 /* Use below internally in f2fs*/
428 unsigned long flags; /* use to pass per-file flags */
429 struct rw_semaphore i_sem; /* protect fi info */
430 atomic_t dirty_pages; /* # of dirty pages */
431 f2fs_hash_t chash; /* hash value of given file name */
432 unsigned int clevel; /* maximum level of given file name */
433 nid_t i_xattr_nid; /* node id that contains xattrs */
434 unsigned long long xattr_ver; /* cp version of xattr modification */
435 struct inode_entry *dirty_dir; /* the pointer of dirty dir */
437 struct list_head inmem_pages; /* inmemory pages managed by f2fs */
438 struct mutex inmem_lock; /* lock for inmemory pages */
440 struct extent_tree *extent_tree; /* cached extent_tree entry */
442 #ifdef CONFIG_F2FS_FS_ENCRYPTION
443 /* Encryption params */
444 struct f2fs_crypt_info *i_crypt_info;
448 static inline void get_extent_info(struct extent_info *ext,
449 struct f2fs_extent i_ext)
451 ext->fofs = le32_to_cpu(i_ext.fofs);
452 ext->blk = le32_to_cpu(i_ext.blk);
453 ext->len = le32_to_cpu(i_ext.len);
456 static inline void set_raw_extent(struct extent_info *ext,
457 struct f2fs_extent *i_ext)
459 i_ext->fofs = cpu_to_le32(ext->fofs);
460 i_ext->blk = cpu_to_le32(ext->blk);
461 i_ext->len = cpu_to_le32(ext->len);
464 static inline void set_extent_info(struct extent_info *ei, unsigned int fofs,
465 u32 blk, unsigned int len)
472 static inline bool __is_extent_same(struct extent_info *ei1,
473 struct extent_info *ei2)
475 return (ei1->fofs == ei2->fofs && ei1->blk == ei2->blk &&
476 ei1->len == ei2->len);
479 static inline bool __is_extent_mergeable(struct extent_info *back,
480 struct extent_info *front)
482 return (back->fofs + back->len == front->fofs &&
483 back->blk + back->len == front->blk);
486 static inline bool __is_back_mergeable(struct extent_info *cur,
487 struct extent_info *back)
489 return __is_extent_mergeable(back, cur);
492 static inline bool __is_front_mergeable(struct extent_info *cur,
493 struct extent_info *front)
495 return __is_extent_mergeable(cur, front);
498 static inline void __try_update_largest_extent(struct extent_tree *et,
499 struct extent_node *en)
501 if (en->ei.len > et->largest.len)
502 et->largest = en->ei;
505 struct f2fs_nm_info {
506 block_t nat_blkaddr; /* base disk address of NAT */
507 nid_t max_nid; /* maximum possible node ids */
508 nid_t available_nids; /* maximum available node ids */
509 nid_t next_scan_nid; /* the next nid to be scanned */
510 unsigned int ram_thresh; /* control the memory footprint */
511 unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */
513 /* NAT cache management */
514 struct radix_tree_root nat_root;/* root of the nat entry cache */
515 struct radix_tree_root nat_set_root;/* root of the nat set cache */
516 struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */
517 struct list_head nat_entries; /* cached nat entry list (clean) */
518 unsigned int nat_cnt; /* the # of cached nat entries */
519 unsigned int dirty_nat_cnt; /* total num of nat entries in set */
521 /* free node ids management */
522 struct radix_tree_root free_nid_root;/* root of the free_nid cache */
523 struct list_head free_nid_list; /* a list for free nids */
524 spinlock_t free_nid_list_lock; /* protect free nid list */
525 unsigned int fcnt; /* the number of free node id */
526 struct mutex build_lock; /* lock for build free nids */
529 char *nat_bitmap; /* NAT bitmap pointer */
530 int bitmap_size; /* bitmap size */
534 * this structure is used as one of function parameters.
535 * all the information are dedicated to a given direct node block determined
536 * by the data offset in a file.
538 struct dnode_of_data {
539 struct inode *inode; /* vfs inode pointer */
540 struct page *inode_page; /* its inode page, NULL is possible */
541 struct page *node_page; /* cached direct node page */
542 nid_t nid; /* node id of the direct node block */
543 unsigned int ofs_in_node; /* data offset in the node page */
544 bool inode_page_locked; /* inode page is locked or not */
545 block_t data_blkaddr; /* block address of the node block */
548 static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode,
549 struct page *ipage, struct page *npage, nid_t nid)
551 memset(dn, 0, sizeof(*dn));
553 dn->inode_page = ipage;
554 dn->node_page = npage;
561 * By default, there are 6 active log areas across the whole main area.
562 * When considering hot and cold data separation to reduce cleaning overhead,
563 * we split 3 for data logs and 3 for node logs as hot, warm, and cold types,
565 * In the current design, you should not change the numbers intentionally.
566 * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6
567 * logs individually according to the underlying devices. (default: 6)
568 * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for
569 * data and 8 for node logs.
571 #define NR_CURSEG_DATA_TYPE (3)
572 #define NR_CURSEG_NODE_TYPE (3)
573 #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE)
576 CURSEG_HOT_DATA = 0, /* directory entry blocks */
577 CURSEG_WARM_DATA, /* data blocks */
578 CURSEG_COLD_DATA, /* multimedia or GCed data blocks */
579 CURSEG_HOT_NODE, /* direct node blocks of directory files */
580 CURSEG_WARM_NODE, /* direct node blocks of normal files */
581 CURSEG_COLD_NODE, /* indirect node blocks */
583 CURSEG_DIRECT_IO, /* to use for the direct IO path */
587 struct completion wait;
588 struct llist_node llnode;
592 struct flush_cmd_control {
593 struct task_struct *f2fs_issue_flush; /* flush thread */
594 wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */
595 struct llist_head issue_list; /* list for command issue */
596 struct llist_node *dispatch_list; /* list for command dispatch */
599 struct f2fs_sm_info {
600 struct sit_info *sit_info; /* whole segment information */
601 struct free_segmap_info *free_info; /* free segment information */
602 struct dirty_seglist_info *dirty_info; /* dirty segment information */
603 struct curseg_info *curseg_array; /* active segment information */
605 block_t seg0_blkaddr; /* block address of 0'th segment */
606 block_t main_blkaddr; /* start block address of main area */
607 block_t ssa_blkaddr; /* start block address of SSA area */
609 unsigned int segment_count; /* total # of segments */
610 unsigned int main_segments; /* # of segments in main area */
611 unsigned int reserved_segments; /* # of reserved segments */
612 unsigned int ovp_segments; /* # of overprovision segments */
614 /* a threshold to reclaim prefree segments */
615 unsigned int rec_prefree_segments;
617 /* for small discard management */
618 struct list_head discard_list; /* 4KB discard list */
619 int nr_discards; /* # of discards in the list */
620 int max_discards; /* max. discards to be issued */
622 /* for batched trimming */
623 unsigned int trim_sections; /* # of sections to trim */
625 struct list_head sit_entry_set; /* sit entry set list */
627 unsigned int ipu_policy; /* in-place-update policy */
628 unsigned int min_ipu_util; /* in-place-update threshold */
629 unsigned int min_fsync_blocks; /* threshold for fsync */
631 /* for flush command control */
632 struct flush_cmd_control *cmd_control_info;
640 * COUNT_TYPE for monitoring
642 * f2fs monitors the number of several block types such as on-writeback,
643 * dirty dentry blocks, dirty node blocks, and dirty meta blocks.
655 * The below are the page types of bios used in submit_bio().
656 * The available types are:
657 * DATA User data pages. It operates as async mode.
658 * NODE Node pages. It operates as async mode.
659 * META FS metadata pages such as SIT, NAT, CP.
660 * NR_PAGE_TYPE The number of page types.
661 * META_FLUSH Make sure the previous pages are written
662 * with waiting the bio's completion
663 * ... Only can be used with META.
665 #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type))
672 INMEM, /* the below types are used by tracepoints only. */
678 struct f2fs_io_info {
679 struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */
680 enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
681 int rw; /* contains R/RS/W/WS with REQ_META/REQ_PRIO */
682 block_t blk_addr; /* block address to be written */
683 struct page *page; /* page to be written */
684 struct page *encrypted_page; /* encrypted page */
687 #define is_read_io(rw) (((rw) & 1) == READ)
688 struct f2fs_bio_info {
689 struct f2fs_sb_info *sbi; /* f2fs superblock */
690 struct bio *bio; /* bios to merge */
691 sector_t last_block_in_bio; /* last block number */
692 struct f2fs_io_info fio; /* store buffered io info. */
693 struct rw_semaphore io_rwsem; /* blocking op for bio */
696 /* for inner inode cache management */
697 struct inode_management {
698 struct radix_tree_root ino_root; /* ino entry array */
699 spinlock_t ino_lock; /* for ino entry lock */
700 struct list_head ino_list; /* inode list head */
701 unsigned long ino_num; /* number of entries */
704 /* For s_flag in struct f2fs_sb_info */
706 SBI_IS_DIRTY, /* dirty flag for checkpoint */
707 SBI_IS_CLOSE, /* specify unmounting */
708 SBI_NEED_FSCK, /* need fsck.f2fs to fix */
709 SBI_POR_DOING, /* recovery is doing or not */
712 struct f2fs_sb_info {
713 struct super_block *sb; /* pointer to VFS super block */
714 struct proc_dir_entry *s_proc; /* proc entry */
715 struct buffer_head *raw_super_buf; /* buffer head of raw sb */
716 struct f2fs_super_block *raw_super; /* raw super block pointer */
717 int s_flag; /* flags for sbi */
719 /* for node-related operations */
720 struct f2fs_nm_info *nm_info; /* node manager */
721 struct inode *node_inode; /* cache node blocks */
723 /* for segment-related operations */
724 struct f2fs_sm_info *sm_info; /* segment manager */
726 /* for bio operations */
727 struct f2fs_bio_info read_io; /* for read bios */
728 struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */
731 struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */
732 struct inode *meta_inode; /* cache meta blocks */
733 struct mutex cp_mutex; /* checkpoint procedure lock */
734 struct rw_semaphore cp_rwsem; /* blocking FS operations */
735 struct rw_semaphore node_write; /* locking node writes */
736 struct mutex writepages; /* mutex for writepages() */
737 wait_queue_head_t cp_wait;
738 long cp_expires, cp_interval; /* next expected periodic cp */
740 struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */
742 /* for orphan inode, use 0'th array */
743 unsigned int max_orphans; /* max orphan inodes */
745 /* for directory inode management */
746 struct list_head dir_inode_list; /* dir inode list */
747 spinlock_t dir_inode_lock; /* for dir inode list lock */
749 /* for extent tree cache */
750 struct radix_tree_root extent_tree_root;/* cache extent cache entries */
751 struct rw_semaphore extent_tree_lock; /* locking extent radix tree */
752 struct list_head extent_list; /* lru list for shrinker */
753 spinlock_t extent_lock; /* locking extent lru list */
754 int total_ext_tree; /* extent tree count */
755 atomic_t total_ext_node; /* extent info count */
757 /* basic filesystem units */
758 unsigned int log_sectors_per_block; /* log2 sectors per block */
759 unsigned int log_blocksize; /* log2 block size */
760 unsigned int blocksize; /* block size */
761 unsigned int root_ino_num; /* root inode number*/
762 unsigned int node_ino_num; /* node inode number*/
763 unsigned int meta_ino_num; /* meta inode number*/
764 unsigned int log_blocks_per_seg; /* log2 blocks per segment */
765 unsigned int blocks_per_seg; /* blocks per segment */
766 unsigned int segs_per_sec; /* segments per section */
767 unsigned int secs_per_zone; /* sections per zone */
768 unsigned int total_sections; /* total section count */
769 unsigned int total_node_count; /* total node block count */
770 unsigned int total_valid_node_count; /* valid node block count */
771 unsigned int total_valid_inode_count; /* valid inode count */
772 int active_logs; /* # of active logs */
773 int dir_level; /* directory level */
775 block_t user_block_count; /* # of user blocks */
776 block_t total_valid_block_count; /* # of valid blocks */
777 block_t alloc_valid_block_count; /* # of allocated blocks */
778 block_t discard_blks; /* discard command candidats */
779 block_t last_valid_block_count; /* for recovery */
780 u32 s_next_generation; /* for NFS support */
781 atomic_t nr_pages[NR_COUNT_TYPE]; /* # of pages, see count_type */
783 struct f2fs_mount_info mount_opt; /* mount options */
785 /* for cleaning operations */
786 struct mutex gc_mutex; /* mutex for GC */
787 struct f2fs_gc_kthread *gc_thread; /* GC thread */
788 unsigned int cur_victim_sec; /* current victim section num */
790 /* maximum # of trials to find a victim segment for SSR and GC */
791 unsigned int max_victim_search;
794 * for stat information.
795 * one is for the LFS mode, and the other is for the SSR mode.
797 #ifdef CONFIG_F2FS_STAT_FS
798 struct f2fs_stat_info *stat_info; /* FS status information */
799 unsigned int segment_count[2]; /* # of allocated segments */
800 unsigned int block_count[2]; /* # of allocated blocks */
801 atomic_t inplace_count; /* # of inplace update */
802 atomic64_t total_hit_ext; /* # of lookup extent cache */
803 atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */
804 atomic64_t read_hit_largest; /* # of hit largest extent node */
805 atomic64_t read_hit_cached; /* # of hit cached extent node */
806 atomic_t inline_xattr; /* # of inline_xattr inodes */
807 atomic_t inline_inode; /* # of inline_data inodes */
808 atomic_t inline_dir; /* # of inline_dentry inodes */
809 int bg_gc; /* background gc calls */
810 unsigned int n_dirty_dirs; /* # of dir inodes */
812 unsigned int last_victim[2]; /* last victim segment # */
813 spinlock_t stat_lock; /* lock for stat operations */
815 /* For sysfs suppport */
816 struct kobject s_kobj;
817 struct completion s_kobj_unregister;
819 /* For shrinker support */
820 struct list_head s_list;
821 struct mutex umount_mutex;
822 unsigned int shrinker_run_no;
828 static inline struct f2fs_inode_info *F2FS_I(struct inode *inode)
830 return container_of(inode, struct f2fs_inode_info, vfs_inode);
833 static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb)
835 return sb->s_fs_info;
838 static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode)
840 return F2FS_SB(inode->i_sb);
843 static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping)
845 return F2FS_I_SB(mapping->host);
848 static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page)
850 return F2FS_M_SB(page->mapping);
853 static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi)
855 return (struct f2fs_super_block *)(sbi->raw_super);
858 static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi)
860 return (struct f2fs_checkpoint *)(sbi->ckpt);
863 static inline struct f2fs_node *F2FS_NODE(struct page *page)
865 return (struct f2fs_node *)page_address(page);
868 static inline struct f2fs_inode *F2FS_INODE(struct page *page)
870 return &((struct f2fs_node *)page_address(page))->i;
873 static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi)
875 return (struct f2fs_nm_info *)(sbi->nm_info);
878 static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi)
880 return (struct f2fs_sm_info *)(sbi->sm_info);
883 static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi)
885 return (struct sit_info *)(SM_I(sbi)->sit_info);
888 static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi)
890 return (struct free_segmap_info *)(SM_I(sbi)->free_info);
893 static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi)
895 return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info);
898 static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi)
900 return sbi->meta_inode->i_mapping;
903 static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
905 return sbi->node_inode->i_mapping;
908 static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
910 return sbi->s_flag & (0x01 << type);
913 static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
915 sbi->s_flag |= (0x01 << type);
918 static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
920 sbi->s_flag &= ~(0x01 << type);
923 static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
925 return le64_to_cpu(cp->checkpoint_ver);
928 static inline bool is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
930 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
931 return ckpt_flags & f;
934 static inline void set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
936 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
938 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
941 static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
943 unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags);
945 cp->ckpt_flags = cpu_to_le32(ckpt_flags);
948 static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
950 down_read(&sbi->cp_rwsem);
953 static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
955 up_read(&sbi->cp_rwsem);
958 static inline void f2fs_lock_all(struct f2fs_sb_info *sbi)
960 down_write(&sbi->cp_rwsem);
963 static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
965 up_write(&sbi->cp_rwsem);
968 static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
970 int reason = CP_SYNC;
972 if (test_opt(sbi, FASTBOOT))
973 reason = CP_FASTBOOT;
974 if (is_sbi_flag_set(sbi, SBI_IS_CLOSE))
979 static inline bool __remain_node_summaries(int reason)
981 return (reason == CP_UMOUNT || reason == CP_FASTBOOT);
984 static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
986 return (is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG) ||
987 is_set_ckpt_flags(F2FS_CKPT(sbi), CP_FASTBOOT_FLAG));
991 * Check whether the given nid is within node id range.
993 static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
995 if (unlikely(nid < F2FS_ROOT_INO(sbi)))
997 if (unlikely(nid >= NM_I(sbi)->max_nid))
1002 #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
1005 * Check whether the inode has blocks or not
1007 static inline int F2FS_HAS_BLOCKS(struct inode *inode)
1009 if (F2FS_I(inode)->i_xattr_nid)
1010 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1;
1012 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
1015 static inline bool f2fs_has_xattr_block(unsigned int ofs)
1017 return ofs == XATTR_NODE_OFFSET;
1020 static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
1021 struct inode *inode, blkcnt_t count)
1023 block_t valid_block_count;
1025 spin_lock(&sbi->stat_lock);
1027 sbi->total_valid_block_count + (block_t)count;
1028 if (unlikely(valid_block_count > sbi->user_block_count)) {
1029 spin_unlock(&sbi->stat_lock);
1032 inode->i_blocks += count;
1033 sbi->total_valid_block_count = valid_block_count;
1034 sbi->alloc_valid_block_count += (block_t)count;
1035 spin_unlock(&sbi->stat_lock);
1039 static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
1040 struct inode *inode,
1043 spin_lock(&sbi->stat_lock);
1044 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
1045 f2fs_bug_on(sbi, inode->i_blocks < count);
1046 inode->i_blocks -= count;
1047 sbi->total_valid_block_count -= (block_t)count;
1048 spin_unlock(&sbi->stat_lock);
1051 static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
1053 atomic_inc(&sbi->nr_pages[count_type]);
1054 set_sbi_flag(sbi, SBI_IS_DIRTY);
1057 static inline void inode_inc_dirty_pages(struct inode *inode)
1059 atomic_inc(&F2FS_I(inode)->dirty_pages);
1060 if (S_ISDIR(inode->i_mode))
1061 inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
1064 static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type)
1066 atomic_dec(&sbi->nr_pages[count_type]);
1069 static inline void inode_dec_dirty_pages(struct inode *inode)
1071 if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) &&
1072 !S_ISLNK(inode->i_mode))
1075 atomic_dec(&F2FS_I(inode)->dirty_pages);
1077 if (S_ISDIR(inode->i_mode))
1078 dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_DENTS);
1081 static inline int get_pages(struct f2fs_sb_info *sbi, int count_type)
1083 return atomic_read(&sbi->nr_pages[count_type]);
1086 static inline int get_dirty_pages(struct inode *inode)
1088 return atomic_read(&F2FS_I(inode)->dirty_pages);
1091 static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type)
1093 unsigned int pages_per_sec = sbi->segs_per_sec *
1094 (1 << sbi->log_blocks_per_seg);
1095 return ((get_pages(sbi, block_type) + pages_per_sec - 1)
1096 >> sbi->log_blocks_per_seg) / sbi->segs_per_sec;
1099 static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi)
1101 return sbi->total_valid_block_count;
1104 static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag)
1106 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1108 /* return NAT or SIT bitmap */
1109 if (flag == NAT_BITMAP)
1110 return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize);
1111 else if (flag == SIT_BITMAP)
1112 return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize);
1117 static inline block_t __cp_payload(struct f2fs_sb_info *sbi)
1119 return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload);
1122 static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag)
1124 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1127 if (__cp_payload(sbi) > 0) {
1128 if (flag == NAT_BITMAP)
1129 return &ckpt->sit_nat_version_bitmap;
1131 return (unsigned char *)ckpt + F2FS_BLKSIZE;
1133 offset = (flag == NAT_BITMAP) ?
1134 le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0;
1135 return &ckpt->sit_nat_version_bitmap + offset;
1139 static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi)
1142 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1143 unsigned long long ckpt_version = cur_cp_version(ckpt);
1145 start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr);
1148 * odd numbered checkpoint should at cp segment 0
1149 * and even segment must be at cp segment 1
1151 if (!(ckpt_version & 1))
1152 start_addr += sbi->blocks_per_seg;
1157 static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
1159 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
1162 static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
1163 struct inode *inode)
1165 block_t valid_block_count;
1166 unsigned int valid_node_count;
1168 spin_lock(&sbi->stat_lock);
1170 valid_block_count = sbi->total_valid_block_count + 1;
1171 if (unlikely(valid_block_count > sbi->user_block_count)) {
1172 spin_unlock(&sbi->stat_lock);
1176 valid_node_count = sbi->total_valid_node_count + 1;
1177 if (unlikely(valid_node_count > sbi->total_node_count)) {
1178 spin_unlock(&sbi->stat_lock);
1185 sbi->alloc_valid_block_count++;
1186 sbi->total_valid_node_count++;
1187 sbi->total_valid_block_count++;
1188 spin_unlock(&sbi->stat_lock);
1193 static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
1194 struct inode *inode)
1196 spin_lock(&sbi->stat_lock);
1198 f2fs_bug_on(sbi, !sbi->total_valid_block_count);
1199 f2fs_bug_on(sbi, !sbi->total_valid_node_count);
1200 f2fs_bug_on(sbi, !inode->i_blocks);
1203 sbi->total_valid_node_count--;
1204 sbi->total_valid_block_count--;
1206 spin_unlock(&sbi->stat_lock);
1209 static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
1211 return sbi->total_valid_node_count;
1214 static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi)
1216 spin_lock(&sbi->stat_lock);
1217 f2fs_bug_on(sbi, sbi->total_valid_inode_count == sbi->total_node_count);
1218 sbi->total_valid_inode_count++;
1219 spin_unlock(&sbi->stat_lock);
1222 static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi)
1224 spin_lock(&sbi->stat_lock);
1225 f2fs_bug_on(sbi, !sbi->total_valid_inode_count);
1226 sbi->total_valid_inode_count--;
1227 spin_unlock(&sbi->stat_lock);
1230 static inline unsigned int valid_inode_count(struct f2fs_sb_info *sbi)
1232 return sbi->total_valid_inode_count;
1235 static inline struct page *f2fs_grab_cache_page(struct address_space *mapping,
1236 pgoff_t index, bool for_write)
1239 return grab_cache_page(mapping, index);
1240 return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS);
1243 static inline void f2fs_copy_page(struct page *src, struct page *dst)
1245 char *src_kaddr = kmap(src);
1246 char *dst_kaddr = kmap(dst);
1248 memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
1253 static inline void f2fs_put_page(struct page *page, int unlock)
1259 f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page));
1262 page_cache_release(page);
1265 static inline void f2fs_put_dnode(struct dnode_of_data *dn)
1268 f2fs_put_page(dn->node_page, 1);
1269 if (dn->inode_page && dn->node_page != dn->inode_page)
1270 f2fs_put_page(dn->inode_page, 0);
1271 dn->node_page = NULL;
1272 dn->inode_page = NULL;
1275 static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name,
1278 return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL);
1281 static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
1286 entry = kmem_cache_alloc(cachep, flags);
1288 entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL);
1292 static inline struct bio *f2fs_bio_alloc(int npages)
1296 /* No failure on bio allocation */
1297 bio = bio_alloc(GFP_NOIO, npages);
1299 bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
1303 static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
1304 unsigned long index, void *item)
1306 while (radix_tree_insert(root, index, item))
1310 #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino)
1312 static inline bool IS_INODE(struct page *page)
1314 struct f2fs_node *p = F2FS_NODE(page);
1315 return RAW_IS_INODE(p);
1318 static inline __le32 *blkaddr_in_node(struct f2fs_node *node)
1320 return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr;
1323 static inline block_t datablock_addr(struct page *node_page,
1324 unsigned int offset)
1326 struct f2fs_node *raw_node;
1328 raw_node = F2FS_NODE(node_page);
1329 addr_array = blkaddr_in_node(raw_node);
1330 return le32_to_cpu(addr_array[offset]);
1333 static inline int f2fs_test_bit(unsigned int nr, char *addr)
1338 mask = 1 << (7 - (nr & 0x07));
1339 return mask & *addr;
1342 static inline void f2fs_set_bit(unsigned int nr, char *addr)
1347 mask = 1 << (7 - (nr & 0x07));
1351 static inline void f2fs_clear_bit(unsigned int nr, char *addr)
1356 mask = 1 << (7 - (nr & 0x07));
1360 static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr)
1366 mask = 1 << (7 - (nr & 0x07));
1372 static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr)
1378 mask = 1 << (7 - (nr & 0x07));
1384 static inline void f2fs_change_bit(unsigned int nr, char *addr)
1389 mask = 1 << (7 - (nr & 0x07));
1393 /* used for f2fs_inode_info->flags */
1395 FI_NEW_INODE, /* indicate newly allocated inode */
1396 FI_DIRTY_INODE, /* indicate inode is dirty or not */
1397 FI_DIRTY_DIR, /* indicate directory has dirty pages */
1398 FI_INC_LINK, /* need to increment i_nlink */
1399 FI_ACL_MODE, /* indicate acl mode */
1400 FI_NO_ALLOC, /* should not allocate any blocks */
1401 FI_FREE_NID, /* free allocated nide */
1402 FI_UPDATE_DIR, /* should update inode block for consistency */
1403 FI_DELAY_IPUT, /* used for the recovery */
1404 FI_NO_EXTENT, /* not to use the extent cache */
1405 FI_INLINE_XATTR, /* used for inline xattr */
1406 FI_INLINE_DATA, /* used for inline data*/
1407 FI_INLINE_DENTRY, /* used for inline dentry */
1408 FI_APPEND_WRITE, /* inode has appended data */
1409 FI_UPDATE_WRITE, /* inode has in-place-update data */
1410 FI_NEED_IPU, /* used for ipu per file */
1411 FI_ATOMIC_FILE, /* indicate atomic file */
1412 FI_VOLATILE_FILE, /* indicate volatile file */
1413 FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */
1414 FI_DROP_CACHE, /* drop dirty page cache */
1415 FI_DATA_EXIST, /* indicate data exists */
1416 FI_INLINE_DOTS, /* indicate inline dot dentries */
1419 static inline void set_inode_flag(struct f2fs_inode_info *fi, int flag)
1421 if (!test_bit(flag, &fi->flags))
1422 set_bit(flag, &fi->flags);
1425 static inline int is_inode_flag_set(struct f2fs_inode_info *fi, int flag)
1427 return test_bit(flag, &fi->flags);
1430 static inline void clear_inode_flag(struct f2fs_inode_info *fi, int flag)
1432 if (test_bit(flag, &fi->flags))
1433 clear_bit(flag, &fi->flags);
1436 static inline void set_acl_inode(struct f2fs_inode_info *fi, umode_t mode)
1438 fi->i_acl_mode = mode;
1439 set_inode_flag(fi, FI_ACL_MODE);
1442 static inline void get_inline_info(struct f2fs_inode_info *fi,
1443 struct f2fs_inode *ri)
1445 if (ri->i_inline & F2FS_INLINE_XATTR)
1446 set_inode_flag(fi, FI_INLINE_XATTR);
1447 if (ri->i_inline & F2FS_INLINE_DATA)
1448 set_inode_flag(fi, FI_INLINE_DATA);
1449 if (ri->i_inline & F2FS_INLINE_DENTRY)
1450 set_inode_flag(fi, FI_INLINE_DENTRY);
1451 if (ri->i_inline & F2FS_DATA_EXIST)
1452 set_inode_flag(fi, FI_DATA_EXIST);
1453 if (ri->i_inline & F2FS_INLINE_DOTS)
1454 set_inode_flag(fi, FI_INLINE_DOTS);
1457 static inline void set_raw_inline(struct f2fs_inode_info *fi,
1458 struct f2fs_inode *ri)
1462 if (is_inode_flag_set(fi, FI_INLINE_XATTR))
1463 ri->i_inline |= F2FS_INLINE_XATTR;
1464 if (is_inode_flag_set(fi, FI_INLINE_DATA))
1465 ri->i_inline |= F2FS_INLINE_DATA;
1466 if (is_inode_flag_set(fi, FI_INLINE_DENTRY))
1467 ri->i_inline |= F2FS_INLINE_DENTRY;
1468 if (is_inode_flag_set(fi, FI_DATA_EXIST))
1469 ri->i_inline |= F2FS_DATA_EXIST;
1470 if (is_inode_flag_set(fi, FI_INLINE_DOTS))
1471 ri->i_inline |= F2FS_INLINE_DOTS;
1474 static inline int f2fs_has_inline_xattr(struct inode *inode)
1476 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_XATTR);
1479 static inline unsigned int addrs_per_inode(struct f2fs_inode_info *fi)
1481 if (f2fs_has_inline_xattr(&fi->vfs_inode))
1482 return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS;
1483 return DEF_ADDRS_PER_INODE;
1486 static inline void *inline_xattr_addr(struct page *page)
1488 struct f2fs_inode *ri = F2FS_INODE(page);
1489 return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE -
1490 F2FS_INLINE_XATTR_ADDRS]);
1493 static inline int inline_xattr_size(struct inode *inode)
1495 if (f2fs_has_inline_xattr(inode))
1496 return F2FS_INLINE_XATTR_ADDRS << 2;
1501 static inline int f2fs_has_inline_data(struct inode *inode)
1503 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DATA);
1506 static inline void f2fs_clear_inline_inode(struct inode *inode)
1508 clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA);
1509 clear_inode_flag(F2FS_I(inode), FI_DATA_EXIST);
1512 static inline int f2fs_exist_data(struct inode *inode)
1514 return is_inode_flag_set(F2FS_I(inode), FI_DATA_EXIST);
1517 static inline int f2fs_has_inline_dots(struct inode *inode)
1519 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DOTS);
1522 static inline bool f2fs_is_atomic_file(struct inode *inode)
1524 return is_inode_flag_set(F2FS_I(inode), FI_ATOMIC_FILE);
1527 static inline bool f2fs_is_volatile_file(struct inode *inode)
1529 return is_inode_flag_set(F2FS_I(inode), FI_VOLATILE_FILE);
1532 static inline bool f2fs_is_first_block_written(struct inode *inode)
1534 return is_inode_flag_set(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN);
1537 static inline bool f2fs_is_drop_cache(struct inode *inode)
1539 return is_inode_flag_set(F2FS_I(inode), FI_DROP_CACHE);
1542 static inline void *inline_data_addr(struct page *page)
1544 struct f2fs_inode *ri = F2FS_INODE(page);
1545 return (void *)&(ri->i_addr[1]);
1548 static inline int f2fs_has_inline_dentry(struct inode *inode)
1550 return is_inode_flag_set(F2FS_I(inode), FI_INLINE_DENTRY);
1553 static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page)
1555 if (!f2fs_has_inline_dentry(dir))
1559 static inline int is_file(struct inode *inode, int type)
1561 return F2FS_I(inode)->i_advise & type;
1564 static inline void set_file(struct inode *inode, int type)
1566 F2FS_I(inode)->i_advise |= type;
1569 static inline void clear_file(struct inode *inode, int type)
1571 F2FS_I(inode)->i_advise &= ~type;
1574 static inline int f2fs_readonly(struct super_block *sb)
1576 return sb->s_flags & MS_RDONLY;
1579 static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi)
1581 return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1584 static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi)
1586 set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG);
1587 sbi->sb->s_flags |= MS_RDONLY;
1590 static inline bool is_dot_dotdot(const struct qstr *str)
1592 if (str->len == 1 && str->name[0] == '.')
1595 if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.')
1601 static inline bool f2fs_may_extent_tree(struct inode *inode)
1603 mode_t mode = inode->i_mode;
1605 if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) ||
1606 is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT))
1609 return S_ISREG(mode);
1612 static inline void *f2fs_kvmalloc(size_t size, gfp_t flags)
1616 ret = kmalloc(size, flags | __GFP_NOWARN);
1618 ret = __vmalloc(size, flags, PAGE_KERNEL);
1622 static inline void *f2fs_kvzalloc(size_t size, gfp_t flags)
1626 ret = kzalloc(size, flags | __GFP_NOWARN);
1628 ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL);
1632 #define get_inode_mode(i) \
1633 ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
1634 (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
1636 /* get offset of first page in next direct node */
1637 #define PGOFS_OF_NEXT_DNODE(pgofs, fi) \
1638 ((pgofs < ADDRS_PER_INODE(fi)) ? ADDRS_PER_INODE(fi) : \
1639 (pgofs - ADDRS_PER_INODE(fi) + ADDRS_PER_BLOCK) / \
1640 ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(fi))
1645 int f2fs_sync_file(struct file *, loff_t, loff_t, int);
1646 void truncate_data_blocks(struct dnode_of_data *);
1647 int truncate_blocks(struct inode *, u64, bool);
1648 int f2fs_truncate(struct inode *, bool);
1649 int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
1650 int f2fs_setattr(struct dentry *, struct iattr *);
1651 int truncate_hole(struct inode *, pgoff_t, pgoff_t);
1652 int truncate_data_blocks_range(struct dnode_of_data *, int);
1653 long f2fs_ioctl(struct file *, unsigned int, unsigned long);
1654 long f2fs_compat_ioctl(struct file *, unsigned int, unsigned long);
1659 void f2fs_set_inode_flags(struct inode *);
1660 struct inode *f2fs_iget(struct super_block *, unsigned long);
1661 int try_to_free_nats(struct f2fs_sb_info *, int);
1662 void update_inode(struct inode *, struct page *);
1663 void update_inode_page(struct inode *);
1664 int f2fs_write_inode(struct inode *, struct writeback_control *);
1665 void f2fs_evict_inode(struct inode *);
1666 void handle_failed_inode(struct inode *);
1671 struct dentry *f2fs_get_parent(struct dentry *child);
1676 extern unsigned char f2fs_filetype_table[F2FS_FT_MAX];
1677 void set_de_type(struct f2fs_dir_entry *, umode_t);
1679 struct f2fs_dir_entry *find_target_dentry(struct f2fs_filename *,
1680 f2fs_hash_t, int *, struct f2fs_dentry_ptr *);
1681 bool f2fs_fill_dentries(struct dir_context *, struct f2fs_dentry_ptr *,
1682 unsigned int, struct f2fs_str *);
1683 void do_make_empty_dir(struct inode *, struct inode *,
1684 struct f2fs_dentry_ptr *);
1685 struct page *init_inode_metadata(struct inode *, struct inode *,
1686 const struct qstr *, struct page *);
1687 void update_parent_metadata(struct inode *, struct inode *, unsigned int);
1688 int room_for_filename(const void *, int, int);
1689 void f2fs_drop_nlink(struct inode *, struct inode *, struct page *);
1690 struct f2fs_dir_entry *f2fs_find_entry(struct inode *, struct qstr *,
1692 struct f2fs_dir_entry *f2fs_parent_dir(struct inode *, struct page **);
1693 ino_t f2fs_inode_by_name(struct inode *, struct qstr *);
1694 void f2fs_set_link(struct inode *, struct f2fs_dir_entry *,
1695 struct page *, struct inode *);
1696 int update_dent_inode(struct inode *, struct inode *, const struct qstr *);
1697 void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *,
1698 const struct qstr *, f2fs_hash_t , unsigned int);
1699 int __f2fs_add_link(struct inode *, const struct qstr *, struct inode *, nid_t,
1701 void f2fs_delete_entry(struct f2fs_dir_entry *, struct page *, struct inode *,
1703 int f2fs_do_tmpfile(struct inode *, struct inode *);
1704 bool f2fs_empty_dir(struct inode *);
1706 static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
1708 return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name,
1709 inode, inode->i_ino, inode->i_mode);
1715 int f2fs_commit_super(struct f2fs_sb_info *, bool);
1716 int f2fs_sync_fs(struct super_block *, int);
1717 extern __printf(3, 4)
1718 void f2fs_msg(struct super_block *, const char *, const char *, ...);
1723 f2fs_hash_t f2fs_dentry_hash(const struct qstr *);
1728 struct dnode_of_data;
1731 bool available_free_memory(struct f2fs_sb_info *, int);
1732 int need_dentry_mark(struct f2fs_sb_info *, nid_t);
1733 bool is_checkpointed_node(struct f2fs_sb_info *, nid_t);
1734 bool need_inode_block_update(struct f2fs_sb_info *, nid_t);
1735 void get_node_info(struct f2fs_sb_info *, nid_t, struct node_info *);
1736 int get_dnode_of_data(struct dnode_of_data *, pgoff_t, int);
1737 int truncate_inode_blocks(struct inode *, pgoff_t);
1738 int truncate_xattr_node(struct inode *, struct page *);
1739 int wait_on_node_pages_writeback(struct f2fs_sb_info *, nid_t);
1740 int remove_inode_page(struct inode *);
1741 struct page *new_inode_page(struct inode *);
1742 struct page *new_node_page(struct dnode_of_data *, unsigned int, struct page *);
1743 void ra_node_page(struct f2fs_sb_info *, nid_t);
1744 struct page *get_node_page(struct f2fs_sb_info *, pgoff_t);
1745 struct page *get_node_page_ra(struct page *, int);
1746 void sync_inode_page(struct dnode_of_data *);
1747 int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *);
1748 bool alloc_nid(struct f2fs_sb_info *, nid_t *);
1749 void alloc_nid_done(struct f2fs_sb_info *, nid_t);
1750 void alloc_nid_failed(struct f2fs_sb_info *, nid_t);
1751 int try_to_free_nids(struct f2fs_sb_info *, int);
1752 void recover_inline_xattr(struct inode *, struct page *);
1753 void recover_xattr_data(struct inode *, struct page *, block_t);
1754 int recover_inode_page(struct f2fs_sb_info *, struct page *);
1755 int restore_node_summary(struct f2fs_sb_info *, unsigned int,
1756 struct f2fs_summary_block *);
1757 void flush_nat_entries(struct f2fs_sb_info *);
1758 int build_node_manager(struct f2fs_sb_info *);
1759 void destroy_node_manager(struct f2fs_sb_info *);
1760 int __init create_node_manager_caches(void);
1761 void destroy_node_manager_caches(void);
1766 void register_inmem_page(struct inode *, struct page *);
1767 int commit_inmem_pages(struct inode *, bool);
1768 void f2fs_balance_fs(struct f2fs_sb_info *);
1769 void f2fs_balance_fs_bg(struct f2fs_sb_info *);
1770 int f2fs_issue_flush(struct f2fs_sb_info *);
1771 int create_flush_cmd_control(struct f2fs_sb_info *);
1772 void destroy_flush_cmd_control(struct f2fs_sb_info *);
1773 void invalidate_blocks(struct f2fs_sb_info *, block_t);
1774 bool is_checkpointed_data(struct f2fs_sb_info *, block_t);
1775 void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
1776 void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *);
1777 void release_discard_addrs(struct f2fs_sb_info *);
1778 bool discard_next_dnode(struct f2fs_sb_info *, block_t);
1779 int npages_for_summary_flush(struct f2fs_sb_info *, bool);
1780 void allocate_new_segments(struct f2fs_sb_info *);
1781 int f2fs_trim_fs(struct f2fs_sb_info *, struct fstrim_range *);
1782 struct page *get_sum_page(struct f2fs_sb_info *, unsigned int);
1783 void update_meta_page(struct f2fs_sb_info *, void *, block_t);
1784 void write_meta_page(struct f2fs_sb_info *, struct page *);
1785 void write_node_page(unsigned int, struct f2fs_io_info *);
1786 void write_data_page(struct dnode_of_data *, struct f2fs_io_info *);
1787 void rewrite_data_page(struct f2fs_io_info *);
1788 void f2fs_replace_block(struct f2fs_sb_info *, struct dnode_of_data *,
1789 block_t, block_t, unsigned char, bool);
1790 void allocate_data_block(struct f2fs_sb_info *, struct page *,
1791 block_t, block_t *, struct f2fs_summary *, int);
1792 void f2fs_wait_on_page_writeback(struct page *, enum page_type);
1793 void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *, block_t);
1794 void write_data_summaries(struct f2fs_sb_info *, block_t);
1795 void write_node_summaries(struct f2fs_sb_info *, block_t);
1796 int lookup_journal_in_cursum(struct f2fs_summary_block *,
1797 int, unsigned int, int);
1798 void flush_sit_entries(struct f2fs_sb_info *, struct cp_control *);
1799 int build_segment_manager(struct f2fs_sb_info *);
1800 void destroy_segment_manager(struct f2fs_sb_info *);
1801 int __init create_segment_manager_caches(void);
1802 void destroy_segment_manager_caches(void);
1807 struct page *grab_meta_page(struct f2fs_sb_info *, pgoff_t);
1808 struct page *get_meta_page(struct f2fs_sb_info *, pgoff_t);
1809 struct page *get_tmp_page(struct f2fs_sb_info *, pgoff_t);
1810 bool is_valid_blkaddr(struct f2fs_sb_info *, block_t, int);
1811 int ra_meta_pages(struct f2fs_sb_info *, block_t, int, int, bool);
1812 void ra_meta_pages_cond(struct f2fs_sb_info *, pgoff_t);
1813 long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long);
1814 void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
1815 void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type);
1816 void release_dirty_inode(struct f2fs_sb_info *);
1817 bool exist_written_data(struct f2fs_sb_info *, nid_t, int);
1818 int acquire_orphan_inode(struct f2fs_sb_info *);
1819 void release_orphan_inode(struct f2fs_sb_info *);
1820 void add_orphan_inode(struct f2fs_sb_info *, nid_t);
1821 void remove_orphan_inode(struct f2fs_sb_info *, nid_t);
1822 int recover_orphan_inodes(struct f2fs_sb_info *);
1823 int get_valid_checkpoint(struct f2fs_sb_info *);
1824 void update_dirty_page(struct inode *, struct page *);
1825 void add_dirty_dir_inode(struct inode *);
1826 void remove_dirty_dir_inode(struct inode *);
1827 void sync_dirty_dir_inodes(struct f2fs_sb_info *);
1828 void write_checkpoint(struct f2fs_sb_info *, struct cp_control *);
1829 void init_ino_entry_info(struct f2fs_sb_info *);
1830 int __init create_checkpoint_caches(void);
1831 void destroy_checkpoint_caches(void);
1836 void f2fs_submit_merged_bio(struct f2fs_sb_info *, enum page_type, int);
1837 int f2fs_submit_page_bio(struct f2fs_io_info *);
1838 void f2fs_submit_page_mbio(struct f2fs_io_info *);
1839 void set_data_blkaddr(struct dnode_of_data *);
1840 int reserve_new_block(struct dnode_of_data *);
1841 int f2fs_get_block(struct dnode_of_data *, pgoff_t);
1842 int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
1843 struct page *get_read_data_page(struct inode *, pgoff_t, int, bool);
1844 struct page *find_data_page(struct inode *, pgoff_t);
1845 struct page *get_lock_data_page(struct inode *, pgoff_t, bool);
1846 struct page *get_new_data_page(struct inode *, struct page *, pgoff_t, bool);
1847 int do_write_data_page(struct f2fs_io_info *);
1848 int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *, u64, u64);
1849 void f2fs_invalidate_page(struct page *, unsigned int, unsigned int);
1850 int f2fs_release_page(struct page *, gfp_t);
1855 int start_gc_thread(struct f2fs_sb_info *);
1856 void stop_gc_thread(struct f2fs_sb_info *);
1857 block_t start_bidx_of_node(unsigned int, struct f2fs_inode_info *);
1858 int f2fs_gc(struct f2fs_sb_info *, bool);
1859 void build_gc_manager(struct f2fs_sb_info *);
1864 int recover_fsync_data(struct f2fs_sb_info *);
1865 bool space_for_roll_forward(struct f2fs_sb_info *);
1870 #ifdef CONFIG_F2FS_STAT_FS
1871 struct f2fs_stat_info {
1872 struct list_head stat_list;
1873 struct f2fs_sb_info *sbi;
1874 int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs;
1875 int main_area_segs, main_area_sections, main_area_zones;
1876 unsigned long long hit_largest, hit_cached, hit_rbtree;
1877 unsigned long long hit_total, total_ext;
1878 int ext_tree, ext_node;
1879 int ndirty_node, ndirty_dent, ndirty_dirs, ndirty_meta;
1880 int nats, dirty_nats, sits, dirty_sits, fnids;
1881 int total_count, utilization;
1882 int bg_gc, inmem_pages, wb_pages;
1883 int inline_xattr, inline_inode, inline_dir;
1884 unsigned int valid_count, valid_node_count, valid_inode_count;
1885 unsigned int bimodal, avg_vblocks;
1886 int util_free, util_valid, util_invalid;
1887 int rsvd_segs, overp_segs;
1888 int dirty_count, node_pages, meta_pages;
1889 int prefree_count, call_count, cp_count;
1890 int tot_segs, node_segs, data_segs, free_segs, free_secs;
1891 int bg_node_segs, bg_data_segs;
1892 int tot_blks, data_blks, node_blks;
1893 int bg_data_blks, bg_node_blks;
1894 int curseg[NR_CURSEG_TYPE];
1895 int cursec[NR_CURSEG_TYPE];
1896 int curzone[NR_CURSEG_TYPE];
1898 unsigned int segment_count[2];
1899 unsigned int block_count[2];
1900 unsigned int inplace_count;
1901 unsigned long long base_mem, cache_mem, page_mem;
1904 static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi)
1906 return (struct f2fs_stat_info *)sbi->stat_info;
1909 #define stat_inc_cp_count(si) ((si)->cp_count++)
1910 #define stat_inc_call_count(si) ((si)->call_count++)
1911 #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++)
1912 #define stat_inc_dirty_dir(sbi) ((sbi)->n_dirty_dirs++)
1913 #define stat_dec_dirty_dir(sbi) ((sbi)->n_dirty_dirs--)
1914 #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext))
1915 #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree))
1916 #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest))
1917 #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached))
1918 #define stat_inc_inline_xattr(inode) \
1920 if (f2fs_has_inline_xattr(inode)) \
1921 (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \
1923 #define stat_dec_inline_xattr(inode) \
1925 if (f2fs_has_inline_xattr(inode)) \
1926 (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \
1928 #define stat_inc_inline_inode(inode) \
1930 if (f2fs_has_inline_data(inode)) \
1931 (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \
1933 #define stat_dec_inline_inode(inode) \
1935 if (f2fs_has_inline_data(inode)) \
1936 (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \
1938 #define stat_inc_inline_dir(inode) \
1940 if (f2fs_has_inline_dentry(inode)) \
1941 (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \
1943 #define stat_dec_inline_dir(inode) \
1945 if (f2fs_has_inline_dentry(inode)) \
1946 (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \
1948 #define stat_inc_seg_type(sbi, curseg) \
1949 ((sbi)->segment_count[(curseg)->alloc_type]++)
1950 #define stat_inc_block_count(sbi, curseg) \
1951 ((sbi)->block_count[(curseg)->alloc_type]++)
1952 #define stat_inc_inplace_blocks(sbi) \
1953 (atomic_inc(&(sbi)->inplace_count))
1954 #define stat_inc_seg_count(sbi, type, gc_type) \
1956 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
1958 if (type == SUM_TYPE_DATA) { \
1960 si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \
1963 si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \
1967 #define stat_inc_tot_blk_count(si, blks) \
1968 (si->tot_blks += (blks))
1970 #define stat_inc_data_blk_count(sbi, blks, gc_type) \
1972 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
1973 stat_inc_tot_blk_count(si, blks); \
1974 si->data_blks += (blks); \
1975 si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \
1978 #define stat_inc_node_blk_count(sbi, blks, gc_type) \
1980 struct f2fs_stat_info *si = F2FS_STAT(sbi); \
1981 stat_inc_tot_blk_count(si, blks); \
1982 si->node_blks += (blks); \
1983 si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \
1986 int f2fs_build_stats(struct f2fs_sb_info *);
1987 void f2fs_destroy_stats(struct f2fs_sb_info *);
1988 void __init f2fs_create_root_stats(void);
1989 void f2fs_destroy_root_stats(void);
1991 #define stat_inc_cp_count(si)
1992 #define stat_inc_call_count(si)
1993 #define stat_inc_bggc_count(si)
1994 #define stat_inc_dirty_dir(sbi)
1995 #define stat_dec_dirty_dir(sbi)
1996 #define stat_inc_total_hit(sb)
1997 #define stat_inc_rbtree_node_hit(sb)
1998 #define stat_inc_largest_node_hit(sbi)
1999 #define stat_inc_cached_node_hit(sbi)
2000 #define stat_inc_inline_xattr(inode)
2001 #define stat_dec_inline_xattr(inode)
2002 #define stat_inc_inline_inode(inode)
2003 #define stat_dec_inline_inode(inode)
2004 #define stat_inc_inline_dir(inode)
2005 #define stat_dec_inline_dir(inode)
2006 #define stat_inc_seg_type(sbi, curseg)
2007 #define stat_inc_block_count(sbi, curseg)
2008 #define stat_inc_inplace_blocks(sbi)
2009 #define stat_inc_seg_count(sbi, type, gc_type)
2010 #define stat_inc_tot_blk_count(si, blks)
2011 #define stat_inc_data_blk_count(sbi, blks, gc_type)
2012 #define stat_inc_node_blk_count(sbi, blks, gc_type)
2014 static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; }
2015 static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { }
2016 static inline void __init f2fs_create_root_stats(void) { }
2017 static inline void f2fs_destroy_root_stats(void) { }
2020 extern const struct file_operations f2fs_dir_operations;
2021 extern const struct file_operations f2fs_file_operations;
2022 extern const struct inode_operations f2fs_file_inode_operations;
2023 extern const struct address_space_operations f2fs_dblock_aops;
2024 extern const struct address_space_operations f2fs_node_aops;
2025 extern const struct address_space_operations f2fs_meta_aops;
2026 extern const struct inode_operations f2fs_dir_inode_operations;
2027 extern const struct inode_operations f2fs_symlink_inode_operations;
2028 extern const struct inode_operations f2fs_encrypted_symlink_inode_operations;
2029 extern const struct inode_operations f2fs_special_inode_operations;
2030 extern struct kmem_cache *inode_entry_slab;
2035 bool f2fs_may_inline_data(struct inode *);
2036 bool f2fs_may_inline_dentry(struct inode *);
2037 void read_inline_data(struct page *, struct page *);
2038 bool truncate_inline_inode(struct page *, u64);
2039 int f2fs_read_inline_data(struct inode *, struct page *);
2040 int f2fs_convert_inline_page(struct dnode_of_data *, struct page *);
2041 int f2fs_convert_inline_inode(struct inode *);
2042 int f2fs_write_inline_data(struct inode *, struct page *);
2043 bool recover_inline_data(struct inode *, struct page *);
2044 struct f2fs_dir_entry *find_in_inline_dir(struct inode *,
2045 struct f2fs_filename *, struct page **);
2046 struct f2fs_dir_entry *f2fs_parent_inline_dir(struct inode *, struct page **);
2047 int make_empty_inline_dir(struct inode *inode, struct inode *, struct page *);
2048 int f2fs_add_inline_entry(struct inode *, const struct qstr *, struct inode *,
2050 void f2fs_delete_inline_entry(struct f2fs_dir_entry *, struct page *,
2051 struct inode *, struct inode *);
2052 bool f2fs_empty_inline_dir(struct inode *);
2053 int f2fs_read_inline_dir(struct file *, struct dir_context *,
2055 int f2fs_inline_data_fiemap(struct inode *,
2056 struct fiemap_extent_info *, __u64, __u64);
2061 unsigned long f2fs_shrink_count(struct shrinker *, struct shrink_control *);
2062 unsigned long f2fs_shrink_scan(struct shrinker *, struct shrink_control *);
2063 void f2fs_join_shrinker(struct f2fs_sb_info *);
2064 void f2fs_leave_shrinker(struct f2fs_sb_info *);
2069 unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *, int);
2070 void f2fs_drop_largest_extent(struct inode *, pgoff_t);
2071 void f2fs_init_extent_tree(struct inode *, struct f2fs_extent *);
2072 unsigned int f2fs_destroy_extent_node(struct inode *);
2073 void f2fs_destroy_extent_tree(struct inode *);
2074 bool f2fs_lookup_extent_cache(struct inode *, pgoff_t, struct extent_info *);
2075 void f2fs_update_extent_cache(struct dnode_of_data *);
2076 void f2fs_update_extent_cache_range(struct dnode_of_data *dn,
2077 pgoff_t, block_t, unsigned int);
2078 void init_extent_cache_info(struct f2fs_sb_info *);
2079 int __init create_extent_cache(void);
2080 void destroy_extent_cache(void);
2085 static inline int f2fs_encrypted_inode(struct inode *inode)
2087 #ifdef CONFIG_F2FS_FS_ENCRYPTION
2088 return file_is_encrypt(inode);
2094 static inline void f2fs_set_encrypted_inode(struct inode *inode)
2096 #ifdef CONFIG_F2FS_FS_ENCRYPTION
2097 file_set_encrypt(inode);
2101 static inline bool f2fs_bio_encrypted(struct bio *bio)
2103 #ifdef CONFIG_F2FS_FS_ENCRYPTION
2104 return unlikely(bio->bi_private != NULL);
2110 static inline int f2fs_sb_has_crypto(struct super_block *sb)
2112 #ifdef CONFIG_F2FS_FS_ENCRYPTION
2113 return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT);
2119 static inline bool f2fs_may_encrypt(struct inode *inode)
2121 #ifdef CONFIG_F2FS_FS_ENCRYPTION
2122 mode_t mode = inode->i_mode;
2124 return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
2130 /* crypto_policy.c */
2131 int f2fs_is_child_context_consistent_with_parent(struct inode *,
2133 int f2fs_inherit_context(struct inode *, struct inode *, struct page *);
2134 int f2fs_process_policy(const struct f2fs_encryption_policy *, struct inode *);
2135 int f2fs_get_policy(struct inode *, struct f2fs_encryption_policy *);
2138 extern struct kmem_cache *f2fs_crypt_info_cachep;
2139 bool f2fs_valid_contents_enc_mode(uint32_t);
2140 uint32_t f2fs_validate_encryption_key_size(uint32_t, uint32_t);
2141 struct f2fs_crypto_ctx *f2fs_get_crypto_ctx(struct inode *);
2142 void f2fs_release_crypto_ctx(struct f2fs_crypto_ctx *);
2143 struct page *f2fs_encrypt(struct inode *, struct page *);
2144 int f2fs_decrypt(struct f2fs_crypto_ctx *, struct page *);
2145 int f2fs_decrypt_one(struct inode *, struct page *);
2146 void f2fs_end_io_crypto_work(struct f2fs_crypto_ctx *, struct bio *);
2149 void f2fs_free_encryption_info(struct inode *, struct f2fs_crypt_info *);
2150 int _f2fs_get_encryption_info(struct inode *inode);
2152 /* crypto_fname.c */
2153 bool f2fs_valid_filenames_enc_mode(uint32_t);
2154 u32 f2fs_fname_crypto_round_up(u32, u32);
2155 int f2fs_fname_crypto_alloc_buffer(struct inode *, u32, struct f2fs_str *);
2156 int f2fs_fname_disk_to_usr(struct inode *, f2fs_hash_t *,
2157 const struct f2fs_str *, struct f2fs_str *);
2158 int f2fs_fname_usr_to_disk(struct inode *, const struct qstr *,
2161 #ifdef CONFIG_F2FS_FS_ENCRYPTION
2162 void f2fs_restore_and_release_control_page(struct page **);
2163 void f2fs_restore_control_page(struct page *);
2165 int __init f2fs_init_crypto(void);
2166 int f2fs_crypto_initialize(void);
2167 void f2fs_exit_crypto(void);
2169 int f2fs_has_encryption_key(struct inode *);
2171 static inline int f2fs_get_encryption_info(struct inode *inode)
2173 struct f2fs_crypt_info *ci = F2FS_I(inode)->i_crypt_info;
2176 (ci->ci_keyring_key &&
2177 (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) |
2178 (1 << KEY_FLAG_REVOKED) |
2179 (1 << KEY_FLAG_DEAD)))))
2180 return _f2fs_get_encryption_info(inode);
2184 void f2fs_fname_crypto_free_buffer(struct f2fs_str *);
2185 int f2fs_fname_setup_filename(struct inode *, const struct qstr *,
2186 int lookup, struct f2fs_filename *);
2187 void f2fs_fname_free_filename(struct f2fs_filename *);
2189 static inline void f2fs_restore_and_release_control_page(struct page **p) { }
2190 static inline void f2fs_restore_control_page(struct page *p) { }
2192 static inline int __init f2fs_init_crypto(void) { return 0; }
2193 static inline void f2fs_exit_crypto(void) { }
2195 static inline int f2fs_has_encryption_key(struct inode *i) { return 0; }
2196 static inline int f2fs_get_encryption_info(struct inode *i) { return 0; }
2197 static inline void f2fs_fname_crypto_free_buffer(struct f2fs_str *p) { }
2199 static inline int f2fs_fname_setup_filename(struct inode *dir,
2200 const struct qstr *iname,
2201 int lookup, struct f2fs_filename *fname)
2203 memset(fname, 0, sizeof(struct f2fs_filename));
2204 fname->usr_fname = iname;
2205 fname->disk_name.name = (unsigned char *)iname->name;
2206 fname->disk_name.len = iname->len;
2210 static inline void f2fs_fname_free_filename(struct f2fs_filename *fname) { }