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 { \ 36db489652SYangtao Li if (WARN_ON(condition)) \ 37caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 389850cf4aSJaegeuk Kim } while (0) 395d56b671SJaegeuk Kim #endif 405d56b671SJaegeuk Kim 412c63feadSJaegeuk Kim enum { 422c63feadSJaegeuk Kim FAULT_KMALLOC, 43628b3d14SChao Yu FAULT_KVMALLOC, 44c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 4501eccef7SChao Yu FAULT_PAGE_GET, 46cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 47cb78942bSJaegeuk Kim FAULT_ORPHAN, 48cb78942bSJaegeuk Kim FAULT_BLOCK, 49cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5053aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 5114b44d23SJaegeuk Kim FAULT_TRUNCATE, 526f5c2ed0SChao Yu FAULT_READ_IO, 530f348028SChao Yu FAULT_CHECKPOINT, 54b83dcfe6SChao Yu FAULT_DISCARD, 556f5c2ed0SChao Yu FAULT_WRITE_IO, 562c63feadSJaegeuk Kim FAULT_MAX, 572c63feadSJaegeuk Kim }; 582c63feadSJaegeuk Kim 597fa750a1SArnd Bergmann #ifdef CONFIG_F2FS_FAULT_INJECTION 60d494500aSChao Yu #define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1) 61d494500aSChao Yu 6208796897SSheng Yong struct f2fs_fault_info { 6308796897SSheng Yong atomic_t inject_ops; 6408796897SSheng Yong unsigned int inject_rate; 6508796897SSheng Yong unsigned int inject_type; 6608796897SSheng Yong }; 6708796897SSheng Yong 6819880e6eSAlexey Dobriyan extern const char *f2fs_fault_name[FAULT_MAX]; 6968afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 702c63feadSJaegeuk Kim #endif 712c63feadSJaegeuk Kim 7239a53e0cSJaegeuk Kim /* 7339a53e0cSJaegeuk Kim * For mount options 7439a53e0cSJaegeuk Kim */ 7539a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 8039a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 81444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 821001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8334d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8434d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8534d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 86d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8789672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 88343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 8973faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 900abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA 0x00080000 910abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA 0x00100000 925c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA 0x00200000 934b2414d0SChao Yu #define F2FS_MOUNT_QUOTA 0x00400000 946afc662eSChao Yu #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 957e65be49SJaegeuk Kim #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 964354994fSDaniel Rosenberg #define F2FS_MOUNT_DISABLE_CHECKPOINT 0x02000000 97a9117ecaSChao Yu #define F2FS_MOUNT_NORECOVERY 0x04000000 98093749e2SChao Yu #define F2FS_MOUNT_ATGC 0x08000000 99261eeb9cSDaeho Jeong #define F2FS_MOUNT_MERGE_CHECKPOINT 0x10000000 1005911d2d1SChao Yu #define F2FS_MOUNT_GC_MERGE 0x20000000 10139a53e0cSJaegeuk Kim 10263189b78SChao Yu #define F2FS_OPTION(sbi) ((sbi)->mount_opt) 10363189b78SChao Yu #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) 10463189b78SChao Yu #define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option) 10563189b78SChao Yu #define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option) 10639a53e0cSJaegeuk Kim 10739a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 10839a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 10939a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 11039a53e0cSJaegeuk Kim 111a9841c4dSJaegeuk Kim typedef u32 block_t; /* 112a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 113a9841c4dSJaegeuk Kim * address format, __le32. 114a9841c4dSJaegeuk Kim */ 11539a53e0cSJaegeuk Kim typedef u32 nid_t; 11639a53e0cSJaegeuk Kim 1174c8ff709SChao Yu #define COMPRESS_EXT_NUM 16 1184c8ff709SChao Yu 11939a53e0cSJaegeuk Kim struct f2fs_mount_info { 12039a53e0cSJaegeuk Kim unsigned int opt; 12163189b78SChao Yu int write_io_size_bits; /* Write IO size bits */ 12263189b78SChao Yu block_t root_reserved_blocks; /* root reserved blocks */ 12363189b78SChao Yu kuid_t s_resuid; /* reserved blocks for uid */ 12463189b78SChao Yu kgid_t s_resgid; /* reserved blocks for gid */ 12563189b78SChao Yu int active_logs; /* # of active logs */ 12663189b78SChao Yu int inline_xattr_size; /* inline xattr size */ 12763189b78SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 12863189b78SChao Yu struct f2fs_fault_info fault_info; /* For fault injection */ 12963189b78SChao Yu #endif 13063189b78SChao Yu #ifdef CONFIG_QUOTA 13163189b78SChao Yu /* Names of quota files with journalled quota */ 13263189b78SChao Yu char *s_qf_names[MAXQUOTAS]; 13363189b78SChao Yu int s_jquota_fmt; /* Format of quota to use */ 13463189b78SChao Yu #endif 13563189b78SChao Yu /* For which write hints are passed down to block layer */ 13663189b78SChao Yu int whint_mode; 13763189b78SChao Yu int alloc_mode; /* segment allocation policy */ 13863189b78SChao Yu int fsync_mode; /* fsync policy */ 139b0332a0fSChao Yu int fs_mode; /* fs mode: LFS or ADAPTIVE */ 140bbbc34fdSChao Yu int bggc_mode; /* bggc mode: off, on or sync */ 141ac4acb1fSEric Biggers struct fscrypt_dummy_policy dummy_enc_policy; /* test dummy encryption */ 1421ae18f71SJaegeuk Kim block_t unusable_cap_perc; /* percentage for cap */ 1434d3aed70SDaniel Rosenberg block_t unusable_cap; /* Amount of space allowed to be 1444d3aed70SDaniel Rosenberg * unusable when disabling checkpoint 1454d3aed70SDaniel Rosenberg */ 1464c8ff709SChao Yu 1474c8ff709SChao Yu /* For compression */ 1484c8ff709SChao Yu unsigned char compress_algorithm; /* algorithm type */ 149b28f047bSChao Yu unsigned char compress_log_size; /* cluster log size */ 1503fde13f8SChao Yu unsigned char compress_level; /* compress level */ 151b28f047bSChao Yu bool compress_chksum; /* compressed data chksum */ 1524c8ff709SChao Yu unsigned char compress_ext_cnt; /* extension count */ 153602a16d5SDaeho Jeong int compress_mode; /* compression mode */ 1544c8ff709SChao Yu unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ 15539a53e0cSJaegeuk Kim }; 15639a53e0cSJaegeuk Kim 157cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1580bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 159e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1607a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1615c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 162704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 1636afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 164234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO 0x0080 1651c1d35dfSChao Yu #define F2FS_FEATURE_INODE_CRTIME 0x0100 166b7c409deSSheng Yong #define F2FS_FEATURE_LOST_FOUND 0x0200 16795ae251fSEric Biggers #define F2FS_FEATURE_VERITY 0x0400 168d440c52dSJunling Zheng #define F2FS_FEATURE_SB_CHKSUM 0x0800 1695aba5430SDaniel Rosenberg #define F2FS_FEATURE_CASEFOLD 0x1000 1704c8ff709SChao Yu #define F2FS_FEATURE_COMPRESSION 0x2000 171cde4de12SJaegeuk Kim 1727beb01f7SChao Yu #define __F2FS_HAS_FEATURE(raw_super, mask) \ 1737beb01f7SChao Yu ((raw_super->feature & cpu_to_le32(mask)) != 0) 1747beb01f7SChao Yu #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask) 1757beb01f7SChao Yu #define F2FS_SET_FEATURE(sbi, mask) \ 1767beb01f7SChao Yu (sbi->raw_super->feature |= cpu_to_le32(mask)) 1777beb01f7SChao Yu #define F2FS_CLEAR_FEATURE(sbi, mask) \ 1787beb01f7SChao Yu (sbi->raw_super->feature &= ~cpu_to_le32(mask)) 17976f105a2SJaegeuk Kim 18039a53e0cSJaegeuk Kim /* 1817c2e5963SJaegeuk Kim * Default values for user and/or group using reserved blocks 1827c2e5963SJaegeuk Kim */ 1837c2e5963SJaegeuk Kim #define F2FS_DEF_RESUID 0 1847c2e5963SJaegeuk Kim #define F2FS_DEF_RESGID 0 1857c2e5963SJaegeuk Kim 1867c2e5963SJaegeuk Kim /* 18739a53e0cSJaegeuk Kim * For checkpoint manager 18839a53e0cSJaegeuk Kim */ 18939a53e0cSJaegeuk Kim enum { 19039a53e0cSJaegeuk Kim NAT_BITMAP, 19139a53e0cSJaegeuk Kim SIT_BITMAP 19239a53e0cSJaegeuk Kim }; 19339a53e0cSJaegeuk Kim 194c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 195c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 196c473f1a9SChao Yu #define CP_SYNC 0x00000004 197c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 198c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1991f43e2adSChao Yu #define CP_TRIMMED 0x00000020 2004354994fSDaniel Rosenberg #define CP_PAUSE 0x00000040 201b4b10061SJaegeuk Kim #define CP_RESIZE 0x00000080 20275ab4cb8SJaegeuk Kim 2034ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 204ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 205969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 206f9d1dcedSYunlei He #define DEF_MID_DISCARD_ISSUE_TIME 500 /* 500 ms, if device busy */ 207969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 2088bb4f253SJaegeuk Kim #define DEF_DISCARD_URGENT_UTIL 80 /* do more discard over 80% */ 20960b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 210dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 2114354994fSDaniel Rosenberg #define DEF_DISABLE_INTERVAL 5 /* 5 secs */ 212db610a64SJaegeuk Kim #define DEF_DISABLE_QUICK_INTERVAL 1 /* 1 secs */ 21303f2c02dSJaegeuk Kim #define DEF_UMOUNT_DISCARD_TIMEOUT 5 /* 5 secs */ 214bba681cbSJaegeuk Kim 21575ab4cb8SJaegeuk Kim struct cp_control { 21675ab4cb8SJaegeuk Kim int reason; 2174b2fecc8SJaegeuk Kim __u64 trim_start; 2184b2fecc8SJaegeuk Kim __u64 trim_end; 2194b2fecc8SJaegeuk Kim __u64 trim_minlen; 22075ab4cb8SJaegeuk Kim }; 22175ab4cb8SJaegeuk Kim 222662befdaSChao Yu /* 223e1da7872SChao Yu * indicate meta/data type 224662befdaSChao Yu */ 225662befdaSChao Yu enum { 226662befdaSChao Yu META_CP, 227662befdaSChao Yu META_NAT, 22881c1a0f1SChao Yu META_SIT, 2294c521f49SJaegeuk Kim META_SSA, 230b63e7be5SChao Yu META_MAX, 2314c521f49SJaegeuk Kim META_POR, 23293770ab7SChao Yu DATA_GENERIC, /* check range only */ 23393770ab7SChao Yu DATA_GENERIC_ENHANCE, /* strong check on range and segment bitmap */ 23493770ab7SChao Yu DATA_GENERIC_ENHANCE_READ, /* 23593770ab7SChao Yu * strong check on range and segment 23693770ab7SChao Yu * bitmap but no warning due to race 23793770ab7SChao Yu * condition of read on truncated area 23893770ab7SChao Yu * by extent_cache 23993770ab7SChao Yu */ 240e1da7872SChao Yu META_GENERIC, 241662befdaSChao Yu }; 242662befdaSChao Yu 2436451e041SJaegeuk Kim /* for the list of ino */ 2446451e041SJaegeuk Kim enum { 2456451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 246fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 247fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 2480a007b97SJaegeuk Kim TRANS_DIR_INO, /* for trasactions dir ino list */ 24939d787beSChao Yu FLUSH_INO, /* for multiple device flushing */ 2506451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 2516451e041SJaegeuk Kim }; 2526451e041SJaegeuk Kim 2536451e041SJaegeuk Kim struct ino_entry { 25439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 25539a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 25639d787beSChao Yu unsigned int dirty_device; /* dirty device bitmap */ 25739a53e0cSJaegeuk Kim }; 25839a53e0cSJaegeuk Kim 2592710fd7eSChao Yu /* for the list of inodes to be GCed */ 26006292073SChao Yu struct inode_entry { 26139a53e0cSJaegeuk Kim struct list_head list; /* list head */ 26239a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 26339a53e0cSJaegeuk Kim }; 26439a53e0cSJaegeuk Kim 26550fa53ecSChao Yu struct fsync_node_entry { 26650fa53ecSChao Yu struct list_head list; /* list head */ 26750fa53ecSChao Yu struct page *page; /* warm node page pointer */ 26850fa53ecSChao Yu unsigned int seq_id; /* sequence id */ 26950fa53ecSChao Yu }; 27050fa53ecSChao Yu 271261eeb9cSDaeho Jeong struct ckpt_req { 272261eeb9cSDaeho Jeong struct completion wait; /* completion for checkpoint done */ 273261eeb9cSDaeho Jeong struct llist_node llnode; /* llist_node to be linked in wait queue */ 274261eeb9cSDaeho Jeong int ret; /* return code of checkpoint */ 275261eeb9cSDaeho Jeong ktime_t queue_time; /* request queued time */ 276261eeb9cSDaeho Jeong }; 277261eeb9cSDaeho Jeong 278261eeb9cSDaeho Jeong struct ckpt_req_control { 279261eeb9cSDaeho Jeong struct task_struct *f2fs_issue_ckpt; /* checkpoint task */ 280e6592066SDaeho Jeong int ckpt_thread_ioprio; /* checkpoint merge thread ioprio */ 281261eeb9cSDaeho Jeong wait_queue_head_t ckpt_wait_queue; /* waiting queue for wake-up */ 282261eeb9cSDaeho Jeong atomic_t issued_ckpt; /* # of actually issued ckpts */ 283261eeb9cSDaeho Jeong atomic_t total_ckpt; /* # of total ckpts */ 284261eeb9cSDaeho Jeong atomic_t queued_ckpt; /* # of queued ckpts */ 285261eeb9cSDaeho Jeong struct llist_head issue_list; /* list for command issue */ 286261eeb9cSDaeho Jeong spinlock_t stat_lock; /* lock for below checkpoint time stats */ 287261eeb9cSDaeho Jeong unsigned int cur_time; /* cur wait time in msec for currently issued checkpoint */ 288261eeb9cSDaeho Jeong unsigned int peak_time; /* peak wait time in msec until now */ 289261eeb9cSDaeho Jeong }; 290261eeb9cSDaeho Jeong 291a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 2927fd9e544SJaegeuk Kim struct discard_entry { 2937fd9e544SJaegeuk Kim struct list_head list; /* list head */ 294a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 295a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 2967fd9e544SJaegeuk Kim }; 2977fd9e544SJaegeuk Kim 298969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 299969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 300969d1b18SChao Yu 301ba48a33eSChao Yu /* max discard pend list number */ 302ba48a33eSChao Yu #define MAX_PLIST_NUM 512 303ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 3042f84babfSSheng Yong (MAX_PLIST_NUM - 1) : ((blk_num) - 1)) 305ba48a33eSChao Yu 30615469963SJaegeuk Kim enum { 30735ec7d57SChao Yu D_PREP, /* initial */ 30835ec7d57SChao Yu D_PARTIAL, /* partially submitted */ 30935ec7d57SChao Yu D_SUBMIT, /* all submitted */ 31035ec7d57SChao Yu D_DONE, /* finished */ 31115469963SJaegeuk Kim }; 31215469963SJaegeuk Kim 313004b6862SChao Yu struct discard_info { 314b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 315b01a9201SJaegeuk Kim block_t len; /* length */ 316004b6862SChao Yu block_t start; /* actual start address in dev */ 317004b6862SChao Yu }; 318004b6862SChao Yu 319b01a9201SJaegeuk Kim struct discard_cmd { 320004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 321004b6862SChao Yu union { 322004b6862SChao Yu struct { 323004b6862SChao Yu block_t lstart; /* logical start address */ 324004b6862SChao Yu block_t len; /* length */ 325004b6862SChao Yu block_t start; /* actual start address in dev */ 326004b6862SChao Yu }; 327004b6862SChao Yu struct discard_info di; /* discard info */ 328004b6862SChao Yu 329004b6862SChao Yu }; 330b01a9201SJaegeuk Kim struct list_head list; /* command list */ 331b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 332c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 333ec9895adSChao Yu unsigned short ref; /* reference count */ 3349a744b92SChao Yu unsigned char state; /* state */ 33572691af6SJaegeuk Kim unsigned char queued; /* queued discard */ 336c81abe34SJaegeuk Kim int error; /* bio error */ 33735ec7d57SChao Yu spinlock_t lock; /* for state/bio_ref updating */ 33835ec7d57SChao Yu unsigned short bio_ref; /* bio reference count */ 339275b66b0SChao Yu }; 340275b66b0SChao Yu 34178997b56SChao Yu enum { 34278997b56SChao Yu DPOLICY_BG, 34378997b56SChao Yu DPOLICY_FORCE, 34478997b56SChao Yu DPOLICY_FSTRIM, 34578997b56SChao Yu DPOLICY_UMOUNT, 34678997b56SChao Yu MAX_DPOLICY, 34778997b56SChao Yu }; 34878997b56SChao Yu 349ecc9aa00SChao Yu struct discard_policy { 35078997b56SChao Yu int type; /* type of discard */ 351ecc9aa00SChao Yu unsigned int min_interval; /* used for candidates exist */ 352f9d1dcedSYunlei He unsigned int mid_interval; /* used for device busy */ 353ecc9aa00SChao Yu unsigned int max_interval; /* used for candidates not exist */ 354ecc9aa00SChao Yu unsigned int max_requests; /* # of discards issued per round */ 355ecc9aa00SChao Yu unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ 356ecc9aa00SChao Yu bool io_aware; /* issue discard in idle time */ 357ecc9aa00SChao Yu bool sync; /* submit discard with REQ_SYNC flag */ 35820ee4382SChao Yu bool ordered; /* issue discard by lba order */ 3596ce48b0cSChao Yu bool timeout; /* discard timeout for put_super */ 36078997b56SChao Yu unsigned int granularity; /* discard granularity */ 361ecc9aa00SChao Yu }; 362ecc9aa00SChao Yu 3630b54fb84SJaegeuk Kim struct discard_cmd_control { 36415469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 36546f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 366ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 36746f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 3688412663dSChao Yu struct list_head fstrim_list; /* in-flight discard from fstrim */ 36915469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 370969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 37115469963SJaegeuk Kim struct mutex cmd_lock; 372d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 373d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 374969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 375d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 37620ee4382SChao Yu unsigned int next_pos; /* next discard position */ 3778b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 37872691af6SJaegeuk Kim atomic_t queued_discard; /* # of queued discard */ 3795f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 3804dada3fdSChao Yu struct rb_root_cached root; /* root of discard rb-tree */ 38167fce70bSChao Yu bool rbtree_check; /* config for consistence check */ 38239a53e0cSJaegeuk Kim }; 38339a53e0cSJaegeuk Kim 38439a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 38539a53e0cSJaegeuk Kim struct fsync_inode_entry { 38639a53e0cSJaegeuk Kim struct list_head list; /* list head */ 38739a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 388c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 389c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 39039a53e0cSJaegeuk Kim }; 39139a53e0cSJaegeuk Kim 39268afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 39368afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 39439a53e0cSJaegeuk Kim 39568afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 39668afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 39768afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 39868afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 39939a53e0cSJaegeuk Kim 400dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 401dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 402309cc2b6SJaegeuk Kim 403dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 40439a53e0cSJaegeuk Kim { 405dfc08a12SChao Yu int before = nats_in_cursum(journal); 406cac5a3d8SDongOh Shin 407dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 40839a53e0cSJaegeuk Kim return before; 40939a53e0cSJaegeuk Kim } 41039a53e0cSJaegeuk Kim 411dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 41239a53e0cSJaegeuk Kim { 413dfc08a12SChao Yu int before = sits_in_cursum(journal); 414cac5a3d8SDongOh Shin 415dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 41639a53e0cSJaegeuk Kim return before; 41739a53e0cSJaegeuk Kim } 41839a53e0cSJaegeuk Kim 419dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 420dfc08a12SChao Yu int size, int type) 421184a5cd2SChao Yu { 422184a5cd2SChao Yu if (type == NAT_JOURNAL) 423dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 424dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 425184a5cd2SChao Yu } 426184a5cd2SChao Yu 427f2470371SChao Yu /* for inline stuff */ 428f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 4297a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 4306afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode); 4317a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 4327a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 433b323fd28SChao Yu get_inline_xattr_addrs(inode) - \ 4346afc662eSChao Yu DEF_INLINE_RESERVED_SIZE)) 435f2470371SChao Yu 436f2470371SChao Yu /* for inline dir */ 437f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 438f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 439f2470371SChao Yu BITS_PER_BYTE + 1)) 440f91108b8SGeert Uytterhoeven #define INLINE_DENTRY_BITMAP_SIZE(inode) \ 441f91108b8SGeert Uytterhoeven DIV_ROUND_UP(NR_INLINE_DENTRY(inode), BITS_PER_BYTE) 442f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 443f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 444f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 445f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 446f2470371SChao Yu 447e9750824SNamjae Jeon /* 44839a53e0cSJaegeuk Kim * For INODE and NODE manager 44939a53e0cSJaegeuk Kim */ 4507b3cd7d6SJaegeuk Kim /* for directory operations */ 45143c780baSEric Biggers 45243c780baSEric Biggers struct f2fs_filename { 45343c780baSEric Biggers /* 45443c780baSEric Biggers * The filename the user specified. This is NULL for some 45543c780baSEric Biggers * filesystem-internal operations, e.g. converting an inline directory 45643c780baSEric Biggers * to a non-inline one, or roll-forward recovering an encrypted dentry. 45743c780baSEric Biggers */ 45843c780baSEric Biggers const struct qstr *usr_fname; 45943c780baSEric Biggers 46043c780baSEric Biggers /* 46143c780baSEric Biggers * The on-disk filename. For encrypted directories, this is encrypted. 46243c780baSEric Biggers * This may be NULL for lookups in an encrypted dir without the key. 46343c780baSEric Biggers */ 46443c780baSEric Biggers struct fscrypt_str disk_name; 46543c780baSEric Biggers 46643c780baSEric Biggers /* The dirhash of this filename */ 46743c780baSEric Biggers f2fs_hash_t hash; 46843c780baSEric Biggers 46943c780baSEric Biggers #ifdef CONFIG_FS_ENCRYPTION 47043c780baSEric Biggers /* 47143c780baSEric Biggers * For lookups in encrypted directories: either the buffer backing 47243c780baSEric Biggers * disk_name, or a buffer that holds the decoded no-key name. 47343c780baSEric Biggers */ 47443c780baSEric Biggers struct fscrypt_str crypto_buf; 47543c780baSEric Biggers #endif 47643c780baSEric Biggers #ifdef CONFIG_UNICODE 47743c780baSEric Biggers /* 47843c780baSEric Biggers * For casefolded directories: the casefolded name, but it's left NULL 4797ad08a58SDaniel Rosenberg * if the original name is not valid Unicode, if the directory is both 4807ad08a58SDaniel Rosenberg * casefolded and encrypted and its encryption key is unavailable, or if 4817ad08a58SDaniel Rosenberg * the filesystem is doing an internal operation where usr_fname is also 4827ad08a58SDaniel Rosenberg * NULL. In all these cases we fall back to treating the name as an 4837ad08a58SDaniel Rosenberg * opaque byte sequence. 48443c780baSEric Biggers */ 48543c780baSEric Biggers struct fscrypt_str cf_name; 48643c780baSEric Biggers #endif 48743c780baSEric Biggers }; 48843c780baSEric Biggers 4897b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 490d8c6822aSJaegeuk Kim struct inode *inode; 49176a9dd85SChao Yu void *bitmap; 4927b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 4937b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 4947b3cd7d6SJaegeuk Kim int max; 49576a9dd85SChao Yu int nr_bitmap; 4967b3cd7d6SJaegeuk Kim }; 4977b3cd7d6SJaegeuk Kim 49864c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 49964c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 5007b3cd7d6SJaegeuk Kim { 501d8c6822aSJaegeuk Kim d->inode = inode; 5027b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 50376a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 504c79d1520SYunlong Song d->bitmap = t->dentry_bitmap; 5057b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 5067b3cd7d6SJaegeuk Kim d->filename = t->filename; 50764c24ecbSTomohiro Kusumi } 508cac5a3d8SDongOh Shin 50964c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 510f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 51164c24ecbSTomohiro Kusumi { 512f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 513f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 514f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 515f2470371SChao Yu 51664c24ecbSTomohiro Kusumi d->inode = inode; 517f2470371SChao Yu d->max = entry_cnt; 518f2470371SChao Yu d->nr_bitmap = bitmap_size; 519f2470371SChao Yu d->bitmap = t; 520f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 521f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 522f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 5237b3cd7d6SJaegeuk Kim } 5247b3cd7d6SJaegeuk Kim 525dbe6a5ffSJaegeuk Kim /* 526dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 527dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 528dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 52939a53e0cSJaegeuk Kim */ 530dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 531dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 532266e97a8SJaegeuk Kim enum { 533266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 534266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 535266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 536266e97a8SJaegeuk Kim * look up a node with readahead called 5374f4124d0SChao Yu * by get_data_block. 53839a53e0cSJaegeuk Kim */ 539266e97a8SJaegeuk Kim }; 540266e97a8SJaegeuk Kim 5417735730dSChao Yu #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO count */ 5427735730dSChao Yu 5435df7731fSChao Yu /* congestion wait timeout value, default: 20ms */ 5445df7731fSChao Yu #define DEFAULT_IO_TIMEOUT (msecs_to_jiffies(20)) 5455df7731fSChao Yu 546af033b2aSChao Yu /* maximum retry quota flush count */ 547af033b2aSChao Yu #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT 8 548af033b2aSChao Yu 549a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 55039a53e0cSJaegeuk Kim 551817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 552817202d9SChao Yu 55339a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 55413054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 55513054c54SChao Yu 55613054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 55713054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 558c11abd1aSJaegeuk Kim 55954c2258cSChao Yu struct rb_entry { 56054c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 5612e9b2bb2SChao Yu union { 5622e9b2bb2SChao Yu struct { 56354c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 56454c2258cSChao Yu unsigned int len; /* length of the entry */ 56554c2258cSChao Yu }; 5662e9b2bb2SChao Yu unsigned long long key; /* 64-bits key */ 56748046cb5SJaegeuk Kim } __packed; 5682e9b2bb2SChao Yu }; 56954c2258cSChao Yu 57039a53e0cSJaegeuk Kim struct extent_info { 57139a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 572111d2495SMasanari Iida unsigned int len; /* length of the extent */ 57354c2258cSChao Yu u32 blk; /* start block address of the extent */ 57439a53e0cSJaegeuk Kim }; 57539a53e0cSJaegeuk Kim 57613054c54SChao Yu struct extent_node { 577c0362117SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 57813054c54SChao Yu struct extent_info ei; /* extent info */ 57954c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 580201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 58113054c54SChao Yu }; 58213054c54SChao Yu 58313054c54SChao Yu struct extent_tree { 58413054c54SChao Yu nid_t ino; /* inode number */ 5854dada3fdSChao Yu struct rb_root_cached root; /* root of extent info rb-tree */ 58662c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 5873e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 588137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 58913054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 59068e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 591b430f726SZhikang Zhang bool largest_updated; /* largest extent updated */ 59213054c54SChao Yu }; 59313054c54SChao Yu 59439a53e0cSJaegeuk Kim /* 595003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 596003a3e1dSJaegeuk Kim * 597003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 598003a3e1dSJaegeuk Kim */ 599003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 600003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 6017f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 6027f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 6037f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 604003a3e1dSJaegeuk Kim 605003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 606003a3e1dSJaegeuk Kim block_t m_pblk; 607003a3e1dSJaegeuk Kim block_t m_lblk; 608003a3e1dSJaegeuk Kim unsigned int m_len; 609003a3e1dSJaegeuk Kim unsigned int m_flags; 610da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 611c4020b2dSChao Yu pgoff_t *m_next_extent; /* point to next possible extent */ 612d5097be5SHyunchul Lee int m_seg_type; 613f9d6d059SChao Yu bool m_may_create; /* indicate it is from write path */ 614003a3e1dSJaegeuk Kim }; 615003a3e1dSJaegeuk Kim 616e2b4e2bcSChao Yu /* for flag in get_data_block */ 617f2220c7fSQiuyang Sun enum { 618f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 619f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 620f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 6210a4daae5SJaegeuk Kim F2FS_GET_BLOCK_DIO, 622f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 623f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 624c4020b2dSChao Yu F2FS_GET_BLOCK_PRECACHE, 625f2220c7fSQiuyang Sun }; 626e2b4e2bcSChao Yu 627003a3e1dSJaegeuk Kim /* 62839a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 62939a53e0cSJaegeuk Kim */ 63039a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 631354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 632cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 633e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 63426787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 635b6a06cbbSChao Yu #define FADVISE_HOT_BIT 0x20 63695ae251fSEric Biggers #define FADVISE_VERITY_BIT 0x40 63739a53e0cSJaegeuk Kim 638797c1cb5SChao Yu #define FADVISE_MODIFIABLE_BITS (FADVISE_COLD_BIT | FADVISE_HOT_BIT) 639797c1cb5SChao Yu 640b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 641b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 642b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 6431153db09SChao Yu 6441153db09SChao Yu #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 6451153db09SChao Yu #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 646b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 6471153db09SChao Yu 648cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 649cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 6501153db09SChao Yu 651e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 652e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 6531153db09SChao Yu 65426787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 65526787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 6561153db09SChao Yu 657b6a06cbbSChao Yu #define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT) 658b6a06cbbSChao Yu #define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT) 659b6a06cbbSChao Yu #define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT) 6601153db09SChao Yu 66195ae251fSEric Biggers #define file_is_verity(inode) is_file(inode, FADVISE_VERITY_BIT) 66295ae251fSEric Biggers #define file_set_verity(inode) set_file(inode, FADVISE_VERITY_BIT) 663cde4de12SJaegeuk Kim 664ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 665ab9fa662SJaegeuk Kim 6662ef79ecbSChao Yu enum { 6672ef79ecbSChao Yu GC_FAILURE_PIN, 6682ef79ecbSChao Yu GC_FAILURE_ATOMIC, 6692ef79ecbSChao Yu MAX_GC_FAILURE 6702ef79ecbSChao Yu }; 6712ef79ecbSChao Yu 6727653b9d8SChao Yu /* used for f2fs_inode_info->flags */ 6737653b9d8SChao Yu enum { 6747653b9d8SChao Yu FI_NEW_INODE, /* indicate newly allocated inode */ 6757653b9d8SChao Yu FI_DIRTY_INODE, /* indicate inode is dirty or not */ 6767653b9d8SChao Yu FI_AUTO_RECOVER, /* indicate inode is recoverable */ 6777653b9d8SChao Yu FI_DIRTY_DIR, /* indicate directory has dirty pages */ 6787653b9d8SChao Yu FI_INC_LINK, /* need to increment i_nlink */ 6797653b9d8SChao Yu FI_ACL_MODE, /* indicate acl mode */ 6807653b9d8SChao Yu FI_NO_ALLOC, /* should not allocate any blocks */ 6817653b9d8SChao Yu FI_FREE_NID, /* free allocated nide */ 6827653b9d8SChao Yu FI_NO_EXTENT, /* not to use the extent cache */ 6837653b9d8SChao Yu FI_INLINE_XATTR, /* used for inline xattr */ 6847653b9d8SChao Yu FI_INLINE_DATA, /* used for inline data*/ 6857653b9d8SChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 6867653b9d8SChao Yu FI_APPEND_WRITE, /* inode has appended data */ 6877653b9d8SChao Yu FI_UPDATE_WRITE, /* inode has in-place-update data */ 6887653b9d8SChao Yu FI_NEED_IPU, /* used for ipu per file */ 6897653b9d8SChao Yu FI_ATOMIC_FILE, /* indicate atomic file */ 6907653b9d8SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 6917653b9d8SChao Yu FI_VOLATILE_FILE, /* indicate volatile file */ 6927653b9d8SChao Yu FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 6937653b9d8SChao Yu FI_DROP_CACHE, /* drop dirty page cache */ 6947653b9d8SChao Yu FI_DATA_EXIST, /* indicate data exists */ 6957653b9d8SChao Yu FI_INLINE_DOTS, /* indicate inline dot dentries */ 6967653b9d8SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 6977653b9d8SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 6987653b9d8SChao Yu FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 6997653b9d8SChao Yu FI_HOT_DATA, /* indicate file is hot */ 7007653b9d8SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 7017653b9d8SChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 7027653b9d8SChao Yu FI_PIN_FILE, /* indicate file should not be gced */ 7037653b9d8SChao Yu FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */ 7047653b9d8SChao Yu FI_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ 7057653b9d8SChao Yu FI_COMPRESSED_FILE, /* indicate file's data can be compressed */ 706b28f047bSChao Yu FI_COMPRESS_CORRUPT, /* indicate compressed cluster is corrupted */ 7077653b9d8SChao Yu FI_MMAP_FILE, /* indicate file was mmapped */ 708602a16d5SDaeho Jeong FI_ENABLE_COMPRESS, /* enable compression in "user" compression mode */ 7097653b9d8SChao Yu FI_MAX, /* max flag, never be used */ 7107653b9d8SChao Yu }; 7117653b9d8SChao Yu 71239a53e0cSJaegeuk Kim struct f2fs_inode_info { 71339a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 71439a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 71539a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 71638431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 7171ad71a27SJaegeuk Kim unsigned int i_current_depth; /* only for directory depth */ 7182ef79ecbSChao Yu /* for gc failure statistic */ 7192ef79ecbSChao Yu unsigned int i_gc_failures[MAX_GC_FAILURE]; 7206666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 72139a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 72239a53e0cSJaegeuk Kim 72339a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 7247653b9d8SChao Yu unsigned long flags[BITS_TO_LONGS(FI_MAX)]; /* use to pass per-file flags */ 725d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 726204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 72739a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 72839a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 72988c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 730b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 73139a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 73226de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 733c10c9820SChao Yu spinlock_t i_size_lock; /* protect last_disk_size */ 73488b88a66SJaegeuk Kim 7350abd675eSChao Yu #ifdef CONFIG_QUOTA 7360abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 7370abd675eSChao Yu 7380abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 7390abd675eSChao Yu qsize_t i_reserved_quota; 7400abd675eSChao Yu #endif 7410f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 7420f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 74357864ae5SJaegeuk Kim struct list_head inmem_ilist; /* list for inmem inodes */ 74488b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 7457a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 74688b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 7473e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 748b2532c69SChao Yu 749b2532c69SChao Yu /* avoid racing between foreground op and gc */ 750b2532c69SChao Yu struct rw_semaphore i_gc_rwsem[2]; 7515a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 75227161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 753f2470371SChao Yu 7547a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 7555c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 7566afc662eSChao Yu int i_inline_xattr_size; /* inline xattr size */ 75724b81dfcSArnd Bergmann struct timespec64 i_crtime; /* inode creation time */ 75824b81dfcSArnd Bergmann struct timespec64 i_disk_time[4];/* inode disk times */ 7594c8ff709SChao Yu 7604c8ff709SChao Yu /* for file compress */ 761c2759ebaSDaeho Jeong atomic_t i_compr_blocks; /* # of compressed blocks */ 7624c8ff709SChao Yu unsigned char i_compress_algorithm; /* algorithm type */ 7634c8ff709SChao Yu unsigned char i_log_cluster_size; /* log of cluster size */ 7643fde13f8SChao Yu unsigned char i_compress_level; /* compress level (lz4hc,zstd) */ 765b28f047bSChao Yu unsigned short i_compress_flag; /* compress flag */ 7664c8ff709SChao Yu unsigned int i_cluster_size; /* cluster size */ 76739a53e0cSJaegeuk Kim }; 76839a53e0cSJaegeuk Kim 76939a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 770bd933d4fSChao Yu struct f2fs_extent *i_ext) 77139a53e0cSJaegeuk Kim { 772bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 773bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 774bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 77539a53e0cSJaegeuk Kim } 77639a53e0cSJaegeuk Kim 77739a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 77839a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 77939a53e0cSJaegeuk Kim { 78039a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 7814d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 78239a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 78339a53e0cSJaegeuk Kim } 78439a53e0cSJaegeuk Kim 785429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 786429511cdSChao Yu u32 blk, unsigned int len) 787429511cdSChao Yu { 788429511cdSChao Yu ei->fofs = fofs; 789429511cdSChao Yu ei->blk = blk; 790429511cdSChao Yu ei->len = len; 791429511cdSChao Yu } 792429511cdSChao Yu 793004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 79435ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 795004b6862SChao Yu { 7969a997188SJaegeuk Kim return (back->lstart + back->len == front->lstart) && 79735ec7d57SChao Yu (back->len + front->len <= max_len); 798004b6862SChao Yu } 799004b6862SChao Yu 800004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 80135ec7d57SChao Yu struct discard_info *back, unsigned int max_len) 802004b6862SChao Yu { 80335ec7d57SChao Yu return __is_discard_mergeable(back, cur, max_len); 804004b6862SChao Yu } 805004b6862SChao Yu 806004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 80735ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 808004b6862SChao Yu { 80935ec7d57SChao Yu return __is_discard_mergeable(cur, front, max_len); 810004b6862SChao Yu } 811004b6862SChao Yu 812429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 813429511cdSChao Yu struct extent_info *front) 814429511cdSChao Yu { 815429511cdSChao Yu return (back->fofs + back->len == front->fofs && 816429511cdSChao Yu back->blk + back->len == front->blk); 817429511cdSChao Yu } 818429511cdSChao Yu 819429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 820429511cdSChao Yu struct extent_info *back) 821429511cdSChao Yu { 822429511cdSChao Yu return __is_extent_mergeable(back, cur); 823429511cdSChao Yu } 824429511cdSChao Yu 825429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 826429511cdSChao Yu struct extent_info *front) 827429511cdSChao Yu { 828429511cdSChao Yu return __is_extent_mergeable(cur, front); 829429511cdSChao Yu } 830429511cdSChao Yu 831cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 832b430f726SZhikang Zhang static inline void __try_update_largest_extent(struct extent_tree *et, 833b430f726SZhikang Zhang struct extent_node *en) 8344abd3f5aSChao Yu { 835205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 8364abd3f5aSChao Yu et->largest = en->ei; 837b430f726SZhikang Zhang et->largest_updated = true; 838205b9822SJaegeuk Kim } 8394abd3f5aSChao Yu } 8404abd3f5aSChao Yu 8419a4ffdf5SChao Yu /* 8429a4ffdf5SChao Yu * For free nid management 8439a4ffdf5SChao Yu */ 8449a4ffdf5SChao Yu enum nid_state { 8459a4ffdf5SChao Yu FREE_NID, /* newly added to free nid list */ 8469a4ffdf5SChao Yu PREALLOC_NID, /* it is preallocated */ 8479a4ffdf5SChao Yu MAX_NID_STATE, 848b8559dc2SChao Yu }; 849b8559dc2SChao Yu 850a95ba66aSJaegeuk Kim enum nat_state { 851a95ba66aSJaegeuk Kim TOTAL_NAT, 852a95ba66aSJaegeuk Kim DIRTY_NAT, 853a95ba66aSJaegeuk Kim RECLAIMABLE_NAT, 854a95ba66aSJaegeuk Kim MAX_NAT_STATE, 855a95ba66aSJaegeuk Kim }; 856a95ba66aSJaegeuk Kim 85739a53e0cSJaegeuk Kim struct f2fs_nm_info { 85839a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 85939a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 86004d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 86139a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 862cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 863ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 8642304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 86539a53e0cSJaegeuk Kim 86639a53e0cSJaegeuk Kim /* NAT cache management */ 86739a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 868309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 869f3e367d4Sqiulaibin struct rw_semaphore nat_tree_lock; /* protect nat entry tree */ 87039a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 87122969158SChao Yu spinlock_t nat_list_lock; /* protect clean nat entry list */ 872a95ba66aSJaegeuk Kim unsigned int nat_cnt[MAX_NAT_STATE]; /* the # of cached nat entries */ 87322ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 87439a53e0cSJaegeuk Kim 87539a53e0cSJaegeuk Kim /* free node ids management */ 8768a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 8779a4ffdf5SChao Yu struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ 8789a4ffdf5SChao Yu unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 879b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 88039a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 881bb1105e4SJaegeuk Kim unsigned char **free_nid_bitmap; 8824ac91242SChao Yu unsigned char *nat_block_bitmap; 883586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 88439a53e0cSJaegeuk Kim 88539a53e0cSJaegeuk Kim /* for checkpoint */ 88639a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 88722ad0b6aSJaegeuk Kim 88822ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 88922ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 89022ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 89122ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 892599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 893599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 894599a09b2SChao Yu #endif 89539a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 89639a53e0cSJaegeuk Kim }; 89739a53e0cSJaegeuk Kim 89839a53e0cSJaegeuk Kim /* 89939a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 90039a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 90139a53e0cSJaegeuk Kim * by the data offset in a file. 90239a53e0cSJaegeuk Kim */ 90339a53e0cSJaegeuk Kim struct dnode_of_data { 90439a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 90539a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 90639a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 90739a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 90839a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 90939a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 91093bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 9113cf45747SChao Yu char cur_level; /* level of hole node page */ 9123cf45747SChao Yu char max_level; /* level of current page located */ 91339a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 91439a53e0cSJaegeuk Kim }; 91539a53e0cSJaegeuk Kim 91639a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 91739a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 91839a53e0cSJaegeuk Kim { 919d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 92039a53e0cSJaegeuk Kim dn->inode = inode; 92139a53e0cSJaegeuk Kim dn->inode_page = ipage; 92239a53e0cSJaegeuk Kim dn->node_page = npage; 92339a53e0cSJaegeuk Kim dn->nid = nid; 92439a53e0cSJaegeuk Kim } 92539a53e0cSJaegeuk Kim 92639a53e0cSJaegeuk Kim /* 92739a53e0cSJaegeuk Kim * For SIT manager 92839a53e0cSJaegeuk Kim * 92939a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 93039a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 93139a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 93239a53e0cSJaegeuk Kim * respectively. 93339a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 93439a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 93539a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 93639a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 93739a53e0cSJaegeuk Kim * data and 8 for node logs. 93839a53e0cSJaegeuk Kim */ 93939a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 94039a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 941093749e2SChao Yu #define NR_CURSEG_INMEM_TYPE (2) 942d0b9e42aSChao Yu #define NR_CURSEG_PERSIST_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 943d0b9e42aSChao Yu #define NR_CURSEG_TYPE (NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE) 94439a53e0cSJaegeuk Kim 94539a53e0cSJaegeuk Kim enum { 94639a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 94739a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 94839a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 94939a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 95039a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 95139a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 952d0b9e42aSChao Yu NR_PERSISTENT_LOG, /* number of persistent log */ 953d0b9e42aSChao Yu CURSEG_COLD_DATA_PINNED = NR_PERSISTENT_LOG, 954d0b9e42aSChao Yu /* pinned file that needs consecutive block address */ 955093749e2SChao Yu CURSEG_ALL_DATA_ATGC, /* SSR alloctor in hot/warm/cold data area */ 956d0b9e42aSChao Yu NO_CHECK_TYPE, /* number of persistent & inmem log */ 95739a53e0cSJaegeuk Kim }; 95839a53e0cSJaegeuk Kim 9596b4afdd7SJaegeuk Kim struct flush_cmd { 9606b4afdd7SJaegeuk Kim struct completion wait; 961721bd4d5SGu Zheng struct llist_node llnode; 96239d787beSChao Yu nid_t ino; 9636b4afdd7SJaegeuk Kim int ret; 9646b4afdd7SJaegeuk Kim }; 9656b4afdd7SJaegeuk Kim 966a688b9d9SGu Zheng struct flush_cmd_control { 967a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 968a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 9698b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 97072691af6SJaegeuk Kim atomic_t queued_flush; /* # of queued flushes */ 971721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 972721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 973a688b9d9SGu Zheng }; 974a688b9d9SGu Zheng 97539a53e0cSJaegeuk Kim struct f2fs_sm_info { 97639a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 97739a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 97839a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 97939a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 98039a53e0cSJaegeuk Kim 9812b60311dSChao Yu struct rw_semaphore curseg_lock; /* for preventing curseg change */ 9822b60311dSChao Yu 98339a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 98439a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 98539a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 98639a53e0cSJaegeuk Kim 98739a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 98839a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 98939a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 99039a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 99181eb8d6eSJaegeuk Kim 99281eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 99381eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 9947fd9e544SJaegeuk Kim 995bba681cbSJaegeuk Kim /* for batched trimming */ 996bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 997bba681cbSJaegeuk Kim 998184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 999184a5cd2SChao Yu 1000216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 1001216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 1002c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 1003853137ceSJaegeuk Kim unsigned int min_seq_blocks; /* threshold for sequential blocks */ 1004ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 1005a2a12b67SChao Yu unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ 10066b4afdd7SJaegeuk Kim 10076b4afdd7SJaegeuk Kim /* for flush command control */ 1008b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 1009a688b9d9SGu Zheng 10100b54fb84SJaegeuk Kim /* for discard command control */ 10110b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 101239a53e0cSJaegeuk Kim }; 101339a53e0cSJaegeuk Kim 101439a53e0cSJaegeuk Kim /* 101539a53e0cSJaegeuk Kim * For superblock 101639a53e0cSJaegeuk Kim */ 101739a53e0cSJaegeuk Kim /* 101839a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 101939a53e0cSJaegeuk Kim * 102039a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 102139a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 102239a53e0cSJaegeuk Kim */ 102336951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 102439a53e0cSJaegeuk Kim enum count_type { 102539a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 1026c227f912SChao Yu F2FS_DIRTY_DATA, 10272c8a4a28SJaegeuk Kim F2FS_DIRTY_QDATA, 102839a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 102939a53e0cSJaegeuk Kim F2FS_DIRTY_META, 10308dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 10310f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 103236951b38SChao Yu F2FS_WB_CP_DATA, 103336951b38SChao Yu F2FS_WB_DATA, 10345f9abab4SJaegeuk Kim F2FS_RD_DATA, 10355f9abab4SJaegeuk Kim F2FS_RD_NODE, 10365f9abab4SJaegeuk Kim F2FS_RD_META, 103702b16d0aSChao Yu F2FS_DIO_WRITE, 103802b16d0aSChao Yu F2FS_DIO_READ, 103939a53e0cSJaegeuk Kim NR_COUNT_TYPE, 104039a53e0cSJaegeuk Kim }; 104139a53e0cSJaegeuk Kim 104239a53e0cSJaegeuk Kim /* 1043e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 104439a53e0cSJaegeuk Kim * The available types are: 104539a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 104639a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 104739a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 104839a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 104939a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 105039a53e0cSJaegeuk Kim * with waiting the bio's completion 105139a53e0cSJaegeuk Kim * ... Only can be used with META. 105239a53e0cSJaegeuk Kim */ 10537d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 105439a53e0cSJaegeuk Kim enum page_type { 105539a53e0cSJaegeuk Kim DATA, 105639a53e0cSJaegeuk Kim NODE, 105739a53e0cSJaegeuk Kim META, 105839a53e0cSJaegeuk Kim NR_PAGE_TYPE, 105939a53e0cSJaegeuk Kim META_FLUSH, 10608ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 10618ce67cb0SJaegeuk Kim INMEM_DROP, 10628c242db9SJaegeuk Kim INMEM_INVALIDATE, 106328bc106bSChao Yu INMEM_REVOKE, 10648ce67cb0SJaegeuk Kim IPU, 10658ce67cb0SJaegeuk Kim OPU, 106639a53e0cSJaegeuk Kim }; 106739a53e0cSJaegeuk Kim 1068a912b54dSJaegeuk Kim enum temp_type { 1069a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 1070a912b54dSJaegeuk Kim WARM, 1071a912b54dSJaegeuk Kim COLD, 1072a912b54dSJaegeuk Kim NR_TEMP_TYPE, 1073a912b54dSJaegeuk Kim }; 1074a912b54dSJaegeuk Kim 1075cc15620bSJaegeuk Kim enum need_lock_type { 1076cc15620bSJaegeuk Kim LOCK_REQ = 0, 1077cc15620bSJaegeuk Kim LOCK_DONE, 1078cc15620bSJaegeuk Kim LOCK_RETRY, 1079cc15620bSJaegeuk Kim }; 1080cc15620bSJaegeuk Kim 1081a5fd5050SChao Yu enum cp_reason_type { 1082a5fd5050SChao Yu CP_NO_NEEDED, 1083a5fd5050SChao Yu CP_NON_REGULAR, 10844c8ff709SChao Yu CP_COMPRESSED, 1085a5fd5050SChao Yu CP_HARDLINK, 1086a5fd5050SChao Yu CP_SB_NEED_CP, 1087a5fd5050SChao Yu CP_WRONG_PINO, 1088a5fd5050SChao Yu CP_NO_SPC_ROLL, 1089a5fd5050SChao Yu CP_NODE_NEED_CP, 1090a5fd5050SChao Yu CP_FASTBOOT_MODE, 1091a5fd5050SChao Yu CP_SPEC_LOG_NUM, 10920a007b97SJaegeuk Kim CP_RECOVER_DIR, 1093a5fd5050SChao Yu }; 1094a5fd5050SChao Yu 1095b0af6d49SChao Yu enum iostat_type { 10968b83ac81SChao Yu /* WRITE IO */ 10978b83ac81SChao Yu APP_DIRECT_IO, /* app direct write IOs */ 10988b83ac81SChao Yu APP_BUFFERED_IO, /* app buffered write IOs */ 1099b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 1100b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 1101b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 1102b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 1103b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 1104b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 1105b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 1106b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 1107b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 1108b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 11098b83ac81SChao Yu 11108b83ac81SChao Yu /* READ IO */ 11118b83ac81SChao Yu APP_DIRECT_READ_IO, /* app direct read IOs */ 11128b83ac81SChao Yu APP_BUFFERED_READ_IO, /* app buffered read IOs */ 11138b83ac81SChao Yu APP_READ_IO, /* app read IOs */ 11148b83ac81SChao Yu APP_MAPPED_READ_IO, /* app mapped read IOs */ 11158b83ac81SChao Yu FS_DATA_READ_IO, /* data read IOs */ 11169c122384SChao Yu FS_GDATA_READ_IO, /* data read IOs from background gc */ 11179c122384SChao Yu FS_CDATA_READ_IO, /* compressed data read IOs */ 11188b83ac81SChao Yu FS_NODE_READ_IO, /* node read IOs */ 11198b83ac81SChao Yu FS_META_READ_IO, /* meta read IOs */ 11208b83ac81SChao Yu 11218b83ac81SChao Yu /* other */ 1122b0af6d49SChao Yu FS_DISCARD, /* discard */ 1123b0af6d49SChao Yu NR_IO_TYPE, 1124b0af6d49SChao Yu }; 1125b0af6d49SChao Yu 1126458e6197SJaegeuk Kim struct f2fs_io_info { 112705ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 112839d787beSChao Yu nid_t ino; /* inode number */ 1129458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 1130a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 113104d328deSMike Christie int op; /* contains REQ_OP_ */ 1132ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 11337a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 113428bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 113505ca3632SJaegeuk Kim struct page *page; /* page to be written */ 11364375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 11374c8ff709SChao Yu struct page *compressed_page; /* compressed page */ 1138fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 1139d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 1140cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 1141fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 11426dc3a126SChao Yu bool is_por; /* indicate IO is from recovery or not */ 1143fe16efe6SChao Yu bool retry; /* need to reallocate block address */ 11444c8ff709SChao Yu int compr_blocks; /* # of compressed block addresses */ 11454c8ff709SChao Yu bool encrypted; /* indicate file is encrypted */ 1146b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 1147578c6478SYufen Yu struct writeback_control *io_wbc; /* writeback control */ 11488648de2cSChao Yu struct bio **bio; /* bio for ipu */ 11498648de2cSChao Yu sector_t *last_block; /* last block number in bio */ 11507735730dSChao Yu unsigned char version; /* version of the node */ 1151458e6197SJaegeuk Kim }; 1152458e6197SJaegeuk Kim 11530b20fcecSChao Yu struct bio_entry { 11540b20fcecSChao Yu struct bio *bio; 11550b20fcecSChao Yu struct list_head list; 11560b20fcecSChao Yu }; 11570b20fcecSChao Yu 115868afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 11591ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 1160458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 11611ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 11621ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 1163458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 1164df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 1165fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 1166fb830fc5SChao Yu struct list_head io_list; /* track fios */ 11670b20fcecSChao Yu struct list_head bio_list; /* bio entry list head */ 11680b20fcecSChao Yu struct rw_semaphore bio_list_lock; /* lock to protect bio entry list */ 11691ff7bd3bSJaegeuk Kim }; 11701ff7bd3bSJaegeuk Kim 11713c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 11723c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 11733c62be17SJaegeuk Kim struct f2fs_dev_info { 11743c62be17SJaegeuk Kim struct block_device *bdev; 11753c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 11763c62be17SJaegeuk Kim unsigned int total_segments; 11773c62be17SJaegeuk Kim block_t start_blk; 11783c62be17SJaegeuk Kim block_t end_blk; 11793c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 11803c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 118195175dafSDamien Le Moal unsigned long *blkz_seq; /* Bitmap indicating sequential zones */ 1182de881df9SAravind Ramesh block_t *zone_capacity_blocks; /* Array of zone capacity in blks */ 11833c62be17SJaegeuk Kim #endif 11843c62be17SJaegeuk Kim }; 11853c62be17SJaegeuk Kim 1186c227f912SChao Yu enum inode_type { 1187c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 1188c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 11890f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 119057864ae5SJaegeuk Kim ATOMIC_FILE, /* for all atomic files */ 1191c227f912SChao Yu NR_INODE_TYPE, 1192c227f912SChao Yu }; 1193c227f912SChao Yu 119467298804SChao Yu /* for inner inode cache management */ 119567298804SChao Yu struct inode_management { 119667298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 119767298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 119867298804SChao Yu struct list_head ino_list; /* inode list head */ 119967298804SChao Yu unsigned long ino_num; /* number of entries */ 120067298804SChao Yu }; 120167298804SChao Yu 1202093749e2SChao Yu /* for GC_AT */ 1203093749e2SChao Yu struct atgc_management { 1204093749e2SChao Yu bool atgc_enabled; /* ATGC is enabled or not */ 1205093749e2SChao Yu struct rb_root_cached root; /* root of victim rb-tree */ 1206093749e2SChao Yu struct list_head victim_list; /* linked with all victim entries */ 1207093749e2SChao Yu unsigned int victim_count; /* victim count in rb-tree */ 1208093749e2SChao Yu unsigned int candidate_ratio; /* candidate ratio */ 1209093749e2SChao Yu unsigned int max_candidate_count; /* max candidate count */ 1210093749e2SChao Yu unsigned int age_weight; /* age weight, vblock_weight = 100 - age_weight */ 1211093749e2SChao Yu unsigned long long age_threshold; /* age threshold */ 1212093749e2SChao Yu }; 1213093749e2SChao Yu 1214caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 1215caf0047eSChao Yu enum { 1216caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 1217caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 1218caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 1219caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 1220df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 1221bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 122283a3bfdbSJaegeuk Kim SBI_IS_SHUTDOWN, /* shutdown by ioctl */ 12231378752bSChao Yu SBI_IS_RECOVERED, /* recovered orphan/data */ 12244354994fSDaniel Rosenberg SBI_CP_DISABLED, /* CP was disabled last mount */ 1225db610a64SJaegeuk Kim SBI_CP_DISABLED_QUICK, /* CP was disabled quickly */ 1226af033b2aSChao Yu SBI_QUOTA_NEED_FLUSH, /* need to flush quota info in CP */ 1227af033b2aSChao Yu SBI_QUOTA_SKIP_FLUSH, /* skip flushing quota in current CP */ 1228af033b2aSChao Yu SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */ 122904f0b2eaSQiuyang Sun SBI_IS_RESIZEFS, /* resizefs is in process */ 1230caf0047eSChao Yu }; 1231caf0047eSChao Yu 12326beceb54SJaegeuk Kim enum { 12336beceb54SJaegeuk Kim CP_TIME, 1234d0239e1bSJaegeuk Kim REQ_TIME, 1235a7d10cf3SSahitya Tummala DISCARD_TIME, 1236a7d10cf3SSahitya Tummala GC_TIME, 12374354994fSDaniel Rosenberg DISABLE_TIME, 123803f2c02dSJaegeuk Kim UMOUNT_DISCARD_TIMEOUT, 12396beceb54SJaegeuk Kim MAX_TIME, 12406beceb54SJaegeuk Kim }; 12416beceb54SJaegeuk Kim 12420cdd3195SHyunchul Lee enum { 12435b0e9539SJaegeuk Kim GC_NORMAL, 12445b0e9539SJaegeuk Kim GC_IDLE_CB, 12455b0e9539SJaegeuk Kim GC_IDLE_GREEDY, 1246093749e2SChao Yu GC_IDLE_AT, 12470e5e8111SDaeho Jeong GC_URGENT_HIGH, 12480e5e8111SDaeho Jeong GC_URGENT_LOW, 12495b0e9539SJaegeuk Kim }; 12505b0e9539SJaegeuk Kim 12515b0e9539SJaegeuk Kim enum { 1252bbbc34fdSChao Yu BGGC_MODE_ON, /* background gc is on */ 1253bbbc34fdSChao Yu BGGC_MODE_OFF, /* background gc is off */ 1254bbbc34fdSChao Yu BGGC_MODE_SYNC, /* 1255bbbc34fdSChao Yu * background gc is on, migrating blocks 1256bbbc34fdSChao Yu * like foreground gc 1257bbbc34fdSChao Yu */ 1258bbbc34fdSChao Yu }; 1259bbbc34fdSChao Yu 1260bbbc34fdSChao Yu enum { 1261b0332a0fSChao Yu FS_MODE_ADAPTIVE, /* use both lfs/ssr allocation */ 1262b0332a0fSChao Yu FS_MODE_LFS, /* use lfs allocation only */ 1263b0332a0fSChao Yu }; 1264b0332a0fSChao Yu 1265b0332a0fSChao Yu enum { 12660cdd3195SHyunchul Lee WHINT_MODE_OFF, /* not pass down write hints */ 12670cdd3195SHyunchul Lee WHINT_MODE_USER, /* try to pass down hints given by users */ 1268f2e703f9SHyunchul Lee WHINT_MODE_FS, /* pass down hints with F2FS policy */ 12690cdd3195SHyunchul Lee }; 12700cdd3195SHyunchul Lee 127107939627SJaegeuk Kim enum { 127207939627SJaegeuk Kim ALLOC_MODE_DEFAULT, /* stay default */ 127307939627SJaegeuk Kim ALLOC_MODE_REUSE, /* reuse segments as much as possible */ 127407939627SJaegeuk Kim }; 127507939627SJaegeuk Kim 127693cf93f1SJunling Zheng enum fsync_mode { 127793cf93f1SJunling Zheng FSYNC_MODE_POSIX, /* fsync follows posix semantics */ 127893cf93f1SJunling Zheng FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */ 1279d6290814SJaegeuk Kim FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */ 128093cf93f1SJunling Zheng }; 128193cf93f1SJunling Zheng 1282602a16d5SDaeho Jeong enum { 1283602a16d5SDaeho Jeong COMPR_MODE_FS, /* 1284602a16d5SDaeho Jeong * automatically compress compression 1285602a16d5SDaeho Jeong * enabled files 1286602a16d5SDaeho Jeong */ 1287602a16d5SDaeho Jeong COMPR_MODE_USER, /* 1288602a16d5SDaeho Jeong * automatical compression is disabled. 1289602a16d5SDaeho Jeong * user can control the file compression 1290602a16d5SDaeho Jeong * using ioctls 1291602a16d5SDaeho Jeong */ 1292602a16d5SDaeho Jeong }; 1293602a16d5SDaeho Jeong 1294*b763f3beSChao Yu static inline int f2fs_test_bit(unsigned int nr, char *addr); 1295*b763f3beSChao Yu static inline void f2fs_set_bit(unsigned int nr, char *addr); 1296*b763f3beSChao Yu static inline void f2fs_clear_bit(unsigned int nr, char *addr); 12974c8ff709SChao Yu 1298*b763f3beSChao Yu /* 1299*b763f3beSChao Yu * Layout of f2fs page.private: 1300*b763f3beSChao Yu * 1301*b763f3beSChao Yu * Layout A: lowest bit should be 1 1302*b763f3beSChao Yu * | bit0 = 1 | bit1 | bit2 | ... | bit MAX | private data .... | 1303*b763f3beSChao Yu * bit 0 PAGE_PRIVATE_NOT_POINTER 1304*b763f3beSChao Yu * bit 1 PAGE_PRIVATE_ATOMIC_WRITE 1305*b763f3beSChao Yu * bit 2 PAGE_PRIVATE_DUMMY_WRITE 1306*b763f3beSChao Yu * bit 3 PAGE_PRIVATE_ONGOING_MIGRATION 1307*b763f3beSChao Yu * bit 4 PAGE_PRIVATE_INLINE_INODE 1308*b763f3beSChao Yu * bit 5 PAGE_PRIVATE_REF_RESOURCE 1309*b763f3beSChao Yu * bit 6- f2fs private data 1310*b763f3beSChao Yu * 1311*b763f3beSChao Yu * Layout B: lowest bit should be 0 1312*b763f3beSChao Yu * page.private is a wrapped pointer. 1313*b763f3beSChao Yu */ 1314*b763f3beSChao Yu enum { 1315*b763f3beSChao Yu PAGE_PRIVATE_NOT_POINTER, /* private contains non-pointer data */ 1316*b763f3beSChao Yu PAGE_PRIVATE_ATOMIC_WRITE, /* data page from atomic write path */ 1317*b763f3beSChao Yu PAGE_PRIVATE_DUMMY_WRITE, /* data page for padding aligned IO */ 1318*b763f3beSChao Yu PAGE_PRIVATE_ONGOING_MIGRATION, /* data page which is on-going migrating */ 1319*b763f3beSChao Yu PAGE_PRIVATE_INLINE_INODE, /* inode page contains inline data */ 1320*b763f3beSChao Yu PAGE_PRIVATE_REF_RESOURCE, /* dirty page has referenced resources */ 1321*b763f3beSChao Yu PAGE_PRIVATE_MAX 1322*b763f3beSChao Yu }; 1323*b763f3beSChao Yu 1324*b763f3beSChao Yu #define PAGE_PRIVATE_GET_FUNC(name, flagname) \ 1325*b763f3beSChao Yu static inline bool page_private_##name(struct page *page) \ 1326*b763f3beSChao Yu { \ 1327*b763f3beSChao Yu return test_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)) && \ 1328*b763f3beSChao Yu test_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \ 1329*b763f3beSChao Yu } 1330*b763f3beSChao Yu 1331*b763f3beSChao Yu #define PAGE_PRIVATE_SET_FUNC(name, flagname) \ 1332*b763f3beSChao Yu static inline void set_page_private_##name(struct page *page) \ 1333*b763f3beSChao Yu { \ 1334*b763f3beSChao Yu if (!PagePrivate(page)) { \ 1335*b763f3beSChao Yu get_page(page); \ 1336*b763f3beSChao Yu SetPagePrivate(page); \ 1337*b763f3beSChao Yu } \ 1338*b763f3beSChao Yu set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)); \ 1339*b763f3beSChao Yu set_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \ 1340*b763f3beSChao Yu } 1341*b763f3beSChao Yu 1342*b763f3beSChao Yu #define PAGE_PRIVATE_CLEAR_FUNC(name, flagname) \ 1343*b763f3beSChao Yu static inline void clear_page_private_##name(struct page *page) \ 1344*b763f3beSChao Yu { \ 1345*b763f3beSChao Yu clear_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \ 1346*b763f3beSChao Yu if (page_private(page) == 1 << PAGE_PRIVATE_NOT_POINTER) { \ 1347*b763f3beSChao Yu set_page_private(page, 0); \ 1348*b763f3beSChao Yu if (PagePrivate(page)) { \ 1349*b763f3beSChao Yu ClearPagePrivate(page); \ 1350*b763f3beSChao Yu put_page(page); \ 1351*b763f3beSChao Yu }\ 1352*b763f3beSChao Yu } \ 1353*b763f3beSChao Yu } 1354*b763f3beSChao Yu 1355*b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(nonpointer, NOT_POINTER); 1356*b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(reference, REF_RESOURCE); 1357*b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(inline, INLINE_INODE); 1358*b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(gcing, ONGOING_MIGRATION); 1359*b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(atomic, ATOMIC_WRITE); 1360*b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(dummy, DUMMY_WRITE); 1361*b763f3beSChao Yu 1362*b763f3beSChao Yu PAGE_PRIVATE_SET_FUNC(reference, REF_RESOURCE); 1363*b763f3beSChao Yu PAGE_PRIVATE_SET_FUNC(inline, INLINE_INODE); 1364*b763f3beSChao Yu PAGE_PRIVATE_SET_FUNC(gcing, ONGOING_MIGRATION); 1365*b763f3beSChao Yu PAGE_PRIVATE_SET_FUNC(atomic, ATOMIC_WRITE); 1366*b763f3beSChao Yu PAGE_PRIVATE_SET_FUNC(dummy, DUMMY_WRITE); 1367*b763f3beSChao Yu 1368*b763f3beSChao Yu PAGE_PRIVATE_CLEAR_FUNC(reference, REF_RESOURCE); 1369*b763f3beSChao Yu PAGE_PRIVATE_CLEAR_FUNC(inline, INLINE_INODE); 1370*b763f3beSChao Yu PAGE_PRIVATE_CLEAR_FUNC(gcing, ONGOING_MIGRATION); 1371*b763f3beSChao Yu PAGE_PRIVATE_CLEAR_FUNC(atomic, ATOMIC_WRITE); 1372*b763f3beSChao Yu PAGE_PRIVATE_CLEAR_FUNC(dummy, DUMMY_WRITE); 13734c8ff709SChao Yu 13744c8ff709SChao Yu /* For compression */ 13754c8ff709SChao Yu enum compress_algorithm_type { 13764c8ff709SChao Yu COMPRESS_LZO, 13774c8ff709SChao Yu COMPRESS_LZ4, 137850cfa66fSChao Yu COMPRESS_ZSTD, 13796d92b201SChao Yu COMPRESS_LZORLE, 13804c8ff709SChao Yu COMPRESS_MAX, 13814c8ff709SChao Yu }; 13824c8ff709SChao Yu 1383b28f047bSChao Yu enum compress_flag { 1384b28f047bSChao Yu COMPRESS_CHKSUM, 1385b28f047bSChao Yu COMPRESS_MAX_FLAG, 1386b28f047bSChao Yu }; 1387b28f047bSChao Yu 1388b28f047bSChao Yu #define COMPRESS_DATA_RESERVED_SIZE 4 13894c8ff709SChao Yu struct compress_data { 13904c8ff709SChao Yu __le32 clen; /* compressed data size */ 1391b28f047bSChao Yu __le32 chksum; /* compressed data chksum */ 13924c8ff709SChao Yu __le32 reserved[COMPRESS_DATA_RESERVED_SIZE]; /* reserved */ 13934c8ff709SChao Yu u8 cdata[]; /* compressed data */ 13944c8ff709SChao Yu }; 13954c8ff709SChao Yu 13964c8ff709SChao Yu #define COMPRESS_HEADER_SIZE (sizeof(struct compress_data)) 13974c8ff709SChao Yu 13984c8ff709SChao Yu #define F2FS_COMPRESSED_PAGE_MAGIC 0xF5F2C000 13994c8ff709SChao Yu 14003fde13f8SChao Yu #define COMPRESS_LEVEL_OFFSET 8 14013fde13f8SChao Yu 14024c8ff709SChao Yu /* compress context */ 14034c8ff709SChao Yu struct compress_ctx { 14044c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 14054c8ff709SChao Yu pgoff_t cluster_idx; /* cluster index number */ 14064c8ff709SChao Yu unsigned int cluster_size; /* page count in cluster */ 14074c8ff709SChao Yu unsigned int log_cluster_size; /* log of cluster size */ 14084c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 14094c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 14104c8ff709SChao Yu struct page **cpages; /* pages store compressed data in cluster */ 14114c8ff709SChao Yu unsigned int nr_cpages; /* total page number in cpages */ 14124c8ff709SChao Yu void *rbuf; /* virtual mapped address on rpages */ 14134c8ff709SChao Yu struct compress_data *cbuf; /* virtual mapped address on cpages */ 14144c8ff709SChao Yu size_t rlen; /* valid data length in rbuf */ 14154c8ff709SChao Yu size_t clen; /* valid data length in cbuf */ 14164c8ff709SChao Yu void *private; /* payload buffer for specified compression algorithm */ 141750cfa66fSChao Yu void *private2; /* extra payload buffer */ 14184c8ff709SChao Yu }; 14194c8ff709SChao Yu 14204c8ff709SChao Yu /* compress context for write IO path */ 14214c8ff709SChao Yu struct compress_io_ctx { 14224c8ff709SChao Yu u32 magic; /* magic number to indicate page is compressed */ 14234c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 14244c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 14254c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 1426e6c3948dSChao Yu atomic_t pending_pages; /* in-flight compressed page count */ 14274c8ff709SChao Yu }; 14284c8ff709SChao Yu 14297f59b277SEric Biggers /* Context for decompressing one cluster on the read IO path */ 14304c8ff709SChao Yu struct decompress_io_ctx { 14314c8ff709SChao Yu u32 magic; /* magic number to indicate page is compressed */ 14324c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 14334c8ff709SChao Yu pgoff_t cluster_idx; /* cluster index number */ 14344c8ff709SChao Yu unsigned int cluster_size; /* page count in cluster */ 14354c8ff709SChao Yu unsigned int log_cluster_size; /* log of cluster size */ 14364c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 14374c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 14384c8ff709SChao Yu struct page **cpages; /* pages store compressed data in cluster */ 14394c8ff709SChao Yu unsigned int nr_cpages; /* total page number in cpages */ 14404c8ff709SChao Yu struct page **tpages; /* temp pages to pad holes in cluster */ 14414c8ff709SChao Yu void *rbuf; /* virtual mapped address on rpages */ 14424c8ff709SChao Yu struct compress_data *cbuf; /* virtual mapped address on cpages */ 14434c8ff709SChao Yu size_t rlen; /* valid data length in rbuf */ 14444c8ff709SChao Yu size_t clen; /* valid data length in cbuf */ 14457f59b277SEric Biggers 14467f59b277SEric Biggers /* 14477f59b277SEric Biggers * The number of compressed pages remaining to be read in this cluster. 14487f59b277SEric Biggers * This is initially nr_cpages. It is decremented by 1 each time a page 14497f59b277SEric Biggers * has been read (or failed to be read). When it reaches 0, the cluster 14507f59b277SEric Biggers * is decompressed (or an error is reported). 14517f59b277SEric Biggers * 14527f59b277SEric Biggers * If an error occurs before all the pages have been submitted for I/O, 14537f59b277SEric Biggers * then this will never reach 0. In this case the I/O submitter is 14547f59b277SEric Biggers * responsible for calling f2fs_decompress_end_io() instead. 14557f59b277SEric Biggers */ 14567f59b277SEric Biggers atomic_t remaining_pages; 14577f59b277SEric Biggers 14587f59b277SEric Biggers /* 14597f59b277SEric Biggers * Number of references to this decompress_io_ctx. 14607f59b277SEric Biggers * 14617f59b277SEric Biggers * One reference is held for I/O completion. This reference is dropped 14627f59b277SEric Biggers * after the pagecache pages are updated and unlocked -- either after 14637f59b277SEric Biggers * decompression (and verity if enabled), or after an error. 14647f59b277SEric Biggers * 14657f59b277SEric Biggers * In addition, each compressed page holds a reference while it is in a 14667f59b277SEric Biggers * bio. These references are necessary prevent compressed pages from 14677f59b277SEric Biggers * being freed while they are still in a bio. 14687f59b277SEric Biggers */ 14697f59b277SEric Biggers refcount_t refcnt; 14707f59b277SEric Biggers 14717f59b277SEric Biggers bool failed; /* IO error occurred before decompression? */ 14727f59b277SEric Biggers bool need_verity; /* need fs-verity verification after decompression? */ 147350cfa66fSChao Yu void *private; /* payload buffer for specified decompression algorithm */ 147450cfa66fSChao Yu void *private2; /* extra payload buffer */ 14757f59b277SEric Biggers struct work_struct verity_work; /* work to verify the decompressed pages */ 14764c8ff709SChao Yu }; 14774c8ff709SChao Yu 14784c8ff709SChao Yu #define NULL_CLUSTER ((unsigned int)(~0)) 14794c8ff709SChao Yu #define MIN_COMPRESS_LOG_SIZE 2 14804c8ff709SChao Yu #define MAX_COMPRESS_LOG_SIZE 8 14810e2b7385SChao Yu #define MAX_COMPRESS_WINDOW_SIZE(log_size) ((PAGE_SIZE) << (log_size)) 14824c8ff709SChao Yu 148339a53e0cSJaegeuk Kim struct f2fs_sb_info { 148439a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 14855e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 148639a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 1487846ae671SChao Yu struct rw_semaphore sb_lock; /* lock for raw super block */ 1488e8240f65SChao Yu int valid_super_block; /* valid super block no */ 1489fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 1490853137ceSJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 149139a53e0cSJaegeuk Kim 1492178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 1493178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1494178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 1495178053e2SDamien Le Moal #endif 1496178053e2SDamien Le Moal 149739a53e0cSJaegeuk Kim /* for node-related operations */ 149839a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 149939a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 150039a53e0cSJaegeuk Kim 150139a53e0cSJaegeuk Kim /* for segment-related operations */ 150239a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 15031ff7bd3bSJaegeuk Kim 15041ff7bd3bSJaegeuk Kim /* for bio operations */ 1505a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1506107a805dSChao Yu /* keep migration IO order for LFS mode */ 1507107a805dSChao Yu struct rw_semaphore io_order_lock; 15080a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 150939a53e0cSJaegeuk Kim 151039a53e0cSJaegeuk Kim /* for checkpoint */ 151139a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 15128508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1513aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 151439a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 15158769918bSSahitya Tummala struct rw_semaphore cp_global_sem; /* checkpoint procedure lock */ 1516b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1517b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 151859c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1519fb51b5efSChangman Lee wait_queue_head_t cp_wait; 15206beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 15216beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 1522261eeb9cSDaeho Jeong struct ckpt_req_control cprc_info; /* for checkpoint request control */ 152339a53e0cSJaegeuk Kim 152467298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 15256451e041SJaegeuk Kim 152650fa53ecSChao Yu spinlock_t fsync_node_lock; /* for node entry lock */ 152750fa53ecSChao Yu struct list_head fsync_node_list; /* node list head */ 152850fa53ecSChao Yu unsigned int fsync_seg_id; /* sequence id */ 152950fa53ecSChao Yu unsigned int fsync_node_num; /* number of node entries */ 153050fa53ecSChao Yu 15316451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 15320d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 153339a53e0cSJaegeuk Kim 1534c227f912SChao Yu /* for inode management */ 1535c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1536c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 1537040d2bb3SChao Yu struct mutex flush_lock; /* for flush exclusion */ 153839a53e0cSJaegeuk Kim 153913054c54SChao Yu /* for extent tree cache */ 154013054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 15415e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 154213054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 154313054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 15447441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1545137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 154674fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 154713054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 154813054c54SChao Yu 154939a53e0cSJaegeuk Kim /* basic filesystem units */ 155039a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 155139a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 155239a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 155339a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 155439a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 155539a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 155639a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 155739a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 155839a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 155939a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 156039a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 156139a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 156239a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1563ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 1564f6df8f23SSheng Yong int readdir_ra; /* readahead inode in readdir */ 156510208567SJaegeuk Kim u64 max_io_bytes; /* max io bytes to merge IOs */ 156639a53e0cSJaegeuk Kim 156739a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 156839a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1569a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 157039a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1571daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 157280d42145SYunlong Song block_t current_reserved_blocks; /* current reserved blocks */ 1573daeb433eSChao Yu 15744354994fSDaniel Rosenberg /* Additional tracking for no checkpoint mode */ 15754354994fSDaniel Rosenberg block_t unusable_block_count; /* # of blocks saved by last cp */ 15764354994fSDaniel Rosenberg 1577292c196aSChao Yu unsigned int nquota_files; /* # of quota sysfile */ 1578db6ec53bSJaegeuk Kim struct rw_semaphore quota_sem; /* blocking cp for flags */ 1579292c196aSChao Yu 1580523be8a6SJaegeuk Kim /* # of pages, see count_type */ 158135782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 158241382ec4SJaegeuk Kim /* # of allocated blocks */ 158341382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 158439a53e0cSJaegeuk Kim 1585687de7f1SJaegeuk Kim /* writeback control */ 1586c29fd0c0SChao Yu atomic_t wb_sync_req[META]; /* count # of WB_SYNC threads */ 1587687de7f1SJaegeuk Kim 1588513c5f37SJaegeuk Kim /* valid inode count */ 1589513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1590513c5f37SJaegeuk Kim 159139a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 159239a53e0cSJaegeuk Kim 159339a53e0cSJaegeuk Kim /* for cleaning operations */ 1594fb24fea7SChao Yu struct rw_semaphore gc_lock; /* 1595fb24fea7SChao Yu * semaphore for GC, avoid 1596fb24fea7SChao Yu * race between GC and GC or CP 1597fb24fea7SChao Yu */ 159839a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 1599093749e2SChao Yu struct atgc_management am; /* atgc management */ 16005ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 16015b0e9539SJaegeuk Kim unsigned int gc_mode; /* current GC state */ 1602e3080b01SChao Yu unsigned int next_victim_seg[2]; /* next segment in victim section */ 16030e5e8111SDaeho Jeong 16042ef79ecbSChao Yu /* for skip statistic */ 1605677017d1SSahitya Tummala unsigned int atomic_files; /* # of opened atomic file */ 16062ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */ 16076f8d4455SJaegeuk Kim unsigned long long skipped_gc_rwsem; /* FG_GC only */ 160839a53e0cSJaegeuk Kim 16091ad71a27SJaegeuk Kim /* threshold for gc trials on pinned files */ 16101ad71a27SJaegeuk Kim u64 gc_pin_file_threshold; 1611f5a53edcSJaegeuk Kim struct rw_semaphore pin_sem; 16121ad71a27SJaegeuk Kim 1613b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1614b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1615e3080b01SChao Yu /* migration granularity of garbage collection, unit: segment */ 1616e3080b01SChao Yu unsigned int migration_granularity; 1617b1c57c1cSJaegeuk Kim 161839a53e0cSJaegeuk Kim /* 161939a53e0cSJaegeuk Kim * for stat information. 162039a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 162139a53e0cSJaegeuk Kim */ 162235b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 162339a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 1624b63e7be5SChao Yu atomic_t meta_count[META_MAX]; /* # of meta blocks */ 162539a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 162639a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1627b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 16285b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 16295b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 16305b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 16315b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1632d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 163303e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 163403e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 16354c8ff709SChao Yu atomic_t compr_inode; /* # of compressed inodes */ 1636ae999bb9SDaeho Jeong atomic64_t compr_blocks; /* # of compressed blocks */ 1637648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 163826a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1639648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 1640274bd9baSChao Yu unsigned int io_skip_bggc; /* skip background gc for in-flight IO */ 1641274bd9baSChao Yu unsigned int other_skip_bggc; /* skip background gc for other reasons */ 164233fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 164335b09d82SNamjae Jeon #endif 164439a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1645b59d0baeSNamjae Jeon 1646b0af6d49SChao Yu /* For app/fs IO statistics */ 1647b0af6d49SChao Yu spinlock_t iostat_lock; 16488b83ac81SChao Yu unsigned long long rw_iostat[NR_IO_TYPE]; 16498b83ac81SChao Yu unsigned long long prev_rw_iostat[NR_IO_TYPE]; 1650b0af6d49SChao Yu bool iostat_enable; 16512bc4bea3SDaeho Jeong unsigned long iostat_next_period; 16522bc4bea3SDaeho Jeong unsigned int iostat_period_ms; 1653b0af6d49SChao Yu 1654da9953b7SJaegeuk Kim /* to attach REQ_META|REQ_FUA flags */ 1655da9953b7SJaegeuk Kim unsigned int data_io_flag; 165632b6aba8SJaegeuk Kim unsigned int node_io_flag; 1657b59d0baeSNamjae Jeon 1658b59d0baeSNamjae Jeon /* For sysfs suppport */ 16595d4daa57SChao Yu struct kobject s_kobj; /* /sys/fs/f2fs/<devname> */ 1660b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 16612658e50dSJaegeuk Kim 16625d4daa57SChao Yu struct kobject s_stat_kobj; /* /sys/fs/f2fs/<devname>/stat */ 16635d4daa57SChao Yu struct completion s_stat_kobj_unregister; 16645d4daa57SChao Yu 16652658e50dSJaegeuk Kim /* For shrinker support */ 16662658e50dSJaegeuk Kim struct list_head s_list; 16673c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 16683c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 16691228b482SChao Yu unsigned int dirty_device; /* for checkpoint data flush */ 16701228b482SChao Yu spinlock_t dev_lock; /* protect dirty_device */ 16712658e50dSJaegeuk Kim struct mutex umount_mutex; 16722658e50dSJaegeuk Kim unsigned int shrinker_run_no; 16738f1dbbbbSShuoran Liu 16748f1dbbbbSShuoran Liu /* For write statistics */ 16758f1dbbbbSShuoran Liu u64 sectors_written_start; 16768f1dbbbbSShuoran Liu u64 kbytes_written; 167743b6573bSKeith Mok 167843b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 167943b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 16801ecc0c5cSChao Yu 1681704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1682704956ecSChao Yu __u32 s_chksum_seed; 16834c8ff709SChao Yu 16844c8ff709SChao Yu struct workqueue_struct *post_read_wq; /* post read workqueue */ 1685a999150fSChao Yu 1686a999150fSChao Yu struct kmem_cache *inline_xattr_slab; /* inline xattr entry */ 1687a999150fSChao Yu unsigned int inline_xattr_slab_size; /* default inline xattr slab size */ 168831083031SChao Yu 168931083031SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 169031083031SChao Yu struct kmem_cache *page_array_slab; /* page array entry */ 169131083031SChao Yu unsigned int page_array_slab_size; /* default page array slab size */ 16925ac443e2SDaeho Jeong 16935ac443e2SDaeho Jeong /* For runtime compression statistics */ 16945ac443e2SDaeho Jeong u64 compr_written_block; 16955ac443e2SDaeho Jeong u64 compr_saved_block; 16965ac443e2SDaeho Jeong u32 compr_new_inode; 169731083031SChao Yu #endif 169839a53e0cSJaegeuk Kim }; 169939a53e0cSJaegeuk Kim 170002b16d0aSChao Yu struct f2fs_private_dio { 170102b16d0aSChao Yu struct inode *inode; 170202b16d0aSChao Yu void *orig_private; 170302b16d0aSChao Yu bio_end_io_t *orig_end_io; 170402b16d0aSChao Yu bool write; 170502b16d0aSChao Yu }; 170602b16d0aSChao Yu 17071ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 1708c45d6002SChao Yu #define f2fs_show_injection_info(sbi, type) \ 1709c45d6002SChao Yu printk_ratelimited("%sF2FS-fs (%s) : inject %s in %s of %pS\n", \ 1710c45d6002SChao Yu KERN_INFO, sbi->sb->s_id, \ 1711c45d6002SChao Yu f2fs_fault_name[type], \ 171255523519SChao Yu __func__, __builtin_return_address(0)) 17131ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 17141ecc0c5cSChao Yu { 171563189b78SChao Yu struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; 17161ecc0c5cSChao Yu 17171ecc0c5cSChao Yu if (!ffi->inject_rate) 17181ecc0c5cSChao Yu return false; 17191ecc0c5cSChao Yu 17201ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 17211ecc0c5cSChao Yu return false; 17221ecc0c5cSChao Yu 17231ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 17241ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 17251ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 17261ecc0c5cSChao Yu return true; 17271ecc0c5cSChao Yu } 17281ecc0c5cSChao Yu return false; 17291ecc0c5cSChao Yu } 17307fa750a1SArnd Bergmann #else 1731c45d6002SChao Yu #define f2fs_show_injection_info(sbi, type) do { } while (0) 17327fa750a1SArnd Bergmann static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 17337fa750a1SArnd Bergmann { 17347fa750a1SArnd Bergmann return false; 17357fa750a1SArnd Bergmann } 17361ecc0c5cSChao Yu #endif 17371ecc0c5cSChao Yu 17380916878dSDamien Le Moal /* 17390916878dSDamien Le Moal * Test if the mounted volume is a multi-device volume. 17400916878dSDamien Le Moal * - For a single regular disk volume, sbi->s_ndevs is 0. 17410916878dSDamien Le Moal * - For a single zoned disk volume, sbi->s_ndevs is 1. 17420916878dSDamien Le Moal * - For a multi-device volume, sbi->s_ndevs is always 2 or more. 17430916878dSDamien Le Moal */ 17440916878dSDamien Le Moal static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi) 17450916878dSDamien Le Moal { 17460916878dSDamien Le Moal return sbi->s_ndevs > 1; 17470916878dSDamien Le Moal } 17480916878dSDamien Le Moal 17496beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 17506beceb54SJaegeuk Kim { 1751a7d10cf3SSahitya Tummala unsigned long now = jiffies; 1752a7d10cf3SSahitya Tummala 1753a7d10cf3SSahitya Tummala sbi->last_time[type] = now; 1754a7d10cf3SSahitya Tummala 1755a7d10cf3SSahitya Tummala /* DISCARD_TIME and GC_TIME are based on REQ_TIME */ 1756a7d10cf3SSahitya Tummala if (type == REQ_TIME) { 1757a7d10cf3SSahitya Tummala sbi->last_time[DISCARD_TIME] = now; 1758a7d10cf3SSahitya Tummala sbi->last_time[GC_TIME] = now; 1759a7d10cf3SSahitya Tummala } 17606beceb54SJaegeuk Kim } 17616beceb54SJaegeuk Kim 17626beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 17636beceb54SJaegeuk Kim { 17646bccfa19SArnd Bergmann unsigned long interval = sbi->interval_time[type] * HZ; 17656beceb54SJaegeuk Kim 17666beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 17676beceb54SJaegeuk Kim } 17686beceb54SJaegeuk Kim 1769a7d10cf3SSahitya Tummala static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi, 1770a7d10cf3SSahitya Tummala int type) 1771a7d10cf3SSahitya Tummala { 1772a7d10cf3SSahitya Tummala unsigned long interval = sbi->interval_time[type] * HZ; 1773a7d10cf3SSahitya Tummala unsigned int wait_ms = 0; 1774a7d10cf3SSahitya Tummala long delta; 1775a7d10cf3SSahitya Tummala 1776a7d10cf3SSahitya Tummala delta = (sbi->last_time[type] + interval) - jiffies; 1777a7d10cf3SSahitya Tummala if (delta > 0) 1778a7d10cf3SSahitya Tummala wait_ms = jiffies_to_msecs(delta); 1779a7d10cf3SSahitya Tummala 1780a7d10cf3SSahitya Tummala return wait_ms; 1781a7d10cf3SSahitya Tummala } 1782a7d10cf3SSahitya Tummala 178339a53e0cSJaegeuk Kim /* 178439a53e0cSJaegeuk Kim * Inline functions 178539a53e0cSJaegeuk Kim */ 1786416d2dbbSChao Yu static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc, 1787704956ecSChao Yu const void *address, unsigned int length) 1788704956ecSChao Yu { 1789704956ecSChao Yu struct { 1790704956ecSChao Yu struct shash_desc shash; 1791704956ecSChao Yu char ctx[4]; 1792704956ecSChao Yu } desc; 1793704956ecSChao Yu int err; 1794704956ecSChao Yu 1795704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1796704956ecSChao Yu 1797704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1798704956ecSChao Yu *(u32 *)desc.ctx = crc; 1799704956ecSChao Yu 1800704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1801704956ecSChao Yu BUG_ON(err); 1802704956ecSChao Yu 1803704956ecSChao Yu return *(u32 *)desc.ctx; 1804704956ecSChao Yu } 1805704956ecSChao Yu 1806416d2dbbSChao Yu static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 1807416d2dbbSChao Yu unsigned int length) 1808416d2dbbSChao Yu { 1809416d2dbbSChao Yu return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length); 1810416d2dbbSChao Yu } 1811416d2dbbSChao Yu 1812416d2dbbSChao Yu static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 1813416d2dbbSChao Yu void *buf, size_t buf_size) 1814416d2dbbSChao Yu { 1815416d2dbbSChao Yu return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 1816416d2dbbSChao Yu } 1817416d2dbbSChao Yu 1818416d2dbbSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1819416d2dbbSChao Yu const void *address, unsigned int length) 1820416d2dbbSChao Yu { 1821416d2dbbSChao Yu return __f2fs_crc32(sbi, crc, address, length); 1822416d2dbbSChao Yu } 1823416d2dbbSChao Yu 182439a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 182539a53e0cSJaegeuk Kim { 182639a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 182739a53e0cSJaegeuk Kim } 182839a53e0cSJaegeuk Kim 182939a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 183039a53e0cSJaegeuk Kim { 183139a53e0cSJaegeuk Kim return sb->s_fs_info; 183239a53e0cSJaegeuk Kim } 183339a53e0cSJaegeuk Kim 18344081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 18354081363fSJaegeuk Kim { 18364081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 18374081363fSJaegeuk Kim } 18384081363fSJaegeuk Kim 18394081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 18404081363fSJaegeuk Kim { 18414081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 18424081363fSJaegeuk Kim } 18434081363fSJaegeuk Kim 18444081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 18454081363fSJaegeuk Kim { 18464969c06aSJaegeuk Kim return F2FS_M_SB(page_file_mapping(page)); 18474081363fSJaegeuk Kim } 18484081363fSJaegeuk Kim 184939a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 185039a53e0cSJaegeuk Kim { 185139a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 185239a53e0cSJaegeuk Kim } 185339a53e0cSJaegeuk Kim 185439a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 185539a53e0cSJaegeuk Kim { 185639a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 185739a53e0cSJaegeuk Kim } 185839a53e0cSJaegeuk Kim 185945590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 186045590710SGu Zheng { 186145590710SGu Zheng return (struct f2fs_node *)page_address(page); 186245590710SGu Zheng } 186345590710SGu Zheng 186458bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 186558bfaf44SJaegeuk Kim { 186658bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 186758bfaf44SJaegeuk Kim } 186858bfaf44SJaegeuk Kim 186939a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 187039a53e0cSJaegeuk Kim { 187139a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 187239a53e0cSJaegeuk Kim } 187339a53e0cSJaegeuk Kim 187439a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 187539a53e0cSJaegeuk Kim { 187639a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 187739a53e0cSJaegeuk Kim } 187839a53e0cSJaegeuk Kim 187939a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 188039a53e0cSJaegeuk Kim { 188139a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 188239a53e0cSJaegeuk Kim } 188339a53e0cSJaegeuk Kim 188439a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 188539a53e0cSJaegeuk Kim { 188639a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 188739a53e0cSJaegeuk Kim } 188839a53e0cSJaegeuk Kim 188939a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 189039a53e0cSJaegeuk Kim { 189139a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 189239a53e0cSJaegeuk Kim } 189339a53e0cSJaegeuk Kim 18949df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 18959df27d98SGu Zheng { 18969df27d98SGu Zheng return sbi->meta_inode->i_mapping; 18979df27d98SGu Zheng } 18989df27d98SGu Zheng 18994ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 19004ef51a8fSJaegeuk Kim { 19014ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 19024ef51a8fSJaegeuk Kim } 19034ef51a8fSJaegeuk Kim 1904caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 190539a53e0cSJaegeuk Kim { 1906fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 190739a53e0cSJaegeuk Kim } 190839a53e0cSJaegeuk Kim 1909caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 191039a53e0cSJaegeuk Kim { 1911fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1912caf0047eSChao Yu } 1913caf0047eSChao Yu 1914caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1915caf0047eSChao Yu { 1916fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 191739a53e0cSJaegeuk Kim } 191839a53e0cSJaegeuk Kim 1919d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1920d71b5564SJaegeuk Kim { 1921d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1922d71b5564SJaegeuk Kim } 1923d71b5564SJaegeuk Kim 1924ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) 1925ea676733SJaegeuk Kim { 1926ea676733SJaegeuk Kim if (type < F2FS_MAX_QUOTAS) 1927ea676733SJaegeuk Kim return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); 1928ea676733SJaegeuk Kim return 0; 1929ea676733SJaegeuk Kim } 1930ea676733SJaegeuk Kim 1931ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1932ced2c7eaSKinglong Mee { 1933ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1934ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1935ced2c7eaSKinglong Mee } 1936ced2c7eaSKinglong Mee 1937aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 193825ca923bSJaegeuk Kim { 193925ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1940aaec2b1dSChao Yu 194125ca923bSJaegeuk Kim return ckpt_flags & f; 194225ca923bSJaegeuk Kim } 194325ca923bSJaegeuk Kim 1944aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 194525ca923bSJaegeuk Kim { 1946aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1947aaec2b1dSChao Yu } 1948aaec2b1dSChao Yu 1949aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1950aaec2b1dSChao Yu { 1951aaec2b1dSChao Yu unsigned int ckpt_flags; 1952aaec2b1dSChao Yu 1953aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 195425ca923bSJaegeuk Kim ckpt_flags |= f; 195525ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 195625ca923bSJaegeuk Kim } 195725ca923bSJaegeuk Kim 1958aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 195925ca923bSJaegeuk Kim { 1960d1aa2453SChao Yu unsigned long flags; 1961d1aa2453SChao Yu 1962d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1963aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1964d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1965aaec2b1dSChao Yu } 1966aaec2b1dSChao Yu 1967aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1968aaec2b1dSChao Yu { 1969aaec2b1dSChao Yu unsigned int ckpt_flags; 1970aaec2b1dSChao Yu 1971aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 197225ca923bSJaegeuk Kim ckpt_flags &= (~f); 197325ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 197425ca923bSJaegeuk Kim } 197525ca923bSJaegeuk Kim 1976aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1977aaec2b1dSChao Yu { 1978d1aa2453SChao Yu unsigned long flags; 1979d1aa2453SChao Yu 1980d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1981aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1982d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1983aaec2b1dSChao Yu } 1984aaec2b1dSChao Yu 198522ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 198622ad0b6aSJaegeuk Kim { 1987d1aa2453SChao Yu unsigned long flags; 19880921835cSChao Yu unsigned char *nat_bits; 1989d1aa2453SChao Yu 1990a742fd41SJaegeuk Kim /* 1991a742fd41SJaegeuk Kim * In order to re-enable nat_bits we need to call fsck.f2fs by 1992a742fd41SJaegeuk Kim * set_sbi_flag(sbi, SBI_NEED_FSCK). But it may give huge cost, 1993a742fd41SJaegeuk Kim * so let's rely on regular fsck or unclean shutdown. 1994a742fd41SJaegeuk Kim */ 199522ad0b6aSJaegeuk Kim 199622ad0b6aSJaegeuk Kim if (lock) 1997d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 199822ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 19990921835cSChao Yu nat_bits = NM_I(sbi)->nat_bits; 200022ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 200122ad0b6aSJaegeuk Kim if (lock) 2002d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 20030921835cSChao Yu 20040921835cSChao Yu kvfree(nat_bits); 200522ad0b6aSJaegeuk Kim } 200622ad0b6aSJaegeuk Kim 200722ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 200822ad0b6aSJaegeuk Kim struct cp_control *cpc) 200922ad0b6aSJaegeuk Kim { 201022ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 201122ad0b6aSJaegeuk Kim 2012c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 201322ad0b6aSJaegeuk Kim } 201422ad0b6aSJaegeuk Kim 2015e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 201639a53e0cSJaegeuk Kim { 2017b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 201839a53e0cSJaegeuk Kim } 201939a53e0cSJaegeuk Kim 2020cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 2021cc15620bSJaegeuk Kim { 2022cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 2023cc15620bSJaegeuk Kim } 2024cc15620bSJaegeuk Kim 2025e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 202639a53e0cSJaegeuk Kim { 2027b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 202839936837SJaegeuk Kim } 202939936837SJaegeuk Kim 2030e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 203139936837SJaegeuk Kim { 2032b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 203339936837SJaegeuk Kim } 203439936837SJaegeuk Kim 2035e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 203639936837SJaegeuk Kim { 2037b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 203839a53e0cSJaegeuk Kim } 203939a53e0cSJaegeuk Kim 2040119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 2041119ee914SJaegeuk Kim { 2042119ee914SJaegeuk Kim int reason = CP_SYNC; 2043119ee914SJaegeuk Kim 2044119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 2045119ee914SJaegeuk Kim reason = CP_FASTBOOT; 2046119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 2047119ee914SJaegeuk Kim reason = CP_UMOUNT; 2048119ee914SJaegeuk Kim return reason; 2049119ee914SJaegeuk Kim } 2050119ee914SJaegeuk Kim 2051119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 2052119ee914SJaegeuk Kim { 2053c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 2054119ee914SJaegeuk Kim } 2055119ee914SJaegeuk Kim 2056119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 2057119ee914SJaegeuk Kim { 2058aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 2059aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 2060119ee914SJaegeuk Kim } 2061119ee914SJaegeuk Kim 206239a53e0cSJaegeuk Kim /* 206339a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 206439a53e0cSJaegeuk Kim */ 206539a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 206639a53e0cSJaegeuk Kim { 20670eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 20680eb0adadSChao Yu 2069000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 207039a53e0cSJaegeuk Kim } 207139a53e0cSJaegeuk Kim 20724bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 20734bc8e9bcSChao Yu { 20744bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 20754bc8e9bcSChao Yu } 20764bc8e9bcSChao Yu 2077d8a9a229SJaegeuk Kim static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, 2078a90a0884SJaegeuk Kim struct inode *inode, bool cap) 20797c2e5963SJaegeuk Kim { 2080d8a9a229SJaegeuk Kim if (!inode) 2081d8a9a229SJaegeuk Kim return true; 20827c2e5963SJaegeuk Kim if (!test_opt(sbi, RESERVE_ROOT)) 20837c2e5963SJaegeuk Kim return false; 2084d8a9a229SJaegeuk Kim if (IS_NOQUOTA(inode)) 2085d8a9a229SJaegeuk Kim return true; 208663189b78SChao Yu if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid())) 20877c2e5963SJaegeuk Kim return true; 208863189b78SChao Yu if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) && 208963189b78SChao Yu in_group_p(F2FS_OPTION(sbi).s_resgid)) 20907c2e5963SJaegeuk Kim return true; 2091a90a0884SJaegeuk Kim if (cap && capable(CAP_SYS_RESOURCE)) 2092162b27aeSJaegeuk Kim return true; 20937c2e5963SJaegeuk Kim return false; 20947c2e5963SJaegeuk Kim } 20957c2e5963SJaegeuk Kim 20960abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 20970abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 209846008c6dSChao Yu struct inode *inode, blkcnt_t *count) 209939a53e0cSJaegeuk Kim { 21000abd675eSChao Yu blkcnt_t diff = 0, release = 0; 2101daeb433eSChao Yu block_t avail_user_block_count; 21020abd675eSChao Yu int ret; 21030abd675eSChao Yu 21040abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 21050abd675eSChao Yu if (ret) 21060abd675eSChao Yu return ret; 2107dd11a5dfSJaegeuk Kim 210855523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 2109c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_BLOCK); 21100abd675eSChao Yu release = *count; 21119ea2f0beSChao Yu goto release_quota; 211255523519SChao Yu } 21137fa750a1SArnd Bergmann 2114dd11a5dfSJaegeuk Kim /* 2115dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 2116dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 2117dd11a5dfSJaegeuk Kim */ 2118dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 211939a53e0cSJaegeuk Kim 212039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 21212555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 212280d42145SYunlong Song avail_user_block_count = sbi->user_block_count - 212380d42145SYunlong Song sbi->current_reserved_blocks; 21247e65be49SJaegeuk Kim 2125a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, true)) 212663189b78SChao Yu avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; 2127a4c3ecaaSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { 2128a4c3ecaaSDaniel Rosenberg if (avail_user_block_count > sbi->unusable_block_count) 21294354994fSDaniel Rosenberg avail_user_block_count -= sbi->unusable_block_count; 2130a4c3ecaaSDaniel Rosenberg else 2131a4c3ecaaSDaniel Rosenberg avail_user_block_count = 0; 2132a4c3ecaaSDaniel Rosenberg } 2133daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 2134daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 21357e65be49SJaegeuk Kim if (diff > *count) 21367e65be49SJaegeuk Kim diff = *count; 2137dd11a5dfSJaegeuk Kim *count -= diff; 21380abd675eSChao Yu release = diff; 21397e65be49SJaegeuk Kim sbi->total_valid_block_count -= diff; 214046008c6dSChao Yu if (!*count) { 214139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 21420abd675eSChao Yu goto enospc; 214339a53e0cSJaegeuk Kim } 214446008c6dSChao Yu } 214539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 214641382ec4SJaegeuk Kim 214736b877afSDaniel Rosenberg if (unlikely(release)) { 214836b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 21490abd675eSChao Yu dquot_release_reservation_block(inode, release); 215036b877afSDaniel Rosenberg } 21510abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 21520abd675eSChao Yu return 0; 21530abd675eSChao Yu 21540abd675eSChao Yu enospc: 215536b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 21569ea2f0beSChao Yu release_quota: 21570abd675eSChao Yu dquot_release_reservation_block(inode, release); 21580abd675eSChao Yu return -ENOSPC; 215939a53e0cSJaegeuk Kim } 216039a53e0cSJaegeuk Kim 2161dcbb4c10SJoe Perches __printf(2, 3) 2162dcbb4c10SJoe Perches void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...); 2163dcbb4c10SJoe Perches 2164dcbb4c10SJoe Perches #define f2fs_err(sbi, fmt, ...) \ 2165dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_ERR fmt, ##__VA_ARGS__) 2166dcbb4c10SJoe Perches #define f2fs_warn(sbi, fmt, ...) \ 2167dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_WARNING fmt, ##__VA_ARGS__) 2168dcbb4c10SJoe Perches #define f2fs_notice(sbi, fmt, ...) \ 2169dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_NOTICE fmt, ##__VA_ARGS__) 2170dcbb4c10SJoe Perches #define f2fs_info(sbi, fmt, ...) \ 2171dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_INFO fmt, ##__VA_ARGS__) 2172dcbb4c10SJoe Perches #define f2fs_debug(sbi, fmt, ...) \ 2173dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_DEBUG fmt, ##__VA_ARGS__) 2174dcbb4c10SJoe Perches 2175da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 217639a53e0cSJaegeuk Kim struct inode *inode, 21770eb0adadSChao Yu block_t count) 217839a53e0cSJaegeuk Kim { 21790eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 21800eb0adadSChao Yu 218139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 21829850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 218339a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 218480d42145SYunlong Song if (sbi->reserved_blocks && 218580d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 218680d42145SYunlong Song sbi->current_reserved_blocks = min(sbi->reserved_blocks, 218780d42145SYunlong Song sbi->current_reserved_blocks + count); 218839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 21895e159cd3SChao Yu if (unlikely(inode->i_blocks < sectors)) { 2190dcbb4c10SJoe Perches f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu", 21915e159cd3SChao Yu inode->i_ino, 21925e159cd3SChao Yu (unsigned long long)inode->i_blocks, 21935e159cd3SChao Yu (unsigned long long)sectors); 21945e159cd3SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 21955e159cd3SChao Yu return; 21965e159cd3SChao Yu } 21970abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 219839a53e0cSJaegeuk Kim } 219939a53e0cSJaegeuk Kim 220039a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 220139a53e0cSJaegeuk Kim { 220235782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 22037c4abcbeSChao Yu 220420109873SChao Yu if (count_type == F2FS_DIRTY_DENTS || 220520109873SChao Yu count_type == F2FS_DIRTY_NODES || 220620109873SChao Yu count_type == F2FS_DIRTY_META || 220720109873SChao Yu count_type == F2FS_DIRTY_QDATA || 220820109873SChao Yu count_type == F2FS_DIRTY_IMETA) 2209caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 221039a53e0cSJaegeuk Kim } 221139a53e0cSJaegeuk Kim 2212a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 221339a53e0cSJaegeuk Kim { 2214204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 2215c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 2216c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 22172c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 22182c8a4a28SJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 221939a53e0cSJaegeuk Kim } 222039a53e0cSJaegeuk Kim 222139a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 222239a53e0cSJaegeuk Kim { 222335782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 222439a53e0cSJaegeuk Kim } 222539a53e0cSJaegeuk Kim 2226a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 222739a53e0cSJaegeuk Kim { 22285ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 22295ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 22301fe54f9dSJaegeuk Kim return; 22311fe54f9dSJaegeuk Kim 2232204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 2233c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 2234c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 22352c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 22362c8a4a28SJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 223739a53e0cSJaegeuk Kim } 223839a53e0cSJaegeuk Kim 2239523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 224039a53e0cSJaegeuk Kim { 224135782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 224239a53e0cSJaegeuk Kim } 224339a53e0cSJaegeuk Kim 2244204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 2245f8b2c1f9SJaegeuk Kim { 2246204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 2247f8b2c1f9SJaegeuk Kim } 2248f8b2c1f9SJaegeuk Kim 22495ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 22505ac206cfSNamjae Jeon { 22513519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 2252523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 2253523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 2254523be8a6SJaegeuk Kim 2255523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 22565ac206cfSNamjae Jeon } 22575ac206cfSNamjae Jeon 225839a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 225939a53e0cSJaegeuk Kim { 22608b8343faSJaegeuk Kim return sbi->total_valid_block_count; 226139a53e0cSJaegeuk Kim } 226239a53e0cSJaegeuk Kim 2263f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 2264f83a2584SYunlei He { 2265f83a2584SYunlei He return sbi->discard_blks; 2266f83a2584SYunlei He } 2267f83a2584SYunlei He 226839a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 226939a53e0cSJaegeuk Kim { 227039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 227139a53e0cSJaegeuk Kim 227239a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 227339a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 227439a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 227539a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 227639a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 227739a53e0cSJaegeuk Kim 227839a53e0cSJaegeuk Kim return 0; 227939a53e0cSJaegeuk Kim } 228039a53e0cSJaegeuk Kim 228155141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 228255141486SWanpeng Li { 228355141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 228455141486SWanpeng Li } 228555141486SWanpeng Li 228639a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 228739a53e0cSJaegeuk Kim { 228839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 22894260c406SGustavo A. R. Silva void *tmp_ptr = &ckpt->sit_nat_version_bitmap; 22901dbe4152SChangman Lee int offset; 22911dbe4152SChangman Lee 2292199bc3feSChao Yu if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { 2293199bc3feSChao Yu offset = (flag == SIT_BITMAP) ? 2294199bc3feSChao Yu le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; 2295b471eb99SChao Yu /* 2296b471eb99SChao Yu * if large_nat_bitmap feature is enabled, leave checksum 2297b471eb99SChao Yu * protection for all nat/sit bitmaps. 2298b471eb99SChao Yu */ 22994260c406SGustavo A. R. Silva return tmp_ptr + offset + sizeof(__le32); 2300199bc3feSChao Yu } 2301199bc3feSChao Yu 230255141486SWanpeng Li if (__cp_payload(sbi) > 0) { 23031dbe4152SChangman Lee if (flag == NAT_BITMAP) 23041dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 23051dbe4152SChangman Lee else 230665b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 23071dbe4152SChangman Lee } else { 23081dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 230925ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 23104260c406SGustavo A. R. Silva return tmp_ptr + offset; 231139a53e0cSJaegeuk Kim } 23121dbe4152SChangman Lee } 231339a53e0cSJaegeuk Kim 231439a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 231539a53e0cSJaegeuk Kim { 23168508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 231739a53e0cSJaegeuk Kim 23188508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 231939a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 232039a53e0cSJaegeuk Kim return start_addr; 232139a53e0cSJaegeuk Kim } 232239a53e0cSJaegeuk Kim 23238508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 23248508e44aSJaegeuk Kim { 23258508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 23268508e44aSJaegeuk Kim 23278508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 23288508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 23298508e44aSJaegeuk Kim return start_addr; 23308508e44aSJaegeuk Kim } 23318508e44aSJaegeuk Kim 23328508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 23338508e44aSJaegeuk Kim { 23348508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 23358508e44aSJaegeuk Kim } 23368508e44aSJaegeuk Kim 233739a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 233839a53e0cSJaegeuk Kim { 233939a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 234039a53e0cSJaegeuk Kim } 234139a53e0cSJaegeuk Kim 23420abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 2343000519f2SChao Yu struct inode *inode, bool is_inode) 234439a53e0cSJaegeuk Kim { 234539a53e0cSJaegeuk Kim block_t valid_block_count; 2346a4c3ecaaSDaniel Rosenberg unsigned int valid_node_count, user_block_count; 2347af033b2aSChao Yu int err; 23480abd675eSChao Yu 2349af033b2aSChao Yu if (is_inode) { 2350af033b2aSChao Yu if (inode) { 2351af033b2aSChao Yu err = dquot_alloc_inode(inode); 2352af033b2aSChao Yu if (err) 2353af033b2aSChao Yu return err; 2354af033b2aSChao Yu } 2355af033b2aSChao Yu } else { 2356af033b2aSChao Yu err = dquot_reserve_block(inode, 1); 2357af033b2aSChao Yu if (err) 2358af033b2aSChao Yu return err; 23590abd675eSChao Yu } 236039a53e0cSJaegeuk Kim 2361812c6056SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 2362c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_BLOCK); 2363812c6056SChao Yu goto enospc; 2364812c6056SChao Yu } 2365812c6056SChao Yu 236639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 236739a53e0cSJaegeuk Kim 23687e65be49SJaegeuk Kim valid_block_count = sbi->total_valid_block_count + 23697e65be49SJaegeuk Kim sbi->current_reserved_blocks + 1; 23707e65be49SJaegeuk Kim 2371a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, false)) 237263189b78SChao Yu valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; 2373a4c3ecaaSDaniel Rosenberg user_block_count = sbi->user_block_count; 23744354994fSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) 2375a4c3ecaaSDaniel Rosenberg user_block_count -= sbi->unusable_block_count; 23767e65be49SJaegeuk Kim 2377a4c3ecaaSDaniel Rosenberg if (unlikely(valid_block_count > user_block_count)) { 237839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 23790abd675eSChao Yu goto enospc; 238039a53e0cSJaegeuk Kim } 238139a53e0cSJaegeuk Kim 2382ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 2383cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 238439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 23850abd675eSChao Yu goto enospc; 238639a53e0cSJaegeuk Kim } 238739a53e0cSJaegeuk Kim 2388ef86d709SGu Zheng sbi->total_valid_node_count++; 2389ef86d709SGu Zheng sbi->total_valid_block_count++; 239039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 239139a53e0cSJaegeuk Kim 23920abd675eSChao Yu if (inode) { 23930abd675eSChao Yu if (is_inode) 23940abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 23950abd675eSChao Yu else 23960abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 23970abd675eSChao Yu } 23980abd675eSChao Yu 239941382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 24000abd675eSChao Yu return 0; 24010abd675eSChao Yu 24020abd675eSChao Yu enospc: 2403af033b2aSChao Yu if (is_inode) { 2404af033b2aSChao Yu if (inode) 2405af033b2aSChao Yu dquot_free_inode(inode); 2406af033b2aSChao Yu } else { 24070abd675eSChao Yu dquot_release_reservation_block(inode, 1); 2408af033b2aSChao Yu } 24090abd675eSChao Yu return -ENOSPC; 241039a53e0cSJaegeuk Kim } 241139a53e0cSJaegeuk Kim 241239a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 2413000519f2SChao Yu struct inode *inode, bool is_inode) 241439a53e0cSJaegeuk Kim { 241539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 241639a53e0cSJaegeuk Kim 24179850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 24189850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 241939a53e0cSJaegeuk Kim 2420ef86d709SGu Zheng sbi->total_valid_node_count--; 2421ef86d709SGu Zheng sbi->total_valid_block_count--; 242280d42145SYunlong Song if (sbi->reserved_blocks && 242380d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 242480d42145SYunlong Song sbi->current_reserved_blocks++; 242539a53e0cSJaegeuk Kim 242639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 24270abd675eSChao Yu 2428ea6d7e72SChao Yu if (is_inode) { 2429af033b2aSChao Yu dquot_free_inode(inode); 2430ea6d7e72SChao Yu } else { 2431ea6d7e72SChao Yu if (unlikely(inode->i_blocks == 0)) { 2432097a7686SChao Yu f2fs_warn(sbi, "dec_valid_node_count: inconsistent i_blocks, ino:%lu, iblocks:%llu", 2433ea6d7e72SChao Yu inode->i_ino, 2434ea6d7e72SChao Yu (unsigned long long)inode->i_blocks); 2435ea6d7e72SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 2436ea6d7e72SChao Yu return; 2437ea6d7e72SChao Yu } 24380abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 243939a53e0cSJaegeuk Kim } 2440ea6d7e72SChao Yu } 244139a53e0cSJaegeuk Kim 244239a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 244339a53e0cSJaegeuk Kim { 24448b8343faSJaegeuk Kim return sbi->total_valid_node_count; 244539a53e0cSJaegeuk Kim } 244639a53e0cSJaegeuk Kim 244739a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 244839a53e0cSJaegeuk Kim { 2449513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 245039a53e0cSJaegeuk Kim } 245139a53e0cSJaegeuk Kim 24520e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 245339a53e0cSJaegeuk Kim { 2454513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 245539a53e0cSJaegeuk Kim } 245639a53e0cSJaegeuk Kim 2457513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 245839a53e0cSJaegeuk Kim { 2459513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 246039a53e0cSJaegeuk Kim } 246139a53e0cSJaegeuk Kim 2462a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 2463a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 2464a56c7c6fSJaegeuk Kim { 246582cf4f13SChao Yu struct page *page; 2466cac5a3d8SDongOh Shin 24677fa750a1SArnd Bergmann if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) { 246882cf4f13SChao Yu if (!for_write) 246982cf4f13SChao Yu page = find_get_page_flags(mapping, index, 247082cf4f13SChao Yu FGP_LOCK | FGP_ACCESSED); 247182cf4f13SChao Yu else 247282cf4f13SChao Yu page = find_lock_page(mapping, index); 2473c41f3cc3SJaegeuk Kim if (page) 2474c41f3cc3SJaegeuk Kim return page; 2475c41f3cc3SJaegeuk Kim 247655523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 2477c45d6002SChao Yu f2fs_show_injection_info(F2FS_M_SB(mapping), 2478c45d6002SChao Yu FAULT_PAGE_ALLOC); 2479c41f3cc3SJaegeuk Kim return NULL; 248055523519SChao Yu } 24817fa750a1SArnd Bergmann } 24827fa750a1SArnd Bergmann 2483a56c7c6fSJaegeuk Kim if (!for_write) 2484a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 2485a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 2486a56c7c6fSJaegeuk Kim } 2487a56c7c6fSJaegeuk Kim 248801eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page( 248901eccef7SChao Yu struct address_space *mapping, pgoff_t index, 249001eccef7SChao Yu int fgp_flags, gfp_t gfp_mask) 249101eccef7SChao Yu { 249201eccef7SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { 2493c45d6002SChao Yu f2fs_show_injection_info(F2FS_M_SB(mapping), FAULT_PAGE_GET); 249401eccef7SChao Yu return NULL; 249501eccef7SChao Yu } 24967fa750a1SArnd Bergmann 249701eccef7SChao Yu return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); 249801eccef7SChao Yu } 249901eccef7SChao Yu 25006e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 25016e2c64adSJaegeuk Kim { 25026e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 25036e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 25046e2c64adSJaegeuk Kim 25056e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 25066e2c64adSJaegeuk Kim kunmap(dst); 25076e2c64adSJaegeuk Kim kunmap(src); 25086e2c64adSJaegeuk Kim } 25096e2c64adSJaegeuk Kim 251039a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 251139a53e0cSJaegeuk Kim { 2512031fa8ccSJaegeuk Kim if (!page) 251339a53e0cSJaegeuk Kim return; 251439a53e0cSJaegeuk Kim 251539a53e0cSJaegeuk Kim if (unlock) { 25169850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 251739a53e0cSJaegeuk Kim unlock_page(page); 251839a53e0cSJaegeuk Kim } 251909cbfeafSKirill A. Shutemov put_page(page); 252039a53e0cSJaegeuk Kim } 252139a53e0cSJaegeuk Kim 252239a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 252339a53e0cSJaegeuk Kim { 252439a53e0cSJaegeuk Kim if (dn->node_page) 252539a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 252639a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 252739a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 252839a53e0cSJaegeuk Kim dn->node_page = NULL; 252939a53e0cSJaegeuk Kim dn->inode_page = NULL; 253039a53e0cSJaegeuk Kim } 253139a53e0cSJaegeuk Kim 253239a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 2533e8512d2eSGu Zheng size_t size) 253439a53e0cSJaegeuk Kim { 2535e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 253639a53e0cSJaegeuk Kim } 253739a53e0cSJaegeuk Kim 25387bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 25397bd59381SGu Zheng gfp_t flags) 25407bd59381SGu Zheng { 25417bd59381SGu Zheng void *entry; 25427bd59381SGu Zheng 254380c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 254480c54505SJaegeuk Kim if (!entry) 254580c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 25467bd59381SGu Zheng return entry; 25477bd59381SGu Zheng } 25487bd59381SGu Zheng 2549493720a4SChao Yu static inline bool is_inflight_io(struct f2fs_sb_info *sbi, int type) 25505f9abab4SJaegeuk Kim { 25515f9abab4SJaegeuk Kim if (get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_RD_NODE) || 25525f9abab4SJaegeuk Kim get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) || 2553fef4129eSChao Yu get_pages(sbi, F2FS_WB_CP_DATA) || 2554fef4129eSChao Yu get_pages(sbi, F2FS_DIO_READ) || 255511ac8ef8SJaegeuk Kim get_pages(sbi, F2FS_DIO_WRITE)) 2556493720a4SChao Yu return true; 255711ac8ef8SJaegeuk Kim 255856659ce8SSahitya Tummala if (type != DISCARD_TIME && SM_I(sbi) && SM_I(sbi)->dcc_info && 255911ac8ef8SJaegeuk Kim atomic_read(&SM_I(sbi)->dcc_info->queued_discard)) 2560493720a4SChao Yu return true; 256111ac8ef8SJaegeuk Kim 256211ac8ef8SJaegeuk Kim if (SM_I(sbi) && SM_I(sbi)->fcc_info && 256372691af6SJaegeuk Kim atomic_read(&SM_I(sbi)->fcc_info->queued_flush)) 2564493720a4SChao Yu return true; 2565493720a4SChao Yu return false; 2566493720a4SChao Yu } 2567493720a4SChao Yu 2568493720a4SChao Yu static inline bool is_idle(struct f2fs_sb_info *sbi, int type) 2569493720a4SChao Yu { 2570493720a4SChao Yu if (sbi->gc_mode == GC_URGENT_HIGH) 2571493720a4SChao Yu return true; 2572493720a4SChao Yu 2573493720a4SChao Yu if (is_inflight_io(sbi, type)) 25745f9abab4SJaegeuk Kim return false; 257511ac8ef8SJaegeuk Kim 25760e5e8111SDaeho Jeong if (sbi->gc_mode == GC_URGENT_LOW && 25770e5e8111SDaeho Jeong (type == DISCARD_TIME || type == GC_TIME)) 25780e5e8111SDaeho Jeong return true; 25790e5e8111SDaeho Jeong 25805f9abab4SJaegeuk Kim return f2fs_time_over(sbi, type); 25815f9abab4SJaegeuk Kim } 25825f9abab4SJaegeuk Kim 25839be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 25849be32d72SJaegeuk Kim unsigned long index, void *item) 25859be32d72SJaegeuk Kim { 25869be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 25879be32d72SJaegeuk Kim cond_resched(); 25889be32d72SJaegeuk Kim } 25899be32d72SJaegeuk Kim 259039a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 259139a53e0cSJaegeuk Kim 259239a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 259339a53e0cSJaegeuk Kim { 259445590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 2595cac5a3d8SDongOh Shin 259639a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 259739a53e0cSJaegeuk Kim } 259839a53e0cSJaegeuk Kim 25997a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 26007a2af766SChao Yu { 26017a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 26027a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 26037a2af766SChao Yu } 26047a2af766SChao Yu 260539a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 260639a53e0cSJaegeuk Kim { 260739a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 260839a53e0cSJaegeuk Kim } 260939a53e0cSJaegeuk Kim 26107a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 2611a2ced1ceSChao Yu static inline block_t data_blkaddr(struct inode *inode, 26127a2af766SChao Yu struct page *node_page, unsigned int offset) 261339a53e0cSJaegeuk Kim { 261439a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 261539a53e0cSJaegeuk Kim __le32 *addr_array; 26167a2af766SChao Yu int base = 0; 26177a2af766SChao Yu bool is_inode = IS_INODE(node_page); 2618cac5a3d8SDongOh Shin 261945590710SGu Zheng raw_node = F2FS_NODE(node_page); 26207a2af766SChao Yu 2621979f492fSLiFan if (is_inode) { 2622979f492fSLiFan if (!inode) 26237a88ddb5SChao Yu /* from GC path only */ 26247a2af766SChao Yu base = offset_in_addr(&raw_node->i); 2625979f492fSLiFan else if (f2fs_has_extra_attr(inode)) 26267a2af766SChao Yu base = get_extra_isize(inode); 26277a2af766SChao Yu } 26287a2af766SChao Yu 262939a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 26307a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 263139a53e0cSJaegeuk Kim } 263239a53e0cSJaegeuk Kim 2633a2ced1ceSChao Yu static inline block_t f2fs_data_blkaddr(struct dnode_of_data *dn) 2634a2ced1ceSChao Yu { 2635a2ced1ceSChao Yu return data_blkaddr(dn->inode, dn->node_page, dn->ofs_in_node); 2636a2ced1ceSChao Yu } 2637a2ced1ceSChao Yu 263839a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 263939a53e0cSJaegeuk Kim { 264039a53e0cSJaegeuk Kim int mask; 264139a53e0cSJaegeuk Kim 264239a53e0cSJaegeuk Kim addr += (nr >> 3); 264339a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 264439a53e0cSJaegeuk Kim return mask & *addr; 264539a53e0cSJaegeuk Kim } 264639a53e0cSJaegeuk Kim 2647a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 2648a66cdd98SJaegeuk Kim { 2649a66cdd98SJaegeuk Kim int mask; 2650a66cdd98SJaegeuk Kim 2651a66cdd98SJaegeuk Kim addr += (nr >> 3); 2652a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2653a66cdd98SJaegeuk Kim *addr |= mask; 2654a66cdd98SJaegeuk Kim } 2655a66cdd98SJaegeuk Kim 2656a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 2657a66cdd98SJaegeuk Kim { 2658a66cdd98SJaegeuk Kim int mask; 2659a66cdd98SJaegeuk Kim 2660a66cdd98SJaegeuk Kim addr += (nr >> 3); 2661a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2662a66cdd98SJaegeuk Kim *addr &= ~mask; 2663a66cdd98SJaegeuk Kim } 2664a66cdd98SJaegeuk Kim 266552aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 266639a53e0cSJaegeuk Kim { 266739a53e0cSJaegeuk Kim int mask; 266839a53e0cSJaegeuk Kim int ret; 266939a53e0cSJaegeuk Kim 267039a53e0cSJaegeuk Kim addr += (nr >> 3); 267139a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 267239a53e0cSJaegeuk Kim ret = mask & *addr; 267339a53e0cSJaegeuk Kim *addr |= mask; 267439a53e0cSJaegeuk Kim return ret; 267539a53e0cSJaegeuk Kim } 267639a53e0cSJaegeuk Kim 267752aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 267839a53e0cSJaegeuk Kim { 267939a53e0cSJaegeuk Kim int mask; 268039a53e0cSJaegeuk Kim int ret; 268139a53e0cSJaegeuk Kim 268239a53e0cSJaegeuk Kim addr += (nr >> 3); 268339a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 268439a53e0cSJaegeuk Kim ret = mask & *addr; 268539a53e0cSJaegeuk Kim *addr &= ~mask; 268639a53e0cSJaegeuk Kim return ret; 268739a53e0cSJaegeuk Kim } 268839a53e0cSJaegeuk Kim 2689c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 2690c6ac4c0eSGu Zheng { 2691c6ac4c0eSGu Zheng int mask; 2692c6ac4c0eSGu Zheng 2693c6ac4c0eSGu Zheng addr += (nr >> 3); 2694c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 2695c6ac4c0eSGu Zheng *addr ^= mask; 2696c6ac4c0eSGu Zheng } 2697c6ac4c0eSGu Zheng 269859c84408SChao Yu /* 269936098557SEric Biggers * On-disk inode flags (f2fs_inode::i_flags) 270059c84408SChao Yu */ 27014c8ff709SChao Yu #define F2FS_COMPR_FL 0x00000004 /* Compress file */ 270259c84408SChao Yu #define F2FS_SYNC_FL 0x00000008 /* Synchronous updates */ 270359c84408SChao Yu #define F2FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ 270459c84408SChao Yu #define F2FS_APPEND_FL 0x00000020 /* writes to file may only append */ 270559c84408SChao Yu #define F2FS_NODUMP_FL 0x00000040 /* do not dump file */ 270659c84408SChao Yu #define F2FS_NOATIME_FL 0x00000080 /* do not update atime */ 27074c8ff709SChao Yu #define F2FS_NOCOMP_FL 0x00000400 /* Don't compress */ 270859c84408SChao Yu #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ 270959c84408SChao Yu #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 271059c84408SChao Yu #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 27112c2eb7a3SDaniel Rosenberg #define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */ 271259c84408SChao Yu 271359c84408SChao Yu /* Flags that should be inherited by new inodes from their parent. */ 271436098557SEric Biggers #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \ 27152c2eb7a3SDaniel Rosenberg F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 27164c8ff709SChao Yu F2FS_CASEFOLD_FL | F2FS_COMPR_FL | F2FS_NOCOMP_FL) 271759c84408SChao Yu 271859c84408SChao Yu /* Flags that are appropriate for regular files (all but dir-specific ones). */ 27192c2eb7a3SDaniel Rosenberg #define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 27202c2eb7a3SDaniel Rosenberg F2FS_CASEFOLD_FL)) 272159c84408SChao Yu 272259c84408SChao Yu /* Flags that are appropriate for non-directories/regular files. */ 272359c84408SChao Yu #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL) 27245c57132eSChao Yu 27255c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 27265c57132eSChao Yu { 27275c57132eSChao Yu if (S_ISDIR(mode)) 27285c57132eSChao Yu return flags; 27295c57132eSChao Yu else if (S_ISREG(mode)) 27305c57132eSChao Yu return flags & F2FS_REG_FLMASK; 27315c57132eSChao Yu else 27325c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 27335c57132eSChao Yu } 27345c57132eSChao Yu 2735205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2736205b9822SJaegeuk Kim int flag, bool set) 273739a53e0cSJaegeuk Kim { 2738205b9822SJaegeuk Kim switch (flag) { 2739205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2740205b9822SJaegeuk Kim case FI_INLINE_DATA: 2741205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 27429ac1e2d8SDaeho Jeong case FI_NEW_INODE: 2743205b9822SJaegeuk Kim if (set) 2744205b9822SJaegeuk Kim return; 2745df561f66SGustavo A. R. Silva fallthrough; 2746205b9822SJaegeuk Kim case FI_DATA_EXIST: 2747205b9822SJaegeuk Kim case FI_INLINE_DOTS: 27481ad71a27SJaegeuk Kim case FI_PIN_FILE: 27497c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2750205b9822SJaegeuk Kim } 275139a53e0cSJaegeuk Kim } 275239a53e0cSJaegeuk Kim 275391942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 275439a53e0cSJaegeuk Kim { 275558f7e00fSYufen Yu set_bit(flag, F2FS_I(inode)->flags); 2756205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 275739a53e0cSJaegeuk Kim } 275839a53e0cSJaegeuk Kim 275991942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 276039a53e0cSJaegeuk Kim { 27617653b9d8SChao Yu return test_bit(flag, F2FS_I(inode)->flags); 276239a53e0cSJaegeuk Kim } 276339a53e0cSJaegeuk Kim 276491942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 276539a53e0cSJaegeuk Kim { 276658f7e00fSYufen Yu clear_bit(flag, F2FS_I(inode)->flags); 2767205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 276839a53e0cSJaegeuk Kim } 276939a53e0cSJaegeuk Kim 277095ae251fSEric Biggers static inline bool f2fs_verity_in_progress(struct inode *inode) 277195ae251fSEric Biggers { 277295ae251fSEric Biggers return IS_ENABLED(CONFIG_FS_VERITY) && 277395ae251fSEric Biggers is_inode_flag_set(inode, FI_VERITY_IN_PROGRESS); 277495ae251fSEric Biggers } 277595ae251fSEric Biggers 277691942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2777444c580fSJaegeuk Kim { 277891942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 277991942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 27807c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 278139a53e0cSJaegeuk Kim } 278239a53e0cSJaegeuk Kim 2783a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2784a1961246SJaegeuk Kim { 2785a1961246SJaegeuk Kim if (inc) 2786a1961246SJaegeuk Kim inc_nlink(inode); 2787a1961246SJaegeuk Kim else 2788a1961246SJaegeuk Kim drop_nlink(inode); 27897c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2790a1961246SJaegeuk Kim } 2791a1961246SJaegeuk Kim 27928edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 27930abd675eSChao Yu block_t diff, bool add, bool claim) 27948edd03c8SJaegeuk Kim { 279526de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 279626de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 279726de9b11SJaegeuk Kim 27980abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 27990abd675eSChao Yu if (add) { 28000abd675eSChao Yu if (claim) 28010abd675eSChao Yu dquot_claim_block(inode, diff); 28020abd675eSChao Yu else 28030abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 28040abd675eSChao Yu } else { 28050abd675eSChao Yu dquot_free_block(inode, diff); 28060abd675eSChao Yu } 28070abd675eSChao Yu 28087c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 280926de9b11SJaegeuk Kim if (clean || recover) 281026de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 28118edd03c8SJaegeuk Kim } 28128edd03c8SJaegeuk Kim 2813fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2814fc9581c8SJaegeuk Kim { 281526de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 281626de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 281726de9b11SJaegeuk Kim 2818fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2819fc9581c8SJaegeuk Kim return; 2820fc9581c8SJaegeuk Kim 2821fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 28227c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 282326de9b11SJaegeuk Kim if (clean || recover) 282426de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 282526de9b11SJaegeuk Kim } 282626de9b11SJaegeuk Kim 2827205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2828205b9822SJaegeuk Kim { 2829205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 28307c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2831205b9822SJaegeuk Kim } 2832205b9822SJaegeuk Kim 28331ad71a27SJaegeuk Kim static inline void f2fs_i_gc_failures_write(struct inode *inode, 28341ad71a27SJaegeuk Kim unsigned int count) 28351ad71a27SJaegeuk Kim { 28362ef79ecbSChao Yu F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count; 28371ad71a27SJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 28381ad71a27SJaegeuk Kim } 28391ad71a27SJaegeuk Kim 2840205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2841205b9822SJaegeuk Kim { 2842205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 28437c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2844205b9822SJaegeuk Kim } 2845205b9822SJaegeuk Kim 2846205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2847205b9822SJaegeuk Kim { 2848205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 28497c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2850205b9822SJaegeuk Kim } 2851205b9822SJaegeuk Kim 285291942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2853444c580fSJaegeuk Kim { 2854205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2855205b9822SJaegeuk Kim 2856444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 28577653b9d8SChao Yu set_bit(FI_INLINE_XATTR, fi->flags); 28581001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 28597653b9d8SChao Yu set_bit(FI_INLINE_DATA, fi->flags); 286034d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 28617653b9d8SChao Yu set_bit(FI_INLINE_DENTRY, fi->flags); 2862b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 28637653b9d8SChao Yu set_bit(FI_DATA_EXIST, fi->flags); 2864510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 28657653b9d8SChao Yu set_bit(FI_INLINE_DOTS, fi->flags); 28667a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 28677653b9d8SChao Yu set_bit(FI_EXTRA_ATTR, fi->flags); 28681ad71a27SJaegeuk Kim if (ri->i_inline & F2FS_PIN_FILE) 28697653b9d8SChao Yu set_bit(FI_PIN_FILE, fi->flags); 2870444c580fSJaegeuk Kim } 2871444c580fSJaegeuk Kim 287291942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2873444c580fSJaegeuk Kim { 2874444c580fSJaegeuk Kim ri->i_inline = 0; 2875444c580fSJaegeuk Kim 287691942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2877444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 287891942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 28791001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 288091942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 288134d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 288291942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2883b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 288491942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2885510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 28867a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 28877a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 28881ad71a27SJaegeuk Kim if (is_inode_flag_set(inode, FI_PIN_FILE)) 28891ad71a27SJaegeuk Kim ri->i_inline |= F2FS_PIN_FILE; 28907a2af766SChao Yu } 28917a2af766SChao Yu 28927a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 28937a2af766SChao Yu { 28947a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2895444c580fSJaegeuk Kim } 2896444c580fSJaegeuk Kim 2897987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2898987c7c31SChao Yu { 289991942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2900987c7c31SChao Yu } 2901987c7c31SChao Yu 29024c8ff709SChao Yu static inline int f2fs_compressed_file(struct inode *inode) 29034c8ff709SChao Yu { 29044c8ff709SChao Yu return S_ISREG(inode->i_mode) && 29054c8ff709SChao Yu is_inode_flag_set(inode, FI_COMPRESSED_FILE); 29064c8ff709SChao Yu } 29074c8ff709SChao Yu 2908602a16d5SDaeho Jeong static inline bool f2fs_need_compress_data(struct inode *inode) 2909602a16d5SDaeho Jeong { 2910602a16d5SDaeho Jeong int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; 2911602a16d5SDaeho Jeong 2912602a16d5SDaeho Jeong if (!f2fs_compressed_file(inode)) 2913602a16d5SDaeho Jeong return false; 2914602a16d5SDaeho Jeong 2915602a16d5SDaeho Jeong if (compress_mode == COMPR_MODE_FS) 2916602a16d5SDaeho Jeong return true; 2917602a16d5SDaeho Jeong else if (compress_mode == COMPR_MODE_USER && 2918602a16d5SDaeho Jeong is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) 2919602a16d5SDaeho Jeong return true; 2920602a16d5SDaeho Jeong 2921602a16d5SDaeho Jeong return false; 2922602a16d5SDaeho Jeong } 2923602a16d5SDaeho Jeong 292481ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2925de93653fSJaegeuk Kim { 2926d02a6e61SChao Yu unsigned int addrs = CUR_ADDRS_PER_INODE(inode) - 2927d02a6e61SChao Yu get_inline_xattr_addrs(inode); 29284c8ff709SChao Yu 29294c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 29304c8ff709SChao Yu return addrs; 29314c8ff709SChao Yu return ALIGN_DOWN(addrs, F2FS_I(inode)->i_cluster_size); 2932d02a6e61SChao Yu } 2933d02a6e61SChao Yu 2934d02a6e61SChao Yu static inline unsigned int addrs_per_block(struct inode *inode) 2935d02a6e61SChao Yu { 29364c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 29374c8ff709SChao Yu return DEF_ADDRS_PER_BLOCK; 29384c8ff709SChao Yu return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, F2FS_I(inode)->i_cluster_size); 2939de93653fSJaegeuk Kim } 2940de93653fSJaegeuk Kim 29416afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page) 294265985d93SJaegeuk Kim { 2943695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2944cac5a3d8SDongOh Shin 294565985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 2946b323fd28SChao Yu get_inline_xattr_addrs(inode)]); 294765985d93SJaegeuk Kim } 294865985d93SJaegeuk Kim 294965985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 295065985d93SJaegeuk Kim { 2951622927f3SChao Yu if (f2fs_has_inline_xattr(inode)) 29526afc662eSChao Yu return get_inline_xattr_addrs(inode) * sizeof(__le32); 2953622927f3SChao Yu return 0; 295465985d93SJaegeuk Kim } 295565985d93SJaegeuk Kim 29560dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 29570dbdc2aeSJaegeuk Kim { 295891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 29590dbdc2aeSJaegeuk Kim } 29600dbdc2aeSJaegeuk Kim 2961b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2962b3d208f9SJaegeuk Kim { 296391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2964b3d208f9SJaegeuk Kim } 2965b3d208f9SJaegeuk Kim 2966510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2967510022a8SJaegeuk Kim { 296891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2969510022a8SJaegeuk Kim } 2970510022a8SJaegeuk Kim 29714c8ff709SChao Yu static inline int f2fs_is_mmap_file(struct inode *inode) 29724c8ff709SChao Yu { 29734c8ff709SChao Yu return is_inode_flag_set(inode, FI_MMAP_FILE); 29744c8ff709SChao Yu } 29754c8ff709SChao Yu 29761ad71a27SJaegeuk Kim static inline bool f2fs_is_pinned_file(struct inode *inode) 29771ad71a27SJaegeuk Kim { 29781ad71a27SJaegeuk Kim return is_inode_flag_set(inode, FI_PIN_FILE); 29791ad71a27SJaegeuk Kim } 29801ad71a27SJaegeuk Kim 298188b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 298288b88a66SJaegeuk Kim { 298391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 298488b88a66SJaegeuk Kim } 298588b88a66SJaegeuk Kim 29865fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 29875fe45743SChao Yu { 29885fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 29895fe45743SChao Yu } 29905fe45743SChao Yu 299102a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 299202a1335fSJaegeuk Kim { 299391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 299402a1335fSJaegeuk Kim } 299502a1335fSJaegeuk Kim 29963c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 29973c6c2bebSJaegeuk Kim { 299891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 29993c6c2bebSJaegeuk Kim } 30003c6c2bebSJaegeuk Kim 30011e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 30021e84371fSJaegeuk Kim { 300391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 30041e84371fSJaegeuk Kim } 30051e84371fSJaegeuk Kim 3006f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 30071001b347SHuajun Li { 3008695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 30097a2af766SChao Yu int extra_size = get_extra_isize(inode); 3010cac5a3d8SDongOh Shin 30117a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 30121001b347SHuajun Li } 30131001b347SHuajun Li 301434d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 301534d67debSChao Yu { 301691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 301734d67debSChao Yu } 301834d67debSChao Yu 3019b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 3020b5492af7SJaegeuk Kim { 3021b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 3022b5492af7SJaegeuk Kim } 3023b5492af7SJaegeuk Kim 3024b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 3025b5492af7SJaegeuk Kim { 3026b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 30277c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 3028b5492af7SJaegeuk Kim } 3029b5492af7SJaegeuk Kim 3030b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 3031b5492af7SJaegeuk Kim { 3032b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 30337c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 3034b5492af7SJaegeuk Kim } 3035b5492af7SJaegeuk Kim 3036fe1897eaSChao Yu static inline bool f2fs_is_time_consistent(struct inode *inode) 3037fe1897eaSChao Yu { 3038fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime)) 3039fe1897eaSChao Yu return false; 3040fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime)) 3041fe1897eaSChao Yu return false; 3042fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime)) 3043fe1897eaSChao Yu return false; 3044fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3, 3045fe1897eaSChao Yu &F2FS_I(inode)->i_crtime)) 3046fe1897eaSChao Yu return false; 3047fe1897eaSChao Yu return true; 3048fe1897eaSChao Yu } 3049fe1897eaSChao Yu 305026787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 305126787236SJaegeuk Kim { 3052a0d00fadSChao Yu bool ret; 3053a0d00fadSChao Yu 305426787236SJaegeuk Kim if (dsync) { 305526787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 305626787236SJaegeuk Kim 305726787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 305826787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 305926787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 306026787236SJaegeuk Kim return ret; 306126787236SJaegeuk Kim } 306226787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 306326787236SJaegeuk Kim file_keep_isize(inode) || 3064235831d7SJunling Zheng i_size_read(inode) & ~PAGE_MASK) 306526787236SJaegeuk Kim return false; 3066a0d00fadSChao Yu 3067fe1897eaSChao Yu if (!f2fs_is_time_consistent(inode)) 3068214c2461SJaegeuk Kim return false; 3069214c2461SJaegeuk Kim 3070c10c9820SChao Yu spin_lock(&F2FS_I(inode)->i_size_lock); 3071a0d00fadSChao Yu ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 3072c10c9820SChao Yu spin_unlock(&F2FS_I(inode)->i_size_lock); 3073a0d00fadSChao Yu 3074a0d00fadSChao Yu return ret; 3075267378d4SChao Yu } 3076267378d4SChao Yu 3077deeedd71SChao Yu static inline bool f2fs_readonly(struct super_block *sb) 307877888c1eSJaegeuk Kim { 3079deeedd71SChao Yu return sb_rdonly(sb); 308077888c1eSJaegeuk Kim } 308177888c1eSJaegeuk Kim 3082744602cfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 3083744602cfSJaegeuk Kim { 3084aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 3085744602cfSJaegeuk Kim } 3086744602cfSJaegeuk Kim 308743c780baSEric Biggers static inline bool is_dot_dotdot(const u8 *name, size_t len) 3088eaa693f4SJaegeuk Kim { 308943c780baSEric Biggers if (len == 1 && name[0] == '.') 3090eaa693f4SJaegeuk Kim return true; 3091eaa693f4SJaegeuk Kim 309243c780baSEric Biggers if (len == 2 && name[0] == '.' && name[1] == '.') 3093eaa693f4SJaegeuk Kim return true; 3094eaa693f4SJaegeuk Kim 3095eaa693f4SJaegeuk Kim return false; 3096eaa693f4SJaegeuk Kim } 3097eaa693f4SJaegeuk Kim 30983e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 30993e72f721SJaegeuk Kim { 3100e4589fa5SSahitya Tummala struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3101e4589fa5SSahitya Tummala 3102e4589fa5SSahitya Tummala if (!test_opt(sbi, EXTENT_CACHE) || 31034c8ff709SChao Yu is_inode_flag_set(inode, FI_NO_EXTENT) || 31044c8ff709SChao Yu is_inode_flag_set(inode, FI_COMPRESSED_FILE)) 31053e72f721SJaegeuk Kim return false; 31063e72f721SJaegeuk Kim 3107e4589fa5SSahitya Tummala /* 3108e4589fa5SSahitya Tummala * for recovered files during mount do not create extents 3109e4589fa5SSahitya Tummala * if shrinker is not registered. 3110e4589fa5SSahitya Tummala */ 3111e4589fa5SSahitya Tummala if (list_empty(&sbi->s_list)) 3112e4589fa5SSahitya Tummala return false; 3113e4589fa5SSahitya Tummala 3114886f56f9SAl Viro return S_ISREG(inode->i_mode); 31153e72f721SJaegeuk Kim } 31163e72f721SJaegeuk Kim 31171ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 31181ecc0c5cSChao Yu size_t size, gfp_t flags) 31190414b004SJaegeuk Kim { 312055523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 3121c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_KMALLOC); 31222c63feadSJaegeuk Kim return NULL; 312355523519SChao Yu } 31247fa750a1SArnd Bergmann 31250b6d4ca0SEric Biggers return kmalloc(size, flags); 31260414b004SJaegeuk Kim } 31270414b004SJaegeuk Kim 3128acbf054dSChao Yu static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, 3129acbf054dSChao Yu size_t size, gfp_t flags) 3130acbf054dSChao Yu { 3131acbf054dSChao Yu return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); 3132acbf054dSChao Yu } 3133acbf054dSChao Yu 3134628b3d14SChao Yu static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, 3135628b3d14SChao Yu size_t size, gfp_t flags) 3136628b3d14SChao Yu { 3137628b3d14SChao Yu if (time_to_inject(sbi, FAULT_KVMALLOC)) { 3138c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_KVMALLOC); 3139628b3d14SChao Yu return NULL; 3140628b3d14SChao Yu } 31417fa750a1SArnd Bergmann 3142628b3d14SChao Yu return kvmalloc(size, flags); 3143628b3d14SChao Yu } 3144628b3d14SChao Yu 3145628b3d14SChao Yu static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi, 3146628b3d14SChao Yu size_t size, gfp_t flags) 3147628b3d14SChao Yu { 3148628b3d14SChao Yu return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO); 3149628b3d14SChao Yu } 3150628b3d14SChao Yu 31517a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 3152f2470371SChao Yu { 31537a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 3154f2470371SChao Yu } 3155f2470371SChao Yu 31566afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode) 31576afc662eSChao Yu { 31586afc662eSChao Yu return F2FS_I(inode)->i_inline_xattr_size; 31596afc662eSChao Yu } 31606afc662eSChao Yu 31614d57b86dSChao Yu #define f2fs_get_inode_mode(i) \ 316291942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 3163a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 3164a6dda0e6SChristoph Hellwig 31657a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 31667a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 31677a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 31687a2af766SChao Yu 31695c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 31705c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 31712f84babfSSheng Yong ((offsetof(typeof(*(f2fs_inode)), field) + \ 31725c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 31732f84babfSSheng Yong <= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize))) \ 31745c57132eSChao Yu 31752bc4bea3SDaeho Jeong #define DEFAULT_IOSTAT_PERIOD_MS 3000 31762bc4bea3SDaeho Jeong #define MIN_IOSTAT_PERIOD_MS 100 31772bc4bea3SDaeho Jeong /* maximum period of iostat tracing is 1 day */ 31782bc4bea3SDaeho Jeong #define MAX_IOSTAT_PERIOD_MS 8640000 31792bc4bea3SDaeho Jeong 3180b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 3181b0af6d49SChao Yu { 3182b0af6d49SChao Yu int i; 3183b0af6d49SChao Yu 3184b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 31852bc4bea3SDaeho Jeong for (i = 0; i < NR_IO_TYPE; i++) { 31868b83ac81SChao Yu sbi->rw_iostat[i] = 0; 31878b83ac81SChao Yu sbi->prev_rw_iostat[i] = 0; 31882bc4bea3SDaeho Jeong } 3189b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 3190b0af6d49SChao Yu } 3191b0af6d49SChao Yu 31922bc4bea3SDaeho Jeong extern void f2fs_record_iostat(struct f2fs_sb_info *sbi); 31932bc4bea3SDaeho Jeong 3194b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 3195b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 3196b0af6d49SChao Yu { 3197b0af6d49SChao Yu if (!sbi->iostat_enable) 3198b0af6d49SChao Yu return; 3199b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 32008b83ac81SChao Yu sbi->rw_iostat[type] += io_bytes; 3201b0af6d49SChao Yu 3202b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 32038b83ac81SChao Yu sbi->rw_iostat[APP_BUFFERED_IO] = 32048b83ac81SChao Yu sbi->rw_iostat[APP_WRITE_IO] - 32058b83ac81SChao Yu sbi->rw_iostat[APP_DIRECT_IO]; 32068b83ac81SChao Yu 32078b83ac81SChao Yu if (type == APP_READ_IO || type == APP_DIRECT_READ_IO) 32088b83ac81SChao Yu sbi->rw_iostat[APP_BUFFERED_READ_IO] = 32098b83ac81SChao Yu sbi->rw_iostat[APP_READ_IO] - 32108b83ac81SChao Yu sbi->rw_iostat[APP_DIRECT_READ_IO]; 3211b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 32122bc4bea3SDaeho Jeong 32132bc4bea3SDaeho Jeong f2fs_record_iostat(sbi); 3214b0af6d49SChao Yu } 3215b0af6d49SChao Yu 32162c70c5e3SChao Yu #define __is_large_section(sbi) ((sbi)->segs_per_sec > 1) 32172c70c5e3SChao Yu 32186dc3a126SChao Yu #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META) 3219c9b60788SChao Yu 3220e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 3221e1da7872SChao Yu block_t blkaddr, int type); 3222e1da7872SChao Yu static inline void verify_blkaddr(struct f2fs_sb_info *sbi, 3223e1da7872SChao Yu block_t blkaddr, int type) 3224e1da7872SChao Yu { 3225e1da7872SChao Yu if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) { 3226dcbb4c10SJoe Perches f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.", 3227e1da7872SChao Yu blkaddr, type); 3228e1da7872SChao Yu f2fs_bug_on(sbi, 1); 3229e1da7872SChao Yu } 3230e1da7872SChao Yu } 3231e1da7872SChao Yu 3232e1da7872SChao Yu static inline bool __is_valid_data_blkaddr(block_t blkaddr) 32337b525dd0SChao Yu { 32344c8ff709SChao Yu if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR || 32354c8ff709SChao Yu blkaddr == COMPRESS_ADDR) 32367b525dd0SChao Yu return false; 32377b525dd0SChao Yu return true; 32387b525dd0SChao Yu } 32397b525dd0SChao Yu 324039a53e0cSJaegeuk Kim /* 324139a53e0cSJaegeuk Kim * file.c 324239a53e0cSJaegeuk Kim */ 3243cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 32444d57b86dSChao Yu void f2fs_truncate_data_blocks(struct dnode_of_data *dn); 32453265d3dbSChao Yu int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock); 3246c42d28ceSChao Yu int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock); 3247cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 3248549c7297SChristian Brauner int f2fs_getattr(struct user_namespace *mnt_userns, const struct path *path, 3249549c7297SChristian Brauner struct kstat *stat, u32 request_mask, unsigned int flags); 3250549c7297SChristian Brauner int f2fs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, 3251549c7297SChristian Brauner struct iattr *attr); 32524d57b86dSChao Yu int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 32534d57b86dSChao Yu void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); 3254c4020b2dSChao Yu int f2fs_precache_extents(struct inode *inode); 32559b1bb01cSMiklos Szeredi int f2fs_fileattr_get(struct dentry *dentry, struct fileattr *fa); 32569b1bb01cSMiklos Szeredi int f2fs_fileattr_set(struct user_namespace *mnt_userns, 32579b1bb01cSMiklos Szeredi struct dentry *dentry, struct fileattr *fa); 3258cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 3259cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 326078130819SChao Yu int f2fs_transfer_project_quota(struct inode *inode, kprojid_t kprojid); 32611ad71a27SJaegeuk Kim int f2fs_pin_file_control(struct inode *inode, bool inc); 326239a53e0cSJaegeuk Kim 326339a53e0cSJaegeuk Kim /* 326439a53e0cSJaegeuk Kim * inode.c 326539a53e0cSJaegeuk Kim */ 3266cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 3267704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 3268704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 3269cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 3270cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 32714d57b86dSChao Yu int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 32724d57b86dSChao Yu void f2fs_update_inode(struct inode *inode, struct page *node_page); 32734d57b86dSChao Yu void f2fs_update_inode_page(struct inode *inode); 3274cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 3275cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 32764d57b86dSChao Yu void f2fs_handle_failed_inode(struct inode *inode); 327739a53e0cSJaegeuk Kim 327839a53e0cSJaegeuk Kim /* 327939a53e0cSJaegeuk Kim * namei.c 328039a53e0cSJaegeuk Kim */ 32814d57b86dSChao Yu int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, 3282b6a06cbbSChao Yu bool hot, bool set); 328339a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 328439a53e0cSJaegeuk Kim 328539a53e0cSJaegeuk Kim /* 328639a53e0cSJaegeuk Kim * dir.c 328739a53e0cSJaegeuk Kim */ 32884d57b86dSChao Yu unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de); 328943c780baSEric Biggers int f2fs_init_casefolded_name(const struct inode *dir, 329043c780baSEric Biggers struct f2fs_filename *fname); 329143c780baSEric Biggers int f2fs_setup_filename(struct inode *dir, const struct qstr *iname, 329243c780baSEric Biggers int lookup, struct f2fs_filename *fname); 329343c780baSEric Biggers int f2fs_prepare_lookup(struct inode *dir, struct dentry *dentry, 329443c780baSEric Biggers struct f2fs_filename *fname); 329543c780baSEric Biggers void f2fs_free_filename(struct f2fs_filename *fname); 329643c780baSEric Biggers struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_ptr *d, 329743c780baSEric Biggers const struct f2fs_filename *fname, int *max_slots); 3298cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 3299cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 33004d57b86dSChao Yu void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent, 3301cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 33024d57b86dSChao Yu struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir, 330343c780baSEric Biggers const struct f2fs_filename *fname, struct page *dpage); 33044d57b86dSChao Yu void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode, 3305cac5a3d8SDongOh Shin unsigned int current_depth); 33064d57b86dSChao Yu int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots); 3307cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 3308cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 330943c780baSEric Biggers const struct f2fs_filename *fname, 331043c780baSEric Biggers struct page **res_page); 3311cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 3312cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 3313cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 3314cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 3315cac5a3d8SDongOh Shin struct page **page); 3316cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 3317cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 3318b06af2afSJaegeuk Kim bool f2fs_has_enough_room(struct inode *dir, struct page *ipage, 331943c780baSEric Biggers const struct f2fs_filename *fname); 3320cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 332143c780baSEric Biggers const struct fscrypt_str *name, f2fs_hash_t name_hash, 3322cac5a3d8SDongOh Shin unsigned int bit_pos); 332343c780baSEric Biggers int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname, 3324cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 332543c780baSEric Biggers int f2fs_add_dentry(struct inode *dir, const struct f2fs_filename *fname, 3326cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 33274d57b86dSChao Yu int f2fs_do_add_link(struct inode *dir, const struct qstr *name, 3328cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 3329cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 3330cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 3331cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 3332cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 333339a53e0cSJaegeuk Kim 3334b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 3335b7f7a5e0SAl Viro { 3336bfc2b7e8SEric Biggers if (fscrypt_is_nokey_name(dentry)) 3337bfc2b7e8SEric Biggers return -ENOKEY; 33384d57b86dSChao Yu return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name, 3339510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 3340b7f7a5e0SAl Viro } 3341b7f7a5e0SAl Viro 334239a53e0cSJaegeuk Kim /* 334339a53e0cSJaegeuk Kim * super.c 334439a53e0cSJaegeuk Kim */ 3345cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 3346cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 3347ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); 3348af033b2aSChao Yu int f2fs_quota_sync(struct super_block *sb, int type); 33496d1451bfSChengguang Xu loff_t max_file_blocks(struct inode *inode); 33504b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 3351cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 3352cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 33534d57b86dSChao Yu int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); 335439a53e0cSJaegeuk Kim 335539a53e0cSJaegeuk Kim /* 335639a53e0cSJaegeuk Kim * hash.c 335739a53e0cSJaegeuk Kim */ 335843c780baSEric Biggers void f2fs_hash_filename(const struct inode *dir, struct f2fs_filename *fname); 335939a53e0cSJaegeuk Kim 336039a53e0cSJaegeuk Kim /* 336139a53e0cSJaegeuk Kim * node.c 336239a53e0cSJaegeuk Kim */ 336339a53e0cSJaegeuk Kim struct node_info; 336439a53e0cSJaegeuk Kim 33654d57b86dSChao Yu int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid); 33664d57b86dSChao Yu bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type); 336750fa53ecSChao Yu bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page); 336850fa53ecSChao Yu void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi); 336950fa53ecSChao Yu void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page); 337050fa53ecSChao Yu void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi); 33714d57b86dSChao Yu int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 33724d57b86dSChao Yu bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 33734d57b86dSChao Yu bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 33747735730dSChao Yu int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, 33754d57b86dSChao Yu struct node_info *ni); 33764d57b86dSChao Yu pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 33774d57b86dSChao Yu int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 33784d57b86dSChao Yu int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from); 33794d57b86dSChao Yu int f2fs_truncate_xattr_node(struct inode *inode); 338050fa53ecSChao Yu int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, 338150fa53ecSChao Yu unsigned int seq_id); 33824d57b86dSChao Yu int f2fs_remove_inode_page(struct inode *inode); 33834d57b86dSChao Yu struct page *f2fs_new_inode_page(struct inode *inode); 33844d57b86dSChao Yu struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs); 33854d57b86dSChao Yu void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 33864d57b86dSChao Yu struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 33874d57b86dSChao Yu struct page *f2fs_get_node_page_ra(struct page *parent, int start); 338848018b4cSChao Yu int f2fs_move_node_page(struct page *node_page, int gc_type); 338968e79bafSJia Yang void f2fs_flush_inline_data(struct f2fs_sb_info *sbi); 33904d57b86dSChao Yu int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 339150fa53ecSChao Yu struct writeback_control *wbc, bool atomic, 339250fa53ecSChao Yu unsigned int *seq_id); 33934d57b86dSChao Yu int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, 33944d57b86dSChao Yu struct writeback_control *wbc, 3395b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 3396e2374015SChao Yu int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 33974d57b86dSChao Yu bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 33984d57b86dSChao Yu void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 33994d57b86dSChao Yu void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 34004d57b86dSChao Yu int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 34019627a7b3SChao Yu int f2fs_recover_inline_xattr(struct inode *inode, struct page *page); 34024d57b86dSChao Yu int f2fs_recover_xattr_data(struct inode *inode, struct page *page); 34034d57b86dSChao Yu int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 34047735730dSChao Yu int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, 3405cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 3406edc55aafSJaegeuk Kim int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 34074d57b86dSChao Yu int f2fs_build_node_manager(struct f2fs_sb_info *sbi); 34084d57b86dSChao Yu void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi); 34094d57b86dSChao Yu int __init f2fs_create_node_manager_caches(void); 34104d57b86dSChao Yu void f2fs_destroy_node_manager_caches(void); 341139a53e0cSJaegeuk Kim 341239a53e0cSJaegeuk Kim /* 341339a53e0cSJaegeuk Kim * segment.c 341439a53e0cSJaegeuk Kim */ 34154d57b86dSChao Yu bool f2fs_need_SSR(struct f2fs_sb_info *sbi); 34164d57b86dSChao Yu void f2fs_register_inmem_page(struct inode *inode, struct page *page); 34174d57b86dSChao Yu void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure); 34184d57b86dSChao Yu void f2fs_drop_inmem_pages(struct inode *inode); 34194d57b86dSChao Yu void f2fs_drop_inmem_page(struct inode *inode, struct page *page); 34204d57b86dSChao Yu int f2fs_commit_inmem_pages(struct inode *inode); 3421cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 34227bcd0cfaSChao Yu void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg); 342339d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 34244d57b86dSChao Yu int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi); 34251228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); 34264d57b86dSChao Yu void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 34274d57b86dSChao Yu void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 34284d57b86dSChao Yu bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 34294d57b86dSChao Yu void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi); 34304d57b86dSChao Yu void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi); 343103f2c02dSJaegeuk Kim bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi); 34324d57b86dSChao Yu void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, 34334d57b86dSChao Yu struct cp_control *cpc); 34344354994fSDaniel Rosenberg void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi); 34354d3aed70SDaniel Rosenberg block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi); 34364d3aed70SDaniel Rosenberg int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable); 34374d57b86dSChao Yu void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi); 34384d57b86dSChao Yu int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 343961461fc9SChao Yu bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno); 3440093749e2SChao Yu void f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi); 3441093749e2SChao Yu void f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi); 3442093749e2SChao Yu void f2fs_restore_inmem_curseg(struct f2fs_sb_info *sbi); 3443093749e2SChao Yu void f2fs_get_new_segment(struct f2fs_sb_info *sbi, 3444093749e2SChao Yu unsigned int *newseg, bool new_sec, int dir); 34450ef81833SChao Yu void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, 344604f0b2eaSQiuyang Sun unsigned int start, unsigned int end); 3447509f1010SChao Yu void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force); 3448901d745fSChao Yu void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi); 3449cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 34504d57b86dSChao Yu bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, 34514d57b86dSChao Yu struct cp_control *cpc); 34524d57b86dSChao Yu struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 34534d57b86dSChao Yu void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src, 34544d57b86dSChao Yu block_t blk_addr); 34554d57b86dSChao Yu void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 3456b0af6d49SChao Yu enum iostat_type io_type); 34574d57b86dSChao Yu void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio); 34584d57b86dSChao Yu void f2fs_outplace_write_data(struct dnode_of_data *dn, 34594d57b86dSChao Yu struct f2fs_io_info *fio); 34604d57b86dSChao Yu int f2fs_inplace_write_data(struct f2fs_io_info *fio); 34614d57b86dSChao Yu void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 3462cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 3463c5d02785SChao Yu bool recover_curseg, bool recover_newaddr, 3464c5d02785SChao Yu bool from_gc); 3465cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 3466cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 3467cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 3468cac5a3d8SDongOh Shin bool recover_newaddr); 34694d57b86dSChao Yu void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 3470cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 3471fb830fc5SChao Yu struct f2fs_summary *sum, int type, 3472f608c38cSChao Yu struct f2fs_io_info *fio); 3473cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 3474bae0ee7aSChao Yu enum page_type type, bool ordered, bool locked); 34750ded69f6SJaegeuk Kim void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr); 34761e78e8bdSSahitya Tummala void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr, 34771e78e8bdSSahitya Tummala block_t len); 34784d57b86dSChao Yu void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 34794d57b86dSChao Yu void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 34804d57b86dSChao Yu int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 3481cac5a3d8SDongOh Shin unsigned int val, int alloc); 34824d57b86dSChao Yu void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 3483c426d991SShin'ichiro Kawasaki int f2fs_fix_curseg_write_pointer(struct f2fs_sb_info *sbi); 3484d508c94eSShin'ichiro Kawasaki int f2fs_check_write_pointer(struct f2fs_sb_info *sbi); 34854d57b86dSChao Yu int f2fs_build_segment_manager(struct f2fs_sb_info *sbi); 34864d57b86dSChao Yu void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi); 34874d57b86dSChao Yu int __init f2fs_create_segment_manager_caches(void); 34884d57b86dSChao Yu void f2fs_destroy_segment_manager_caches(void); 34894d57b86dSChao Yu int f2fs_rw_hint_to_seg_type(enum rw_hint hint); 34904d57b86dSChao Yu enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, 34914d57b86dSChao Yu enum page_type type, enum temp_type temp); 3492de881df9SAravind Ramesh unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi, 3493de881df9SAravind Ramesh unsigned int segno); 3494de881df9SAravind Ramesh unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi, 3495de881df9SAravind Ramesh unsigned int segno); 349639a53e0cSJaegeuk Kim 349739a53e0cSJaegeuk Kim /* 349839a53e0cSJaegeuk Kim * checkpoint.c 349939a53e0cSJaegeuk Kim */ 3500cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 35014d57b86dSChao Yu struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 35024d57b86dSChao Yu struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 350386f33603SJaegeuk Kim struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index); 35044d57b86dSChao Yu struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 3505e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 35064d57b86dSChao Yu block_t blkaddr, int type); 35074d57b86dSChao Yu int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 3508cac5a3d8SDongOh Shin int type, bool sync); 35094d57b86dSChao Yu void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 35104d57b86dSChao Yu long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 3511b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 35124d57b86dSChao Yu void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 35134d57b86dSChao Yu void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 35144d57b86dSChao Yu void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all); 35154d57b86dSChao Yu bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 35164d57b86dSChao Yu void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 351739d787beSChao Yu unsigned int devidx, int type); 35184d57b86dSChao Yu bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 351939d787beSChao Yu unsigned int devidx, int type); 3520cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 35214d57b86dSChao Yu int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi); 35224d57b86dSChao Yu void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi); 35234d57b86dSChao Yu void f2fs_add_orphan_inode(struct inode *inode); 35244d57b86dSChao Yu void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 35254d57b86dSChao Yu int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi); 35264d57b86dSChao Yu int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi); 35274d57b86dSChao Yu void f2fs_update_dirty_page(struct inode *inode, struct page *page); 35284d57b86dSChao Yu void f2fs_remove_dirty_inode(struct inode *inode); 35294d57b86dSChao Yu int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 3530bf22c3ccSSahitya Tummala void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type); 35313a0a9cbcSChao Yu u64 f2fs_get_sectors_written(struct f2fs_sb_info *sbi); 35324d57b86dSChao Yu int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 35334d57b86dSChao Yu void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi); 35344d57b86dSChao Yu int __init f2fs_create_checkpoint_caches(void); 35354d57b86dSChao Yu void f2fs_destroy_checkpoint_caches(void); 3536261eeb9cSDaeho Jeong int f2fs_issue_checkpoint(struct f2fs_sb_info *sbi); 3537261eeb9cSDaeho Jeong int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi); 3538261eeb9cSDaeho Jeong void f2fs_stop_ckpt_thread(struct f2fs_sb_info *sbi); 3539261eeb9cSDaeho Jeong void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi); 354039a53e0cSJaegeuk Kim 354139a53e0cSJaegeuk Kim /* 354239a53e0cSJaegeuk Kim * data.c 354339a53e0cSJaegeuk Kim */ 3544f543805fSChao Yu int __init f2fs_init_bioset(void); 3545f543805fSChao Yu void f2fs_destroy_bioset(void); 35460b20fcecSChao Yu int f2fs_init_bio_entry_cache(void); 35470b20fcecSChao Yu void f2fs_destroy_bio_entry_cache(void); 35484c8ff709SChao Yu void f2fs_submit_bio(struct f2fs_sb_info *sbi, 35494c8ff709SChao Yu struct bio *bio, enum page_type type); 3550b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 3551b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 3552bab475c5SChao Yu struct inode *inode, struct page *page, 3553bab475c5SChao Yu nid_t ino, enum page_type type); 35540b20fcecSChao Yu void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi, 35550b20fcecSChao Yu struct bio **bio, struct page *page); 3556b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 3557cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 35588648de2cSChao Yu int f2fs_merge_page_bio(struct f2fs_io_info *fio); 3559fe16efe6SChao Yu void f2fs_submit_page_write(struct f2fs_io_info *fio); 3560cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 3561cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 3562cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 35634d57b86dSChao Yu void f2fs_set_data_blkaddr(struct dnode_of_data *dn); 3564cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 35654d57b86dSChao Yu int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 35664d57b86dSChao Yu int f2fs_reserve_new_block(struct dnode_of_data *dn); 3567cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 3568cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 3569cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 35704d57b86dSChao Yu struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, 3571cac5a3d8SDongOh Shin int op_flags, bool for_write); 35724d57b86dSChao Yu struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index); 35734d57b86dSChao Yu struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index, 3574cac5a3d8SDongOh Shin bool for_write); 35754d57b86dSChao Yu struct page *f2fs_get_new_data_page(struct inode *inode, 3576cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 35774d57b86dSChao Yu int f2fs_do_write_data_page(struct f2fs_io_info *fio); 35780ef81833SChao Yu void f2fs_do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock); 3579cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 3580cac5a3d8SDongOh Shin int create, int flag); 3581cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 3582cac5a3d8SDongOh Shin u64 start, u64 len); 35834c8ff709SChao Yu int f2fs_encrypt_one_page(struct f2fs_io_info *fio); 35844d57b86dSChao Yu bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); 35854d57b86dSChao Yu bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); 35864c8ff709SChao Yu int f2fs_write_single_data_page(struct page *page, int *submitted, 35874c8ff709SChao Yu struct bio **bio, sector_t *last_block, 35884c8ff709SChao Yu struct writeback_control *wbc, 35894c8ff709SChao Yu enum iostat_type io_type, 35903afae09fSChao Yu int compr_blocks, bool allow_balance); 3591cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 3592cac5a3d8SDongOh Shin unsigned int length); 3593cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 35945b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 3595cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 3596cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 35975b7a487cSWeichao Guo #endif 3598b91050a8SHyunchul Lee bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len); 35995ec2d99dSMatthew Wilcox void f2fs_clear_page_cache_dirty_tag(struct page *page); 36004c8ff709SChao Yu int f2fs_init_post_read_processing(void); 36014c8ff709SChao Yu void f2fs_destroy_post_read_processing(void); 36024c8ff709SChao Yu int f2fs_init_post_read_wq(struct f2fs_sb_info *sbi); 36034c8ff709SChao Yu void f2fs_destroy_post_read_wq(struct f2fs_sb_info *sbi); 360439a53e0cSJaegeuk Kim 360539a53e0cSJaegeuk Kim /* 360639a53e0cSJaegeuk Kim * gc.c 360739a53e0cSJaegeuk Kim */ 36084d57b86dSChao Yu int f2fs_start_gc_thread(struct f2fs_sb_info *sbi); 36094d57b86dSChao Yu void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi); 36104d57b86dSChao Yu block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 36117dede886SChao Yu int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, bool force, 3612e066b83cSJaegeuk Kim unsigned int segno); 36134d57b86dSChao Yu void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); 361404f0b2eaSQiuyang Sun int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count); 3615093749e2SChao Yu int __init f2fs_create_garbage_collection_cache(void); 3616093749e2SChao Yu void f2fs_destroy_garbage_collection_cache(void); 361739a53e0cSJaegeuk Kim 361839a53e0cSJaegeuk Kim /* 361939a53e0cSJaegeuk Kim * recovery.c 362039a53e0cSJaegeuk Kim */ 36214d57b86dSChao Yu int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 36224d57b86dSChao Yu bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi); 362339a53e0cSJaegeuk Kim 362439a53e0cSJaegeuk Kim /* 362539a53e0cSJaegeuk Kim * debug.c 362639a53e0cSJaegeuk Kim */ 362739a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 362839a53e0cSJaegeuk Kim struct f2fs_stat_info { 362939a53e0cSJaegeuk Kim struct list_head stat_list; 363039a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 363139a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 363239a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 36335b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 36345b7ee374SChao Yu unsigned long long hit_total, total_ext; 3635c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 36362c8a4a28SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; 36372c8a4a28SJaegeuk Kim int ndirty_data, ndirty_qdata; 363835782b23SJaegeuk Kim int inmem_pages; 36392c8a4a28SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; 36405b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 36415b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 364239a53e0cSJaegeuk Kim int total_count, utilization; 36438b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 36445f9abab4SJaegeuk Kim int nr_rd_data, nr_rd_node, nr_rd_meta; 364502b16d0aSChao Yu int nr_dio_read, nr_dio_write; 3646274bd9baSChao Yu unsigned int io_skip_bggc, other_skip_bggc; 364714d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 364814d8d5f7SChao Yu int nr_discarding, nr_discarded; 36495f32366aSChao Yu int nr_discard_cmd; 3650d84d1cbdSChao Yu unsigned int undiscard_blks; 3651261eeb9cSDaeho Jeong int nr_issued_ckpt, nr_total_ckpt, nr_queued_ckpt; 3652261eeb9cSDaeho Jeong unsigned int cur_ckpt_time, peak_ckpt_time; 3653a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 3654ae999bb9SDaeho Jeong int compr_inode; 3655ae999bb9SDaeho Jeong unsigned long long compr_blocks; 3656648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 3657f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 365839a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 365939a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 366039a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 366139a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 366242190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 366339a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 3664e1235983SChangman Lee int bg_node_segs, bg_data_segs; 366539a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 3666e1235983SChangman Lee int bg_data_blks, bg_node_blks; 36672ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; 366839a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 366939a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 367039a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 36710759e2c1SChao Yu unsigned int dirty_seg[NR_CURSEG_TYPE]; 36720759e2c1SChao Yu unsigned int full_seg[NR_CURSEG_TYPE]; 36730759e2c1SChao Yu unsigned int valid_blks[NR_CURSEG_TYPE]; 367439a53e0cSJaegeuk Kim 3675b63e7be5SChao Yu unsigned int meta_count[META_MAX]; 367639a53e0cSJaegeuk Kim unsigned int segment_count[2]; 367739a53e0cSJaegeuk Kim unsigned int block_count[2]; 3678b9a2c252SChangman Lee unsigned int inplace_count; 36799edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 368039a53e0cSJaegeuk Kim }; 368139a53e0cSJaegeuk Kim 3682963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 3683963d4f7dSGu Zheng { 3684963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 3685963d4f7dSGu Zheng } 3686963d4f7dSGu Zheng 3687942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 368842190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 368939a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 3690fc7100eaSHridya Valsaraju #define stat_inc_bggc_count(si) ((si)->bg_gc++) 3691274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) ((sbi)->io_skip_bggc++) 3692274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) ((sbi)->other_skip_bggc++) 369333fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 369433fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 36955b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 36965b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 36975b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 36985b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 3699d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 3700d5e8f6c9SChao Yu do { \ 3701d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3702d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 3703d5e8f6c9SChao Yu } while (0) 3704d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 3705d5e8f6c9SChao Yu do { \ 3706d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3707d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 3708d5e8f6c9SChao Yu } while (0) 37090dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 37100dbdc2aeSJaegeuk Kim do { \ 37110dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 371203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 37130dbdc2aeSJaegeuk Kim } while (0) 37140dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 37150dbdc2aeSJaegeuk Kim do { \ 37160dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 371703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 37180dbdc2aeSJaegeuk Kim } while (0) 37193289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 37203289c061SJaegeuk Kim do { \ 37213289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 372203e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 37233289c061SJaegeuk Kim } while (0) 37243289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 37253289c061SJaegeuk Kim do { \ 37263289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 372703e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 37283289c061SJaegeuk Kim } while (0) 37294c8ff709SChao Yu #define stat_inc_compr_inode(inode) \ 37304c8ff709SChao Yu do { \ 37314c8ff709SChao Yu if (f2fs_compressed_file(inode)) \ 37324c8ff709SChao Yu (atomic_inc(&F2FS_I_SB(inode)->compr_inode)); \ 37334c8ff709SChao Yu } while (0) 37344c8ff709SChao Yu #define stat_dec_compr_inode(inode) \ 37354c8ff709SChao Yu do { \ 37364c8ff709SChao Yu if (f2fs_compressed_file(inode)) \ 37374c8ff709SChao Yu (atomic_dec(&F2FS_I_SB(inode)->compr_inode)); \ 37384c8ff709SChao Yu } while (0) 37394c8ff709SChao Yu #define stat_add_compr_blocks(inode, blocks) \ 3740ae999bb9SDaeho Jeong (atomic64_add(blocks, &F2FS_I_SB(inode)->compr_blocks)) 37414c8ff709SChao Yu #define stat_sub_compr_blocks(inode, blocks) \ 3742ae999bb9SDaeho Jeong (atomic64_sub(blocks, &F2FS_I_SB(inode)->compr_blocks)) 3743b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) \ 3744b63e7be5SChao Yu do { \ 3745b63e7be5SChao Yu if (blkaddr < SIT_I(sbi)->sit_base_addr) \ 3746b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_CP]); \ 3747b63e7be5SChao Yu else if (blkaddr < NM_I(sbi)->nat_blkaddr) \ 3748b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SIT]); \ 3749b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->ssa_blkaddr) \ 3750b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_NAT]); \ 3751b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->main_blkaddr) \ 3752b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SSA]); \ 3753b63e7be5SChao Yu } while (0) 3754dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 3755dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 3756dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 3757dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 3758b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 3759b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 376026a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 376126a28a0cSJaegeuk Kim do { \ 37620e6d0164SSahitya Tummala int cur = F2FS_I_SB(inode)->atomic_files; \ 376326a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 376426a28a0cSJaegeuk Kim if (cur > max) \ 376526a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 376626a28a0cSJaegeuk Kim } while (0) 3767648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 3768648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 3769648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 3770648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 3771648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 3772648d50baSChao Yu do { \ 3773648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 3774648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 3775648d50baSChao Yu if (cur > max) \ 3776648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 3777648d50baSChao Yu } while (0) 3778e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 377939a53e0cSJaegeuk Kim do { \ 3780963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 378168afcf2dSTomohiro Kusumi si->tot_segs++; \ 378268afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 378339a53e0cSJaegeuk Kim si->data_segs++; \ 3784e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 3785e1235983SChangman Lee } else { \ 378639a53e0cSJaegeuk Kim si->node_segs++; \ 3787e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 3788e1235983SChangman Lee } \ 378939a53e0cSJaegeuk Kim } while (0) 379039a53e0cSJaegeuk Kim 379139a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 379268afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 379339a53e0cSJaegeuk Kim 3794e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 379539a53e0cSJaegeuk Kim do { \ 3796963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 379739a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 379839a53e0cSJaegeuk Kim si->data_blks += (blks); \ 379968afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 380039a53e0cSJaegeuk Kim } while (0) 380139a53e0cSJaegeuk Kim 3802e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 380339a53e0cSJaegeuk Kim do { \ 3804963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 380539a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 380639a53e0cSJaegeuk Kim si->node_blks += (blks); \ 380768afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 380839a53e0cSJaegeuk Kim } while (0) 380939a53e0cSJaegeuk Kim 3810cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 3811cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 381221acc07dSGreg Kroah-Hartman void __init f2fs_create_root_stats(void); 38134589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 3814fc7100eaSHridya Valsaraju void f2fs_update_sit_info(struct f2fs_sb_info *sbi); 381539a53e0cSJaegeuk Kim #else 3816d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 3817d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 3818d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 3819d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 3820274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) do { } while (0) 3821274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) do { } while (0) 3822d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 3823d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 3824fc7100eaSHridya Valsaraju #define stat_inc_total_hit(sbi) do { } while (0) 3825fc7100eaSHridya Valsaraju #define stat_inc_rbtree_node_hit(sbi) do { } while (0) 3826d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 3827d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 3828d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 3829d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 3830d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 3831d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 3832d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 3833d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 38344c8ff709SChao Yu #define stat_inc_compr_inode(inode) do { } while (0) 38354c8ff709SChao Yu #define stat_dec_compr_inode(inode) do { } while (0) 38364c8ff709SChao Yu #define stat_add_compr_blocks(inode, blocks) do { } while (0) 38374c8ff709SChao Yu #define stat_sub_compr_blocks(inode, blocks) do { } while (0) 3838d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 3839d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 3840d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 3841d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 3842b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) do { } while (0) 3843d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 3844d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 3845d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 3846d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 3847d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 3848d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 3849d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 385039a53e0cSJaegeuk Kim 385139a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 385239a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 385321acc07dSGreg Kroah-Hartman static inline void __init f2fs_create_root_stats(void) { } 38544589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 385548abe91aSYueHaibing static inline void f2fs_update_sit_info(struct f2fs_sb_info *sbi) {} 385639a53e0cSJaegeuk Kim #endif 385739a53e0cSJaegeuk Kim 385839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 385939a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 386039a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 386139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 386239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 386339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 386439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 386539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 3866cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 386739a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 38684d57b86dSChao Yu extern struct kmem_cache *f2fs_inode_entry_slab; 38691001b347SHuajun Li 3870e18c65b2SHuajun Li /* 3871e18c65b2SHuajun Li * inline.c 3872e18c65b2SHuajun Li */ 3873cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 3874cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 38754d57b86dSChao Yu void f2fs_do_read_inline_data(struct page *page, struct page *ipage); 38764d57b86dSChao Yu void f2fs_truncate_inline_inode(struct inode *inode, 38774d57b86dSChao Yu struct page *ipage, u64 from); 3878cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 3879cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 3880cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 3881b06af2afSJaegeuk Kim int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry); 3882cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 38839627a7b3SChao Yu int f2fs_recover_inline_data(struct inode *inode, struct page *npage); 38844d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, 388543c780baSEric Biggers const struct f2fs_filename *fname, 388643c780baSEric Biggers struct page **res_page); 38874d57b86dSChao Yu int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 3888cac5a3d8SDongOh Shin struct page *ipage); 388943c780baSEric Biggers int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname, 3890cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 38914d57b86dSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, 38924d57b86dSChao Yu struct page *page, struct inode *dir, 38934d57b86dSChao Yu struct inode *inode); 3894cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 3895cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 3896cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 3897cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 3898cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 3899cac5a3d8SDongOh Shin __u64 start, __u64 len); 3900cde4de12SJaegeuk Kim 3901cde4de12SJaegeuk Kim /* 39022658e50dSJaegeuk Kim * shrinker.c 39032658e50dSJaegeuk Kim */ 3904cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 3905cac5a3d8SDongOh Shin struct shrink_control *sc); 3906cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 3907cac5a3d8SDongOh Shin struct shrink_control *sc); 3908cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 3909cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 39102658e50dSJaegeuk Kim 39112658e50dSJaegeuk Kim /* 3912a28ef1f5SChao Yu * extent_cache.c 3913a28ef1f5SChao Yu */ 39144dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree(struct rb_root_cached *root, 3915004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 39162e9b2bb2SChao Yu struct rb_node **f2fs_lookup_rb_tree_ext(struct f2fs_sb_info *sbi, 39172e9b2bb2SChao Yu struct rb_root_cached *root, 39182e9b2bb2SChao Yu struct rb_node **parent, 39192e9b2bb2SChao Yu unsigned long long key, bool *left_most); 39204d57b86dSChao Yu struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 39214dada3fdSChao Yu struct rb_root_cached *root, 39224dada3fdSChao Yu struct rb_node **parent, 39234dada3fdSChao Yu unsigned int ofs, bool *leftmost); 39244dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root, 3925004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 3926004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 3927004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 39284dada3fdSChao Yu bool force, bool *leftmost); 39294d57b86dSChao Yu bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi, 39302e9b2bb2SChao Yu struct rb_root_cached *root, bool check_key); 3931cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 3932a6d601f3SChao Yu void f2fs_init_extent_tree(struct inode *inode, struct page *ipage); 3933cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 3934cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 3935cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 3936cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 3937cac5a3d8SDongOh Shin struct extent_info *ei); 3938cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 393919b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 3940cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 39414d57b86dSChao Yu void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi); 39424d57b86dSChao Yu int __init f2fs_create_extent_cache(void); 39434d57b86dSChao Yu void f2fs_destroy_extent_cache(void); 3944a28ef1f5SChao Yu 3945a28ef1f5SChao Yu /* 39468ceffcb2SChao Yu * sysfs.c 39478ceffcb2SChao Yu */ 3948dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 3949dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 3950dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 3951dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 39528ceffcb2SChao Yu 395395ae251fSEric Biggers /* verity.c */ 395495ae251fSEric Biggers extern const struct fsverity_operations f2fs_verityops; 395595ae251fSEric Biggers 39568ceffcb2SChao Yu /* 3957cde4de12SJaegeuk Kim * crypto support 3958cde4de12SJaegeuk Kim */ 39591958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 39601958593eSJaegeuk Kim { 396162230e0dSChandan Rajendra return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); 39621958593eSJaegeuk Kim } 39631958593eSJaegeuk Kim 3964cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 3965cde4de12SJaegeuk Kim { 3966643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 3967cde4de12SJaegeuk Kim file_set_encrypt(inode); 39689149a5ebSChao Yu f2fs_set_inode_flags(inode); 3969cde4de12SJaegeuk Kim #endif 3970cde4de12SJaegeuk Kim } 3971cde4de12SJaegeuk Kim 39726dbb1796SEric Biggers /* 39736dbb1796SEric Biggers * Returns true if the reads of the inode's data need to undergo some 39746dbb1796SEric Biggers * postprocessing step, like decryption or authenticity verification. 39756dbb1796SEric Biggers */ 39766dbb1796SEric Biggers static inline bool f2fs_post_read_required(struct inode *inode) 3977cde4de12SJaegeuk Kim { 39784c8ff709SChao Yu return f2fs_encrypted_file(inode) || fsverity_active(inode) || 39794c8ff709SChao Yu f2fs_compressed_file(inode); 39804c8ff709SChao Yu } 39814c8ff709SChao Yu 39824c8ff709SChao Yu /* 39834c8ff709SChao Yu * compress.c 39844c8ff709SChao Yu */ 39854c8ff709SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 39864c8ff709SChao Yu bool f2fs_is_compressed_page(struct page *page); 39874c8ff709SChao Yu struct page *f2fs_compress_control_page(struct page *page); 39884c8ff709SChao Yu int f2fs_prepare_compress_overwrite(struct inode *inode, 39894c8ff709SChao Yu struct page **pagep, pgoff_t index, void **fsdata); 39904c8ff709SChao Yu bool f2fs_compress_write_end(struct inode *inode, void *fsdata, 39914c8ff709SChao Yu pgoff_t index, unsigned copied); 39923265d3dbSChao Yu int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock); 39934c8ff709SChao Yu void f2fs_compress_write_end_io(struct bio *bio, struct page *page); 39944c8ff709SChao Yu bool f2fs_is_compress_backend_ready(struct inode *inode); 39955e6bbde9SChao Yu int f2fs_init_compress_mempool(void); 39965e6bbde9SChao Yu void f2fs_destroy_compress_mempool(void); 39977f59b277SEric Biggers void f2fs_end_read_compressed_page(struct page *page, bool failed); 39984c8ff709SChao Yu bool f2fs_cluster_is_empty(struct compress_ctx *cc); 39994c8ff709SChao Yu bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index); 40004c8ff709SChao Yu void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page); 40014c8ff709SChao Yu int f2fs_write_multi_pages(struct compress_ctx *cc, 40024c8ff709SChao Yu int *submitted, 40034c8ff709SChao Yu struct writeback_control *wbc, 40044c8ff709SChao Yu enum iostat_type io_type); 40054c8ff709SChao Yu int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index); 40064c8ff709SChao Yu int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, 40074c8ff709SChao Yu unsigned nr_pages, sector_t *last_block_in_bio, 40080683728aSChao Yu bool is_readahead, bool for_write); 40094c8ff709SChao Yu struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc); 40107f59b277SEric Biggers void f2fs_decompress_end_io(struct decompress_io_ctx *dic, bool failed); 40117f59b277SEric Biggers void f2fs_put_page_dic(struct page *page); 40124c8ff709SChao Yu int f2fs_init_compress_ctx(struct compress_ctx *cc); 40138bfbfb0dSChao Yu void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse); 40144c8ff709SChao Yu void f2fs_init_compress_info(struct f2fs_sb_info *sbi); 401531083031SChao Yu int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi); 401631083031SChao Yu void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi); 4017c68d6c88SChao Yu int __init f2fs_init_compress_cache(void); 4018c68d6c88SChao Yu void f2fs_destroy_compress_cache(void); 40195ac443e2SDaeho Jeong #define inc_compr_inode_stat(inode) \ 40205ac443e2SDaeho Jeong do { \ 40215ac443e2SDaeho Jeong struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ 40225ac443e2SDaeho Jeong sbi->compr_new_inode++; \ 40235ac443e2SDaeho Jeong } while (0) 40245ac443e2SDaeho Jeong #define add_compr_block_stat(inode, blocks) \ 40255ac443e2SDaeho Jeong do { \ 40265ac443e2SDaeho Jeong struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ 40275ac443e2SDaeho Jeong int diff = F2FS_I(inode)->i_cluster_size - blocks; \ 40285ac443e2SDaeho Jeong sbi->compr_written_block += blocks; \ 40295ac443e2SDaeho Jeong sbi->compr_saved_block += diff; \ 40305ac443e2SDaeho Jeong } while (0) 40314c8ff709SChao Yu #else 40324c8ff709SChao Yu static inline bool f2fs_is_compressed_page(struct page *page) { return false; } 40334c8ff709SChao Yu static inline bool f2fs_is_compress_backend_ready(struct inode *inode) 40344c8ff709SChao Yu { 40354c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 40364c8ff709SChao Yu return true; 40374c8ff709SChao Yu /* not support compression */ 40384c8ff709SChao Yu return false; 40394c8ff709SChao Yu } 40404c8ff709SChao Yu static inline struct page *f2fs_compress_control_page(struct page *page) 40414c8ff709SChao Yu { 40424c8ff709SChao Yu WARN_ON_ONCE(1); 40434c8ff709SChao Yu return ERR_PTR(-EINVAL); 40444c8ff709SChao Yu } 40455e6bbde9SChao Yu static inline int f2fs_init_compress_mempool(void) { return 0; } 40465e6bbde9SChao Yu static inline void f2fs_destroy_compress_mempool(void) { } 40477f59b277SEric Biggers static inline void f2fs_end_read_compressed_page(struct page *page, bool failed) 40487f59b277SEric Biggers { 40497f59b277SEric Biggers WARN_ON_ONCE(1); 40507f59b277SEric Biggers } 40517f59b277SEric Biggers static inline void f2fs_put_page_dic(struct page *page) 40527f59b277SEric Biggers { 40537f59b277SEric Biggers WARN_ON_ONCE(1); 40547f59b277SEric Biggers } 405531083031SChao Yu static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { return 0; } 405631083031SChao Yu static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) { } 4057c68d6c88SChao Yu static inline int __init f2fs_init_compress_cache(void) { return 0; } 4058c68d6c88SChao Yu static inline void f2fs_destroy_compress_cache(void) { } 40595ac443e2SDaeho Jeong #define inc_compr_inode_stat(inode) do { } while (0) 40604c8ff709SChao Yu #endif 40614c8ff709SChao Yu 40624c8ff709SChao Yu static inline void set_compress_context(struct inode *inode) 40634c8ff709SChao Yu { 40644c8ff709SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 40654c8ff709SChao Yu 40664c8ff709SChao Yu F2FS_I(inode)->i_compress_algorithm = 40674c8ff709SChao Yu F2FS_OPTION(sbi).compress_algorithm; 40684c8ff709SChao Yu F2FS_I(inode)->i_log_cluster_size = 40694c8ff709SChao Yu F2FS_OPTION(sbi).compress_log_size; 4070b28f047bSChao Yu F2FS_I(inode)->i_compress_flag = 4071b28f047bSChao Yu F2FS_OPTION(sbi).compress_chksum ? 4072b28f047bSChao Yu 1 << COMPRESS_CHKSUM : 0; 40734c8ff709SChao Yu F2FS_I(inode)->i_cluster_size = 40744c8ff709SChao Yu 1 << F2FS_I(inode)->i_log_cluster_size; 40753fde13f8SChao Yu if (F2FS_I(inode)->i_compress_algorithm == COMPRESS_LZ4 && 40763fde13f8SChao Yu F2FS_OPTION(sbi).compress_level) 40773fde13f8SChao Yu F2FS_I(inode)->i_compress_flag |= 40783fde13f8SChao Yu F2FS_OPTION(sbi).compress_level << 40793fde13f8SChao Yu COMPRESS_LEVEL_OFFSET; 40804c8ff709SChao Yu F2FS_I(inode)->i_flags |= F2FS_COMPR_FL; 40814c8ff709SChao Yu set_inode_flag(inode, FI_COMPRESSED_FILE); 40824c8ff709SChao Yu stat_inc_compr_inode(inode); 40835ac443e2SDaeho Jeong inc_compr_inode_stat(inode); 4084530e0704SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 40854c8ff709SChao Yu } 40864c8ff709SChao Yu 408778134d03SDaeho Jeong static inline bool f2fs_disable_compressed_file(struct inode *inode) 40884c8ff709SChao Yu { 40894c8ff709SChao Yu struct f2fs_inode_info *fi = F2FS_I(inode); 40904c8ff709SChao Yu 40914c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 409278134d03SDaeho Jeong return true; 409378134d03SDaeho Jeong if (S_ISREG(inode->i_mode) && 409478134d03SDaeho Jeong (get_dirty_pages(inode) || atomic_read(&fi->i_compr_blocks))) 409578134d03SDaeho Jeong return false; 40964c8ff709SChao Yu 40974c8ff709SChao Yu fi->i_flags &= ~F2FS_COMPR_FL; 40984c8ff709SChao Yu stat_dec_compr_inode(inode); 409996f5b4faSChao Yu clear_inode_flag(inode, FI_COMPRESSED_FILE); 4100530e0704SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 410178134d03SDaeho Jeong return true; 4102cde4de12SJaegeuk Kim } 4103cde4de12SJaegeuk Kim 4104ccd31cb2SSheng Yong #define F2FS_FEATURE_FUNCS(name, flagname) \ 41057beb01f7SChao Yu static inline int f2fs_sb_has_##name(struct f2fs_sb_info *sbi) \ 4106ccd31cb2SSheng Yong { \ 41077beb01f7SChao Yu return F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_##flagname); \ 4108cde4de12SJaegeuk Kim } 4109f424f664SJaegeuk Kim 4110ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(encrypt, ENCRYPT); 4111ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(blkzoned, BLKZONED); 4112ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR); 4113ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA); 4114ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM); 4115ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); 4116ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); 4117ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); 4118b7c409deSSheng Yong F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); 411995ae251fSEric Biggers F2FS_FEATURE_FUNCS(verity, VERITY); 4120d440c52dSJunling Zheng F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); 41215aba5430SDaniel Rosenberg F2FS_FEATURE_FUNCS(casefold, CASEFOLD); 41224c8ff709SChao Yu F2FS_FEATURE_FUNCS(compression, COMPRESSION); 41231c1d35dfSChao Yu 4124178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 412595175dafSDamien Le Moal static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, 412695175dafSDamien Le Moal block_t blkaddr) 4127178053e2SDamien Le Moal { 4128178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 4129178053e2SDamien Le Moal 413095175dafSDamien Le Moal return test_bit(zno, FDEV(devi).blkz_seq); 4131178053e2SDamien Le Moal } 4132178053e2SDamien Le Moal #endif 4133178053e2SDamien Le Moal 41347d20c8abSChao Yu static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi) 413596ba2decSDamien Le Moal { 41367beb01f7SChao Yu return f2fs_sb_has_blkzoned(sbi); 41377d20c8abSChao Yu } 413896ba2decSDamien Le Moal 41397f3d7719SDamien Le Moal static inline bool f2fs_bdev_support_discard(struct block_device *bdev) 41407f3d7719SDamien Le Moal { 41417f3d7719SDamien Le Moal return blk_queue_discard(bdev_get_queue(bdev)) || 41427f3d7719SDamien Le Moal bdev_is_zoned(bdev); 41437f3d7719SDamien Le Moal } 41447f3d7719SDamien Le Moal 41457d20c8abSChao Yu static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi) 41467d20c8abSChao Yu { 41477f3d7719SDamien Le Moal int i; 41487f3d7719SDamien Le Moal 41497f3d7719SDamien Le Moal if (!f2fs_is_multi_device(sbi)) 41507f3d7719SDamien Le Moal return f2fs_bdev_support_discard(sbi->sb->s_bdev); 41517f3d7719SDamien Le Moal 41527f3d7719SDamien Le Moal for (i = 0; i < sbi->s_ndevs; i++) 41537f3d7719SDamien Le Moal if (f2fs_bdev_support_discard(FDEV(i).bdev)) 41547f3d7719SDamien Le Moal return true; 41557f3d7719SDamien Le Moal return false; 41567d20c8abSChao Yu } 41577d20c8abSChao Yu 41587d20c8abSChao Yu static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) 41597d20c8abSChao Yu { 41607d20c8abSChao Yu return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) || 41617d20c8abSChao Yu f2fs_hw_should_discard(sbi); 416252763a4bSJaegeuk Kim } 416352763a4bSJaegeuk Kim 4164f824deb5SChao Yu static inline bool f2fs_hw_is_readonly(struct f2fs_sb_info *sbi) 4165f824deb5SChao Yu { 4166f824deb5SChao Yu int i; 4167f824deb5SChao Yu 4168f824deb5SChao Yu if (!f2fs_is_multi_device(sbi)) 4169f824deb5SChao Yu return bdev_read_only(sbi->sb->s_bdev); 4170f824deb5SChao Yu 4171f824deb5SChao Yu for (i = 0; i < sbi->s_ndevs; i++) 4172f824deb5SChao Yu if (bdev_read_only(FDEV(i).bdev)) 4173f824deb5SChao Yu return true; 4174f824deb5SChao Yu return false; 4175f824deb5SChao Yu } 4176f824deb5SChao Yu 4177b0332a0fSChao Yu static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi) 417852763a4bSJaegeuk Kim { 4179b0332a0fSChao Yu return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS; 418052763a4bSJaegeuk Kim } 418152763a4bSJaegeuk Kim 41824c8ff709SChao Yu static inline bool f2fs_may_compress(struct inode *inode) 41834c8ff709SChao Yu { 41844c8ff709SChao Yu if (IS_SWAPFILE(inode) || f2fs_is_pinned_file(inode) || 41854c8ff709SChao Yu f2fs_is_atomic_file(inode) || 41864c8ff709SChao Yu f2fs_is_volatile_file(inode)) 41874c8ff709SChao Yu return false; 41884c8ff709SChao Yu return S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode); 41894c8ff709SChao Yu } 41904c8ff709SChao Yu 41914c8ff709SChao Yu static inline void f2fs_i_compr_blocks_update(struct inode *inode, 41924c8ff709SChao Yu u64 blocks, bool add) 41934c8ff709SChao Yu { 41944c8ff709SChao Yu int diff = F2FS_I(inode)->i_cluster_size - blocks; 4195c2759ebaSDaeho Jeong struct f2fs_inode_info *fi = F2FS_I(inode); 41964c8ff709SChao Yu 4197ef8d563fSChao Yu /* don't update i_compr_blocks if saved blocks were released */ 4198c2759ebaSDaeho Jeong if (!add && !atomic_read(&fi->i_compr_blocks)) 4199ef8d563fSChao Yu return; 4200ef8d563fSChao Yu 42014c8ff709SChao Yu if (add) { 4202c2759ebaSDaeho Jeong atomic_add(diff, &fi->i_compr_blocks); 42034c8ff709SChao Yu stat_add_compr_blocks(inode, diff); 42044c8ff709SChao Yu } else { 4205c2759ebaSDaeho Jeong atomic_sub(diff, &fi->i_compr_blocks); 42064c8ff709SChao Yu stat_sub_compr_blocks(inode, diff); 42074c8ff709SChao Yu } 42084c8ff709SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 42094c8ff709SChao Yu } 42104c8ff709SChao Yu 4211f847c699SChao Yu static inline int block_unaligned_IO(struct inode *inode, 4212f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4213b91050a8SHyunchul Lee { 4214f847c699SChao Yu unsigned int i_blkbits = READ_ONCE(inode->i_blkbits); 4215f847c699SChao Yu unsigned int blocksize_mask = (1 << i_blkbits) - 1; 4216f847c699SChao Yu loff_t offset = iocb->ki_pos; 4217f847c699SChao Yu unsigned long align = offset | iov_iter_alignment(iter); 4218f847c699SChao Yu 4219f847c699SChao Yu return align & blocksize_mask; 4220f847c699SChao Yu } 4221f847c699SChao Yu 4222f847c699SChao Yu static inline int allow_outplace_dio(struct inode *inode, 4223f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4224f847c699SChao Yu { 4225f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4226f847c699SChao Yu int rw = iov_iter_rw(iter); 4227f847c699SChao Yu 4228b0332a0fSChao Yu return (f2fs_lfs_mode(sbi) && (rw == WRITE) && 4229f847c699SChao Yu !block_unaligned_IO(inode, iocb, iter)); 4230f847c699SChao Yu } 4231f847c699SChao Yu 4232f847c699SChao Yu static inline bool f2fs_force_buffered_io(struct inode *inode, 4233f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4234f847c699SChao Yu { 4235f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4236f847c699SChao Yu int rw = iov_iter_rw(iter); 4237f847c699SChao Yu 4238f847c699SChao Yu if (f2fs_post_read_required(inode)) 4239f847c699SChao Yu return true; 42400916878dSDamien Le Moal if (f2fs_is_multi_device(sbi)) 4241f847c699SChao Yu return true; 4242f847c699SChao Yu /* 4243f847c699SChao Yu * for blkzoned device, fallback direct IO to buffered IO, so 4244f847c699SChao Yu * all IOs can be serialized by log-structured write. 4245f847c699SChao Yu */ 42467beb01f7SChao Yu if (f2fs_sb_has_blkzoned(sbi)) 4247f847c699SChao Yu return true; 4248b0332a0fSChao Yu if (f2fs_lfs_mode(sbi) && (rw == WRITE)) { 42499720ee80SChao Yu if (block_unaligned_IO(inode, iocb, iter)) 4250f847c699SChao Yu return true; 42519720ee80SChao Yu if (F2FS_IO_ALIGNED(sbi)) 42529720ee80SChao Yu return true; 42539720ee80SChao Yu } 4254ebc29b62Shuangjianan@oppo.com if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED)) 42554354994fSDaniel Rosenberg return true; 42564354994fSDaniel Rosenberg 4257f847c699SChao Yu return false; 4258b91050a8SHyunchul Lee } 4259b91050a8SHyunchul Lee 42607f59b277SEric Biggers static inline bool f2fs_need_verity(const struct inode *inode, pgoff_t idx) 42617f59b277SEric Biggers { 42627f59b277SEric Biggers return fsverity_active(inode) && 42637f59b277SEric Biggers idx < DIV_ROUND_UP(inode->i_size, PAGE_SIZE); 42647f59b277SEric Biggers } 42657f59b277SEric Biggers 426683a3bfdbSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 4267d494500aSChao Yu extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, 4268d494500aSChao Yu unsigned int type); 426983a3bfdbSJaegeuk Kim #else 4270d494500aSChao Yu #define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) 427183a3bfdbSJaegeuk Kim #endif 427283a3bfdbSJaegeuk Kim 4273af033b2aSChao Yu static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) 4274af033b2aSChao Yu { 4275af033b2aSChao Yu #ifdef CONFIG_QUOTA 42767beb01f7SChao Yu if (f2fs_sb_has_quota_ino(sbi)) 4277af033b2aSChao Yu return true; 4278af033b2aSChao Yu if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || 4279af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || 4280af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) 4281af033b2aSChao Yu return true; 4282af033b2aSChao Yu #endif 4283af033b2aSChao Yu return false; 4284af033b2aSChao Yu } 42850af725fcSJaegeuk Kim 428610f966bbSChao Yu #define EFSBADCRC EBADMSG /* Bad CRC detected */ 428710f966bbSChao Yu #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 428810f966bbSChao Yu 4289e1074d4bSChao Yu #endif /* _LINUX_F2FS_H */ 4290