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> 28734f0d24SDave Chinner 295d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 309850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 315d56b671SJaegeuk Kim #else 329850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 339850cf4aSJaegeuk Kim do { \ 349850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 359850cf4aSJaegeuk Kim WARN_ON(1); \ 36caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 379850cf4aSJaegeuk Kim } \ 389850cf4aSJaegeuk Kim } while (0) 395d56b671SJaegeuk Kim #endif 405d56b671SJaegeuk Kim 412c63feadSJaegeuk Kim enum { 422c63feadSJaegeuk Kim FAULT_KMALLOC, 43628b3d14SChao Yu FAULT_KVMALLOC, 44c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 4501eccef7SChao Yu FAULT_PAGE_GET, 46d62fe971SChao Yu FAULT_ALLOC_BIO, 47cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 48cb78942bSJaegeuk Kim FAULT_ORPHAN, 49cb78942bSJaegeuk Kim FAULT_BLOCK, 50cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5153aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 5214b44d23SJaegeuk Kim FAULT_TRUNCATE, 536f5c2ed0SChao Yu FAULT_READ_IO, 540f348028SChao Yu FAULT_CHECKPOINT, 55b83dcfe6SChao Yu FAULT_DISCARD, 566f5c2ed0SChao Yu FAULT_WRITE_IO, 572c63feadSJaegeuk Kim FAULT_MAX, 582c63feadSJaegeuk Kim }; 592c63feadSJaegeuk Kim 607fa750a1SArnd Bergmann #ifdef CONFIG_F2FS_FAULT_INJECTION 61d494500aSChao Yu #define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1) 62d494500aSChao Yu 6308796897SSheng Yong struct f2fs_fault_info { 6408796897SSheng Yong atomic_t inject_ops; 6508796897SSheng Yong unsigned int inject_rate; 6608796897SSheng Yong unsigned int inject_type; 6708796897SSheng Yong }; 6808796897SSheng Yong 6919880e6eSAlexey Dobriyan extern const char *f2fs_fault_name[FAULT_MAX]; 7068afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 712c63feadSJaegeuk Kim #endif 722c63feadSJaegeuk Kim 7339a53e0cSJaegeuk Kim /* 7439a53e0cSJaegeuk Kim * For mount options 7539a53e0cSJaegeuk Kim */ 7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 8039a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 8139a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 8239a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 83444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 841001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8534d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8634d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8734d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 88d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8989672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 906aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 91343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 9273faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 9336abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 9436abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 950abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA 0x00080000 960abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA 0x00100000 975c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA 0x00200000 984b2414d0SChao Yu #define F2FS_MOUNT_QUOTA 0x00400000 996afc662eSChao Yu #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 1007e65be49SJaegeuk Kim #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 1014354994fSDaniel Rosenberg #define F2FS_MOUNT_DISABLE_CHECKPOINT 0x02000000 10239a53e0cSJaegeuk Kim 10363189b78SChao Yu #define F2FS_OPTION(sbi) ((sbi)->mount_opt) 10463189b78SChao Yu #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) 10563189b78SChao Yu #define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option) 10663189b78SChao Yu #define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option) 10739a53e0cSJaegeuk Kim 10839a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 10939a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 11039a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 11139a53e0cSJaegeuk Kim 112a9841c4dSJaegeuk Kim typedef u32 block_t; /* 113a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 114a9841c4dSJaegeuk Kim * address format, __le32. 115a9841c4dSJaegeuk Kim */ 11639a53e0cSJaegeuk Kim typedef u32 nid_t; 11739a53e0cSJaegeuk Kim 11839a53e0cSJaegeuk Kim struct f2fs_mount_info { 11939a53e0cSJaegeuk Kim unsigned int opt; 12063189b78SChao Yu int write_io_size_bits; /* Write IO size bits */ 12163189b78SChao Yu block_t root_reserved_blocks; /* root reserved blocks */ 12263189b78SChao Yu kuid_t s_resuid; /* reserved blocks for uid */ 12363189b78SChao Yu kgid_t s_resgid; /* reserved blocks for gid */ 12463189b78SChao Yu int active_logs; /* # of active logs */ 12563189b78SChao Yu int inline_xattr_size; /* inline xattr size */ 12663189b78SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 12763189b78SChao Yu struct f2fs_fault_info fault_info; /* For fault injection */ 12863189b78SChao Yu #endif 12963189b78SChao Yu #ifdef CONFIG_QUOTA 13063189b78SChao Yu /* Names of quota files with journalled quota */ 13163189b78SChao Yu char *s_qf_names[MAXQUOTAS]; 13263189b78SChao Yu int s_jquota_fmt; /* Format of quota to use */ 13363189b78SChao Yu #endif 13463189b78SChao Yu /* For which write hints are passed down to block layer */ 13563189b78SChao Yu int whint_mode; 13663189b78SChao Yu int alloc_mode; /* segment allocation policy */ 13763189b78SChao Yu int fsync_mode; /* fsync policy */ 138ff62af20SSheng Yong bool test_dummy_encryption; /* test dummy encryption */ 1394d3aed70SDaniel Rosenberg block_t unusable_cap; /* Amount of space allowed to be 1404d3aed70SDaniel Rosenberg * unusable when disabling checkpoint 1414d3aed70SDaniel Rosenberg */ 14239a53e0cSJaegeuk Kim }; 14339a53e0cSJaegeuk Kim 144cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1450bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 146e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1477a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1485c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 149704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 1506afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 151234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO 0x0080 1521c1d35dfSChao Yu #define F2FS_FEATURE_INODE_CRTIME 0x0100 153b7c409deSSheng Yong #define F2FS_FEATURE_LOST_FOUND 0x0200 15453fedcc0SEric Biggers #define F2FS_FEATURE_VERITY 0x0400 /* reserved */ 155d440c52dSJunling Zheng #define F2FS_FEATURE_SB_CHKSUM 0x0800 1565aba5430SDaniel Rosenberg #define F2FS_FEATURE_CASEFOLD 0x1000 157cde4de12SJaegeuk Kim 1587beb01f7SChao Yu #define __F2FS_HAS_FEATURE(raw_super, mask) \ 1597beb01f7SChao Yu ((raw_super->feature & cpu_to_le32(mask)) != 0) 1607beb01f7SChao Yu #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask) 1617beb01f7SChao Yu #define F2FS_SET_FEATURE(sbi, mask) \ 1627beb01f7SChao Yu (sbi->raw_super->feature |= cpu_to_le32(mask)) 1637beb01f7SChao Yu #define F2FS_CLEAR_FEATURE(sbi, mask) \ 1647beb01f7SChao Yu (sbi->raw_super->feature &= ~cpu_to_le32(mask)) 16576f105a2SJaegeuk Kim 16639a53e0cSJaegeuk Kim /* 1677c2e5963SJaegeuk Kim * Default values for user and/or group using reserved blocks 1687c2e5963SJaegeuk Kim */ 1697c2e5963SJaegeuk Kim #define F2FS_DEF_RESUID 0 1707c2e5963SJaegeuk Kim #define F2FS_DEF_RESGID 0 1717c2e5963SJaegeuk Kim 1727c2e5963SJaegeuk Kim /* 17339a53e0cSJaegeuk Kim * For checkpoint manager 17439a53e0cSJaegeuk Kim */ 17539a53e0cSJaegeuk Kim enum { 17639a53e0cSJaegeuk Kim NAT_BITMAP, 17739a53e0cSJaegeuk Kim SIT_BITMAP 17839a53e0cSJaegeuk Kim }; 17939a53e0cSJaegeuk Kim 180c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 181c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 182c473f1a9SChao Yu #define CP_SYNC 0x00000004 183c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 184c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1851f43e2adSChao Yu #define CP_TRIMMED 0x00000020 1864354994fSDaniel Rosenberg #define CP_PAUSE 0x00000040 18775ab4cb8SJaegeuk Kim 1884ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 189ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 190969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 191f9d1dcedSYunlei He #define DEF_MID_DISCARD_ISSUE_TIME 500 /* 500 ms, if device busy */ 192969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 1938bb4f253SJaegeuk Kim #define DEF_DISCARD_URGENT_UTIL 80 /* do more discard over 80% */ 19460b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 195dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 1964354994fSDaniel Rosenberg #define DEF_DISABLE_INTERVAL 5 /* 5 secs */ 197db610a64SJaegeuk Kim #define DEF_DISABLE_QUICK_INTERVAL 1 /* 1 secs */ 19803f2c02dSJaegeuk Kim #define DEF_UMOUNT_DISCARD_TIMEOUT 5 /* 5 secs */ 199bba681cbSJaegeuk Kim 20075ab4cb8SJaegeuk Kim struct cp_control { 20175ab4cb8SJaegeuk Kim int reason; 2024b2fecc8SJaegeuk Kim __u64 trim_start; 2034b2fecc8SJaegeuk Kim __u64 trim_end; 2044b2fecc8SJaegeuk Kim __u64 trim_minlen; 20575ab4cb8SJaegeuk Kim }; 20675ab4cb8SJaegeuk Kim 207662befdaSChao Yu /* 208e1da7872SChao Yu * indicate meta/data type 209662befdaSChao Yu */ 210662befdaSChao Yu enum { 211662befdaSChao Yu META_CP, 212662befdaSChao Yu META_NAT, 21381c1a0f1SChao Yu META_SIT, 2144c521f49SJaegeuk Kim META_SSA, 215b63e7be5SChao Yu META_MAX, 2164c521f49SJaegeuk Kim META_POR, 21793770ab7SChao Yu DATA_GENERIC, /* check range only */ 21893770ab7SChao Yu DATA_GENERIC_ENHANCE, /* strong check on range and segment bitmap */ 21993770ab7SChao Yu DATA_GENERIC_ENHANCE_READ, /* 22093770ab7SChao Yu * strong check on range and segment 22193770ab7SChao Yu * bitmap but no warning due to race 22293770ab7SChao Yu * condition of read on truncated area 22393770ab7SChao Yu * by extent_cache 22493770ab7SChao Yu */ 225e1da7872SChao Yu META_GENERIC, 226662befdaSChao Yu }; 227662befdaSChao Yu 2286451e041SJaegeuk Kim /* for the list of ino */ 2296451e041SJaegeuk Kim enum { 2306451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 231fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 232fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 2330a007b97SJaegeuk Kim TRANS_DIR_INO, /* for trasactions dir ino list */ 23439d787beSChao Yu FLUSH_INO, /* for multiple device flushing */ 2356451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 2366451e041SJaegeuk Kim }; 2376451e041SJaegeuk Kim 2386451e041SJaegeuk Kim struct ino_entry { 23939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 24039a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 24139d787beSChao Yu unsigned int dirty_device; /* dirty device bitmap */ 24239a53e0cSJaegeuk Kim }; 24339a53e0cSJaegeuk Kim 2442710fd7eSChao Yu /* for the list of inodes to be GCed */ 24506292073SChao Yu struct inode_entry { 24639a53e0cSJaegeuk Kim struct list_head list; /* list head */ 24739a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 24839a53e0cSJaegeuk Kim }; 24939a53e0cSJaegeuk Kim 25050fa53ecSChao Yu struct fsync_node_entry { 25150fa53ecSChao Yu struct list_head list; /* list head */ 25250fa53ecSChao Yu struct page *page; /* warm node page pointer */ 25350fa53ecSChao Yu unsigned int seq_id; /* sequence id */ 25450fa53ecSChao Yu }; 25550fa53ecSChao Yu 256a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 2577fd9e544SJaegeuk Kim struct discard_entry { 2587fd9e544SJaegeuk Kim struct list_head list; /* list head */ 259a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 260a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 2617fd9e544SJaegeuk Kim }; 2627fd9e544SJaegeuk Kim 263969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 264969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 265969d1b18SChao Yu 266ba48a33eSChao Yu /* max discard pend list number */ 267ba48a33eSChao Yu #define MAX_PLIST_NUM 512 268ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 2692f84babfSSheng Yong (MAX_PLIST_NUM - 1) : ((blk_num) - 1)) 270ba48a33eSChao Yu 27115469963SJaegeuk Kim enum { 27235ec7d57SChao Yu D_PREP, /* initial */ 27335ec7d57SChao Yu D_PARTIAL, /* partially submitted */ 27435ec7d57SChao Yu D_SUBMIT, /* all submitted */ 27535ec7d57SChao Yu D_DONE, /* finished */ 27615469963SJaegeuk Kim }; 27715469963SJaegeuk Kim 278004b6862SChao Yu struct discard_info { 279b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 280b01a9201SJaegeuk Kim block_t len; /* length */ 281004b6862SChao Yu block_t start; /* actual start address in dev */ 282004b6862SChao Yu }; 283004b6862SChao Yu 284b01a9201SJaegeuk Kim struct discard_cmd { 285004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 286004b6862SChao Yu union { 287004b6862SChao Yu struct { 288004b6862SChao Yu block_t lstart; /* logical start address */ 289004b6862SChao Yu block_t len; /* length */ 290004b6862SChao Yu block_t start; /* actual start address in dev */ 291004b6862SChao Yu }; 292004b6862SChao Yu struct discard_info di; /* discard info */ 293004b6862SChao Yu 294004b6862SChao Yu }; 295b01a9201SJaegeuk Kim struct list_head list; /* command list */ 296b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 297c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 298ec9895adSChao Yu unsigned short ref; /* reference count */ 2999a744b92SChao Yu unsigned char state; /* state */ 30072691af6SJaegeuk Kim unsigned char queued; /* queued discard */ 301c81abe34SJaegeuk Kim int error; /* bio error */ 30235ec7d57SChao Yu spinlock_t lock; /* for state/bio_ref updating */ 30335ec7d57SChao Yu unsigned short bio_ref; /* bio reference count */ 304275b66b0SChao Yu }; 305275b66b0SChao Yu 30678997b56SChao Yu enum { 30778997b56SChao Yu DPOLICY_BG, 30878997b56SChao Yu DPOLICY_FORCE, 30978997b56SChao Yu DPOLICY_FSTRIM, 31078997b56SChao Yu DPOLICY_UMOUNT, 31178997b56SChao Yu MAX_DPOLICY, 31278997b56SChao Yu }; 31378997b56SChao Yu 314ecc9aa00SChao Yu struct discard_policy { 31578997b56SChao Yu int type; /* type of discard */ 316ecc9aa00SChao Yu unsigned int min_interval; /* used for candidates exist */ 317f9d1dcedSYunlei He unsigned int mid_interval; /* used for device busy */ 318ecc9aa00SChao Yu unsigned int max_interval; /* used for candidates not exist */ 319ecc9aa00SChao Yu unsigned int max_requests; /* # of discards issued per round */ 320ecc9aa00SChao Yu unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ 321ecc9aa00SChao Yu bool io_aware; /* issue discard in idle time */ 322ecc9aa00SChao Yu bool sync; /* submit discard with REQ_SYNC flag */ 32320ee4382SChao Yu bool ordered; /* issue discard by lba order */ 32478997b56SChao Yu unsigned int granularity; /* discard granularity */ 32503f2c02dSJaegeuk Kim int timeout; /* discard timeout for put_super */ 326ecc9aa00SChao Yu }; 327ecc9aa00SChao Yu 3280b54fb84SJaegeuk Kim struct discard_cmd_control { 32915469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 33046f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 331ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 33246f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 3338412663dSChao Yu struct list_head fstrim_list; /* in-flight discard from fstrim */ 33415469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 335969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 33615469963SJaegeuk Kim struct mutex cmd_lock; 337d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 338d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 339969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 340d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 34120ee4382SChao Yu unsigned int next_pos; /* next discard position */ 3428b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 34372691af6SJaegeuk Kim atomic_t queued_discard; /* # of queued discard */ 3445f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 3454dada3fdSChao Yu struct rb_root_cached root; /* root of discard rb-tree */ 34667fce70bSChao Yu bool rbtree_check; /* config for consistence check */ 34739a53e0cSJaegeuk Kim }; 34839a53e0cSJaegeuk Kim 34939a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 35039a53e0cSJaegeuk Kim struct fsync_inode_entry { 35139a53e0cSJaegeuk Kim struct list_head list; /* list head */ 35239a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 353c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 354c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 35539a53e0cSJaegeuk Kim }; 35639a53e0cSJaegeuk Kim 35768afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 35868afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 35939a53e0cSJaegeuk Kim 36068afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 36168afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 36268afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 36368afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 36439a53e0cSJaegeuk Kim 365dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 366dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 367309cc2b6SJaegeuk Kim 368dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 36939a53e0cSJaegeuk Kim { 370dfc08a12SChao Yu int before = nats_in_cursum(journal); 371cac5a3d8SDongOh Shin 372dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 37339a53e0cSJaegeuk Kim return before; 37439a53e0cSJaegeuk Kim } 37539a53e0cSJaegeuk Kim 376dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 37739a53e0cSJaegeuk Kim { 378dfc08a12SChao Yu int before = sits_in_cursum(journal); 379cac5a3d8SDongOh Shin 380dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 38139a53e0cSJaegeuk Kim return before; 38239a53e0cSJaegeuk Kim } 38339a53e0cSJaegeuk Kim 384dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 385dfc08a12SChao Yu int size, int type) 386184a5cd2SChao Yu { 387184a5cd2SChao Yu if (type == NAT_JOURNAL) 388dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 389dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 390184a5cd2SChao Yu } 391184a5cd2SChao Yu 39239a53e0cSJaegeuk Kim /* 393e9750824SNamjae Jeon * ioctl commands 394e9750824SNamjae Jeon */ 395e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 396e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 397d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 398e9750824SNamjae Jeon 39988b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 40088b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 40188b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 40202a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 4031e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 4041e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 405d07efb50SJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32) 406456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 407d07efb50SJaegeuk Kim #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \ 408d07efb50SJaegeuk Kim struct f2fs_defragment) 4094dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 4104dd6f977SJaegeuk Kim struct f2fs_move_range) 411e066b83cSJaegeuk Kim #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ 412e066b83cSJaegeuk Kim struct f2fs_flush_device) 41334dc77adSJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ 41434dc77adSJaegeuk Kim struct f2fs_gc_range) 415e65ef207SJaegeuk Kim #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) 4161ad71a27SJaegeuk Kim #define F2FS_IOC_SET_PIN_FILE _IOW(F2FS_IOCTL_MAGIC, 13, __u32) 4171ad71a27SJaegeuk Kim #define F2FS_IOC_GET_PIN_FILE _IOR(F2FS_IOCTL_MAGIC, 14, __u32) 418c4020b2dSChao Yu #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) 41904f0b2eaSQiuyang Sun #define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64) 42088b88a66SJaegeuk Kim 4214507847cSChao Yu #define F2FS_IOC_GET_VOLUME_NAME FS_IOC_GETFSLABEL 4224507847cSChao Yu #define F2FS_IOC_SET_VOLUME_NAME FS_IOC_SETFSLABEL 4234507847cSChao Yu 4240b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 4250b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 4260b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 427f424f664SJaegeuk Kim 4281abff93dSJaegeuk Kim /* 4291abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 4301abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 4311abff93dSJaegeuk Kim */ 4321abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 4331abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 4341abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 4351abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 436c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 4370cd6d9b0SJaegeuk Kim #define F2FS_GOING_DOWN_NEED_FSCK 0x4 /* going down to trigger fsck */ 4381abff93dSJaegeuk Kim 439e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 440e9750824SNamjae Jeon /* 441e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 442e9750824SNamjae Jeon */ 443e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 444e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 44504ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 446e9750824SNamjae Jeon #endif 447e9750824SNamjae Jeon 4482c1d0305SChao Yu #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR 4492c1d0305SChao Yu #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR 4502c1d0305SChao Yu 45134dc77adSJaegeuk Kim struct f2fs_gc_range { 45234dc77adSJaegeuk Kim u32 sync; 45334dc77adSJaegeuk Kim u64 start; 45434dc77adSJaegeuk Kim u64 len; 45534dc77adSJaegeuk Kim }; 45634dc77adSJaegeuk Kim 457d323d005SChao Yu struct f2fs_defragment { 458d323d005SChao Yu u64 start; 459d323d005SChao Yu u64 len; 460d323d005SChao Yu }; 461d323d005SChao Yu 4624dd6f977SJaegeuk Kim struct f2fs_move_range { 4634dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 4644dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 4654dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 4664dd6f977SJaegeuk Kim u64 len; /* size to move */ 4674dd6f977SJaegeuk Kim }; 4684dd6f977SJaegeuk Kim 469e066b83cSJaegeuk Kim struct f2fs_flush_device { 470e066b83cSJaegeuk Kim u32 dev_num; /* device number to flush */ 471e066b83cSJaegeuk Kim u32 segments; /* # of segments to flush */ 472e066b83cSJaegeuk Kim }; 473e066b83cSJaegeuk Kim 474f2470371SChao Yu /* for inline stuff */ 475f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 4767a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 4776afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode); 4787a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 4797a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 480b323fd28SChao Yu get_inline_xattr_addrs(inode) - \ 4816afc662eSChao Yu DEF_INLINE_RESERVED_SIZE)) 482f2470371SChao Yu 483f2470371SChao Yu /* for inline dir */ 484f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 485f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 486f2470371SChao Yu BITS_PER_BYTE + 1)) 487f91108b8SGeert Uytterhoeven #define INLINE_DENTRY_BITMAP_SIZE(inode) \ 488f91108b8SGeert Uytterhoeven DIV_ROUND_UP(NR_INLINE_DENTRY(inode), BITS_PER_BYTE) 489f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 490f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 491f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 492f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 493f2470371SChao Yu 494e9750824SNamjae Jeon /* 49539a53e0cSJaegeuk Kim * For INODE and NODE manager 49639a53e0cSJaegeuk Kim */ 4977b3cd7d6SJaegeuk Kim /* for directory operations */ 4987b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 499d8c6822aSJaegeuk Kim struct inode *inode; 50076a9dd85SChao Yu void *bitmap; 5017b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 5027b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 5037b3cd7d6SJaegeuk Kim int max; 50476a9dd85SChao Yu int nr_bitmap; 5057b3cd7d6SJaegeuk Kim }; 5067b3cd7d6SJaegeuk Kim 50764c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 50864c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 5097b3cd7d6SJaegeuk Kim { 510d8c6822aSJaegeuk Kim d->inode = inode; 5117b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 51276a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 513c79d1520SYunlong Song d->bitmap = t->dentry_bitmap; 5147b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 5157b3cd7d6SJaegeuk Kim d->filename = t->filename; 51664c24ecbSTomohiro Kusumi } 517cac5a3d8SDongOh Shin 51864c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 519f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 52064c24ecbSTomohiro Kusumi { 521f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 522f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 523f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 524f2470371SChao Yu 52564c24ecbSTomohiro Kusumi d->inode = inode; 526f2470371SChao Yu d->max = entry_cnt; 527f2470371SChao Yu d->nr_bitmap = bitmap_size; 528f2470371SChao Yu d->bitmap = t; 529f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 530f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 531f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 5327b3cd7d6SJaegeuk Kim } 5337b3cd7d6SJaegeuk Kim 534dbe6a5ffSJaegeuk Kim /* 535dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 536dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 537dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 53839a53e0cSJaegeuk Kim */ 539dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 540dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 541266e97a8SJaegeuk Kim enum { 542266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 543266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 544266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 545266e97a8SJaegeuk Kim * look up a node with readahead called 5464f4124d0SChao Yu * by get_data_block. 54739a53e0cSJaegeuk Kim */ 548266e97a8SJaegeuk Kim }; 549266e97a8SJaegeuk Kim 5507735730dSChao Yu #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO count */ 5517735730dSChao Yu 552af033b2aSChao Yu /* maximum retry quota flush count */ 553af033b2aSChao Yu #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT 8 554af033b2aSChao Yu 555a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 55639a53e0cSJaegeuk Kim 557817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 558817202d9SChao Yu 55939a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 56013054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 56113054c54SChao Yu 56213054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 56313054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 564c11abd1aSJaegeuk Kim 56554c2258cSChao Yu struct rb_entry { 56654c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 56754c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 56854c2258cSChao Yu unsigned int len; /* length of the entry */ 56954c2258cSChao Yu }; 57054c2258cSChao Yu 57139a53e0cSJaegeuk Kim struct extent_info { 57239a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 573111d2495SMasanari Iida unsigned int len; /* length of the extent */ 57454c2258cSChao Yu u32 blk; /* start block address of the extent */ 57539a53e0cSJaegeuk Kim }; 57639a53e0cSJaegeuk Kim 57713054c54SChao Yu struct extent_node { 578c0362117SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 57913054c54SChao Yu struct extent_info ei; /* extent info */ 58054c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 581201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 58213054c54SChao Yu }; 58313054c54SChao Yu 58413054c54SChao Yu struct extent_tree { 58513054c54SChao Yu nid_t ino; /* inode number */ 5864dada3fdSChao Yu struct rb_root_cached root; /* root of extent info rb-tree */ 58762c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 5883e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 589137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 59013054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 59168e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 592b430f726SZhikang Zhang bool largest_updated; /* largest extent updated */ 59313054c54SChao Yu }; 59413054c54SChao Yu 59539a53e0cSJaegeuk Kim /* 596003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 597003a3e1dSJaegeuk Kim * 598003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 599003a3e1dSJaegeuk Kim */ 600003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 601003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 6027f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 6037f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 6047f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 605003a3e1dSJaegeuk Kim 606003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 607003a3e1dSJaegeuk Kim block_t m_pblk; 608003a3e1dSJaegeuk Kim block_t m_lblk; 609003a3e1dSJaegeuk Kim unsigned int m_len; 610003a3e1dSJaegeuk Kim unsigned int m_flags; 611da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 612c4020b2dSChao Yu pgoff_t *m_next_extent; /* point to next possible extent */ 613d5097be5SHyunchul Lee int m_seg_type; 614f9d6d059SChao Yu bool m_may_create; /* indicate it is from write path */ 615003a3e1dSJaegeuk Kim }; 616003a3e1dSJaegeuk Kim 617e2b4e2bcSChao Yu /* for flag in get_data_block */ 618f2220c7fSQiuyang Sun enum { 619f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 620f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 621f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 6220a4daae5SJaegeuk Kim F2FS_GET_BLOCK_DIO, 623f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 624f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 625c4020b2dSChao Yu F2FS_GET_BLOCK_PRECACHE, 626f2220c7fSQiuyang Sun }; 627e2b4e2bcSChao Yu 628003a3e1dSJaegeuk Kim /* 62939a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 63039a53e0cSJaegeuk Kim */ 63139a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 632354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 633cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 634e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 63526787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 636b6a06cbbSChao Yu #define FADVISE_HOT_BIT 0x20 63753fedcc0SEric Biggers #define FADVISE_VERITY_BIT 0x40 /* reserved */ 63839a53e0cSJaegeuk Kim 639797c1cb5SChao Yu #define FADVISE_MODIFIABLE_BITS (FADVISE_COLD_BIT | FADVISE_HOT_BIT) 640797c1cb5SChao Yu 641b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 642b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 643b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 644b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 645b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 646b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 647cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 648cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 649cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 650e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 651e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 65226787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 65326787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 654b6a06cbbSChao Yu #define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT) 655b6a06cbbSChao Yu #define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT) 656b6a06cbbSChao Yu #define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT) 657cde4de12SJaegeuk Kim 658ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 659ab9fa662SJaegeuk Kim 6602ef79ecbSChao Yu enum { 6612ef79ecbSChao Yu GC_FAILURE_PIN, 6622ef79ecbSChao Yu GC_FAILURE_ATOMIC, 6632ef79ecbSChao Yu MAX_GC_FAILURE 6642ef79ecbSChao Yu }; 6652ef79ecbSChao Yu 66639a53e0cSJaegeuk Kim struct f2fs_inode_info { 66739a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 66839a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 66939a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 67038431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 6711ad71a27SJaegeuk Kim unsigned int i_current_depth; /* only for directory depth */ 6722ef79ecbSChao Yu /* for gc failure statistic */ 6732ef79ecbSChao Yu unsigned int i_gc_failures[MAX_GC_FAILURE]; 6746666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 67539a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 67639a53e0cSJaegeuk Kim 67739a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 67839a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 679d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 680204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 68139a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 68239a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 68388c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 684b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 68539a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 68626de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 68788b88a66SJaegeuk Kim 6880abd675eSChao Yu #ifdef CONFIG_QUOTA 6890abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 6900abd675eSChao Yu 6910abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 6920abd675eSChao Yu qsize_t i_reserved_quota; 6930abd675eSChao Yu #endif 6940f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 6950f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 69657864ae5SJaegeuk Kim struct list_head inmem_ilist; /* list for inmem inodes */ 69788b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 6987a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 69988b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 7003e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 701b2532c69SChao Yu 702b2532c69SChao Yu /* avoid racing between foreground op and gc */ 703b2532c69SChao Yu struct rw_semaphore i_gc_rwsem[2]; 7045a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 70527161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 706f2470371SChao Yu 7077a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 7085c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 7096afc662eSChao Yu int i_inline_xattr_size; /* inline xattr size */ 71024b81dfcSArnd Bergmann struct timespec64 i_crtime; /* inode creation time */ 71124b81dfcSArnd Bergmann struct timespec64 i_disk_time[4];/* inode disk times */ 71239a53e0cSJaegeuk Kim }; 71339a53e0cSJaegeuk Kim 71439a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 715bd933d4fSChao Yu struct f2fs_extent *i_ext) 71639a53e0cSJaegeuk Kim { 717bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 718bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 719bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 72039a53e0cSJaegeuk Kim } 72139a53e0cSJaegeuk Kim 72239a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 72339a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 72439a53e0cSJaegeuk Kim { 72539a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 7264d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 72739a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 72839a53e0cSJaegeuk Kim } 72939a53e0cSJaegeuk Kim 730429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 731429511cdSChao Yu u32 blk, unsigned int len) 732429511cdSChao Yu { 733429511cdSChao Yu ei->fofs = fofs; 734429511cdSChao Yu ei->blk = blk; 735429511cdSChao Yu ei->len = len; 736429511cdSChao Yu } 737429511cdSChao Yu 738004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 73935ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 740004b6862SChao Yu { 7419a997188SJaegeuk Kim return (back->lstart + back->len == front->lstart) && 74235ec7d57SChao Yu (back->len + front->len <= max_len); 743004b6862SChao Yu } 744004b6862SChao Yu 745004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 74635ec7d57SChao Yu struct discard_info *back, unsigned int max_len) 747004b6862SChao Yu { 74835ec7d57SChao Yu return __is_discard_mergeable(back, cur, max_len); 749004b6862SChao Yu } 750004b6862SChao Yu 751004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 75235ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 753004b6862SChao Yu { 75435ec7d57SChao Yu return __is_discard_mergeable(cur, front, max_len); 755004b6862SChao Yu } 756004b6862SChao Yu 757429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 758429511cdSChao Yu struct extent_info *front) 759429511cdSChao Yu { 760429511cdSChao Yu return (back->fofs + back->len == front->fofs && 761429511cdSChao Yu back->blk + back->len == front->blk); 762429511cdSChao Yu } 763429511cdSChao Yu 764429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 765429511cdSChao Yu struct extent_info *back) 766429511cdSChao Yu { 767429511cdSChao Yu return __is_extent_mergeable(back, cur); 768429511cdSChao Yu } 769429511cdSChao Yu 770429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 771429511cdSChao Yu struct extent_info *front) 772429511cdSChao Yu { 773429511cdSChao Yu return __is_extent_mergeable(cur, front); 774429511cdSChao Yu } 775429511cdSChao Yu 776cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 777b430f726SZhikang Zhang static inline void __try_update_largest_extent(struct extent_tree *et, 778b430f726SZhikang Zhang struct extent_node *en) 7794abd3f5aSChao Yu { 780205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 7814abd3f5aSChao Yu et->largest = en->ei; 782b430f726SZhikang Zhang et->largest_updated = true; 783205b9822SJaegeuk Kim } 7844abd3f5aSChao Yu } 7854abd3f5aSChao Yu 7869a4ffdf5SChao Yu /* 7879a4ffdf5SChao Yu * For free nid management 7889a4ffdf5SChao Yu */ 7899a4ffdf5SChao Yu enum nid_state { 7909a4ffdf5SChao Yu FREE_NID, /* newly added to free nid list */ 7919a4ffdf5SChao Yu PREALLOC_NID, /* it is preallocated */ 7929a4ffdf5SChao Yu MAX_NID_STATE, 793b8559dc2SChao Yu }; 794b8559dc2SChao Yu 79539a53e0cSJaegeuk Kim struct f2fs_nm_info { 79639a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 79739a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 79804d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 79939a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 800cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 801ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 8022304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 80339a53e0cSJaegeuk Kim 80439a53e0cSJaegeuk Kim /* NAT cache management */ 80539a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 806309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 807b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 80839a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 80922969158SChao Yu spinlock_t nat_list_lock; /* protect clean nat entry list */ 810309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 811aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 81222ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 81339a53e0cSJaegeuk Kim 81439a53e0cSJaegeuk Kim /* free node ids management */ 8158a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 8169a4ffdf5SChao Yu struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ 8179a4ffdf5SChao Yu unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 818b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 81939a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 820bb1105e4SJaegeuk Kim unsigned char **free_nid_bitmap; 8214ac91242SChao Yu unsigned char *nat_block_bitmap; 822586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 82339a53e0cSJaegeuk Kim 82439a53e0cSJaegeuk Kim /* for checkpoint */ 82539a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 82622ad0b6aSJaegeuk Kim 82722ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 82822ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 82922ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 83022ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 831599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 832599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 833599a09b2SChao Yu #endif 83439a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 83539a53e0cSJaegeuk Kim }; 83639a53e0cSJaegeuk Kim 83739a53e0cSJaegeuk Kim /* 83839a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 83939a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 84039a53e0cSJaegeuk Kim * by the data offset in a file. 84139a53e0cSJaegeuk Kim */ 84239a53e0cSJaegeuk Kim struct dnode_of_data { 84339a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 84439a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 84539a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 84639a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 84739a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 84839a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 84993bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 8503cf45747SChao Yu char cur_level; /* level of hole node page */ 8513cf45747SChao Yu char max_level; /* level of current page located */ 85239a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 85339a53e0cSJaegeuk Kim }; 85439a53e0cSJaegeuk Kim 85539a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 85639a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 85739a53e0cSJaegeuk Kim { 858d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 85939a53e0cSJaegeuk Kim dn->inode = inode; 86039a53e0cSJaegeuk Kim dn->inode_page = ipage; 86139a53e0cSJaegeuk Kim dn->node_page = npage; 86239a53e0cSJaegeuk Kim dn->nid = nid; 86339a53e0cSJaegeuk Kim } 86439a53e0cSJaegeuk Kim 86539a53e0cSJaegeuk Kim /* 86639a53e0cSJaegeuk Kim * For SIT manager 86739a53e0cSJaegeuk Kim * 86839a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 86939a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 87039a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 87139a53e0cSJaegeuk Kim * respectively. 87239a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 87339a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 87439a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 87539a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 87639a53e0cSJaegeuk Kim * data and 8 for node logs. 87739a53e0cSJaegeuk Kim */ 87839a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 87939a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 88039a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 88139a53e0cSJaegeuk Kim 88239a53e0cSJaegeuk Kim enum { 88339a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 88439a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 88539a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 88639a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 88739a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 88839a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 88938aa0889SJaegeuk Kim NO_CHECK_TYPE, 89039a53e0cSJaegeuk Kim }; 89139a53e0cSJaegeuk Kim 8926b4afdd7SJaegeuk Kim struct flush_cmd { 8936b4afdd7SJaegeuk Kim struct completion wait; 894721bd4d5SGu Zheng struct llist_node llnode; 89539d787beSChao Yu nid_t ino; 8966b4afdd7SJaegeuk Kim int ret; 8976b4afdd7SJaegeuk Kim }; 8986b4afdd7SJaegeuk Kim 899a688b9d9SGu Zheng struct flush_cmd_control { 900a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 901a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 9028b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 90372691af6SJaegeuk Kim atomic_t queued_flush; /* # of queued flushes */ 904721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 905721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 906a688b9d9SGu Zheng }; 907a688b9d9SGu Zheng 90839a53e0cSJaegeuk Kim struct f2fs_sm_info { 90939a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 91039a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 91139a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 91239a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 91339a53e0cSJaegeuk Kim 9142b60311dSChao Yu struct rw_semaphore curseg_lock; /* for preventing curseg change */ 9152b60311dSChao Yu 91639a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 91739a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 91839a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 91939a53e0cSJaegeuk Kim 92039a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 92139a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 92239a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 92339a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 92481eb8d6eSJaegeuk Kim 92581eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 92681eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 9277fd9e544SJaegeuk Kim 928bba681cbSJaegeuk Kim /* for batched trimming */ 929bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 930bba681cbSJaegeuk Kim 931184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 932184a5cd2SChao Yu 933216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 934216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 935c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 936853137ceSJaegeuk Kim unsigned int min_seq_blocks; /* threshold for sequential blocks */ 937ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 938a2a12b67SChao Yu unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ 9396b4afdd7SJaegeuk Kim 9406b4afdd7SJaegeuk Kim /* for flush command control */ 941b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 942a688b9d9SGu Zheng 9430b54fb84SJaegeuk Kim /* for discard command control */ 9440b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 94539a53e0cSJaegeuk Kim }; 94639a53e0cSJaegeuk Kim 94739a53e0cSJaegeuk Kim /* 94839a53e0cSJaegeuk Kim * For superblock 94939a53e0cSJaegeuk Kim */ 95039a53e0cSJaegeuk Kim /* 95139a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 95239a53e0cSJaegeuk Kim * 95339a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 95439a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 95539a53e0cSJaegeuk Kim */ 95636951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 95739a53e0cSJaegeuk Kim enum count_type { 95839a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 959c227f912SChao Yu F2FS_DIRTY_DATA, 9602c8a4a28SJaegeuk Kim F2FS_DIRTY_QDATA, 96139a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 96239a53e0cSJaegeuk Kim F2FS_DIRTY_META, 9638dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 9640f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 96536951b38SChao Yu F2FS_WB_CP_DATA, 96636951b38SChao Yu F2FS_WB_DATA, 9675f9abab4SJaegeuk Kim F2FS_RD_DATA, 9685f9abab4SJaegeuk Kim F2FS_RD_NODE, 9695f9abab4SJaegeuk Kim F2FS_RD_META, 97002b16d0aSChao Yu F2FS_DIO_WRITE, 97102b16d0aSChao Yu F2FS_DIO_READ, 97239a53e0cSJaegeuk Kim NR_COUNT_TYPE, 97339a53e0cSJaegeuk Kim }; 97439a53e0cSJaegeuk Kim 97539a53e0cSJaegeuk Kim /* 976e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 97739a53e0cSJaegeuk Kim * The available types are: 97839a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 97939a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 98039a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 98139a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 98239a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 98339a53e0cSJaegeuk Kim * with waiting the bio's completion 98439a53e0cSJaegeuk Kim * ... Only can be used with META. 98539a53e0cSJaegeuk Kim */ 9867d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 98739a53e0cSJaegeuk Kim enum page_type { 98839a53e0cSJaegeuk Kim DATA, 98939a53e0cSJaegeuk Kim NODE, 99039a53e0cSJaegeuk Kim META, 99139a53e0cSJaegeuk Kim NR_PAGE_TYPE, 99239a53e0cSJaegeuk Kim META_FLUSH, 9938ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 9948ce67cb0SJaegeuk Kim INMEM_DROP, 9958c242db9SJaegeuk Kim INMEM_INVALIDATE, 99628bc106bSChao Yu INMEM_REVOKE, 9978ce67cb0SJaegeuk Kim IPU, 9988ce67cb0SJaegeuk Kim OPU, 99939a53e0cSJaegeuk Kim }; 100039a53e0cSJaegeuk Kim 1001a912b54dSJaegeuk Kim enum temp_type { 1002a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 1003a912b54dSJaegeuk Kim WARM, 1004a912b54dSJaegeuk Kim COLD, 1005a912b54dSJaegeuk Kim NR_TEMP_TYPE, 1006a912b54dSJaegeuk Kim }; 1007a912b54dSJaegeuk Kim 1008cc15620bSJaegeuk Kim enum need_lock_type { 1009cc15620bSJaegeuk Kim LOCK_REQ = 0, 1010cc15620bSJaegeuk Kim LOCK_DONE, 1011cc15620bSJaegeuk Kim LOCK_RETRY, 1012cc15620bSJaegeuk Kim }; 1013cc15620bSJaegeuk Kim 1014a5fd5050SChao Yu enum cp_reason_type { 1015a5fd5050SChao Yu CP_NO_NEEDED, 1016a5fd5050SChao Yu CP_NON_REGULAR, 1017a5fd5050SChao Yu CP_HARDLINK, 1018a5fd5050SChao Yu CP_SB_NEED_CP, 1019a5fd5050SChao Yu CP_WRONG_PINO, 1020a5fd5050SChao Yu CP_NO_SPC_ROLL, 1021a5fd5050SChao Yu CP_NODE_NEED_CP, 1022a5fd5050SChao Yu CP_FASTBOOT_MODE, 1023a5fd5050SChao Yu CP_SPEC_LOG_NUM, 10240a007b97SJaegeuk Kim CP_RECOVER_DIR, 1025a5fd5050SChao Yu }; 1026a5fd5050SChao Yu 1027b0af6d49SChao Yu enum iostat_type { 1028b0af6d49SChao Yu APP_DIRECT_IO, /* app direct IOs */ 1029b0af6d49SChao Yu APP_BUFFERED_IO, /* app buffered IOs */ 1030b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 1031b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 1032b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 1033b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 1034b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 1035b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 1036b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 1037b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 1038b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 1039b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 1040b0af6d49SChao Yu FS_DISCARD, /* discard */ 1041b0af6d49SChao Yu NR_IO_TYPE, 1042b0af6d49SChao Yu }; 1043b0af6d49SChao Yu 1044458e6197SJaegeuk Kim struct f2fs_io_info { 104505ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 104639d787beSChao Yu nid_t ino; /* inode number */ 1047458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 1048a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 104904d328deSMike Christie int op; /* contains REQ_OP_ */ 1050ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 10517a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 105228bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 105305ca3632SJaegeuk Kim struct page *page; /* page to be written */ 10544375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 1055fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 1056d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 1057cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 1058fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 10596dc3a126SChao Yu bool is_por; /* indicate IO is from recovery or not */ 1060fe16efe6SChao Yu bool retry; /* need to reallocate block address */ 1061b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 1062578c6478SYufen Yu struct writeback_control *io_wbc; /* writeback control */ 10638648de2cSChao Yu struct bio **bio; /* bio for ipu */ 10648648de2cSChao Yu sector_t *last_block; /* last block number in bio */ 10657735730dSChao Yu unsigned char version; /* version of the node */ 1066458e6197SJaegeuk Kim }; 1067458e6197SJaegeuk Kim 106868afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 10691ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 1070458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 10711ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 10721ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 1073458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 1074df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 1075fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 1076fb830fc5SChao Yu struct list_head io_list; /* track fios */ 10771ff7bd3bSJaegeuk Kim }; 10781ff7bd3bSJaegeuk Kim 10793c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 10803c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 10813c62be17SJaegeuk Kim struct f2fs_dev_info { 10823c62be17SJaegeuk Kim struct block_device *bdev; 10833c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 10843c62be17SJaegeuk Kim unsigned int total_segments; 10853c62be17SJaegeuk Kim block_t start_blk; 10863c62be17SJaegeuk Kim block_t end_blk; 10873c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 10883c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 108995175dafSDamien Le Moal unsigned long *blkz_seq; /* Bitmap indicating sequential zones */ 10903c62be17SJaegeuk Kim #endif 10913c62be17SJaegeuk Kim }; 10923c62be17SJaegeuk Kim 1093c227f912SChao Yu enum inode_type { 1094c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 1095c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 10960f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 109757864ae5SJaegeuk Kim ATOMIC_FILE, /* for all atomic files */ 1098c227f912SChao Yu NR_INODE_TYPE, 1099c227f912SChao Yu }; 1100c227f912SChao Yu 110167298804SChao Yu /* for inner inode cache management */ 110267298804SChao Yu struct inode_management { 110367298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 110467298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 110567298804SChao Yu struct list_head ino_list; /* inode list head */ 110667298804SChao Yu unsigned long ino_num; /* number of entries */ 110767298804SChao Yu }; 110867298804SChao Yu 1109caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 1110caf0047eSChao Yu enum { 1111caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 1112caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 1113caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 1114caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 1115df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 1116bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 111783a3bfdbSJaegeuk Kim SBI_IS_SHUTDOWN, /* shutdown by ioctl */ 11181378752bSChao Yu SBI_IS_RECOVERED, /* recovered orphan/data */ 11194354994fSDaniel Rosenberg SBI_CP_DISABLED, /* CP was disabled last mount */ 1120db610a64SJaegeuk Kim SBI_CP_DISABLED_QUICK, /* CP was disabled quickly */ 1121af033b2aSChao Yu SBI_QUOTA_NEED_FLUSH, /* need to flush quota info in CP */ 1122af033b2aSChao Yu SBI_QUOTA_SKIP_FLUSH, /* skip flushing quota in current CP */ 1123af033b2aSChao Yu SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */ 112404f0b2eaSQiuyang Sun SBI_IS_RESIZEFS, /* resizefs is in process */ 1125caf0047eSChao Yu }; 1126caf0047eSChao Yu 11276beceb54SJaegeuk Kim enum { 11286beceb54SJaegeuk Kim CP_TIME, 1129d0239e1bSJaegeuk Kim REQ_TIME, 1130a7d10cf3SSahitya Tummala DISCARD_TIME, 1131a7d10cf3SSahitya Tummala GC_TIME, 11324354994fSDaniel Rosenberg DISABLE_TIME, 113303f2c02dSJaegeuk Kim UMOUNT_DISCARD_TIMEOUT, 11346beceb54SJaegeuk Kim MAX_TIME, 11356beceb54SJaegeuk Kim }; 11366beceb54SJaegeuk Kim 11370cdd3195SHyunchul Lee enum { 11385b0e9539SJaegeuk Kim GC_NORMAL, 11395b0e9539SJaegeuk Kim GC_IDLE_CB, 11405b0e9539SJaegeuk Kim GC_IDLE_GREEDY, 11415b0e9539SJaegeuk Kim GC_URGENT, 11425b0e9539SJaegeuk Kim }; 11435b0e9539SJaegeuk Kim 11445b0e9539SJaegeuk Kim enum { 11450cdd3195SHyunchul Lee WHINT_MODE_OFF, /* not pass down write hints */ 11460cdd3195SHyunchul Lee WHINT_MODE_USER, /* try to pass down hints given by users */ 1147f2e703f9SHyunchul Lee WHINT_MODE_FS, /* pass down hints with F2FS policy */ 11480cdd3195SHyunchul Lee }; 11490cdd3195SHyunchul Lee 115007939627SJaegeuk Kim enum { 115107939627SJaegeuk Kim ALLOC_MODE_DEFAULT, /* stay default */ 115207939627SJaegeuk Kim ALLOC_MODE_REUSE, /* reuse segments as much as possible */ 115307939627SJaegeuk Kim }; 115407939627SJaegeuk Kim 115593cf93f1SJunling Zheng enum fsync_mode { 115693cf93f1SJunling Zheng FSYNC_MODE_POSIX, /* fsync follows posix semantics */ 115793cf93f1SJunling Zheng FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */ 1158d6290814SJaegeuk Kim FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */ 115993cf93f1SJunling Zheng }; 116093cf93f1SJunling Zheng 1161643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 1162ff62af20SSheng Yong #define DUMMY_ENCRYPTION_ENABLED(sbi) \ 1163ff62af20SSheng Yong (unlikely(F2FS_OPTION(sbi).test_dummy_encryption)) 1164ff62af20SSheng Yong #else 1165ff62af20SSheng Yong #define DUMMY_ENCRYPTION_ENABLED(sbi) (0) 1166ff62af20SSheng Yong #endif 1167ff62af20SSheng Yong 116839a53e0cSJaegeuk Kim struct f2fs_sb_info { 116939a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 11705e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 117139a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 1172846ae671SChao Yu struct rw_semaphore sb_lock; /* lock for raw super block */ 1173e8240f65SChao Yu int valid_super_block; /* valid super block no */ 1174fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 1175853137ceSJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 11765aba5430SDaniel Rosenberg #ifdef CONFIG_UNICODE 11775aba5430SDaniel Rosenberg struct unicode_map *s_encoding; 11785aba5430SDaniel Rosenberg __u16 s_encoding_flags; 11795aba5430SDaniel Rosenberg #endif 118039a53e0cSJaegeuk Kim 1181178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 1182178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1183178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 1184178053e2SDamien Le Moal #endif 1185178053e2SDamien Le Moal 118639a53e0cSJaegeuk Kim /* for node-related operations */ 118739a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 118839a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 118939a53e0cSJaegeuk Kim 119039a53e0cSJaegeuk Kim /* for segment-related operations */ 119139a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 11921ff7bd3bSJaegeuk Kim 11931ff7bd3bSJaegeuk Kim /* for bio operations */ 1194a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1195107a805dSChao Yu /* keep migration IO order for LFS mode */ 1196107a805dSChao Yu struct rw_semaphore io_order_lock; 11970a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 119839a53e0cSJaegeuk Kim 119939a53e0cSJaegeuk Kim /* for checkpoint */ 120039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 12018508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1202aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 120339a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 120439936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 1205b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1206b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 120759c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1208fb51b5efSChangman Lee wait_queue_head_t cp_wait; 12096beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 12106beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 121139a53e0cSJaegeuk Kim 121267298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 12136451e041SJaegeuk Kim 121450fa53ecSChao Yu spinlock_t fsync_node_lock; /* for node entry lock */ 121550fa53ecSChao Yu struct list_head fsync_node_list; /* node list head */ 121650fa53ecSChao Yu unsigned int fsync_seg_id; /* sequence id */ 121750fa53ecSChao Yu unsigned int fsync_node_num; /* number of node entries */ 121850fa53ecSChao Yu 12196451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 12200d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 122139a53e0cSJaegeuk Kim 1222c227f912SChao Yu /* for inode management */ 1223c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1224c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 1225040d2bb3SChao Yu struct mutex flush_lock; /* for flush exclusion */ 122639a53e0cSJaegeuk Kim 122713054c54SChao Yu /* for extent tree cache */ 122813054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 12295e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 123013054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 123113054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 12327441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1233137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 123474fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 123513054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 123613054c54SChao Yu 123739a53e0cSJaegeuk Kim /* basic filesystem units */ 123839a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 123939a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 124039a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 124139a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 124239a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 124339a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 124439a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 124539a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 124639a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 124739a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 124839a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 124904f0b2eaSQiuyang Sun struct mutex resize_mutex; /* for resize exclusion */ 125039a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 125139a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1252e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 1253ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 1254f6df8f23SSheng Yong int readdir_ra; /* readahead inode in readdir */ 125539a53e0cSJaegeuk Kim 125639a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 125739a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1258a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 125939a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1260daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 126180d42145SYunlong Song block_t current_reserved_blocks; /* current reserved blocks */ 1262daeb433eSChao Yu 12634354994fSDaniel Rosenberg /* Additional tracking for no checkpoint mode */ 12644354994fSDaniel Rosenberg block_t unusable_block_count; /* # of blocks saved by last cp */ 12654354994fSDaniel Rosenberg 1266292c196aSChao Yu unsigned int nquota_files; /* # of quota sysfile */ 1267db6ec53bSJaegeuk Kim struct rw_semaphore quota_sem; /* blocking cp for flags */ 1268292c196aSChao Yu 1269523be8a6SJaegeuk Kim /* # of pages, see count_type */ 127035782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 127141382ec4SJaegeuk Kim /* # of allocated blocks */ 127241382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 127339a53e0cSJaegeuk Kim 1274687de7f1SJaegeuk Kim /* writeback control */ 1275c29fd0c0SChao Yu atomic_t wb_sync_req[META]; /* count # of WB_SYNC threads */ 1276687de7f1SJaegeuk Kim 1277513c5f37SJaegeuk Kim /* valid inode count */ 1278513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1279513c5f37SJaegeuk Kim 128039a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 128139a53e0cSJaegeuk Kim 128239a53e0cSJaegeuk Kim /* for cleaning operations */ 128339a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 128439a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 12855ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 12865b0e9539SJaegeuk Kim unsigned int gc_mode; /* current GC state */ 1287e3080b01SChao Yu unsigned int next_victim_seg[2]; /* next segment in victim section */ 12882ef79ecbSChao Yu /* for skip statistic */ 12892ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */ 12906f8d4455SJaegeuk Kim unsigned long long skipped_gc_rwsem; /* FG_GC only */ 129139a53e0cSJaegeuk Kim 12921ad71a27SJaegeuk Kim /* threshold for gc trials on pinned files */ 12931ad71a27SJaegeuk Kim u64 gc_pin_file_threshold; 12941ad71a27SJaegeuk Kim 1295b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1296b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1297e3080b01SChao Yu /* migration granularity of garbage collection, unit: segment */ 1298e3080b01SChao Yu unsigned int migration_granularity; 1299b1c57c1cSJaegeuk Kim 130039a53e0cSJaegeuk Kim /* 130139a53e0cSJaegeuk Kim * for stat information. 130239a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 130339a53e0cSJaegeuk Kim */ 130435b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 130539a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 1306b63e7be5SChao Yu atomic_t meta_count[META_MAX]; /* # of meta blocks */ 130739a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 130839a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1309b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 13105b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 13115b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 13125b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 13135b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1314d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 131503e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 131603e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 131726a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 1318648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 131926a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1320648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 132139a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 1322274bd9baSChao Yu unsigned int io_skip_bggc; /* skip background gc for in-flight IO */ 1323274bd9baSChao Yu unsigned int other_skip_bggc; /* skip background gc for other reasons */ 132433fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 132535b09d82SNamjae Jeon #endif 132639a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1327b59d0baeSNamjae Jeon 1328b0af6d49SChao Yu /* For app/fs IO statistics */ 1329b0af6d49SChao Yu spinlock_t iostat_lock; 1330b0af6d49SChao Yu unsigned long long write_iostat[NR_IO_TYPE]; 1331b0af6d49SChao Yu bool iostat_enable; 1332b0af6d49SChao Yu 1333b59d0baeSNamjae Jeon /* For sysfs suppport */ 1334b59d0baeSNamjae Jeon struct kobject s_kobj; 1335b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 13362658e50dSJaegeuk Kim 13372658e50dSJaegeuk Kim /* For shrinker support */ 13382658e50dSJaegeuk Kim struct list_head s_list; 13393c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 13403c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 13411228b482SChao Yu unsigned int dirty_device; /* for checkpoint data flush */ 13421228b482SChao Yu spinlock_t dev_lock; /* protect dirty_device */ 13432658e50dSJaegeuk Kim struct mutex umount_mutex; 13442658e50dSJaegeuk Kim unsigned int shrinker_run_no; 13458f1dbbbbSShuoran Liu 13468f1dbbbbSShuoran Liu /* For write statistics */ 13478f1dbbbbSShuoran Liu u64 sectors_written_start; 13488f1dbbbbSShuoran Liu u64 kbytes_written; 134943b6573bSKeith Mok 135043b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 135143b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 13521ecc0c5cSChao Yu 1353704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1354704956ecSChao Yu __u32 s_chksum_seed; 135539a53e0cSJaegeuk Kim }; 135639a53e0cSJaegeuk Kim 135702b16d0aSChao Yu struct f2fs_private_dio { 135802b16d0aSChao Yu struct inode *inode; 135902b16d0aSChao Yu void *orig_private; 136002b16d0aSChao Yu bio_end_io_t *orig_end_io; 136102b16d0aSChao Yu bool write; 136202b16d0aSChao Yu }; 136302b16d0aSChao Yu 13641ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 136555523519SChao Yu #define f2fs_show_injection_info(type) \ 1366d75f773cSSakari Ailus printk_ratelimited("%sF2FS-fs : inject %s in %s of %pS\n", \ 13672d3a5856SGao Xiang KERN_INFO, f2fs_fault_name[type], \ 136855523519SChao Yu __func__, __builtin_return_address(0)) 13691ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 13701ecc0c5cSChao Yu { 137163189b78SChao Yu struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; 13721ecc0c5cSChao Yu 13731ecc0c5cSChao Yu if (!ffi->inject_rate) 13741ecc0c5cSChao Yu return false; 13751ecc0c5cSChao Yu 13761ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 13771ecc0c5cSChao Yu return false; 13781ecc0c5cSChao Yu 13791ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 13801ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 13811ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 13821ecc0c5cSChao Yu return true; 13831ecc0c5cSChao Yu } 13841ecc0c5cSChao Yu return false; 13851ecc0c5cSChao Yu } 13867fa750a1SArnd Bergmann #else 13877fa750a1SArnd Bergmann #define f2fs_show_injection_info(type) do { } while (0) 13887fa750a1SArnd Bergmann static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 13897fa750a1SArnd Bergmann { 13907fa750a1SArnd Bergmann return false; 13917fa750a1SArnd Bergmann } 13921ecc0c5cSChao Yu #endif 13931ecc0c5cSChao Yu 13940916878dSDamien Le Moal /* 13950916878dSDamien Le Moal * Test if the mounted volume is a multi-device volume. 13960916878dSDamien Le Moal * - For a single regular disk volume, sbi->s_ndevs is 0. 13970916878dSDamien Le Moal * - For a single zoned disk volume, sbi->s_ndevs is 1. 13980916878dSDamien Le Moal * - For a multi-device volume, sbi->s_ndevs is always 2 or more. 13990916878dSDamien Le Moal */ 14000916878dSDamien Le Moal static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi) 14010916878dSDamien Le Moal { 14020916878dSDamien Le Moal return sbi->s_ndevs > 1; 14030916878dSDamien Le Moal } 14040916878dSDamien Le Moal 14058f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 14068f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 14078f1dbbbbSShuoran Liu */ 14088f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 1409dbae2c55SMichael Callahan (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[STAT_WRITE]) - \ 141068afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 14118f1dbbbbSShuoran Liu 14126beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 14136beceb54SJaegeuk Kim { 1414a7d10cf3SSahitya Tummala unsigned long now = jiffies; 1415a7d10cf3SSahitya Tummala 1416a7d10cf3SSahitya Tummala sbi->last_time[type] = now; 1417a7d10cf3SSahitya Tummala 1418a7d10cf3SSahitya Tummala /* DISCARD_TIME and GC_TIME are based on REQ_TIME */ 1419a7d10cf3SSahitya Tummala if (type == REQ_TIME) { 1420a7d10cf3SSahitya Tummala sbi->last_time[DISCARD_TIME] = now; 1421a7d10cf3SSahitya Tummala sbi->last_time[GC_TIME] = now; 1422a7d10cf3SSahitya Tummala } 14236beceb54SJaegeuk Kim } 14246beceb54SJaegeuk Kim 14256beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 14266beceb54SJaegeuk Kim { 14276bccfa19SArnd Bergmann unsigned long interval = sbi->interval_time[type] * HZ; 14286beceb54SJaegeuk Kim 14296beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 14306beceb54SJaegeuk Kim } 14316beceb54SJaegeuk Kim 1432a7d10cf3SSahitya Tummala static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi, 1433a7d10cf3SSahitya Tummala int type) 1434a7d10cf3SSahitya Tummala { 1435a7d10cf3SSahitya Tummala unsigned long interval = sbi->interval_time[type] * HZ; 1436a7d10cf3SSahitya Tummala unsigned int wait_ms = 0; 1437a7d10cf3SSahitya Tummala long delta; 1438a7d10cf3SSahitya Tummala 1439a7d10cf3SSahitya Tummala delta = (sbi->last_time[type] + interval) - jiffies; 1440a7d10cf3SSahitya Tummala if (delta > 0) 1441a7d10cf3SSahitya Tummala wait_ms = jiffies_to_msecs(delta); 1442a7d10cf3SSahitya Tummala 1443a7d10cf3SSahitya Tummala return wait_ms; 1444a7d10cf3SSahitya Tummala } 1445a7d10cf3SSahitya Tummala 144639a53e0cSJaegeuk Kim /* 144739a53e0cSJaegeuk Kim * Inline functions 144839a53e0cSJaegeuk Kim */ 1449416d2dbbSChao Yu static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc, 1450704956ecSChao Yu const void *address, unsigned int length) 1451704956ecSChao Yu { 1452704956ecSChao Yu struct { 1453704956ecSChao Yu struct shash_desc shash; 1454704956ecSChao Yu char ctx[4]; 1455704956ecSChao Yu } desc; 1456704956ecSChao Yu int err; 1457704956ecSChao Yu 1458704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1459704956ecSChao Yu 1460704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1461704956ecSChao Yu *(u32 *)desc.ctx = crc; 1462704956ecSChao Yu 1463704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1464704956ecSChao Yu BUG_ON(err); 1465704956ecSChao Yu 1466704956ecSChao Yu return *(u32 *)desc.ctx; 1467704956ecSChao Yu } 1468704956ecSChao Yu 1469416d2dbbSChao Yu static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 1470416d2dbbSChao Yu unsigned int length) 1471416d2dbbSChao Yu { 1472416d2dbbSChao Yu return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length); 1473416d2dbbSChao Yu } 1474416d2dbbSChao Yu 1475416d2dbbSChao Yu static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 1476416d2dbbSChao Yu void *buf, size_t buf_size) 1477416d2dbbSChao Yu { 1478416d2dbbSChao Yu return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 1479416d2dbbSChao Yu } 1480416d2dbbSChao Yu 1481416d2dbbSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1482416d2dbbSChao Yu const void *address, unsigned int length) 1483416d2dbbSChao Yu { 1484416d2dbbSChao Yu return __f2fs_crc32(sbi, crc, address, length); 1485416d2dbbSChao Yu } 1486416d2dbbSChao Yu 148739a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 148839a53e0cSJaegeuk Kim { 148939a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 149039a53e0cSJaegeuk Kim } 149139a53e0cSJaegeuk Kim 149239a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 149339a53e0cSJaegeuk Kim { 149439a53e0cSJaegeuk Kim return sb->s_fs_info; 149539a53e0cSJaegeuk Kim } 149639a53e0cSJaegeuk Kim 14974081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 14984081363fSJaegeuk Kim { 14994081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 15004081363fSJaegeuk Kim } 15014081363fSJaegeuk Kim 15024081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 15034081363fSJaegeuk Kim { 15044081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 15054081363fSJaegeuk Kim } 15064081363fSJaegeuk Kim 15074081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 15084081363fSJaegeuk Kim { 15094969c06aSJaegeuk Kim return F2FS_M_SB(page_file_mapping(page)); 15104081363fSJaegeuk Kim } 15114081363fSJaegeuk Kim 151239a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 151339a53e0cSJaegeuk Kim { 151439a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 151539a53e0cSJaegeuk Kim } 151639a53e0cSJaegeuk Kim 151739a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 151839a53e0cSJaegeuk Kim { 151939a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 152039a53e0cSJaegeuk Kim } 152139a53e0cSJaegeuk Kim 152245590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 152345590710SGu Zheng { 152445590710SGu Zheng return (struct f2fs_node *)page_address(page); 152545590710SGu Zheng } 152645590710SGu Zheng 152758bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 152858bfaf44SJaegeuk Kim { 152958bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 153058bfaf44SJaegeuk Kim } 153158bfaf44SJaegeuk Kim 153239a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 153339a53e0cSJaegeuk Kim { 153439a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 153539a53e0cSJaegeuk Kim } 153639a53e0cSJaegeuk Kim 153739a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 153839a53e0cSJaegeuk Kim { 153939a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 154039a53e0cSJaegeuk Kim } 154139a53e0cSJaegeuk Kim 154239a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 154339a53e0cSJaegeuk Kim { 154439a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 154539a53e0cSJaegeuk Kim } 154639a53e0cSJaegeuk Kim 154739a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 154839a53e0cSJaegeuk Kim { 154939a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 155039a53e0cSJaegeuk Kim } 155139a53e0cSJaegeuk Kim 155239a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 155339a53e0cSJaegeuk Kim { 155439a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 155539a53e0cSJaegeuk Kim } 155639a53e0cSJaegeuk Kim 15579df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 15589df27d98SGu Zheng { 15599df27d98SGu Zheng return sbi->meta_inode->i_mapping; 15609df27d98SGu Zheng } 15619df27d98SGu Zheng 15624ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 15634ef51a8fSJaegeuk Kim { 15644ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 15654ef51a8fSJaegeuk Kim } 15664ef51a8fSJaegeuk Kim 1567caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 156839a53e0cSJaegeuk Kim { 1569fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 157039a53e0cSJaegeuk Kim } 157139a53e0cSJaegeuk Kim 1572caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 157339a53e0cSJaegeuk Kim { 1574fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1575caf0047eSChao Yu } 1576caf0047eSChao Yu 1577caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1578caf0047eSChao Yu { 1579fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 158039a53e0cSJaegeuk Kim } 158139a53e0cSJaegeuk Kim 1582d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1583d71b5564SJaegeuk Kim { 1584d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1585d71b5564SJaegeuk Kim } 1586d71b5564SJaegeuk Kim 1587ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) 1588ea676733SJaegeuk Kim { 1589ea676733SJaegeuk Kim if (type < F2FS_MAX_QUOTAS) 1590ea676733SJaegeuk Kim return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); 1591ea676733SJaegeuk Kim return 0; 1592ea676733SJaegeuk Kim } 1593ea676733SJaegeuk Kim 1594ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1595ced2c7eaSKinglong Mee { 1596ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1597ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1598ced2c7eaSKinglong Mee } 1599ced2c7eaSKinglong Mee 1600aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 160125ca923bSJaegeuk Kim { 160225ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1603aaec2b1dSChao Yu 160425ca923bSJaegeuk Kim return ckpt_flags & f; 160525ca923bSJaegeuk Kim } 160625ca923bSJaegeuk Kim 1607aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 160825ca923bSJaegeuk Kim { 1609aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1610aaec2b1dSChao Yu } 1611aaec2b1dSChao Yu 1612aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1613aaec2b1dSChao Yu { 1614aaec2b1dSChao Yu unsigned int ckpt_flags; 1615aaec2b1dSChao Yu 1616aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 161725ca923bSJaegeuk Kim ckpt_flags |= f; 161825ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 161925ca923bSJaegeuk Kim } 162025ca923bSJaegeuk Kim 1621aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 162225ca923bSJaegeuk Kim { 1623d1aa2453SChao Yu unsigned long flags; 1624d1aa2453SChao Yu 1625d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1626aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1627d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1628aaec2b1dSChao Yu } 1629aaec2b1dSChao Yu 1630aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1631aaec2b1dSChao Yu { 1632aaec2b1dSChao Yu unsigned int ckpt_flags; 1633aaec2b1dSChao Yu 1634aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 163525ca923bSJaegeuk Kim ckpt_flags &= (~f); 163625ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 163725ca923bSJaegeuk Kim } 163825ca923bSJaegeuk Kim 1639aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1640aaec2b1dSChao Yu { 1641d1aa2453SChao Yu unsigned long flags; 1642d1aa2453SChao Yu 1643d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1644aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1645d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1646aaec2b1dSChao Yu } 1647aaec2b1dSChao Yu 164822ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 164922ad0b6aSJaegeuk Kim { 1650d1aa2453SChao Yu unsigned long flags; 16510921835cSChao Yu unsigned char *nat_bits; 1652d1aa2453SChao Yu 1653a742fd41SJaegeuk Kim /* 1654a742fd41SJaegeuk Kim * In order to re-enable nat_bits we need to call fsck.f2fs by 1655a742fd41SJaegeuk Kim * set_sbi_flag(sbi, SBI_NEED_FSCK). But it may give huge cost, 1656a742fd41SJaegeuk Kim * so let's rely on regular fsck or unclean shutdown. 1657a742fd41SJaegeuk Kim */ 165822ad0b6aSJaegeuk Kim 165922ad0b6aSJaegeuk Kim if (lock) 1660d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 166122ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 16620921835cSChao Yu nat_bits = NM_I(sbi)->nat_bits; 166322ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 166422ad0b6aSJaegeuk Kim if (lock) 1665d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 16660921835cSChao Yu 16670921835cSChao Yu kvfree(nat_bits); 166822ad0b6aSJaegeuk Kim } 166922ad0b6aSJaegeuk Kim 167022ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 167122ad0b6aSJaegeuk Kim struct cp_control *cpc) 167222ad0b6aSJaegeuk Kim { 167322ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 167422ad0b6aSJaegeuk Kim 1675c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 167622ad0b6aSJaegeuk Kim } 167722ad0b6aSJaegeuk Kim 1678e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 167939a53e0cSJaegeuk Kim { 1680b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 168139a53e0cSJaegeuk Kim } 168239a53e0cSJaegeuk Kim 1683cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1684cc15620bSJaegeuk Kim { 1685cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1686cc15620bSJaegeuk Kim } 1687cc15620bSJaegeuk Kim 1688e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 168939a53e0cSJaegeuk Kim { 1690b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 169139936837SJaegeuk Kim } 169239936837SJaegeuk Kim 1693e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 169439936837SJaegeuk Kim { 1695b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 169639936837SJaegeuk Kim } 169739936837SJaegeuk Kim 1698e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 169939936837SJaegeuk Kim { 1700b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 170139a53e0cSJaegeuk Kim } 170239a53e0cSJaegeuk Kim 1703119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1704119ee914SJaegeuk Kim { 1705119ee914SJaegeuk Kim int reason = CP_SYNC; 1706119ee914SJaegeuk Kim 1707119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1708119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1709119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1710119ee914SJaegeuk Kim reason = CP_UMOUNT; 1711119ee914SJaegeuk Kim return reason; 1712119ee914SJaegeuk Kim } 1713119ee914SJaegeuk Kim 1714119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1715119ee914SJaegeuk Kim { 1716c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1717119ee914SJaegeuk Kim } 1718119ee914SJaegeuk Kim 1719119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1720119ee914SJaegeuk Kim { 1721aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1722aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1723119ee914SJaegeuk Kim } 1724119ee914SJaegeuk Kim 172539a53e0cSJaegeuk Kim /* 172639a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 172739a53e0cSJaegeuk Kim */ 172839a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 172939a53e0cSJaegeuk Kim { 17300eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 17310eb0adadSChao Yu 1732000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 173339a53e0cSJaegeuk Kim } 173439a53e0cSJaegeuk Kim 17354bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 17364bc8e9bcSChao Yu { 17374bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 17384bc8e9bcSChao Yu } 17394bc8e9bcSChao Yu 1740d8a9a229SJaegeuk Kim static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, 1741a90a0884SJaegeuk Kim struct inode *inode, bool cap) 17427c2e5963SJaegeuk Kim { 1743d8a9a229SJaegeuk Kim if (!inode) 1744d8a9a229SJaegeuk Kim return true; 17457c2e5963SJaegeuk Kim if (!test_opt(sbi, RESERVE_ROOT)) 17467c2e5963SJaegeuk Kim return false; 1747d8a9a229SJaegeuk Kim if (IS_NOQUOTA(inode)) 1748d8a9a229SJaegeuk Kim return true; 174963189b78SChao Yu if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid())) 17507c2e5963SJaegeuk Kim return true; 175163189b78SChao Yu if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) && 175263189b78SChao Yu in_group_p(F2FS_OPTION(sbi).s_resgid)) 17537c2e5963SJaegeuk Kim return true; 1754a90a0884SJaegeuk Kim if (cap && capable(CAP_SYS_RESOURCE)) 1755162b27aeSJaegeuk Kim return true; 17567c2e5963SJaegeuk Kim return false; 17577c2e5963SJaegeuk Kim } 17587c2e5963SJaegeuk Kim 17590abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 17600abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 176146008c6dSChao Yu struct inode *inode, blkcnt_t *count) 176239a53e0cSJaegeuk Kim { 17630abd675eSChao Yu blkcnt_t diff = 0, release = 0; 1764daeb433eSChao Yu block_t avail_user_block_count; 17650abd675eSChao Yu int ret; 17660abd675eSChao Yu 17670abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 17680abd675eSChao Yu if (ret) 17690abd675eSChao Yu return ret; 1770dd11a5dfSJaegeuk Kim 177155523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 177255523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 17730abd675eSChao Yu release = *count; 1774*9ea2f0beSChao Yu goto release_quota; 177555523519SChao Yu } 17767fa750a1SArnd Bergmann 1777dd11a5dfSJaegeuk Kim /* 1778dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1779dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1780dd11a5dfSJaegeuk Kim */ 1781dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 178239a53e0cSJaegeuk Kim 178339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 17842555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 178580d42145SYunlong Song avail_user_block_count = sbi->user_block_count - 178680d42145SYunlong Song sbi->current_reserved_blocks; 17877e65be49SJaegeuk Kim 1788a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, true)) 178963189b78SChao Yu avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; 1790a4c3ecaaSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { 1791a4c3ecaaSDaniel Rosenberg if (avail_user_block_count > sbi->unusable_block_count) 17924354994fSDaniel Rosenberg avail_user_block_count -= sbi->unusable_block_count; 1793a4c3ecaaSDaniel Rosenberg else 1794a4c3ecaaSDaniel Rosenberg avail_user_block_count = 0; 1795a4c3ecaaSDaniel Rosenberg } 1796daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1797daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 17987e65be49SJaegeuk Kim if (diff > *count) 17997e65be49SJaegeuk Kim diff = *count; 1800dd11a5dfSJaegeuk Kim *count -= diff; 18010abd675eSChao Yu release = diff; 18027e65be49SJaegeuk Kim sbi->total_valid_block_count -= diff; 180346008c6dSChao Yu if (!*count) { 180439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 18050abd675eSChao Yu goto enospc; 180639a53e0cSJaegeuk Kim } 180746008c6dSChao Yu } 180839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 180941382ec4SJaegeuk Kim 181036b877afSDaniel Rosenberg if (unlikely(release)) { 181136b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 18120abd675eSChao Yu dquot_release_reservation_block(inode, release); 181336b877afSDaniel Rosenberg } 18140abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 18150abd675eSChao Yu return 0; 18160abd675eSChao Yu 18170abd675eSChao Yu enospc: 181836b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 1819*9ea2f0beSChao Yu release_quota: 18200abd675eSChao Yu dquot_release_reservation_block(inode, release); 18210abd675eSChao Yu return -ENOSPC; 182239a53e0cSJaegeuk Kim } 182339a53e0cSJaegeuk Kim 1824dcbb4c10SJoe Perches __printf(2, 3) 1825dcbb4c10SJoe Perches void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...); 1826dcbb4c10SJoe Perches 1827dcbb4c10SJoe Perches #define f2fs_err(sbi, fmt, ...) \ 1828dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_ERR fmt, ##__VA_ARGS__) 1829dcbb4c10SJoe Perches #define f2fs_warn(sbi, fmt, ...) \ 1830dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_WARNING fmt, ##__VA_ARGS__) 1831dcbb4c10SJoe Perches #define f2fs_notice(sbi, fmt, ...) \ 1832dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_NOTICE fmt, ##__VA_ARGS__) 1833dcbb4c10SJoe Perches #define f2fs_info(sbi, fmt, ...) \ 1834dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_INFO fmt, ##__VA_ARGS__) 1835dcbb4c10SJoe Perches #define f2fs_debug(sbi, fmt, ...) \ 1836dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_DEBUG fmt, ##__VA_ARGS__) 1837dcbb4c10SJoe Perches 1838da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 183939a53e0cSJaegeuk Kim struct inode *inode, 18400eb0adadSChao Yu block_t count) 184139a53e0cSJaegeuk Kim { 18420eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 18430eb0adadSChao Yu 184439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 18459850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 184639a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 184780d42145SYunlong Song if (sbi->reserved_blocks && 184880d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 184980d42145SYunlong Song sbi->current_reserved_blocks = min(sbi->reserved_blocks, 185080d42145SYunlong Song sbi->current_reserved_blocks + count); 185139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 18525e159cd3SChao Yu if (unlikely(inode->i_blocks < sectors)) { 1853dcbb4c10SJoe Perches f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu", 18545e159cd3SChao Yu inode->i_ino, 18555e159cd3SChao Yu (unsigned long long)inode->i_blocks, 18565e159cd3SChao Yu (unsigned long long)sectors); 18575e159cd3SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 18585e159cd3SChao Yu return; 18595e159cd3SChao Yu } 18600abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 186139a53e0cSJaegeuk Kim } 186239a53e0cSJaegeuk Kim 186339a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 186439a53e0cSJaegeuk Kim { 186535782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 18667c4abcbeSChao Yu 186720109873SChao Yu if (count_type == F2FS_DIRTY_DENTS || 186820109873SChao Yu count_type == F2FS_DIRTY_NODES || 186920109873SChao Yu count_type == F2FS_DIRTY_META || 187020109873SChao Yu count_type == F2FS_DIRTY_QDATA || 187120109873SChao Yu count_type == F2FS_DIRTY_IMETA) 1872caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 187339a53e0cSJaegeuk Kim } 187439a53e0cSJaegeuk Kim 1875a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 187639a53e0cSJaegeuk Kim { 1877204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1878c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1879c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 18802c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 18812c8a4a28SJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 188239a53e0cSJaegeuk Kim } 188339a53e0cSJaegeuk Kim 188439a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 188539a53e0cSJaegeuk Kim { 188635782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 188739a53e0cSJaegeuk Kim } 188839a53e0cSJaegeuk Kim 1889a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 189039a53e0cSJaegeuk Kim { 18915ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 18925ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 18931fe54f9dSJaegeuk Kim return; 18941fe54f9dSJaegeuk Kim 1895204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1896c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1897c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 18982c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 18992c8a4a28SJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 190039a53e0cSJaegeuk Kim } 190139a53e0cSJaegeuk Kim 1902523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 190339a53e0cSJaegeuk Kim { 190435782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 190539a53e0cSJaegeuk Kim } 190639a53e0cSJaegeuk Kim 1907204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1908f8b2c1f9SJaegeuk Kim { 1909204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1910f8b2c1f9SJaegeuk Kim } 1911f8b2c1f9SJaegeuk Kim 19125ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 19135ac206cfSNamjae Jeon { 19143519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1915523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1916523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1917523be8a6SJaegeuk Kim 1918523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 19195ac206cfSNamjae Jeon } 19205ac206cfSNamjae Jeon 192139a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 192239a53e0cSJaegeuk Kim { 19238b8343faSJaegeuk Kim return sbi->total_valid_block_count; 192439a53e0cSJaegeuk Kim } 192539a53e0cSJaegeuk Kim 1926f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1927f83a2584SYunlei He { 1928f83a2584SYunlei He return sbi->discard_blks; 1929f83a2584SYunlei He } 1930f83a2584SYunlei He 193139a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 193239a53e0cSJaegeuk Kim { 193339a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 193439a53e0cSJaegeuk Kim 193539a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 193639a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 193739a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 193839a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 193939a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 194039a53e0cSJaegeuk Kim 194139a53e0cSJaegeuk Kim return 0; 194239a53e0cSJaegeuk Kim } 194339a53e0cSJaegeuk Kim 194455141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 194555141486SWanpeng Li { 194655141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 194755141486SWanpeng Li } 194855141486SWanpeng Li 194939a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 195039a53e0cSJaegeuk Kim { 195139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 19521dbe4152SChangman Lee int offset; 19531dbe4152SChangman Lee 1954199bc3feSChao Yu if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { 1955199bc3feSChao Yu offset = (flag == SIT_BITMAP) ? 1956199bc3feSChao Yu le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; 1957b471eb99SChao Yu /* 1958b471eb99SChao Yu * if large_nat_bitmap feature is enabled, leave checksum 1959b471eb99SChao Yu * protection for all nat/sit bitmaps. 1960b471eb99SChao Yu */ 1961b471eb99SChao Yu return &ckpt->sit_nat_version_bitmap + offset + sizeof(__le32); 1962199bc3feSChao Yu } 1963199bc3feSChao Yu 196455141486SWanpeng Li if (__cp_payload(sbi) > 0) { 19651dbe4152SChangman Lee if (flag == NAT_BITMAP) 19661dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 19671dbe4152SChangman Lee else 196865b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 19691dbe4152SChangman Lee } else { 19701dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 197125ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 197239a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 197339a53e0cSJaegeuk Kim } 19741dbe4152SChangman Lee } 197539a53e0cSJaegeuk Kim 197639a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 197739a53e0cSJaegeuk Kim { 19788508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 197939a53e0cSJaegeuk Kim 19808508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 198139a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 198239a53e0cSJaegeuk Kim return start_addr; 198339a53e0cSJaegeuk Kim } 198439a53e0cSJaegeuk Kim 19858508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 19868508e44aSJaegeuk Kim { 19878508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 19888508e44aSJaegeuk Kim 19898508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 19908508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 19918508e44aSJaegeuk Kim return start_addr; 19928508e44aSJaegeuk Kim } 19938508e44aSJaegeuk Kim 19948508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 19958508e44aSJaegeuk Kim { 19968508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 19978508e44aSJaegeuk Kim } 19988508e44aSJaegeuk Kim 199939a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 200039a53e0cSJaegeuk Kim { 200139a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 200239a53e0cSJaegeuk Kim } 200339a53e0cSJaegeuk Kim 20040abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 2005000519f2SChao Yu struct inode *inode, bool is_inode) 200639a53e0cSJaegeuk Kim { 200739a53e0cSJaegeuk Kim block_t valid_block_count; 2008a4c3ecaaSDaniel Rosenberg unsigned int valid_node_count, user_block_count; 2009af033b2aSChao Yu int err; 20100abd675eSChao Yu 2011af033b2aSChao Yu if (is_inode) { 2012af033b2aSChao Yu if (inode) { 2013af033b2aSChao Yu err = dquot_alloc_inode(inode); 2014af033b2aSChao Yu if (err) 2015af033b2aSChao Yu return err; 2016af033b2aSChao Yu } 2017af033b2aSChao Yu } else { 2018af033b2aSChao Yu err = dquot_reserve_block(inode, 1); 2019af033b2aSChao Yu if (err) 2020af033b2aSChao Yu return err; 20210abd675eSChao Yu } 202239a53e0cSJaegeuk Kim 2023812c6056SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 2024812c6056SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 2025812c6056SChao Yu goto enospc; 2026812c6056SChao Yu } 2027812c6056SChao Yu 202839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 202939a53e0cSJaegeuk Kim 20307e65be49SJaegeuk Kim valid_block_count = sbi->total_valid_block_count + 20317e65be49SJaegeuk Kim sbi->current_reserved_blocks + 1; 20327e65be49SJaegeuk Kim 2033a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, false)) 203463189b78SChao Yu valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; 2035a4c3ecaaSDaniel Rosenberg user_block_count = sbi->user_block_count; 20364354994fSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) 2037a4c3ecaaSDaniel Rosenberg user_block_count -= sbi->unusable_block_count; 20387e65be49SJaegeuk Kim 2039a4c3ecaaSDaniel Rosenberg if (unlikely(valid_block_count > user_block_count)) { 204039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 20410abd675eSChao Yu goto enospc; 204239a53e0cSJaegeuk Kim } 204339a53e0cSJaegeuk Kim 2044ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 2045cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 204639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 20470abd675eSChao Yu goto enospc; 204839a53e0cSJaegeuk Kim } 204939a53e0cSJaegeuk Kim 2050ef86d709SGu Zheng sbi->total_valid_node_count++; 2051ef86d709SGu Zheng sbi->total_valid_block_count++; 205239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 205339a53e0cSJaegeuk Kim 20540abd675eSChao Yu if (inode) { 20550abd675eSChao Yu if (is_inode) 20560abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 20570abd675eSChao Yu else 20580abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 20590abd675eSChao Yu } 20600abd675eSChao Yu 206141382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 20620abd675eSChao Yu return 0; 20630abd675eSChao Yu 20640abd675eSChao Yu enospc: 2065af033b2aSChao Yu if (is_inode) { 2066af033b2aSChao Yu if (inode) 2067af033b2aSChao Yu dquot_free_inode(inode); 2068af033b2aSChao Yu } else { 20690abd675eSChao Yu dquot_release_reservation_block(inode, 1); 2070af033b2aSChao Yu } 20710abd675eSChao Yu return -ENOSPC; 207239a53e0cSJaegeuk Kim } 207339a53e0cSJaegeuk Kim 207439a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 2075000519f2SChao Yu struct inode *inode, bool is_inode) 207639a53e0cSJaegeuk Kim { 207739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 207839a53e0cSJaegeuk Kim 20799850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 20809850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 208139a53e0cSJaegeuk Kim 2082ef86d709SGu Zheng sbi->total_valid_node_count--; 2083ef86d709SGu Zheng sbi->total_valid_block_count--; 208480d42145SYunlong Song if (sbi->reserved_blocks && 208580d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 208680d42145SYunlong Song sbi->current_reserved_blocks++; 208739a53e0cSJaegeuk Kim 208839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 20890abd675eSChao Yu 2090ea6d7e72SChao Yu if (is_inode) { 2091af033b2aSChao Yu dquot_free_inode(inode); 2092ea6d7e72SChao Yu } else { 2093ea6d7e72SChao Yu if (unlikely(inode->i_blocks == 0)) { 2094dcbb4c10SJoe Perches f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu", 2095ea6d7e72SChao Yu inode->i_ino, 2096ea6d7e72SChao Yu (unsigned long long)inode->i_blocks); 2097ea6d7e72SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 2098ea6d7e72SChao Yu return; 2099ea6d7e72SChao Yu } 21000abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 210139a53e0cSJaegeuk Kim } 2102ea6d7e72SChao Yu } 210339a53e0cSJaegeuk Kim 210439a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 210539a53e0cSJaegeuk Kim { 21068b8343faSJaegeuk Kim return sbi->total_valid_node_count; 210739a53e0cSJaegeuk Kim } 210839a53e0cSJaegeuk Kim 210939a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 211039a53e0cSJaegeuk Kim { 2111513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 211239a53e0cSJaegeuk Kim } 211339a53e0cSJaegeuk Kim 21140e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 211539a53e0cSJaegeuk Kim { 2116513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 211739a53e0cSJaegeuk Kim } 211839a53e0cSJaegeuk Kim 2119513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 212039a53e0cSJaegeuk Kim { 2121513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 212239a53e0cSJaegeuk Kim } 212339a53e0cSJaegeuk Kim 2124a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 2125a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 2126a56c7c6fSJaegeuk Kim { 212782cf4f13SChao Yu struct page *page; 2128cac5a3d8SDongOh Shin 21297fa750a1SArnd Bergmann if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) { 213082cf4f13SChao Yu if (!for_write) 213182cf4f13SChao Yu page = find_get_page_flags(mapping, index, 213282cf4f13SChao Yu FGP_LOCK | FGP_ACCESSED); 213382cf4f13SChao Yu else 213482cf4f13SChao Yu page = find_lock_page(mapping, index); 2135c41f3cc3SJaegeuk Kim if (page) 2136c41f3cc3SJaegeuk Kim return page; 2137c41f3cc3SJaegeuk Kim 213855523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 213955523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 2140c41f3cc3SJaegeuk Kim return NULL; 214155523519SChao Yu } 21427fa750a1SArnd Bergmann } 21437fa750a1SArnd Bergmann 2144a56c7c6fSJaegeuk Kim if (!for_write) 2145a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 2146a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 2147a56c7c6fSJaegeuk Kim } 2148a56c7c6fSJaegeuk Kim 214901eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page( 215001eccef7SChao Yu struct address_space *mapping, pgoff_t index, 215101eccef7SChao Yu int fgp_flags, gfp_t gfp_mask) 215201eccef7SChao Yu { 215301eccef7SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { 215401eccef7SChao Yu f2fs_show_injection_info(FAULT_PAGE_GET); 215501eccef7SChao Yu return NULL; 215601eccef7SChao Yu } 21577fa750a1SArnd Bergmann 215801eccef7SChao Yu return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); 215901eccef7SChao Yu } 216001eccef7SChao Yu 21616e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 21626e2c64adSJaegeuk Kim { 21636e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 21646e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 21656e2c64adSJaegeuk Kim 21666e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 21676e2c64adSJaegeuk Kim kunmap(dst); 21686e2c64adSJaegeuk Kim kunmap(src); 21696e2c64adSJaegeuk Kim } 21706e2c64adSJaegeuk Kim 217139a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 217239a53e0cSJaegeuk Kim { 2173031fa8ccSJaegeuk Kim if (!page) 217439a53e0cSJaegeuk Kim return; 217539a53e0cSJaegeuk Kim 217639a53e0cSJaegeuk Kim if (unlock) { 21779850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 217839a53e0cSJaegeuk Kim unlock_page(page); 217939a53e0cSJaegeuk Kim } 218009cbfeafSKirill A. Shutemov put_page(page); 218139a53e0cSJaegeuk Kim } 218239a53e0cSJaegeuk Kim 218339a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 218439a53e0cSJaegeuk Kim { 218539a53e0cSJaegeuk Kim if (dn->node_page) 218639a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 218739a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 218839a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 218939a53e0cSJaegeuk Kim dn->node_page = NULL; 219039a53e0cSJaegeuk Kim dn->inode_page = NULL; 219139a53e0cSJaegeuk Kim } 219239a53e0cSJaegeuk Kim 219339a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 2194e8512d2eSGu Zheng size_t size) 219539a53e0cSJaegeuk Kim { 2196e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 219739a53e0cSJaegeuk Kim } 219839a53e0cSJaegeuk Kim 21997bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 22007bd59381SGu Zheng gfp_t flags) 22017bd59381SGu Zheng { 22027bd59381SGu Zheng void *entry; 22037bd59381SGu Zheng 220480c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 220580c54505SJaegeuk Kim if (!entry) 220680c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 22077bd59381SGu Zheng return entry; 22087bd59381SGu Zheng } 22097bd59381SGu Zheng 2210d62fe971SChao Yu static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, 2211d62fe971SChao Yu int npages, bool no_fail) 2212740432f8SJaegeuk Kim { 2213740432f8SJaegeuk Kim struct bio *bio; 2214740432f8SJaegeuk Kim 2215d62fe971SChao Yu if (no_fail) { 2216740432f8SJaegeuk Kim /* No failure on bio allocation */ 2217740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 221880c54505SJaegeuk Kim if (!bio) 221980c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 2220740432f8SJaegeuk Kim return bio; 2221740432f8SJaegeuk Kim } 2222d62fe971SChao Yu if (time_to_inject(sbi, FAULT_ALLOC_BIO)) { 2223d62fe971SChao Yu f2fs_show_injection_info(FAULT_ALLOC_BIO); 2224d62fe971SChao Yu return NULL; 2225d62fe971SChao Yu } 22267fa750a1SArnd Bergmann 2227d62fe971SChao Yu return bio_alloc(GFP_KERNEL, npages); 2228d62fe971SChao Yu } 2229740432f8SJaegeuk Kim 22305f9abab4SJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi, int type) 22315f9abab4SJaegeuk Kim { 2232f7dfd9f3SPark Ju Hyung if (sbi->gc_mode == GC_URGENT) 2233f7dfd9f3SPark Ju Hyung return true; 2234f7dfd9f3SPark Ju Hyung 22355f9abab4SJaegeuk Kim if (get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_RD_NODE) || 22365f9abab4SJaegeuk Kim get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) || 2237fef4129eSChao Yu get_pages(sbi, F2FS_WB_CP_DATA) || 2238fef4129eSChao Yu get_pages(sbi, F2FS_DIO_READ) || 223911ac8ef8SJaegeuk Kim get_pages(sbi, F2FS_DIO_WRITE)) 224011ac8ef8SJaegeuk Kim return false; 224111ac8ef8SJaegeuk Kim 224256659ce8SSahitya Tummala if (type != DISCARD_TIME && SM_I(sbi) && SM_I(sbi)->dcc_info && 224311ac8ef8SJaegeuk Kim atomic_read(&SM_I(sbi)->dcc_info->queued_discard)) 224411ac8ef8SJaegeuk Kim return false; 224511ac8ef8SJaegeuk Kim 224611ac8ef8SJaegeuk Kim if (SM_I(sbi) && SM_I(sbi)->fcc_info && 224772691af6SJaegeuk Kim atomic_read(&SM_I(sbi)->fcc_info->queued_flush)) 22485f9abab4SJaegeuk Kim return false; 224911ac8ef8SJaegeuk Kim 22505f9abab4SJaegeuk Kim return f2fs_time_over(sbi, type); 22515f9abab4SJaegeuk Kim } 22525f9abab4SJaegeuk Kim 22539be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 22549be32d72SJaegeuk Kim unsigned long index, void *item) 22559be32d72SJaegeuk Kim { 22569be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 22579be32d72SJaegeuk Kim cond_resched(); 22589be32d72SJaegeuk Kim } 22599be32d72SJaegeuk Kim 226039a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 226139a53e0cSJaegeuk Kim 226239a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 226339a53e0cSJaegeuk Kim { 226445590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 2265cac5a3d8SDongOh Shin 226639a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 226739a53e0cSJaegeuk Kim } 226839a53e0cSJaegeuk Kim 22697a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 22707a2af766SChao Yu { 22717a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 22727a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 22737a2af766SChao Yu } 22747a2af766SChao Yu 227539a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 227639a53e0cSJaegeuk Kim { 227739a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 227839a53e0cSJaegeuk Kim } 227939a53e0cSJaegeuk Kim 22807a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 22817a2af766SChao Yu static inline block_t datablock_addr(struct inode *inode, 22827a2af766SChao Yu struct page *node_page, unsigned int offset) 228339a53e0cSJaegeuk Kim { 228439a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 228539a53e0cSJaegeuk Kim __le32 *addr_array; 22867a2af766SChao Yu int base = 0; 22877a2af766SChao Yu bool is_inode = IS_INODE(node_page); 2288cac5a3d8SDongOh Shin 228945590710SGu Zheng raw_node = F2FS_NODE(node_page); 22907a2af766SChao Yu 22917a2af766SChao Yu /* from GC path only */ 2292979f492fSLiFan if (is_inode) { 2293979f492fSLiFan if (!inode) 22947a2af766SChao Yu base = offset_in_addr(&raw_node->i); 2295979f492fSLiFan else if (f2fs_has_extra_attr(inode)) 22967a2af766SChao Yu base = get_extra_isize(inode); 22977a2af766SChao Yu } 22987a2af766SChao Yu 229939a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 23007a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 230139a53e0cSJaegeuk Kim } 230239a53e0cSJaegeuk Kim 230339a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 230439a53e0cSJaegeuk Kim { 230539a53e0cSJaegeuk Kim int mask; 230639a53e0cSJaegeuk Kim 230739a53e0cSJaegeuk Kim addr += (nr >> 3); 230839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 230939a53e0cSJaegeuk Kim return mask & *addr; 231039a53e0cSJaegeuk Kim } 231139a53e0cSJaegeuk Kim 2312a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 2313a66cdd98SJaegeuk Kim { 2314a66cdd98SJaegeuk Kim int mask; 2315a66cdd98SJaegeuk Kim 2316a66cdd98SJaegeuk Kim addr += (nr >> 3); 2317a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2318a66cdd98SJaegeuk Kim *addr |= mask; 2319a66cdd98SJaegeuk Kim } 2320a66cdd98SJaegeuk Kim 2321a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 2322a66cdd98SJaegeuk Kim { 2323a66cdd98SJaegeuk Kim int mask; 2324a66cdd98SJaegeuk Kim 2325a66cdd98SJaegeuk Kim addr += (nr >> 3); 2326a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2327a66cdd98SJaegeuk Kim *addr &= ~mask; 2328a66cdd98SJaegeuk Kim } 2329a66cdd98SJaegeuk Kim 233052aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 233139a53e0cSJaegeuk Kim { 233239a53e0cSJaegeuk Kim int mask; 233339a53e0cSJaegeuk Kim int ret; 233439a53e0cSJaegeuk Kim 233539a53e0cSJaegeuk Kim addr += (nr >> 3); 233639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 233739a53e0cSJaegeuk Kim ret = mask & *addr; 233839a53e0cSJaegeuk Kim *addr |= mask; 233939a53e0cSJaegeuk Kim return ret; 234039a53e0cSJaegeuk Kim } 234139a53e0cSJaegeuk Kim 234252aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 234339a53e0cSJaegeuk Kim { 234439a53e0cSJaegeuk Kim int mask; 234539a53e0cSJaegeuk Kim int ret; 234639a53e0cSJaegeuk Kim 234739a53e0cSJaegeuk Kim addr += (nr >> 3); 234839a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 234939a53e0cSJaegeuk Kim ret = mask & *addr; 235039a53e0cSJaegeuk Kim *addr &= ~mask; 235139a53e0cSJaegeuk Kim return ret; 235239a53e0cSJaegeuk Kim } 235339a53e0cSJaegeuk Kim 2354c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 2355c6ac4c0eSGu Zheng { 2356c6ac4c0eSGu Zheng int mask; 2357c6ac4c0eSGu Zheng 2358c6ac4c0eSGu Zheng addr += (nr >> 3); 2359c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 2360c6ac4c0eSGu Zheng *addr ^= mask; 2361c6ac4c0eSGu Zheng } 2362c6ac4c0eSGu Zheng 236359c84408SChao Yu /* 236436098557SEric Biggers * On-disk inode flags (f2fs_inode::i_flags) 236559c84408SChao Yu */ 236659c84408SChao Yu #define F2FS_SYNC_FL 0x00000008 /* Synchronous updates */ 236759c84408SChao Yu #define F2FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ 236859c84408SChao Yu #define F2FS_APPEND_FL 0x00000020 /* writes to file may only append */ 236959c84408SChao Yu #define F2FS_NODUMP_FL 0x00000040 /* do not dump file */ 237059c84408SChao Yu #define F2FS_NOATIME_FL 0x00000080 /* do not update atime */ 237159c84408SChao Yu #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ 237259c84408SChao Yu #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 237359c84408SChao Yu #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 23742c2eb7a3SDaniel Rosenberg #define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */ 237559c84408SChao Yu 237659c84408SChao Yu /* Flags that should be inherited by new inodes from their parent. */ 237736098557SEric Biggers #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \ 23782c2eb7a3SDaniel Rosenberg F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 23792c2eb7a3SDaniel Rosenberg F2FS_CASEFOLD_FL) 238059c84408SChao Yu 238159c84408SChao Yu /* Flags that are appropriate for regular files (all but dir-specific ones). */ 23822c2eb7a3SDaniel Rosenberg #define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 23832c2eb7a3SDaniel Rosenberg F2FS_CASEFOLD_FL)) 238459c84408SChao Yu 238559c84408SChao Yu /* Flags that are appropriate for non-directories/regular files. */ 238659c84408SChao Yu #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL) 23875c57132eSChao Yu 23885c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 23895c57132eSChao Yu { 23905c57132eSChao Yu if (S_ISDIR(mode)) 23915c57132eSChao Yu return flags; 23925c57132eSChao Yu else if (S_ISREG(mode)) 23935c57132eSChao Yu return flags & F2FS_REG_FLMASK; 23945c57132eSChao Yu else 23955c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 23965c57132eSChao Yu } 23975c57132eSChao Yu 239839a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 239939a53e0cSJaegeuk Kim enum { 240039a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 2401b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 240226de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 2403ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 240439a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 240539a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 240639a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 2407c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 2408c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 2409444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 24101001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 241134d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 2412fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 2413fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 241488b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 241588b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 24165fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 241702a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 24183c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 24191e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 2420b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 2421510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 2422d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 2423c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 2424dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 2425ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 24267a2af766SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 24275c57132eSChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 24281ad71a27SJaegeuk Kim FI_PIN_FILE, /* indicate file should not be gced */ 24292ef79ecbSChao Yu FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */ 243039a53e0cSJaegeuk Kim }; 243139a53e0cSJaegeuk Kim 2432205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2433205b9822SJaegeuk Kim int flag, bool set) 243439a53e0cSJaegeuk Kim { 2435205b9822SJaegeuk Kim switch (flag) { 2436205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2437205b9822SJaegeuk Kim case FI_INLINE_DATA: 2438205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 24399ac1e2d8SDaeho Jeong case FI_NEW_INODE: 2440205b9822SJaegeuk Kim if (set) 2441205b9822SJaegeuk Kim return; 2442f5d5510eSJaegeuk Kim /* fall through */ 2443205b9822SJaegeuk Kim case FI_DATA_EXIST: 2444205b9822SJaegeuk Kim case FI_INLINE_DOTS: 24451ad71a27SJaegeuk Kim case FI_PIN_FILE: 24467c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2447205b9822SJaegeuk Kim } 244839a53e0cSJaegeuk Kim } 244939a53e0cSJaegeuk Kim 245091942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 245139a53e0cSJaegeuk Kim { 245291942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 245391942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 2454205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 245539a53e0cSJaegeuk Kim } 245639a53e0cSJaegeuk Kim 245791942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 245839a53e0cSJaegeuk Kim { 245991942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 246039a53e0cSJaegeuk Kim } 246139a53e0cSJaegeuk Kim 246291942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 246339a53e0cSJaegeuk Kim { 246491942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 246591942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 2466205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 246739a53e0cSJaegeuk Kim } 246839a53e0cSJaegeuk Kim 246991942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2470444c580fSJaegeuk Kim { 247191942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 247291942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 24737c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 247439a53e0cSJaegeuk Kim } 247539a53e0cSJaegeuk Kim 2476a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2477a1961246SJaegeuk Kim { 2478a1961246SJaegeuk Kim if (inc) 2479a1961246SJaegeuk Kim inc_nlink(inode); 2480a1961246SJaegeuk Kim else 2481a1961246SJaegeuk Kim drop_nlink(inode); 24827c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2483a1961246SJaegeuk Kim } 2484a1961246SJaegeuk Kim 24858edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 24860abd675eSChao Yu block_t diff, bool add, bool claim) 24878edd03c8SJaegeuk Kim { 248826de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 248926de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 249026de9b11SJaegeuk Kim 24910abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 24920abd675eSChao Yu if (add) { 24930abd675eSChao Yu if (claim) 24940abd675eSChao Yu dquot_claim_block(inode, diff); 24950abd675eSChao Yu else 24960abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 24970abd675eSChao Yu } else { 24980abd675eSChao Yu dquot_free_block(inode, diff); 24990abd675eSChao Yu } 25000abd675eSChao Yu 25017c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 250226de9b11SJaegeuk Kim if (clean || recover) 250326de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 25048edd03c8SJaegeuk Kim } 25058edd03c8SJaegeuk Kim 2506fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2507fc9581c8SJaegeuk Kim { 250826de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 250926de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 251026de9b11SJaegeuk Kim 2511fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2512fc9581c8SJaegeuk Kim return; 2513fc9581c8SJaegeuk Kim 2514fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 25157c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 251626de9b11SJaegeuk Kim if (clean || recover) 251726de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 251826de9b11SJaegeuk Kim } 251926de9b11SJaegeuk Kim 2520205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2521205b9822SJaegeuk Kim { 2522205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 25237c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2524205b9822SJaegeuk Kim } 2525205b9822SJaegeuk Kim 25261ad71a27SJaegeuk Kim static inline void f2fs_i_gc_failures_write(struct inode *inode, 25271ad71a27SJaegeuk Kim unsigned int count) 25281ad71a27SJaegeuk Kim { 25292ef79ecbSChao Yu F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count; 25301ad71a27SJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 25311ad71a27SJaegeuk Kim } 25321ad71a27SJaegeuk Kim 2533205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2534205b9822SJaegeuk Kim { 2535205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 25367c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2537205b9822SJaegeuk Kim } 2538205b9822SJaegeuk Kim 2539205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2540205b9822SJaegeuk Kim { 2541205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 25427c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2543205b9822SJaegeuk Kim } 2544205b9822SJaegeuk Kim 254591942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2546444c580fSJaegeuk Kim { 2547205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2548205b9822SJaegeuk Kim 2549444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 2550205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 25511001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 2552205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 255334d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 2554205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 2555b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 2556205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 2557510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 2558205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 25597a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 25607a2af766SChao Yu set_bit(FI_EXTRA_ATTR, &fi->flags); 25611ad71a27SJaegeuk Kim if (ri->i_inline & F2FS_PIN_FILE) 25621ad71a27SJaegeuk Kim set_bit(FI_PIN_FILE, &fi->flags); 2563444c580fSJaegeuk Kim } 2564444c580fSJaegeuk Kim 256591942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2566444c580fSJaegeuk Kim { 2567444c580fSJaegeuk Kim ri->i_inline = 0; 2568444c580fSJaegeuk Kim 256991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2570444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 257191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 25721001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 257391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 257434d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 257591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2576b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 257791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2578510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 25797a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 25807a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 25811ad71a27SJaegeuk Kim if (is_inode_flag_set(inode, FI_PIN_FILE)) 25821ad71a27SJaegeuk Kim ri->i_inline |= F2FS_PIN_FILE; 25837a2af766SChao Yu } 25847a2af766SChao Yu 25857a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 25867a2af766SChao Yu { 25877a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2588444c580fSJaegeuk Kim } 2589444c580fSJaegeuk Kim 2590987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2591987c7c31SChao Yu { 259291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2593987c7c31SChao Yu } 2594987c7c31SChao Yu 259581ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2596de93653fSJaegeuk Kim { 2597d02a6e61SChao Yu unsigned int addrs = CUR_ADDRS_PER_INODE(inode) - 2598d02a6e61SChao Yu get_inline_xattr_addrs(inode); 2599d02a6e61SChao Yu return ALIGN_DOWN(addrs, 1); 2600d02a6e61SChao Yu } 2601d02a6e61SChao Yu 2602d02a6e61SChao Yu static inline unsigned int addrs_per_block(struct inode *inode) 2603d02a6e61SChao Yu { 2604d02a6e61SChao Yu return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, 1); 2605de93653fSJaegeuk Kim } 2606de93653fSJaegeuk Kim 26076afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page) 260865985d93SJaegeuk Kim { 2609695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2610cac5a3d8SDongOh Shin 261165985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 2612b323fd28SChao Yu get_inline_xattr_addrs(inode)]); 261365985d93SJaegeuk Kim } 261465985d93SJaegeuk Kim 261565985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 261665985d93SJaegeuk Kim { 2617622927f3SChao Yu if (f2fs_has_inline_xattr(inode)) 26186afc662eSChao Yu return get_inline_xattr_addrs(inode) * sizeof(__le32); 2619622927f3SChao Yu return 0; 262065985d93SJaegeuk Kim } 262165985d93SJaegeuk Kim 26220dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 26230dbdc2aeSJaegeuk Kim { 262491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 26250dbdc2aeSJaegeuk Kim } 26260dbdc2aeSJaegeuk Kim 2627b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2628b3d208f9SJaegeuk Kim { 262991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2630b3d208f9SJaegeuk Kim } 2631b3d208f9SJaegeuk Kim 2632510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2633510022a8SJaegeuk Kim { 263491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2635510022a8SJaegeuk Kim } 2636510022a8SJaegeuk Kim 26371ad71a27SJaegeuk Kim static inline bool f2fs_is_pinned_file(struct inode *inode) 26381ad71a27SJaegeuk Kim { 26391ad71a27SJaegeuk Kim return is_inode_flag_set(inode, FI_PIN_FILE); 26401ad71a27SJaegeuk Kim } 26411ad71a27SJaegeuk Kim 264288b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 264388b88a66SJaegeuk Kim { 264491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 264588b88a66SJaegeuk Kim } 264688b88a66SJaegeuk Kim 26475fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 26485fe45743SChao Yu { 26495fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 26505fe45743SChao Yu } 26515fe45743SChao Yu 265202a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 265302a1335fSJaegeuk Kim { 265491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 265502a1335fSJaegeuk Kim } 265602a1335fSJaegeuk Kim 26573c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 26583c6c2bebSJaegeuk Kim { 265991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 26603c6c2bebSJaegeuk Kim } 26613c6c2bebSJaegeuk Kim 26621e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 26631e84371fSJaegeuk Kim { 266491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 26651e84371fSJaegeuk Kim } 26661e84371fSJaegeuk Kim 2667f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 26681001b347SHuajun Li { 2669695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 26707a2af766SChao Yu int extra_size = get_extra_isize(inode); 2671cac5a3d8SDongOh Shin 26727a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 26731001b347SHuajun Li } 26741001b347SHuajun Li 267534d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 267634d67debSChao Yu { 267791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 267834d67debSChao Yu } 267934d67debSChao Yu 2680b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2681b5492af7SJaegeuk Kim { 2682b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2683b5492af7SJaegeuk Kim } 2684b5492af7SJaegeuk Kim 2685b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2686b5492af7SJaegeuk Kim { 2687b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 26887c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2689b5492af7SJaegeuk Kim } 2690b5492af7SJaegeuk Kim 2691b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2692b5492af7SJaegeuk Kim { 2693b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 26947c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2695b5492af7SJaegeuk Kim } 2696b5492af7SJaegeuk Kim 269726787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 269826787236SJaegeuk Kim { 2699a0d00fadSChao Yu bool ret; 2700a0d00fadSChao Yu 270126787236SJaegeuk Kim if (dsync) { 270226787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 270326787236SJaegeuk Kim 270426787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 270526787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 270626787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 270726787236SJaegeuk Kim return ret; 270826787236SJaegeuk Kim } 270926787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 271026787236SJaegeuk Kim file_keep_isize(inode) || 2711235831d7SJunling Zheng i_size_read(inode) & ~PAGE_MASK) 271226787236SJaegeuk Kim return false; 2713a0d00fadSChao Yu 271424b81dfcSArnd Bergmann if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime)) 2715214c2461SJaegeuk Kim return false; 271624b81dfcSArnd Bergmann if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime)) 2717214c2461SJaegeuk Kim return false; 271824b81dfcSArnd Bergmann if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime)) 2719214c2461SJaegeuk Kim return false; 272024b81dfcSArnd Bergmann if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3, 2721214c2461SJaegeuk Kim &F2FS_I(inode)->i_crtime)) 2722214c2461SJaegeuk Kim return false; 2723214c2461SJaegeuk Kim 2724a0d00fadSChao Yu down_read(&F2FS_I(inode)->i_sem); 2725a0d00fadSChao Yu ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 2726a0d00fadSChao Yu up_read(&F2FS_I(inode)->i_sem); 2727a0d00fadSChao Yu 2728a0d00fadSChao Yu return ret; 2729267378d4SChao Yu } 2730267378d4SChao Yu 2731deeedd71SChao Yu static inline bool f2fs_readonly(struct super_block *sb) 273277888c1eSJaegeuk Kim { 2733deeedd71SChao Yu return sb_rdonly(sb); 273477888c1eSJaegeuk Kim } 273577888c1eSJaegeuk Kim 2736744602cfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 2737744602cfSJaegeuk Kim { 2738aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 2739744602cfSJaegeuk Kim } 2740744602cfSJaegeuk Kim 2741eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2742eaa693f4SJaegeuk Kim { 2743eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2744eaa693f4SJaegeuk Kim return true; 2745eaa693f4SJaegeuk Kim 2746eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2747eaa693f4SJaegeuk Kim return true; 2748eaa693f4SJaegeuk Kim 2749eaa693f4SJaegeuk Kim return false; 2750eaa693f4SJaegeuk Kim } 2751eaa693f4SJaegeuk Kim 27523e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 27533e72f721SJaegeuk Kim { 2754e4589fa5SSahitya Tummala struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2755e4589fa5SSahitya Tummala 2756e4589fa5SSahitya Tummala if (!test_opt(sbi, EXTENT_CACHE) || 275791942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 27583e72f721SJaegeuk Kim return false; 27593e72f721SJaegeuk Kim 2760e4589fa5SSahitya Tummala /* 2761e4589fa5SSahitya Tummala * for recovered files during mount do not create extents 2762e4589fa5SSahitya Tummala * if shrinker is not registered. 2763e4589fa5SSahitya Tummala */ 2764e4589fa5SSahitya Tummala if (list_empty(&sbi->s_list)) 2765e4589fa5SSahitya Tummala return false; 2766e4589fa5SSahitya Tummala 2767886f56f9SAl Viro return S_ISREG(inode->i_mode); 27683e72f721SJaegeuk Kim } 27693e72f721SJaegeuk Kim 27701ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 27711ecc0c5cSChao Yu size_t size, gfp_t flags) 27720414b004SJaegeuk Kim { 27735222595dSJaegeuk Kim void *ret; 27745222595dSJaegeuk Kim 277555523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 277655523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 27772c63feadSJaegeuk Kim return NULL; 277855523519SChao Yu } 27797fa750a1SArnd Bergmann 27805222595dSJaegeuk Kim ret = kmalloc(size, flags); 27815222595dSJaegeuk Kim if (ret) 27825222595dSJaegeuk Kim return ret; 27835222595dSJaegeuk Kim 27845222595dSJaegeuk Kim return kvmalloc(size, flags); 27850414b004SJaegeuk Kim } 27860414b004SJaegeuk Kim 2787acbf054dSChao Yu static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, 2788acbf054dSChao Yu size_t size, gfp_t flags) 2789acbf054dSChao Yu { 2790acbf054dSChao Yu return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); 2791acbf054dSChao Yu } 2792acbf054dSChao Yu 2793628b3d14SChao Yu static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, 2794628b3d14SChao Yu size_t size, gfp_t flags) 2795628b3d14SChao Yu { 2796628b3d14SChao Yu if (time_to_inject(sbi, FAULT_KVMALLOC)) { 2797628b3d14SChao Yu f2fs_show_injection_info(FAULT_KVMALLOC); 2798628b3d14SChao Yu return NULL; 2799628b3d14SChao Yu } 28007fa750a1SArnd Bergmann 2801628b3d14SChao Yu return kvmalloc(size, flags); 2802628b3d14SChao Yu } 2803628b3d14SChao Yu 2804628b3d14SChao Yu static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi, 2805628b3d14SChao Yu size_t size, gfp_t flags) 2806628b3d14SChao Yu { 2807628b3d14SChao Yu return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO); 2808628b3d14SChao Yu } 2809628b3d14SChao Yu 28107a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 2811f2470371SChao Yu { 28127a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 2813f2470371SChao Yu } 2814f2470371SChao Yu 28156afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode) 28166afc662eSChao Yu { 28176afc662eSChao Yu return F2FS_I(inode)->i_inline_xattr_size; 28186afc662eSChao Yu } 28196afc662eSChao Yu 28204d57b86dSChao Yu #define f2fs_get_inode_mode(i) \ 282191942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 2822a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 2823a6dda0e6SChristoph Hellwig 28247a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 28257a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 28267a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 28277a2af766SChao Yu 28285c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 28295c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 28302f84babfSSheng Yong ((offsetof(typeof(*(f2fs_inode)), field) + \ 28315c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 28322f84babfSSheng Yong <= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize))) \ 28335c57132eSChao Yu 2834b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 2835b0af6d49SChao Yu { 2836b0af6d49SChao Yu int i; 2837b0af6d49SChao Yu 2838b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2839b0af6d49SChao Yu for (i = 0; i < NR_IO_TYPE; i++) 2840b0af6d49SChao Yu sbi->write_iostat[i] = 0; 2841b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2842b0af6d49SChao Yu } 2843b0af6d49SChao Yu 2844b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 2845b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 2846b0af6d49SChao Yu { 2847b0af6d49SChao Yu if (!sbi->iostat_enable) 2848b0af6d49SChao Yu return; 2849b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2850b0af6d49SChao Yu sbi->write_iostat[type] += io_bytes; 2851b0af6d49SChao Yu 2852b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 2853b0af6d49SChao Yu sbi->write_iostat[APP_BUFFERED_IO] = 2854b0af6d49SChao Yu sbi->write_iostat[APP_WRITE_IO] - 2855b0af6d49SChao Yu sbi->write_iostat[APP_DIRECT_IO]; 2856b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2857b0af6d49SChao Yu } 2858b0af6d49SChao Yu 28592c70c5e3SChao Yu #define __is_large_section(sbi) ((sbi)->segs_per_sec > 1) 28602c70c5e3SChao Yu 28616dc3a126SChao Yu #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META) 2862c9b60788SChao Yu 2863e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 2864e1da7872SChao Yu block_t blkaddr, int type); 2865e1da7872SChao Yu static inline void verify_blkaddr(struct f2fs_sb_info *sbi, 2866e1da7872SChao Yu block_t blkaddr, int type) 2867e1da7872SChao Yu { 2868e1da7872SChao Yu if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) { 2869dcbb4c10SJoe Perches f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.", 2870e1da7872SChao Yu blkaddr, type); 2871e1da7872SChao Yu f2fs_bug_on(sbi, 1); 2872e1da7872SChao Yu } 2873e1da7872SChao Yu } 2874e1da7872SChao Yu 2875e1da7872SChao Yu static inline bool __is_valid_data_blkaddr(block_t blkaddr) 28767b525dd0SChao Yu { 28777b525dd0SChao Yu if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) 28787b525dd0SChao Yu return false; 28797b525dd0SChao Yu return true; 28807b525dd0SChao Yu } 28817b525dd0SChao Yu 2882240a5915SChao Yu static inline void f2fs_set_page_private(struct page *page, 2883240a5915SChao Yu unsigned long data) 2884240a5915SChao Yu { 2885240a5915SChao Yu if (PagePrivate(page)) 2886240a5915SChao Yu return; 2887240a5915SChao Yu 2888240a5915SChao Yu get_page(page); 2889240a5915SChao Yu SetPagePrivate(page); 2890240a5915SChao Yu set_page_private(page, data); 2891240a5915SChao Yu } 2892240a5915SChao Yu 2893240a5915SChao Yu static inline void f2fs_clear_page_private(struct page *page) 2894240a5915SChao Yu { 2895240a5915SChao Yu if (!PagePrivate(page)) 2896240a5915SChao Yu return; 2897240a5915SChao Yu 2898240a5915SChao Yu set_page_private(page, 0); 2899240a5915SChao Yu ClearPagePrivate(page); 2900240a5915SChao Yu f2fs_put_page(page, 0); 2901240a5915SChao Yu } 2902240a5915SChao Yu 290339a53e0cSJaegeuk Kim /* 290439a53e0cSJaegeuk Kim * file.c 290539a53e0cSJaegeuk Kim */ 2906cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 29074d57b86dSChao Yu void f2fs_truncate_data_blocks(struct dnode_of_data *dn); 2908c42d28ceSChao Yu int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock); 2909cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2910a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2911a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2912cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 29134d57b86dSChao Yu int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 29144d57b86dSChao Yu void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2915c4020b2dSChao Yu int f2fs_precache_extents(struct inode *inode); 2916cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2917cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 291878130819SChao Yu int f2fs_transfer_project_quota(struct inode *inode, kprojid_t kprojid); 29191ad71a27SJaegeuk Kim int f2fs_pin_file_control(struct inode *inode, bool inc); 292039a53e0cSJaegeuk Kim 292139a53e0cSJaegeuk Kim /* 292239a53e0cSJaegeuk Kim * inode.c 292339a53e0cSJaegeuk Kim */ 2924cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2925704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 2926704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 2927cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2928cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 29294d57b86dSChao Yu int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 29304d57b86dSChao Yu void f2fs_update_inode(struct inode *inode, struct page *node_page); 29314d57b86dSChao Yu void f2fs_update_inode_page(struct inode *inode); 2932cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2933cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 29344d57b86dSChao Yu void f2fs_handle_failed_inode(struct inode *inode); 293539a53e0cSJaegeuk Kim 293639a53e0cSJaegeuk Kim /* 293739a53e0cSJaegeuk Kim * namei.c 293839a53e0cSJaegeuk Kim */ 29394d57b86dSChao Yu int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, 2940b6a06cbbSChao Yu bool hot, bool set); 294139a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 294239a53e0cSJaegeuk Kim 29432c2eb7a3SDaniel Rosenberg extern int f2fs_ci_compare(const struct inode *parent, 29442c2eb7a3SDaniel Rosenberg const struct qstr *name, 2945950d47f2SChao Yu const struct qstr *entry, 2946950d47f2SChao Yu bool quick); 29472c2eb7a3SDaniel Rosenberg 294839a53e0cSJaegeuk Kim /* 294939a53e0cSJaegeuk Kim * dir.c 295039a53e0cSJaegeuk Kim */ 29514d57b86dSChao Yu unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de); 29524d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_target_dentry(struct fscrypt_name *fname, 2953cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2954cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2955cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2956cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 29574d57b86dSChao Yu void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent, 2958cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 29594d57b86dSChao Yu struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir, 2960cac5a3d8SDongOh Shin const struct qstr *new_name, 2961cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 29624d57b86dSChao Yu void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode, 2963cac5a3d8SDongOh Shin unsigned int current_depth); 29644d57b86dSChao Yu int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots); 2965cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2966cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2967cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2968cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2969cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2970cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2971cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2972cac5a3d8SDongOh Shin struct page **page); 2973cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2974cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2975cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2976cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2977cac5a3d8SDongOh Shin unsigned int bit_pos); 2978cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2979cac5a3d8SDongOh Shin const struct qstr *orig_name, 2980cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 29814d57b86dSChao Yu int f2fs_add_dentry(struct inode *dir, struct fscrypt_name *fname, 2982cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 29834d57b86dSChao Yu int f2fs_do_add_link(struct inode *dir, const struct qstr *name, 2984cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2985cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2986cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2987cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2988cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 298939a53e0cSJaegeuk Kim 2990b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2991b7f7a5e0SAl Viro { 29924d57b86dSChao Yu return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2993510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2994b7f7a5e0SAl Viro } 2995b7f7a5e0SAl Viro 299639a53e0cSJaegeuk Kim /* 299739a53e0cSJaegeuk Kim * super.c 299839a53e0cSJaegeuk Kim */ 2999cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 3000cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 3001ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); 3002af033b2aSChao Yu int f2fs_quota_sync(struct super_block *sb, int type); 30034b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 3004cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 3005cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 30064d57b86dSChao Yu int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); 300739a53e0cSJaegeuk Kim 300839a53e0cSJaegeuk Kim /* 300939a53e0cSJaegeuk Kim * hash.c 301039a53e0cSJaegeuk Kim */ 30112c2eb7a3SDaniel Rosenberg f2fs_hash_t f2fs_dentry_hash(const struct inode *dir, 30122c2eb7a3SDaniel Rosenberg const struct qstr *name_info, struct fscrypt_name *fname); 301339a53e0cSJaegeuk Kim 301439a53e0cSJaegeuk Kim /* 301539a53e0cSJaegeuk Kim * node.c 301639a53e0cSJaegeuk Kim */ 301739a53e0cSJaegeuk Kim struct dnode_of_data; 301839a53e0cSJaegeuk Kim struct node_info; 301939a53e0cSJaegeuk Kim 30204d57b86dSChao Yu int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid); 30214d57b86dSChao Yu bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type); 302250fa53ecSChao Yu bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page); 302350fa53ecSChao Yu void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi); 302450fa53ecSChao Yu void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page); 302550fa53ecSChao Yu void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi); 30264d57b86dSChao Yu int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 30274d57b86dSChao Yu bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 30284d57b86dSChao Yu bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 30297735730dSChao Yu int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, 30304d57b86dSChao Yu struct node_info *ni); 30314d57b86dSChao Yu pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 30324d57b86dSChao Yu int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 30334d57b86dSChao Yu int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from); 30344d57b86dSChao Yu int f2fs_truncate_xattr_node(struct inode *inode); 303550fa53ecSChao Yu int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, 303650fa53ecSChao Yu unsigned int seq_id); 30374d57b86dSChao Yu int f2fs_remove_inode_page(struct inode *inode); 30384d57b86dSChao Yu struct page *f2fs_new_inode_page(struct inode *inode); 30394d57b86dSChao Yu struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs); 30404d57b86dSChao Yu void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 30414d57b86dSChao Yu struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 30424d57b86dSChao Yu struct page *f2fs_get_node_page_ra(struct page *parent, int start); 304348018b4cSChao Yu int f2fs_move_node_page(struct page *node_page, int gc_type); 30444d57b86dSChao Yu int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 304550fa53ecSChao Yu struct writeback_control *wbc, bool atomic, 304650fa53ecSChao Yu unsigned int *seq_id); 30474d57b86dSChao Yu int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, 30484d57b86dSChao Yu struct writeback_control *wbc, 3049b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 3050e2374015SChao Yu int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 30514d57b86dSChao Yu bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 30524d57b86dSChao Yu void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 30534d57b86dSChao Yu void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 30544d57b86dSChao Yu int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 30554d57b86dSChao Yu void f2fs_recover_inline_xattr(struct inode *inode, struct page *page); 30564d57b86dSChao Yu int f2fs_recover_xattr_data(struct inode *inode, struct page *page); 30574d57b86dSChao Yu int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 30587735730dSChao Yu int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, 3059cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 3060edc55aafSJaegeuk Kim int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 30614d57b86dSChao Yu int f2fs_build_node_manager(struct f2fs_sb_info *sbi); 30624d57b86dSChao Yu void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi); 30634d57b86dSChao Yu int __init f2fs_create_node_manager_caches(void); 30644d57b86dSChao Yu void f2fs_destroy_node_manager_caches(void); 306539a53e0cSJaegeuk Kim 306639a53e0cSJaegeuk Kim /* 306739a53e0cSJaegeuk Kim * segment.c 306839a53e0cSJaegeuk Kim */ 30694d57b86dSChao Yu bool f2fs_need_SSR(struct f2fs_sb_info *sbi); 30704d57b86dSChao Yu void f2fs_register_inmem_page(struct inode *inode, struct page *page); 30714d57b86dSChao Yu void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure); 30724d57b86dSChao Yu void f2fs_drop_inmem_pages(struct inode *inode); 30734d57b86dSChao Yu void f2fs_drop_inmem_page(struct inode *inode, struct page *page); 30744d57b86dSChao Yu int f2fs_commit_inmem_pages(struct inode *inode); 3075cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 3076cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 307739d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 30784d57b86dSChao Yu int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi); 30791228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); 30804d57b86dSChao Yu void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 30814d57b86dSChao Yu void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 30824d57b86dSChao Yu bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 30834d57b86dSChao Yu void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi); 30844d57b86dSChao Yu void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi); 308503f2c02dSJaegeuk Kim bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi); 30864d57b86dSChao Yu void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, 30874d57b86dSChao Yu struct cp_control *cpc); 30884354994fSDaniel Rosenberg void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi); 30894d3aed70SDaniel Rosenberg block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi); 30904d3aed70SDaniel Rosenberg int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable); 30914d57b86dSChao Yu void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi); 30924d57b86dSChao Yu int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 309304f0b2eaSQiuyang Sun void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, 309404f0b2eaSQiuyang Sun unsigned int start, unsigned int end); 30954d57b86dSChao Yu void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi); 3096cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 30974d57b86dSChao Yu bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, 30984d57b86dSChao Yu struct cp_control *cpc); 30994d57b86dSChao Yu struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 31004d57b86dSChao Yu void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src, 31014d57b86dSChao Yu block_t blk_addr); 31024d57b86dSChao Yu void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 3103b0af6d49SChao Yu enum iostat_type io_type); 31044d57b86dSChao Yu void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio); 31054d57b86dSChao Yu void f2fs_outplace_write_data(struct dnode_of_data *dn, 31064d57b86dSChao Yu struct f2fs_io_info *fio); 31074d57b86dSChao Yu int f2fs_inplace_write_data(struct f2fs_io_info *fio); 31084d57b86dSChao Yu void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 3109cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 3110cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 3111cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 3112cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 3113cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 3114cac5a3d8SDongOh Shin bool recover_newaddr); 31154d57b86dSChao Yu void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 3116cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 3117fb830fc5SChao Yu struct f2fs_summary *sum, int type, 3118fb830fc5SChao Yu struct f2fs_io_info *fio, bool add_list); 3119cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 3120bae0ee7aSChao Yu enum page_type type, bool ordered, bool locked); 31210ded69f6SJaegeuk Kim void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr); 31221e78e8bdSSahitya Tummala void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr, 31231e78e8bdSSahitya Tummala block_t len); 31244d57b86dSChao Yu void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 31254d57b86dSChao Yu void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 31264d57b86dSChao Yu int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 3127cac5a3d8SDongOh Shin unsigned int val, int alloc); 31284d57b86dSChao Yu void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 31294d57b86dSChao Yu int f2fs_build_segment_manager(struct f2fs_sb_info *sbi); 31304d57b86dSChao Yu void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi); 31314d57b86dSChao Yu int __init f2fs_create_segment_manager_caches(void); 31324d57b86dSChao Yu void f2fs_destroy_segment_manager_caches(void); 31334d57b86dSChao Yu int f2fs_rw_hint_to_seg_type(enum rw_hint hint); 31344d57b86dSChao Yu enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, 31354d57b86dSChao Yu enum page_type type, enum temp_type temp); 313639a53e0cSJaegeuk Kim 313739a53e0cSJaegeuk Kim /* 313839a53e0cSJaegeuk Kim * checkpoint.c 313939a53e0cSJaegeuk Kim */ 3140cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 31414d57b86dSChao Yu struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 31424d57b86dSChao Yu struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 31437735730dSChao Yu struct page *f2fs_get_meta_page_nofail(struct f2fs_sb_info *sbi, pgoff_t index); 31444d57b86dSChao Yu struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 3145e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 31464d57b86dSChao Yu block_t blkaddr, int type); 31474d57b86dSChao Yu int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 3148cac5a3d8SDongOh Shin int type, bool sync); 31494d57b86dSChao Yu void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 31504d57b86dSChao Yu long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 3151b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 31524d57b86dSChao Yu void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 31534d57b86dSChao Yu void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 31544d57b86dSChao Yu void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all); 31554d57b86dSChao Yu bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 31564d57b86dSChao Yu void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 315739d787beSChao Yu unsigned int devidx, int type); 31584d57b86dSChao Yu bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 315939d787beSChao Yu unsigned int devidx, int type); 3160cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 31614d57b86dSChao Yu int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi); 31624d57b86dSChao Yu void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi); 31634d57b86dSChao Yu void f2fs_add_orphan_inode(struct inode *inode); 31644d57b86dSChao Yu void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 31654d57b86dSChao Yu int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi); 31664d57b86dSChao Yu int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi); 31674d57b86dSChao Yu void f2fs_update_dirty_page(struct inode *inode, struct page *page); 31684d57b86dSChao Yu void f2fs_remove_dirty_inode(struct inode *inode); 31694d57b86dSChao Yu int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 317050fa53ecSChao Yu void f2fs_wait_on_all_pages_writeback(struct f2fs_sb_info *sbi); 31714d57b86dSChao Yu int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 31724d57b86dSChao Yu void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi); 31734d57b86dSChao Yu int __init f2fs_create_checkpoint_caches(void); 31744d57b86dSChao Yu void f2fs_destroy_checkpoint_caches(void); 317539a53e0cSJaegeuk Kim 317639a53e0cSJaegeuk Kim /* 317739a53e0cSJaegeuk Kim * data.c 317839a53e0cSJaegeuk Kim */ 31796dbb1796SEric Biggers int f2fs_init_post_read_processing(void); 31806dbb1796SEric Biggers void f2fs_destroy_post_read_processing(void); 3181b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 3182b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 3183bab475c5SChao Yu struct inode *inode, struct page *page, 3184bab475c5SChao Yu nid_t ino, enum page_type type); 3185b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 3186cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 31878648de2cSChao Yu int f2fs_merge_page_bio(struct f2fs_io_info *fio); 3188fe16efe6SChao Yu void f2fs_submit_page_write(struct f2fs_io_info *fio); 3189cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 3190cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 3191cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 31924d57b86dSChao Yu void f2fs_set_data_blkaddr(struct dnode_of_data *dn); 3193cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 31944d57b86dSChao Yu int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 31954d57b86dSChao Yu int f2fs_reserve_new_block(struct dnode_of_data *dn); 3196cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 3197cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 3198cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 31994d57b86dSChao Yu struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, 3200cac5a3d8SDongOh Shin int op_flags, bool for_write); 32014d57b86dSChao Yu struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index); 32024d57b86dSChao Yu struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index, 3203cac5a3d8SDongOh Shin bool for_write); 32044d57b86dSChao Yu struct page *f2fs_get_new_data_page(struct inode *inode, 3205cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 32064d57b86dSChao Yu int f2fs_do_write_data_page(struct f2fs_io_info *fio); 320739a86958SChao Yu void __do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock); 3208cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 3209cac5a3d8SDongOh Shin int create, int flag); 3210cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 3211cac5a3d8SDongOh Shin u64 start, u64 len); 32124d57b86dSChao Yu bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); 32134d57b86dSChao Yu bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); 3214cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 3215cac5a3d8SDongOh Shin unsigned int length); 3216cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 32175b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 3218cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 3219cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 32205b7a487cSWeichao Guo #endif 3221b91050a8SHyunchul Lee bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len); 32225ec2d99dSMatthew Wilcox void f2fs_clear_page_cache_dirty_tag(struct page *page); 322339a53e0cSJaegeuk Kim 322439a53e0cSJaegeuk Kim /* 322539a53e0cSJaegeuk Kim * gc.c 322639a53e0cSJaegeuk Kim */ 32274d57b86dSChao Yu int f2fs_start_gc_thread(struct f2fs_sb_info *sbi); 32284d57b86dSChao Yu void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi); 32294d57b86dSChao Yu block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 3230e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 3231e066b83cSJaegeuk Kim unsigned int segno); 32324d57b86dSChao Yu void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); 323304f0b2eaSQiuyang Sun int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count); 323439a53e0cSJaegeuk Kim 323539a53e0cSJaegeuk Kim /* 323639a53e0cSJaegeuk Kim * recovery.c 323739a53e0cSJaegeuk Kim */ 32384d57b86dSChao Yu int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 32394d57b86dSChao Yu bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi); 324039a53e0cSJaegeuk Kim 324139a53e0cSJaegeuk Kim /* 324239a53e0cSJaegeuk Kim * debug.c 324339a53e0cSJaegeuk Kim */ 324439a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 324539a53e0cSJaegeuk Kim struct f2fs_stat_info { 324639a53e0cSJaegeuk Kim struct list_head stat_list; 324739a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 324839a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 324939a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 32505b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 32515b7ee374SChao Yu unsigned long long hit_total, total_ext; 3252c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 32532c8a4a28SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; 32542c8a4a28SJaegeuk Kim int ndirty_data, ndirty_qdata; 325535782b23SJaegeuk Kim int inmem_pages; 32562c8a4a28SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; 32575b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 32585b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 325939a53e0cSJaegeuk Kim int total_count, utilization; 32608b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 32615f9abab4SJaegeuk Kim int nr_rd_data, nr_rd_node, nr_rd_meta; 326202b16d0aSChao Yu int nr_dio_read, nr_dio_write; 3263274bd9baSChao Yu unsigned int io_skip_bggc, other_skip_bggc; 326414d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 326514d8d5f7SChao Yu int nr_discarding, nr_discarded; 32665f32366aSChao Yu int nr_discard_cmd; 3267d84d1cbdSChao Yu unsigned int undiscard_blks; 3268a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 3269648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 3270f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 327139a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 327239a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 327339a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 327439a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 327542190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 327639a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 3277e1235983SChangman Lee int bg_node_segs, bg_data_segs; 327839a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 3279e1235983SChangman Lee int bg_data_blks, bg_node_blks; 32802ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; 328139a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 328239a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 328339a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 328439a53e0cSJaegeuk Kim 3285b63e7be5SChao Yu unsigned int meta_count[META_MAX]; 328639a53e0cSJaegeuk Kim unsigned int segment_count[2]; 328739a53e0cSJaegeuk Kim unsigned int block_count[2]; 3288b9a2c252SChangman Lee unsigned int inplace_count; 32899edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 329039a53e0cSJaegeuk Kim }; 329139a53e0cSJaegeuk Kim 3292963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 3293963d4f7dSGu Zheng { 3294963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 3295963d4f7dSGu Zheng } 3296963d4f7dSGu Zheng 3297942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 329842190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 329939a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 3300dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 3301274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) ((sbi)->io_skip_bggc++) 3302274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) ((sbi)->other_skip_bggc++) 330333fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 330433fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 33055b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 33065b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 33075b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 33085b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 3309d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 3310d5e8f6c9SChao Yu do { \ 3311d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3312d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 3313d5e8f6c9SChao Yu } while (0) 3314d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 3315d5e8f6c9SChao Yu do { \ 3316d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3317d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 3318d5e8f6c9SChao Yu } while (0) 33190dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 33200dbdc2aeSJaegeuk Kim do { \ 33210dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 332203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 33230dbdc2aeSJaegeuk Kim } while (0) 33240dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 33250dbdc2aeSJaegeuk Kim do { \ 33260dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 332703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 33280dbdc2aeSJaegeuk Kim } while (0) 33293289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 33303289c061SJaegeuk Kim do { \ 33313289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 333203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 33333289c061SJaegeuk Kim } while (0) 33343289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 33353289c061SJaegeuk Kim do { \ 33363289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 333703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 33383289c061SJaegeuk Kim } while (0) 3339b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) \ 3340b63e7be5SChao Yu do { \ 3341b63e7be5SChao Yu if (blkaddr < SIT_I(sbi)->sit_base_addr) \ 3342b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_CP]); \ 3343b63e7be5SChao Yu else if (blkaddr < NM_I(sbi)->nat_blkaddr) \ 3344b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SIT]); \ 3345b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->ssa_blkaddr) \ 3346b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_NAT]); \ 3347b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->main_blkaddr) \ 3348b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SSA]); \ 3349b63e7be5SChao Yu } while (0) 3350dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 3351dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 3352dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 3353dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 3354b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 3355b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 335626a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 3357cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 335826a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 3359cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 336026a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 336126a28a0cSJaegeuk Kim do { \ 336226a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 336326a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 336426a28a0cSJaegeuk Kim if (cur > max) \ 336526a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 336626a28a0cSJaegeuk Kim } while (0) 3367648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 3368648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 3369648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 3370648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 3371648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 3372648d50baSChao Yu do { \ 3373648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 3374648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 3375648d50baSChao Yu if (cur > max) \ 3376648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 3377648d50baSChao Yu } while (0) 3378e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 337939a53e0cSJaegeuk Kim do { \ 3380963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 338168afcf2dSTomohiro Kusumi si->tot_segs++; \ 338268afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 338339a53e0cSJaegeuk Kim si->data_segs++; \ 3384e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 3385e1235983SChangman Lee } else { \ 338639a53e0cSJaegeuk Kim si->node_segs++; \ 3387e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 3388e1235983SChangman Lee } \ 338939a53e0cSJaegeuk Kim } while (0) 339039a53e0cSJaegeuk Kim 339139a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 339268afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 339339a53e0cSJaegeuk Kim 3394e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 339539a53e0cSJaegeuk Kim do { \ 3396963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 339739a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 339839a53e0cSJaegeuk Kim si->data_blks += (blks); \ 339968afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 340039a53e0cSJaegeuk Kim } while (0) 340139a53e0cSJaegeuk Kim 3402e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 340339a53e0cSJaegeuk Kim do { \ 3404963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 340539a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 340639a53e0cSJaegeuk Kim si->node_blks += (blks); \ 340768afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 340839a53e0cSJaegeuk Kim } while (0) 340939a53e0cSJaegeuk Kim 3410cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 3411cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 341221acc07dSGreg Kroah-Hartman void __init f2fs_create_root_stats(void); 34134589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 341439a53e0cSJaegeuk Kim #else 3415d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 3416d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 3417d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 3418d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 3419274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) do { } while (0) 3420274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) do { } while (0) 3421d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 3422d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 3423d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 3424d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 3425d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 3426d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 3427d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 3428d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 3429d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 3430d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 3431d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 3432d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 3433d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 3434d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 3435d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 3436d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 3437d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 3438d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 3439b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) do { } while (0) 3440d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 3441d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 3442d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 3443d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 3444d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 3445d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 3446d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 344739a53e0cSJaegeuk Kim 344839a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 344939a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 345021acc07dSGreg Kroah-Hartman static inline void __init f2fs_create_root_stats(void) { } 34514589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 345239a53e0cSJaegeuk Kim #endif 345339a53e0cSJaegeuk Kim 345439a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 34552c2eb7a3SDaniel Rosenberg #ifdef CONFIG_UNICODE 34562c2eb7a3SDaniel Rosenberg extern const struct dentry_operations f2fs_dentry_ops; 34572c2eb7a3SDaniel Rosenberg #endif 345839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 345939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 346039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 346139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 346239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 346339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 346439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 3465cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 346639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 34674d57b86dSChao Yu extern struct kmem_cache *f2fs_inode_entry_slab; 34681001b347SHuajun Li 3469e18c65b2SHuajun Li /* 3470e18c65b2SHuajun Li * inline.c 3471e18c65b2SHuajun Li */ 3472cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 3473cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 34744d57b86dSChao Yu void f2fs_do_read_inline_data(struct page *page, struct page *ipage); 34754d57b86dSChao Yu void f2fs_truncate_inline_inode(struct inode *inode, 34764d57b86dSChao Yu struct page *ipage, u64 from); 3477cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 3478cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 3479cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 3480cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 34814d57b86dSChao Yu bool f2fs_recover_inline_data(struct inode *inode, struct page *npage); 34824d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, 3483cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 34844d57b86dSChao Yu int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 3485cac5a3d8SDongOh Shin struct page *ipage); 3486cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 3487cac5a3d8SDongOh Shin const struct qstr *orig_name, 3488cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 34894d57b86dSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, 34904d57b86dSChao Yu struct page *page, struct inode *dir, 34914d57b86dSChao Yu struct inode *inode); 3492cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 3493cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 3494cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 3495cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 3496cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 3497cac5a3d8SDongOh Shin __u64 start, __u64 len); 3498cde4de12SJaegeuk Kim 3499cde4de12SJaegeuk Kim /* 35002658e50dSJaegeuk Kim * shrinker.c 35012658e50dSJaegeuk Kim */ 3502cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 3503cac5a3d8SDongOh Shin struct shrink_control *sc); 3504cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 3505cac5a3d8SDongOh Shin struct shrink_control *sc); 3506cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 3507cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 35082658e50dSJaegeuk Kim 35092658e50dSJaegeuk Kim /* 3510a28ef1f5SChao Yu * extent_cache.c 3511a28ef1f5SChao Yu */ 35124dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree(struct rb_root_cached *root, 3513004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 35144d57b86dSChao Yu struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 35154dada3fdSChao Yu struct rb_root_cached *root, 35164dada3fdSChao Yu struct rb_node **parent, 35174dada3fdSChao Yu unsigned int ofs, bool *leftmost); 35184dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root, 3519004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 3520004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 3521004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 35224dada3fdSChao Yu bool force, bool *leftmost); 35234d57b86dSChao Yu bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi, 35244dada3fdSChao Yu struct rb_root_cached *root); 3525cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 3526cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 3527cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 3528cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 3529cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 3530cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 3531cac5a3d8SDongOh Shin struct extent_info *ei); 3532cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 353319b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 3534cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 35354d57b86dSChao Yu void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi); 35364d57b86dSChao Yu int __init f2fs_create_extent_cache(void); 35374d57b86dSChao Yu void f2fs_destroy_extent_cache(void); 3538a28ef1f5SChao Yu 3539a28ef1f5SChao Yu /* 35408ceffcb2SChao Yu * sysfs.c 35418ceffcb2SChao Yu */ 3542dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 3543dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 3544dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 3545dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 35468ceffcb2SChao Yu 35478ceffcb2SChao Yu /* 3548cde4de12SJaegeuk Kim * crypto support 3549cde4de12SJaegeuk Kim */ 35501958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 35511958593eSJaegeuk Kim { 355262230e0dSChandan Rajendra return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); 35531958593eSJaegeuk Kim } 35541958593eSJaegeuk Kim 3555cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 3556cde4de12SJaegeuk Kim { 3557643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 3558cde4de12SJaegeuk Kim file_set_encrypt(inode); 35599149a5ebSChao Yu f2fs_set_inode_flags(inode); 3560cde4de12SJaegeuk Kim #endif 3561cde4de12SJaegeuk Kim } 3562cde4de12SJaegeuk Kim 35636dbb1796SEric Biggers /* 35646dbb1796SEric Biggers * Returns true if the reads of the inode's data need to undergo some 35656dbb1796SEric Biggers * postprocessing step, like decryption or authenticity verification. 35666dbb1796SEric Biggers */ 35676dbb1796SEric Biggers static inline bool f2fs_post_read_required(struct inode *inode) 3568cde4de12SJaegeuk Kim { 35696dbb1796SEric Biggers return f2fs_encrypted_file(inode); 3570cde4de12SJaegeuk Kim } 3571cde4de12SJaegeuk Kim 3572ccd31cb2SSheng Yong #define F2FS_FEATURE_FUNCS(name, flagname) \ 35737beb01f7SChao Yu static inline int f2fs_sb_has_##name(struct f2fs_sb_info *sbi) \ 3574ccd31cb2SSheng Yong { \ 35757beb01f7SChao Yu return F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_##flagname); \ 3576cde4de12SJaegeuk Kim } 3577f424f664SJaegeuk Kim 3578ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(encrypt, ENCRYPT); 3579ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(blkzoned, BLKZONED); 3580ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR); 3581ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA); 3582ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM); 3583ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); 3584ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); 3585ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); 3586b7c409deSSheng Yong F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); 3587d440c52dSJunling Zheng F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); 35885aba5430SDaniel Rosenberg F2FS_FEATURE_FUNCS(casefold, CASEFOLD); 35891c1d35dfSChao Yu 3590178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 359195175dafSDamien Le Moal static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, 359295175dafSDamien Le Moal block_t blkaddr) 3593178053e2SDamien Le Moal { 3594178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 3595178053e2SDamien Le Moal 359695175dafSDamien Le Moal return test_bit(zno, FDEV(devi).blkz_seq); 3597178053e2SDamien Le Moal } 3598178053e2SDamien Le Moal #endif 3599178053e2SDamien Le Moal 36007d20c8abSChao Yu static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi) 360196ba2decSDamien Le Moal { 36027beb01f7SChao Yu return f2fs_sb_has_blkzoned(sbi); 36037d20c8abSChao Yu } 360496ba2decSDamien Le Moal 36057f3d7719SDamien Le Moal static inline bool f2fs_bdev_support_discard(struct block_device *bdev) 36067f3d7719SDamien Le Moal { 36077f3d7719SDamien Le Moal return blk_queue_discard(bdev_get_queue(bdev)) || 36087f3d7719SDamien Le Moal bdev_is_zoned(bdev); 36097f3d7719SDamien Le Moal } 36107f3d7719SDamien Le Moal 36117d20c8abSChao Yu static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi) 36127d20c8abSChao Yu { 36137f3d7719SDamien Le Moal int i; 36147f3d7719SDamien Le Moal 36157f3d7719SDamien Le Moal if (!f2fs_is_multi_device(sbi)) 36167f3d7719SDamien Le Moal return f2fs_bdev_support_discard(sbi->sb->s_bdev); 36177f3d7719SDamien Le Moal 36187f3d7719SDamien Le Moal for (i = 0; i < sbi->s_ndevs; i++) 36197f3d7719SDamien Le Moal if (f2fs_bdev_support_discard(FDEV(i).bdev)) 36207f3d7719SDamien Le Moal return true; 36217f3d7719SDamien Le Moal return false; 36227d20c8abSChao Yu } 36237d20c8abSChao Yu 36247d20c8abSChao Yu static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) 36257d20c8abSChao Yu { 36267d20c8abSChao Yu return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) || 36277d20c8abSChao Yu f2fs_hw_should_discard(sbi); 362852763a4bSJaegeuk Kim } 362952763a4bSJaegeuk Kim 3630f824deb5SChao Yu static inline bool f2fs_hw_is_readonly(struct f2fs_sb_info *sbi) 3631f824deb5SChao Yu { 3632f824deb5SChao Yu int i; 3633f824deb5SChao Yu 3634f824deb5SChao Yu if (!f2fs_is_multi_device(sbi)) 3635f824deb5SChao Yu return bdev_read_only(sbi->sb->s_bdev); 3636f824deb5SChao Yu 3637f824deb5SChao Yu for (i = 0; i < sbi->s_ndevs; i++) 3638f824deb5SChao Yu if (bdev_read_only(FDEV(i).bdev)) 3639f824deb5SChao Yu return true; 3640f824deb5SChao Yu return false; 3641f824deb5SChao Yu } 3642f824deb5SChao Yu 3643f824deb5SChao Yu 364452763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 364552763a4bSJaegeuk Kim { 364652763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 364752763a4bSJaegeuk Kim clear_opt(sbi, LFS); 364852763a4bSJaegeuk Kim 364952763a4bSJaegeuk Kim switch (mt) { 365052763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 365152763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 365252763a4bSJaegeuk Kim break; 365352763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 365452763a4bSJaegeuk Kim set_opt(sbi, LFS); 365552763a4bSJaegeuk Kim break; 365652763a4bSJaegeuk Kim } 365752763a4bSJaegeuk Kim } 365852763a4bSJaegeuk Kim 3659fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 3660fcc85a4dSJaegeuk Kim { 3661643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 3662886f56f9SAl Viro umode_t mode = inode->i_mode; 3663fcc85a4dSJaegeuk Kim 3664fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 3665fcc85a4dSJaegeuk Kim #else 36666e45f2a5SGustavo A. R. Silva return false; 3667fcc85a4dSJaegeuk Kim #endif 3668fcc85a4dSJaegeuk Kim } 3669fcc85a4dSJaegeuk Kim 3670f847c699SChao Yu static inline int block_unaligned_IO(struct inode *inode, 3671f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 3672b91050a8SHyunchul Lee { 3673f847c699SChao Yu unsigned int i_blkbits = READ_ONCE(inode->i_blkbits); 3674f847c699SChao Yu unsigned int blocksize_mask = (1 << i_blkbits) - 1; 3675f847c699SChao Yu loff_t offset = iocb->ki_pos; 3676f847c699SChao Yu unsigned long align = offset | iov_iter_alignment(iter); 3677f847c699SChao Yu 3678f847c699SChao Yu return align & blocksize_mask; 3679f847c699SChao Yu } 3680f847c699SChao Yu 3681f847c699SChao Yu static inline int allow_outplace_dio(struct inode *inode, 3682f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 3683f847c699SChao Yu { 3684f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3685f847c699SChao Yu int rw = iov_iter_rw(iter); 3686f847c699SChao Yu 3687f847c699SChao Yu return (test_opt(sbi, LFS) && (rw == WRITE) && 3688f847c699SChao Yu !block_unaligned_IO(inode, iocb, iter)); 3689f847c699SChao Yu } 3690f847c699SChao Yu 3691f847c699SChao Yu static inline bool f2fs_force_buffered_io(struct inode *inode, 3692f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 3693f847c699SChao Yu { 3694f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3695f847c699SChao Yu int rw = iov_iter_rw(iter); 3696f847c699SChao Yu 3697f847c699SChao Yu if (f2fs_post_read_required(inode)) 3698f847c699SChao Yu return true; 36990916878dSDamien Le Moal if (f2fs_is_multi_device(sbi)) 3700f847c699SChao Yu return true; 3701f847c699SChao Yu /* 3702f847c699SChao Yu * for blkzoned device, fallback direct IO to buffered IO, so 3703f847c699SChao Yu * all IOs can be serialized by log-structured write. 3704f847c699SChao Yu */ 37057beb01f7SChao Yu if (f2fs_sb_has_blkzoned(sbi)) 3706f847c699SChao Yu return true; 3707f847c699SChao Yu if (test_opt(sbi, LFS) && (rw == WRITE) && 3708f847c699SChao Yu block_unaligned_IO(inode, iocb, iter)) 3709f847c699SChao Yu return true; 37104969c06aSJaegeuk Kim if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED) && 37113ee0c5d3SChao Yu !IS_SWAPFILE(inode)) 37124354994fSDaniel Rosenberg return true; 37134354994fSDaniel Rosenberg 3714f847c699SChao Yu return false; 3715b91050a8SHyunchul Lee } 3716b91050a8SHyunchul Lee 371783a3bfdbSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 3718d494500aSChao Yu extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, 3719d494500aSChao Yu unsigned int type); 372083a3bfdbSJaegeuk Kim #else 3721d494500aSChao Yu #define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) 372283a3bfdbSJaegeuk Kim #endif 372383a3bfdbSJaegeuk Kim 3724af033b2aSChao Yu static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) 3725af033b2aSChao Yu { 3726af033b2aSChao Yu #ifdef CONFIG_QUOTA 37277beb01f7SChao Yu if (f2fs_sb_has_quota_ino(sbi)) 3728af033b2aSChao Yu return true; 3729af033b2aSChao Yu if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || 3730af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || 3731af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) 3732af033b2aSChao Yu return true; 3733af033b2aSChao Yu #endif 3734af033b2aSChao Yu return false; 3735af033b2aSChao Yu } 37360af725fcSJaegeuk Kim 373710f966bbSChao Yu #define EFSBADCRC EBADMSG /* Bad CRC detected */ 373810f966bbSChao Yu #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 373910f966bbSChao Yu 3740e1074d4bSChao Yu #endif /* _LINUX_F2FS_H */ 3741