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) 30688b88a66SJaegeuk Kim 3070b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 3080b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 3090b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 310f424f664SJaegeuk Kim 3111abff93dSJaegeuk Kim /* 3121abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 3131abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 3141abff93dSJaegeuk Kim */ 3151abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 3161abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 3171abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 3181abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 319c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 3201abff93dSJaegeuk Kim 321e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 322e9750824SNamjae Jeon /* 323e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 324e9750824SNamjae Jeon */ 325e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 326e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 32704ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 328e9750824SNamjae Jeon #endif 329e9750824SNamjae Jeon 330d323d005SChao Yu struct f2fs_defragment { 331d323d005SChao Yu u64 start; 332d323d005SChao Yu u64 len; 333d323d005SChao Yu }; 334d323d005SChao Yu 3354dd6f977SJaegeuk Kim struct f2fs_move_range { 3364dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3374dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3384dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3394dd6f977SJaegeuk Kim u64 len; /* size to move */ 3404dd6f977SJaegeuk Kim }; 3414dd6f977SJaegeuk Kim 342e066b83cSJaegeuk Kim struct f2fs_flush_device { 343e066b83cSJaegeuk Kim u32 dev_num; /* device number to flush */ 344e066b83cSJaegeuk Kim u32 segments; /* # of segments to flush */ 345e066b83cSJaegeuk Kim }; 346e066b83cSJaegeuk Kim 347e9750824SNamjae Jeon /* 34839a53e0cSJaegeuk Kim * For INODE and NODE manager 34939a53e0cSJaegeuk Kim */ 3507b3cd7d6SJaegeuk Kim /* for directory operations */ 3517b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 352d8c6822aSJaegeuk Kim struct inode *inode; 3537b3cd7d6SJaegeuk Kim const void *bitmap; 3547b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 3557b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 3567b3cd7d6SJaegeuk Kim int max; 3577b3cd7d6SJaegeuk Kim }; 3587b3cd7d6SJaegeuk Kim 35964c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 36064c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 3617b3cd7d6SJaegeuk Kim { 362d8c6822aSJaegeuk Kim d->inode = inode; 3637b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 3647b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3657b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3667b3cd7d6SJaegeuk Kim d->filename = t->filename; 36764c24ecbSTomohiro Kusumi } 368cac5a3d8SDongOh Shin 36964c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 37064c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_inline_dentry *t) 37164c24ecbSTomohiro Kusumi { 37264c24ecbSTomohiro Kusumi d->inode = inode; 3737b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3747b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3757b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3767b3cd7d6SJaegeuk Kim d->filename = t->filename; 3777b3cd7d6SJaegeuk Kim } 3787b3cd7d6SJaegeuk Kim 379dbe6a5ffSJaegeuk Kim /* 380dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 381dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 382dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 38339a53e0cSJaegeuk Kim */ 384dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 385dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 386266e97a8SJaegeuk Kim enum { 387266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 388266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 389266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 390266e97a8SJaegeuk Kim * look up a node with readahead called 3914f4124d0SChao Yu * by get_data_block. 39239a53e0cSJaegeuk Kim */ 393266e97a8SJaegeuk Kim }; 394266e97a8SJaegeuk Kim 395a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 39639a53e0cSJaegeuk Kim 397817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 398817202d9SChao Yu 39913054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 40013054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 40113054c54SChao Yu 40239a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 40313054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 40413054c54SChao Yu 40513054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 40613054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 407c11abd1aSJaegeuk Kim 40854c2258cSChao Yu struct rb_entry { 40954c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 41054c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 41154c2258cSChao Yu unsigned int len; /* length of the entry */ 41254c2258cSChao Yu }; 41354c2258cSChao Yu 41439a53e0cSJaegeuk Kim struct extent_info { 41539a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 416111d2495SMasanari Iida unsigned int len; /* length of the extent */ 41754c2258cSChao Yu u32 blk; /* start block address of the extent */ 41839a53e0cSJaegeuk Kim }; 41939a53e0cSJaegeuk Kim 42013054c54SChao Yu struct extent_node { 42154c2258cSChao Yu struct rb_node rb_node; 42254c2258cSChao Yu union { 42354c2258cSChao Yu struct { 42454c2258cSChao Yu unsigned int fofs; 42554c2258cSChao Yu unsigned int len; 42654c2258cSChao Yu u32 blk; 42754c2258cSChao Yu }; 42813054c54SChao Yu struct extent_info ei; /* extent info */ 42954c2258cSChao Yu 43054c2258cSChao Yu }; 43154c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 432201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 43313054c54SChao Yu }; 43413054c54SChao Yu 43513054c54SChao Yu struct extent_tree { 43613054c54SChao Yu nid_t ino; /* inode number */ 43713054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 43862c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 4393e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 440137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 44113054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 44268e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 44313054c54SChao Yu }; 44413054c54SChao Yu 44539a53e0cSJaegeuk Kim /* 446003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 447003a3e1dSJaegeuk Kim * 448003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 449003a3e1dSJaegeuk Kim */ 450003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 451003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 4527f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 4537f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 4547f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 455003a3e1dSJaegeuk Kim 456003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 457003a3e1dSJaegeuk Kim block_t m_pblk; 458003a3e1dSJaegeuk Kim block_t m_lblk; 459003a3e1dSJaegeuk Kim unsigned int m_len; 460003a3e1dSJaegeuk Kim unsigned int m_flags; 461da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 462003a3e1dSJaegeuk Kim }; 463003a3e1dSJaegeuk Kim 464e2b4e2bcSChao Yu /* for flag in get_data_block */ 465e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 466e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 467e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 468e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 469b439b103SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_DIO 4 47024b84912SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_AIO 5 471e2b4e2bcSChao Yu 472003a3e1dSJaegeuk Kim /* 47339a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 47439a53e0cSJaegeuk Kim */ 47539a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 476354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 477cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 478e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 47926787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 48039a53e0cSJaegeuk Kim 481b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 482b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 483b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 484b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 485b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 486b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 487cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 488cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 489cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 490e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 491e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 49226787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 49326787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 494cde4de12SJaegeuk Kim 495ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 496ab9fa662SJaegeuk Kim 49739a53e0cSJaegeuk Kim struct f2fs_inode_info { 49839a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 49939a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 50039a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 50138431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 50239a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 5036666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 50439a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 50539a53e0cSJaegeuk Kim 50639a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 50739a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 508d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 509204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 51039a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 51139a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 51288c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 51339a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 51426de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 51588b88a66SJaegeuk Kim 5160f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 5170f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 51888b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 51988b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 5203e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 52182e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 5225a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 52339a53e0cSJaegeuk Kim }; 52439a53e0cSJaegeuk Kim 52539a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 526bd933d4fSChao Yu struct f2fs_extent *i_ext) 52739a53e0cSJaegeuk Kim { 528bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 529bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 530bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 53139a53e0cSJaegeuk Kim } 53239a53e0cSJaegeuk Kim 53339a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 53439a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 53539a53e0cSJaegeuk Kim { 53639a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 5374d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 53839a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 53939a53e0cSJaegeuk Kim } 54039a53e0cSJaegeuk Kim 541429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 542429511cdSChao Yu u32 blk, unsigned int len) 543429511cdSChao Yu { 544429511cdSChao Yu ei->fofs = fofs; 545429511cdSChao Yu ei->blk = blk; 546429511cdSChao Yu ei->len = len; 547429511cdSChao Yu } 548429511cdSChao Yu 549004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 550004b6862SChao Yu struct discard_info *front) 551004b6862SChao Yu { 552004b6862SChao Yu return back->lstart + back->len == front->lstart; 553004b6862SChao Yu } 554004b6862SChao Yu 555004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 556004b6862SChao Yu struct discard_info *back) 557004b6862SChao Yu { 558004b6862SChao Yu return __is_discard_mergeable(back, cur); 559004b6862SChao Yu } 560004b6862SChao Yu 561004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 562004b6862SChao Yu struct discard_info *front) 563004b6862SChao Yu { 564004b6862SChao Yu return __is_discard_mergeable(cur, front); 565004b6862SChao Yu } 566004b6862SChao Yu 567429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 568429511cdSChao Yu struct extent_info *front) 569429511cdSChao Yu { 570429511cdSChao Yu return (back->fofs + back->len == front->fofs && 571429511cdSChao Yu back->blk + back->len == front->blk); 572429511cdSChao Yu } 573429511cdSChao Yu 574429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 575429511cdSChao Yu struct extent_info *back) 576429511cdSChao Yu { 577429511cdSChao Yu return __is_extent_mergeable(back, cur); 578429511cdSChao Yu } 579429511cdSChao Yu 580429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 581429511cdSChao Yu struct extent_info *front) 582429511cdSChao Yu { 583429511cdSChao Yu return __is_extent_mergeable(cur, front); 584429511cdSChao Yu } 585429511cdSChao Yu 586cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 587205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 588205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 5894abd3f5aSChao Yu { 590205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 5914abd3f5aSChao Yu et->largest = en->ei; 5927c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 593205b9822SJaegeuk Kim } 5944abd3f5aSChao Yu } 5954abd3f5aSChao Yu 596b8559dc2SChao Yu enum nid_list { 597b8559dc2SChao Yu FREE_NID_LIST, 598b8559dc2SChao Yu ALLOC_NID_LIST, 599b8559dc2SChao Yu MAX_NID_LIST, 600b8559dc2SChao Yu }; 601b8559dc2SChao Yu 60239a53e0cSJaegeuk Kim struct f2fs_nm_info { 60339a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 60439a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 60504d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 60639a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 607cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 608ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 6092304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 61039a53e0cSJaegeuk Kim 61139a53e0cSJaegeuk Kim /* NAT cache management */ 61239a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 613309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 614b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 61539a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 616309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 617aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 61822ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 61939a53e0cSJaegeuk Kim 62039a53e0cSJaegeuk Kim /* free node ids management */ 6218a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 622b8559dc2SChao Yu struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ 623b8559dc2SChao Yu unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 624b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 62539a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 6264ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 6274ac91242SChao Yu unsigned char *nat_block_bitmap; 628586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 62939a53e0cSJaegeuk Kim 63039a53e0cSJaegeuk Kim /* for checkpoint */ 63139a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 63222ad0b6aSJaegeuk Kim 63322ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 63422ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 63522ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 63622ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 637599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 638599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 639599a09b2SChao Yu #endif 64039a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 64139a53e0cSJaegeuk Kim }; 64239a53e0cSJaegeuk Kim 64339a53e0cSJaegeuk Kim /* 64439a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 64539a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 64639a53e0cSJaegeuk Kim * by the data offset in a file. 64739a53e0cSJaegeuk Kim */ 64839a53e0cSJaegeuk Kim struct dnode_of_data { 64939a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 65039a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 65139a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 65239a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 65339a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 65439a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 65593bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 6563cf45747SChao Yu char cur_level; /* level of hole node page */ 6573cf45747SChao Yu char max_level; /* level of current page located */ 65839a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 65939a53e0cSJaegeuk Kim }; 66039a53e0cSJaegeuk Kim 66139a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 66239a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 66339a53e0cSJaegeuk Kim { 664d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 66539a53e0cSJaegeuk Kim dn->inode = inode; 66639a53e0cSJaegeuk Kim dn->inode_page = ipage; 66739a53e0cSJaegeuk Kim dn->node_page = npage; 66839a53e0cSJaegeuk Kim dn->nid = nid; 66939a53e0cSJaegeuk Kim } 67039a53e0cSJaegeuk Kim 67139a53e0cSJaegeuk Kim /* 67239a53e0cSJaegeuk Kim * For SIT manager 67339a53e0cSJaegeuk Kim * 67439a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 67539a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 67639a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 67739a53e0cSJaegeuk Kim * respectively. 67839a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 67939a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 68039a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 68139a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 68239a53e0cSJaegeuk Kim * data and 8 for node logs. 68339a53e0cSJaegeuk Kim */ 68439a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 68539a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 68639a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 68739a53e0cSJaegeuk Kim 68839a53e0cSJaegeuk Kim enum { 68939a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 69039a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 69139a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 69239a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 69339a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 69439a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 69538aa0889SJaegeuk Kim NO_CHECK_TYPE, 69639a53e0cSJaegeuk Kim }; 69739a53e0cSJaegeuk Kim 6986b4afdd7SJaegeuk Kim struct flush_cmd { 6996b4afdd7SJaegeuk Kim struct completion wait; 700721bd4d5SGu Zheng struct llist_node llnode; 7016b4afdd7SJaegeuk Kim int ret; 7026b4afdd7SJaegeuk Kim }; 7036b4afdd7SJaegeuk Kim 704a688b9d9SGu Zheng struct flush_cmd_control { 705a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 706a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 7078b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 7088b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 709721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 710721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 711a688b9d9SGu Zheng }; 712a688b9d9SGu Zheng 71339a53e0cSJaegeuk Kim struct f2fs_sm_info { 71439a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 71539a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 71639a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 71739a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 71839a53e0cSJaegeuk Kim 71939a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 72039a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 72139a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 72239a53e0cSJaegeuk Kim 72339a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 72439a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 72539a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 72639a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 72781eb8d6eSJaegeuk Kim 72881eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 72981eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 7307fd9e544SJaegeuk Kim 731bba681cbSJaegeuk Kim /* for batched trimming */ 732bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 733bba681cbSJaegeuk Kim 734184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 735184a5cd2SChao Yu 736216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 737216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 738c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 739ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 7406b4afdd7SJaegeuk Kim 7416b4afdd7SJaegeuk Kim /* for flush command control */ 742b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 743a688b9d9SGu Zheng 7440b54fb84SJaegeuk Kim /* for discard command control */ 7450b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 74639a53e0cSJaegeuk Kim }; 74739a53e0cSJaegeuk Kim 74839a53e0cSJaegeuk Kim /* 74939a53e0cSJaegeuk Kim * For superblock 75039a53e0cSJaegeuk Kim */ 75139a53e0cSJaegeuk Kim /* 75239a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 75339a53e0cSJaegeuk Kim * 75439a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 75539a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 75639a53e0cSJaegeuk Kim */ 75736951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 75839a53e0cSJaegeuk Kim enum count_type { 75939a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 760c227f912SChao Yu F2FS_DIRTY_DATA, 76139a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 76239a53e0cSJaegeuk Kim F2FS_DIRTY_META, 7638dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 7640f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 76536951b38SChao Yu F2FS_WB_CP_DATA, 76636951b38SChao Yu F2FS_WB_DATA, 76739a53e0cSJaegeuk Kim NR_COUNT_TYPE, 76839a53e0cSJaegeuk Kim }; 76939a53e0cSJaegeuk Kim 77039a53e0cSJaegeuk Kim /* 771e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 77239a53e0cSJaegeuk Kim * The available types are: 77339a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 77439a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 77539a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 77639a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 77739a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 77839a53e0cSJaegeuk Kim * with waiting the bio's completion 77939a53e0cSJaegeuk Kim * ... Only can be used with META. 78039a53e0cSJaegeuk Kim */ 7817d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 78239a53e0cSJaegeuk Kim enum page_type { 78339a53e0cSJaegeuk Kim DATA, 78439a53e0cSJaegeuk Kim NODE, 78539a53e0cSJaegeuk Kim META, 78639a53e0cSJaegeuk Kim NR_PAGE_TYPE, 78739a53e0cSJaegeuk Kim META_FLUSH, 7888ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 7898ce67cb0SJaegeuk Kim INMEM_DROP, 7908c242db9SJaegeuk Kim INMEM_INVALIDATE, 79128bc106bSChao Yu INMEM_REVOKE, 7928ce67cb0SJaegeuk Kim IPU, 7938ce67cb0SJaegeuk Kim OPU, 79439a53e0cSJaegeuk Kim }; 79539a53e0cSJaegeuk Kim 796a912b54dSJaegeuk Kim enum temp_type { 797a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 798a912b54dSJaegeuk Kim WARM, 799a912b54dSJaegeuk Kim COLD, 800a912b54dSJaegeuk Kim NR_TEMP_TYPE, 801a912b54dSJaegeuk Kim }; 802a912b54dSJaegeuk Kim 803cc15620bSJaegeuk Kim enum need_lock_type { 804cc15620bSJaegeuk Kim LOCK_REQ = 0, 805cc15620bSJaegeuk Kim LOCK_DONE, 806cc15620bSJaegeuk Kim LOCK_RETRY, 807cc15620bSJaegeuk Kim }; 808cc15620bSJaegeuk Kim 809458e6197SJaegeuk Kim struct f2fs_io_info { 81005ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 811458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 812a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 81304d328deSMike Christie int op; /* contains REQ_OP_ */ 814ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 8157a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 81628bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 81705ca3632SJaegeuk Kim struct page *page; /* page to be written */ 8184375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 819fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 820d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 821cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 822fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 823458e6197SJaegeuk Kim }; 824458e6197SJaegeuk Kim 82568afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 8261ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 827458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 8281ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 8291ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 830458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 831df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 832fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 833fb830fc5SChao Yu struct list_head io_list; /* track fios */ 8341ff7bd3bSJaegeuk Kim }; 8351ff7bd3bSJaegeuk Kim 8363c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 8373c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 8383c62be17SJaegeuk Kim struct f2fs_dev_info { 8393c62be17SJaegeuk Kim struct block_device *bdev; 8403c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 8413c62be17SJaegeuk Kim unsigned int total_segments; 8423c62be17SJaegeuk Kim block_t start_blk; 8433c62be17SJaegeuk Kim block_t end_blk; 8443c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 8453c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 8463c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 8473c62be17SJaegeuk Kim #endif 8483c62be17SJaegeuk Kim }; 8493c62be17SJaegeuk Kim 850c227f912SChao Yu enum inode_type { 851c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 852c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 8530f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 854c227f912SChao Yu NR_INODE_TYPE, 855c227f912SChao Yu }; 856c227f912SChao Yu 85767298804SChao Yu /* for inner inode cache management */ 85867298804SChao Yu struct inode_management { 85967298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 86067298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 86167298804SChao Yu struct list_head ino_list; /* inode list head */ 86267298804SChao Yu unsigned long ino_num; /* number of entries */ 86367298804SChao Yu }; 86467298804SChao Yu 865caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 866caf0047eSChao Yu enum { 867caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 868caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 869caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 870caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 871df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 872bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 873caf0047eSChao Yu }; 874caf0047eSChao Yu 8756beceb54SJaegeuk Kim enum { 8766beceb54SJaegeuk Kim CP_TIME, 877d0239e1bSJaegeuk Kim REQ_TIME, 8786beceb54SJaegeuk Kim MAX_TIME, 8796beceb54SJaegeuk Kim }; 8806beceb54SJaegeuk Kim 88139a53e0cSJaegeuk Kim struct f2fs_sb_info { 88239a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 8835e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 88439a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 885e8240f65SChao Yu int valid_super_block; /* valid super block no */ 886fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 88739a53e0cSJaegeuk Kim 888178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 889178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 890178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 891178053e2SDamien Le Moal #endif 892178053e2SDamien Le Moal 89339a53e0cSJaegeuk Kim /* for node-related operations */ 89439a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 89539a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 89639a53e0cSJaegeuk Kim 89739a53e0cSJaegeuk Kim /* for segment-related operations */ 89839a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 8991ff7bd3bSJaegeuk Kim 9001ff7bd3bSJaegeuk Kim /* for bio operations */ 901a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 902e41e6d75SChao Yu struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 903e41e6d75SChao Yu /* bio ordering for NODE/DATA */ 9040a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 9050a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 90639a53e0cSJaegeuk Kim 90739a53e0cSJaegeuk Kim /* for checkpoint */ 90839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 9098508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 910aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 91139a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 91239936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 913b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 914b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 91559c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 916fb51b5efSChangman Lee wait_queue_head_t cp_wait; 9176beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 9186beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 91939a53e0cSJaegeuk Kim 92067298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 9216451e041SJaegeuk Kim 9226451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 9230d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 92439a53e0cSJaegeuk Kim 925c227f912SChao Yu /* for inode management */ 926c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 927c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 92839a53e0cSJaegeuk Kim 92913054c54SChao Yu /* for extent tree cache */ 93013054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 9315e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 93213054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 93313054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 9347441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 935137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 93674fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 93713054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 93813054c54SChao Yu 93939a53e0cSJaegeuk Kim /* basic filesystem units */ 94039a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 94139a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 94239a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 94339a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 94439a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 94539a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 94639a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 94739a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 94839a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 94939a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 95039a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 95139a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 95239a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 953e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 95439a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 955ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 95639a53e0cSJaegeuk Kim 95739a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 95839a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 959a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 96039a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 96139a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 962523be8a6SJaegeuk Kim 963523be8a6SJaegeuk Kim /* # of pages, see count_type */ 96435782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 96541382ec4SJaegeuk Kim /* # of allocated blocks */ 96641382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 96739a53e0cSJaegeuk Kim 968687de7f1SJaegeuk Kim /* writeback control */ 969687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 970687de7f1SJaegeuk Kim 971513c5f37SJaegeuk Kim /* valid inode count */ 972513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 973513c5f37SJaegeuk Kim 97439a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 97539a53e0cSJaegeuk Kim 97639a53e0cSJaegeuk Kim /* for cleaning operations */ 97739a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 97839a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 9795ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 98039a53e0cSJaegeuk Kim 981e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 982e93b9865SHou Pengyang u64 fggc_threshold; 983e93b9865SHou Pengyang 984b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 985b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 986b1c57c1cSJaegeuk Kim 98739a53e0cSJaegeuk Kim /* 98839a53e0cSJaegeuk Kim * for stat information. 98939a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 99039a53e0cSJaegeuk Kim */ 99135b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 99239a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 99339a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 99439a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 995b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 9965b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 9975b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 9985b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 9995b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1000d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 100103e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 100203e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 100326a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 1004648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 100526a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1006648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 100739a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 100833fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 100935b09d82SNamjae Jeon #endif 101039a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1011b59d0baeSNamjae Jeon 1012b59d0baeSNamjae Jeon /* For sysfs suppport */ 1013b59d0baeSNamjae Jeon struct kobject s_kobj; 1014b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 10152658e50dSJaegeuk Kim 10162658e50dSJaegeuk Kim /* For shrinker support */ 10172658e50dSJaegeuk Kim struct list_head s_list; 10183c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 10193c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 10202658e50dSJaegeuk Kim struct mutex umount_mutex; 10212658e50dSJaegeuk Kim unsigned int shrinker_run_no; 10228f1dbbbbSShuoran Liu 10238f1dbbbbSShuoran Liu /* For write statistics */ 10248f1dbbbbSShuoran Liu u64 sectors_written_start; 10258f1dbbbbSShuoran Liu u64 kbytes_written; 102643b6573bSKeith Mok 102743b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 102843b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 10291ecc0c5cSChao Yu 10301ecc0c5cSChao Yu /* For fault injection */ 10311ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 10321ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 10331ecc0c5cSChao Yu #endif 103439a53e0cSJaegeuk Kim }; 103539a53e0cSJaegeuk Kim 10361ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 103755523519SChao Yu #define f2fs_show_injection_info(type) \ 103855523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 103955523519SChao Yu KERN_INFO, fault_name[type], \ 104055523519SChao Yu __func__, __builtin_return_address(0)) 10411ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 10421ecc0c5cSChao Yu { 10431ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 10441ecc0c5cSChao Yu 10451ecc0c5cSChao Yu if (!ffi->inject_rate) 10461ecc0c5cSChao Yu return false; 10471ecc0c5cSChao Yu 10481ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 10491ecc0c5cSChao Yu return false; 10501ecc0c5cSChao Yu 10511ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 10521ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 10531ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 10541ecc0c5cSChao Yu return true; 10551ecc0c5cSChao Yu } 10561ecc0c5cSChao Yu return false; 10571ecc0c5cSChao Yu } 10581ecc0c5cSChao Yu #endif 10591ecc0c5cSChao Yu 10608f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 10618f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 10628f1dbbbbSShuoran Liu */ 10638f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 106468afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 106568afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 10668f1dbbbbSShuoran Liu 10676beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 10686beceb54SJaegeuk Kim { 10696beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 10706beceb54SJaegeuk Kim } 10716beceb54SJaegeuk Kim 10726beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 10736beceb54SJaegeuk Kim { 10746beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 10756beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 10766beceb54SJaegeuk Kim 10776beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 10786beceb54SJaegeuk Kim } 10796beceb54SJaegeuk Kim 1080d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1081d0239e1bSJaegeuk Kim { 1082d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1083d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1084d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1085d0239e1bSJaegeuk Kim 1086d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1087d0239e1bSJaegeuk Kim return 0; 1088d0239e1bSJaegeuk Kim 1089d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1090d0239e1bSJaegeuk Kim } 1091d0239e1bSJaegeuk Kim 109239a53e0cSJaegeuk Kim /* 109339a53e0cSJaegeuk Kim * Inline functions 109439a53e0cSJaegeuk Kim */ 109543b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 109643b6573bSKeith Mok unsigned int length) 109743b6573bSKeith Mok { 109843b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 109943b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 110043b6573bSKeith Mok int err; 110143b6573bSKeith Mok 110243b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 110343b6573bSKeith Mok shash->flags = 0; 110443b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 110543b6573bSKeith Mok 110643b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 110743b6573bSKeith Mok BUG_ON(err); 110843b6573bSKeith Mok 110943b6573bSKeith Mok return *ctx; 111043b6573bSKeith Mok } 111143b6573bSKeith Mok 111243b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 111343b6573bSKeith Mok void *buf, size_t buf_size) 111443b6573bSKeith Mok { 111543b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 111643b6573bSKeith Mok } 111743b6573bSKeith Mok 111839a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 111939a53e0cSJaegeuk Kim { 112039a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 112139a53e0cSJaegeuk Kim } 112239a53e0cSJaegeuk Kim 112339a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 112439a53e0cSJaegeuk Kim { 112539a53e0cSJaegeuk Kim return sb->s_fs_info; 112639a53e0cSJaegeuk Kim } 112739a53e0cSJaegeuk Kim 11284081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 11294081363fSJaegeuk Kim { 11304081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 11314081363fSJaegeuk Kim } 11324081363fSJaegeuk Kim 11334081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 11344081363fSJaegeuk Kim { 11354081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 11364081363fSJaegeuk Kim } 11374081363fSJaegeuk Kim 11384081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 11394081363fSJaegeuk Kim { 11404081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 11414081363fSJaegeuk Kim } 11424081363fSJaegeuk Kim 114339a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 114439a53e0cSJaegeuk Kim { 114539a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 114639a53e0cSJaegeuk Kim } 114739a53e0cSJaegeuk Kim 114839a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 114939a53e0cSJaegeuk Kim { 115039a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 115139a53e0cSJaegeuk Kim } 115239a53e0cSJaegeuk Kim 115345590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 115445590710SGu Zheng { 115545590710SGu Zheng return (struct f2fs_node *)page_address(page); 115645590710SGu Zheng } 115745590710SGu Zheng 115858bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 115958bfaf44SJaegeuk Kim { 116058bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 116158bfaf44SJaegeuk Kim } 116258bfaf44SJaegeuk Kim 116339a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 116439a53e0cSJaegeuk Kim { 116539a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 116639a53e0cSJaegeuk Kim } 116739a53e0cSJaegeuk Kim 116839a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 116939a53e0cSJaegeuk Kim { 117039a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 117139a53e0cSJaegeuk Kim } 117239a53e0cSJaegeuk Kim 117339a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 117439a53e0cSJaegeuk Kim { 117539a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 117639a53e0cSJaegeuk Kim } 117739a53e0cSJaegeuk Kim 117839a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 117939a53e0cSJaegeuk Kim { 118039a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 118139a53e0cSJaegeuk Kim } 118239a53e0cSJaegeuk Kim 118339a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 118439a53e0cSJaegeuk Kim { 118539a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 118639a53e0cSJaegeuk Kim } 118739a53e0cSJaegeuk Kim 11889df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 11899df27d98SGu Zheng { 11909df27d98SGu Zheng return sbi->meta_inode->i_mapping; 11919df27d98SGu Zheng } 11929df27d98SGu Zheng 11934ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 11944ef51a8fSJaegeuk Kim { 11954ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 11964ef51a8fSJaegeuk Kim } 11974ef51a8fSJaegeuk Kim 1198caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 119939a53e0cSJaegeuk Kim { 1200fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 120139a53e0cSJaegeuk Kim } 120239a53e0cSJaegeuk Kim 1203caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 120439a53e0cSJaegeuk Kim { 1205fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1206caf0047eSChao Yu } 1207caf0047eSChao Yu 1208caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1209caf0047eSChao Yu { 1210fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 121139a53e0cSJaegeuk Kim } 121239a53e0cSJaegeuk Kim 1213d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1214d71b5564SJaegeuk Kim { 1215d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1216d71b5564SJaegeuk Kim } 1217d71b5564SJaegeuk Kim 1218ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1219ced2c7eaSKinglong Mee { 1220ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1221ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1222ced2c7eaSKinglong Mee } 1223ced2c7eaSKinglong Mee 1224aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 122525ca923bSJaegeuk Kim { 122625ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1227aaec2b1dSChao Yu 122825ca923bSJaegeuk Kim return ckpt_flags & f; 122925ca923bSJaegeuk Kim } 123025ca923bSJaegeuk Kim 1231aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 123225ca923bSJaegeuk Kim { 1233aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1234aaec2b1dSChao Yu } 1235aaec2b1dSChao Yu 1236aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1237aaec2b1dSChao Yu { 1238aaec2b1dSChao Yu unsigned int ckpt_flags; 1239aaec2b1dSChao Yu 1240aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 124125ca923bSJaegeuk Kim ckpt_flags |= f; 124225ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 124325ca923bSJaegeuk Kim } 124425ca923bSJaegeuk Kim 1245aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 124625ca923bSJaegeuk Kim { 1247aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1248aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1249aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1250aaec2b1dSChao Yu } 1251aaec2b1dSChao Yu 1252aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1253aaec2b1dSChao Yu { 1254aaec2b1dSChao Yu unsigned int ckpt_flags; 1255aaec2b1dSChao Yu 1256aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 125725ca923bSJaegeuk Kim ckpt_flags &= (~f); 125825ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 125925ca923bSJaegeuk Kim } 126025ca923bSJaegeuk Kim 1261aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1262aaec2b1dSChao Yu { 1263aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1264aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1265aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1266aaec2b1dSChao Yu } 1267aaec2b1dSChao Yu 126822ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 126922ad0b6aSJaegeuk Kim { 127022ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 127122ad0b6aSJaegeuk Kim 127222ad0b6aSJaegeuk Kim if (lock) 127322ad0b6aSJaegeuk Kim spin_lock(&sbi->cp_lock); 127422ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 127522ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 127622ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 127722ad0b6aSJaegeuk Kim if (lock) 127822ad0b6aSJaegeuk Kim spin_unlock(&sbi->cp_lock); 127922ad0b6aSJaegeuk Kim } 128022ad0b6aSJaegeuk Kim 128122ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 128222ad0b6aSJaegeuk Kim struct cp_control *cpc) 128322ad0b6aSJaegeuk Kim { 128422ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 128522ad0b6aSJaegeuk Kim 1286c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 128722ad0b6aSJaegeuk Kim } 128822ad0b6aSJaegeuk Kim 1289e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 129039a53e0cSJaegeuk Kim { 1291b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 129239a53e0cSJaegeuk Kim } 129339a53e0cSJaegeuk Kim 1294cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1295cc15620bSJaegeuk Kim { 1296cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1297cc15620bSJaegeuk Kim } 1298cc15620bSJaegeuk Kim 1299e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 130039a53e0cSJaegeuk Kim { 1301b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 130239936837SJaegeuk Kim } 130339936837SJaegeuk Kim 1304e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 130539936837SJaegeuk Kim { 1306b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 130739936837SJaegeuk Kim } 130839936837SJaegeuk Kim 1309e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 131039936837SJaegeuk Kim { 1311b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 131239a53e0cSJaegeuk Kim } 131339a53e0cSJaegeuk Kim 1314119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1315119ee914SJaegeuk Kim { 1316119ee914SJaegeuk Kim int reason = CP_SYNC; 1317119ee914SJaegeuk Kim 1318119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1319119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1320119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1321119ee914SJaegeuk Kim reason = CP_UMOUNT; 1322119ee914SJaegeuk Kim return reason; 1323119ee914SJaegeuk Kim } 1324119ee914SJaegeuk Kim 1325119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1326119ee914SJaegeuk Kim { 1327c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1328119ee914SJaegeuk Kim } 1329119ee914SJaegeuk Kim 1330119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1331119ee914SJaegeuk Kim { 1332aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1333aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1334119ee914SJaegeuk Kim } 1335119ee914SJaegeuk Kim 133639a53e0cSJaegeuk Kim /* 133739a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 133839a53e0cSJaegeuk Kim */ 1339064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 134039a53e0cSJaegeuk Kim { 1341d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1342d6b7d4b3SChao Yu return -EINVAL; 1343cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1344064e0823SNamjae Jeon return -EINVAL; 1345064e0823SNamjae Jeon return 0; 134639a53e0cSJaegeuk Kim } 134739a53e0cSJaegeuk Kim 134839a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 134939a53e0cSJaegeuk Kim 135039a53e0cSJaegeuk Kim /* 135139a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 135239a53e0cSJaegeuk Kim */ 135339a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 135439a53e0cSJaegeuk Kim { 135539a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 13566c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 135739a53e0cSJaegeuk Kim else 13586c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 135939a53e0cSJaegeuk Kim } 136039a53e0cSJaegeuk Kim 13614bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 13624bc8e9bcSChao Yu { 13634bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 13644bc8e9bcSChao Yu } 13654bc8e9bcSChao Yu 13668edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 136739a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 136846008c6dSChao Yu struct inode *inode, blkcnt_t *count) 136939a53e0cSJaegeuk Kim { 1370dd11a5dfSJaegeuk Kim blkcnt_t diff; 1371dd11a5dfSJaegeuk Kim 1372cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 137355523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 137455523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 1375cb78942bSJaegeuk Kim return false; 137655523519SChao Yu } 1377cb78942bSJaegeuk Kim #endif 1378dd11a5dfSJaegeuk Kim /* 1379dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1380dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1381dd11a5dfSJaegeuk Kim */ 1382dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1383cfb271d4SChao Yu 138439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13852555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 13862555a2d5SJaegeuk Kim if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { 1387dd11a5dfSJaegeuk Kim diff = sbi->total_valid_block_count - sbi->user_block_count; 1388dd11a5dfSJaegeuk Kim *count -= diff; 13892555a2d5SJaegeuk Kim sbi->total_valid_block_count = sbi->user_block_count; 139046008c6dSChao Yu if (!*count) { 139139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1392dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 139339a53e0cSJaegeuk Kim return false; 139439a53e0cSJaegeuk Kim } 139546008c6dSChao Yu } 139639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 139741382ec4SJaegeuk Kim 13982555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, *count, true); 139939a53e0cSJaegeuk Kim return true; 140039a53e0cSJaegeuk Kim } 140139a53e0cSJaegeuk Kim 1402da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 140339a53e0cSJaegeuk Kim struct inode *inode, 140439a53e0cSJaegeuk Kim blkcnt_t count) 140539a53e0cSJaegeuk Kim { 140639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 14079850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 14089850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 140939a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 141039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 14112555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, count, false); 141239a53e0cSJaegeuk Kim } 141339a53e0cSJaegeuk Kim 141439a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 141539a53e0cSJaegeuk Kim { 141635782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 14177c4abcbeSChao Yu 141836951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 141936951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 14207c4abcbeSChao Yu return; 14217c4abcbeSChao Yu 1422caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 142339a53e0cSJaegeuk Kim } 142439a53e0cSJaegeuk Kim 1425a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 142639a53e0cSJaegeuk Kim { 1427204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1428c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1429c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 143039a53e0cSJaegeuk Kim } 143139a53e0cSJaegeuk Kim 143239a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 143339a53e0cSJaegeuk Kim { 143435782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 143539a53e0cSJaegeuk Kim } 143639a53e0cSJaegeuk Kim 1437a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 143839a53e0cSJaegeuk Kim { 14395ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 14405ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 14411fe54f9dSJaegeuk Kim return; 14421fe54f9dSJaegeuk Kim 1443204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1444c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1445c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 144639a53e0cSJaegeuk Kim } 144739a53e0cSJaegeuk Kim 1448523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 144939a53e0cSJaegeuk Kim { 145035782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 145139a53e0cSJaegeuk Kim } 145239a53e0cSJaegeuk Kim 1453204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1454f8b2c1f9SJaegeuk Kim { 1455204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1456f8b2c1f9SJaegeuk Kim } 1457f8b2c1f9SJaegeuk Kim 14585ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 14595ac206cfSNamjae Jeon { 14603519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1461523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1462523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1463523be8a6SJaegeuk Kim 1464523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 14655ac206cfSNamjae Jeon } 14665ac206cfSNamjae Jeon 146739a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 146839a53e0cSJaegeuk Kim { 14698b8343faSJaegeuk Kim return sbi->total_valid_block_count; 147039a53e0cSJaegeuk Kim } 147139a53e0cSJaegeuk Kim 1472f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1473f83a2584SYunlei He { 1474f83a2584SYunlei He return sbi->discard_blks; 1475f83a2584SYunlei He } 1476f83a2584SYunlei He 147739a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 147839a53e0cSJaegeuk Kim { 147939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 148039a53e0cSJaegeuk Kim 148139a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 148239a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 148339a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 148439a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 148539a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 148639a53e0cSJaegeuk Kim 148739a53e0cSJaegeuk Kim return 0; 148839a53e0cSJaegeuk Kim } 148939a53e0cSJaegeuk Kim 149055141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 149155141486SWanpeng Li { 149255141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 149355141486SWanpeng Li } 149455141486SWanpeng Li 149539a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 149639a53e0cSJaegeuk Kim { 149739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 14981dbe4152SChangman Lee int offset; 14991dbe4152SChangman Lee 150055141486SWanpeng Li if (__cp_payload(sbi) > 0) { 15011dbe4152SChangman Lee if (flag == NAT_BITMAP) 15021dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 15031dbe4152SChangman Lee else 150465b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 15051dbe4152SChangman Lee } else { 15061dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 150725ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 150839a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 150939a53e0cSJaegeuk Kim } 15101dbe4152SChangman Lee } 151139a53e0cSJaegeuk Kim 151239a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 151339a53e0cSJaegeuk Kim { 15148508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 151539a53e0cSJaegeuk Kim 15168508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 151739a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 151839a53e0cSJaegeuk Kim return start_addr; 151939a53e0cSJaegeuk Kim } 152039a53e0cSJaegeuk Kim 15218508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 15228508e44aSJaegeuk Kim { 15238508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 15248508e44aSJaegeuk Kim 15258508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 15268508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 15278508e44aSJaegeuk Kim return start_addr; 15288508e44aSJaegeuk Kim } 15298508e44aSJaegeuk Kim 15308508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 15318508e44aSJaegeuk Kim { 15328508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 15338508e44aSJaegeuk Kim } 15348508e44aSJaegeuk Kim 153539a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 153639a53e0cSJaegeuk Kim { 153739a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 153839a53e0cSJaegeuk Kim } 153939a53e0cSJaegeuk Kim 154039a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1541ef86d709SGu Zheng struct inode *inode) 154239a53e0cSJaegeuk Kim { 154339a53e0cSJaegeuk Kim block_t valid_block_count; 154439a53e0cSJaegeuk Kim unsigned int valid_node_count; 154539a53e0cSJaegeuk Kim 154639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 154739a53e0cSJaegeuk Kim 1548ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1549cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 155039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 155139a53e0cSJaegeuk Kim return false; 155239a53e0cSJaegeuk Kim } 155339a53e0cSJaegeuk Kim 1554ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1555cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 155639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 155739a53e0cSJaegeuk Kim return false; 155839a53e0cSJaegeuk Kim } 155939a53e0cSJaegeuk Kim 156039a53e0cSJaegeuk Kim if (inode) 15618edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, true); 1562ef86d709SGu Zheng 1563ef86d709SGu Zheng sbi->total_valid_node_count++; 1564ef86d709SGu Zheng sbi->total_valid_block_count++; 156539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 156639a53e0cSJaegeuk Kim 156741382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 156839a53e0cSJaegeuk Kim return true; 156939a53e0cSJaegeuk Kim } 157039a53e0cSJaegeuk Kim 157139a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1572ef86d709SGu Zheng struct inode *inode) 157339a53e0cSJaegeuk Kim { 157439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 157539a53e0cSJaegeuk Kim 15769850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 15779850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 15789850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 157939a53e0cSJaegeuk Kim 15808edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, false); 1581ef86d709SGu Zheng sbi->total_valid_node_count--; 1582ef86d709SGu Zheng sbi->total_valid_block_count--; 158339a53e0cSJaegeuk Kim 158439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 158539a53e0cSJaegeuk Kim } 158639a53e0cSJaegeuk Kim 158739a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 158839a53e0cSJaegeuk Kim { 15898b8343faSJaegeuk Kim return sbi->total_valid_node_count; 159039a53e0cSJaegeuk Kim } 159139a53e0cSJaegeuk Kim 159239a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 159339a53e0cSJaegeuk Kim { 1594513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 159539a53e0cSJaegeuk Kim } 159639a53e0cSJaegeuk Kim 15970e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 159839a53e0cSJaegeuk Kim { 1599513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 160039a53e0cSJaegeuk Kim } 160139a53e0cSJaegeuk Kim 1602513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 160339a53e0cSJaegeuk Kim { 1604513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 160539a53e0cSJaegeuk Kim } 160639a53e0cSJaegeuk Kim 1607a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1608a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1609a56c7c6fSJaegeuk Kim { 1610c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1611c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1612cac5a3d8SDongOh Shin 1613c41f3cc3SJaegeuk Kim if (page) 1614c41f3cc3SJaegeuk Kim return page; 1615c41f3cc3SJaegeuk Kim 161655523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 161755523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1618c41f3cc3SJaegeuk Kim return NULL; 161955523519SChao Yu } 1620c41f3cc3SJaegeuk Kim #endif 1621a56c7c6fSJaegeuk Kim if (!for_write) 1622a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1623a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1624a56c7c6fSJaegeuk Kim } 1625a56c7c6fSJaegeuk Kim 16266e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 16276e2c64adSJaegeuk Kim { 16286e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 16296e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 16306e2c64adSJaegeuk Kim 16316e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 16326e2c64adSJaegeuk Kim kunmap(dst); 16336e2c64adSJaegeuk Kim kunmap(src); 16346e2c64adSJaegeuk Kim } 16356e2c64adSJaegeuk Kim 163639a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 163739a53e0cSJaegeuk Kim { 1638031fa8ccSJaegeuk Kim if (!page) 163939a53e0cSJaegeuk Kim return; 164039a53e0cSJaegeuk Kim 164139a53e0cSJaegeuk Kim if (unlock) { 16429850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 164339a53e0cSJaegeuk Kim unlock_page(page); 164439a53e0cSJaegeuk Kim } 164509cbfeafSKirill A. Shutemov put_page(page); 164639a53e0cSJaegeuk Kim } 164739a53e0cSJaegeuk Kim 164839a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 164939a53e0cSJaegeuk Kim { 165039a53e0cSJaegeuk Kim if (dn->node_page) 165139a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 165239a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 165339a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 165439a53e0cSJaegeuk Kim dn->node_page = NULL; 165539a53e0cSJaegeuk Kim dn->inode_page = NULL; 165639a53e0cSJaegeuk Kim } 165739a53e0cSJaegeuk Kim 165839a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1659e8512d2eSGu Zheng size_t size) 166039a53e0cSJaegeuk Kim { 1661e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 166239a53e0cSJaegeuk Kim } 166339a53e0cSJaegeuk Kim 16647bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 16657bd59381SGu Zheng gfp_t flags) 16667bd59381SGu Zheng { 16677bd59381SGu Zheng void *entry; 16687bd59381SGu Zheng 166980c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 167080c54505SJaegeuk Kim if (!entry) 167180c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 16727bd59381SGu Zheng return entry; 16737bd59381SGu Zheng } 16747bd59381SGu Zheng 1675740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1676740432f8SJaegeuk Kim { 1677740432f8SJaegeuk Kim struct bio *bio; 1678740432f8SJaegeuk Kim 1679740432f8SJaegeuk Kim /* No failure on bio allocation */ 1680740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 168180c54505SJaegeuk Kim if (!bio) 168280c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1683740432f8SJaegeuk Kim return bio; 1684740432f8SJaegeuk Kim } 1685740432f8SJaegeuk Kim 16869be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 16879be32d72SJaegeuk Kim unsigned long index, void *item) 16889be32d72SJaegeuk Kim { 16899be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 16909be32d72SJaegeuk Kim cond_resched(); 16919be32d72SJaegeuk Kim } 16929be32d72SJaegeuk Kim 169339a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 169439a53e0cSJaegeuk Kim 169539a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 169639a53e0cSJaegeuk Kim { 169745590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1698cac5a3d8SDongOh Shin 169939a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 170039a53e0cSJaegeuk Kim } 170139a53e0cSJaegeuk Kim 170239a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 170339a53e0cSJaegeuk Kim { 170439a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 170539a53e0cSJaegeuk Kim } 170639a53e0cSJaegeuk Kim 170739a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 170839a53e0cSJaegeuk Kim unsigned int offset) 170939a53e0cSJaegeuk Kim { 171039a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 171139a53e0cSJaegeuk Kim __le32 *addr_array; 1712cac5a3d8SDongOh Shin 171345590710SGu Zheng raw_node = F2FS_NODE(node_page); 171439a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 171539a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 171639a53e0cSJaegeuk Kim } 171739a53e0cSJaegeuk Kim 171839a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 171939a53e0cSJaegeuk Kim { 172039a53e0cSJaegeuk Kim int mask; 172139a53e0cSJaegeuk Kim 172239a53e0cSJaegeuk Kim addr += (nr >> 3); 172339a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 172439a53e0cSJaegeuk Kim return mask & *addr; 172539a53e0cSJaegeuk Kim } 172639a53e0cSJaegeuk Kim 1727a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1728a66cdd98SJaegeuk Kim { 1729a66cdd98SJaegeuk Kim int mask; 1730a66cdd98SJaegeuk Kim 1731a66cdd98SJaegeuk Kim addr += (nr >> 3); 1732a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1733a66cdd98SJaegeuk Kim *addr |= mask; 1734a66cdd98SJaegeuk Kim } 1735a66cdd98SJaegeuk Kim 1736a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1737a66cdd98SJaegeuk Kim { 1738a66cdd98SJaegeuk Kim int mask; 1739a66cdd98SJaegeuk Kim 1740a66cdd98SJaegeuk Kim addr += (nr >> 3); 1741a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1742a66cdd98SJaegeuk Kim *addr &= ~mask; 1743a66cdd98SJaegeuk Kim } 1744a66cdd98SJaegeuk Kim 174552aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 174639a53e0cSJaegeuk Kim { 174739a53e0cSJaegeuk Kim int mask; 174839a53e0cSJaegeuk Kim int ret; 174939a53e0cSJaegeuk Kim 175039a53e0cSJaegeuk Kim addr += (nr >> 3); 175139a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 175239a53e0cSJaegeuk Kim ret = mask & *addr; 175339a53e0cSJaegeuk Kim *addr |= mask; 175439a53e0cSJaegeuk Kim return ret; 175539a53e0cSJaegeuk Kim } 175639a53e0cSJaegeuk Kim 175752aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 175839a53e0cSJaegeuk Kim { 175939a53e0cSJaegeuk Kim int mask; 176039a53e0cSJaegeuk Kim int ret; 176139a53e0cSJaegeuk Kim 176239a53e0cSJaegeuk Kim addr += (nr >> 3); 176339a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 176439a53e0cSJaegeuk Kim ret = mask & *addr; 176539a53e0cSJaegeuk Kim *addr &= ~mask; 176639a53e0cSJaegeuk Kim return ret; 176739a53e0cSJaegeuk Kim } 176839a53e0cSJaegeuk Kim 1769c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1770c6ac4c0eSGu Zheng { 1771c6ac4c0eSGu Zheng int mask; 1772c6ac4c0eSGu Zheng 1773c6ac4c0eSGu Zheng addr += (nr >> 3); 1774c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1775c6ac4c0eSGu Zheng *addr ^= mask; 1776c6ac4c0eSGu Zheng } 1777c6ac4c0eSGu Zheng 177839a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 177939a53e0cSJaegeuk Kim enum { 178039a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1781b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 178226de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1783ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 178439a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 178539a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 178639a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1787c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1788c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1789444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 17901001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 179134d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1792fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1793fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 179488b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 179588b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 17965fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 179702a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 17983c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 17991e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1800b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1801510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1802d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1803c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 1804dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 1805ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 180639a53e0cSJaegeuk Kim }; 180739a53e0cSJaegeuk Kim 1808205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 1809205b9822SJaegeuk Kim int flag, bool set) 181039a53e0cSJaegeuk Kim { 1811205b9822SJaegeuk Kim switch (flag) { 1812205b9822SJaegeuk Kim case FI_INLINE_XATTR: 1813205b9822SJaegeuk Kim case FI_INLINE_DATA: 1814205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 1815205b9822SJaegeuk Kim if (set) 1816205b9822SJaegeuk Kim return; 1817205b9822SJaegeuk Kim case FI_DATA_EXIST: 1818205b9822SJaegeuk Kim case FI_INLINE_DOTS: 18197c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1820205b9822SJaegeuk Kim } 182139a53e0cSJaegeuk Kim } 182239a53e0cSJaegeuk Kim 182391942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 182439a53e0cSJaegeuk Kim { 182591942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 182691942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 1827205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 182839a53e0cSJaegeuk Kim } 182939a53e0cSJaegeuk Kim 183091942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 183139a53e0cSJaegeuk Kim { 183291942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 183339a53e0cSJaegeuk Kim } 183439a53e0cSJaegeuk Kim 183591942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 183639a53e0cSJaegeuk Kim { 183791942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 183891942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 1839205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 184039a53e0cSJaegeuk Kim } 184139a53e0cSJaegeuk Kim 184291942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 1843444c580fSJaegeuk Kim { 184491942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 184591942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 18467c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 184739a53e0cSJaegeuk Kim } 184839a53e0cSJaegeuk Kim 1849a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 1850a1961246SJaegeuk Kim { 1851a1961246SJaegeuk Kim if (inc) 1852a1961246SJaegeuk Kim inc_nlink(inode); 1853a1961246SJaegeuk Kim else 1854a1961246SJaegeuk Kim drop_nlink(inode); 18557c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1856a1961246SJaegeuk Kim } 1857a1961246SJaegeuk Kim 18588edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 18598edd03c8SJaegeuk Kim blkcnt_t diff, bool add) 18608edd03c8SJaegeuk Kim { 186126de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 186226de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 186326de9b11SJaegeuk Kim 18648edd03c8SJaegeuk Kim inode->i_blocks = add ? inode->i_blocks + diff : 18658edd03c8SJaegeuk Kim inode->i_blocks - diff; 18667c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 186726de9b11SJaegeuk Kim if (clean || recover) 186826de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 18698edd03c8SJaegeuk Kim } 18708edd03c8SJaegeuk Kim 1871fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 1872fc9581c8SJaegeuk Kim { 187326de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 187426de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 187526de9b11SJaegeuk Kim 1876fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 1877fc9581c8SJaegeuk Kim return; 1878fc9581c8SJaegeuk Kim 1879fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 18807c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 188126de9b11SJaegeuk Kim if (clean || recover) 188226de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 188326de9b11SJaegeuk Kim } 188426de9b11SJaegeuk Kim 1885205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 1886205b9822SJaegeuk Kim { 1887205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 18887c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1889205b9822SJaegeuk Kim } 1890205b9822SJaegeuk Kim 1891205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 1892205b9822SJaegeuk Kim { 1893205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 18947c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1895205b9822SJaegeuk Kim } 1896205b9822SJaegeuk Kim 1897205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 1898205b9822SJaegeuk Kim { 1899205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 19007c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1901205b9822SJaegeuk Kim } 1902205b9822SJaegeuk Kim 190391942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 1904444c580fSJaegeuk Kim { 1905205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 1906205b9822SJaegeuk Kim 1907444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1908205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 19091001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 1910205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 191134d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1912205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 1913b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1914205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 1915510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1916205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 1917444c580fSJaegeuk Kim } 1918444c580fSJaegeuk Kim 191991942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 1920444c580fSJaegeuk Kim { 1921444c580fSJaegeuk Kim ri->i_inline = 0; 1922444c580fSJaegeuk Kim 192391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 1924444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 192591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 19261001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 192791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 192834d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 192991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 1930b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 193191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 1932510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1933444c580fSJaegeuk Kim } 1934444c580fSJaegeuk Kim 1935987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1936987c7c31SChao Yu { 193791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 1938987c7c31SChao Yu } 1939987c7c31SChao Yu 194081ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1941de93653fSJaegeuk Kim { 194281ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1943de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1944de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1945de93653fSJaegeuk Kim } 1946de93653fSJaegeuk Kim 194765985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 194865985d93SJaegeuk Kim { 1949695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1950cac5a3d8SDongOh Shin 195165985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 195265985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 195365985d93SJaegeuk Kim } 195465985d93SJaegeuk Kim 195565985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 195665985d93SJaegeuk Kim { 1957987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 195865985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 195965985d93SJaegeuk Kim else 196065985d93SJaegeuk Kim return 0; 196165985d93SJaegeuk Kim } 196265985d93SJaegeuk Kim 19630dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 19640dbdc2aeSJaegeuk Kim { 196591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 19660dbdc2aeSJaegeuk Kim } 19670dbdc2aeSJaegeuk Kim 1968b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1969b3d208f9SJaegeuk Kim { 197091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 1971b3d208f9SJaegeuk Kim } 1972b3d208f9SJaegeuk Kim 1973510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1974510022a8SJaegeuk Kim { 197591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 1976510022a8SJaegeuk Kim } 1977510022a8SJaegeuk Kim 197888b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 197988b88a66SJaegeuk Kim { 198091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 198188b88a66SJaegeuk Kim } 198288b88a66SJaegeuk Kim 19835fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 19845fe45743SChao Yu { 19855fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 19865fe45743SChao Yu } 19875fe45743SChao Yu 198802a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 198902a1335fSJaegeuk Kim { 199091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 199102a1335fSJaegeuk Kim } 199202a1335fSJaegeuk Kim 19933c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 19943c6c2bebSJaegeuk Kim { 199591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 19963c6c2bebSJaegeuk Kim } 19973c6c2bebSJaegeuk Kim 19981e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 19991e84371fSJaegeuk Kim { 200091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 20011e84371fSJaegeuk Kim } 20021e84371fSJaegeuk Kim 20031001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 20041001b347SHuajun Li { 2005695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2006cac5a3d8SDongOh Shin 20071001b347SHuajun Li return (void *)&(ri->i_addr[1]); 20081001b347SHuajun Li } 20091001b347SHuajun Li 201034d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 201134d67debSChao Yu { 201291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 201334d67debSChao Yu } 201434d67debSChao Yu 20159486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 20169486ba44SJaegeuk Kim { 20179486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 20189486ba44SJaegeuk Kim kunmap(page); 20199486ba44SJaegeuk Kim } 20209486ba44SJaegeuk Kim 2021b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2022b5492af7SJaegeuk Kim { 2023b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2024b5492af7SJaegeuk Kim } 2025b5492af7SJaegeuk Kim 2026b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2027b5492af7SJaegeuk Kim { 2028b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 20297c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2030b5492af7SJaegeuk Kim } 2031b5492af7SJaegeuk Kim 2032b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2033b5492af7SJaegeuk Kim { 2034b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 20357c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2036b5492af7SJaegeuk Kim } 2037b5492af7SJaegeuk Kim 203826787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 203926787236SJaegeuk Kim { 204026787236SJaegeuk Kim if (dsync) { 204126787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 204226787236SJaegeuk Kim bool ret; 204326787236SJaegeuk Kim 204426787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 204526787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 204626787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 204726787236SJaegeuk Kim return ret; 204826787236SJaegeuk Kim } 204926787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 205026787236SJaegeuk Kim file_keep_isize(inode) || 205126787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 205226787236SJaegeuk Kim return false; 205326787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 2054267378d4SChao Yu } 2055267378d4SChao Yu 2056267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 2057267378d4SChao Yu { 2058267378d4SChao Yu return sb->s_flags & MS_RDONLY; 2059267378d4SChao Yu } 206039a53e0cSJaegeuk Kim 206139a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 206239a53e0cSJaegeuk Kim { 2063aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 206439a53e0cSJaegeuk Kim } 206539a53e0cSJaegeuk Kim 2066eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2067eaa693f4SJaegeuk Kim { 2068eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2069eaa693f4SJaegeuk Kim return true; 2070eaa693f4SJaegeuk Kim 2071eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2072eaa693f4SJaegeuk Kim return true; 2073eaa693f4SJaegeuk Kim 2074eaa693f4SJaegeuk Kim return false; 2075eaa693f4SJaegeuk Kim } 2076eaa693f4SJaegeuk Kim 20773e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 20783e72f721SJaegeuk Kim { 20793e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 208091942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 20813e72f721SJaegeuk Kim return false; 20823e72f721SJaegeuk Kim 2083886f56f9SAl Viro return S_ISREG(inode->i_mode); 20843e72f721SJaegeuk Kim } 20853e72f721SJaegeuk Kim 20861ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 20871ecc0c5cSChao Yu size_t size, gfp_t flags) 20880414b004SJaegeuk Kim { 20892c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 209055523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 209155523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 20922c63feadSJaegeuk Kim return NULL; 209355523519SChao Yu } 20942c63feadSJaegeuk Kim #endif 20950414b004SJaegeuk Kim return kmalloc(size, flags); 20960414b004SJaegeuk Kim } 20970414b004SJaegeuk Kim 209839307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 209939307a8eSJaegeuk Kim { 210039307a8eSJaegeuk Kim void *ret; 210139307a8eSJaegeuk Kim 210239307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 210339307a8eSJaegeuk Kim if (!ret) 210439307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 210539307a8eSJaegeuk Kim return ret; 210639307a8eSJaegeuk Kim } 210739307a8eSJaegeuk Kim 210839307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 210939307a8eSJaegeuk Kim { 211039307a8eSJaegeuk Kim void *ret; 211139307a8eSJaegeuk Kim 211239307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 211339307a8eSJaegeuk Kim if (!ret) 211439307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 211539307a8eSJaegeuk Kim return ret; 211639307a8eSJaegeuk Kim } 211739307a8eSJaegeuk Kim 211839a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 211991942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 212039a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 212139a53e0cSJaegeuk Kim 212239a53e0cSJaegeuk Kim /* 21231e1bb4baSJaegeuk Kim * file.c 212439a53e0cSJaegeuk Kim */ 2125cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2126cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2127cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2128cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2129a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2130a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2131cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2132cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2133cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2134cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2135cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 213639a53e0cSJaegeuk Kim 213739a53e0cSJaegeuk Kim /* 213839a53e0cSJaegeuk Kim * inode.c 213939a53e0cSJaegeuk Kim */ 2140cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2141cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2142cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2143cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2144cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2145cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2146cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2147cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2148cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 214939a53e0cSJaegeuk Kim 215039a53e0cSJaegeuk Kim /* 215139a53e0cSJaegeuk Kim * namei.c 215239a53e0cSJaegeuk Kim */ 215339a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 215439a53e0cSJaegeuk Kim 215539a53e0cSJaegeuk Kim /* 215639a53e0cSJaegeuk Kim * dir.c 215739a53e0cSJaegeuk Kim */ 2158cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2159cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2160cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2161cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2162cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2163cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2164cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2165cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2166cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2167cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2168cac5a3d8SDongOh Shin const struct qstr *new_name, 2169cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2170cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2171cac5a3d8SDongOh Shin unsigned int current_depth); 2172cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2173cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2174cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2175cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2176cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2177cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2178cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2179cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2180cac5a3d8SDongOh Shin struct page **page); 2181cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2182cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2183cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2184cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2185cac5a3d8SDongOh Shin unsigned int bit_pos); 2186cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2187cac5a3d8SDongOh Shin const struct qstr *orig_name, 2188cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2189cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2190cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2191cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2192cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2193cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2194cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2195cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2196cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 219739a53e0cSJaegeuk Kim 2198b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2199b7f7a5e0SAl Viro { 22002b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2201510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2202b7f7a5e0SAl Viro } 2203b7f7a5e0SAl Viro 220439a53e0cSJaegeuk Kim /* 220539a53e0cSJaegeuk Kim * super.c 220639a53e0cSJaegeuk Kim */ 2207cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2208cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2209cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2210cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2211a07ef784SNamjae Jeon extern __printf(3, 4) 2212cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2213984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 221439a53e0cSJaegeuk Kim 221539a53e0cSJaegeuk Kim /* 221639a53e0cSJaegeuk Kim * hash.c 221739a53e0cSJaegeuk Kim */ 22186332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, 22196332cd32SJaegeuk Kim struct fscrypt_name *fname); 222039a53e0cSJaegeuk Kim 222139a53e0cSJaegeuk Kim /* 222239a53e0cSJaegeuk Kim * node.c 222339a53e0cSJaegeuk Kim */ 222439a53e0cSJaegeuk Kim struct dnode_of_data; 222539a53e0cSJaegeuk Kim struct node_info; 222639a53e0cSJaegeuk Kim 2227cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2228cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2229cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2230cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2231cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2232cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2233cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2234cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2235cac5a3d8SDongOh Shin int truncate_xattr_node(struct inode *inode, struct page *page); 2236cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2237cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2238cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 2239cac5a3d8SDongOh Shin struct page *new_node_page(struct dnode_of_data *dn, 2240cac5a3d8SDongOh Shin unsigned int ofs, struct page *ipage); 2241cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2242cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2243cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2244cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2245cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2246cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2247cac5a3d8SDongOh Shin int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc); 224822ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2249cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2250cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2251cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2252cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2253cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2254d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2255cac5a3d8SDongOh Shin block_t blkaddr); 2256cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2257cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2258cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 225922ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2260cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2261cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 22626e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 226339a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 226439a53e0cSJaegeuk Kim 226539a53e0cSJaegeuk Kim /* 226639a53e0cSJaegeuk Kim * segment.c 226739a53e0cSJaegeuk Kim */ 2268cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 2269cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 22708c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2271cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2272cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2273cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2274cac5a3d8SDongOh Shin int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2275cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2276cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2277cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2278cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2279cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2280d431413fSChao Yu void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2281cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2282cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2283cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2284cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2285cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2286cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2287cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2288cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2289cac5a3d8SDongOh Shin void write_meta_page(struct f2fs_sb_info *sbi, struct page *page); 2290cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2291cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2292d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2293cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2294cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2295cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2296cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2297cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2298cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2299cac5a3d8SDongOh Shin bool recover_newaddr); 2300cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2301cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2302fb830fc5SChao Yu struct f2fs_summary *sum, int type, 2303fb830fc5SChao Yu struct f2fs_io_info *fio, bool add_list); 2304cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2305cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2306cac5a3d8SDongOh Shin void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2307cac5a3d8SDongOh Shin block_t blkaddr); 2308cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2309cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2310cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2311cac5a3d8SDongOh Shin unsigned int val, int alloc); 2312cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2313cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2314cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 23157fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 23167fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 231739a53e0cSJaegeuk Kim 231839a53e0cSJaegeuk Kim /* 231939a53e0cSJaegeuk Kim * checkpoint.c 232039a53e0cSJaegeuk Kim */ 2321cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2322cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2323cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2324cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2325cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2326cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2327cac5a3d8SDongOh Shin int type, bool sync); 2328cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2329cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2330cac5a3d8SDongOh Shin long nr_to_write); 2331cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2332cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2333cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2334cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2335cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2336cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2337cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2338cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2339cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2340cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2341cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2342cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2343cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2344cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2345cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2346cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 23476e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 234839a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 234939a53e0cSJaegeuk Kim 235039a53e0cSJaegeuk Kim /* 235139a53e0cSJaegeuk Kim * data.c 235239a53e0cSJaegeuk Kim */ 2353b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 2354b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 2355942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2356b9109b0eSJaegeuk Kim enum page_type type); 2357b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 2358cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2359b9109b0eSJaegeuk Kim int f2fs_submit_page_write(struct f2fs_io_info *fio); 2360cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2361cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2362cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2363cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2364cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2365cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2366cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2367cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2368cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2369cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2370cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2371cac5a3d8SDongOh Shin int op_flags, bool for_write); 2372cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2373cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2374cac5a3d8SDongOh Shin bool for_write); 2375cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2376cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2377cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2378cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2379cac5a3d8SDongOh Shin int create, int flag); 2380cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2381cac5a3d8SDongOh Shin u64 start, u64 len); 2382cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2383cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2384cac5a3d8SDongOh Shin unsigned int length); 2385cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 23865b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2387cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2388cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 23895b7a487cSWeichao Guo #endif 239039a53e0cSJaegeuk Kim 239139a53e0cSJaegeuk Kim /* 239239a53e0cSJaegeuk Kim * gc.c 239339a53e0cSJaegeuk Kim */ 2394cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2395cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2396cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2397e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 2398e066b83cSJaegeuk Kim unsigned int segno); 2399cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 240039a53e0cSJaegeuk Kim 240139a53e0cSJaegeuk Kim /* 240239a53e0cSJaegeuk Kim * recovery.c 240339a53e0cSJaegeuk Kim */ 2404cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2405cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 240639a53e0cSJaegeuk Kim 240739a53e0cSJaegeuk Kim /* 240839a53e0cSJaegeuk Kim * debug.c 240939a53e0cSJaegeuk Kim */ 241039a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 241139a53e0cSJaegeuk Kim struct f2fs_stat_info { 241239a53e0cSJaegeuk Kim struct list_head stat_list; 241339a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 241439a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 241539a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 24165b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 24175b7ee374SChao Yu unsigned long long hit_total, total_ext; 2418c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 241935782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 242035782b23SJaegeuk Kim int inmem_pages; 24210f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 24225b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 24235b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 242439a53e0cSJaegeuk Kim int total_count, utilization; 24258b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 24268b8dd65fSChao Yu int nr_flushing, nr_flushed, nr_discarding, nr_discarded; 24275f32366aSChao Yu int nr_discard_cmd; 2428d84d1cbdSChao Yu unsigned int undiscard_blks; 2429a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2430648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2431f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 243239a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 243339a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 243439a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 243539a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 243642190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 243739a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2438e1235983SChangman Lee int bg_node_segs, bg_data_segs; 243939a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2440e1235983SChangman Lee int bg_data_blks, bg_node_blks; 244139a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 244239a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 244339a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 244439a53e0cSJaegeuk Kim 244539a53e0cSJaegeuk Kim unsigned int segment_count[2]; 244639a53e0cSJaegeuk Kim unsigned int block_count[2]; 2447b9a2c252SChangman Lee unsigned int inplace_count; 24489edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 244939a53e0cSJaegeuk Kim }; 245039a53e0cSJaegeuk Kim 2451963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2452963d4f7dSGu Zheng { 2453963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2454963d4f7dSGu Zheng } 2455963d4f7dSGu Zheng 2456942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 245742190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 245839a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2459dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 246033fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 246133fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 24625b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 24635b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 24645b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 24655b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2466d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2467d5e8f6c9SChao Yu do { \ 2468d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2469d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2470d5e8f6c9SChao Yu } while (0) 2471d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2472d5e8f6c9SChao Yu do { \ 2473d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2474d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2475d5e8f6c9SChao Yu } while (0) 24760dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 24770dbdc2aeSJaegeuk Kim do { \ 24780dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 247903e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 24800dbdc2aeSJaegeuk Kim } while (0) 24810dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 24820dbdc2aeSJaegeuk Kim do { \ 24830dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 248403e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 24850dbdc2aeSJaegeuk Kim } while (0) 24863289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 24873289c061SJaegeuk Kim do { \ 24883289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 248903e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 24903289c061SJaegeuk Kim } while (0) 24913289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 24923289c061SJaegeuk Kim do { \ 24933289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 249403e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 24953289c061SJaegeuk Kim } while (0) 2496dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2497dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2498dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2499dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2500b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2501b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 250226a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2503cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 250426a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2505cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 250626a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 250726a28a0cSJaegeuk Kim do { \ 250826a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 250926a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 251026a28a0cSJaegeuk Kim if (cur > max) \ 251126a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 251226a28a0cSJaegeuk Kim } while (0) 2513648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2514648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2515648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2516648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2517648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2518648d50baSChao Yu do { \ 2519648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2520648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2521648d50baSChao Yu if (cur > max) \ 2522648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2523648d50baSChao Yu } while (0) 2524e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 252539a53e0cSJaegeuk Kim do { \ 2526963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 252768afcf2dSTomohiro Kusumi si->tot_segs++; \ 252868afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 252939a53e0cSJaegeuk Kim si->data_segs++; \ 2530e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2531e1235983SChangman Lee } else { \ 253239a53e0cSJaegeuk Kim si->node_segs++; \ 2533e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2534e1235983SChangman Lee } \ 253539a53e0cSJaegeuk Kim } while (0) 253639a53e0cSJaegeuk Kim 253739a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 253868afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 253939a53e0cSJaegeuk Kim 2540e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 254139a53e0cSJaegeuk Kim do { \ 2542963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 254339a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 254439a53e0cSJaegeuk Kim si->data_blks += (blks); \ 254568afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 254639a53e0cSJaegeuk Kim } while (0) 254739a53e0cSJaegeuk Kim 2548e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 254939a53e0cSJaegeuk Kim do { \ 2550963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 255139a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 255239a53e0cSJaegeuk Kim si->node_blks += (blks); \ 255368afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 255439a53e0cSJaegeuk Kim } while (0) 255539a53e0cSJaegeuk Kim 2556cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2557cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2558787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 25594589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 256039a53e0cSJaegeuk Kim #else 2561d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 2562d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 2563d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 2564d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 2565d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 2566d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 2567d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 2568d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 2569d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 2570d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 2571d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 2572d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 2573d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 2574d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 2575d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 2576d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 2577d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 2578d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 2579d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 2580d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 2581d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 2582d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 2583d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 2584d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 2585d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 2586d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 2587d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 2588d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 2589d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 259039a53e0cSJaegeuk Kim 259139a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 259239a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2593787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 25944589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 259539a53e0cSJaegeuk Kim #endif 259639a53e0cSJaegeuk Kim 259739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 259839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 259939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 260039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 260139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 260239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 260339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 260439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2605cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 260639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 260729e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 26081001b347SHuajun Li 2609e18c65b2SHuajun Li /* 2610e18c65b2SHuajun Li * inline.c 2611e18c65b2SHuajun Li */ 2612cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2613cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2614cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2615bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2616cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2617cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2618cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2619cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2620cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2621cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2622cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2623cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2624cac5a3d8SDongOh Shin struct page *ipage); 2625cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2626cac5a3d8SDongOh Shin const struct qstr *orig_name, 2627cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2628cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2629cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2630cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2631cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2632cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2633cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2634cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2635cac5a3d8SDongOh Shin __u64 start, __u64 len); 2636cde4de12SJaegeuk Kim 2637cde4de12SJaegeuk Kim /* 26382658e50dSJaegeuk Kim * shrinker.c 26392658e50dSJaegeuk Kim */ 2640cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2641cac5a3d8SDongOh Shin struct shrink_control *sc); 2642cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2643cac5a3d8SDongOh Shin struct shrink_control *sc); 2644cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2645cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 26462658e50dSJaegeuk Kim 26472658e50dSJaegeuk Kim /* 2648a28ef1f5SChao Yu * extent_cache.c 2649a28ef1f5SChao Yu */ 2650004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 2651004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 2652004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 2653004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 2654004b6862SChao Yu unsigned int ofs); 2655004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 2656004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 2657004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 2658004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 2659004b6862SChao Yu bool force); 2660df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi, 2661df0f6b44SChao Yu struct rb_root *root); 2662cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2663cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2664cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2665cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2666cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2667cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2668cac5a3d8SDongOh Shin struct extent_info *ei); 2669cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 267019b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2671cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2672cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2673a28ef1f5SChao Yu int __init create_extent_cache(void); 2674a28ef1f5SChao Yu void destroy_extent_cache(void); 2675a28ef1f5SChao Yu 2676a28ef1f5SChao Yu /* 2677*8ceffcb2SChao Yu * sysfs.c 2678*8ceffcb2SChao Yu */ 2679*8ceffcb2SChao Yu int __init f2fs_register_sysfs(void); 2680*8ceffcb2SChao Yu void f2fs_unregister_sysfs(void); 2681*8ceffcb2SChao Yu int f2fs_init_sysfs(struct f2fs_sb_info *sbi); 2682*8ceffcb2SChao Yu void f2fs_exit_sysfs(struct f2fs_sb_info *sbi); 2683*8ceffcb2SChao Yu 2684*8ceffcb2SChao Yu /* 2685cde4de12SJaegeuk Kim * crypto support 2686cde4de12SJaegeuk Kim */ 26870b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2688cde4de12SJaegeuk Kim { 2689cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2690cde4de12SJaegeuk Kim } 2691cde4de12SJaegeuk Kim 2692cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2693cde4de12SJaegeuk Kim { 2694cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2695cde4de12SJaegeuk Kim file_set_encrypt(inode); 2696cde4de12SJaegeuk Kim #endif 2697cde4de12SJaegeuk Kim } 2698cde4de12SJaegeuk Kim 2699cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2700cde4de12SJaegeuk Kim { 27010b81d077SJaegeuk Kim return bio->bi_private != NULL; 2702cde4de12SJaegeuk Kim } 2703cde4de12SJaegeuk Kim 2704cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2705cde4de12SJaegeuk Kim { 2706cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2707cde4de12SJaegeuk Kim } 2708f424f664SJaegeuk Kim 27090bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 271052763a4bSJaegeuk Kim { 27110bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 271252763a4bSJaegeuk Kim } 271352763a4bSJaegeuk Kim 2714178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2715178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 27163c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2717178053e2SDamien Le Moal { 2718178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 27193c62be17SJaegeuk Kim int i; 2720178053e2SDamien Le Moal 27213c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 27223c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 27233c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 27243c62be17SJaegeuk Kim return -EINVAL; 2725178053e2SDamien Le Moal } 2726178053e2SDamien Le Moal #endif 2727178053e2SDamien Le Moal 272896ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 272996ba2decSDamien Le Moal { 273096ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 273196ba2decSDamien Le Moal 273296ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 273352763a4bSJaegeuk Kim } 273452763a4bSJaegeuk Kim 273552763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 273652763a4bSJaegeuk Kim { 273752763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 273852763a4bSJaegeuk Kim clear_opt(sbi, LFS); 273952763a4bSJaegeuk Kim 274052763a4bSJaegeuk Kim switch (mt) { 274152763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 274252763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 274352763a4bSJaegeuk Kim break; 274452763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 274552763a4bSJaegeuk Kim set_opt(sbi, LFS); 274652763a4bSJaegeuk Kim break; 274752763a4bSJaegeuk Kim } 274852763a4bSJaegeuk Kim } 274952763a4bSJaegeuk Kim 2750fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2751fcc85a4dSJaegeuk Kim { 2752fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2753886f56f9SAl Viro umode_t mode = inode->i_mode; 2754fcc85a4dSJaegeuk Kim 2755fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2756fcc85a4dSJaegeuk Kim #else 2757fcc85a4dSJaegeuk Kim return 0; 2758fcc85a4dSJaegeuk Kim #endif 2759fcc85a4dSJaegeuk Kim } 2760fcc85a4dSJaegeuk Kim 276139a53e0cSJaegeuk Kim #endif 2762