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 */ 52239a53e0cSJaegeuk Kim }; 52339a53e0cSJaegeuk Kim 52439a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 525bd933d4fSChao Yu struct f2fs_extent *i_ext) 52639a53e0cSJaegeuk Kim { 527bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 528bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 529bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 53039a53e0cSJaegeuk Kim } 53139a53e0cSJaegeuk Kim 53239a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 53339a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 53439a53e0cSJaegeuk Kim { 53539a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 5364d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 53739a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 53839a53e0cSJaegeuk Kim } 53939a53e0cSJaegeuk Kim 540429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 541429511cdSChao Yu u32 blk, unsigned int len) 542429511cdSChao Yu { 543429511cdSChao Yu ei->fofs = fofs; 544429511cdSChao Yu ei->blk = blk; 545429511cdSChao Yu ei->len = len; 546429511cdSChao Yu } 547429511cdSChao Yu 548004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 549004b6862SChao Yu struct discard_info *front) 550004b6862SChao Yu { 551004b6862SChao Yu return back->lstart + back->len == front->lstart; 552004b6862SChao Yu } 553004b6862SChao Yu 554004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 555004b6862SChao Yu struct discard_info *back) 556004b6862SChao Yu { 557004b6862SChao Yu return __is_discard_mergeable(back, cur); 558004b6862SChao Yu } 559004b6862SChao Yu 560004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 561004b6862SChao Yu struct discard_info *front) 562004b6862SChao Yu { 563004b6862SChao Yu return __is_discard_mergeable(cur, front); 564004b6862SChao Yu } 565004b6862SChao Yu 566429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 567429511cdSChao Yu struct extent_info *front) 568429511cdSChao Yu { 569429511cdSChao Yu return (back->fofs + back->len == front->fofs && 570429511cdSChao Yu back->blk + back->len == front->blk); 571429511cdSChao Yu } 572429511cdSChao Yu 573429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 574429511cdSChao Yu struct extent_info *back) 575429511cdSChao Yu { 576429511cdSChao Yu return __is_extent_mergeable(back, cur); 577429511cdSChao Yu } 578429511cdSChao Yu 579429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 580429511cdSChao Yu struct extent_info *front) 581429511cdSChao Yu { 582429511cdSChao Yu return __is_extent_mergeable(cur, front); 583429511cdSChao Yu } 584429511cdSChao Yu 585cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 586205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 587205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 5884abd3f5aSChao Yu { 589205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 5904abd3f5aSChao Yu et->largest = en->ei; 5917c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 592205b9822SJaegeuk Kim } 5934abd3f5aSChao Yu } 5944abd3f5aSChao Yu 595b8559dc2SChao Yu enum nid_list { 596b8559dc2SChao Yu FREE_NID_LIST, 597b8559dc2SChao Yu ALLOC_NID_LIST, 598b8559dc2SChao Yu MAX_NID_LIST, 599b8559dc2SChao Yu }; 600b8559dc2SChao Yu 60139a53e0cSJaegeuk Kim struct f2fs_nm_info { 60239a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 60339a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 60404d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 60539a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 606cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 607ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 6082304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 60939a53e0cSJaegeuk Kim 61039a53e0cSJaegeuk Kim /* NAT cache management */ 61139a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 612309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 613b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 61439a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 615309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 616aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 61722ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 61839a53e0cSJaegeuk Kim 61939a53e0cSJaegeuk Kim /* free node ids management */ 6208a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 621b8559dc2SChao Yu struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ 622b8559dc2SChao Yu unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 623b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 62439a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 6254ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 6264ac91242SChao Yu unsigned char *nat_block_bitmap; 627586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 62839a53e0cSJaegeuk Kim 62939a53e0cSJaegeuk Kim /* for checkpoint */ 63039a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 63122ad0b6aSJaegeuk Kim 63222ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 63322ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 63422ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 63522ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 636599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 637599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 638599a09b2SChao Yu #endif 63939a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 64039a53e0cSJaegeuk Kim }; 64139a53e0cSJaegeuk Kim 64239a53e0cSJaegeuk Kim /* 64339a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 64439a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 64539a53e0cSJaegeuk Kim * by the data offset in a file. 64639a53e0cSJaegeuk Kim */ 64739a53e0cSJaegeuk Kim struct dnode_of_data { 64839a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 64939a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 65039a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 65139a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 65239a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 65339a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 65493bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 6553cf45747SChao Yu char cur_level; /* level of hole node page */ 6563cf45747SChao Yu char max_level; /* level of current page located */ 65739a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 65839a53e0cSJaegeuk Kim }; 65939a53e0cSJaegeuk Kim 66039a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 66139a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 66239a53e0cSJaegeuk Kim { 663d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 66439a53e0cSJaegeuk Kim dn->inode = inode; 66539a53e0cSJaegeuk Kim dn->inode_page = ipage; 66639a53e0cSJaegeuk Kim dn->node_page = npage; 66739a53e0cSJaegeuk Kim dn->nid = nid; 66839a53e0cSJaegeuk Kim } 66939a53e0cSJaegeuk Kim 67039a53e0cSJaegeuk Kim /* 67139a53e0cSJaegeuk Kim * For SIT manager 67239a53e0cSJaegeuk Kim * 67339a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 67439a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 67539a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 67639a53e0cSJaegeuk Kim * respectively. 67739a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 67839a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 67939a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 68039a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 68139a53e0cSJaegeuk Kim * data and 8 for node logs. 68239a53e0cSJaegeuk Kim */ 68339a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 68439a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 68539a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 68639a53e0cSJaegeuk Kim 68739a53e0cSJaegeuk Kim enum { 68839a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 68939a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 69039a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 69139a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 69239a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 69339a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 69438aa0889SJaegeuk Kim NO_CHECK_TYPE, 69539a53e0cSJaegeuk Kim }; 69639a53e0cSJaegeuk Kim 6976b4afdd7SJaegeuk Kim struct flush_cmd { 6986b4afdd7SJaegeuk Kim struct completion wait; 699721bd4d5SGu Zheng struct llist_node llnode; 7006b4afdd7SJaegeuk Kim int ret; 7016b4afdd7SJaegeuk Kim }; 7026b4afdd7SJaegeuk Kim 703a688b9d9SGu Zheng struct flush_cmd_control { 704a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 705a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 7068b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 7078b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 708721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 709721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 710a688b9d9SGu Zheng }; 711a688b9d9SGu Zheng 71239a53e0cSJaegeuk Kim struct f2fs_sm_info { 71339a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 71439a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 71539a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 71639a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 71739a53e0cSJaegeuk Kim 71839a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 71939a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 72039a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 72139a53e0cSJaegeuk Kim 72239a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 72339a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 72439a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 72539a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 72681eb8d6eSJaegeuk Kim 72781eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 72881eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 7297fd9e544SJaegeuk Kim 730bba681cbSJaegeuk Kim /* for batched trimming */ 731bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 732bba681cbSJaegeuk Kim 733184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 734184a5cd2SChao Yu 735216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 736216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 737c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 738ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 7396b4afdd7SJaegeuk Kim 7406b4afdd7SJaegeuk Kim /* for flush command control */ 741b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 742a688b9d9SGu Zheng 7430b54fb84SJaegeuk Kim /* for discard command control */ 7440b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 74539a53e0cSJaegeuk Kim }; 74639a53e0cSJaegeuk Kim 74739a53e0cSJaegeuk Kim /* 74839a53e0cSJaegeuk Kim * For superblock 74939a53e0cSJaegeuk Kim */ 75039a53e0cSJaegeuk Kim /* 75139a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 75239a53e0cSJaegeuk Kim * 75339a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 75439a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 75539a53e0cSJaegeuk Kim */ 75636951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 75739a53e0cSJaegeuk Kim enum count_type { 75839a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 759c227f912SChao Yu F2FS_DIRTY_DATA, 76039a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 76139a53e0cSJaegeuk Kim F2FS_DIRTY_META, 7628dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 7630f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 76436951b38SChao Yu F2FS_WB_CP_DATA, 76536951b38SChao Yu F2FS_WB_DATA, 76639a53e0cSJaegeuk Kim NR_COUNT_TYPE, 76739a53e0cSJaegeuk Kim }; 76839a53e0cSJaegeuk Kim 76939a53e0cSJaegeuk Kim /* 770e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 77139a53e0cSJaegeuk Kim * The available types are: 77239a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 77339a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 77439a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 77539a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 77639a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 77739a53e0cSJaegeuk Kim * with waiting the bio's completion 77839a53e0cSJaegeuk Kim * ... Only can be used with META. 77939a53e0cSJaegeuk Kim */ 7807d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 78139a53e0cSJaegeuk Kim enum page_type { 78239a53e0cSJaegeuk Kim DATA, 78339a53e0cSJaegeuk Kim NODE, 78439a53e0cSJaegeuk Kim META, 78539a53e0cSJaegeuk Kim NR_PAGE_TYPE, 78639a53e0cSJaegeuk Kim META_FLUSH, 7878ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 7888ce67cb0SJaegeuk Kim INMEM_DROP, 7898c242db9SJaegeuk Kim INMEM_INVALIDATE, 79028bc106bSChao Yu INMEM_REVOKE, 7918ce67cb0SJaegeuk Kim IPU, 7928ce67cb0SJaegeuk Kim OPU, 79339a53e0cSJaegeuk Kim }; 79439a53e0cSJaegeuk Kim 795a912b54dSJaegeuk Kim enum temp_type { 796a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 797a912b54dSJaegeuk Kim WARM, 798a912b54dSJaegeuk Kim COLD, 799a912b54dSJaegeuk Kim NR_TEMP_TYPE, 800a912b54dSJaegeuk Kim }; 801a912b54dSJaegeuk Kim 802*cc15620bSJaegeuk Kim enum need_lock_type { 803*cc15620bSJaegeuk Kim LOCK_REQ = 0, 804*cc15620bSJaegeuk Kim LOCK_DONE, 805*cc15620bSJaegeuk Kim LOCK_RETRY, 806*cc15620bSJaegeuk Kim }; 807*cc15620bSJaegeuk Kim 808458e6197SJaegeuk Kim struct f2fs_io_info { 80905ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 810458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 811a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 81204d328deSMike Christie int op; /* contains REQ_OP_ */ 813ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 8147a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 81528bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 81605ca3632SJaegeuk Kim struct page *page; /* page to be written */ 8174375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 818d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 819*cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 820458e6197SJaegeuk Kim }; 821458e6197SJaegeuk Kim 82268afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 8231ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 824458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 8251ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 8261ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 827458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 828df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 8291ff7bd3bSJaegeuk Kim }; 8301ff7bd3bSJaegeuk Kim 8313c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 8323c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 8333c62be17SJaegeuk Kim struct f2fs_dev_info { 8343c62be17SJaegeuk Kim struct block_device *bdev; 8353c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 8363c62be17SJaegeuk Kim unsigned int total_segments; 8373c62be17SJaegeuk Kim block_t start_blk; 8383c62be17SJaegeuk Kim block_t end_blk; 8393c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 8403c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 8413c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 8423c62be17SJaegeuk Kim #endif 8433c62be17SJaegeuk Kim }; 8443c62be17SJaegeuk Kim 845c227f912SChao Yu enum inode_type { 846c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 847c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 8480f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 849c227f912SChao Yu NR_INODE_TYPE, 850c227f912SChao Yu }; 851c227f912SChao Yu 85267298804SChao Yu /* for inner inode cache management */ 85367298804SChao Yu struct inode_management { 85467298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 85567298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 85667298804SChao Yu struct list_head ino_list; /* inode list head */ 85767298804SChao Yu unsigned long ino_num; /* number of entries */ 85867298804SChao Yu }; 85967298804SChao Yu 860caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 861caf0047eSChao Yu enum { 862caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 863caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 864caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 865caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 866df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 867bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 868caf0047eSChao Yu }; 869caf0047eSChao Yu 8706beceb54SJaegeuk Kim enum { 8716beceb54SJaegeuk Kim CP_TIME, 872d0239e1bSJaegeuk Kim REQ_TIME, 8736beceb54SJaegeuk Kim MAX_TIME, 8746beceb54SJaegeuk Kim }; 8756beceb54SJaegeuk Kim 87639a53e0cSJaegeuk Kim struct f2fs_sb_info { 87739a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 8785e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 87939a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 880e8240f65SChao Yu int valid_super_block; /* valid super block no */ 881fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 88239a53e0cSJaegeuk Kim 883178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 884178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 885178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 886178053e2SDamien Le Moal #endif 887178053e2SDamien Le Moal 88839a53e0cSJaegeuk Kim /* for node-related operations */ 88939a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 89039a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 89139a53e0cSJaegeuk Kim 89239a53e0cSJaegeuk Kim /* for segment-related operations */ 89339a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 8941ff7bd3bSJaegeuk Kim 8951ff7bd3bSJaegeuk Kim /* for bio operations */ 896a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 8977dfeaa32SJaegeuk Kim struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ 8980a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 8990a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 90039a53e0cSJaegeuk Kim 90139a53e0cSJaegeuk Kim /* for checkpoint */ 90239a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 9038508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 904aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 90539a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 90639936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 907b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 908b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 90959c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 910fb51b5efSChangman Lee wait_queue_head_t cp_wait; 9116beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 9126beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 91339a53e0cSJaegeuk Kim 91467298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 9156451e041SJaegeuk Kim 9166451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 9170d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 91839a53e0cSJaegeuk Kim 919c227f912SChao Yu /* for inode management */ 920c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 921c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 92239a53e0cSJaegeuk Kim 92313054c54SChao Yu /* for extent tree cache */ 92413054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 9255e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 92613054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 92713054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 9287441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 929137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 93074fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 93113054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 93213054c54SChao Yu 93339a53e0cSJaegeuk Kim /* basic filesystem units */ 93439a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 93539a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 93639a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 93739a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 93839a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 93939a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 94039a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 94139a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 94239a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 94339a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 94439a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 94539a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 94639a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 947e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 94839a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 949ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 95039a53e0cSJaegeuk Kim 95139a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 95239a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 953a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 95439a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 95539a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 956523be8a6SJaegeuk Kim 957523be8a6SJaegeuk Kim /* # of pages, see count_type */ 95835782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 95941382ec4SJaegeuk Kim /* # of allocated blocks */ 96041382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 96139a53e0cSJaegeuk Kim 962687de7f1SJaegeuk Kim /* writeback control */ 963687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 964687de7f1SJaegeuk Kim 965513c5f37SJaegeuk Kim /* valid inode count */ 966513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 967513c5f37SJaegeuk Kim 96839a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 96939a53e0cSJaegeuk Kim 97039a53e0cSJaegeuk Kim /* for cleaning operations */ 97139a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 97239a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 9735ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 97439a53e0cSJaegeuk Kim 975e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 976e93b9865SHou Pengyang u64 fggc_threshold; 977e93b9865SHou Pengyang 978b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 979b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 980b1c57c1cSJaegeuk Kim 98139a53e0cSJaegeuk Kim /* 98239a53e0cSJaegeuk Kim * for stat information. 98339a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 98439a53e0cSJaegeuk Kim */ 98535b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 98639a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 98739a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 98839a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 989b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 9905b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 9915b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 9925b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 9935b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 994d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 99503e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 99603e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 99726a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 998648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 99926a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1000648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 100139a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 100233fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 100335b09d82SNamjae Jeon #endif 100439a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1005b59d0baeSNamjae Jeon 1006b59d0baeSNamjae Jeon /* For sysfs suppport */ 1007b59d0baeSNamjae Jeon struct kobject s_kobj; 1008b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 10092658e50dSJaegeuk Kim 10102658e50dSJaegeuk Kim /* For shrinker support */ 10112658e50dSJaegeuk Kim struct list_head s_list; 10123c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 10133c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 10142658e50dSJaegeuk Kim struct mutex umount_mutex; 10152658e50dSJaegeuk Kim unsigned int shrinker_run_no; 10168f1dbbbbSShuoran Liu 10178f1dbbbbSShuoran Liu /* For write statistics */ 10188f1dbbbbSShuoran Liu u64 sectors_written_start; 10198f1dbbbbSShuoran Liu u64 kbytes_written; 102043b6573bSKeith Mok 102143b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 102243b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 10231ecc0c5cSChao Yu 10241ecc0c5cSChao Yu /* For fault injection */ 10251ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 10261ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 10271ecc0c5cSChao Yu #endif 102839a53e0cSJaegeuk Kim }; 102939a53e0cSJaegeuk Kim 10301ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 103155523519SChao Yu #define f2fs_show_injection_info(type) \ 103255523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 103355523519SChao Yu KERN_INFO, fault_name[type], \ 103455523519SChao Yu __func__, __builtin_return_address(0)) 10351ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 10361ecc0c5cSChao Yu { 10371ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 10381ecc0c5cSChao Yu 10391ecc0c5cSChao Yu if (!ffi->inject_rate) 10401ecc0c5cSChao Yu return false; 10411ecc0c5cSChao Yu 10421ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 10431ecc0c5cSChao Yu return false; 10441ecc0c5cSChao Yu 10451ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 10461ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 10471ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 10481ecc0c5cSChao Yu return true; 10491ecc0c5cSChao Yu } 10501ecc0c5cSChao Yu return false; 10511ecc0c5cSChao Yu } 10521ecc0c5cSChao Yu #endif 10531ecc0c5cSChao Yu 10548f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 10558f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 10568f1dbbbbSShuoran Liu */ 10578f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 105868afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 105968afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 10608f1dbbbbSShuoran Liu 10616beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 10626beceb54SJaegeuk Kim { 10636beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 10646beceb54SJaegeuk Kim } 10656beceb54SJaegeuk Kim 10666beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 10676beceb54SJaegeuk Kim { 10686beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 10696beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 10706beceb54SJaegeuk Kim 10716beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 10726beceb54SJaegeuk Kim } 10736beceb54SJaegeuk Kim 1074d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1075d0239e1bSJaegeuk Kim { 1076d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1077d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1078d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1079d0239e1bSJaegeuk Kim 1080d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1081d0239e1bSJaegeuk Kim return 0; 1082d0239e1bSJaegeuk Kim 1083d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1084d0239e1bSJaegeuk Kim } 1085d0239e1bSJaegeuk Kim 108639a53e0cSJaegeuk Kim /* 108739a53e0cSJaegeuk Kim * Inline functions 108839a53e0cSJaegeuk Kim */ 108943b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 109043b6573bSKeith Mok unsigned int length) 109143b6573bSKeith Mok { 109243b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 109343b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 109443b6573bSKeith Mok int err; 109543b6573bSKeith Mok 109643b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 109743b6573bSKeith Mok shash->flags = 0; 109843b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 109943b6573bSKeith Mok 110043b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 110143b6573bSKeith Mok BUG_ON(err); 110243b6573bSKeith Mok 110343b6573bSKeith Mok return *ctx; 110443b6573bSKeith Mok } 110543b6573bSKeith Mok 110643b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 110743b6573bSKeith Mok void *buf, size_t buf_size) 110843b6573bSKeith Mok { 110943b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 111043b6573bSKeith Mok } 111143b6573bSKeith Mok 111239a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 111339a53e0cSJaegeuk Kim { 111439a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 111539a53e0cSJaegeuk Kim } 111639a53e0cSJaegeuk Kim 111739a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 111839a53e0cSJaegeuk Kim { 111939a53e0cSJaegeuk Kim return sb->s_fs_info; 112039a53e0cSJaegeuk Kim } 112139a53e0cSJaegeuk Kim 11224081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 11234081363fSJaegeuk Kim { 11244081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 11254081363fSJaegeuk Kim } 11264081363fSJaegeuk Kim 11274081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 11284081363fSJaegeuk Kim { 11294081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 11304081363fSJaegeuk Kim } 11314081363fSJaegeuk Kim 11324081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 11334081363fSJaegeuk Kim { 11344081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 11354081363fSJaegeuk Kim } 11364081363fSJaegeuk Kim 113739a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 113839a53e0cSJaegeuk Kim { 113939a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 114039a53e0cSJaegeuk Kim } 114139a53e0cSJaegeuk Kim 114239a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 114339a53e0cSJaegeuk Kim { 114439a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 114539a53e0cSJaegeuk Kim } 114639a53e0cSJaegeuk Kim 114745590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 114845590710SGu Zheng { 114945590710SGu Zheng return (struct f2fs_node *)page_address(page); 115045590710SGu Zheng } 115145590710SGu Zheng 115258bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 115358bfaf44SJaegeuk Kim { 115458bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 115558bfaf44SJaegeuk Kim } 115658bfaf44SJaegeuk Kim 115739a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 115839a53e0cSJaegeuk Kim { 115939a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 116039a53e0cSJaegeuk Kim } 116139a53e0cSJaegeuk Kim 116239a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 116339a53e0cSJaegeuk Kim { 116439a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 116539a53e0cSJaegeuk Kim } 116639a53e0cSJaegeuk Kim 116739a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 116839a53e0cSJaegeuk Kim { 116939a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 117039a53e0cSJaegeuk Kim } 117139a53e0cSJaegeuk Kim 117239a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 117339a53e0cSJaegeuk Kim { 117439a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 117539a53e0cSJaegeuk Kim } 117639a53e0cSJaegeuk Kim 117739a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 117839a53e0cSJaegeuk Kim { 117939a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 118039a53e0cSJaegeuk Kim } 118139a53e0cSJaegeuk Kim 11829df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 11839df27d98SGu Zheng { 11849df27d98SGu Zheng return sbi->meta_inode->i_mapping; 11859df27d98SGu Zheng } 11869df27d98SGu Zheng 11874ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 11884ef51a8fSJaegeuk Kim { 11894ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 11904ef51a8fSJaegeuk Kim } 11914ef51a8fSJaegeuk Kim 1192caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 119339a53e0cSJaegeuk Kim { 1194fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 119539a53e0cSJaegeuk Kim } 119639a53e0cSJaegeuk Kim 1197caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 119839a53e0cSJaegeuk Kim { 1199fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1200caf0047eSChao Yu } 1201caf0047eSChao Yu 1202caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1203caf0047eSChao Yu { 1204fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 120539a53e0cSJaegeuk Kim } 120639a53e0cSJaegeuk Kim 1207d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1208d71b5564SJaegeuk Kim { 1209d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1210d71b5564SJaegeuk Kim } 1211d71b5564SJaegeuk Kim 1212ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1213ced2c7eaSKinglong Mee { 1214ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1215ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1216ced2c7eaSKinglong Mee } 1217ced2c7eaSKinglong Mee 1218aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 121925ca923bSJaegeuk Kim { 122025ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1221aaec2b1dSChao Yu 122225ca923bSJaegeuk Kim return ckpt_flags & f; 122325ca923bSJaegeuk Kim } 122425ca923bSJaegeuk Kim 1225aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 122625ca923bSJaegeuk Kim { 1227aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1228aaec2b1dSChao Yu } 1229aaec2b1dSChao Yu 1230aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1231aaec2b1dSChao Yu { 1232aaec2b1dSChao Yu unsigned int ckpt_flags; 1233aaec2b1dSChao Yu 1234aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 123525ca923bSJaegeuk Kim ckpt_flags |= f; 123625ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 123725ca923bSJaegeuk Kim } 123825ca923bSJaegeuk Kim 1239aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 124025ca923bSJaegeuk Kim { 1241aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1242aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1243aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1244aaec2b1dSChao Yu } 1245aaec2b1dSChao Yu 1246aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1247aaec2b1dSChao Yu { 1248aaec2b1dSChao Yu unsigned int ckpt_flags; 1249aaec2b1dSChao Yu 1250aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 125125ca923bSJaegeuk Kim ckpt_flags &= (~f); 125225ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 125325ca923bSJaegeuk Kim } 125425ca923bSJaegeuk Kim 1255aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1256aaec2b1dSChao Yu { 1257aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1258aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1259aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1260aaec2b1dSChao Yu } 1261aaec2b1dSChao Yu 126222ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 126322ad0b6aSJaegeuk Kim { 126422ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 126522ad0b6aSJaegeuk Kim 126622ad0b6aSJaegeuk Kim if (lock) 126722ad0b6aSJaegeuk Kim spin_lock(&sbi->cp_lock); 126822ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 126922ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 127022ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 127122ad0b6aSJaegeuk Kim if (lock) 127222ad0b6aSJaegeuk Kim spin_unlock(&sbi->cp_lock); 127322ad0b6aSJaegeuk Kim } 127422ad0b6aSJaegeuk Kim 127522ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 127622ad0b6aSJaegeuk Kim struct cp_control *cpc) 127722ad0b6aSJaegeuk Kim { 127822ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 127922ad0b6aSJaegeuk Kim 1280c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 128122ad0b6aSJaegeuk Kim } 128222ad0b6aSJaegeuk Kim 1283e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 128439a53e0cSJaegeuk Kim { 1285b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 128639a53e0cSJaegeuk Kim } 128739a53e0cSJaegeuk Kim 1288*cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1289*cc15620bSJaegeuk Kim { 1290*cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1291*cc15620bSJaegeuk Kim } 1292*cc15620bSJaegeuk Kim 1293e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 129439a53e0cSJaegeuk Kim { 1295b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 129639936837SJaegeuk Kim } 129739936837SJaegeuk Kim 1298e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 129939936837SJaegeuk Kim { 1300b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 130139936837SJaegeuk Kim } 130239936837SJaegeuk Kim 1303e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 130439936837SJaegeuk Kim { 1305b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 130639a53e0cSJaegeuk Kim } 130739a53e0cSJaegeuk Kim 1308119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1309119ee914SJaegeuk Kim { 1310119ee914SJaegeuk Kim int reason = CP_SYNC; 1311119ee914SJaegeuk Kim 1312119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1313119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1314119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1315119ee914SJaegeuk Kim reason = CP_UMOUNT; 1316119ee914SJaegeuk Kim return reason; 1317119ee914SJaegeuk Kim } 1318119ee914SJaegeuk Kim 1319119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1320119ee914SJaegeuk Kim { 1321c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1322119ee914SJaegeuk Kim } 1323119ee914SJaegeuk Kim 1324119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1325119ee914SJaegeuk Kim { 1326aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1327aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1328119ee914SJaegeuk Kim } 1329119ee914SJaegeuk Kim 133039a53e0cSJaegeuk Kim /* 133139a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 133239a53e0cSJaegeuk Kim */ 1333064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 133439a53e0cSJaegeuk Kim { 1335d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1336d6b7d4b3SChao Yu return -EINVAL; 1337cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1338064e0823SNamjae Jeon return -EINVAL; 1339064e0823SNamjae Jeon return 0; 134039a53e0cSJaegeuk Kim } 134139a53e0cSJaegeuk Kim 134239a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 134339a53e0cSJaegeuk Kim 134439a53e0cSJaegeuk Kim /* 134539a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 134639a53e0cSJaegeuk Kim */ 134739a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 134839a53e0cSJaegeuk Kim { 134939a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 13506c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 135139a53e0cSJaegeuk Kim else 13526c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 135339a53e0cSJaegeuk Kim } 135439a53e0cSJaegeuk Kim 13554bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 13564bc8e9bcSChao Yu { 13574bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 13584bc8e9bcSChao Yu } 13594bc8e9bcSChao Yu 13608edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 136139a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 136246008c6dSChao Yu struct inode *inode, blkcnt_t *count) 136339a53e0cSJaegeuk Kim { 1364dd11a5dfSJaegeuk Kim blkcnt_t diff; 1365dd11a5dfSJaegeuk Kim 1366cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 136755523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 136855523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 1369cb78942bSJaegeuk Kim return false; 137055523519SChao Yu } 1371cb78942bSJaegeuk Kim #endif 1372dd11a5dfSJaegeuk Kim /* 1373dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1374dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1375dd11a5dfSJaegeuk Kim */ 1376dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1377cfb271d4SChao Yu 137839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13792555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 13802555a2d5SJaegeuk Kim if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { 1381dd11a5dfSJaegeuk Kim diff = sbi->total_valid_block_count - sbi->user_block_count; 1382dd11a5dfSJaegeuk Kim *count -= diff; 13832555a2d5SJaegeuk Kim sbi->total_valid_block_count = sbi->user_block_count; 138446008c6dSChao Yu if (!*count) { 138539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1386dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 138739a53e0cSJaegeuk Kim return false; 138839a53e0cSJaegeuk Kim } 138946008c6dSChao Yu } 139039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 139141382ec4SJaegeuk Kim 13922555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, *count, true); 139339a53e0cSJaegeuk Kim return true; 139439a53e0cSJaegeuk Kim } 139539a53e0cSJaegeuk Kim 1396da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 139739a53e0cSJaegeuk Kim struct inode *inode, 139839a53e0cSJaegeuk Kim blkcnt_t count) 139939a53e0cSJaegeuk Kim { 140039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 14019850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 14029850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 140339a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 140439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 14052555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, count, false); 140639a53e0cSJaegeuk Kim } 140739a53e0cSJaegeuk Kim 140839a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 140939a53e0cSJaegeuk Kim { 141035782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 14117c4abcbeSChao Yu 141236951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 141336951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 14147c4abcbeSChao Yu return; 14157c4abcbeSChao Yu 1416caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 141739a53e0cSJaegeuk Kim } 141839a53e0cSJaegeuk Kim 1419a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 142039a53e0cSJaegeuk Kim { 1421204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1422c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1423c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 142439a53e0cSJaegeuk Kim } 142539a53e0cSJaegeuk Kim 142639a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 142739a53e0cSJaegeuk Kim { 142835782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 142939a53e0cSJaegeuk Kim } 143039a53e0cSJaegeuk Kim 1431a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 143239a53e0cSJaegeuk Kim { 14335ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 14345ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 14351fe54f9dSJaegeuk Kim return; 14361fe54f9dSJaegeuk Kim 1437204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1438c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1439c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 144039a53e0cSJaegeuk Kim } 144139a53e0cSJaegeuk Kim 1442523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 144339a53e0cSJaegeuk Kim { 144435782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 144539a53e0cSJaegeuk Kim } 144639a53e0cSJaegeuk Kim 1447204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1448f8b2c1f9SJaegeuk Kim { 1449204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1450f8b2c1f9SJaegeuk Kim } 1451f8b2c1f9SJaegeuk Kim 14525ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 14535ac206cfSNamjae Jeon { 14543519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1455523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1456523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1457523be8a6SJaegeuk Kim 1458523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 14595ac206cfSNamjae Jeon } 14605ac206cfSNamjae Jeon 146139a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 146239a53e0cSJaegeuk Kim { 14638b8343faSJaegeuk Kim return sbi->total_valid_block_count; 146439a53e0cSJaegeuk Kim } 146539a53e0cSJaegeuk Kim 1466f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1467f83a2584SYunlei He { 1468f83a2584SYunlei He return sbi->discard_blks; 1469f83a2584SYunlei He } 1470f83a2584SYunlei He 147139a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 147239a53e0cSJaegeuk Kim { 147339a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 147439a53e0cSJaegeuk Kim 147539a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 147639a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 147739a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 147839a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 147939a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 148039a53e0cSJaegeuk Kim 148139a53e0cSJaegeuk Kim return 0; 148239a53e0cSJaegeuk Kim } 148339a53e0cSJaegeuk Kim 148455141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 148555141486SWanpeng Li { 148655141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 148755141486SWanpeng Li } 148855141486SWanpeng Li 148939a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 149039a53e0cSJaegeuk Kim { 149139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 14921dbe4152SChangman Lee int offset; 14931dbe4152SChangman Lee 149455141486SWanpeng Li if (__cp_payload(sbi) > 0) { 14951dbe4152SChangman Lee if (flag == NAT_BITMAP) 14961dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 14971dbe4152SChangman Lee else 149865b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 14991dbe4152SChangman Lee } else { 15001dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 150125ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 150239a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 150339a53e0cSJaegeuk Kim } 15041dbe4152SChangman Lee } 150539a53e0cSJaegeuk Kim 150639a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 150739a53e0cSJaegeuk Kim { 15088508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 150939a53e0cSJaegeuk Kim 15108508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 151139a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 151239a53e0cSJaegeuk Kim return start_addr; 151339a53e0cSJaegeuk Kim } 151439a53e0cSJaegeuk Kim 15158508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 15168508e44aSJaegeuk Kim { 15178508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 15188508e44aSJaegeuk Kim 15198508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 15208508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 15218508e44aSJaegeuk Kim return start_addr; 15228508e44aSJaegeuk Kim } 15238508e44aSJaegeuk Kim 15248508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 15258508e44aSJaegeuk Kim { 15268508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 15278508e44aSJaegeuk Kim } 15288508e44aSJaegeuk Kim 152939a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 153039a53e0cSJaegeuk Kim { 153139a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 153239a53e0cSJaegeuk Kim } 153339a53e0cSJaegeuk Kim 153439a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1535ef86d709SGu Zheng struct inode *inode) 153639a53e0cSJaegeuk Kim { 153739a53e0cSJaegeuk Kim block_t valid_block_count; 153839a53e0cSJaegeuk Kim unsigned int valid_node_count; 153939a53e0cSJaegeuk Kim 154039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 154139a53e0cSJaegeuk Kim 1542ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1543cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 154439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 154539a53e0cSJaegeuk Kim return false; 154639a53e0cSJaegeuk Kim } 154739a53e0cSJaegeuk Kim 1548ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1549cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 155039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 155139a53e0cSJaegeuk Kim return false; 155239a53e0cSJaegeuk Kim } 155339a53e0cSJaegeuk Kim 155439a53e0cSJaegeuk Kim if (inode) 15558edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, true); 1556ef86d709SGu Zheng 1557ef86d709SGu Zheng sbi->total_valid_node_count++; 1558ef86d709SGu Zheng sbi->total_valid_block_count++; 155939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 156039a53e0cSJaegeuk Kim 156141382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 156239a53e0cSJaegeuk Kim return true; 156339a53e0cSJaegeuk Kim } 156439a53e0cSJaegeuk Kim 156539a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1566ef86d709SGu Zheng struct inode *inode) 156739a53e0cSJaegeuk Kim { 156839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 156939a53e0cSJaegeuk Kim 15709850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 15719850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 15729850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 157339a53e0cSJaegeuk Kim 15748edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, false); 1575ef86d709SGu Zheng sbi->total_valid_node_count--; 1576ef86d709SGu Zheng sbi->total_valid_block_count--; 157739a53e0cSJaegeuk Kim 157839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 157939a53e0cSJaegeuk Kim } 158039a53e0cSJaegeuk Kim 158139a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 158239a53e0cSJaegeuk Kim { 15838b8343faSJaegeuk Kim return sbi->total_valid_node_count; 158439a53e0cSJaegeuk Kim } 158539a53e0cSJaegeuk Kim 158639a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 158739a53e0cSJaegeuk Kim { 1588513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 158939a53e0cSJaegeuk Kim } 159039a53e0cSJaegeuk Kim 15910e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 159239a53e0cSJaegeuk Kim { 1593513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 159439a53e0cSJaegeuk Kim } 159539a53e0cSJaegeuk Kim 1596513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 159739a53e0cSJaegeuk Kim { 1598513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 159939a53e0cSJaegeuk Kim } 160039a53e0cSJaegeuk Kim 1601a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1602a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1603a56c7c6fSJaegeuk Kim { 1604c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1605c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1606cac5a3d8SDongOh Shin 1607c41f3cc3SJaegeuk Kim if (page) 1608c41f3cc3SJaegeuk Kim return page; 1609c41f3cc3SJaegeuk Kim 161055523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 161155523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1612c41f3cc3SJaegeuk Kim return NULL; 161355523519SChao Yu } 1614c41f3cc3SJaegeuk Kim #endif 1615a56c7c6fSJaegeuk Kim if (!for_write) 1616a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1617a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1618a56c7c6fSJaegeuk Kim } 1619a56c7c6fSJaegeuk Kim 16206e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 16216e2c64adSJaegeuk Kim { 16226e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 16236e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 16246e2c64adSJaegeuk Kim 16256e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 16266e2c64adSJaegeuk Kim kunmap(dst); 16276e2c64adSJaegeuk Kim kunmap(src); 16286e2c64adSJaegeuk Kim } 16296e2c64adSJaegeuk Kim 163039a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 163139a53e0cSJaegeuk Kim { 1632031fa8ccSJaegeuk Kim if (!page) 163339a53e0cSJaegeuk Kim return; 163439a53e0cSJaegeuk Kim 163539a53e0cSJaegeuk Kim if (unlock) { 16369850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 163739a53e0cSJaegeuk Kim unlock_page(page); 163839a53e0cSJaegeuk Kim } 163909cbfeafSKirill A. Shutemov put_page(page); 164039a53e0cSJaegeuk Kim } 164139a53e0cSJaegeuk Kim 164239a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 164339a53e0cSJaegeuk Kim { 164439a53e0cSJaegeuk Kim if (dn->node_page) 164539a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 164639a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 164739a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 164839a53e0cSJaegeuk Kim dn->node_page = NULL; 164939a53e0cSJaegeuk Kim dn->inode_page = NULL; 165039a53e0cSJaegeuk Kim } 165139a53e0cSJaegeuk Kim 165239a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1653e8512d2eSGu Zheng size_t size) 165439a53e0cSJaegeuk Kim { 1655e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 165639a53e0cSJaegeuk Kim } 165739a53e0cSJaegeuk Kim 16587bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 16597bd59381SGu Zheng gfp_t flags) 16607bd59381SGu Zheng { 16617bd59381SGu Zheng void *entry; 16627bd59381SGu Zheng 166380c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 166480c54505SJaegeuk Kim if (!entry) 166580c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 16667bd59381SGu Zheng return entry; 16677bd59381SGu Zheng } 16687bd59381SGu Zheng 1669740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1670740432f8SJaegeuk Kim { 1671740432f8SJaegeuk Kim struct bio *bio; 1672740432f8SJaegeuk Kim 1673740432f8SJaegeuk Kim /* No failure on bio allocation */ 1674740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 167580c54505SJaegeuk Kim if (!bio) 167680c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1677740432f8SJaegeuk Kim return bio; 1678740432f8SJaegeuk Kim } 1679740432f8SJaegeuk Kim 16809be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 16819be32d72SJaegeuk Kim unsigned long index, void *item) 16829be32d72SJaegeuk Kim { 16839be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 16849be32d72SJaegeuk Kim cond_resched(); 16859be32d72SJaegeuk Kim } 16869be32d72SJaegeuk Kim 168739a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 168839a53e0cSJaegeuk Kim 168939a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 169039a53e0cSJaegeuk Kim { 169145590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1692cac5a3d8SDongOh Shin 169339a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 169439a53e0cSJaegeuk Kim } 169539a53e0cSJaegeuk Kim 169639a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 169739a53e0cSJaegeuk Kim { 169839a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 169939a53e0cSJaegeuk Kim } 170039a53e0cSJaegeuk Kim 170139a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 170239a53e0cSJaegeuk Kim unsigned int offset) 170339a53e0cSJaegeuk Kim { 170439a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 170539a53e0cSJaegeuk Kim __le32 *addr_array; 1706cac5a3d8SDongOh Shin 170745590710SGu Zheng raw_node = F2FS_NODE(node_page); 170839a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 170939a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 171039a53e0cSJaegeuk Kim } 171139a53e0cSJaegeuk Kim 171239a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 171339a53e0cSJaegeuk Kim { 171439a53e0cSJaegeuk Kim int mask; 171539a53e0cSJaegeuk Kim 171639a53e0cSJaegeuk Kim addr += (nr >> 3); 171739a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 171839a53e0cSJaegeuk Kim return mask & *addr; 171939a53e0cSJaegeuk Kim } 172039a53e0cSJaegeuk Kim 1721a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1722a66cdd98SJaegeuk Kim { 1723a66cdd98SJaegeuk Kim int mask; 1724a66cdd98SJaegeuk Kim 1725a66cdd98SJaegeuk Kim addr += (nr >> 3); 1726a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1727a66cdd98SJaegeuk Kim *addr |= mask; 1728a66cdd98SJaegeuk Kim } 1729a66cdd98SJaegeuk Kim 1730a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1731a66cdd98SJaegeuk Kim { 1732a66cdd98SJaegeuk Kim int mask; 1733a66cdd98SJaegeuk Kim 1734a66cdd98SJaegeuk Kim addr += (nr >> 3); 1735a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1736a66cdd98SJaegeuk Kim *addr &= ~mask; 1737a66cdd98SJaegeuk Kim } 1738a66cdd98SJaegeuk Kim 173952aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 174039a53e0cSJaegeuk Kim { 174139a53e0cSJaegeuk Kim int mask; 174239a53e0cSJaegeuk Kim int ret; 174339a53e0cSJaegeuk Kim 174439a53e0cSJaegeuk Kim addr += (nr >> 3); 174539a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 174639a53e0cSJaegeuk Kim ret = mask & *addr; 174739a53e0cSJaegeuk Kim *addr |= mask; 174839a53e0cSJaegeuk Kim return ret; 174939a53e0cSJaegeuk Kim } 175039a53e0cSJaegeuk Kim 175152aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 175239a53e0cSJaegeuk Kim { 175339a53e0cSJaegeuk Kim int mask; 175439a53e0cSJaegeuk Kim int ret; 175539a53e0cSJaegeuk Kim 175639a53e0cSJaegeuk Kim addr += (nr >> 3); 175739a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 175839a53e0cSJaegeuk Kim ret = mask & *addr; 175939a53e0cSJaegeuk Kim *addr &= ~mask; 176039a53e0cSJaegeuk Kim return ret; 176139a53e0cSJaegeuk Kim } 176239a53e0cSJaegeuk Kim 1763c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1764c6ac4c0eSGu Zheng { 1765c6ac4c0eSGu Zheng int mask; 1766c6ac4c0eSGu Zheng 1767c6ac4c0eSGu Zheng addr += (nr >> 3); 1768c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1769c6ac4c0eSGu Zheng *addr ^= mask; 1770c6ac4c0eSGu Zheng } 1771c6ac4c0eSGu Zheng 177239a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 177339a53e0cSJaegeuk Kim enum { 177439a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1775b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 177626de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1777ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 177839a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 177939a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 178039a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1781c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1782c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1783444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 17841001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 178534d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1786fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1787fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 178888b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 178988b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 17905fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 179102a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 17923c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 17931e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1794b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1795510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1796d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1797c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 1798dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 1799ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 180039a53e0cSJaegeuk Kim }; 180139a53e0cSJaegeuk Kim 1802205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 1803205b9822SJaegeuk Kim int flag, bool set) 180439a53e0cSJaegeuk Kim { 1805205b9822SJaegeuk Kim switch (flag) { 1806205b9822SJaegeuk Kim case FI_INLINE_XATTR: 1807205b9822SJaegeuk Kim case FI_INLINE_DATA: 1808205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 1809205b9822SJaegeuk Kim if (set) 1810205b9822SJaegeuk Kim return; 1811205b9822SJaegeuk Kim case FI_DATA_EXIST: 1812205b9822SJaegeuk Kim case FI_INLINE_DOTS: 18137c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1814205b9822SJaegeuk Kim } 181539a53e0cSJaegeuk Kim } 181639a53e0cSJaegeuk Kim 181791942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 181839a53e0cSJaegeuk Kim { 181991942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 182091942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 1821205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 182239a53e0cSJaegeuk Kim } 182339a53e0cSJaegeuk Kim 182491942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 182539a53e0cSJaegeuk Kim { 182691942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 182739a53e0cSJaegeuk Kim } 182839a53e0cSJaegeuk Kim 182991942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 183039a53e0cSJaegeuk Kim { 183191942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 183291942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 1833205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 183439a53e0cSJaegeuk Kim } 183539a53e0cSJaegeuk Kim 183691942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 1837444c580fSJaegeuk Kim { 183891942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 183991942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 18407c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 184139a53e0cSJaegeuk Kim } 184239a53e0cSJaegeuk Kim 1843a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 1844a1961246SJaegeuk Kim { 1845a1961246SJaegeuk Kim if (inc) 1846a1961246SJaegeuk Kim inc_nlink(inode); 1847a1961246SJaegeuk Kim else 1848a1961246SJaegeuk Kim drop_nlink(inode); 18497c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1850a1961246SJaegeuk Kim } 1851a1961246SJaegeuk Kim 18528edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 18538edd03c8SJaegeuk Kim blkcnt_t diff, bool add) 18548edd03c8SJaegeuk Kim { 185526de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 185626de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 185726de9b11SJaegeuk Kim 18588edd03c8SJaegeuk Kim inode->i_blocks = add ? inode->i_blocks + diff : 18598edd03c8SJaegeuk Kim inode->i_blocks - diff; 18607c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 186126de9b11SJaegeuk Kim if (clean || recover) 186226de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 18638edd03c8SJaegeuk Kim } 18648edd03c8SJaegeuk Kim 1865fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 1866fc9581c8SJaegeuk Kim { 186726de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 186826de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 186926de9b11SJaegeuk Kim 1870fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 1871fc9581c8SJaegeuk Kim return; 1872fc9581c8SJaegeuk Kim 1873fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 18747c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 187526de9b11SJaegeuk Kim if (clean || recover) 187626de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 187726de9b11SJaegeuk Kim } 187826de9b11SJaegeuk Kim 1879205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 1880205b9822SJaegeuk Kim { 1881205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 18827c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1883205b9822SJaegeuk Kim } 1884205b9822SJaegeuk Kim 1885205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 1886205b9822SJaegeuk Kim { 1887205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 18887c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1889205b9822SJaegeuk Kim } 1890205b9822SJaegeuk Kim 1891205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 1892205b9822SJaegeuk Kim { 1893205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 18947c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1895205b9822SJaegeuk Kim } 1896205b9822SJaegeuk Kim 189791942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 1898444c580fSJaegeuk Kim { 1899205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 1900205b9822SJaegeuk Kim 1901444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1902205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 19031001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 1904205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 190534d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1906205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 1907b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1908205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 1909510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1910205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 1911444c580fSJaegeuk Kim } 1912444c580fSJaegeuk Kim 191391942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 1914444c580fSJaegeuk Kim { 1915444c580fSJaegeuk Kim ri->i_inline = 0; 1916444c580fSJaegeuk Kim 191791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 1918444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 191991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 19201001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 192191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 192234d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 192391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 1924b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 192591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 1926510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1927444c580fSJaegeuk Kim } 1928444c580fSJaegeuk Kim 1929987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1930987c7c31SChao Yu { 193191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 1932987c7c31SChao Yu } 1933987c7c31SChao Yu 193481ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1935de93653fSJaegeuk Kim { 193681ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1937de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1938de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1939de93653fSJaegeuk Kim } 1940de93653fSJaegeuk Kim 194165985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 194265985d93SJaegeuk Kim { 1943695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1944cac5a3d8SDongOh Shin 194565985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 194665985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 194765985d93SJaegeuk Kim } 194865985d93SJaegeuk Kim 194965985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 195065985d93SJaegeuk Kim { 1951987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 195265985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 195365985d93SJaegeuk Kim else 195465985d93SJaegeuk Kim return 0; 195565985d93SJaegeuk Kim } 195665985d93SJaegeuk Kim 19570dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 19580dbdc2aeSJaegeuk Kim { 195991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 19600dbdc2aeSJaegeuk Kim } 19610dbdc2aeSJaegeuk Kim 1962b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1963b3d208f9SJaegeuk Kim { 196491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 1965b3d208f9SJaegeuk Kim } 1966b3d208f9SJaegeuk Kim 1967510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1968510022a8SJaegeuk Kim { 196991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 1970510022a8SJaegeuk Kim } 1971510022a8SJaegeuk Kim 197288b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 197388b88a66SJaegeuk Kim { 197491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 197588b88a66SJaegeuk Kim } 197688b88a66SJaegeuk Kim 19775fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 19785fe45743SChao Yu { 19795fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 19805fe45743SChao Yu } 19815fe45743SChao Yu 198202a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 198302a1335fSJaegeuk Kim { 198491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 198502a1335fSJaegeuk Kim } 198602a1335fSJaegeuk Kim 19873c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 19883c6c2bebSJaegeuk Kim { 198991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 19903c6c2bebSJaegeuk Kim } 19913c6c2bebSJaegeuk Kim 19921e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 19931e84371fSJaegeuk Kim { 199491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 19951e84371fSJaegeuk Kim } 19961e84371fSJaegeuk Kim 19971001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 19981001b347SHuajun Li { 1999695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2000cac5a3d8SDongOh Shin 20011001b347SHuajun Li return (void *)&(ri->i_addr[1]); 20021001b347SHuajun Li } 20031001b347SHuajun Li 200434d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 200534d67debSChao Yu { 200691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 200734d67debSChao Yu } 200834d67debSChao Yu 20099486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 20109486ba44SJaegeuk Kim { 20119486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 20129486ba44SJaegeuk Kim kunmap(page); 20139486ba44SJaegeuk Kim } 20149486ba44SJaegeuk Kim 2015b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2016b5492af7SJaegeuk Kim { 2017b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2018b5492af7SJaegeuk Kim } 2019b5492af7SJaegeuk Kim 2020b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2021b5492af7SJaegeuk Kim { 2022b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 20237c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2024b5492af7SJaegeuk Kim } 2025b5492af7SJaegeuk Kim 2026b5492af7SJaegeuk Kim static inline void clear_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 203226787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 203326787236SJaegeuk Kim { 203426787236SJaegeuk Kim if (dsync) { 203526787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 203626787236SJaegeuk Kim bool ret; 203726787236SJaegeuk Kim 203826787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 203926787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 204026787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 204126787236SJaegeuk Kim return ret; 204226787236SJaegeuk Kim } 204326787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 204426787236SJaegeuk Kim file_keep_isize(inode) || 204526787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 204626787236SJaegeuk Kim return false; 204726787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 2048267378d4SChao Yu } 2049267378d4SChao Yu 2050267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 2051267378d4SChao Yu { 2052267378d4SChao Yu return sb->s_flags & MS_RDONLY; 2053267378d4SChao Yu } 205439a53e0cSJaegeuk Kim 205539a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 205639a53e0cSJaegeuk Kim { 2057aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 205839a53e0cSJaegeuk Kim } 205939a53e0cSJaegeuk Kim 2060eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2061eaa693f4SJaegeuk Kim { 2062eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2063eaa693f4SJaegeuk Kim return true; 2064eaa693f4SJaegeuk Kim 2065eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2066eaa693f4SJaegeuk Kim return true; 2067eaa693f4SJaegeuk Kim 2068eaa693f4SJaegeuk Kim return false; 2069eaa693f4SJaegeuk Kim } 2070eaa693f4SJaegeuk Kim 20713e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 20723e72f721SJaegeuk Kim { 20733e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 207491942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 20753e72f721SJaegeuk Kim return false; 20763e72f721SJaegeuk Kim 2077886f56f9SAl Viro return S_ISREG(inode->i_mode); 20783e72f721SJaegeuk Kim } 20793e72f721SJaegeuk Kim 20801ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 20811ecc0c5cSChao Yu size_t size, gfp_t flags) 20820414b004SJaegeuk Kim { 20832c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 208455523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 208555523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 20862c63feadSJaegeuk Kim return NULL; 208755523519SChao Yu } 20882c63feadSJaegeuk Kim #endif 20890414b004SJaegeuk Kim return kmalloc(size, flags); 20900414b004SJaegeuk Kim } 20910414b004SJaegeuk Kim 209239307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 209339307a8eSJaegeuk Kim { 209439307a8eSJaegeuk Kim void *ret; 209539307a8eSJaegeuk Kim 209639307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 209739307a8eSJaegeuk Kim if (!ret) 209839307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 209939307a8eSJaegeuk Kim return ret; 210039307a8eSJaegeuk Kim } 210139307a8eSJaegeuk Kim 210239307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 210339307a8eSJaegeuk Kim { 210439307a8eSJaegeuk Kim void *ret; 210539307a8eSJaegeuk Kim 210639307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 210739307a8eSJaegeuk Kim if (!ret) 210839307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 210939307a8eSJaegeuk Kim return ret; 211039307a8eSJaegeuk Kim } 211139307a8eSJaegeuk Kim 211239a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 211391942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 211439a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 211539a53e0cSJaegeuk Kim 211639a53e0cSJaegeuk Kim /* 21171e1bb4baSJaegeuk Kim * file.c 211839a53e0cSJaegeuk Kim */ 2119cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2120cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2121cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2122cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2123a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2124a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2125cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2126cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2127cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2128cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2129cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 213039a53e0cSJaegeuk Kim 213139a53e0cSJaegeuk Kim /* 213239a53e0cSJaegeuk Kim * inode.c 213339a53e0cSJaegeuk Kim */ 2134cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2135cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2136cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2137cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2138cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2139cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2140cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2141cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2142cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 214339a53e0cSJaegeuk Kim 214439a53e0cSJaegeuk Kim /* 214539a53e0cSJaegeuk Kim * namei.c 214639a53e0cSJaegeuk Kim */ 214739a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 214839a53e0cSJaegeuk Kim 214939a53e0cSJaegeuk Kim /* 215039a53e0cSJaegeuk Kim * dir.c 215139a53e0cSJaegeuk Kim */ 2152cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2153cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2154cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2155cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2156cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2157cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2158cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2159cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2160cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2161cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2162cac5a3d8SDongOh Shin const struct qstr *new_name, 2163cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2164cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2165cac5a3d8SDongOh Shin unsigned int current_depth); 2166cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2167cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2168cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2169cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2170cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2171cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2172cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2173cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2174cac5a3d8SDongOh Shin struct page **page); 2175cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2176cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2177cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2178cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2179cac5a3d8SDongOh Shin unsigned int bit_pos); 2180cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2181cac5a3d8SDongOh Shin const struct qstr *orig_name, 2182cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2183cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2184cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2185cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2186cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2187cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2188cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2189cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2190cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 219139a53e0cSJaegeuk Kim 2192b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2193b7f7a5e0SAl Viro { 21942b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2195510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2196b7f7a5e0SAl Viro } 2197b7f7a5e0SAl Viro 219839a53e0cSJaegeuk Kim /* 219939a53e0cSJaegeuk Kim * super.c 220039a53e0cSJaegeuk Kim */ 2201cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2202cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2203cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2204cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2205a07ef784SNamjae Jeon extern __printf(3, 4) 2206cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2207984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 220839a53e0cSJaegeuk Kim 220939a53e0cSJaegeuk Kim /* 221039a53e0cSJaegeuk Kim * hash.c 221139a53e0cSJaegeuk Kim */ 22126332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, 22136332cd32SJaegeuk Kim struct fscrypt_name *fname); 221439a53e0cSJaegeuk Kim 221539a53e0cSJaegeuk Kim /* 221639a53e0cSJaegeuk Kim * node.c 221739a53e0cSJaegeuk Kim */ 221839a53e0cSJaegeuk Kim struct dnode_of_data; 221939a53e0cSJaegeuk Kim struct node_info; 222039a53e0cSJaegeuk Kim 2221cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2222cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2223cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2224cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2225cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2226cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2227cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2228cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2229cac5a3d8SDongOh Shin int truncate_xattr_node(struct inode *inode, struct page *page); 2230cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2231cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2232cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 2233cac5a3d8SDongOh Shin struct page *new_node_page(struct dnode_of_data *dn, 2234cac5a3d8SDongOh Shin unsigned int ofs, struct page *ipage); 2235cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2236cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2237cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2238cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2239cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2240cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2241cac5a3d8SDongOh Shin int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc); 224222ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2243cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2244cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2245cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2246cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2247cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2248d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2249cac5a3d8SDongOh Shin block_t blkaddr); 2250cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2251cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2252cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 225322ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2254cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2255cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 22566e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 225739a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 225839a53e0cSJaegeuk Kim 225939a53e0cSJaegeuk Kim /* 226039a53e0cSJaegeuk Kim * segment.c 226139a53e0cSJaegeuk Kim */ 2262cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 2263cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 22648c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2265cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2266cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2267cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2268cac5a3d8SDongOh Shin int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2269cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2270cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2271cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2272cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2273cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2274d431413fSChao Yu void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2275cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2276cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2277cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2278cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2279cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2280cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2281cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2282cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2283cac5a3d8SDongOh Shin void write_meta_page(struct f2fs_sb_info *sbi, struct page *page); 2284cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2285cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2286d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2287cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2288cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2289cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2290cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2291cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2292cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2293cac5a3d8SDongOh Shin bool recover_newaddr); 2294cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2295cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2296cac5a3d8SDongOh Shin struct f2fs_summary *sum, int type); 2297cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2298cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2299cac5a3d8SDongOh Shin void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2300cac5a3d8SDongOh Shin block_t blkaddr); 2301cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2302cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2303cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2304cac5a3d8SDongOh Shin unsigned int val, int alloc); 2305cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2306cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2307cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 23087fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 23097fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 231039a53e0cSJaegeuk Kim 231139a53e0cSJaegeuk Kim /* 231239a53e0cSJaegeuk Kim * checkpoint.c 231339a53e0cSJaegeuk Kim */ 2314cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2315cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2316cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2317cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2318cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2319cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2320cac5a3d8SDongOh Shin int type, bool sync); 2321cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2322cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2323cac5a3d8SDongOh Shin long nr_to_write); 2324cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2325cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2326cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2327cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2328cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2329cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2330cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2331cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2332cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2333cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2334cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2335cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2336cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2337cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2338cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2339cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 23406e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 234139a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 234239a53e0cSJaegeuk Kim 234339a53e0cSJaegeuk Kim /* 234439a53e0cSJaegeuk Kim * data.c 234539a53e0cSJaegeuk Kim */ 2346b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 2347b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 2348942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2349b9109b0eSJaegeuk Kim enum page_type type); 2350b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 2351cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2352b9109b0eSJaegeuk Kim int f2fs_submit_page_write(struct f2fs_io_info *fio); 2353cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2354cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2355cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2356cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2357cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2358cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2359cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2360cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2361cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2362cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2363cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2364cac5a3d8SDongOh Shin int op_flags, bool for_write); 2365cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2366cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2367cac5a3d8SDongOh Shin bool for_write); 2368cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2369cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2370cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2371cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2372cac5a3d8SDongOh Shin int create, int flag); 2373cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2374cac5a3d8SDongOh Shin u64 start, u64 len); 2375cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2376cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2377cac5a3d8SDongOh Shin unsigned int length); 2378cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 23795b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2380cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2381cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 23825b7a487cSWeichao Guo #endif 238339a53e0cSJaegeuk Kim 238439a53e0cSJaegeuk Kim /* 238539a53e0cSJaegeuk Kim * gc.c 238639a53e0cSJaegeuk Kim */ 2387cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2388cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2389cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2390e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 2391e066b83cSJaegeuk Kim unsigned int segno); 2392cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 239339a53e0cSJaegeuk Kim 239439a53e0cSJaegeuk Kim /* 239539a53e0cSJaegeuk Kim * recovery.c 239639a53e0cSJaegeuk Kim */ 2397cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2398cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 239939a53e0cSJaegeuk Kim 240039a53e0cSJaegeuk Kim /* 240139a53e0cSJaegeuk Kim * debug.c 240239a53e0cSJaegeuk Kim */ 240339a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 240439a53e0cSJaegeuk Kim struct f2fs_stat_info { 240539a53e0cSJaegeuk Kim struct list_head stat_list; 240639a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 240739a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 240839a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 24095b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 24105b7ee374SChao Yu unsigned long long hit_total, total_ext; 2411c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 241235782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 241335782b23SJaegeuk Kim int inmem_pages; 24140f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 24155b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 24165b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 241739a53e0cSJaegeuk Kim int total_count, utilization; 24188b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 24198b8dd65fSChao Yu int nr_flushing, nr_flushed, nr_discarding, nr_discarded; 24205f32366aSChao Yu int nr_discard_cmd; 2421d84d1cbdSChao Yu unsigned int undiscard_blks; 2422a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2423648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2424f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 242539a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 242639a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 242739a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 242839a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 242942190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 243039a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2431e1235983SChangman Lee int bg_node_segs, bg_data_segs; 243239a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2433e1235983SChangman Lee int bg_data_blks, bg_node_blks; 243439a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 243539a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 243639a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 243739a53e0cSJaegeuk Kim 243839a53e0cSJaegeuk Kim unsigned int segment_count[2]; 243939a53e0cSJaegeuk Kim unsigned int block_count[2]; 2440b9a2c252SChangman Lee unsigned int inplace_count; 24419edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 244239a53e0cSJaegeuk Kim }; 244339a53e0cSJaegeuk Kim 2444963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2445963d4f7dSGu Zheng { 2446963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2447963d4f7dSGu Zheng } 2448963d4f7dSGu Zheng 2449942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 245042190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 245139a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2452dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 245333fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 245433fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 24555b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 24565b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 24575b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 24585b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2459d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2460d5e8f6c9SChao Yu do { \ 2461d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2462d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2463d5e8f6c9SChao Yu } while (0) 2464d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2465d5e8f6c9SChao Yu do { \ 2466d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2467d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2468d5e8f6c9SChao Yu } while (0) 24690dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 24700dbdc2aeSJaegeuk Kim do { \ 24710dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 247203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 24730dbdc2aeSJaegeuk Kim } while (0) 24740dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 24750dbdc2aeSJaegeuk Kim do { \ 24760dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 247703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 24780dbdc2aeSJaegeuk Kim } while (0) 24793289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 24803289c061SJaegeuk Kim do { \ 24813289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 248203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 24833289c061SJaegeuk Kim } while (0) 24843289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 24853289c061SJaegeuk Kim do { \ 24863289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 248703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 24883289c061SJaegeuk Kim } while (0) 2489dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2490dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2491dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2492dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2493b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2494b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 249526a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2496cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 249726a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2498cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 249926a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 250026a28a0cSJaegeuk Kim do { \ 250126a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 250226a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 250326a28a0cSJaegeuk Kim if (cur > max) \ 250426a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 250526a28a0cSJaegeuk Kim } while (0) 2506648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2507648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2508648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2509648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2510648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2511648d50baSChao Yu do { \ 2512648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2513648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2514648d50baSChao Yu if (cur > max) \ 2515648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2516648d50baSChao Yu } while (0) 2517e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 251839a53e0cSJaegeuk Kim do { \ 2519963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 252068afcf2dSTomohiro Kusumi si->tot_segs++; \ 252168afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 252239a53e0cSJaegeuk Kim si->data_segs++; \ 2523e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2524e1235983SChangman Lee } else { \ 252539a53e0cSJaegeuk Kim si->node_segs++; \ 2526e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2527e1235983SChangman Lee } \ 252839a53e0cSJaegeuk Kim } while (0) 252939a53e0cSJaegeuk Kim 253039a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 253168afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 253239a53e0cSJaegeuk Kim 2533e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 253439a53e0cSJaegeuk Kim do { \ 2535963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 253639a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 253739a53e0cSJaegeuk Kim si->data_blks += (blks); \ 253868afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 253939a53e0cSJaegeuk Kim } while (0) 254039a53e0cSJaegeuk Kim 2541e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 254239a53e0cSJaegeuk Kim do { \ 2543963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 254439a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 254539a53e0cSJaegeuk Kim si->node_blks += (blks); \ 254668afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 254739a53e0cSJaegeuk Kim } while (0) 254839a53e0cSJaegeuk Kim 2549cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2550cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2551787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 25524589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 255339a53e0cSJaegeuk Kim #else 2554d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 2555d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 2556d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 2557d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 2558d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 2559d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 2560d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 2561d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 2562d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 2563d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 2564d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 2565d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 2566d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 2567d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 2568d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 2569d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 2570d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 2571d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 2572d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 2573d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 2574d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 2575d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 2576d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 2577d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 2578d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 2579d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 2580d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 2581d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 2582d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 258339a53e0cSJaegeuk Kim 258439a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 258539a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2586787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 25874589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 258839a53e0cSJaegeuk Kim #endif 258939a53e0cSJaegeuk Kim 259039a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 259139a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 259239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 259339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 259439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 259539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 259639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 259739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2598cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 259939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 260029e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 26011001b347SHuajun Li 2602e18c65b2SHuajun Li /* 2603e18c65b2SHuajun Li * inline.c 2604e18c65b2SHuajun Li */ 2605cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2606cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2607cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2608bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2609cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2610cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2611cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2612cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2613cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2614cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2615cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2616cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2617cac5a3d8SDongOh Shin struct page *ipage); 2618cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2619cac5a3d8SDongOh Shin const struct qstr *orig_name, 2620cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2621cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2622cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2623cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2624cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2625cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2626cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2627cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2628cac5a3d8SDongOh Shin __u64 start, __u64 len); 2629cde4de12SJaegeuk Kim 2630cde4de12SJaegeuk Kim /* 26312658e50dSJaegeuk Kim * shrinker.c 26322658e50dSJaegeuk Kim */ 2633cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2634cac5a3d8SDongOh Shin struct shrink_control *sc); 2635cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2636cac5a3d8SDongOh Shin struct shrink_control *sc); 2637cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2638cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 26392658e50dSJaegeuk Kim 26402658e50dSJaegeuk Kim /* 2641a28ef1f5SChao Yu * extent_cache.c 2642a28ef1f5SChao Yu */ 2643004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 2644004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 2645004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 2646004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 2647004b6862SChao Yu unsigned int ofs); 2648004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 2649004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 2650004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 2651004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 2652004b6862SChao Yu bool force); 2653df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi, 2654df0f6b44SChao Yu struct rb_root *root); 2655cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2656cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2657cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2658cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2659cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2660cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2661cac5a3d8SDongOh Shin struct extent_info *ei); 2662cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 266319b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2664cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2665cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2666a28ef1f5SChao Yu int __init create_extent_cache(void); 2667a28ef1f5SChao Yu void destroy_extent_cache(void); 2668a28ef1f5SChao Yu 2669a28ef1f5SChao Yu /* 2670cde4de12SJaegeuk Kim * crypto support 2671cde4de12SJaegeuk Kim */ 26720b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2673cde4de12SJaegeuk Kim { 2674cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2675cde4de12SJaegeuk Kim } 2676cde4de12SJaegeuk Kim 2677cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2678cde4de12SJaegeuk Kim { 2679cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2680cde4de12SJaegeuk Kim file_set_encrypt(inode); 2681cde4de12SJaegeuk Kim #endif 2682cde4de12SJaegeuk Kim } 2683cde4de12SJaegeuk Kim 2684cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2685cde4de12SJaegeuk Kim { 26860b81d077SJaegeuk Kim return bio->bi_private != NULL; 2687cde4de12SJaegeuk Kim } 2688cde4de12SJaegeuk Kim 2689cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2690cde4de12SJaegeuk Kim { 2691cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2692cde4de12SJaegeuk Kim } 2693f424f664SJaegeuk Kim 26940bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 269552763a4bSJaegeuk Kim { 26960bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 269752763a4bSJaegeuk Kim } 269852763a4bSJaegeuk Kim 2699178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2700178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 27013c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2702178053e2SDamien Le Moal { 2703178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 27043c62be17SJaegeuk Kim int i; 2705178053e2SDamien Le Moal 27063c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 27073c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 27083c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 27093c62be17SJaegeuk Kim return -EINVAL; 2710178053e2SDamien Le Moal } 2711178053e2SDamien Le Moal #endif 2712178053e2SDamien Le Moal 271396ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 271496ba2decSDamien Le Moal { 271596ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 271696ba2decSDamien Le Moal 271796ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 271852763a4bSJaegeuk Kim } 271952763a4bSJaegeuk Kim 272052763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 272152763a4bSJaegeuk Kim { 272252763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 272352763a4bSJaegeuk Kim clear_opt(sbi, LFS); 272452763a4bSJaegeuk Kim 272552763a4bSJaegeuk Kim switch (mt) { 272652763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 272752763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 272852763a4bSJaegeuk Kim break; 272952763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 273052763a4bSJaegeuk Kim set_opt(sbi, LFS); 273152763a4bSJaegeuk Kim break; 273252763a4bSJaegeuk Kim } 273352763a4bSJaegeuk Kim } 273452763a4bSJaegeuk Kim 2735fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2736fcc85a4dSJaegeuk Kim { 2737fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2738886f56f9SAl Viro umode_t mode = inode->i_mode; 2739fcc85a4dSJaegeuk Kim 2740fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2741fcc85a4dSJaegeuk Kim #else 2742fcc85a4dSJaegeuk Kim return 0; 2743fcc85a4dSJaegeuk Kim #endif 2744fcc85a4dSJaegeuk Kim } 2745fcc85a4dSJaegeuk Kim 274639a53e0cSJaegeuk Kim #endif 2747