10a8165d7SJaegeuk Kim /* 239a53e0cSJaegeuk Kim * fs/f2fs/f2fs.h 339a53e0cSJaegeuk Kim * 439a53e0cSJaegeuk Kim * Copyright (c) 2012 Samsung Electronics Co., Ltd. 539a53e0cSJaegeuk Kim * http://www.samsung.com/ 639a53e0cSJaegeuk Kim * 739a53e0cSJaegeuk Kim * This program is free software; you can redistribute it and/or modify 839a53e0cSJaegeuk Kim * it under the terms of the GNU General Public License version 2 as 939a53e0cSJaegeuk Kim * published by the Free Software Foundation. 1039a53e0cSJaegeuk Kim */ 1139a53e0cSJaegeuk Kim #ifndef _LINUX_F2FS_H 1239a53e0cSJaegeuk Kim #define _LINUX_F2FS_H 1339a53e0cSJaegeuk Kim 1439a53e0cSJaegeuk Kim #include <linux/types.h> 1539a53e0cSJaegeuk Kim #include <linux/page-flags.h> 1639a53e0cSJaegeuk Kim #include <linux/buffer_head.h> 1739a53e0cSJaegeuk Kim #include <linux/slab.h> 1839a53e0cSJaegeuk Kim #include <linux/crc32.h> 1939a53e0cSJaegeuk Kim #include <linux/magic.h> 20c2d715d1SJaegeuk Kim #include <linux/kobject.h> 217bd59381SGu Zheng #include <linux/sched.h> 2239307a8eSJaegeuk Kim #include <linux/vmalloc.h> 23740432f8SJaegeuk Kim #include <linux/bio.h> 24d0239e1bSJaegeuk Kim #include <linux/blkdev.h> 2546f47e48SEric Biggers #ifdef CONFIG_F2FS_FS_ENCRYPTION 2646f47e48SEric Biggers #include <linux/fscrypt_supp.h> 2746f47e48SEric Biggers #else 2846f47e48SEric Biggers #include <linux/fscrypt_notsupp.h> 2946f47e48SEric Biggers #endif 3043b6573bSKeith Mok #include <crypto/hash.h> 3139a53e0cSJaegeuk Kim 325d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 339850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 345d56b671SJaegeuk Kim #else 359850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 369850cf4aSJaegeuk Kim do { \ 379850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 389850cf4aSJaegeuk Kim WARN_ON(1); \ 39caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 409850cf4aSJaegeuk Kim } \ 419850cf4aSJaegeuk Kim } while (0) 425d56b671SJaegeuk Kim #endif 435d56b671SJaegeuk Kim 442c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 452c63feadSJaegeuk Kim enum { 462c63feadSJaegeuk Kim FAULT_KMALLOC, 47c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 48cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 49cb78942bSJaegeuk Kim FAULT_ORPHAN, 50cb78942bSJaegeuk Kim FAULT_BLOCK, 51cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5253aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 5314b44d23SJaegeuk Kim FAULT_TRUNCATE, 548b038c70SChao Yu FAULT_IO, 550f348028SChao Yu FAULT_CHECKPOINT, 562c63feadSJaegeuk Kim FAULT_MAX, 572c63feadSJaegeuk Kim }; 582c63feadSJaegeuk Kim 5908796897SSheng Yong struct f2fs_fault_info { 6008796897SSheng Yong atomic_t inject_ops; 6108796897SSheng Yong unsigned int inject_rate; 6208796897SSheng Yong unsigned int inject_type; 6308796897SSheng Yong }; 6408796897SSheng Yong 652c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX]; 6668afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 672c63feadSJaegeuk Kim #endif 682c63feadSJaegeuk Kim 6939a53e0cSJaegeuk Kim /* 7039a53e0cSJaegeuk Kim * For mount options 7139a53e0cSJaegeuk Kim */ 7239a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 7339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7439a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7539a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 79444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 801001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8134d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8234d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8334d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 84d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8589672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 866aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 87343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 8873faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 8936abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 9036abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 9139a53e0cSJaegeuk Kim 9268afcf2dSTomohiro Kusumi #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) 9368afcf2dSTomohiro Kusumi #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) 9468afcf2dSTomohiro Kusumi #define test_opt(sbi, option) ((sbi)->mount_opt.opt & F2FS_MOUNT_##option) 9539a53e0cSJaegeuk Kim 9639a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 9739a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 9839a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 9939a53e0cSJaegeuk Kim 100a9841c4dSJaegeuk Kim typedef u32 block_t; /* 101a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 102a9841c4dSJaegeuk Kim * address format, __le32. 103a9841c4dSJaegeuk Kim */ 10439a53e0cSJaegeuk Kim typedef u32 nid_t; 10539a53e0cSJaegeuk Kim 10639a53e0cSJaegeuk Kim struct f2fs_mount_info { 10739a53e0cSJaegeuk Kim unsigned int opt; 10839a53e0cSJaegeuk Kim }; 10939a53e0cSJaegeuk Kim 110cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1110bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 112cde4de12SJaegeuk Kim 11376f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 11476f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 11576f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 116c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 11776f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 118c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 11976f105a2SJaegeuk Kim 12039a53e0cSJaegeuk Kim /* 12139a53e0cSJaegeuk Kim * For checkpoint manager 12239a53e0cSJaegeuk Kim */ 12339a53e0cSJaegeuk Kim enum { 12439a53e0cSJaegeuk Kim NAT_BITMAP, 12539a53e0cSJaegeuk Kim SIT_BITMAP 12639a53e0cSJaegeuk Kim }; 12739a53e0cSJaegeuk Kim 128c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 129c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 130c473f1a9SChao Yu #define CP_SYNC 0x00000004 131c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 132c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1331f43e2adSChao Yu #define CP_TRIMMED 0x00000020 13475ab4cb8SJaegeuk Kim 13547b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 136bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 1374ddb1a4dSJaegeuk Kim (GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections)) 138a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 139a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 1404ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 14115469963SJaegeuk Kim #define DISCARD_ISSUE_RATE 8 14260b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 143dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 144bba681cbSJaegeuk Kim 14575ab4cb8SJaegeuk Kim struct cp_control { 14675ab4cb8SJaegeuk Kim int reason; 1474b2fecc8SJaegeuk Kim __u64 trim_start; 1484b2fecc8SJaegeuk Kim __u64 trim_end; 1494b2fecc8SJaegeuk Kim __u64 trim_minlen; 1504b2fecc8SJaegeuk Kim __u64 trimmed; 15175ab4cb8SJaegeuk Kim }; 15275ab4cb8SJaegeuk Kim 153662befdaSChao Yu /* 15481c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 155662befdaSChao Yu */ 156662befdaSChao Yu enum { 157662befdaSChao Yu META_CP, 158662befdaSChao Yu META_NAT, 15981c1a0f1SChao Yu META_SIT, 1604c521f49SJaegeuk Kim META_SSA, 1614c521f49SJaegeuk Kim META_POR, 162662befdaSChao Yu }; 163662befdaSChao Yu 1646451e041SJaegeuk Kim /* for the list of ino */ 1656451e041SJaegeuk Kim enum { 1666451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 167fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 168fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1696451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1706451e041SJaegeuk Kim }; 1716451e041SJaegeuk Kim 1726451e041SJaegeuk Kim struct ino_entry { 17339a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17439a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 17539a53e0cSJaegeuk Kim }; 17639a53e0cSJaegeuk Kim 1772710fd7eSChao Yu /* for the list of inodes to be GCed */ 17806292073SChao Yu struct inode_entry { 17939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18039a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 18139a53e0cSJaegeuk Kim }; 18239a53e0cSJaegeuk Kim 183a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 1847fd9e544SJaegeuk Kim struct discard_entry { 1857fd9e544SJaegeuk Kim struct list_head list; /* list head */ 186a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 187a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 1887fd9e544SJaegeuk Kim }; 1897fd9e544SJaegeuk Kim 190ba48a33eSChao Yu /* max discard pend list number */ 191ba48a33eSChao Yu #define MAX_PLIST_NUM 512 192ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 193ba48a33eSChao Yu (MAX_PLIST_NUM - 1) : (blk_num - 1)) 194ba48a33eSChao Yu 19515469963SJaegeuk Kim enum { 19615469963SJaegeuk Kim D_PREP, 19715469963SJaegeuk Kim D_SUBMIT, 19815469963SJaegeuk Kim D_DONE, 19915469963SJaegeuk Kim }; 20015469963SJaegeuk Kim 201004b6862SChao Yu struct discard_info { 202b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 203b01a9201SJaegeuk Kim block_t len; /* length */ 204004b6862SChao Yu block_t start; /* actual start address in dev */ 205004b6862SChao Yu }; 206004b6862SChao Yu 207b01a9201SJaegeuk Kim struct discard_cmd { 208004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 209004b6862SChao Yu union { 210004b6862SChao Yu struct { 211004b6862SChao Yu block_t lstart; /* logical start address */ 212004b6862SChao Yu block_t len; /* length */ 213004b6862SChao Yu block_t start; /* actual start address in dev */ 214004b6862SChao Yu }; 215004b6862SChao Yu struct discard_info di; /* discard info */ 216004b6862SChao Yu 217004b6862SChao Yu }; 218b01a9201SJaegeuk Kim struct list_head list; /* command list */ 219b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 220c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 221ec9895adSChao Yu unsigned short ref; /* reference count */ 2229a744b92SChao Yu unsigned char state; /* state */ 223c81abe34SJaegeuk Kim int error; /* bio error */ 224275b66b0SChao Yu }; 225275b66b0SChao Yu 2260b54fb84SJaegeuk Kim struct discard_cmd_control { 22715469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 22846f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 229ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 23046f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 23115469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 23215469963SJaegeuk Kim struct mutex cmd_lock; 233d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 234d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 235d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 2368b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 2378b8dd65fSChao Yu atomic_t issing_discard; /* # of issing discard */ 2385f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 239004b6862SChao Yu struct rb_root root; /* root of discard rb-tree */ 24039a53e0cSJaegeuk Kim }; 24139a53e0cSJaegeuk Kim 24239a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 24339a53e0cSJaegeuk Kim struct fsync_inode_entry { 24439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 24539a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 246c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 247c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 24839a53e0cSJaegeuk Kim }; 24939a53e0cSJaegeuk Kim 25068afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 25168afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 25239a53e0cSJaegeuk Kim 25368afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 25468afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 25568afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 25668afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 25739a53e0cSJaegeuk Kim 258dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 259dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 260309cc2b6SJaegeuk Kim 261dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 26239a53e0cSJaegeuk Kim { 263dfc08a12SChao Yu int before = nats_in_cursum(journal); 264cac5a3d8SDongOh Shin 265dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 26639a53e0cSJaegeuk Kim return before; 26739a53e0cSJaegeuk Kim } 26839a53e0cSJaegeuk Kim 269dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 27039a53e0cSJaegeuk Kim { 271dfc08a12SChao Yu int before = sits_in_cursum(journal); 272cac5a3d8SDongOh Shin 273dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 27439a53e0cSJaegeuk Kim return before; 27539a53e0cSJaegeuk Kim } 27639a53e0cSJaegeuk Kim 277dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 278dfc08a12SChao Yu int size, int type) 279184a5cd2SChao Yu { 280184a5cd2SChao Yu if (type == NAT_JOURNAL) 281dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 282dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 283184a5cd2SChao Yu } 284184a5cd2SChao Yu 28539a53e0cSJaegeuk Kim /* 286e9750824SNamjae Jeon * ioctl commands 287e9750824SNamjae Jeon */ 288e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 289e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 290d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 291e9750824SNamjae Jeon 29288b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 29388b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 29488b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 29502a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2961e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2971e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 298d07efb50SJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32) 299456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 300d07efb50SJaegeuk Kim #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \ 301d07efb50SJaegeuk Kim struct f2fs_defragment) 3024dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 3034dd6f977SJaegeuk Kim struct f2fs_move_range) 304e066b83cSJaegeuk Kim #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ 305e066b83cSJaegeuk Kim struct f2fs_flush_device) 30634dc77adSJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ 30734dc77adSJaegeuk Kim struct f2fs_gc_range) 30888b88a66SJaegeuk Kim 3090b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 3100b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 3110b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 312f424f664SJaegeuk Kim 3131abff93dSJaegeuk Kim /* 3141abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 3151abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 3161abff93dSJaegeuk Kim */ 3171abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 3181abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 3191abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 3201abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 321c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 3221abff93dSJaegeuk Kim 323e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 324e9750824SNamjae Jeon /* 325e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 326e9750824SNamjae Jeon */ 327e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 328e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 32904ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 330e9750824SNamjae Jeon #endif 331e9750824SNamjae Jeon 33234dc77adSJaegeuk Kim struct f2fs_gc_range { 33334dc77adSJaegeuk Kim u32 sync; 33434dc77adSJaegeuk Kim u64 start; 33534dc77adSJaegeuk Kim u64 len; 33634dc77adSJaegeuk Kim }; 33734dc77adSJaegeuk Kim 338d323d005SChao Yu struct f2fs_defragment { 339d323d005SChao Yu u64 start; 340d323d005SChao Yu u64 len; 341d323d005SChao Yu }; 342d323d005SChao Yu 3434dd6f977SJaegeuk Kim struct f2fs_move_range { 3444dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3454dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3464dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3474dd6f977SJaegeuk Kim u64 len; /* size to move */ 3484dd6f977SJaegeuk Kim }; 3494dd6f977SJaegeuk Kim 350e066b83cSJaegeuk Kim struct f2fs_flush_device { 351e066b83cSJaegeuk Kim u32 dev_num; /* device number to flush */ 352e066b83cSJaegeuk Kim u32 segments; /* # of segments to flush */ 353e066b83cSJaegeuk Kim }; 354e066b83cSJaegeuk Kim 355e9750824SNamjae Jeon /* 35639a53e0cSJaegeuk Kim * For INODE and NODE manager 35739a53e0cSJaegeuk Kim */ 3587b3cd7d6SJaegeuk Kim /* for directory operations */ 3597b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 360d8c6822aSJaegeuk Kim struct inode *inode; 3617b3cd7d6SJaegeuk Kim const void *bitmap; 3627b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 3637b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 3647b3cd7d6SJaegeuk Kim int max; 3657b3cd7d6SJaegeuk Kim }; 3667b3cd7d6SJaegeuk Kim 36764c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 36864c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 3697b3cd7d6SJaegeuk Kim { 370d8c6822aSJaegeuk Kim d->inode = inode; 3717b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 3727b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3737b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3747b3cd7d6SJaegeuk Kim d->filename = t->filename; 37564c24ecbSTomohiro Kusumi } 376cac5a3d8SDongOh Shin 37764c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 37864c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_inline_dentry *t) 37964c24ecbSTomohiro Kusumi { 38064c24ecbSTomohiro Kusumi d->inode = inode; 3817b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3827b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3837b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3847b3cd7d6SJaegeuk Kim d->filename = t->filename; 3857b3cd7d6SJaegeuk Kim } 3867b3cd7d6SJaegeuk Kim 387dbe6a5ffSJaegeuk Kim /* 388dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 389dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 390dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 39139a53e0cSJaegeuk Kim */ 392dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 393dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 394266e97a8SJaegeuk Kim enum { 395266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 396266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 397266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 398266e97a8SJaegeuk Kim * look up a node with readahead called 3994f4124d0SChao Yu * by get_data_block. 40039a53e0cSJaegeuk Kim */ 401266e97a8SJaegeuk Kim }; 402266e97a8SJaegeuk Kim 403a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 40439a53e0cSJaegeuk Kim 405817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 406817202d9SChao Yu 40713054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 40813054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 40913054c54SChao Yu 41039a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 41113054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 41213054c54SChao Yu 41313054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 41413054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 415c11abd1aSJaegeuk Kim 41654c2258cSChao Yu struct rb_entry { 41754c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 41854c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 41954c2258cSChao Yu unsigned int len; /* length of the entry */ 42054c2258cSChao Yu }; 42154c2258cSChao Yu 42239a53e0cSJaegeuk Kim struct extent_info { 42339a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 424111d2495SMasanari Iida unsigned int len; /* length of the extent */ 42554c2258cSChao Yu u32 blk; /* start block address of the extent */ 42639a53e0cSJaegeuk Kim }; 42739a53e0cSJaegeuk Kim 42813054c54SChao Yu struct extent_node { 42954c2258cSChao Yu struct rb_node rb_node; 43054c2258cSChao Yu union { 43154c2258cSChao Yu struct { 43254c2258cSChao Yu unsigned int fofs; 43354c2258cSChao Yu unsigned int len; 43454c2258cSChao Yu u32 blk; 43554c2258cSChao Yu }; 43613054c54SChao Yu struct extent_info ei; /* extent info */ 43754c2258cSChao Yu 43854c2258cSChao Yu }; 43954c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 440201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 44113054c54SChao Yu }; 44213054c54SChao Yu 44313054c54SChao Yu struct extent_tree { 44413054c54SChao Yu nid_t ino; /* inode number */ 44513054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 44662c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 4473e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 448137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 44913054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 45068e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 45113054c54SChao Yu }; 45213054c54SChao Yu 45339a53e0cSJaegeuk Kim /* 454003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 455003a3e1dSJaegeuk Kim * 456003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 457003a3e1dSJaegeuk Kim */ 458003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 459003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 4607f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 4617f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 4627f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 463003a3e1dSJaegeuk Kim 464003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 465003a3e1dSJaegeuk Kim block_t m_pblk; 466003a3e1dSJaegeuk Kim block_t m_lblk; 467003a3e1dSJaegeuk Kim unsigned int m_len; 468003a3e1dSJaegeuk Kim unsigned int m_flags; 469da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 470003a3e1dSJaegeuk Kim }; 471003a3e1dSJaegeuk Kim 472e2b4e2bcSChao Yu /* for flag in get_data_block */ 473e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 474e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 475e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 476e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 477b439b103SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_DIO 4 47824b84912SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_AIO 5 479e2b4e2bcSChao Yu 480003a3e1dSJaegeuk Kim /* 48139a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 48239a53e0cSJaegeuk Kim */ 48339a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 484354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 485cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 486e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 48726787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 48839a53e0cSJaegeuk Kim 489b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 490b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 491b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 492b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 493b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 494b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 495cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 496cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 497cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 498e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 499e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 50026787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 50126787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 502cde4de12SJaegeuk Kim 503ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 504ab9fa662SJaegeuk Kim 50539a53e0cSJaegeuk Kim struct f2fs_inode_info { 50639a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 50739a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 50839a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 50938431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 51039a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 5116666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 51239a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 51339a53e0cSJaegeuk Kim 51439a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 51539a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 516d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 517204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 51839a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 51939a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 52088c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 52139a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 52226de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 52388b88a66SJaegeuk Kim 5240f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 5250f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 52688b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 52788b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 5283e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 52982e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 5305a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 53139a53e0cSJaegeuk Kim }; 53239a53e0cSJaegeuk Kim 53339a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 534bd933d4fSChao Yu struct f2fs_extent *i_ext) 53539a53e0cSJaegeuk Kim { 536bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 537bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 538bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 53939a53e0cSJaegeuk Kim } 54039a53e0cSJaegeuk Kim 54139a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 54239a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 54339a53e0cSJaegeuk Kim { 54439a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 5454d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 54639a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 54739a53e0cSJaegeuk Kim } 54839a53e0cSJaegeuk Kim 549429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 550429511cdSChao Yu u32 blk, unsigned int len) 551429511cdSChao Yu { 552429511cdSChao Yu ei->fofs = fofs; 553429511cdSChao Yu ei->blk = blk; 554429511cdSChao Yu ei->len = len; 555429511cdSChao Yu } 556429511cdSChao Yu 557004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 558004b6862SChao Yu struct discard_info *front) 559004b6862SChao Yu { 560004b6862SChao Yu return back->lstart + back->len == front->lstart; 561004b6862SChao Yu } 562004b6862SChao Yu 563004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 564004b6862SChao Yu struct discard_info *back) 565004b6862SChao Yu { 566004b6862SChao Yu return __is_discard_mergeable(back, cur); 567004b6862SChao Yu } 568004b6862SChao Yu 569004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 570004b6862SChao Yu struct discard_info *front) 571004b6862SChao Yu { 572004b6862SChao Yu return __is_discard_mergeable(cur, front); 573004b6862SChao Yu } 574004b6862SChao Yu 575429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 576429511cdSChao Yu struct extent_info *front) 577429511cdSChao Yu { 578429511cdSChao Yu return (back->fofs + back->len == front->fofs && 579429511cdSChao Yu back->blk + back->len == front->blk); 580429511cdSChao Yu } 581429511cdSChao Yu 582429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 583429511cdSChao Yu struct extent_info *back) 584429511cdSChao Yu { 585429511cdSChao Yu return __is_extent_mergeable(back, cur); 586429511cdSChao Yu } 587429511cdSChao Yu 588429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 589429511cdSChao Yu struct extent_info *front) 590429511cdSChao Yu { 591429511cdSChao Yu return __is_extent_mergeable(cur, front); 592429511cdSChao Yu } 593429511cdSChao Yu 594cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 595205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 596205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 5974abd3f5aSChao Yu { 598205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 5994abd3f5aSChao Yu et->largest = en->ei; 6007c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 601205b9822SJaegeuk Kim } 6024abd3f5aSChao Yu } 6034abd3f5aSChao Yu 604b8559dc2SChao Yu enum nid_list { 605b8559dc2SChao Yu FREE_NID_LIST, 606b8559dc2SChao Yu ALLOC_NID_LIST, 607b8559dc2SChao Yu MAX_NID_LIST, 608b8559dc2SChao Yu }; 609b8559dc2SChao Yu 61039a53e0cSJaegeuk Kim struct f2fs_nm_info { 61139a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 61239a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 61304d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 61439a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 615cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 616ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 6172304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 61839a53e0cSJaegeuk Kim 61939a53e0cSJaegeuk Kim /* NAT cache management */ 62039a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 621309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 622b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 62339a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 624309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 625aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 62622ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 62739a53e0cSJaegeuk Kim 62839a53e0cSJaegeuk Kim /* free node ids management */ 6298a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 630b8559dc2SChao Yu struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ 631b8559dc2SChao Yu unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 632b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 63339a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 6344ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 6354ac91242SChao Yu unsigned char *nat_block_bitmap; 636586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 63739a53e0cSJaegeuk Kim 63839a53e0cSJaegeuk Kim /* for checkpoint */ 63939a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 64022ad0b6aSJaegeuk Kim 64122ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 64222ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 64322ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 64422ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 645599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 646599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 647599a09b2SChao Yu #endif 64839a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 64939a53e0cSJaegeuk Kim }; 65039a53e0cSJaegeuk Kim 65139a53e0cSJaegeuk Kim /* 65239a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 65339a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 65439a53e0cSJaegeuk Kim * by the data offset in a file. 65539a53e0cSJaegeuk Kim */ 65639a53e0cSJaegeuk Kim struct dnode_of_data { 65739a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 65839a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 65939a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 66039a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 66139a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 66239a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 66393bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 6643cf45747SChao Yu char cur_level; /* level of hole node page */ 6653cf45747SChao Yu char max_level; /* level of current page located */ 66639a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 66739a53e0cSJaegeuk Kim }; 66839a53e0cSJaegeuk Kim 66939a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 67039a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 67139a53e0cSJaegeuk Kim { 672d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 67339a53e0cSJaegeuk Kim dn->inode = inode; 67439a53e0cSJaegeuk Kim dn->inode_page = ipage; 67539a53e0cSJaegeuk Kim dn->node_page = npage; 67639a53e0cSJaegeuk Kim dn->nid = nid; 67739a53e0cSJaegeuk Kim } 67839a53e0cSJaegeuk Kim 67939a53e0cSJaegeuk Kim /* 68039a53e0cSJaegeuk Kim * For SIT manager 68139a53e0cSJaegeuk Kim * 68239a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 68339a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 68439a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 68539a53e0cSJaegeuk Kim * respectively. 68639a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 68739a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 68839a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 68939a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 69039a53e0cSJaegeuk Kim * data and 8 for node logs. 69139a53e0cSJaegeuk Kim */ 69239a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 69339a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 69439a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 69539a53e0cSJaegeuk Kim 69639a53e0cSJaegeuk Kim enum { 69739a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 69839a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 69939a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 70039a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 70139a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 70239a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 70338aa0889SJaegeuk Kim NO_CHECK_TYPE, 70439a53e0cSJaegeuk Kim }; 70539a53e0cSJaegeuk Kim 7066b4afdd7SJaegeuk Kim struct flush_cmd { 7076b4afdd7SJaegeuk Kim struct completion wait; 708721bd4d5SGu Zheng struct llist_node llnode; 7096b4afdd7SJaegeuk Kim int ret; 7106b4afdd7SJaegeuk Kim }; 7116b4afdd7SJaegeuk Kim 712a688b9d9SGu Zheng struct flush_cmd_control { 713a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 714a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 7158b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 7168b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 717721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 718721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 719a688b9d9SGu Zheng }; 720a688b9d9SGu Zheng 72139a53e0cSJaegeuk Kim struct f2fs_sm_info { 72239a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 72339a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 72439a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 72539a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 72639a53e0cSJaegeuk Kim 72739a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 72839a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 72939a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 73039a53e0cSJaegeuk Kim 73139a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 73239a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 73339a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 73439a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 73581eb8d6eSJaegeuk Kim 73681eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 73781eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 7387fd9e544SJaegeuk Kim 739bba681cbSJaegeuk Kim /* for batched trimming */ 740bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 741bba681cbSJaegeuk Kim 742184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 743184a5cd2SChao Yu 744216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 745216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 746c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 747ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 7486b4afdd7SJaegeuk Kim 7496b4afdd7SJaegeuk Kim /* for flush command control */ 750b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 751a688b9d9SGu Zheng 7520b54fb84SJaegeuk Kim /* for discard command control */ 7530b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 75439a53e0cSJaegeuk Kim }; 75539a53e0cSJaegeuk Kim 75639a53e0cSJaegeuk Kim /* 75739a53e0cSJaegeuk Kim * For superblock 75839a53e0cSJaegeuk Kim */ 75939a53e0cSJaegeuk Kim /* 76039a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 76139a53e0cSJaegeuk Kim * 76239a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 76339a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 76439a53e0cSJaegeuk Kim */ 76536951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 76639a53e0cSJaegeuk Kim enum count_type { 76739a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 768c227f912SChao Yu F2FS_DIRTY_DATA, 76939a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 77039a53e0cSJaegeuk Kim F2FS_DIRTY_META, 7718dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 7720f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 77336951b38SChao Yu F2FS_WB_CP_DATA, 77436951b38SChao Yu F2FS_WB_DATA, 77539a53e0cSJaegeuk Kim NR_COUNT_TYPE, 77639a53e0cSJaegeuk Kim }; 77739a53e0cSJaegeuk Kim 77839a53e0cSJaegeuk Kim /* 779e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 78039a53e0cSJaegeuk Kim * The available types are: 78139a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 78239a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 78339a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 78439a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 78539a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 78639a53e0cSJaegeuk Kim * with waiting the bio's completion 78739a53e0cSJaegeuk Kim * ... Only can be used with META. 78839a53e0cSJaegeuk Kim */ 7897d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 79039a53e0cSJaegeuk Kim enum page_type { 79139a53e0cSJaegeuk Kim DATA, 79239a53e0cSJaegeuk Kim NODE, 79339a53e0cSJaegeuk Kim META, 79439a53e0cSJaegeuk Kim NR_PAGE_TYPE, 79539a53e0cSJaegeuk Kim META_FLUSH, 7968ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 7978ce67cb0SJaegeuk Kim INMEM_DROP, 7988c242db9SJaegeuk Kim INMEM_INVALIDATE, 79928bc106bSChao Yu INMEM_REVOKE, 8008ce67cb0SJaegeuk Kim IPU, 8018ce67cb0SJaegeuk Kim OPU, 80239a53e0cSJaegeuk Kim }; 80339a53e0cSJaegeuk Kim 804a912b54dSJaegeuk Kim enum temp_type { 805a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 806a912b54dSJaegeuk Kim WARM, 807a912b54dSJaegeuk Kim COLD, 808a912b54dSJaegeuk Kim NR_TEMP_TYPE, 809a912b54dSJaegeuk Kim }; 810a912b54dSJaegeuk Kim 811cc15620bSJaegeuk Kim enum need_lock_type { 812cc15620bSJaegeuk Kim LOCK_REQ = 0, 813cc15620bSJaegeuk Kim LOCK_DONE, 814cc15620bSJaegeuk Kim LOCK_RETRY, 815cc15620bSJaegeuk Kim }; 816cc15620bSJaegeuk Kim 817458e6197SJaegeuk Kim struct f2fs_io_info { 81805ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 819458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 820a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 82104d328deSMike Christie int op; /* contains REQ_OP_ */ 822ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 8237a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 82428bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 82505ca3632SJaegeuk Kim struct page *page; /* page to be written */ 8264375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 827fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 828d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 829cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 830fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 831458e6197SJaegeuk Kim }; 832458e6197SJaegeuk Kim 83368afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 8341ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 835458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 8361ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 8371ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 838458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 839df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 840fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 841fb830fc5SChao Yu struct list_head io_list; /* track fios */ 8421ff7bd3bSJaegeuk Kim }; 8431ff7bd3bSJaegeuk Kim 8443c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 8453c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 8463c62be17SJaegeuk Kim struct f2fs_dev_info { 8473c62be17SJaegeuk Kim struct block_device *bdev; 8483c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 8493c62be17SJaegeuk Kim unsigned int total_segments; 8503c62be17SJaegeuk Kim block_t start_blk; 8513c62be17SJaegeuk Kim block_t end_blk; 8523c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 8533c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 8543c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 8553c62be17SJaegeuk Kim #endif 8563c62be17SJaegeuk Kim }; 8573c62be17SJaegeuk Kim 858c227f912SChao Yu enum inode_type { 859c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 860c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 8610f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 862c227f912SChao Yu NR_INODE_TYPE, 863c227f912SChao Yu }; 864c227f912SChao Yu 86567298804SChao Yu /* for inner inode cache management */ 86667298804SChao Yu struct inode_management { 86767298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 86867298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 86967298804SChao Yu struct list_head ino_list; /* inode list head */ 87067298804SChao Yu unsigned long ino_num; /* number of entries */ 87167298804SChao Yu }; 87267298804SChao Yu 873caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 874caf0047eSChao Yu enum { 875caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 876caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 877caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 878caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 879df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 880bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 881caf0047eSChao Yu }; 882caf0047eSChao Yu 8836beceb54SJaegeuk Kim enum { 8846beceb54SJaegeuk Kim CP_TIME, 885d0239e1bSJaegeuk Kim REQ_TIME, 8866beceb54SJaegeuk Kim MAX_TIME, 8876beceb54SJaegeuk Kim }; 8886beceb54SJaegeuk Kim 88939a53e0cSJaegeuk Kim struct f2fs_sb_info { 89039a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 8915e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 89239a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 893e8240f65SChao Yu int valid_super_block; /* valid super block no */ 894fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 89539a53e0cSJaegeuk Kim 896178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 897178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 898178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 899178053e2SDamien Le Moal #endif 900178053e2SDamien Le Moal 90139a53e0cSJaegeuk Kim /* for node-related operations */ 90239a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 90339a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 90439a53e0cSJaegeuk Kim 90539a53e0cSJaegeuk Kim /* for segment-related operations */ 90639a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 9071ff7bd3bSJaegeuk Kim 9081ff7bd3bSJaegeuk Kim /* for bio operations */ 909a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 910e41e6d75SChao Yu struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 911e41e6d75SChao Yu /* bio ordering for NODE/DATA */ 9120a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 9130a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 91439a53e0cSJaegeuk Kim 91539a53e0cSJaegeuk Kim /* for checkpoint */ 91639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 9178508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 918aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 91939a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 92039936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 921b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 922b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 92359c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 924fb51b5efSChangman Lee wait_queue_head_t cp_wait; 9256beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 9266beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 92739a53e0cSJaegeuk Kim 92867298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 9296451e041SJaegeuk Kim 9306451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 9310d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 93239a53e0cSJaegeuk Kim 933c227f912SChao Yu /* for inode management */ 934c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 935c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 93639a53e0cSJaegeuk Kim 93713054c54SChao Yu /* for extent tree cache */ 93813054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 9395e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 94013054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 94113054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 9427441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 943137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 94474fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 94513054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 94613054c54SChao Yu 94739a53e0cSJaegeuk Kim /* basic filesystem units */ 94839a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 94939a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 95039a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 95139a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 95239a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 95339a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 95439a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 95539a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 95639a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 95739a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 95839a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 95939a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 96039a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 961e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 96239a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 963ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 96439a53e0cSJaegeuk Kim 96539a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 96639a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 967a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 96839a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 969*daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 970*daeb433eSChao Yu 97139a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 972523be8a6SJaegeuk Kim 973523be8a6SJaegeuk Kim /* # of pages, see count_type */ 97435782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 97541382ec4SJaegeuk Kim /* # of allocated blocks */ 97641382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 97739a53e0cSJaegeuk Kim 978687de7f1SJaegeuk Kim /* writeback control */ 979687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 980687de7f1SJaegeuk Kim 981513c5f37SJaegeuk Kim /* valid inode count */ 982513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 983513c5f37SJaegeuk Kim 98439a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 98539a53e0cSJaegeuk Kim 98639a53e0cSJaegeuk Kim /* for cleaning operations */ 98739a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 98839a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 9895ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 99039a53e0cSJaegeuk Kim 991e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 992e93b9865SHou Pengyang u64 fggc_threshold; 993e93b9865SHou Pengyang 994b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 995b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 996b1c57c1cSJaegeuk Kim 99739a53e0cSJaegeuk Kim /* 99839a53e0cSJaegeuk Kim * for stat information. 99939a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 100039a53e0cSJaegeuk Kim */ 100135b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 100239a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 100339a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 100439a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1005b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 10065b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 10075b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 10085b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 10095b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1010d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 101103e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 101203e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 101326a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 1014648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 101526a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1016648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 101739a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 101833fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 101935b09d82SNamjae Jeon #endif 102039a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1021b59d0baeSNamjae Jeon 1022b59d0baeSNamjae Jeon /* For sysfs suppport */ 1023b59d0baeSNamjae Jeon struct kobject s_kobj; 1024b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 10252658e50dSJaegeuk Kim 10262658e50dSJaegeuk Kim /* For shrinker support */ 10272658e50dSJaegeuk Kim struct list_head s_list; 10283c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 10293c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 10302658e50dSJaegeuk Kim struct mutex umount_mutex; 10312658e50dSJaegeuk Kim unsigned int shrinker_run_no; 10328f1dbbbbSShuoran Liu 10338f1dbbbbSShuoran Liu /* For write statistics */ 10348f1dbbbbSShuoran Liu u64 sectors_written_start; 10358f1dbbbbSShuoran Liu u64 kbytes_written; 103643b6573bSKeith Mok 103743b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 103843b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 10391ecc0c5cSChao Yu 10401ecc0c5cSChao Yu /* For fault injection */ 10411ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 10421ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 10431ecc0c5cSChao Yu #endif 104439a53e0cSJaegeuk Kim }; 104539a53e0cSJaegeuk Kim 10461ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 104755523519SChao Yu #define f2fs_show_injection_info(type) \ 104855523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 104955523519SChao Yu KERN_INFO, fault_name[type], \ 105055523519SChao Yu __func__, __builtin_return_address(0)) 10511ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 10521ecc0c5cSChao Yu { 10531ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 10541ecc0c5cSChao Yu 10551ecc0c5cSChao Yu if (!ffi->inject_rate) 10561ecc0c5cSChao Yu return false; 10571ecc0c5cSChao Yu 10581ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 10591ecc0c5cSChao Yu return false; 10601ecc0c5cSChao Yu 10611ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 10621ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 10631ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 10641ecc0c5cSChao Yu return true; 10651ecc0c5cSChao Yu } 10661ecc0c5cSChao Yu return false; 10671ecc0c5cSChao Yu } 10681ecc0c5cSChao Yu #endif 10691ecc0c5cSChao Yu 10708f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 10718f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 10728f1dbbbbSShuoran Liu */ 10738f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 107468afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 107568afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 10768f1dbbbbSShuoran Liu 10776beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 10786beceb54SJaegeuk Kim { 10796beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 10806beceb54SJaegeuk Kim } 10816beceb54SJaegeuk Kim 10826beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 10836beceb54SJaegeuk Kim { 10846beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 10856beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 10866beceb54SJaegeuk Kim 10876beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 10886beceb54SJaegeuk Kim } 10896beceb54SJaegeuk Kim 1090d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1091d0239e1bSJaegeuk Kim { 1092d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1093d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1094d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1095d0239e1bSJaegeuk Kim 1096d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1097d0239e1bSJaegeuk Kim return 0; 1098d0239e1bSJaegeuk Kim 1099d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1100d0239e1bSJaegeuk Kim } 1101d0239e1bSJaegeuk Kim 110239a53e0cSJaegeuk Kim /* 110339a53e0cSJaegeuk Kim * Inline functions 110439a53e0cSJaegeuk Kim */ 110543b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 110643b6573bSKeith Mok unsigned int length) 110743b6573bSKeith Mok { 110843b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 110943b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 111043b6573bSKeith Mok int err; 111143b6573bSKeith Mok 111243b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 111343b6573bSKeith Mok shash->flags = 0; 111443b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 111543b6573bSKeith Mok 111643b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 111743b6573bSKeith Mok BUG_ON(err); 111843b6573bSKeith Mok 111943b6573bSKeith Mok return *ctx; 112043b6573bSKeith Mok } 112143b6573bSKeith Mok 112243b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 112343b6573bSKeith Mok void *buf, size_t buf_size) 112443b6573bSKeith Mok { 112543b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 112643b6573bSKeith Mok } 112743b6573bSKeith Mok 112839a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 112939a53e0cSJaegeuk Kim { 113039a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 113139a53e0cSJaegeuk Kim } 113239a53e0cSJaegeuk Kim 113339a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 113439a53e0cSJaegeuk Kim { 113539a53e0cSJaegeuk Kim return sb->s_fs_info; 113639a53e0cSJaegeuk Kim } 113739a53e0cSJaegeuk Kim 11384081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 11394081363fSJaegeuk Kim { 11404081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 11414081363fSJaegeuk Kim } 11424081363fSJaegeuk Kim 11434081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 11444081363fSJaegeuk Kim { 11454081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 11464081363fSJaegeuk Kim } 11474081363fSJaegeuk Kim 11484081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 11494081363fSJaegeuk Kim { 11504081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 11514081363fSJaegeuk Kim } 11524081363fSJaegeuk Kim 115339a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 115439a53e0cSJaegeuk Kim { 115539a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 115639a53e0cSJaegeuk Kim } 115739a53e0cSJaegeuk Kim 115839a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 115939a53e0cSJaegeuk Kim { 116039a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 116139a53e0cSJaegeuk Kim } 116239a53e0cSJaegeuk Kim 116345590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 116445590710SGu Zheng { 116545590710SGu Zheng return (struct f2fs_node *)page_address(page); 116645590710SGu Zheng } 116745590710SGu Zheng 116858bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 116958bfaf44SJaegeuk Kim { 117058bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 117158bfaf44SJaegeuk Kim } 117258bfaf44SJaegeuk Kim 117339a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 117439a53e0cSJaegeuk Kim { 117539a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 117639a53e0cSJaegeuk Kim } 117739a53e0cSJaegeuk Kim 117839a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 117939a53e0cSJaegeuk Kim { 118039a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 118139a53e0cSJaegeuk Kim } 118239a53e0cSJaegeuk Kim 118339a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 118439a53e0cSJaegeuk Kim { 118539a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 118639a53e0cSJaegeuk Kim } 118739a53e0cSJaegeuk Kim 118839a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 118939a53e0cSJaegeuk Kim { 119039a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 119139a53e0cSJaegeuk Kim } 119239a53e0cSJaegeuk Kim 119339a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 119439a53e0cSJaegeuk Kim { 119539a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 119639a53e0cSJaegeuk Kim } 119739a53e0cSJaegeuk Kim 11989df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 11999df27d98SGu Zheng { 12009df27d98SGu Zheng return sbi->meta_inode->i_mapping; 12019df27d98SGu Zheng } 12029df27d98SGu Zheng 12034ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 12044ef51a8fSJaegeuk Kim { 12054ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 12064ef51a8fSJaegeuk Kim } 12074ef51a8fSJaegeuk Kim 1208caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 120939a53e0cSJaegeuk Kim { 1210fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 121139a53e0cSJaegeuk Kim } 121239a53e0cSJaegeuk Kim 1213caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 121439a53e0cSJaegeuk Kim { 1215fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1216caf0047eSChao Yu } 1217caf0047eSChao Yu 1218caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1219caf0047eSChao Yu { 1220fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 122139a53e0cSJaegeuk Kim } 122239a53e0cSJaegeuk Kim 1223d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1224d71b5564SJaegeuk Kim { 1225d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1226d71b5564SJaegeuk Kim } 1227d71b5564SJaegeuk Kim 1228ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1229ced2c7eaSKinglong Mee { 1230ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1231ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1232ced2c7eaSKinglong Mee } 1233ced2c7eaSKinglong Mee 1234aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 123525ca923bSJaegeuk Kim { 123625ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1237aaec2b1dSChao Yu 123825ca923bSJaegeuk Kim return ckpt_flags & f; 123925ca923bSJaegeuk Kim } 124025ca923bSJaegeuk Kim 1241aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 124225ca923bSJaegeuk Kim { 1243aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1244aaec2b1dSChao Yu } 1245aaec2b1dSChao Yu 1246aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1247aaec2b1dSChao Yu { 1248aaec2b1dSChao Yu unsigned int ckpt_flags; 1249aaec2b1dSChao Yu 1250aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 125125ca923bSJaegeuk Kim ckpt_flags |= f; 125225ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 125325ca923bSJaegeuk Kim } 125425ca923bSJaegeuk Kim 1255aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 125625ca923bSJaegeuk Kim { 1257aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1258aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1259aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1260aaec2b1dSChao Yu } 1261aaec2b1dSChao Yu 1262aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1263aaec2b1dSChao Yu { 1264aaec2b1dSChao Yu unsigned int ckpt_flags; 1265aaec2b1dSChao Yu 1266aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 126725ca923bSJaegeuk Kim ckpt_flags &= (~f); 126825ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 126925ca923bSJaegeuk Kim } 127025ca923bSJaegeuk Kim 1271aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1272aaec2b1dSChao Yu { 1273aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1274aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1275aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1276aaec2b1dSChao Yu } 1277aaec2b1dSChao Yu 127822ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 127922ad0b6aSJaegeuk Kim { 128022ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 128122ad0b6aSJaegeuk Kim 128222ad0b6aSJaegeuk Kim if (lock) 128322ad0b6aSJaegeuk Kim spin_lock(&sbi->cp_lock); 128422ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 128522ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 128622ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 128722ad0b6aSJaegeuk Kim if (lock) 128822ad0b6aSJaegeuk Kim spin_unlock(&sbi->cp_lock); 128922ad0b6aSJaegeuk Kim } 129022ad0b6aSJaegeuk Kim 129122ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 129222ad0b6aSJaegeuk Kim struct cp_control *cpc) 129322ad0b6aSJaegeuk Kim { 129422ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 129522ad0b6aSJaegeuk Kim 1296c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 129722ad0b6aSJaegeuk Kim } 129822ad0b6aSJaegeuk Kim 1299e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 130039a53e0cSJaegeuk Kim { 1301b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 130239a53e0cSJaegeuk Kim } 130339a53e0cSJaegeuk Kim 1304cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1305cc15620bSJaegeuk Kim { 1306cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1307cc15620bSJaegeuk Kim } 1308cc15620bSJaegeuk Kim 1309e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 131039a53e0cSJaegeuk Kim { 1311b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 131239936837SJaegeuk Kim } 131339936837SJaegeuk Kim 1314e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 131539936837SJaegeuk Kim { 1316b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 131739936837SJaegeuk Kim } 131839936837SJaegeuk Kim 1319e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 132039936837SJaegeuk Kim { 1321b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 132239a53e0cSJaegeuk Kim } 132339a53e0cSJaegeuk Kim 1324119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1325119ee914SJaegeuk Kim { 1326119ee914SJaegeuk Kim int reason = CP_SYNC; 1327119ee914SJaegeuk Kim 1328119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1329119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1330119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1331119ee914SJaegeuk Kim reason = CP_UMOUNT; 1332119ee914SJaegeuk Kim return reason; 1333119ee914SJaegeuk Kim } 1334119ee914SJaegeuk Kim 1335119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1336119ee914SJaegeuk Kim { 1337c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1338119ee914SJaegeuk Kim } 1339119ee914SJaegeuk Kim 1340119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1341119ee914SJaegeuk Kim { 1342aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1343aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1344119ee914SJaegeuk Kim } 1345119ee914SJaegeuk Kim 134639a53e0cSJaegeuk Kim /* 134739a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 134839a53e0cSJaegeuk Kim */ 1349064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 135039a53e0cSJaegeuk Kim { 1351d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1352d6b7d4b3SChao Yu return -EINVAL; 1353cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1354064e0823SNamjae Jeon return -EINVAL; 1355064e0823SNamjae Jeon return 0; 135639a53e0cSJaegeuk Kim } 135739a53e0cSJaegeuk Kim 135839a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 135939a53e0cSJaegeuk Kim 136039a53e0cSJaegeuk Kim /* 136139a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 136239a53e0cSJaegeuk Kim */ 136339a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 136439a53e0cSJaegeuk Kim { 13650eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 13660eb0adadSChao Yu 13670eb0adadSChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > 13680eb0adadSChao Yu (F2FS_DEFAULT_ALLOCATED_BLOCKS + xattr_block); 136939a53e0cSJaegeuk Kim } 137039a53e0cSJaegeuk Kim 13714bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 13724bc8e9bcSChao Yu { 13734bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 13744bc8e9bcSChao Yu } 13754bc8e9bcSChao Yu 13760eb0adadSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool); 137739a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 137846008c6dSChao Yu struct inode *inode, blkcnt_t *count) 137939a53e0cSJaegeuk Kim { 1380dd11a5dfSJaegeuk Kim blkcnt_t diff; 1381*daeb433eSChao Yu block_t avail_user_block_count; 1382dd11a5dfSJaegeuk Kim 1383cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 138455523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 138555523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 1386cb78942bSJaegeuk Kim return false; 138755523519SChao Yu } 1388cb78942bSJaegeuk Kim #endif 1389dd11a5dfSJaegeuk Kim /* 1390dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1391dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1392dd11a5dfSJaegeuk Kim */ 1393dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1394cfb271d4SChao Yu 139539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13962555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 1397*daeb433eSChao Yu avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks; 1398*daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1399*daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 1400dd11a5dfSJaegeuk Kim *count -= diff; 1401*daeb433eSChao Yu sbi->total_valid_block_count = avail_user_block_count; 140246008c6dSChao Yu if (!*count) { 140339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1404dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 140539a53e0cSJaegeuk Kim return false; 140639a53e0cSJaegeuk Kim } 140746008c6dSChao Yu } 140839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 140941382ec4SJaegeuk Kim 14102555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, *count, true); 141139a53e0cSJaegeuk Kim return true; 141239a53e0cSJaegeuk Kim } 141339a53e0cSJaegeuk Kim 1414da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 141539a53e0cSJaegeuk Kim struct inode *inode, 14160eb0adadSChao Yu block_t count) 141739a53e0cSJaegeuk Kim { 14180eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 14190eb0adadSChao Yu 142039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 14219850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 14220eb0adadSChao Yu f2fs_bug_on(sbi, inode->i_blocks < sectors); 142339a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 142439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 14252555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, count, false); 142639a53e0cSJaegeuk Kim } 142739a53e0cSJaegeuk Kim 142839a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 142939a53e0cSJaegeuk Kim { 143035782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 14317c4abcbeSChao Yu 143236951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 143336951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 14347c4abcbeSChao Yu return; 14357c4abcbeSChao Yu 1436caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 143739a53e0cSJaegeuk Kim } 143839a53e0cSJaegeuk Kim 1439a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 144039a53e0cSJaegeuk Kim { 1441204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1442c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1443c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 144439a53e0cSJaegeuk Kim } 144539a53e0cSJaegeuk Kim 144639a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 144739a53e0cSJaegeuk Kim { 144835782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 144939a53e0cSJaegeuk Kim } 145039a53e0cSJaegeuk Kim 1451a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 145239a53e0cSJaegeuk Kim { 14535ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 14545ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 14551fe54f9dSJaegeuk Kim return; 14561fe54f9dSJaegeuk Kim 1457204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1458c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1459c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 146039a53e0cSJaegeuk Kim } 146139a53e0cSJaegeuk Kim 1462523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 146339a53e0cSJaegeuk Kim { 146435782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 146539a53e0cSJaegeuk Kim } 146639a53e0cSJaegeuk Kim 1467204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1468f8b2c1f9SJaegeuk Kim { 1469204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1470f8b2c1f9SJaegeuk Kim } 1471f8b2c1f9SJaegeuk Kim 14725ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 14735ac206cfSNamjae Jeon { 14743519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1475523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1476523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1477523be8a6SJaegeuk Kim 1478523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 14795ac206cfSNamjae Jeon } 14805ac206cfSNamjae Jeon 148139a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 148239a53e0cSJaegeuk Kim { 14838b8343faSJaegeuk Kim return sbi->total_valid_block_count; 148439a53e0cSJaegeuk Kim } 148539a53e0cSJaegeuk Kim 1486f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1487f83a2584SYunlei He { 1488f83a2584SYunlei He return sbi->discard_blks; 1489f83a2584SYunlei He } 1490f83a2584SYunlei He 149139a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 149239a53e0cSJaegeuk Kim { 149339a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 149439a53e0cSJaegeuk Kim 149539a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 149639a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 149739a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 149839a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 149939a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 150039a53e0cSJaegeuk Kim 150139a53e0cSJaegeuk Kim return 0; 150239a53e0cSJaegeuk Kim } 150339a53e0cSJaegeuk Kim 150455141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 150555141486SWanpeng Li { 150655141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 150755141486SWanpeng Li } 150855141486SWanpeng Li 150939a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 151039a53e0cSJaegeuk Kim { 151139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 15121dbe4152SChangman Lee int offset; 15131dbe4152SChangman Lee 151455141486SWanpeng Li if (__cp_payload(sbi) > 0) { 15151dbe4152SChangman Lee if (flag == NAT_BITMAP) 15161dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 15171dbe4152SChangman Lee else 151865b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 15191dbe4152SChangman Lee } else { 15201dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 152125ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 152239a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 152339a53e0cSJaegeuk Kim } 15241dbe4152SChangman Lee } 152539a53e0cSJaegeuk Kim 152639a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 152739a53e0cSJaegeuk Kim { 15288508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 152939a53e0cSJaegeuk Kim 15308508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 153139a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 153239a53e0cSJaegeuk Kim return start_addr; 153339a53e0cSJaegeuk Kim } 153439a53e0cSJaegeuk Kim 15358508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 15368508e44aSJaegeuk Kim { 15378508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 15388508e44aSJaegeuk Kim 15398508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 15408508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 15418508e44aSJaegeuk Kim return start_addr; 15428508e44aSJaegeuk Kim } 15438508e44aSJaegeuk Kim 15448508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 15458508e44aSJaegeuk Kim { 15468508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 15478508e44aSJaegeuk Kim } 15488508e44aSJaegeuk Kim 154939a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 155039a53e0cSJaegeuk Kim { 155139a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 155239a53e0cSJaegeuk Kim } 155339a53e0cSJaegeuk Kim 155439a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1555ef86d709SGu Zheng struct inode *inode) 155639a53e0cSJaegeuk Kim { 155739a53e0cSJaegeuk Kim block_t valid_block_count; 155839a53e0cSJaegeuk Kim unsigned int valid_node_count; 155939a53e0cSJaegeuk Kim 156039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 156139a53e0cSJaegeuk Kim 1562ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1563*daeb433eSChao Yu if (unlikely(valid_block_count + sbi->reserved_blocks > 1564*daeb433eSChao Yu sbi->user_block_count)) { 156539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 156639a53e0cSJaegeuk Kim return false; 156739a53e0cSJaegeuk Kim } 156839a53e0cSJaegeuk Kim 1569ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1570cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 157139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 157239a53e0cSJaegeuk Kim return false; 157339a53e0cSJaegeuk Kim } 157439a53e0cSJaegeuk Kim 157539a53e0cSJaegeuk Kim if (inode) 15768edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, true); 1577ef86d709SGu Zheng 1578ef86d709SGu Zheng sbi->total_valid_node_count++; 1579ef86d709SGu Zheng sbi->total_valid_block_count++; 158039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 158139a53e0cSJaegeuk Kim 158241382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 158339a53e0cSJaegeuk Kim return true; 158439a53e0cSJaegeuk Kim } 158539a53e0cSJaegeuk Kim 158639a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1587ef86d709SGu Zheng struct inode *inode) 158839a53e0cSJaegeuk Kim { 158939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 159039a53e0cSJaegeuk Kim 15919850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 15929850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 15939850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 159439a53e0cSJaegeuk Kim 15958edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, false); 1596ef86d709SGu Zheng sbi->total_valid_node_count--; 1597ef86d709SGu Zheng sbi->total_valid_block_count--; 159839a53e0cSJaegeuk Kim 159939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 160039a53e0cSJaegeuk Kim } 160139a53e0cSJaegeuk Kim 160239a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 160339a53e0cSJaegeuk Kim { 16048b8343faSJaegeuk Kim return sbi->total_valid_node_count; 160539a53e0cSJaegeuk Kim } 160639a53e0cSJaegeuk Kim 160739a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 160839a53e0cSJaegeuk Kim { 1609513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 161039a53e0cSJaegeuk Kim } 161139a53e0cSJaegeuk Kim 16120e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 161339a53e0cSJaegeuk Kim { 1614513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 161539a53e0cSJaegeuk Kim } 161639a53e0cSJaegeuk Kim 1617513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 161839a53e0cSJaegeuk Kim { 1619513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 162039a53e0cSJaegeuk Kim } 162139a53e0cSJaegeuk Kim 1622a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1623a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1624a56c7c6fSJaegeuk Kim { 1625c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1626c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1627cac5a3d8SDongOh Shin 1628c41f3cc3SJaegeuk Kim if (page) 1629c41f3cc3SJaegeuk Kim return page; 1630c41f3cc3SJaegeuk Kim 163155523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 163255523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1633c41f3cc3SJaegeuk Kim return NULL; 163455523519SChao Yu } 1635c41f3cc3SJaegeuk Kim #endif 1636a56c7c6fSJaegeuk Kim if (!for_write) 1637a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1638a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1639a56c7c6fSJaegeuk Kim } 1640a56c7c6fSJaegeuk Kim 16416e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 16426e2c64adSJaegeuk Kim { 16436e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 16446e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 16456e2c64adSJaegeuk Kim 16466e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 16476e2c64adSJaegeuk Kim kunmap(dst); 16486e2c64adSJaegeuk Kim kunmap(src); 16496e2c64adSJaegeuk Kim } 16506e2c64adSJaegeuk Kim 165139a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 165239a53e0cSJaegeuk Kim { 1653031fa8ccSJaegeuk Kim if (!page) 165439a53e0cSJaegeuk Kim return; 165539a53e0cSJaegeuk Kim 165639a53e0cSJaegeuk Kim if (unlock) { 16579850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 165839a53e0cSJaegeuk Kim unlock_page(page); 165939a53e0cSJaegeuk Kim } 166009cbfeafSKirill A. Shutemov put_page(page); 166139a53e0cSJaegeuk Kim } 166239a53e0cSJaegeuk Kim 166339a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 166439a53e0cSJaegeuk Kim { 166539a53e0cSJaegeuk Kim if (dn->node_page) 166639a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 166739a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 166839a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 166939a53e0cSJaegeuk Kim dn->node_page = NULL; 167039a53e0cSJaegeuk Kim dn->inode_page = NULL; 167139a53e0cSJaegeuk Kim } 167239a53e0cSJaegeuk Kim 167339a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1674e8512d2eSGu Zheng size_t size) 167539a53e0cSJaegeuk Kim { 1676e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 167739a53e0cSJaegeuk Kim } 167839a53e0cSJaegeuk Kim 16797bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 16807bd59381SGu Zheng gfp_t flags) 16817bd59381SGu Zheng { 16827bd59381SGu Zheng void *entry; 16837bd59381SGu Zheng 168480c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 168580c54505SJaegeuk Kim if (!entry) 168680c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 16877bd59381SGu Zheng return entry; 16887bd59381SGu Zheng } 16897bd59381SGu Zheng 1690740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1691740432f8SJaegeuk Kim { 1692740432f8SJaegeuk Kim struct bio *bio; 1693740432f8SJaegeuk Kim 1694740432f8SJaegeuk Kim /* No failure on bio allocation */ 1695740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 169680c54505SJaegeuk Kim if (!bio) 169780c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1698740432f8SJaegeuk Kim return bio; 1699740432f8SJaegeuk Kim } 1700740432f8SJaegeuk Kim 17019be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 17029be32d72SJaegeuk Kim unsigned long index, void *item) 17039be32d72SJaegeuk Kim { 17049be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 17059be32d72SJaegeuk Kim cond_resched(); 17069be32d72SJaegeuk Kim } 17079be32d72SJaegeuk Kim 170839a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 170939a53e0cSJaegeuk Kim 171039a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 171139a53e0cSJaegeuk Kim { 171245590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1713cac5a3d8SDongOh Shin 171439a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 171539a53e0cSJaegeuk Kim } 171639a53e0cSJaegeuk Kim 171739a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 171839a53e0cSJaegeuk Kim { 171939a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 172039a53e0cSJaegeuk Kim } 172139a53e0cSJaegeuk Kim 172239a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 172339a53e0cSJaegeuk Kim unsigned int offset) 172439a53e0cSJaegeuk Kim { 172539a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 172639a53e0cSJaegeuk Kim __le32 *addr_array; 1727cac5a3d8SDongOh Shin 172845590710SGu Zheng raw_node = F2FS_NODE(node_page); 172939a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 173039a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 173139a53e0cSJaegeuk Kim } 173239a53e0cSJaegeuk Kim 173339a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 173439a53e0cSJaegeuk Kim { 173539a53e0cSJaegeuk Kim int mask; 173639a53e0cSJaegeuk Kim 173739a53e0cSJaegeuk Kim addr += (nr >> 3); 173839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 173939a53e0cSJaegeuk Kim return mask & *addr; 174039a53e0cSJaegeuk Kim } 174139a53e0cSJaegeuk Kim 1742a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1743a66cdd98SJaegeuk Kim { 1744a66cdd98SJaegeuk Kim int mask; 1745a66cdd98SJaegeuk Kim 1746a66cdd98SJaegeuk Kim addr += (nr >> 3); 1747a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1748a66cdd98SJaegeuk Kim *addr |= mask; 1749a66cdd98SJaegeuk Kim } 1750a66cdd98SJaegeuk Kim 1751a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1752a66cdd98SJaegeuk Kim { 1753a66cdd98SJaegeuk Kim int mask; 1754a66cdd98SJaegeuk Kim 1755a66cdd98SJaegeuk Kim addr += (nr >> 3); 1756a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1757a66cdd98SJaegeuk Kim *addr &= ~mask; 1758a66cdd98SJaegeuk Kim } 1759a66cdd98SJaegeuk Kim 176052aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 176139a53e0cSJaegeuk Kim { 176239a53e0cSJaegeuk Kim int mask; 176339a53e0cSJaegeuk Kim int ret; 176439a53e0cSJaegeuk Kim 176539a53e0cSJaegeuk Kim addr += (nr >> 3); 176639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 176739a53e0cSJaegeuk Kim ret = mask & *addr; 176839a53e0cSJaegeuk Kim *addr |= mask; 176939a53e0cSJaegeuk Kim return ret; 177039a53e0cSJaegeuk Kim } 177139a53e0cSJaegeuk Kim 177252aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 177339a53e0cSJaegeuk Kim { 177439a53e0cSJaegeuk Kim int mask; 177539a53e0cSJaegeuk Kim int ret; 177639a53e0cSJaegeuk Kim 177739a53e0cSJaegeuk Kim addr += (nr >> 3); 177839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 177939a53e0cSJaegeuk Kim ret = mask & *addr; 178039a53e0cSJaegeuk Kim *addr &= ~mask; 178139a53e0cSJaegeuk Kim return ret; 178239a53e0cSJaegeuk Kim } 178339a53e0cSJaegeuk Kim 1784c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1785c6ac4c0eSGu Zheng { 1786c6ac4c0eSGu Zheng int mask; 1787c6ac4c0eSGu Zheng 1788c6ac4c0eSGu Zheng addr += (nr >> 3); 1789c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1790c6ac4c0eSGu Zheng *addr ^= mask; 1791c6ac4c0eSGu Zheng } 1792c6ac4c0eSGu Zheng 179339a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 179439a53e0cSJaegeuk Kim enum { 179539a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1796b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 179726de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1798ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 179939a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 180039a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 180139a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1802c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1803c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1804444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 18051001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 180634d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1807fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1808fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 180988b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 181088b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 18115fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 181202a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 18133c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 18141e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1815b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1816510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1817d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1818c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 1819dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 1820ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 182139a53e0cSJaegeuk Kim }; 182239a53e0cSJaegeuk Kim 1823205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 1824205b9822SJaegeuk Kim int flag, bool set) 182539a53e0cSJaegeuk Kim { 1826205b9822SJaegeuk Kim switch (flag) { 1827205b9822SJaegeuk Kim case FI_INLINE_XATTR: 1828205b9822SJaegeuk Kim case FI_INLINE_DATA: 1829205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 1830205b9822SJaegeuk Kim if (set) 1831205b9822SJaegeuk Kim return; 1832205b9822SJaegeuk Kim case FI_DATA_EXIST: 1833205b9822SJaegeuk Kim case FI_INLINE_DOTS: 18347c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1835205b9822SJaegeuk Kim } 183639a53e0cSJaegeuk Kim } 183739a53e0cSJaegeuk Kim 183891942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 183939a53e0cSJaegeuk Kim { 184091942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 184191942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 1842205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 184339a53e0cSJaegeuk Kim } 184439a53e0cSJaegeuk Kim 184591942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 184639a53e0cSJaegeuk Kim { 184791942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 184839a53e0cSJaegeuk Kim } 184939a53e0cSJaegeuk Kim 185091942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 185139a53e0cSJaegeuk Kim { 185291942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 185391942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 1854205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 185539a53e0cSJaegeuk Kim } 185639a53e0cSJaegeuk Kim 185791942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 1858444c580fSJaegeuk Kim { 185991942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 186091942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 18617c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 186239a53e0cSJaegeuk Kim } 186339a53e0cSJaegeuk Kim 1864a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 1865a1961246SJaegeuk Kim { 1866a1961246SJaegeuk Kim if (inc) 1867a1961246SJaegeuk Kim inc_nlink(inode); 1868a1961246SJaegeuk Kim else 1869a1961246SJaegeuk Kim drop_nlink(inode); 18707c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1871a1961246SJaegeuk Kim } 1872a1961246SJaegeuk Kim 18738edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 18740eb0adadSChao Yu block_t diff, bool add) 18758edd03c8SJaegeuk Kim { 187626de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 187726de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 18780eb0adadSChao Yu blkcnt_t sectors = diff << F2FS_LOG_SECTORS_PER_BLOCK; 187926de9b11SJaegeuk Kim 18800eb0adadSChao Yu inode->i_blocks = add ? inode->i_blocks + sectors : 18810eb0adadSChao Yu inode->i_blocks - sectors; 18827c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 188326de9b11SJaegeuk Kim if (clean || recover) 188426de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 18858edd03c8SJaegeuk Kim } 18868edd03c8SJaegeuk Kim 1887fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 1888fc9581c8SJaegeuk Kim { 188926de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 189026de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 189126de9b11SJaegeuk Kim 1892fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 1893fc9581c8SJaegeuk Kim return; 1894fc9581c8SJaegeuk Kim 1895fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 18967c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 189726de9b11SJaegeuk Kim if (clean || recover) 189826de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 189926de9b11SJaegeuk Kim } 190026de9b11SJaegeuk Kim 1901205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 1902205b9822SJaegeuk Kim { 1903205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 19047c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1905205b9822SJaegeuk Kim } 1906205b9822SJaegeuk Kim 1907205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 1908205b9822SJaegeuk Kim { 1909205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 19107c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1911205b9822SJaegeuk Kim } 1912205b9822SJaegeuk Kim 1913205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 1914205b9822SJaegeuk Kim { 1915205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 19167c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1917205b9822SJaegeuk Kim } 1918205b9822SJaegeuk Kim 191991942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 1920444c580fSJaegeuk Kim { 1921205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 1922205b9822SJaegeuk Kim 1923444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1924205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 19251001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 1926205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 192734d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1928205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 1929b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1930205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 1931510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1932205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 1933444c580fSJaegeuk Kim } 1934444c580fSJaegeuk Kim 193591942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 1936444c580fSJaegeuk Kim { 1937444c580fSJaegeuk Kim ri->i_inline = 0; 1938444c580fSJaegeuk Kim 193991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 1940444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 194191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 19421001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 194391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 194434d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 194591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 1946b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 194791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 1948510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1949444c580fSJaegeuk Kim } 1950444c580fSJaegeuk Kim 1951987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1952987c7c31SChao Yu { 195391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 1954987c7c31SChao Yu } 1955987c7c31SChao Yu 195681ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1957de93653fSJaegeuk Kim { 195881ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1959de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1960de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1961de93653fSJaegeuk Kim } 1962de93653fSJaegeuk Kim 196365985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 196465985d93SJaegeuk Kim { 1965695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1966cac5a3d8SDongOh Shin 196765985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 196865985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 196965985d93SJaegeuk Kim } 197065985d93SJaegeuk Kim 197165985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 197265985d93SJaegeuk Kim { 1973987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 197465985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 197565985d93SJaegeuk Kim else 197665985d93SJaegeuk Kim return 0; 197765985d93SJaegeuk Kim } 197865985d93SJaegeuk Kim 19790dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 19800dbdc2aeSJaegeuk Kim { 198191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 19820dbdc2aeSJaegeuk Kim } 19830dbdc2aeSJaegeuk Kim 1984b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1985b3d208f9SJaegeuk Kim { 198691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 1987b3d208f9SJaegeuk Kim } 1988b3d208f9SJaegeuk Kim 1989510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1990510022a8SJaegeuk Kim { 199191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 1992510022a8SJaegeuk Kim } 1993510022a8SJaegeuk Kim 199488b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 199588b88a66SJaegeuk Kim { 199691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 199788b88a66SJaegeuk Kim } 199888b88a66SJaegeuk Kim 19995fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 20005fe45743SChao Yu { 20015fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 20025fe45743SChao Yu } 20035fe45743SChao Yu 200402a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 200502a1335fSJaegeuk Kim { 200691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 200702a1335fSJaegeuk Kim } 200802a1335fSJaegeuk Kim 20093c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 20103c6c2bebSJaegeuk Kim { 201191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 20123c6c2bebSJaegeuk Kim } 20133c6c2bebSJaegeuk Kim 20141e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 20151e84371fSJaegeuk Kim { 201691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 20171e84371fSJaegeuk Kim } 20181e84371fSJaegeuk Kim 20191001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 20201001b347SHuajun Li { 2021695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2022cac5a3d8SDongOh Shin 20231001b347SHuajun Li return (void *)&(ri->i_addr[1]); 20241001b347SHuajun Li } 20251001b347SHuajun Li 202634d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 202734d67debSChao Yu { 202891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 202934d67debSChao Yu } 203034d67debSChao Yu 20319486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 20329486ba44SJaegeuk Kim { 20339486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 20349486ba44SJaegeuk Kim kunmap(page); 20359486ba44SJaegeuk Kim } 20369486ba44SJaegeuk Kim 2037b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2038b5492af7SJaegeuk Kim { 2039b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2040b5492af7SJaegeuk Kim } 2041b5492af7SJaegeuk Kim 2042b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2043b5492af7SJaegeuk Kim { 2044b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 20457c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2046b5492af7SJaegeuk Kim } 2047b5492af7SJaegeuk Kim 2048b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2049b5492af7SJaegeuk Kim { 2050b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 20517c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2052b5492af7SJaegeuk Kim } 2053b5492af7SJaegeuk Kim 205426787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 205526787236SJaegeuk Kim { 205626787236SJaegeuk Kim if (dsync) { 205726787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 205826787236SJaegeuk Kim bool ret; 205926787236SJaegeuk Kim 206026787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 206126787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 206226787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 206326787236SJaegeuk Kim return ret; 206426787236SJaegeuk Kim } 206526787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 206626787236SJaegeuk Kim file_keep_isize(inode) || 206726787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 206826787236SJaegeuk Kim return false; 206926787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 2070267378d4SChao Yu } 2071267378d4SChao Yu 2072267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 2073267378d4SChao Yu { 2074267378d4SChao Yu return sb->s_flags & MS_RDONLY; 2075267378d4SChao Yu } 207639a53e0cSJaegeuk Kim 207739a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 207839a53e0cSJaegeuk Kim { 2079aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 208039a53e0cSJaegeuk Kim } 208139a53e0cSJaegeuk Kim 2082eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2083eaa693f4SJaegeuk Kim { 2084eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2085eaa693f4SJaegeuk Kim return true; 2086eaa693f4SJaegeuk Kim 2087eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2088eaa693f4SJaegeuk Kim return true; 2089eaa693f4SJaegeuk Kim 2090eaa693f4SJaegeuk Kim return false; 2091eaa693f4SJaegeuk Kim } 2092eaa693f4SJaegeuk Kim 20933e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 20943e72f721SJaegeuk Kim { 20953e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 209691942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 20973e72f721SJaegeuk Kim return false; 20983e72f721SJaegeuk Kim 2099886f56f9SAl Viro return S_ISREG(inode->i_mode); 21003e72f721SJaegeuk Kim } 21013e72f721SJaegeuk Kim 21021ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 21031ecc0c5cSChao Yu size_t size, gfp_t flags) 21040414b004SJaegeuk Kim { 21052c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 210655523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 210755523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 21082c63feadSJaegeuk Kim return NULL; 210955523519SChao Yu } 21102c63feadSJaegeuk Kim #endif 21110414b004SJaegeuk Kim return kmalloc(size, flags); 21120414b004SJaegeuk Kim } 21130414b004SJaegeuk Kim 211439307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 211539307a8eSJaegeuk Kim { 211639307a8eSJaegeuk Kim void *ret; 211739307a8eSJaegeuk Kim 211839307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 211939307a8eSJaegeuk Kim if (!ret) 212039307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 212139307a8eSJaegeuk Kim return ret; 212239307a8eSJaegeuk Kim } 212339307a8eSJaegeuk Kim 212439307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 212539307a8eSJaegeuk Kim { 212639307a8eSJaegeuk Kim void *ret; 212739307a8eSJaegeuk Kim 212839307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 212939307a8eSJaegeuk Kim if (!ret) 213039307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 213139307a8eSJaegeuk Kim return ret; 213239307a8eSJaegeuk Kim } 213339307a8eSJaegeuk Kim 213439a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 213591942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 213639a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 213739a53e0cSJaegeuk Kim 213839a53e0cSJaegeuk Kim /* 21391e1bb4baSJaegeuk Kim * file.c 214039a53e0cSJaegeuk Kim */ 2141cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2142cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2143cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2144cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2145a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2146a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2147cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2148cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2149cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2150cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2151cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 215239a53e0cSJaegeuk Kim 215339a53e0cSJaegeuk Kim /* 215439a53e0cSJaegeuk Kim * inode.c 215539a53e0cSJaegeuk Kim */ 2156cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2157cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2158cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2159cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2160cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2161cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2162cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2163cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2164cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 216539a53e0cSJaegeuk Kim 216639a53e0cSJaegeuk Kim /* 216739a53e0cSJaegeuk Kim * namei.c 216839a53e0cSJaegeuk Kim */ 216939a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 217039a53e0cSJaegeuk Kim 217139a53e0cSJaegeuk Kim /* 217239a53e0cSJaegeuk Kim * dir.c 217339a53e0cSJaegeuk Kim */ 2174cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2175cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2176cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2177cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2178cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2179cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2180cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2181cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2182cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2183cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2184cac5a3d8SDongOh Shin const struct qstr *new_name, 2185cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2186cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2187cac5a3d8SDongOh Shin unsigned int current_depth); 2188cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2189cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2190cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2191cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2192cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2193cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2194cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2195cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2196cac5a3d8SDongOh Shin struct page **page); 2197cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2198cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2199cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2200cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2201cac5a3d8SDongOh Shin unsigned int bit_pos); 2202cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2203cac5a3d8SDongOh Shin const struct qstr *orig_name, 2204cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2205cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2206cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2207cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2208cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2209cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2210cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2211cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2212cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 221339a53e0cSJaegeuk Kim 2214b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2215b7f7a5e0SAl Viro { 22162b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2217510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2218b7f7a5e0SAl Viro } 2219b7f7a5e0SAl Viro 222039a53e0cSJaegeuk Kim /* 222139a53e0cSJaegeuk Kim * super.c 222239a53e0cSJaegeuk Kim */ 2223cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2224cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2225cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2226cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2227a07ef784SNamjae Jeon extern __printf(3, 4) 2228cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2229984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 223039a53e0cSJaegeuk Kim 223139a53e0cSJaegeuk Kim /* 223239a53e0cSJaegeuk Kim * hash.c 223339a53e0cSJaegeuk Kim */ 22346332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, 22356332cd32SJaegeuk Kim struct fscrypt_name *fname); 223639a53e0cSJaegeuk Kim 223739a53e0cSJaegeuk Kim /* 223839a53e0cSJaegeuk Kim * node.c 223939a53e0cSJaegeuk Kim */ 224039a53e0cSJaegeuk Kim struct dnode_of_data; 224139a53e0cSJaegeuk Kim struct node_info; 224239a53e0cSJaegeuk Kim 2243cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2244cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2245cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2246cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2247cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2248cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2249cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2250cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2251cac5a3d8SDongOh Shin int truncate_xattr_node(struct inode *inode, struct page *page); 2252cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2253cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2254cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 2255cac5a3d8SDongOh Shin struct page *new_node_page(struct dnode_of_data *dn, 2256cac5a3d8SDongOh Shin unsigned int ofs, struct page *ipage); 2257cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2258cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2259cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2260cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2261cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2262cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2263cac5a3d8SDongOh Shin int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc); 226422ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2265cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2266cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2267cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2268cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2269cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2270d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2271cac5a3d8SDongOh Shin block_t blkaddr); 2272cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2273cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2274cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 227522ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2276cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2277cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 22786e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 227939a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 228039a53e0cSJaegeuk Kim 228139a53e0cSJaegeuk Kim /* 228239a53e0cSJaegeuk Kim * segment.c 228339a53e0cSJaegeuk Kim */ 2284cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 2285cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 22868c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2287cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2288cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2289cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2290cac5a3d8SDongOh Shin int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2291cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2292cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2293cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2294cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2295cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2296d431413fSChao Yu void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2297cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2298cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2299cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2300cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2301cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2302cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2303cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2304cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2305cac5a3d8SDongOh Shin void write_meta_page(struct f2fs_sb_info *sbi, struct page *page); 2306cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2307cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2308d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2309cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2310cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2311cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2312cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2313cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2314cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2315cac5a3d8SDongOh Shin bool recover_newaddr); 2316cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2317cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2318fb830fc5SChao Yu struct f2fs_summary *sum, int type, 2319fb830fc5SChao Yu struct f2fs_io_info *fio, bool add_list); 2320cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2321cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2322cac5a3d8SDongOh Shin void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2323cac5a3d8SDongOh Shin block_t blkaddr); 2324cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2325cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2326cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2327cac5a3d8SDongOh Shin unsigned int val, int alloc); 2328cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2329cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2330cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 23317fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 23327fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 233339a53e0cSJaegeuk Kim 233439a53e0cSJaegeuk Kim /* 233539a53e0cSJaegeuk Kim * checkpoint.c 233639a53e0cSJaegeuk Kim */ 2337cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2338cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2339cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2340cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2341cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2342cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2343cac5a3d8SDongOh Shin int type, bool sync); 2344cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2345cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2346cac5a3d8SDongOh Shin long nr_to_write); 2347cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2348cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2349cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2350cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2351cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2352cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2353cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2354cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2355cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2356cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2357cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2358cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2359cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2360cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2361cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2362cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 23636e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 236439a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 236539a53e0cSJaegeuk Kim 236639a53e0cSJaegeuk Kim /* 236739a53e0cSJaegeuk Kim * data.c 236839a53e0cSJaegeuk Kim */ 2369b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 2370b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 2371942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2372b9109b0eSJaegeuk Kim enum page_type type); 2373b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 2374cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2375b9109b0eSJaegeuk Kim int f2fs_submit_page_write(struct f2fs_io_info *fio); 2376cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2377cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2378cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2379cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2380cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2381cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2382cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2383cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2384cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2385cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2386cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2387cac5a3d8SDongOh Shin int op_flags, bool for_write); 2388cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2389cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2390cac5a3d8SDongOh Shin bool for_write); 2391cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2392cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2393cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2394cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2395cac5a3d8SDongOh Shin int create, int flag); 2396cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2397cac5a3d8SDongOh Shin u64 start, u64 len); 2398cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2399cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2400cac5a3d8SDongOh Shin unsigned int length); 2401cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 24025b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2403cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2404cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 24055b7a487cSWeichao Guo #endif 240639a53e0cSJaegeuk Kim 240739a53e0cSJaegeuk Kim /* 240839a53e0cSJaegeuk Kim * gc.c 240939a53e0cSJaegeuk Kim */ 2410cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2411cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2412cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2413e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 2414e066b83cSJaegeuk Kim unsigned int segno); 2415cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 241639a53e0cSJaegeuk Kim 241739a53e0cSJaegeuk Kim /* 241839a53e0cSJaegeuk Kim * recovery.c 241939a53e0cSJaegeuk Kim */ 2420cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2421cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 242239a53e0cSJaegeuk Kim 242339a53e0cSJaegeuk Kim /* 242439a53e0cSJaegeuk Kim * debug.c 242539a53e0cSJaegeuk Kim */ 242639a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 242739a53e0cSJaegeuk Kim struct f2fs_stat_info { 242839a53e0cSJaegeuk Kim struct list_head stat_list; 242939a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 243039a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 243139a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 24325b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 24335b7ee374SChao Yu unsigned long long hit_total, total_ext; 2434c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 243535782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 243635782b23SJaegeuk Kim int inmem_pages; 24370f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 24385b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 24395b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 244039a53e0cSJaegeuk Kim int total_count, utilization; 24418b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 24428b8dd65fSChao Yu int nr_flushing, nr_flushed, nr_discarding, nr_discarded; 24435f32366aSChao Yu int nr_discard_cmd; 2444d84d1cbdSChao Yu unsigned int undiscard_blks; 2445a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2446648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2447f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 244839a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 244939a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 245039a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 245139a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 245242190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 245339a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2454e1235983SChangman Lee int bg_node_segs, bg_data_segs; 245539a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2456e1235983SChangman Lee int bg_data_blks, bg_node_blks; 245739a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 245839a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 245939a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 246039a53e0cSJaegeuk Kim 246139a53e0cSJaegeuk Kim unsigned int segment_count[2]; 246239a53e0cSJaegeuk Kim unsigned int block_count[2]; 2463b9a2c252SChangman Lee unsigned int inplace_count; 24649edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 246539a53e0cSJaegeuk Kim }; 246639a53e0cSJaegeuk Kim 2467963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2468963d4f7dSGu Zheng { 2469963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2470963d4f7dSGu Zheng } 2471963d4f7dSGu Zheng 2472942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 247342190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 247439a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2475dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 247633fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 247733fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 24785b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 24795b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 24805b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 24815b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2482d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2483d5e8f6c9SChao Yu do { \ 2484d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2485d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2486d5e8f6c9SChao Yu } while (0) 2487d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2488d5e8f6c9SChao Yu do { \ 2489d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2490d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2491d5e8f6c9SChao Yu } while (0) 24920dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 24930dbdc2aeSJaegeuk Kim do { \ 24940dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 249503e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 24960dbdc2aeSJaegeuk Kim } while (0) 24970dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 24980dbdc2aeSJaegeuk Kim do { \ 24990dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 250003e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 25010dbdc2aeSJaegeuk Kim } while (0) 25023289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 25033289c061SJaegeuk Kim do { \ 25043289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 250503e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 25063289c061SJaegeuk Kim } while (0) 25073289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 25083289c061SJaegeuk Kim do { \ 25093289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 251003e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 25113289c061SJaegeuk Kim } while (0) 2512dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2513dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2514dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2515dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2516b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2517b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 251826a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2519cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 252026a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2521cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 252226a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 252326a28a0cSJaegeuk Kim do { \ 252426a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 252526a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 252626a28a0cSJaegeuk Kim if (cur > max) \ 252726a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 252826a28a0cSJaegeuk Kim } while (0) 2529648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2530648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2531648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2532648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2533648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2534648d50baSChao Yu do { \ 2535648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2536648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2537648d50baSChao Yu if (cur > max) \ 2538648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2539648d50baSChao Yu } while (0) 2540e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 254139a53e0cSJaegeuk Kim do { \ 2542963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 254368afcf2dSTomohiro Kusumi si->tot_segs++; \ 254468afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 254539a53e0cSJaegeuk Kim si->data_segs++; \ 2546e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2547e1235983SChangman Lee } else { \ 254839a53e0cSJaegeuk Kim si->node_segs++; \ 2549e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2550e1235983SChangman Lee } \ 255139a53e0cSJaegeuk Kim } while (0) 255239a53e0cSJaegeuk Kim 255339a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 255468afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 255539a53e0cSJaegeuk Kim 2556e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 255739a53e0cSJaegeuk Kim do { \ 2558963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 255939a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 256039a53e0cSJaegeuk Kim si->data_blks += (blks); \ 256168afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 256239a53e0cSJaegeuk Kim } while (0) 256339a53e0cSJaegeuk Kim 2564e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 256539a53e0cSJaegeuk Kim do { \ 2566963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 256739a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 256839a53e0cSJaegeuk Kim si->node_blks += (blks); \ 256968afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 257039a53e0cSJaegeuk Kim } while (0) 257139a53e0cSJaegeuk Kim 2572cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2573cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2574787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 25754589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 257639a53e0cSJaegeuk Kim #else 2577d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 2578d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 2579d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 2580d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 2581d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 2582d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 2583d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 2584d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 2585d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 2586d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 2587d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 2588d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 2589d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 2590d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 2591d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 2592d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 2593d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 2594d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 2595d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 2596d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 2597d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 2598d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 2599d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 2600d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 2601d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 2602d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 2603d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 2604d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 2605d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 260639a53e0cSJaegeuk Kim 260739a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 260839a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2609787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 26104589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 261139a53e0cSJaegeuk Kim #endif 261239a53e0cSJaegeuk Kim 261339a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 261439a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 261539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 261639a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 261739a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 261839a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 261939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 262039a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2621cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 262239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 262329e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 26241001b347SHuajun Li 2625e18c65b2SHuajun Li /* 2626e18c65b2SHuajun Li * inline.c 2627e18c65b2SHuajun Li */ 2628cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2629cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2630cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2631bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2632cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2633cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2634cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2635cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2636cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2637cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2638cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2639cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2640cac5a3d8SDongOh Shin struct page *ipage); 2641cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2642cac5a3d8SDongOh Shin const struct qstr *orig_name, 2643cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2644cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2645cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2646cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2647cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2648cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2649cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2650cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2651cac5a3d8SDongOh Shin __u64 start, __u64 len); 2652cde4de12SJaegeuk Kim 2653cde4de12SJaegeuk Kim /* 26542658e50dSJaegeuk Kim * shrinker.c 26552658e50dSJaegeuk Kim */ 2656cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2657cac5a3d8SDongOh Shin struct shrink_control *sc); 2658cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2659cac5a3d8SDongOh Shin struct shrink_control *sc); 2660cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2661cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 26622658e50dSJaegeuk Kim 26632658e50dSJaegeuk Kim /* 2664a28ef1f5SChao Yu * extent_cache.c 2665a28ef1f5SChao Yu */ 2666004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 2667004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 2668004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 2669004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 2670004b6862SChao Yu unsigned int ofs); 2671004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 2672004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 2673004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 2674004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 2675004b6862SChao Yu bool force); 2676df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi, 2677df0f6b44SChao Yu struct rb_root *root); 2678cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2679cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2680cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2681cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2682cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2683cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2684cac5a3d8SDongOh Shin struct extent_info *ei); 2685cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 268619b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2687cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2688cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2689a28ef1f5SChao Yu int __init create_extent_cache(void); 2690a28ef1f5SChao Yu void destroy_extent_cache(void); 2691a28ef1f5SChao Yu 2692a28ef1f5SChao Yu /* 26938ceffcb2SChao Yu * sysfs.c 26948ceffcb2SChao Yu */ 26958ceffcb2SChao Yu int __init f2fs_register_sysfs(void); 26968ceffcb2SChao Yu void f2fs_unregister_sysfs(void); 26978ceffcb2SChao Yu int f2fs_init_sysfs(struct f2fs_sb_info *sbi); 26988ceffcb2SChao Yu void f2fs_exit_sysfs(struct f2fs_sb_info *sbi); 26998ceffcb2SChao Yu 27008ceffcb2SChao Yu /* 2701cde4de12SJaegeuk Kim * crypto support 2702cde4de12SJaegeuk Kim */ 27030b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2704cde4de12SJaegeuk Kim { 2705cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2706cde4de12SJaegeuk Kim } 2707cde4de12SJaegeuk Kim 2708cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2709cde4de12SJaegeuk Kim { 2710cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2711cde4de12SJaegeuk Kim file_set_encrypt(inode); 2712cde4de12SJaegeuk Kim #endif 2713cde4de12SJaegeuk Kim } 2714cde4de12SJaegeuk Kim 2715cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2716cde4de12SJaegeuk Kim { 27170b81d077SJaegeuk Kim return bio->bi_private != NULL; 2718cde4de12SJaegeuk Kim } 2719cde4de12SJaegeuk Kim 2720cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2721cde4de12SJaegeuk Kim { 2722cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2723cde4de12SJaegeuk Kim } 2724f424f664SJaegeuk Kim 27250bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 272652763a4bSJaegeuk Kim { 27270bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 272852763a4bSJaegeuk Kim } 272952763a4bSJaegeuk Kim 2730178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2731178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 27323c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2733178053e2SDamien Le Moal { 2734178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 27353c62be17SJaegeuk Kim int i; 2736178053e2SDamien Le Moal 27373c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 27383c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 27393c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 27403c62be17SJaegeuk Kim return -EINVAL; 2741178053e2SDamien Le Moal } 2742178053e2SDamien Le Moal #endif 2743178053e2SDamien Le Moal 274496ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 274596ba2decSDamien Le Moal { 274696ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 274796ba2decSDamien Le Moal 274896ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 274952763a4bSJaegeuk Kim } 275052763a4bSJaegeuk Kim 275152763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 275252763a4bSJaegeuk Kim { 275352763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 275452763a4bSJaegeuk Kim clear_opt(sbi, LFS); 275552763a4bSJaegeuk Kim 275652763a4bSJaegeuk Kim switch (mt) { 275752763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 275852763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 275952763a4bSJaegeuk Kim break; 276052763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 276152763a4bSJaegeuk Kim set_opt(sbi, LFS); 276252763a4bSJaegeuk Kim break; 276352763a4bSJaegeuk Kim } 276452763a4bSJaegeuk Kim } 276552763a4bSJaegeuk Kim 2766fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2767fcc85a4dSJaegeuk Kim { 2768fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2769886f56f9SAl Viro umode_t mode = inode->i_mode; 2770fcc85a4dSJaegeuk Kim 2771fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2772fcc85a4dSJaegeuk Kim #else 2773fcc85a4dSJaegeuk Kim return 0; 2774fcc85a4dSJaegeuk Kim #endif 2775fcc85a4dSJaegeuk Kim } 2776fcc85a4dSJaegeuk Kim 277739a53e0cSJaegeuk Kim #endif 2778