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 12875ab4cb8SJaegeuk Kim enum { 12975ab4cb8SJaegeuk Kim CP_UMOUNT, 130119ee914SJaegeuk Kim CP_FASTBOOT, 13175ab4cb8SJaegeuk Kim CP_SYNC, 13210027551SJaegeuk Kim CP_RECOVERY, 1334b2fecc8SJaegeuk Kim CP_DISCARD, 13475ab4cb8SJaegeuk Kim }; 13575ab4cb8SJaegeuk Kim 13647b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 137bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 1384ddb1a4dSJaegeuk Kim (GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections)) 139a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 140a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 1414ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 14215469963SJaegeuk Kim #define DISCARD_ISSUE_RATE 8 14360b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 144dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 145bba681cbSJaegeuk Kim 14675ab4cb8SJaegeuk Kim struct cp_control { 14775ab4cb8SJaegeuk Kim int reason; 1484b2fecc8SJaegeuk Kim __u64 trim_start; 1494b2fecc8SJaegeuk Kim __u64 trim_end; 1504b2fecc8SJaegeuk Kim __u64 trim_minlen; 1514b2fecc8SJaegeuk Kim __u64 trimmed; 15275ab4cb8SJaegeuk Kim }; 15375ab4cb8SJaegeuk Kim 154662befdaSChao Yu /* 15581c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 156662befdaSChao Yu */ 157662befdaSChao Yu enum { 158662befdaSChao Yu META_CP, 159662befdaSChao Yu META_NAT, 16081c1a0f1SChao Yu META_SIT, 1614c521f49SJaegeuk Kim META_SSA, 1624c521f49SJaegeuk Kim META_POR, 163662befdaSChao Yu }; 164662befdaSChao Yu 1656451e041SJaegeuk Kim /* for the list of ino */ 1666451e041SJaegeuk Kim enum { 1676451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 168fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 169fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1706451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1716451e041SJaegeuk Kim }; 1726451e041SJaegeuk Kim 1736451e041SJaegeuk Kim struct ino_entry { 17439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17539a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 17639a53e0cSJaegeuk Kim }; 17739a53e0cSJaegeuk Kim 1782710fd7eSChao Yu /* for the list of inodes to be GCed */ 17906292073SChao Yu struct inode_entry { 18039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 18239a53e0cSJaegeuk Kim }; 18339a53e0cSJaegeuk Kim 184a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 1857fd9e544SJaegeuk Kim struct discard_entry { 1867fd9e544SJaegeuk Kim struct list_head list; /* list head */ 187a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 188a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 1897fd9e544SJaegeuk Kim }; 1907fd9e544SJaegeuk Kim 191ba48a33eSChao Yu /* max discard pend list number */ 192ba48a33eSChao Yu #define MAX_PLIST_NUM 512 193ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 194ba48a33eSChao Yu (MAX_PLIST_NUM - 1) : (blk_num - 1)) 195ba48a33eSChao Yu 19615469963SJaegeuk Kim enum { 19715469963SJaegeuk Kim D_PREP, 19815469963SJaegeuk Kim D_SUBMIT, 19915469963SJaegeuk Kim D_DONE, 20015469963SJaegeuk Kim }; 20115469963SJaegeuk Kim 202004b6862SChao Yu struct discard_info { 203004b6862SChao Yu block_t lstart; /* logical start address */ 204004b6862SChao Yu block_t len; /* length */ 205004b6862SChao Yu block_t start; /* actual start address in dev */ 206004b6862SChao Yu }; 207004b6862SChao Yu 208b01a9201SJaegeuk Kim struct discard_cmd { 209004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 210004b6862SChao Yu union { 211004b6862SChao Yu struct { 212004b6862SChao Yu block_t lstart; /* logical start address */ 213004b6862SChao Yu block_t len; /* length */ 214004b6862SChao Yu block_t start; /* actual start address in dev */ 215004b6862SChao Yu }; 216004b6862SChao Yu struct discard_info di; /* discard info */ 217004b6862SChao Yu 218004b6862SChao Yu }; 219b01a9201SJaegeuk Kim struct list_head list; /* command list */ 220b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 221c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 22215469963SJaegeuk Kim int 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; 233*d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 234*d618ebafSChao 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 795458e6197SJaegeuk Kim struct f2fs_io_info { 79605ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 797458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 79804d328deSMike Christie int op; /* contains REQ_OP_ */ 799ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 8007a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 80128bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 80205ca3632SJaegeuk Kim struct page *page; /* page to be written */ 8034375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 804d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 805001c584cSChao Yu bool cp_rwsem_locked; /* indicate cp_rwsem is held */ 806458e6197SJaegeuk Kim }; 807458e6197SJaegeuk Kim 80868afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 8091ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 810458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 8111ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 8121ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 813458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 814df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 8151ff7bd3bSJaegeuk Kim }; 8161ff7bd3bSJaegeuk Kim 8173c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 8183c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 8193c62be17SJaegeuk Kim struct f2fs_dev_info { 8203c62be17SJaegeuk Kim struct block_device *bdev; 8213c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 8223c62be17SJaegeuk Kim unsigned int total_segments; 8233c62be17SJaegeuk Kim block_t start_blk; 8243c62be17SJaegeuk Kim block_t end_blk; 8253c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 8263c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 8273c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 8283c62be17SJaegeuk Kim #endif 8293c62be17SJaegeuk Kim }; 8303c62be17SJaegeuk Kim 831c227f912SChao Yu enum inode_type { 832c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 833c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 8340f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 835c227f912SChao Yu NR_INODE_TYPE, 836c227f912SChao Yu }; 837c227f912SChao Yu 83867298804SChao Yu /* for inner inode cache management */ 83967298804SChao Yu struct inode_management { 84067298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 84167298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 84267298804SChao Yu struct list_head ino_list; /* inode list head */ 84367298804SChao Yu unsigned long ino_num; /* number of entries */ 84467298804SChao Yu }; 84567298804SChao Yu 846caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 847caf0047eSChao Yu enum { 848caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 849caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 850caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 851caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 852df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 853bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 854caf0047eSChao Yu }; 855caf0047eSChao Yu 8566beceb54SJaegeuk Kim enum { 8576beceb54SJaegeuk Kim CP_TIME, 858d0239e1bSJaegeuk Kim REQ_TIME, 8596beceb54SJaegeuk Kim MAX_TIME, 8606beceb54SJaegeuk Kim }; 8616beceb54SJaegeuk Kim 86239a53e0cSJaegeuk Kim struct f2fs_sb_info { 86339a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 8645e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 86539a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 866e8240f65SChao Yu int valid_super_block; /* valid super block no */ 867fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 86839a53e0cSJaegeuk Kim 869178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 870178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 871178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 872178053e2SDamien Le Moal #endif 873178053e2SDamien Le Moal 87439a53e0cSJaegeuk Kim /* for node-related operations */ 87539a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 87639a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 87739a53e0cSJaegeuk Kim 87839a53e0cSJaegeuk Kim /* for segment-related operations */ 87939a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 8801ff7bd3bSJaegeuk Kim 8811ff7bd3bSJaegeuk Kim /* for bio operations */ 882924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 8831ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 8847dfeaa32SJaegeuk Kim struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ 8850a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 8860a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 88739a53e0cSJaegeuk Kim 88839a53e0cSJaegeuk Kim /* for checkpoint */ 88939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 8908508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 891aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 89239a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 89339936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 894b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 895b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 89659c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 897fb51b5efSChangman Lee wait_queue_head_t cp_wait; 8986beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 8996beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 90039a53e0cSJaegeuk Kim 90167298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 9026451e041SJaegeuk Kim 9036451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 9040d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 90539a53e0cSJaegeuk Kim 906c227f912SChao Yu /* for inode management */ 907c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 908c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 90939a53e0cSJaegeuk Kim 91013054c54SChao Yu /* for extent tree cache */ 91113054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 9125e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 91313054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 91413054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 9157441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 916137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 91774fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 91813054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 91913054c54SChao Yu 92039a53e0cSJaegeuk Kim /* basic filesystem units */ 92139a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 92239a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 92339a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 92439a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 92539a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 92639a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 92739a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 92839a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 92939a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 93039a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 93139a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 93239a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 93339a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 934e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 93539a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 936ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 93739a53e0cSJaegeuk Kim 93839a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 93939a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 940a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 94139a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 94239a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 943523be8a6SJaegeuk Kim 944523be8a6SJaegeuk Kim /* # of pages, see count_type */ 94535782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 94641382ec4SJaegeuk Kim /* # of allocated blocks */ 94741382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 94839a53e0cSJaegeuk Kim 949687de7f1SJaegeuk Kim /* writeback control */ 950687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 951687de7f1SJaegeuk Kim 952513c5f37SJaegeuk Kim /* valid inode count */ 953513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 954513c5f37SJaegeuk Kim 95539a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 95639a53e0cSJaegeuk Kim 95739a53e0cSJaegeuk Kim /* for cleaning operations */ 95839a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 95939a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 9605ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 96139a53e0cSJaegeuk Kim 962e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 963e93b9865SHou Pengyang u64 fggc_threshold; 964e93b9865SHou Pengyang 965b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 966b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 967b1c57c1cSJaegeuk Kim 96839a53e0cSJaegeuk Kim /* 96939a53e0cSJaegeuk Kim * for stat information. 97039a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 97139a53e0cSJaegeuk Kim */ 97235b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 97339a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 97439a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 97539a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 976b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 9775b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 9785b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 9795b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 9805b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 981d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 98203e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 98303e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 98426a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 985648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 98626a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 987648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 98839a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 98933fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 99035b09d82SNamjae Jeon #endif 99139a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 992b59d0baeSNamjae Jeon 993b59d0baeSNamjae Jeon /* For sysfs suppport */ 994b59d0baeSNamjae Jeon struct kobject s_kobj; 995b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 9962658e50dSJaegeuk Kim 9972658e50dSJaegeuk Kim /* For shrinker support */ 9982658e50dSJaegeuk Kim struct list_head s_list; 9993c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 10003c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 10012658e50dSJaegeuk Kim struct mutex umount_mutex; 10022658e50dSJaegeuk Kim unsigned int shrinker_run_no; 10038f1dbbbbSShuoran Liu 10048f1dbbbbSShuoran Liu /* For write statistics */ 10058f1dbbbbSShuoran Liu u64 sectors_written_start; 10068f1dbbbbSShuoran Liu u64 kbytes_written; 100743b6573bSKeith Mok 100843b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 100943b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 10101ecc0c5cSChao Yu 10111ecc0c5cSChao Yu /* For fault injection */ 10121ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 10131ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 10141ecc0c5cSChao Yu #endif 101539a53e0cSJaegeuk Kim }; 101639a53e0cSJaegeuk Kim 10171ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 101855523519SChao Yu #define f2fs_show_injection_info(type) \ 101955523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 102055523519SChao Yu KERN_INFO, fault_name[type], \ 102155523519SChao Yu __func__, __builtin_return_address(0)) 10221ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 10231ecc0c5cSChao Yu { 10241ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 10251ecc0c5cSChao Yu 10261ecc0c5cSChao Yu if (!ffi->inject_rate) 10271ecc0c5cSChao Yu return false; 10281ecc0c5cSChao Yu 10291ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 10301ecc0c5cSChao Yu return false; 10311ecc0c5cSChao Yu 10321ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 10331ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 10341ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 10351ecc0c5cSChao Yu return true; 10361ecc0c5cSChao Yu } 10371ecc0c5cSChao Yu return false; 10381ecc0c5cSChao Yu } 10391ecc0c5cSChao Yu #endif 10401ecc0c5cSChao Yu 10418f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 10428f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 10438f1dbbbbSShuoran Liu */ 10448f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 104568afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 104668afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 10478f1dbbbbSShuoran Liu 10486beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 10496beceb54SJaegeuk Kim { 10506beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 10516beceb54SJaegeuk Kim } 10526beceb54SJaegeuk Kim 10536beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 10546beceb54SJaegeuk Kim { 10556beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 10566beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 10576beceb54SJaegeuk Kim 10586beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 10596beceb54SJaegeuk Kim } 10606beceb54SJaegeuk Kim 1061d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1062d0239e1bSJaegeuk Kim { 1063d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1064d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1065d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1066d0239e1bSJaegeuk Kim 1067d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1068d0239e1bSJaegeuk Kim return 0; 1069d0239e1bSJaegeuk Kim 1070d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1071d0239e1bSJaegeuk Kim } 1072d0239e1bSJaegeuk Kim 107339a53e0cSJaegeuk Kim /* 107439a53e0cSJaegeuk Kim * Inline functions 107539a53e0cSJaegeuk Kim */ 107643b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 107743b6573bSKeith Mok unsigned int length) 107843b6573bSKeith Mok { 107943b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 108043b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 108143b6573bSKeith Mok int err; 108243b6573bSKeith Mok 108343b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 108443b6573bSKeith Mok shash->flags = 0; 108543b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 108643b6573bSKeith Mok 108743b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 108843b6573bSKeith Mok BUG_ON(err); 108943b6573bSKeith Mok 109043b6573bSKeith Mok return *ctx; 109143b6573bSKeith Mok } 109243b6573bSKeith Mok 109343b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 109443b6573bSKeith Mok void *buf, size_t buf_size) 109543b6573bSKeith Mok { 109643b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 109743b6573bSKeith Mok } 109843b6573bSKeith Mok 109939a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 110039a53e0cSJaegeuk Kim { 110139a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 110239a53e0cSJaegeuk Kim } 110339a53e0cSJaegeuk Kim 110439a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 110539a53e0cSJaegeuk Kim { 110639a53e0cSJaegeuk Kim return sb->s_fs_info; 110739a53e0cSJaegeuk Kim } 110839a53e0cSJaegeuk Kim 11094081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 11104081363fSJaegeuk Kim { 11114081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 11124081363fSJaegeuk Kim } 11134081363fSJaegeuk Kim 11144081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 11154081363fSJaegeuk Kim { 11164081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 11174081363fSJaegeuk Kim } 11184081363fSJaegeuk Kim 11194081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 11204081363fSJaegeuk Kim { 11214081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 11224081363fSJaegeuk Kim } 11234081363fSJaegeuk Kim 112439a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 112539a53e0cSJaegeuk Kim { 112639a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 112739a53e0cSJaegeuk Kim } 112839a53e0cSJaegeuk Kim 112939a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 113039a53e0cSJaegeuk Kim { 113139a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 113239a53e0cSJaegeuk Kim } 113339a53e0cSJaegeuk Kim 113445590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 113545590710SGu Zheng { 113645590710SGu Zheng return (struct f2fs_node *)page_address(page); 113745590710SGu Zheng } 113845590710SGu Zheng 113958bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 114058bfaf44SJaegeuk Kim { 114158bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 114258bfaf44SJaegeuk Kim } 114358bfaf44SJaegeuk Kim 114439a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 114539a53e0cSJaegeuk Kim { 114639a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 114739a53e0cSJaegeuk Kim } 114839a53e0cSJaegeuk Kim 114939a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 115039a53e0cSJaegeuk Kim { 115139a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 115239a53e0cSJaegeuk Kim } 115339a53e0cSJaegeuk Kim 115439a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 115539a53e0cSJaegeuk Kim { 115639a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 115739a53e0cSJaegeuk Kim } 115839a53e0cSJaegeuk Kim 115939a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 116039a53e0cSJaegeuk Kim { 116139a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 116239a53e0cSJaegeuk Kim } 116339a53e0cSJaegeuk Kim 116439a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 116539a53e0cSJaegeuk Kim { 116639a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 116739a53e0cSJaegeuk Kim } 116839a53e0cSJaegeuk Kim 11699df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 11709df27d98SGu Zheng { 11719df27d98SGu Zheng return sbi->meta_inode->i_mapping; 11729df27d98SGu Zheng } 11739df27d98SGu Zheng 11744ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 11754ef51a8fSJaegeuk Kim { 11764ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 11774ef51a8fSJaegeuk Kim } 11784ef51a8fSJaegeuk Kim 1179caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 118039a53e0cSJaegeuk Kim { 1181fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 118239a53e0cSJaegeuk Kim } 118339a53e0cSJaegeuk Kim 1184caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 118539a53e0cSJaegeuk Kim { 1186fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1187caf0047eSChao Yu } 1188caf0047eSChao Yu 1189caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1190caf0047eSChao Yu { 1191fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 119239a53e0cSJaegeuk Kim } 119339a53e0cSJaegeuk Kim 1194d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1195d71b5564SJaegeuk Kim { 1196d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1197d71b5564SJaegeuk Kim } 1198d71b5564SJaegeuk Kim 1199ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1200ced2c7eaSKinglong Mee { 1201ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1202ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1203ced2c7eaSKinglong Mee } 1204ced2c7eaSKinglong Mee 1205aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 120625ca923bSJaegeuk Kim { 120725ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1208aaec2b1dSChao Yu 120925ca923bSJaegeuk Kim return ckpt_flags & f; 121025ca923bSJaegeuk Kim } 121125ca923bSJaegeuk Kim 1212aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 121325ca923bSJaegeuk Kim { 1214aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1215aaec2b1dSChao Yu } 1216aaec2b1dSChao Yu 1217aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1218aaec2b1dSChao Yu { 1219aaec2b1dSChao Yu unsigned int ckpt_flags; 1220aaec2b1dSChao Yu 1221aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 122225ca923bSJaegeuk Kim ckpt_flags |= f; 122325ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 122425ca923bSJaegeuk Kim } 122525ca923bSJaegeuk Kim 1226aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 122725ca923bSJaegeuk Kim { 1228aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1229aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1230aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1231aaec2b1dSChao Yu } 1232aaec2b1dSChao Yu 1233aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1234aaec2b1dSChao Yu { 1235aaec2b1dSChao Yu unsigned int ckpt_flags; 1236aaec2b1dSChao Yu 1237aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 123825ca923bSJaegeuk Kim ckpt_flags &= (~f); 123925ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 124025ca923bSJaegeuk Kim } 124125ca923bSJaegeuk Kim 1242aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1243aaec2b1dSChao Yu { 1244aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1245aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1246aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1247aaec2b1dSChao Yu } 1248aaec2b1dSChao Yu 124922ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 125022ad0b6aSJaegeuk Kim { 125122ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 125222ad0b6aSJaegeuk Kim 125322ad0b6aSJaegeuk Kim if (lock) 125422ad0b6aSJaegeuk Kim spin_lock(&sbi->cp_lock); 125522ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 125622ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 125722ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 125822ad0b6aSJaegeuk Kim if (lock) 125922ad0b6aSJaegeuk Kim spin_unlock(&sbi->cp_lock); 126022ad0b6aSJaegeuk Kim } 126122ad0b6aSJaegeuk Kim 126222ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 126322ad0b6aSJaegeuk Kim struct cp_control *cpc) 126422ad0b6aSJaegeuk Kim { 126522ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 126622ad0b6aSJaegeuk Kim 126722ad0b6aSJaegeuk Kim return (cpc) ? (cpc->reason == CP_UMOUNT) && set : set; 126822ad0b6aSJaegeuk Kim } 126922ad0b6aSJaegeuk Kim 1270e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 127139a53e0cSJaegeuk Kim { 1272b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 127339a53e0cSJaegeuk Kim } 127439a53e0cSJaegeuk Kim 1275e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 127639a53e0cSJaegeuk Kim { 1277b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 127839936837SJaegeuk Kim } 127939936837SJaegeuk Kim 1280e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 128139936837SJaegeuk Kim { 1282b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 128339936837SJaegeuk Kim } 128439936837SJaegeuk Kim 1285e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 128639936837SJaegeuk Kim { 1287b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 128839a53e0cSJaegeuk Kim } 128939a53e0cSJaegeuk Kim 1290119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1291119ee914SJaegeuk Kim { 1292119ee914SJaegeuk Kim int reason = CP_SYNC; 1293119ee914SJaegeuk Kim 1294119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1295119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1296119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1297119ee914SJaegeuk Kim reason = CP_UMOUNT; 1298119ee914SJaegeuk Kim return reason; 1299119ee914SJaegeuk Kim } 1300119ee914SJaegeuk Kim 1301119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1302119ee914SJaegeuk Kim { 1303119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 1304119ee914SJaegeuk Kim } 1305119ee914SJaegeuk Kim 1306119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1307119ee914SJaegeuk Kim { 1308aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1309aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1310119ee914SJaegeuk Kim } 1311119ee914SJaegeuk Kim 131239a53e0cSJaegeuk Kim /* 131339a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 131439a53e0cSJaegeuk Kim */ 1315064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 131639a53e0cSJaegeuk Kim { 1317d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1318d6b7d4b3SChao Yu return -EINVAL; 1319cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1320064e0823SNamjae Jeon return -EINVAL; 1321064e0823SNamjae Jeon return 0; 132239a53e0cSJaegeuk Kim } 132339a53e0cSJaegeuk Kim 132439a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 132539a53e0cSJaegeuk Kim 132639a53e0cSJaegeuk Kim /* 132739a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 132839a53e0cSJaegeuk Kim */ 132939a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 133039a53e0cSJaegeuk Kim { 133139a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 13326c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 133339a53e0cSJaegeuk Kim else 13346c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 133539a53e0cSJaegeuk Kim } 133639a53e0cSJaegeuk Kim 13374bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 13384bc8e9bcSChao Yu { 13394bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 13404bc8e9bcSChao Yu } 13414bc8e9bcSChao Yu 13428edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 134339a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 134446008c6dSChao Yu struct inode *inode, blkcnt_t *count) 134539a53e0cSJaegeuk Kim { 1346dd11a5dfSJaegeuk Kim blkcnt_t diff; 1347dd11a5dfSJaegeuk Kim 1348cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 134955523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 135055523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 1351cb78942bSJaegeuk Kim return false; 135255523519SChao Yu } 1353cb78942bSJaegeuk Kim #endif 1354dd11a5dfSJaegeuk Kim /* 1355dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1356dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1357dd11a5dfSJaegeuk Kim */ 1358dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1359cfb271d4SChao Yu 136039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13612555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 13622555a2d5SJaegeuk Kim if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { 1363dd11a5dfSJaegeuk Kim diff = sbi->total_valid_block_count - sbi->user_block_count; 1364dd11a5dfSJaegeuk Kim *count -= diff; 13652555a2d5SJaegeuk Kim sbi->total_valid_block_count = sbi->user_block_count; 136646008c6dSChao Yu if (!*count) { 136739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1368dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 136939a53e0cSJaegeuk Kim return false; 137039a53e0cSJaegeuk Kim } 137146008c6dSChao Yu } 137239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 137341382ec4SJaegeuk Kim 13742555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, *count, true); 137539a53e0cSJaegeuk Kim return true; 137639a53e0cSJaegeuk Kim } 137739a53e0cSJaegeuk Kim 1378da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 137939a53e0cSJaegeuk Kim struct inode *inode, 138039a53e0cSJaegeuk Kim blkcnt_t count) 138139a53e0cSJaegeuk Kim { 138239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13839850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 13849850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 138539a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 138639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 13872555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, count, false); 138839a53e0cSJaegeuk Kim } 138939a53e0cSJaegeuk Kim 139039a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 139139a53e0cSJaegeuk Kim { 139235782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 13937c4abcbeSChao Yu 139436951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 139536951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 13967c4abcbeSChao Yu return; 13977c4abcbeSChao Yu 1398caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 139939a53e0cSJaegeuk Kim } 140039a53e0cSJaegeuk Kim 1401a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 140239a53e0cSJaegeuk Kim { 1403204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1404c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1405c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 140639a53e0cSJaegeuk Kim } 140739a53e0cSJaegeuk Kim 140839a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 140939a53e0cSJaegeuk Kim { 141035782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 141139a53e0cSJaegeuk Kim } 141239a53e0cSJaegeuk Kim 1413a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 141439a53e0cSJaegeuk Kim { 14155ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 14165ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 14171fe54f9dSJaegeuk Kim return; 14181fe54f9dSJaegeuk Kim 1419204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1420c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1421c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 142239a53e0cSJaegeuk Kim } 142339a53e0cSJaegeuk Kim 1424523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 142539a53e0cSJaegeuk Kim { 142635782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 142739a53e0cSJaegeuk Kim } 142839a53e0cSJaegeuk Kim 1429204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1430f8b2c1f9SJaegeuk Kim { 1431204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1432f8b2c1f9SJaegeuk Kim } 1433f8b2c1f9SJaegeuk Kim 14345ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 14355ac206cfSNamjae Jeon { 14363519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1437523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1438523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1439523be8a6SJaegeuk Kim 1440523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 14415ac206cfSNamjae Jeon } 14425ac206cfSNamjae Jeon 144339a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 144439a53e0cSJaegeuk Kim { 14458b8343faSJaegeuk Kim return sbi->total_valid_block_count; 144639a53e0cSJaegeuk Kim } 144739a53e0cSJaegeuk Kim 1448f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1449f83a2584SYunlei He { 1450f83a2584SYunlei He return sbi->discard_blks; 1451f83a2584SYunlei He } 1452f83a2584SYunlei He 145339a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 145439a53e0cSJaegeuk Kim { 145539a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 145639a53e0cSJaegeuk Kim 145739a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 145839a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 145939a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 146039a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 146139a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 146239a53e0cSJaegeuk Kim 146339a53e0cSJaegeuk Kim return 0; 146439a53e0cSJaegeuk Kim } 146539a53e0cSJaegeuk Kim 146655141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 146755141486SWanpeng Li { 146855141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 146955141486SWanpeng Li } 147055141486SWanpeng Li 147139a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 147239a53e0cSJaegeuk Kim { 147339a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 14741dbe4152SChangman Lee int offset; 14751dbe4152SChangman Lee 147655141486SWanpeng Li if (__cp_payload(sbi) > 0) { 14771dbe4152SChangman Lee if (flag == NAT_BITMAP) 14781dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 14791dbe4152SChangman Lee else 148065b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 14811dbe4152SChangman Lee } else { 14821dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 148325ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 148439a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 148539a53e0cSJaegeuk Kim } 14861dbe4152SChangman Lee } 148739a53e0cSJaegeuk Kim 148839a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 148939a53e0cSJaegeuk Kim { 14908508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 149139a53e0cSJaegeuk Kim 14928508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 149339a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 149439a53e0cSJaegeuk Kim return start_addr; 149539a53e0cSJaegeuk Kim } 149639a53e0cSJaegeuk Kim 14978508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 14988508e44aSJaegeuk Kim { 14998508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 15008508e44aSJaegeuk Kim 15018508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 15028508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 15038508e44aSJaegeuk Kim return start_addr; 15048508e44aSJaegeuk Kim } 15058508e44aSJaegeuk Kim 15068508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 15078508e44aSJaegeuk Kim { 15088508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 15098508e44aSJaegeuk Kim } 15108508e44aSJaegeuk Kim 151139a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 151239a53e0cSJaegeuk Kim { 151339a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 151439a53e0cSJaegeuk Kim } 151539a53e0cSJaegeuk Kim 151639a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1517ef86d709SGu Zheng struct inode *inode) 151839a53e0cSJaegeuk Kim { 151939a53e0cSJaegeuk Kim block_t valid_block_count; 152039a53e0cSJaegeuk Kim unsigned int valid_node_count; 152139a53e0cSJaegeuk Kim 152239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 152339a53e0cSJaegeuk Kim 1524ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1525cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 152639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 152739a53e0cSJaegeuk Kim return false; 152839a53e0cSJaegeuk Kim } 152939a53e0cSJaegeuk Kim 1530ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1531cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 153239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 153339a53e0cSJaegeuk Kim return false; 153439a53e0cSJaegeuk Kim } 153539a53e0cSJaegeuk Kim 153639a53e0cSJaegeuk Kim if (inode) 15378edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, true); 1538ef86d709SGu Zheng 1539ef86d709SGu Zheng sbi->total_valid_node_count++; 1540ef86d709SGu Zheng sbi->total_valid_block_count++; 154139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 154239a53e0cSJaegeuk Kim 154341382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 154439a53e0cSJaegeuk Kim return true; 154539a53e0cSJaegeuk Kim } 154639a53e0cSJaegeuk Kim 154739a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1548ef86d709SGu Zheng struct inode *inode) 154939a53e0cSJaegeuk Kim { 155039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 155139a53e0cSJaegeuk Kim 15529850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 15539850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 15549850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 155539a53e0cSJaegeuk Kim 15568edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, false); 1557ef86d709SGu Zheng sbi->total_valid_node_count--; 1558ef86d709SGu Zheng sbi->total_valid_block_count--; 155939a53e0cSJaegeuk Kim 156039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 156139a53e0cSJaegeuk Kim } 156239a53e0cSJaegeuk Kim 156339a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 156439a53e0cSJaegeuk Kim { 15658b8343faSJaegeuk Kim return sbi->total_valid_node_count; 156639a53e0cSJaegeuk Kim } 156739a53e0cSJaegeuk Kim 156839a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 156939a53e0cSJaegeuk Kim { 1570513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 157139a53e0cSJaegeuk Kim } 157239a53e0cSJaegeuk Kim 15730e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 157439a53e0cSJaegeuk Kim { 1575513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 157639a53e0cSJaegeuk Kim } 157739a53e0cSJaegeuk Kim 1578513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 157939a53e0cSJaegeuk Kim { 1580513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 158139a53e0cSJaegeuk Kim } 158239a53e0cSJaegeuk Kim 1583a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1584a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1585a56c7c6fSJaegeuk Kim { 1586c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1587c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1588cac5a3d8SDongOh Shin 1589c41f3cc3SJaegeuk Kim if (page) 1590c41f3cc3SJaegeuk Kim return page; 1591c41f3cc3SJaegeuk Kim 159255523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 159355523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1594c41f3cc3SJaegeuk Kim return NULL; 159555523519SChao Yu } 1596c41f3cc3SJaegeuk Kim #endif 1597a56c7c6fSJaegeuk Kim if (!for_write) 1598a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1599a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1600a56c7c6fSJaegeuk Kim } 1601a56c7c6fSJaegeuk Kim 16026e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 16036e2c64adSJaegeuk Kim { 16046e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 16056e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 16066e2c64adSJaegeuk Kim 16076e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 16086e2c64adSJaegeuk Kim kunmap(dst); 16096e2c64adSJaegeuk Kim kunmap(src); 16106e2c64adSJaegeuk Kim } 16116e2c64adSJaegeuk Kim 161239a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 161339a53e0cSJaegeuk Kim { 1614031fa8ccSJaegeuk Kim if (!page) 161539a53e0cSJaegeuk Kim return; 161639a53e0cSJaegeuk Kim 161739a53e0cSJaegeuk Kim if (unlock) { 16189850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 161939a53e0cSJaegeuk Kim unlock_page(page); 162039a53e0cSJaegeuk Kim } 162109cbfeafSKirill A. Shutemov put_page(page); 162239a53e0cSJaegeuk Kim } 162339a53e0cSJaegeuk Kim 162439a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 162539a53e0cSJaegeuk Kim { 162639a53e0cSJaegeuk Kim if (dn->node_page) 162739a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 162839a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 162939a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 163039a53e0cSJaegeuk Kim dn->node_page = NULL; 163139a53e0cSJaegeuk Kim dn->inode_page = NULL; 163239a53e0cSJaegeuk Kim } 163339a53e0cSJaegeuk Kim 163439a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1635e8512d2eSGu Zheng size_t size) 163639a53e0cSJaegeuk Kim { 1637e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 163839a53e0cSJaegeuk Kim } 163939a53e0cSJaegeuk Kim 16407bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 16417bd59381SGu Zheng gfp_t flags) 16427bd59381SGu Zheng { 16437bd59381SGu Zheng void *entry; 16447bd59381SGu Zheng 164580c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 164680c54505SJaegeuk Kim if (!entry) 164780c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 16487bd59381SGu Zheng return entry; 16497bd59381SGu Zheng } 16507bd59381SGu Zheng 1651740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1652740432f8SJaegeuk Kim { 1653740432f8SJaegeuk Kim struct bio *bio; 1654740432f8SJaegeuk Kim 1655740432f8SJaegeuk Kim /* No failure on bio allocation */ 1656740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 165780c54505SJaegeuk Kim if (!bio) 165880c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1659740432f8SJaegeuk Kim return bio; 1660740432f8SJaegeuk Kim } 1661740432f8SJaegeuk Kim 16629be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 16639be32d72SJaegeuk Kim unsigned long index, void *item) 16649be32d72SJaegeuk Kim { 16659be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 16669be32d72SJaegeuk Kim cond_resched(); 16679be32d72SJaegeuk Kim } 16689be32d72SJaegeuk Kim 166939a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 167039a53e0cSJaegeuk Kim 167139a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 167239a53e0cSJaegeuk Kim { 167345590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1674cac5a3d8SDongOh Shin 167539a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 167639a53e0cSJaegeuk Kim } 167739a53e0cSJaegeuk Kim 167839a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 167939a53e0cSJaegeuk Kim { 168039a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 168139a53e0cSJaegeuk Kim } 168239a53e0cSJaegeuk Kim 168339a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 168439a53e0cSJaegeuk Kim unsigned int offset) 168539a53e0cSJaegeuk Kim { 168639a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 168739a53e0cSJaegeuk Kim __le32 *addr_array; 1688cac5a3d8SDongOh Shin 168945590710SGu Zheng raw_node = F2FS_NODE(node_page); 169039a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 169139a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 169239a53e0cSJaegeuk Kim } 169339a53e0cSJaegeuk Kim 169439a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 169539a53e0cSJaegeuk Kim { 169639a53e0cSJaegeuk Kim int mask; 169739a53e0cSJaegeuk Kim 169839a53e0cSJaegeuk Kim addr += (nr >> 3); 169939a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 170039a53e0cSJaegeuk Kim return mask & *addr; 170139a53e0cSJaegeuk Kim } 170239a53e0cSJaegeuk Kim 1703a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1704a66cdd98SJaegeuk Kim { 1705a66cdd98SJaegeuk Kim int mask; 1706a66cdd98SJaegeuk Kim 1707a66cdd98SJaegeuk Kim addr += (nr >> 3); 1708a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1709a66cdd98SJaegeuk Kim *addr |= mask; 1710a66cdd98SJaegeuk Kim } 1711a66cdd98SJaegeuk Kim 1712a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1713a66cdd98SJaegeuk Kim { 1714a66cdd98SJaegeuk Kim int mask; 1715a66cdd98SJaegeuk Kim 1716a66cdd98SJaegeuk Kim addr += (nr >> 3); 1717a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1718a66cdd98SJaegeuk Kim *addr &= ~mask; 1719a66cdd98SJaegeuk Kim } 1720a66cdd98SJaegeuk Kim 172152aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 172239a53e0cSJaegeuk Kim { 172339a53e0cSJaegeuk Kim int mask; 172439a53e0cSJaegeuk Kim int ret; 172539a53e0cSJaegeuk Kim 172639a53e0cSJaegeuk Kim addr += (nr >> 3); 172739a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 172839a53e0cSJaegeuk Kim ret = mask & *addr; 172939a53e0cSJaegeuk Kim *addr |= mask; 173039a53e0cSJaegeuk Kim return ret; 173139a53e0cSJaegeuk Kim } 173239a53e0cSJaegeuk Kim 173352aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 173439a53e0cSJaegeuk Kim { 173539a53e0cSJaegeuk Kim int mask; 173639a53e0cSJaegeuk Kim int ret; 173739a53e0cSJaegeuk Kim 173839a53e0cSJaegeuk Kim addr += (nr >> 3); 173939a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 174039a53e0cSJaegeuk Kim ret = mask & *addr; 174139a53e0cSJaegeuk Kim *addr &= ~mask; 174239a53e0cSJaegeuk Kim return ret; 174339a53e0cSJaegeuk Kim } 174439a53e0cSJaegeuk Kim 1745c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1746c6ac4c0eSGu Zheng { 1747c6ac4c0eSGu Zheng int mask; 1748c6ac4c0eSGu Zheng 1749c6ac4c0eSGu Zheng addr += (nr >> 3); 1750c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1751c6ac4c0eSGu Zheng *addr ^= mask; 1752c6ac4c0eSGu Zheng } 1753c6ac4c0eSGu Zheng 175439a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 175539a53e0cSJaegeuk Kim enum { 175639a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1757b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 175826de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1759ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 176039a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 176139a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 176239a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1763c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1764c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1765444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 17661001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 176734d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1768fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1769fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 177088b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 177188b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 17725fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 177302a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 17743c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 17751e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1776b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1777510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1778d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1779c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 1780dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 1781ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 178239a53e0cSJaegeuk Kim }; 178339a53e0cSJaegeuk Kim 1784205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 1785205b9822SJaegeuk Kim int flag, bool set) 178639a53e0cSJaegeuk Kim { 1787205b9822SJaegeuk Kim switch (flag) { 1788205b9822SJaegeuk Kim case FI_INLINE_XATTR: 1789205b9822SJaegeuk Kim case FI_INLINE_DATA: 1790205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 1791205b9822SJaegeuk Kim if (set) 1792205b9822SJaegeuk Kim return; 1793205b9822SJaegeuk Kim case FI_DATA_EXIST: 1794205b9822SJaegeuk Kim case FI_INLINE_DOTS: 17957c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1796205b9822SJaegeuk Kim } 179739a53e0cSJaegeuk Kim } 179839a53e0cSJaegeuk Kim 179991942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 180039a53e0cSJaegeuk Kim { 180191942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 180291942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 1803205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 180439a53e0cSJaegeuk Kim } 180539a53e0cSJaegeuk Kim 180691942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 180739a53e0cSJaegeuk Kim { 180891942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 180939a53e0cSJaegeuk Kim } 181039a53e0cSJaegeuk Kim 181191942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 181239a53e0cSJaegeuk Kim { 181391942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 181491942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 1815205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 181639a53e0cSJaegeuk Kim } 181739a53e0cSJaegeuk Kim 181891942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 1819444c580fSJaegeuk Kim { 182091942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 182191942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 18227c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 182339a53e0cSJaegeuk Kim } 182439a53e0cSJaegeuk Kim 1825a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 1826a1961246SJaegeuk Kim { 1827a1961246SJaegeuk Kim if (inc) 1828a1961246SJaegeuk Kim inc_nlink(inode); 1829a1961246SJaegeuk Kim else 1830a1961246SJaegeuk Kim drop_nlink(inode); 18317c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1832a1961246SJaegeuk Kim } 1833a1961246SJaegeuk Kim 18348edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 18358edd03c8SJaegeuk Kim blkcnt_t diff, bool add) 18368edd03c8SJaegeuk Kim { 183726de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 183826de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 183926de9b11SJaegeuk Kim 18408edd03c8SJaegeuk Kim inode->i_blocks = add ? inode->i_blocks + diff : 18418edd03c8SJaegeuk Kim inode->i_blocks - diff; 18427c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 184326de9b11SJaegeuk Kim if (clean || recover) 184426de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 18458edd03c8SJaegeuk Kim } 18468edd03c8SJaegeuk Kim 1847fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 1848fc9581c8SJaegeuk Kim { 184926de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 185026de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 185126de9b11SJaegeuk Kim 1852fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 1853fc9581c8SJaegeuk Kim return; 1854fc9581c8SJaegeuk Kim 1855fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 18567c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 185726de9b11SJaegeuk Kim if (clean || recover) 185826de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 185926de9b11SJaegeuk Kim } 186026de9b11SJaegeuk Kim 1861205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 1862205b9822SJaegeuk Kim { 1863205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 18647c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1865205b9822SJaegeuk Kim } 1866205b9822SJaegeuk Kim 1867205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 1868205b9822SJaegeuk Kim { 1869205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 18707c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1871205b9822SJaegeuk Kim } 1872205b9822SJaegeuk Kim 1873205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 1874205b9822SJaegeuk Kim { 1875205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 18767c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1877205b9822SJaegeuk Kim } 1878205b9822SJaegeuk Kim 187991942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 1880444c580fSJaegeuk Kim { 1881205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 1882205b9822SJaegeuk Kim 1883444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1884205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 18851001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 1886205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 188734d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1888205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 1889b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1890205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 1891510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1892205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 1893444c580fSJaegeuk Kim } 1894444c580fSJaegeuk Kim 189591942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 1896444c580fSJaegeuk Kim { 1897444c580fSJaegeuk Kim ri->i_inline = 0; 1898444c580fSJaegeuk Kim 189991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 1900444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 190191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 19021001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 190391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 190434d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 190591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 1906b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 190791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 1908510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1909444c580fSJaegeuk Kim } 1910444c580fSJaegeuk Kim 1911987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1912987c7c31SChao Yu { 191391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 1914987c7c31SChao Yu } 1915987c7c31SChao Yu 191681ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1917de93653fSJaegeuk Kim { 191881ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1919de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1920de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1921de93653fSJaegeuk Kim } 1922de93653fSJaegeuk Kim 192365985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 192465985d93SJaegeuk Kim { 1925695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1926cac5a3d8SDongOh Shin 192765985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 192865985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 192965985d93SJaegeuk Kim } 193065985d93SJaegeuk Kim 193165985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 193265985d93SJaegeuk Kim { 1933987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 193465985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 193565985d93SJaegeuk Kim else 193665985d93SJaegeuk Kim return 0; 193765985d93SJaegeuk Kim } 193865985d93SJaegeuk Kim 19390dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 19400dbdc2aeSJaegeuk Kim { 194191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 19420dbdc2aeSJaegeuk Kim } 19430dbdc2aeSJaegeuk Kim 1944b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1945b3d208f9SJaegeuk Kim { 194691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 1947b3d208f9SJaegeuk Kim } 1948b3d208f9SJaegeuk Kim 1949510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1950510022a8SJaegeuk Kim { 195191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 1952510022a8SJaegeuk Kim } 1953510022a8SJaegeuk Kim 195488b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 195588b88a66SJaegeuk Kim { 195691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 195788b88a66SJaegeuk Kim } 195888b88a66SJaegeuk Kim 19595fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 19605fe45743SChao Yu { 19615fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 19625fe45743SChao Yu } 19635fe45743SChao Yu 196402a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 196502a1335fSJaegeuk Kim { 196691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 196702a1335fSJaegeuk Kim } 196802a1335fSJaegeuk Kim 19693c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 19703c6c2bebSJaegeuk Kim { 197191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 19723c6c2bebSJaegeuk Kim } 19733c6c2bebSJaegeuk Kim 19741e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 19751e84371fSJaegeuk Kim { 197691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 19771e84371fSJaegeuk Kim } 19781e84371fSJaegeuk Kim 19791001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 19801001b347SHuajun Li { 1981695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1982cac5a3d8SDongOh Shin 19831001b347SHuajun Li return (void *)&(ri->i_addr[1]); 19841001b347SHuajun Li } 19851001b347SHuajun Li 198634d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 198734d67debSChao Yu { 198891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 198934d67debSChao Yu } 199034d67debSChao Yu 19919486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 19929486ba44SJaegeuk Kim { 19939486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 19949486ba44SJaegeuk Kim kunmap(page); 19959486ba44SJaegeuk Kim } 19969486ba44SJaegeuk Kim 1997b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1998b5492af7SJaegeuk Kim { 1999b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2000b5492af7SJaegeuk Kim } 2001b5492af7SJaegeuk Kim 2002b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2003b5492af7SJaegeuk Kim { 2004b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 20057c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2006b5492af7SJaegeuk Kim } 2007b5492af7SJaegeuk Kim 2008b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2009b5492af7SJaegeuk Kim { 2010b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 20117c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2012b5492af7SJaegeuk Kim } 2013b5492af7SJaegeuk Kim 201426787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 201526787236SJaegeuk Kim { 201626787236SJaegeuk Kim if (dsync) { 201726787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 201826787236SJaegeuk Kim bool ret; 201926787236SJaegeuk Kim 202026787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 202126787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 202226787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 202326787236SJaegeuk Kim return ret; 202426787236SJaegeuk Kim } 202526787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 202626787236SJaegeuk Kim file_keep_isize(inode) || 202726787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 202826787236SJaegeuk Kim return false; 202926787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 2030267378d4SChao Yu } 2031267378d4SChao Yu 2032267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 2033267378d4SChao Yu { 2034267378d4SChao Yu return sb->s_flags & MS_RDONLY; 2035267378d4SChao Yu } 203639a53e0cSJaegeuk Kim 203739a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 203839a53e0cSJaegeuk Kim { 2039aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 204039a53e0cSJaegeuk Kim } 204139a53e0cSJaegeuk Kim 2042eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2043eaa693f4SJaegeuk Kim { 2044eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2045eaa693f4SJaegeuk Kim return true; 2046eaa693f4SJaegeuk Kim 2047eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2048eaa693f4SJaegeuk Kim return true; 2049eaa693f4SJaegeuk Kim 2050eaa693f4SJaegeuk Kim return false; 2051eaa693f4SJaegeuk Kim } 2052eaa693f4SJaegeuk Kim 20533e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 20543e72f721SJaegeuk Kim { 20553e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 205691942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 20573e72f721SJaegeuk Kim return false; 20583e72f721SJaegeuk Kim 2059886f56f9SAl Viro return S_ISREG(inode->i_mode); 20603e72f721SJaegeuk Kim } 20613e72f721SJaegeuk Kim 20621ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 20631ecc0c5cSChao Yu size_t size, gfp_t flags) 20640414b004SJaegeuk Kim { 20652c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 206655523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 206755523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 20682c63feadSJaegeuk Kim return NULL; 206955523519SChao Yu } 20702c63feadSJaegeuk Kim #endif 20710414b004SJaegeuk Kim return kmalloc(size, flags); 20720414b004SJaegeuk Kim } 20730414b004SJaegeuk Kim 207439307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 207539307a8eSJaegeuk Kim { 207639307a8eSJaegeuk Kim void *ret; 207739307a8eSJaegeuk Kim 207839307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 207939307a8eSJaegeuk Kim if (!ret) 208039307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 208139307a8eSJaegeuk Kim return ret; 208239307a8eSJaegeuk Kim } 208339307a8eSJaegeuk Kim 208439307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 208539307a8eSJaegeuk Kim { 208639307a8eSJaegeuk Kim void *ret; 208739307a8eSJaegeuk Kim 208839307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 208939307a8eSJaegeuk Kim if (!ret) 209039307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 209139307a8eSJaegeuk Kim return ret; 209239307a8eSJaegeuk Kim } 209339307a8eSJaegeuk Kim 209439a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 209591942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 209639a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 209739a53e0cSJaegeuk Kim 209839a53e0cSJaegeuk Kim /* 20991e1bb4baSJaegeuk Kim * file.c 210039a53e0cSJaegeuk Kim */ 2101cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2102cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2103cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2104cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2105a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2106a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2107cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2108cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2109cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2110cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2111cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 211239a53e0cSJaegeuk Kim 211339a53e0cSJaegeuk Kim /* 211439a53e0cSJaegeuk Kim * inode.c 211539a53e0cSJaegeuk Kim */ 2116cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2117cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2118cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2119cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2120cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2121cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2122cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2123cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2124cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 212539a53e0cSJaegeuk Kim 212639a53e0cSJaegeuk Kim /* 212739a53e0cSJaegeuk Kim * namei.c 212839a53e0cSJaegeuk Kim */ 212939a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 213039a53e0cSJaegeuk Kim 213139a53e0cSJaegeuk Kim /* 213239a53e0cSJaegeuk Kim * dir.c 213339a53e0cSJaegeuk Kim */ 2134cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2135cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2136cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2137cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2138cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2139cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2140cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2141cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2142cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2143cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2144cac5a3d8SDongOh Shin const struct qstr *new_name, 2145cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2146cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2147cac5a3d8SDongOh Shin unsigned int current_depth); 2148cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2149cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2150cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2151cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2152cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2153cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2154cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2155cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2156cac5a3d8SDongOh Shin struct page **page); 2157cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2158cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2159cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2160cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2161cac5a3d8SDongOh Shin unsigned int bit_pos); 2162cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2163cac5a3d8SDongOh Shin const struct qstr *orig_name, 2164cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2165cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2166cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2167cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2168cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2169cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2170cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2171cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2172cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 217339a53e0cSJaegeuk Kim 2174b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2175b7f7a5e0SAl Viro { 21762b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2177510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2178b7f7a5e0SAl Viro } 2179b7f7a5e0SAl Viro 218039a53e0cSJaegeuk Kim /* 218139a53e0cSJaegeuk Kim * super.c 218239a53e0cSJaegeuk Kim */ 2183cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2184cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2185cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2186cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2187a07ef784SNamjae Jeon extern __printf(3, 4) 2188cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2189984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 219039a53e0cSJaegeuk Kim 219139a53e0cSJaegeuk Kim /* 219239a53e0cSJaegeuk Kim * hash.c 219339a53e0cSJaegeuk Kim */ 2194cac5a3d8SDongOh Shin f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info); 219539a53e0cSJaegeuk Kim 219639a53e0cSJaegeuk Kim /* 219739a53e0cSJaegeuk Kim * node.c 219839a53e0cSJaegeuk Kim */ 219939a53e0cSJaegeuk Kim struct dnode_of_data; 220039a53e0cSJaegeuk Kim struct node_info; 220139a53e0cSJaegeuk Kim 2202cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2203cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2204cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2205cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2206cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2207cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2208cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2209cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2210cac5a3d8SDongOh Shin int truncate_xattr_node(struct inode *inode, struct page *page); 2211cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2212cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2213cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 2214cac5a3d8SDongOh Shin struct page *new_node_page(struct dnode_of_data *dn, 2215cac5a3d8SDongOh Shin unsigned int ofs, struct page *ipage); 2216cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2217cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2218cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2219cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2220cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2221cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2222cac5a3d8SDongOh Shin int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc); 222322ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2224cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2225cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2226cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2227cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2228cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2229d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2230cac5a3d8SDongOh Shin block_t blkaddr); 2231cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2232cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2233cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 223422ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2235cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2236cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 22376e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 223839a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 223939a53e0cSJaegeuk Kim 224039a53e0cSJaegeuk Kim /* 224139a53e0cSJaegeuk Kim * segment.c 224239a53e0cSJaegeuk Kim */ 2243cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 2244cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 22458c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2246cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2247cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2248cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2249cac5a3d8SDongOh Shin int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2250cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2251cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2252cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2253cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2254cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2255d431413fSChao Yu void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2256cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2257cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2258cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2259cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2260cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2261cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2262cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2263cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2264cac5a3d8SDongOh Shin void write_meta_page(struct f2fs_sb_info *sbi, struct page *page); 2265cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2266cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2267d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2268cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2269cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2270cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2271cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2272cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2273cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2274cac5a3d8SDongOh Shin bool recover_newaddr); 2275cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2276cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2277cac5a3d8SDongOh Shin struct f2fs_summary *sum, int type); 2278cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2279cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2280cac5a3d8SDongOh Shin void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2281cac5a3d8SDongOh Shin block_t blkaddr); 2282cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2283cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2284cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2285cac5a3d8SDongOh Shin unsigned int val, int alloc); 2286cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2287cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2288cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 22897fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 22907fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 229139a53e0cSJaegeuk Kim 229239a53e0cSJaegeuk Kim /* 229339a53e0cSJaegeuk Kim * checkpoint.c 229439a53e0cSJaegeuk Kim */ 2295cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2296cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2297cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2298cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2299cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2300cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2301cac5a3d8SDongOh Shin int type, bool sync); 2302cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2303cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2304cac5a3d8SDongOh Shin long nr_to_write); 2305cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2306cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2307cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2308cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2309cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2310cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2311cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2312cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2313cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2314cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2315cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2316cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2317cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2318cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2319cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2320cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 23216e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 232239a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 232339a53e0cSJaegeuk Kim 232439a53e0cSJaegeuk Kim /* 232539a53e0cSJaegeuk Kim * data.c 232639a53e0cSJaegeuk Kim */ 2327cac5a3d8SDongOh Shin void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 2328cac5a3d8SDongOh Shin int rw); 2329cac5a3d8SDongOh Shin void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, 2330942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2331942fd319SJaegeuk Kim enum page_type type, int rw); 2332cac5a3d8SDongOh Shin void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi); 2333cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2334cac5a3d8SDongOh Shin int f2fs_submit_page_mbio(struct f2fs_io_info *fio); 2335cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2336cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2337cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2338cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2339cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2340cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2341cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2342cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2343cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2344cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2345cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2346cac5a3d8SDongOh Shin int op_flags, bool for_write); 2347cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2348cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2349cac5a3d8SDongOh Shin bool for_write); 2350cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2351cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2352cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2353cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2354cac5a3d8SDongOh Shin int create, int flag); 2355cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2356cac5a3d8SDongOh Shin u64 start, u64 len); 2357cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2358cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2359cac5a3d8SDongOh Shin unsigned int length); 2360cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 23615b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2362cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2363cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 23645b7a487cSWeichao Guo #endif 236539a53e0cSJaegeuk Kim 236639a53e0cSJaegeuk Kim /* 236739a53e0cSJaegeuk Kim * gc.c 236839a53e0cSJaegeuk Kim */ 2369cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2370cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2371cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2372e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 2373e066b83cSJaegeuk Kim unsigned int segno); 2374cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 237539a53e0cSJaegeuk Kim 237639a53e0cSJaegeuk Kim /* 237739a53e0cSJaegeuk Kim * recovery.c 237839a53e0cSJaegeuk Kim */ 2379cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2380cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 238139a53e0cSJaegeuk Kim 238239a53e0cSJaegeuk Kim /* 238339a53e0cSJaegeuk Kim * debug.c 238439a53e0cSJaegeuk Kim */ 238539a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 238639a53e0cSJaegeuk Kim struct f2fs_stat_info { 238739a53e0cSJaegeuk Kim struct list_head stat_list; 238839a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 238939a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 239039a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 23915b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 23925b7ee374SChao Yu unsigned long long hit_total, total_ext; 2393c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 239435782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 239535782b23SJaegeuk Kim int inmem_pages; 23960f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 2397b8559dc2SChao Yu int nats, dirty_nats, sits, dirty_sits, free_nids, alloc_nids; 239839a53e0cSJaegeuk Kim int total_count, utilization; 23998b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 24008b8dd65fSChao Yu int nr_flushing, nr_flushed, nr_discarding, nr_discarded; 24015f32366aSChao Yu int nr_discard_cmd; 2402d84d1cbdSChao Yu unsigned int undiscard_blks; 2403a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2404648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2405f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 240639a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 240739a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 240839a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 240939a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 241042190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 241139a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2412e1235983SChangman Lee int bg_node_segs, bg_data_segs; 241339a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2414e1235983SChangman Lee int bg_data_blks, bg_node_blks; 241539a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 241639a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 241739a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 241839a53e0cSJaegeuk Kim 241939a53e0cSJaegeuk Kim unsigned int segment_count[2]; 242039a53e0cSJaegeuk Kim unsigned int block_count[2]; 2421b9a2c252SChangman Lee unsigned int inplace_count; 24229edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 242339a53e0cSJaegeuk Kim }; 242439a53e0cSJaegeuk Kim 2425963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2426963d4f7dSGu Zheng { 2427963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2428963d4f7dSGu Zheng } 2429963d4f7dSGu Zheng 2430942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 243142190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 243239a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2433dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 243433fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 243533fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 24365b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 24375b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 24385b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 24395b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2440d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2441d5e8f6c9SChao Yu do { \ 2442d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2443d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2444d5e8f6c9SChao Yu } while (0) 2445d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2446d5e8f6c9SChao Yu do { \ 2447d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2448d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2449d5e8f6c9SChao Yu } while (0) 24500dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 24510dbdc2aeSJaegeuk Kim do { \ 24520dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 245303e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 24540dbdc2aeSJaegeuk Kim } while (0) 24550dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 24560dbdc2aeSJaegeuk Kim do { \ 24570dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 245803e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 24590dbdc2aeSJaegeuk Kim } while (0) 24603289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 24613289c061SJaegeuk Kim do { \ 24623289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 246303e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 24643289c061SJaegeuk Kim } while (0) 24653289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 24663289c061SJaegeuk Kim do { \ 24673289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 246803e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 24693289c061SJaegeuk Kim } while (0) 2470dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2471dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2472dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2473dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2474b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2475b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 247626a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2477cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 247826a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2479cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 248026a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 248126a28a0cSJaegeuk Kim do { \ 248226a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 248326a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 248426a28a0cSJaegeuk Kim if (cur > max) \ 248526a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 248626a28a0cSJaegeuk Kim } while (0) 2487648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2488648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2489648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2490648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2491648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2492648d50baSChao Yu do { \ 2493648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2494648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2495648d50baSChao Yu if (cur > max) \ 2496648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2497648d50baSChao Yu } while (0) 2498e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 249939a53e0cSJaegeuk Kim do { \ 2500963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 250168afcf2dSTomohiro Kusumi si->tot_segs++; \ 250268afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 250339a53e0cSJaegeuk Kim si->data_segs++; \ 2504e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2505e1235983SChangman Lee } else { \ 250639a53e0cSJaegeuk Kim si->node_segs++; \ 2507e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2508e1235983SChangman Lee } \ 250939a53e0cSJaegeuk Kim } while (0) 251039a53e0cSJaegeuk Kim 251139a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 251268afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 251339a53e0cSJaegeuk Kim 2514e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 251539a53e0cSJaegeuk Kim do { \ 2516963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 251739a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 251839a53e0cSJaegeuk Kim si->data_blks += (blks); \ 251968afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 252039a53e0cSJaegeuk Kim } while (0) 252139a53e0cSJaegeuk Kim 2522e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 252339a53e0cSJaegeuk Kim do { \ 2524963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 252539a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 252639a53e0cSJaegeuk Kim si->node_blks += (blks); \ 252768afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 252839a53e0cSJaegeuk Kim } while (0) 252939a53e0cSJaegeuk Kim 2530cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2531cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2532787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 25334589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 253439a53e0cSJaegeuk Kim #else 2535d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 2536d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 2537d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 2538d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 2539d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 2540d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 2541d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 2542d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 2543d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 2544d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 2545d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 2546d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 2547d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 2548d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 2549d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 2550d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 2551d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 2552d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 2553d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 2554d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 2555d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 2556d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 2557d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 2558d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 2559d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 2560d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 2561d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 2562d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 2563d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 256439a53e0cSJaegeuk Kim 256539a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 256639a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2567787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 25684589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 256939a53e0cSJaegeuk Kim #endif 257039a53e0cSJaegeuk Kim 257139a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 257239a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 257339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 257439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 257539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 257639a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 257739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 257839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2579cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 258039a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 258129e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 25821001b347SHuajun Li 2583e18c65b2SHuajun Li /* 2584e18c65b2SHuajun Li * inline.c 2585e18c65b2SHuajun Li */ 2586cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2587cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2588cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2589bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2590cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2591cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2592cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2593cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2594cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2595cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2596cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2597cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2598cac5a3d8SDongOh Shin struct page *ipage); 2599cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2600cac5a3d8SDongOh Shin const struct qstr *orig_name, 2601cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2602cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2603cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2604cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2605cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2606cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2607cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2608cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2609cac5a3d8SDongOh Shin __u64 start, __u64 len); 2610cde4de12SJaegeuk Kim 2611cde4de12SJaegeuk Kim /* 26122658e50dSJaegeuk Kim * shrinker.c 26132658e50dSJaegeuk Kim */ 2614cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2615cac5a3d8SDongOh Shin struct shrink_control *sc); 2616cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2617cac5a3d8SDongOh Shin struct shrink_control *sc); 2618cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2619cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 26202658e50dSJaegeuk Kim 26212658e50dSJaegeuk Kim /* 2622a28ef1f5SChao Yu * extent_cache.c 2623a28ef1f5SChao Yu */ 2624004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 2625004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 2626004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 2627004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 2628004b6862SChao Yu unsigned int ofs); 2629004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 2630004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 2631004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 2632004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 2633004b6862SChao Yu bool force); 2634df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi, 2635df0f6b44SChao Yu struct rb_root *root); 2636cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2637cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2638cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2639cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2640cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2641cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2642cac5a3d8SDongOh Shin struct extent_info *ei); 2643cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 264419b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2645cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2646cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2647a28ef1f5SChao Yu int __init create_extent_cache(void); 2648a28ef1f5SChao Yu void destroy_extent_cache(void); 2649a28ef1f5SChao Yu 2650a28ef1f5SChao Yu /* 2651cde4de12SJaegeuk Kim * crypto support 2652cde4de12SJaegeuk Kim */ 26530b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2654cde4de12SJaegeuk Kim { 2655cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2656cde4de12SJaegeuk Kim } 2657cde4de12SJaegeuk Kim 2658cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2659cde4de12SJaegeuk Kim { 2660cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2661cde4de12SJaegeuk Kim file_set_encrypt(inode); 2662cde4de12SJaegeuk Kim #endif 2663cde4de12SJaegeuk Kim } 2664cde4de12SJaegeuk Kim 2665cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2666cde4de12SJaegeuk Kim { 26670b81d077SJaegeuk Kim return bio->bi_private != NULL; 2668cde4de12SJaegeuk Kim } 2669cde4de12SJaegeuk Kim 2670cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2671cde4de12SJaegeuk Kim { 2672cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2673cde4de12SJaegeuk Kim } 2674f424f664SJaegeuk Kim 26750bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 267652763a4bSJaegeuk Kim { 26770bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 267852763a4bSJaegeuk Kim } 267952763a4bSJaegeuk Kim 2680178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2681178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 26823c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2683178053e2SDamien Le Moal { 2684178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 26853c62be17SJaegeuk Kim int i; 2686178053e2SDamien Le Moal 26873c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 26883c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 26893c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 26903c62be17SJaegeuk Kim return -EINVAL; 2691178053e2SDamien Le Moal } 2692178053e2SDamien Le Moal #endif 2693178053e2SDamien Le Moal 269496ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 269596ba2decSDamien Le Moal { 269696ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 269796ba2decSDamien Le Moal 269896ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 269952763a4bSJaegeuk Kim } 270052763a4bSJaegeuk Kim 270152763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 270252763a4bSJaegeuk Kim { 270352763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 270452763a4bSJaegeuk Kim clear_opt(sbi, LFS); 270552763a4bSJaegeuk Kim 270652763a4bSJaegeuk Kim switch (mt) { 270752763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 270852763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 270952763a4bSJaegeuk Kim break; 271052763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 271152763a4bSJaegeuk Kim set_opt(sbi, LFS); 271252763a4bSJaegeuk Kim break; 271352763a4bSJaegeuk Kim } 271452763a4bSJaegeuk Kim } 271552763a4bSJaegeuk Kim 2716fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2717fcc85a4dSJaegeuk Kim { 2718fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2719886f56f9SAl Viro umode_t mode = inode->i_mode; 2720fcc85a4dSJaegeuk Kim 2721fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2722fcc85a4dSJaegeuk Kim #else 2723fcc85a4dSJaegeuk Kim return 0; 2724fcc85a4dSJaegeuk Kim #endif 2725fcc85a4dSJaegeuk Kim } 2726fcc85a4dSJaegeuk Kim 272739a53e0cSJaegeuk Kim #endif 2728