17c1a000dSChao Yu // SPDX-License-Identifier: GPL-2.0 20a8165d7SJaegeuk Kim /* 339a53e0cSJaegeuk Kim * fs/f2fs/f2fs.h 439a53e0cSJaegeuk Kim * 539a53e0cSJaegeuk Kim * Copyright (c) 2012 Samsung Electronics Co., Ltd. 639a53e0cSJaegeuk Kim * http://www.samsung.com/ 739a53e0cSJaegeuk Kim */ 839a53e0cSJaegeuk Kim #ifndef _LINUX_F2FS_H 939a53e0cSJaegeuk Kim #define _LINUX_F2FS_H 1039a53e0cSJaegeuk Kim 11f847c699SChao Yu #include <linux/uio.h> 1239a53e0cSJaegeuk Kim #include <linux/types.h> 1339a53e0cSJaegeuk Kim #include <linux/page-flags.h> 1439a53e0cSJaegeuk Kim #include <linux/buffer_head.h> 1539a53e0cSJaegeuk Kim #include <linux/slab.h> 1639a53e0cSJaegeuk Kim #include <linux/crc32.h> 1739a53e0cSJaegeuk Kim #include <linux/magic.h> 18c2d715d1SJaegeuk Kim #include <linux/kobject.h> 197bd59381SGu Zheng #include <linux/sched.h> 207c2e5963SJaegeuk Kim #include <linux/cred.h> 2139307a8eSJaegeuk Kim #include <linux/vmalloc.h> 22740432f8SJaegeuk Kim #include <linux/bio.h> 23d0239e1bSJaegeuk Kim #include <linux/blkdev.h> 240abd675eSChao Yu #include <linux/quotaops.h> 2543b6573bSKeith Mok #include <crypto/hash.h> 2639a53e0cSJaegeuk Kim 27734f0d24SDave Chinner #include <linux/fscrypt.h> 2895ae251fSEric Biggers #include <linux/fsverity.h> 29734f0d24SDave Chinner 305d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 319850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 325d56b671SJaegeuk Kim #else 339850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 349850cf4aSJaegeuk Kim do { \ 359850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 369850cf4aSJaegeuk Kim WARN_ON(1); \ 37caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 389850cf4aSJaegeuk Kim } \ 399850cf4aSJaegeuk Kim } while (0) 405d56b671SJaegeuk Kim #endif 415d56b671SJaegeuk Kim 422c63feadSJaegeuk Kim enum { 432c63feadSJaegeuk Kim FAULT_KMALLOC, 44628b3d14SChao Yu FAULT_KVMALLOC, 45c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 4601eccef7SChao Yu FAULT_PAGE_GET, 47d62fe971SChao Yu FAULT_ALLOC_BIO, 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, 546f5c2ed0SChao Yu FAULT_READ_IO, 550f348028SChao Yu FAULT_CHECKPOINT, 56b83dcfe6SChao Yu FAULT_DISCARD, 576f5c2ed0SChao Yu FAULT_WRITE_IO, 582c63feadSJaegeuk Kim FAULT_MAX, 592c63feadSJaegeuk Kim }; 602c63feadSJaegeuk Kim 617fa750a1SArnd Bergmann #ifdef CONFIG_F2FS_FAULT_INJECTION 62d494500aSChao Yu #define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1) 63d494500aSChao Yu 6408796897SSheng Yong struct f2fs_fault_info { 6508796897SSheng Yong atomic_t inject_ops; 6608796897SSheng Yong unsigned int inject_rate; 6708796897SSheng Yong unsigned int inject_type; 6808796897SSheng Yong }; 6908796897SSheng Yong 7019880e6eSAlexey Dobriyan extern const char *f2fs_fault_name[FAULT_MAX]; 7168afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 722c63feadSJaegeuk Kim #endif 732c63feadSJaegeuk Kim 7439a53e0cSJaegeuk Kim /* 7539a53e0cSJaegeuk Kim * For mount options 7639a53e0cSJaegeuk Kim */ 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 8039a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 8139a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 8239a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 8339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 84444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 851001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8634d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8734d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8834d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 89d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 9089672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 916aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 92343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 9373faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 9436abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 9536abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 960abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA 0x00080000 970abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA 0x00100000 985c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA 0x00200000 994b2414d0SChao Yu #define F2FS_MOUNT_QUOTA 0x00400000 1006afc662eSChao Yu #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 1017e65be49SJaegeuk Kim #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 1024354994fSDaniel Rosenberg #define F2FS_MOUNT_DISABLE_CHECKPOINT 0x02000000 10339a53e0cSJaegeuk Kim 10463189b78SChao Yu #define F2FS_OPTION(sbi) ((sbi)->mount_opt) 10563189b78SChao Yu #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) 10663189b78SChao Yu #define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option) 10763189b78SChao Yu #define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option) 10839a53e0cSJaegeuk Kim 10939a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 11039a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 11139a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 11239a53e0cSJaegeuk Kim 113a9841c4dSJaegeuk Kim typedef u32 block_t; /* 114a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 115a9841c4dSJaegeuk Kim * address format, __le32. 116a9841c4dSJaegeuk Kim */ 11739a53e0cSJaegeuk Kim typedef u32 nid_t; 11839a53e0cSJaegeuk Kim 11939a53e0cSJaegeuk Kim struct f2fs_mount_info { 12039a53e0cSJaegeuk Kim unsigned int opt; 12163189b78SChao Yu int write_io_size_bits; /* Write IO size bits */ 12263189b78SChao Yu block_t root_reserved_blocks; /* root reserved blocks */ 12363189b78SChao Yu kuid_t s_resuid; /* reserved blocks for uid */ 12463189b78SChao Yu kgid_t s_resgid; /* reserved blocks for gid */ 12563189b78SChao Yu int active_logs; /* # of active logs */ 12663189b78SChao Yu int inline_xattr_size; /* inline xattr size */ 12763189b78SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 12863189b78SChao Yu struct f2fs_fault_info fault_info; /* For fault injection */ 12963189b78SChao Yu #endif 13063189b78SChao Yu #ifdef CONFIG_QUOTA 13163189b78SChao Yu /* Names of quota files with journalled quota */ 13263189b78SChao Yu char *s_qf_names[MAXQUOTAS]; 13363189b78SChao Yu int s_jquota_fmt; /* Format of quota to use */ 13463189b78SChao Yu #endif 13563189b78SChao Yu /* For which write hints are passed down to block layer */ 13663189b78SChao Yu int whint_mode; 13763189b78SChao Yu int alloc_mode; /* segment allocation policy */ 13863189b78SChao Yu int fsync_mode; /* fsync policy */ 139ff62af20SSheng Yong bool test_dummy_encryption; /* test dummy encryption */ 1404d3aed70SDaniel Rosenberg block_t unusable_cap; /* Amount of space allowed to be 1414d3aed70SDaniel Rosenberg * unusable when disabling checkpoint 1424d3aed70SDaniel Rosenberg */ 14339a53e0cSJaegeuk Kim }; 14439a53e0cSJaegeuk Kim 145cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1460bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 147e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1487a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1495c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 150704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 1516afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 152234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO 0x0080 1531c1d35dfSChao Yu #define F2FS_FEATURE_INODE_CRTIME 0x0100 154b7c409deSSheng Yong #define F2FS_FEATURE_LOST_FOUND 0x0200 15595ae251fSEric Biggers #define F2FS_FEATURE_VERITY 0x0400 156d440c52dSJunling Zheng #define F2FS_FEATURE_SB_CHKSUM 0x0800 1575aba5430SDaniel Rosenberg #define F2FS_FEATURE_CASEFOLD 0x1000 158cde4de12SJaegeuk Kim 1597beb01f7SChao Yu #define __F2FS_HAS_FEATURE(raw_super, mask) \ 1607beb01f7SChao Yu ((raw_super->feature & cpu_to_le32(mask)) != 0) 1617beb01f7SChao Yu #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask) 1627beb01f7SChao Yu #define F2FS_SET_FEATURE(sbi, mask) \ 1637beb01f7SChao Yu (sbi->raw_super->feature |= cpu_to_le32(mask)) 1647beb01f7SChao Yu #define F2FS_CLEAR_FEATURE(sbi, mask) \ 1657beb01f7SChao Yu (sbi->raw_super->feature &= ~cpu_to_le32(mask)) 16676f105a2SJaegeuk Kim 16739a53e0cSJaegeuk Kim /* 1687c2e5963SJaegeuk Kim * Default values for user and/or group using reserved blocks 1697c2e5963SJaegeuk Kim */ 1707c2e5963SJaegeuk Kim #define F2FS_DEF_RESUID 0 1717c2e5963SJaegeuk Kim #define F2FS_DEF_RESGID 0 1727c2e5963SJaegeuk Kim 1737c2e5963SJaegeuk Kim /* 17439a53e0cSJaegeuk Kim * For checkpoint manager 17539a53e0cSJaegeuk Kim */ 17639a53e0cSJaegeuk Kim enum { 17739a53e0cSJaegeuk Kim NAT_BITMAP, 17839a53e0cSJaegeuk Kim SIT_BITMAP 17939a53e0cSJaegeuk Kim }; 18039a53e0cSJaegeuk Kim 181c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 182c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 183c473f1a9SChao Yu #define CP_SYNC 0x00000004 184c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 185c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1861f43e2adSChao Yu #define CP_TRIMMED 0x00000020 1874354994fSDaniel Rosenberg #define CP_PAUSE 0x00000040 18875ab4cb8SJaegeuk Kim 1894ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 190ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 191969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 192f9d1dcedSYunlei He #define DEF_MID_DISCARD_ISSUE_TIME 500 /* 500 ms, if device busy */ 193969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 1948bb4f253SJaegeuk Kim #define DEF_DISCARD_URGENT_UTIL 80 /* do more discard over 80% */ 19560b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 196dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 1974354994fSDaniel Rosenberg #define DEF_DISABLE_INTERVAL 5 /* 5 secs */ 198db610a64SJaegeuk Kim #define DEF_DISABLE_QUICK_INTERVAL 1 /* 1 secs */ 19903f2c02dSJaegeuk Kim #define DEF_UMOUNT_DISCARD_TIMEOUT 5 /* 5 secs */ 200bba681cbSJaegeuk Kim 20175ab4cb8SJaegeuk Kim struct cp_control { 20275ab4cb8SJaegeuk Kim int reason; 2034b2fecc8SJaegeuk Kim __u64 trim_start; 2044b2fecc8SJaegeuk Kim __u64 trim_end; 2054b2fecc8SJaegeuk Kim __u64 trim_minlen; 20675ab4cb8SJaegeuk Kim }; 20775ab4cb8SJaegeuk Kim 208662befdaSChao Yu /* 209e1da7872SChao Yu * indicate meta/data type 210662befdaSChao Yu */ 211662befdaSChao Yu enum { 212662befdaSChao Yu META_CP, 213662befdaSChao Yu META_NAT, 21481c1a0f1SChao Yu META_SIT, 2154c521f49SJaegeuk Kim META_SSA, 216b63e7be5SChao Yu META_MAX, 2174c521f49SJaegeuk Kim META_POR, 21893770ab7SChao Yu DATA_GENERIC, /* check range only */ 21993770ab7SChao Yu DATA_GENERIC_ENHANCE, /* strong check on range and segment bitmap */ 22093770ab7SChao Yu DATA_GENERIC_ENHANCE_READ, /* 22193770ab7SChao Yu * strong check on range and segment 22293770ab7SChao Yu * bitmap but no warning due to race 22393770ab7SChao Yu * condition of read on truncated area 22493770ab7SChao Yu * by extent_cache 22593770ab7SChao Yu */ 226e1da7872SChao Yu META_GENERIC, 227662befdaSChao Yu }; 228662befdaSChao Yu 2296451e041SJaegeuk Kim /* for the list of ino */ 2306451e041SJaegeuk Kim enum { 2316451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 232fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 233fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 2340a007b97SJaegeuk Kim TRANS_DIR_INO, /* for trasactions dir ino list */ 23539d787beSChao Yu FLUSH_INO, /* for multiple device flushing */ 2366451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 2376451e041SJaegeuk Kim }; 2386451e041SJaegeuk Kim 2396451e041SJaegeuk Kim struct ino_entry { 24039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 24139a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 24239d787beSChao Yu unsigned int dirty_device; /* dirty device bitmap */ 24339a53e0cSJaegeuk Kim }; 24439a53e0cSJaegeuk Kim 2452710fd7eSChao Yu /* for the list of inodes to be GCed */ 24606292073SChao Yu struct inode_entry { 24739a53e0cSJaegeuk Kim struct list_head list; /* list head */ 24839a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 24939a53e0cSJaegeuk Kim }; 25039a53e0cSJaegeuk Kim 25150fa53ecSChao Yu struct fsync_node_entry { 25250fa53ecSChao Yu struct list_head list; /* list head */ 25350fa53ecSChao Yu struct page *page; /* warm node page pointer */ 25450fa53ecSChao Yu unsigned int seq_id; /* sequence id */ 25550fa53ecSChao Yu }; 25650fa53ecSChao Yu 257a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 2587fd9e544SJaegeuk Kim struct discard_entry { 2597fd9e544SJaegeuk Kim struct list_head list; /* list head */ 260a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 261a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 2627fd9e544SJaegeuk Kim }; 2637fd9e544SJaegeuk Kim 264969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 265969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 266969d1b18SChao Yu 267ba48a33eSChao Yu /* max discard pend list number */ 268ba48a33eSChao Yu #define MAX_PLIST_NUM 512 269ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 2702f84babfSSheng Yong (MAX_PLIST_NUM - 1) : ((blk_num) - 1)) 271ba48a33eSChao Yu 27215469963SJaegeuk Kim enum { 27335ec7d57SChao Yu D_PREP, /* initial */ 27435ec7d57SChao Yu D_PARTIAL, /* partially submitted */ 27535ec7d57SChao Yu D_SUBMIT, /* all submitted */ 27635ec7d57SChao Yu D_DONE, /* finished */ 27715469963SJaegeuk Kim }; 27815469963SJaegeuk Kim 279004b6862SChao Yu struct discard_info { 280b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 281b01a9201SJaegeuk Kim block_t len; /* length */ 282004b6862SChao Yu block_t start; /* actual start address in dev */ 283004b6862SChao Yu }; 284004b6862SChao Yu 285b01a9201SJaegeuk Kim struct discard_cmd { 286004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 287004b6862SChao Yu union { 288004b6862SChao Yu struct { 289004b6862SChao Yu block_t lstart; /* logical start address */ 290004b6862SChao Yu block_t len; /* length */ 291004b6862SChao Yu block_t start; /* actual start address in dev */ 292004b6862SChao Yu }; 293004b6862SChao Yu struct discard_info di; /* discard info */ 294004b6862SChao Yu 295004b6862SChao Yu }; 296b01a9201SJaegeuk Kim struct list_head list; /* command list */ 297b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 298c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 299ec9895adSChao Yu unsigned short ref; /* reference count */ 3009a744b92SChao Yu unsigned char state; /* state */ 30172691af6SJaegeuk Kim unsigned char queued; /* queued discard */ 302c81abe34SJaegeuk Kim int error; /* bio error */ 30335ec7d57SChao Yu spinlock_t lock; /* for state/bio_ref updating */ 30435ec7d57SChao Yu unsigned short bio_ref; /* bio reference count */ 305275b66b0SChao Yu }; 306275b66b0SChao Yu 30778997b56SChao Yu enum { 30878997b56SChao Yu DPOLICY_BG, 30978997b56SChao Yu DPOLICY_FORCE, 31078997b56SChao Yu DPOLICY_FSTRIM, 31178997b56SChao Yu DPOLICY_UMOUNT, 31278997b56SChao Yu MAX_DPOLICY, 31378997b56SChao Yu }; 31478997b56SChao Yu 315ecc9aa00SChao Yu struct discard_policy { 31678997b56SChao Yu int type; /* type of discard */ 317ecc9aa00SChao Yu unsigned int min_interval; /* used for candidates exist */ 318f9d1dcedSYunlei He unsigned int mid_interval; /* used for device busy */ 319ecc9aa00SChao Yu unsigned int max_interval; /* used for candidates not exist */ 320ecc9aa00SChao Yu unsigned int max_requests; /* # of discards issued per round */ 321ecc9aa00SChao Yu unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ 322ecc9aa00SChao Yu bool io_aware; /* issue discard in idle time */ 323ecc9aa00SChao Yu bool sync; /* submit discard with REQ_SYNC flag */ 32420ee4382SChao Yu bool ordered; /* issue discard by lba order */ 32578997b56SChao Yu unsigned int granularity; /* discard granularity */ 32603f2c02dSJaegeuk Kim int timeout; /* discard timeout for put_super */ 327ecc9aa00SChao Yu }; 328ecc9aa00SChao Yu 3290b54fb84SJaegeuk Kim struct discard_cmd_control { 33015469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 33146f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 332ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 33346f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 3348412663dSChao Yu struct list_head fstrim_list; /* in-flight discard from fstrim */ 33515469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 336969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 33715469963SJaegeuk Kim struct mutex cmd_lock; 338d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 339d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 340969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 341d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 34220ee4382SChao Yu unsigned int next_pos; /* next discard position */ 3438b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 34472691af6SJaegeuk Kim atomic_t queued_discard; /* # of queued discard */ 3455f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 3464dada3fdSChao Yu struct rb_root_cached root; /* root of discard rb-tree */ 34767fce70bSChao Yu bool rbtree_check; /* config for consistence check */ 34839a53e0cSJaegeuk Kim }; 34939a53e0cSJaegeuk Kim 35039a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 35139a53e0cSJaegeuk Kim struct fsync_inode_entry { 35239a53e0cSJaegeuk Kim struct list_head list; /* list head */ 35339a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 354c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 355c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 35639a53e0cSJaegeuk Kim }; 35739a53e0cSJaegeuk Kim 35868afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 35968afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 36039a53e0cSJaegeuk Kim 36168afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 36268afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 36368afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 36468afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 36539a53e0cSJaegeuk Kim 366dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 367dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 368309cc2b6SJaegeuk Kim 369dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 37039a53e0cSJaegeuk Kim { 371dfc08a12SChao Yu int before = nats_in_cursum(journal); 372cac5a3d8SDongOh Shin 373dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 37439a53e0cSJaegeuk Kim return before; 37539a53e0cSJaegeuk Kim } 37639a53e0cSJaegeuk Kim 377dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 37839a53e0cSJaegeuk Kim { 379dfc08a12SChao Yu int before = sits_in_cursum(journal); 380cac5a3d8SDongOh Shin 381dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 38239a53e0cSJaegeuk Kim return before; 38339a53e0cSJaegeuk Kim } 38439a53e0cSJaegeuk Kim 385dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 386dfc08a12SChao Yu int size, int type) 387184a5cd2SChao Yu { 388184a5cd2SChao Yu if (type == NAT_JOURNAL) 389dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 390dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 391184a5cd2SChao Yu } 392184a5cd2SChao Yu 39339a53e0cSJaegeuk Kim /* 394e9750824SNamjae Jeon * ioctl commands 395e9750824SNamjae Jeon */ 396e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 397e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 398d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 399e9750824SNamjae Jeon 40088b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 40188b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 40288b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 40302a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 4041e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 4051e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 406d07efb50SJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32) 407456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 408d07efb50SJaegeuk Kim #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \ 409d07efb50SJaegeuk Kim struct f2fs_defragment) 4104dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 4114dd6f977SJaegeuk Kim struct f2fs_move_range) 412e066b83cSJaegeuk Kim #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ 413e066b83cSJaegeuk Kim struct f2fs_flush_device) 41434dc77adSJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ 41534dc77adSJaegeuk Kim struct f2fs_gc_range) 416e65ef207SJaegeuk Kim #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) 4171ad71a27SJaegeuk Kim #define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32) 4181ad71a27SJaegeuk Kim #define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32) 419c4020b2dSChao Yu #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) 42004f0b2eaSQiuyang Sun #define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64) 42188b88a66SJaegeuk Kim 4224507847cSChao Yu #define F2FS_IOC_GET_VOLUME_NAME FS_IOC_GETFSLABEL 4234507847cSChao Yu #define F2FS_IOC_SET_VOLUME_NAME FS_IOC_SETFSLABEL 4244507847cSChao Yu 4250b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 4260b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 4270b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 428f424f664SJaegeuk Kim 4291abff93dSJaegeuk Kim /* 4301abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 4311abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 4321abff93dSJaegeuk Kim */ 4331abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 4341abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 4351abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 4361abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 437c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 4380cd6d9b0SJaegeuk Kim #define F2FS_GOING_DOWN_NEED_FSCK 0x4 /* going down to trigger fsck */ 4391abff93dSJaegeuk Kim 440e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 441e9750824SNamjae Jeon /* 442e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 443e9750824SNamjae Jeon */ 444e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 445e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 44604ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 447e9750824SNamjae Jeon #endif 448e9750824SNamjae Jeon 4492c1d0305SChao Yu #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR 4502c1d0305SChao Yu #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR 4512c1d0305SChao Yu 45234dc77adSJaegeuk Kim struct f2fs_gc_range { 45334dc77adSJaegeuk Kim u32 sync; 45434dc77adSJaegeuk Kim u64 start; 45534dc77adSJaegeuk Kim u64 len; 45634dc77adSJaegeuk Kim }; 45734dc77adSJaegeuk Kim 458d323d005SChao Yu struct f2fs_defragment { 459d323d005SChao Yu u64 start; 460d323d005SChao Yu u64 len; 461d323d005SChao Yu }; 462d323d005SChao Yu 4634dd6f977SJaegeuk Kim struct f2fs_move_range { 4644dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 4654dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 4664dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 4674dd6f977SJaegeuk Kim u64 len; /* size to move */ 4684dd6f977SJaegeuk Kim }; 4694dd6f977SJaegeuk Kim 470e066b83cSJaegeuk Kim struct f2fs_flush_device { 471e066b83cSJaegeuk Kim u32 dev_num; /* device number to flush */ 472e066b83cSJaegeuk Kim u32 segments; /* # of segments to flush */ 473e066b83cSJaegeuk Kim }; 474e066b83cSJaegeuk Kim 475f2470371SChao Yu /* for inline stuff */ 476f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 4777a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 4786afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode); 4797a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 4807a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 481b323fd28SChao Yu get_inline_xattr_addrs(inode) - \ 4826afc662eSChao Yu DEF_INLINE_RESERVED_SIZE)) 483f2470371SChao Yu 484f2470371SChao Yu /* for inline dir */ 485f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 486f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 487f2470371SChao Yu BITS_PER_BYTE + 1)) 488f91108b8SGeert Uytterhoeven #define INLINE_DENTRY_BITMAP_SIZE(inode) \ 489f91108b8SGeert Uytterhoeven DIV_ROUND_UP(NR_INLINE_DENTRY(inode), BITS_PER_BYTE) 490f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 491f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 492f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 493f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 494f2470371SChao Yu 495e9750824SNamjae Jeon /* 49639a53e0cSJaegeuk Kim * For INODE and NODE manager 49739a53e0cSJaegeuk Kim */ 4987b3cd7d6SJaegeuk Kim /* for directory operations */ 4997b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 500d8c6822aSJaegeuk Kim struct inode *inode; 50176a9dd85SChao Yu void *bitmap; 5027b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 5037b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 5047b3cd7d6SJaegeuk Kim int max; 50576a9dd85SChao Yu int nr_bitmap; 5067b3cd7d6SJaegeuk Kim }; 5077b3cd7d6SJaegeuk Kim 50864c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 50964c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 5107b3cd7d6SJaegeuk Kim { 511d8c6822aSJaegeuk Kim d->inode = inode; 5127b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 51376a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 514c79d1520SYunlong Song d->bitmap = t->dentry_bitmap; 5157b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 5167b3cd7d6SJaegeuk Kim d->filename = t->filename; 51764c24ecbSTomohiro Kusumi } 518cac5a3d8SDongOh Shin 51964c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 520f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 52164c24ecbSTomohiro Kusumi { 522f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 523f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 524f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 525f2470371SChao Yu 52664c24ecbSTomohiro Kusumi d->inode = inode; 527f2470371SChao Yu d->max = entry_cnt; 528f2470371SChao Yu d->nr_bitmap = bitmap_size; 529f2470371SChao Yu d->bitmap = t; 530f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 531f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 532f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 5337b3cd7d6SJaegeuk Kim } 5347b3cd7d6SJaegeuk Kim 535dbe6a5ffSJaegeuk Kim /* 536dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 537dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 538dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 53939a53e0cSJaegeuk Kim */ 540dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 541dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 542266e97a8SJaegeuk Kim enum { 543266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 544266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 545266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 546266e97a8SJaegeuk Kim * look up a node with readahead called 5474f4124d0SChao Yu * by get_data_block. 54839a53e0cSJaegeuk Kim */ 549266e97a8SJaegeuk Kim }; 550266e97a8SJaegeuk Kim 5517735730dSChao Yu #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO count */ 5527735730dSChao Yu 553af033b2aSChao Yu /* maximum retry quota flush count */ 554af033b2aSChao Yu #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT 8 555af033b2aSChao Yu 556a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 55739a53e0cSJaegeuk Kim 558817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 559817202d9SChao Yu 56039a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 56113054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 56213054c54SChao Yu 56313054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 56413054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 565c11abd1aSJaegeuk Kim 56654c2258cSChao Yu struct rb_entry { 56754c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 56854c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 56954c2258cSChao Yu unsigned int len; /* length of the entry */ 57054c2258cSChao Yu }; 57154c2258cSChao Yu 57239a53e0cSJaegeuk Kim struct extent_info { 57339a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 574111d2495SMasanari Iida unsigned int len; /* length of the extent */ 57554c2258cSChao Yu u32 blk; /* start block address of the extent */ 57639a53e0cSJaegeuk Kim }; 57739a53e0cSJaegeuk Kim 57813054c54SChao Yu struct extent_node { 579c0362117SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 58013054c54SChao Yu struct extent_info ei; /* extent info */ 58154c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 582201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 58313054c54SChao Yu }; 58413054c54SChao Yu 58513054c54SChao Yu struct extent_tree { 58613054c54SChao Yu nid_t ino; /* inode number */ 5874dada3fdSChao Yu struct rb_root_cached root; /* root of extent info rb-tree */ 58862c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 5893e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 590137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 59113054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 59268e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 593b430f726SZhikang Zhang bool largest_updated; /* largest extent updated */ 59413054c54SChao Yu }; 59513054c54SChao Yu 59639a53e0cSJaegeuk Kim /* 597003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 598003a3e1dSJaegeuk Kim * 599003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 600003a3e1dSJaegeuk Kim */ 601003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 602003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 6037f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 6047f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 6057f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 606003a3e1dSJaegeuk Kim 607003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 608003a3e1dSJaegeuk Kim block_t m_pblk; 609003a3e1dSJaegeuk Kim block_t m_lblk; 610003a3e1dSJaegeuk Kim unsigned int m_len; 611003a3e1dSJaegeuk Kim unsigned int m_flags; 612da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 613c4020b2dSChao Yu pgoff_t *m_next_extent; /* point to next possible extent */ 614d5097be5SHyunchul Lee int m_seg_type; 615f9d6d059SChao Yu bool m_may_create; /* indicate it is from write path */ 616003a3e1dSJaegeuk Kim }; 617003a3e1dSJaegeuk Kim 618e2b4e2bcSChao Yu /* for flag in get_data_block */ 619f2220c7fSQiuyang Sun enum { 620f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 621f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 622f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 6230a4daae5SJaegeuk Kim F2FS_GET_BLOCK_DIO, 624f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 625f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 626c4020b2dSChao Yu F2FS_GET_BLOCK_PRECACHE, 627f2220c7fSQiuyang Sun }; 628e2b4e2bcSChao Yu 629003a3e1dSJaegeuk Kim /* 63039a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 63139a53e0cSJaegeuk Kim */ 63239a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 633354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 634cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 635e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 63626787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 637b6a06cbbSChao Yu #define FADVISE_HOT_BIT 0x20 63895ae251fSEric Biggers #define FADVISE_VERITY_BIT 0x40 63939a53e0cSJaegeuk Kim 640797c1cb5SChao Yu #define FADVISE_MODIFIABLE_BITS (FADVISE_COLD_BIT | FADVISE_HOT_BIT) 641797c1cb5SChao Yu 642b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 643b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 644b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 645b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 646b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 647b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 648cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 649cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 650cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 651e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 652e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 65326787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 65426787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 655b6a06cbbSChao Yu #define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT) 656b6a06cbbSChao Yu #define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT) 657b6a06cbbSChao Yu #define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT) 65895ae251fSEric Biggers #define file_is_verity(inode) is_file(inode, FADVISE_VERITY_BIT) 65995ae251fSEric Biggers #define file_set_verity(inode) set_file(inode, FADVISE_VERITY_BIT) 660cde4de12SJaegeuk Kim 661ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 662ab9fa662SJaegeuk Kim 6632ef79ecbSChao Yu enum { 6642ef79ecbSChao Yu GC_FAILURE_PIN, 6652ef79ecbSChao Yu GC_FAILURE_ATOMIC, 6662ef79ecbSChao Yu MAX_GC_FAILURE 6672ef79ecbSChao Yu }; 6682ef79ecbSChao Yu 66939a53e0cSJaegeuk Kim struct f2fs_inode_info { 67039a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 67139a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 67239a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 67338431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 6741ad71a27SJaegeuk Kim unsigned int i_current_depth; /* only for directory depth */ 6752ef79ecbSChao Yu /* for gc failure statistic */ 6762ef79ecbSChao Yu unsigned int i_gc_failures[MAX_GC_FAILURE]; 6776666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 67839a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 67939a53e0cSJaegeuk Kim 68039a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 68139a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 682d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 683204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 68439a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 68539a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 68688c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 687b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 68839a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 68926de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 69088b88a66SJaegeuk Kim 6910abd675eSChao Yu #ifdef CONFIG_QUOTA 6920abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 6930abd675eSChao Yu 6940abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 6950abd675eSChao Yu qsize_t i_reserved_quota; 6960abd675eSChao Yu #endif 6970f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 6980f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 69957864ae5SJaegeuk Kim struct list_head inmem_ilist; /* list for inmem inodes */ 70088b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 7017a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 70288b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 7033e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 704b2532c69SChao Yu 705b2532c69SChao Yu /* avoid racing between foreground op and gc */ 706b2532c69SChao Yu struct rw_semaphore i_gc_rwsem[2]; 7075a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 70827161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 709f2470371SChao Yu 7107a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 7115c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 7126afc662eSChao Yu int i_inline_xattr_size; /* inline xattr size */ 71324b81dfcSArnd Bergmann struct timespec64 i_crtime; /* inode creation time */ 71424b81dfcSArnd Bergmann struct timespec64 i_disk_time[4];/* inode disk times */ 71539a53e0cSJaegeuk Kim }; 71639a53e0cSJaegeuk Kim 71739a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 718bd933d4fSChao Yu struct f2fs_extent *i_ext) 71939a53e0cSJaegeuk Kim { 720bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 721bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 722bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 72339a53e0cSJaegeuk Kim } 72439a53e0cSJaegeuk Kim 72539a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 72639a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 72739a53e0cSJaegeuk Kim { 72839a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 7294d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 73039a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 73139a53e0cSJaegeuk Kim } 73239a53e0cSJaegeuk Kim 733429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 734429511cdSChao Yu u32 blk, unsigned int len) 735429511cdSChao Yu { 736429511cdSChao Yu ei->fofs = fofs; 737429511cdSChao Yu ei->blk = blk; 738429511cdSChao Yu ei->len = len; 739429511cdSChao Yu } 740429511cdSChao Yu 741004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 74235ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 743004b6862SChao Yu { 7449a997188SJaegeuk Kim return (back->lstart + back->len == front->lstart) && 74535ec7d57SChao Yu (back->len + front->len <= max_len); 746004b6862SChao Yu } 747004b6862SChao Yu 748004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 74935ec7d57SChao Yu struct discard_info *back, unsigned int max_len) 750004b6862SChao Yu { 75135ec7d57SChao Yu return __is_discard_mergeable(back, cur, max_len); 752004b6862SChao Yu } 753004b6862SChao Yu 754004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 75535ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 756004b6862SChao Yu { 75735ec7d57SChao Yu return __is_discard_mergeable(cur, front, max_len); 758004b6862SChao Yu } 759004b6862SChao Yu 760429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 761429511cdSChao Yu struct extent_info *front) 762429511cdSChao Yu { 763429511cdSChao Yu return (back->fofs + back->len == front->fofs && 764429511cdSChao Yu back->blk + back->len == front->blk); 765429511cdSChao Yu } 766429511cdSChao Yu 767429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 768429511cdSChao Yu struct extent_info *back) 769429511cdSChao Yu { 770429511cdSChao Yu return __is_extent_mergeable(back, cur); 771429511cdSChao Yu } 772429511cdSChao Yu 773429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 774429511cdSChao Yu struct extent_info *front) 775429511cdSChao Yu { 776429511cdSChao Yu return __is_extent_mergeable(cur, front); 777429511cdSChao Yu } 778429511cdSChao Yu 779cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 780b430f726SZhikang Zhang static inline void __try_update_largest_extent(struct extent_tree *et, 781b430f726SZhikang Zhang struct extent_node *en) 7824abd3f5aSChao Yu { 783205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 7844abd3f5aSChao Yu et->largest = en->ei; 785b430f726SZhikang Zhang et->largest_updated = true; 786205b9822SJaegeuk Kim } 7874abd3f5aSChao Yu } 7884abd3f5aSChao Yu 7899a4ffdf5SChao Yu /* 7909a4ffdf5SChao Yu * For free nid management 7919a4ffdf5SChao Yu */ 7929a4ffdf5SChao Yu enum nid_state { 7939a4ffdf5SChao Yu FREE_NID, /* newly added to free nid list */ 7949a4ffdf5SChao Yu PREALLOC_NID, /* it is preallocated */ 7959a4ffdf5SChao Yu MAX_NID_STATE, 796b8559dc2SChao Yu }; 797b8559dc2SChao Yu 79839a53e0cSJaegeuk Kim struct f2fs_nm_info { 79939a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 80039a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 80104d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 80239a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 803cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 804ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 8052304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 80639a53e0cSJaegeuk Kim 80739a53e0cSJaegeuk Kim /* NAT cache management */ 80839a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 809309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 810b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 81139a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 81222969158SChao Yu spinlock_t nat_list_lock; /* protect clean nat entry list */ 813309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 814aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 81522ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 81639a53e0cSJaegeuk Kim 81739a53e0cSJaegeuk Kim /* free node ids management */ 8188a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 8199a4ffdf5SChao Yu struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ 8209a4ffdf5SChao Yu unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 821b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 82239a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 823bb1105e4SJaegeuk Kim unsigned char **free_nid_bitmap; 8244ac91242SChao Yu unsigned char *nat_block_bitmap; 825586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 82639a53e0cSJaegeuk Kim 82739a53e0cSJaegeuk Kim /* for checkpoint */ 82839a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 82922ad0b6aSJaegeuk Kim 83022ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 83122ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 83222ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 83322ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 834599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 835599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 836599a09b2SChao Yu #endif 83739a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 83839a53e0cSJaegeuk Kim }; 83939a53e0cSJaegeuk Kim 84039a53e0cSJaegeuk Kim /* 84139a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 84239a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 84339a53e0cSJaegeuk Kim * by the data offset in a file. 84439a53e0cSJaegeuk Kim */ 84539a53e0cSJaegeuk Kim struct dnode_of_data { 84639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 84739a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 84839a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 84939a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 85039a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 85139a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 85293bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 8533cf45747SChao Yu char cur_level; /* level of hole node page */ 8543cf45747SChao Yu char max_level; /* level of current page located */ 85539a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 85639a53e0cSJaegeuk Kim }; 85739a53e0cSJaegeuk Kim 85839a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 85939a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 86039a53e0cSJaegeuk Kim { 861d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 86239a53e0cSJaegeuk Kim dn->inode = inode; 86339a53e0cSJaegeuk Kim dn->inode_page = ipage; 86439a53e0cSJaegeuk Kim dn->node_page = npage; 86539a53e0cSJaegeuk Kim dn->nid = nid; 86639a53e0cSJaegeuk Kim } 86739a53e0cSJaegeuk Kim 86839a53e0cSJaegeuk Kim /* 86939a53e0cSJaegeuk Kim * For SIT manager 87039a53e0cSJaegeuk Kim * 87139a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 87239a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 87339a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 87439a53e0cSJaegeuk Kim * respectively. 87539a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 87639a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 87739a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 87839a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 87939a53e0cSJaegeuk Kim * data and 8 for node logs. 88039a53e0cSJaegeuk Kim */ 88139a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 88239a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 88339a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 88439a53e0cSJaegeuk Kim 88539a53e0cSJaegeuk Kim enum { 88639a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 88739a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 88839a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 88939a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 89039a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 89139a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 89238aa0889SJaegeuk Kim NO_CHECK_TYPE, 893f5a53edcSJaegeuk Kim CURSEG_COLD_DATA_PINNED,/* cold data for pinned file */ 89439a53e0cSJaegeuk Kim }; 89539a53e0cSJaegeuk Kim 8966b4afdd7SJaegeuk Kim struct flush_cmd { 8976b4afdd7SJaegeuk Kim struct completion wait; 898721bd4d5SGu Zheng struct llist_node llnode; 89939d787beSChao Yu nid_t ino; 9006b4afdd7SJaegeuk Kim int ret; 9016b4afdd7SJaegeuk Kim }; 9026b4afdd7SJaegeuk Kim 903a688b9d9SGu Zheng struct flush_cmd_control { 904a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 905a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 9068b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 90772691af6SJaegeuk Kim atomic_t queued_flush; /* # of queued flushes */ 908721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 909721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 910a688b9d9SGu Zheng }; 911a688b9d9SGu Zheng 91239a53e0cSJaegeuk Kim struct f2fs_sm_info { 91339a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 91439a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 91539a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 91639a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 91739a53e0cSJaegeuk Kim 9182b60311dSChao Yu struct rw_semaphore curseg_lock; /* for preventing curseg change */ 9192b60311dSChao Yu 92039a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 92139a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 92239a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 92339a53e0cSJaegeuk Kim 92439a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 92539a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 92639a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 92739a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 92881eb8d6eSJaegeuk Kim 92981eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 93081eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 9317fd9e544SJaegeuk Kim 932bba681cbSJaegeuk Kim /* for batched trimming */ 933bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 934bba681cbSJaegeuk Kim 935184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 936184a5cd2SChao Yu 937216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 938216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 939c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 940853137ceSJaegeuk Kim unsigned int min_seq_blocks; /* threshold for sequential blocks */ 941ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 942a2a12b67SChao Yu unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ 9436b4afdd7SJaegeuk Kim 9446b4afdd7SJaegeuk Kim /* for flush command control */ 945b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 946a688b9d9SGu Zheng 9470b54fb84SJaegeuk Kim /* for discard command control */ 9480b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 94939a53e0cSJaegeuk Kim }; 95039a53e0cSJaegeuk Kim 95139a53e0cSJaegeuk Kim /* 95239a53e0cSJaegeuk Kim * For superblock 95339a53e0cSJaegeuk Kim */ 95439a53e0cSJaegeuk Kim /* 95539a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 95639a53e0cSJaegeuk Kim * 95739a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 95839a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 95939a53e0cSJaegeuk Kim */ 96036951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 96139a53e0cSJaegeuk Kim enum count_type { 96239a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 963c227f912SChao Yu F2FS_DIRTY_DATA, 9642c8a4a28SJaegeuk Kim F2FS_DIRTY_QDATA, 96539a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 96639a53e0cSJaegeuk Kim F2FS_DIRTY_META, 9678dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 9680f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 96936951b38SChao Yu F2FS_WB_CP_DATA, 97036951b38SChao Yu F2FS_WB_DATA, 9715f9abab4SJaegeuk Kim F2FS_RD_DATA, 9725f9abab4SJaegeuk Kim F2FS_RD_NODE, 9735f9abab4SJaegeuk Kim F2FS_RD_META, 97402b16d0aSChao Yu F2FS_DIO_WRITE, 97502b16d0aSChao Yu F2FS_DIO_READ, 97639a53e0cSJaegeuk Kim NR_COUNT_TYPE, 97739a53e0cSJaegeuk Kim }; 97839a53e0cSJaegeuk Kim 97939a53e0cSJaegeuk Kim /* 980e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 98139a53e0cSJaegeuk Kim * The available types are: 98239a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 98339a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 98439a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 98539a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 98639a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 98739a53e0cSJaegeuk Kim * with waiting the bio's completion 98839a53e0cSJaegeuk Kim * ... Only can be used with META. 98939a53e0cSJaegeuk Kim */ 9907d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 99139a53e0cSJaegeuk Kim enum page_type { 99239a53e0cSJaegeuk Kim DATA, 99339a53e0cSJaegeuk Kim NODE, 99439a53e0cSJaegeuk Kim META, 99539a53e0cSJaegeuk Kim NR_PAGE_TYPE, 99639a53e0cSJaegeuk Kim META_FLUSH, 9978ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 9988ce67cb0SJaegeuk Kim INMEM_DROP, 9998c242db9SJaegeuk Kim INMEM_INVALIDATE, 100028bc106bSChao Yu INMEM_REVOKE, 10018ce67cb0SJaegeuk Kim IPU, 10028ce67cb0SJaegeuk Kim OPU, 100339a53e0cSJaegeuk Kim }; 100439a53e0cSJaegeuk Kim 1005a912b54dSJaegeuk Kim enum temp_type { 1006a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 1007a912b54dSJaegeuk Kim WARM, 1008a912b54dSJaegeuk Kim COLD, 1009a912b54dSJaegeuk Kim NR_TEMP_TYPE, 1010a912b54dSJaegeuk Kim }; 1011a912b54dSJaegeuk Kim 1012cc15620bSJaegeuk Kim enum need_lock_type { 1013cc15620bSJaegeuk Kim LOCK_REQ = 0, 1014cc15620bSJaegeuk Kim LOCK_DONE, 1015cc15620bSJaegeuk Kim LOCK_RETRY, 1016cc15620bSJaegeuk Kim }; 1017cc15620bSJaegeuk Kim 1018a5fd5050SChao Yu enum cp_reason_type { 1019a5fd5050SChao Yu CP_NO_NEEDED, 1020a5fd5050SChao Yu CP_NON_REGULAR, 1021a5fd5050SChao Yu CP_HARDLINK, 1022a5fd5050SChao Yu CP_SB_NEED_CP, 1023a5fd5050SChao Yu CP_WRONG_PINO, 1024a5fd5050SChao Yu CP_NO_SPC_ROLL, 1025a5fd5050SChao Yu CP_NODE_NEED_CP, 1026a5fd5050SChao Yu CP_FASTBOOT_MODE, 1027a5fd5050SChao Yu CP_SPEC_LOG_NUM, 10280a007b97SJaegeuk Kim CP_RECOVER_DIR, 1029a5fd5050SChao Yu }; 1030a5fd5050SChao Yu 1031b0af6d49SChao Yu enum iostat_type { 1032b0af6d49SChao Yu APP_DIRECT_IO, /* app direct IOs */ 1033b0af6d49SChao Yu APP_BUFFERED_IO, /* app buffered IOs */ 1034b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 1035b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 1036b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 1037b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 1038b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 1039b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 1040b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 1041b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 1042b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 1043b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 1044b0af6d49SChao Yu FS_DISCARD, /* discard */ 1045b0af6d49SChao Yu NR_IO_TYPE, 1046b0af6d49SChao Yu }; 1047b0af6d49SChao Yu 1048458e6197SJaegeuk Kim struct f2fs_io_info { 104905ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 105039d787beSChao Yu nid_t ino; /* inode number */ 1051458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 1052a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 105304d328deSMike Christie int op; /* contains REQ_OP_ */ 1054ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 10557a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 105628bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 105705ca3632SJaegeuk Kim struct page *page; /* page to be written */ 10584375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 1059fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 1060d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 1061cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 1062fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 10636dc3a126SChao Yu bool is_por; /* indicate IO is from recovery or not */ 1064fe16efe6SChao Yu bool retry; /* need to reallocate block address */ 1065b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 1066578c6478SYufen Yu struct writeback_control *io_wbc; /* writeback control */ 10678648de2cSChao Yu struct bio **bio; /* bio for ipu */ 10688648de2cSChao Yu sector_t *last_block; /* last block number in bio */ 10697735730dSChao Yu unsigned char version; /* version of the node */ 1070458e6197SJaegeuk Kim }; 1071458e6197SJaegeuk Kim 10720b20fcecSChao Yu struct bio_entry { 10730b20fcecSChao Yu struct bio *bio; 10740b20fcecSChao Yu struct list_head list; 10750b20fcecSChao Yu }; 10760b20fcecSChao Yu 107768afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 10781ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 1079458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 10801ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 10811ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 1082458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 1083df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 1084fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 1085fb830fc5SChao Yu struct list_head io_list; /* track fios */ 10860b20fcecSChao Yu struct list_head bio_list; /* bio entry list head */ 10870b20fcecSChao Yu struct rw_semaphore bio_list_lock; /* lock to protect bio entry list */ 10881ff7bd3bSJaegeuk Kim }; 10891ff7bd3bSJaegeuk Kim 10903c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 10913c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 10923c62be17SJaegeuk Kim struct f2fs_dev_info { 10933c62be17SJaegeuk Kim struct block_device *bdev; 10943c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 10953c62be17SJaegeuk Kim unsigned int total_segments; 10963c62be17SJaegeuk Kim block_t start_blk; 10973c62be17SJaegeuk Kim block_t end_blk; 10983c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 10993c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 110095175dafSDamien Le Moal unsigned long *blkz_seq; /* Bitmap indicating sequential zones */ 11013c62be17SJaegeuk Kim #endif 11023c62be17SJaegeuk Kim }; 11033c62be17SJaegeuk Kim 1104c227f912SChao Yu enum inode_type { 1105c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 1106c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 11070f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 110857864ae5SJaegeuk Kim ATOMIC_FILE, /* for all atomic files */ 1109c227f912SChao Yu NR_INODE_TYPE, 1110c227f912SChao Yu }; 1111c227f912SChao Yu 111267298804SChao Yu /* for inner inode cache management */ 111367298804SChao Yu struct inode_management { 111467298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 111567298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 111667298804SChao Yu struct list_head ino_list; /* inode list head */ 111767298804SChao Yu unsigned long ino_num; /* number of entries */ 111867298804SChao Yu }; 111967298804SChao Yu 1120caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 1121caf0047eSChao Yu enum { 1122caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 1123caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 1124caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 1125caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 1126df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 1127bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 112883a3bfdbSJaegeuk Kim SBI_IS_SHUTDOWN, /* shutdown by ioctl */ 11291378752bSChao Yu SBI_IS_RECOVERED, /* recovered orphan/data */ 11304354994fSDaniel Rosenberg SBI_CP_DISABLED, /* CP was disabled last mount */ 1131db610a64SJaegeuk Kim SBI_CP_DISABLED_QUICK, /* CP was disabled quickly */ 1132af033b2aSChao Yu SBI_QUOTA_NEED_FLUSH, /* need to flush quota info in CP */ 1133af033b2aSChao Yu SBI_QUOTA_SKIP_FLUSH, /* skip flushing quota in current CP */ 1134af033b2aSChao Yu SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */ 113504f0b2eaSQiuyang Sun SBI_IS_RESIZEFS, /* resizefs is in process */ 1136caf0047eSChao Yu }; 1137caf0047eSChao Yu 11386beceb54SJaegeuk Kim enum { 11396beceb54SJaegeuk Kim CP_TIME, 1140d0239e1bSJaegeuk Kim REQ_TIME, 1141a7d10cf3SSahitya Tummala DISCARD_TIME, 1142a7d10cf3SSahitya Tummala GC_TIME, 11434354994fSDaniel Rosenberg DISABLE_TIME, 114403f2c02dSJaegeuk Kim UMOUNT_DISCARD_TIMEOUT, 11456beceb54SJaegeuk Kim MAX_TIME, 11466beceb54SJaegeuk Kim }; 11476beceb54SJaegeuk Kim 11480cdd3195SHyunchul Lee enum { 11495b0e9539SJaegeuk Kim GC_NORMAL, 11505b0e9539SJaegeuk Kim GC_IDLE_CB, 11515b0e9539SJaegeuk Kim GC_IDLE_GREEDY, 11525b0e9539SJaegeuk Kim GC_URGENT, 11535b0e9539SJaegeuk Kim }; 11545b0e9539SJaegeuk Kim 11555b0e9539SJaegeuk Kim enum { 11560cdd3195SHyunchul Lee WHINT_MODE_OFF, /* not pass down write hints */ 11570cdd3195SHyunchul Lee WHINT_MODE_USER, /* try to pass down hints given by users */ 1158f2e703f9SHyunchul Lee WHINT_MODE_FS, /* pass down hints with F2FS policy */ 11590cdd3195SHyunchul Lee }; 11600cdd3195SHyunchul Lee 116107939627SJaegeuk Kim enum { 116207939627SJaegeuk Kim ALLOC_MODE_DEFAULT, /* stay default */ 116307939627SJaegeuk Kim ALLOC_MODE_REUSE, /* reuse segments as much as possible */ 116407939627SJaegeuk Kim }; 116507939627SJaegeuk Kim 116693cf93f1SJunling Zheng enum fsync_mode { 116793cf93f1SJunling Zheng FSYNC_MODE_POSIX, /* fsync follows posix semantics */ 116893cf93f1SJunling Zheng FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */ 1169d6290814SJaegeuk Kim FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */ 117093cf93f1SJunling Zheng }; 117193cf93f1SJunling Zheng 1172643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 1173ff62af20SSheng Yong #define DUMMY_ENCRYPTION_ENABLED(sbi) \ 1174ff62af20SSheng Yong (unlikely(F2FS_OPTION(sbi).test_dummy_encryption)) 1175ff62af20SSheng Yong #else 1176ff62af20SSheng Yong #define DUMMY_ENCRYPTION_ENABLED(sbi) (0) 1177ff62af20SSheng Yong #endif 1178ff62af20SSheng Yong 117939a53e0cSJaegeuk Kim struct f2fs_sb_info { 118039a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 11815e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 118239a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 1183846ae671SChao Yu struct rw_semaphore sb_lock; /* lock for raw super block */ 1184e8240f65SChao Yu int valid_super_block; /* valid super block no */ 1185fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 1186853137ceSJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 11875aba5430SDaniel Rosenberg #ifdef CONFIG_UNICODE 11885aba5430SDaniel Rosenberg struct unicode_map *s_encoding; 11895aba5430SDaniel Rosenberg __u16 s_encoding_flags; 11905aba5430SDaniel Rosenberg #endif 119139a53e0cSJaegeuk Kim 1192178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 1193178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1194178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 1195178053e2SDamien Le Moal #endif 1196178053e2SDamien Le Moal 119739a53e0cSJaegeuk Kim /* for node-related operations */ 119839a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 119939a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 120039a53e0cSJaegeuk Kim 120139a53e0cSJaegeuk Kim /* for segment-related operations */ 120239a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 12031ff7bd3bSJaegeuk Kim 12041ff7bd3bSJaegeuk Kim /* for bio operations */ 1205a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1206107a805dSChao Yu /* keep migration IO order for LFS mode */ 1207107a805dSChao Yu struct rw_semaphore io_order_lock; 12080a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 120939a53e0cSJaegeuk Kim 121039a53e0cSJaegeuk Kim /* for checkpoint */ 121139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 12128508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1213aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 121439a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 121539936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 1216b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1217b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 121859c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1219fb51b5efSChangman Lee wait_queue_head_t cp_wait; 12206beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 12216beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 122239a53e0cSJaegeuk Kim 122367298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 12246451e041SJaegeuk Kim 122550fa53ecSChao Yu spinlock_t fsync_node_lock; /* for node entry lock */ 122650fa53ecSChao Yu struct list_head fsync_node_list; /* node list head */ 122750fa53ecSChao Yu unsigned int fsync_seg_id; /* sequence id */ 122850fa53ecSChao Yu unsigned int fsync_node_num; /* number of node entries */ 122950fa53ecSChao Yu 12306451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 12310d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 123239a53e0cSJaegeuk Kim 1233c227f912SChao Yu /* for inode management */ 1234c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1235c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 1236040d2bb3SChao Yu struct mutex flush_lock; /* for flush exclusion */ 123739a53e0cSJaegeuk Kim 123813054c54SChao Yu /* for extent tree cache */ 123913054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 12405e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 124113054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 124213054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 12437441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1244137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 124574fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 124613054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 124713054c54SChao Yu 124839a53e0cSJaegeuk Kim /* basic filesystem units */ 124939a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 125039a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 125139a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 125239a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 125339a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 125439a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 125539a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 125639a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 125739a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 125839a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 125939a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 126004f0b2eaSQiuyang Sun struct mutex resize_mutex; /* for resize exclusion */ 126139a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 126239a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1263e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 1264ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 1265f6df8f23SSheng Yong int readdir_ra; /* readahead inode in readdir */ 126639a53e0cSJaegeuk Kim 126739a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 126839a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1269a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 127039a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1271daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 127280d42145SYunlong Song block_t current_reserved_blocks; /* current reserved blocks */ 1273daeb433eSChao Yu 12744354994fSDaniel Rosenberg /* Additional tracking for no checkpoint mode */ 12754354994fSDaniel Rosenberg block_t unusable_block_count; /* # of blocks saved by last cp */ 12764354994fSDaniel Rosenberg 1277292c196aSChao Yu unsigned int nquota_files; /* # of quota sysfile */ 1278db6ec53bSJaegeuk Kim struct rw_semaphore quota_sem; /* blocking cp for flags */ 1279292c196aSChao Yu 1280523be8a6SJaegeuk Kim /* # of pages, see count_type */ 128135782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 128241382ec4SJaegeuk Kim /* # of allocated blocks */ 128341382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 128439a53e0cSJaegeuk Kim 1285687de7f1SJaegeuk Kim /* writeback control */ 1286c29fd0c0SChao Yu atomic_t wb_sync_req[META]; /* count # of WB_SYNC threads */ 1287687de7f1SJaegeuk Kim 1288513c5f37SJaegeuk Kim /* valid inode count */ 1289513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1290513c5f37SJaegeuk Kim 129139a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 129239a53e0cSJaegeuk Kim 129339a53e0cSJaegeuk Kim /* for cleaning operations */ 129439a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 129539a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 12965ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 12975b0e9539SJaegeuk Kim unsigned int gc_mode; /* current GC state */ 1298e3080b01SChao Yu unsigned int next_victim_seg[2]; /* next segment in victim section */ 12992ef79ecbSChao Yu /* for skip statistic */ 1300677017d1SSahitya Tummala unsigned int atomic_files; /* # of opened atomic file */ 13012ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */ 13026f8d4455SJaegeuk Kim unsigned long long skipped_gc_rwsem; /* FG_GC only */ 130339a53e0cSJaegeuk Kim 13041ad71a27SJaegeuk Kim /* threshold for gc trials on pinned files */ 13051ad71a27SJaegeuk Kim u64 gc_pin_file_threshold; 1306f5a53edcSJaegeuk Kim struct rw_semaphore pin_sem; 13071ad71a27SJaegeuk Kim 1308b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1309b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1310e3080b01SChao Yu /* migration granularity of garbage collection, unit: segment */ 1311e3080b01SChao Yu unsigned int migration_granularity; 1312b1c57c1cSJaegeuk Kim 131339a53e0cSJaegeuk Kim /* 131439a53e0cSJaegeuk Kim * for stat information. 131539a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 131639a53e0cSJaegeuk Kim */ 131735b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 131839a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 1319b63e7be5SChao Yu atomic_t meta_count[META_MAX]; /* # of meta blocks */ 132039a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 132139a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1322b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 13235b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 13245b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 13255b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 13265b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1327d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 132803e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 132903e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 1330648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 133126a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1332648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 133339a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 1334274bd9baSChao Yu unsigned int io_skip_bggc; /* skip background gc for in-flight IO */ 1335274bd9baSChao Yu unsigned int other_skip_bggc; /* skip background gc for other reasons */ 133633fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 133735b09d82SNamjae Jeon #endif 133839a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1339b59d0baeSNamjae Jeon 1340b0af6d49SChao Yu /* For app/fs IO statistics */ 1341b0af6d49SChao Yu spinlock_t iostat_lock; 1342b0af6d49SChao Yu unsigned long long write_iostat[NR_IO_TYPE]; 1343b0af6d49SChao Yu bool iostat_enable; 1344b0af6d49SChao Yu 1345b59d0baeSNamjae Jeon /* For sysfs suppport */ 1346b59d0baeSNamjae Jeon struct kobject s_kobj; 1347b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 13482658e50dSJaegeuk Kim 13492658e50dSJaegeuk Kim /* For shrinker support */ 13502658e50dSJaegeuk Kim struct list_head s_list; 13513c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 13523c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 13531228b482SChao Yu unsigned int dirty_device; /* for checkpoint data flush */ 13541228b482SChao Yu spinlock_t dev_lock; /* protect dirty_device */ 13552658e50dSJaegeuk Kim struct mutex umount_mutex; 13562658e50dSJaegeuk Kim unsigned int shrinker_run_no; 13578f1dbbbbSShuoran Liu 13588f1dbbbbSShuoran Liu /* For write statistics */ 13598f1dbbbbSShuoran Liu u64 sectors_written_start; 13608f1dbbbbSShuoran Liu u64 kbytes_written; 136143b6573bSKeith Mok 136243b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 136343b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 13641ecc0c5cSChao Yu 1365704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1366704956ecSChao Yu __u32 s_chksum_seed; 136739a53e0cSJaegeuk Kim }; 136839a53e0cSJaegeuk Kim 136902b16d0aSChao Yu struct f2fs_private_dio { 137002b16d0aSChao Yu struct inode *inode; 137102b16d0aSChao Yu void *orig_private; 137202b16d0aSChao Yu bio_end_io_t *orig_end_io; 137302b16d0aSChao Yu bool write; 137402b16d0aSChao Yu }; 137502b16d0aSChao Yu 13761ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 1377c45d6002SChao Yu #define f2fs_show_injection_info(sbi, type) \ 1378c45d6002SChao Yu printk_ratelimited("%sF2FS-fs (%s) : inject %s in %s of %pS\n", \ 1379c45d6002SChao Yu KERN_INFO, sbi->sb->s_id, \ 1380c45d6002SChao Yu f2fs_fault_name[type], \ 138155523519SChao Yu __func__, __builtin_return_address(0)) 13821ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 13831ecc0c5cSChao Yu { 138463189b78SChao Yu struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; 13851ecc0c5cSChao Yu 13861ecc0c5cSChao Yu if (!ffi->inject_rate) 13871ecc0c5cSChao Yu return false; 13881ecc0c5cSChao Yu 13891ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 13901ecc0c5cSChao Yu return false; 13911ecc0c5cSChao Yu 13921ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 13931ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 13941ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 13951ecc0c5cSChao Yu return true; 13961ecc0c5cSChao Yu } 13971ecc0c5cSChao Yu return false; 13981ecc0c5cSChao Yu } 13997fa750a1SArnd Bergmann #else 1400c45d6002SChao Yu #define f2fs_show_injection_info(sbi, type) do { } while (0) 14017fa750a1SArnd Bergmann static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 14027fa750a1SArnd Bergmann { 14037fa750a1SArnd Bergmann return false; 14047fa750a1SArnd Bergmann } 14051ecc0c5cSChao Yu #endif 14061ecc0c5cSChao Yu 14070916878dSDamien Le Moal /* 14080916878dSDamien Le Moal * Test if the mounted volume is a multi-device volume. 14090916878dSDamien Le Moal * - For a single regular disk volume, sbi->s_ndevs is 0. 14100916878dSDamien Le Moal * - For a single zoned disk volume, sbi->s_ndevs is 1. 14110916878dSDamien Le Moal * - For a multi-device volume, sbi->s_ndevs is always 2 or more. 14120916878dSDamien Le Moal */ 14130916878dSDamien Le Moal static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi) 14140916878dSDamien Le Moal { 14150916878dSDamien Le Moal return sbi->s_ndevs > 1; 14160916878dSDamien Le Moal } 14170916878dSDamien Le Moal 14188f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 14198f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 14208f1dbbbbSShuoran Liu */ 14218f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 1422dbae2c55SMichael Callahan (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[STAT_WRITE]) - \ 142368afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 14248f1dbbbbSShuoran Liu 14256beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 14266beceb54SJaegeuk Kim { 1427a7d10cf3SSahitya Tummala unsigned long now = jiffies; 1428a7d10cf3SSahitya Tummala 1429a7d10cf3SSahitya Tummala sbi->last_time[type] = now; 1430a7d10cf3SSahitya Tummala 1431a7d10cf3SSahitya Tummala /* DISCARD_TIME and GC_TIME are based on REQ_TIME */ 1432a7d10cf3SSahitya Tummala if (type == REQ_TIME) { 1433a7d10cf3SSahitya Tummala sbi->last_time[DISCARD_TIME] = now; 1434a7d10cf3SSahitya Tummala sbi->last_time[GC_TIME] = now; 1435a7d10cf3SSahitya Tummala } 14366beceb54SJaegeuk Kim } 14376beceb54SJaegeuk Kim 14386beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 14396beceb54SJaegeuk Kim { 14406bccfa19SArnd Bergmann unsigned long interval = sbi->interval_time[type] * HZ; 14416beceb54SJaegeuk Kim 14426beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 14436beceb54SJaegeuk Kim } 14446beceb54SJaegeuk Kim 1445a7d10cf3SSahitya Tummala static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi, 1446a7d10cf3SSahitya Tummala int type) 1447a7d10cf3SSahitya Tummala { 1448a7d10cf3SSahitya Tummala unsigned long interval = sbi->interval_time[type] * HZ; 1449a7d10cf3SSahitya Tummala unsigned int wait_ms = 0; 1450a7d10cf3SSahitya Tummala long delta; 1451a7d10cf3SSahitya Tummala 1452a7d10cf3SSahitya Tummala delta = (sbi->last_time[type] + interval) - jiffies; 1453a7d10cf3SSahitya Tummala if (delta > 0) 1454a7d10cf3SSahitya Tummala wait_ms = jiffies_to_msecs(delta); 1455a7d10cf3SSahitya Tummala 1456a7d10cf3SSahitya Tummala return wait_ms; 1457a7d10cf3SSahitya Tummala } 1458a7d10cf3SSahitya Tummala 145939a53e0cSJaegeuk Kim /* 146039a53e0cSJaegeuk Kim * Inline functions 146139a53e0cSJaegeuk Kim */ 1462416d2dbbSChao Yu static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc, 1463704956ecSChao Yu const void *address, unsigned int length) 1464704956ecSChao Yu { 1465704956ecSChao Yu struct { 1466704956ecSChao Yu struct shash_desc shash; 1467704956ecSChao Yu char ctx[4]; 1468704956ecSChao Yu } desc; 1469704956ecSChao Yu int err; 1470704956ecSChao Yu 1471704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1472704956ecSChao Yu 1473704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1474704956ecSChao Yu *(u32 *)desc.ctx = crc; 1475704956ecSChao Yu 1476704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1477704956ecSChao Yu BUG_ON(err); 1478704956ecSChao Yu 1479704956ecSChao Yu return *(u32 *)desc.ctx; 1480704956ecSChao Yu } 1481704956ecSChao Yu 1482416d2dbbSChao Yu static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 1483416d2dbbSChao Yu unsigned int length) 1484416d2dbbSChao Yu { 1485416d2dbbSChao Yu return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length); 1486416d2dbbSChao Yu } 1487416d2dbbSChao Yu 1488416d2dbbSChao Yu static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 1489416d2dbbSChao Yu void *buf, size_t buf_size) 1490416d2dbbSChao Yu { 1491416d2dbbSChao Yu return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 1492416d2dbbSChao Yu } 1493416d2dbbSChao Yu 1494416d2dbbSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1495416d2dbbSChao Yu const void *address, unsigned int length) 1496416d2dbbSChao Yu { 1497416d2dbbSChao Yu return __f2fs_crc32(sbi, crc, address, length); 1498416d2dbbSChao Yu } 1499416d2dbbSChao Yu 150039a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 150139a53e0cSJaegeuk Kim { 150239a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 150339a53e0cSJaegeuk Kim } 150439a53e0cSJaegeuk Kim 150539a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 150639a53e0cSJaegeuk Kim { 150739a53e0cSJaegeuk Kim return sb->s_fs_info; 150839a53e0cSJaegeuk Kim } 150939a53e0cSJaegeuk Kim 15104081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 15114081363fSJaegeuk Kim { 15124081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 15134081363fSJaegeuk Kim } 15144081363fSJaegeuk Kim 15154081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 15164081363fSJaegeuk Kim { 15174081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 15184081363fSJaegeuk Kim } 15194081363fSJaegeuk Kim 15204081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 15214081363fSJaegeuk Kim { 15224969c06aSJaegeuk Kim return F2FS_M_SB(page_file_mapping(page)); 15234081363fSJaegeuk Kim } 15244081363fSJaegeuk Kim 152539a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 152639a53e0cSJaegeuk Kim { 152739a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 152839a53e0cSJaegeuk Kim } 152939a53e0cSJaegeuk Kim 153039a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 153139a53e0cSJaegeuk Kim { 153239a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 153339a53e0cSJaegeuk Kim } 153439a53e0cSJaegeuk Kim 153545590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 153645590710SGu Zheng { 153745590710SGu Zheng return (struct f2fs_node *)page_address(page); 153845590710SGu Zheng } 153945590710SGu Zheng 154058bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 154158bfaf44SJaegeuk Kim { 154258bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 154358bfaf44SJaegeuk Kim } 154458bfaf44SJaegeuk Kim 154539a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 154639a53e0cSJaegeuk Kim { 154739a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 154839a53e0cSJaegeuk Kim } 154939a53e0cSJaegeuk Kim 155039a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 155139a53e0cSJaegeuk Kim { 155239a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 155339a53e0cSJaegeuk Kim } 155439a53e0cSJaegeuk Kim 155539a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 155639a53e0cSJaegeuk Kim { 155739a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 155839a53e0cSJaegeuk Kim } 155939a53e0cSJaegeuk Kim 156039a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 156139a53e0cSJaegeuk Kim { 156239a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 156339a53e0cSJaegeuk Kim } 156439a53e0cSJaegeuk Kim 156539a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 156639a53e0cSJaegeuk Kim { 156739a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 156839a53e0cSJaegeuk Kim } 156939a53e0cSJaegeuk Kim 15709df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 15719df27d98SGu Zheng { 15729df27d98SGu Zheng return sbi->meta_inode->i_mapping; 15739df27d98SGu Zheng } 15749df27d98SGu Zheng 15754ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 15764ef51a8fSJaegeuk Kim { 15774ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 15784ef51a8fSJaegeuk Kim } 15794ef51a8fSJaegeuk Kim 1580caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 158139a53e0cSJaegeuk Kim { 1582fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 158339a53e0cSJaegeuk Kim } 158439a53e0cSJaegeuk Kim 1585caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 158639a53e0cSJaegeuk Kim { 1587fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1588caf0047eSChao Yu } 1589caf0047eSChao Yu 1590caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1591caf0047eSChao Yu { 1592fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 159339a53e0cSJaegeuk Kim } 159439a53e0cSJaegeuk Kim 1595d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1596d71b5564SJaegeuk Kim { 1597d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1598d71b5564SJaegeuk Kim } 1599d71b5564SJaegeuk Kim 1600ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) 1601ea676733SJaegeuk Kim { 1602ea676733SJaegeuk Kim if (type < F2FS_MAX_QUOTAS) 1603ea676733SJaegeuk Kim return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); 1604ea676733SJaegeuk Kim return 0; 1605ea676733SJaegeuk Kim } 1606ea676733SJaegeuk Kim 1607ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1608ced2c7eaSKinglong Mee { 1609ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1610ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1611ced2c7eaSKinglong Mee } 1612ced2c7eaSKinglong Mee 1613aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 161425ca923bSJaegeuk Kim { 161525ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1616aaec2b1dSChao Yu 161725ca923bSJaegeuk Kim return ckpt_flags & f; 161825ca923bSJaegeuk Kim } 161925ca923bSJaegeuk Kim 1620aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 162125ca923bSJaegeuk Kim { 1622aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1623aaec2b1dSChao Yu } 1624aaec2b1dSChao Yu 1625aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1626aaec2b1dSChao Yu { 1627aaec2b1dSChao Yu unsigned int ckpt_flags; 1628aaec2b1dSChao Yu 1629aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 163025ca923bSJaegeuk Kim ckpt_flags |= f; 163125ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 163225ca923bSJaegeuk Kim } 163325ca923bSJaegeuk Kim 1634aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 163525ca923bSJaegeuk Kim { 1636d1aa2453SChao Yu unsigned long flags; 1637d1aa2453SChao Yu 1638d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1639aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1640d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1641aaec2b1dSChao Yu } 1642aaec2b1dSChao Yu 1643aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1644aaec2b1dSChao Yu { 1645aaec2b1dSChao Yu unsigned int ckpt_flags; 1646aaec2b1dSChao Yu 1647aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 164825ca923bSJaegeuk Kim ckpt_flags &= (~f); 164925ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 165025ca923bSJaegeuk Kim } 165125ca923bSJaegeuk Kim 1652aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1653aaec2b1dSChao Yu { 1654d1aa2453SChao Yu unsigned long flags; 1655d1aa2453SChao Yu 1656d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1657aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1658d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1659aaec2b1dSChao Yu } 1660aaec2b1dSChao Yu 166122ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 166222ad0b6aSJaegeuk Kim { 1663d1aa2453SChao Yu unsigned long flags; 16640921835cSChao Yu unsigned char *nat_bits; 1665d1aa2453SChao Yu 1666a742fd41SJaegeuk Kim /* 1667a742fd41SJaegeuk Kim * In order to re-enable nat_bits we need to call fsck.f2fs by 1668a742fd41SJaegeuk Kim * set_sbi_flag(sbi, SBI_NEED_FSCK). But it may give huge cost, 1669a742fd41SJaegeuk Kim * so let's rely on regular fsck or unclean shutdown. 1670a742fd41SJaegeuk Kim */ 167122ad0b6aSJaegeuk Kim 167222ad0b6aSJaegeuk Kim if (lock) 1673d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 167422ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 16750921835cSChao Yu nat_bits = NM_I(sbi)->nat_bits; 167622ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 167722ad0b6aSJaegeuk Kim if (lock) 1678d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 16790921835cSChao Yu 16800921835cSChao Yu kvfree(nat_bits); 168122ad0b6aSJaegeuk Kim } 168222ad0b6aSJaegeuk Kim 168322ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 168422ad0b6aSJaegeuk Kim struct cp_control *cpc) 168522ad0b6aSJaegeuk Kim { 168622ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 168722ad0b6aSJaegeuk Kim 1688c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 168922ad0b6aSJaegeuk Kim } 169022ad0b6aSJaegeuk Kim 1691e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 169239a53e0cSJaegeuk Kim { 1693b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 169439a53e0cSJaegeuk Kim } 169539a53e0cSJaegeuk Kim 1696cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1697cc15620bSJaegeuk Kim { 1698cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1699cc15620bSJaegeuk Kim } 1700cc15620bSJaegeuk Kim 1701e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 170239a53e0cSJaegeuk Kim { 1703b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 170439936837SJaegeuk Kim } 170539936837SJaegeuk Kim 1706e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 170739936837SJaegeuk Kim { 1708b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 170939936837SJaegeuk Kim } 171039936837SJaegeuk Kim 1711e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 171239936837SJaegeuk Kim { 1713b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 171439a53e0cSJaegeuk Kim } 171539a53e0cSJaegeuk Kim 1716119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1717119ee914SJaegeuk Kim { 1718119ee914SJaegeuk Kim int reason = CP_SYNC; 1719119ee914SJaegeuk Kim 1720119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1721119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1722119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1723119ee914SJaegeuk Kim reason = CP_UMOUNT; 1724119ee914SJaegeuk Kim return reason; 1725119ee914SJaegeuk Kim } 1726119ee914SJaegeuk Kim 1727119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1728119ee914SJaegeuk Kim { 1729c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1730119ee914SJaegeuk Kim } 1731119ee914SJaegeuk Kim 1732119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1733119ee914SJaegeuk Kim { 1734aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1735aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1736119ee914SJaegeuk Kim } 1737119ee914SJaegeuk Kim 173839a53e0cSJaegeuk Kim /* 173939a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 174039a53e0cSJaegeuk Kim */ 174139a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 174239a53e0cSJaegeuk Kim { 17430eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 17440eb0adadSChao Yu 1745000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 174639a53e0cSJaegeuk Kim } 174739a53e0cSJaegeuk Kim 17484bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 17494bc8e9bcSChao Yu { 17504bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 17514bc8e9bcSChao Yu } 17524bc8e9bcSChao Yu 1753d8a9a229SJaegeuk Kim static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, 1754a90a0884SJaegeuk Kim struct inode *inode, bool cap) 17557c2e5963SJaegeuk Kim { 1756d8a9a229SJaegeuk Kim if (!inode) 1757d8a9a229SJaegeuk Kim return true; 17587c2e5963SJaegeuk Kim if (!test_opt(sbi, RESERVE_ROOT)) 17597c2e5963SJaegeuk Kim return false; 1760d8a9a229SJaegeuk Kim if (IS_NOQUOTA(inode)) 1761d8a9a229SJaegeuk Kim return true; 176263189b78SChao Yu if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid())) 17637c2e5963SJaegeuk Kim return true; 176463189b78SChao Yu if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) && 176563189b78SChao Yu in_group_p(F2FS_OPTION(sbi).s_resgid)) 17667c2e5963SJaegeuk Kim return true; 1767a90a0884SJaegeuk Kim if (cap && capable(CAP_SYS_RESOURCE)) 1768162b27aeSJaegeuk Kim return true; 17697c2e5963SJaegeuk Kim return false; 17707c2e5963SJaegeuk Kim } 17717c2e5963SJaegeuk Kim 17720abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 17730abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 177446008c6dSChao Yu struct inode *inode, blkcnt_t *count) 177539a53e0cSJaegeuk Kim { 17760abd675eSChao Yu blkcnt_t diff = 0, release = 0; 1777daeb433eSChao Yu block_t avail_user_block_count; 17780abd675eSChao Yu int ret; 17790abd675eSChao Yu 17800abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 17810abd675eSChao Yu if (ret) 17820abd675eSChao Yu return ret; 1783dd11a5dfSJaegeuk Kim 178455523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 1785c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_BLOCK); 17860abd675eSChao Yu release = *count; 17879ea2f0beSChao Yu goto release_quota; 178855523519SChao Yu } 17897fa750a1SArnd Bergmann 1790dd11a5dfSJaegeuk Kim /* 1791dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1792dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1793dd11a5dfSJaegeuk Kim */ 1794dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 179539a53e0cSJaegeuk Kim 179639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 17972555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 179880d42145SYunlong Song avail_user_block_count = sbi->user_block_count - 179980d42145SYunlong Song sbi->current_reserved_blocks; 18007e65be49SJaegeuk Kim 1801a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, true)) 180263189b78SChao Yu avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; 1803a4c3ecaaSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { 1804a4c3ecaaSDaniel Rosenberg if (avail_user_block_count > sbi->unusable_block_count) 18054354994fSDaniel Rosenberg avail_user_block_count -= sbi->unusable_block_count; 1806a4c3ecaaSDaniel Rosenberg else 1807a4c3ecaaSDaniel Rosenberg avail_user_block_count = 0; 1808a4c3ecaaSDaniel Rosenberg } 1809daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1810daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 18117e65be49SJaegeuk Kim if (diff > *count) 18127e65be49SJaegeuk Kim diff = *count; 1813dd11a5dfSJaegeuk Kim *count -= diff; 18140abd675eSChao Yu release = diff; 18157e65be49SJaegeuk Kim sbi->total_valid_block_count -= diff; 181646008c6dSChao Yu if (!*count) { 181739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 18180abd675eSChao Yu goto enospc; 181939a53e0cSJaegeuk Kim } 182046008c6dSChao Yu } 182139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 182241382ec4SJaegeuk Kim 182336b877afSDaniel Rosenberg if (unlikely(release)) { 182436b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 18250abd675eSChao Yu dquot_release_reservation_block(inode, release); 182636b877afSDaniel Rosenberg } 18270abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 18280abd675eSChao Yu return 0; 18290abd675eSChao Yu 18300abd675eSChao Yu enospc: 183136b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 18329ea2f0beSChao Yu release_quota: 18330abd675eSChao Yu dquot_release_reservation_block(inode, release); 18340abd675eSChao Yu return -ENOSPC; 183539a53e0cSJaegeuk Kim } 183639a53e0cSJaegeuk Kim 1837dcbb4c10SJoe Perches __printf(2, 3) 1838dcbb4c10SJoe Perches void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...); 1839dcbb4c10SJoe Perches 1840dcbb4c10SJoe Perches #define f2fs_err(sbi, fmt, ...) \ 1841dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_ERR fmt, ##__VA_ARGS__) 1842dcbb4c10SJoe Perches #define f2fs_warn(sbi, fmt, ...) \ 1843dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_WARNING fmt, ##__VA_ARGS__) 1844dcbb4c10SJoe Perches #define f2fs_notice(sbi, fmt, ...) \ 1845dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_NOTICE fmt, ##__VA_ARGS__) 1846dcbb4c10SJoe Perches #define f2fs_info(sbi, fmt, ...) \ 1847dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_INFO fmt, ##__VA_ARGS__) 1848dcbb4c10SJoe Perches #define f2fs_debug(sbi, fmt, ...) \ 1849dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_DEBUG fmt, ##__VA_ARGS__) 1850dcbb4c10SJoe Perches 1851da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 185239a53e0cSJaegeuk Kim struct inode *inode, 18530eb0adadSChao Yu block_t count) 185439a53e0cSJaegeuk Kim { 18550eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 18560eb0adadSChao Yu 185739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 18589850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 185939a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 186080d42145SYunlong Song if (sbi->reserved_blocks && 186180d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 186280d42145SYunlong Song sbi->current_reserved_blocks = min(sbi->reserved_blocks, 186380d42145SYunlong Song sbi->current_reserved_blocks + count); 186439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 18655e159cd3SChao Yu if (unlikely(inode->i_blocks < sectors)) { 1866dcbb4c10SJoe Perches f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu", 18675e159cd3SChao Yu inode->i_ino, 18685e159cd3SChao Yu (unsigned long long)inode->i_blocks, 18695e159cd3SChao Yu (unsigned long long)sectors); 18705e159cd3SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 18715e159cd3SChao Yu return; 18725e159cd3SChao Yu } 18730abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 187439a53e0cSJaegeuk Kim } 187539a53e0cSJaegeuk Kim 187639a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 187739a53e0cSJaegeuk Kim { 187835782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 18797c4abcbeSChao Yu 188020109873SChao Yu if (count_type == F2FS_DIRTY_DENTS || 188120109873SChao Yu count_type == F2FS_DIRTY_NODES || 188220109873SChao Yu count_type == F2FS_DIRTY_META || 188320109873SChao Yu count_type == F2FS_DIRTY_QDATA || 188420109873SChao Yu count_type == F2FS_DIRTY_IMETA) 1885caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 188639a53e0cSJaegeuk Kim } 188739a53e0cSJaegeuk Kim 1888a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 188939a53e0cSJaegeuk Kim { 1890204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1891c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1892c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 18932c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 18942c8a4a28SJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 189539a53e0cSJaegeuk Kim } 189639a53e0cSJaegeuk Kim 189739a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 189839a53e0cSJaegeuk Kim { 189935782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 190039a53e0cSJaegeuk Kim } 190139a53e0cSJaegeuk Kim 1902a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 190339a53e0cSJaegeuk Kim { 19045ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 19055ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 19061fe54f9dSJaegeuk Kim return; 19071fe54f9dSJaegeuk Kim 1908204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1909c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1910c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 19112c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 19122c8a4a28SJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 191339a53e0cSJaegeuk Kim } 191439a53e0cSJaegeuk Kim 1915523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 191639a53e0cSJaegeuk Kim { 191735782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 191839a53e0cSJaegeuk Kim } 191939a53e0cSJaegeuk Kim 1920204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1921f8b2c1f9SJaegeuk Kim { 1922204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1923f8b2c1f9SJaegeuk Kim } 1924f8b2c1f9SJaegeuk Kim 19255ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 19265ac206cfSNamjae Jeon { 19273519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1928523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1929523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1930523be8a6SJaegeuk Kim 1931523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 19325ac206cfSNamjae Jeon } 19335ac206cfSNamjae Jeon 193439a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 193539a53e0cSJaegeuk Kim { 19368b8343faSJaegeuk Kim return sbi->total_valid_block_count; 193739a53e0cSJaegeuk Kim } 193839a53e0cSJaegeuk Kim 1939f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1940f83a2584SYunlei He { 1941f83a2584SYunlei He return sbi->discard_blks; 1942f83a2584SYunlei He } 1943f83a2584SYunlei He 194439a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 194539a53e0cSJaegeuk Kim { 194639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 194739a53e0cSJaegeuk Kim 194839a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 194939a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 195039a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 195139a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 195239a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 195339a53e0cSJaegeuk Kim 195439a53e0cSJaegeuk Kim return 0; 195539a53e0cSJaegeuk Kim } 195639a53e0cSJaegeuk Kim 195755141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 195855141486SWanpeng Li { 195955141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 196055141486SWanpeng Li } 196155141486SWanpeng Li 196239a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 196339a53e0cSJaegeuk Kim { 196439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 19651dbe4152SChangman Lee int offset; 19661dbe4152SChangman Lee 1967199bc3feSChao Yu if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { 1968199bc3feSChao Yu offset = (flag == SIT_BITMAP) ? 1969199bc3feSChao Yu le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; 1970b471eb99SChao Yu /* 1971b471eb99SChao Yu * if large_nat_bitmap feature is enabled, leave checksum 1972b471eb99SChao Yu * protection for all nat/sit bitmaps. 1973b471eb99SChao Yu */ 1974b471eb99SChao Yu return &ckpt->sit_nat_version_bitmap + offset + sizeof(__le32); 1975199bc3feSChao Yu } 1976199bc3feSChao Yu 197755141486SWanpeng Li if (__cp_payload(sbi) > 0) { 19781dbe4152SChangman Lee if (flag == NAT_BITMAP) 19791dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 19801dbe4152SChangman Lee else 198165b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 19821dbe4152SChangman Lee } else { 19831dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 198425ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 198539a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 198639a53e0cSJaegeuk Kim } 19871dbe4152SChangman Lee } 198839a53e0cSJaegeuk Kim 198939a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 199039a53e0cSJaegeuk Kim { 19918508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 199239a53e0cSJaegeuk Kim 19938508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 199439a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 199539a53e0cSJaegeuk Kim return start_addr; 199639a53e0cSJaegeuk Kim } 199739a53e0cSJaegeuk Kim 19988508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 19998508e44aSJaegeuk Kim { 20008508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 20018508e44aSJaegeuk Kim 20028508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 20038508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 20048508e44aSJaegeuk Kim return start_addr; 20058508e44aSJaegeuk Kim } 20068508e44aSJaegeuk Kim 20078508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 20088508e44aSJaegeuk Kim { 20098508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 20108508e44aSJaegeuk Kim } 20118508e44aSJaegeuk Kim 201239a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 201339a53e0cSJaegeuk Kim { 201439a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 201539a53e0cSJaegeuk Kim } 201639a53e0cSJaegeuk Kim 20170abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 2018000519f2SChao Yu struct inode *inode, bool is_inode) 201939a53e0cSJaegeuk Kim { 202039a53e0cSJaegeuk Kim block_t valid_block_count; 2021a4c3ecaaSDaniel Rosenberg unsigned int valid_node_count, user_block_count; 2022af033b2aSChao Yu int err; 20230abd675eSChao Yu 2024af033b2aSChao Yu if (is_inode) { 2025af033b2aSChao Yu if (inode) { 2026af033b2aSChao Yu err = dquot_alloc_inode(inode); 2027af033b2aSChao Yu if (err) 2028af033b2aSChao Yu return err; 2029af033b2aSChao Yu } 2030af033b2aSChao Yu } else { 2031af033b2aSChao Yu err = dquot_reserve_block(inode, 1); 2032af033b2aSChao Yu if (err) 2033af033b2aSChao Yu return err; 20340abd675eSChao Yu } 203539a53e0cSJaegeuk Kim 2036812c6056SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 2037c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_BLOCK); 2038812c6056SChao Yu goto enospc; 2039812c6056SChao Yu } 2040812c6056SChao Yu 204139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 204239a53e0cSJaegeuk Kim 20437e65be49SJaegeuk Kim valid_block_count = sbi->total_valid_block_count + 20447e65be49SJaegeuk Kim sbi->current_reserved_blocks + 1; 20457e65be49SJaegeuk Kim 2046a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, false)) 204763189b78SChao Yu valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; 2048a4c3ecaaSDaniel Rosenberg user_block_count = sbi->user_block_count; 20494354994fSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) 2050a4c3ecaaSDaniel Rosenberg user_block_count -= sbi->unusable_block_count; 20517e65be49SJaegeuk Kim 2052a4c3ecaaSDaniel Rosenberg if (unlikely(valid_block_count > user_block_count)) { 205339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 20540abd675eSChao Yu goto enospc; 205539a53e0cSJaegeuk Kim } 205639a53e0cSJaegeuk Kim 2057ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 2058cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 205939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 20600abd675eSChao Yu goto enospc; 206139a53e0cSJaegeuk Kim } 206239a53e0cSJaegeuk Kim 2063ef86d709SGu Zheng sbi->total_valid_node_count++; 2064ef86d709SGu Zheng sbi->total_valid_block_count++; 206539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 206639a53e0cSJaegeuk Kim 20670abd675eSChao Yu if (inode) { 20680abd675eSChao Yu if (is_inode) 20690abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 20700abd675eSChao Yu else 20710abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 20720abd675eSChao Yu } 20730abd675eSChao Yu 207441382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 20750abd675eSChao Yu return 0; 20760abd675eSChao Yu 20770abd675eSChao Yu enospc: 2078af033b2aSChao Yu if (is_inode) { 2079af033b2aSChao Yu if (inode) 2080af033b2aSChao Yu dquot_free_inode(inode); 2081af033b2aSChao Yu } else { 20820abd675eSChao Yu dquot_release_reservation_block(inode, 1); 2083af033b2aSChao Yu } 20840abd675eSChao Yu return -ENOSPC; 208539a53e0cSJaegeuk Kim } 208639a53e0cSJaegeuk Kim 208739a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 2088000519f2SChao Yu struct inode *inode, bool is_inode) 208939a53e0cSJaegeuk Kim { 209039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 209139a53e0cSJaegeuk Kim 20929850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 20939850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 209439a53e0cSJaegeuk Kim 2095ef86d709SGu Zheng sbi->total_valid_node_count--; 2096ef86d709SGu Zheng sbi->total_valid_block_count--; 209780d42145SYunlong Song if (sbi->reserved_blocks && 209880d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 209980d42145SYunlong Song sbi->current_reserved_blocks++; 210039a53e0cSJaegeuk Kim 210139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 21020abd675eSChao Yu 2103ea6d7e72SChao Yu if (is_inode) { 2104af033b2aSChao Yu dquot_free_inode(inode); 2105ea6d7e72SChao Yu } else { 2106ea6d7e72SChao Yu if (unlikely(inode->i_blocks == 0)) { 2107dcbb4c10SJoe Perches f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu", 2108ea6d7e72SChao Yu inode->i_ino, 2109ea6d7e72SChao Yu (unsigned long long)inode->i_blocks); 2110ea6d7e72SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 2111ea6d7e72SChao Yu return; 2112ea6d7e72SChao Yu } 21130abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 211439a53e0cSJaegeuk Kim } 2115ea6d7e72SChao Yu } 211639a53e0cSJaegeuk Kim 211739a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 211839a53e0cSJaegeuk Kim { 21198b8343faSJaegeuk Kim return sbi->total_valid_node_count; 212039a53e0cSJaegeuk Kim } 212139a53e0cSJaegeuk Kim 212239a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 212339a53e0cSJaegeuk Kim { 2124513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 212539a53e0cSJaegeuk Kim } 212639a53e0cSJaegeuk Kim 21270e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 212839a53e0cSJaegeuk Kim { 2129513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 213039a53e0cSJaegeuk Kim } 213139a53e0cSJaegeuk Kim 2132513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 213339a53e0cSJaegeuk Kim { 2134513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 213539a53e0cSJaegeuk Kim } 213639a53e0cSJaegeuk Kim 2137a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 2138a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 2139a56c7c6fSJaegeuk Kim { 214082cf4f13SChao Yu struct page *page; 2141cac5a3d8SDongOh Shin 21427fa750a1SArnd Bergmann if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) { 214382cf4f13SChao Yu if (!for_write) 214482cf4f13SChao Yu page = find_get_page_flags(mapping, index, 214582cf4f13SChao Yu FGP_LOCK | FGP_ACCESSED); 214682cf4f13SChao Yu else 214782cf4f13SChao Yu page = find_lock_page(mapping, index); 2148c41f3cc3SJaegeuk Kim if (page) 2149c41f3cc3SJaegeuk Kim return page; 2150c41f3cc3SJaegeuk Kim 215155523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 2152c45d6002SChao Yu f2fs_show_injection_info(F2FS_M_SB(mapping), 2153c45d6002SChao Yu FAULT_PAGE_ALLOC); 2154c41f3cc3SJaegeuk Kim return NULL; 215555523519SChao Yu } 21567fa750a1SArnd Bergmann } 21577fa750a1SArnd Bergmann 2158a56c7c6fSJaegeuk Kim if (!for_write) 2159a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 2160a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 2161a56c7c6fSJaegeuk Kim } 2162a56c7c6fSJaegeuk Kim 216301eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page( 216401eccef7SChao Yu struct address_space *mapping, pgoff_t index, 216501eccef7SChao Yu int fgp_flags, gfp_t gfp_mask) 216601eccef7SChao Yu { 216701eccef7SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { 2168c45d6002SChao Yu f2fs_show_injection_info(F2FS_M_SB(mapping), FAULT_PAGE_GET); 216901eccef7SChao Yu return NULL; 217001eccef7SChao Yu } 21717fa750a1SArnd Bergmann 217201eccef7SChao Yu return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); 217301eccef7SChao Yu } 217401eccef7SChao Yu 21756e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 21766e2c64adSJaegeuk Kim { 21776e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 21786e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 21796e2c64adSJaegeuk Kim 21806e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 21816e2c64adSJaegeuk Kim kunmap(dst); 21826e2c64adSJaegeuk Kim kunmap(src); 21836e2c64adSJaegeuk Kim } 21846e2c64adSJaegeuk Kim 218539a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 218639a53e0cSJaegeuk Kim { 2187031fa8ccSJaegeuk Kim if (!page) 218839a53e0cSJaegeuk Kim return; 218939a53e0cSJaegeuk Kim 219039a53e0cSJaegeuk Kim if (unlock) { 21919850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 219239a53e0cSJaegeuk Kim unlock_page(page); 219339a53e0cSJaegeuk Kim } 219409cbfeafSKirill A. Shutemov put_page(page); 219539a53e0cSJaegeuk Kim } 219639a53e0cSJaegeuk Kim 219739a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 219839a53e0cSJaegeuk Kim { 219939a53e0cSJaegeuk Kim if (dn->node_page) 220039a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 220139a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 220239a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 220339a53e0cSJaegeuk Kim dn->node_page = NULL; 220439a53e0cSJaegeuk Kim dn->inode_page = NULL; 220539a53e0cSJaegeuk Kim } 220639a53e0cSJaegeuk Kim 220739a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 2208e8512d2eSGu Zheng size_t size) 220939a53e0cSJaegeuk Kim { 2210e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 221139a53e0cSJaegeuk Kim } 221239a53e0cSJaegeuk Kim 22137bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 22147bd59381SGu Zheng gfp_t flags) 22157bd59381SGu Zheng { 22167bd59381SGu Zheng void *entry; 22177bd59381SGu Zheng 221880c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 221980c54505SJaegeuk Kim if (!entry) 222080c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 22217bd59381SGu Zheng return entry; 22227bd59381SGu Zheng } 22237bd59381SGu Zheng 22245f9abab4SJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi, int type) 22255f9abab4SJaegeuk Kim { 2226f7dfd9f3SPark Ju Hyung if (sbi->gc_mode == GC_URGENT) 2227f7dfd9f3SPark Ju Hyung return true; 2228f7dfd9f3SPark Ju Hyung 22295f9abab4SJaegeuk Kim if (get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_RD_NODE) || 22305f9abab4SJaegeuk Kim get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) || 2231fef4129eSChao Yu get_pages(sbi, F2FS_WB_CP_DATA) || 2232fef4129eSChao Yu get_pages(sbi, F2FS_DIO_READ) || 223311ac8ef8SJaegeuk Kim get_pages(sbi, F2FS_DIO_WRITE)) 223411ac8ef8SJaegeuk Kim return false; 223511ac8ef8SJaegeuk Kim 223656659ce8SSahitya Tummala if (type != DISCARD_TIME && SM_I(sbi) && SM_I(sbi)->dcc_info && 223711ac8ef8SJaegeuk Kim atomic_read(&SM_I(sbi)->dcc_info->queued_discard)) 223811ac8ef8SJaegeuk Kim return false; 223911ac8ef8SJaegeuk Kim 224011ac8ef8SJaegeuk Kim if (SM_I(sbi) && SM_I(sbi)->fcc_info && 224172691af6SJaegeuk Kim atomic_read(&SM_I(sbi)->fcc_info->queued_flush)) 22425f9abab4SJaegeuk Kim return false; 224311ac8ef8SJaegeuk Kim 22445f9abab4SJaegeuk Kim return f2fs_time_over(sbi, type); 22455f9abab4SJaegeuk Kim } 22465f9abab4SJaegeuk Kim 22479be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 22489be32d72SJaegeuk Kim unsigned long index, void *item) 22499be32d72SJaegeuk Kim { 22509be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 22519be32d72SJaegeuk Kim cond_resched(); 22529be32d72SJaegeuk Kim } 22539be32d72SJaegeuk Kim 225439a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 225539a53e0cSJaegeuk Kim 225639a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 225739a53e0cSJaegeuk Kim { 225845590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 2259cac5a3d8SDongOh Shin 226039a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 226139a53e0cSJaegeuk Kim } 226239a53e0cSJaegeuk Kim 22637a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 22647a2af766SChao Yu { 22657a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 22667a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 22677a2af766SChao Yu } 22687a2af766SChao Yu 226939a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 227039a53e0cSJaegeuk Kim { 227139a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 227239a53e0cSJaegeuk Kim } 227339a53e0cSJaegeuk Kim 22747a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 22757a2af766SChao Yu static inline block_t datablock_addr(struct inode *inode, 22767a2af766SChao Yu struct page *node_page, unsigned int offset) 227739a53e0cSJaegeuk Kim { 227839a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 227939a53e0cSJaegeuk Kim __le32 *addr_array; 22807a2af766SChao Yu int base = 0; 22817a2af766SChao Yu bool is_inode = IS_INODE(node_page); 2282cac5a3d8SDongOh Shin 228345590710SGu Zheng raw_node = F2FS_NODE(node_page); 22847a2af766SChao Yu 22857a2af766SChao Yu /* from GC path only */ 2286979f492fSLiFan if (is_inode) { 2287979f492fSLiFan if (!inode) 22887a2af766SChao Yu base = offset_in_addr(&raw_node->i); 2289979f492fSLiFan else if (f2fs_has_extra_attr(inode)) 22907a2af766SChao Yu base = get_extra_isize(inode); 22917a2af766SChao Yu } 22927a2af766SChao Yu 229339a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 22947a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 229539a53e0cSJaegeuk Kim } 229639a53e0cSJaegeuk Kim 229739a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 229839a53e0cSJaegeuk Kim { 229939a53e0cSJaegeuk Kim int mask; 230039a53e0cSJaegeuk Kim 230139a53e0cSJaegeuk Kim addr += (nr >> 3); 230239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 230339a53e0cSJaegeuk Kim return mask & *addr; 230439a53e0cSJaegeuk Kim } 230539a53e0cSJaegeuk Kim 2306a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 2307a66cdd98SJaegeuk Kim { 2308a66cdd98SJaegeuk Kim int mask; 2309a66cdd98SJaegeuk Kim 2310a66cdd98SJaegeuk Kim addr += (nr >> 3); 2311a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2312a66cdd98SJaegeuk Kim *addr |= mask; 2313a66cdd98SJaegeuk Kim } 2314a66cdd98SJaegeuk Kim 2315a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 2316a66cdd98SJaegeuk Kim { 2317a66cdd98SJaegeuk Kim int mask; 2318a66cdd98SJaegeuk Kim 2319a66cdd98SJaegeuk Kim addr += (nr >> 3); 2320a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2321a66cdd98SJaegeuk Kim *addr &= ~mask; 2322a66cdd98SJaegeuk Kim } 2323a66cdd98SJaegeuk Kim 232452aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 232539a53e0cSJaegeuk Kim { 232639a53e0cSJaegeuk Kim int mask; 232739a53e0cSJaegeuk Kim int ret; 232839a53e0cSJaegeuk Kim 232939a53e0cSJaegeuk Kim addr += (nr >> 3); 233039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 233139a53e0cSJaegeuk Kim ret = mask & *addr; 233239a53e0cSJaegeuk Kim *addr |= mask; 233339a53e0cSJaegeuk Kim return ret; 233439a53e0cSJaegeuk Kim } 233539a53e0cSJaegeuk Kim 233652aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 233739a53e0cSJaegeuk Kim { 233839a53e0cSJaegeuk Kim int mask; 233939a53e0cSJaegeuk Kim int ret; 234039a53e0cSJaegeuk Kim 234139a53e0cSJaegeuk Kim addr += (nr >> 3); 234239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 234339a53e0cSJaegeuk Kim ret = mask & *addr; 234439a53e0cSJaegeuk Kim *addr &= ~mask; 234539a53e0cSJaegeuk Kim return ret; 234639a53e0cSJaegeuk Kim } 234739a53e0cSJaegeuk Kim 2348c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 2349c6ac4c0eSGu Zheng { 2350c6ac4c0eSGu Zheng int mask; 2351c6ac4c0eSGu Zheng 2352c6ac4c0eSGu Zheng addr += (nr >> 3); 2353c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 2354c6ac4c0eSGu Zheng *addr ^= mask; 2355c6ac4c0eSGu Zheng } 2356c6ac4c0eSGu Zheng 235759c84408SChao Yu /* 235836098557SEric Biggers * On-disk inode flags (f2fs_inode::i_flags) 235959c84408SChao Yu */ 236059c84408SChao Yu #define F2FS_SYNC_FL 0x00000008 /* Synchronous updates */ 236159c84408SChao Yu #define F2FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ 236259c84408SChao Yu #define F2FS_APPEND_FL 0x00000020 /* writes to file may only append */ 236359c84408SChao Yu #define F2FS_NODUMP_FL 0x00000040 /* do not dump file */ 236459c84408SChao Yu #define F2FS_NOATIME_FL 0x00000080 /* do not update atime */ 236559c84408SChao Yu #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ 236659c84408SChao Yu #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 236759c84408SChao Yu #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 23682c2eb7a3SDaniel Rosenberg #define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */ 236959c84408SChao Yu 237059c84408SChao Yu /* Flags that should be inherited by new inodes from their parent. */ 237136098557SEric Biggers #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \ 23722c2eb7a3SDaniel Rosenberg F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 23732c2eb7a3SDaniel Rosenberg F2FS_CASEFOLD_FL) 237459c84408SChao Yu 237559c84408SChao Yu /* Flags that are appropriate for regular files (all but dir-specific ones). */ 23762c2eb7a3SDaniel Rosenberg #define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 23772c2eb7a3SDaniel Rosenberg F2FS_CASEFOLD_FL)) 237859c84408SChao Yu 237959c84408SChao Yu /* Flags that are appropriate for non-directories/regular files. */ 238059c84408SChao Yu #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL) 23815c57132eSChao Yu 23825c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 23835c57132eSChao Yu { 23845c57132eSChao Yu if (S_ISDIR(mode)) 23855c57132eSChao Yu return flags; 23865c57132eSChao Yu else if (S_ISREG(mode)) 23875c57132eSChao Yu return flags & F2FS_REG_FLMASK; 23885c57132eSChao Yu else 23895c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 23905c57132eSChao Yu } 23915c57132eSChao Yu 239239a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 239339a53e0cSJaegeuk Kim enum { 239439a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 2395b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 239626de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 2397ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 239839a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 239939a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 240039a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 2401c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 2402c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 2403444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 24041001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 240534d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 2406fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 2407fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 240888b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 240988b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 24105fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 241102a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 24123c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 24131e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 2414b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 2415510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 2416d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 2417c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 2418dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 2419ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 24207a2af766SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 24215c57132eSChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 24221ad71a27SJaegeuk Kim FI_PIN_FILE, /* indicate file should not be gced */ 24232ef79ecbSChao Yu FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */ 242495ae251fSEric Biggers FI_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ 242539a53e0cSJaegeuk Kim }; 242639a53e0cSJaegeuk Kim 2427205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2428205b9822SJaegeuk Kim int flag, bool set) 242939a53e0cSJaegeuk Kim { 2430205b9822SJaegeuk Kim switch (flag) { 2431205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2432205b9822SJaegeuk Kim case FI_INLINE_DATA: 2433205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 24349ac1e2d8SDaeho Jeong case FI_NEW_INODE: 2435205b9822SJaegeuk Kim if (set) 2436205b9822SJaegeuk Kim return; 2437f5d5510eSJaegeuk Kim /* fall through */ 2438205b9822SJaegeuk Kim case FI_DATA_EXIST: 2439205b9822SJaegeuk Kim case FI_INLINE_DOTS: 24401ad71a27SJaegeuk Kim case FI_PIN_FILE: 24417c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2442205b9822SJaegeuk Kim } 244339a53e0cSJaegeuk Kim } 244439a53e0cSJaegeuk Kim 244591942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 244639a53e0cSJaegeuk Kim { 244791942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 244891942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 2449205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 245039a53e0cSJaegeuk Kim } 245139a53e0cSJaegeuk Kim 245291942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 245339a53e0cSJaegeuk Kim { 245491942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 245539a53e0cSJaegeuk Kim } 245639a53e0cSJaegeuk Kim 245791942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 245839a53e0cSJaegeuk Kim { 245991942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 246091942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 2461205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 246239a53e0cSJaegeuk Kim } 246339a53e0cSJaegeuk Kim 246495ae251fSEric Biggers static inline bool f2fs_verity_in_progress(struct inode *inode) 246595ae251fSEric Biggers { 246695ae251fSEric Biggers return IS_ENABLED(CONFIG_FS_VERITY) && 246795ae251fSEric Biggers is_inode_flag_set(inode, FI_VERITY_IN_PROGRESS); 246895ae251fSEric Biggers } 246995ae251fSEric Biggers 247091942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2471444c580fSJaegeuk Kim { 247291942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 247391942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 24747c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 247539a53e0cSJaegeuk Kim } 247639a53e0cSJaegeuk Kim 2477a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2478a1961246SJaegeuk Kim { 2479a1961246SJaegeuk Kim if (inc) 2480a1961246SJaegeuk Kim inc_nlink(inode); 2481a1961246SJaegeuk Kim else 2482a1961246SJaegeuk Kim drop_nlink(inode); 24837c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2484a1961246SJaegeuk Kim } 2485a1961246SJaegeuk Kim 24868edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 24870abd675eSChao Yu block_t diff, bool add, bool claim) 24888edd03c8SJaegeuk Kim { 248926de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 249026de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 249126de9b11SJaegeuk Kim 24920abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 24930abd675eSChao Yu if (add) { 24940abd675eSChao Yu if (claim) 24950abd675eSChao Yu dquot_claim_block(inode, diff); 24960abd675eSChao Yu else 24970abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 24980abd675eSChao Yu } else { 24990abd675eSChao Yu dquot_free_block(inode, diff); 25000abd675eSChao Yu } 25010abd675eSChao Yu 25027c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 250326de9b11SJaegeuk Kim if (clean || recover) 250426de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 25058edd03c8SJaegeuk Kim } 25068edd03c8SJaegeuk Kim 2507fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2508fc9581c8SJaegeuk Kim { 250926de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 251026de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 251126de9b11SJaegeuk Kim 2512fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2513fc9581c8SJaegeuk Kim return; 2514fc9581c8SJaegeuk Kim 2515fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 25167c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 251726de9b11SJaegeuk Kim if (clean || recover) 251826de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 251926de9b11SJaegeuk Kim } 252026de9b11SJaegeuk Kim 2521205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2522205b9822SJaegeuk Kim { 2523205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 25247c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2525205b9822SJaegeuk Kim } 2526205b9822SJaegeuk Kim 25271ad71a27SJaegeuk Kim static inline void f2fs_i_gc_failures_write(struct inode *inode, 25281ad71a27SJaegeuk Kim unsigned int count) 25291ad71a27SJaegeuk Kim { 25302ef79ecbSChao Yu F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count; 25311ad71a27SJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 25321ad71a27SJaegeuk Kim } 25331ad71a27SJaegeuk Kim 2534205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2535205b9822SJaegeuk Kim { 2536205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 25377c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2538205b9822SJaegeuk Kim } 2539205b9822SJaegeuk Kim 2540205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2541205b9822SJaegeuk Kim { 2542205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 25437c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2544205b9822SJaegeuk Kim } 2545205b9822SJaegeuk Kim 254691942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2547444c580fSJaegeuk Kim { 2548205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2549205b9822SJaegeuk Kim 2550444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 2551205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 25521001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 2553205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 255434d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 2555205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 2556b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 2557205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 2558510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 2559205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 25607a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 25617a2af766SChao Yu set_bit(FI_EXTRA_ATTR, &fi->flags); 25621ad71a27SJaegeuk Kim if (ri->i_inline & F2FS_PIN_FILE) 25631ad71a27SJaegeuk Kim set_bit(FI_PIN_FILE, &fi->flags); 2564444c580fSJaegeuk Kim } 2565444c580fSJaegeuk Kim 256691942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2567444c580fSJaegeuk Kim { 2568444c580fSJaegeuk Kim ri->i_inline = 0; 2569444c580fSJaegeuk Kim 257091942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2571444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 257291942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 25731001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 257491942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 257534d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 257691942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2577b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 257891942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2579510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 25807a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 25817a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 25821ad71a27SJaegeuk Kim if (is_inode_flag_set(inode, FI_PIN_FILE)) 25831ad71a27SJaegeuk Kim ri->i_inline |= F2FS_PIN_FILE; 25847a2af766SChao Yu } 25857a2af766SChao Yu 25867a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 25877a2af766SChao Yu { 25887a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2589444c580fSJaegeuk Kim } 2590444c580fSJaegeuk Kim 2591987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2592987c7c31SChao Yu { 259391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2594987c7c31SChao Yu } 2595987c7c31SChao Yu 259681ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2597de93653fSJaegeuk Kim { 2598d02a6e61SChao Yu unsigned int addrs = CUR_ADDRS_PER_INODE(inode) - 2599d02a6e61SChao Yu get_inline_xattr_addrs(inode); 2600d02a6e61SChao Yu return ALIGN_DOWN(addrs, 1); 2601d02a6e61SChao Yu } 2602d02a6e61SChao Yu 2603d02a6e61SChao Yu static inline unsigned int addrs_per_block(struct inode *inode) 2604d02a6e61SChao Yu { 2605d02a6e61SChao Yu return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, 1); 2606de93653fSJaegeuk Kim } 2607de93653fSJaegeuk Kim 26086afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page) 260965985d93SJaegeuk Kim { 2610695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2611cac5a3d8SDongOh Shin 261265985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 2613b323fd28SChao Yu get_inline_xattr_addrs(inode)]); 261465985d93SJaegeuk Kim } 261565985d93SJaegeuk Kim 261665985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 261765985d93SJaegeuk Kim { 2618622927f3SChao Yu if (f2fs_has_inline_xattr(inode)) 26196afc662eSChao Yu return get_inline_xattr_addrs(inode) * sizeof(__le32); 2620622927f3SChao Yu return 0; 262165985d93SJaegeuk Kim } 262265985d93SJaegeuk Kim 26230dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 26240dbdc2aeSJaegeuk Kim { 262591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 26260dbdc2aeSJaegeuk Kim } 26270dbdc2aeSJaegeuk Kim 2628b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2629b3d208f9SJaegeuk Kim { 263091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2631b3d208f9SJaegeuk Kim } 2632b3d208f9SJaegeuk Kim 2633510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2634510022a8SJaegeuk Kim { 263591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2636510022a8SJaegeuk Kim } 2637510022a8SJaegeuk Kim 26381ad71a27SJaegeuk Kim static inline bool f2fs_is_pinned_file(struct inode *inode) 26391ad71a27SJaegeuk Kim { 26401ad71a27SJaegeuk Kim return is_inode_flag_set(inode, FI_PIN_FILE); 26411ad71a27SJaegeuk Kim } 26421ad71a27SJaegeuk Kim 264388b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 264488b88a66SJaegeuk Kim { 264591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 264688b88a66SJaegeuk Kim } 264788b88a66SJaegeuk Kim 26485fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 26495fe45743SChao Yu { 26505fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 26515fe45743SChao Yu } 26525fe45743SChao Yu 265302a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 265402a1335fSJaegeuk Kim { 265591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 265602a1335fSJaegeuk Kim } 265702a1335fSJaegeuk Kim 26583c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 26593c6c2bebSJaegeuk Kim { 266091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 26613c6c2bebSJaegeuk Kim } 26623c6c2bebSJaegeuk Kim 26631e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 26641e84371fSJaegeuk Kim { 266591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 26661e84371fSJaegeuk Kim } 26671e84371fSJaegeuk Kim 2668f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 26691001b347SHuajun Li { 2670695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 26717a2af766SChao Yu int extra_size = get_extra_isize(inode); 2672cac5a3d8SDongOh Shin 26737a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 26741001b347SHuajun Li } 26751001b347SHuajun Li 267634d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 267734d67debSChao Yu { 267891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 267934d67debSChao Yu } 268034d67debSChao Yu 2681b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2682b5492af7SJaegeuk Kim { 2683b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2684b5492af7SJaegeuk Kim } 2685b5492af7SJaegeuk Kim 2686b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2687b5492af7SJaegeuk Kim { 2688b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 26897c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2690b5492af7SJaegeuk Kim } 2691b5492af7SJaegeuk Kim 2692b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2693b5492af7SJaegeuk Kim { 2694b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 26957c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2696b5492af7SJaegeuk Kim } 2697b5492af7SJaegeuk Kim 2698fe1897eaSChao Yu static inline bool f2fs_is_time_consistent(struct inode *inode) 2699fe1897eaSChao Yu { 2700fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime)) 2701fe1897eaSChao Yu return false; 2702fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime)) 2703fe1897eaSChao Yu return false; 2704fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime)) 2705fe1897eaSChao Yu return false; 2706fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3, 2707fe1897eaSChao Yu &F2FS_I(inode)->i_crtime)) 2708fe1897eaSChao Yu return false; 2709fe1897eaSChao Yu return true; 2710fe1897eaSChao Yu } 2711fe1897eaSChao Yu 271226787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 271326787236SJaegeuk Kim { 2714a0d00fadSChao Yu bool ret; 2715a0d00fadSChao Yu 271626787236SJaegeuk Kim if (dsync) { 271726787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 271826787236SJaegeuk Kim 271926787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 272026787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 272126787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 272226787236SJaegeuk Kim return ret; 272326787236SJaegeuk Kim } 272426787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 272526787236SJaegeuk Kim file_keep_isize(inode) || 2726235831d7SJunling Zheng i_size_read(inode) & ~PAGE_MASK) 272726787236SJaegeuk Kim return false; 2728a0d00fadSChao Yu 2729fe1897eaSChao Yu if (!f2fs_is_time_consistent(inode)) 2730214c2461SJaegeuk Kim return false; 2731214c2461SJaegeuk Kim 2732a0d00fadSChao Yu down_read(&F2FS_I(inode)->i_sem); 2733a0d00fadSChao Yu ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 2734a0d00fadSChao Yu up_read(&F2FS_I(inode)->i_sem); 2735a0d00fadSChao Yu 2736a0d00fadSChao Yu return ret; 2737267378d4SChao Yu } 2738267378d4SChao Yu 2739deeedd71SChao Yu static inline bool f2fs_readonly(struct super_block *sb) 274077888c1eSJaegeuk Kim { 2741deeedd71SChao Yu return sb_rdonly(sb); 274277888c1eSJaegeuk Kim } 274377888c1eSJaegeuk Kim 2744744602cfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 2745744602cfSJaegeuk Kim { 2746aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 2747744602cfSJaegeuk Kim } 2748744602cfSJaegeuk Kim 2749eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2750eaa693f4SJaegeuk Kim { 2751eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2752eaa693f4SJaegeuk Kim return true; 2753eaa693f4SJaegeuk Kim 2754eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2755eaa693f4SJaegeuk Kim return true; 2756eaa693f4SJaegeuk Kim 2757eaa693f4SJaegeuk Kim return false; 2758eaa693f4SJaegeuk Kim } 2759eaa693f4SJaegeuk Kim 27603e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 27613e72f721SJaegeuk Kim { 2762e4589fa5SSahitya Tummala struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2763e4589fa5SSahitya Tummala 2764e4589fa5SSahitya Tummala if (!test_opt(sbi, EXTENT_CACHE) || 276591942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 27663e72f721SJaegeuk Kim return false; 27673e72f721SJaegeuk Kim 2768e4589fa5SSahitya Tummala /* 2769e4589fa5SSahitya Tummala * for recovered files during mount do not create extents 2770e4589fa5SSahitya Tummala * if shrinker is not registered. 2771e4589fa5SSahitya Tummala */ 2772e4589fa5SSahitya Tummala if (list_empty(&sbi->s_list)) 2773e4589fa5SSahitya Tummala return false; 2774e4589fa5SSahitya Tummala 2775886f56f9SAl Viro return S_ISREG(inode->i_mode); 27763e72f721SJaegeuk Kim } 27773e72f721SJaegeuk Kim 27781ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 27791ecc0c5cSChao Yu size_t size, gfp_t flags) 27800414b004SJaegeuk Kim { 27815222595dSJaegeuk Kim void *ret; 27825222595dSJaegeuk Kim 278355523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 2784c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_KMALLOC); 27852c63feadSJaegeuk Kim return NULL; 278655523519SChao Yu } 27877fa750a1SArnd Bergmann 27885222595dSJaegeuk Kim ret = kmalloc(size, flags); 27895222595dSJaegeuk Kim if (ret) 27905222595dSJaegeuk Kim return ret; 27915222595dSJaegeuk Kim 27925222595dSJaegeuk Kim return kvmalloc(size, flags); 27930414b004SJaegeuk Kim } 27940414b004SJaegeuk Kim 2795acbf054dSChao Yu static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, 2796acbf054dSChao Yu size_t size, gfp_t flags) 2797acbf054dSChao Yu { 2798acbf054dSChao Yu return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); 2799acbf054dSChao Yu } 2800acbf054dSChao Yu 2801628b3d14SChao Yu static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, 2802628b3d14SChao Yu size_t size, gfp_t flags) 2803628b3d14SChao Yu { 2804628b3d14SChao Yu if (time_to_inject(sbi, FAULT_KVMALLOC)) { 2805c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_KVMALLOC); 2806628b3d14SChao Yu return NULL; 2807628b3d14SChao Yu } 28087fa750a1SArnd Bergmann 2809628b3d14SChao Yu return kvmalloc(size, flags); 2810628b3d14SChao Yu } 2811628b3d14SChao Yu 2812628b3d14SChao Yu static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi, 2813628b3d14SChao Yu size_t size, gfp_t flags) 2814628b3d14SChao Yu { 2815628b3d14SChao Yu return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO); 2816628b3d14SChao Yu } 2817628b3d14SChao Yu 28187a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 2819f2470371SChao Yu { 28207a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 2821f2470371SChao Yu } 2822f2470371SChao Yu 28236afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode) 28246afc662eSChao Yu { 28256afc662eSChao Yu return F2FS_I(inode)->i_inline_xattr_size; 28266afc662eSChao Yu } 28276afc662eSChao Yu 28284d57b86dSChao Yu #define f2fs_get_inode_mode(i) \ 282991942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 2830a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 2831a6dda0e6SChristoph Hellwig 28327a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 28337a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 28347a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 28357a2af766SChao Yu 28365c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 28375c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 28382f84babfSSheng Yong ((offsetof(typeof(*(f2fs_inode)), field) + \ 28395c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 28402f84babfSSheng Yong <= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize))) \ 28415c57132eSChao Yu 2842b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 2843b0af6d49SChao Yu { 2844b0af6d49SChao Yu int i; 2845b0af6d49SChao Yu 2846b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2847b0af6d49SChao Yu for (i = 0; i < NR_IO_TYPE; i++) 2848b0af6d49SChao Yu sbi->write_iostat[i] = 0; 2849b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2850b0af6d49SChao Yu } 2851b0af6d49SChao Yu 2852b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 2853b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 2854b0af6d49SChao Yu { 2855b0af6d49SChao Yu if (!sbi->iostat_enable) 2856b0af6d49SChao Yu return; 2857b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2858b0af6d49SChao Yu sbi->write_iostat[type] += io_bytes; 2859b0af6d49SChao Yu 2860b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 2861b0af6d49SChao Yu sbi->write_iostat[APP_BUFFERED_IO] = 2862b0af6d49SChao Yu sbi->write_iostat[APP_WRITE_IO] - 2863b0af6d49SChao Yu sbi->write_iostat[APP_DIRECT_IO]; 2864b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2865b0af6d49SChao Yu } 2866b0af6d49SChao Yu 28672c70c5e3SChao Yu #define __is_large_section(sbi) ((sbi)->segs_per_sec > 1) 28682c70c5e3SChao Yu 28696dc3a126SChao Yu #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META) 2870c9b60788SChao Yu 2871e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 2872e1da7872SChao Yu block_t blkaddr, int type); 2873e1da7872SChao Yu static inline void verify_blkaddr(struct f2fs_sb_info *sbi, 2874e1da7872SChao Yu block_t blkaddr, int type) 2875e1da7872SChao Yu { 2876e1da7872SChao Yu if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) { 2877dcbb4c10SJoe Perches f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.", 2878e1da7872SChao Yu blkaddr, type); 2879e1da7872SChao Yu f2fs_bug_on(sbi, 1); 2880e1da7872SChao Yu } 2881e1da7872SChao Yu } 2882e1da7872SChao Yu 2883e1da7872SChao Yu static inline bool __is_valid_data_blkaddr(block_t blkaddr) 28847b525dd0SChao Yu { 28857b525dd0SChao Yu if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) 28867b525dd0SChao Yu return false; 28877b525dd0SChao Yu return true; 28887b525dd0SChao Yu } 28897b525dd0SChao Yu 2890240a5915SChao Yu static inline void f2fs_set_page_private(struct page *page, 2891240a5915SChao Yu unsigned long data) 2892240a5915SChao Yu { 2893240a5915SChao Yu if (PagePrivate(page)) 2894240a5915SChao Yu return; 2895240a5915SChao Yu 2896240a5915SChao Yu get_page(page); 2897240a5915SChao Yu SetPagePrivate(page); 2898240a5915SChao Yu set_page_private(page, data); 2899240a5915SChao Yu } 2900240a5915SChao Yu 2901240a5915SChao Yu static inline void f2fs_clear_page_private(struct page *page) 2902240a5915SChao Yu { 2903240a5915SChao Yu if (!PagePrivate(page)) 2904240a5915SChao Yu return; 2905240a5915SChao Yu 2906240a5915SChao Yu set_page_private(page, 0); 2907240a5915SChao Yu ClearPagePrivate(page); 2908240a5915SChao Yu f2fs_put_page(page, 0); 2909240a5915SChao Yu } 2910240a5915SChao Yu 291139a53e0cSJaegeuk Kim /* 291239a53e0cSJaegeuk Kim * file.c 291339a53e0cSJaegeuk Kim */ 2914cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 29154d57b86dSChao Yu void f2fs_truncate_data_blocks(struct dnode_of_data *dn); 2916c42d28ceSChao Yu int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock); 2917cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2918a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2919a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2920cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 29214d57b86dSChao Yu int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 29224d57b86dSChao Yu void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2923c4020b2dSChao Yu int f2fs_precache_extents(struct inode *inode); 2924cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2925cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 292678130819SChao Yu int f2fs_transfer_project_quota(struct inode *inode, kprojid_t kprojid); 29271ad71a27SJaegeuk Kim int f2fs_pin_file_control(struct inode *inode, bool inc); 292839a53e0cSJaegeuk Kim 292939a53e0cSJaegeuk Kim /* 293039a53e0cSJaegeuk Kim * inode.c 293139a53e0cSJaegeuk Kim */ 2932cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2933704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 2934704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 2935cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2936cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 29374d57b86dSChao Yu int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 29384d57b86dSChao Yu void f2fs_update_inode(struct inode *inode, struct page *node_page); 29394d57b86dSChao Yu void f2fs_update_inode_page(struct inode *inode); 2940cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2941cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 29424d57b86dSChao Yu void f2fs_handle_failed_inode(struct inode *inode); 294339a53e0cSJaegeuk Kim 294439a53e0cSJaegeuk Kim /* 294539a53e0cSJaegeuk Kim * namei.c 294639a53e0cSJaegeuk Kim */ 29474d57b86dSChao Yu int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, 2948b6a06cbbSChao Yu bool hot, bool set); 294939a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 295039a53e0cSJaegeuk Kim 29512c2eb7a3SDaniel Rosenberg extern int f2fs_ci_compare(const struct inode *parent, 29522c2eb7a3SDaniel Rosenberg const struct qstr *name, 2953950d47f2SChao Yu const struct qstr *entry, 2954950d47f2SChao Yu bool quick); 29552c2eb7a3SDaniel Rosenberg 295639a53e0cSJaegeuk Kim /* 295739a53e0cSJaegeuk Kim * dir.c 295839a53e0cSJaegeuk Kim */ 29594d57b86dSChao Yu unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de); 29604d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, 2961cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2962cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2963cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2964cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 29654d57b86dSChao Yu void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent, 2966cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 29674d57b86dSChao Yu struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir, 2968cac5a3d8SDongOh Shin const struct qstr *new_name, 2969cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 29704d57b86dSChao Yu void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode, 2971cac5a3d8SDongOh Shin unsigned int current_depth); 29724d57b86dSChao Yu int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots); 2973cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2974cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2975cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2976cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2977cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2978cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2979cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2980cac5a3d8SDongOh Shin struct page **page); 2981cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2982cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2983cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2984cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2985cac5a3d8SDongOh Shin unsigned int bit_pos); 2986cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2987cac5a3d8SDongOh Shin const struct qstr *orig_name, 2988cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 29894d57b86dSChao Yu int f2fs_add_dentry(struct inode *dir, struct fscrypt_name *fname, 2990cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 29914d57b86dSChao Yu int f2fs_do_add_link(struct inode *dir, const struct qstr *name, 2992cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2993cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2994cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2995cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2996cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 299739a53e0cSJaegeuk Kim 2998b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2999b7f7a5e0SAl Viro { 30004d57b86dSChao Yu return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name, 3001510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 3002b7f7a5e0SAl Viro } 3003b7f7a5e0SAl Viro 300439a53e0cSJaegeuk Kim /* 300539a53e0cSJaegeuk Kim * super.c 300639a53e0cSJaegeuk Kim */ 3007cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 3008cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 3009ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); 3010af033b2aSChao Yu int f2fs_quota_sync(struct super_block *sb, int type); 30114b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 3012cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 3013cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 30144d57b86dSChao Yu int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); 301539a53e0cSJaegeuk Kim 301639a53e0cSJaegeuk Kim /* 301739a53e0cSJaegeuk Kim * hash.c 301839a53e0cSJaegeuk Kim */ 30192c2eb7a3SDaniel Rosenberg f2fs_hash_t f2fs_dentry_hash(const struct inode *dir, 30202c2eb7a3SDaniel Rosenberg const struct qstr *name_info, struct fscrypt_name *fname); 302139a53e0cSJaegeuk Kim 302239a53e0cSJaegeuk Kim /* 302339a53e0cSJaegeuk Kim * node.c 302439a53e0cSJaegeuk Kim */ 302539a53e0cSJaegeuk Kim struct dnode_of_data; 302639a53e0cSJaegeuk Kim struct node_info; 302739a53e0cSJaegeuk Kim 30284d57b86dSChao Yu int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid); 30294d57b86dSChao Yu bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type); 303050fa53ecSChao Yu bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page); 303150fa53ecSChao Yu void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi); 303250fa53ecSChao Yu void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page); 303350fa53ecSChao Yu void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi); 30344d57b86dSChao Yu int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 30354d57b86dSChao Yu bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 30364d57b86dSChao Yu bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 30377735730dSChao Yu int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, 30384d57b86dSChao Yu struct node_info *ni); 30394d57b86dSChao Yu pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 30404d57b86dSChao Yu int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 30414d57b86dSChao Yu int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from); 30424d57b86dSChao Yu int f2fs_truncate_xattr_node(struct inode *inode); 304350fa53ecSChao Yu int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, 304450fa53ecSChao Yu unsigned int seq_id); 30454d57b86dSChao Yu int f2fs_remove_inode_page(struct inode *inode); 30464d57b86dSChao Yu struct page *f2fs_new_inode_page(struct inode *inode); 30474d57b86dSChao Yu struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs); 30484d57b86dSChao Yu void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 30494d57b86dSChao Yu struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 30504d57b86dSChao Yu struct page *f2fs_get_node_page_ra(struct page *parent, int start); 305148018b4cSChao Yu int f2fs_move_node_page(struct page *node_page, int gc_type); 30524d57b86dSChao Yu int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 305350fa53ecSChao Yu struct writeback_control *wbc, bool atomic, 305450fa53ecSChao Yu unsigned int *seq_id); 30554d57b86dSChao Yu int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, 30564d57b86dSChao Yu struct writeback_control *wbc, 3057b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 3058e2374015SChao Yu int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 30594d57b86dSChao Yu bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 30604d57b86dSChao Yu void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 30614d57b86dSChao Yu void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 30624d57b86dSChao Yu int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 30634d57b86dSChao Yu void f2fs_recover_inline_xattr(struct inode *inode, struct page *page); 30644d57b86dSChao Yu int f2fs_recover_xattr_data(struct inode *inode, struct page *page); 30654d57b86dSChao Yu int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 30667735730dSChao Yu int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, 3067cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 3068edc55aafSJaegeuk Kim int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 30694d57b86dSChao Yu int f2fs_build_node_manager(struct f2fs_sb_info *sbi); 30704d57b86dSChao Yu void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi); 30714d57b86dSChao Yu int __init f2fs_create_node_manager_caches(void); 30724d57b86dSChao Yu void f2fs_destroy_node_manager_caches(void); 307339a53e0cSJaegeuk Kim 307439a53e0cSJaegeuk Kim /* 307539a53e0cSJaegeuk Kim * segment.c 307639a53e0cSJaegeuk Kim */ 30774d57b86dSChao Yu bool f2fs_need_SSR(struct f2fs_sb_info *sbi); 30784d57b86dSChao Yu void f2fs_register_inmem_page(struct inode *inode, struct page *page); 30794d57b86dSChao Yu void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure); 30804d57b86dSChao Yu void f2fs_drop_inmem_pages(struct inode *inode); 30814d57b86dSChao Yu void f2fs_drop_inmem_page(struct inode *inode, struct page *page); 30824d57b86dSChao Yu int f2fs_commit_inmem_pages(struct inode *inode); 3083cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 3084cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 308539d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 30864d57b86dSChao Yu int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi); 30871228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); 30884d57b86dSChao Yu void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 30894d57b86dSChao Yu void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 30904d57b86dSChao Yu bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 30914d57b86dSChao Yu void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi); 30924d57b86dSChao Yu void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi); 309303f2c02dSJaegeuk Kim bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi); 30944d57b86dSChao Yu void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, 30954d57b86dSChao Yu struct cp_control *cpc); 30964354994fSDaniel Rosenberg void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi); 30974d3aed70SDaniel Rosenberg block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi); 30984d3aed70SDaniel Rosenberg int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable); 30994d57b86dSChao Yu void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi); 31004d57b86dSChao Yu int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 310104f0b2eaSQiuyang Sun void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, 310204f0b2eaSQiuyang Sun unsigned int start, unsigned int end); 3103f5a53edcSJaegeuk Kim void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi, int type); 3104cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 31054d57b86dSChao Yu bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, 31064d57b86dSChao Yu struct cp_control *cpc); 31074d57b86dSChao Yu struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 31084d57b86dSChao Yu void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src, 31094d57b86dSChao Yu block_t blk_addr); 31104d57b86dSChao Yu void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 3111b0af6d49SChao Yu enum iostat_type io_type); 31124d57b86dSChao Yu void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio); 31134d57b86dSChao Yu void f2fs_outplace_write_data(struct dnode_of_data *dn, 31144d57b86dSChao Yu struct f2fs_io_info *fio); 31154d57b86dSChao Yu int f2fs_inplace_write_data(struct f2fs_io_info *fio); 31164d57b86dSChao Yu void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 3117cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 3118cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 3119cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 3120cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 3121cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 3122cac5a3d8SDongOh Shin bool recover_newaddr); 31234d57b86dSChao Yu void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 3124cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 3125fb830fc5SChao Yu struct f2fs_summary *sum, int type, 3126fb830fc5SChao Yu struct f2fs_io_info *fio, bool add_list); 3127cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 3128bae0ee7aSChao Yu enum page_type type, bool ordered, bool locked); 31290ded69f6SJaegeuk Kim void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr); 31301e78e8bdSSahitya Tummala void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr, 31311e78e8bdSSahitya Tummala block_t len); 31324d57b86dSChao Yu void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 31334d57b86dSChao Yu void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 31344d57b86dSChao Yu int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 3135cac5a3d8SDongOh Shin unsigned int val, int alloc); 31364d57b86dSChao Yu void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 3137c426d991SShin'ichiro Kawasaki int f2fs_fix_curseg_write_pointer(struct f2fs_sb_info *sbi); 3138d508c94eSShin'ichiro Kawasaki int f2fs_check_write_pointer(struct f2fs_sb_info *sbi); 31394d57b86dSChao Yu int f2fs_build_segment_manager(struct f2fs_sb_info *sbi); 31404d57b86dSChao Yu void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi); 31414d57b86dSChao Yu int __init f2fs_create_segment_manager_caches(void); 31424d57b86dSChao Yu void f2fs_destroy_segment_manager_caches(void); 31434d57b86dSChao Yu int f2fs_rw_hint_to_seg_type(enum rw_hint hint); 31444d57b86dSChao Yu enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, 31454d57b86dSChao Yu enum page_type type, enum temp_type temp); 314639a53e0cSJaegeuk Kim 314739a53e0cSJaegeuk Kim /* 314839a53e0cSJaegeuk Kim * checkpoint.c 314939a53e0cSJaegeuk Kim */ 3150cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 31514d57b86dSChao Yu struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 31524d57b86dSChao Yu struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 31537735730dSChao Yu struct page *f2fs_get_meta_page_nofail(struct f2fs_sb_info *sbi, pgoff_t index); 31544d57b86dSChao Yu struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 3155e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 31564d57b86dSChao Yu block_t blkaddr, int type); 31574d57b86dSChao Yu int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 3158cac5a3d8SDongOh Shin int type, bool sync); 31594d57b86dSChao Yu void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 31604d57b86dSChao Yu long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 3161b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 31624d57b86dSChao Yu void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 31634d57b86dSChao Yu void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 31644d57b86dSChao Yu void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all); 31654d57b86dSChao Yu bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 31664d57b86dSChao Yu void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 316739d787beSChao Yu unsigned int devidx, int type); 31684d57b86dSChao Yu bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 316939d787beSChao Yu unsigned int devidx, int type); 3170cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 31714d57b86dSChao Yu int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi); 31724d57b86dSChao Yu void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi); 31734d57b86dSChao Yu void f2fs_add_orphan_inode(struct inode *inode); 31744d57b86dSChao Yu void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 31754d57b86dSChao Yu int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi); 31764d57b86dSChao Yu int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi); 31774d57b86dSChao Yu void f2fs_update_dirty_page(struct inode *inode, struct page *page); 31784d57b86dSChao Yu void f2fs_remove_dirty_inode(struct inode *inode); 31794d57b86dSChao Yu int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 318050fa53ecSChao Yu void f2fs_wait_on_all_pages_writeback(struct f2fs_sb_info *sbi); 31814d57b86dSChao Yu int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 31824d57b86dSChao Yu void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi); 31834d57b86dSChao Yu int __init f2fs_create_checkpoint_caches(void); 31844d57b86dSChao Yu void f2fs_destroy_checkpoint_caches(void); 318539a53e0cSJaegeuk Kim 318639a53e0cSJaegeuk Kim /* 318739a53e0cSJaegeuk Kim * data.c 318839a53e0cSJaegeuk Kim */ 3189*f543805fSChao Yu int __init f2fs_init_bioset(void); 3190*f543805fSChao Yu void f2fs_destroy_bioset(void); 3191*f543805fSChao Yu struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, int npages, bool no_fail); 31926dbb1796SEric Biggers int f2fs_init_post_read_processing(void); 31936dbb1796SEric Biggers void f2fs_destroy_post_read_processing(void); 31940b20fcecSChao Yu int f2fs_init_bio_entry_cache(void); 31950b20fcecSChao Yu void f2fs_destroy_bio_entry_cache(void); 3196b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 3197b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 3198bab475c5SChao Yu struct inode *inode, struct page *page, 3199bab475c5SChao Yu nid_t ino, enum page_type type); 32000b20fcecSChao Yu void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi, 32010b20fcecSChao Yu struct bio **bio, struct page *page); 3202b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 3203cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 32048648de2cSChao Yu int f2fs_merge_page_bio(struct f2fs_io_info *fio); 3205fe16efe6SChao Yu void f2fs_submit_page_write(struct f2fs_io_info *fio); 3206cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 3207cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 3208cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 32094d57b86dSChao Yu void f2fs_set_data_blkaddr(struct dnode_of_data *dn); 3210cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 32114d57b86dSChao Yu int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 32124d57b86dSChao Yu int f2fs_reserve_new_block(struct dnode_of_data *dn); 3213cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 3214cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 3215cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 32164d57b86dSChao Yu struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, 3217cac5a3d8SDongOh Shin int op_flags, bool for_write); 32184d57b86dSChao Yu struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index); 32194d57b86dSChao Yu struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index, 3220cac5a3d8SDongOh Shin bool for_write); 32214d57b86dSChao Yu struct page *f2fs_get_new_data_page(struct inode *inode, 3222cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 32234d57b86dSChao Yu int f2fs_do_write_data_page(struct f2fs_io_info *fio); 322439a86958SChao Yu void __do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock); 3225cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 3226cac5a3d8SDongOh Shin int create, int flag); 3227cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 3228cac5a3d8SDongOh Shin u64 start, u64 len); 32294d57b86dSChao Yu bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); 32304d57b86dSChao Yu bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); 3231cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 3232cac5a3d8SDongOh Shin unsigned int length); 3233cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 32345b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 3235cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 3236cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 32375b7a487cSWeichao Guo #endif 3238b91050a8SHyunchul Lee bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len); 32395ec2d99dSMatthew Wilcox void f2fs_clear_page_cache_dirty_tag(struct page *page); 324039a53e0cSJaegeuk Kim 324139a53e0cSJaegeuk Kim /* 324239a53e0cSJaegeuk Kim * gc.c 324339a53e0cSJaegeuk Kim */ 32444d57b86dSChao Yu int f2fs_start_gc_thread(struct f2fs_sb_info *sbi); 32454d57b86dSChao Yu void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi); 32464d57b86dSChao Yu block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 3247e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 3248e066b83cSJaegeuk Kim unsigned int segno); 32494d57b86dSChao Yu void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); 325004f0b2eaSQiuyang Sun int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count); 325139a53e0cSJaegeuk Kim 325239a53e0cSJaegeuk Kim /* 325339a53e0cSJaegeuk Kim * recovery.c 325439a53e0cSJaegeuk Kim */ 32554d57b86dSChao Yu int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 32564d57b86dSChao Yu bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi); 325739a53e0cSJaegeuk Kim 325839a53e0cSJaegeuk Kim /* 325939a53e0cSJaegeuk Kim * debug.c 326039a53e0cSJaegeuk Kim */ 326139a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 326239a53e0cSJaegeuk Kim struct f2fs_stat_info { 326339a53e0cSJaegeuk Kim struct list_head stat_list; 326439a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 326539a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 326639a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 32675b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 32685b7ee374SChao Yu unsigned long long hit_total, total_ext; 3269c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 32702c8a4a28SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; 32712c8a4a28SJaegeuk Kim int ndirty_data, ndirty_qdata; 327235782b23SJaegeuk Kim int inmem_pages; 32732c8a4a28SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; 32745b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 32755b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 327639a53e0cSJaegeuk Kim int total_count, utilization; 32778b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 32785f9abab4SJaegeuk Kim int nr_rd_data, nr_rd_node, nr_rd_meta; 327902b16d0aSChao Yu int nr_dio_read, nr_dio_write; 3280274bd9baSChao Yu unsigned int io_skip_bggc, other_skip_bggc; 328114d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 328214d8d5f7SChao Yu int nr_discarding, nr_discarded; 32835f32366aSChao Yu int nr_discard_cmd; 3284d84d1cbdSChao Yu unsigned int undiscard_blks; 3285a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 3286648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 3287f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 328839a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 328939a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 329039a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 329139a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 329242190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 329339a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 3294e1235983SChangman Lee int bg_node_segs, bg_data_segs; 329539a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 3296e1235983SChangman Lee int bg_data_blks, bg_node_blks; 32972ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; 329839a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 329939a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 330039a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 330139a53e0cSJaegeuk Kim 3302b63e7be5SChao Yu unsigned int meta_count[META_MAX]; 330339a53e0cSJaegeuk Kim unsigned int segment_count[2]; 330439a53e0cSJaegeuk Kim unsigned int block_count[2]; 3305b9a2c252SChangman Lee unsigned int inplace_count; 33069edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 330739a53e0cSJaegeuk Kim }; 330839a53e0cSJaegeuk Kim 3309963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 3310963d4f7dSGu Zheng { 3311963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 3312963d4f7dSGu Zheng } 3313963d4f7dSGu Zheng 3314942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 331542190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 331639a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 3317dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 3318274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) ((sbi)->io_skip_bggc++) 3319274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) ((sbi)->other_skip_bggc++) 332033fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 332133fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 33225b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 33235b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 33245b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 33255b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 3326d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 3327d5e8f6c9SChao Yu do { \ 3328d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3329d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 3330d5e8f6c9SChao Yu } while (0) 3331d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 3332d5e8f6c9SChao Yu do { \ 3333d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3334d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 3335d5e8f6c9SChao Yu } while (0) 33360dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 33370dbdc2aeSJaegeuk Kim do { \ 33380dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 333903e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 33400dbdc2aeSJaegeuk Kim } while (0) 33410dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 33420dbdc2aeSJaegeuk Kim do { \ 33430dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 334403e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 33450dbdc2aeSJaegeuk Kim } while (0) 33463289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 33473289c061SJaegeuk Kim do { \ 33483289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 334903e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 33503289c061SJaegeuk Kim } while (0) 33513289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 33523289c061SJaegeuk Kim do { \ 33533289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 335403e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 33553289c061SJaegeuk Kim } while (0) 3356b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) \ 3357b63e7be5SChao Yu do { \ 3358b63e7be5SChao Yu if (blkaddr < SIT_I(sbi)->sit_base_addr) \ 3359b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_CP]); \ 3360b63e7be5SChao Yu else if (blkaddr < NM_I(sbi)->nat_blkaddr) \ 3361b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SIT]); \ 3362b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->ssa_blkaddr) \ 3363b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_NAT]); \ 3364b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->main_blkaddr) \ 3365b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SSA]); \ 3366b63e7be5SChao Yu } while (0) 3367dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 3368dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 3369dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 3370dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 3371b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 3372b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 337326a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 337426a28a0cSJaegeuk Kim do { \ 33750e6d0164SSahitya Tummala int cur = F2FS_I_SB(inode)->atomic_files; \ 337626a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 337726a28a0cSJaegeuk Kim if (cur > max) \ 337826a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 337926a28a0cSJaegeuk Kim } while (0) 3380648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 3381648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 3382648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 3383648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 3384648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 3385648d50baSChao Yu do { \ 3386648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 3387648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 3388648d50baSChao Yu if (cur > max) \ 3389648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 3390648d50baSChao Yu } while (0) 3391e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 339239a53e0cSJaegeuk Kim do { \ 3393963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 339468afcf2dSTomohiro Kusumi si->tot_segs++; \ 339568afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 339639a53e0cSJaegeuk Kim si->data_segs++; \ 3397e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 3398e1235983SChangman Lee } else { \ 339939a53e0cSJaegeuk Kim si->node_segs++; \ 3400e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 3401e1235983SChangman Lee } \ 340239a53e0cSJaegeuk Kim } while (0) 340339a53e0cSJaegeuk Kim 340439a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 340568afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 340639a53e0cSJaegeuk Kim 3407e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 340839a53e0cSJaegeuk Kim do { \ 3409963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 341039a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 341139a53e0cSJaegeuk Kim si->data_blks += (blks); \ 341268afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 341339a53e0cSJaegeuk Kim } while (0) 341439a53e0cSJaegeuk Kim 3415e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 341639a53e0cSJaegeuk Kim do { \ 3417963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 341839a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 341939a53e0cSJaegeuk Kim si->node_blks += (blks); \ 342068afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 342139a53e0cSJaegeuk Kim } while (0) 342239a53e0cSJaegeuk Kim 3423cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 3424cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 342521acc07dSGreg Kroah-Hartman void __init f2fs_create_root_stats(void); 34264589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 342739a53e0cSJaegeuk Kim #else 3428d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 3429d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 3430d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 3431d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 3432274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) do { } while (0) 3433274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) do { } while (0) 3434d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 3435d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 3436d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 3437d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 3438d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 3439d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 3440d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 3441d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 3442d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 3443d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 3444d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 3445d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 3446d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 3447d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 3448d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 3449d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 3450d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 3451d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 3452b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) do { } while (0) 3453d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 3454d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 3455d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 3456d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 3457d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 3458d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 3459d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 346039a53e0cSJaegeuk Kim 346139a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 346239a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 346321acc07dSGreg Kroah-Hartman static inline void __init f2fs_create_root_stats(void) { } 34644589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 346539a53e0cSJaegeuk Kim #endif 346639a53e0cSJaegeuk Kim 346739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 34682c2eb7a3SDaniel Rosenberg #ifdef CONFIG_UNICODE 34692c2eb7a3SDaniel Rosenberg extern const struct dentry_operations f2fs_dentry_ops; 34702c2eb7a3SDaniel Rosenberg #endif 347139a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 347239a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 347339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 347439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 347539a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 347639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 347739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 3478cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 347939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 34804d57b86dSChao Yu extern struct kmem_cache *f2fs_inode_entry_slab; 34811001b347SHuajun Li 3482e18c65b2SHuajun Li /* 3483e18c65b2SHuajun Li * inline.c 3484e18c65b2SHuajun Li */ 3485cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 3486cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 34874d57b86dSChao Yu void f2fs_do_read_inline_data(struct page *page, struct page *ipage); 34884d57b86dSChao Yu void f2fs_truncate_inline_inode(struct inode *inode, 34894d57b86dSChao Yu struct page *ipage, u64 from); 3490cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 3491cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 3492cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 3493cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 34944d57b86dSChao Yu bool f2fs_recover_inline_data(struct inode *inode, struct page *npage); 34954d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, 3496cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 34974d57b86dSChao Yu int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 3498cac5a3d8SDongOh Shin struct page *ipage); 3499cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 3500cac5a3d8SDongOh Shin const struct qstr *orig_name, 3501cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 35024d57b86dSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, 35034d57b86dSChao Yu struct page *page, struct inode *dir, 35044d57b86dSChao Yu struct inode *inode); 3505cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 3506cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 3507cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 3508cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 3509cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 3510cac5a3d8SDongOh Shin __u64 start, __u64 len); 3511cde4de12SJaegeuk Kim 3512cde4de12SJaegeuk Kim /* 35132658e50dSJaegeuk Kim * shrinker.c 35142658e50dSJaegeuk Kim */ 3515cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 3516cac5a3d8SDongOh Shin struct shrink_control *sc); 3517cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 3518cac5a3d8SDongOh Shin struct shrink_control *sc); 3519cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 3520cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 35212658e50dSJaegeuk Kim 35222658e50dSJaegeuk Kim /* 3523a28ef1f5SChao Yu * extent_cache.c 3524a28ef1f5SChao Yu */ 35254dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree(struct rb_root_cached *root, 3526004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 35274d57b86dSChao Yu struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 35284dada3fdSChao Yu struct rb_root_cached *root, 35294dada3fdSChao Yu struct rb_node **parent, 35304dada3fdSChao Yu unsigned int ofs, bool *leftmost); 35314dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root, 3532004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 3533004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 3534004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 35354dada3fdSChao Yu bool force, bool *leftmost); 35364d57b86dSChao Yu bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi, 35374dada3fdSChao Yu struct rb_root_cached *root); 3538cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 3539cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 3540cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 3541cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 3542cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 3543cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 3544cac5a3d8SDongOh Shin struct extent_info *ei); 3545cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 354619b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 3547cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 35484d57b86dSChao Yu void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi); 35494d57b86dSChao Yu int __init f2fs_create_extent_cache(void); 35504d57b86dSChao Yu void f2fs_destroy_extent_cache(void); 3551a28ef1f5SChao Yu 3552a28ef1f5SChao Yu /* 35538ceffcb2SChao Yu * sysfs.c 35548ceffcb2SChao Yu */ 3555dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 3556dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 3557dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 3558dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 35598ceffcb2SChao Yu 356095ae251fSEric Biggers /* verity.c */ 356195ae251fSEric Biggers extern const struct fsverity_operations f2fs_verityops; 356295ae251fSEric Biggers 35638ceffcb2SChao Yu /* 3564cde4de12SJaegeuk Kim * crypto support 3565cde4de12SJaegeuk Kim */ 35661958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 35671958593eSJaegeuk Kim { 356862230e0dSChandan Rajendra return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); 35691958593eSJaegeuk Kim } 35701958593eSJaegeuk Kim 3571cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 3572cde4de12SJaegeuk Kim { 3573643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 3574cde4de12SJaegeuk Kim file_set_encrypt(inode); 35759149a5ebSChao Yu f2fs_set_inode_flags(inode); 3576cde4de12SJaegeuk Kim #endif 3577cde4de12SJaegeuk Kim } 3578cde4de12SJaegeuk Kim 35796dbb1796SEric Biggers /* 35806dbb1796SEric Biggers * Returns true if the reads of the inode's data need to undergo some 35816dbb1796SEric Biggers * postprocessing step, like decryption or authenticity verification. 35826dbb1796SEric Biggers */ 35836dbb1796SEric Biggers static inline bool f2fs_post_read_required(struct inode *inode) 3584cde4de12SJaegeuk Kim { 358595ae251fSEric Biggers return f2fs_encrypted_file(inode) || fsverity_active(inode); 3586cde4de12SJaegeuk Kim } 3587cde4de12SJaegeuk Kim 3588ccd31cb2SSheng Yong #define F2FS_FEATURE_FUNCS(name, flagname) \ 35897beb01f7SChao Yu static inline int f2fs_sb_has_##name(struct f2fs_sb_info *sbi) \ 3590ccd31cb2SSheng Yong { \ 35917beb01f7SChao Yu return F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_##flagname); \ 3592cde4de12SJaegeuk Kim } 3593f424f664SJaegeuk Kim 3594ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(encrypt, ENCRYPT); 3595ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(blkzoned, BLKZONED); 3596ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR); 3597ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA); 3598ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM); 3599ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); 3600ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); 3601ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); 3602b7c409deSSheng Yong F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); 360395ae251fSEric Biggers F2FS_FEATURE_FUNCS(verity, VERITY); 3604d440c52dSJunling Zheng F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); 36055aba5430SDaniel Rosenberg F2FS_FEATURE_FUNCS(casefold, CASEFOLD); 36061c1d35dfSChao Yu 3607178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 360895175dafSDamien Le Moal static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, 360995175dafSDamien Le Moal block_t blkaddr) 3610178053e2SDamien Le Moal { 3611178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 3612178053e2SDamien Le Moal 361395175dafSDamien Le Moal return test_bit(zno, FDEV(devi).blkz_seq); 3614178053e2SDamien Le Moal } 3615178053e2SDamien Le Moal #endif 3616178053e2SDamien Le Moal 36177d20c8abSChao Yu static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi) 361896ba2decSDamien Le Moal { 36197beb01f7SChao Yu return f2fs_sb_has_blkzoned(sbi); 36207d20c8abSChao Yu } 362196ba2decSDamien Le Moal 36227f3d7719SDamien Le Moal static inline bool f2fs_bdev_support_discard(struct block_device *bdev) 36237f3d7719SDamien Le Moal { 36247f3d7719SDamien Le Moal return blk_queue_discard(bdev_get_queue(bdev)) || 36257f3d7719SDamien Le Moal bdev_is_zoned(bdev); 36267f3d7719SDamien Le Moal } 36277f3d7719SDamien Le Moal 36287d20c8abSChao Yu static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi) 36297d20c8abSChao Yu { 36307f3d7719SDamien Le Moal int i; 36317f3d7719SDamien Le Moal 36327f3d7719SDamien Le Moal if (!f2fs_is_multi_device(sbi)) 36337f3d7719SDamien Le Moal return f2fs_bdev_support_discard(sbi->sb->s_bdev); 36347f3d7719SDamien Le Moal 36357f3d7719SDamien Le Moal for (i = 0; i < sbi->s_ndevs; i++) 36367f3d7719SDamien Le Moal if (f2fs_bdev_support_discard(FDEV(i).bdev)) 36377f3d7719SDamien Le Moal return true; 36387f3d7719SDamien Le Moal return false; 36397d20c8abSChao Yu } 36407d20c8abSChao Yu 36417d20c8abSChao Yu static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) 36427d20c8abSChao Yu { 36437d20c8abSChao Yu return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) || 36447d20c8abSChao Yu f2fs_hw_should_discard(sbi); 364552763a4bSJaegeuk Kim } 364652763a4bSJaegeuk Kim 3647f824deb5SChao Yu static inline bool f2fs_hw_is_readonly(struct f2fs_sb_info *sbi) 3648f824deb5SChao Yu { 3649f824deb5SChao Yu int i; 3650f824deb5SChao Yu 3651f824deb5SChao Yu if (!f2fs_is_multi_device(sbi)) 3652f824deb5SChao Yu return bdev_read_only(sbi->sb->s_bdev); 3653f824deb5SChao Yu 3654f824deb5SChao Yu for (i = 0; i < sbi->s_ndevs; i++) 3655f824deb5SChao Yu if (bdev_read_only(FDEV(i).bdev)) 3656f824deb5SChao Yu return true; 3657f824deb5SChao Yu return false; 3658f824deb5SChao Yu } 3659f824deb5SChao Yu 3660f824deb5SChao Yu 366152763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 366252763a4bSJaegeuk Kim { 366352763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 366452763a4bSJaegeuk Kim clear_opt(sbi, LFS); 366552763a4bSJaegeuk Kim 366652763a4bSJaegeuk Kim switch (mt) { 366752763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 366852763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 366952763a4bSJaegeuk Kim break; 367052763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 367152763a4bSJaegeuk Kim set_opt(sbi, LFS); 367252763a4bSJaegeuk Kim break; 367352763a4bSJaegeuk Kim } 367452763a4bSJaegeuk Kim } 367552763a4bSJaegeuk Kim 3676fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 3677fcc85a4dSJaegeuk Kim { 3678643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 3679886f56f9SAl Viro umode_t mode = inode->i_mode; 3680fcc85a4dSJaegeuk Kim 3681fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 3682fcc85a4dSJaegeuk Kim #else 36836e45f2a5SGustavo A. R. Silva return false; 3684fcc85a4dSJaegeuk Kim #endif 3685fcc85a4dSJaegeuk Kim } 3686fcc85a4dSJaegeuk Kim 3687f847c699SChao Yu static inline int block_unaligned_IO(struct inode *inode, 3688f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 3689b91050a8SHyunchul Lee { 3690f847c699SChao Yu unsigned int i_blkbits = READ_ONCE(inode->i_blkbits); 3691f847c699SChao Yu unsigned int blocksize_mask = (1 << i_blkbits) - 1; 3692f847c699SChao Yu loff_t offset = iocb->ki_pos; 3693f847c699SChao Yu unsigned long align = offset | iov_iter_alignment(iter); 3694f847c699SChao Yu 3695f847c699SChao Yu return align & blocksize_mask; 3696f847c699SChao Yu } 3697f847c699SChao Yu 3698f847c699SChao Yu static inline int allow_outplace_dio(struct inode *inode, 3699f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 3700f847c699SChao Yu { 3701f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3702f847c699SChao Yu int rw = iov_iter_rw(iter); 3703f847c699SChao Yu 3704f847c699SChao Yu return (test_opt(sbi, LFS) && (rw == WRITE) && 3705f847c699SChao Yu !block_unaligned_IO(inode, iocb, iter)); 3706f847c699SChao Yu } 3707f847c699SChao Yu 3708f847c699SChao Yu static inline bool f2fs_force_buffered_io(struct inode *inode, 3709f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 3710f847c699SChao Yu { 3711f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3712f847c699SChao Yu int rw = iov_iter_rw(iter); 3713f847c699SChao Yu 3714f847c699SChao Yu if (f2fs_post_read_required(inode)) 3715f847c699SChao Yu return true; 37160916878dSDamien Le Moal if (f2fs_is_multi_device(sbi)) 3717f847c699SChao Yu return true; 3718f847c699SChao Yu /* 3719f847c699SChao Yu * for blkzoned device, fallback direct IO to buffered IO, so 3720f847c699SChao Yu * all IOs can be serialized by log-structured write. 3721f847c699SChao Yu */ 37227beb01f7SChao Yu if (f2fs_sb_has_blkzoned(sbi)) 3723f847c699SChao Yu return true; 37249720ee80SChao Yu if (test_opt(sbi, LFS) && (rw == WRITE)) { 37259720ee80SChao Yu if (block_unaligned_IO(inode, iocb, iter)) 3726f847c699SChao Yu return true; 37279720ee80SChao Yu if (F2FS_IO_ALIGNED(sbi)) 37289720ee80SChao Yu return true; 37299720ee80SChao Yu } 37304969c06aSJaegeuk Kim if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED) && 37313ee0c5d3SChao Yu !IS_SWAPFILE(inode)) 37324354994fSDaniel Rosenberg return true; 37334354994fSDaniel Rosenberg 3734f847c699SChao Yu return false; 3735b91050a8SHyunchul Lee } 3736b91050a8SHyunchul Lee 373783a3bfdbSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 3738d494500aSChao Yu extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, 3739d494500aSChao Yu unsigned int type); 374083a3bfdbSJaegeuk Kim #else 3741d494500aSChao Yu #define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) 374283a3bfdbSJaegeuk Kim #endif 374383a3bfdbSJaegeuk Kim 3744af033b2aSChao Yu static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) 3745af033b2aSChao Yu { 3746af033b2aSChao Yu #ifdef CONFIG_QUOTA 37477beb01f7SChao Yu if (f2fs_sb_has_quota_ino(sbi)) 3748af033b2aSChao Yu return true; 3749af033b2aSChao Yu if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || 3750af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || 3751af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) 3752af033b2aSChao Yu return true; 3753af033b2aSChao Yu #endif 3754af033b2aSChao Yu return false; 3755af033b2aSChao Yu } 37560af725fcSJaegeuk Kim 375710f966bbSChao Yu #define EFSBADCRC EBADMSG /* Bad CRC detected */ 375810f966bbSChao Yu #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 375910f966bbSChao Yu 3760e1074d4bSChao Yu #endif /* _LINUX_F2FS_H */ 3761