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]; 661ecc0c5cSChao Yu #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 9239a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 9339a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 9439a53e0cSJaegeuk Kim #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) \ 138bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 139a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 140a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 141ad4d307fSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) \ 142ad4d307fSJaegeuk Kim ((1 << (sbi)->log_blocks_per_seg) * (sbi)->segs_per_sec) 14315469963SJaegeuk Kim #define DISCARD_ISSUE_RATE 8 14460b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 145dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 146bba681cbSJaegeuk Kim 14775ab4cb8SJaegeuk Kim struct cp_control { 14875ab4cb8SJaegeuk Kim int reason; 1494b2fecc8SJaegeuk Kim __u64 trim_start; 1504b2fecc8SJaegeuk Kim __u64 trim_end; 1514b2fecc8SJaegeuk Kim __u64 trim_minlen; 1524b2fecc8SJaegeuk Kim __u64 trimmed; 15375ab4cb8SJaegeuk Kim }; 15475ab4cb8SJaegeuk Kim 155662befdaSChao Yu /* 15681c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 157662befdaSChao Yu */ 158662befdaSChao Yu enum { 159662befdaSChao Yu META_CP, 160662befdaSChao Yu META_NAT, 16181c1a0f1SChao Yu META_SIT, 1624c521f49SJaegeuk Kim META_SSA, 1634c521f49SJaegeuk Kim META_POR, 164662befdaSChao Yu }; 165662befdaSChao Yu 1666451e041SJaegeuk Kim /* for the list of ino */ 1676451e041SJaegeuk Kim enum { 1686451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 169fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 170fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1716451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1726451e041SJaegeuk Kim }; 1736451e041SJaegeuk Kim 1746451e041SJaegeuk Kim struct ino_entry { 17539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17639a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 17739a53e0cSJaegeuk Kim }; 17839a53e0cSJaegeuk Kim 1792710fd7eSChao Yu /* for the list of inodes to be GCed */ 18006292073SChao Yu struct inode_entry { 18139a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18239a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 18339a53e0cSJaegeuk Kim }; 18439a53e0cSJaegeuk Kim 185a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 1867fd9e544SJaegeuk Kim struct discard_entry { 1877fd9e544SJaegeuk Kim struct list_head list; /* list head */ 188a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 189a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 1907fd9e544SJaegeuk Kim }; 1917fd9e544SJaegeuk Kim 19215469963SJaegeuk Kim enum { 19315469963SJaegeuk Kim D_PREP, 19415469963SJaegeuk Kim D_SUBMIT, 19515469963SJaegeuk Kim D_DONE, 19615469963SJaegeuk Kim }; 19715469963SJaegeuk Kim 198b01a9201SJaegeuk Kim struct discard_cmd { 199b01a9201SJaegeuk Kim struct list_head list; /* command list */ 200b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 201c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 202b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 203c81abe34SJaegeuk Kim block_t start; /* actual start address in dev */ 204b01a9201SJaegeuk Kim block_t len; /* length */ 20515469963SJaegeuk Kim int state; /* state */ 206c81abe34SJaegeuk Kim int error; /* bio error */ 207275b66b0SChao Yu }; 208275b66b0SChao Yu 2090b54fb84SJaegeuk Kim struct discard_cmd_control { 21015469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 2110b54fb84SJaegeuk Kim struct list_head discard_entry_list; /* 4KB discard entry list */ 2120b54fb84SJaegeuk Kim int nr_discards; /* # of discards in the list */ 21322d375ddSChao Yu struct list_head discard_pend_list; /* store pending entries */ 21422d375ddSChao Yu struct list_head discard_wait_list; /* store on-flushing entries */ 21515469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 21615469963SJaegeuk Kim struct mutex cmd_lock; 2170b54fb84SJaegeuk Kim int max_discards; /* max. discards to be issued */ 2188b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 2198b8dd65fSChao Yu atomic_t issing_discard; /* # of issing discard */ 2205f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 22139a53e0cSJaegeuk Kim }; 22239a53e0cSJaegeuk Kim 22339a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 22439a53e0cSJaegeuk Kim struct fsync_inode_entry { 22539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 22639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 227c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 228c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 22939a53e0cSJaegeuk Kim }; 23039a53e0cSJaegeuk Kim 231dfc08a12SChao Yu #define nats_in_cursum(jnl) (le16_to_cpu(jnl->n_nats)) 232dfc08a12SChao Yu #define sits_in_cursum(jnl) (le16_to_cpu(jnl->n_sits)) 23339a53e0cSJaegeuk Kim 234dfc08a12SChao Yu #define nat_in_journal(jnl, i) (jnl->nat_j.entries[i].ne) 235dfc08a12SChao Yu #define nid_in_journal(jnl, i) (jnl->nat_j.entries[i].nid) 236dfc08a12SChao Yu #define sit_in_journal(jnl, i) (jnl->sit_j.entries[i].se) 237dfc08a12SChao Yu #define segno_in_journal(jnl, i) (jnl->sit_j.entries[i].segno) 23839a53e0cSJaegeuk Kim 239dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 240dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 241309cc2b6SJaegeuk Kim 242dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 24339a53e0cSJaegeuk Kim { 244dfc08a12SChao Yu int before = nats_in_cursum(journal); 245cac5a3d8SDongOh Shin 246dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 24739a53e0cSJaegeuk Kim return before; 24839a53e0cSJaegeuk Kim } 24939a53e0cSJaegeuk Kim 250dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 25139a53e0cSJaegeuk Kim { 252dfc08a12SChao Yu int before = sits_in_cursum(journal); 253cac5a3d8SDongOh Shin 254dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 25539a53e0cSJaegeuk Kim return before; 25639a53e0cSJaegeuk Kim } 25739a53e0cSJaegeuk Kim 258dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 259dfc08a12SChao Yu int size, int type) 260184a5cd2SChao Yu { 261184a5cd2SChao Yu if (type == NAT_JOURNAL) 262dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 263dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 264184a5cd2SChao Yu } 265184a5cd2SChao Yu 26639a53e0cSJaegeuk Kim /* 267e9750824SNamjae Jeon * ioctl commands 268e9750824SNamjae Jeon */ 269e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 270e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 271d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 272e9750824SNamjae Jeon 27388b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 27488b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 27588b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 27602a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2771e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2781e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 279c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 280456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 281d323d005SChao Yu #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) 2824dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 2834dd6f977SJaegeuk Kim struct f2fs_move_range) 28488b88a66SJaegeuk Kim 2850b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 2860b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 2870b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 288f424f664SJaegeuk Kim 2891abff93dSJaegeuk Kim /* 2901abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2911abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2921abff93dSJaegeuk Kim */ 2931abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2941abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2951abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2961abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 297c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 2981abff93dSJaegeuk Kim 299e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 300e9750824SNamjae Jeon /* 301e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 302e9750824SNamjae Jeon */ 303e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 304e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 30504ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 306e9750824SNamjae Jeon #endif 307e9750824SNamjae Jeon 308d323d005SChao Yu struct f2fs_defragment { 309d323d005SChao Yu u64 start; 310d323d005SChao Yu u64 len; 311d323d005SChao Yu }; 312d323d005SChao Yu 3134dd6f977SJaegeuk Kim struct f2fs_move_range { 3144dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3154dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3164dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3174dd6f977SJaegeuk Kim u64 len; /* size to move */ 3184dd6f977SJaegeuk Kim }; 3194dd6f977SJaegeuk Kim 320e9750824SNamjae Jeon /* 32139a53e0cSJaegeuk Kim * For INODE and NODE manager 32239a53e0cSJaegeuk Kim */ 3237b3cd7d6SJaegeuk Kim /* for directory operations */ 3247b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 325d8c6822aSJaegeuk Kim struct inode *inode; 3267b3cd7d6SJaegeuk Kim const void *bitmap; 3277b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 3287b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 3297b3cd7d6SJaegeuk Kim int max; 3307b3cd7d6SJaegeuk Kim }; 3317b3cd7d6SJaegeuk Kim 33264c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 33364c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 3347b3cd7d6SJaegeuk Kim { 335d8c6822aSJaegeuk Kim d->inode = inode; 3367b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 3377b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3387b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3397b3cd7d6SJaegeuk Kim d->filename = t->filename; 34064c24ecbSTomohiro Kusumi } 341cac5a3d8SDongOh Shin 34264c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 34364c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_inline_dentry *t) 34464c24ecbSTomohiro Kusumi { 34564c24ecbSTomohiro Kusumi d->inode = inode; 3467b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3477b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3487b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3497b3cd7d6SJaegeuk Kim d->filename = t->filename; 3507b3cd7d6SJaegeuk Kim } 3517b3cd7d6SJaegeuk Kim 352dbe6a5ffSJaegeuk Kim /* 353dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 354dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 355dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 35639a53e0cSJaegeuk Kim */ 357dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 358dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 359266e97a8SJaegeuk Kim enum { 360266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 361266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 362266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 363266e97a8SJaegeuk Kim * look up a node with readahead called 3644f4124d0SChao Yu * by get_data_block. 36539a53e0cSJaegeuk Kim */ 366266e97a8SJaegeuk Kim }; 367266e97a8SJaegeuk Kim 368a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 36939a53e0cSJaegeuk Kim 370817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 371817202d9SChao Yu 37213054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 37313054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 37413054c54SChao Yu 37539a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 37613054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 37713054c54SChao Yu 37813054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 37913054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 380c11abd1aSJaegeuk Kim 38139a53e0cSJaegeuk Kim struct extent_info { 38239a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3834d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 384111d2495SMasanari Iida unsigned int len; /* length of the extent */ 38539a53e0cSJaegeuk Kim }; 38639a53e0cSJaegeuk Kim 38713054c54SChao Yu struct extent_node { 38813054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 38913054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 39013054c54SChao Yu struct extent_info ei; /* extent info */ 391201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 39213054c54SChao Yu }; 39313054c54SChao Yu 39413054c54SChao Yu struct extent_tree { 39513054c54SChao Yu nid_t ino; /* inode number */ 39613054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 39762c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 3983e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 399137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 40013054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 40168e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 40213054c54SChao Yu }; 40313054c54SChao Yu 40439a53e0cSJaegeuk Kim /* 405003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 406003a3e1dSJaegeuk Kim * 407003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 408003a3e1dSJaegeuk Kim */ 409003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 410003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 4117f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 4127f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 4137f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 414003a3e1dSJaegeuk Kim 415003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 416003a3e1dSJaegeuk Kim block_t m_pblk; 417003a3e1dSJaegeuk Kim block_t m_lblk; 418003a3e1dSJaegeuk Kim unsigned int m_len; 419003a3e1dSJaegeuk Kim unsigned int m_flags; 420da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 421003a3e1dSJaegeuk Kim }; 422003a3e1dSJaegeuk Kim 423e2b4e2bcSChao Yu /* for flag in get_data_block */ 424e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 425e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 426e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 427e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 428b439b103SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_DIO 4 42924b84912SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_AIO 5 430e2b4e2bcSChao Yu 431003a3e1dSJaegeuk Kim /* 43239a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 43339a53e0cSJaegeuk Kim */ 43439a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 435354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 436cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 437e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 43826787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 43939a53e0cSJaegeuk Kim 440b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 441b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 442b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 443b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 444b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 445b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 446cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 447cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 448cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 449e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 450e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 45126787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 45226787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 453cde4de12SJaegeuk Kim 454ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 455ab9fa662SJaegeuk Kim 45639a53e0cSJaegeuk Kim struct f2fs_inode_info { 45739a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 45839a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 45939a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 46038431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 46139a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4626666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 46339a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 46439a53e0cSJaegeuk Kim 46539a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 46639a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 467d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 468204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 46939a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 47039a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 47188c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 47239a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 47326de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 47488b88a66SJaegeuk Kim 4750f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 4760f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 47788b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 47888b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 4793e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 48082e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 48139a53e0cSJaegeuk Kim }; 48239a53e0cSJaegeuk Kim 48339a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 484bd933d4fSChao Yu struct f2fs_extent *i_ext) 48539a53e0cSJaegeuk Kim { 486bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 487bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 488bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 48939a53e0cSJaegeuk Kim } 49039a53e0cSJaegeuk Kim 49139a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 49239a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 49339a53e0cSJaegeuk Kim { 49439a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4954d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 49639a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 49739a53e0cSJaegeuk Kim } 49839a53e0cSJaegeuk Kim 499429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 500429511cdSChao Yu u32 blk, unsigned int len) 501429511cdSChao Yu { 502429511cdSChao Yu ei->fofs = fofs; 503429511cdSChao Yu ei->blk = blk; 504429511cdSChao Yu ei->len = len; 505429511cdSChao Yu } 506429511cdSChao Yu 507429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 508429511cdSChao Yu struct extent_info *front) 509429511cdSChao Yu { 510429511cdSChao Yu return (back->fofs + back->len == front->fofs && 511429511cdSChao Yu back->blk + back->len == front->blk); 512429511cdSChao Yu } 513429511cdSChao Yu 514429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 515429511cdSChao Yu struct extent_info *back) 516429511cdSChao Yu { 517429511cdSChao Yu return __is_extent_mergeable(back, cur); 518429511cdSChao Yu } 519429511cdSChao Yu 520429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 521429511cdSChao Yu struct extent_info *front) 522429511cdSChao Yu { 523429511cdSChao Yu return __is_extent_mergeable(cur, front); 524429511cdSChao Yu } 525429511cdSChao Yu 526cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 527205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 528205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 5294abd3f5aSChao Yu { 530205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 5314abd3f5aSChao Yu et->largest = en->ei; 5327c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 533205b9822SJaegeuk Kim } 5344abd3f5aSChao Yu } 5354abd3f5aSChao Yu 536b8559dc2SChao Yu enum nid_list { 537b8559dc2SChao Yu FREE_NID_LIST, 538b8559dc2SChao Yu ALLOC_NID_LIST, 539b8559dc2SChao Yu MAX_NID_LIST, 540b8559dc2SChao Yu }; 541b8559dc2SChao Yu 54239a53e0cSJaegeuk Kim struct f2fs_nm_info { 54339a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 54439a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 54504d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 54639a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 547cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 548ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 5492304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 55039a53e0cSJaegeuk Kim 55139a53e0cSJaegeuk Kim /* NAT cache management */ 55239a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 553309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 554b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 55539a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 556309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 557aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 55822ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 55939a53e0cSJaegeuk Kim 56039a53e0cSJaegeuk Kim /* free node ids management */ 5618a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 562b8559dc2SChao Yu struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ 563b8559dc2SChao Yu unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 564b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 56539a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 5664ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 5674ac91242SChao Yu unsigned char *nat_block_bitmap; 568586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 56939a53e0cSJaegeuk Kim 57039a53e0cSJaegeuk Kim /* for checkpoint */ 57139a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 57222ad0b6aSJaegeuk Kim 57322ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 57422ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 57522ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 57622ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 577599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 578599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 579599a09b2SChao Yu #endif 58039a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 58139a53e0cSJaegeuk Kim }; 58239a53e0cSJaegeuk Kim 58339a53e0cSJaegeuk Kim /* 58439a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 58539a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 58639a53e0cSJaegeuk Kim * by the data offset in a file. 58739a53e0cSJaegeuk Kim */ 58839a53e0cSJaegeuk Kim struct dnode_of_data { 58939a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 59039a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 59139a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 59239a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 59339a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 59439a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 59593bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 5963cf45747SChao Yu char cur_level; /* level of hole node page */ 5973cf45747SChao Yu char max_level; /* level of current page located */ 59839a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 59939a53e0cSJaegeuk Kim }; 60039a53e0cSJaegeuk Kim 60139a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 60239a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 60339a53e0cSJaegeuk Kim { 604d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 60539a53e0cSJaegeuk Kim dn->inode = inode; 60639a53e0cSJaegeuk Kim dn->inode_page = ipage; 60739a53e0cSJaegeuk Kim dn->node_page = npage; 60839a53e0cSJaegeuk Kim dn->nid = nid; 60939a53e0cSJaegeuk Kim } 61039a53e0cSJaegeuk Kim 61139a53e0cSJaegeuk Kim /* 61239a53e0cSJaegeuk Kim * For SIT manager 61339a53e0cSJaegeuk Kim * 61439a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 61539a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 61639a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 61739a53e0cSJaegeuk Kim * respectively. 61839a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 61939a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 62039a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 62139a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 62239a53e0cSJaegeuk Kim * data and 8 for node logs. 62339a53e0cSJaegeuk Kim */ 62439a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 62539a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 62639a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 62739a53e0cSJaegeuk Kim 62839a53e0cSJaegeuk Kim enum { 62939a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 63039a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 63139a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 63239a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 63339a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 63439a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 63538aa0889SJaegeuk Kim NO_CHECK_TYPE, 63639a53e0cSJaegeuk Kim }; 63739a53e0cSJaegeuk Kim 6386b4afdd7SJaegeuk Kim struct flush_cmd { 6396b4afdd7SJaegeuk Kim struct completion wait; 640721bd4d5SGu Zheng struct llist_node llnode; 6416b4afdd7SJaegeuk Kim int ret; 6426b4afdd7SJaegeuk Kim }; 6436b4afdd7SJaegeuk Kim 644a688b9d9SGu Zheng struct flush_cmd_control { 645a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 646a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 6478b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 6488b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 649721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 650721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 651a688b9d9SGu Zheng }; 652a688b9d9SGu Zheng 65339a53e0cSJaegeuk Kim struct f2fs_sm_info { 65439a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 65539a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 65639a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 65739a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 65839a53e0cSJaegeuk Kim 65939a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 66039a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 66139a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 66239a53e0cSJaegeuk Kim 66339a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 66439a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 66539a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 66639a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 66781eb8d6eSJaegeuk Kim 66881eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 66981eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 6707fd9e544SJaegeuk Kim 671bba681cbSJaegeuk Kim /* for batched trimming */ 672bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 673bba681cbSJaegeuk Kim 674184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 675184a5cd2SChao Yu 676216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 677216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 678c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 679ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 6806b4afdd7SJaegeuk Kim 6816b4afdd7SJaegeuk Kim /* for flush command control */ 682b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 683a688b9d9SGu Zheng 6840b54fb84SJaegeuk Kim /* for discard command control */ 6850b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 68639a53e0cSJaegeuk Kim }; 68739a53e0cSJaegeuk Kim 68839a53e0cSJaegeuk Kim /* 68939a53e0cSJaegeuk Kim * For superblock 69039a53e0cSJaegeuk Kim */ 69139a53e0cSJaegeuk Kim /* 69239a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 69339a53e0cSJaegeuk Kim * 69439a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 69539a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 69639a53e0cSJaegeuk Kim */ 69736951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 69839a53e0cSJaegeuk Kim enum count_type { 69939a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 700c227f912SChao Yu F2FS_DIRTY_DATA, 70139a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 70239a53e0cSJaegeuk Kim F2FS_DIRTY_META, 7038dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 7040f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 70536951b38SChao Yu F2FS_WB_CP_DATA, 70636951b38SChao Yu F2FS_WB_DATA, 70739a53e0cSJaegeuk Kim NR_COUNT_TYPE, 70839a53e0cSJaegeuk Kim }; 70939a53e0cSJaegeuk Kim 71039a53e0cSJaegeuk Kim /* 711e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 71239a53e0cSJaegeuk Kim * The available types are: 71339a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 71439a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 71539a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 71639a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 71739a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 71839a53e0cSJaegeuk Kim * with waiting the bio's completion 71939a53e0cSJaegeuk Kim * ... Only can be used with META. 72039a53e0cSJaegeuk Kim */ 7217d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 72239a53e0cSJaegeuk Kim enum page_type { 72339a53e0cSJaegeuk Kim DATA, 72439a53e0cSJaegeuk Kim NODE, 72539a53e0cSJaegeuk Kim META, 72639a53e0cSJaegeuk Kim NR_PAGE_TYPE, 72739a53e0cSJaegeuk Kim META_FLUSH, 7288ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 7298ce67cb0SJaegeuk Kim INMEM_DROP, 7308c242db9SJaegeuk Kim INMEM_INVALIDATE, 73128bc106bSChao Yu INMEM_REVOKE, 7328ce67cb0SJaegeuk Kim IPU, 7338ce67cb0SJaegeuk Kim OPU, 73439a53e0cSJaegeuk Kim }; 73539a53e0cSJaegeuk Kim 736458e6197SJaegeuk Kim struct f2fs_io_info { 73705ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 738458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 73904d328deSMike Christie int op; /* contains REQ_OP_ */ 740ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 7417a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 74228bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 74305ca3632SJaegeuk Kim struct page *page; /* page to be written */ 7444375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 745d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 746458e6197SJaegeuk Kim }; 747458e6197SJaegeuk Kim 74804d328deSMike Christie #define is_read_io(rw) (rw == READ) 7491ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 750458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 7511ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 7521ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 753458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 754df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 7551ff7bd3bSJaegeuk Kim }; 7561ff7bd3bSJaegeuk Kim 7573c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 7583c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 7593c62be17SJaegeuk Kim struct f2fs_dev_info { 7603c62be17SJaegeuk Kim struct block_device *bdev; 7613c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 7623c62be17SJaegeuk Kim unsigned int total_segments; 7633c62be17SJaegeuk Kim block_t start_blk; 7643c62be17SJaegeuk Kim block_t end_blk; 7653c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 7663c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 7673c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 7683c62be17SJaegeuk Kim #endif 7693c62be17SJaegeuk Kim }; 7703c62be17SJaegeuk Kim 771c227f912SChao Yu enum inode_type { 772c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 773c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 7740f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 775c227f912SChao Yu NR_INODE_TYPE, 776c227f912SChao Yu }; 777c227f912SChao Yu 77867298804SChao Yu /* for inner inode cache management */ 77967298804SChao Yu struct inode_management { 78067298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 78167298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 78267298804SChao Yu struct list_head ino_list; /* inode list head */ 78367298804SChao Yu unsigned long ino_num; /* number of entries */ 78467298804SChao Yu }; 78567298804SChao Yu 786caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 787caf0047eSChao Yu enum { 788caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 789caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 790caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 791caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 792df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 793bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 794caf0047eSChao Yu }; 795caf0047eSChao Yu 7966beceb54SJaegeuk Kim enum { 7976beceb54SJaegeuk Kim CP_TIME, 798d0239e1bSJaegeuk Kim REQ_TIME, 7996beceb54SJaegeuk Kim MAX_TIME, 8006beceb54SJaegeuk Kim }; 8016beceb54SJaegeuk Kim 80239a53e0cSJaegeuk Kim struct f2fs_sb_info { 80339a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 8045e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 80539a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 806e8240f65SChao Yu int valid_super_block; /* valid super block no */ 807fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 80839a53e0cSJaegeuk Kim 809178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 810178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 811178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 812178053e2SDamien Le Moal #endif 813178053e2SDamien Le Moal 81439a53e0cSJaegeuk Kim /* for node-related operations */ 81539a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 81639a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 81739a53e0cSJaegeuk Kim 81839a53e0cSJaegeuk Kim /* for segment-related operations */ 81939a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 8201ff7bd3bSJaegeuk Kim 8211ff7bd3bSJaegeuk Kim /* for bio operations */ 822924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 8231ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 8247dfeaa32SJaegeuk Kim struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ 8250a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 8260a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 82739a53e0cSJaegeuk Kim 82839a53e0cSJaegeuk Kim /* for checkpoint */ 82939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 8308508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 831aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 83239a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 83339936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 834b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 835b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 83659c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 837fb51b5efSChangman Lee wait_queue_head_t cp_wait; 8386beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 8396beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 84039a53e0cSJaegeuk Kim 84167298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 8426451e041SJaegeuk Kim 8436451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 8440d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 84539a53e0cSJaegeuk Kim 846c227f912SChao Yu /* for inode management */ 847c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 848c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 84939a53e0cSJaegeuk Kim 85013054c54SChao Yu /* for extent tree cache */ 85113054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 8525e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 85313054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 85413054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 8557441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 856137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 85774fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 85813054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 85913054c54SChao Yu 86039a53e0cSJaegeuk Kim /* basic filesystem units */ 86139a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 86239a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 86339a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 86439a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 86539a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 86639a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 86739a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 86839a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 86939a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 87039a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 87139a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 87239a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 87339a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 874e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 87539a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 876ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 87739a53e0cSJaegeuk Kim 87839a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 87939a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 880a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 88139a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 88239a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 883523be8a6SJaegeuk Kim 884523be8a6SJaegeuk Kim /* # of pages, see count_type */ 88535782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 88641382ec4SJaegeuk Kim /* # of allocated blocks */ 88741382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 88839a53e0cSJaegeuk Kim 889687de7f1SJaegeuk Kim /* writeback control */ 890687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 891687de7f1SJaegeuk Kim 892513c5f37SJaegeuk Kim /* valid inode count */ 893513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 894513c5f37SJaegeuk Kim 89539a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 89639a53e0cSJaegeuk Kim 89739a53e0cSJaegeuk Kim /* for cleaning operations */ 89839a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 89939a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 9005ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 90139a53e0cSJaegeuk Kim 902e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 903e93b9865SHou Pengyang u64 fggc_threshold; 904e93b9865SHou Pengyang 905b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 906b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 907b1c57c1cSJaegeuk Kim 90839a53e0cSJaegeuk Kim /* 90939a53e0cSJaegeuk Kim * for stat information. 91039a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 91139a53e0cSJaegeuk Kim */ 91235b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 91339a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 91439a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 91539a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 916b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 9175b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 9185b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 9195b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 9205b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 921d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 92203e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 92303e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 92426a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 925648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 92626a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 927648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 92839a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 92933fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 93035b09d82SNamjae Jeon #endif 93135b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 93239a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 933b59d0baeSNamjae Jeon 934b59d0baeSNamjae Jeon /* For sysfs suppport */ 935b59d0baeSNamjae Jeon struct kobject s_kobj; 936b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 9372658e50dSJaegeuk Kim 9382658e50dSJaegeuk Kim /* For shrinker support */ 9392658e50dSJaegeuk Kim struct list_head s_list; 9403c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 9413c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 9422658e50dSJaegeuk Kim struct mutex umount_mutex; 9432658e50dSJaegeuk Kim unsigned int shrinker_run_no; 9448f1dbbbbSShuoran Liu 9458f1dbbbbSShuoran Liu /* For write statistics */ 9468f1dbbbbSShuoran Liu u64 sectors_written_start; 9478f1dbbbbSShuoran Liu u64 kbytes_written; 94843b6573bSKeith Mok 94943b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 95043b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 9511ecc0c5cSChao Yu 9521ecc0c5cSChao Yu /* For fault injection */ 9531ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 9541ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 9551ecc0c5cSChao Yu #endif 95639a53e0cSJaegeuk Kim }; 95739a53e0cSJaegeuk Kim 9581ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 95955523519SChao Yu #define f2fs_show_injection_info(type) \ 96055523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 96155523519SChao Yu KERN_INFO, fault_name[type], \ 96255523519SChao Yu __func__, __builtin_return_address(0)) 9631ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 9641ecc0c5cSChao Yu { 9651ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 9661ecc0c5cSChao Yu 9671ecc0c5cSChao Yu if (!ffi->inject_rate) 9681ecc0c5cSChao Yu return false; 9691ecc0c5cSChao Yu 9701ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 9711ecc0c5cSChao Yu return false; 9721ecc0c5cSChao Yu 9731ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 9741ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 9751ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 9761ecc0c5cSChao Yu return true; 9771ecc0c5cSChao Yu } 9781ecc0c5cSChao Yu return false; 9791ecc0c5cSChao Yu } 9801ecc0c5cSChao Yu #endif 9811ecc0c5cSChao Yu 9828f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 9838f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 9848f1dbbbbSShuoran Liu */ 9858f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 9868f1dbbbbSShuoran Liu (((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) - \ 9878f1dbbbbSShuoran Liu s->sectors_written_start) >> 1) 9888f1dbbbbSShuoran Liu 9896beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 9906beceb54SJaegeuk Kim { 9916beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 9926beceb54SJaegeuk Kim } 9936beceb54SJaegeuk Kim 9946beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 9956beceb54SJaegeuk Kim { 9966beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 9976beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 9986beceb54SJaegeuk Kim 9996beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 10006beceb54SJaegeuk Kim } 10016beceb54SJaegeuk Kim 1002d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1003d0239e1bSJaegeuk Kim { 1004d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1005d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1006d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1007d0239e1bSJaegeuk Kim 1008d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1009d0239e1bSJaegeuk Kim return 0; 1010d0239e1bSJaegeuk Kim 1011d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1012d0239e1bSJaegeuk Kim } 1013d0239e1bSJaegeuk Kim 101439a53e0cSJaegeuk Kim /* 101539a53e0cSJaegeuk Kim * Inline functions 101639a53e0cSJaegeuk Kim */ 101743b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 101843b6573bSKeith Mok unsigned int length) 101943b6573bSKeith Mok { 102043b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 102143b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 102243b6573bSKeith Mok int err; 102343b6573bSKeith Mok 102443b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 102543b6573bSKeith Mok shash->flags = 0; 102643b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 102743b6573bSKeith Mok 102843b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 102943b6573bSKeith Mok BUG_ON(err); 103043b6573bSKeith Mok 103143b6573bSKeith Mok return *ctx; 103243b6573bSKeith Mok } 103343b6573bSKeith Mok 103443b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 103543b6573bSKeith Mok void *buf, size_t buf_size) 103643b6573bSKeith Mok { 103743b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 103843b6573bSKeith Mok } 103943b6573bSKeith Mok 104039a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 104139a53e0cSJaegeuk Kim { 104239a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 104339a53e0cSJaegeuk Kim } 104439a53e0cSJaegeuk Kim 104539a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 104639a53e0cSJaegeuk Kim { 104739a53e0cSJaegeuk Kim return sb->s_fs_info; 104839a53e0cSJaegeuk Kim } 104939a53e0cSJaegeuk Kim 10504081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 10514081363fSJaegeuk Kim { 10524081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 10534081363fSJaegeuk Kim } 10544081363fSJaegeuk Kim 10554081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 10564081363fSJaegeuk Kim { 10574081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 10584081363fSJaegeuk Kim } 10594081363fSJaegeuk Kim 10604081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 10614081363fSJaegeuk Kim { 10624081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 10634081363fSJaegeuk Kim } 10644081363fSJaegeuk Kim 106539a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 106639a53e0cSJaegeuk Kim { 106739a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 106839a53e0cSJaegeuk Kim } 106939a53e0cSJaegeuk Kim 107039a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 107139a53e0cSJaegeuk Kim { 107239a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 107339a53e0cSJaegeuk Kim } 107439a53e0cSJaegeuk Kim 107545590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 107645590710SGu Zheng { 107745590710SGu Zheng return (struct f2fs_node *)page_address(page); 107845590710SGu Zheng } 107945590710SGu Zheng 108058bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 108158bfaf44SJaegeuk Kim { 108258bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 108358bfaf44SJaegeuk Kim } 108458bfaf44SJaegeuk Kim 108539a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 108639a53e0cSJaegeuk Kim { 108739a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 108839a53e0cSJaegeuk Kim } 108939a53e0cSJaegeuk Kim 109039a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 109139a53e0cSJaegeuk Kim { 109239a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 109339a53e0cSJaegeuk Kim } 109439a53e0cSJaegeuk Kim 109539a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 109639a53e0cSJaegeuk Kim { 109739a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 109839a53e0cSJaegeuk Kim } 109939a53e0cSJaegeuk Kim 110039a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 110139a53e0cSJaegeuk Kim { 110239a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 110339a53e0cSJaegeuk Kim } 110439a53e0cSJaegeuk Kim 110539a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 110639a53e0cSJaegeuk Kim { 110739a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 110839a53e0cSJaegeuk Kim } 110939a53e0cSJaegeuk Kim 11109df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 11119df27d98SGu Zheng { 11129df27d98SGu Zheng return sbi->meta_inode->i_mapping; 11139df27d98SGu Zheng } 11149df27d98SGu Zheng 11154ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 11164ef51a8fSJaegeuk Kim { 11174ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 11184ef51a8fSJaegeuk Kim } 11194ef51a8fSJaegeuk Kim 1120caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 112139a53e0cSJaegeuk Kim { 1122fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 112339a53e0cSJaegeuk Kim } 112439a53e0cSJaegeuk Kim 1125caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 112639a53e0cSJaegeuk Kim { 1127fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1128caf0047eSChao Yu } 1129caf0047eSChao Yu 1130caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1131caf0047eSChao Yu { 1132fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 113339a53e0cSJaegeuk Kim } 113439a53e0cSJaegeuk Kim 1135d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1136d71b5564SJaegeuk Kim { 1137d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1138d71b5564SJaegeuk Kim } 1139d71b5564SJaegeuk Kim 1140ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1141ced2c7eaSKinglong Mee { 1142ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1143ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1144ced2c7eaSKinglong Mee } 1145ced2c7eaSKinglong Mee 1146aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 114725ca923bSJaegeuk Kim { 114825ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1149aaec2b1dSChao Yu 115025ca923bSJaegeuk Kim return ckpt_flags & f; 115125ca923bSJaegeuk Kim } 115225ca923bSJaegeuk Kim 1153aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 115425ca923bSJaegeuk Kim { 1155aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1156aaec2b1dSChao Yu } 1157aaec2b1dSChao Yu 1158aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1159aaec2b1dSChao Yu { 1160aaec2b1dSChao Yu unsigned int ckpt_flags; 1161aaec2b1dSChao Yu 1162aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 116325ca923bSJaegeuk Kim ckpt_flags |= f; 116425ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 116525ca923bSJaegeuk Kim } 116625ca923bSJaegeuk Kim 1167aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 116825ca923bSJaegeuk Kim { 1169aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1170aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1171aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1172aaec2b1dSChao Yu } 1173aaec2b1dSChao Yu 1174aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1175aaec2b1dSChao Yu { 1176aaec2b1dSChao Yu unsigned int ckpt_flags; 1177aaec2b1dSChao Yu 1178aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 117925ca923bSJaegeuk Kim ckpt_flags &= (~f); 118025ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 118125ca923bSJaegeuk Kim } 118225ca923bSJaegeuk Kim 1183aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1184aaec2b1dSChao Yu { 1185aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1186aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1187aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1188aaec2b1dSChao Yu } 1189aaec2b1dSChao Yu 119022ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 119122ad0b6aSJaegeuk Kim { 119222ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 119322ad0b6aSJaegeuk Kim 119422ad0b6aSJaegeuk Kim if (lock) 119522ad0b6aSJaegeuk Kim spin_lock(&sbi->cp_lock); 119622ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 119722ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 119822ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 119922ad0b6aSJaegeuk Kim if (lock) 120022ad0b6aSJaegeuk Kim spin_unlock(&sbi->cp_lock); 120122ad0b6aSJaegeuk Kim } 120222ad0b6aSJaegeuk Kim 120322ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 120422ad0b6aSJaegeuk Kim struct cp_control *cpc) 120522ad0b6aSJaegeuk Kim { 120622ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 120722ad0b6aSJaegeuk Kim 120822ad0b6aSJaegeuk Kim return (cpc) ? (cpc->reason == CP_UMOUNT) && set : set; 120922ad0b6aSJaegeuk Kim } 121022ad0b6aSJaegeuk Kim 1211e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 121239a53e0cSJaegeuk Kim { 1213b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 121439a53e0cSJaegeuk Kim } 121539a53e0cSJaegeuk Kim 1216e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 121739a53e0cSJaegeuk Kim { 1218b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 121939936837SJaegeuk Kim } 122039936837SJaegeuk Kim 1221e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 122239936837SJaegeuk Kim { 1223b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 122439936837SJaegeuk Kim } 122539936837SJaegeuk Kim 1226e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 122739936837SJaegeuk Kim { 1228b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 122939a53e0cSJaegeuk Kim } 123039a53e0cSJaegeuk Kim 1231119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1232119ee914SJaegeuk Kim { 1233119ee914SJaegeuk Kim int reason = CP_SYNC; 1234119ee914SJaegeuk Kim 1235119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1236119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1237119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1238119ee914SJaegeuk Kim reason = CP_UMOUNT; 1239119ee914SJaegeuk Kim return reason; 1240119ee914SJaegeuk Kim } 1241119ee914SJaegeuk Kim 1242119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1243119ee914SJaegeuk Kim { 1244119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 1245119ee914SJaegeuk Kim } 1246119ee914SJaegeuk Kim 1247119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1248119ee914SJaegeuk Kim { 1249aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1250aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1251119ee914SJaegeuk Kim } 1252119ee914SJaegeuk Kim 125339a53e0cSJaegeuk Kim /* 125439a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 125539a53e0cSJaegeuk Kim */ 1256064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 125739a53e0cSJaegeuk Kim { 1258d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1259d6b7d4b3SChao Yu return -EINVAL; 1260cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1261064e0823SNamjae Jeon return -EINVAL; 1262064e0823SNamjae Jeon return 0; 126339a53e0cSJaegeuk Kim } 126439a53e0cSJaegeuk Kim 126539a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 126639a53e0cSJaegeuk Kim 126739a53e0cSJaegeuk Kim /* 126839a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 126939a53e0cSJaegeuk Kim */ 127039a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 127139a53e0cSJaegeuk Kim { 127239a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 12736c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 127439a53e0cSJaegeuk Kim else 12756c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 127639a53e0cSJaegeuk Kim } 127739a53e0cSJaegeuk Kim 12784bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 12794bc8e9bcSChao Yu { 12804bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 12814bc8e9bcSChao Yu } 12824bc8e9bcSChao Yu 12838edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 128439a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 128546008c6dSChao Yu struct inode *inode, blkcnt_t *count) 128639a53e0cSJaegeuk Kim { 1287dd11a5dfSJaegeuk Kim blkcnt_t diff; 1288dd11a5dfSJaegeuk Kim 1289cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 129055523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 129155523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 1292cb78942bSJaegeuk Kim return false; 129355523519SChao Yu } 1294cb78942bSJaegeuk Kim #endif 1295dd11a5dfSJaegeuk Kim /* 1296dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1297dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1298dd11a5dfSJaegeuk Kim */ 1299dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1300cfb271d4SChao Yu 130139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13022555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 13032555a2d5SJaegeuk Kim if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { 1304dd11a5dfSJaegeuk Kim diff = sbi->total_valid_block_count - sbi->user_block_count; 1305dd11a5dfSJaegeuk Kim *count -= diff; 13062555a2d5SJaegeuk Kim sbi->total_valid_block_count = sbi->user_block_count; 130746008c6dSChao Yu if (!*count) { 130839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1309dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 131039a53e0cSJaegeuk Kim return false; 131139a53e0cSJaegeuk Kim } 131246008c6dSChao Yu } 131339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 131441382ec4SJaegeuk Kim 13152555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, *count, true); 131639a53e0cSJaegeuk Kim return true; 131739a53e0cSJaegeuk Kim } 131839a53e0cSJaegeuk Kim 1319da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 132039a53e0cSJaegeuk Kim struct inode *inode, 132139a53e0cSJaegeuk Kim blkcnt_t count) 132239a53e0cSJaegeuk Kim { 132339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13249850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 13259850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 132639a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 132739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 13282555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, count, false); 132939a53e0cSJaegeuk Kim } 133039a53e0cSJaegeuk Kim 133139a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 133239a53e0cSJaegeuk Kim { 133335782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 13347c4abcbeSChao Yu 133536951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 133636951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 13377c4abcbeSChao Yu return; 13387c4abcbeSChao Yu 1339caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 134039a53e0cSJaegeuk Kim } 134139a53e0cSJaegeuk Kim 1342a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 134339a53e0cSJaegeuk Kim { 1344204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1345c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1346c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 134739a53e0cSJaegeuk Kim } 134839a53e0cSJaegeuk Kim 134939a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 135039a53e0cSJaegeuk Kim { 135135782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 135239a53e0cSJaegeuk Kim } 135339a53e0cSJaegeuk Kim 1354a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 135539a53e0cSJaegeuk Kim { 13565ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 13575ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 13581fe54f9dSJaegeuk Kim return; 13591fe54f9dSJaegeuk Kim 1360204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1361c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1362c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 136339a53e0cSJaegeuk Kim } 136439a53e0cSJaegeuk Kim 1365523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 136639a53e0cSJaegeuk Kim { 136735782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 136839a53e0cSJaegeuk Kim } 136939a53e0cSJaegeuk Kim 1370204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1371f8b2c1f9SJaegeuk Kim { 1372204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1373f8b2c1f9SJaegeuk Kim } 1374f8b2c1f9SJaegeuk Kim 13755ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 13765ac206cfSNamjae Jeon { 13773519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1378523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1379523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1380523be8a6SJaegeuk Kim 1381523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 13825ac206cfSNamjae Jeon } 13835ac206cfSNamjae Jeon 138439a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 138539a53e0cSJaegeuk Kim { 13868b8343faSJaegeuk Kim return sbi->total_valid_block_count; 138739a53e0cSJaegeuk Kim } 138839a53e0cSJaegeuk Kim 1389f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1390f83a2584SYunlei He { 1391f83a2584SYunlei He return sbi->discard_blks; 1392f83a2584SYunlei He } 1393f83a2584SYunlei He 139439a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 139539a53e0cSJaegeuk Kim { 139639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 139739a53e0cSJaegeuk Kim 139839a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 139939a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 140039a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 140139a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 140239a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 140339a53e0cSJaegeuk Kim 140439a53e0cSJaegeuk Kim return 0; 140539a53e0cSJaegeuk Kim } 140639a53e0cSJaegeuk Kim 140755141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 140855141486SWanpeng Li { 140955141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 141055141486SWanpeng Li } 141155141486SWanpeng Li 141239a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 141339a53e0cSJaegeuk Kim { 141439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 14151dbe4152SChangman Lee int offset; 14161dbe4152SChangman Lee 141755141486SWanpeng Li if (__cp_payload(sbi) > 0) { 14181dbe4152SChangman Lee if (flag == NAT_BITMAP) 14191dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 14201dbe4152SChangman Lee else 142165b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 14221dbe4152SChangman Lee } else { 14231dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 142425ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 142539a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 142639a53e0cSJaegeuk Kim } 14271dbe4152SChangman Lee } 142839a53e0cSJaegeuk Kim 142939a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 143039a53e0cSJaegeuk Kim { 14318508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 143239a53e0cSJaegeuk Kim 14338508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 143439a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 143539a53e0cSJaegeuk Kim return start_addr; 143639a53e0cSJaegeuk Kim } 143739a53e0cSJaegeuk Kim 14388508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 14398508e44aSJaegeuk Kim { 14408508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 14418508e44aSJaegeuk Kim 14428508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 14438508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 14448508e44aSJaegeuk Kim return start_addr; 14458508e44aSJaegeuk Kim } 14468508e44aSJaegeuk Kim 14478508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 14488508e44aSJaegeuk Kim { 14498508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 14508508e44aSJaegeuk Kim } 14518508e44aSJaegeuk Kim 145239a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 145339a53e0cSJaegeuk Kim { 145439a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 145539a53e0cSJaegeuk Kim } 145639a53e0cSJaegeuk Kim 145739a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1458ef86d709SGu Zheng struct inode *inode) 145939a53e0cSJaegeuk Kim { 146039a53e0cSJaegeuk Kim block_t valid_block_count; 146139a53e0cSJaegeuk Kim unsigned int valid_node_count; 146239a53e0cSJaegeuk Kim 146339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 146439a53e0cSJaegeuk Kim 1465ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1466cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 146739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 146839a53e0cSJaegeuk Kim return false; 146939a53e0cSJaegeuk Kim } 147039a53e0cSJaegeuk Kim 1471ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1472cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 147339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 147439a53e0cSJaegeuk Kim return false; 147539a53e0cSJaegeuk Kim } 147639a53e0cSJaegeuk Kim 147739a53e0cSJaegeuk Kim if (inode) 14788edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, true); 1479ef86d709SGu Zheng 1480ef86d709SGu Zheng sbi->total_valid_node_count++; 1481ef86d709SGu Zheng sbi->total_valid_block_count++; 148239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 148339a53e0cSJaegeuk Kim 148441382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 148539a53e0cSJaegeuk Kim return true; 148639a53e0cSJaegeuk Kim } 148739a53e0cSJaegeuk Kim 148839a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1489ef86d709SGu Zheng struct inode *inode) 149039a53e0cSJaegeuk Kim { 149139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 149239a53e0cSJaegeuk Kim 14939850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 14949850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 14959850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 149639a53e0cSJaegeuk Kim 14978edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, false); 1498ef86d709SGu Zheng sbi->total_valid_node_count--; 1499ef86d709SGu Zheng sbi->total_valid_block_count--; 150039a53e0cSJaegeuk Kim 150139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 150239a53e0cSJaegeuk Kim } 150339a53e0cSJaegeuk Kim 150439a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 150539a53e0cSJaegeuk Kim { 15068b8343faSJaegeuk Kim return sbi->total_valid_node_count; 150739a53e0cSJaegeuk Kim } 150839a53e0cSJaegeuk Kim 150939a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 151039a53e0cSJaegeuk Kim { 1511513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 151239a53e0cSJaegeuk Kim } 151339a53e0cSJaegeuk Kim 15140e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 151539a53e0cSJaegeuk Kim { 1516513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 151739a53e0cSJaegeuk Kim } 151839a53e0cSJaegeuk Kim 1519513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 152039a53e0cSJaegeuk Kim { 1521513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 152239a53e0cSJaegeuk Kim } 152339a53e0cSJaegeuk Kim 1524a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1525a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1526a56c7c6fSJaegeuk Kim { 1527c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1528c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1529cac5a3d8SDongOh Shin 1530c41f3cc3SJaegeuk Kim if (page) 1531c41f3cc3SJaegeuk Kim return page; 1532c41f3cc3SJaegeuk Kim 153355523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 153455523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1535c41f3cc3SJaegeuk Kim return NULL; 153655523519SChao Yu } 1537c41f3cc3SJaegeuk Kim #endif 1538a56c7c6fSJaegeuk Kim if (!for_write) 1539a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1540a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1541a56c7c6fSJaegeuk Kim } 1542a56c7c6fSJaegeuk Kim 15436e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 15446e2c64adSJaegeuk Kim { 15456e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 15466e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 15476e2c64adSJaegeuk Kim 15486e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 15496e2c64adSJaegeuk Kim kunmap(dst); 15506e2c64adSJaegeuk Kim kunmap(src); 15516e2c64adSJaegeuk Kim } 15526e2c64adSJaegeuk Kim 155339a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 155439a53e0cSJaegeuk Kim { 1555031fa8ccSJaegeuk Kim if (!page) 155639a53e0cSJaegeuk Kim return; 155739a53e0cSJaegeuk Kim 155839a53e0cSJaegeuk Kim if (unlock) { 15599850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 156039a53e0cSJaegeuk Kim unlock_page(page); 156139a53e0cSJaegeuk Kim } 156209cbfeafSKirill A. Shutemov put_page(page); 156339a53e0cSJaegeuk Kim } 156439a53e0cSJaegeuk Kim 156539a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 156639a53e0cSJaegeuk Kim { 156739a53e0cSJaegeuk Kim if (dn->node_page) 156839a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 156939a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 157039a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 157139a53e0cSJaegeuk Kim dn->node_page = NULL; 157239a53e0cSJaegeuk Kim dn->inode_page = NULL; 157339a53e0cSJaegeuk Kim } 157439a53e0cSJaegeuk Kim 157539a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1576e8512d2eSGu Zheng size_t size) 157739a53e0cSJaegeuk Kim { 1578e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 157939a53e0cSJaegeuk Kim } 158039a53e0cSJaegeuk Kim 15817bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 15827bd59381SGu Zheng gfp_t flags) 15837bd59381SGu Zheng { 15847bd59381SGu Zheng void *entry; 15857bd59381SGu Zheng 158680c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 158780c54505SJaegeuk Kim if (!entry) 158880c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 15897bd59381SGu Zheng return entry; 15907bd59381SGu Zheng } 15917bd59381SGu Zheng 1592740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1593740432f8SJaegeuk Kim { 1594740432f8SJaegeuk Kim struct bio *bio; 1595740432f8SJaegeuk Kim 1596740432f8SJaegeuk Kim /* No failure on bio allocation */ 1597740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 159880c54505SJaegeuk Kim if (!bio) 159980c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1600740432f8SJaegeuk Kim return bio; 1601740432f8SJaegeuk Kim } 1602740432f8SJaegeuk Kim 16039be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 16049be32d72SJaegeuk Kim unsigned long index, void *item) 16059be32d72SJaegeuk Kim { 16069be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 16079be32d72SJaegeuk Kim cond_resched(); 16089be32d72SJaegeuk Kim } 16099be32d72SJaegeuk Kim 161039a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 161139a53e0cSJaegeuk Kim 161239a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 161339a53e0cSJaegeuk Kim { 161445590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1615cac5a3d8SDongOh Shin 161639a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 161739a53e0cSJaegeuk Kim } 161839a53e0cSJaegeuk Kim 161939a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 162039a53e0cSJaegeuk Kim { 162139a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 162239a53e0cSJaegeuk Kim } 162339a53e0cSJaegeuk Kim 162439a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 162539a53e0cSJaegeuk Kim unsigned int offset) 162639a53e0cSJaegeuk Kim { 162739a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 162839a53e0cSJaegeuk Kim __le32 *addr_array; 1629cac5a3d8SDongOh Shin 163045590710SGu Zheng raw_node = F2FS_NODE(node_page); 163139a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 163239a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 163339a53e0cSJaegeuk Kim } 163439a53e0cSJaegeuk Kim 163539a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 163639a53e0cSJaegeuk Kim { 163739a53e0cSJaegeuk Kim int mask; 163839a53e0cSJaegeuk Kim 163939a53e0cSJaegeuk Kim addr += (nr >> 3); 164039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 164139a53e0cSJaegeuk Kim return mask & *addr; 164239a53e0cSJaegeuk Kim } 164339a53e0cSJaegeuk Kim 1644a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1645a66cdd98SJaegeuk Kim { 1646a66cdd98SJaegeuk Kim int mask; 1647a66cdd98SJaegeuk Kim 1648a66cdd98SJaegeuk Kim addr += (nr >> 3); 1649a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1650a66cdd98SJaegeuk Kim *addr |= mask; 1651a66cdd98SJaegeuk Kim } 1652a66cdd98SJaegeuk Kim 1653a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1654a66cdd98SJaegeuk Kim { 1655a66cdd98SJaegeuk Kim int mask; 1656a66cdd98SJaegeuk Kim 1657a66cdd98SJaegeuk Kim addr += (nr >> 3); 1658a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1659a66cdd98SJaegeuk Kim *addr &= ~mask; 1660a66cdd98SJaegeuk Kim } 1661a66cdd98SJaegeuk Kim 166252aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 166339a53e0cSJaegeuk Kim { 166439a53e0cSJaegeuk Kim int mask; 166539a53e0cSJaegeuk Kim int ret; 166639a53e0cSJaegeuk Kim 166739a53e0cSJaegeuk Kim addr += (nr >> 3); 166839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 166939a53e0cSJaegeuk Kim ret = mask & *addr; 167039a53e0cSJaegeuk Kim *addr |= mask; 167139a53e0cSJaegeuk Kim return ret; 167239a53e0cSJaegeuk Kim } 167339a53e0cSJaegeuk Kim 167452aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 167539a53e0cSJaegeuk Kim { 167639a53e0cSJaegeuk Kim int mask; 167739a53e0cSJaegeuk Kim int ret; 167839a53e0cSJaegeuk Kim 167939a53e0cSJaegeuk Kim addr += (nr >> 3); 168039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 168139a53e0cSJaegeuk Kim ret = mask & *addr; 168239a53e0cSJaegeuk Kim *addr &= ~mask; 168339a53e0cSJaegeuk Kim return ret; 168439a53e0cSJaegeuk Kim } 168539a53e0cSJaegeuk Kim 1686c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1687c6ac4c0eSGu Zheng { 1688c6ac4c0eSGu Zheng int mask; 1689c6ac4c0eSGu Zheng 1690c6ac4c0eSGu Zheng addr += (nr >> 3); 1691c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1692c6ac4c0eSGu Zheng *addr ^= mask; 1693c6ac4c0eSGu Zheng } 1694c6ac4c0eSGu Zheng 169539a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 169639a53e0cSJaegeuk Kim enum { 169739a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1698b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 169926de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1700ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 170139a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 170239a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 170339a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1704c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1705c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1706444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 17071001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 170834d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1709fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1710fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 171188b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 171288b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 17135fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 171402a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 17153c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 17161e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1717b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1718510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1719d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1720c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 1721dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 1722ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 172339a53e0cSJaegeuk Kim }; 172439a53e0cSJaegeuk Kim 1725205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 1726205b9822SJaegeuk Kim int flag, bool set) 172739a53e0cSJaegeuk Kim { 1728205b9822SJaegeuk Kim switch (flag) { 1729205b9822SJaegeuk Kim case FI_INLINE_XATTR: 1730205b9822SJaegeuk Kim case FI_INLINE_DATA: 1731205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 1732205b9822SJaegeuk Kim if (set) 1733205b9822SJaegeuk Kim return; 1734205b9822SJaegeuk Kim case FI_DATA_EXIST: 1735205b9822SJaegeuk Kim case FI_INLINE_DOTS: 17367c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1737205b9822SJaegeuk Kim } 173839a53e0cSJaegeuk Kim } 173939a53e0cSJaegeuk Kim 174091942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 174139a53e0cSJaegeuk Kim { 174291942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 174391942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 1744205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 174539a53e0cSJaegeuk Kim } 174639a53e0cSJaegeuk Kim 174791942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 174839a53e0cSJaegeuk Kim { 174991942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 175039a53e0cSJaegeuk Kim } 175139a53e0cSJaegeuk Kim 175291942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 175339a53e0cSJaegeuk Kim { 175491942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 175591942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 1756205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 175739a53e0cSJaegeuk Kim } 175839a53e0cSJaegeuk Kim 175991942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 1760444c580fSJaegeuk Kim { 176191942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 176291942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 17637c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 176439a53e0cSJaegeuk Kim } 176539a53e0cSJaegeuk Kim 1766a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 1767a1961246SJaegeuk Kim { 1768a1961246SJaegeuk Kim if (inc) 1769a1961246SJaegeuk Kim inc_nlink(inode); 1770a1961246SJaegeuk Kim else 1771a1961246SJaegeuk Kim drop_nlink(inode); 17727c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1773a1961246SJaegeuk Kim } 1774a1961246SJaegeuk Kim 17758edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 17768edd03c8SJaegeuk Kim blkcnt_t diff, bool add) 17778edd03c8SJaegeuk Kim { 177826de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 177926de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 178026de9b11SJaegeuk Kim 17818edd03c8SJaegeuk Kim inode->i_blocks = add ? inode->i_blocks + diff : 17828edd03c8SJaegeuk Kim inode->i_blocks - diff; 17837c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 178426de9b11SJaegeuk Kim if (clean || recover) 178526de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 17868edd03c8SJaegeuk Kim } 17878edd03c8SJaegeuk Kim 1788fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 1789fc9581c8SJaegeuk Kim { 179026de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 179126de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 179226de9b11SJaegeuk Kim 1793fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 1794fc9581c8SJaegeuk Kim return; 1795fc9581c8SJaegeuk Kim 1796fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 17977c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 179826de9b11SJaegeuk Kim if (clean || recover) 179926de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 180026de9b11SJaegeuk Kim } 180126de9b11SJaegeuk Kim 1802205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 1803205b9822SJaegeuk Kim { 1804205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 18057c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1806205b9822SJaegeuk Kim } 1807205b9822SJaegeuk Kim 1808205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 1809205b9822SJaegeuk Kim { 1810205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 18117c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1812205b9822SJaegeuk Kim } 1813205b9822SJaegeuk Kim 1814205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 1815205b9822SJaegeuk Kim { 1816205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 18177c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1818205b9822SJaegeuk Kim } 1819205b9822SJaegeuk Kim 182091942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 1821444c580fSJaegeuk Kim { 1822205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 1823205b9822SJaegeuk Kim 1824444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1825205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 18261001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 1827205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 182834d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1829205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 1830b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1831205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 1832510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1833205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 1834444c580fSJaegeuk Kim } 1835444c580fSJaegeuk Kim 183691942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 1837444c580fSJaegeuk Kim { 1838444c580fSJaegeuk Kim ri->i_inline = 0; 1839444c580fSJaegeuk Kim 184091942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 1841444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 184291942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 18431001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 184491942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 184534d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 184691942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 1847b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 184891942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 1849510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1850444c580fSJaegeuk Kim } 1851444c580fSJaegeuk Kim 1852987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1853987c7c31SChao Yu { 185491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 1855987c7c31SChao Yu } 1856987c7c31SChao Yu 185781ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1858de93653fSJaegeuk Kim { 185981ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1860de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1861de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1862de93653fSJaegeuk Kim } 1863de93653fSJaegeuk Kim 186465985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 186565985d93SJaegeuk Kim { 1866695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1867cac5a3d8SDongOh Shin 186865985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 186965985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 187065985d93SJaegeuk Kim } 187165985d93SJaegeuk Kim 187265985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 187365985d93SJaegeuk Kim { 1874987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 187565985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 187665985d93SJaegeuk Kim else 187765985d93SJaegeuk Kim return 0; 187865985d93SJaegeuk Kim } 187965985d93SJaegeuk Kim 18800dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 18810dbdc2aeSJaegeuk Kim { 188291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 18830dbdc2aeSJaegeuk Kim } 18840dbdc2aeSJaegeuk Kim 1885b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1886b3d208f9SJaegeuk Kim { 188791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 1888b3d208f9SJaegeuk Kim } 1889b3d208f9SJaegeuk Kim 1890510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1891510022a8SJaegeuk Kim { 189291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 1893510022a8SJaegeuk Kim } 1894510022a8SJaegeuk Kim 189588b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 189688b88a66SJaegeuk Kim { 189791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 189888b88a66SJaegeuk Kim } 189988b88a66SJaegeuk Kim 19005fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 19015fe45743SChao Yu { 19025fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 19035fe45743SChao Yu } 19045fe45743SChao Yu 190502a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 190602a1335fSJaegeuk Kim { 190791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 190802a1335fSJaegeuk Kim } 190902a1335fSJaegeuk Kim 19103c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 19113c6c2bebSJaegeuk Kim { 191291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 19133c6c2bebSJaegeuk Kim } 19143c6c2bebSJaegeuk Kim 19151e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 19161e84371fSJaegeuk Kim { 191791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 19181e84371fSJaegeuk Kim } 19191e84371fSJaegeuk Kim 19201001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 19211001b347SHuajun Li { 1922695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1923cac5a3d8SDongOh Shin 19241001b347SHuajun Li return (void *)&(ri->i_addr[1]); 19251001b347SHuajun Li } 19261001b347SHuajun Li 192734d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 192834d67debSChao Yu { 192991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 193034d67debSChao Yu } 193134d67debSChao Yu 19329486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 19339486ba44SJaegeuk Kim { 19349486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 19359486ba44SJaegeuk Kim kunmap(page); 19369486ba44SJaegeuk Kim } 19379486ba44SJaegeuk Kim 1938b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1939b5492af7SJaegeuk Kim { 1940b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1941b5492af7SJaegeuk Kim } 1942b5492af7SJaegeuk Kim 1943b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1944b5492af7SJaegeuk Kim { 1945b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 19467c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1947b5492af7SJaegeuk Kim } 1948b5492af7SJaegeuk Kim 1949b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1950b5492af7SJaegeuk Kim { 1951b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 19527c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1953b5492af7SJaegeuk Kim } 1954b5492af7SJaegeuk Kim 195526787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 195626787236SJaegeuk Kim { 195726787236SJaegeuk Kim if (dsync) { 195826787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 195926787236SJaegeuk Kim bool ret; 196026787236SJaegeuk Kim 196126787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 196226787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 196326787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 196426787236SJaegeuk Kim return ret; 196526787236SJaegeuk Kim } 196626787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 196726787236SJaegeuk Kim file_keep_isize(inode) || 196826787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 196926787236SJaegeuk Kim return false; 197026787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 1971267378d4SChao Yu } 1972267378d4SChao Yu 1973267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 1974267378d4SChao Yu { 1975267378d4SChao Yu return sb->s_flags & MS_RDONLY; 1976267378d4SChao Yu } 197739a53e0cSJaegeuk Kim 197839a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 197939a53e0cSJaegeuk Kim { 1980aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 198139a53e0cSJaegeuk Kim } 198239a53e0cSJaegeuk Kim 1983eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1984eaa693f4SJaegeuk Kim { 1985eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1986eaa693f4SJaegeuk Kim return true; 1987eaa693f4SJaegeuk Kim 1988eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1989eaa693f4SJaegeuk Kim return true; 1990eaa693f4SJaegeuk Kim 1991eaa693f4SJaegeuk Kim return false; 1992eaa693f4SJaegeuk Kim } 1993eaa693f4SJaegeuk Kim 19943e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 19953e72f721SJaegeuk Kim { 19963e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 199791942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 19983e72f721SJaegeuk Kim return false; 19993e72f721SJaegeuk Kim 2000886f56f9SAl Viro return S_ISREG(inode->i_mode); 20013e72f721SJaegeuk Kim } 20023e72f721SJaegeuk Kim 20031ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 20041ecc0c5cSChao Yu size_t size, gfp_t flags) 20050414b004SJaegeuk Kim { 20062c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 200755523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 200855523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 20092c63feadSJaegeuk Kim return NULL; 201055523519SChao Yu } 20112c63feadSJaegeuk Kim #endif 20120414b004SJaegeuk Kim return kmalloc(size, flags); 20130414b004SJaegeuk Kim } 20140414b004SJaegeuk Kim 201539307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 201639307a8eSJaegeuk Kim { 201739307a8eSJaegeuk Kim void *ret; 201839307a8eSJaegeuk Kim 201939307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 202039307a8eSJaegeuk Kim if (!ret) 202139307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 202239307a8eSJaegeuk Kim return ret; 202339307a8eSJaegeuk Kim } 202439307a8eSJaegeuk Kim 202539307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 202639307a8eSJaegeuk Kim { 202739307a8eSJaegeuk Kim void *ret; 202839307a8eSJaegeuk Kim 202939307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 203039307a8eSJaegeuk Kim if (!ret) 203139307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 203239307a8eSJaegeuk Kim return ret; 203339307a8eSJaegeuk Kim } 203439307a8eSJaegeuk Kim 203539a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 203691942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 203739a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 203839a53e0cSJaegeuk Kim 203939a53e0cSJaegeuk Kim /* 20401e1bb4baSJaegeuk Kim * file.c 204139a53e0cSJaegeuk Kim */ 2042cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2043cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2044cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2045cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2046a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2047a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2048cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2049cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2050cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2051cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2052cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 205339a53e0cSJaegeuk Kim 205439a53e0cSJaegeuk Kim /* 205539a53e0cSJaegeuk Kim * inode.c 205639a53e0cSJaegeuk Kim */ 2057cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2058cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2059cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2060cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2061cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2062cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2063cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2064cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2065cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 206639a53e0cSJaegeuk Kim 206739a53e0cSJaegeuk Kim /* 206839a53e0cSJaegeuk Kim * namei.c 206939a53e0cSJaegeuk Kim */ 207039a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 207139a53e0cSJaegeuk Kim 207239a53e0cSJaegeuk Kim /* 207339a53e0cSJaegeuk Kim * dir.c 207439a53e0cSJaegeuk Kim */ 2075cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2076cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2077cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2078cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2079cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2080cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2081cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2082cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2083cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2084cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2085cac5a3d8SDongOh Shin const struct qstr *new_name, 2086cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2087cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2088cac5a3d8SDongOh Shin unsigned int current_depth); 2089cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2090cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2091cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2092cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2093cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2094cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2095cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2096cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2097cac5a3d8SDongOh Shin struct page **page); 2098cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2099cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2100cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2101cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2102cac5a3d8SDongOh Shin unsigned int bit_pos); 2103cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2104cac5a3d8SDongOh Shin const struct qstr *orig_name, 2105cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2106cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2107cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2108cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2109cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2110cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2111cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2112cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2113cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 211439a53e0cSJaegeuk Kim 2115b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2116b7f7a5e0SAl Viro { 21172b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2118510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2119b7f7a5e0SAl Viro } 2120b7f7a5e0SAl Viro 212139a53e0cSJaegeuk Kim /* 212239a53e0cSJaegeuk Kim * super.c 212339a53e0cSJaegeuk Kim */ 2124cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2125cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2126cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2127cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2128a07ef784SNamjae Jeon extern __printf(3, 4) 2129cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2130984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 213139a53e0cSJaegeuk Kim 213239a53e0cSJaegeuk Kim /* 213339a53e0cSJaegeuk Kim * hash.c 213439a53e0cSJaegeuk Kim */ 2135cac5a3d8SDongOh Shin f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info); 213639a53e0cSJaegeuk Kim 213739a53e0cSJaegeuk Kim /* 213839a53e0cSJaegeuk Kim * node.c 213939a53e0cSJaegeuk Kim */ 214039a53e0cSJaegeuk Kim struct dnode_of_data; 214139a53e0cSJaegeuk Kim struct node_info; 214239a53e0cSJaegeuk Kim 2143cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2144cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2145cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2146cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2147cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2148cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2149cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2150cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2151cac5a3d8SDongOh Shin int truncate_xattr_node(struct inode *inode, struct page *page); 2152cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2153cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2154cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 2155cac5a3d8SDongOh Shin struct page *new_node_page(struct dnode_of_data *dn, 2156cac5a3d8SDongOh Shin unsigned int ofs, struct page *ipage); 2157cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2158cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2159cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2160cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2161cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2162cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2163cac5a3d8SDongOh Shin int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc); 216422ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2165cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2166cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2167cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2168cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2169cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2170d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2171cac5a3d8SDongOh Shin block_t blkaddr); 2172cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2173cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2174cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 217522ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2176cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2177cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 21786e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 217939a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 218039a53e0cSJaegeuk Kim 218139a53e0cSJaegeuk Kim /* 218239a53e0cSJaegeuk Kim * segment.c 218339a53e0cSJaegeuk Kim */ 2184cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 2185cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 21868c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2187cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2188cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2189cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2190cac5a3d8SDongOh Shin int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2191cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2192cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2193cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2194cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2195cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2196*d431413fSChao Yu void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2197cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2198cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2199cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2200cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2201cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2202cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2203cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2204cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2205cac5a3d8SDongOh Shin void write_meta_page(struct f2fs_sb_info *sbi, struct page *page); 2206cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2207cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2208d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2209cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2210cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2211cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2212cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2213cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2214cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2215cac5a3d8SDongOh Shin bool recover_newaddr); 2216cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2217cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2218cac5a3d8SDongOh Shin struct f2fs_summary *sum, int type); 2219cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2220cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2221cac5a3d8SDongOh Shin void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2222cac5a3d8SDongOh Shin block_t blkaddr); 2223cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2224cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2225cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2226cac5a3d8SDongOh Shin unsigned int val, int alloc); 2227cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2228cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2229cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 22307fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 22317fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 223239a53e0cSJaegeuk Kim 223339a53e0cSJaegeuk Kim /* 223439a53e0cSJaegeuk Kim * checkpoint.c 223539a53e0cSJaegeuk Kim */ 2236cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2237cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2238cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2239cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2240cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2241cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2242cac5a3d8SDongOh Shin int type, bool sync); 2243cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2244cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2245cac5a3d8SDongOh Shin long nr_to_write); 2246cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2247cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2248cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2249cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2250cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2251cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2252cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2253cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2254cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2255cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2256cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2257cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2258cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2259cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2260cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2261cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 22626e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 226339a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 226439a53e0cSJaegeuk Kim 226539a53e0cSJaegeuk Kim /* 226639a53e0cSJaegeuk Kim * data.c 226739a53e0cSJaegeuk Kim */ 2268cac5a3d8SDongOh Shin void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 2269cac5a3d8SDongOh Shin int rw); 2270cac5a3d8SDongOh Shin void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, 2271942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2272942fd319SJaegeuk Kim enum page_type type, int rw); 2273cac5a3d8SDongOh Shin void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi); 2274cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2275cac5a3d8SDongOh Shin int f2fs_submit_page_mbio(struct f2fs_io_info *fio); 2276cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2277cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2278cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2279cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2280cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2281cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2282cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2283cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2284cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2285cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2286cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2287cac5a3d8SDongOh Shin int op_flags, bool for_write); 2288cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2289cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2290cac5a3d8SDongOh Shin bool for_write); 2291cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2292cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2293cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2294cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2295cac5a3d8SDongOh Shin int create, int flag); 2296cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2297cac5a3d8SDongOh Shin u64 start, u64 len); 2298cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2299cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2300cac5a3d8SDongOh Shin unsigned int length); 2301cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 23025b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2303cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2304cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 23055b7a487cSWeichao Guo #endif 230639a53e0cSJaegeuk Kim 230739a53e0cSJaegeuk Kim /* 230839a53e0cSJaegeuk Kim * gc.c 230939a53e0cSJaegeuk Kim */ 2310cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2311cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2312cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2313cac5a3d8SDongOh Shin int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background); 2314cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 231539a53e0cSJaegeuk Kim 231639a53e0cSJaegeuk Kim /* 231739a53e0cSJaegeuk Kim * recovery.c 231839a53e0cSJaegeuk Kim */ 2319cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2320cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 232139a53e0cSJaegeuk Kim 232239a53e0cSJaegeuk Kim /* 232339a53e0cSJaegeuk Kim * debug.c 232439a53e0cSJaegeuk Kim */ 232539a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 232639a53e0cSJaegeuk Kim struct f2fs_stat_info { 232739a53e0cSJaegeuk Kim struct list_head stat_list; 232839a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 232939a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 233039a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 23315b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 23325b7ee374SChao Yu unsigned long long hit_total, total_ext; 2333c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 233435782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 233535782b23SJaegeuk Kim int inmem_pages; 23360f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 2337b8559dc2SChao Yu int nats, dirty_nats, sits, dirty_sits, free_nids, alloc_nids; 233839a53e0cSJaegeuk Kim int total_count, utilization; 23398b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 23408b8dd65fSChao Yu int nr_flushing, nr_flushed, nr_discarding, nr_discarded; 23415f32366aSChao Yu int nr_discard_cmd; 2342a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2343648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2344f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 234539a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 234639a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 234739a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 234839a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 234942190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 235039a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2351e1235983SChangman Lee int bg_node_segs, bg_data_segs; 235239a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2353e1235983SChangman Lee int bg_data_blks, bg_node_blks; 235439a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 235539a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 235639a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 235739a53e0cSJaegeuk Kim 235839a53e0cSJaegeuk Kim unsigned int segment_count[2]; 235939a53e0cSJaegeuk Kim unsigned int block_count[2]; 2360b9a2c252SChangman Lee unsigned int inplace_count; 23619edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 236239a53e0cSJaegeuk Kim }; 236339a53e0cSJaegeuk Kim 2364963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2365963d4f7dSGu Zheng { 2366963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2367963d4f7dSGu Zheng } 2368963d4f7dSGu Zheng 2369942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 237042190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 237139a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2372dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 237333fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 237433fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 23755b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 23765b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 23775b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 23785b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2379d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2380d5e8f6c9SChao Yu do { \ 2381d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2382d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2383d5e8f6c9SChao Yu } while (0) 2384d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2385d5e8f6c9SChao Yu do { \ 2386d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2387d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2388d5e8f6c9SChao Yu } while (0) 23890dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 23900dbdc2aeSJaegeuk Kim do { \ 23910dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 239203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 23930dbdc2aeSJaegeuk Kim } while (0) 23940dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 23950dbdc2aeSJaegeuk Kim do { \ 23960dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 239703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 23980dbdc2aeSJaegeuk Kim } while (0) 23993289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 24003289c061SJaegeuk Kim do { \ 24013289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 240203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 24033289c061SJaegeuk Kim } while (0) 24043289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 24053289c061SJaegeuk Kim do { \ 24063289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 240703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 24083289c061SJaegeuk Kim } while (0) 2409dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2410dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2411dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2412dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2413b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2414b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 241526a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2416cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 241726a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2418cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 241926a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 242026a28a0cSJaegeuk Kim do { \ 242126a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 242226a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 242326a28a0cSJaegeuk Kim if (cur > max) \ 242426a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 242526a28a0cSJaegeuk Kim } while (0) 2426648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2427648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2428648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2429648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2430648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2431648d50baSChao Yu do { \ 2432648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2433648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2434648d50baSChao Yu if (cur > max) \ 2435648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2436648d50baSChao Yu } while (0) 2437e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 243839a53e0cSJaegeuk Kim do { \ 2439963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 244039a53e0cSJaegeuk Kim (si)->tot_segs++; \ 2441e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 244239a53e0cSJaegeuk Kim si->data_segs++; \ 2443e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2444e1235983SChangman Lee } else { \ 244539a53e0cSJaegeuk Kim si->node_segs++; \ 2446e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2447e1235983SChangman Lee } \ 244839a53e0cSJaegeuk Kim } while (0) 244939a53e0cSJaegeuk Kim 245039a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 245139a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 245239a53e0cSJaegeuk Kim 2453e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 245439a53e0cSJaegeuk Kim do { \ 2455963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 245639a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 245739a53e0cSJaegeuk Kim si->data_blks += (blks); \ 2458e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 245939a53e0cSJaegeuk Kim } while (0) 246039a53e0cSJaegeuk Kim 2461e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 246239a53e0cSJaegeuk Kim do { \ 2463963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 246439a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 246539a53e0cSJaegeuk Kim si->node_blks += (blks); \ 2466e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 246739a53e0cSJaegeuk Kim } while (0) 246839a53e0cSJaegeuk Kim 2469cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2470cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2471787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 24724589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 247339a53e0cSJaegeuk Kim #else 2474942e0be6SChangman Lee #define stat_inc_cp_count(si) 247542190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) 247639a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 2477dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 247833fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) 247933fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) 2480dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 2481029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 248291c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 248391c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 2484d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 2485d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 24860dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 24870dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 24883289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 24893289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 249026a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) 249126a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) 249226a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) 2493648d50baSChao Yu #define stat_inc_volatile_write(inode) 2494648d50baSChao Yu #define stat_dec_volatile_write(inode) 2495648d50baSChao Yu #define stat_update_max_volatile_write(inode) 2496dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 2497dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 2498b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 2499e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 250039a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 2501e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 2502e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 250339a53e0cSJaegeuk Kim 250439a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 250539a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2506787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 25074589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 250839a53e0cSJaegeuk Kim #endif 250939a53e0cSJaegeuk Kim 251039a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 251139a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 251239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 251339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 251439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 251539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 251639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 251739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2518cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 251939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 252029e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 25211001b347SHuajun Li 2522e18c65b2SHuajun Li /* 2523e18c65b2SHuajun Li * inline.c 2524e18c65b2SHuajun Li */ 2525cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2526cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2527cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2528bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2529cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2530cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2531cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2532cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2533cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2534cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2535cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2536cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2537cac5a3d8SDongOh Shin struct page *ipage); 2538cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2539cac5a3d8SDongOh Shin const struct qstr *orig_name, 2540cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2541cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2542cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2543cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2544cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2545cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2546cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2547cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2548cac5a3d8SDongOh Shin __u64 start, __u64 len); 2549cde4de12SJaegeuk Kim 2550cde4de12SJaegeuk Kim /* 25512658e50dSJaegeuk Kim * shrinker.c 25522658e50dSJaegeuk Kim */ 2553cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2554cac5a3d8SDongOh Shin struct shrink_control *sc); 2555cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2556cac5a3d8SDongOh Shin struct shrink_control *sc); 2557cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2558cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 25592658e50dSJaegeuk Kim 25602658e50dSJaegeuk Kim /* 2561a28ef1f5SChao Yu * extent_cache.c 2562a28ef1f5SChao Yu */ 2563cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2564cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2565cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2566cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2567cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2568cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2569cac5a3d8SDongOh Shin struct extent_info *ei); 2570cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 257119b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2572cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2573cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2574a28ef1f5SChao Yu int __init create_extent_cache(void); 2575a28ef1f5SChao Yu void destroy_extent_cache(void); 2576a28ef1f5SChao Yu 2577a28ef1f5SChao Yu /* 2578cde4de12SJaegeuk Kim * crypto support 2579cde4de12SJaegeuk Kim */ 25800b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2581cde4de12SJaegeuk Kim { 2582cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2583cde4de12SJaegeuk Kim } 2584cde4de12SJaegeuk Kim 2585cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2586cde4de12SJaegeuk Kim { 2587cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2588cde4de12SJaegeuk Kim file_set_encrypt(inode); 2589cde4de12SJaegeuk Kim #endif 2590cde4de12SJaegeuk Kim } 2591cde4de12SJaegeuk Kim 2592cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2593cde4de12SJaegeuk Kim { 25940b81d077SJaegeuk Kim return bio->bi_private != NULL; 2595cde4de12SJaegeuk Kim } 2596cde4de12SJaegeuk Kim 2597cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2598cde4de12SJaegeuk Kim { 2599cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2600cde4de12SJaegeuk Kim } 2601f424f664SJaegeuk Kim 26020bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 260352763a4bSJaegeuk Kim { 26040bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 260552763a4bSJaegeuk Kim } 260652763a4bSJaegeuk Kim 2607178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2608178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 26093c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2610178053e2SDamien Le Moal { 2611178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 26123c62be17SJaegeuk Kim int i; 2613178053e2SDamien Le Moal 26143c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 26153c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 26163c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 26173c62be17SJaegeuk Kim return -EINVAL; 2618178053e2SDamien Le Moal } 2619178053e2SDamien Le Moal #endif 2620178053e2SDamien Le Moal 262196ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 262296ba2decSDamien Le Moal { 262396ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 262496ba2decSDamien Le Moal 262596ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 262652763a4bSJaegeuk Kim } 262752763a4bSJaegeuk Kim 262852763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 262952763a4bSJaegeuk Kim { 263052763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 263152763a4bSJaegeuk Kim clear_opt(sbi, LFS); 263252763a4bSJaegeuk Kim 263352763a4bSJaegeuk Kim switch (mt) { 263452763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 263552763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 263652763a4bSJaegeuk Kim break; 263752763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 263852763a4bSJaegeuk Kim set_opt(sbi, LFS); 263952763a4bSJaegeuk Kim break; 264052763a4bSJaegeuk Kim } 264152763a4bSJaegeuk Kim } 264252763a4bSJaegeuk Kim 2643fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2644fcc85a4dSJaegeuk Kim { 2645fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2646886f56f9SAl Viro umode_t mode = inode->i_mode; 2647fcc85a4dSJaegeuk Kim 2648fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2649fcc85a4dSJaegeuk Kim #else 2650fcc85a4dSJaegeuk Kim return 0; 2651fcc85a4dSJaegeuk Kim #endif 2652fcc85a4dSJaegeuk Kim } 2653fcc85a4dSJaegeuk Kim 265439a53e0cSJaegeuk Kim #endif 2655