1d29fbcdbSNishad Kamdar /* 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> 25c6a564ffSChristoph Hellwig #include <linux/part_stat.h> 2643b6573bSKeith Mok #include <crypto/hash.h> 2739a53e0cSJaegeuk Kim 28734f0d24SDave Chinner #include <linux/fscrypt.h> 2995ae251fSEric Biggers #include <linux/fsverity.h> 30734f0d24SDave Chinner 315d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 329850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 335d56b671SJaegeuk Kim #else 349850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 359850cf4aSJaegeuk Kim do { \ 369850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 379850cf4aSJaegeuk Kim WARN_ON(1); \ 38caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 399850cf4aSJaegeuk Kim } \ 409850cf4aSJaegeuk Kim } while (0) 415d56b671SJaegeuk Kim #endif 425d56b671SJaegeuk Kim 432c63feadSJaegeuk Kim enum { 442c63feadSJaegeuk Kim FAULT_KMALLOC, 45628b3d14SChao Yu FAULT_KVMALLOC, 46c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 4701eccef7SChao Yu FAULT_PAGE_GET, 48d62fe971SChao Yu FAULT_ALLOC_BIO, 49cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 50cb78942bSJaegeuk Kim FAULT_ORPHAN, 51cb78942bSJaegeuk Kim FAULT_BLOCK, 52cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5353aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 5414b44d23SJaegeuk Kim FAULT_TRUNCATE, 556f5c2ed0SChao Yu FAULT_READ_IO, 560f348028SChao Yu FAULT_CHECKPOINT, 57b83dcfe6SChao Yu FAULT_DISCARD, 586f5c2ed0SChao Yu FAULT_WRITE_IO, 592c63feadSJaegeuk Kim FAULT_MAX, 602c63feadSJaegeuk Kim }; 612c63feadSJaegeuk Kim 627fa750a1SArnd Bergmann #ifdef CONFIG_F2FS_FAULT_INJECTION 63d494500aSChao Yu #define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1) 64d494500aSChao Yu 6508796897SSheng Yong struct f2fs_fault_info { 6608796897SSheng Yong atomic_t inject_ops; 6708796897SSheng Yong unsigned int inject_rate; 6808796897SSheng Yong unsigned int inject_type; 6908796897SSheng Yong }; 7008796897SSheng Yong 7119880e6eSAlexey Dobriyan extern const char *f2fs_fault_name[FAULT_MAX]; 7268afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 732c63feadSJaegeuk Kim #endif 742c63feadSJaegeuk Kim 7539a53e0cSJaegeuk Kim /* 7639a53e0cSJaegeuk Kim * For mount options 7739a53e0cSJaegeuk Kim */ 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 8039a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 8139a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 8239a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 8339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 84444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 851001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8634d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8734d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8834d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 89d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 9089672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 91343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 9273faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 930abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA 0x00080000 940abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA 0x00100000 955c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA 0x00200000 964b2414d0SChao Yu #define F2FS_MOUNT_QUOTA 0x00400000 976afc662eSChao Yu #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 987e65be49SJaegeuk Kim #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 994354994fSDaniel Rosenberg #define F2FS_MOUNT_DISABLE_CHECKPOINT 0x02000000 100a9117ecaSChao Yu #define F2FS_MOUNT_NORECOVERY 0x04000000 101093749e2SChao Yu #define F2FS_MOUNT_ATGC 0x08000000 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 1184c8ff709SChao Yu #define COMPRESS_EXT_NUM 16 1194c8ff709SChao Yu 12039a53e0cSJaegeuk Kim struct f2fs_mount_info { 12139a53e0cSJaegeuk Kim unsigned int opt; 12263189b78SChao Yu int write_io_size_bits; /* Write IO size bits */ 12363189b78SChao Yu block_t root_reserved_blocks; /* root reserved blocks */ 12463189b78SChao Yu kuid_t s_resuid; /* reserved blocks for uid */ 12563189b78SChao Yu kgid_t s_resgid; /* reserved blocks for gid */ 12663189b78SChao Yu int active_logs; /* # of active logs */ 12763189b78SChao Yu int inline_xattr_size; /* inline xattr size */ 12863189b78SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 12963189b78SChao Yu struct f2fs_fault_info fault_info; /* For fault injection */ 13063189b78SChao Yu #endif 13163189b78SChao Yu #ifdef CONFIG_QUOTA 13263189b78SChao Yu /* Names of quota files with journalled quota */ 13363189b78SChao Yu char *s_qf_names[MAXQUOTAS]; 13463189b78SChao Yu int s_jquota_fmt; /* Format of quota to use */ 13563189b78SChao Yu #endif 13663189b78SChao Yu /* For which write hints are passed down to block layer */ 13763189b78SChao Yu int whint_mode; 13863189b78SChao Yu int alloc_mode; /* segment allocation policy */ 13963189b78SChao Yu int fsync_mode; /* fsync policy */ 140b0332a0fSChao Yu int fs_mode; /* fs mode: LFS or ADAPTIVE */ 141bbbc34fdSChao Yu int bggc_mode; /* bggc mode: off, on or sync */ 142ac4acb1fSEric Biggers struct fscrypt_dummy_policy dummy_enc_policy; /* test dummy encryption */ 1431ae18f71SJaegeuk Kim block_t unusable_cap_perc; /* percentage for cap */ 1444d3aed70SDaniel Rosenberg block_t unusable_cap; /* Amount of space allowed to be 1454d3aed70SDaniel Rosenberg * unusable when disabling checkpoint 1464d3aed70SDaniel Rosenberg */ 1474c8ff709SChao Yu 1484c8ff709SChao Yu /* For compression */ 1494c8ff709SChao Yu unsigned char compress_algorithm; /* algorithm type */ 150*b28f047bSChao Yu unsigned char compress_log_size; /* cluster log size */ 151*b28f047bSChao Yu bool compress_chksum; /* compressed data chksum */ 1524c8ff709SChao Yu unsigned char compress_ext_cnt; /* extension count */ 1534c8ff709SChao Yu unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ 15439a53e0cSJaegeuk Kim }; 15539a53e0cSJaegeuk Kim 156cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1570bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 158e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1597a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1605c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 161704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 1626afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 163234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO 0x0080 1641c1d35dfSChao Yu #define F2FS_FEATURE_INODE_CRTIME 0x0100 165b7c409deSSheng Yong #define F2FS_FEATURE_LOST_FOUND 0x0200 16695ae251fSEric Biggers #define F2FS_FEATURE_VERITY 0x0400 167d440c52dSJunling Zheng #define F2FS_FEATURE_SB_CHKSUM 0x0800 1685aba5430SDaniel Rosenberg #define F2FS_FEATURE_CASEFOLD 0x1000 1694c8ff709SChao Yu #define F2FS_FEATURE_COMPRESSION 0x2000 170cde4de12SJaegeuk Kim 1717beb01f7SChao Yu #define __F2FS_HAS_FEATURE(raw_super, mask) \ 1727beb01f7SChao Yu ((raw_super->feature & cpu_to_le32(mask)) != 0) 1737beb01f7SChao Yu #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask) 1747beb01f7SChao Yu #define F2FS_SET_FEATURE(sbi, mask) \ 1757beb01f7SChao Yu (sbi->raw_super->feature |= cpu_to_le32(mask)) 1767beb01f7SChao Yu #define F2FS_CLEAR_FEATURE(sbi, mask) \ 1777beb01f7SChao Yu (sbi->raw_super->feature &= ~cpu_to_le32(mask)) 17876f105a2SJaegeuk Kim 17939a53e0cSJaegeuk Kim /* 1807c2e5963SJaegeuk Kim * Default values for user and/or group using reserved blocks 1817c2e5963SJaegeuk Kim */ 1827c2e5963SJaegeuk Kim #define F2FS_DEF_RESUID 0 1837c2e5963SJaegeuk Kim #define F2FS_DEF_RESGID 0 1847c2e5963SJaegeuk Kim 1857c2e5963SJaegeuk Kim /* 18639a53e0cSJaegeuk Kim * For checkpoint manager 18739a53e0cSJaegeuk Kim */ 18839a53e0cSJaegeuk Kim enum { 18939a53e0cSJaegeuk Kim NAT_BITMAP, 19039a53e0cSJaegeuk Kim SIT_BITMAP 19139a53e0cSJaegeuk Kim }; 19239a53e0cSJaegeuk Kim 193c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 194c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 195c473f1a9SChao Yu #define CP_SYNC 0x00000004 196c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 197c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1981f43e2adSChao Yu #define CP_TRIMMED 0x00000020 1994354994fSDaniel Rosenberg #define CP_PAUSE 0x00000040 200b4b10061SJaegeuk Kim #define CP_RESIZE 0x00000080 20175ab4cb8SJaegeuk Kim 2024ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 203ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 204969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 205f9d1dcedSYunlei He #define DEF_MID_DISCARD_ISSUE_TIME 500 /* 500 ms, if device busy */ 206969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 2078bb4f253SJaegeuk Kim #define DEF_DISCARD_URGENT_UTIL 80 /* do more discard over 80% */ 20860b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 209dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 2104354994fSDaniel Rosenberg #define DEF_DISABLE_INTERVAL 5 /* 5 secs */ 211db610a64SJaegeuk Kim #define DEF_DISABLE_QUICK_INTERVAL 1 /* 1 secs */ 21203f2c02dSJaegeuk Kim #define DEF_UMOUNT_DISCARD_TIMEOUT 5 /* 5 secs */ 213bba681cbSJaegeuk Kim 21475ab4cb8SJaegeuk Kim struct cp_control { 21575ab4cb8SJaegeuk Kim int reason; 2164b2fecc8SJaegeuk Kim __u64 trim_start; 2174b2fecc8SJaegeuk Kim __u64 trim_end; 2184b2fecc8SJaegeuk Kim __u64 trim_minlen; 21975ab4cb8SJaegeuk Kim }; 22075ab4cb8SJaegeuk Kim 221662befdaSChao Yu /* 222e1da7872SChao Yu * indicate meta/data type 223662befdaSChao Yu */ 224662befdaSChao Yu enum { 225662befdaSChao Yu META_CP, 226662befdaSChao Yu META_NAT, 22781c1a0f1SChao Yu META_SIT, 2284c521f49SJaegeuk Kim META_SSA, 229b63e7be5SChao Yu META_MAX, 2304c521f49SJaegeuk Kim META_POR, 23193770ab7SChao Yu DATA_GENERIC, /* check range only */ 23293770ab7SChao Yu DATA_GENERIC_ENHANCE, /* strong check on range and segment bitmap */ 23393770ab7SChao Yu DATA_GENERIC_ENHANCE_READ, /* 23493770ab7SChao Yu * strong check on range and segment 23593770ab7SChao Yu * bitmap but no warning due to race 23693770ab7SChao Yu * condition of read on truncated area 23793770ab7SChao Yu * by extent_cache 23893770ab7SChao Yu */ 239e1da7872SChao Yu META_GENERIC, 240662befdaSChao Yu }; 241662befdaSChao Yu 2426451e041SJaegeuk Kim /* for the list of ino */ 2436451e041SJaegeuk Kim enum { 2446451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 245fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 246fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 2470a007b97SJaegeuk Kim TRANS_DIR_INO, /* for trasactions dir ino list */ 24839d787beSChao Yu FLUSH_INO, /* for multiple device flushing */ 2496451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 2506451e041SJaegeuk Kim }; 2516451e041SJaegeuk Kim 2526451e041SJaegeuk Kim struct ino_entry { 25339a53e0cSJaegeuk Kim struct list_head list; /* list head */ 25439a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 25539d787beSChao Yu unsigned int dirty_device; /* dirty device bitmap */ 25639a53e0cSJaegeuk Kim }; 25739a53e0cSJaegeuk Kim 2582710fd7eSChao Yu /* for the list of inodes to be GCed */ 25906292073SChao Yu struct inode_entry { 26039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 26139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 26239a53e0cSJaegeuk Kim }; 26339a53e0cSJaegeuk Kim 26450fa53ecSChao Yu struct fsync_node_entry { 26550fa53ecSChao Yu struct list_head list; /* list head */ 26650fa53ecSChao Yu struct page *page; /* warm node page pointer */ 26750fa53ecSChao Yu unsigned int seq_id; /* sequence id */ 26850fa53ecSChao Yu }; 26950fa53ecSChao Yu 270a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 2717fd9e544SJaegeuk Kim struct discard_entry { 2727fd9e544SJaegeuk Kim struct list_head list; /* list head */ 273a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 274a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 2757fd9e544SJaegeuk Kim }; 2767fd9e544SJaegeuk Kim 277969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 278969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 279969d1b18SChao Yu 280ba48a33eSChao Yu /* max discard pend list number */ 281ba48a33eSChao Yu #define MAX_PLIST_NUM 512 282ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 2832f84babfSSheng Yong (MAX_PLIST_NUM - 1) : ((blk_num) - 1)) 284ba48a33eSChao Yu 28515469963SJaegeuk Kim enum { 28635ec7d57SChao Yu D_PREP, /* initial */ 28735ec7d57SChao Yu D_PARTIAL, /* partially submitted */ 28835ec7d57SChao Yu D_SUBMIT, /* all submitted */ 28935ec7d57SChao Yu D_DONE, /* finished */ 29015469963SJaegeuk Kim }; 29115469963SJaegeuk Kim 292004b6862SChao Yu struct discard_info { 293b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 294b01a9201SJaegeuk Kim block_t len; /* length */ 295004b6862SChao Yu block_t start; /* actual start address in dev */ 296004b6862SChao Yu }; 297004b6862SChao Yu 298b01a9201SJaegeuk Kim struct discard_cmd { 299004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 300004b6862SChao Yu union { 301004b6862SChao Yu struct { 302004b6862SChao Yu block_t lstart; /* logical start address */ 303004b6862SChao Yu block_t len; /* length */ 304004b6862SChao Yu block_t start; /* actual start address in dev */ 305004b6862SChao Yu }; 306004b6862SChao Yu struct discard_info di; /* discard info */ 307004b6862SChao Yu 308004b6862SChao Yu }; 309b01a9201SJaegeuk Kim struct list_head list; /* command list */ 310b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 311c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 312ec9895adSChao Yu unsigned short ref; /* reference count */ 3139a744b92SChao Yu unsigned char state; /* state */ 31472691af6SJaegeuk Kim unsigned char queued; /* queued discard */ 315c81abe34SJaegeuk Kim int error; /* bio error */ 31635ec7d57SChao Yu spinlock_t lock; /* for state/bio_ref updating */ 31735ec7d57SChao Yu unsigned short bio_ref; /* bio reference count */ 318275b66b0SChao Yu }; 319275b66b0SChao Yu 32078997b56SChao Yu enum { 32178997b56SChao Yu DPOLICY_BG, 32278997b56SChao Yu DPOLICY_FORCE, 32378997b56SChao Yu DPOLICY_FSTRIM, 32478997b56SChao Yu DPOLICY_UMOUNT, 32578997b56SChao Yu MAX_DPOLICY, 32678997b56SChao Yu }; 32778997b56SChao Yu 328ecc9aa00SChao Yu struct discard_policy { 32978997b56SChao Yu int type; /* type of discard */ 330ecc9aa00SChao Yu unsigned int min_interval; /* used for candidates exist */ 331f9d1dcedSYunlei He unsigned int mid_interval; /* used for device busy */ 332ecc9aa00SChao Yu unsigned int max_interval; /* used for candidates not exist */ 333ecc9aa00SChao Yu unsigned int max_requests; /* # of discards issued per round */ 334ecc9aa00SChao Yu unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ 335ecc9aa00SChao Yu bool io_aware; /* issue discard in idle time */ 336ecc9aa00SChao Yu bool sync; /* submit discard with REQ_SYNC flag */ 33720ee4382SChao Yu bool ordered; /* issue discard by lba order */ 3386ce48b0cSChao Yu bool timeout; /* discard timeout for put_super */ 33978997b56SChao Yu unsigned int granularity; /* discard granularity */ 340ecc9aa00SChao Yu }; 341ecc9aa00SChao Yu 3420b54fb84SJaegeuk Kim struct discard_cmd_control { 34315469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 34446f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 345ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 34646f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 3478412663dSChao Yu struct list_head fstrim_list; /* in-flight discard from fstrim */ 34815469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 349969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 35015469963SJaegeuk Kim struct mutex cmd_lock; 351d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 352d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 353969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 354d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 35520ee4382SChao Yu unsigned int next_pos; /* next discard position */ 3568b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 35772691af6SJaegeuk Kim atomic_t queued_discard; /* # of queued discard */ 3585f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 3594dada3fdSChao Yu struct rb_root_cached root; /* root of discard rb-tree */ 36067fce70bSChao Yu bool rbtree_check; /* config for consistence check */ 36139a53e0cSJaegeuk Kim }; 36239a53e0cSJaegeuk Kim 36339a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 36439a53e0cSJaegeuk Kim struct fsync_inode_entry { 36539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 36639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 367c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 368c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 36939a53e0cSJaegeuk Kim }; 37039a53e0cSJaegeuk Kim 37168afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 37268afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 37339a53e0cSJaegeuk Kim 37468afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 37568afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 37668afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 37768afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 37839a53e0cSJaegeuk Kim 379dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 380dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 381309cc2b6SJaegeuk Kim 382dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 38339a53e0cSJaegeuk Kim { 384dfc08a12SChao Yu int before = nats_in_cursum(journal); 385cac5a3d8SDongOh Shin 386dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 38739a53e0cSJaegeuk Kim return before; 38839a53e0cSJaegeuk Kim } 38939a53e0cSJaegeuk Kim 390dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 39139a53e0cSJaegeuk Kim { 392dfc08a12SChao Yu int before = sits_in_cursum(journal); 393cac5a3d8SDongOh Shin 394dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 39539a53e0cSJaegeuk Kim return before; 39639a53e0cSJaegeuk Kim } 39739a53e0cSJaegeuk Kim 398dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 399dfc08a12SChao Yu int size, int type) 400184a5cd2SChao Yu { 401184a5cd2SChao Yu if (type == NAT_JOURNAL) 402dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 403dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 404184a5cd2SChao Yu } 405184a5cd2SChao Yu 406f2470371SChao Yu /* for inline stuff */ 407f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 4087a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 4096afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode); 4107a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 4117a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 412b323fd28SChao Yu get_inline_xattr_addrs(inode) - \ 4136afc662eSChao Yu DEF_INLINE_RESERVED_SIZE)) 414f2470371SChao Yu 415f2470371SChao Yu /* for inline dir */ 416f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 417f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 418f2470371SChao Yu BITS_PER_BYTE + 1)) 419f91108b8SGeert Uytterhoeven #define INLINE_DENTRY_BITMAP_SIZE(inode) \ 420f91108b8SGeert Uytterhoeven DIV_ROUND_UP(NR_INLINE_DENTRY(inode), BITS_PER_BYTE) 421f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 422f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 423f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 424f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 425f2470371SChao Yu 426e9750824SNamjae Jeon /* 42739a53e0cSJaegeuk Kim * For INODE and NODE manager 42839a53e0cSJaegeuk Kim */ 4297b3cd7d6SJaegeuk Kim /* for directory operations */ 43043c780baSEric Biggers 43143c780baSEric Biggers struct f2fs_filename { 43243c780baSEric Biggers /* 43343c780baSEric Biggers * The filename the user specified. This is NULL for some 43443c780baSEric Biggers * filesystem-internal operations, e.g. converting an inline directory 43543c780baSEric Biggers * to a non-inline one, or roll-forward recovering an encrypted dentry. 43643c780baSEric Biggers */ 43743c780baSEric Biggers const struct qstr *usr_fname; 43843c780baSEric Biggers 43943c780baSEric Biggers /* 44043c780baSEric Biggers * The on-disk filename. For encrypted directories, this is encrypted. 44143c780baSEric Biggers * This may be NULL for lookups in an encrypted dir without the key. 44243c780baSEric Biggers */ 44343c780baSEric Biggers struct fscrypt_str disk_name; 44443c780baSEric Biggers 44543c780baSEric Biggers /* The dirhash of this filename */ 44643c780baSEric Biggers f2fs_hash_t hash; 44743c780baSEric Biggers 44843c780baSEric Biggers #ifdef CONFIG_FS_ENCRYPTION 44943c780baSEric Biggers /* 45043c780baSEric Biggers * For lookups in encrypted directories: either the buffer backing 45143c780baSEric Biggers * disk_name, or a buffer that holds the decoded no-key name. 45243c780baSEric Biggers */ 45343c780baSEric Biggers struct fscrypt_str crypto_buf; 45443c780baSEric Biggers #endif 45543c780baSEric Biggers #ifdef CONFIG_UNICODE 45643c780baSEric Biggers /* 45743c780baSEric Biggers * For casefolded directories: the casefolded name, but it's left NULL 4587ad08a58SDaniel Rosenberg * if the original name is not valid Unicode, if the directory is both 4597ad08a58SDaniel Rosenberg * casefolded and encrypted and its encryption key is unavailable, or if 4607ad08a58SDaniel Rosenberg * the filesystem is doing an internal operation where usr_fname is also 4617ad08a58SDaniel Rosenberg * NULL. In all these cases we fall back to treating the name as an 4627ad08a58SDaniel Rosenberg * opaque byte sequence. 46343c780baSEric Biggers */ 46443c780baSEric Biggers struct fscrypt_str cf_name; 46543c780baSEric Biggers #endif 46643c780baSEric Biggers }; 46743c780baSEric Biggers 4687b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 469d8c6822aSJaegeuk Kim struct inode *inode; 47076a9dd85SChao Yu void *bitmap; 4717b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 4727b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 4737b3cd7d6SJaegeuk Kim int max; 47476a9dd85SChao Yu int nr_bitmap; 4757b3cd7d6SJaegeuk Kim }; 4767b3cd7d6SJaegeuk Kim 47764c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 47864c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 4797b3cd7d6SJaegeuk Kim { 480d8c6822aSJaegeuk Kim d->inode = inode; 4817b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 48276a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 483c79d1520SYunlong Song d->bitmap = t->dentry_bitmap; 4847b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 4857b3cd7d6SJaegeuk Kim d->filename = t->filename; 48664c24ecbSTomohiro Kusumi } 487cac5a3d8SDongOh Shin 48864c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 489f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 49064c24ecbSTomohiro Kusumi { 491f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 492f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 493f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 494f2470371SChao Yu 49564c24ecbSTomohiro Kusumi d->inode = inode; 496f2470371SChao Yu d->max = entry_cnt; 497f2470371SChao Yu d->nr_bitmap = bitmap_size; 498f2470371SChao Yu d->bitmap = t; 499f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 500f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 501f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 5027b3cd7d6SJaegeuk Kim } 5037b3cd7d6SJaegeuk Kim 504dbe6a5ffSJaegeuk Kim /* 505dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 506dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 507dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 50839a53e0cSJaegeuk Kim */ 509dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 510dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 511266e97a8SJaegeuk Kim enum { 512266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 513266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 514266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 515266e97a8SJaegeuk Kim * look up a node with readahead called 5164f4124d0SChao Yu * by get_data_block. 51739a53e0cSJaegeuk Kim */ 518266e97a8SJaegeuk Kim }; 519266e97a8SJaegeuk Kim 5207735730dSChao Yu #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO count */ 5217735730dSChao Yu 5225df7731fSChao Yu /* congestion wait timeout value, default: 20ms */ 5235df7731fSChao Yu #define DEFAULT_IO_TIMEOUT (msecs_to_jiffies(20)) 5245df7731fSChao Yu 525af033b2aSChao Yu /* maximum retry quota flush count */ 526af033b2aSChao Yu #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT 8 527af033b2aSChao Yu 528a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 52939a53e0cSJaegeuk Kim 530817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 531817202d9SChao Yu 53239a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 53313054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 53413054c54SChao Yu 53513054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 53613054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 537c11abd1aSJaegeuk Kim 53854c2258cSChao Yu struct rb_entry { 53954c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 5402e9b2bb2SChao Yu union { 5412e9b2bb2SChao Yu struct { 54254c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 54354c2258cSChao Yu unsigned int len; /* length of the entry */ 54454c2258cSChao Yu }; 5452e9b2bb2SChao Yu unsigned long long key; /* 64-bits key */ 54648046cb5SJaegeuk Kim } __packed; 5472e9b2bb2SChao Yu }; 54854c2258cSChao Yu 54939a53e0cSJaegeuk Kim struct extent_info { 55039a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 551111d2495SMasanari Iida unsigned int len; /* length of the extent */ 55254c2258cSChao Yu u32 blk; /* start block address of the extent */ 55339a53e0cSJaegeuk Kim }; 55439a53e0cSJaegeuk Kim 55513054c54SChao Yu struct extent_node { 556c0362117SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 55713054c54SChao Yu struct extent_info ei; /* extent info */ 55854c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 559201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 56013054c54SChao Yu }; 56113054c54SChao Yu 56213054c54SChao Yu struct extent_tree { 56313054c54SChao Yu nid_t ino; /* inode number */ 5644dada3fdSChao Yu struct rb_root_cached root; /* root of extent info rb-tree */ 56562c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 5663e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 567137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 56813054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 56968e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 570b430f726SZhikang Zhang bool largest_updated; /* largest extent updated */ 57113054c54SChao Yu }; 57213054c54SChao Yu 57339a53e0cSJaegeuk Kim /* 574003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 575003a3e1dSJaegeuk Kim * 576003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 577003a3e1dSJaegeuk Kim */ 578003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 579003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 5807f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 5817f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 5827f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 583003a3e1dSJaegeuk Kim 584003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 585003a3e1dSJaegeuk Kim block_t m_pblk; 586003a3e1dSJaegeuk Kim block_t m_lblk; 587003a3e1dSJaegeuk Kim unsigned int m_len; 588003a3e1dSJaegeuk Kim unsigned int m_flags; 589da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 590c4020b2dSChao Yu pgoff_t *m_next_extent; /* point to next possible extent */ 591d5097be5SHyunchul Lee int m_seg_type; 592f9d6d059SChao Yu bool m_may_create; /* indicate it is from write path */ 593003a3e1dSJaegeuk Kim }; 594003a3e1dSJaegeuk Kim 595e2b4e2bcSChao Yu /* for flag in get_data_block */ 596f2220c7fSQiuyang Sun enum { 597f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 598f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 599f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 6000a4daae5SJaegeuk Kim F2FS_GET_BLOCK_DIO, 601f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 602f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 603c4020b2dSChao Yu F2FS_GET_BLOCK_PRECACHE, 604f2220c7fSQiuyang Sun }; 605e2b4e2bcSChao Yu 606003a3e1dSJaegeuk Kim /* 60739a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 60839a53e0cSJaegeuk Kim */ 60939a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 610354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 611cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 612e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 61326787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 614b6a06cbbSChao Yu #define FADVISE_HOT_BIT 0x20 61595ae251fSEric Biggers #define FADVISE_VERITY_BIT 0x40 61639a53e0cSJaegeuk Kim 617797c1cb5SChao Yu #define FADVISE_MODIFIABLE_BITS (FADVISE_COLD_BIT | FADVISE_HOT_BIT) 618797c1cb5SChao Yu 619b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 620b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 621b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 622b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 623b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 624b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 625cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 626cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 627cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 628e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 629e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 63026787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 63126787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 632b6a06cbbSChao Yu #define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT) 633b6a06cbbSChao Yu #define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT) 634b6a06cbbSChao Yu #define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT) 63595ae251fSEric Biggers #define file_is_verity(inode) is_file(inode, FADVISE_VERITY_BIT) 63695ae251fSEric Biggers #define file_set_verity(inode) set_file(inode, FADVISE_VERITY_BIT) 637cde4de12SJaegeuk Kim 638ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 639ab9fa662SJaegeuk Kim 6402ef79ecbSChao Yu enum { 6412ef79ecbSChao Yu GC_FAILURE_PIN, 6422ef79ecbSChao Yu GC_FAILURE_ATOMIC, 6432ef79ecbSChao Yu MAX_GC_FAILURE 6442ef79ecbSChao Yu }; 6452ef79ecbSChao Yu 6467653b9d8SChao Yu /* used for f2fs_inode_info->flags */ 6477653b9d8SChao Yu enum { 6487653b9d8SChao Yu FI_NEW_INODE, /* indicate newly allocated inode */ 6497653b9d8SChao Yu FI_DIRTY_INODE, /* indicate inode is dirty or not */ 6507653b9d8SChao Yu FI_AUTO_RECOVER, /* indicate inode is recoverable */ 6517653b9d8SChao Yu FI_DIRTY_DIR, /* indicate directory has dirty pages */ 6527653b9d8SChao Yu FI_INC_LINK, /* need to increment i_nlink */ 6537653b9d8SChao Yu FI_ACL_MODE, /* indicate acl mode */ 6547653b9d8SChao Yu FI_NO_ALLOC, /* should not allocate any blocks */ 6557653b9d8SChao Yu FI_FREE_NID, /* free allocated nide */ 6567653b9d8SChao Yu FI_NO_EXTENT, /* not to use the extent cache */ 6577653b9d8SChao Yu FI_INLINE_XATTR, /* used for inline xattr */ 6587653b9d8SChao Yu FI_INLINE_DATA, /* used for inline data*/ 6597653b9d8SChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 6607653b9d8SChao Yu FI_APPEND_WRITE, /* inode has appended data */ 6617653b9d8SChao Yu FI_UPDATE_WRITE, /* inode has in-place-update data */ 6627653b9d8SChao Yu FI_NEED_IPU, /* used for ipu per file */ 6637653b9d8SChao Yu FI_ATOMIC_FILE, /* indicate atomic file */ 6647653b9d8SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 6657653b9d8SChao Yu FI_VOLATILE_FILE, /* indicate volatile file */ 6667653b9d8SChao Yu FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 6677653b9d8SChao Yu FI_DROP_CACHE, /* drop dirty page cache */ 6687653b9d8SChao Yu FI_DATA_EXIST, /* indicate data exists */ 6697653b9d8SChao Yu FI_INLINE_DOTS, /* indicate inline dot dentries */ 6707653b9d8SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 6717653b9d8SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 6727653b9d8SChao Yu FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 6737653b9d8SChao Yu FI_HOT_DATA, /* indicate file is hot */ 6747653b9d8SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 6757653b9d8SChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 6767653b9d8SChao Yu FI_PIN_FILE, /* indicate file should not be gced */ 6777653b9d8SChao Yu FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */ 6787653b9d8SChao Yu FI_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ 6797653b9d8SChao Yu FI_COMPRESSED_FILE, /* indicate file's data can be compressed */ 680*b28f047bSChao Yu FI_COMPRESS_CORRUPT, /* indicate compressed cluster is corrupted */ 6817653b9d8SChao Yu FI_MMAP_FILE, /* indicate file was mmapped */ 6827653b9d8SChao Yu FI_MAX, /* max flag, never be used */ 6837653b9d8SChao Yu }; 6847653b9d8SChao Yu 68539a53e0cSJaegeuk Kim struct f2fs_inode_info { 68639a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 68739a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 68839a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 68938431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 6901ad71a27SJaegeuk Kim unsigned int i_current_depth; /* only for directory depth */ 6912ef79ecbSChao Yu /* for gc failure statistic */ 6922ef79ecbSChao Yu unsigned int i_gc_failures[MAX_GC_FAILURE]; 6936666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 69439a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 69539a53e0cSJaegeuk Kim 69639a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 6977653b9d8SChao Yu unsigned long flags[BITS_TO_LONGS(FI_MAX)]; /* use to pass per-file flags */ 698d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 699204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 70039a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 70139a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 70288c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 703b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 70439a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 70526de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 706c10c9820SChao Yu spinlock_t i_size_lock; /* protect last_disk_size */ 70788b88a66SJaegeuk Kim 7080abd675eSChao Yu #ifdef CONFIG_QUOTA 7090abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 7100abd675eSChao Yu 7110abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 7120abd675eSChao Yu qsize_t i_reserved_quota; 7130abd675eSChao Yu #endif 7140f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 7150f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 71657864ae5SJaegeuk Kim struct list_head inmem_ilist; /* list for inmem inodes */ 71788b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 7187a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 71988b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 7206b12367dSJaegeuk Kim pgoff_t ra_offset; /* ongoing readahead offset */ 7213e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 722b2532c69SChao Yu 723b2532c69SChao Yu /* avoid racing between foreground op and gc */ 724b2532c69SChao Yu struct rw_semaphore i_gc_rwsem[2]; 7255a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 72627161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 727f2470371SChao Yu 7287a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 7295c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 7306afc662eSChao Yu int i_inline_xattr_size; /* inline xattr size */ 73124b81dfcSArnd Bergmann struct timespec64 i_crtime; /* inode creation time */ 73224b81dfcSArnd Bergmann struct timespec64 i_disk_time[4];/* inode disk times */ 7334c8ff709SChao Yu 7344c8ff709SChao Yu /* for file compress */ 735c2759ebaSDaeho Jeong atomic_t i_compr_blocks; /* # of compressed blocks */ 7364c8ff709SChao Yu unsigned char i_compress_algorithm; /* algorithm type */ 7374c8ff709SChao Yu unsigned char i_log_cluster_size; /* log of cluster size */ 738*b28f047bSChao Yu unsigned short i_compress_flag; /* compress flag */ 7394c8ff709SChao Yu unsigned int i_cluster_size; /* cluster size */ 74039a53e0cSJaegeuk Kim }; 74139a53e0cSJaegeuk Kim 74239a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 743bd933d4fSChao Yu struct f2fs_extent *i_ext) 74439a53e0cSJaegeuk Kim { 745bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 746bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 747bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 74839a53e0cSJaegeuk Kim } 74939a53e0cSJaegeuk Kim 75039a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 75139a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 75239a53e0cSJaegeuk Kim { 75339a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 7544d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 75539a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 75639a53e0cSJaegeuk Kim } 75739a53e0cSJaegeuk Kim 758429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 759429511cdSChao Yu u32 blk, unsigned int len) 760429511cdSChao Yu { 761429511cdSChao Yu ei->fofs = fofs; 762429511cdSChao Yu ei->blk = blk; 763429511cdSChao Yu ei->len = len; 764429511cdSChao Yu } 765429511cdSChao Yu 766004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 76735ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 768004b6862SChao Yu { 7699a997188SJaegeuk Kim return (back->lstart + back->len == front->lstart) && 77035ec7d57SChao Yu (back->len + front->len <= max_len); 771004b6862SChao Yu } 772004b6862SChao Yu 773004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 77435ec7d57SChao Yu struct discard_info *back, unsigned int max_len) 775004b6862SChao Yu { 77635ec7d57SChao Yu return __is_discard_mergeable(back, cur, max_len); 777004b6862SChao Yu } 778004b6862SChao Yu 779004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 78035ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 781004b6862SChao Yu { 78235ec7d57SChao Yu return __is_discard_mergeable(cur, front, max_len); 783004b6862SChao Yu } 784004b6862SChao Yu 785429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 786429511cdSChao Yu struct extent_info *front) 787429511cdSChao Yu { 788429511cdSChao Yu return (back->fofs + back->len == front->fofs && 789429511cdSChao Yu back->blk + back->len == front->blk); 790429511cdSChao Yu } 791429511cdSChao Yu 792429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 793429511cdSChao Yu struct extent_info *back) 794429511cdSChao Yu { 795429511cdSChao Yu return __is_extent_mergeable(back, cur); 796429511cdSChao Yu } 797429511cdSChao Yu 798429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 799429511cdSChao Yu struct extent_info *front) 800429511cdSChao Yu { 801429511cdSChao Yu return __is_extent_mergeable(cur, front); 802429511cdSChao Yu } 803429511cdSChao Yu 804cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 805b430f726SZhikang Zhang static inline void __try_update_largest_extent(struct extent_tree *et, 806b430f726SZhikang Zhang struct extent_node *en) 8074abd3f5aSChao Yu { 808205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 8094abd3f5aSChao Yu et->largest = en->ei; 810b430f726SZhikang Zhang et->largest_updated = true; 811205b9822SJaegeuk Kim } 8124abd3f5aSChao Yu } 8134abd3f5aSChao Yu 8149a4ffdf5SChao Yu /* 8159a4ffdf5SChao Yu * For free nid management 8169a4ffdf5SChao Yu */ 8179a4ffdf5SChao Yu enum nid_state { 8189a4ffdf5SChao Yu FREE_NID, /* newly added to free nid list */ 8199a4ffdf5SChao Yu PREALLOC_NID, /* it is preallocated */ 8209a4ffdf5SChao Yu MAX_NID_STATE, 821b8559dc2SChao Yu }; 822b8559dc2SChao Yu 82339a53e0cSJaegeuk Kim struct f2fs_nm_info { 82439a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 82539a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 82604d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 82739a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 828cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 829ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 8302304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 83139a53e0cSJaegeuk Kim 83239a53e0cSJaegeuk Kim /* NAT cache management */ 83339a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 834309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 835b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 83639a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 83722969158SChao Yu spinlock_t nat_list_lock; /* protect clean nat entry list */ 838309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 839aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 84022ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 84139a53e0cSJaegeuk Kim 84239a53e0cSJaegeuk Kim /* free node ids management */ 8438a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 8449a4ffdf5SChao Yu struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ 8459a4ffdf5SChao Yu unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 846b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 84739a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 848bb1105e4SJaegeuk Kim unsigned char **free_nid_bitmap; 8494ac91242SChao Yu unsigned char *nat_block_bitmap; 850586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 85139a53e0cSJaegeuk Kim 85239a53e0cSJaegeuk Kim /* for checkpoint */ 85339a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 85422ad0b6aSJaegeuk Kim 85522ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 85622ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 85722ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 85822ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 859599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 860599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 861599a09b2SChao Yu #endif 86239a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 86339a53e0cSJaegeuk Kim }; 86439a53e0cSJaegeuk Kim 86539a53e0cSJaegeuk Kim /* 86639a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 86739a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 86839a53e0cSJaegeuk Kim * by the data offset in a file. 86939a53e0cSJaegeuk Kim */ 87039a53e0cSJaegeuk Kim struct dnode_of_data { 87139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 87239a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 87339a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 87439a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 87539a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 87639a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 87793bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 8783cf45747SChao Yu char cur_level; /* level of hole node page */ 8793cf45747SChao Yu char max_level; /* level of current page located */ 88039a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 88139a53e0cSJaegeuk Kim }; 88239a53e0cSJaegeuk Kim 88339a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 88439a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 88539a53e0cSJaegeuk Kim { 886d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 88739a53e0cSJaegeuk Kim dn->inode = inode; 88839a53e0cSJaegeuk Kim dn->inode_page = ipage; 88939a53e0cSJaegeuk Kim dn->node_page = npage; 89039a53e0cSJaegeuk Kim dn->nid = nid; 89139a53e0cSJaegeuk Kim } 89239a53e0cSJaegeuk Kim 89339a53e0cSJaegeuk Kim /* 89439a53e0cSJaegeuk Kim * For SIT manager 89539a53e0cSJaegeuk Kim * 89639a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 89739a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 89839a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 89939a53e0cSJaegeuk Kim * respectively. 90039a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 90139a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 90239a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 90339a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 90439a53e0cSJaegeuk Kim * data and 8 for node logs. 90539a53e0cSJaegeuk Kim */ 90639a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 90739a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 908093749e2SChao Yu #define NR_CURSEG_INMEM_TYPE (2) 909d0b9e42aSChao Yu #define NR_CURSEG_PERSIST_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 910d0b9e42aSChao Yu #define NR_CURSEG_TYPE (NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE) 91139a53e0cSJaegeuk Kim 91239a53e0cSJaegeuk Kim enum { 91339a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 91439a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 91539a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 91639a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 91739a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 91839a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 919d0b9e42aSChao Yu NR_PERSISTENT_LOG, /* number of persistent log */ 920d0b9e42aSChao Yu CURSEG_COLD_DATA_PINNED = NR_PERSISTENT_LOG, 921d0b9e42aSChao Yu /* pinned file that needs consecutive block address */ 922093749e2SChao Yu CURSEG_ALL_DATA_ATGC, /* SSR alloctor in hot/warm/cold data area */ 923d0b9e42aSChao Yu NO_CHECK_TYPE, /* number of persistent & inmem log */ 92439a53e0cSJaegeuk Kim }; 92539a53e0cSJaegeuk Kim 9266b4afdd7SJaegeuk Kim struct flush_cmd { 9276b4afdd7SJaegeuk Kim struct completion wait; 928721bd4d5SGu Zheng struct llist_node llnode; 92939d787beSChao Yu nid_t ino; 9306b4afdd7SJaegeuk Kim int ret; 9316b4afdd7SJaegeuk Kim }; 9326b4afdd7SJaegeuk Kim 933a688b9d9SGu Zheng struct flush_cmd_control { 934a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 935a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 9368b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 93772691af6SJaegeuk Kim atomic_t queued_flush; /* # of queued flushes */ 938721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 939721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 940a688b9d9SGu Zheng }; 941a688b9d9SGu Zheng 94239a53e0cSJaegeuk Kim struct f2fs_sm_info { 94339a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 94439a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 94539a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 94639a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 94739a53e0cSJaegeuk Kim 9482b60311dSChao Yu struct rw_semaphore curseg_lock; /* for preventing curseg change */ 9492b60311dSChao Yu 95039a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 95139a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 95239a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 95339a53e0cSJaegeuk Kim 95439a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 95539a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 95639a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 95739a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 95881eb8d6eSJaegeuk Kim 95981eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 96081eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 9617fd9e544SJaegeuk Kim 962bba681cbSJaegeuk Kim /* for batched trimming */ 963bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 964bba681cbSJaegeuk Kim 965184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 966184a5cd2SChao Yu 967216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 968216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 969c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 970853137ceSJaegeuk Kim unsigned int min_seq_blocks; /* threshold for sequential blocks */ 971ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 972a2a12b67SChao Yu unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ 9736b4afdd7SJaegeuk Kim 9746b4afdd7SJaegeuk Kim /* for flush command control */ 975b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 976a688b9d9SGu Zheng 9770b54fb84SJaegeuk Kim /* for discard command control */ 9780b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 97939a53e0cSJaegeuk Kim }; 98039a53e0cSJaegeuk Kim 98139a53e0cSJaegeuk Kim /* 98239a53e0cSJaegeuk Kim * For superblock 98339a53e0cSJaegeuk Kim */ 98439a53e0cSJaegeuk Kim /* 98539a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 98639a53e0cSJaegeuk Kim * 98739a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 98839a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 98939a53e0cSJaegeuk Kim */ 99036951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 99139a53e0cSJaegeuk Kim enum count_type { 99239a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 993c227f912SChao Yu F2FS_DIRTY_DATA, 9942c8a4a28SJaegeuk Kim F2FS_DIRTY_QDATA, 99539a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 99639a53e0cSJaegeuk Kim F2FS_DIRTY_META, 9978dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 9980f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 99936951b38SChao Yu F2FS_WB_CP_DATA, 100036951b38SChao Yu F2FS_WB_DATA, 10015f9abab4SJaegeuk Kim F2FS_RD_DATA, 10025f9abab4SJaegeuk Kim F2FS_RD_NODE, 10035f9abab4SJaegeuk Kim F2FS_RD_META, 100402b16d0aSChao Yu F2FS_DIO_WRITE, 100502b16d0aSChao Yu F2FS_DIO_READ, 100639a53e0cSJaegeuk Kim NR_COUNT_TYPE, 100739a53e0cSJaegeuk Kim }; 100839a53e0cSJaegeuk Kim 100939a53e0cSJaegeuk Kim /* 1010e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 101139a53e0cSJaegeuk Kim * The available types are: 101239a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 101339a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 101439a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 101539a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 101639a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 101739a53e0cSJaegeuk Kim * with waiting the bio's completion 101839a53e0cSJaegeuk Kim * ... Only can be used with META. 101939a53e0cSJaegeuk Kim */ 10207d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 102139a53e0cSJaegeuk Kim enum page_type { 102239a53e0cSJaegeuk Kim DATA, 102339a53e0cSJaegeuk Kim NODE, 102439a53e0cSJaegeuk Kim META, 102539a53e0cSJaegeuk Kim NR_PAGE_TYPE, 102639a53e0cSJaegeuk Kim META_FLUSH, 10278ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 10288ce67cb0SJaegeuk Kim INMEM_DROP, 10298c242db9SJaegeuk Kim INMEM_INVALIDATE, 103028bc106bSChao Yu INMEM_REVOKE, 10318ce67cb0SJaegeuk Kim IPU, 10328ce67cb0SJaegeuk Kim OPU, 103339a53e0cSJaegeuk Kim }; 103439a53e0cSJaegeuk Kim 1035a912b54dSJaegeuk Kim enum temp_type { 1036a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 1037a912b54dSJaegeuk Kim WARM, 1038a912b54dSJaegeuk Kim COLD, 1039a912b54dSJaegeuk Kim NR_TEMP_TYPE, 1040a912b54dSJaegeuk Kim }; 1041a912b54dSJaegeuk Kim 1042cc15620bSJaegeuk Kim enum need_lock_type { 1043cc15620bSJaegeuk Kim LOCK_REQ = 0, 1044cc15620bSJaegeuk Kim LOCK_DONE, 1045cc15620bSJaegeuk Kim LOCK_RETRY, 1046cc15620bSJaegeuk Kim }; 1047cc15620bSJaegeuk Kim 1048a5fd5050SChao Yu enum cp_reason_type { 1049a5fd5050SChao Yu CP_NO_NEEDED, 1050a5fd5050SChao Yu CP_NON_REGULAR, 10514c8ff709SChao Yu CP_COMPRESSED, 1052a5fd5050SChao Yu CP_HARDLINK, 1053a5fd5050SChao Yu CP_SB_NEED_CP, 1054a5fd5050SChao Yu CP_WRONG_PINO, 1055a5fd5050SChao Yu CP_NO_SPC_ROLL, 1056a5fd5050SChao Yu CP_NODE_NEED_CP, 1057a5fd5050SChao Yu CP_FASTBOOT_MODE, 1058a5fd5050SChao Yu CP_SPEC_LOG_NUM, 10590a007b97SJaegeuk Kim CP_RECOVER_DIR, 1060a5fd5050SChao Yu }; 1061a5fd5050SChao Yu 1062b0af6d49SChao Yu enum iostat_type { 10638b83ac81SChao Yu /* WRITE IO */ 10648b83ac81SChao Yu APP_DIRECT_IO, /* app direct write IOs */ 10658b83ac81SChao Yu APP_BUFFERED_IO, /* app buffered write IOs */ 1066b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 1067b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 1068b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 1069b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 1070b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 1071b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 1072b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 1073b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 1074b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 1075b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 10768b83ac81SChao Yu 10778b83ac81SChao Yu /* READ IO */ 10788b83ac81SChao Yu APP_DIRECT_READ_IO, /* app direct read IOs */ 10798b83ac81SChao Yu APP_BUFFERED_READ_IO, /* app buffered read IOs */ 10808b83ac81SChao Yu APP_READ_IO, /* app read IOs */ 10818b83ac81SChao Yu APP_MAPPED_READ_IO, /* app mapped read IOs */ 10828b83ac81SChao Yu FS_DATA_READ_IO, /* data read IOs */ 10839c122384SChao Yu FS_GDATA_READ_IO, /* data read IOs from background gc */ 10849c122384SChao Yu FS_CDATA_READ_IO, /* compressed data read IOs */ 10858b83ac81SChao Yu FS_NODE_READ_IO, /* node read IOs */ 10868b83ac81SChao Yu FS_META_READ_IO, /* meta read IOs */ 10878b83ac81SChao Yu 10888b83ac81SChao Yu /* other */ 1089b0af6d49SChao Yu FS_DISCARD, /* discard */ 1090b0af6d49SChao Yu NR_IO_TYPE, 1091b0af6d49SChao Yu }; 1092b0af6d49SChao Yu 1093458e6197SJaegeuk Kim struct f2fs_io_info { 109405ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 109539d787beSChao Yu nid_t ino; /* inode number */ 1096458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 1097a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 109804d328deSMike Christie int op; /* contains REQ_OP_ */ 1099ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 11007a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 110128bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 110205ca3632SJaegeuk Kim struct page *page; /* page to be written */ 11034375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 11044c8ff709SChao Yu struct page *compressed_page; /* compressed page */ 1105fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 1106d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 1107cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 1108fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 11096dc3a126SChao Yu bool is_por; /* indicate IO is from recovery or not */ 1110fe16efe6SChao Yu bool retry; /* need to reallocate block address */ 11114c8ff709SChao Yu int compr_blocks; /* # of compressed block addresses */ 11124c8ff709SChao Yu bool encrypted; /* indicate file is encrypted */ 1113b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 1114578c6478SYufen Yu struct writeback_control *io_wbc; /* writeback control */ 11158648de2cSChao Yu struct bio **bio; /* bio for ipu */ 11168648de2cSChao Yu sector_t *last_block; /* last block number in bio */ 11177735730dSChao Yu unsigned char version; /* version of the node */ 1118458e6197SJaegeuk Kim }; 1119458e6197SJaegeuk Kim 11200b20fcecSChao Yu struct bio_entry { 11210b20fcecSChao Yu struct bio *bio; 11220b20fcecSChao Yu struct list_head list; 11230b20fcecSChao Yu }; 11240b20fcecSChao Yu 112568afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 11261ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 1127458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 11281ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 11291ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 1130458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 1131df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 1132fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 1133fb830fc5SChao Yu struct list_head io_list; /* track fios */ 11340b20fcecSChao Yu struct list_head bio_list; /* bio entry list head */ 11350b20fcecSChao Yu struct rw_semaphore bio_list_lock; /* lock to protect bio entry list */ 11361ff7bd3bSJaegeuk Kim }; 11371ff7bd3bSJaegeuk Kim 11383c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 11393c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 11403c62be17SJaegeuk Kim struct f2fs_dev_info { 11413c62be17SJaegeuk Kim struct block_device *bdev; 11423c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 11433c62be17SJaegeuk Kim unsigned int total_segments; 11443c62be17SJaegeuk Kim block_t start_blk; 11453c62be17SJaegeuk Kim block_t end_blk; 11463c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 11473c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 114895175dafSDamien Le Moal unsigned long *blkz_seq; /* Bitmap indicating sequential zones */ 1149de881df9SAravind Ramesh block_t *zone_capacity_blocks; /* Array of zone capacity in blks */ 11503c62be17SJaegeuk Kim #endif 11513c62be17SJaegeuk Kim }; 11523c62be17SJaegeuk Kim 1153c227f912SChao Yu enum inode_type { 1154c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 1155c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 11560f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 115757864ae5SJaegeuk Kim ATOMIC_FILE, /* for all atomic files */ 1158c227f912SChao Yu NR_INODE_TYPE, 1159c227f912SChao Yu }; 1160c227f912SChao Yu 116167298804SChao Yu /* for inner inode cache management */ 116267298804SChao Yu struct inode_management { 116367298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 116467298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 116567298804SChao Yu struct list_head ino_list; /* inode list head */ 116667298804SChao Yu unsigned long ino_num; /* number of entries */ 116767298804SChao Yu }; 116867298804SChao Yu 1169093749e2SChao Yu /* for GC_AT */ 1170093749e2SChao Yu struct atgc_management { 1171093749e2SChao Yu bool atgc_enabled; /* ATGC is enabled or not */ 1172093749e2SChao Yu struct rb_root_cached root; /* root of victim rb-tree */ 1173093749e2SChao Yu struct list_head victim_list; /* linked with all victim entries */ 1174093749e2SChao Yu unsigned int victim_count; /* victim count in rb-tree */ 1175093749e2SChao Yu unsigned int candidate_ratio; /* candidate ratio */ 1176093749e2SChao Yu unsigned int max_candidate_count; /* max candidate count */ 1177093749e2SChao Yu unsigned int age_weight; /* age weight, vblock_weight = 100 - age_weight */ 1178093749e2SChao Yu unsigned long long age_threshold; /* age threshold */ 1179093749e2SChao Yu }; 1180093749e2SChao Yu 1181caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 1182caf0047eSChao Yu enum { 1183caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 1184caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 1185caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 1186caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 1187df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 1188bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 118983a3bfdbSJaegeuk Kim SBI_IS_SHUTDOWN, /* shutdown by ioctl */ 11901378752bSChao Yu SBI_IS_RECOVERED, /* recovered orphan/data */ 11914354994fSDaniel Rosenberg SBI_CP_DISABLED, /* CP was disabled last mount */ 1192db610a64SJaegeuk Kim SBI_CP_DISABLED_QUICK, /* CP was disabled quickly */ 1193af033b2aSChao Yu SBI_QUOTA_NEED_FLUSH, /* need to flush quota info in CP */ 1194af033b2aSChao Yu SBI_QUOTA_SKIP_FLUSH, /* skip flushing quota in current CP */ 1195af033b2aSChao Yu SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */ 119604f0b2eaSQiuyang Sun SBI_IS_RESIZEFS, /* resizefs is in process */ 1197caf0047eSChao Yu }; 1198caf0047eSChao Yu 11996beceb54SJaegeuk Kim enum { 12006beceb54SJaegeuk Kim CP_TIME, 1201d0239e1bSJaegeuk Kim REQ_TIME, 1202a7d10cf3SSahitya Tummala DISCARD_TIME, 1203a7d10cf3SSahitya Tummala GC_TIME, 12044354994fSDaniel Rosenberg DISABLE_TIME, 120503f2c02dSJaegeuk Kim UMOUNT_DISCARD_TIMEOUT, 12066beceb54SJaegeuk Kim MAX_TIME, 12076beceb54SJaegeuk Kim }; 12086beceb54SJaegeuk Kim 12090cdd3195SHyunchul Lee enum { 12105b0e9539SJaegeuk Kim GC_NORMAL, 12115b0e9539SJaegeuk Kim GC_IDLE_CB, 12125b0e9539SJaegeuk Kim GC_IDLE_GREEDY, 1213093749e2SChao Yu GC_IDLE_AT, 12140e5e8111SDaeho Jeong GC_URGENT_HIGH, 12150e5e8111SDaeho Jeong GC_URGENT_LOW, 12165b0e9539SJaegeuk Kim }; 12175b0e9539SJaegeuk Kim 12185b0e9539SJaegeuk Kim enum { 1219bbbc34fdSChao Yu BGGC_MODE_ON, /* background gc is on */ 1220bbbc34fdSChao Yu BGGC_MODE_OFF, /* background gc is off */ 1221bbbc34fdSChao Yu BGGC_MODE_SYNC, /* 1222bbbc34fdSChao Yu * background gc is on, migrating blocks 1223bbbc34fdSChao Yu * like foreground gc 1224bbbc34fdSChao Yu */ 1225bbbc34fdSChao Yu }; 1226bbbc34fdSChao Yu 1227bbbc34fdSChao Yu enum { 1228b0332a0fSChao Yu FS_MODE_ADAPTIVE, /* use both lfs/ssr allocation */ 1229b0332a0fSChao Yu FS_MODE_LFS, /* use lfs allocation only */ 1230b0332a0fSChao Yu }; 1231b0332a0fSChao Yu 1232b0332a0fSChao Yu enum { 12330cdd3195SHyunchul Lee WHINT_MODE_OFF, /* not pass down write hints */ 12340cdd3195SHyunchul Lee WHINT_MODE_USER, /* try to pass down hints given by users */ 1235f2e703f9SHyunchul Lee WHINT_MODE_FS, /* pass down hints with F2FS policy */ 12360cdd3195SHyunchul Lee }; 12370cdd3195SHyunchul Lee 123807939627SJaegeuk Kim enum { 123907939627SJaegeuk Kim ALLOC_MODE_DEFAULT, /* stay default */ 124007939627SJaegeuk Kim ALLOC_MODE_REUSE, /* reuse segments as much as possible */ 124107939627SJaegeuk Kim }; 124207939627SJaegeuk Kim 124393cf93f1SJunling Zheng enum fsync_mode { 124493cf93f1SJunling Zheng FSYNC_MODE_POSIX, /* fsync follows posix semantics */ 124593cf93f1SJunling Zheng FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */ 1246d6290814SJaegeuk Kim FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */ 124793cf93f1SJunling Zheng }; 124893cf93f1SJunling Zheng 12494c8ff709SChao Yu /* 12504c8ff709SChao Yu * this value is set in page as a private data which indicate that 12514c8ff709SChao Yu * the page is atomically written, and it is in inmem_pages list. 12524c8ff709SChao Yu */ 12534c8ff709SChao Yu #define ATOMIC_WRITTEN_PAGE ((unsigned long)-1) 12544c8ff709SChao Yu #define DUMMY_WRITTEN_PAGE ((unsigned long)-2) 12554c8ff709SChao Yu 12564c8ff709SChao Yu #define IS_ATOMIC_WRITTEN_PAGE(page) \ 1257e90027d2SXiaojun Wang (page_private(page) == ATOMIC_WRITTEN_PAGE) 12584c8ff709SChao Yu #define IS_DUMMY_WRITTEN_PAGE(page) \ 1259e90027d2SXiaojun Wang (page_private(page) == DUMMY_WRITTEN_PAGE) 12604c8ff709SChao Yu 126129b993c7SYu Changchun #ifdef CONFIG_F2FS_IO_TRACE 126229b993c7SYu Changchun #define IS_IO_TRACED_PAGE(page) \ 126329b993c7SYu Changchun (page_private(page) > 0 && \ 126429b993c7SYu Changchun page_private(page) < (unsigned long)PID_MAX_LIMIT) 126529b993c7SYu Changchun #else 126629b993c7SYu Changchun #define IS_IO_TRACED_PAGE(page) (0) 126729b993c7SYu Changchun #endif 126829b993c7SYu Changchun 12694c8ff709SChao Yu /* For compression */ 12704c8ff709SChao Yu enum compress_algorithm_type { 12714c8ff709SChao Yu COMPRESS_LZO, 12724c8ff709SChao Yu COMPRESS_LZ4, 127350cfa66fSChao Yu COMPRESS_ZSTD, 12746d92b201SChao Yu COMPRESS_LZORLE, 12754c8ff709SChao Yu COMPRESS_MAX, 12764c8ff709SChao Yu }; 12774c8ff709SChao Yu 1278*b28f047bSChao Yu enum compress_flag { 1279*b28f047bSChao Yu COMPRESS_CHKSUM, 1280*b28f047bSChao Yu COMPRESS_MAX_FLAG, 1281*b28f047bSChao Yu }; 1282*b28f047bSChao Yu 1283*b28f047bSChao Yu #define COMPRESS_DATA_RESERVED_SIZE 4 12844c8ff709SChao Yu struct compress_data { 12854c8ff709SChao Yu __le32 clen; /* compressed data size */ 1286*b28f047bSChao Yu __le32 chksum; /* compressed data chksum */ 12874c8ff709SChao Yu __le32 reserved[COMPRESS_DATA_RESERVED_SIZE]; /* reserved */ 12884c8ff709SChao Yu u8 cdata[]; /* compressed data */ 12894c8ff709SChao Yu }; 12904c8ff709SChao Yu 12914c8ff709SChao Yu #define COMPRESS_HEADER_SIZE (sizeof(struct compress_data)) 12924c8ff709SChao Yu 12934c8ff709SChao Yu #define F2FS_COMPRESSED_PAGE_MAGIC 0xF5F2C000 12944c8ff709SChao Yu 12954c8ff709SChao Yu /* compress context */ 12964c8ff709SChao Yu struct compress_ctx { 12974c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 12984c8ff709SChao Yu pgoff_t cluster_idx; /* cluster index number */ 12994c8ff709SChao Yu unsigned int cluster_size; /* page count in cluster */ 13004c8ff709SChao Yu unsigned int log_cluster_size; /* log of cluster size */ 13014c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 13024c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 13034c8ff709SChao Yu struct page **cpages; /* pages store compressed data in cluster */ 13044c8ff709SChao Yu unsigned int nr_cpages; /* total page number in cpages */ 13054c8ff709SChao Yu void *rbuf; /* virtual mapped address on rpages */ 13064c8ff709SChao Yu struct compress_data *cbuf; /* virtual mapped address on cpages */ 13074c8ff709SChao Yu size_t rlen; /* valid data length in rbuf */ 13084c8ff709SChao Yu size_t clen; /* valid data length in cbuf */ 13094c8ff709SChao Yu void *private; /* payload buffer for specified compression algorithm */ 131050cfa66fSChao Yu void *private2; /* extra payload buffer */ 13114c8ff709SChao Yu }; 13124c8ff709SChao Yu 13134c8ff709SChao Yu /* compress context for write IO path */ 13144c8ff709SChao Yu struct compress_io_ctx { 13154c8ff709SChao Yu u32 magic; /* magic number to indicate page is compressed */ 13164c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 13174c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 13184c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 1319e6c3948dSChao Yu atomic_t pending_pages; /* in-flight compressed page count */ 13204c8ff709SChao Yu }; 13214c8ff709SChao Yu 13224c8ff709SChao Yu /* decompress io context for read IO path */ 13234c8ff709SChao Yu struct decompress_io_ctx { 13244c8ff709SChao Yu u32 magic; /* magic number to indicate page is compressed */ 13254c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 13264c8ff709SChao Yu pgoff_t cluster_idx; /* cluster index number */ 13274c8ff709SChao Yu unsigned int cluster_size; /* page count in cluster */ 13284c8ff709SChao Yu unsigned int log_cluster_size; /* log of cluster size */ 13294c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 13304c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 13314c8ff709SChao Yu struct page **cpages; /* pages store compressed data in cluster */ 13324c8ff709SChao Yu unsigned int nr_cpages; /* total page number in cpages */ 13334c8ff709SChao Yu struct page **tpages; /* temp pages to pad holes in cluster */ 13344c8ff709SChao Yu void *rbuf; /* virtual mapped address on rpages */ 13354c8ff709SChao Yu struct compress_data *cbuf; /* virtual mapped address on cpages */ 13364c8ff709SChao Yu size_t rlen; /* valid data length in rbuf */ 13374c8ff709SChao Yu size_t clen; /* valid data length in cbuf */ 1338e6c3948dSChao Yu atomic_t pending_pages; /* in-flight compressed page count */ 13394c8ff709SChao Yu bool failed; /* indicate IO error during decompression */ 134050cfa66fSChao Yu void *private; /* payload buffer for specified decompression algorithm */ 134150cfa66fSChao Yu void *private2; /* extra payload buffer */ 13424c8ff709SChao Yu }; 13434c8ff709SChao Yu 13444c8ff709SChao Yu #define NULL_CLUSTER ((unsigned int)(~0)) 13454c8ff709SChao Yu #define MIN_COMPRESS_LOG_SIZE 2 13464c8ff709SChao Yu #define MAX_COMPRESS_LOG_SIZE 8 13470e2b7385SChao Yu #define MAX_COMPRESS_WINDOW_SIZE(log_size) ((PAGE_SIZE) << (log_size)) 13484c8ff709SChao Yu 134939a53e0cSJaegeuk Kim struct f2fs_sb_info { 135039a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 13515e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 135239a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 1353846ae671SChao Yu struct rw_semaphore sb_lock; /* lock for raw super block */ 1354e8240f65SChao Yu int valid_super_block; /* valid super block no */ 1355fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 1356853137ceSJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 135739a53e0cSJaegeuk Kim 1358178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 1359178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1360178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 1361178053e2SDamien Le Moal #endif 1362178053e2SDamien Le Moal 136339a53e0cSJaegeuk Kim /* for node-related operations */ 136439a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 136539a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 136639a53e0cSJaegeuk Kim 136739a53e0cSJaegeuk Kim /* for segment-related operations */ 136839a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 13691ff7bd3bSJaegeuk Kim 13701ff7bd3bSJaegeuk Kim /* for bio operations */ 1371a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1372107a805dSChao Yu /* keep migration IO order for LFS mode */ 1373107a805dSChao Yu struct rw_semaphore io_order_lock; 13740a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 137539a53e0cSJaegeuk Kim 137639a53e0cSJaegeuk Kim /* for checkpoint */ 137739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 13788508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1379aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 138039a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 13818769918bSSahitya Tummala struct rw_semaphore cp_global_sem; /* checkpoint procedure lock */ 1382b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1383b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 138459c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1385fb51b5efSChangman Lee wait_queue_head_t cp_wait; 13866beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 13876beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 138839a53e0cSJaegeuk Kim 138967298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 13906451e041SJaegeuk Kim 139150fa53ecSChao Yu spinlock_t fsync_node_lock; /* for node entry lock */ 139250fa53ecSChao Yu struct list_head fsync_node_list; /* node list head */ 139350fa53ecSChao Yu unsigned int fsync_seg_id; /* sequence id */ 139450fa53ecSChao Yu unsigned int fsync_node_num; /* number of node entries */ 139550fa53ecSChao Yu 13966451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 13970d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 139839a53e0cSJaegeuk Kim 1399c227f912SChao Yu /* for inode management */ 1400c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1401c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 1402040d2bb3SChao Yu struct mutex flush_lock; /* for flush exclusion */ 140339a53e0cSJaegeuk Kim 140413054c54SChao Yu /* for extent tree cache */ 140513054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 14065e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 140713054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 140813054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 14097441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1410137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 141174fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 141213054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 141313054c54SChao Yu 141439a53e0cSJaegeuk Kim /* basic filesystem units */ 141539a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 141639a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 141739a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 141839a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 141939a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 142039a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 142139a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 142239a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 142339a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 142439a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 142539a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 142639a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 142739a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1428e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 1429ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 1430f6df8f23SSheng Yong int readdir_ra; /* readahead inode in readdir */ 143139a53e0cSJaegeuk Kim 143239a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 143339a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1434a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 143539a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1436daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 143780d42145SYunlong Song block_t current_reserved_blocks; /* current reserved blocks */ 1438daeb433eSChao Yu 14394354994fSDaniel Rosenberg /* Additional tracking for no checkpoint mode */ 14404354994fSDaniel Rosenberg block_t unusable_block_count; /* # of blocks saved by last cp */ 14414354994fSDaniel Rosenberg 1442292c196aSChao Yu unsigned int nquota_files; /* # of quota sysfile */ 1443db6ec53bSJaegeuk Kim struct rw_semaphore quota_sem; /* blocking cp for flags */ 1444292c196aSChao Yu 1445523be8a6SJaegeuk Kim /* # of pages, see count_type */ 144635782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 144741382ec4SJaegeuk Kim /* # of allocated blocks */ 144841382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 144939a53e0cSJaegeuk Kim 1450687de7f1SJaegeuk Kim /* writeback control */ 1451c29fd0c0SChao Yu atomic_t wb_sync_req[META]; /* count # of WB_SYNC threads */ 1452687de7f1SJaegeuk Kim 1453513c5f37SJaegeuk Kim /* valid inode count */ 1454513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1455513c5f37SJaegeuk Kim 145639a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 145739a53e0cSJaegeuk Kim 145839a53e0cSJaegeuk Kim /* for cleaning operations */ 1459fb24fea7SChao Yu struct rw_semaphore gc_lock; /* 1460fb24fea7SChao Yu * semaphore for GC, avoid 1461fb24fea7SChao Yu * race between GC and GC or CP 1462fb24fea7SChao Yu */ 146339a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 1464093749e2SChao Yu struct atgc_management am; /* atgc management */ 14655ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 14665b0e9539SJaegeuk Kim unsigned int gc_mode; /* current GC state */ 1467e3080b01SChao Yu unsigned int next_victim_seg[2]; /* next segment in victim section */ 14680e5e8111SDaeho Jeong 14692ef79ecbSChao Yu /* for skip statistic */ 1470677017d1SSahitya Tummala unsigned int atomic_files; /* # of opened atomic file */ 14712ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */ 14726f8d4455SJaegeuk Kim unsigned long long skipped_gc_rwsem; /* FG_GC only */ 147339a53e0cSJaegeuk Kim 14741ad71a27SJaegeuk Kim /* threshold for gc trials on pinned files */ 14751ad71a27SJaegeuk Kim u64 gc_pin_file_threshold; 1476f5a53edcSJaegeuk Kim struct rw_semaphore pin_sem; 14771ad71a27SJaegeuk Kim 1478b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1479b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1480e3080b01SChao Yu /* migration granularity of garbage collection, unit: segment */ 1481e3080b01SChao Yu unsigned int migration_granularity; 1482b1c57c1cSJaegeuk Kim 148339a53e0cSJaegeuk Kim /* 148439a53e0cSJaegeuk Kim * for stat information. 148539a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 148639a53e0cSJaegeuk Kim */ 148735b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 148839a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 1489b63e7be5SChao Yu atomic_t meta_count[META_MAX]; /* # of meta blocks */ 149039a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 149139a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1492b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 14935b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 14945b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 14955b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 14965b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1497d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 149803e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 149903e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 15004c8ff709SChao Yu atomic_t compr_inode; /* # of compressed inodes */ 1501ae999bb9SDaeho Jeong atomic64_t compr_blocks; /* # of compressed blocks */ 1502648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 150326a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1504648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 1505274bd9baSChao Yu unsigned int io_skip_bggc; /* skip background gc for in-flight IO */ 1506274bd9baSChao Yu unsigned int other_skip_bggc; /* skip background gc for other reasons */ 150733fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 150835b09d82SNamjae Jeon #endif 150939a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1510b59d0baeSNamjae Jeon 1511b0af6d49SChao Yu /* For app/fs IO statistics */ 1512b0af6d49SChao Yu spinlock_t iostat_lock; 15138b83ac81SChao Yu unsigned long long rw_iostat[NR_IO_TYPE]; 15148b83ac81SChao Yu unsigned long long prev_rw_iostat[NR_IO_TYPE]; 1515b0af6d49SChao Yu bool iostat_enable; 15162bc4bea3SDaeho Jeong unsigned long iostat_next_period; 15172bc4bea3SDaeho Jeong unsigned int iostat_period_ms; 1518b0af6d49SChao Yu 1519da9953b7SJaegeuk Kim /* to attach REQ_META|REQ_FUA flags */ 1520da9953b7SJaegeuk Kim unsigned int data_io_flag; 152132b6aba8SJaegeuk Kim unsigned int node_io_flag; 1522b59d0baeSNamjae Jeon 1523b59d0baeSNamjae Jeon /* For sysfs suppport */ 1524b59d0baeSNamjae Jeon struct kobject s_kobj; 1525b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 15262658e50dSJaegeuk Kim 15272658e50dSJaegeuk Kim /* For shrinker support */ 15282658e50dSJaegeuk Kim struct list_head s_list; 15293c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 15303c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 15311228b482SChao Yu unsigned int dirty_device; /* for checkpoint data flush */ 15321228b482SChao Yu spinlock_t dev_lock; /* protect dirty_device */ 15332658e50dSJaegeuk Kim struct mutex umount_mutex; 15342658e50dSJaegeuk Kim unsigned int shrinker_run_no; 15358f1dbbbbSShuoran Liu 15368f1dbbbbSShuoran Liu /* For write statistics */ 15378f1dbbbbSShuoran Liu u64 sectors_written_start; 15388f1dbbbbSShuoran Liu u64 kbytes_written; 153943b6573bSKeith Mok 154043b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 154143b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 15421ecc0c5cSChao Yu 1543704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1544704956ecSChao Yu __u32 s_chksum_seed; 15454c8ff709SChao Yu 15464c8ff709SChao Yu struct workqueue_struct *post_read_wq; /* post read workqueue */ 1547a999150fSChao Yu 1548a999150fSChao Yu struct kmem_cache *inline_xattr_slab; /* inline xattr entry */ 1549a999150fSChao Yu unsigned int inline_xattr_slab_size; /* default inline xattr slab size */ 155031083031SChao Yu 155131083031SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 155231083031SChao Yu struct kmem_cache *page_array_slab; /* page array entry */ 155331083031SChao Yu unsigned int page_array_slab_size; /* default page array slab size */ 155431083031SChao Yu #endif 155539a53e0cSJaegeuk Kim }; 155639a53e0cSJaegeuk Kim 155702b16d0aSChao Yu struct f2fs_private_dio { 155802b16d0aSChao Yu struct inode *inode; 155902b16d0aSChao Yu void *orig_private; 156002b16d0aSChao Yu bio_end_io_t *orig_end_io; 156102b16d0aSChao Yu bool write; 156202b16d0aSChao Yu }; 156302b16d0aSChao Yu 15641ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 1565c45d6002SChao Yu #define f2fs_show_injection_info(sbi, type) \ 1566c45d6002SChao Yu printk_ratelimited("%sF2FS-fs (%s) : inject %s in %s of %pS\n", \ 1567c45d6002SChao Yu KERN_INFO, sbi->sb->s_id, \ 1568c45d6002SChao Yu f2fs_fault_name[type], \ 156955523519SChao Yu __func__, __builtin_return_address(0)) 15701ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 15711ecc0c5cSChao Yu { 157263189b78SChao Yu struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; 15731ecc0c5cSChao Yu 15741ecc0c5cSChao Yu if (!ffi->inject_rate) 15751ecc0c5cSChao Yu return false; 15761ecc0c5cSChao Yu 15771ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 15781ecc0c5cSChao Yu return false; 15791ecc0c5cSChao Yu 15801ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 15811ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 15821ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 15831ecc0c5cSChao Yu return true; 15841ecc0c5cSChao Yu } 15851ecc0c5cSChao Yu return false; 15861ecc0c5cSChao Yu } 15877fa750a1SArnd Bergmann #else 1588c45d6002SChao Yu #define f2fs_show_injection_info(sbi, type) do { } while (0) 15897fa750a1SArnd Bergmann static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 15907fa750a1SArnd Bergmann { 15917fa750a1SArnd Bergmann return false; 15927fa750a1SArnd Bergmann } 15931ecc0c5cSChao Yu #endif 15941ecc0c5cSChao Yu 15950916878dSDamien Le Moal /* 15960916878dSDamien Le Moal * Test if the mounted volume is a multi-device volume. 15970916878dSDamien Le Moal * - For a single regular disk volume, sbi->s_ndevs is 0. 15980916878dSDamien Le Moal * - For a single zoned disk volume, sbi->s_ndevs is 1. 15990916878dSDamien Le Moal * - For a multi-device volume, sbi->s_ndevs is always 2 or more. 16000916878dSDamien Le Moal */ 16010916878dSDamien Le Moal static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi) 16020916878dSDamien Le Moal { 16030916878dSDamien Le Moal return sbi->s_ndevs > 1; 16040916878dSDamien Le Moal } 16050916878dSDamien Le Moal 16068f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 16078f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 16088f1dbbbbSShuoran Liu */ 16098f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 1610dbae2c55SMichael Callahan (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[STAT_WRITE]) - \ 161168afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 16128f1dbbbbSShuoran Liu 16136beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 16146beceb54SJaegeuk Kim { 1615a7d10cf3SSahitya Tummala unsigned long now = jiffies; 1616a7d10cf3SSahitya Tummala 1617a7d10cf3SSahitya Tummala sbi->last_time[type] = now; 1618a7d10cf3SSahitya Tummala 1619a7d10cf3SSahitya Tummala /* DISCARD_TIME and GC_TIME are based on REQ_TIME */ 1620a7d10cf3SSahitya Tummala if (type == REQ_TIME) { 1621a7d10cf3SSahitya Tummala sbi->last_time[DISCARD_TIME] = now; 1622a7d10cf3SSahitya Tummala sbi->last_time[GC_TIME] = now; 1623a7d10cf3SSahitya Tummala } 16246beceb54SJaegeuk Kim } 16256beceb54SJaegeuk Kim 16266beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 16276beceb54SJaegeuk Kim { 16286bccfa19SArnd Bergmann unsigned long interval = sbi->interval_time[type] * HZ; 16296beceb54SJaegeuk Kim 16306beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 16316beceb54SJaegeuk Kim } 16326beceb54SJaegeuk Kim 1633a7d10cf3SSahitya Tummala static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi, 1634a7d10cf3SSahitya Tummala int type) 1635a7d10cf3SSahitya Tummala { 1636a7d10cf3SSahitya Tummala unsigned long interval = sbi->interval_time[type] * HZ; 1637a7d10cf3SSahitya Tummala unsigned int wait_ms = 0; 1638a7d10cf3SSahitya Tummala long delta; 1639a7d10cf3SSahitya Tummala 1640a7d10cf3SSahitya Tummala delta = (sbi->last_time[type] + interval) - jiffies; 1641a7d10cf3SSahitya Tummala if (delta > 0) 1642a7d10cf3SSahitya Tummala wait_ms = jiffies_to_msecs(delta); 1643a7d10cf3SSahitya Tummala 1644a7d10cf3SSahitya Tummala return wait_ms; 1645a7d10cf3SSahitya Tummala } 1646a7d10cf3SSahitya Tummala 164739a53e0cSJaegeuk Kim /* 164839a53e0cSJaegeuk Kim * Inline functions 164939a53e0cSJaegeuk Kim */ 1650416d2dbbSChao Yu static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc, 1651704956ecSChao Yu const void *address, unsigned int length) 1652704956ecSChao Yu { 1653704956ecSChao Yu struct { 1654704956ecSChao Yu struct shash_desc shash; 1655704956ecSChao Yu char ctx[4]; 1656704956ecSChao Yu } desc; 1657704956ecSChao Yu int err; 1658704956ecSChao Yu 1659704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1660704956ecSChao Yu 1661704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1662704956ecSChao Yu *(u32 *)desc.ctx = crc; 1663704956ecSChao Yu 1664704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1665704956ecSChao Yu BUG_ON(err); 1666704956ecSChao Yu 1667704956ecSChao Yu return *(u32 *)desc.ctx; 1668704956ecSChao Yu } 1669704956ecSChao Yu 1670416d2dbbSChao Yu static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 1671416d2dbbSChao Yu unsigned int length) 1672416d2dbbSChao Yu { 1673416d2dbbSChao Yu return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length); 1674416d2dbbSChao Yu } 1675416d2dbbSChao Yu 1676416d2dbbSChao Yu static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 1677416d2dbbSChao Yu void *buf, size_t buf_size) 1678416d2dbbSChao Yu { 1679416d2dbbSChao Yu return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 1680416d2dbbSChao Yu } 1681416d2dbbSChao Yu 1682416d2dbbSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1683416d2dbbSChao Yu const void *address, unsigned int length) 1684416d2dbbSChao Yu { 1685416d2dbbSChao Yu return __f2fs_crc32(sbi, crc, address, length); 1686416d2dbbSChao Yu } 1687416d2dbbSChao Yu 168839a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 168939a53e0cSJaegeuk Kim { 169039a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 169139a53e0cSJaegeuk Kim } 169239a53e0cSJaegeuk Kim 169339a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 169439a53e0cSJaegeuk Kim { 169539a53e0cSJaegeuk Kim return sb->s_fs_info; 169639a53e0cSJaegeuk Kim } 169739a53e0cSJaegeuk Kim 16984081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 16994081363fSJaegeuk Kim { 17004081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 17014081363fSJaegeuk Kim } 17024081363fSJaegeuk Kim 17034081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 17044081363fSJaegeuk Kim { 17054081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 17064081363fSJaegeuk Kim } 17074081363fSJaegeuk Kim 17084081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 17094081363fSJaegeuk Kim { 17104969c06aSJaegeuk Kim return F2FS_M_SB(page_file_mapping(page)); 17114081363fSJaegeuk Kim } 17124081363fSJaegeuk Kim 171339a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 171439a53e0cSJaegeuk Kim { 171539a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 171639a53e0cSJaegeuk Kim } 171739a53e0cSJaegeuk Kim 171839a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 171939a53e0cSJaegeuk Kim { 172039a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 172139a53e0cSJaegeuk Kim } 172239a53e0cSJaegeuk Kim 172345590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 172445590710SGu Zheng { 172545590710SGu Zheng return (struct f2fs_node *)page_address(page); 172645590710SGu Zheng } 172745590710SGu Zheng 172858bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 172958bfaf44SJaegeuk Kim { 173058bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 173158bfaf44SJaegeuk Kim } 173258bfaf44SJaegeuk Kim 173339a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 173439a53e0cSJaegeuk Kim { 173539a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 173639a53e0cSJaegeuk Kim } 173739a53e0cSJaegeuk Kim 173839a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 173939a53e0cSJaegeuk Kim { 174039a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 174139a53e0cSJaegeuk Kim } 174239a53e0cSJaegeuk Kim 174339a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 174439a53e0cSJaegeuk Kim { 174539a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 174639a53e0cSJaegeuk Kim } 174739a53e0cSJaegeuk Kim 174839a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 174939a53e0cSJaegeuk Kim { 175039a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 175139a53e0cSJaegeuk Kim } 175239a53e0cSJaegeuk Kim 175339a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 175439a53e0cSJaegeuk Kim { 175539a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 175639a53e0cSJaegeuk Kim } 175739a53e0cSJaegeuk Kim 17589df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 17599df27d98SGu Zheng { 17609df27d98SGu Zheng return sbi->meta_inode->i_mapping; 17619df27d98SGu Zheng } 17629df27d98SGu Zheng 17634ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 17644ef51a8fSJaegeuk Kim { 17654ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 17664ef51a8fSJaegeuk Kim } 17674ef51a8fSJaegeuk Kim 1768caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 176939a53e0cSJaegeuk Kim { 1770fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 177139a53e0cSJaegeuk Kim } 177239a53e0cSJaegeuk Kim 1773caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 177439a53e0cSJaegeuk Kim { 1775fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1776caf0047eSChao Yu } 1777caf0047eSChao Yu 1778caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1779caf0047eSChao Yu { 1780fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 178139a53e0cSJaegeuk Kim } 178239a53e0cSJaegeuk Kim 1783d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1784d71b5564SJaegeuk Kim { 1785d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1786d71b5564SJaegeuk Kim } 1787d71b5564SJaegeuk Kim 1788ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) 1789ea676733SJaegeuk Kim { 1790ea676733SJaegeuk Kim if (type < F2FS_MAX_QUOTAS) 1791ea676733SJaegeuk Kim return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); 1792ea676733SJaegeuk Kim return 0; 1793ea676733SJaegeuk Kim } 1794ea676733SJaegeuk Kim 1795ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1796ced2c7eaSKinglong Mee { 1797ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1798ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1799ced2c7eaSKinglong Mee } 1800ced2c7eaSKinglong Mee 1801aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 180225ca923bSJaegeuk Kim { 180325ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1804aaec2b1dSChao Yu 180525ca923bSJaegeuk Kim return ckpt_flags & f; 180625ca923bSJaegeuk Kim } 180725ca923bSJaegeuk Kim 1808aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 180925ca923bSJaegeuk Kim { 1810aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1811aaec2b1dSChao Yu } 1812aaec2b1dSChao Yu 1813aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1814aaec2b1dSChao Yu { 1815aaec2b1dSChao Yu unsigned int ckpt_flags; 1816aaec2b1dSChao Yu 1817aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 181825ca923bSJaegeuk Kim ckpt_flags |= f; 181925ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 182025ca923bSJaegeuk Kim } 182125ca923bSJaegeuk Kim 1822aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 182325ca923bSJaegeuk Kim { 1824d1aa2453SChao Yu unsigned long flags; 1825d1aa2453SChao Yu 1826d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1827aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1828d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1829aaec2b1dSChao Yu } 1830aaec2b1dSChao Yu 1831aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1832aaec2b1dSChao Yu { 1833aaec2b1dSChao Yu unsigned int ckpt_flags; 1834aaec2b1dSChao Yu 1835aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 183625ca923bSJaegeuk Kim ckpt_flags &= (~f); 183725ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 183825ca923bSJaegeuk Kim } 183925ca923bSJaegeuk Kim 1840aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1841aaec2b1dSChao Yu { 1842d1aa2453SChao Yu unsigned long flags; 1843d1aa2453SChao Yu 1844d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1845aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1846d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1847aaec2b1dSChao Yu } 1848aaec2b1dSChao Yu 184922ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 185022ad0b6aSJaegeuk Kim { 1851d1aa2453SChao Yu unsigned long flags; 18520921835cSChao Yu unsigned char *nat_bits; 1853d1aa2453SChao Yu 1854a742fd41SJaegeuk Kim /* 1855a742fd41SJaegeuk Kim * In order to re-enable nat_bits we need to call fsck.f2fs by 1856a742fd41SJaegeuk Kim * set_sbi_flag(sbi, SBI_NEED_FSCK). But it may give huge cost, 1857a742fd41SJaegeuk Kim * so let's rely on regular fsck or unclean shutdown. 1858a742fd41SJaegeuk Kim */ 185922ad0b6aSJaegeuk Kim 186022ad0b6aSJaegeuk Kim if (lock) 1861d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 186222ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 18630921835cSChao Yu nat_bits = NM_I(sbi)->nat_bits; 186422ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 186522ad0b6aSJaegeuk Kim if (lock) 1866d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 18670921835cSChao Yu 18680921835cSChao Yu kvfree(nat_bits); 186922ad0b6aSJaegeuk Kim } 187022ad0b6aSJaegeuk Kim 187122ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 187222ad0b6aSJaegeuk Kim struct cp_control *cpc) 187322ad0b6aSJaegeuk Kim { 187422ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 187522ad0b6aSJaegeuk Kim 1876c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 187722ad0b6aSJaegeuk Kim } 187822ad0b6aSJaegeuk Kim 1879e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 188039a53e0cSJaegeuk Kim { 1881b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 188239a53e0cSJaegeuk Kim } 188339a53e0cSJaegeuk Kim 1884cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1885cc15620bSJaegeuk Kim { 1886cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1887cc15620bSJaegeuk Kim } 1888cc15620bSJaegeuk Kim 1889e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 189039a53e0cSJaegeuk Kim { 1891b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 189239936837SJaegeuk Kim } 189339936837SJaegeuk Kim 1894e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 189539936837SJaegeuk Kim { 1896b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 189739936837SJaegeuk Kim } 189839936837SJaegeuk Kim 1899e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 190039936837SJaegeuk Kim { 1901b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 190239a53e0cSJaegeuk Kim } 190339a53e0cSJaegeuk Kim 1904119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1905119ee914SJaegeuk Kim { 1906119ee914SJaegeuk Kim int reason = CP_SYNC; 1907119ee914SJaegeuk Kim 1908119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1909119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1910119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1911119ee914SJaegeuk Kim reason = CP_UMOUNT; 1912119ee914SJaegeuk Kim return reason; 1913119ee914SJaegeuk Kim } 1914119ee914SJaegeuk Kim 1915119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1916119ee914SJaegeuk Kim { 1917c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1918119ee914SJaegeuk Kim } 1919119ee914SJaegeuk Kim 1920119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1921119ee914SJaegeuk Kim { 1922aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1923aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1924119ee914SJaegeuk Kim } 1925119ee914SJaegeuk Kim 192639a53e0cSJaegeuk Kim /* 192739a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 192839a53e0cSJaegeuk Kim */ 192939a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 193039a53e0cSJaegeuk Kim { 19310eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 19320eb0adadSChao Yu 1933000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 193439a53e0cSJaegeuk Kim } 193539a53e0cSJaegeuk Kim 19364bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 19374bc8e9bcSChao Yu { 19384bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 19394bc8e9bcSChao Yu } 19404bc8e9bcSChao Yu 1941d8a9a229SJaegeuk Kim static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, 1942a90a0884SJaegeuk Kim struct inode *inode, bool cap) 19437c2e5963SJaegeuk Kim { 1944d8a9a229SJaegeuk Kim if (!inode) 1945d8a9a229SJaegeuk Kim return true; 19467c2e5963SJaegeuk Kim if (!test_opt(sbi, RESERVE_ROOT)) 19477c2e5963SJaegeuk Kim return false; 1948d8a9a229SJaegeuk Kim if (IS_NOQUOTA(inode)) 1949d8a9a229SJaegeuk Kim return true; 195063189b78SChao Yu if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid())) 19517c2e5963SJaegeuk Kim return true; 195263189b78SChao Yu if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) && 195363189b78SChao Yu in_group_p(F2FS_OPTION(sbi).s_resgid)) 19547c2e5963SJaegeuk Kim return true; 1955a90a0884SJaegeuk Kim if (cap && capable(CAP_SYS_RESOURCE)) 1956162b27aeSJaegeuk Kim return true; 19577c2e5963SJaegeuk Kim return false; 19587c2e5963SJaegeuk Kim } 19597c2e5963SJaegeuk Kim 19600abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 19610abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 196246008c6dSChao Yu struct inode *inode, blkcnt_t *count) 196339a53e0cSJaegeuk Kim { 19640abd675eSChao Yu blkcnt_t diff = 0, release = 0; 1965daeb433eSChao Yu block_t avail_user_block_count; 19660abd675eSChao Yu int ret; 19670abd675eSChao Yu 19680abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 19690abd675eSChao Yu if (ret) 19700abd675eSChao Yu return ret; 1971dd11a5dfSJaegeuk Kim 197255523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 1973c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_BLOCK); 19740abd675eSChao Yu release = *count; 19759ea2f0beSChao Yu goto release_quota; 197655523519SChao Yu } 19777fa750a1SArnd Bergmann 1978dd11a5dfSJaegeuk Kim /* 1979dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1980dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1981dd11a5dfSJaegeuk Kim */ 1982dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 198339a53e0cSJaegeuk Kim 198439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 19852555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 198680d42145SYunlong Song avail_user_block_count = sbi->user_block_count - 198780d42145SYunlong Song sbi->current_reserved_blocks; 19887e65be49SJaegeuk Kim 1989a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, true)) 199063189b78SChao Yu avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; 1991a4c3ecaaSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { 1992a4c3ecaaSDaniel Rosenberg if (avail_user_block_count > sbi->unusable_block_count) 19934354994fSDaniel Rosenberg avail_user_block_count -= sbi->unusable_block_count; 1994a4c3ecaaSDaniel Rosenberg else 1995a4c3ecaaSDaniel Rosenberg avail_user_block_count = 0; 1996a4c3ecaaSDaniel Rosenberg } 1997daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1998daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 19997e65be49SJaegeuk Kim if (diff > *count) 20007e65be49SJaegeuk Kim diff = *count; 2001dd11a5dfSJaegeuk Kim *count -= diff; 20020abd675eSChao Yu release = diff; 20037e65be49SJaegeuk Kim sbi->total_valid_block_count -= diff; 200446008c6dSChao Yu if (!*count) { 200539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 20060abd675eSChao Yu goto enospc; 200739a53e0cSJaegeuk Kim } 200846008c6dSChao Yu } 200939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 201041382ec4SJaegeuk Kim 201136b877afSDaniel Rosenberg if (unlikely(release)) { 201236b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 20130abd675eSChao Yu dquot_release_reservation_block(inode, release); 201436b877afSDaniel Rosenberg } 20150abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 20160abd675eSChao Yu return 0; 20170abd675eSChao Yu 20180abd675eSChao Yu enospc: 201936b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 20209ea2f0beSChao Yu release_quota: 20210abd675eSChao Yu dquot_release_reservation_block(inode, release); 20220abd675eSChao Yu return -ENOSPC; 202339a53e0cSJaegeuk Kim } 202439a53e0cSJaegeuk Kim 2025dcbb4c10SJoe Perches __printf(2, 3) 2026dcbb4c10SJoe Perches void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...); 2027dcbb4c10SJoe Perches 2028dcbb4c10SJoe Perches #define f2fs_err(sbi, fmt, ...) \ 2029dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_ERR fmt, ##__VA_ARGS__) 2030dcbb4c10SJoe Perches #define f2fs_warn(sbi, fmt, ...) \ 2031dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_WARNING fmt, ##__VA_ARGS__) 2032dcbb4c10SJoe Perches #define f2fs_notice(sbi, fmt, ...) \ 2033dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_NOTICE fmt, ##__VA_ARGS__) 2034dcbb4c10SJoe Perches #define f2fs_info(sbi, fmt, ...) \ 2035dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_INFO fmt, ##__VA_ARGS__) 2036dcbb4c10SJoe Perches #define f2fs_debug(sbi, fmt, ...) \ 2037dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_DEBUG fmt, ##__VA_ARGS__) 2038dcbb4c10SJoe Perches 2039da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 204039a53e0cSJaegeuk Kim struct inode *inode, 20410eb0adadSChao Yu block_t count) 204239a53e0cSJaegeuk Kim { 20430eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 20440eb0adadSChao Yu 204539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 20469850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 204739a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 204880d42145SYunlong Song if (sbi->reserved_blocks && 204980d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 205080d42145SYunlong Song sbi->current_reserved_blocks = min(sbi->reserved_blocks, 205180d42145SYunlong Song sbi->current_reserved_blocks + count); 205239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 20535e159cd3SChao Yu if (unlikely(inode->i_blocks < sectors)) { 2054dcbb4c10SJoe Perches f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu", 20555e159cd3SChao Yu inode->i_ino, 20565e159cd3SChao Yu (unsigned long long)inode->i_blocks, 20575e159cd3SChao Yu (unsigned long long)sectors); 20585e159cd3SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 20595e159cd3SChao Yu return; 20605e159cd3SChao Yu } 20610abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 206239a53e0cSJaegeuk Kim } 206339a53e0cSJaegeuk Kim 206439a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 206539a53e0cSJaegeuk Kim { 206635782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 20677c4abcbeSChao Yu 206820109873SChao Yu if (count_type == F2FS_DIRTY_DENTS || 206920109873SChao Yu count_type == F2FS_DIRTY_NODES || 207020109873SChao Yu count_type == F2FS_DIRTY_META || 207120109873SChao Yu count_type == F2FS_DIRTY_QDATA || 207220109873SChao Yu count_type == F2FS_DIRTY_IMETA) 2073caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 207439a53e0cSJaegeuk Kim } 207539a53e0cSJaegeuk Kim 2076a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 207739a53e0cSJaegeuk Kim { 2078204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 2079c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 2080c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 20812c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 20822c8a4a28SJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 208339a53e0cSJaegeuk Kim } 208439a53e0cSJaegeuk Kim 208539a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 208639a53e0cSJaegeuk Kim { 208735782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 208839a53e0cSJaegeuk Kim } 208939a53e0cSJaegeuk Kim 2090a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 209139a53e0cSJaegeuk Kim { 20925ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 20935ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 20941fe54f9dSJaegeuk Kim return; 20951fe54f9dSJaegeuk Kim 2096204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 2097c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 2098c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 20992c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 21002c8a4a28SJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 210139a53e0cSJaegeuk Kim } 210239a53e0cSJaegeuk Kim 2103523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 210439a53e0cSJaegeuk Kim { 210535782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 210639a53e0cSJaegeuk Kim } 210739a53e0cSJaegeuk Kim 2108204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 2109f8b2c1f9SJaegeuk Kim { 2110204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 2111f8b2c1f9SJaegeuk Kim } 2112f8b2c1f9SJaegeuk Kim 21135ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 21145ac206cfSNamjae Jeon { 21153519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 2116523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 2117523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 2118523be8a6SJaegeuk Kim 2119523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 21205ac206cfSNamjae Jeon } 21215ac206cfSNamjae Jeon 212239a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 212339a53e0cSJaegeuk Kim { 21248b8343faSJaegeuk Kim return sbi->total_valid_block_count; 212539a53e0cSJaegeuk Kim } 212639a53e0cSJaegeuk Kim 2127f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 2128f83a2584SYunlei He { 2129f83a2584SYunlei He return sbi->discard_blks; 2130f83a2584SYunlei He } 2131f83a2584SYunlei He 213239a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 213339a53e0cSJaegeuk Kim { 213439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 213539a53e0cSJaegeuk Kim 213639a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 213739a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 213839a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 213939a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 214039a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 214139a53e0cSJaegeuk Kim 214239a53e0cSJaegeuk Kim return 0; 214339a53e0cSJaegeuk Kim } 214439a53e0cSJaegeuk Kim 214555141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 214655141486SWanpeng Li { 214755141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 214855141486SWanpeng Li } 214955141486SWanpeng Li 215039a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 215139a53e0cSJaegeuk Kim { 215239a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 21531dbe4152SChangman Lee int offset; 21541dbe4152SChangman Lee 2155199bc3feSChao Yu if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { 2156199bc3feSChao Yu offset = (flag == SIT_BITMAP) ? 2157199bc3feSChao Yu le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; 2158b471eb99SChao Yu /* 2159b471eb99SChao Yu * if large_nat_bitmap feature is enabled, leave checksum 2160b471eb99SChao Yu * protection for all nat/sit bitmaps. 2161b471eb99SChao Yu */ 2162b471eb99SChao Yu return &ckpt->sit_nat_version_bitmap + offset + sizeof(__le32); 2163199bc3feSChao Yu } 2164199bc3feSChao Yu 216555141486SWanpeng Li if (__cp_payload(sbi) > 0) { 21661dbe4152SChangman Lee if (flag == NAT_BITMAP) 21671dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 21681dbe4152SChangman Lee else 216965b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 21701dbe4152SChangman Lee } else { 21711dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 217225ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 217339a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 217439a53e0cSJaegeuk Kim } 21751dbe4152SChangman Lee } 217639a53e0cSJaegeuk Kim 217739a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 217839a53e0cSJaegeuk Kim { 21798508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 218039a53e0cSJaegeuk Kim 21818508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 218239a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 218339a53e0cSJaegeuk Kim return start_addr; 218439a53e0cSJaegeuk Kim } 218539a53e0cSJaegeuk Kim 21868508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 21878508e44aSJaegeuk Kim { 21888508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 21898508e44aSJaegeuk Kim 21908508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 21918508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 21928508e44aSJaegeuk Kim return start_addr; 21938508e44aSJaegeuk Kim } 21948508e44aSJaegeuk Kim 21958508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 21968508e44aSJaegeuk Kim { 21978508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 21988508e44aSJaegeuk Kim } 21998508e44aSJaegeuk Kim 220039a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 220139a53e0cSJaegeuk Kim { 220239a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 220339a53e0cSJaegeuk Kim } 220439a53e0cSJaegeuk Kim 22050abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 2206000519f2SChao Yu struct inode *inode, bool is_inode) 220739a53e0cSJaegeuk Kim { 220839a53e0cSJaegeuk Kim block_t valid_block_count; 2209a4c3ecaaSDaniel Rosenberg unsigned int valid_node_count, user_block_count; 2210af033b2aSChao Yu int err; 22110abd675eSChao Yu 2212af033b2aSChao Yu if (is_inode) { 2213af033b2aSChao Yu if (inode) { 2214af033b2aSChao Yu err = dquot_alloc_inode(inode); 2215af033b2aSChao Yu if (err) 2216af033b2aSChao Yu return err; 2217af033b2aSChao Yu } 2218af033b2aSChao Yu } else { 2219af033b2aSChao Yu err = dquot_reserve_block(inode, 1); 2220af033b2aSChao Yu if (err) 2221af033b2aSChao Yu return err; 22220abd675eSChao Yu } 222339a53e0cSJaegeuk Kim 2224812c6056SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 2225c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_BLOCK); 2226812c6056SChao Yu goto enospc; 2227812c6056SChao Yu } 2228812c6056SChao Yu 222939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 223039a53e0cSJaegeuk Kim 22317e65be49SJaegeuk Kim valid_block_count = sbi->total_valid_block_count + 22327e65be49SJaegeuk Kim sbi->current_reserved_blocks + 1; 22337e65be49SJaegeuk Kim 2234a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, false)) 223563189b78SChao Yu valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; 2236a4c3ecaaSDaniel Rosenberg user_block_count = sbi->user_block_count; 22374354994fSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) 2238a4c3ecaaSDaniel Rosenberg user_block_count -= sbi->unusable_block_count; 22397e65be49SJaegeuk Kim 2240a4c3ecaaSDaniel Rosenberg if (unlikely(valid_block_count > user_block_count)) { 224139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 22420abd675eSChao Yu goto enospc; 224339a53e0cSJaegeuk Kim } 224439a53e0cSJaegeuk Kim 2245ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 2246cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 224739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 22480abd675eSChao Yu goto enospc; 224939a53e0cSJaegeuk Kim } 225039a53e0cSJaegeuk Kim 2251ef86d709SGu Zheng sbi->total_valid_node_count++; 2252ef86d709SGu Zheng sbi->total_valid_block_count++; 225339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 225439a53e0cSJaegeuk Kim 22550abd675eSChao Yu if (inode) { 22560abd675eSChao Yu if (is_inode) 22570abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 22580abd675eSChao Yu else 22590abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 22600abd675eSChao Yu } 22610abd675eSChao Yu 226241382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 22630abd675eSChao Yu return 0; 22640abd675eSChao Yu 22650abd675eSChao Yu enospc: 2266af033b2aSChao Yu if (is_inode) { 2267af033b2aSChao Yu if (inode) 2268af033b2aSChao Yu dquot_free_inode(inode); 2269af033b2aSChao Yu } else { 22700abd675eSChao Yu dquot_release_reservation_block(inode, 1); 2271af033b2aSChao Yu } 22720abd675eSChao Yu return -ENOSPC; 227339a53e0cSJaegeuk Kim } 227439a53e0cSJaegeuk Kim 227539a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 2276000519f2SChao Yu struct inode *inode, bool is_inode) 227739a53e0cSJaegeuk Kim { 227839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 227939a53e0cSJaegeuk Kim 22809850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 22819850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 228239a53e0cSJaegeuk Kim 2283ef86d709SGu Zheng sbi->total_valid_node_count--; 2284ef86d709SGu Zheng sbi->total_valid_block_count--; 228580d42145SYunlong Song if (sbi->reserved_blocks && 228680d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 228780d42145SYunlong Song sbi->current_reserved_blocks++; 228839a53e0cSJaegeuk Kim 228939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 22900abd675eSChao Yu 2291ea6d7e72SChao Yu if (is_inode) { 2292af033b2aSChao Yu dquot_free_inode(inode); 2293ea6d7e72SChao Yu } else { 2294ea6d7e72SChao Yu if (unlikely(inode->i_blocks == 0)) { 2295097a7686SChao Yu f2fs_warn(sbi, "dec_valid_node_count: inconsistent i_blocks, ino:%lu, iblocks:%llu", 2296ea6d7e72SChao Yu inode->i_ino, 2297ea6d7e72SChao Yu (unsigned long long)inode->i_blocks); 2298ea6d7e72SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 2299ea6d7e72SChao Yu return; 2300ea6d7e72SChao Yu } 23010abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 230239a53e0cSJaegeuk Kim } 2303ea6d7e72SChao Yu } 230439a53e0cSJaegeuk Kim 230539a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 230639a53e0cSJaegeuk Kim { 23078b8343faSJaegeuk Kim return sbi->total_valid_node_count; 230839a53e0cSJaegeuk Kim } 230939a53e0cSJaegeuk Kim 231039a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 231139a53e0cSJaegeuk Kim { 2312513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 231339a53e0cSJaegeuk Kim } 231439a53e0cSJaegeuk Kim 23150e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 231639a53e0cSJaegeuk Kim { 2317513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 231839a53e0cSJaegeuk Kim } 231939a53e0cSJaegeuk Kim 2320513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 232139a53e0cSJaegeuk Kim { 2322513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 232339a53e0cSJaegeuk Kim } 232439a53e0cSJaegeuk Kim 2325a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 2326a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 2327a56c7c6fSJaegeuk Kim { 232882cf4f13SChao Yu struct page *page; 2329cac5a3d8SDongOh Shin 23307fa750a1SArnd Bergmann if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) { 233182cf4f13SChao Yu if (!for_write) 233282cf4f13SChao Yu page = find_get_page_flags(mapping, index, 233382cf4f13SChao Yu FGP_LOCK | FGP_ACCESSED); 233482cf4f13SChao Yu else 233582cf4f13SChao Yu page = find_lock_page(mapping, index); 2336c41f3cc3SJaegeuk Kim if (page) 2337c41f3cc3SJaegeuk Kim return page; 2338c41f3cc3SJaegeuk Kim 233955523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 2340c45d6002SChao Yu f2fs_show_injection_info(F2FS_M_SB(mapping), 2341c45d6002SChao Yu FAULT_PAGE_ALLOC); 2342c41f3cc3SJaegeuk Kim return NULL; 234355523519SChao Yu } 23447fa750a1SArnd Bergmann } 23457fa750a1SArnd Bergmann 2346a56c7c6fSJaegeuk Kim if (!for_write) 2347a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 2348a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 2349a56c7c6fSJaegeuk Kim } 2350a56c7c6fSJaegeuk Kim 235101eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page( 235201eccef7SChao Yu struct address_space *mapping, pgoff_t index, 235301eccef7SChao Yu int fgp_flags, gfp_t gfp_mask) 235401eccef7SChao Yu { 235501eccef7SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { 2356c45d6002SChao Yu f2fs_show_injection_info(F2FS_M_SB(mapping), FAULT_PAGE_GET); 235701eccef7SChao Yu return NULL; 235801eccef7SChao Yu } 23597fa750a1SArnd Bergmann 236001eccef7SChao Yu return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); 236101eccef7SChao Yu } 236201eccef7SChao Yu 23636e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 23646e2c64adSJaegeuk Kim { 23656e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 23666e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 23676e2c64adSJaegeuk Kim 23686e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 23696e2c64adSJaegeuk Kim kunmap(dst); 23706e2c64adSJaegeuk Kim kunmap(src); 23716e2c64adSJaegeuk Kim } 23726e2c64adSJaegeuk Kim 237339a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 237439a53e0cSJaegeuk Kim { 2375031fa8ccSJaegeuk Kim if (!page) 237639a53e0cSJaegeuk Kim return; 237739a53e0cSJaegeuk Kim 237839a53e0cSJaegeuk Kim if (unlock) { 23799850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 238039a53e0cSJaegeuk Kim unlock_page(page); 238139a53e0cSJaegeuk Kim } 238209cbfeafSKirill A. Shutemov put_page(page); 238339a53e0cSJaegeuk Kim } 238439a53e0cSJaegeuk Kim 238539a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 238639a53e0cSJaegeuk Kim { 238739a53e0cSJaegeuk Kim if (dn->node_page) 238839a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 238939a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 239039a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 239139a53e0cSJaegeuk Kim dn->node_page = NULL; 239239a53e0cSJaegeuk Kim dn->inode_page = NULL; 239339a53e0cSJaegeuk Kim } 239439a53e0cSJaegeuk Kim 239539a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 2396e8512d2eSGu Zheng size_t size) 239739a53e0cSJaegeuk Kim { 2398e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 239939a53e0cSJaegeuk Kim } 240039a53e0cSJaegeuk Kim 24017bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 24027bd59381SGu Zheng gfp_t flags) 24037bd59381SGu Zheng { 24047bd59381SGu Zheng void *entry; 24057bd59381SGu Zheng 240680c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 240780c54505SJaegeuk Kim if (!entry) 240880c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 24097bd59381SGu Zheng return entry; 24107bd59381SGu Zheng } 24117bd59381SGu Zheng 2412493720a4SChao Yu static inline bool is_inflight_io(struct f2fs_sb_info *sbi, int type) 24135f9abab4SJaegeuk Kim { 24145f9abab4SJaegeuk Kim if (get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_RD_NODE) || 24155f9abab4SJaegeuk Kim get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) || 2416fef4129eSChao Yu get_pages(sbi, F2FS_WB_CP_DATA) || 2417fef4129eSChao Yu get_pages(sbi, F2FS_DIO_READ) || 241811ac8ef8SJaegeuk Kim get_pages(sbi, F2FS_DIO_WRITE)) 2419493720a4SChao Yu return true; 242011ac8ef8SJaegeuk Kim 242156659ce8SSahitya Tummala if (type != DISCARD_TIME && SM_I(sbi) && SM_I(sbi)->dcc_info && 242211ac8ef8SJaegeuk Kim atomic_read(&SM_I(sbi)->dcc_info->queued_discard)) 2423493720a4SChao Yu return true; 242411ac8ef8SJaegeuk Kim 242511ac8ef8SJaegeuk Kim if (SM_I(sbi) && SM_I(sbi)->fcc_info && 242672691af6SJaegeuk Kim atomic_read(&SM_I(sbi)->fcc_info->queued_flush)) 2427493720a4SChao Yu return true; 2428493720a4SChao Yu return false; 2429493720a4SChao Yu } 2430493720a4SChao Yu 2431493720a4SChao Yu static inline bool is_idle(struct f2fs_sb_info *sbi, int type) 2432493720a4SChao Yu { 2433493720a4SChao Yu if (sbi->gc_mode == GC_URGENT_HIGH) 2434493720a4SChao Yu return true; 2435493720a4SChao Yu 2436493720a4SChao Yu if (is_inflight_io(sbi, type)) 24375f9abab4SJaegeuk Kim return false; 243811ac8ef8SJaegeuk Kim 24390e5e8111SDaeho Jeong if (sbi->gc_mode == GC_URGENT_LOW && 24400e5e8111SDaeho Jeong (type == DISCARD_TIME || type == GC_TIME)) 24410e5e8111SDaeho Jeong return true; 24420e5e8111SDaeho Jeong 24435f9abab4SJaegeuk Kim return f2fs_time_over(sbi, type); 24445f9abab4SJaegeuk Kim } 24455f9abab4SJaegeuk Kim 24469be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 24479be32d72SJaegeuk Kim unsigned long index, void *item) 24489be32d72SJaegeuk Kim { 24499be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 24509be32d72SJaegeuk Kim cond_resched(); 24519be32d72SJaegeuk Kim } 24529be32d72SJaegeuk Kim 245339a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 245439a53e0cSJaegeuk Kim 245539a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 245639a53e0cSJaegeuk Kim { 245745590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 2458cac5a3d8SDongOh Shin 245939a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 246039a53e0cSJaegeuk Kim } 246139a53e0cSJaegeuk Kim 24627a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 24637a2af766SChao Yu { 24647a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 24657a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 24667a2af766SChao Yu } 24677a2af766SChao Yu 246839a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 246939a53e0cSJaegeuk Kim { 247039a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 247139a53e0cSJaegeuk Kim } 247239a53e0cSJaegeuk Kim 24737a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 2474a2ced1ceSChao Yu static inline block_t data_blkaddr(struct inode *inode, 24757a2af766SChao Yu struct page *node_page, unsigned int offset) 247639a53e0cSJaegeuk Kim { 247739a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 247839a53e0cSJaegeuk Kim __le32 *addr_array; 24797a2af766SChao Yu int base = 0; 24807a2af766SChao Yu bool is_inode = IS_INODE(node_page); 2481cac5a3d8SDongOh Shin 248245590710SGu Zheng raw_node = F2FS_NODE(node_page); 24837a2af766SChao Yu 2484979f492fSLiFan if (is_inode) { 2485979f492fSLiFan if (!inode) 24867a88ddb5SChao Yu /* from GC path only */ 24877a2af766SChao Yu base = offset_in_addr(&raw_node->i); 2488979f492fSLiFan else if (f2fs_has_extra_attr(inode)) 24897a2af766SChao Yu base = get_extra_isize(inode); 24907a2af766SChao Yu } 24917a2af766SChao Yu 249239a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 24937a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 249439a53e0cSJaegeuk Kim } 249539a53e0cSJaegeuk Kim 2496a2ced1ceSChao Yu static inline block_t f2fs_data_blkaddr(struct dnode_of_data *dn) 2497a2ced1ceSChao Yu { 2498a2ced1ceSChao Yu return data_blkaddr(dn->inode, dn->node_page, dn->ofs_in_node); 2499a2ced1ceSChao Yu } 2500a2ced1ceSChao Yu 250139a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 250239a53e0cSJaegeuk Kim { 250339a53e0cSJaegeuk Kim int mask; 250439a53e0cSJaegeuk Kim 250539a53e0cSJaegeuk Kim addr += (nr >> 3); 250639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 250739a53e0cSJaegeuk Kim return mask & *addr; 250839a53e0cSJaegeuk Kim } 250939a53e0cSJaegeuk Kim 2510a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 2511a66cdd98SJaegeuk Kim { 2512a66cdd98SJaegeuk Kim int mask; 2513a66cdd98SJaegeuk Kim 2514a66cdd98SJaegeuk Kim addr += (nr >> 3); 2515a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2516a66cdd98SJaegeuk Kim *addr |= mask; 2517a66cdd98SJaegeuk Kim } 2518a66cdd98SJaegeuk Kim 2519a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 2520a66cdd98SJaegeuk Kim { 2521a66cdd98SJaegeuk Kim int mask; 2522a66cdd98SJaegeuk Kim 2523a66cdd98SJaegeuk Kim addr += (nr >> 3); 2524a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2525a66cdd98SJaegeuk Kim *addr &= ~mask; 2526a66cdd98SJaegeuk Kim } 2527a66cdd98SJaegeuk Kim 252852aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 252939a53e0cSJaegeuk Kim { 253039a53e0cSJaegeuk Kim int mask; 253139a53e0cSJaegeuk Kim int ret; 253239a53e0cSJaegeuk Kim 253339a53e0cSJaegeuk Kim addr += (nr >> 3); 253439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 253539a53e0cSJaegeuk Kim ret = mask & *addr; 253639a53e0cSJaegeuk Kim *addr |= mask; 253739a53e0cSJaegeuk Kim return ret; 253839a53e0cSJaegeuk Kim } 253939a53e0cSJaegeuk Kim 254052aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 254139a53e0cSJaegeuk Kim { 254239a53e0cSJaegeuk Kim int mask; 254339a53e0cSJaegeuk Kim int ret; 254439a53e0cSJaegeuk Kim 254539a53e0cSJaegeuk Kim addr += (nr >> 3); 254639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 254739a53e0cSJaegeuk Kim ret = mask & *addr; 254839a53e0cSJaegeuk Kim *addr &= ~mask; 254939a53e0cSJaegeuk Kim return ret; 255039a53e0cSJaegeuk Kim } 255139a53e0cSJaegeuk Kim 2552c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 2553c6ac4c0eSGu Zheng { 2554c6ac4c0eSGu Zheng int mask; 2555c6ac4c0eSGu Zheng 2556c6ac4c0eSGu Zheng addr += (nr >> 3); 2557c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 2558c6ac4c0eSGu Zheng *addr ^= mask; 2559c6ac4c0eSGu Zheng } 2560c6ac4c0eSGu Zheng 256159c84408SChao Yu /* 256236098557SEric Biggers * On-disk inode flags (f2fs_inode::i_flags) 256359c84408SChao Yu */ 25644c8ff709SChao Yu #define F2FS_COMPR_FL 0x00000004 /* Compress file */ 256559c84408SChao Yu #define F2FS_SYNC_FL 0x00000008 /* Synchronous updates */ 256659c84408SChao Yu #define F2FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ 256759c84408SChao Yu #define F2FS_APPEND_FL 0x00000020 /* writes to file may only append */ 256859c84408SChao Yu #define F2FS_NODUMP_FL 0x00000040 /* do not dump file */ 256959c84408SChao Yu #define F2FS_NOATIME_FL 0x00000080 /* do not update atime */ 25704c8ff709SChao Yu #define F2FS_NOCOMP_FL 0x00000400 /* Don't compress */ 257159c84408SChao Yu #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ 257259c84408SChao Yu #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 257359c84408SChao Yu #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 25742c2eb7a3SDaniel Rosenberg #define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */ 257559c84408SChao Yu 257659c84408SChao Yu /* Flags that should be inherited by new inodes from their parent. */ 257736098557SEric Biggers #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \ 25782c2eb7a3SDaniel Rosenberg F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 25794c8ff709SChao Yu F2FS_CASEFOLD_FL | F2FS_COMPR_FL | F2FS_NOCOMP_FL) 258059c84408SChao Yu 258159c84408SChao Yu /* Flags that are appropriate for regular files (all but dir-specific ones). */ 25822c2eb7a3SDaniel Rosenberg #define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 25832c2eb7a3SDaniel Rosenberg F2FS_CASEFOLD_FL)) 258459c84408SChao Yu 258559c84408SChao Yu /* Flags that are appropriate for non-directories/regular files. */ 258659c84408SChao Yu #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL) 25875c57132eSChao Yu 25885c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 25895c57132eSChao Yu { 25905c57132eSChao Yu if (S_ISDIR(mode)) 25915c57132eSChao Yu return flags; 25925c57132eSChao Yu else if (S_ISREG(mode)) 25935c57132eSChao Yu return flags & F2FS_REG_FLMASK; 25945c57132eSChao Yu else 25955c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 25965c57132eSChao Yu } 25975c57132eSChao Yu 2598205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2599205b9822SJaegeuk Kim int flag, bool set) 260039a53e0cSJaegeuk Kim { 2601205b9822SJaegeuk Kim switch (flag) { 2602205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2603205b9822SJaegeuk Kim case FI_INLINE_DATA: 2604205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 26059ac1e2d8SDaeho Jeong case FI_NEW_INODE: 2606205b9822SJaegeuk Kim if (set) 2607205b9822SJaegeuk Kim return; 2608df561f66SGustavo A. R. Silva fallthrough; 2609205b9822SJaegeuk Kim case FI_DATA_EXIST: 2610205b9822SJaegeuk Kim case FI_INLINE_DOTS: 26111ad71a27SJaegeuk Kim case FI_PIN_FILE: 26127c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2613205b9822SJaegeuk Kim } 261439a53e0cSJaegeuk Kim } 261539a53e0cSJaegeuk Kim 261691942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 261739a53e0cSJaegeuk Kim { 261858f7e00fSYufen Yu set_bit(flag, F2FS_I(inode)->flags); 2619205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 262039a53e0cSJaegeuk Kim } 262139a53e0cSJaegeuk Kim 262291942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 262339a53e0cSJaegeuk Kim { 26247653b9d8SChao Yu return test_bit(flag, F2FS_I(inode)->flags); 262539a53e0cSJaegeuk Kim } 262639a53e0cSJaegeuk Kim 262791942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 262839a53e0cSJaegeuk Kim { 262958f7e00fSYufen Yu clear_bit(flag, F2FS_I(inode)->flags); 2630205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 263139a53e0cSJaegeuk Kim } 263239a53e0cSJaegeuk Kim 263395ae251fSEric Biggers static inline bool f2fs_verity_in_progress(struct inode *inode) 263495ae251fSEric Biggers { 263595ae251fSEric Biggers return IS_ENABLED(CONFIG_FS_VERITY) && 263695ae251fSEric Biggers is_inode_flag_set(inode, FI_VERITY_IN_PROGRESS); 263795ae251fSEric Biggers } 263895ae251fSEric Biggers 263991942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2640444c580fSJaegeuk Kim { 264191942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 264291942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 26437c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 264439a53e0cSJaegeuk Kim } 264539a53e0cSJaegeuk Kim 2646a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2647a1961246SJaegeuk Kim { 2648a1961246SJaegeuk Kim if (inc) 2649a1961246SJaegeuk Kim inc_nlink(inode); 2650a1961246SJaegeuk Kim else 2651a1961246SJaegeuk Kim drop_nlink(inode); 26527c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2653a1961246SJaegeuk Kim } 2654a1961246SJaegeuk Kim 26558edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 26560abd675eSChao Yu block_t diff, bool add, bool claim) 26578edd03c8SJaegeuk Kim { 265826de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 265926de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 266026de9b11SJaegeuk Kim 26610abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 26620abd675eSChao Yu if (add) { 26630abd675eSChao Yu if (claim) 26640abd675eSChao Yu dquot_claim_block(inode, diff); 26650abd675eSChao Yu else 26660abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 26670abd675eSChao Yu } else { 26680abd675eSChao Yu dquot_free_block(inode, diff); 26690abd675eSChao Yu } 26700abd675eSChao Yu 26717c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 267226de9b11SJaegeuk Kim if (clean || recover) 267326de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 26748edd03c8SJaegeuk Kim } 26758edd03c8SJaegeuk Kim 2676fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2677fc9581c8SJaegeuk Kim { 267826de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 267926de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 268026de9b11SJaegeuk Kim 2681fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2682fc9581c8SJaegeuk Kim return; 2683fc9581c8SJaegeuk Kim 2684fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 26857c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 268626de9b11SJaegeuk Kim if (clean || recover) 268726de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 268826de9b11SJaegeuk Kim } 268926de9b11SJaegeuk Kim 2690205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2691205b9822SJaegeuk Kim { 2692205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 26937c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2694205b9822SJaegeuk Kim } 2695205b9822SJaegeuk Kim 26961ad71a27SJaegeuk Kim static inline void f2fs_i_gc_failures_write(struct inode *inode, 26971ad71a27SJaegeuk Kim unsigned int count) 26981ad71a27SJaegeuk Kim { 26992ef79ecbSChao Yu F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count; 27001ad71a27SJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 27011ad71a27SJaegeuk Kim } 27021ad71a27SJaegeuk Kim 2703205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2704205b9822SJaegeuk Kim { 2705205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 27067c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2707205b9822SJaegeuk Kim } 2708205b9822SJaegeuk Kim 2709205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2710205b9822SJaegeuk Kim { 2711205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 27127c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2713205b9822SJaegeuk Kim } 2714205b9822SJaegeuk Kim 271591942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2716444c580fSJaegeuk Kim { 2717205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2718205b9822SJaegeuk Kim 2719444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 27207653b9d8SChao Yu set_bit(FI_INLINE_XATTR, fi->flags); 27211001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 27227653b9d8SChao Yu set_bit(FI_INLINE_DATA, fi->flags); 272334d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 27247653b9d8SChao Yu set_bit(FI_INLINE_DENTRY, fi->flags); 2725b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 27267653b9d8SChao Yu set_bit(FI_DATA_EXIST, fi->flags); 2727510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 27287653b9d8SChao Yu set_bit(FI_INLINE_DOTS, fi->flags); 27297a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 27307653b9d8SChao Yu set_bit(FI_EXTRA_ATTR, fi->flags); 27311ad71a27SJaegeuk Kim if (ri->i_inline & F2FS_PIN_FILE) 27327653b9d8SChao Yu set_bit(FI_PIN_FILE, fi->flags); 2733444c580fSJaegeuk Kim } 2734444c580fSJaegeuk Kim 273591942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2736444c580fSJaegeuk Kim { 2737444c580fSJaegeuk Kim ri->i_inline = 0; 2738444c580fSJaegeuk Kim 273991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2740444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 274191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 27421001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 274391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 274434d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 274591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2746b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 274791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2748510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 27497a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 27507a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 27511ad71a27SJaegeuk Kim if (is_inode_flag_set(inode, FI_PIN_FILE)) 27521ad71a27SJaegeuk Kim ri->i_inline |= F2FS_PIN_FILE; 27537a2af766SChao Yu } 27547a2af766SChao Yu 27557a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 27567a2af766SChao Yu { 27577a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2758444c580fSJaegeuk Kim } 2759444c580fSJaegeuk Kim 2760987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2761987c7c31SChao Yu { 276291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2763987c7c31SChao Yu } 2764987c7c31SChao Yu 27654c8ff709SChao Yu static inline int f2fs_compressed_file(struct inode *inode) 27664c8ff709SChao Yu { 27674c8ff709SChao Yu return S_ISREG(inode->i_mode) && 27684c8ff709SChao Yu is_inode_flag_set(inode, FI_COMPRESSED_FILE); 27694c8ff709SChao Yu } 27704c8ff709SChao Yu 277181ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2772de93653fSJaegeuk Kim { 2773d02a6e61SChao Yu unsigned int addrs = CUR_ADDRS_PER_INODE(inode) - 2774d02a6e61SChao Yu get_inline_xattr_addrs(inode); 27754c8ff709SChao Yu 27764c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 27774c8ff709SChao Yu return addrs; 27784c8ff709SChao Yu return ALIGN_DOWN(addrs, F2FS_I(inode)->i_cluster_size); 2779d02a6e61SChao Yu } 2780d02a6e61SChao Yu 2781d02a6e61SChao Yu static inline unsigned int addrs_per_block(struct inode *inode) 2782d02a6e61SChao Yu { 27834c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 27844c8ff709SChao Yu return DEF_ADDRS_PER_BLOCK; 27854c8ff709SChao Yu return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, F2FS_I(inode)->i_cluster_size); 2786de93653fSJaegeuk Kim } 2787de93653fSJaegeuk Kim 27886afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page) 278965985d93SJaegeuk Kim { 2790695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2791cac5a3d8SDongOh Shin 279265985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 2793b323fd28SChao Yu get_inline_xattr_addrs(inode)]); 279465985d93SJaegeuk Kim } 279565985d93SJaegeuk Kim 279665985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 279765985d93SJaegeuk Kim { 2798622927f3SChao Yu if (f2fs_has_inline_xattr(inode)) 27996afc662eSChao Yu return get_inline_xattr_addrs(inode) * sizeof(__le32); 2800622927f3SChao Yu return 0; 280165985d93SJaegeuk Kim } 280265985d93SJaegeuk Kim 28030dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 28040dbdc2aeSJaegeuk Kim { 280591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 28060dbdc2aeSJaegeuk Kim } 28070dbdc2aeSJaegeuk Kim 2808b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2809b3d208f9SJaegeuk Kim { 281091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2811b3d208f9SJaegeuk Kim } 2812b3d208f9SJaegeuk Kim 2813510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2814510022a8SJaegeuk Kim { 281591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2816510022a8SJaegeuk Kim } 2817510022a8SJaegeuk Kim 28184c8ff709SChao Yu static inline int f2fs_is_mmap_file(struct inode *inode) 28194c8ff709SChao Yu { 28204c8ff709SChao Yu return is_inode_flag_set(inode, FI_MMAP_FILE); 28214c8ff709SChao Yu } 28224c8ff709SChao Yu 28231ad71a27SJaegeuk Kim static inline bool f2fs_is_pinned_file(struct inode *inode) 28241ad71a27SJaegeuk Kim { 28251ad71a27SJaegeuk Kim return is_inode_flag_set(inode, FI_PIN_FILE); 28261ad71a27SJaegeuk Kim } 28271ad71a27SJaegeuk Kim 282888b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 282988b88a66SJaegeuk Kim { 283091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 283188b88a66SJaegeuk Kim } 283288b88a66SJaegeuk Kim 28335fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 28345fe45743SChao Yu { 28355fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 28365fe45743SChao Yu } 28375fe45743SChao Yu 283802a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 283902a1335fSJaegeuk Kim { 284091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 284102a1335fSJaegeuk Kim } 284202a1335fSJaegeuk Kim 28433c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 28443c6c2bebSJaegeuk Kim { 284591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 28463c6c2bebSJaegeuk Kim } 28473c6c2bebSJaegeuk Kim 28481e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 28491e84371fSJaegeuk Kim { 285091942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 28511e84371fSJaegeuk Kim } 28521e84371fSJaegeuk Kim 2853f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 28541001b347SHuajun Li { 2855695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 28567a2af766SChao Yu int extra_size = get_extra_isize(inode); 2857cac5a3d8SDongOh Shin 28587a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 28591001b347SHuajun Li } 28601001b347SHuajun Li 286134d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 286234d67debSChao Yu { 286391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 286434d67debSChao Yu } 286534d67debSChao Yu 2866b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2867b5492af7SJaegeuk Kim { 2868b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2869b5492af7SJaegeuk Kim } 2870b5492af7SJaegeuk Kim 2871b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2872b5492af7SJaegeuk Kim { 2873b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 28747c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2875b5492af7SJaegeuk Kim } 2876b5492af7SJaegeuk Kim 2877b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2878b5492af7SJaegeuk Kim { 2879b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 28807c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2881b5492af7SJaegeuk Kim } 2882b5492af7SJaegeuk Kim 2883fe1897eaSChao Yu static inline bool f2fs_is_time_consistent(struct inode *inode) 2884fe1897eaSChao Yu { 2885fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime)) 2886fe1897eaSChao Yu return false; 2887fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime)) 2888fe1897eaSChao Yu return false; 2889fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime)) 2890fe1897eaSChao Yu return false; 2891fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3, 2892fe1897eaSChao Yu &F2FS_I(inode)->i_crtime)) 2893fe1897eaSChao Yu return false; 2894fe1897eaSChao Yu return true; 2895fe1897eaSChao Yu } 2896fe1897eaSChao Yu 289726787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 289826787236SJaegeuk Kim { 2899a0d00fadSChao Yu bool ret; 2900a0d00fadSChao Yu 290126787236SJaegeuk Kim if (dsync) { 290226787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 290326787236SJaegeuk Kim 290426787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 290526787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 290626787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 290726787236SJaegeuk Kim return ret; 290826787236SJaegeuk Kim } 290926787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 291026787236SJaegeuk Kim file_keep_isize(inode) || 2911235831d7SJunling Zheng i_size_read(inode) & ~PAGE_MASK) 291226787236SJaegeuk Kim return false; 2913a0d00fadSChao Yu 2914fe1897eaSChao Yu if (!f2fs_is_time_consistent(inode)) 2915214c2461SJaegeuk Kim return false; 2916214c2461SJaegeuk Kim 2917c10c9820SChao Yu spin_lock(&F2FS_I(inode)->i_size_lock); 2918a0d00fadSChao Yu ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 2919c10c9820SChao Yu spin_unlock(&F2FS_I(inode)->i_size_lock); 2920a0d00fadSChao Yu 2921a0d00fadSChao Yu return ret; 2922267378d4SChao Yu } 2923267378d4SChao Yu 2924deeedd71SChao Yu static inline bool f2fs_readonly(struct super_block *sb) 292577888c1eSJaegeuk Kim { 2926deeedd71SChao Yu return sb_rdonly(sb); 292777888c1eSJaegeuk Kim } 292877888c1eSJaegeuk Kim 2929744602cfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 2930744602cfSJaegeuk Kim { 2931aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 2932744602cfSJaegeuk Kim } 2933744602cfSJaegeuk Kim 293443c780baSEric Biggers static inline bool is_dot_dotdot(const u8 *name, size_t len) 2935eaa693f4SJaegeuk Kim { 293643c780baSEric Biggers if (len == 1 && name[0] == '.') 2937eaa693f4SJaegeuk Kim return true; 2938eaa693f4SJaegeuk Kim 293943c780baSEric Biggers if (len == 2 && name[0] == '.' && name[1] == '.') 2940eaa693f4SJaegeuk Kim return true; 2941eaa693f4SJaegeuk Kim 2942eaa693f4SJaegeuk Kim return false; 2943eaa693f4SJaegeuk Kim } 2944eaa693f4SJaegeuk Kim 29453e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 29463e72f721SJaegeuk Kim { 2947e4589fa5SSahitya Tummala struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 2948e4589fa5SSahitya Tummala 2949e4589fa5SSahitya Tummala if (!test_opt(sbi, EXTENT_CACHE) || 29504c8ff709SChao Yu is_inode_flag_set(inode, FI_NO_EXTENT) || 29514c8ff709SChao Yu is_inode_flag_set(inode, FI_COMPRESSED_FILE)) 29523e72f721SJaegeuk Kim return false; 29533e72f721SJaegeuk Kim 2954e4589fa5SSahitya Tummala /* 2955e4589fa5SSahitya Tummala * for recovered files during mount do not create extents 2956e4589fa5SSahitya Tummala * if shrinker is not registered. 2957e4589fa5SSahitya Tummala */ 2958e4589fa5SSahitya Tummala if (list_empty(&sbi->s_list)) 2959e4589fa5SSahitya Tummala return false; 2960e4589fa5SSahitya Tummala 2961886f56f9SAl Viro return S_ISREG(inode->i_mode); 29623e72f721SJaegeuk Kim } 29633e72f721SJaegeuk Kim 29641ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 29651ecc0c5cSChao Yu size_t size, gfp_t flags) 29660414b004SJaegeuk Kim { 296755523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 2968c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_KMALLOC); 29692c63feadSJaegeuk Kim return NULL; 297055523519SChao Yu } 29717fa750a1SArnd Bergmann 29720b6d4ca0SEric Biggers return kmalloc(size, flags); 29730414b004SJaegeuk Kim } 29740414b004SJaegeuk Kim 2975acbf054dSChao Yu static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, 2976acbf054dSChao Yu size_t size, gfp_t flags) 2977acbf054dSChao Yu { 2978acbf054dSChao Yu return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); 2979acbf054dSChao Yu } 2980acbf054dSChao Yu 2981628b3d14SChao Yu static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, 2982628b3d14SChao Yu size_t size, gfp_t flags) 2983628b3d14SChao Yu { 2984628b3d14SChao Yu if (time_to_inject(sbi, FAULT_KVMALLOC)) { 2985c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_KVMALLOC); 2986628b3d14SChao Yu return NULL; 2987628b3d14SChao Yu } 29887fa750a1SArnd Bergmann 2989628b3d14SChao Yu return kvmalloc(size, flags); 2990628b3d14SChao Yu } 2991628b3d14SChao Yu 2992628b3d14SChao Yu static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi, 2993628b3d14SChao Yu size_t size, gfp_t flags) 2994628b3d14SChao Yu { 2995628b3d14SChao Yu return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO); 2996628b3d14SChao Yu } 2997628b3d14SChao Yu 29987a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 2999f2470371SChao Yu { 30007a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 3001f2470371SChao Yu } 3002f2470371SChao Yu 30036afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode) 30046afc662eSChao Yu { 30056afc662eSChao Yu return F2FS_I(inode)->i_inline_xattr_size; 30066afc662eSChao Yu } 30076afc662eSChao Yu 30084d57b86dSChao Yu #define f2fs_get_inode_mode(i) \ 300991942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 3010a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 3011a6dda0e6SChristoph Hellwig 30127a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 30137a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 30147a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 30157a2af766SChao Yu 30165c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 30175c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 30182f84babfSSheng Yong ((offsetof(typeof(*(f2fs_inode)), field) + \ 30195c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 30202f84babfSSheng Yong <= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize))) \ 30215c57132eSChao Yu 30222bc4bea3SDaeho Jeong #define DEFAULT_IOSTAT_PERIOD_MS 3000 30232bc4bea3SDaeho Jeong #define MIN_IOSTAT_PERIOD_MS 100 30242bc4bea3SDaeho Jeong /* maximum period of iostat tracing is 1 day */ 30252bc4bea3SDaeho Jeong #define MAX_IOSTAT_PERIOD_MS 8640000 30262bc4bea3SDaeho Jeong 3027b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 3028b0af6d49SChao Yu { 3029b0af6d49SChao Yu int i; 3030b0af6d49SChao Yu 3031b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 30322bc4bea3SDaeho Jeong for (i = 0; i < NR_IO_TYPE; i++) { 30338b83ac81SChao Yu sbi->rw_iostat[i] = 0; 30348b83ac81SChao Yu sbi->prev_rw_iostat[i] = 0; 30352bc4bea3SDaeho Jeong } 3036b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 3037b0af6d49SChao Yu } 3038b0af6d49SChao Yu 30392bc4bea3SDaeho Jeong extern void f2fs_record_iostat(struct f2fs_sb_info *sbi); 30402bc4bea3SDaeho Jeong 3041b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 3042b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 3043b0af6d49SChao Yu { 3044b0af6d49SChao Yu if (!sbi->iostat_enable) 3045b0af6d49SChao Yu return; 3046b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 30478b83ac81SChao Yu sbi->rw_iostat[type] += io_bytes; 3048b0af6d49SChao Yu 3049b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 30508b83ac81SChao Yu sbi->rw_iostat[APP_BUFFERED_IO] = 30518b83ac81SChao Yu sbi->rw_iostat[APP_WRITE_IO] - 30528b83ac81SChao Yu sbi->rw_iostat[APP_DIRECT_IO]; 30538b83ac81SChao Yu 30548b83ac81SChao Yu if (type == APP_READ_IO || type == APP_DIRECT_READ_IO) 30558b83ac81SChao Yu sbi->rw_iostat[APP_BUFFERED_READ_IO] = 30568b83ac81SChao Yu sbi->rw_iostat[APP_READ_IO] - 30578b83ac81SChao Yu sbi->rw_iostat[APP_DIRECT_READ_IO]; 3058b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 30592bc4bea3SDaeho Jeong 30602bc4bea3SDaeho Jeong f2fs_record_iostat(sbi); 3061b0af6d49SChao Yu } 3062b0af6d49SChao Yu 30632c70c5e3SChao Yu #define __is_large_section(sbi) ((sbi)->segs_per_sec > 1) 30642c70c5e3SChao Yu 30656dc3a126SChao Yu #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META) 3066c9b60788SChao Yu 3067e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 3068e1da7872SChao Yu block_t blkaddr, int type); 3069e1da7872SChao Yu static inline void verify_blkaddr(struct f2fs_sb_info *sbi, 3070e1da7872SChao Yu block_t blkaddr, int type) 3071e1da7872SChao Yu { 3072e1da7872SChao Yu if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) { 3073dcbb4c10SJoe Perches f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.", 3074e1da7872SChao Yu blkaddr, type); 3075e1da7872SChao Yu f2fs_bug_on(sbi, 1); 3076e1da7872SChao Yu } 3077e1da7872SChao Yu } 3078e1da7872SChao Yu 3079e1da7872SChao Yu static inline bool __is_valid_data_blkaddr(block_t blkaddr) 30807b525dd0SChao Yu { 30814c8ff709SChao Yu if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR || 30824c8ff709SChao Yu blkaddr == COMPRESS_ADDR) 30837b525dd0SChao Yu return false; 30847b525dd0SChao Yu return true; 30857b525dd0SChao Yu } 30867b525dd0SChao Yu 3087240a5915SChao Yu static inline void f2fs_set_page_private(struct page *page, 3088240a5915SChao Yu unsigned long data) 3089240a5915SChao Yu { 3090240a5915SChao Yu if (PagePrivate(page)) 3091240a5915SChao Yu return; 3092240a5915SChao Yu 30937128cf9aSGuoqing Jiang attach_page_private(page, (void *)data); 3094240a5915SChao Yu } 3095240a5915SChao Yu 3096240a5915SChao Yu static inline void f2fs_clear_page_private(struct page *page) 3097240a5915SChao Yu { 30987128cf9aSGuoqing Jiang detach_page_private(page); 3099240a5915SChao Yu } 3100240a5915SChao Yu 310139a53e0cSJaegeuk Kim /* 310239a53e0cSJaegeuk Kim * file.c 310339a53e0cSJaegeuk Kim */ 3104cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 31054d57b86dSChao Yu void f2fs_truncate_data_blocks(struct dnode_of_data *dn); 31063265d3dbSChao Yu int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock); 3107c42d28ceSChao Yu int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock); 3108cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 3109a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 3110a528d35eSDavid Howells u32 request_mask, unsigned int flags); 3111cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 31124d57b86dSChao Yu int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 31134d57b86dSChao Yu void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); 3114c4020b2dSChao Yu int f2fs_precache_extents(struct inode *inode); 3115cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 3116cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 311778130819SChao Yu int f2fs_transfer_project_quota(struct inode *inode, kprojid_t kprojid); 31181ad71a27SJaegeuk Kim int f2fs_pin_file_control(struct inode *inode, bool inc); 311939a53e0cSJaegeuk Kim 312039a53e0cSJaegeuk Kim /* 312139a53e0cSJaegeuk Kim * inode.c 312239a53e0cSJaegeuk Kim */ 3123cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 3124704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 3125704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 3126cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 3127cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 31284d57b86dSChao Yu int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 31294d57b86dSChao Yu void f2fs_update_inode(struct inode *inode, struct page *node_page); 31304d57b86dSChao Yu void f2fs_update_inode_page(struct inode *inode); 3131cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 3132cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 31334d57b86dSChao Yu void f2fs_handle_failed_inode(struct inode *inode); 313439a53e0cSJaegeuk Kim 313539a53e0cSJaegeuk Kim /* 313639a53e0cSJaegeuk Kim * namei.c 313739a53e0cSJaegeuk Kim */ 31384d57b86dSChao Yu int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, 3139b6a06cbbSChao Yu bool hot, bool set); 314039a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 314139a53e0cSJaegeuk Kim 314239a53e0cSJaegeuk Kim /* 314339a53e0cSJaegeuk Kim * dir.c 314439a53e0cSJaegeuk Kim */ 31454d57b86dSChao Yu unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de); 314643c780baSEric Biggers int f2fs_init_casefolded_name(const struct inode *dir, 314743c780baSEric Biggers struct f2fs_filename *fname); 314843c780baSEric Biggers int f2fs_setup_filename(struct inode *dir, const struct qstr *iname, 314943c780baSEric Biggers int lookup, struct f2fs_filename *fname); 315043c780baSEric Biggers int f2fs_prepare_lookup(struct inode *dir, struct dentry *dentry, 315143c780baSEric Biggers struct f2fs_filename *fname); 315243c780baSEric Biggers void f2fs_free_filename(struct f2fs_filename *fname); 315343c780baSEric Biggers struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_ptr *d, 315443c780baSEric Biggers const struct f2fs_filename *fname, int *max_slots); 3155cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 3156cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 31574d57b86dSChao Yu void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent, 3158cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 31594d57b86dSChao Yu struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir, 316043c780baSEric Biggers const struct f2fs_filename *fname, struct page *dpage); 31614d57b86dSChao Yu void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode, 3162cac5a3d8SDongOh Shin unsigned int current_depth); 31634d57b86dSChao Yu int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots); 3164cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 3165cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 316643c780baSEric Biggers const struct f2fs_filename *fname, 316743c780baSEric Biggers struct page **res_page); 3168cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 3169cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 3170cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 3171cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 3172cac5a3d8SDongOh Shin struct page **page); 3173cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 3174cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 3175b06af2afSJaegeuk Kim bool f2fs_has_enough_room(struct inode *dir, struct page *ipage, 317643c780baSEric Biggers const struct f2fs_filename *fname); 3177cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 317843c780baSEric Biggers const struct fscrypt_str *name, f2fs_hash_t name_hash, 3179cac5a3d8SDongOh Shin unsigned int bit_pos); 318043c780baSEric Biggers int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname, 3181cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 318243c780baSEric Biggers int f2fs_add_dentry(struct inode *dir, const struct f2fs_filename *fname, 3183cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 31844d57b86dSChao Yu int f2fs_do_add_link(struct inode *dir, const struct qstr *name, 3185cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 3186cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 3187cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 3188cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 3189cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 319039a53e0cSJaegeuk Kim 3191b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 3192b7f7a5e0SAl Viro { 31934d57b86dSChao Yu return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name, 3194510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 3195b7f7a5e0SAl Viro } 3196b7f7a5e0SAl Viro 319739a53e0cSJaegeuk Kim /* 319839a53e0cSJaegeuk Kim * super.c 319939a53e0cSJaegeuk Kim */ 3200cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 3201cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 3202ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); 3203af033b2aSChao Yu int f2fs_quota_sync(struct super_block *sb, int type); 32044b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 3205cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 3206cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 32074d57b86dSChao Yu int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); 320839a53e0cSJaegeuk Kim 320939a53e0cSJaegeuk Kim /* 321039a53e0cSJaegeuk Kim * hash.c 321139a53e0cSJaegeuk Kim */ 321243c780baSEric Biggers void f2fs_hash_filename(const struct inode *dir, struct f2fs_filename *fname); 321339a53e0cSJaegeuk Kim 321439a53e0cSJaegeuk Kim /* 321539a53e0cSJaegeuk Kim * node.c 321639a53e0cSJaegeuk Kim */ 321739a53e0cSJaegeuk Kim struct dnode_of_data; 321839a53e0cSJaegeuk Kim struct node_info; 321939a53e0cSJaegeuk Kim 32204d57b86dSChao Yu int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid); 32214d57b86dSChao Yu bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type); 322250fa53ecSChao Yu bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page); 322350fa53ecSChao Yu void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi); 322450fa53ecSChao Yu void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page); 322550fa53ecSChao Yu void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi); 32264d57b86dSChao Yu int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 32274d57b86dSChao Yu bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 32284d57b86dSChao Yu bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 32297735730dSChao Yu int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, 32304d57b86dSChao Yu struct node_info *ni); 32314d57b86dSChao Yu pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 32324d57b86dSChao Yu int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 32334d57b86dSChao Yu int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from); 32344d57b86dSChao Yu int f2fs_truncate_xattr_node(struct inode *inode); 323550fa53ecSChao Yu int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, 323650fa53ecSChao Yu unsigned int seq_id); 32374d57b86dSChao Yu int f2fs_remove_inode_page(struct inode *inode); 32384d57b86dSChao Yu struct page *f2fs_new_inode_page(struct inode *inode); 32394d57b86dSChao Yu struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs); 32404d57b86dSChao Yu void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 32414d57b86dSChao Yu struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 32424d57b86dSChao Yu struct page *f2fs_get_node_page_ra(struct page *parent, int start); 324348018b4cSChao Yu int f2fs_move_node_page(struct page *node_page, int gc_type); 324468e79bafSJia Yang void f2fs_flush_inline_data(struct f2fs_sb_info *sbi); 32454d57b86dSChao Yu int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 324650fa53ecSChao Yu struct writeback_control *wbc, bool atomic, 324750fa53ecSChao Yu unsigned int *seq_id); 32484d57b86dSChao Yu int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, 32494d57b86dSChao Yu struct writeback_control *wbc, 3250b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 3251e2374015SChao Yu int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 32524d57b86dSChao Yu bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 32534d57b86dSChao Yu void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 32544d57b86dSChao Yu void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 32554d57b86dSChao Yu int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 32569627a7b3SChao Yu int f2fs_recover_inline_xattr(struct inode *inode, struct page *page); 32574d57b86dSChao Yu int f2fs_recover_xattr_data(struct inode *inode, struct page *page); 32584d57b86dSChao Yu int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 32597735730dSChao Yu int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, 3260cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 3261edc55aafSJaegeuk Kim int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 32624d57b86dSChao Yu int f2fs_build_node_manager(struct f2fs_sb_info *sbi); 32634d57b86dSChao Yu void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi); 32644d57b86dSChao Yu int __init f2fs_create_node_manager_caches(void); 32654d57b86dSChao Yu void f2fs_destroy_node_manager_caches(void); 326639a53e0cSJaegeuk Kim 326739a53e0cSJaegeuk Kim /* 326839a53e0cSJaegeuk Kim * segment.c 326939a53e0cSJaegeuk Kim */ 32704d57b86dSChao Yu bool f2fs_need_SSR(struct f2fs_sb_info *sbi); 32714d57b86dSChao Yu void f2fs_register_inmem_page(struct inode *inode, struct page *page); 32724d57b86dSChao Yu void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure); 32734d57b86dSChao Yu void f2fs_drop_inmem_pages(struct inode *inode); 32744d57b86dSChao Yu void f2fs_drop_inmem_page(struct inode *inode, struct page *page); 32754d57b86dSChao Yu int f2fs_commit_inmem_pages(struct inode *inode); 3276cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 32777bcd0cfaSChao Yu void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg); 327839d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 32794d57b86dSChao Yu int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi); 32801228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); 32814d57b86dSChao Yu void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 32824d57b86dSChao Yu void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 32834d57b86dSChao Yu bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 32844d57b86dSChao Yu void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi); 32854d57b86dSChao Yu void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi); 328603f2c02dSJaegeuk Kim bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi); 32874d57b86dSChao Yu void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, 32884d57b86dSChao Yu struct cp_control *cpc); 32894354994fSDaniel Rosenberg void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi); 32904d3aed70SDaniel Rosenberg block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi); 32914d3aed70SDaniel Rosenberg int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable); 32924d57b86dSChao Yu void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi); 32934d57b86dSChao Yu int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 3294093749e2SChao Yu void f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi); 3295093749e2SChao Yu void f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi); 3296093749e2SChao Yu void f2fs_restore_inmem_curseg(struct f2fs_sb_info *sbi); 3297093749e2SChao Yu void f2fs_get_new_segment(struct f2fs_sb_info *sbi, 3298093749e2SChao Yu unsigned int *newseg, bool new_sec, int dir); 32990ef81833SChao Yu void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, 330004f0b2eaSQiuyang Sun unsigned int start, unsigned int end); 3301901d745fSChao Yu void f2fs_allocate_new_segment(struct f2fs_sb_info *sbi, int type); 3302901d745fSChao Yu void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi); 3303cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 33044d57b86dSChao Yu bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, 33054d57b86dSChao Yu struct cp_control *cpc); 33064d57b86dSChao Yu struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 33074d57b86dSChao Yu void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src, 33084d57b86dSChao Yu block_t blk_addr); 33094d57b86dSChao Yu void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 3310b0af6d49SChao Yu enum iostat_type io_type); 33114d57b86dSChao Yu void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio); 33124d57b86dSChao Yu void f2fs_outplace_write_data(struct dnode_of_data *dn, 33134d57b86dSChao Yu struct f2fs_io_info *fio); 33144d57b86dSChao Yu int f2fs_inplace_write_data(struct f2fs_io_info *fio); 33154d57b86dSChao Yu void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 3316cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 3317c5d02785SChao Yu bool recover_curseg, bool recover_newaddr, 3318c5d02785SChao Yu bool from_gc); 3319cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 3320cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 3321cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 3322cac5a3d8SDongOh Shin bool recover_newaddr); 33234d57b86dSChao Yu void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 3324cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 3325fb830fc5SChao Yu struct f2fs_summary *sum, int type, 3326f608c38cSChao Yu struct f2fs_io_info *fio); 3327cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 3328bae0ee7aSChao Yu enum page_type type, bool ordered, bool locked); 33290ded69f6SJaegeuk Kim void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr); 33301e78e8bdSSahitya Tummala void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr, 33311e78e8bdSSahitya Tummala block_t len); 33324d57b86dSChao Yu void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 33334d57b86dSChao Yu void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 33344d57b86dSChao Yu int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 3335cac5a3d8SDongOh Shin unsigned int val, int alloc); 33364d57b86dSChao Yu void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 3337c426d991SShin'ichiro Kawasaki int f2fs_fix_curseg_write_pointer(struct f2fs_sb_info *sbi); 3338d508c94eSShin'ichiro Kawasaki int f2fs_check_write_pointer(struct f2fs_sb_info *sbi); 33394d57b86dSChao Yu int f2fs_build_segment_manager(struct f2fs_sb_info *sbi); 33404d57b86dSChao Yu void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi); 33414d57b86dSChao Yu int __init f2fs_create_segment_manager_caches(void); 33424d57b86dSChao Yu void f2fs_destroy_segment_manager_caches(void); 33434d57b86dSChao Yu int f2fs_rw_hint_to_seg_type(enum rw_hint hint); 33444d57b86dSChao Yu enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, 33454d57b86dSChao Yu enum page_type type, enum temp_type temp); 3346de881df9SAravind Ramesh unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi, 3347de881df9SAravind Ramesh unsigned int segno); 3348de881df9SAravind Ramesh unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi, 3349de881df9SAravind Ramesh unsigned int segno); 335039a53e0cSJaegeuk Kim 335139a53e0cSJaegeuk Kim /* 335239a53e0cSJaegeuk Kim * checkpoint.c 335339a53e0cSJaegeuk Kim */ 3354cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 33554d57b86dSChao Yu struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 33564d57b86dSChao Yu struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 335786f33603SJaegeuk Kim struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index); 33584d57b86dSChao Yu struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 3359e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 33604d57b86dSChao Yu block_t blkaddr, int type); 33614d57b86dSChao Yu int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 3362cac5a3d8SDongOh Shin int type, bool sync); 33634d57b86dSChao Yu void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 33644d57b86dSChao Yu long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 3365b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 33664d57b86dSChao Yu void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 33674d57b86dSChao Yu void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 33684d57b86dSChao Yu void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all); 33694d57b86dSChao Yu bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 33704d57b86dSChao Yu void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 337139d787beSChao Yu unsigned int devidx, int type); 33724d57b86dSChao Yu bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 337339d787beSChao Yu unsigned int devidx, int type); 3374cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 33754d57b86dSChao Yu int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi); 33764d57b86dSChao Yu void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi); 33774d57b86dSChao Yu void f2fs_add_orphan_inode(struct inode *inode); 33784d57b86dSChao Yu void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 33794d57b86dSChao Yu int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi); 33804d57b86dSChao Yu int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi); 33814d57b86dSChao Yu void f2fs_update_dirty_page(struct inode *inode, struct page *page); 33824d57b86dSChao Yu void f2fs_remove_dirty_inode(struct inode *inode); 33834d57b86dSChao Yu int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 3384bf22c3ccSSahitya Tummala void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type); 33854d57b86dSChao Yu int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 33864d57b86dSChao Yu void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi); 33874d57b86dSChao Yu int __init f2fs_create_checkpoint_caches(void); 33884d57b86dSChao Yu void f2fs_destroy_checkpoint_caches(void); 338939a53e0cSJaegeuk Kim 339039a53e0cSJaegeuk Kim /* 339139a53e0cSJaegeuk Kim * data.c 339239a53e0cSJaegeuk Kim */ 3393f543805fSChao Yu int __init f2fs_init_bioset(void); 3394f543805fSChao Yu void f2fs_destroy_bioset(void); 3395ca9e968aSChao Yu struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, int npages, bool noio); 33960b20fcecSChao Yu int f2fs_init_bio_entry_cache(void); 33970b20fcecSChao Yu void f2fs_destroy_bio_entry_cache(void); 33984c8ff709SChao Yu void f2fs_submit_bio(struct f2fs_sb_info *sbi, 33994c8ff709SChao Yu struct bio *bio, enum page_type type); 3400b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 3401b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 3402bab475c5SChao Yu struct inode *inode, struct page *page, 3403bab475c5SChao Yu nid_t ino, enum page_type type); 34040b20fcecSChao Yu void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi, 34050b20fcecSChao Yu struct bio **bio, struct page *page); 3406b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 3407cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 34088648de2cSChao Yu int f2fs_merge_page_bio(struct f2fs_io_info *fio); 3409fe16efe6SChao Yu void f2fs_submit_page_write(struct f2fs_io_info *fio); 3410cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 3411cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 3412cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 34134d57b86dSChao Yu void f2fs_set_data_blkaddr(struct dnode_of_data *dn); 3414cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 34154d57b86dSChao Yu int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 34164d57b86dSChao Yu int f2fs_reserve_new_block(struct dnode_of_data *dn); 3417cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 3418cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 3419cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 34204d57b86dSChao Yu struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, 3421cac5a3d8SDongOh Shin int op_flags, bool for_write); 34224d57b86dSChao Yu struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index); 34234d57b86dSChao Yu struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index, 3424cac5a3d8SDongOh Shin bool for_write); 34254d57b86dSChao Yu struct page *f2fs_get_new_data_page(struct inode *inode, 3426cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 34274d57b86dSChao Yu int f2fs_do_write_data_page(struct f2fs_io_info *fio); 34280ef81833SChao Yu void f2fs_do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock); 3429cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 3430cac5a3d8SDongOh Shin int create, int flag); 3431cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 3432cac5a3d8SDongOh Shin u64 start, u64 len); 34334c8ff709SChao Yu int f2fs_encrypt_one_page(struct f2fs_io_info *fio); 34344d57b86dSChao Yu bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); 34354d57b86dSChao Yu bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); 34364c8ff709SChao Yu int f2fs_write_single_data_page(struct page *page, int *submitted, 34374c8ff709SChao Yu struct bio **bio, sector_t *last_block, 34384c8ff709SChao Yu struct writeback_control *wbc, 34394c8ff709SChao Yu enum iostat_type io_type, 34404c8ff709SChao Yu int compr_blocks); 3441cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 3442cac5a3d8SDongOh Shin unsigned int length); 3443cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 34445b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 3445cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 3446cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 34475b7a487cSWeichao Guo #endif 3448b91050a8SHyunchul Lee bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len); 34495ec2d99dSMatthew Wilcox void f2fs_clear_page_cache_dirty_tag(struct page *page); 34504c8ff709SChao Yu int f2fs_init_post_read_processing(void); 34514c8ff709SChao Yu void f2fs_destroy_post_read_processing(void); 34524c8ff709SChao Yu int f2fs_init_post_read_wq(struct f2fs_sb_info *sbi); 34534c8ff709SChao Yu void f2fs_destroy_post_read_wq(struct f2fs_sb_info *sbi); 345439a53e0cSJaegeuk Kim 345539a53e0cSJaegeuk Kim /* 345639a53e0cSJaegeuk Kim * gc.c 345739a53e0cSJaegeuk Kim */ 34584d57b86dSChao Yu int f2fs_start_gc_thread(struct f2fs_sb_info *sbi); 34594d57b86dSChao Yu void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi); 34604d57b86dSChao Yu block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 3461e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 3462e066b83cSJaegeuk Kim unsigned int segno); 34634d57b86dSChao Yu void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); 346404f0b2eaSQiuyang Sun int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count); 3465093749e2SChao Yu int __init f2fs_create_garbage_collection_cache(void); 3466093749e2SChao Yu void f2fs_destroy_garbage_collection_cache(void); 346739a53e0cSJaegeuk Kim 346839a53e0cSJaegeuk Kim /* 346939a53e0cSJaegeuk Kim * recovery.c 347039a53e0cSJaegeuk Kim */ 34714d57b86dSChao Yu int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 34724d57b86dSChao Yu bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi); 347339a53e0cSJaegeuk Kim 347439a53e0cSJaegeuk Kim /* 347539a53e0cSJaegeuk Kim * debug.c 347639a53e0cSJaegeuk Kim */ 347739a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 347839a53e0cSJaegeuk Kim struct f2fs_stat_info { 347939a53e0cSJaegeuk Kim struct list_head stat_list; 348039a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 348139a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 348239a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 34835b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 34845b7ee374SChao Yu unsigned long long hit_total, total_ext; 3485c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 34862c8a4a28SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; 34872c8a4a28SJaegeuk Kim int ndirty_data, ndirty_qdata; 348835782b23SJaegeuk Kim int inmem_pages; 34892c8a4a28SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; 34905b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 34915b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 349239a53e0cSJaegeuk Kim int total_count, utilization; 34938b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 34945f9abab4SJaegeuk Kim int nr_rd_data, nr_rd_node, nr_rd_meta; 349502b16d0aSChao Yu int nr_dio_read, nr_dio_write; 3496274bd9baSChao Yu unsigned int io_skip_bggc, other_skip_bggc; 349714d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 349814d8d5f7SChao Yu int nr_discarding, nr_discarded; 34995f32366aSChao Yu int nr_discard_cmd; 3500d84d1cbdSChao Yu unsigned int undiscard_blks; 3501a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 3502ae999bb9SDaeho Jeong int compr_inode; 3503ae999bb9SDaeho Jeong unsigned long long compr_blocks; 3504648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 3505f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 350639a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 350739a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 350839a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 350939a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 351042190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 351139a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 3512e1235983SChangman Lee int bg_node_segs, bg_data_segs; 351339a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 3514e1235983SChangman Lee int bg_data_blks, bg_node_blks; 35152ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; 351639a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 351739a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 351839a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 35190759e2c1SChao Yu unsigned int dirty_seg[NR_CURSEG_TYPE]; 35200759e2c1SChao Yu unsigned int full_seg[NR_CURSEG_TYPE]; 35210759e2c1SChao Yu unsigned int valid_blks[NR_CURSEG_TYPE]; 352239a53e0cSJaegeuk Kim 3523b63e7be5SChao Yu unsigned int meta_count[META_MAX]; 352439a53e0cSJaegeuk Kim unsigned int segment_count[2]; 352539a53e0cSJaegeuk Kim unsigned int block_count[2]; 3526b9a2c252SChangman Lee unsigned int inplace_count; 35279edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 352839a53e0cSJaegeuk Kim }; 352939a53e0cSJaegeuk Kim 3530963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 3531963d4f7dSGu Zheng { 3532963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 3533963d4f7dSGu Zheng } 3534963d4f7dSGu Zheng 3535942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 353642190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 353739a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 3538fc7100eaSHridya Valsaraju #define stat_inc_bggc_count(si) ((si)->bg_gc++) 3539274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) ((sbi)->io_skip_bggc++) 3540274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) ((sbi)->other_skip_bggc++) 354133fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 354233fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 35435b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 35445b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 35455b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 35465b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 3547d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 3548d5e8f6c9SChao Yu do { \ 3549d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3550d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 3551d5e8f6c9SChao Yu } while (0) 3552d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 3553d5e8f6c9SChao Yu do { \ 3554d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3555d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 3556d5e8f6c9SChao Yu } while (0) 35570dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 35580dbdc2aeSJaegeuk Kim do { \ 35590dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 356003e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 35610dbdc2aeSJaegeuk Kim } while (0) 35620dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 35630dbdc2aeSJaegeuk Kim do { \ 35640dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 356503e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 35660dbdc2aeSJaegeuk Kim } while (0) 35673289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 35683289c061SJaegeuk Kim do { \ 35693289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 357003e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 35713289c061SJaegeuk Kim } while (0) 35723289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 35733289c061SJaegeuk Kim do { \ 35743289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 357503e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 35763289c061SJaegeuk Kim } while (0) 35774c8ff709SChao Yu #define stat_inc_compr_inode(inode) \ 35784c8ff709SChao Yu do { \ 35794c8ff709SChao Yu if (f2fs_compressed_file(inode)) \ 35804c8ff709SChao Yu (atomic_inc(&F2FS_I_SB(inode)->compr_inode)); \ 35814c8ff709SChao Yu } while (0) 35824c8ff709SChao Yu #define stat_dec_compr_inode(inode) \ 35834c8ff709SChao Yu do { \ 35844c8ff709SChao Yu if (f2fs_compressed_file(inode)) \ 35854c8ff709SChao Yu (atomic_dec(&F2FS_I_SB(inode)->compr_inode)); \ 35864c8ff709SChao Yu } while (0) 35874c8ff709SChao Yu #define stat_add_compr_blocks(inode, blocks) \ 3588ae999bb9SDaeho Jeong (atomic64_add(blocks, &F2FS_I_SB(inode)->compr_blocks)) 35894c8ff709SChao Yu #define stat_sub_compr_blocks(inode, blocks) \ 3590ae999bb9SDaeho Jeong (atomic64_sub(blocks, &F2FS_I_SB(inode)->compr_blocks)) 3591b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) \ 3592b63e7be5SChao Yu do { \ 3593b63e7be5SChao Yu if (blkaddr < SIT_I(sbi)->sit_base_addr) \ 3594b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_CP]); \ 3595b63e7be5SChao Yu else if (blkaddr < NM_I(sbi)->nat_blkaddr) \ 3596b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SIT]); \ 3597b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->ssa_blkaddr) \ 3598b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_NAT]); \ 3599b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->main_blkaddr) \ 3600b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SSA]); \ 3601b63e7be5SChao Yu } while (0) 3602dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 3603dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 3604dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 3605dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 3606b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 3607b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 360826a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 360926a28a0cSJaegeuk Kim do { \ 36100e6d0164SSahitya Tummala int cur = F2FS_I_SB(inode)->atomic_files; \ 361126a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 361226a28a0cSJaegeuk Kim if (cur > max) \ 361326a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 361426a28a0cSJaegeuk Kim } while (0) 3615648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 3616648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 3617648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 3618648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 3619648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 3620648d50baSChao Yu do { \ 3621648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 3622648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 3623648d50baSChao Yu if (cur > max) \ 3624648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 3625648d50baSChao Yu } while (0) 3626e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 362739a53e0cSJaegeuk Kim do { \ 3628963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 362968afcf2dSTomohiro Kusumi si->tot_segs++; \ 363068afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 363139a53e0cSJaegeuk Kim si->data_segs++; \ 3632e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 3633e1235983SChangman Lee } else { \ 363439a53e0cSJaegeuk Kim si->node_segs++; \ 3635e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 3636e1235983SChangman Lee } \ 363739a53e0cSJaegeuk Kim } while (0) 363839a53e0cSJaegeuk Kim 363939a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 364068afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 364139a53e0cSJaegeuk Kim 3642e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 364339a53e0cSJaegeuk Kim do { \ 3644963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 364539a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 364639a53e0cSJaegeuk Kim si->data_blks += (blks); \ 364768afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 364839a53e0cSJaegeuk Kim } while (0) 364939a53e0cSJaegeuk Kim 3650e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 365139a53e0cSJaegeuk Kim do { \ 3652963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 365339a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 365439a53e0cSJaegeuk Kim si->node_blks += (blks); \ 365568afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 365639a53e0cSJaegeuk Kim } while (0) 365739a53e0cSJaegeuk Kim 3658cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 3659cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 366021acc07dSGreg Kroah-Hartman void __init f2fs_create_root_stats(void); 36614589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 3662fc7100eaSHridya Valsaraju void f2fs_update_sit_info(struct f2fs_sb_info *sbi); 366339a53e0cSJaegeuk Kim #else 3664d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 3665d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 3666d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 3667d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 3668274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) do { } while (0) 3669274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) do { } while (0) 3670d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 3671d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 3672fc7100eaSHridya Valsaraju #define stat_inc_total_hit(sbi) do { } while (0) 3673fc7100eaSHridya Valsaraju #define stat_inc_rbtree_node_hit(sbi) do { } while (0) 3674d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 3675d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 3676d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 3677d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 3678d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 3679d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 3680d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 3681d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 36824c8ff709SChao Yu #define stat_inc_compr_inode(inode) do { } while (0) 36834c8ff709SChao Yu #define stat_dec_compr_inode(inode) do { } while (0) 36844c8ff709SChao Yu #define stat_add_compr_blocks(inode, blocks) do { } while (0) 36854c8ff709SChao Yu #define stat_sub_compr_blocks(inode, blocks) do { } while (0) 3686d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 3687d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 3688d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 3689d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 3690d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 3691d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 3692b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) do { } while (0) 3693d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 3694d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 3695d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 3696d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 3697d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 3698d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 3699d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 370039a53e0cSJaegeuk Kim 370139a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 370239a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 370321acc07dSGreg Kroah-Hartman static inline void __init f2fs_create_root_stats(void) { } 37044589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 370548abe91aSYueHaibing static inline void f2fs_update_sit_info(struct f2fs_sb_info *sbi) {} 370639a53e0cSJaegeuk Kim #endif 370739a53e0cSJaegeuk Kim 370839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 370939a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 371039a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 371139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 371239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 371339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 371439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 371539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 3716cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 371739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 37184d57b86dSChao Yu extern struct kmem_cache *f2fs_inode_entry_slab; 37191001b347SHuajun Li 3720e18c65b2SHuajun Li /* 3721e18c65b2SHuajun Li * inline.c 3722e18c65b2SHuajun Li */ 3723cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 3724cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 37254d57b86dSChao Yu void f2fs_do_read_inline_data(struct page *page, struct page *ipage); 37264d57b86dSChao Yu void f2fs_truncate_inline_inode(struct inode *inode, 37274d57b86dSChao Yu struct page *ipage, u64 from); 3728cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 3729cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 3730cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 3731b06af2afSJaegeuk Kim int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry); 3732cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 37339627a7b3SChao Yu int f2fs_recover_inline_data(struct inode *inode, struct page *npage); 37344d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, 373543c780baSEric Biggers const struct f2fs_filename *fname, 373643c780baSEric Biggers struct page **res_page); 37374d57b86dSChao Yu int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 3738cac5a3d8SDongOh Shin struct page *ipage); 373943c780baSEric Biggers int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname, 3740cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 37414d57b86dSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, 37424d57b86dSChao Yu struct page *page, struct inode *dir, 37434d57b86dSChao Yu struct inode *inode); 3744cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 3745cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 3746cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 3747cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 3748cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 3749cac5a3d8SDongOh Shin __u64 start, __u64 len); 3750cde4de12SJaegeuk Kim 3751cde4de12SJaegeuk Kim /* 37522658e50dSJaegeuk Kim * shrinker.c 37532658e50dSJaegeuk Kim */ 3754cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 3755cac5a3d8SDongOh Shin struct shrink_control *sc); 3756cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 3757cac5a3d8SDongOh Shin struct shrink_control *sc); 3758cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 3759cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 37602658e50dSJaegeuk Kim 37612658e50dSJaegeuk Kim /* 3762a28ef1f5SChao Yu * extent_cache.c 3763a28ef1f5SChao Yu */ 37644dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree(struct rb_root_cached *root, 3765004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 37662e9b2bb2SChao Yu struct rb_node **f2fs_lookup_rb_tree_ext(struct f2fs_sb_info *sbi, 37672e9b2bb2SChao Yu struct rb_root_cached *root, 37682e9b2bb2SChao Yu struct rb_node **parent, 37692e9b2bb2SChao Yu unsigned long long key, bool *left_most); 37704d57b86dSChao Yu struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 37714dada3fdSChao Yu struct rb_root_cached *root, 37724dada3fdSChao Yu struct rb_node **parent, 37734dada3fdSChao Yu unsigned int ofs, bool *leftmost); 37744dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root, 3775004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 3776004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 3777004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 37784dada3fdSChao Yu bool force, bool *leftmost); 37794d57b86dSChao Yu bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi, 37802e9b2bb2SChao Yu struct rb_root_cached *root, bool check_key); 3781cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 3782a6d601f3SChao Yu void f2fs_init_extent_tree(struct inode *inode, struct page *ipage); 3783cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 3784cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 3785cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 3786cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 3787cac5a3d8SDongOh Shin struct extent_info *ei); 3788cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 378919b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 3790cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 37914d57b86dSChao Yu void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi); 37924d57b86dSChao Yu int __init f2fs_create_extent_cache(void); 37934d57b86dSChao Yu void f2fs_destroy_extent_cache(void); 3794a28ef1f5SChao Yu 3795a28ef1f5SChao Yu /* 37968ceffcb2SChao Yu * sysfs.c 37978ceffcb2SChao Yu */ 3798dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 3799dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 3800dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 3801dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 38028ceffcb2SChao Yu 380395ae251fSEric Biggers /* verity.c */ 380495ae251fSEric Biggers extern const struct fsverity_operations f2fs_verityops; 380595ae251fSEric Biggers 38068ceffcb2SChao Yu /* 3807cde4de12SJaegeuk Kim * crypto support 3808cde4de12SJaegeuk Kim */ 38091958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 38101958593eSJaegeuk Kim { 381162230e0dSChandan Rajendra return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); 38121958593eSJaegeuk Kim } 38131958593eSJaegeuk Kim 3814cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 3815cde4de12SJaegeuk Kim { 3816643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 3817cde4de12SJaegeuk Kim file_set_encrypt(inode); 38189149a5ebSChao Yu f2fs_set_inode_flags(inode); 3819cde4de12SJaegeuk Kim #endif 3820cde4de12SJaegeuk Kim } 3821cde4de12SJaegeuk Kim 38226dbb1796SEric Biggers /* 38236dbb1796SEric Biggers * Returns true if the reads of the inode's data need to undergo some 38246dbb1796SEric Biggers * postprocessing step, like decryption or authenticity verification. 38256dbb1796SEric Biggers */ 38266dbb1796SEric Biggers static inline bool f2fs_post_read_required(struct inode *inode) 3827cde4de12SJaegeuk Kim { 38284c8ff709SChao Yu return f2fs_encrypted_file(inode) || fsverity_active(inode) || 38294c8ff709SChao Yu f2fs_compressed_file(inode); 38304c8ff709SChao Yu } 38314c8ff709SChao Yu 38324c8ff709SChao Yu /* 38334c8ff709SChao Yu * compress.c 38344c8ff709SChao Yu */ 38354c8ff709SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 38364c8ff709SChao Yu bool f2fs_is_compressed_page(struct page *page); 38374c8ff709SChao Yu struct page *f2fs_compress_control_page(struct page *page); 38384c8ff709SChao Yu int f2fs_prepare_compress_overwrite(struct inode *inode, 38394c8ff709SChao Yu struct page **pagep, pgoff_t index, void **fsdata); 38404c8ff709SChao Yu bool f2fs_compress_write_end(struct inode *inode, void *fsdata, 38414c8ff709SChao Yu pgoff_t index, unsigned copied); 38423265d3dbSChao Yu int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock); 38434c8ff709SChao Yu void f2fs_compress_write_end_io(struct bio *bio, struct page *page); 38444c8ff709SChao Yu bool f2fs_is_compress_backend_ready(struct inode *inode); 38455e6bbde9SChao Yu int f2fs_init_compress_mempool(void); 38465e6bbde9SChao Yu void f2fs_destroy_compress_mempool(void); 38474c8ff709SChao Yu void f2fs_decompress_pages(struct bio *bio, struct page *page, bool verity); 38484c8ff709SChao Yu bool f2fs_cluster_is_empty(struct compress_ctx *cc); 38494c8ff709SChao Yu bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index); 38504c8ff709SChao Yu void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page); 38514c8ff709SChao Yu int f2fs_write_multi_pages(struct compress_ctx *cc, 38524c8ff709SChao Yu int *submitted, 38534c8ff709SChao Yu struct writeback_control *wbc, 38544c8ff709SChao Yu enum iostat_type io_type); 38554c8ff709SChao Yu int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index); 38564c8ff709SChao Yu int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, 38574c8ff709SChao Yu unsigned nr_pages, sector_t *last_block_in_bio, 38580683728aSChao Yu bool is_readahead, bool for_write); 38594c8ff709SChao Yu struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc); 38604c8ff709SChao Yu void f2fs_free_dic(struct decompress_io_ctx *dic); 38614c8ff709SChao Yu void f2fs_decompress_end_io(struct page **rpages, 38624c8ff709SChao Yu unsigned int cluster_size, bool err, bool verity); 38634c8ff709SChao Yu int f2fs_init_compress_ctx(struct compress_ctx *cc); 38644c8ff709SChao Yu void f2fs_destroy_compress_ctx(struct compress_ctx *cc); 38654c8ff709SChao Yu void f2fs_init_compress_info(struct f2fs_sb_info *sbi); 386631083031SChao Yu int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi); 386731083031SChao Yu void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi); 3868c68d6c88SChao Yu int __init f2fs_init_compress_cache(void); 3869c68d6c88SChao Yu void f2fs_destroy_compress_cache(void); 38704c8ff709SChao Yu #else 38714c8ff709SChao Yu static inline bool f2fs_is_compressed_page(struct page *page) { return false; } 38724c8ff709SChao Yu static inline bool f2fs_is_compress_backend_ready(struct inode *inode) 38734c8ff709SChao Yu { 38744c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 38754c8ff709SChao Yu return true; 38764c8ff709SChao Yu /* not support compression */ 38774c8ff709SChao Yu return false; 38784c8ff709SChao Yu } 38794c8ff709SChao Yu static inline struct page *f2fs_compress_control_page(struct page *page) 38804c8ff709SChao Yu { 38814c8ff709SChao Yu WARN_ON_ONCE(1); 38824c8ff709SChao Yu return ERR_PTR(-EINVAL); 38834c8ff709SChao Yu } 38845e6bbde9SChao Yu static inline int f2fs_init_compress_mempool(void) { return 0; } 38855e6bbde9SChao Yu static inline void f2fs_destroy_compress_mempool(void) { } 388631083031SChao Yu static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { return 0; } 388731083031SChao Yu static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) { } 3888c68d6c88SChao Yu static inline int __init f2fs_init_compress_cache(void) { return 0; } 3889c68d6c88SChao Yu static inline void f2fs_destroy_compress_cache(void) { } 38904c8ff709SChao Yu #endif 38914c8ff709SChao Yu 38924c8ff709SChao Yu static inline void set_compress_context(struct inode *inode) 38934c8ff709SChao Yu { 38944c8ff709SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 38954c8ff709SChao Yu 38964c8ff709SChao Yu F2FS_I(inode)->i_compress_algorithm = 38974c8ff709SChao Yu F2FS_OPTION(sbi).compress_algorithm; 38984c8ff709SChao Yu F2FS_I(inode)->i_log_cluster_size = 38994c8ff709SChao Yu F2FS_OPTION(sbi).compress_log_size; 3900*b28f047bSChao Yu F2FS_I(inode)->i_compress_flag = 3901*b28f047bSChao Yu F2FS_OPTION(sbi).compress_chksum ? 3902*b28f047bSChao Yu 1 << COMPRESS_CHKSUM : 0; 39034c8ff709SChao Yu F2FS_I(inode)->i_cluster_size = 39044c8ff709SChao Yu 1 << F2FS_I(inode)->i_log_cluster_size; 39054c8ff709SChao Yu F2FS_I(inode)->i_flags |= F2FS_COMPR_FL; 39064c8ff709SChao Yu set_inode_flag(inode, FI_COMPRESSED_FILE); 39074c8ff709SChao Yu stat_inc_compr_inode(inode); 3908530e0704SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 39094c8ff709SChao Yu } 39104c8ff709SChao Yu 391178134d03SDaeho Jeong static inline bool f2fs_disable_compressed_file(struct inode *inode) 39124c8ff709SChao Yu { 39134c8ff709SChao Yu struct f2fs_inode_info *fi = F2FS_I(inode); 39144c8ff709SChao Yu 39154c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 391678134d03SDaeho Jeong return true; 391778134d03SDaeho Jeong if (S_ISREG(inode->i_mode) && 391878134d03SDaeho Jeong (get_dirty_pages(inode) || atomic_read(&fi->i_compr_blocks))) 391978134d03SDaeho Jeong return false; 39204c8ff709SChao Yu 39214c8ff709SChao Yu fi->i_flags &= ~F2FS_COMPR_FL; 39224c8ff709SChao Yu stat_dec_compr_inode(inode); 392396f5b4faSChao Yu clear_inode_flag(inode, FI_COMPRESSED_FILE); 3924530e0704SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 392578134d03SDaeho Jeong return true; 3926cde4de12SJaegeuk Kim } 3927cde4de12SJaegeuk Kim 3928ccd31cb2SSheng Yong #define F2FS_FEATURE_FUNCS(name, flagname) \ 39297beb01f7SChao Yu static inline int f2fs_sb_has_##name(struct f2fs_sb_info *sbi) \ 3930ccd31cb2SSheng Yong { \ 39317beb01f7SChao Yu return F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_##flagname); \ 3932cde4de12SJaegeuk Kim } 3933f424f664SJaegeuk Kim 3934ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(encrypt, ENCRYPT); 3935ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(blkzoned, BLKZONED); 3936ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR); 3937ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA); 3938ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM); 3939ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); 3940ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); 3941ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); 3942b7c409deSSheng Yong F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); 394395ae251fSEric Biggers F2FS_FEATURE_FUNCS(verity, VERITY); 3944d440c52dSJunling Zheng F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); 39455aba5430SDaniel Rosenberg F2FS_FEATURE_FUNCS(casefold, CASEFOLD); 39464c8ff709SChao Yu F2FS_FEATURE_FUNCS(compression, COMPRESSION); 39471c1d35dfSChao Yu 3948178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 394995175dafSDamien Le Moal static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, 395095175dafSDamien Le Moal block_t blkaddr) 3951178053e2SDamien Le Moal { 3952178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 3953178053e2SDamien Le Moal 395495175dafSDamien Le Moal return test_bit(zno, FDEV(devi).blkz_seq); 3955178053e2SDamien Le Moal } 3956178053e2SDamien Le Moal #endif 3957178053e2SDamien Le Moal 39587d20c8abSChao Yu static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi) 395996ba2decSDamien Le Moal { 39607beb01f7SChao Yu return f2fs_sb_has_blkzoned(sbi); 39617d20c8abSChao Yu } 396296ba2decSDamien Le Moal 39637f3d7719SDamien Le Moal static inline bool f2fs_bdev_support_discard(struct block_device *bdev) 39647f3d7719SDamien Le Moal { 39657f3d7719SDamien Le Moal return blk_queue_discard(bdev_get_queue(bdev)) || 39667f3d7719SDamien Le Moal bdev_is_zoned(bdev); 39677f3d7719SDamien Le Moal } 39687f3d7719SDamien Le Moal 39697d20c8abSChao Yu static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi) 39707d20c8abSChao Yu { 39717f3d7719SDamien Le Moal int i; 39727f3d7719SDamien Le Moal 39737f3d7719SDamien Le Moal if (!f2fs_is_multi_device(sbi)) 39747f3d7719SDamien Le Moal return f2fs_bdev_support_discard(sbi->sb->s_bdev); 39757f3d7719SDamien Le Moal 39767f3d7719SDamien Le Moal for (i = 0; i < sbi->s_ndevs; i++) 39777f3d7719SDamien Le Moal if (f2fs_bdev_support_discard(FDEV(i).bdev)) 39787f3d7719SDamien Le Moal return true; 39797f3d7719SDamien Le Moal return false; 39807d20c8abSChao Yu } 39817d20c8abSChao Yu 39827d20c8abSChao Yu static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) 39837d20c8abSChao Yu { 39847d20c8abSChao Yu return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) || 39857d20c8abSChao Yu f2fs_hw_should_discard(sbi); 398652763a4bSJaegeuk Kim } 398752763a4bSJaegeuk Kim 3988f824deb5SChao Yu static inline bool f2fs_hw_is_readonly(struct f2fs_sb_info *sbi) 3989f824deb5SChao Yu { 3990f824deb5SChao Yu int i; 3991f824deb5SChao Yu 3992f824deb5SChao Yu if (!f2fs_is_multi_device(sbi)) 3993f824deb5SChao Yu return bdev_read_only(sbi->sb->s_bdev); 3994f824deb5SChao Yu 3995f824deb5SChao Yu for (i = 0; i < sbi->s_ndevs; i++) 3996f824deb5SChao Yu if (bdev_read_only(FDEV(i).bdev)) 3997f824deb5SChao Yu return true; 3998f824deb5SChao Yu return false; 3999f824deb5SChao Yu } 4000f824deb5SChao Yu 4001b0332a0fSChao Yu static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi) 400252763a4bSJaegeuk Kim { 4003b0332a0fSChao Yu return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS; 400452763a4bSJaegeuk Kim } 400552763a4bSJaegeuk Kim 40064c8ff709SChao Yu static inline bool f2fs_may_compress(struct inode *inode) 40074c8ff709SChao Yu { 40084c8ff709SChao Yu if (IS_SWAPFILE(inode) || f2fs_is_pinned_file(inode) || 40094c8ff709SChao Yu f2fs_is_atomic_file(inode) || 40104c8ff709SChao Yu f2fs_is_volatile_file(inode)) 40114c8ff709SChao Yu return false; 40124c8ff709SChao Yu return S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode); 40134c8ff709SChao Yu } 40144c8ff709SChao Yu 40154c8ff709SChao Yu static inline void f2fs_i_compr_blocks_update(struct inode *inode, 40164c8ff709SChao Yu u64 blocks, bool add) 40174c8ff709SChao Yu { 40184c8ff709SChao Yu int diff = F2FS_I(inode)->i_cluster_size - blocks; 4019c2759ebaSDaeho Jeong struct f2fs_inode_info *fi = F2FS_I(inode); 40204c8ff709SChao Yu 4021ef8d563fSChao Yu /* don't update i_compr_blocks if saved blocks were released */ 4022c2759ebaSDaeho Jeong if (!add && !atomic_read(&fi->i_compr_blocks)) 4023ef8d563fSChao Yu return; 4024ef8d563fSChao Yu 40254c8ff709SChao Yu if (add) { 4026c2759ebaSDaeho Jeong atomic_add(diff, &fi->i_compr_blocks); 40274c8ff709SChao Yu stat_add_compr_blocks(inode, diff); 40284c8ff709SChao Yu } else { 4029c2759ebaSDaeho Jeong atomic_sub(diff, &fi->i_compr_blocks); 40304c8ff709SChao Yu stat_sub_compr_blocks(inode, diff); 40314c8ff709SChao Yu } 40324c8ff709SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 40334c8ff709SChao Yu } 40344c8ff709SChao Yu 4035f847c699SChao Yu static inline int block_unaligned_IO(struct inode *inode, 4036f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4037b91050a8SHyunchul Lee { 4038f847c699SChao Yu unsigned int i_blkbits = READ_ONCE(inode->i_blkbits); 4039f847c699SChao Yu unsigned int blocksize_mask = (1 << i_blkbits) - 1; 4040f847c699SChao Yu loff_t offset = iocb->ki_pos; 4041f847c699SChao Yu unsigned long align = offset | iov_iter_alignment(iter); 4042f847c699SChao Yu 4043f847c699SChao Yu return align & blocksize_mask; 4044f847c699SChao Yu } 4045f847c699SChao Yu 4046f847c699SChao Yu static inline int allow_outplace_dio(struct inode *inode, 4047f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4048f847c699SChao Yu { 4049f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4050f847c699SChao Yu int rw = iov_iter_rw(iter); 4051f847c699SChao Yu 4052b0332a0fSChao Yu return (f2fs_lfs_mode(sbi) && (rw == WRITE) && 4053f847c699SChao Yu !block_unaligned_IO(inode, iocb, iter)); 4054f847c699SChao Yu } 4055f847c699SChao Yu 4056f847c699SChao Yu static inline bool f2fs_force_buffered_io(struct inode *inode, 4057f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4058f847c699SChao Yu { 4059f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4060f847c699SChao Yu int rw = iov_iter_rw(iter); 4061f847c699SChao Yu 4062f847c699SChao Yu if (f2fs_post_read_required(inode)) 4063f847c699SChao Yu return true; 40640916878dSDamien Le Moal if (f2fs_is_multi_device(sbi)) 4065f847c699SChao Yu return true; 4066f847c699SChao Yu /* 4067f847c699SChao Yu * for blkzoned device, fallback direct IO to buffered IO, so 4068f847c699SChao Yu * all IOs can be serialized by log-structured write. 4069f847c699SChao Yu */ 40707beb01f7SChao Yu if (f2fs_sb_has_blkzoned(sbi)) 4071f847c699SChao Yu return true; 4072b0332a0fSChao Yu if (f2fs_lfs_mode(sbi) && (rw == WRITE)) { 40739720ee80SChao Yu if (block_unaligned_IO(inode, iocb, iter)) 4074f847c699SChao Yu return true; 40759720ee80SChao Yu if (F2FS_IO_ALIGNED(sbi)) 40769720ee80SChao Yu return true; 40779720ee80SChao Yu } 40784969c06aSJaegeuk Kim if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED) && 40793ee0c5d3SChao Yu !IS_SWAPFILE(inode)) 40804354994fSDaniel Rosenberg return true; 40814354994fSDaniel Rosenberg 4082f847c699SChao Yu return false; 4083b91050a8SHyunchul Lee } 4084b91050a8SHyunchul Lee 408583a3bfdbSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 4086d494500aSChao Yu extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, 4087d494500aSChao Yu unsigned int type); 408883a3bfdbSJaegeuk Kim #else 4089d494500aSChao Yu #define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) 409083a3bfdbSJaegeuk Kim #endif 409183a3bfdbSJaegeuk Kim 4092af033b2aSChao Yu static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) 4093af033b2aSChao Yu { 4094af033b2aSChao Yu #ifdef CONFIG_QUOTA 40957beb01f7SChao Yu if (f2fs_sb_has_quota_ino(sbi)) 4096af033b2aSChao Yu return true; 4097af033b2aSChao Yu if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || 4098af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || 4099af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) 4100af033b2aSChao Yu return true; 4101af033b2aSChao Yu #endif 4102af033b2aSChao Yu return false; 4103af033b2aSChao Yu } 41040af725fcSJaegeuk Kim 410510f966bbSChao Yu #define EFSBADCRC EBADMSG /* Bad CRC detected */ 410610f966bbSChao Yu #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 410710f966bbSChao Yu 4108e1074d4bSChao Yu #endif /* _LINUX_F2FS_H */ 4109