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, 538b038c70SChao Yu FAULT_IO, 540f348028SChao Yu FAULT_CHECKPOINT, 552c63feadSJaegeuk Kim FAULT_MAX, 562c63feadSJaegeuk Kim }; 572c63feadSJaegeuk Kim 5808796897SSheng Yong struct f2fs_fault_info { 5908796897SSheng Yong atomic_t inject_ops; 6008796897SSheng Yong unsigned int inject_rate; 6108796897SSheng Yong unsigned int inject_type; 6208796897SSheng Yong }; 6308796897SSheng Yong 642c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX]; 651ecc0c5cSChao Yu #define IS_FAULT_SET(fi, type) (fi->inject_type & (1 << (type))) 662c63feadSJaegeuk Kim #endif 672c63feadSJaegeuk Kim 6839a53e0cSJaegeuk Kim /* 6939a53e0cSJaegeuk Kim * For mount options 7039a53e0cSJaegeuk Kim */ 7139a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 7239a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7439a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 7539a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 78444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 791001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8034d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8134d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8234d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 83d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8489672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 856aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 86343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 8773faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 8836abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 8936abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 9039a53e0cSJaegeuk Kim 9139a53e0cSJaegeuk Kim #define clear_opt(sbi, option) (sbi->mount_opt.opt &= ~F2FS_MOUNT_##option) 9239a53e0cSJaegeuk Kim #define set_opt(sbi, option) (sbi->mount_opt.opt |= F2FS_MOUNT_##option) 9339a53e0cSJaegeuk Kim #define test_opt(sbi, option) (sbi->mount_opt.opt & F2FS_MOUNT_##option) 9439a53e0cSJaegeuk Kim 9539a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 9639a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 9739a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 9839a53e0cSJaegeuk Kim 99a9841c4dSJaegeuk Kim typedef u32 block_t; /* 100a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 101a9841c4dSJaegeuk Kim * address format, __le32. 102a9841c4dSJaegeuk Kim */ 10339a53e0cSJaegeuk Kim typedef u32 nid_t; 10439a53e0cSJaegeuk Kim 10539a53e0cSJaegeuk Kim struct f2fs_mount_info { 10639a53e0cSJaegeuk Kim unsigned int opt; 10739a53e0cSJaegeuk Kim }; 10839a53e0cSJaegeuk Kim 109cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1100bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 111cde4de12SJaegeuk Kim 11276f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 11376f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 11476f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 115c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 11676f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 117c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 11876f105a2SJaegeuk Kim 11939a53e0cSJaegeuk Kim /* 12039a53e0cSJaegeuk Kim * For checkpoint manager 12139a53e0cSJaegeuk Kim */ 12239a53e0cSJaegeuk Kim enum { 12339a53e0cSJaegeuk Kim NAT_BITMAP, 12439a53e0cSJaegeuk Kim SIT_BITMAP 12539a53e0cSJaegeuk Kim }; 12639a53e0cSJaegeuk Kim 12775ab4cb8SJaegeuk Kim enum { 12875ab4cb8SJaegeuk Kim CP_UMOUNT, 129119ee914SJaegeuk Kim CP_FASTBOOT, 13075ab4cb8SJaegeuk Kim CP_SYNC, 13110027551SJaegeuk Kim CP_RECOVERY, 1324b2fecc8SJaegeuk Kim CP_DISCARD, 13375ab4cb8SJaegeuk Kim }; 13475ab4cb8SJaegeuk Kim 13547b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 136bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 137bba681cbSJaegeuk Kim (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec) 138a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 139a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 140ad4d307fSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) \ 141ad4d307fSJaegeuk Kim ((1 << (sbi)->log_blocks_per_seg) * (sbi)->segs_per_sec) 14215469963SJaegeuk Kim #define DISCARD_ISSUE_RATE 8 14360b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 144dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 145bba681cbSJaegeuk Kim 14675ab4cb8SJaegeuk Kim struct cp_control { 14775ab4cb8SJaegeuk Kim int reason; 1484b2fecc8SJaegeuk Kim __u64 trim_start; 1494b2fecc8SJaegeuk Kim __u64 trim_end; 1504b2fecc8SJaegeuk Kim __u64 trim_minlen; 1514b2fecc8SJaegeuk Kim __u64 trimmed; 15275ab4cb8SJaegeuk Kim }; 15375ab4cb8SJaegeuk Kim 154662befdaSChao Yu /* 15581c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 156662befdaSChao Yu */ 157662befdaSChao Yu enum { 158662befdaSChao Yu META_CP, 159662befdaSChao Yu META_NAT, 16081c1a0f1SChao Yu META_SIT, 1614c521f49SJaegeuk Kim META_SSA, 1624c521f49SJaegeuk Kim META_POR, 163662befdaSChao Yu }; 164662befdaSChao Yu 1656451e041SJaegeuk Kim /* for the list of ino */ 1666451e041SJaegeuk Kim enum { 1676451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 168fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 169fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1706451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1716451e041SJaegeuk Kim }; 1726451e041SJaegeuk Kim 1736451e041SJaegeuk Kim struct ino_entry { 17439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17539a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 17639a53e0cSJaegeuk Kim }; 17739a53e0cSJaegeuk Kim 1782710fd7eSChao Yu /* for the list of inodes to be GCed */ 17906292073SChao Yu struct inode_entry { 18039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 18239a53e0cSJaegeuk Kim }; 18339a53e0cSJaegeuk Kim 1847fd9e544SJaegeuk Kim /* for the list of blockaddresses to be discarded */ 1857fd9e544SJaegeuk Kim struct discard_entry { 1867fd9e544SJaegeuk Kim struct list_head list; /* list head */ 1877fd9e544SJaegeuk Kim block_t blkaddr; /* block address to be discarded */ 1887fd9e544SJaegeuk Kim int len; /* # of consecutive blocks of the discard */ 1897fd9e544SJaegeuk Kim }; 1907fd9e544SJaegeuk Kim 19115469963SJaegeuk Kim enum { 19215469963SJaegeuk Kim D_PREP, 19315469963SJaegeuk Kim D_SUBMIT, 19415469963SJaegeuk Kim D_DONE, 19515469963SJaegeuk Kim }; 19615469963SJaegeuk Kim 197b01a9201SJaegeuk Kim struct discard_cmd { 198b01a9201SJaegeuk Kim struct list_head list; /* command list */ 199b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 200b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 201b01a9201SJaegeuk Kim block_t len; /* length */ 202b01a9201SJaegeuk Kim struct bio *bio; /* bio */ 20315469963SJaegeuk Kim int state; /* state */ 204275b66b0SChao Yu }; 205275b66b0SChao Yu 2060b54fb84SJaegeuk Kim struct discard_cmd_control { 20715469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 2080b54fb84SJaegeuk Kim struct list_head discard_entry_list; /* 4KB discard entry list */ 2090b54fb84SJaegeuk Kim int nr_discards; /* # of discards in the list */ 2100b54fb84SJaegeuk Kim struct list_head discard_cmd_list; /* discard cmd list */ 21115469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 21215469963SJaegeuk Kim struct mutex cmd_lock; 2130b54fb84SJaegeuk Kim int max_discards; /* max. discards to be issued */ 214dcc9165dSJaegeuk Kim atomic_t submit_discard; /* # of issued discard */ 21539a53e0cSJaegeuk Kim }; 21639a53e0cSJaegeuk Kim 21739a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 21839a53e0cSJaegeuk Kim struct fsync_inode_entry { 21939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 22039a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 221c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 222c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 22339a53e0cSJaegeuk Kim }; 22439a53e0cSJaegeuk Kim 225dfc08a12SChao Yu #define nats_in_cursum(jnl) (le16_to_cpu(jnl->n_nats)) 226dfc08a12SChao Yu #define sits_in_cursum(jnl) (le16_to_cpu(jnl->n_sits)) 22739a53e0cSJaegeuk Kim 228dfc08a12SChao Yu #define nat_in_journal(jnl, i) (jnl->nat_j.entries[i].ne) 229dfc08a12SChao Yu #define nid_in_journal(jnl, i) (jnl->nat_j.entries[i].nid) 230dfc08a12SChao Yu #define sit_in_journal(jnl, i) (jnl->sit_j.entries[i].se) 231dfc08a12SChao Yu #define segno_in_journal(jnl, i) (jnl->sit_j.entries[i].segno) 23239a53e0cSJaegeuk Kim 233dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 234dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 235309cc2b6SJaegeuk Kim 236dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 23739a53e0cSJaegeuk Kim { 238dfc08a12SChao Yu int before = nats_in_cursum(journal); 239cac5a3d8SDongOh Shin 240dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 24139a53e0cSJaegeuk Kim return before; 24239a53e0cSJaegeuk Kim } 24339a53e0cSJaegeuk Kim 244dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 24539a53e0cSJaegeuk Kim { 246dfc08a12SChao Yu int before = sits_in_cursum(journal); 247cac5a3d8SDongOh Shin 248dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 24939a53e0cSJaegeuk Kim return before; 25039a53e0cSJaegeuk Kim } 25139a53e0cSJaegeuk Kim 252dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 253dfc08a12SChao Yu int size, int type) 254184a5cd2SChao Yu { 255184a5cd2SChao Yu if (type == NAT_JOURNAL) 256dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 257dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 258184a5cd2SChao Yu } 259184a5cd2SChao Yu 26039a53e0cSJaegeuk Kim /* 261e9750824SNamjae Jeon * ioctl commands 262e9750824SNamjae Jeon */ 263e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 264e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 265d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 266e9750824SNamjae Jeon 26788b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 26888b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 26988b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 27002a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2711e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2721e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 273c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 274456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 275d323d005SChao Yu #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) 2764dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 2774dd6f977SJaegeuk Kim struct f2fs_move_range) 27888b88a66SJaegeuk Kim 2790b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 2800b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 2810b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 282f424f664SJaegeuk Kim 2831abff93dSJaegeuk Kim /* 2841abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 2851abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 2861abff93dSJaegeuk Kim */ 2871abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 2881abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 2891abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 2901abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 291c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 2921abff93dSJaegeuk Kim 293e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 294e9750824SNamjae Jeon /* 295e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 296e9750824SNamjae Jeon */ 297e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 298e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 29904ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 300e9750824SNamjae Jeon #endif 301e9750824SNamjae Jeon 302d323d005SChao Yu struct f2fs_defragment { 303d323d005SChao Yu u64 start; 304d323d005SChao Yu u64 len; 305d323d005SChao Yu }; 306d323d005SChao Yu 3074dd6f977SJaegeuk Kim struct f2fs_move_range { 3084dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3094dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3104dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3114dd6f977SJaegeuk Kim u64 len; /* size to move */ 3124dd6f977SJaegeuk Kim }; 3134dd6f977SJaegeuk Kim 314e9750824SNamjae Jeon /* 31539a53e0cSJaegeuk Kim * For INODE and NODE manager 31639a53e0cSJaegeuk Kim */ 3177b3cd7d6SJaegeuk Kim /* for directory operations */ 3187b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 319d8c6822aSJaegeuk Kim struct inode *inode; 3207b3cd7d6SJaegeuk Kim const void *bitmap; 3217b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 3227b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 3237b3cd7d6SJaegeuk Kim int max; 3247b3cd7d6SJaegeuk Kim }; 3257b3cd7d6SJaegeuk Kim 326d8c6822aSJaegeuk Kim static inline void make_dentry_ptr(struct inode *inode, 327d8c6822aSJaegeuk Kim struct f2fs_dentry_ptr *d, void *src, int type) 3287b3cd7d6SJaegeuk Kim { 329d8c6822aSJaegeuk Kim d->inode = inode; 330d8c6822aSJaegeuk Kim 3317b3cd7d6SJaegeuk Kim if (type == 1) { 3327b3cd7d6SJaegeuk Kim struct f2fs_dentry_block *t = (struct f2fs_dentry_block *)src; 333cac5a3d8SDongOh Shin 3347b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 3357b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3367b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3377b3cd7d6SJaegeuk Kim d->filename = t->filename; 3387b3cd7d6SJaegeuk Kim } else { 3397b3cd7d6SJaegeuk Kim struct f2fs_inline_dentry *t = (struct f2fs_inline_dentry *)src; 340cac5a3d8SDongOh Shin 3417b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3427b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3437b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3447b3cd7d6SJaegeuk Kim d->filename = t->filename; 3457b3cd7d6SJaegeuk Kim } 3467b3cd7d6SJaegeuk Kim } 3477b3cd7d6SJaegeuk Kim 348dbe6a5ffSJaegeuk Kim /* 349dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 350dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 351dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 35239a53e0cSJaegeuk Kim */ 353dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 354dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 355266e97a8SJaegeuk Kim enum { 356266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 357266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 358266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 359266e97a8SJaegeuk Kim * look up a node with readahead called 3604f4124d0SChao Yu * by get_data_block. 36139a53e0cSJaegeuk Kim */ 362266e97a8SJaegeuk Kim }; 363266e97a8SJaegeuk Kim 364a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 36539a53e0cSJaegeuk Kim 366817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 367817202d9SChao Yu 36813054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 36913054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 37013054c54SChao Yu 37139a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 37213054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 37313054c54SChao Yu 37413054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 37513054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 376c11abd1aSJaegeuk Kim 37739a53e0cSJaegeuk Kim struct extent_info { 37839a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 3794d0b0bd4SChao Yu u32 blk; /* start block address of the extent */ 380111d2495SMasanari Iida unsigned int len; /* length of the extent */ 38139a53e0cSJaegeuk Kim }; 38239a53e0cSJaegeuk Kim 38313054c54SChao Yu struct extent_node { 38413054c54SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 38513054c54SChao Yu struct list_head list; /* node in global extent list of sbi */ 38613054c54SChao Yu struct extent_info ei; /* extent info */ 387201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 38813054c54SChao Yu }; 38913054c54SChao Yu 39013054c54SChao Yu struct extent_tree { 39113054c54SChao Yu nid_t ino; /* inode number */ 39213054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 39362c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 3943e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 395137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 39613054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 39768e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 39813054c54SChao Yu }; 39913054c54SChao Yu 40039a53e0cSJaegeuk Kim /* 401003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 402003a3e1dSJaegeuk Kim * 403003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 404003a3e1dSJaegeuk Kim */ 405003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 406003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 4077f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 4087f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 4097f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 410003a3e1dSJaegeuk Kim 411003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 412003a3e1dSJaegeuk Kim block_t m_pblk; 413003a3e1dSJaegeuk Kim block_t m_lblk; 414003a3e1dSJaegeuk Kim unsigned int m_len; 415003a3e1dSJaegeuk Kim unsigned int m_flags; 416da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 417003a3e1dSJaegeuk Kim }; 418003a3e1dSJaegeuk Kim 419e2b4e2bcSChao Yu /* for flag in get_data_block */ 420e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 421e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 422e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 423e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 424b439b103SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_DIO 4 42524b84912SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_AIO 5 426e2b4e2bcSChao Yu 427003a3e1dSJaegeuk Kim /* 42839a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 42939a53e0cSJaegeuk Kim */ 43039a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 431354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 432cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 433e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 43426787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 43539a53e0cSJaegeuk Kim 436b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 437b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 438b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 439b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 440b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 441b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 442cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 443cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 444cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 445e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 446e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 44726787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 44826787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 449cde4de12SJaegeuk Kim 450ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 451ab9fa662SJaegeuk Kim 45239a53e0cSJaegeuk Kim struct f2fs_inode_info { 45339a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 45439a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 45539a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 45638431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 45739a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4586666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 45939a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 46039a53e0cSJaegeuk Kim 46139a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 46239a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 463d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 464204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 46539a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 46639a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 46788c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 46839a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 46926de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 47088b88a66SJaegeuk Kim 4710f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 4720f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 47388b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 47488b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 4753e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 47682e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 47739a53e0cSJaegeuk Kim }; 47839a53e0cSJaegeuk Kim 47939a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 480bd933d4fSChao Yu struct f2fs_extent *i_ext) 48139a53e0cSJaegeuk Kim { 482bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 483bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 484bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 48539a53e0cSJaegeuk Kim } 48639a53e0cSJaegeuk Kim 48739a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 48839a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 48939a53e0cSJaegeuk Kim { 49039a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 4914d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 49239a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 49339a53e0cSJaegeuk Kim } 49439a53e0cSJaegeuk Kim 495429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 496429511cdSChao Yu u32 blk, unsigned int len) 497429511cdSChao Yu { 498429511cdSChao Yu ei->fofs = fofs; 499429511cdSChao Yu ei->blk = blk; 500429511cdSChao Yu ei->len = len; 501429511cdSChao Yu } 502429511cdSChao Yu 503429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 504429511cdSChao Yu struct extent_info *front) 505429511cdSChao Yu { 506429511cdSChao Yu return (back->fofs + back->len == front->fofs && 507429511cdSChao Yu back->blk + back->len == front->blk); 508429511cdSChao Yu } 509429511cdSChao Yu 510429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 511429511cdSChao Yu struct extent_info *back) 512429511cdSChao Yu { 513429511cdSChao Yu return __is_extent_mergeable(back, cur); 514429511cdSChao Yu } 515429511cdSChao Yu 516429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 517429511cdSChao Yu struct extent_info *front) 518429511cdSChao Yu { 519429511cdSChao Yu return __is_extent_mergeable(cur, front); 520429511cdSChao Yu } 521429511cdSChao Yu 522cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 523205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 524205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 5254abd3f5aSChao Yu { 526205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 5274abd3f5aSChao Yu et->largest = en->ei; 5287c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 529205b9822SJaegeuk Kim } 5304abd3f5aSChao Yu } 5314abd3f5aSChao Yu 532b8559dc2SChao Yu enum nid_list { 533b8559dc2SChao Yu FREE_NID_LIST, 534b8559dc2SChao Yu ALLOC_NID_LIST, 535b8559dc2SChao Yu MAX_NID_LIST, 536b8559dc2SChao Yu }; 537b8559dc2SChao Yu 53839a53e0cSJaegeuk Kim struct f2fs_nm_info { 53939a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 54039a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 54104d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 54239a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 543cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 544ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 5452304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 54639a53e0cSJaegeuk Kim 54739a53e0cSJaegeuk Kim /* NAT cache management */ 54839a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 549309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 550b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 55139a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 552309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 553aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 55422ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 55539a53e0cSJaegeuk Kim 55639a53e0cSJaegeuk Kim /* free node ids management */ 5578a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 558b8559dc2SChao Yu struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ 559b8559dc2SChao Yu unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 560b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 56139a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 5624ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 5634ac91242SChao Yu unsigned char *nat_block_bitmap; 564586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 565586d1492SChao Yu spinlock_t free_nid_lock; /* protect updating of nid count */ 56639a53e0cSJaegeuk Kim 56739a53e0cSJaegeuk Kim /* for checkpoint */ 56839a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 56922ad0b6aSJaegeuk Kim 57022ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 57122ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 57222ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 57322ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 574599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 575599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 576599a09b2SChao Yu #endif 57739a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 57839a53e0cSJaegeuk Kim }; 57939a53e0cSJaegeuk Kim 58039a53e0cSJaegeuk Kim /* 58139a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 58239a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 58339a53e0cSJaegeuk Kim * by the data offset in a file. 58439a53e0cSJaegeuk Kim */ 58539a53e0cSJaegeuk Kim struct dnode_of_data { 58639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 58739a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 58839a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 58939a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 59039a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 59139a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 59293bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 5933cf45747SChao Yu char cur_level; /* level of hole node page */ 5943cf45747SChao Yu char max_level; /* level of current page located */ 59539a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 59639a53e0cSJaegeuk Kim }; 59739a53e0cSJaegeuk Kim 59839a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 59939a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 60039a53e0cSJaegeuk Kim { 601d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 60239a53e0cSJaegeuk Kim dn->inode = inode; 60339a53e0cSJaegeuk Kim dn->inode_page = ipage; 60439a53e0cSJaegeuk Kim dn->node_page = npage; 60539a53e0cSJaegeuk Kim dn->nid = nid; 60639a53e0cSJaegeuk Kim } 60739a53e0cSJaegeuk Kim 60839a53e0cSJaegeuk Kim /* 60939a53e0cSJaegeuk Kim * For SIT manager 61039a53e0cSJaegeuk Kim * 61139a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 61239a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 61339a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 61439a53e0cSJaegeuk Kim * respectively. 61539a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 61639a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 61739a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 61839a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 61939a53e0cSJaegeuk Kim * data and 8 for node logs. 62039a53e0cSJaegeuk Kim */ 62139a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 62239a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 62339a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 62439a53e0cSJaegeuk Kim 62539a53e0cSJaegeuk Kim enum { 62639a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 62739a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 62839a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 62939a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 63039a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 63139a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 63238aa0889SJaegeuk Kim NO_CHECK_TYPE, 63339a53e0cSJaegeuk Kim }; 63439a53e0cSJaegeuk Kim 6356b4afdd7SJaegeuk Kim struct flush_cmd { 6366b4afdd7SJaegeuk Kim struct completion wait; 637721bd4d5SGu Zheng struct llist_node llnode; 6386b4afdd7SJaegeuk Kim int ret; 6396b4afdd7SJaegeuk Kim }; 6406b4afdd7SJaegeuk Kim 641a688b9d9SGu Zheng struct flush_cmd_control { 642a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 643a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 6440a87f664SJaegeuk Kim atomic_t submit_flush; /* # of issued flushes */ 645721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 646721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 647a688b9d9SGu Zheng }; 648a688b9d9SGu Zheng 64939a53e0cSJaegeuk Kim struct f2fs_sm_info { 65039a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 65139a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 65239a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 65339a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 65439a53e0cSJaegeuk Kim 65539a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 65639a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 65739a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 65839a53e0cSJaegeuk Kim 65939a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 66039a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 66139a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 66239a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 66381eb8d6eSJaegeuk Kim 66481eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 66581eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 6667fd9e544SJaegeuk Kim 667bba681cbSJaegeuk Kim /* for batched trimming */ 668bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 669bba681cbSJaegeuk Kim 670184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 671184a5cd2SChao Yu 672216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 673216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 674c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 6756b4afdd7SJaegeuk Kim 6766b4afdd7SJaegeuk Kim /* for flush command control */ 677b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 678a688b9d9SGu Zheng 6790b54fb84SJaegeuk Kim /* for discard command control */ 6800b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 68139a53e0cSJaegeuk Kim }; 68239a53e0cSJaegeuk Kim 68339a53e0cSJaegeuk Kim /* 68439a53e0cSJaegeuk Kim * For superblock 68539a53e0cSJaegeuk Kim */ 68639a53e0cSJaegeuk Kim /* 68739a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 68839a53e0cSJaegeuk Kim * 68939a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 69039a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 69139a53e0cSJaegeuk Kim */ 69236951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 69339a53e0cSJaegeuk Kim enum count_type { 69439a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 695c227f912SChao Yu F2FS_DIRTY_DATA, 69639a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 69739a53e0cSJaegeuk Kim F2FS_DIRTY_META, 6988dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 6990f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 70036951b38SChao Yu F2FS_WB_CP_DATA, 70136951b38SChao Yu F2FS_WB_DATA, 70239a53e0cSJaegeuk Kim NR_COUNT_TYPE, 70339a53e0cSJaegeuk Kim }; 70439a53e0cSJaegeuk Kim 70539a53e0cSJaegeuk Kim /* 706e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 70739a53e0cSJaegeuk Kim * The available types are: 70839a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 70939a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 71039a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 71139a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 71239a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 71339a53e0cSJaegeuk Kim * with waiting the bio's completion 71439a53e0cSJaegeuk Kim * ... Only can be used with META. 71539a53e0cSJaegeuk Kim */ 7167d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 71739a53e0cSJaegeuk Kim enum page_type { 71839a53e0cSJaegeuk Kim DATA, 71939a53e0cSJaegeuk Kim NODE, 72039a53e0cSJaegeuk Kim META, 72139a53e0cSJaegeuk Kim NR_PAGE_TYPE, 72239a53e0cSJaegeuk Kim META_FLUSH, 7238ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 7248ce67cb0SJaegeuk Kim INMEM_DROP, 72528bc106bSChao Yu INMEM_REVOKE, 7268ce67cb0SJaegeuk Kim IPU, 7278ce67cb0SJaegeuk Kim OPU, 72839a53e0cSJaegeuk Kim }; 72939a53e0cSJaegeuk Kim 730458e6197SJaegeuk Kim struct f2fs_io_info { 73105ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 732458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 73304d328deSMike Christie int op; /* contains REQ_OP_ */ 734ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 7357a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 73628bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 73705ca3632SJaegeuk Kim struct page *page; /* page to be written */ 7384375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 739d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 740458e6197SJaegeuk Kim }; 741458e6197SJaegeuk Kim 74204d328deSMike Christie #define is_read_io(rw) (rw == READ) 7431ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 744458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 7451ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 7461ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 747458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 748df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 7491ff7bd3bSJaegeuk Kim }; 7501ff7bd3bSJaegeuk Kim 7513c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 7523c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 7533c62be17SJaegeuk Kim struct f2fs_dev_info { 7543c62be17SJaegeuk Kim struct block_device *bdev; 7553c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 7563c62be17SJaegeuk Kim unsigned int total_segments; 7573c62be17SJaegeuk Kim block_t start_blk; 7583c62be17SJaegeuk Kim block_t end_blk; 7593c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 7603c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 7613c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 7623c62be17SJaegeuk Kim #endif 7633c62be17SJaegeuk Kim }; 7643c62be17SJaegeuk Kim 765c227f912SChao Yu enum inode_type { 766c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 767c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 7680f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 769c227f912SChao Yu NR_INODE_TYPE, 770c227f912SChao Yu }; 771c227f912SChao Yu 77267298804SChao Yu /* for inner inode cache management */ 77367298804SChao Yu struct inode_management { 77467298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 77567298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 77667298804SChao Yu struct list_head ino_list; /* inode list head */ 77767298804SChao Yu unsigned long ino_num; /* number of entries */ 77867298804SChao Yu }; 77967298804SChao Yu 780caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 781caf0047eSChao Yu enum { 782caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 783caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 784caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 785caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 786df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 787bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 788caf0047eSChao Yu }; 789caf0047eSChao Yu 7906beceb54SJaegeuk Kim enum { 7916beceb54SJaegeuk Kim CP_TIME, 792d0239e1bSJaegeuk Kim REQ_TIME, 7936beceb54SJaegeuk Kim MAX_TIME, 7946beceb54SJaegeuk Kim }; 7956beceb54SJaegeuk Kim 79639a53e0cSJaegeuk Kim struct f2fs_sb_info { 79739a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 7985e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 79939a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 800e8240f65SChao Yu int valid_super_block; /* valid super block no */ 801fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 80239a53e0cSJaegeuk Kim 803178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 804178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 805178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 806178053e2SDamien Le Moal #endif 807178053e2SDamien Le Moal 80839a53e0cSJaegeuk Kim /* for node-related operations */ 80939a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 81039a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 81139a53e0cSJaegeuk Kim 81239a53e0cSJaegeuk Kim /* for segment-related operations */ 81339a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 8141ff7bd3bSJaegeuk Kim 8151ff7bd3bSJaegeuk Kim /* for bio operations */ 816924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 8171ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 8187dfeaa32SJaegeuk Kim struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ 8190a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 8200a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 82139a53e0cSJaegeuk Kim 82239a53e0cSJaegeuk Kim /* for checkpoint */ 82339a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 8248508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 825aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 82639a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 82739936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 828b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 829b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 830fb51b5efSChangman Lee wait_queue_head_t cp_wait; 8316beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 8326beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 83339a53e0cSJaegeuk Kim 83467298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 8356451e041SJaegeuk Kim 8366451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 8370d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 83839a53e0cSJaegeuk Kim 839c227f912SChao Yu /* for inode management */ 840c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 841c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 84239a53e0cSJaegeuk Kim 84313054c54SChao Yu /* for extent tree cache */ 84413054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 8455e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 84613054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 84713054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 8487441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 849137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 85074fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 85113054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 85213054c54SChao Yu 85339a53e0cSJaegeuk Kim /* basic filesystem units */ 85439a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 85539a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 85639a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 85739a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 85839a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 85939a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 86039a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 86139a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 86239a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 86339a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 86439a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 86539a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 86639a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 867e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 86839a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 869ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 87039a53e0cSJaegeuk Kim 87139a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 87239a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 873a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 87439a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 87539a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 876523be8a6SJaegeuk Kim 877523be8a6SJaegeuk Kim /* # of pages, see count_type */ 87835782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 87941382ec4SJaegeuk Kim /* # of allocated blocks */ 88041382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 88139a53e0cSJaegeuk Kim 882513c5f37SJaegeuk Kim /* valid inode count */ 883513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 884513c5f37SJaegeuk Kim 88539a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 88639a53e0cSJaegeuk Kim 88739a53e0cSJaegeuk Kim /* for cleaning operations */ 88839a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 88939a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 8905ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 89139a53e0cSJaegeuk Kim 892e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 893e93b9865SHou Pengyang u64 fggc_threshold; 894e93b9865SHou Pengyang 895b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 896b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 897b1c57c1cSJaegeuk Kim 89839a53e0cSJaegeuk Kim /* 89939a53e0cSJaegeuk Kim * for stat information. 90039a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 90139a53e0cSJaegeuk Kim */ 90235b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 90339a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 90439a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 90539a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 906b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 9075b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 9085b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 9095b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 9105b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 911d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 91203e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 91303e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 91426a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 91526a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 91639a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 91733fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 91835b09d82SNamjae Jeon #endif 91935b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 92039a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 921b59d0baeSNamjae Jeon 922b59d0baeSNamjae Jeon /* For sysfs suppport */ 923b59d0baeSNamjae Jeon struct kobject s_kobj; 924b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 9252658e50dSJaegeuk Kim 9262658e50dSJaegeuk Kim /* For shrinker support */ 9272658e50dSJaegeuk Kim struct list_head s_list; 9283c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 9293c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 9302658e50dSJaegeuk Kim struct mutex umount_mutex; 9312658e50dSJaegeuk Kim unsigned int shrinker_run_no; 9328f1dbbbbSShuoran Liu 9338f1dbbbbSShuoran Liu /* For write statistics */ 9348f1dbbbbSShuoran Liu u64 sectors_written_start; 9358f1dbbbbSShuoran Liu u64 kbytes_written; 93643b6573bSKeith Mok 93743b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 93843b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 9391ecc0c5cSChao Yu 9401ecc0c5cSChao Yu /* For fault injection */ 9411ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 9421ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 9431ecc0c5cSChao Yu #endif 94439a53e0cSJaegeuk Kim }; 94539a53e0cSJaegeuk Kim 9461ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 94755523519SChao Yu #define f2fs_show_injection_info(type) \ 94855523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 94955523519SChao Yu KERN_INFO, fault_name[type], \ 95055523519SChao Yu __func__, __builtin_return_address(0)) 9511ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 9521ecc0c5cSChao Yu { 9531ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 9541ecc0c5cSChao Yu 9551ecc0c5cSChao Yu if (!ffi->inject_rate) 9561ecc0c5cSChao Yu return false; 9571ecc0c5cSChao Yu 9581ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 9591ecc0c5cSChao Yu return false; 9601ecc0c5cSChao Yu 9611ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 9621ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 9631ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 9641ecc0c5cSChao Yu return true; 9651ecc0c5cSChao Yu } 9661ecc0c5cSChao Yu return false; 9671ecc0c5cSChao Yu } 9681ecc0c5cSChao Yu #endif 9691ecc0c5cSChao Yu 9708f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 9718f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 9728f1dbbbbSShuoran Liu */ 9738f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 9748f1dbbbbSShuoran Liu (((u64)part_stat_read(s->sb->s_bdev->bd_part, sectors[1]) - \ 9758f1dbbbbSShuoran Liu s->sectors_written_start) >> 1) 9768f1dbbbbSShuoran Liu 9776beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 9786beceb54SJaegeuk Kim { 9796beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 9806beceb54SJaegeuk Kim } 9816beceb54SJaegeuk Kim 9826beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 9836beceb54SJaegeuk Kim { 9846beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 9856beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 9866beceb54SJaegeuk Kim 9876beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 9886beceb54SJaegeuk Kim } 9896beceb54SJaegeuk Kim 990d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 991d0239e1bSJaegeuk Kim { 992d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 993d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 994d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 995d0239e1bSJaegeuk Kim 996d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 997d0239e1bSJaegeuk Kim return 0; 998d0239e1bSJaegeuk Kim 999d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1000d0239e1bSJaegeuk Kim } 1001d0239e1bSJaegeuk Kim 100239a53e0cSJaegeuk Kim /* 100339a53e0cSJaegeuk Kim * Inline functions 100439a53e0cSJaegeuk Kim */ 100543b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 100643b6573bSKeith Mok unsigned int length) 100743b6573bSKeith Mok { 100843b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 100943b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 101043b6573bSKeith Mok int err; 101143b6573bSKeith Mok 101243b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 101343b6573bSKeith Mok shash->flags = 0; 101443b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 101543b6573bSKeith Mok 101643b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 101743b6573bSKeith Mok BUG_ON(err); 101843b6573bSKeith Mok 101943b6573bSKeith Mok return *ctx; 102043b6573bSKeith Mok } 102143b6573bSKeith Mok 102243b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 102343b6573bSKeith Mok void *buf, size_t buf_size) 102443b6573bSKeith Mok { 102543b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 102643b6573bSKeith Mok } 102743b6573bSKeith Mok 102839a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 102939a53e0cSJaegeuk Kim { 103039a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 103139a53e0cSJaegeuk Kim } 103239a53e0cSJaegeuk Kim 103339a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 103439a53e0cSJaegeuk Kim { 103539a53e0cSJaegeuk Kim return sb->s_fs_info; 103639a53e0cSJaegeuk Kim } 103739a53e0cSJaegeuk Kim 10384081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 10394081363fSJaegeuk Kim { 10404081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 10414081363fSJaegeuk Kim } 10424081363fSJaegeuk Kim 10434081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 10444081363fSJaegeuk Kim { 10454081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 10464081363fSJaegeuk Kim } 10474081363fSJaegeuk Kim 10484081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 10494081363fSJaegeuk Kim { 10504081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 10514081363fSJaegeuk Kim } 10524081363fSJaegeuk Kim 105339a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 105439a53e0cSJaegeuk Kim { 105539a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 105639a53e0cSJaegeuk Kim } 105739a53e0cSJaegeuk Kim 105839a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 105939a53e0cSJaegeuk Kim { 106039a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 106139a53e0cSJaegeuk Kim } 106239a53e0cSJaegeuk Kim 106345590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 106445590710SGu Zheng { 106545590710SGu Zheng return (struct f2fs_node *)page_address(page); 106645590710SGu Zheng } 106745590710SGu Zheng 106858bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 106958bfaf44SJaegeuk Kim { 107058bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 107158bfaf44SJaegeuk Kim } 107258bfaf44SJaegeuk Kim 107339a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 107439a53e0cSJaegeuk Kim { 107539a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 107639a53e0cSJaegeuk Kim } 107739a53e0cSJaegeuk Kim 107839a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 107939a53e0cSJaegeuk Kim { 108039a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 108139a53e0cSJaegeuk Kim } 108239a53e0cSJaegeuk Kim 108339a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 108439a53e0cSJaegeuk Kim { 108539a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 108639a53e0cSJaegeuk Kim } 108739a53e0cSJaegeuk Kim 108839a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 108939a53e0cSJaegeuk Kim { 109039a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 109139a53e0cSJaegeuk Kim } 109239a53e0cSJaegeuk Kim 109339a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 109439a53e0cSJaegeuk Kim { 109539a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 109639a53e0cSJaegeuk Kim } 109739a53e0cSJaegeuk Kim 10989df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 10999df27d98SGu Zheng { 11009df27d98SGu Zheng return sbi->meta_inode->i_mapping; 11019df27d98SGu Zheng } 11029df27d98SGu Zheng 11034ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 11044ef51a8fSJaegeuk Kim { 11054ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 11064ef51a8fSJaegeuk Kim } 11074ef51a8fSJaegeuk Kim 1108caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 110939a53e0cSJaegeuk Kim { 1110fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 111139a53e0cSJaegeuk Kim } 111239a53e0cSJaegeuk Kim 1113caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 111439a53e0cSJaegeuk Kim { 1115fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1116caf0047eSChao Yu } 1117caf0047eSChao Yu 1118caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1119caf0047eSChao Yu { 1120fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 112139a53e0cSJaegeuk Kim } 112239a53e0cSJaegeuk Kim 1123d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1124d71b5564SJaegeuk Kim { 1125d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1126d71b5564SJaegeuk Kim } 1127d71b5564SJaegeuk Kim 1128ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1129ced2c7eaSKinglong Mee { 1130ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1131ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1132ced2c7eaSKinglong Mee } 1133ced2c7eaSKinglong Mee 1134aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 113525ca923bSJaegeuk Kim { 113625ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1137aaec2b1dSChao Yu 113825ca923bSJaegeuk Kim return ckpt_flags & f; 113925ca923bSJaegeuk Kim } 114025ca923bSJaegeuk Kim 1141aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 114225ca923bSJaegeuk Kim { 1143aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1144aaec2b1dSChao Yu } 1145aaec2b1dSChao Yu 1146aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1147aaec2b1dSChao Yu { 1148aaec2b1dSChao Yu unsigned int ckpt_flags; 1149aaec2b1dSChao Yu 1150aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 115125ca923bSJaegeuk Kim ckpt_flags |= f; 115225ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 115325ca923bSJaegeuk Kim } 115425ca923bSJaegeuk Kim 1155aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 115625ca923bSJaegeuk Kim { 1157aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1158aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1159aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1160aaec2b1dSChao Yu } 1161aaec2b1dSChao Yu 1162aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1163aaec2b1dSChao Yu { 1164aaec2b1dSChao Yu unsigned int ckpt_flags; 1165aaec2b1dSChao Yu 1166aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 116725ca923bSJaegeuk Kim ckpt_flags &= (~f); 116825ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 116925ca923bSJaegeuk Kim } 117025ca923bSJaegeuk Kim 1171aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1172aaec2b1dSChao Yu { 1173aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1174aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1175aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1176aaec2b1dSChao Yu } 1177aaec2b1dSChao Yu 117822ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 117922ad0b6aSJaegeuk Kim { 118022ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 118122ad0b6aSJaegeuk Kim 118222ad0b6aSJaegeuk Kim if (lock) 118322ad0b6aSJaegeuk Kim spin_lock(&sbi->cp_lock); 118422ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 118522ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 118622ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 118722ad0b6aSJaegeuk Kim if (lock) 118822ad0b6aSJaegeuk Kim spin_unlock(&sbi->cp_lock); 118922ad0b6aSJaegeuk Kim } 119022ad0b6aSJaegeuk Kim 119122ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 119222ad0b6aSJaegeuk Kim struct cp_control *cpc) 119322ad0b6aSJaegeuk Kim { 119422ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 119522ad0b6aSJaegeuk Kim 119622ad0b6aSJaegeuk Kim return (cpc) ? (cpc->reason == CP_UMOUNT) && set : set; 119722ad0b6aSJaegeuk Kim } 119822ad0b6aSJaegeuk Kim 1199e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 120039a53e0cSJaegeuk Kim { 1201b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 120239a53e0cSJaegeuk Kim } 120339a53e0cSJaegeuk Kim 1204e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 120539a53e0cSJaegeuk Kim { 1206b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 120739936837SJaegeuk Kim } 120839936837SJaegeuk Kim 1209e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 121039936837SJaegeuk Kim { 1211b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 121239936837SJaegeuk Kim } 121339936837SJaegeuk Kim 1214e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 121539936837SJaegeuk Kim { 1216b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 121739a53e0cSJaegeuk Kim } 121839a53e0cSJaegeuk Kim 1219119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1220119ee914SJaegeuk Kim { 1221119ee914SJaegeuk Kim int reason = CP_SYNC; 1222119ee914SJaegeuk Kim 1223119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1224119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1225119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1226119ee914SJaegeuk Kim reason = CP_UMOUNT; 1227119ee914SJaegeuk Kim return reason; 1228119ee914SJaegeuk Kim } 1229119ee914SJaegeuk Kim 1230119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1231119ee914SJaegeuk Kim { 1232119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 1233119ee914SJaegeuk Kim } 1234119ee914SJaegeuk Kim 1235119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1236119ee914SJaegeuk Kim { 1237aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1238aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1239119ee914SJaegeuk Kim } 1240119ee914SJaegeuk Kim 124139a53e0cSJaegeuk Kim /* 124239a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 124339a53e0cSJaegeuk Kim */ 1244064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 124539a53e0cSJaegeuk Kim { 1246d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1247d6b7d4b3SChao Yu return -EINVAL; 1248cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1249064e0823SNamjae Jeon return -EINVAL; 1250064e0823SNamjae Jeon return 0; 125139a53e0cSJaegeuk Kim } 125239a53e0cSJaegeuk Kim 125339a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 125439a53e0cSJaegeuk Kim 125539a53e0cSJaegeuk Kim /* 125639a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 125739a53e0cSJaegeuk Kim */ 125839a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 125939a53e0cSJaegeuk Kim { 126039a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 12616c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 126239a53e0cSJaegeuk Kim else 12636c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 126439a53e0cSJaegeuk Kim } 126539a53e0cSJaegeuk Kim 12664bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 12674bc8e9bcSChao Yu { 12684bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 12694bc8e9bcSChao Yu } 12704bc8e9bcSChao Yu 12718edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 127239a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 127346008c6dSChao Yu struct inode *inode, blkcnt_t *count) 127439a53e0cSJaegeuk Kim { 1275dd11a5dfSJaegeuk Kim blkcnt_t diff; 1276dd11a5dfSJaegeuk Kim 1277cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 127855523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 127955523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 1280cb78942bSJaegeuk Kim return false; 128155523519SChao Yu } 1282cb78942bSJaegeuk Kim #endif 1283dd11a5dfSJaegeuk Kim /* 1284dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1285dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1286dd11a5dfSJaegeuk Kim */ 1287dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1288cfb271d4SChao Yu 128939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 12902555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 12912555a2d5SJaegeuk Kim if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { 1292dd11a5dfSJaegeuk Kim diff = sbi->total_valid_block_count - sbi->user_block_count; 1293dd11a5dfSJaegeuk Kim *count -= diff; 12942555a2d5SJaegeuk Kim sbi->total_valid_block_count = sbi->user_block_count; 129546008c6dSChao Yu if (!*count) { 129639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1297dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 129839a53e0cSJaegeuk Kim return false; 129939a53e0cSJaegeuk Kim } 130046008c6dSChao Yu } 130139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 130241382ec4SJaegeuk Kim 13032555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, *count, true); 130439a53e0cSJaegeuk Kim return true; 130539a53e0cSJaegeuk Kim } 130639a53e0cSJaegeuk Kim 1307da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 130839a53e0cSJaegeuk Kim struct inode *inode, 130939a53e0cSJaegeuk Kim blkcnt_t count) 131039a53e0cSJaegeuk Kim { 131139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13129850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 13139850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 131439a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 131539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 13162555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, count, false); 131739a53e0cSJaegeuk Kim } 131839a53e0cSJaegeuk Kim 131939a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 132039a53e0cSJaegeuk Kim { 132135782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 13227c4abcbeSChao Yu 132336951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 132436951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 13257c4abcbeSChao Yu return; 13267c4abcbeSChao Yu 1327caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 132839a53e0cSJaegeuk Kim } 132939a53e0cSJaegeuk Kim 1330a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 133139a53e0cSJaegeuk Kim { 1332204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1333c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1334c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 133539a53e0cSJaegeuk Kim } 133639a53e0cSJaegeuk Kim 133739a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 133839a53e0cSJaegeuk Kim { 133935782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 134039a53e0cSJaegeuk Kim } 134139a53e0cSJaegeuk Kim 1342a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 134339a53e0cSJaegeuk Kim { 13445ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 13455ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 13461fe54f9dSJaegeuk Kim return; 13471fe54f9dSJaegeuk Kim 1348204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1349c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1350c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 135139a53e0cSJaegeuk Kim } 135239a53e0cSJaegeuk Kim 1353523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 135439a53e0cSJaegeuk Kim { 135535782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 135639a53e0cSJaegeuk Kim } 135739a53e0cSJaegeuk Kim 1358204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1359f8b2c1f9SJaegeuk Kim { 1360204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1361f8b2c1f9SJaegeuk Kim } 1362f8b2c1f9SJaegeuk Kim 13635ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 13645ac206cfSNamjae Jeon { 13653519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1366523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1367523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1368523be8a6SJaegeuk Kim 1369523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 13705ac206cfSNamjae Jeon } 13715ac206cfSNamjae Jeon 137239a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 137339a53e0cSJaegeuk Kim { 13748b8343faSJaegeuk Kim return sbi->total_valid_block_count; 137539a53e0cSJaegeuk Kim } 137639a53e0cSJaegeuk Kim 1377f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1378f83a2584SYunlei He { 1379f83a2584SYunlei He return sbi->discard_blks; 1380f83a2584SYunlei He } 1381f83a2584SYunlei He 138239a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 138339a53e0cSJaegeuk Kim { 138439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 138539a53e0cSJaegeuk Kim 138639a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 138739a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 138839a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 138939a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 139039a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 139139a53e0cSJaegeuk Kim 139239a53e0cSJaegeuk Kim return 0; 139339a53e0cSJaegeuk Kim } 139439a53e0cSJaegeuk Kim 139555141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 139655141486SWanpeng Li { 139755141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 139855141486SWanpeng Li } 139955141486SWanpeng Li 140039a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 140139a53e0cSJaegeuk Kim { 140239a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 14031dbe4152SChangman Lee int offset; 14041dbe4152SChangman Lee 140555141486SWanpeng Li if (__cp_payload(sbi) > 0) { 14061dbe4152SChangman Lee if (flag == NAT_BITMAP) 14071dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 14081dbe4152SChangman Lee else 140965b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 14101dbe4152SChangman Lee } else { 14111dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 141225ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 141339a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 141439a53e0cSJaegeuk Kim } 14151dbe4152SChangman Lee } 141639a53e0cSJaegeuk Kim 141739a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 141839a53e0cSJaegeuk Kim { 14198508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 142039a53e0cSJaegeuk Kim 14218508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 142239a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 142339a53e0cSJaegeuk Kim return start_addr; 142439a53e0cSJaegeuk Kim } 142539a53e0cSJaegeuk Kim 14268508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 14278508e44aSJaegeuk Kim { 14288508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 14298508e44aSJaegeuk Kim 14308508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 14318508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 14328508e44aSJaegeuk Kim return start_addr; 14338508e44aSJaegeuk Kim } 14348508e44aSJaegeuk Kim 14358508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 14368508e44aSJaegeuk Kim { 14378508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 14388508e44aSJaegeuk Kim } 14398508e44aSJaegeuk Kim 144039a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 144139a53e0cSJaegeuk Kim { 144239a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 144339a53e0cSJaegeuk Kim } 144439a53e0cSJaegeuk Kim 144539a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1446ef86d709SGu Zheng struct inode *inode) 144739a53e0cSJaegeuk Kim { 144839a53e0cSJaegeuk Kim block_t valid_block_count; 144939a53e0cSJaegeuk Kim unsigned int valid_node_count; 145039a53e0cSJaegeuk Kim 145139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 145239a53e0cSJaegeuk Kim 1453ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1454cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 145539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 145639a53e0cSJaegeuk Kim return false; 145739a53e0cSJaegeuk Kim } 145839a53e0cSJaegeuk Kim 1459ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1460cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 146139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 146239a53e0cSJaegeuk Kim return false; 146339a53e0cSJaegeuk Kim } 146439a53e0cSJaegeuk Kim 146539a53e0cSJaegeuk Kim if (inode) 14668edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, true); 1467ef86d709SGu Zheng 1468ef86d709SGu Zheng sbi->total_valid_node_count++; 1469ef86d709SGu Zheng sbi->total_valid_block_count++; 147039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 147139a53e0cSJaegeuk Kim 147241382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 147339a53e0cSJaegeuk Kim return true; 147439a53e0cSJaegeuk Kim } 147539a53e0cSJaegeuk Kim 147639a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1477ef86d709SGu Zheng struct inode *inode) 147839a53e0cSJaegeuk Kim { 147939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 148039a53e0cSJaegeuk Kim 14819850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 14829850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 14839850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 148439a53e0cSJaegeuk Kim 14858edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, false); 1486ef86d709SGu Zheng sbi->total_valid_node_count--; 1487ef86d709SGu Zheng sbi->total_valid_block_count--; 148839a53e0cSJaegeuk Kim 148939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 149039a53e0cSJaegeuk Kim } 149139a53e0cSJaegeuk Kim 149239a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 149339a53e0cSJaegeuk Kim { 14948b8343faSJaegeuk Kim return sbi->total_valid_node_count; 149539a53e0cSJaegeuk Kim } 149639a53e0cSJaegeuk Kim 149739a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 149839a53e0cSJaegeuk Kim { 1499513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 150039a53e0cSJaegeuk Kim } 150139a53e0cSJaegeuk Kim 15020e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 150339a53e0cSJaegeuk Kim { 1504513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 150539a53e0cSJaegeuk Kim } 150639a53e0cSJaegeuk Kim 1507513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 150839a53e0cSJaegeuk Kim { 1509513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 151039a53e0cSJaegeuk Kim } 151139a53e0cSJaegeuk Kim 1512a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1513a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1514a56c7c6fSJaegeuk Kim { 1515c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1516c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1517cac5a3d8SDongOh Shin 1518c41f3cc3SJaegeuk Kim if (page) 1519c41f3cc3SJaegeuk Kim return page; 1520c41f3cc3SJaegeuk Kim 152155523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 152255523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1523c41f3cc3SJaegeuk Kim return NULL; 152455523519SChao Yu } 1525c41f3cc3SJaegeuk Kim #endif 1526a56c7c6fSJaegeuk Kim if (!for_write) 1527a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1528a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1529a56c7c6fSJaegeuk Kim } 1530a56c7c6fSJaegeuk Kim 15316e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 15326e2c64adSJaegeuk Kim { 15336e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 15346e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 15356e2c64adSJaegeuk Kim 15366e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 15376e2c64adSJaegeuk Kim kunmap(dst); 15386e2c64adSJaegeuk Kim kunmap(src); 15396e2c64adSJaegeuk Kim } 15406e2c64adSJaegeuk Kim 154139a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 154239a53e0cSJaegeuk Kim { 1543031fa8ccSJaegeuk Kim if (!page) 154439a53e0cSJaegeuk Kim return; 154539a53e0cSJaegeuk Kim 154639a53e0cSJaegeuk Kim if (unlock) { 15479850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 154839a53e0cSJaegeuk Kim unlock_page(page); 154939a53e0cSJaegeuk Kim } 155009cbfeafSKirill A. Shutemov put_page(page); 155139a53e0cSJaegeuk Kim } 155239a53e0cSJaegeuk Kim 155339a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 155439a53e0cSJaegeuk Kim { 155539a53e0cSJaegeuk Kim if (dn->node_page) 155639a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 155739a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 155839a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 155939a53e0cSJaegeuk Kim dn->node_page = NULL; 156039a53e0cSJaegeuk Kim dn->inode_page = NULL; 156139a53e0cSJaegeuk Kim } 156239a53e0cSJaegeuk Kim 156339a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1564e8512d2eSGu Zheng size_t size) 156539a53e0cSJaegeuk Kim { 1566e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 156739a53e0cSJaegeuk Kim } 156839a53e0cSJaegeuk Kim 15697bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 15707bd59381SGu Zheng gfp_t flags) 15717bd59381SGu Zheng { 15727bd59381SGu Zheng void *entry; 15737bd59381SGu Zheng 157480c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 157580c54505SJaegeuk Kim if (!entry) 157680c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 15777bd59381SGu Zheng return entry; 15787bd59381SGu Zheng } 15797bd59381SGu Zheng 1580740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1581740432f8SJaegeuk Kim { 1582740432f8SJaegeuk Kim struct bio *bio; 1583740432f8SJaegeuk Kim 1584740432f8SJaegeuk Kim /* No failure on bio allocation */ 1585740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 158680c54505SJaegeuk Kim if (!bio) 158780c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1588740432f8SJaegeuk Kim return bio; 1589740432f8SJaegeuk Kim } 1590740432f8SJaegeuk Kim 15919be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 15929be32d72SJaegeuk Kim unsigned long index, void *item) 15939be32d72SJaegeuk Kim { 15949be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 15959be32d72SJaegeuk Kim cond_resched(); 15969be32d72SJaegeuk Kim } 15979be32d72SJaegeuk Kim 159839a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 159939a53e0cSJaegeuk Kim 160039a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 160139a53e0cSJaegeuk Kim { 160245590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1603cac5a3d8SDongOh Shin 160439a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 160539a53e0cSJaegeuk Kim } 160639a53e0cSJaegeuk Kim 160739a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 160839a53e0cSJaegeuk Kim { 160939a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 161039a53e0cSJaegeuk Kim } 161139a53e0cSJaegeuk Kim 161239a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 161339a53e0cSJaegeuk Kim unsigned int offset) 161439a53e0cSJaegeuk Kim { 161539a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 161639a53e0cSJaegeuk Kim __le32 *addr_array; 1617cac5a3d8SDongOh Shin 161845590710SGu Zheng raw_node = F2FS_NODE(node_page); 161939a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 162039a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 162139a53e0cSJaegeuk Kim } 162239a53e0cSJaegeuk Kim 162339a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 162439a53e0cSJaegeuk Kim { 162539a53e0cSJaegeuk Kim int mask; 162639a53e0cSJaegeuk Kim 162739a53e0cSJaegeuk Kim addr += (nr >> 3); 162839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 162939a53e0cSJaegeuk Kim return mask & *addr; 163039a53e0cSJaegeuk Kim } 163139a53e0cSJaegeuk Kim 1632a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1633a66cdd98SJaegeuk Kim { 1634a66cdd98SJaegeuk Kim int mask; 1635a66cdd98SJaegeuk Kim 1636a66cdd98SJaegeuk Kim addr += (nr >> 3); 1637a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1638a66cdd98SJaegeuk Kim *addr |= mask; 1639a66cdd98SJaegeuk Kim } 1640a66cdd98SJaegeuk Kim 1641a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1642a66cdd98SJaegeuk Kim { 1643a66cdd98SJaegeuk Kim int mask; 1644a66cdd98SJaegeuk Kim 1645a66cdd98SJaegeuk Kim addr += (nr >> 3); 1646a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1647a66cdd98SJaegeuk Kim *addr &= ~mask; 1648a66cdd98SJaegeuk Kim } 1649a66cdd98SJaegeuk Kim 165052aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 165139a53e0cSJaegeuk Kim { 165239a53e0cSJaegeuk Kim int mask; 165339a53e0cSJaegeuk Kim int ret; 165439a53e0cSJaegeuk Kim 165539a53e0cSJaegeuk Kim addr += (nr >> 3); 165639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 165739a53e0cSJaegeuk Kim ret = mask & *addr; 165839a53e0cSJaegeuk Kim *addr |= mask; 165939a53e0cSJaegeuk Kim return ret; 166039a53e0cSJaegeuk Kim } 166139a53e0cSJaegeuk Kim 166252aca074SGu Zheng static inline int f2fs_test_and_clear_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 1674c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1675c6ac4c0eSGu Zheng { 1676c6ac4c0eSGu Zheng int mask; 1677c6ac4c0eSGu Zheng 1678c6ac4c0eSGu Zheng addr += (nr >> 3); 1679c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1680c6ac4c0eSGu Zheng *addr ^= mask; 1681c6ac4c0eSGu Zheng } 1682c6ac4c0eSGu Zheng 168339a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 168439a53e0cSJaegeuk Kim enum { 168539a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1686b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 168726de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1688ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 168939a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 169039a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 169139a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1692c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1693c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1694444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 16951001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 169634d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1697fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1698fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 169988b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 170088b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 17015fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 170202a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 17033c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 17041e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1705b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1706510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1707d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1708c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 1709dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 171039a53e0cSJaegeuk Kim }; 171139a53e0cSJaegeuk Kim 1712205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 1713205b9822SJaegeuk Kim int flag, bool set) 171439a53e0cSJaegeuk Kim { 1715205b9822SJaegeuk Kim switch (flag) { 1716205b9822SJaegeuk Kim case FI_INLINE_XATTR: 1717205b9822SJaegeuk Kim case FI_INLINE_DATA: 1718205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 1719205b9822SJaegeuk Kim if (set) 1720205b9822SJaegeuk Kim return; 1721205b9822SJaegeuk Kim case FI_DATA_EXIST: 1722205b9822SJaegeuk Kim case FI_INLINE_DOTS: 17237c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1724205b9822SJaegeuk Kim } 172539a53e0cSJaegeuk Kim } 172639a53e0cSJaegeuk Kim 172791942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 172839a53e0cSJaegeuk Kim { 172991942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 173091942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 1731205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 173239a53e0cSJaegeuk Kim } 173339a53e0cSJaegeuk Kim 173491942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 173539a53e0cSJaegeuk Kim { 173691942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 173739a53e0cSJaegeuk Kim } 173839a53e0cSJaegeuk Kim 173991942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 174039a53e0cSJaegeuk Kim { 174191942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 174291942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 1743205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 174439a53e0cSJaegeuk Kim } 174539a53e0cSJaegeuk Kim 174691942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 1747444c580fSJaegeuk Kim { 174891942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 174991942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 17507c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 175139a53e0cSJaegeuk Kim } 175239a53e0cSJaegeuk Kim 1753a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 1754a1961246SJaegeuk Kim { 1755a1961246SJaegeuk Kim if (inc) 1756a1961246SJaegeuk Kim inc_nlink(inode); 1757a1961246SJaegeuk Kim else 1758a1961246SJaegeuk Kim drop_nlink(inode); 17597c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1760a1961246SJaegeuk Kim } 1761a1961246SJaegeuk Kim 17628edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 17638edd03c8SJaegeuk Kim blkcnt_t diff, bool add) 17648edd03c8SJaegeuk Kim { 176526de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 176626de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 176726de9b11SJaegeuk Kim 17688edd03c8SJaegeuk Kim inode->i_blocks = add ? inode->i_blocks + diff : 17698edd03c8SJaegeuk Kim inode->i_blocks - diff; 17707c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 177126de9b11SJaegeuk Kim if (clean || recover) 177226de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 17738edd03c8SJaegeuk Kim } 17748edd03c8SJaegeuk Kim 1775fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 1776fc9581c8SJaegeuk Kim { 177726de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 177826de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 177926de9b11SJaegeuk Kim 1780fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 1781fc9581c8SJaegeuk Kim return; 1782fc9581c8SJaegeuk Kim 1783fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 17847c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 178526de9b11SJaegeuk Kim if (clean || recover) 178626de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 178726de9b11SJaegeuk Kim } 178826de9b11SJaegeuk Kim 1789205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 1790205b9822SJaegeuk Kim { 1791205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 17927c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1793205b9822SJaegeuk Kim } 1794205b9822SJaegeuk Kim 1795205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 1796205b9822SJaegeuk Kim { 1797205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 17987c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1799205b9822SJaegeuk Kim } 1800205b9822SJaegeuk Kim 1801205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 1802205b9822SJaegeuk Kim { 1803205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 18047c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1805205b9822SJaegeuk Kim } 1806205b9822SJaegeuk Kim 180791942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 1808444c580fSJaegeuk Kim { 1809205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 1810205b9822SJaegeuk Kim 1811444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1812205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 18131001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 1814205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 181534d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1816205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 1817b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1818205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 1819510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1820205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 1821444c580fSJaegeuk Kim } 1822444c580fSJaegeuk Kim 182391942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 1824444c580fSJaegeuk Kim { 1825444c580fSJaegeuk Kim ri->i_inline = 0; 1826444c580fSJaegeuk Kim 182791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 1828444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 182991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 18301001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 183191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 183234d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 183391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 1834b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 183591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 1836510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1837444c580fSJaegeuk Kim } 1838444c580fSJaegeuk Kim 1839987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1840987c7c31SChao Yu { 184191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 1842987c7c31SChao Yu } 1843987c7c31SChao Yu 184481ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1845de93653fSJaegeuk Kim { 184681ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1847de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1848de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1849de93653fSJaegeuk Kim } 1850de93653fSJaegeuk Kim 185165985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 185265985d93SJaegeuk Kim { 1853695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1854cac5a3d8SDongOh Shin 185565985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 185665985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 185765985d93SJaegeuk Kim } 185865985d93SJaegeuk Kim 185965985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 186065985d93SJaegeuk Kim { 1861987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 186265985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 186365985d93SJaegeuk Kim else 186465985d93SJaegeuk Kim return 0; 186565985d93SJaegeuk Kim } 186665985d93SJaegeuk Kim 18670dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 18680dbdc2aeSJaegeuk Kim { 186991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 18700dbdc2aeSJaegeuk Kim } 18710dbdc2aeSJaegeuk Kim 1872b3d208f9SJaegeuk Kim static inline void f2fs_clear_inline_inode(struct inode *inode) 1873b3d208f9SJaegeuk Kim { 187491942321SJaegeuk Kim clear_inode_flag(inode, FI_INLINE_DATA); 187591942321SJaegeuk Kim clear_inode_flag(inode, FI_DATA_EXIST); 1876b3d208f9SJaegeuk Kim } 1877b3d208f9SJaegeuk Kim 1878b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1879b3d208f9SJaegeuk Kim { 188091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 1881b3d208f9SJaegeuk Kim } 1882b3d208f9SJaegeuk Kim 1883510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1884510022a8SJaegeuk Kim { 188591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 1886510022a8SJaegeuk Kim } 1887510022a8SJaegeuk Kim 188888b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 188988b88a66SJaegeuk Kim { 189091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 189188b88a66SJaegeuk Kim } 189288b88a66SJaegeuk Kim 18935fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 18945fe45743SChao Yu { 18955fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 18965fe45743SChao Yu } 18975fe45743SChao Yu 189802a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 189902a1335fSJaegeuk Kim { 190091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 190102a1335fSJaegeuk Kim } 190202a1335fSJaegeuk Kim 19033c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 19043c6c2bebSJaegeuk Kim { 190591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 19063c6c2bebSJaegeuk Kim } 19073c6c2bebSJaegeuk Kim 19081e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 19091e84371fSJaegeuk Kim { 191091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 19111e84371fSJaegeuk Kim } 19121e84371fSJaegeuk Kim 19131001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 19141001b347SHuajun Li { 1915695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1916cac5a3d8SDongOh Shin 19171001b347SHuajun Li return (void *)&(ri->i_addr[1]); 19181001b347SHuajun Li } 19191001b347SHuajun Li 192034d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 192134d67debSChao Yu { 192291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 192334d67debSChao Yu } 192434d67debSChao Yu 19259486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 19269486ba44SJaegeuk Kim { 19279486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 19289486ba44SJaegeuk Kim kunmap(page); 19299486ba44SJaegeuk Kim } 19309486ba44SJaegeuk Kim 1931b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1932b5492af7SJaegeuk Kim { 1933b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1934b5492af7SJaegeuk Kim } 1935b5492af7SJaegeuk Kim 1936b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1937b5492af7SJaegeuk Kim { 1938b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 19397c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1940b5492af7SJaegeuk Kim } 1941b5492af7SJaegeuk Kim 1942b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 1943b5492af7SJaegeuk Kim { 1944b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 19457c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1946b5492af7SJaegeuk Kim } 1947b5492af7SJaegeuk Kim 194826787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 194926787236SJaegeuk Kim { 195026787236SJaegeuk Kim if (dsync) { 195126787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 195226787236SJaegeuk Kim bool ret; 195326787236SJaegeuk Kim 195426787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 195526787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 195626787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 195726787236SJaegeuk Kim return ret; 195826787236SJaegeuk Kim } 195926787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 196026787236SJaegeuk Kim file_keep_isize(inode) || 196126787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 196226787236SJaegeuk Kim return false; 196326787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 1964267378d4SChao Yu } 1965267378d4SChao Yu 1966267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 1967267378d4SChao Yu { 1968267378d4SChao Yu return sb->s_flags & MS_RDONLY; 1969267378d4SChao Yu } 197039a53e0cSJaegeuk Kim 197139a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 197239a53e0cSJaegeuk Kim { 1973aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 197439a53e0cSJaegeuk Kim } 197539a53e0cSJaegeuk Kim 1976eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 1977eaa693f4SJaegeuk Kim { 1978eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 1979eaa693f4SJaegeuk Kim return true; 1980eaa693f4SJaegeuk Kim 1981eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 1982eaa693f4SJaegeuk Kim return true; 1983eaa693f4SJaegeuk Kim 1984eaa693f4SJaegeuk Kim return false; 1985eaa693f4SJaegeuk Kim } 1986eaa693f4SJaegeuk Kim 19873e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 19883e72f721SJaegeuk Kim { 19893e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 199091942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 19913e72f721SJaegeuk Kim return false; 19923e72f721SJaegeuk Kim 1993886f56f9SAl Viro return S_ISREG(inode->i_mode); 19943e72f721SJaegeuk Kim } 19953e72f721SJaegeuk Kim 19961ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 19971ecc0c5cSChao Yu size_t size, gfp_t flags) 19980414b004SJaegeuk Kim { 19992c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 200055523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 200155523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 20022c63feadSJaegeuk Kim return NULL; 200355523519SChao Yu } 20042c63feadSJaegeuk Kim #endif 20050414b004SJaegeuk Kim return kmalloc(size, flags); 20060414b004SJaegeuk Kim } 20070414b004SJaegeuk Kim 200839307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 200939307a8eSJaegeuk Kim { 201039307a8eSJaegeuk Kim void *ret; 201139307a8eSJaegeuk Kim 201239307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 201339307a8eSJaegeuk Kim if (!ret) 201439307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 201539307a8eSJaegeuk Kim return ret; 201639307a8eSJaegeuk Kim } 201739307a8eSJaegeuk Kim 201839307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 201939307a8eSJaegeuk Kim { 202039307a8eSJaegeuk Kim void *ret; 202139307a8eSJaegeuk Kim 202239307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 202339307a8eSJaegeuk Kim if (!ret) 202439307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 202539307a8eSJaegeuk Kim return ret; 202639307a8eSJaegeuk Kim } 202739307a8eSJaegeuk Kim 202839a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 202991942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 203039a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 203139a53e0cSJaegeuk Kim 203239a53e0cSJaegeuk Kim /* get offset of first page in next direct node */ 203381ca7350SChao Yu #define PGOFS_OF_NEXT_DNODE(pgofs, inode) \ 203481ca7350SChao Yu ((pgofs < ADDRS_PER_INODE(inode)) ? ADDRS_PER_INODE(inode) : \ 203581ca7350SChao Yu (pgofs - ADDRS_PER_INODE(inode) + ADDRS_PER_BLOCK) / \ 203681ca7350SChao Yu ADDRS_PER_BLOCK * ADDRS_PER_BLOCK + ADDRS_PER_INODE(inode)) 20371e1bb4baSJaegeuk Kim 203839a53e0cSJaegeuk Kim /* 20392d4d9fb5SJaegeuk Kim * file.c 204039a53e0cSJaegeuk Kim */ 2041cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2042cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2043cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2044cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2045a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2046a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2047cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2048cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2049cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2050cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2051cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 205239a53e0cSJaegeuk Kim 205339a53e0cSJaegeuk Kim /* 205439a53e0cSJaegeuk Kim * inode.c 205539a53e0cSJaegeuk Kim */ 2056cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2057cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2058cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2059cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2060cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2061cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2062cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2063cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2064cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 206539a53e0cSJaegeuk Kim 206639a53e0cSJaegeuk Kim /* 206739a53e0cSJaegeuk Kim * namei.c 206839a53e0cSJaegeuk Kim */ 206939a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 207039a53e0cSJaegeuk Kim 207139a53e0cSJaegeuk Kim /* 207239a53e0cSJaegeuk Kim * dir.c 207339a53e0cSJaegeuk Kim */ 2074cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2075cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2076cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2077cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2078cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2079cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2080cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2081cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2082cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2083cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2084cac5a3d8SDongOh Shin const struct qstr *new_name, 2085cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2086cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2087cac5a3d8SDongOh Shin unsigned int current_depth); 2088cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2089cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2090cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2091cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2092cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2093cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2094cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2095cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2096cac5a3d8SDongOh Shin struct page **page); 2097cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2098cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2099cac5a3d8SDongOh Shin int update_dent_inode(struct inode *inode, struct inode *to, 2100cac5a3d8SDongOh Shin const struct qstr *name); 2101cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2102cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2103cac5a3d8SDongOh Shin unsigned int bit_pos); 2104cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2105cac5a3d8SDongOh Shin const struct qstr *orig_name, 2106cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2107cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2108cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2109cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2110cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2111cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2112cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2113cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2114cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 211539a53e0cSJaegeuk Kim 2116b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2117b7f7a5e0SAl Viro { 21182b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2119510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2120b7f7a5e0SAl Viro } 2121b7f7a5e0SAl Viro 212239a53e0cSJaegeuk Kim /* 212339a53e0cSJaegeuk Kim * super.c 212439a53e0cSJaegeuk Kim */ 2125cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2126cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2127cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2128cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2129a07ef784SNamjae Jeon extern __printf(3, 4) 2130cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2131984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 213239a53e0cSJaegeuk Kim 213339a53e0cSJaegeuk Kim /* 213439a53e0cSJaegeuk Kim * hash.c 213539a53e0cSJaegeuk Kim */ 2136*6332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, 2137*6332cd32SJaegeuk Kim struct fscrypt_name *fname); 213839a53e0cSJaegeuk Kim 213939a53e0cSJaegeuk Kim /* 214039a53e0cSJaegeuk Kim * node.c 214139a53e0cSJaegeuk Kim */ 214239a53e0cSJaegeuk Kim struct dnode_of_data; 214339a53e0cSJaegeuk Kim struct node_info; 214439a53e0cSJaegeuk Kim 2145cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2146cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2147cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2148cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2149cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2150cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2151cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2152cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2153cac5a3d8SDongOh Shin int truncate_xattr_node(struct inode *inode, struct page *page); 2154cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2155cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2156cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 2157cac5a3d8SDongOh Shin struct page *new_node_page(struct dnode_of_data *dn, 2158cac5a3d8SDongOh Shin unsigned int ofs, struct page *ipage); 2159cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2160cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2161cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2162cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2163cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2164cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2165cac5a3d8SDongOh Shin int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc); 216622ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2167cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2168cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2169cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2170cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2171cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2172d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2173cac5a3d8SDongOh Shin block_t blkaddr); 2174cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2175cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2176cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 217722ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2178cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2179cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 21806e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 218139a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 218239a53e0cSJaegeuk Kim 218339a53e0cSJaegeuk Kim /* 218439a53e0cSJaegeuk Kim * segment.c 218539a53e0cSJaegeuk Kim */ 2186cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 2187cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 2188cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2189cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2190cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2191cac5a3d8SDongOh Shin int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2192cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2193cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2194cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2195cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2196cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2197cac5a3d8SDongOh Shin void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr); 2198cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2199cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2200cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2201cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2202cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2203cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2204cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2205cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2206cac5a3d8SDongOh Shin void write_meta_page(struct f2fs_sb_info *sbi, struct page *page); 2207cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2208cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2209cac5a3d8SDongOh Shin void rewrite_data_page(struct f2fs_io_info *fio); 2210cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2211cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2212cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2213cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2214cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2215cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2216cac5a3d8SDongOh Shin bool recover_newaddr); 2217cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2218cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2219cac5a3d8SDongOh Shin struct f2fs_summary *sum, int type); 2220cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2221cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2222cac5a3d8SDongOh Shin void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2223cac5a3d8SDongOh Shin block_t blkaddr); 2224cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2225cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2226cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2227cac5a3d8SDongOh Shin unsigned int val, int alloc); 2228cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2229cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2230cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 22317fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 22327fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 223339a53e0cSJaegeuk Kim 223439a53e0cSJaegeuk Kim /* 223539a53e0cSJaegeuk Kim * checkpoint.c 223639a53e0cSJaegeuk Kim */ 2237cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2238cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2239cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2240cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2241cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2242cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2243cac5a3d8SDongOh Shin int type, bool sync); 2244cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2245cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2246cac5a3d8SDongOh Shin long nr_to_write); 2247cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2248cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2249cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2250cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2251cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2252cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2253cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2254cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2255cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2256cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2257cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2258cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2259cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2260cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2261cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2262cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 22636e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 226439a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 226539a53e0cSJaegeuk Kim 226639a53e0cSJaegeuk Kim /* 226739a53e0cSJaegeuk Kim * data.c 226839a53e0cSJaegeuk Kim */ 2269cac5a3d8SDongOh Shin void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 2270cac5a3d8SDongOh Shin int rw); 2271cac5a3d8SDongOh Shin void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, 2272942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2273942fd319SJaegeuk Kim enum page_type type, int rw); 2274cac5a3d8SDongOh Shin void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi); 2275cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2276cac5a3d8SDongOh Shin int f2fs_submit_page_mbio(struct f2fs_io_info *fio); 2277cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2278cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2279cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2280cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2281cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2282cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2283cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2284cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2285cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2286cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2287cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2288cac5a3d8SDongOh Shin int op_flags, bool for_write); 2289cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2290cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2291cac5a3d8SDongOh Shin bool for_write); 2292cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2293cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2294cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2295cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2296cac5a3d8SDongOh Shin int create, int flag); 2297cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2298cac5a3d8SDongOh Shin u64 start, u64 len); 2299cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2300cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2301cac5a3d8SDongOh Shin unsigned int length); 2302cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 23035b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2304cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2305cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 23065b7a487cSWeichao Guo #endif 230739a53e0cSJaegeuk Kim 230839a53e0cSJaegeuk Kim /* 230939a53e0cSJaegeuk Kim * gc.c 231039a53e0cSJaegeuk Kim */ 2311cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2312cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2313cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2314cac5a3d8SDongOh Shin int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background); 2315cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 231639a53e0cSJaegeuk Kim 231739a53e0cSJaegeuk Kim /* 231839a53e0cSJaegeuk Kim * recovery.c 231939a53e0cSJaegeuk Kim */ 2320cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2321cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 232239a53e0cSJaegeuk Kim 232339a53e0cSJaegeuk Kim /* 232439a53e0cSJaegeuk Kim * debug.c 232539a53e0cSJaegeuk Kim */ 232639a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 232739a53e0cSJaegeuk Kim struct f2fs_stat_info { 232839a53e0cSJaegeuk Kim struct list_head stat_list; 232939a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 233039a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 233139a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 23325b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 23335b7ee374SChao Yu unsigned long long hit_total, total_ext; 2334c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 233535782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 233635782b23SJaegeuk Kim int inmem_pages; 23370f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 2338b8559dc2SChao Yu int nats, dirty_nats, sits, dirty_sits, free_nids, alloc_nids; 233939a53e0cSJaegeuk Kim int total_count, utilization; 2340dcc9165dSJaegeuk Kim int bg_gc, nr_wb_cp_data, nr_wb_data, nr_flush, nr_discard; 2341a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 234226a28a0cSJaegeuk Kim int aw_cnt, max_aw_cnt; 2343f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 234439a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 234539a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 234639a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 234739a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 234842190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 234939a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2350e1235983SChangman Lee int bg_node_segs, bg_data_segs; 235139a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2352e1235983SChangman Lee int bg_data_blks, bg_node_blks; 235339a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 235439a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 235539a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 235639a53e0cSJaegeuk Kim 235739a53e0cSJaegeuk Kim unsigned int segment_count[2]; 235839a53e0cSJaegeuk Kim unsigned int block_count[2]; 2359b9a2c252SChangman Lee unsigned int inplace_count; 23609edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 236139a53e0cSJaegeuk Kim }; 236239a53e0cSJaegeuk Kim 2363963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2364963d4f7dSGu Zheng { 2365963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2366963d4f7dSGu Zheng } 2367963d4f7dSGu Zheng 2368942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 236942190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 237039a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2371dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 237233fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 237333fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 23745b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 23755b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 23765b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 23775b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2378d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2379d5e8f6c9SChao Yu do { \ 2380d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2381d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2382d5e8f6c9SChao Yu } while (0) 2383d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2384d5e8f6c9SChao Yu do { \ 2385d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2386d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2387d5e8f6c9SChao Yu } while (0) 23880dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 23890dbdc2aeSJaegeuk Kim do { \ 23900dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 239103e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 23920dbdc2aeSJaegeuk Kim } while (0) 23930dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 23940dbdc2aeSJaegeuk Kim do { \ 23950dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 239603e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 23970dbdc2aeSJaegeuk Kim } while (0) 23983289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 23993289c061SJaegeuk Kim do { \ 24003289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 240103e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 24023289c061SJaegeuk Kim } while (0) 24033289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 24043289c061SJaegeuk Kim do { \ 24053289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 240603e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 24073289c061SJaegeuk Kim } while (0) 2408dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2409dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2410dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2411dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2412b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2413b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 241426a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2415cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 241626a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2417cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 241826a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 241926a28a0cSJaegeuk Kim do { \ 242026a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 242126a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 242226a28a0cSJaegeuk Kim if (cur > max) \ 242326a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 242426a28a0cSJaegeuk Kim } while (0) 2425e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 242639a53e0cSJaegeuk Kim do { \ 2427963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 242839a53e0cSJaegeuk Kim (si)->tot_segs++; \ 2429e1235983SChangman Lee if (type == SUM_TYPE_DATA) { \ 243039a53e0cSJaegeuk Kim si->data_segs++; \ 2431e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2432e1235983SChangman Lee } else { \ 243339a53e0cSJaegeuk Kim si->node_segs++; \ 2434e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2435e1235983SChangman Lee } \ 243639a53e0cSJaegeuk Kim } while (0) 243739a53e0cSJaegeuk Kim 243839a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 243939a53e0cSJaegeuk Kim (si->tot_blks += (blks)) 244039a53e0cSJaegeuk Kim 2441e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 244239a53e0cSJaegeuk Kim do { \ 2443963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 244439a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 244539a53e0cSJaegeuk Kim si->data_blks += (blks); \ 2446e1235983SChangman Lee si->bg_data_blks += (gc_type == BG_GC) ? (blks) : 0; \ 244739a53e0cSJaegeuk Kim } while (0) 244839a53e0cSJaegeuk Kim 2449e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 245039a53e0cSJaegeuk Kim do { \ 2451963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 245239a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 245339a53e0cSJaegeuk Kim si->node_blks += (blks); \ 2454e1235983SChangman Lee si->bg_node_blks += (gc_type == BG_GC) ? (blks) : 0; \ 245539a53e0cSJaegeuk Kim } while (0) 245639a53e0cSJaegeuk Kim 2457cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2458cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2459787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 24604589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 246139a53e0cSJaegeuk Kim #else 2462942e0be6SChangman Lee #define stat_inc_cp_count(si) 246342190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) 246439a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 2465dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 246633fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) 246733fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) 2468dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 2469029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 247091c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 247191c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 2472d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 2473d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 24740dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 24750dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 24763289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 24773289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 247826a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) 247926a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) 248026a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) 2481dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 2482dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 2483b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 2484e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 248539a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 2486e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 2487e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 248839a53e0cSJaegeuk Kim 248939a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 249039a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2491787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 24924589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 249339a53e0cSJaegeuk Kim #endif 249439a53e0cSJaegeuk Kim 249539a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 249639a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 249739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 249839a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 249939a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 250039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 250139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 250239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2503cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 250439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 250529e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 25061001b347SHuajun Li 2507e18c65b2SHuajun Li /* 2508e18c65b2SHuajun Li * inline.c 2509e18c65b2SHuajun Li */ 2510cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2511cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2512cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2513cac5a3d8SDongOh Shin bool truncate_inline_inode(struct page *ipage, u64 from); 2514cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2515cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2516cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2517cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2518cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2519cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2520cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2521cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2522cac5a3d8SDongOh Shin struct page *ipage); 2523cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2524cac5a3d8SDongOh Shin const struct qstr *orig_name, 2525cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2526cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2527cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2528cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2529cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2530cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2531cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2532cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2533cac5a3d8SDongOh Shin __u64 start, __u64 len); 2534cde4de12SJaegeuk Kim 2535cde4de12SJaegeuk Kim /* 25362658e50dSJaegeuk Kim * shrinker.c 25372658e50dSJaegeuk Kim */ 2538cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2539cac5a3d8SDongOh Shin struct shrink_control *sc); 2540cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2541cac5a3d8SDongOh Shin struct shrink_control *sc); 2542cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2543cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 25442658e50dSJaegeuk Kim 25452658e50dSJaegeuk Kim /* 2546a28ef1f5SChao Yu * extent_cache.c 2547a28ef1f5SChao Yu */ 2548cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2549cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2550cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2551cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2552cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2553cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2554cac5a3d8SDongOh Shin struct extent_info *ei); 2555cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 255619b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2557cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2558cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2559a28ef1f5SChao Yu int __init create_extent_cache(void); 2560a28ef1f5SChao Yu void destroy_extent_cache(void); 2561a28ef1f5SChao Yu 2562a28ef1f5SChao Yu /* 2563cde4de12SJaegeuk Kim * crypto support 2564cde4de12SJaegeuk Kim */ 25650b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2566cde4de12SJaegeuk Kim { 2567cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2568cde4de12SJaegeuk Kim } 2569cde4de12SJaegeuk Kim 2570cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2571cde4de12SJaegeuk Kim { 2572cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2573cde4de12SJaegeuk Kim file_set_encrypt(inode); 2574cde4de12SJaegeuk Kim #endif 2575cde4de12SJaegeuk Kim } 2576cde4de12SJaegeuk Kim 2577cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2578cde4de12SJaegeuk Kim { 25790b81d077SJaegeuk Kim return bio->bi_private != NULL; 2580cde4de12SJaegeuk Kim } 2581cde4de12SJaegeuk Kim 2582cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2583cde4de12SJaegeuk Kim { 2584cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2585cde4de12SJaegeuk Kim } 2586f424f664SJaegeuk Kim 25870bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 258852763a4bSJaegeuk Kim { 25890bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 259052763a4bSJaegeuk Kim } 259152763a4bSJaegeuk Kim 2592178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2593178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 25943c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2595178053e2SDamien Le Moal { 2596178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 25973c62be17SJaegeuk Kim int i; 2598178053e2SDamien Le Moal 25993c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 26003c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 26013c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 26023c62be17SJaegeuk Kim return -EINVAL; 2603178053e2SDamien Le Moal } 2604178053e2SDamien Le Moal #endif 2605178053e2SDamien Le Moal 260696ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 260796ba2decSDamien Le Moal { 260896ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 260996ba2decSDamien Le Moal 261096ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 261152763a4bSJaegeuk Kim } 261252763a4bSJaegeuk Kim 261352763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 261452763a4bSJaegeuk Kim { 261552763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 261652763a4bSJaegeuk Kim clear_opt(sbi, LFS); 261752763a4bSJaegeuk Kim 261852763a4bSJaegeuk Kim switch (mt) { 261952763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 262052763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 262152763a4bSJaegeuk Kim break; 262252763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 262352763a4bSJaegeuk Kim set_opt(sbi, LFS); 262452763a4bSJaegeuk Kim break; 262552763a4bSJaegeuk Kim } 262652763a4bSJaegeuk Kim } 262752763a4bSJaegeuk Kim 2628fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2629fcc85a4dSJaegeuk Kim { 2630fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2631886f56f9SAl Viro umode_t mode = inode->i_mode; 2632fcc85a4dSJaegeuk Kim 2633fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2634fcc85a4dSJaegeuk Kim #else 2635fcc85a4dSJaegeuk Kim return 0; 2636fcc85a4dSJaegeuk Kim #endif 2637fcc85a4dSJaegeuk Kim } 2638fcc85a4dSJaegeuk Kim 263939a53e0cSJaegeuk Kim #endif 2640