10a8165d7SJaegeuk Kim /* 239a53e0cSJaegeuk Kim * fs/f2fs/f2fs.h 339a53e0cSJaegeuk Kim * 439a53e0cSJaegeuk Kim * Copyright (c) 2012 Samsung Electronics Co., Ltd. 539a53e0cSJaegeuk Kim * http://www.samsung.com/ 639a53e0cSJaegeuk Kim * 739a53e0cSJaegeuk Kim * This program is free software; you can redistribute it and/or modify 839a53e0cSJaegeuk Kim * it under the terms of the GNU General Public License version 2 as 939a53e0cSJaegeuk Kim * published by the Free Software Foundation. 1039a53e0cSJaegeuk Kim */ 1139a53e0cSJaegeuk Kim #ifndef _LINUX_F2FS_H 1239a53e0cSJaegeuk Kim #define _LINUX_F2FS_H 1339a53e0cSJaegeuk Kim 1439a53e0cSJaegeuk Kim #include <linux/types.h> 1539a53e0cSJaegeuk Kim #include <linux/page-flags.h> 1639a53e0cSJaegeuk Kim #include <linux/buffer_head.h> 1739a53e0cSJaegeuk Kim #include <linux/slab.h> 1839a53e0cSJaegeuk Kim #include <linux/crc32.h> 1939a53e0cSJaegeuk Kim #include <linux/magic.h> 20c2d715d1SJaegeuk Kim #include <linux/kobject.h> 217bd59381SGu Zheng #include <linux/sched.h> 2239307a8eSJaegeuk Kim #include <linux/vmalloc.h> 23740432f8SJaegeuk Kim #include <linux/bio.h> 24d0239e1bSJaegeuk Kim #include <linux/blkdev.h> 2546f47e48SEric Biggers #ifdef CONFIG_F2FS_FS_ENCRYPTION 2646f47e48SEric Biggers #include <linux/fscrypt_supp.h> 2746f47e48SEric Biggers #else 2846f47e48SEric Biggers #include <linux/fscrypt_notsupp.h> 2946f47e48SEric Biggers #endif 3043b6573bSKeith Mok #include <crypto/hash.h> 3139a53e0cSJaegeuk Kim 325d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 339850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 345d56b671SJaegeuk Kim #else 359850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 369850cf4aSJaegeuk Kim do { \ 379850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 389850cf4aSJaegeuk Kim WARN_ON(1); \ 39caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 409850cf4aSJaegeuk Kim } \ 419850cf4aSJaegeuk Kim } while (0) 425d56b671SJaegeuk Kim #endif 435d56b671SJaegeuk Kim 442c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 452c63feadSJaegeuk Kim enum { 462c63feadSJaegeuk Kim FAULT_KMALLOC, 47c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 48cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 49cb78942bSJaegeuk Kim FAULT_ORPHAN, 50cb78942bSJaegeuk Kim FAULT_BLOCK, 51cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5253aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 5314b44d23SJaegeuk Kim FAULT_TRUNCATE, 548b038c70SChao Yu FAULT_IO, 550f348028SChao Yu FAULT_CHECKPOINT, 562c63feadSJaegeuk Kim FAULT_MAX, 572c63feadSJaegeuk Kim }; 582c63feadSJaegeuk Kim 5908796897SSheng Yong struct f2fs_fault_info { 6008796897SSheng Yong atomic_t inject_ops; 6108796897SSheng Yong unsigned int inject_rate; 6208796897SSheng Yong unsigned int inject_type; 6308796897SSheng Yong }; 6408796897SSheng Yong 652c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX]; 6668afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 672c63feadSJaegeuk Kim #endif 682c63feadSJaegeuk Kim 6939a53e0cSJaegeuk Kim /* 7039a53e0cSJaegeuk Kim * For mount options 7139a53e0cSJaegeuk Kim */ 7239a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 7339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7439a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7539a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 79444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 801001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8134d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8234d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8334d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 84d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8589672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 866aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 87343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 8873faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 8936abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 9036abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 9139a53e0cSJaegeuk Kim 9268afcf2dSTomohiro Kusumi #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) 9368afcf2dSTomohiro Kusumi #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) 9468afcf2dSTomohiro Kusumi #define test_opt(sbi, option) ((sbi)->mount_opt.opt & F2FS_MOUNT_##option) 9539a53e0cSJaegeuk Kim 9639a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 9739a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 9839a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 9939a53e0cSJaegeuk Kim 100a9841c4dSJaegeuk Kim typedef u32 block_t; /* 101a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 102a9841c4dSJaegeuk Kim * address format, __le32. 103a9841c4dSJaegeuk Kim */ 10439a53e0cSJaegeuk Kim typedef u32 nid_t; 10539a53e0cSJaegeuk Kim 10639a53e0cSJaegeuk Kim struct f2fs_mount_info { 10739a53e0cSJaegeuk Kim unsigned int opt; 10839a53e0cSJaegeuk Kim }; 10939a53e0cSJaegeuk Kim 110cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1110bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 112cde4de12SJaegeuk Kim 11376f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 11476f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 11576f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 116c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 11776f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 118c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 11976f105a2SJaegeuk Kim 12039a53e0cSJaegeuk Kim /* 12139a53e0cSJaegeuk Kim * For checkpoint manager 12239a53e0cSJaegeuk Kim */ 12339a53e0cSJaegeuk Kim enum { 12439a53e0cSJaegeuk Kim NAT_BITMAP, 12539a53e0cSJaegeuk Kim SIT_BITMAP 12639a53e0cSJaegeuk Kim }; 12739a53e0cSJaegeuk Kim 12875ab4cb8SJaegeuk Kim enum { 12975ab4cb8SJaegeuk Kim CP_UMOUNT, 130119ee914SJaegeuk Kim CP_FASTBOOT, 13175ab4cb8SJaegeuk Kim CP_SYNC, 13210027551SJaegeuk Kim CP_RECOVERY, 1334b2fecc8SJaegeuk Kim CP_DISCARD, 13475ab4cb8SJaegeuk Kim }; 13575ab4cb8SJaegeuk Kim 13647b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 137bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 1384ddb1a4dSJaegeuk Kim (GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections)) 139a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 140a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 1414ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 14215469963SJaegeuk Kim #define DISCARD_ISSUE_RATE 8 14360b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 144dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 145bba681cbSJaegeuk Kim 14675ab4cb8SJaegeuk Kim struct cp_control { 14775ab4cb8SJaegeuk Kim int reason; 1484b2fecc8SJaegeuk Kim __u64 trim_start; 1494b2fecc8SJaegeuk Kim __u64 trim_end; 1504b2fecc8SJaegeuk Kim __u64 trim_minlen; 1514b2fecc8SJaegeuk Kim __u64 trimmed; 15275ab4cb8SJaegeuk Kim }; 15375ab4cb8SJaegeuk Kim 154662befdaSChao Yu /* 15581c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 156662befdaSChao Yu */ 157662befdaSChao Yu enum { 158662befdaSChao Yu META_CP, 159662befdaSChao Yu META_NAT, 16081c1a0f1SChao Yu META_SIT, 1614c521f49SJaegeuk Kim META_SSA, 1624c521f49SJaegeuk Kim META_POR, 163662befdaSChao Yu }; 164662befdaSChao Yu 1656451e041SJaegeuk Kim /* for the list of ino */ 1666451e041SJaegeuk Kim enum { 1676451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 168fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 169fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1706451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1716451e041SJaegeuk Kim }; 1726451e041SJaegeuk Kim 1736451e041SJaegeuk Kim struct ino_entry { 17439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 17539a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 17639a53e0cSJaegeuk Kim }; 17739a53e0cSJaegeuk Kim 1782710fd7eSChao Yu /* for the list of inodes to be GCed */ 17906292073SChao Yu struct inode_entry { 18039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 18239a53e0cSJaegeuk Kim }; 18339a53e0cSJaegeuk Kim 184a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 1857fd9e544SJaegeuk Kim struct discard_entry { 1867fd9e544SJaegeuk Kim struct list_head list; /* list head */ 187a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 188a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 1897fd9e544SJaegeuk Kim }; 1907fd9e544SJaegeuk Kim 191*ba48a33eSChao Yu /* max discard pend list number */ 192*ba48a33eSChao Yu #define MAX_PLIST_NUM 512 193*ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 194*ba48a33eSChao Yu (MAX_PLIST_NUM - 1) : (blk_num - 1)) 195*ba48a33eSChao Yu 19615469963SJaegeuk Kim enum { 19715469963SJaegeuk Kim D_PREP, 19815469963SJaegeuk Kim D_SUBMIT, 19915469963SJaegeuk Kim D_DONE, 20015469963SJaegeuk Kim }; 20115469963SJaegeuk Kim 202004b6862SChao Yu struct discard_info { 203004b6862SChao Yu block_t lstart; /* logical start address */ 204004b6862SChao Yu block_t len; /* length */ 205004b6862SChao Yu block_t start; /* actual start address in dev */ 206004b6862SChao Yu }; 207004b6862SChao Yu 208b01a9201SJaegeuk Kim struct discard_cmd { 209004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 210004b6862SChao Yu union { 211004b6862SChao Yu struct { 212004b6862SChao Yu block_t lstart; /* logical start address */ 213004b6862SChao Yu block_t len; /* length */ 214004b6862SChao Yu block_t start; /* actual start address in dev */ 215004b6862SChao Yu }; 216004b6862SChao Yu struct discard_info di; /* discard info */ 217004b6862SChao Yu 218004b6862SChao Yu }; 219b01a9201SJaegeuk Kim struct list_head list; /* command list */ 220b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 221c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 22215469963SJaegeuk Kim int state; /* state */ 223c81abe34SJaegeuk Kim int error; /* bio error */ 224275b66b0SChao Yu }; 225275b66b0SChao Yu 2260b54fb84SJaegeuk Kim struct discard_cmd_control { 22715469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 22846f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 229*ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 23046f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 23115469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 23215469963SJaegeuk Kim struct mutex cmd_lock; 23346f84c2cSChao Yu int nr_discards; /* # of discards in the list */ 2340b54fb84SJaegeuk Kim int max_discards; /* max. discards to be issued */ 2358b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 2368b8dd65fSChao Yu atomic_t issing_discard; /* # of issing discard */ 2375f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 238004b6862SChao Yu struct rb_root root; /* root of discard rb-tree */ 23939a53e0cSJaegeuk Kim }; 24039a53e0cSJaegeuk Kim 24139a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 24239a53e0cSJaegeuk Kim struct fsync_inode_entry { 24339a53e0cSJaegeuk Kim struct list_head list; /* list head */ 24439a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 245c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 246c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 24739a53e0cSJaegeuk Kim }; 24839a53e0cSJaegeuk Kim 24968afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 25068afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 25139a53e0cSJaegeuk Kim 25268afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 25368afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 25468afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 25568afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 25639a53e0cSJaegeuk Kim 257dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 258dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 259309cc2b6SJaegeuk Kim 260dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 26139a53e0cSJaegeuk Kim { 262dfc08a12SChao Yu int before = nats_in_cursum(journal); 263cac5a3d8SDongOh Shin 264dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 26539a53e0cSJaegeuk Kim return before; 26639a53e0cSJaegeuk Kim } 26739a53e0cSJaegeuk Kim 268dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 26939a53e0cSJaegeuk Kim { 270dfc08a12SChao Yu int before = sits_in_cursum(journal); 271cac5a3d8SDongOh Shin 272dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 27339a53e0cSJaegeuk Kim return before; 27439a53e0cSJaegeuk Kim } 27539a53e0cSJaegeuk Kim 276dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 277dfc08a12SChao Yu int size, int type) 278184a5cd2SChao Yu { 279184a5cd2SChao Yu if (type == NAT_JOURNAL) 280dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 281dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 282184a5cd2SChao Yu } 283184a5cd2SChao Yu 28439a53e0cSJaegeuk Kim /* 285e9750824SNamjae Jeon * ioctl commands 286e9750824SNamjae Jeon */ 287e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 288e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 289d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 290e9750824SNamjae Jeon 29188b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 29288b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 29388b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 29402a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 2951e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 2961e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 297c1c1b583SChao Yu #define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6) 298456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 299d323d005SChao Yu #define F2FS_IOC_DEFRAGMENT _IO(F2FS_IOCTL_MAGIC, 8) 3004dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 3014dd6f977SJaegeuk Kim struct f2fs_move_range) 30288b88a66SJaegeuk Kim 3030b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 3040b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 3050b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 306f424f664SJaegeuk Kim 3071abff93dSJaegeuk Kim /* 3081abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 3091abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 3101abff93dSJaegeuk Kim */ 3111abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 3121abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 3131abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 3141abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 315c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 3161abff93dSJaegeuk Kim 317e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 318e9750824SNamjae Jeon /* 319e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 320e9750824SNamjae Jeon */ 321e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 322e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 32304ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 324e9750824SNamjae Jeon #endif 325e9750824SNamjae Jeon 326d323d005SChao Yu struct f2fs_defragment { 327d323d005SChao Yu u64 start; 328d323d005SChao Yu u64 len; 329d323d005SChao Yu }; 330d323d005SChao Yu 3314dd6f977SJaegeuk Kim struct f2fs_move_range { 3324dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3334dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3344dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3354dd6f977SJaegeuk Kim u64 len; /* size to move */ 3364dd6f977SJaegeuk Kim }; 3374dd6f977SJaegeuk Kim 338e9750824SNamjae Jeon /* 33939a53e0cSJaegeuk Kim * For INODE and NODE manager 34039a53e0cSJaegeuk Kim */ 3417b3cd7d6SJaegeuk Kim /* for directory operations */ 3427b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 343d8c6822aSJaegeuk Kim struct inode *inode; 3447b3cd7d6SJaegeuk Kim const void *bitmap; 3457b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 3467b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 3477b3cd7d6SJaegeuk Kim int max; 3487b3cd7d6SJaegeuk Kim }; 3497b3cd7d6SJaegeuk Kim 35064c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 35164c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 3527b3cd7d6SJaegeuk Kim { 353d8c6822aSJaegeuk Kim d->inode = inode; 3547b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 3557b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3567b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3577b3cd7d6SJaegeuk Kim d->filename = t->filename; 35864c24ecbSTomohiro Kusumi } 359cac5a3d8SDongOh Shin 36064c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 36164c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_inline_dentry *t) 36264c24ecbSTomohiro Kusumi { 36364c24ecbSTomohiro Kusumi d->inode = inode; 3647b3cd7d6SJaegeuk Kim d->max = NR_INLINE_DENTRY; 3657b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 3667b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 3677b3cd7d6SJaegeuk Kim d->filename = t->filename; 3687b3cd7d6SJaegeuk Kim } 3697b3cd7d6SJaegeuk Kim 370dbe6a5ffSJaegeuk Kim /* 371dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 372dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 373dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 37439a53e0cSJaegeuk Kim */ 375dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 376dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 377266e97a8SJaegeuk Kim enum { 378266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 379266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 380266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 381266e97a8SJaegeuk Kim * look up a node with readahead called 3824f4124d0SChao Yu * by get_data_block. 38339a53e0cSJaegeuk Kim */ 384266e97a8SJaegeuk Kim }; 385266e97a8SJaegeuk Kim 386a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 38739a53e0cSJaegeuk Kim 388817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 389817202d9SChao Yu 39013054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 39113054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 39213054c54SChao Yu 39339a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 39413054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 39513054c54SChao Yu 39613054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 39713054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 398c11abd1aSJaegeuk Kim 39954c2258cSChao Yu struct rb_entry { 40054c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 40154c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 40254c2258cSChao Yu unsigned int len; /* length of the entry */ 40354c2258cSChao Yu }; 40454c2258cSChao Yu 40539a53e0cSJaegeuk Kim struct extent_info { 40639a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 407111d2495SMasanari Iida unsigned int len; /* length of the extent */ 40854c2258cSChao Yu u32 blk; /* start block address of the extent */ 40939a53e0cSJaegeuk Kim }; 41039a53e0cSJaegeuk Kim 41113054c54SChao Yu struct extent_node { 41254c2258cSChao Yu struct rb_node rb_node; 41354c2258cSChao Yu union { 41454c2258cSChao Yu struct { 41554c2258cSChao Yu unsigned int fofs; 41654c2258cSChao Yu unsigned int len; 41754c2258cSChao Yu u32 blk; 41854c2258cSChao Yu }; 41913054c54SChao Yu struct extent_info ei; /* extent info */ 42054c2258cSChao Yu 42154c2258cSChao Yu }; 42254c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 423201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 42413054c54SChao Yu }; 42513054c54SChao Yu 42613054c54SChao Yu struct extent_tree { 42713054c54SChao Yu nid_t ino; /* inode number */ 42813054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 42962c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 4303e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 431137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 43213054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 43368e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 43413054c54SChao Yu }; 43513054c54SChao Yu 43639a53e0cSJaegeuk Kim /* 437003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 438003a3e1dSJaegeuk Kim * 439003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 440003a3e1dSJaegeuk Kim */ 441003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 442003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 4437f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 4447f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 4457f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 446003a3e1dSJaegeuk Kim 447003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 448003a3e1dSJaegeuk Kim block_t m_pblk; 449003a3e1dSJaegeuk Kim block_t m_lblk; 450003a3e1dSJaegeuk Kim unsigned int m_len; 451003a3e1dSJaegeuk Kim unsigned int m_flags; 452da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 453003a3e1dSJaegeuk Kim }; 454003a3e1dSJaegeuk Kim 455e2b4e2bcSChao Yu /* for flag in get_data_block */ 456e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_READ 0 457e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_DIO 1 458e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_FIEMAP 2 459e2b4e2bcSChao Yu #define F2FS_GET_BLOCK_BMAP 3 460b439b103SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_DIO 4 46124b84912SJaegeuk Kim #define F2FS_GET_BLOCK_PRE_AIO 5 462e2b4e2bcSChao Yu 463003a3e1dSJaegeuk Kim /* 46439a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 46539a53e0cSJaegeuk Kim */ 46639a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 467354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 468cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 469e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 47026787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 47139a53e0cSJaegeuk Kim 472b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 473b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 474b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 475b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 476b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 477b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 478cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 479cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 480cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 481e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 482e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 48326787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 48426787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 485cde4de12SJaegeuk Kim 486ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 487ab9fa662SJaegeuk Kim 48839a53e0cSJaegeuk Kim struct f2fs_inode_info { 48939a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 49039a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 49139a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 49238431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 49339a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 4946666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 49539a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 49639a53e0cSJaegeuk Kim 49739a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 49839a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 499d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 500204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 50139a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 50239a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 50388c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 50439a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 50526de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 50688b88a66SJaegeuk Kim 5070f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 5080f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 50988b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 51088b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 5113e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 51282e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 51339a53e0cSJaegeuk Kim }; 51439a53e0cSJaegeuk Kim 51539a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 516bd933d4fSChao Yu struct f2fs_extent *i_ext) 51739a53e0cSJaegeuk Kim { 518bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 519bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 520bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 52139a53e0cSJaegeuk Kim } 52239a53e0cSJaegeuk Kim 52339a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 52439a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 52539a53e0cSJaegeuk Kim { 52639a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 5274d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 52839a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 52939a53e0cSJaegeuk Kim } 53039a53e0cSJaegeuk Kim 531429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 532429511cdSChao Yu u32 blk, unsigned int len) 533429511cdSChao Yu { 534429511cdSChao Yu ei->fofs = fofs; 535429511cdSChao Yu ei->blk = blk; 536429511cdSChao Yu ei->len = len; 537429511cdSChao Yu } 538429511cdSChao Yu 539004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 540004b6862SChao Yu struct discard_info *front) 541004b6862SChao Yu { 542004b6862SChao Yu return back->lstart + back->len == front->lstart; 543004b6862SChao Yu } 544004b6862SChao Yu 545004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 546004b6862SChao Yu struct discard_info *back) 547004b6862SChao Yu { 548004b6862SChao Yu return __is_discard_mergeable(back, cur); 549004b6862SChao Yu } 550004b6862SChao Yu 551004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 552004b6862SChao Yu struct discard_info *front) 553004b6862SChao Yu { 554004b6862SChao Yu return __is_discard_mergeable(cur, front); 555004b6862SChao Yu } 556004b6862SChao Yu 557429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 558429511cdSChao Yu struct extent_info *front) 559429511cdSChao Yu { 560429511cdSChao Yu return (back->fofs + back->len == front->fofs && 561429511cdSChao Yu back->blk + back->len == front->blk); 562429511cdSChao Yu } 563429511cdSChao Yu 564429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 565429511cdSChao Yu struct extent_info *back) 566429511cdSChao Yu { 567429511cdSChao Yu return __is_extent_mergeable(back, cur); 568429511cdSChao Yu } 569429511cdSChao Yu 570429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 571429511cdSChao Yu struct extent_info *front) 572429511cdSChao Yu { 573429511cdSChao Yu return __is_extent_mergeable(cur, front); 574429511cdSChao Yu } 575429511cdSChao Yu 576cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 577205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 578205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 5794abd3f5aSChao Yu { 580205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 5814abd3f5aSChao Yu et->largest = en->ei; 5827c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 583205b9822SJaegeuk Kim } 5844abd3f5aSChao Yu } 5854abd3f5aSChao Yu 586b8559dc2SChao Yu enum nid_list { 587b8559dc2SChao Yu FREE_NID_LIST, 588b8559dc2SChao Yu ALLOC_NID_LIST, 589b8559dc2SChao Yu MAX_NID_LIST, 590b8559dc2SChao Yu }; 591b8559dc2SChao Yu 59239a53e0cSJaegeuk Kim struct f2fs_nm_info { 59339a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 59439a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 59504d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 59639a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 597cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 598ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 5992304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 60039a53e0cSJaegeuk Kim 60139a53e0cSJaegeuk Kim /* NAT cache management */ 60239a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 603309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 604b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 60539a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 606309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 607aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 60822ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 60939a53e0cSJaegeuk Kim 61039a53e0cSJaegeuk Kim /* free node ids management */ 6118a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 612b8559dc2SChao Yu struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ 613b8559dc2SChao Yu unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 614b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 61539a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 6164ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 6174ac91242SChao Yu unsigned char *nat_block_bitmap; 618586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 61939a53e0cSJaegeuk Kim 62039a53e0cSJaegeuk Kim /* for checkpoint */ 62139a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 62222ad0b6aSJaegeuk Kim 62322ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 62422ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 62522ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 62622ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 627599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 628599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 629599a09b2SChao Yu #endif 63039a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 63139a53e0cSJaegeuk Kim }; 63239a53e0cSJaegeuk Kim 63339a53e0cSJaegeuk Kim /* 63439a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 63539a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 63639a53e0cSJaegeuk Kim * by the data offset in a file. 63739a53e0cSJaegeuk Kim */ 63839a53e0cSJaegeuk Kim struct dnode_of_data { 63939a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 64039a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 64139a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 64239a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 64339a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 64439a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 64593bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 6463cf45747SChao Yu char cur_level; /* level of hole node page */ 6473cf45747SChao Yu char max_level; /* level of current page located */ 64839a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 64939a53e0cSJaegeuk Kim }; 65039a53e0cSJaegeuk Kim 65139a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 65239a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 65339a53e0cSJaegeuk Kim { 654d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 65539a53e0cSJaegeuk Kim dn->inode = inode; 65639a53e0cSJaegeuk Kim dn->inode_page = ipage; 65739a53e0cSJaegeuk Kim dn->node_page = npage; 65839a53e0cSJaegeuk Kim dn->nid = nid; 65939a53e0cSJaegeuk Kim } 66039a53e0cSJaegeuk Kim 66139a53e0cSJaegeuk Kim /* 66239a53e0cSJaegeuk Kim * For SIT manager 66339a53e0cSJaegeuk Kim * 66439a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 66539a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 66639a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 66739a53e0cSJaegeuk Kim * respectively. 66839a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 66939a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 67039a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 67139a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 67239a53e0cSJaegeuk Kim * data and 8 for node logs. 67339a53e0cSJaegeuk Kim */ 67439a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 67539a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 67639a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 67739a53e0cSJaegeuk Kim 67839a53e0cSJaegeuk Kim enum { 67939a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 68039a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 68139a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 68239a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 68339a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 68439a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 68538aa0889SJaegeuk Kim NO_CHECK_TYPE, 68639a53e0cSJaegeuk Kim }; 68739a53e0cSJaegeuk Kim 6886b4afdd7SJaegeuk Kim struct flush_cmd { 6896b4afdd7SJaegeuk Kim struct completion wait; 690721bd4d5SGu Zheng struct llist_node llnode; 6916b4afdd7SJaegeuk Kim int ret; 6926b4afdd7SJaegeuk Kim }; 6936b4afdd7SJaegeuk Kim 694a688b9d9SGu Zheng struct flush_cmd_control { 695a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 696a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 6978b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 6988b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 699721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 700721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 701a688b9d9SGu Zheng }; 702a688b9d9SGu Zheng 70339a53e0cSJaegeuk Kim struct f2fs_sm_info { 70439a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 70539a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 70639a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 70739a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 70839a53e0cSJaegeuk Kim 70939a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 71039a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 71139a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 71239a53e0cSJaegeuk Kim 71339a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 71439a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 71539a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 71639a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 71781eb8d6eSJaegeuk Kim 71881eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 71981eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 7207fd9e544SJaegeuk Kim 721bba681cbSJaegeuk Kim /* for batched trimming */ 722bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 723bba681cbSJaegeuk Kim 724184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 725184a5cd2SChao Yu 726216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 727216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 728c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 729ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 7306b4afdd7SJaegeuk Kim 7316b4afdd7SJaegeuk Kim /* for flush command control */ 732b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 733a688b9d9SGu Zheng 7340b54fb84SJaegeuk Kim /* for discard command control */ 7350b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 73639a53e0cSJaegeuk Kim }; 73739a53e0cSJaegeuk Kim 73839a53e0cSJaegeuk Kim /* 73939a53e0cSJaegeuk Kim * For superblock 74039a53e0cSJaegeuk Kim */ 74139a53e0cSJaegeuk Kim /* 74239a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 74339a53e0cSJaegeuk Kim * 74439a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 74539a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 74639a53e0cSJaegeuk Kim */ 74736951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 74839a53e0cSJaegeuk Kim enum count_type { 74939a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 750c227f912SChao Yu F2FS_DIRTY_DATA, 75139a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 75239a53e0cSJaegeuk Kim F2FS_DIRTY_META, 7538dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 7540f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 75536951b38SChao Yu F2FS_WB_CP_DATA, 75636951b38SChao Yu F2FS_WB_DATA, 75739a53e0cSJaegeuk Kim NR_COUNT_TYPE, 75839a53e0cSJaegeuk Kim }; 75939a53e0cSJaegeuk Kim 76039a53e0cSJaegeuk Kim /* 761e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 76239a53e0cSJaegeuk Kim * The available types are: 76339a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 76439a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 76539a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 76639a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 76739a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 76839a53e0cSJaegeuk Kim * with waiting the bio's completion 76939a53e0cSJaegeuk Kim * ... Only can be used with META. 77039a53e0cSJaegeuk Kim */ 7717d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 77239a53e0cSJaegeuk Kim enum page_type { 77339a53e0cSJaegeuk Kim DATA, 77439a53e0cSJaegeuk Kim NODE, 77539a53e0cSJaegeuk Kim META, 77639a53e0cSJaegeuk Kim NR_PAGE_TYPE, 77739a53e0cSJaegeuk Kim META_FLUSH, 7788ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 7798ce67cb0SJaegeuk Kim INMEM_DROP, 7808c242db9SJaegeuk Kim INMEM_INVALIDATE, 78128bc106bSChao Yu INMEM_REVOKE, 7828ce67cb0SJaegeuk Kim IPU, 7838ce67cb0SJaegeuk Kim OPU, 78439a53e0cSJaegeuk Kim }; 78539a53e0cSJaegeuk Kim 786458e6197SJaegeuk Kim struct f2fs_io_info { 78705ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 788458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 78904d328deSMike Christie int op; /* contains REQ_OP_ */ 790ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 7917a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 79228bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 79305ca3632SJaegeuk Kim struct page *page; /* page to be written */ 7944375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 795d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 796458e6197SJaegeuk Kim }; 797458e6197SJaegeuk Kim 79868afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 7991ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 800458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 8011ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 8021ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 803458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 804df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 8051ff7bd3bSJaegeuk Kim }; 8061ff7bd3bSJaegeuk Kim 8073c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 8083c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 8093c62be17SJaegeuk Kim struct f2fs_dev_info { 8103c62be17SJaegeuk Kim struct block_device *bdev; 8113c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 8123c62be17SJaegeuk Kim unsigned int total_segments; 8133c62be17SJaegeuk Kim block_t start_blk; 8143c62be17SJaegeuk Kim block_t end_blk; 8153c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 8163c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 8173c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 8183c62be17SJaegeuk Kim #endif 8193c62be17SJaegeuk Kim }; 8203c62be17SJaegeuk Kim 821c227f912SChao Yu enum inode_type { 822c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 823c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 8240f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 825c227f912SChao Yu NR_INODE_TYPE, 826c227f912SChao Yu }; 827c227f912SChao Yu 82867298804SChao Yu /* for inner inode cache management */ 82967298804SChao Yu struct inode_management { 83067298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 83167298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 83267298804SChao Yu struct list_head ino_list; /* inode list head */ 83367298804SChao Yu unsigned long ino_num; /* number of entries */ 83467298804SChao Yu }; 83567298804SChao Yu 836caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 837caf0047eSChao Yu enum { 838caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 839caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 840caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 841caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 842df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 843bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 844caf0047eSChao Yu }; 845caf0047eSChao Yu 8466beceb54SJaegeuk Kim enum { 8476beceb54SJaegeuk Kim CP_TIME, 848d0239e1bSJaegeuk Kim REQ_TIME, 8496beceb54SJaegeuk Kim MAX_TIME, 8506beceb54SJaegeuk Kim }; 8516beceb54SJaegeuk Kim 85239a53e0cSJaegeuk Kim struct f2fs_sb_info { 85339a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 8545e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 85539a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 856e8240f65SChao Yu int valid_super_block; /* valid super block no */ 857fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 85839a53e0cSJaegeuk Kim 859178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 860178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 861178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 862178053e2SDamien Le Moal #endif 863178053e2SDamien Le Moal 86439a53e0cSJaegeuk Kim /* for node-related operations */ 86539a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 86639a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 86739a53e0cSJaegeuk Kim 86839a53e0cSJaegeuk Kim /* for segment-related operations */ 86939a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 8701ff7bd3bSJaegeuk Kim 8711ff7bd3bSJaegeuk Kim /* for bio operations */ 872924b720bSChao Yu struct f2fs_bio_info read_io; /* for read bios */ 8731ff7bd3bSJaegeuk Kim struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 8747dfeaa32SJaegeuk Kim struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ 8750a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 8760a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 87739a53e0cSJaegeuk Kim 87839a53e0cSJaegeuk Kim /* for checkpoint */ 87939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 8808508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 881aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 88239a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 88339936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 884b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 885b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 88659c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 887fb51b5efSChangman Lee wait_queue_head_t cp_wait; 8886beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 8896beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 89039a53e0cSJaegeuk Kim 89167298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 8926451e041SJaegeuk Kim 8936451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 8940d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 89539a53e0cSJaegeuk Kim 896c227f912SChao Yu /* for inode management */ 897c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 898c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 89939a53e0cSJaegeuk Kim 90013054c54SChao Yu /* for extent tree cache */ 90113054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 9025e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 90313054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 90413054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 9057441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 906137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 90774fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 90813054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 90913054c54SChao Yu 91039a53e0cSJaegeuk Kim /* basic filesystem units */ 91139a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 91239a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 91339a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 91439a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 91539a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 91639a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 91739a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 91839a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 91939a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 92039a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 92139a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 92239a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 92339a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 924e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 92539a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 926ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 92739a53e0cSJaegeuk Kim 92839a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 92939a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 930a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 93139a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 93239a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 933523be8a6SJaegeuk Kim 934523be8a6SJaegeuk Kim /* # of pages, see count_type */ 93535782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 93641382ec4SJaegeuk Kim /* # of allocated blocks */ 93741382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 93839a53e0cSJaegeuk Kim 939687de7f1SJaegeuk Kim /* writeback control */ 940687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 941687de7f1SJaegeuk Kim 942513c5f37SJaegeuk Kim /* valid inode count */ 943513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 944513c5f37SJaegeuk Kim 94539a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 94639a53e0cSJaegeuk Kim 94739a53e0cSJaegeuk Kim /* for cleaning operations */ 94839a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 94939a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 9505ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 95139a53e0cSJaegeuk Kim 952e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 953e93b9865SHou Pengyang u64 fggc_threshold; 954e93b9865SHou Pengyang 955b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 956b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 957b1c57c1cSJaegeuk Kim 95839a53e0cSJaegeuk Kim /* 95939a53e0cSJaegeuk Kim * for stat information. 96039a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 96139a53e0cSJaegeuk Kim */ 96235b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 96339a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 96439a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 96539a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 966b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 9675b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 9685b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 9695b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 9705b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 971d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 97203e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 97303e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 97426a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 975648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 97626a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 977648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 97839a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 97933fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 98035b09d82SNamjae Jeon #endif 98135b09d82SNamjae Jeon unsigned int last_victim[2]; /* last victim segment # */ 98239a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 983b59d0baeSNamjae Jeon 984b59d0baeSNamjae Jeon /* For sysfs suppport */ 985b59d0baeSNamjae Jeon struct kobject s_kobj; 986b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 9872658e50dSJaegeuk Kim 9882658e50dSJaegeuk Kim /* For shrinker support */ 9892658e50dSJaegeuk Kim struct list_head s_list; 9903c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 9913c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 9922658e50dSJaegeuk Kim struct mutex umount_mutex; 9932658e50dSJaegeuk Kim unsigned int shrinker_run_no; 9948f1dbbbbSShuoran Liu 9958f1dbbbbSShuoran Liu /* For write statistics */ 9968f1dbbbbSShuoran Liu u64 sectors_written_start; 9978f1dbbbbSShuoran Liu u64 kbytes_written; 99843b6573bSKeith Mok 99943b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 100043b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 10011ecc0c5cSChao Yu 10021ecc0c5cSChao Yu /* For fault injection */ 10031ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 10041ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 10051ecc0c5cSChao Yu #endif 100639a53e0cSJaegeuk Kim }; 100739a53e0cSJaegeuk Kim 10081ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 100955523519SChao Yu #define f2fs_show_injection_info(type) \ 101055523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 101155523519SChao Yu KERN_INFO, fault_name[type], \ 101255523519SChao Yu __func__, __builtin_return_address(0)) 10131ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 10141ecc0c5cSChao Yu { 10151ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 10161ecc0c5cSChao Yu 10171ecc0c5cSChao Yu if (!ffi->inject_rate) 10181ecc0c5cSChao Yu return false; 10191ecc0c5cSChao Yu 10201ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 10211ecc0c5cSChao Yu return false; 10221ecc0c5cSChao Yu 10231ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 10241ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 10251ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 10261ecc0c5cSChao Yu return true; 10271ecc0c5cSChao Yu } 10281ecc0c5cSChao Yu return false; 10291ecc0c5cSChao Yu } 10301ecc0c5cSChao Yu #endif 10311ecc0c5cSChao Yu 10328f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 10338f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 10348f1dbbbbSShuoran Liu */ 10358f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 103668afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 103768afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 10388f1dbbbbSShuoran Liu 10396beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 10406beceb54SJaegeuk Kim { 10416beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 10426beceb54SJaegeuk Kim } 10436beceb54SJaegeuk Kim 10446beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 10456beceb54SJaegeuk Kim { 10466beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 10476beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 10486beceb54SJaegeuk Kim 10496beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 10506beceb54SJaegeuk Kim } 10516beceb54SJaegeuk Kim 1052d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1053d0239e1bSJaegeuk Kim { 1054d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1055d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1056d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1057d0239e1bSJaegeuk Kim 1058d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1059d0239e1bSJaegeuk Kim return 0; 1060d0239e1bSJaegeuk Kim 1061d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1062d0239e1bSJaegeuk Kim } 1063d0239e1bSJaegeuk Kim 106439a53e0cSJaegeuk Kim /* 106539a53e0cSJaegeuk Kim * Inline functions 106639a53e0cSJaegeuk Kim */ 106743b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 106843b6573bSKeith Mok unsigned int length) 106943b6573bSKeith Mok { 107043b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 107143b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 107243b6573bSKeith Mok int err; 107343b6573bSKeith Mok 107443b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 107543b6573bSKeith Mok shash->flags = 0; 107643b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 107743b6573bSKeith Mok 107843b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 107943b6573bSKeith Mok BUG_ON(err); 108043b6573bSKeith Mok 108143b6573bSKeith Mok return *ctx; 108243b6573bSKeith Mok } 108343b6573bSKeith Mok 108443b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 108543b6573bSKeith Mok void *buf, size_t buf_size) 108643b6573bSKeith Mok { 108743b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 108843b6573bSKeith Mok } 108943b6573bSKeith Mok 109039a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 109139a53e0cSJaegeuk Kim { 109239a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 109339a53e0cSJaegeuk Kim } 109439a53e0cSJaegeuk Kim 109539a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 109639a53e0cSJaegeuk Kim { 109739a53e0cSJaegeuk Kim return sb->s_fs_info; 109839a53e0cSJaegeuk Kim } 109939a53e0cSJaegeuk Kim 11004081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 11014081363fSJaegeuk Kim { 11024081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 11034081363fSJaegeuk Kim } 11044081363fSJaegeuk Kim 11054081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 11064081363fSJaegeuk Kim { 11074081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 11084081363fSJaegeuk Kim } 11094081363fSJaegeuk Kim 11104081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 11114081363fSJaegeuk Kim { 11124081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 11134081363fSJaegeuk Kim } 11144081363fSJaegeuk Kim 111539a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 111639a53e0cSJaegeuk Kim { 111739a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 111839a53e0cSJaegeuk Kim } 111939a53e0cSJaegeuk Kim 112039a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 112139a53e0cSJaegeuk Kim { 112239a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 112339a53e0cSJaegeuk Kim } 112439a53e0cSJaegeuk Kim 112545590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 112645590710SGu Zheng { 112745590710SGu Zheng return (struct f2fs_node *)page_address(page); 112845590710SGu Zheng } 112945590710SGu Zheng 113058bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 113158bfaf44SJaegeuk Kim { 113258bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 113358bfaf44SJaegeuk Kim } 113458bfaf44SJaegeuk Kim 113539a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 113639a53e0cSJaegeuk Kim { 113739a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 113839a53e0cSJaegeuk Kim } 113939a53e0cSJaegeuk Kim 114039a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 114139a53e0cSJaegeuk Kim { 114239a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 114339a53e0cSJaegeuk Kim } 114439a53e0cSJaegeuk Kim 114539a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 114639a53e0cSJaegeuk Kim { 114739a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 114839a53e0cSJaegeuk Kim } 114939a53e0cSJaegeuk Kim 115039a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 115139a53e0cSJaegeuk Kim { 115239a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 115339a53e0cSJaegeuk Kim } 115439a53e0cSJaegeuk Kim 115539a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 115639a53e0cSJaegeuk Kim { 115739a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 115839a53e0cSJaegeuk Kim } 115939a53e0cSJaegeuk Kim 11609df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 11619df27d98SGu Zheng { 11629df27d98SGu Zheng return sbi->meta_inode->i_mapping; 11639df27d98SGu Zheng } 11649df27d98SGu Zheng 11654ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 11664ef51a8fSJaegeuk Kim { 11674ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 11684ef51a8fSJaegeuk Kim } 11694ef51a8fSJaegeuk Kim 1170caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 117139a53e0cSJaegeuk Kim { 1172fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 117339a53e0cSJaegeuk Kim } 117439a53e0cSJaegeuk Kim 1175caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 117639a53e0cSJaegeuk Kim { 1177fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1178caf0047eSChao Yu } 1179caf0047eSChao Yu 1180caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1181caf0047eSChao Yu { 1182fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 118339a53e0cSJaegeuk Kim } 118439a53e0cSJaegeuk Kim 1185d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1186d71b5564SJaegeuk Kim { 1187d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1188d71b5564SJaegeuk Kim } 1189d71b5564SJaegeuk Kim 1190ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1191ced2c7eaSKinglong Mee { 1192ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1193ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1194ced2c7eaSKinglong Mee } 1195ced2c7eaSKinglong Mee 1196aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 119725ca923bSJaegeuk Kim { 119825ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1199aaec2b1dSChao Yu 120025ca923bSJaegeuk Kim return ckpt_flags & f; 120125ca923bSJaegeuk Kim } 120225ca923bSJaegeuk Kim 1203aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 120425ca923bSJaegeuk Kim { 1205aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1206aaec2b1dSChao Yu } 1207aaec2b1dSChao Yu 1208aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1209aaec2b1dSChao Yu { 1210aaec2b1dSChao Yu unsigned int ckpt_flags; 1211aaec2b1dSChao Yu 1212aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 121325ca923bSJaegeuk Kim ckpt_flags |= f; 121425ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 121525ca923bSJaegeuk Kim } 121625ca923bSJaegeuk Kim 1217aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 121825ca923bSJaegeuk Kim { 1219aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1220aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1221aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1222aaec2b1dSChao Yu } 1223aaec2b1dSChao Yu 1224aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1225aaec2b1dSChao Yu { 1226aaec2b1dSChao Yu unsigned int ckpt_flags; 1227aaec2b1dSChao Yu 1228aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 122925ca923bSJaegeuk Kim ckpt_flags &= (~f); 123025ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 123125ca923bSJaegeuk Kim } 123225ca923bSJaegeuk Kim 1233aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1234aaec2b1dSChao Yu { 1235aaec2b1dSChao Yu spin_lock(&sbi->cp_lock); 1236aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1237aaec2b1dSChao Yu spin_unlock(&sbi->cp_lock); 1238aaec2b1dSChao Yu } 1239aaec2b1dSChao Yu 124022ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 124122ad0b6aSJaegeuk Kim { 124222ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 124322ad0b6aSJaegeuk Kim 124422ad0b6aSJaegeuk Kim if (lock) 124522ad0b6aSJaegeuk Kim spin_lock(&sbi->cp_lock); 124622ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 124722ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 124822ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 124922ad0b6aSJaegeuk Kim if (lock) 125022ad0b6aSJaegeuk Kim spin_unlock(&sbi->cp_lock); 125122ad0b6aSJaegeuk Kim } 125222ad0b6aSJaegeuk Kim 125322ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 125422ad0b6aSJaegeuk Kim struct cp_control *cpc) 125522ad0b6aSJaegeuk Kim { 125622ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 125722ad0b6aSJaegeuk Kim 125822ad0b6aSJaegeuk Kim return (cpc) ? (cpc->reason == CP_UMOUNT) && set : set; 125922ad0b6aSJaegeuk Kim } 126022ad0b6aSJaegeuk Kim 1261e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 126239a53e0cSJaegeuk Kim { 1263b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 126439a53e0cSJaegeuk Kim } 126539a53e0cSJaegeuk Kim 1266e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 126739a53e0cSJaegeuk Kim { 1268b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 126939936837SJaegeuk Kim } 127039936837SJaegeuk Kim 1271e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 127239936837SJaegeuk Kim { 1273b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 127439936837SJaegeuk Kim } 127539936837SJaegeuk Kim 1276e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 127739936837SJaegeuk Kim { 1278b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 127939a53e0cSJaegeuk Kim } 128039a53e0cSJaegeuk Kim 1281119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1282119ee914SJaegeuk Kim { 1283119ee914SJaegeuk Kim int reason = CP_SYNC; 1284119ee914SJaegeuk Kim 1285119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1286119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1287119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1288119ee914SJaegeuk Kim reason = CP_UMOUNT; 1289119ee914SJaegeuk Kim return reason; 1290119ee914SJaegeuk Kim } 1291119ee914SJaegeuk Kim 1292119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1293119ee914SJaegeuk Kim { 1294119ee914SJaegeuk Kim return (reason == CP_UMOUNT || reason == CP_FASTBOOT); 1295119ee914SJaegeuk Kim } 1296119ee914SJaegeuk Kim 1297119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1298119ee914SJaegeuk Kim { 1299aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1300aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1301119ee914SJaegeuk Kim } 1302119ee914SJaegeuk Kim 130339a53e0cSJaegeuk Kim /* 130439a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 130539a53e0cSJaegeuk Kim */ 1306064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 130739a53e0cSJaegeuk Kim { 1308d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1309d6b7d4b3SChao Yu return -EINVAL; 1310cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1311064e0823SNamjae Jeon return -EINVAL; 1312064e0823SNamjae Jeon return 0; 131339a53e0cSJaegeuk Kim } 131439a53e0cSJaegeuk Kim 131539a53e0cSJaegeuk Kim #define F2FS_DEFAULT_ALLOCATED_BLOCKS 1 131639a53e0cSJaegeuk Kim 131739a53e0cSJaegeuk Kim /* 131839a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 131939a53e0cSJaegeuk Kim */ 132039a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 132139a53e0cSJaegeuk Kim { 132239a53e0cSJaegeuk Kim if (F2FS_I(inode)->i_xattr_nid) 13236c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 132439a53e0cSJaegeuk Kim else 13256c311ec6SChris Fries return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS; 132639a53e0cSJaegeuk Kim } 132739a53e0cSJaegeuk Kim 13284bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 13294bc8e9bcSChao Yu { 13304bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 13314bc8e9bcSChao Yu } 13324bc8e9bcSChao Yu 13338edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 133439a53e0cSJaegeuk Kim static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 133546008c6dSChao Yu struct inode *inode, blkcnt_t *count) 133639a53e0cSJaegeuk Kim { 1337dd11a5dfSJaegeuk Kim blkcnt_t diff; 1338dd11a5dfSJaegeuk Kim 1339cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 134055523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 134155523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 1342cb78942bSJaegeuk Kim return false; 134355523519SChao Yu } 1344cb78942bSJaegeuk Kim #endif 1345dd11a5dfSJaegeuk Kim /* 1346dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1347dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1348dd11a5dfSJaegeuk Kim */ 1349dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1350cfb271d4SChao Yu 135139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13522555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 13532555a2d5SJaegeuk Kim if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { 1354dd11a5dfSJaegeuk Kim diff = sbi->total_valid_block_count - sbi->user_block_count; 1355dd11a5dfSJaegeuk Kim *count -= diff; 13562555a2d5SJaegeuk Kim sbi->total_valid_block_count = sbi->user_block_count; 135746008c6dSChao Yu if (!*count) { 135839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1359dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 136039a53e0cSJaegeuk Kim return false; 136139a53e0cSJaegeuk Kim } 136246008c6dSChao Yu } 136339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 136441382ec4SJaegeuk Kim 13652555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, *count, true); 136639a53e0cSJaegeuk Kim return true; 136739a53e0cSJaegeuk Kim } 136839a53e0cSJaegeuk Kim 1369da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 137039a53e0cSJaegeuk Kim struct inode *inode, 137139a53e0cSJaegeuk Kim blkcnt_t count) 137239a53e0cSJaegeuk Kim { 137339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 13749850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 13759850cf4aSJaegeuk Kim f2fs_bug_on(sbi, inode->i_blocks < count); 137639a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 137739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 13782555a2d5SJaegeuk Kim f2fs_i_blocks_write(inode, count, false); 137939a53e0cSJaegeuk Kim } 138039a53e0cSJaegeuk Kim 138139a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 138239a53e0cSJaegeuk Kim { 138335782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 13847c4abcbeSChao Yu 138536951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 138636951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 13877c4abcbeSChao Yu return; 13887c4abcbeSChao Yu 1389caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 139039a53e0cSJaegeuk Kim } 139139a53e0cSJaegeuk Kim 1392a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 139339a53e0cSJaegeuk Kim { 1394204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1395c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1396c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 139739a53e0cSJaegeuk Kim } 139839a53e0cSJaegeuk Kim 139939a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 140039a53e0cSJaegeuk Kim { 140135782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 140239a53e0cSJaegeuk Kim } 140339a53e0cSJaegeuk Kim 1404a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 140539a53e0cSJaegeuk Kim { 14065ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 14075ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 14081fe54f9dSJaegeuk Kim return; 14091fe54f9dSJaegeuk Kim 1410204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1411c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1412c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 141339a53e0cSJaegeuk Kim } 141439a53e0cSJaegeuk Kim 1415523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 141639a53e0cSJaegeuk Kim { 141735782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 141839a53e0cSJaegeuk Kim } 141939a53e0cSJaegeuk Kim 1420204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1421f8b2c1f9SJaegeuk Kim { 1422204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1423f8b2c1f9SJaegeuk Kim } 1424f8b2c1f9SJaegeuk Kim 14255ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 14265ac206cfSNamjae Jeon { 14273519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1428523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1429523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1430523be8a6SJaegeuk Kim 1431523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 14325ac206cfSNamjae Jeon } 14335ac206cfSNamjae Jeon 143439a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 143539a53e0cSJaegeuk Kim { 14368b8343faSJaegeuk Kim return sbi->total_valid_block_count; 143739a53e0cSJaegeuk Kim } 143839a53e0cSJaegeuk Kim 1439f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1440f83a2584SYunlei He { 1441f83a2584SYunlei He return sbi->discard_blks; 1442f83a2584SYunlei He } 1443f83a2584SYunlei He 144439a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 144539a53e0cSJaegeuk Kim { 144639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 144739a53e0cSJaegeuk Kim 144839a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 144939a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 145039a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 145139a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 145239a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 145339a53e0cSJaegeuk Kim 145439a53e0cSJaegeuk Kim return 0; 145539a53e0cSJaegeuk Kim } 145639a53e0cSJaegeuk Kim 145755141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 145855141486SWanpeng Li { 145955141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 146055141486SWanpeng Li } 146155141486SWanpeng Li 146239a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 146339a53e0cSJaegeuk Kim { 146439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 14651dbe4152SChangman Lee int offset; 14661dbe4152SChangman Lee 146755141486SWanpeng Li if (__cp_payload(sbi) > 0) { 14681dbe4152SChangman Lee if (flag == NAT_BITMAP) 14691dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 14701dbe4152SChangman Lee else 147165b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 14721dbe4152SChangman Lee } else { 14731dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 147425ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 147539a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 147639a53e0cSJaegeuk Kim } 14771dbe4152SChangman Lee } 147839a53e0cSJaegeuk Kim 147939a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 148039a53e0cSJaegeuk Kim { 14818508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 148239a53e0cSJaegeuk Kim 14838508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 148439a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 148539a53e0cSJaegeuk Kim return start_addr; 148639a53e0cSJaegeuk Kim } 148739a53e0cSJaegeuk Kim 14888508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 14898508e44aSJaegeuk Kim { 14908508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 14918508e44aSJaegeuk Kim 14928508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 14938508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 14948508e44aSJaegeuk Kim return start_addr; 14958508e44aSJaegeuk Kim } 14968508e44aSJaegeuk Kim 14978508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 14988508e44aSJaegeuk Kim { 14998508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 15008508e44aSJaegeuk Kim } 15018508e44aSJaegeuk Kim 150239a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 150339a53e0cSJaegeuk Kim { 150439a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 150539a53e0cSJaegeuk Kim } 150639a53e0cSJaegeuk Kim 150739a53e0cSJaegeuk Kim static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1508ef86d709SGu Zheng struct inode *inode) 150939a53e0cSJaegeuk Kim { 151039a53e0cSJaegeuk Kim block_t valid_block_count; 151139a53e0cSJaegeuk Kim unsigned int valid_node_count; 151239a53e0cSJaegeuk Kim 151339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 151439a53e0cSJaegeuk Kim 1515ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1516cfb271d4SChao Yu if (unlikely(valid_block_count > sbi->user_block_count)) { 151739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 151839a53e0cSJaegeuk Kim return false; 151939a53e0cSJaegeuk Kim } 152039a53e0cSJaegeuk Kim 1521ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1522cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 152339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 152439a53e0cSJaegeuk Kim return false; 152539a53e0cSJaegeuk Kim } 152639a53e0cSJaegeuk Kim 152739a53e0cSJaegeuk Kim if (inode) 15288edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, true); 1529ef86d709SGu Zheng 1530ef86d709SGu Zheng sbi->total_valid_node_count++; 1531ef86d709SGu Zheng sbi->total_valid_block_count++; 153239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 153339a53e0cSJaegeuk Kim 153441382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 153539a53e0cSJaegeuk Kim return true; 153639a53e0cSJaegeuk Kim } 153739a53e0cSJaegeuk Kim 153839a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1539ef86d709SGu Zheng struct inode *inode) 154039a53e0cSJaegeuk Kim { 154139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 154239a53e0cSJaegeuk Kim 15439850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 15449850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 15459850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !inode->i_blocks); 154639a53e0cSJaegeuk Kim 15478edd03c8SJaegeuk Kim f2fs_i_blocks_write(inode, 1, false); 1548ef86d709SGu Zheng sbi->total_valid_node_count--; 1549ef86d709SGu Zheng sbi->total_valid_block_count--; 155039a53e0cSJaegeuk Kim 155139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 155239a53e0cSJaegeuk Kim } 155339a53e0cSJaegeuk Kim 155439a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 155539a53e0cSJaegeuk Kim { 15568b8343faSJaegeuk Kim return sbi->total_valid_node_count; 155739a53e0cSJaegeuk Kim } 155839a53e0cSJaegeuk Kim 155939a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 156039a53e0cSJaegeuk Kim { 1561513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 156239a53e0cSJaegeuk Kim } 156339a53e0cSJaegeuk Kim 15640e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 156539a53e0cSJaegeuk Kim { 1566513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 156739a53e0cSJaegeuk Kim } 156839a53e0cSJaegeuk Kim 1569513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 157039a53e0cSJaegeuk Kim { 1571513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 157239a53e0cSJaegeuk Kim } 157339a53e0cSJaegeuk Kim 1574a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1575a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1576a56c7c6fSJaegeuk Kim { 1577c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1578c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1579cac5a3d8SDongOh Shin 1580c41f3cc3SJaegeuk Kim if (page) 1581c41f3cc3SJaegeuk Kim return page; 1582c41f3cc3SJaegeuk Kim 158355523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 158455523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1585c41f3cc3SJaegeuk Kim return NULL; 158655523519SChao Yu } 1587c41f3cc3SJaegeuk Kim #endif 1588a56c7c6fSJaegeuk Kim if (!for_write) 1589a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1590a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1591a56c7c6fSJaegeuk Kim } 1592a56c7c6fSJaegeuk Kim 15936e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 15946e2c64adSJaegeuk Kim { 15956e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 15966e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 15976e2c64adSJaegeuk Kim 15986e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 15996e2c64adSJaegeuk Kim kunmap(dst); 16006e2c64adSJaegeuk Kim kunmap(src); 16016e2c64adSJaegeuk Kim } 16026e2c64adSJaegeuk Kim 160339a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 160439a53e0cSJaegeuk Kim { 1605031fa8ccSJaegeuk Kim if (!page) 160639a53e0cSJaegeuk Kim return; 160739a53e0cSJaegeuk Kim 160839a53e0cSJaegeuk Kim if (unlock) { 16099850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 161039a53e0cSJaegeuk Kim unlock_page(page); 161139a53e0cSJaegeuk Kim } 161209cbfeafSKirill A. Shutemov put_page(page); 161339a53e0cSJaegeuk Kim } 161439a53e0cSJaegeuk Kim 161539a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 161639a53e0cSJaegeuk Kim { 161739a53e0cSJaegeuk Kim if (dn->node_page) 161839a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 161939a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 162039a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 162139a53e0cSJaegeuk Kim dn->node_page = NULL; 162239a53e0cSJaegeuk Kim dn->inode_page = NULL; 162339a53e0cSJaegeuk Kim } 162439a53e0cSJaegeuk Kim 162539a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1626e8512d2eSGu Zheng size_t size) 162739a53e0cSJaegeuk Kim { 1628e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 162939a53e0cSJaegeuk Kim } 163039a53e0cSJaegeuk Kim 16317bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 16327bd59381SGu Zheng gfp_t flags) 16337bd59381SGu Zheng { 16347bd59381SGu Zheng void *entry; 16357bd59381SGu Zheng 163680c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 163780c54505SJaegeuk Kim if (!entry) 163880c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 16397bd59381SGu Zheng return entry; 16407bd59381SGu Zheng } 16417bd59381SGu Zheng 1642740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1643740432f8SJaegeuk Kim { 1644740432f8SJaegeuk Kim struct bio *bio; 1645740432f8SJaegeuk Kim 1646740432f8SJaegeuk Kim /* No failure on bio allocation */ 1647740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 164880c54505SJaegeuk Kim if (!bio) 164980c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1650740432f8SJaegeuk Kim return bio; 1651740432f8SJaegeuk Kim } 1652740432f8SJaegeuk Kim 16539be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 16549be32d72SJaegeuk Kim unsigned long index, void *item) 16559be32d72SJaegeuk Kim { 16569be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 16579be32d72SJaegeuk Kim cond_resched(); 16589be32d72SJaegeuk Kim } 16599be32d72SJaegeuk Kim 166039a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 166139a53e0cSJaegeuk Kim 166239a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 166339a53e0cSJaegeuk Kim { 166445590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1665cac5a3d8SDongOh Shin 166639a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 166739a53e0cSJaegeuk Kim } 166839a53e0cSJaegeuk Kim 166939a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 167039a53e0cSJaegeuk Kim { 167139a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 167239a53e0cSJaegeuk Kim } 167339a53e0cSJaegeuk Kim 167439a53e0cSJaegeuk Kim static inline block_t datablock_addr(struct page *node_page, 167539a53e0cSJaegeuk Kim unsigned int offset) 167639a53e0cSJaegeuk Kim { 167739a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 167839a53e0cSJaegeuk Kim __le32 *addr_array; 1679cac5a3d8SDongOh Shin 168045590710SGu Zheng raw_node = F2FS_NODE(node_page); 168139a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 168239a53e0cSJaegeuk Kim return le32_to_cpu(addr_array[offset]); 168339a53e0cSJaegeuk Kim } 168439a53e0cSJaegeuk Kim 168539a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 168639a53e0cSJaegeuk Kim { 168739a53e0cSJaegeuk Kim int mask; 168839a53e0cSJaegeuk Kim 168939a53e0cSJaegeuk Kim addr += (nr >> 3); 169039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 169139a53e0cSJaegeuk Kim return mask & *addr; 169239a53e0cSJaegeuk Kim } 169339a53e0cSJaegeuk Kim 1694a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1695a66cdd98SJaegeuk Kim { 1696a66cdd98SJaegeuk Kim int mask; 1697a66cdd98SJaegeuk Kim 1698a66cdd98SJaegeuk Kim addr += (nr >> 3); 1699a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1700a66cdd98SJaegeuk Kim *addr |= mask; 1701a66cdd98SJaegeuk Kim } 1702a66cdd98SJaegeuk Kim 1703a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1704a66cdd98SJaegeuk Kim { 1705a66cdd98SJaegeuk Kim int mask; 1706a66cdd98SJaegeuk Kim 1707a66cdd98SJaegeuk Kim addr += (nr >> 3); 1708a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1709a66cdd98SJaegeuk Kim *addr &= ~mask; 1710a66cdd98SJaegeuk Kim } 1711a66cdd98SJaegeuk Kim 171252aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 171339a53e0cSJaegeuk Kim { 171439a53e0cSJaegeuk Kim int mask; 171539a53e0cSJaegeuk Kim int ret; 171639a53e0cSJaegeuk Kim 171739a53e0cSJaegeuk Kim addr += (nr >> 3); 171839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 171939a53e0cSJaegeuk Kim ret = mask & *addr; 172039a53e0cSJaegeuk Kim *addr |= mask; 172139a53e0cSJaegeuk Kim return ret; 172239a53e0cSJaegeuk Kim } 172339a53e0cSJaegeuk Kim 172452aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 172539a53e0cSJaegeuk Kim { 172639a53e0cSJaegeuk Kim int mask; 172739a53e0cSJaegeuk Kim int ret; 172839a53e0cSJaegeuk Kim 172939a53e0cSJaegeuk Kim addr += (nr >> 3); 173039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 173139a53e0cSJaegeuk Kim ret = mask & *addr; 173239a53e0cSJaegeuk Kim *addr &= ~mask; 173339a53e0cSJaegeuk Kim return ret; 173439a53e0cSJaegeuk Kim } 173539a53e0cSJaegeuk Kim 1736c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1737c6ac4c0eSGu Zheng { 1738c6ac4c0eSGu Zheng int mask; 1739c6ac4c0eSGu Zheng 1740c6ac4c0eSGu Zheng addr += (nr >> 3); 1741c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1742c6ac4c0eSGu Zheng *addr ^= mask; 1743c6ac4c0eSGu Zheng } 1744c6ac4c0eSGu Zheng 174539a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 174639a53e0cSJaegeuk Kim enum { 174739a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1748b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 174926de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1750ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 175139a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 175239a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 175339a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1754c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1755c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1756444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 17571001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 175834d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1759fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1760fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 176188b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 176288b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 17635fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 176402a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 17653c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 17661e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 1767b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 1768510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 1769d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 1770c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 1771dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 1772ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 177339a53e0cSJaegeuk Kim }; 177439a53e0cSJaegeuk Kim 1775205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 1776205b9822SJaegeuk Kim int flag, bool set) 177739a53e0cSJaegeuk Kim { 1778205b9822SJaegeuk Kim switch (flag) { 1779205b9822SJaegeuk Kim case FI_INLINE_XATTR: 1780205b9822SJaegeuk Kim case FI_INLINE_DATA: 1781205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 1782205b9822SJaegeuk Kim if (set) 1783205b9822SJaegeuk Kim return; 1784205b9822SJaegeuk Kim case FI_DATA_EXIST: 1785205b9822SJaegeuk Kim case FI_INLINE_DOTS: 17867c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1787205b9822SJaegeuk Kim } 178839a53e0cSJaegeuk Kim } 178939a53e0cSJaegeuk Kim 179091942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 179139a53e0cSJaegeuk Kim { 179291942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 179391942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 1794205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 179539a53e0cSJaegeuk Kim } 179639a53e0cSJaegeuk Kim 179791942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 179839a53e0cSJaegeuk Kim { 179991942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 180039a53e0cSJaegeuk Kim } 180139a53e0cSJaegeuk Kim 180291942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 180339a53e0cSJaegeuk Kim { 180491942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 180591942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 1806205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 180739a53e0cSJaegeuk Kim } 180839a53e0cSJaegeuk Kim 180991942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 1810444c580fSJaegeuk Kim { 181191942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 181291942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 18137c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 181439a53e0cSJaegeuk Kim } 181539a53e0cSJaegeuk Kim 1816a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 1817a1961246SJaegeuk Kim { 1818a1961246SJaegeuk Kim if (inc) 1819a1961246SJaegeuk Kim inc_nlink(inode); 1820a1961246SJaegeuk Kim else 1821a1961246SJaegeuk Kim drop_nlink(inode); 18227c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1823a1961246SJaegeuk Kim } 1824a1961246SJaegeuk Kim 18258edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 18268edd03c8SJaegeuk Kim blkcnt_t diff, bool add) 18278edd03c8SJaegeuk Kim { 182826de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 182926de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 183026de9b11SJaegeuk Kim 18318edd03c8SJaegeuk Kim inode->i_blocks = add ? inode->i_blocks + diff : 18328edd03c8SJaegeuk Kim inode->i_blocks - diff; 18337c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 183426de9b11SJaegeuk Kim if (clean || recover) 183526de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 18368edd03c8SJaegeuk Kim } 18378edd03c8SJaegeuk Kim 1838fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 1839fc9581c8SJaegeuk Kim { 184026de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 184126de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 184226de9b11SJaegeuk Kim 1843fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 1844fc9581c8SJaegeuk Kim return; 1845fc9581c8SJaegeuk Kim 1846fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 18477c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 184826de9b11SJaegeuk Kim if (clean || recover) 184926de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 185026de9b11SJaegeuk Kim } 185126de9b11SJaegeuk Kim 1852205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 1853205b9822SJaegeuk Kim { 1854205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 18557c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1856205b9822SJaegeuk Kim } 1857205b9822SJaegeuk Kim 1858205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 1859205b9822SJaegeuk Kim { 1860205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 18617c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1862205b9822SJaegeuk Kim } 1863205b9822SJaegeuk Kim 1864205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 1865205b9822SJaegeuk Kim { 1866205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 18677c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1868205b9822SJaegeuk Kim } 1869205b9822SJaegeuk Kim 187091942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 1871444c580fSJaegeuk Kim { 1872205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 1873205b9822SJaegeuk Kim 1874444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 1875205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 18761001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 1877205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 187834d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 1879205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 1880b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 1881205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 1882510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 1883205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 1884444c580fSJaegeuk Kim } 1885444c580fSJaegeuk Kim 188691942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 1887444c580fSJaegeuk Kim { 1888444c580fSJaegeuk Kim ri->i_inline = 0; 1889444c580fSJaegeuk Kim 189091942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 1891444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 189291942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 18931001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 189491942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 189534d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 189691942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 1897b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 189891942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 1899510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 1900444c580fSJaegeuk Kim } 1901444c580fSJaegeuk Kim 1902987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 1903987c7c31SChao Yu { 190491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 1905987c7c31SChao Yu } 1906987c7c31SChao Yu 190781ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 1908de93653fSJaegeuk Kim { 190981ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 1910de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE - F2FS_INLINE_XATTR_ADDRS; 1911de93653fSJaegeuk Kim return DEF_ADDRS_PER_INODE; 1912de93653fSJaegeuk Kim } 1913de93653fSJaegeuk Kim 191465985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 191565985d93SJaegeuk Kim { 1916695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1917cac5a3d8SDongOh Shin 191865985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 191965985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 192065985d93SJaegeuk Kim } 192165985d93SJaegeuk Kim 192265985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 192365985d93SJaegeuk Kim { 1924987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 192565985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 192665985d93SJaegeuk Kim else 192765985d93SJaegeuk Kim return 0; 192865985d93SJaegeuk Kim } 192965985d93SJaegeuk Kim 19300dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 19310dbdc2aeSJaegeuk Kim { 193291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 19330dbdc2aeSJaegeuk Kim } 19340dbdc2aeSJaegeuk Kim 1935b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 1936b3d208f9SJaegeuk Kim { 193791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 1938b3d208f9SJaegeuk Kim } 1939b3d208f9SJaegeuk Kim 1940510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 1941510022a8SJaegeuk Kim { 194291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 1943510022a8SJaegeuk Kim } 1944510022a8SJaegeuk Kim 194588b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 194688b88a66SJaegeuk Kim { 194791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 194888b88a66SJaegeuk Kim } 194988b88a66SJaegeuk Kim 19505fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 19515fe45743SChao Yu { 19525fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 19535fe45743SChao Yu } 19545fe45743SChao Yu 195502a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 195602a1335fSJaegeuk Kim { 195791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 195802a1335fSJaegeuk Kim } 195902a1335fSJaegeuk Kim 19603c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 19613c6c2bebSJaegeuk Kim { 196291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 19633c6c2bebSJaegeuk Kim } 19643c6c2bebSJaegeuk Kim 19651e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 19661e84371fSJaegeuk Kim { 196791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 19681e84371fSJaegeuk Kim } 19691e84371fSJaegeuk Kim 19701001b347SHuajun Li static inline void *inline_data_addr(struct page *page) 19711001b347SHuajun Li { 1972695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 1973cac5a3d8SDongOh Shin 19741001b347SHuajun Li return (void *)&(ri->i_addr[1]); 19751001b347SHuajun Li } 19761001b347SHuajun Li 197734d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 197834d67debSChao Yu { 197991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 198034d67debSChao Yu } 198134d67debSChao Yu 19829486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 19839486ba44SJaegeuk Kim { 19849486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 19859486ba44SJaegeuk Kim kunmap(page); 19869486ba44SJaegeuk Kim } 19879486ba44SJaegeuk Kim 1988b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 1989b5492af7SJaegeuk Kim { 1990b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 1991b5492af7SJaegeuk Kim } 1992b5492af7SJaegeuk Kim 1993b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 1994b5492af7SJaegeuk Kim { 1995b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 19967c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 1997b5492af7SJaegeuk Kim } 1998b5492af7SJaegeuk Kim 1999b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2000b5492af7SJaegeuk Kim { 2001b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 20027c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2003b5492af7SJaegeuk Kim } 2004b5492af7SJaegeuk Kim 200526787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 200626787236SJaegeuk Kim { 200726787236SJaegeuk Kim if (dsync) { 200826787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 200926787236SJaegeuk Kim bool ret; 201026787236SJaegeuk Kim 201126787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 201226787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 201326787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 201426787236SJaegeuk Kim return ret; 201526787236SJaegeuk Kim } 201626787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 201726787236SJaegeuk Kim file_keep_isize(inode) || 201826787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 201926787236SJaegeuk Kim return false; 202026787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 2021267378d4SChao Yu } 2022267378d4SChao Yu 2023267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 2024267378d4SChao Yu { 2025267378d4SChao Yu return sb->s_flags & MS_RDONLY; 2026267378d4SChao Yu } 202739a53e0cSJaegeuk Kim 202839a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 202939a53e0cSJaegeuk Kim { 2030aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 203139a53e0cSJaegeuk Kim } 203239a53e0cSJaegeuk Kim 2033eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2034eaa693f4SJaegeuk Kim { 2035eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2036eaa693f4SJaegeuk Kim return true; 2037eaa693f4SJaegeuk Kim 2038eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2039eaa693f4SJaegeuk Kim return true; 2040eaa693f4SJaegeuk Kim 2041eaa693f4SJaegeuk Kim return false; 2042eaa693f4SJaegeuk Kim } 2043eaa693f4SJaegeuk Kim 20443e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 20453e72f721SJaegeuk Kim { 20463e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 204791942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 20483e72f721SJaegeuk Kim return false; 20493e72f721SJaegeuk Kim 2050886f56f9SAl Viro return S_ISREG(inode->i_mode); 20513e72f721SJaegeuk Kim } 20523e72f721SJaegeuk Kim 20531ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 20541ecc0c5cSChao Yu size_t size, gfp_t flags) 20550414b004SJaegeuk Kim { 20562c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 205755523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 205855523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 20592c63feadSJaegeuk Kim return NULL; 206055523519SChao Yu } 20612c63feadSJaegeuk Kim #endif 20620414b004SJaegeuk Kim return kmalloc(size, flags); 20630414b004SJaegeuk Kim } 20640414b004SJaegeuk Kim 206539307a8eSJaegeuk Kim static inline void *f2fs_kvmalloc(size_t size, gfp_t flags) 206639307a8eSJaegeuk Kim { 206739307a8eSJaegeuk Kim void *ret; 206839307a8eSJaegeuk Kim 206939307a8eSJaegeuk Kim ret = kmalloc(size, flags | __GFP_NOWARN); 207039307a8eSJaegeuk Kim if (!ret) 207139307a8eSJaegeuk Kim ret = __vmalloc(size, flags, PAGE_KERNEL); 207239307a8eSJaegeuk Kim return ret; 207339307a8eSJaegeuk Kim } 207439307a8eSJaegeuk Kim 207539307a8eSJaegeuk Kim static inline void *f2fs_kvzalloc(size_t size, gfp_t flags) 207639307a8eSJaegeuk Kim { 207739307a8eSJaegeuk Kim void *ret; 207839307a8eSJaegeuk Kim 207939307a8eSJaegeuk Kim ret = kzalloc(size, flags | __GFP_NOWARN); 208039307a8eSJaegeuk Kim if (!ret) 208139307a8eSJaegeuk Kim ret = __vmalloc(size, flags | __GFP_ZERO, PAGE_KERNEL); 208239307a8eSJaegeuk Kim return ret; 208339307a8eSJaegeuk Kim } 208439307a8eSJaegeuk Kim 208539a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 208691942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 208739a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 208839a53e0cSJaegeuk Kim 208939a53e0cSJaegeuk Kim /* 20901e1bb4baSJaegeuk Kim * file.c 209139a53e0cSJaegeuk Kim */ 2092cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2093cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2094cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2095cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2096a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2097a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2098cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2099cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2100cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2101cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2102cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 210339a53e0cSJaegeuk Kim 210439a53e0cSJaegeuk Kim /* 210539a53e0cSJaegeuk Kim * inode.c 210639a53e0cSJaegeuk Kim */ 2107cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2108cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2109cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2110cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2111cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2112cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2113cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2114cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2115cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 211639a53e0cSJaegeuk Kim 211739a53e0cSJaegeuk Kim /* 211839a53e0cSJaegeuk Kim * namei.c 211939a53e0cSJaegeuk Kim */ 212039a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 212139a53e0cSJaegeuk Kim 212239a53e0cSJaegeuk Kim /* 212339a53e0cSJaegeuk Kim * dir.c 212439a53e0cSJaegeuk Kim */ 2125cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2126cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2127cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2128cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2129cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2130cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2131cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2132cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2133cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2134cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2135cac5a3d8SDongOh Shin const struct qstr *new_name, 2136cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2137cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2138cac5a3d8SDongOh Shin unsigned int current_depth); 2139cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2140cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2141cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2142cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2143cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2144cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2145cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2146cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2147cac5a3d8SDongOh Shin struct page **page); 2148cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2149cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2150cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2151cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2152cac5a3d8SDongOh Shin unsigned int bit_pos); 2153cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2154cac5a3d8SDongOh Shin const struct qstr *orig_name, 2155cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2156cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2157cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2158cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2159cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2160cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2161cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2162cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2163cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 216439a53e0cSJaegeuk Kim 2165b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2166b7f7a5e0SAl Viro { 21672b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2168510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2169b7f7a5e0SAl Viro } 2170b7f7a5e0SAl Viro 217139a53e0cSJaegeuk Kim /* 217239a53e0cSJaegeuk Kim * super.c 217339a53e0cSJaegeuk Kim */ 2174cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2175cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2176cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2177cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2178a07ef784SNamjae Jeon extern __printf(3, 4) 2179cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2180984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 218139a53e0cSJaegeuk Kim 218239a53e0cSJaegeuk Kim /* 218339a53e0cSJaegeuk Kim * hash.c 218439a53e0cSJaegeuk Kim */ 2185cac5a3d8SDongOh Shin f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info); 218639a53e0cSJaegeuk Kim 218739a53e0cSJaegeuk Kim /* 218839a53e0cSJaegeuk Kim * node.c 218939a53e0cSJaegeuk Kim */ 219039a53e0cSJaegeuk Kim struct dnode_of_data; 219139a53e0cSJaegeuk Kim struct node_info; 219239a53e0cSJaegeuk Kim 2193cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2194cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2195cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2196cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2197cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2198cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2199cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2200cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2201cac5a3d8SDongOh Shin int truncate_xattr_node(struct inode *inode, struct page *page); 2202cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2203cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2204cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 2205cac5a3d8SDongOh Shin struct page *new_node_page(struct dnode_of_data *dn, 2206cac5a3d8SDongOh Shin unsigned int ofs, struct page *ipage); 2207cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2208cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2209cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2210cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2211cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2212cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2213cac5a3d8SDongOh Shin int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc); 221422ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2215cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2216cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2217cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2218cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2219cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2220d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2221cac5a3d8SDongOh Shin block_t blkaddr); 2222cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2223cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2224cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 222522ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2226cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2227cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 22286e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 222939a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 223039a53e0cSJaegeuk Kim 223139a53e0cSJaegeuk Kim /* 223239a53e0cSJaegeuk Kim * segment.c 223339a53e0cSJaegeuk Kim */ 2234cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 2235cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 22368c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2237cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2238cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2239cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2240cac5a3d8SDongOh Shin int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2241cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2242cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2243cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2244cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2245cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2246d431413fSChao Yu void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2247cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2248cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2249cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2250cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2251cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2252cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2253cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2254cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2255cac5a3d8SDongOh Shin void write_meta_page(struct f2fs_sb_info *sbi, struct page *page); 2256cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2257cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2258d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2259cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2260cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2261cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2262cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2263cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2264cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2265cac5a3d8SDongOh Shin bool recover_newaddr); 2266cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2267cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2268cac5a3d8SDongOh Shin struct f2fs_summary *sum, int type); 2269cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2270cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2271cac5a3d8SDongOh Shin void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2272cac5a3d8SDongOh Shin block_t blkaddr); 2273cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2274cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2275cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2276cac5a3d8SDongOh Shin unsigned int val, int alloc); 2277cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2278cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2279cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 22807fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 22817fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 228239a53e0cSJaegeuk Kim 228339a53e0cSJaegeuk Kim /* 228439a53e0cSJaegeuk Kim * checkpoint.c 228539a53e0cSJaegeuk Kim */ 2286cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2287cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2288cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2289cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2290cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2291cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2292cac5a3d8SDongOh Shin int type, bool sync); 2293cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2294cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2295cac5a3d8SDongOh Shin long nr_to_write); 2296cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2297cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2298cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2299cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2300cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2301cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2302cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2303cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2304cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2305cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2306cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2307cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2308cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2309cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2310cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2311cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 23126e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 231339a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 231439a53e0cSJaegeuk Kim 231539a53e0cSJaegeuk Kim /* 231639a53e0cSJaegeuk Kim * data.c 231739a53e0cSJaegeuk Kim */ 2318cac5a3d8SDongOh Shin void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 2319cac5a3d8SDongOh Shin int rw); 2320cac5a3d8SDongOh Shin void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, 2321942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2322942fd319SJaegeuk Kim enum page_type type, int rw); 2323cac5a3d8SDongOh Shin void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi); 2324cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2325cac5a3d8SDongOh Shin int f2fs_submit_page_mbio(struct f2fs_io_info *fio); 2326cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2327cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2328cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2329cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2330cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2331cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2332cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2333cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2334cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2335cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2336cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2337cac5a3d8SDongOh Shin int op_flags, bool for_write); 2338cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2339cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2340cac5a3d8SDongOh Shin bool for_write); 2341cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2342cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2343cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2344cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2345cac5a3d8SDongOh Shin int create, int flag); 2346cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2347cac5a3d8SDongOh Shin u64 start, u64 len); 2348cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2349cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2350cac5a3d8SDongOh Shin unsigned int length); 2351cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 23525b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2353cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2354cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 23555b7a487cSWeichao Guo #endif 235639a53e0cSJaegeuk Kim 235739a53e0cSJaegeuk Kim /* 235839a53e0cSJaegeuk Kim * gc.c 235939a53e0cSJaegeuk Kim */ 2360cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2361cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2362cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2363cac5a3d8SDongOh Shin int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background); 2364cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 236539a53e0cSJaegeuk Kim 236639a53e0cSJaegeuk Kim /* 236739a53e0cSJaegeuk Kim * recovery.c 236839a53e0cSJaegeuk Kim */ 2369cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2370cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 237139a53e0cSJaegeuk Kim 237239a53e0cSJaegeuk Kim /* 237339a53e0cSJaegeuk Kim * debug.c 237439a53e0cSJaegeuk Kim */ 237539a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 237639a53e0cSJaegeuk Kim struct f2fs_stat_info { 237739a53e0cSJaegeuk Kim struct list_head stat_list; 237839a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 237939a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 238039a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 23815b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 23825b7ee374SChao Yu unsigned long long hit_total, total_ext; 2383c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 238435782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 238535782b23SJaegeuk Kim int inmem_pages; 23860f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 2387b8559dc2SChao Yu int nats, dirty_nats, sits, dirty_sits, free_nids, alloc_nids; 238839a53e0cSJaegeuk Kim int total_count, utilization; 23898b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 23908b8dd65fSChao Yu int nr_flushing, nr_flushed, nr_discarding, nr_discarded; 23915f32366aSChao Yu int nr_discard_cmd; 2392a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2393648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2394f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 239539a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 239639a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 239739a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 239839a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 239942190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 240039a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2401e1235983SChangman Lee int bg_node_segs, bg_data_segs; 240239a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2403e1235983SChangman Lee int bg_data_blks, bg_node_blks; 240439a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 240539a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 240639a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 240739a53e0cSJaegeuk Kim 240839a53e0cSJaegeuk Kim unsigned int segment_count[2]; 240939a53e0cSJaegeuk Kim unsigned int block_count[2]; 2410b9a2c252SChangman Lee unsigned int inplace_count; 24119edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 241239a53e0cSJaegeuk Kim }; 241339a53e0cSJaegeuk Kim 2414963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2415963d4f7dSGu Zheng { 2416963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2417963d4f7dSGu Zheng } 2418963d4f7dSGu Zheng 2419942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 242042190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 242139a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2422dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 242333fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 242433fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 24255b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 24265b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 24275b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 24285b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2429d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2430d5e8f6c9SChao Yu do { \ 2431d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2432d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2433d5e8f6c9SChao Yu } while (0) 2434d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2435d5e8f6c9SChao Yu do { \ 2436d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2437d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2438d5e8f6c9SChao Yu } while (0) 24390dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 24400dbdc2aeSJaegeuk Kim do { \ 24410dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 244203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 24430dbdc2aeSJaegeuk Kim } while (0) 24440dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 24450dbdc2aeSJaegeuk Kim do { \ 24460dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 244703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 24480dbdc2aeSJaegeuk Kim } while (0) 24493289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 24503289c061SJaegeuk Kim do { \ 24513289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 245203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 24533289c061SJaegeuk Kim } while (0) 24543289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 24553289c061SJaegeuk Kim do { \ 24563289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 245703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 24583289c061SJaegeuk Kim } while (0) 2459dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2460dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2461dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2462dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2463b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2464b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 246526a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2466cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 246726a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2468cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 246926a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 247026a28a0cSJaegeuk Kim do { \ 247126a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 247226a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 247326a28a0cSJaegeuk Kim if (cur > max) \ 247426a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 247526a28a0cSJaegeuk Kim } while (0) 2476648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2477648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2478648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2479648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2480648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2481648d50baSChao Yu do { \ 2482648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2483648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2484648d50baSChao Yu if (cur > max) \ 2485648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2486648d50baSChao Yu } while (0) 2487e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 248839a53e0cSJaegeuk Kim do { \ 2489963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 249068afcf2dSTomohiro Kusumi si->tot_segs++; \ 249168afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 249239a53e0cSJaegeuk Kim si->data_segs++; \ 2493e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2494e1235983SChangman Lee } else { \ 249539a53e0cSJaegeuk Kim si->node_segs++; \ 2496e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2497e1235983SChangman Lee } \ 249839a53e0cSJaegeuk Kim } while (0) 249939a53e0cSJaegeuk Kim 250039a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 250168afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 250239a53e0cSJaegeuk Kim 2503e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 250439a53e0cSJaegeuk Kim do { \ 2505963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 250639a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 250739a53e0cSJaegeuk Kim si->data_blks += (blks); \ 250868afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 250939a53e0cSJaegeuk Kim } while (0) 251039a53e0cSJaegeuk Kim 2511e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 251239a53e0cSJaegeuk Kim do { \ 2513963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 251439a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 251539a53e0cSJaegeuk Kim si->node_blks += (blks); \ 251668afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 251739a53e0cSJaegeuk Kim } while (0) 251839a53e0cSJaegeuk Kim 2519cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2520cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2521787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 25224589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 252339a53e0cSJaegeuk Kim #else 2524942e0be6SChangman Lee #define stat_inc_cp_count(si) 252542190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) 252639a53e0cSJaegeuk Kim #define stat_inc_call_count(si) 2527dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(si) 252833fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) 252933fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) 2530dcdfff65SJaegeuk Kim #define stat_inc_total_hit(sb) 2531029e13ccSChao Yu #define stat_inc_rbtree_node_hit(sb) 253291c481ffSChao Yu #define stat_inc_largest_node_hit(sbi) 253391c481ffSChao Yu #define stat_inc_cached_node_hit(sbi) 2534d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) 2535d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) 25360dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) 25370dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) 25383289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) 25393289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) 254026a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) 254126a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) 254226a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) 2543648d50baSChao Yu #define stat_inc_volatile_write(inode) 2544648d50baSChao Yu #define stat_dec_volatile_write(inode) 2545648d50baSChao Yu #define stat_update_max_volatile_write(inode) 2546dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) 2547dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) 2548b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) 2549e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) 255039a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) 2551e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) 2552e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) 255339a53e0cSJaegeuk Kim 255439a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 255539a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2556787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 25574589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 255839a53e0cSJaegeuk Kim #endif 255939a53e0cSJaegeuk Kim 256039a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 256139a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 256239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 256339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 256439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 256539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 256639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 256739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2568cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 256939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 257029e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 25711001b347SHuajun Li 2572e18c65b2SHuajun Li /* 2573e18c65b2SHuajun Li * inline.c 2574e18c65b2SHuajun Li */ 2575cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2576cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2577cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2578bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2579cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2580cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2581cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2582cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2583cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2584cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2585cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2586cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2587cac5a3d8SDongOh Shin struct page *ipage); 2588cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2589cac5a3d8SDongOh Shin const struct qstr *orig_name, 2590cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2591cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2592cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2593cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2594cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2595cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2596cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2597cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2598cac5a3d8SDongOh Shin __u64 start, __u64 len); 2599cde4de12SJaegeuk Kim 2600cde4de12SJaegeuk Kim /* 26012658e50dSJaegeuk Kim * shrinker.c 26022658e50dSJaegeuk Kim */ 2603cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2604cac5a3d8SDongOh Shin struct shrink_control *sc); 2605cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2606cac5a3d8SDongOh Shin struct shrink_control *sc); 2607cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2608cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 26092658e50dSJaegeuk Kim 26102658e50dSJaegeuk Kim /* 2611a28ef1f5SChao Yu * extent_cache.c 2612a28ef1f5SChao Yu */ 2613004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 2614004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 2615004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 2616004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 2617004b6862SChao Yu unsigned int ofs); 2618004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 2619004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 2620004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 2621004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 2622004b6862SChao Yu bool force); 2623cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2624cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2625cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2626cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2627cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2628cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2629cac5a3d8SDongOh Shin struct extent_info *ei); 2630cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 263119b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2632cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2633cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2634a28ef1f5SChao Yu int __init create_extent_cache(void); 2635a28ef1f5SChao Yu void destroy_extent_cache(void); 2636a28ef1f5SChao Yu 2637a28ef1f5SChao Yu /* 2638cde4de12SJaegeuk Kim * crypto support 2639cde4de12SJaegeuk Kim */ 26400b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2641cde4de12SJaegeuk Kim { 2642cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2643cde4de12SJaegeuk Kim } 2644cde4de12SJaegeuk Kim 2645cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2646cde4de12SJaegeuk Kim { 2647cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2648cde4de12SJaegeuk Kim file_set_encrypt(inode); 2649cde4de12SJaegeuk Kim #endif 2650cde4de12SJaegeuk Kim } 2651cde4de12SJaegeuk Kim 2652cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2653cde4de12SJaegeuk Kim { 26540b81d077SJaegeuk Kim return bio->bi_private != NULL; 2655cde4de12SJaegeuk Kim } 2656cde4de12SJaegeuk Kim 2657cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2658cde4de12SJaegeuk Kim { 2659cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2660cde4de12SJaegeuk Kim } 2661f424f664SJaegeuk Kim 26620bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 266352763a4bSJaegeuk Kim { 26640bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 266552763a4bSJaegeuk Kim } 266652763a4bSJaegeuk Kim 2667178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2668178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 26693c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2670178053e2SDamien Le Moal { 2671178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 26723c62be17SJaegeuk Kim int i; 2673178053e2SDamien Le Moal 26743c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 26753c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 26763c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 26773c62be17SJaegeuk Kim return -EINVAL; 2678178053e2SDamien Le Moal } 2679178053e2SDamien Le Moal #endif 2680178053e2SDamien Le Moal 268196ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 268296ba2decSDamien Le Moal { 268396ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 268496ba2decSDamien Le Moal 268596ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 268652763a4bSJaegeuk Kim } 268752763a4bSJaegeuk Kim 268852763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 268952763a4bSJaegeuk Kim { 269052763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 269152763a4bSJaegeuk Kim clear_opt(sbi, LFS); 269252763a4bSJaegeuk Kim 269352763a4bSJaegeuk Kim switch (mt) { 269452763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 269552763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 269652763a4bSJaegeuk Kim break; 269752763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 269852763a4bSJaegeuk Kim set_opt(sbi, LFS); 269952763a4bSJaegeuk Kim break; 270052763a4bSJaegeuk Kim } 270152763a4bSJaegeuk Kim } 270252763a4bSJaegeuk Kim 2703fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 2704fcc85a4dSJaegeuk Kim { 2705fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2706886f56f9SAl Viro umode_t mode = inode->i_mode; 2707fcc85a4dSJaegeuk Kim 2708fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 2709fcc85a4dSJaegeuk Kim #else 2710fcc85a4dSJaegeuk Kim return 0; 2711fcc85a4dSJaegeuk Kim #endif 2712fcc85a4dSJaegeuk Kim } 2713fcc85a4dSJaegeuk Kim 271439a53e0cSJaegeuk Kim #endif 2715