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 10039a53e0cSJaegeuk Kim 10163189b78SChao Yu #define F2FS_OPTION(sbi) ((sbi)->mount_opt) 10263189b78SChao Yu #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) 10363189b78SChao Yu #define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option) 10463189b78SChao Yu #define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option) 10539a53e0cSJaegeuk Kim 10639a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 10739a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 10839a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 10939a53e0cSJaegeuk Kim 110a9841c4dSJaegeuk Kim typedef u32 block_t; /* 111a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 112a9841c4dSJaegeuk Kim * address format, __le32. 113a9841c4dSJaegeuk Kim */ 11439a53e0cSJaegeuk Kim typedef u32 nid_t; 11539a53e0cSJaegeuk Kim 1164c8ff709SChao Yu #define COMPRESS_EXT_NUM 16 1174c8ff709SChao Yu 11839a53e0cSJaegeuk Kim struct f2fs_mount_info { 11939a53e0cSJaegeuk Kim unsigned int opt; 12063189b78SChao Yu int write_io_size_bits; /* Write IO size bits */ 12163189b78SChao Yu block_t root_reserved_blocks; /* root reserved blocks */ 12263189b78SChao Yu kuid_t s_resuid; /* reserved blocks for uid */ 12363189b78SChao Yu kgid_t s_resgid; /* reserved blocks for gid */ 12463189b78SChao Yu int active_logs; /* # of active logs */ 12563189b78SChao Yu int inline_xattr_size; /* inline xattr size */ 12663189b78SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 12763189b78SChao Yu struct f2fs_fault_info fault_info; /* For fault injection */ 12863189b78SChao Yu #endif 12963189b78SChao Yu #ifdef CONFIG_QUOTA 13063189b78SChao Yu /* Names of quota files with journalled quota */ 13163189b78SChao Yu char *s_qf_names[MAXQUOTAS]; 13263189b78SChao Yu int s_jquota_fmt; /* Format of quota to use */ 13363189b78SChao Yu #endif 13463189b78SChao Yu /* For which write hints are passed down to block layer */ 13563189b78SChao Yu int whint_mode; 13663189b78SChao Yu int alloc_mode; /* segment allocation policy */ 13763189b78SChao Yu int fsync_mode; /* fsync policy */ 138b0332a0fSChao Yu int fs_mode; /* fs mode: LFS or ADAPTIVE */ 139bbbc34fdSChao Yu int bggc_mode; /* bggc mode: off, on or sync */ 140ac4acb1fSEric Biggers struct fscrypt_dummy_policy dummy_enc_policy; /* test dummy encryption */ 1411ae18f71SJaegeuk Kim block_t unusable_cap_perc; /* percentage for cap */ 1424d3aed70SDaniel Rosenberg block_t unusable_cap; /* Amount of space allowed to be 1434d3aed70SDaniel Rosenberg * unusable when disabling checkpoint 1444d3aed70SDaniel Rosenberg */ 1454c8ff709SChao Yu 1464c8ff709SChao Yu /* For compression */ 1474c8ff709SChao Yu unsigned char compress_algorithm; /* algorithm type */ 148b28f047bSChao Yu unsigned char compress_log_size; /* cluster log size */ 1493fde13f8SChao Yu unsigned char compress_level; /* compress level */ 150b28f047bSChao Yu bool compress_chksum; /* compressed data chksum */ 1514c8ff709SChao Yu unsigned char compress_ext_cnt; /* extension count */ 152602a16d5SDaeho Jeong int compress_mode; /* compression mode */ 1534c8ff709SChao Yu unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ 15439a53e0cSJaegeuk Kim }; 15539a53e0cSJaegeuk Kim 156cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1570bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 158e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1597a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1605c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 161704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 1626afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 163234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO 0x0080 1641c1d35dfSChao Yu #define F2FS_FEATURE_INODE_CRTIME 0x0100 165b7c409deSSheng Yong #define F2FS_FEATURE_LOST_FOUND 0x0200 16695ae251fSEric Biggers #define F2FS_FEATURE_VERITY 0x0400 167d440c52dSJunling Zheng #define F2FS_FEATURE_SB_CHKSUM 0x0800 1685aba5430SDaniel Rosenberg #define F2FS_FEATURE_CASEFOLD 0x1000 1694c8ff709SChao Yu #define F2FS_FEATURE_COMPRESSION 0x2000 170cde4de12SJaegeuk Kim 1717beb01f7SChao Yu #define __F2FS_HAS_FEATURE(raw_super, mask) \ 1727beb01f7SChao Yu ((raw_super->feature & cpu_to_le32(mask)) != 0) 1737beb01f7SChao Yu #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask) 1747beb01f7SChao Yu #define F2FS_SET_FEATURE(sbi, mask) \ 1757beb01f7SChao Yu (sbi->raw_super->feature |= cpu_to_le32(mask)) 1767beb01f7SChao Yu #define F2FS_CLEAR_FEATURE(sbi, mask) \ 1777beb01f7SChao Yu (sbi->raw_super->feature &= ~cpu_to_le32(mask)) 17876f105a2SJaegeuk Kim 17939a53e0cSJaegeuk Kim /* 1807c2e5963SJaegeuk Kim * Default values for user and/or group using reserved blocks 1817c2e5963SJaegeuk Kim */ 1827c2e5963SJaegeuk Kim #define F2FS_DEF_RESUID 0 1837c2e5963SJaegeuk Kim #define F2FS_DEF_RESGID 0 1847c2e5963SJaegeuk Kim 1857c2e5963SJaegeuk Kim /* 18639a53e0cSJaegeuk Kim * For checkpoint manager 18739a53e0cSJaegeuk Kim */ 18839a53e0cSJaegeuk Kim enum { 18939a53e0cSJaegeuk Kim NAT_BITMAP, 19039a53e0cSJaegeuk Kim SIT_BITMAP 19139a53e0cSJaegeuk Kim }; 19239a53e0cSJaegeuk Kim 193c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 194c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 195c473f1a9SChao Yu #define CP_SYNC 0x00000004 196c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 197c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1981f43e2adSChao Yu #define CP_TRIMMED 0x00000020 1994354994fSDaniel Rosenberg #define CP_PAUSE 0x00000040 200b4b10061SJaegeuk Kim #define CP_RESIZE 0x00000080 20175ab4cb8SJaegeuk Kim 2024ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 203ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 204969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 205f9d1dcedSYunlei He #define DEF_MID_DISCARD_ISSUE_TIME 500 /* 500 ms, if device busy */ 206969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 2078bb4f253SJaegeuk Kim #define DEF_DISCARD_URGENT_UTIL 80 /* do more discard over 80% */ 20860b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 209dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 2104354994fSDaniel Rosenberg #define DEF_DISABLE_INTERVAL 5 /* 5 secs */ 211db610a64SJaegeuk Kim #define DEF_DISABLE_QUICK_INTERVAL 1 /* 1 secs */ 21203f2c02dSJaegeuk Kim #define DEF_UMOUNT_DISCARD_TIMEOUT 5 /* 5 secs */ 213bba681cbSJaegeuk Kim 21475ab4cb8SJaegeuk Kim struct cp_control { 21575ab4cb8SJaegeuk Kim int reason; 2164b2fecc8SJaegeuk Kim __u64 trim_start; 2174b2fecc8SJaegeuk Kim __u64 trim_end; 2184b2fecc8SJaegeuk Kim __u64 trim_minlen; 21975ab4cb8SJaegeuk Kim }; 22075ab4cb8SJaegeuk Kim 221662befdaSChao Yu /* 222e1da7872SChao Yu * indicate meta/data type 223662befdaSChao Yu */ 224662befdaSChao Yu enum { 225662befdaSChao Yu META_CP, 226662befdaSChao Yu META_NAT, 22781c1a0f1SChao Yu META_SIT, 2284c521f49SJaegeuk Kim META_SSA, 229b63e7be5SChao Yu META_MAX, 2304c521f49SJaegeuk Kim META_POR, 23193770ab7SChao Yu DATA_GENERIC, /* check range only */ 23293770ab7SChao Yu DATA_GENERIC_ENHANCE, /* strong check on range and segment bitmap */ 23393770ab7SChao Yu DATA_GENERIC_ENHANCE_READ, /* 23493770ab7SChao Yu * strong check on range and segment 23593770ab7SChao Yu * bitmap but no warning due to race 23693770ab7SChao Yu * condition of read on truncated area 23793770ab7SChao Yu * by extent_cache 23893770ab7SChao Yu */ 239e1da7872SChao Yu META_GENERIC, 240662befdaSChao Yu }; 241662befdaSChao Yu 2426451e041SJaegeuk Kim /* for the list of ino */ 2436451e041SJaegeuk Kim enum { 2446451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 245fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 246fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 2470a007b97SJaegeuk Kim TRANS_DIR_INO, /* for trasactions dir ino list */ 24839d787beSChao Yu FLUSH_INO, /* for multiple device flushing */ 2496451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 2506451e041SJaegeuk Kim }; 2516451e041SJaegeuk Kim 2526451e041SJaegeuk Kim struct ino_entry { 25339a53e0cSJaegeuk Kim struct list_head list; /* list head */ 25439a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 25539d787beSChao Yu unsigned int dirty_device; /* dirty device bitmap */ 25639a53e0cSJaegeuk Kim }; 25739a53e0cSJaegeuk Kim 2582710fd7eSChao Yu /* for the list of inodes to be GCed */ 25906292073SChao Yu struct inode_entry { 26039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 26139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 26239a53e0cSJaegeuk Kim }; 26339a53e0cSJaegeuk Kim 26450fa53ecSChao Yu struct fsync_node_entry { 26550fa53ecSChao Yu struct list_head list; /* list head */ 26650fa53ecSChao Yu struct page *page; /* warm node page pointer */ 26750fa53ecSChao Yu unsigned int seq_id; /* sequence id */ 26850fa53ecSChao Yu }; 26950fa53ecSChao Yu 270261eeb9cSDaeho Jeong struct ckpt_req { 271261eeb9cSDaeho Jeong struct completion wait; /* completion for checkpoint done */ 272261eeb9cSDaeho Jeong struct llist_node llnode; /* llist_node to be linked in wait queue */ 273261eeb9cSDaeho Jeong int ret; /* return code of checkpoint */ 274261eeb9cSDaeho Jeong ktime_t queue_time; /* request queued time */ 275261eeb9cSDaeho Jeong }; 276261eeb9cSDaeho Jeong 277261eeb9cSDaeho Jeong struct ckpt_req_control { 278261eeb9cSDaeho Jeong struct task_struct *f2fs_issue_ckpt; /* checkpoint task */ 279e6592066SDaeho Jeong int ckpt_thread_ioprio; /* checkpoint merge thread ioprio */ 280261eeb9cSDaeho Jeong wait_queue_head_t ckpt_wait_queue; /* waiting queue for wake-up */ 281261eeb9cSDaeho Jeong atomic_t issued_ckpt; /* # of actually issued ckpts */ 282261eeb9cSDaeho Jeong atomic_t total_ckpt; /* # of total ckpts */ 283261eeb9cSDaeho Jeong atomic_t queued_ckpt; /* # of queued ckpts */ 284261eeb9cSDaeho Jeong struct llist_head issue_list; /* list for command issue */ 285261eeb9cSDaeho Jeong spinlock_t stat_lock; /* lock for below checkpoint time stats */ 286261eeb9cSDaeho Jeong unsigned int cur_time; /* cur wait time in msec for currently issued checkpoint */ 287261eeb9cSDaeho Jeong unsigned int peak_time; /* peak wait time in msec until now */ 288261eeb9cSDaeho Jeong }; 289261eeb9cSDaeho Jeong 290a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 2917fd9e544SJaegeuk Kim struct discard_entry { 2927fd9e544SJaegeuk Kim struct list_head list; /* list head */ 293a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 294a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 2957fd9e544SJaegeuk Kim }; 2967fd9e544SJaegeuk Kim 297969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 298969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 299969d1b18SChao Yu 300ba48a33eSChao Yu /* max discard pend list number */ 301ba48a33eSChao Yu #define MAX_PLIST_NUM 512 302ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 3032f84babfSSheng Yong (MAX_PLIST_NUM - 1) : ((blk_num) - 1)) 304ba48a33eSChao Yu 30515469963SJaegeuk Kim enum { 30635ec7d57SChao Yu D_PREP, /* initial */ 30735ec7d57SChao Yu D_PARTIAL, /* partially submitted */ 30835ec7d57SChao Yu D_SUBMIT, /* all submitted */ 30935ec7d57SChao Yu D_DONE, /* finished */ 31015469963SJaegeuk Kim }; 31115469963SJaegeuk Kim 312004b6862SChao Yu struct discard_info { 313b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 314b01a9201SJaegeuk Kim block_t len; /* length */ 315004b6862SChao Yu block_t start; /* actual start address in dev */ 316004b6862SChao Yu }; 317004b6862SChao Yu 318b01a9201SJaegeuk Kim struct discard_cmd { 319004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 320004b6862SChao Yu union { 321004b6862SChao Yu struct { 322004b6862SChao Yu block_t lstart; /* logical start address */ 323004b6862SChao Yu block_t len; /* length */ 324004b6862SChao Yu block_t start; /* actual start address in dev */ 325004b6862SChao Yu }; 326004b6862SChao Yu struct discard_info di; /* discard info */ 327004b6862SChao Yu 328004b6862SChao Yu }; 329b01a9201SJaegeuk Kim struct list_head list; /* command list */ 330b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 331c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 332ec9895adSChao Yu unsigned short ref; /* reference count */ 3339a744b92SChao Yu unsigned char state; /* state */ 33472691af6SJaegeuk Kim unsigned char queued; /* queued discard */ 335c81abe34SJaegeuk Kim int error; /* bio error */ 33635ec7d57SChao Yu spinlock_t lock; /* for state/bio_ref updating */ 33735ec7d57SChao Yu unsigned short bio_ref; /* bio reference count */ 338275b66b0SChao Yu }; 339275b66b0SChao Yu 34078997b56SChao Yu enum { 34178997b56SChao Yu DPOLICY_BG, 34278997b56SChao Yu DPOLICY_FORCE, 34378997b56SChao Yu DPOLICY_FSTRIM, 34478997b56SChao Yu DPOLICY_UMOUNT, 34578997b56SChao Yu MAX_DPOLICY, 34678997b56SChao Yu }; 34778997b56SChao Yu 348ecc9aa00SChao Yu struct discard_policy { 34978997b56SChao Yu int type; /* type of discard */ 350ecc9aa00SChao Yu unsigned int min_interval; /* used for candidates exist */ 351f9d1dcedSYunlei He unsigned int mid_interval; /* used for device busy */ 352ecc9aa00SChao Yu unsigned int max_interval; /* used for candidates not exist */ 353ecc9aa00SChao Yu unsigned int max_requests; /* # of discards issued per round */ 354ecc9aa00SChao Yu unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ 355ecc9aa00SChao Yu bool io_aware; /* issue discard in idle time */ 356ecc9aa00SChao Yu bool sync; /* submit discard with REQ_SYNC flag */ 35720ee4382SChao Yu bool ordered; /* issue discard by lba order */ 3586ce48b0cSChao Yu bool timeout; /* discard timeout for put_super */ 35978997b56SChao Yu unsigned int granularity; /* discard granularity */ 360ecc9aa00SChao Yu }; 361ecc9aa00SChao Yu 3620b54fb84SJaegeuk Kim struct discard_cmd_control { 36315469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 36446f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 365ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 36646f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 3678412663dSChao Yu struct list_head fstrim_list; /* in-flight discard from fstrim */ 36815469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 369969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 37015469963SJaegeuk Kim struct mutex cmd_lock; 371d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 372d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 373969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 374d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 37520ee4382SChao Yu unsigned int next_pos; /* next discard position */ 3768b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 37772691af6SJaegeuk Kim atomic_t queued_discard; /* # of queued discard */ 3785f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 3794dada3fdSChao Yu struct rb_root_cached root; /* root of discard rb-tree */ 38067fce70bSChao Yu bool rbtree_check; /* config for consistence check */ 38139a53e0cSJaegeuk Kim }; 38239a53e0cSJaegeuk Kim 38339a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 38439a53e0cSJaegeuk Kim struct fsync_inode_entry { 38539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 38639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 387c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 388c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 38939a53e0cSJaegeuk Kim }; 39039a53e0cSJaegeuk Kim 39168afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 39268afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 39339a53e0cSJaegeuk Kim 39468afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 39568afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 39668afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 39768afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 39839a53e0cSJaegeuk Kim 399dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 400dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 401309cc2b6SJaegeuk Kim 402dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 40339a53e0cSJaegeuk Kim { 404dfc08a12SChao Yu int before = nats_in_cursum(journal); 405cac5a3d8SDongOh Shin 406dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 40739a53e0cSJaegeuk Kim return before; 40839a53e0cSJaegeuk Kim } 40939a53e0cSJaegeuk Kim 410dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 41139a53e0cSJaegeuk Kim { 412dfc08a12SChao Yu int before = sits_in_cursum(journal); 413cac5a3d8SDongOh Shin 414dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 41539a53e0cSJaegeuk Kim return before; 41639a53e0cSJaegeuk Kim } 41739a53e0cSJaegeuk Kim 418dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 419dfc08a12SChao Yu int size, int type) 420184a5cd2SChao Yu { 421184a5cd2SChao Yu if (type == NAT_JOURNAL) 422dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 423dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 424184a5cd2SChao Yu } 425184a5cd2SChao Yu 426f2470371SChao Yu /* for inline stuff */ 427f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 4287a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 4296afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode); 4307a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 4317a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 432b323fd28SChao Yu get_inline_xattr_addrs(inode) - \ 4336afc662eSChao Yu DEF_INLINE_RESERVED_SIZE)) 434f2470371SChao Yu 435f2470371SChao Yu /* for inline dir */ 436f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 437f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 438f2470371SChao Yu BITS_PER_BYTE + 1)) 439f91108b8SGeert Uytterhoeven #define INLINE_DENTRY_BITMAP_SIZE(inode) \ 440f91108b8SGeert Uytterhoeven DIV_ROUND_UP(NR_INLINE_DENTRY(inode), BITS_PER_BYTE) 441f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 442f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 443f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 444f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 445f2470371SChao Yu 446e9750824SNamjae Jeon /* 44739a53e0cSJaegeuk Kim * For INODE and NODE manager 44839a53e0cSJaegeuk Kim */ 4497b3cd7d6SJaegeuk Kim /* for directory operations */ 45043c780baSEric Biggers 45143c780baSEric Biggers struct f2fs_filename { 45243c780baSEric Biggers /* 45343c780baSEric Biggers * The filename the user specified. This is NULL for some 45443c780baSEric Biggers * filesystem-internal operations, e.g. converting an inline directory 45543c780baSEric Biggers * to a non-inline one, or roll-forward recovering an encrypted dentry. 45643c780baSEric Biggers */ 45743c780baSEric Biggers const struct qstr *usr_fname; 45843c780baSEric Biggers 45943c780baSEric Biggers /* 46043c780baSEric Biggers * The on-disk filename. For encrypted directories, this is encrypted. 46143c780baSEric Biggers * This may be NULL for lookups in an encrypted dir without the key. 46243c780baSEric Biggers */ 46343c780baSEric Biggers struct fscrypt_str disk_name; 46443c780baSEric Biggers 46543c780baSEric Biggers /* The dirhash of this filename */ 46643c780baSEric Biggers f2fs_hash_t hash; 46743c780baSEric Biggers 46843c780baSEric Biggers #ifdef CONFIG_FS_ENCRYPTION 46943c780baSEric Biggers /* 47043c780baSEric Biggers * For lookups in encrypted directories: either the buffer backing 47143c780baSEric Biggers * disk_name, or a buffer that holds the decoded no-key name. 47243c780baSEric Biggers */ 47343c780baSEric Biggers struct fscrypt_str crypto_buf; 47443c780baSEric Biggers #endif 47543c780baSEric Biggers #ifdef CONFIG_UNICODE 47643c780baSEric Biggers /* 47743c780baSEric Biggers * For casefolded directories: the casefolded name, but it's left NULL 4787ad08a58SDaniel Rosenberg * if the original name is not valid Unicode, if the directory is both 4797ad08a58SDaniel Rosenberg * casefolded and encrypted and its encryption key is unavailable, or if 4807ad08a58SDaniel Rosenberg * the filesystem is doing an internal operation where usr_fname is also 4817ad08a58SDaniel Rosenberg * NULL. In all these cases we fall back to treating the name as an 4827ad08a58SDaniel Rosenberg * opaque byte sequence. 48343c780baSEric Biggers */ 48443c780baSEric Biggers struct fscrypt_str cf_name; 48543c780baSEric Biggers #endif 48643c780baSEric Biggers }; 48743c780baSEric Biggers 4887b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 489d8c6822aSJaegeuk Kim struct inode *inode; 49076a9dd85SChao Yu void *bitmap; 4917b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 4927b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 4937b3cd7d6SJaegeuk Kim int max; 49476a9dd85SChao Yu int nr_bitmap; 4957b3cd7d6SJaegeuk Kim }; 4967b3cd7d6SJaegeuk Kim 49764c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 49864c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 4997b3cd7d6SJaegeuk Kim { 500d8c6822aSJaegeuk Kim d->inode = inode; 5017b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 50276a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 503c79d1520SYunlong Song d->bitmap = t->dentry_bitmap; 5047b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 5057b3cd7d6SJaegeuk Kim d->filename = t->filename; 50664c24ecbSTomohiro Kusumi } 507cac5a3d8SDongOh Shin 50864c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 509f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 51064c24ecbSTomohiro Kusumi { 511f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 512f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 513f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 514f2470371SChao Yu 51564c24ecbSTomohiro Kusumi d->inode = inode; 516f2470371SChao Yu d->max = entry_cnt; 517f2470371SChao Yu d->nr_bitmap = bitmap_size; 518f2470371SChao Yu d->bitmap = t; 519f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 520f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 521f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 5227b3cd7d6SJaegeuk Kim } 5237b3cd7d6SJaegeuk Kim 524dbe6a5ffSJaegeuk Kim /* 525dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 526dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 527dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 52839a53e0cSJaegeuk Kim */ 529dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 530dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 531266e97a8SJaegeuk Kim enum { 532266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 533266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 534266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 535266e97a8SJaegeuk Kim * look up a node with readahead called 5364f4124d0SChao Yu * by get_data_block. 53739a53e0cSJaegeuk Kim */ 538266e97a8SJaegeuk Kim }; 539266e97a8SJaegeuk Kim 5407735730dSChao Yu #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO count */ 5417735730dSChao Yu 5425df7731fSChao Yu /* congestion wait timeout value, default: 20ms */ 5435df7731fSChao Yu #define DEFAULT_IO_TIMEOUT (msecs_to_jiffies(20)) 5445df7731fSChao Yu 545af033b2aSChao Yu /* maximum retry quota flush count */ 546af033b2aSChao Yu #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT 8 547af033b2aSChao Yu 548a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 54939a53e0cSJaegeuk Kim 550817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 551817202d9SChao Yu 55239a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 55313054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 55413054c54SChao Yu 55513054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 55613054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 557c11abd1aSJaegeuk Kim 55854c2258cSChao Yu struct rb_entry { 55954c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 5602e9b2bb2SChao Yu union { 5612e9b2bb2SChao Yu struct { 56254c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 56354c2258cSChao Yu unsigned int len; /* length of the entry */ 56454c2258cSChao Yu }; 5652e9b2bb2SChao Yu unsigned long long key; /* 64-bits key */ 56648046cb5SJaegeuk Kim } __packed; 5672e9b2bb2SChao Yu }; 56854c2258cSChao Yu 56939a53e0cSJaegeuk Kim struct extent_info { 57039a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 571111d2495SMasanari Iida unsigned int len; /* length of the extent */ 57254c2258cSChao Yu u32 blk; /* start block address of the extent */ 57339a53e0cSJaegeuk Kim }; 57439a53e0cSJaegeuk Kim 57513054c54SChao Yu struct extent_node { 576c0362117SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 57713054c54SChao Yu struct extent_info ei; /* extent info */ 57854c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 579201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 58013054c54SChao Yu }; 58113054c54SChao Yu 58213054c54SChao Yu struct extent_tree { 58313054c54SChao Yu nid_t ino; /* inode number */ 5844dada3fdSChao Yu struct rb_root_cached root; /* root of extent info rb-tree */ 58562c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 5863e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 587137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 58813054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 58968e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 590b430f726SZhikang Zhang bool largest_updated; /* largest extent updated */ 59113054c54SChao Yu }; 59213054c54SChao Yu 59339a53e0cSJaegeuk Kim /* 594003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 595003a3e1dSJaegeuk Kim * 596003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 597003a3e1dSJaegeuk Kim */ 598003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 599003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 6007f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 6017f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 6027f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 603003a3e1dSJaegeuk Kim 604003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 605003a3e1dSJaegeuk Kim block_t m_pblk; 606003a3e1dSJaegeuk Kim block_t m_lblk; 607003a3e1dSJaegeuk Kim unsigned int m_len; 608003a3e1dSJaegeuk Kim unsigned int m_flags; 609da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 610c4020b2dSChao Yu pgoff_t *m_next_extent; /* point to next possible extent */ 611d5097be5SHyunchul Lee int m_seg_type; 612f9d6d059SChao Yu bool m_may_create; /* indicate it is from write path */ 613003a3e1dSJaegeuk Kim }; 614003a3e1dSJaegeuk Kim 615e2b4e2bcSChao Yu /* for flag in get_data_block */ 616f2220c7fSQiuyang Sun enum { 617f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 618f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 619f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 6200a4daae5SJaegeuk Kim F2FS_GET_BLOCK_DIO, 621f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 622f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 623c4020b2dSChao Yu F2FS_GET_BLOCK_PRECACHE, 624f2220c7fSQiuyang Sun }; 625e2b4e2bcSChao Yu 626003a3e1dSJaegeuk Kim /* 62739a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 62839a53e0cSJaegeuk Kim */ 62939a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 630354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 631cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 632e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 63326787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 634b6a06cbbSChao Yu #define FADVISE_HOT_BIT 0x20 63595ae251fSEric Biggers #define FADVISE_VERITY_BIT 0x40 63639a53e0cSJaegeuk Kim 637797c1cb5SChao Yu #define FADVISE_MODIFIABLE_BITS (FADVISE_COLD_BIT | FADVISE_HOT_BIT) 638797c1cb5SChao Yu 639b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 640b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 641b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 6421153db09SChao Yu 6431153db09SChao Yu #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 6441153db09SChao Yu #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 645b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 6461153db09SChao Yu 647cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 648cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 6491153db09SChao Yu 650e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 651e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 6521153db09SChao Yu 65326787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 65426787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 6551153db09SChao Yu 656b6a06cbbSChao Yu #define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT) 657b6a06cbbSChao Yu #define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT) 658b6a06cbbSChao Yu #define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT) 6591153db09SChao Yu 66095ae251fSEric Biggers #define file_is_verity(inode) is_file(inode, FADVISE_VERITY_BIT) 66195ae251fSEric Biggers #define file_set_verity(inode) set_file(inode, FADVISE_VERITY_BIT) 662cde4de12SJaegeuk Kim 663ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 664ab9fa662SJaegeuk Kim 6652ef79ecbSChao Yu enum { 6662ef79ecbSChao Yu GC_FAILURE_PIN, 6672ef79ecbSChao Yu GC_FAILURE_ATOMIC, 6682ef79ecbSChao Yu MAX_GC_FAILURE 6692ef79ecbSChao Yu }; 6702ef79ecbSChao Yu 6717653b9d8SChao Yu /* used for f2fs_inode_info->flags */ 6727653b9d8SChao Yu enum { 6737653b9d8SChao Yu FI_NEW_INODE, /* indicate newly allocated inode */ 6747653b9d8SChao Yu FI_DIRTY_INODE, /* indicate inode is dirty or not */ 6757653b9d8SChao Yu FI_AUTO_RECOVER, /* indicate inode is recoverable */ 6767653b9d8SChao Yu FI_DIRTY_DIR, /* indicate directory has dirty pages */ 6777653b9d8SChao Yu FI_INC_LINK, /* need to increment i_nlink */ 6787653b9d8SChao Yu FI_ACL_MODE, /* indicate acl mode */ 6797653b9d8SChao Yu FI_NO_ALLOC, /* should not allocate any blocks */ 6807653b9d8SChao Yu FI_FREE_NID, /* free allocated nide */ 6817653b9d8SChao Yu FI_NO_EXTENT, /* not to use the extent cache */ 6827653b9d8SChao Yu FI_INLINE_XATTR, /* used for inline xattr */ 6837653b9d8SChao Yu FI_INLINE_DATA, /* used for inline data*/ 6847653b9d8SChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 6857653b9d8SChao Yu FI_APPEND_WRITE, /* inode has appended data */ 6867653b9d8SChao Yu FI_UPDATE_WRITE, /* inode has in-place-update data */ 6877653b9d8SChao Yu FI_NEED_IPU, /* used for ipu per file */ 6887653b9d8SChao Yu FI_ATOMIC_FILE, /* indicate atomic file */ 6897653b9d8SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 6907653b9d8SChao Yu FI_VOLATILE_FILE, /* indicate volatile file */ 6917653b9d8SChao Yu FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 6927653b9d8SChao Yu FI_DROP_CACHE, /* drop dirty page cache */ 6937653b9d8SChao Yu FI_DATA_EXIST, /* indicate data exists */ 6947653b9d8SChao Yu FI_INLINE_DOTS, /* indicate inline dot dentries */ 6957653b9d8SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 6967653b9d8SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 6977653b9d8SChao Yu FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 6987653b9d8SChao Yu FI_HOT_DATA, /* indicate file is hot */ 6997653b9d8SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 7007653b9d8SChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 7017653b9d8SChao Yu FI_PIN_FILE, /* indicate file should not be gced */ 7027653b9d8SChao Yu FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */ 7037653b9d8SChao Yu FI_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ 7047653b9d8SChao Yu FI_COMPRESSED_FILE, /* indicate file's data can be compressed */ 705b28f047bSChao Yu FI_COMPRESS_CORRUPT, /* indicate compressed cluster is corrupted */ 7067653b9d8SChao Yu FI_MMAP_FILE, /* indicate file was mmapped */ 707602a16d5SDaeho Jeong FI_ENABLE_COMPRESS, /* enable compression in "user" compression mode */ 7087653b9d8SChao Yu FI_MAX, /* max flag, never be used */ 7097653b9d8SChao Yu }; 7107653b9d8SChao Yu 71139a53e0cSJaegeuk Kim struct f2fs_inode_info { 71239a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 71339a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 71439a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 71538431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 7161ad71a27SJaegeuk Kim unsigned int i_current_depth; /* only for directory depth */ 7172ef79ecbSChao Yu /* for gc failure statistic */ 7182ef79ecbSChao Yu unsigned int i_gc_failures[MAX_GC_FAILURE]; 7196666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 72039a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 72139a53e0cSJaegeuk Kim 72239a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 7237653b9d8SChao Yu unsigned long flags[BITS_TO_LONGS(FI_MAX)]; /* use to pass per-file flags */ 724d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 725204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 72639a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 72739a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 72888c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 729b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 73039a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 73126de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 732c10c9820SChao Yu spinlock_t i_size_lock; /* protect last_disk_size */ 73388b88a66SJaegeuk Kim 7340abd675eSChao Yu #ifdef CONFIG_QUOTA 7350abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 7360abd675eSChao Yu 7370abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 7380abd675eSChao Yu qsize_t i_reserved_quota; 7390abd675eSChao Yu #endif 7400f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 7410f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 74257864ae5SJaegeuk Kim struct list_head inmem_ilist; /* list for inmem inodes */ 74388b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 7447a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 74588b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 7463e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 747b2532c69SChao Yu 748b2532c69SChao Yu /* avoid racing between foreground op and gc */ 749b2532c69SChao Yu struct rw_semaphore i_gc_rwsem[2]; 7505a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 75127161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 752f2470371SChao Yu 7537a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 7545c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 7556afc662eSChao Yu int i_inline_xattr_size; /* inline xattr size */ 75624b81dfcSArnd Bergmann struct timespec64 i_crtime; /* inode creation time */ 75724b81dfcSArnd Bergmann struct timespec64 i_disk_time[4];/* inode disk times */ 7584c8ff709SChao Yu 7594c8ff709SChao Yu /* for file compress */ 760c2759ebaSDaeho Jeong atomic_t i_compr_blocks; /* # of compressed blocks */ 7614c8ff709SChao Yu unsigned char i_compress_algorithm; /* algorithm type */ 7624c8ff709SChao Yu unsigned char i_log_cluster_size; /* log of cluster size */ 7633fde13f8SChao Yu unsigned char i_compress_level; /* compress level (lz4hc,zstd) */ 764b28f047bSChao Yu unsigned short i_compress_flag; /* compress flag */ 7654c8ff709SChao Yu unsigned int i_cluster_size; /* cluster size */ 76639a53e0cSJaegeuk Kim }; 76739a53e0cSJaegeuk Kim 76839a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 769bd933d4fSChao Yu struct f2fs_extent *i_ext) 77039a53e0cSJaegeuk Kim { 771bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 772bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 773bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 77439a53e0cSJaegeuk Kim } 77539a53e0cSJaegeuk Kim 77639a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 77739a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 77839a53e0cSJaegeuk Kim { 77939a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 7804d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 78139a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 78239a53e0cSJaegeuk Kim } 78339a53e0cSJaegeuk Kim 784429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 785429511cdSChao Yu u32 blk, unsigned int len) 786429511cdSChao Yu { 787429511cdSChao Yu ei->fofs = fofs; 788429511cdSChao Yu ei->blk = blk; 789429511cdSChao Yu ei->len = len; 790429511cdSChao Yu } 791429511cdSChao Yu 792004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 79335ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 794004b6862SChao Yu { 7959a997188SJaegeuk Kim return (back->lstart + back->len == front->lstart) && 79635ec7d57SChao Yu (back->len + front->len <= max_len); 797004b6862SChao Yu } 798004b6862SChao Yu 799004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 80035ec7d57SChao Yu struct discard_info *back, unsigned int max_len) 801004b6862SChao Yu { 80235ec7d57SChao Yu return __is_discard_mergeable(back, cur, max_len); 803004b6862SChao Yu } 804004b6862SChao Yu 805004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 80635ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 807004b6862SChao Yu { 80835ec7d57SChao Yu return __is_discard_mergeable(cur, front, max_len); 809004b6862SChao Yu } 810004b6862SChao Yu 811429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 812429511cdSChao Yu struct extent_info *front) 813429511cdSChao Yu { 814429511cdSChao Yu return (back->fofs + back->len == front->fofs && 815429511cdSChao Yu back->blk + back->len == front->blk); 816429511cdSChao Yu } 817429511cdSChao Yu 818429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 819429511cdSChao Yu struct extent_info *back) 820429511cdSChao Yu { 821429511cdSChao Yu return __is_extent_mergeable(back, cur); 822429511cdSChao Yu } 823429511cdSChao Yu 824429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 825429511cdSChao Yu struct extent_info *front) 826429511cdSChao Yu { 827429511cdSChao Yu return __is_extent_mergeable(cur, front); 828429511cdSChao Yu } 829429511cdSChao Yu 830cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 831b430f726SZhikang Zhang static inline void __try_update_largest_extent(struct extent_tree *et, 832b430f726SZhikang Zhang struct extent_node *en) 8334abd3f5aSChao Yu { 834205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 8354abd3f5aSChao Yu et->largest = en->ei; 836b430f726SZhikang Zhang et->largest_updated = true; 837205b9822SJaegeuk Kim } 8384abd3f5aSChao Yu } 8394abd3f5aSChao Yu 8409a4ffdf5SChao Yu /* 8419a4ffdf5SChao Yu * For free nid management 8429a4ffdf5SChao Yu */ 8439a4ffdf5SChao Yu enum nid_state { 8449a4ffdf5SChao Yu FREE_NID, /* newly added to free nid list */ 8459a4ffdf5SChao Yu PREALLOC_NID, /* it is preallocated */ 8469a4ffdf5SChao Yu MAX_NID_STATE, 847b8559dc2SChao Yu }; 848b8559dc2SChao Yu 849a95ba66aSJaegeuk Kim enum nat_state { 850a95ba66aSJaegeuk Kim TOTAL_NAT, 851a95ba66aSJaegeuk Kim DIRTY_NAT, 852a95ba66aSJaegeuk Kim RECLAIMABLE_NAT, 853a95ba66aSJaegeuk Kim MAX_NAT_STATE, 854a95ba66aSJaegeuk Kim }; 855a95ba66aSJaegeuk Kim 85639a53e0cSJaegeuk Kim struct f2fs_nm_info { 85739a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 85839a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 85904d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 86039a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 861cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 862ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 8632304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 86439a53e0cSJaegeuk Kim 86539a53e0cSJaegeuk Kim /* NAT cache management */ 86639a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 867309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 868f3e367d4Sqiulaibin struct rw_semaphore nat_tree_lock; /* protect nat entry tree */ 86939a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 87022969158SChao Yu spinlock_t nat_list_lock; /* protect clean nat entry list */ 871a95ba66aSJaegeuk Kim unsigned int nat_cnt[MAX_NAT_STATE]; /* the # of cached nat entries */ 87222ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 87339a53e0cSJaegeuk Kim 87439a53e0cSJaegeuk Kim /* free node ids management */ 8758a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 8769a4ffdf5SChao Yu struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ 8779a4ffdf5SChao Yu unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 878b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 87939a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 880bb1105e4SJaegeuk Kim unsigned char **free_nid_bitmap; 8814ac91242SChao Yu unsigned char *nat_block_bitmap; 882586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 88339a53e0cSJaegeuk Kim 88439a53e0cSJaegeuk Kim /* for checkpoint */ 88539a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 88622ad0b6aSJaegeuk Kim 88722ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 88822ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 88922ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 89022ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 891599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 892599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 893599a09b2SChao Yu #endif 89439a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 89539a53e0cSJaegeuk Kim }; 89639a53e0cSJaegeuk Kim 89739a53e0cSJaegeuk Kim /* 89839a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 89939a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 90039a53e0cSJaegeuk Kim * by the data offset in a file. 90139a53e0cSJaegeuk Kim */ 90239a53e0cSJaegeuk Kim struct dnode_of_data { 90339a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 90439a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 90539a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 90639a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 90739a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 90839a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 90993bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 9103cf45747SChao Yu char cur_level; /* level of hole node page */ 9113cf45747SChao Yu char max_level; /* level of current page located */ 91239a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 91339a53e0cSJaegeuk Kim }; 91439a53e0cSJaegeuk Kim 91539a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 91639a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 91739a53e0cSJaegeuk Kim { 918d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 91939a53e0cSJaegeuk Kim dn->inode = inode; 92039a53e0cSJaegeuk Kim dn->inode_page = ipage; 92139a53e0cSJaegeuk Kim dn->node_page = npage; 92239a53e0cSJaegeuk Kim dn->nid = nid; 92339a53e0cSJaegeuk Kim } 92439a53e0cSJaegeuk Kim 92539a53e0cSJaegeuk Kim /* 92639a53e0cSJaegeuk Kim * For SIT manager 92739a53e0cSJaegeuk Kim * 92839a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 92939a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 93039a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 93139a53e0cSJaegeuk Kim * respectively. 93239a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 93339a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 93439a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 93539a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 93639a53e0cSJaegeuk Kim * data and 8 for node logs. 93739a53e0cSJaegeuk Kim */ 93839a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 93939a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 940093749e2SChao Yu #define NR_CURSEG_INMEM_TYPE (2) 941d0b9e42aSChao Yu #define NR_CURSEG_PERSIST_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 942d0b9e42aSChao Yu #define NR_CURSEG_TYPE (NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE) 94339a53e0cSJaegeuk Kim 94439a53e0cSJaegeuk Kim enum { 94539a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 94639a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 94739a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 94839a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 94939a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 95039a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 951d0b9e42aSChao Yu NR_PERSISTENT_LOG, /* number of persistent log */ 952d0b9e42aSChao Yu CURSEG_COLD_DATA_PINNED = NR_PERSISTENT_LOG, 953d0b9e42aSChao Yu /* pinned file that needs consecutive block address */ 954093749e2SChao Yu CURSEG_ALL_DATA_ATGC, /* SSR alloctor in hot/warm/cold data area */ 955d0b9e42aSChao Yu NO_CHECK_TYPE, /* number of persistent & inmem log */ 95639a53e0cSJaegeuk Kim }; 95739a53e0cSJaegeuk Kim 9586b4afdd7SJaegeuk Kim struct flush_cmd { 9596b4afdd7SJaegeuk Kim struct completion wait; 960721bd4d5SGu Zheng struct llist_node llnode; 96139d787beSChao Yu nid_t ino; 9626b4afdd7SJaegeuk Kim int ret; 9636b4afdd7SJaegeuk Kim }; 9646b4afdd7SJaegeuk Kim 965a688b9d9SGu Zheng struct flush_cmd_control { 966a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 967a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 9688b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 96972691af6SJaegeuk Kim atomic_t queued_flush; /* # of queued flushes */ 970721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 971721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 972a688b9d9SGu Zheng }; 973a688b9d9SGu Zheng 97439a53e0cSJaegeuk Kim struct f2fs_sm_info { 97539a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 97639a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 97739a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 97839a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 97939a53e0cSJaegeuk Kim 9802b60311dSChao Yu struct rw_semaphore curseg_lock; /* for preventing curseg change */ 9812b60311dSChao Yu 98239a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 98339a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 98439a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 98539a53e0cSJaegeuk Kim 98639a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 98739a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 98839a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 98939a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 99081eb8d6eSJaegeuk Kim 99181eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 99281eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 9937fd9e544SJaegeuk Kim 994bba681cbSJaegeuk Kim /* for batched trimming */ 995bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 996bba681cbSJaegeuk Kim 997184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 998184a5cd2SChao Yu 999216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 1000216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 1001c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 1002853137ceSJaegeuk Kim unsigned int min_seq_blocks; /* threshold for sequential blocks */ 1003ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 1004a2a12b67SChao Yu unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ 10056b4afdd7SJaegeuk Kim 10066b4afdd7SJaegeuk Kim /* for flush command control */ 1007b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 1008a688b9d9SGu Zheng 10090b54fb84SJaegeuk Kim /* for discard command control */ 10100b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 101139a53e0cSJaegeuk Kim }; 101239a53e0cSJaegeuk Kim 101339a53e0cSJaegeuk Kim /* 101439a53e0cSJaegeuk Kim * For superblock 101539a53e0cSJaegeuk Kim */ 101639a53e0cSJaegeuk Kim /* 101739a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 101839a53e0cSJaegeuk Kim * 101939a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 102039a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 102139a53e0cSJaegeuk Kim */ 102236951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 102339a53e0cSJaegeuk Kim enum count_type { 102439a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 1025c227f912SChao Yu F2FS_DIRTY_DATA, 10262c8a4a28SJaegeuk Kim F2FS_DIRTY_QDATA, 102739a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 102839a53e0cSJaegeuk Kim F2FS_DIRTY_META, 10298dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 10300f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 103136951b38SChao Yu F2FS_WB_CP_DATA, 103236951b38SChao Yu F2FS_WB_DATA, 10335f9abab4SJaegeuk Kim F2FS_RD_DATA, 10345f9abab4SJaegeuk Kim F2FS_RD_NODE, 10355f9abab4SJaegeuk Kim F2FS_RD_META, 103602b16d0aSChao Yu F2FS_DIO_WRITE, 103702b16d0aSChao Yu F2FS_DIO_READ, 103839a53e0cSJaegeuk Kim NR_COUNT_TYPE, 103939a53e0cSJaegeuk Kim }; 104039a53e0cSJaegeuk Kim 104139a53e0cSJaegeuk Kim /* 1042e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 104339a53e0cSJaegeuk Kim * The available types are: 104439a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 104539a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 104639a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 104739a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 104839a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 104939a53e0cSJaegeuk Kim * with waiting the bio's completion 105039a53e0cSJaegeuk Kim * ... Only can be used with META. 105139a53e0cSJaegeuk Kim */ 10527d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 105339a53e0cSJaegeuk Kim enum page_type { 105439a53e0cSJaegeuk Kim DATA, 105539a53e0cSJaegeuk Kim NODE, 105639a53e0cSJaegeuk Kim META, 105739a53e0cSJaegeuk Kim NR_PAGE_TYPE, 105839a53e0cSJaegeuk Kim META_FLUSH, 10598ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 10608ce67cb0SJaegeuk Kim INMEM_DROP, 10618c242db9SJaegeuk Kim INMEM_INVALIDATE, 106228bc106bSChao Yu INMEM_REVOKE, 10638ce67cb0SJaegeuk Kim IPU, 10648ce67cb0SJaegeuk Kim OPU, 106539a53e0cSJaegeuk Kim }; 106639a53e0cSJaegeuk Kim 1067a912b54dSJaegeuk Kim enum temp_type { 1068a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 1069a912b54dSJaegeuk Kim WARM, 1070a912b54dSJaegeuk Kim COLD, 1071a912b54dSJaegeuk Kim NR_TEMP_TYPE, 1072a912b54dSJaegeuk Kim }; 1073a912b54dSJaegeuk Kim 1074cc15620bSJaegeuk Kim enum need_lock_type { 1075cc15620bSJaegeuk Kim LOCK_REQ = 0, 1076cc15620bSJaegeuk Kim LOCK_DONE, 1077cc15620bSJaegeuk Kim LOCK_RETRY, 1078cc15620bSJaegeuk Kim }; 1079cc15620bSJaegeuk Kim 1080a5fd5050SChao Yu enum cp_reason_type { 1081a5fd5050SChao Yu CP_NO_NEEDED, 1082a5fd5050SChao Yu CP_NON_REGULAR, 10834c8ff709SChao Yu CP_COMPRESSED, 1084a5fd5050SChao Yu CP_HARDLINK, 1085a5fd5050SChao Yu CP_SB_NEED_CP, 1086a5fd5050SChao Yu CP_WRONG_PINO, 1087a5fd5050SChao Yu CP_NO_SPC_ROLL, 1088a5fd5050SChao Yu CP_NODE_NEED_CP, 1089a5fd5050SChao Yu CP_FASTBOOT_MODE, 1090a5fd5050SChao Yu CP_SPEC_LOG_NUM, 10910a007b97SJaegeuk Kim CP_RECOVER_DIR, 1092a5fd5050SChao Yu }; 1093a5fd5050SChao Yu 1094b0af6d49SChao Yu enum iostat_type { 10958b83ac81SChao Yu /* WRITE IO */ 10968b83ac81SChao Yu APP_DIRECT_IO, /* app direct write IOs */ 10978b83ac81SChao Yu APP_BUFFERED_IO, /* app buffered write IOs */ 1098b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 1099b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 1100b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 1101b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 1102b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 1103b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 1104b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 1105b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 1106b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 1107b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 11088b83ac81SChao Yu 11098b83ac81SChao Yu /* READ IO */ 11108b83ac81SChao Yu APP_DIRECT_READ_IO, /* app direct read IOs */ 11118b83ac81SChao Yu APP_BUFFERED_READ_IO, /* app buffered read IOs */ 11128b83ac81SChao Yu APP_READ_IO, /* app read IOs */ 11138b83ac81SChao Yu APP_MAPPED_READ_IO, /* app mapped read IOs */ 11148b83ac81SChao Yu FS_DATA_READ_IO, /* data read IOs */ 11159c122384SChao Yu FS_GDATA_READ_IO, /* data read IOs from background gc */ 11169c122384SChao Yu FS_CDATA_READ_IO, /* compressed data read IOs */ 11178b83ac81SChao Yu FS_NODE_READ_IO, /* node read IOs */ 11188b83ac81SChao Yu FS_META_READ_IO, /* meta read IOs */ 11198b83ac81SChao Yu 11208b83ac81SChao Yu /* other */ 1121b0af6d49SChao Yu FS_DISCARD, /* discard */ 1122b0af6d49SChao Yu NR_IO_TYPE, 1123b0af6d49SChao Yu }; 1124b0af6d49SChao Yu 1125458e6197SJaegeuk Kim struct f2fs_io_info { 112605ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 112739d787beSChao Yu nid_t ino; /* inode number */ 1128458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 1129a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 113004d328deSMike Christie int op; /* contains REQ_OP_ */ 1131ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 11327a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 113328bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 113405ca3632SJaegeuk Kim struct page *page; /* page to be written */ 11354375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 11364c8ff709SChao Yu struct page *compressed_page; /* compressed page */ 1137fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 1138d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 1139cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 1140fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 11416dc3a126SChao Yu bool is_por; /* indicate IO is from recovery or not */ 1142fe16efe6SChao Yu bool retry; /* need to reallocate block address */ 11434c8ff709SChao Yu int compr_blocks; /* # of compressed block addresses */ 11444c8ff709SChao Yu bool encrypted; /* indicate file is encrypted */ 1145b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 1146578c6478SYufen Yu struct writeback_control *io_wbc; /* writeback control */ 11478648de2cSChao Yu struct bio **bio; /* bio for ipu */ 11488648de2cSChao Yu sector_t *last_block; /* last block number in bio */ 11497735730dSChao Yu unsigned char version; /* version of the node */ 1150458e6197SJaegeuk Kim }; 1151458e6197SJaegeuk Kim 11520b20fcecSChao Yu struct bio_entry { 11530b20fcecSChao Yu struct bio *bio; 11540b20fcecSChao Yu struct list_head list; 11550b20fcecSChao Yu }; 11560b20fcecSChao Yu 115768afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 11581ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 1159458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 11601ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 11611ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 1162458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 1163df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 1164fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 1165fb830fc5SChao Yu struct list_head io_list; /* track fios */ 11660b20fcecSChao Yu struct list_head bio_list; /* bio entry list head */ 11670b20fcecSChao Yu struct rw_semaphore bio_list_lock; /* lock to protect bio entry list */ 11681ff7bd3bSJaegeuk Kim }; 11691ff7bd3bSJaegeuk Kim 11703c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 11713c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 11723c62be17SJaegeuk Kim struct f2fs_dev_info { 11733c62be17SJaegeuk Kim struct block_device *bdev; 11743c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 11753c62be17SJaegeuk Kim unsigned int total_segments; 11763c62be17SJaegeuk Kim block_t start_blk; 11773c62be17SJaegeuk Kim block_t end_blk; 11783c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 11793c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 118095175dafSDamien Le Moal unsigned long *blkz_seq; /* Bitmap indicating sequential zones */ 1181de881df9SAravind Ramesh block_t *zone_capacity_blocks; /* Array of zone capacity in blks */ 11823c62be17SJaegeuk Kim #endif 11833c62be17SJaegeuk Kim }; 11843c62be17SJaegeuk Kim 1185c227f912SChao Yu enum inode_type { 1186c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 1187c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 11880f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 118957864ae5SJaegeuk Kim ATOMIC_FILE, /* for all atomic files */ 1190c227f912SChao Yu NR_INODE_TYPE, 1191c227f912SChao Yu }; 1192c227f912SChao Yu 119367298804SChao Yu /* for inner inode cache management */ 119467298804SChao Yu struct inode_management { 119567298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 119667298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 119767298804SChao Yu struct list_head ino_list; /* inode list head */ 119867298804SChao Yu unsigned long ino_num; /* number of entries */ 119967298804SChao Yu }; 120067298804SChao Yu 1201093749e2SChao Yu /* for GC_AT */ 1202093749e2SChao Yu struct atgc_management { 1203093749e2SChao Yu bool atgc_enabled; /* ATGC is enabled or not */ 1204093749e2SChao Yu struct rb_root_cached root; /* root of victim rb-tree */ 1205093749e2SChao Yu struct list_head victim_list; /* linked with all victim entries */ 1206093749e2SChao Yu unsigned int victim_count; /* victim count in rb-tree */ 1207093749e2SChao Yu unsigned int candidate_ratio; /* candidate ratio */ 1208093749e2SChao Yu unsigned int max_candidate_count; /* max candidate count */ 1209093749e2SChao Yu unsigned int age_weight; /* age weight, vblock_weight = 100 - age_weight */ 1210093749e2SChao Yu unsigned long long age_threshold; /* age threshold */ 1211093749e2SChao Yu }; 1212093749e2SChao Yu 1213caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 1214caf0047eSChao Yu enum { 1215caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 1216caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 1217caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 1218caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 1219df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 1220bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 122183a3bfdbSJaegeuk Kim SBI_IS_SHUTDOWN, /* shutdown by ioctl */ 12221378752bSChao Yu SBI_IS_RECOVERED, /* recovered orphan/data */ 12234354994fSDaniel Rosenberg SBI_CP_DISABLED, /* CP was disabled last mount */ 1224db610a64SJaegeuk Kim SBI_CP_DISABLED_QUICK, /* CP was disabled quickly */ 1225af033b2aSChao Yu SBI_QUOTA_NEED_FLUSH, /* need to flush quota info in CP */ 1226af033b2aSChao Yu SBI_QUOTA_SKIP_FLUSH, /* skip flushing quota in current CP */ 1227af033b2aSChao Yu SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */ 122804f0b2eaSQiuyang Sun SBI_IS_RESIZEFS, /* resizefs is in process */ 1229caf0047eSChao Yu }; 1230caf0047eSChao Yu 12316beceb54SJaegeuk Kim enum { 12326beceb54SJaegeuk Kim CP_TIME, 1233d0239e1bSJaegeuk Kim REQ_TIME, 1234a7d10cf3SSahitya Tummala DISCARD_TIME, 1235a7d10cf3SSahitya Tummala GC_TIME, 12364354994fSDaniel Rosenberg DISABLE_TIME, 123703f2c02dSJaegeuk Kim UMOUNT_DISCARD_TIMEOUT, 12386beceb54SJaegeuk Kim MAX_TIME, 12396beceb54SJaegeuk Kim }; 12406beceb54SJaegeuk Kim 12410cdd3195SHyunchul Lee enum { 12425b0e9539SJaegeuk Kim GC_NORMAL, 12435b0e9539SJaegeuk Kim GC_IDLE_CB, 12445b0e9539SJaegeuk Kim GC_IDLE_GREEDY, 1245093749e2SChao Yu GC_IDLE_AT, 12460e5e8111SDaeho Jeong GC_URGENT_HIGH, 12470e5e8111SDaeho Jeong GC_URGENT_LOW, 12485b0e9539SJaegeuk Kim }; 12495b0e9539SJaegeuk Kim 12505b0e9539SJaegeuk Kim enum { 1251bbbc34fdSChao Yu BGGC_MODE_ON, /* background gc is on */ 1252bbbc34fdSChao Yu BGGC_MODE_OFF, /* background gc is off */ 1253bbbc34fdSChao Yu BGGC_MODE_SYNC, /* 1254bbbc34fdSChao Yu * background gc is on, migrating blocks 1255bbbc34fdSChao Yu * like foreground gc 1256bbbc34fdSChao Yu */ 1257bbbc34fdSChao Yu }; 1258bbbc34fdSChao Yu 1259bbbc34fdSChao Yu enum { 1260b0332a0fSChao Yu FS_MODE_ADAPTIVE, /* use both lfs/ssr allocation */ 1261b0332a0fSChao Yu FS_MODE_LFS, /* use lfs allocation only */ 1262b0332a0fSChao Yu }; 1263b0332a0fSChao Yu 1264b0332a0fSChao Yu enum { 12650cdd3195SHyunchul Lee WHINT_MODE_OFF, /* not pass down write hints */ 12660cdd3195SHyunchul Lee WHINT_MODE_USER, /* try to pass down hints given by users */ 1267f2e703f9SHyunchul Lee WHINT_MODE_FS, /* pass down hints with F2FS policy */ 12680cdd3195SHyunchul Lee }; 12690cdd3195SHyunchul Lee 127007939627SJaegeuk Kim enum { 127107939627SJaegeuk Kim ALLOC_MODE_DEFAULT, /* stay default */ 127207939627SJaegeuk Kim ALLOC_MODE_REUSE, /* reuse segments as much as possible */ 127307939627SJaegeuk Kim }; 127407939627SJaegeuk Kim 127593cf93f1SJunling Zheng enum fsync_mode { 127693cf93f1SJunling Zheng FSYNC_MODE_POSIX, /* fsync follows posix semantics */ 127793cf93f1SJunling Zheng FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */ 1278d6290814SJaegeuk Kim FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */ 127993cf93f1SJunling Zheng }; 128093cf93f1SJunling Zheng 1281602a16d5SDaeho Jeong enum { 1282602a16d5SDaeho Jeong COMPR_MODE_FS, /* 1283602a16d5SDaeho Jeong * automatically compress compression 1284602a16d5SDaeho Jeong * enabled files 1285602a16d5SDaeho Jeong */ 1286602a16d5SDaeho Jeong COMPR_MODE_USER, /* 1287602a16d5SDaeho Jeong * automatical compression is disabled. 1288602a16d5SDaeho Jeong * user can control the file compression 1289602a16d5SDaeho Jeong * using ioctls 1290602a16d5SDaeho Jeong */ 1291602a16d5SDaeho Jeong }; 1292602a16d5SDaeho Jeong 12934c8ff709SChao Yu /* 12944c8ff709SChao Yu * this value is set in page as a private data which indicate that 12954c8ff709SChao Yu * the page is atomically written, and it is in inmem_pages list. 12964c8ff709SChao Yu */ 12974c8ff709SChao Yu #define ATOMIC_WRITTEN_PAGE ((unsigned long)-1) 12984c8ff709SChao Yu #define DUMMY_WRITTEN_PAGE ((unsigned long)-2) 12994c8ff709SChao Yu 13004c8ff709SChao Yu #define IS_ATOMIC_WRITTEN_PAGE(page) \ 1301e90027d2SXiaojun Wang (page_private(page) == ATOMIC_WRITTEN_PAGE) 13024c8ff709SChao Yu #define IS_DUMMY_WRITTEN_PAGE(page) \ 1303e90027d2SXiaojun Wang (page_private(page) == DUMMY_WRITTEN_PAGE) 13044c8ff709SChao Yu 130529b993c7SYu Changchun #ifdef CONFIG_F2FS_IO_TRACE 130629b993c7SYu Changchun #define IS_IO_TRACED_PAGE(page) \ 130729b993c7SYu Changchun (page_private(page) > 0 && \ 130829b993c7SYu Changchun page_private(page) < (unsigned long)PID_MAX_LIMIT) 130929b993c7SYu Changchun #else 131029b993c7SYu Changchun #define IS_IO_TRACED_PAGE(page) (0) 131129b993c7SYu Changchun #endif 131229b993c7SYu Changchun 13134c8ff709SChao Yu /* For compression */ 13144c8ff709SChao Yu enum compress_algorithm_type { 13154c8ff709SChao Yu COMPRESS_LZO, 13164c8ff709SChao Yu COMPRESS_LZ4, 131750cfa66fSChao Yu COMPRESS_ZSTD, 13186d92b201SChao Yu COMPRESS_LZORLE, 13194c8ff709SChao Yu COMPRESS_MAX, 13204c8ff709SChao Yu }; 13214c8ff709SChao Yu 1322b28f047bSChao Yu enum compress_flag { 1323b28f047bSChao Yu COMPRESS_CHKSUM, 1324b28f047bSChao Yu COMPRESS_MAX_FLAG, 1325b28f047bSChao Yu }; 1326b28f047bSChao Yu 1327b28f047bSChao Yu #define COMPRESS_DATA_RESERVED_SIZE 4 13284c8ff709SChao Yu struct compress_data { 13294c8ff709SChao Yu __le32 clen; /* compressed data size */ 1330b28f047bSChao Yu __le32 chksum; /* compressed data chksum */ 13314c8ff709SChao Yu __le32 reserved[COMPRESS_DATA_RESERVED_SIZE]; /* reserved */ 13324c8ff709SChao Yu u8 cdata[]; /* compressed data */ 13334c8ff709SChao Yu }; 13344c8ff709SChao Yu 13354c8ff709SChao Yu #define COMPRESS_HEADER_SIZE (sizeof(struct compress_data)) 13364c8ff709SChao Yu 13374c8ff709SChao Yu #define F2FS_COMPRESSED_PAGE_MAGIC 0xF5F2C000 13384c8ff709SChao Yu 13393fde13f8SChao Yu #define COMPRESS_LEVEL_OFFSET 8 13403fde13f8SChao Yu 13414c8ff709SChao Yu /* compress context */ 13424c8ff709SChao Yu struct compress_ctx { 13434c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 13444c8ff709SChao Yu pgoff_t cluster_idx; /* cluster index number */ 13454c8ff709SChao Yu unsigned int cluster_size; /* page count in cluster */ 13464c8ff709SChao Yu unsigned int log_cluster_size; /* log of cluster size */ 13474c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 13484c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 13494c8ff709SChao Yu struct page **cpages; /* pages store compressed data in cluster */ 13504c8ff709SChao Yu unsigned int nr_cpages; /* total page number in cpages */ 13514c8ff709SChao Yu void *rbuf; /* virtual mapped address on rpages */ 13524c8ff709SChao Yu struct compress_data *cbuf; /* virtual mapped address on cpages */ 13534c8ff709SChao Yu size_t rlen; /* valid data length in rbuf */ 13544c8ff709SChao Yu size_t clen; /* valid data length in cbuf */ 13554c8ff709SChao Yu void *private; /* payload buffer for specified compression algorithm */ 135650cfa66fSChao Yu void *private2; /* extra payload buffer */ 13574c8ff709SChao Yu }; 13584c8ff709SChao Yu 13594c8ff709SChao Yu /* compress context for write IO path */ 13604c8ff709SChao Yu struct compress_io_ctx { 13614c8ff709SChao Yu u32 magic; /* magic number to indicate page is compressed */ 13624c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 13634c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 13644c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 1365e6c3948dSChao Yu atomic_t pending_pages; /* in-flight compressed page count */ 13664c8ff709SChao Yu }; 13674c8ff709SChao Yu 13687f59b277SEric Biggers /* Context for decompressing one cluster on the read IO path */ 13694c8ff709SChao Yu struct decompress_io_ctx { 13704c8ff709SChao Yu u32 magic; /* magic number to indicate page is compressed */ 13714c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 13724c8ff709SChao Yu pgoff_t cluster_idx; /* cluster index number */ 13734c8ff709SChao Yu unsigned int cluster_size; /* page count in cluster */ 13744c8ff709SChao Yu unsigned int log_cluster_size; /* log of cluster size */ 13754c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 13764c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 13774c8ff709SChao Yu struct page **cpages; /* pages store compressed data in cluster */ 13784c8ff709SChao Yu unsigned int nr_cpages; /* total page number in cpages */ 13794c8ff709SChao Yu struct page **tpages; /* temp pages to pad holes in cluster */ 13804c8ff709SChao Yu void *rbuf; /* virtual mapped address on rpages */ 13814c8ff709SChao Yu struct compress_data *cbuf; /* virtual mapped address on cpages */ 13824c8ff709SChao Yu size_t rlen; /* valid data length in rbuf */ 13834c8ff709SChao Yu size_t clen; /* valid data length in cbuf */ 13847f59b277SEric Biggers 13857f59b277SEric Biggers /* 13867f59b277SEric Biggers * The number of compressed pages remaining to be read in this cluster. 13877f59b277SEric Biggers * This is initially nr_cpages. It is decremented by 1 each time a page 13887f59b277SEric Biggers * has been read (or failed to be read). When it reaches 0, the cluster 13897f59b277SEric Biggers * is decompressed (or an error is reported). 13907f59b277SEric Biggers * 13917f59b277SEric Biggers * If an error occurs before all the pages have been submitted for I/O, 13927f59b277SEric Biggers * then this will never reach 0. In this case the I/O submitter is 13937f59b277SEric Biggers * responsible for calling f2fs_decompress_end_io() instead. 13947f59b277SEric Biggers */ 13957f59b277SEric Biggers atomic_t remaining_pages; 13967f59b277SEric Biggers 13977f59b277SEric Biggers /* 13987f59b277SEric Biggers * Number of references to this decompress_io_ctx. 13997f59b277SEric Biggers * 14007f59b277SEric Biggers * One reference is held for I/O completion. This reference is dropped 14017f59b277SEric Biggers * after the pagecache pages are updated and unlocked -- either after 14027f59b277SEric Biggers * decompression (and verity if enabled), or after an error. 14037f59b277SEric Biggers * 14047f59b277SEric Biggers * In addition, each compressed page holds a reference while it is in a 14057f59b277SEric Biggers * bio. These references are necessary prevent compressed pages from 14067f59b277SEric Biggers * being freed while they are still in a bio. 14077f59b277SEric Biggers */ 14087f59b277SEric Biggers refcount_t refcnt; 14097f59b277SEric Biggers 14107f59b277SEric Biggers bool failed; /* IO error occurred before decompression? */ 14117f59b277SEric Biggers bool need_verity; /* need fs-verity verification after decompression? */ 141250cfa66fSChao Yu void *private; /* payload buffer for specified decompression algorithm */ 141350cfa66fSChao Yu void *private2; /* extra payload buffer */ 14147f59b277SEric Biggers struct work_struct verity_work; /* work to verify the decompressed pages */ 14154c8ff709SChao Yu }; 14164c8ff709SChao Yu 14174c8ff709SChao Yu #define NULL_CLUSTER ((unsigned int)(~0)) 14184c8ff709SChao Yu #define MIN_COMPRESS_LOG_SIZE 2 14194c8ff709SChao Yu #define MAX_COMPRESS_LOG_SIZE 8 14200e2b7385SChao Yu #define MAX_COMPRESS_WINDOW_SIZE(log_size) ((PAGE_SIZE) << (log_size)) 14214c8ff709SChao Yu 142239a53e0cSJaegeuk Kim struct f2fs_sb_info { 142339a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 14245e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 142539a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 1426846ae671SChao Yu struct rw_semaphore sb_lock; /* lock for raw super block */ 1427e8240f65SChao Yu int valid_super_block; /* valid super block no */ 1428fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 1429853137ceSJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 143039a53e0cSJaegeuk Kim 1431178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 1432178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1433178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 1434178053e2SDamien Le Moal #endif 1435178053e2SDamien Le Moal 143639a53e0cSJaegeuk Kim /* for node-related operations */ 143739a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 143839a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 143939a53e0cSJaegeuk Kim 144039a53e0cSJaegeuk Kim /* for segment-related operations */ 144139a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 14421ff7bd3bSJaegeuk Kim 14431ff7bd3bSJaegeuk Kim /* for bio operations */ 1444a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1445107a805dSChao Yu /* keep migration IO order for LFS mode */ 1446107a805dSChao Yu struct rw_semaphore io_order_lock; 14470a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 144839a53e0cSJaegeuk Kim 144939a53e0cSJaegeuk Kim /* for checkpoint */ 145039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 14518508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1452aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 145339a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 14548769918bSSahitya Tummala struct rw_semaphore cp_global_sem; /* checkpoint procedure lock */ 1455b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1456b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 145759c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1458fb51b5efSChangman Lee wait_queue_head_t cp_wait; 14596beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 14606beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 1461261eeb9cSDaeho Jeong struct ckpt_req_control cprc_info; /* for checkpoint request control */ 146239a53e0cSJaegeuk Kim 146367298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 14646451e041SJaegeuk Kim 146550fa53ecSChao Yu spinlock_t fsync_node_lock; /* for node entry lock */ 146650fa53ecSChao Yu struct list_head fsync_node_list; /* node list head */ 146750fa53ecSChao Yu unsigned int fsync_seg_id; /* sequence id */ 146850fa53ecSChao Yu unsigned int fsync_node_num; /* number of node entries */ 146950fa53ecSChao Yu 14706451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 14710d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 147239a53e0cSJaegeuk Kim 1473c227f912SChao Yu /* for inode management */ 1474c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1475c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 1476040d2bb3SChao Yu struct mutex flush_lock; /* for flush exclusion */ 147739a53e0cSJaegeuk Kim 147813054c54SChao Yu /* for extent tree cache */ 147913054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 14805e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 148113054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 148213054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 14837441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1484137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 148574fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 148613054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 148713054c54SChao Yu 148839a53e0cSJaegeuk Kim /* basic filesystem units */ 148939a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 149039a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 149139a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 149239a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 149339a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 149439a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 149539a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 149639a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 149739a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 149839a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 149939a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 150039a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 150139a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1502ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 1503f6df8f23SSheng Yong int readdir_ra; /* readahead inode in readdir */ 150410208567SJaegeuk Kim u64 max_io_bytes; /* max io bytes to merge IOs */ 150539a53e0cSJaegeuk Kim 150639a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 150739a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1508a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 150939a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1510daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 151180d42145SYunlong Song block_t current_reserved_blocks; /* current reserved blocks */ 1512daeb433eSChao Yu 15134354994fSDaniel Rosenberg /* Additional tracking for no checkpoint mode */ 15144354994fSDaniel Rosenberg block_t unusable_block_count; /* # of blocks saved by last cp */ 15154354994fSDaniel Rosenberg 1516292c196aSChao Yu unsigned int nquota_files; /* # of quota sysfile */ 1517db6ec53bSJaegeuk Kim struct rw_semaphore quota_sem; /* blocking cp for flags */ 1518292c196aSChao Yu 1519523be8a6SJaegeuk Kim /* # of pages, see count_type */ 152035782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 152141382ec4SJaegeuk Kim /* # of allocated blocks */ 152241382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 152339a53e0cSJaegeuk Kim 1524687de7f1SJaegeuk Kim /* writeback control */ 1525c29fd0c0SChao Yu atomic_t wb_sync_req[META]; /* count # of WB_SYNC threads */ 1526687de7f1SJaegeuk Kim 1527513c5f37SJaegeuk Kim /* valid inode count */ 1528513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1529513c5f37SJaegeuk Kim 153039a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 153139a53e0cSJaegeuk Kim 153239a53e0cSJaegeuk Kim /* for cleaning operations */ 1533fb24fea7SChao Yu struct rw_semaphore gc_lock; /* 1534fb24fea7SChao Yu * semaphore for GC, avoid 1535fb24fea7SChao Yu * race between GC and GC or CP 1536fb24fea7SChao Yu */ 153739a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 1538093749e2SChao Yu struct atgc_management am; /* atgc management */ 15395ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 15405b0e9539SJaegeuk Kim unsigned int gc_mode; /* current GC state */ 1541e3080b01SChao Yu unsigned int next_victim_seg[2]; /* next segment in victim section */ 15420e5e8111SDaeho Jeong 15432ef79ecbSChao Yu /* for skip statistic */ 1544677017d1SSahitya Tummala unsigned int atomic_files; /* # of opened atomic file */ 15452ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */ 15466f8d4455SJaegeuk Kim unsigned long long skipped_gc_rwsem; /* FG_GC only */ 154739a53e0cSJaegeuk Kim 15481ad71a27SJaegeuk Kim /* threshold for gc trials on pinned files */ 15491ad71a27SJaegeuk Kim u64 gc_pin_file_threshold; 1550f5a53edcSJaegeuk Kim struct rw_semaphore pin_sem; 15511ad71a27SJaegeuk Kim 1552b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1553b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1554e3080b01SChao Yu /* migration granularity of garbage collection, unit: segment */ 1555e3080b01SChao Yu unsigned int migration_granularity; 1556b1c57c1cSJaegeuk Kim 155739a53e0cSJaegeuk Kim /* 155839a53e0cSJaegeuk Kim * for stat information. 155939a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 156039a53e0cSJaegeuk Kim */ 156135b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 156239a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 1563b63e7be5SChao Yu atomic_t meta_count[META_MAX]; /* # of meta blocks */ 156439a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 156539a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1566b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 15675b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 15685b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 15695b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 15705b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1571d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 157203e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 157303e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 15744c8ff709SChao Yu atomic_t compr_inode; /* # of compressed inodes */ 1575ae999bb9SDaeho Jeong atomic64_t compr_blocks; /* # of compressed blocks */ 1576648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 157726a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1578648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 1579274bd9baSChao Yu unsigned int io_skip_bggc; /* skip background gc for in-flight IO */ 1580274bd9baSChao Yu unsigned int other_skip_bggc; /* skip background gc for other reasons */ 158133fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 158235b09d82SNamjae Jeon #endif 158339a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1584b59d0baeSNamjae Jeon 1585b0af6d49SChao Yu /* For app/fs IO statistics */ 1586b0af6d49SChao Yu spinlock_t iostat_lock; 15878b83ac81SChao Yu unsigned long long rw_iostat[NR_IO_TYPE]; 15888b83ac81SChao Yu unsigned long long prev_rw_iostat[NR_IO_TYPE]; 1589b0af6d49SChao Yu bool iostat_enable; 15902bc4bea3SDaeho Jeong unsigned long iostat_next_period; 15912bc4bea3SDaeho Jeong unsigned int iostat_period_ms; 1592b0af6d49SChao Yu 1593da9953b7SJaegeuk Kim /* to attach REQ_META|REQ_FUA flags */ 1594da9953b7SJaegeuk Kim unsigned int data_io_flag; 159532b6aba8SJaegeuk Kim unsigned int node_io_flag; 1596b59d0baeSNamjae Jeon 1597b59d0baeSNamjae Jeon /* For sysfs suppport */ 15985d4daa57SChao Yu struct kobject s_kobj; /* /sys/fs/f2fs/<devname> */ 1599b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 16002658e50dSJaegeuk Kim 16015d4daa57SChao Yu struct kobject s_stat_kobj; /* /sys/fs/f2fs/<devname>/stat */ 16025d4daa57SChao Yu struct completion s_stat_kobj_unregister; 16035d4daa57SChao Yu 16042658e50dSJaegeuk Kim /* For shrinker support */ 16052658e50dSJaegeuk Kim struct list_head s_list; 16063c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 16073c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 16081228b482SChao Yu unsigned int dirty_device; /* for checkpoint data flush */ 16091228b482SChao Yu spinlock_t dev_lock; /* protect dirty_device */ 16102658e50dSJaegeuk Kim struct mutex umount_mutex; 16112658e50dSJaegeuk Kim unsigned int shrinker_run_no; 16128f1dbbbbSShuoran Liu 16138f1dbbbbSShuoran Liu /* For write statistics */ 16148f1dbbbbSShuoran Liu u64 sectors_written_start; 16158f1dbbbbSShuoran Liu u64 kbytes_written; 161643b6573bSKeith Mok 161743b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 161843b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 16191ecc0c5cSChao Yu 1620704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1621704956ecSChao Yu __u32 s_chksum_seed; 16224c8ff709SChao Yu 16234c8ff709SChao Yu struct workqueue_struct *post_read_wq; /* post read workqueue */ 1624a999150fSChao Yu 1625a999150fSChao Yu struct kmem_cache *inline_xattr_slab; /* inline xattr entry */ 1626a999150fSChao Yu unsigned int inline_xattr_slab_size; /* default inline xattr slab size */ 162731083031SChao Yu 162831083031SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 162931083031SChao Yu struct kmem_cache *page_array_slab; /* page array entry */ 163031083031SChao Yu unsigned int page_array_slab_size; /* default page array slab size */ 16315ac443e2SDaeho Jeong 16325ac443e2SDaeho Jeong /* For runtime compression statistics */ 16335ac443e2SDaeho Jeong u64 compr_written_block; 16345ac443e2SDaeho Jeong u64 compr_saved_block; 16355ac443e2SDaeho Jeong u32 compr_new_inode; 163631083031SChao Yu #endif 163739a53e0cSJaegeuk Kim }; 163839a53e0cSJaegeuk Kim 163902b16d0aSChao Yu struct f2fs_private_dio { 164002b16d0aSChao Yu struct inode *inode; 164102b16d0aSChao Yu void *orig_private; 164202b16d0aSChao Yu bio_end_io_t *orig_end_io; 164302b16d0aSChao Yu bool write; 164402b16d0aSChao Yu }; 164502b16d0aSChao Yu 16461ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 1647c45d6002SChao Yu #define f2fs_show_injection_info(sbi, type) \ 1648c45d6002SChao Yu printk_ratelimited("%sF2FS-fs (%s) : inject %s in %s of %pS\n", \ 1649c45d6002SChao Yu KERN_INFO, sbi->sb->s_id, \ 1650c45d6002SChao Yu f2fs_fault_name[type], \ 165155523519SChao Yu __func__, __builtin_return_address(0)) 16521ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 16531ecc0c5cSChao Yu { 165463189b78SChao Yu struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; 16551ecc0c5cSChao Yu 16561ecc0c5cSChao Yu if (!ffi->inject_rate) 16571ecc0c5cSChao Yu return false; 16581ecc0c5cSChao Yu 16591ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 16601ecc0c5cSChao Yu return false; 16611ecc0c5cSChao Yu 16621ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 16631ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 16641ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 16651ecc0c5cSChao Yu return true; 16661ecc0c5cSChao Yu } 16671ecc0c5cSChao Yu return false; 16681ecc0c5cSChao Yu } 16697fa750a1SArnd Bergmann #else 1670c45d6002SChao Yu #define f2fs_show_injection_info(sbi, type) do { } while (0) 16717fa750a1SArnd Bergmann static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 16727fa750a1SArnd Bergmann { 16737fa750a1SArnd Bergmann return false; 16747fa750a1SArnd Bergmann } 16751ecc0c5cSChao Yu #endif 16761ecc0c5cSChao Yu 16770916878dSDamien Le Moal /* 16780916878dSDamien Le Moal * Test if the mounted volume is a multi-device volume. 16790916878dSDamien Le Moal * - For a single regular disk volume, sbi->s_ndevs is 0. 16800916878dSDamien Le Moal * - For a single zoned disk volume, sbi->s_ndevs is 1. 16810916878dSDamien Le Moal * - For a multi-device volume, sbi->s_ndevs is always 2 or more. 16820916878dSDamien Le Moal */ 16830916878dSDamien Le Moal static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi) 16840916878dSDamien Le Moal { 16850916878dSDamien Le Moal return sbi->s_ndevs > 1; 16860916878dSDamien Le Moal } 16870916878dSDamien Le Moal 16886beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 16896beceb54SJaegeuk Kim { 1690a7d10cf3SSahitya Tummala unsigned long now = jiffies; 1691a7d10cf3SSahitya Tummala 1692a7d10cf3SSahitya Tummala sbi->last_time[type] = now; 1693a7d10cf3SSahitya Tummala 1694a7d10cf3SSahitya Tummala /* DISCARD_TIME and GC_TIME are based on REQ_TIME */ 1695a7d10cf3SSahitya Tummala if (type == REQ_TIME) { 1696a7d10cf3SSahitya Tummala sbi->last_time[DISCARD_TIME] = now; 1697a7d10cf3SSahitya Tummala sbi->last_time[GC_TIME] = now; 1698a7d10cf3SSahitya Tummala } 16996beceb54SJaegeuk Kim } 17006beceb54SJaegeuk Kim 17016beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 17026beceb54SJaegeuk Kim { 17036bccfa19SArnd Bergmann unsigned long interval = sbi->interval_time[type] * HZ; 17046beceb54SJaegeuk Kim 17056beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 17066beceb54SJaegeuk Kim } 17076beceb54SJaegeuk Kim 1708a7d10cf3SSahitya Tummala static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi, 1709a7d10cf3SSahitya Tummala int type) 1710a7d10cf3SSahitya Tummala { 1711a7d10cf3SSahitya Tummala unsigned long interval = sbi->interval_time[type] * HZ; 1712a7d10cf3SSahitya Tummala unsigned int wait_ms = 0; 1713a7d10cf3SSahitya Tummala long delta; 1714a7d10cf3SSahitya Tummala 1715a7d10cf3SSahitya Tummala delta = (sbi->last_time[type] + interval) - jiffies; 1716a7d10cf3SSahitya Tummala if (delta > 0) 1717a7d10cf3SSahitya Tummala wait_ms = jiffies_to_msecs(delta); 1718a7d10cf3SSahitya Tummala 1719a7d10cf3SSahitya Tummala return wait_ms; 1720a7d10cf3SSahitya Tummala } 1721a7d10cf3SSahitya Tummala 172239a53e0cSJaegeuk Kim /* 172339a53e0cSJaegeuk Kim * Inline functions 172439a53e0cSJaegeuk Kim */ 1725416d2dbbSChao Yu static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc, 1726704956ecSChao Yu const void *address, unsigned int length) 1727704956ecSChao Yu { 1728704956ecSChao Yu struct { 1729704956ecSChao Yu struct shash_desc shash; 1730704956ecSChao Yu char ctx[4]; 1731704956ecSChao Yu } desc; 1732704956ecSChao Yu int err; 1733704956ecSChao Yu 1734704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1735704956ecSChao Yu 1736704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1737704956ecSChao Yu *(u32 *)desc.ctx = crc; 1738704956ecSChao Yu 1739704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1740704956ecSChao Yu BUG_ON(err); 1741704956ecSChao Yu 1742704956ecSChao Yu return *(u32 *)desc.ctx; 1743704956ecSChao Yu } 1744704956ecSChao Yu 1745416d2dbbSChao Yu static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 1746416d2dbbSChao Yu unsigned int length) 1747416d2dbbSChao Yu { 1748416d2dbbSChao Yu return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length); 1749416d2dbbSChao Yu } 1750416d2dbbSChao Yu 1751416d2dbbSChao Yu static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 1752416d2dbbSChao Yu void *buf, size_t buf_size) 1753416d2dbbSChao Yu { 1754416d2dbbSChao Yu return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 1755416d2dbbSChao Yu } 1756416d2dbbSChao Yu 1757416d2dbbSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1758416d2dbbSChao Yu const void *address, unsigned int length) 1759416d2dbbSChao Yu { 1760416d2dbbSChao Yu return __f2fs_crc32(sbi, crc, address, length); 1761416d2dbbSChao Yu } 1762416d2dbbSChao Yu 176339a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 176439a53e0cSJaegeuk Kim { 176539a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 176639a53e0cSJaegeuk Kim } 176739a53e0cSJaegeuk Kim 176839a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 176939a53e0cSJaegeuk Kim { 177039a53e0cSJaegeuk Kim return sb->s_fs_info; 177139a53e0cSJaegeuk Kim } 177239a53e0cSJaegeuk Kim 17734081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 17744081363fSJaegeuk Kim { 17754081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 17764081363fSJaegeuk Kim } 17774081363fSJaegeuk Kim 17784081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 17794081363fSJaegeuk Kim { 17804081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 17814081363fSJaegeuk Kim } 17824081363fSJaegeuk Kim 17834081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 17844081363fSJaegeuk Kim { 17854969c06aSJaegeuk Kim return F2FS_M_SB(page_file_mapping(page)); 17864081363fSJaegeuk Kim } 17874081363fSJaegeuk Kim 178839a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 178939a53e0cSJaegeuk Kim { 179039a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 179139a53e0cSJaegeuk Kim } 179239a53e0cSJaegeuk Kim 179339a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 179439a53e0cSJaegeuk Kim { 179539a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 179639a53e0cSJaegeuk Kim } 179739a53e0cSJaegeuk Kim 179845590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 179945590710SGu Zheng { 180045590710SGu Zheng return (struct f2fs_node *)page_address(page); 180145590710SGu Zheng } 180245590710SGu Zheng 180358bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 180458bfaf44SJaegeuk Kim { 180558bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 180658bfaf44SJaegeuk Kim } 180758bfaf44SJaegeuk Kim 180839a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 180939a53e0cSJaegeuk Kim { 181039a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 181139a53e0cSJaegeuk Kim } 181239a53e0cSJaegeuk Kim 181339a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 181439a53e0cSJaegeuk Kim { 181539a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 181639a53e0cSJaegeuk Kim } 181739a53e0cSJaegeuk Kim 181839a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 181939a53e0cSJaegeuk Kim { 182039a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 182139a53e0cSJaegeuk Kim } 182239a53e0cSJaegeuk Kim 182339a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 182439a53e0cSJaegeuk Kim { 182539a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 182639a53e0cSJaegeuk Kim } 182739a53e0cSJaegeuk Kim 182839a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 182939a53e0cSJaegeuk Kim { 183039a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 183139a53e0cSJaegeuk Kim } 183239a53e0cSJaegeuk Kim 18339df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 18349df27d98SGu Zheng { 18359df27d98SGu Zheng return sbi->meta_inode->i_mapping; 18369df27d98SGu Zheng } 18379df27d98SGu Zheng 18384ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 18394ef51a8fSJaegeuk Kim { 18404ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 18414ef51a8fSJaegeuk Kim } 18424ef51a8fSJaegeuk Kim 1843caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 184439a53e0cSJaegeuk Kim { 1845fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 184639a53e0cSJaegeuk Kim } 184739a53e0cSJaegeuk Kim 1848caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 184939a53e0cSJaegeuk Kim { 1850fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1851caf0047eSChao Yu } 1852caf0047eSChao Yu 1853caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1854caf0047eSChao Yu { 1855fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 185639a53e0cSJaegeuk Kim } 185739a53e0cSJaegeuk Kim 1858d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1859d71b5564SJaegeuk Kim { 1860d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1861d71b5564SJaegeuk Kim } 1862d71b5564SJaegeuk Kim 1863ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) 1864ea676733SJaegeuk Kim { 1865ea676733SJaegeuk Kim if (type < F2FS_MAX_QUOTAS) 1866ea676733SJaegeuk Kim return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); 1867ea676733SJaegeuk Kim return 0; 1868ea676733SJaegeuk Kim } 1869ea676733SJaegeuk Kim 1870ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1871ced2c7eaSKinglong Mee { 1872ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1873ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1874ced2c7eaSKinglong Mee } 1875ced2c7eaSKinglong Mee 1876aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 187725ca923bSJaegeuk Kim { 187825ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1879aaec2b1dSChao Yu 188025ca923bSJaegeuk Kim return ckpt_flags & f; 188125ca923bSJaegeuk Kim } 188225ca923bSJaegeuk Kim 1883aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 188425ca923bSJaegeuk Kim { 1885aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1886aaec2b1dSChao Yu } 1887aaec2b1dSChao Yu 1888aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1889aaec2b1dSChao Yu { 1890aaec2b1dSChao Yu unsigned int ckpt_flags; 1891aaec2b1dSChao Yu 1892aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 189325ca923bSJaegeuk Kim ckpt_flags |= f; 189425ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 189525ca923bSJaegeuk Kim } 189625ca923bSJaegeuk Kim 1897aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 189825ca923bSJaegeuk Kim { 1899d1aa2453SChao Yu unsigned long flags; 1900d1aa2453SChao Yu 1901d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1902aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1903d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1904aaec2b1dSChao Yu } 1905aaec2b1dSChao Yu 1906aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1907aaec2b1dSChao Yu { 1908aaec2b1dSChao Yu unsigned int ckpt_flags; 1909aaec2b1dSChao Yu 1910aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 191125ca923bSJaegeuk Kim ckpt_flags &= (~f); 191225ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 191325ca923bSJaegeuk Kim } 191425ca923bSJaegeuk Kim 1915aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1916aaec2b1dSChao Yu { 1917d1aa2453SChao Yu unsigned long flags; 1918d1aa2453SChao Yu 1919d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1920aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1921d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1922aaec2b1dSChao Yu } 1923aaec2b1dSChao Yu 192422ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 192522ad0b6aSJaegeuk Kim { 1926d1aa2453SChao Yu unsigned long flags; 19270921835cSChao Yu unsigned char *nat_bits; 1928d1aa2453SChao Yu 1929a742fd41SJaegeuk Kim /* 1930a742fd41SJaegeuk Kim * In order to re-enable nat_bits we need to call fsck.f2fs by 1931a742fd41SJaegeuk Kim * set_sbi_flag(sbi, SBI_NEED_FSCK). But it may give huge cost, 1932a742fd41SJaegeuk Kim * so let's rely on regular fsck or unclean shutdown. 1933a742fd41SJaegeuk Kim */ 193422ad0b6aSJaegeuk Kim 193522ad0b6aSJaegeuk Kim if (lock) 1936d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 193722ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 19380921835cSChao Yu nat_bits = NM_I(sbi)->nat_bits; 193922ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 194022ad0b6aSJaegeuk Kim if (lock) 1941d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 19420921835cSChao Yu 19430921835cSChao Yu kvfree(nat_bits); 194422ad0b6aSJaegeuk Kim } 194522ad0b6aSJaegeuk Kim 194622ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 194722ad0b6aSJaegeuk Kim struct cp_control *cpc) 194822ad0b6aSJaegeuk Kim { 194922ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 195022ad0b6aSJaegeuk Kim 1951c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 195222ad0b6aSJaegeuk Kim } 195322ad0b6aSJaegeuk Kim 1954e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 195539a53e0cSJaegeuk Kim { 1956b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 195739a53e0cSJaegeuk Kim } 195839a53e0cSJaegeuk Kim 1959cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1960cc15620bSJaegeuk Kim { 1961cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1962cc15620bSJaegeuk Kim } 1963cc15620bSJaegeuk Kim 1964e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 196539a53e0cSJaegeuk Kim { 1966b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 196739936837SJaegeuk Kim } 196839936837SJaegeuk Kim 1969e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 197039936837SJaegeuk Kim { 1971b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 197239936837SJaegeuk Kim } 197339936837SJaegeuk Kim 1974e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 197539936837SJaegeuk Kim { 1976b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 197739a53e0cSJaegeuk Kim } 197839a53e0cSJaegeuk Kim 1979119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1980119ee914SJaegeuk Kim { 1981119ee914SJaegeuk Kim int reason = CP_SYNC; 1982119ee914SJaegeuk Kim 1983119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1984119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1985119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1986119ee914SJaegeuk Kim reason = CP_UMOUNT; 1987119ee914SJaegeuk Kim return reason; 1988119ee914SJaegeuk Kim } 1989119ee914SJaegeuk Kim 1990119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1991119ee914SJaegeuk Kim { 1992c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1993119ee914SJaegeuk Kim } 1994119ee914SJaegeuk Kim 1995119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1996119ee914SJaegeuk Kim { 1997aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1998aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1999119ee914SJaegeuk Kim } 2000119ee914SJaegeuk Kim 200139a53e0cSJaegeuk Kim /* 200239a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 200339a53e0cSJaegeuk Kim */ 200439a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 200539a53e0cSJaegeuk Kim { 20060eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 20070eb0adadSChao Yu 2008000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 200939a53e0cSJaegeuk Kim } 201039a53e0cSJaegeuk Kim 20114bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 20124bc8e9bcSChao Yu { 20134bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 20144bc8e9bcSChao Yu } 20154bc8e9bcSChao Yu 2016d8a9a229SJaegeuk Kim static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, 2017a90a0884SJaegeuk Kim struct inode *inode, bool cap) 20187c2e5963SJaegeuk Kim { 2019d8a9a229SJaegeuk Kim if (!inode) 2020d8a9a229SJaegeuk Kim return true; 20217c2e5963SJaegeuk Kim if (!test_opt(sbi, RESERVE_ROOT)) 20227c2e5963SJaegeuk Kim return false; 2023d8a9a229SJaegeuk Kim if (IS_NOQUOTA(inode)) 2024d8a9a229SJaegeuk Kim return true; 202563189b78SChao Yu if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid())) 20267c2e5963SJaegeuk Kim return true; 202763189b78SChao Yu if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) && 202863189b78SChao Yu in_group_p(F2FS_OPTION(sbi).s_resgid)) 20297c2e5963SJaegeuk Kim return true; 2030a90a0884SJaegeuk Kim if (cap && capable(CAP_SYS_RESOURCE)) 2031162b27aeSJaegeuk Kim return true; 20327c2e5963SJaegeuk Kim return false; 20337c2e5963SJaegeuk Kim } 20347c2e5963SJaegeuk Kim 20350abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 20360abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 203746008c6dSChao Yu struct inode *inode, blkcnt_t *count) 203839a53e0cSJaegeuk Kim { 20390abd675eSChao Yu blkcnt_t diff = 0, release = 0; 2040daeb433eSChao Yu block_t avail_user_block_count; 20410abd675eSChao Yu int ret; 20420abd675eSChao Yu 20430abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 20440abd675eSChao Yu if (ret) 20450abd675eSChao Yu return ret; 2046dd11a5dfSJaegeuk Kim 204755523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 2048c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_BLOCK); 20490abd675eSChao Yu release = *count; 20509ea2f0beSChao Yu goto release_quota; 205155523519SChao Yu } 20527fa750a1SArnd Bergmann 2053dd11a5dfSJaegeuk Kim /* 2054dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 2055dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 2056dd11a5dfSJaegeuk Kim */ 2057dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 205839a53e0cSJaegeuk Kim 205939a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 20602555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 206180d42145SYunlong Song avail_user_block_count = sbi->user_block_count - 206280d42145SYunlong Song sbi->current_reserved_blocks; 20637e65be49SJaegeuk Kim 2064a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, true)) 206563189b78SChao Yu avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; 2066a4c3ecaaSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { 2067a4c3ecaaSDaniel Rosenberg if (avail_user_block_count > sbi->unusable_block_count) 20684354994fSDaniel Rosenberg avail_user_block_count -= sbi->unusable_block_count; 2069a4c3ecaaSDaniel Rosenberg else 2070a4c3ecaaSDaniel Rosenberg avail_user_block_count = 0; 2071a4c3ecaaSDaniel Rosenberg } 2072daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 2073daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 20747e65be49SJaegeuk Kim if (diff > *count) 20757e65be49SJaegeuk Kim diff = *count; 2076dd11a5dfSJaegeuk Kim *count -= diff; 20770abd675eSChao Yu release = diff; 20787e65be49SJaegeuk Kim sbi->total_valid_block_count -= diff; 207946008c6dSChao Yu if (!*count) { 208039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 20810abd675eSChao Yu goto enospc; 208239a53e0cSJaegeuk Kim } 208346008c6dSChao Yu } 208439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 208541382ec4SJaegeuk Kim 208636b877afSDaniel Rosenberg if (unlikely(release)) { 208736b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 20880abd675eSChao Yu dquot_release_reservation_block(inode, release); 208936b877afSDaniel Rosenberg } 20900abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 20910abd675eSChao Yu return 0; 20920abd675eSChao Yu 20930abd675eSChao Yu enospc: 209436b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 20959ea2f0beSChao Yu release_quota: 20960abd675eSChao Yu dquot_release_reservation_block(inode, release); 20970abd675eSChao Yu return -ENOSPC; 209839a53e0cSJaegeuk Kim } 209939a53e0cSJaegeuk Kim 2100dcbb4c10SJoe Perches __printf(2, 3) 2101dcbb4c10SJoe Perches void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...); 2102dcbb4c10SJoe Perches 2103dcbb4c10SJoe Perches #define f2fs_err(sbi, fmt, ...) \ 2104dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_ERR fmt, ##__VA_ARGS__) 2105dcbb4c10SJoe Perches #define f2fs_warn(sbi, fmt, ...) \ 2106dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_WARNING fmt, ##__VA_ARGS__) 2107dcbb4c10SJoe Perches #define f2fs_notice(sbi, fmt, ...) \ 2108dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_NOTICE fmt, ##__VA_ARGS__) 2109dcbb4c10SJoe Perches #define f2fs_info(sbi, fmt, ...) \ 2110dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_INFO fmt, ##__VA_ARGS__) 2111dcbb4c10SJoe Perches #define f2fs_debug(sbi, fmt, ...) \ 2112dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_DEBUG fmt, ##__VA_ARGS__) 2113dcbb4c10SJoe Perches 2114da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 211539a53e0cSJaegeuk Kim struct inode *inode, 21160eb0adadSChao Yu block_t count) 211739a53e0cSJaegeuk Kim { 21180eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 21190eb0adadSChao Yu 212039a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 21219850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 212239a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 212380d42145SYunlong Song if (sbi->reserved_blocks && 212480d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 212580d42145SYunlong Song sbi->current_reserved_blocks = min(sbi->reserved_blocks, 212680d42145SYunlong Song sbi->current_reserved_blocks + count); 212739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 21285e159cd3SChao Yu if (unlikely(inode->i_blocks < sectors)) { 2129dcbb4c10SJoe Perches f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu", 21305e159cd3SChao Yu inode->i_ino, 21315e159cd3SChao Yu (unsigned long long)inode->i_blocks, 21325e159cd3SChao Yu (unsigned long long)sectors); 21335e159cd3SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 21345e159cd3SChao Yu return; 21355e159cd3SChao Yu } 21360abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 213739a53e0cSJaegeuk Kim } 213839a53e0cSJaegeuk Kim 213939a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 214039a53e0cSJaegeuk Kim { 214135782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 21427c4abcbeSChao Yu 214320109873SChao Yu if (count_type == F2FS_DIRTY_DENTS || 214420109873SChao Yu count_type == F2FS_DIRTY_NODES || 214520109873SChao Yu count_type == F2FS_DIRTY_META || 214620109873SChao Yu count_type == F2FS_DIRTY_QDATA || 214720109873SChao Yu count_type == F2FS_DIRTY_IMETA) 2148caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 214939a53e0cSJaegeuk Kim } 215039a53e0cSJaegeuk Kim 2151a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 215239a53e0cSJaegeuk Kim { 2153204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 2154c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 2155c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 21562c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 21572c8a4a28SJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 215839a53e0cSJaegeuk Kim } 215939a53e0cSJaegeuk Kim 216039a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 216139a53e0cSJaegeuk Kim { 216235782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 216339a53e0cSJaegeuk Kim } 216439a53e0cSJaegeuk Kim 2165a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 216639a53e0cSJaegeuk Kim { 21675ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 21685ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 21691fe54f9dSJaegeuk Kim return; 21701fe54f9dSJaegeuk Kim 2171204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 2172c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 2173c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 21742c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 21752c8a4a28SJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 217639a53e0cSJaegeuk Kim } 217739a53e0cSJaegeuk Kim 2178523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 217939a53e0cSJaegeuk Kim { 218035782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 218139a53e0cSJaegeuk Kim } 218239a53e0cSJaegeuk Kim 2183204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 2184f8b2c1f9SJaegeuk Kim { 2185204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 2186f8b2c1f9SJaegeuk Kim } 2187f8b2c1f9SJaegeuk Kim 21885ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 21895ac206cfSNamjae Jeon { 21903519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 2191523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 2192523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 2193523be8a6SJaegeuk Kim 2194523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 21955ac206cfSNamjae Jeon } 21965ac206cfSNamjae Jeon 219739a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 219839a53e0cSJaegeuk Kim { 21998b8343faSJaegeuk Kim return sbi->total_valid_block_count; 220039a53e0cSJaegeuk Kim } 220139a53e0cSJaegeuk Kim 2202f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 2203f83a2584SYunlei He { 2204f83a2584SYunlei He return sbi->discard_blks; 2205f83a2584SYunlei He } 2206f83a2584SYunlei He 220739a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 220839a53e0cSJaegeuk Kim { 220939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 221039a53e0cSJaegeuk Kim 221139a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 221239a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 221339a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 221439a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 221539a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 221639a53e0cSJaegeuk Kim 221739a53e0cSJaegeuk Kim return 0; 221839a53e0cSJaegeuk Kim } 221939a53e0cSJaegeuk Kim 222055141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 222155141486SWanpeng Li { 222255141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 222355141486SWanpeng Li } 222455141486SWanpeng Li 222539a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 222639a53e0cSJaegeuk Kim { 222739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 22284260c406SGustavo A. R. Silva void *tmp_ptr = &ckpt->sit_nat_version_bitmap; 22291dbe4152SChangman Lee int offset; 22301dbe4152SChangman Lee 2231199bc3feSChao Yu if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { 2232199bc3feSChao Yu offset = (flag == SIT_BITMAP) ? 2233199bc3feSChao Yu le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; 2234b471eb99SChao Yu /* 2235b471eb99SChao Yu * if large_nat_bitmap feature is enabled, leave checksum 2236b471eb99SChao Yu * protection for all nat/sit bitmaps. 2237b471eb99SChao Yu */ 22384260c406SGustavo A. R. Silva return tmp_ptr + offset + sizeof(__le32); 2239199bc3feSChao Yu } 2240199bc3feSChao Yu 224155141486SWanpeng Li if (__cp_payload(sbi) > 0) { 22421dbe4152SChangman Lee if (flag == NAT_BITMAP) 22431dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 22441dbe4152SChangman Lee else 224565b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 22461dbe4152SChangman Lee } else { 22471dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 224825ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 22494260c406SGustavo A. R. Silva return tmp_ptr + offset; 225039a53e0cSJaegeuk Kim } 22511dbe4152SChangman Lee } 225239a53e0cSJaegeuk Kim 225339a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 225439a53e0cSJaegeuk Kim { 22558508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 225639a53e0cSJaegeuk Kim 22578508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 225839a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 225939a53e0cSJaegeuk Kim return start_addr; 226039a53e0cSJaegeuk Kim } 226139a53e0cSJaegeuk Kim 22628508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 22638508e44aSJaegeuk Kim { 22648508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 22658508e44aSJaegeuk Kim 22668508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 22678508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 22688508e44aSJaegeuk Kim return start_addr; 22698508e44aSJaegeuk Kim } 22708508e44aSJaegeuk Kim 22718508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 22728508e44aSJaegeuk Kim { 22738508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 22748508e44aSJaegeuk Kim } 22758508e44aSJaegeuk Kim 227639a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 227739a53e0cSJaegeuk Kim { 227839a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 227939a53e0cSJaegeuk Kim } 228039a53e0cSJaegeuk Kim 22810abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 2282000519f2SChao Yu struct inode *inode, bool is_inode) 228339a53e0cSJaegeuk Kim { 228439a53e0cSJaegeuk Kim block_t valid_block_count; 2285a4c3ecaaSDaniel Rosenberg unsigned int valid_node_count, user_block_count; 2286af033b2aSChao Yu int err; 22870abd675eSChao Yu 2288af033b2aSChao Yu if (is_inode) { 2289af033b2aSChao Yu if (inode) { 2290af033b2aSChao Yu err = dquot_alloc_inode(inode); 2291af033b2aSChao Yu if (err) 2292af033b2aSChao Yu return err; 2293af033b2aSChao Yu } 2294af033b2aSChao Yu } else { 2295af033b2aSChao Yu err = dquot_reserve_block(inode, 1); 2296af033b2aSChao Yu if (err) 2297af033b2aSChao Yu return err; 22980abd675eSChao Yu } 229939a53e0cSJaegeuk Kim 2300812c6056SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 2301c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_BLOCK); 2302812c6056SChao Yu goto enospc; 2303812c6056SChao Yu } 2304812c6056SChao Yu 230539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 230639a53e0cSJaegeuk Kim 23077e65be49SJaegeuk Kim valid_block_count = sbi->total_valid_block_count + 23087e65be49SJaegeuk Kim sbi->current_reserved_blocks + 1; 23097e65be49SJaegeuk Kim 2310a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, false)) 231163189b78SChao Yu valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; 2312a4c3ecaaSDaniel Rosenberg user_block_count = sbi->user_block_count; 23134354994fSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) 2314a4c3ecaaSDaniel Rosenberg user_block_count -= sbi->unusable_block_count; 23157e65be49SJaegeuk Kim 2316a4c3ecaaSDaniel Rosenberg if (unlikely(valid_block_count > user_block_count)) { 231739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 23180abd675eSChao Yu goto enospc; 231939a53e0cSJaegeuk Kim } 232039a53e0cSJaegeuk Kim 2321ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 2322cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 232339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 23240abd675eSChao Yu goto enospc; 232539a53e0cSJaegeuk Kim } 232639a53e0cSJaegeuk Kim 2327ef86d709SGu Zheng sbi->total_valid_node_count++; 2328ef86d709SGu Zheng sbi->total_valid_block_count++; 232939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 233039a53e0cSJaegeuk Kim 23310abd675eSChao Yu if (inode) { 23320abd675eSChao Yu if (is_inode) 23330abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 23340abd675eSChao Yu else 23350abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 23360abd675eSChao Yu } 23370abd675eSChao Yu 233841382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 23390abd675eSChao Yu return 0; 23400abd675eSChao Yu 23410abd675eSChao Yu enospc: 2342af033b2aSChao Yu if (is_inode) { 2343af033b2aSChao Yu if (inode) 2344af033b2aSChao Yu dquot_free_inode(inode); 2345af033b2aSChao Yu } else { 23460abd675eSChao Yu dquot_release_reservation_block(inode, 1); 2347af033b2aSChao Yu } 23480abd675eSChao Yu return -ENOSPC; 234939a53e0cSJaegeuk Kim } 235039a53e0cSJaegeuk Kim 235139a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 2352000519f2SChao Yu struct inode *inode, bool is_inode) 235339a53e0cSJaegeuk Kim { 235439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 235539a53e0cSJaegeuk Kim 23569850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 23579850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 235839a53e0cSJaegeuk Kim 2359ef86d709SGu Zheng sbi->total_valid_node_count--; 2360ef86d709SGu Zheng sbi->total_valid_block_count--; 236180d42145SYunlong Song if (sbi->reserved_blocks && 236280d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 236380d42145SYunlong Song sbi->current_reserved_blocks++; 236439a53e0cSJaegeuk Kim 236539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 23660abd675eSChao Yu 2367ea6d7e72SChao Yu if (is_inode) { 2368af033b2aSChao Yu dquot_free_inode(inode); 2369ea6d7e72SChao Yu } else { 2370ea6d7e72SChao Yu if (unlikely(inode->i_blocks == 0)) { 2371097a7686SChao Yu f2fs_warn(sbi, "dec_valid_node_count: inconsistent i_blocks, ino:%lu, iblocks:%llu", 2372ea6d7e72SChao Yu inode->i_ino, 2373ea6d7e72SChao Yu (unsigned long long)inode->i_blocks); 2374ea6d7e72SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 2375ea6d7e72SChao Yu return; 2376ea6d7e72SChao Yu } 23770abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 237839a53e0cSJaegeuk Kim } 2379ea6d7e72SChao Yu } 238039a53e0cSJaegeuk Kim 238139a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 238239a53e0cSJaegeuk Kim { 23838b8343faSJaegeuk Kim return sbi->total_valid_node_count; 238439a53e0cSJaegeuk Kim } 238539a53e0cSJaegeuk Kim 238639a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 238739a53e0cSJaegeuk Kim { 2388513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 238939a53e0cSJaegeuk Kim } 239039a53e0cSJaegeuk Kim 23910e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 239239a53e0cSJaegeuk Kim { 2393513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 239439a53e0cSJaegeuk Kim } 239539a53e0cSJaegeuk Kim 2396513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 239739a53e0cSJaegeuk Kim { 2398513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 239939a53e0cSJaegeuk Kim } 240039a53e0cSJaegeuk Kim 2401a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 2402a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 2403a56c7c6fSJaegeuk Kim { 240482cf4f13SChao Yu struct page *page; 2405cac5a3d8SDongOh Shin 24067fa750a1SArnd Bergmann if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) { 240782cf4f13SChao Yu if (!for_write) 240882cf4f13SChao Yu page = find_get_page_flags(mapping, index, 240982cf4f13SChao Yu FGP_LOCK | FGP_ACCESSED); 241082cf4f13SChao Yu else 241182cf4f13SChao Yu page = find_lock_page(mapping, index); 2412c41f3cc3SJaegeuk Kim if (page) 2413c41f3cc3SJaegeuk Kim return page; 2414c41f3cc3SJaegeuk Kim 241555523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 2416c45d6002SChao Yu f2fs_show_injection_info(F2FS_M_SB(mapping), 2417c45d6002SChao Yu FAULT_PAGE_ALLOC); 2418c41f3cc3SJaegeuk Kim return NULL; 241955523519SChao Yu } 24207fa750a1SArnd Bergmann } 24217fa750a1SArnd Bergmann 2422a56c7c6fSJaegeuk Kim if (!for_write) 2423a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 2424a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 2425a56c7c6fSJaegeuk Kim } 2426a56c7c6fSJaegeuk Kim 242701eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page( 242801eccef7SChao Yu struct address_space *mapping, pgoff_t index, 242901eccef7SChao Yu int fgp_flags, gfp_t gfp_mask) 243001eccef7SChao Yu { 243101eccef7SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { 2432c45d6002SChao Yu f2fs_show_injection_info(F2FS_M_SB(mapping), FAULT_PAGE_GET); 243301eccef7SChao Yu return NULL; 243401eccef7SChao Yu } 24357fa750a1SArnd Bergmann 243601eccef7SChao Yu return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); 243701eccef7SChao Yu } 243801eccef7SChao Yu 24396e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 24406e2c64adSJaegeuk Kim { 24416e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 24426e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 24436e2c64adSJaegeuk Kim 24446e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 24456e2c64adSJaegeuk Kim kunmap(dst); 24466e2c64adSJaegeuk Kim kunmap(src); 24476e2c64adSJaegeuk Kim } 24486e2c64adSJaegeuk Kim 244939a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 245039a53e0cSJaegeuk Kim { 2451031fa8ccSJaegeuk Kim if (!page) 245239a53e0cSJaegeuk Kim return; 245339a53e0cSJaegeuk Kim 245439a53e0cSJaegeuk Kim if (unlock) { 24559850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 245639a53e0cSJaegeuk Kim unlock_page(page); 245739a53e0cSJaegeuk Kim } 245809cbfeafSKirill A. Shutemov put_page(page); 245939a53e0cSJaegeuk Kim } 246039a53e0cSJaegeuk Kim 246139a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 246239a53e0cSJaegeuk Kim { 246339a53e0cSJaegeuk Kim if (dn->node_page) 246439a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 246539a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 246639a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 246739a53e0cSJaegeuk Kim dn->node_page = NULL; 246839a53e0cSJaegeuk Kim dn->inode_page = NULL; 246939a53e0cSJaegeuk Kim } 247039a53e0cSJaegeuk Kim 247139a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 2472e8512d2eSGu Zheng size_t size) 247339a53e0cSJaegeuk Kim { 2474e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 247539a53e0cSJaegeuk Kim } 247639a53e0cSJaegeuk Kim 24777bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 24787bd59381SGu Zheng gfp_t flags) 24797bd59381SGu Zheng { 24807bd59381SGu Zheng void *entry; 24817bd59381SGu Zheng 248280c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 248380c54505SJaegeuk Kim if (!entry) 248480c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 24857bd59381SGu Zheng return entry; 24867bd59381SGu Zheng } 24877bd59381SGu Zheng 2488493720a4SChao Yu static inline bool is_inflight_io(struct f2fs_sb_info *sbi, int type) 24895f9abab4SJaegeuk Kim { 24905f9abab4SJaegeuk Kim if (get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_RD_NODE) || 24915f9abab4SJaegeuk Kim get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) || 2492fef4129eSChao Yu get_pages(sbi, F2FS_WB_CP_DATA) || 2493fef4129eSChao Yu get_pages(sbi, F2FS_DIO_READ) || 249411ac8ef8SJaegeuk Kim get_pages(sbi, F2FS_DIO_WRITE)) 2495493720a4SChao Yu return true; 249611ac8ef8SJaegeuk Kim 249756659ce8SSahitya Tummala if (type != DISCARD_TIME && SM_I(sbi) && SM_I(sbi)->dcc_info && 249811ac8ef8SJaegeuk Kim atomic_read(&SM_I(sbi)->dcc_info->queued_discard)) 2499493720a4SChao Yu return true; 250011ac8ef8SJaegeuk Kim 250111ac8ef8SJaegeuk Kim if (SM_I(sbi) && SM_I(sbi)->fcc_info && 250272691af6SJaegeuk Kim atomic_read(&SM_I(sbi)->fcc_info->queued_flush)) 2503493720a4SChao Yu return true; 2504493720a4SChao Yu return false; 2505493720a4SChao Yu } 2506493720a4SChao Yu 2507493720a4SChao Yu static inline bool is_idle(struct f2fs_sb_info *sbi, int type) 2508493720a4SChao Yu { 2509493720a4SChao Yu if (sbi->gc_mode == GC_URGENT_HIGH) 2510493720a4SChao Yu return true; 2511493720a4SChao Yu 2512493720a4SChao Yu if (is_inflight_io(sbi, type)) 25135f9abab4SJaegeuk Kim return false; 251411ac8ef8SJaegeuk Kim 25150e5e8111SDaeho Jeong if (sbi->gc_mode == GC_URGENT_LOW && 25160e5e8111SDaeho Jeong (type == DISCARD_TIME || type == GC_TIME)) 25170e5e8111SDaeho Jeong return true; 25180e5e8111SDaeho Jeong 25195f9abab4SJaegeuk Kim return f2fs_time_over(sbi, type); 25205f9abab4SJaegeuk Kim } 25215f9abab4SJaegeuk Kim 25229be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 25239be32d72SJaegeuk Kim unsigned long index, void *item) 25249be32d72SJaegeuk Kim { 25259be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 25269be32d72SJaegeuk Kim cond_resched(); 25279be32d72SJaegeuk Kim } 25289be32d72SJaegeuk Kim 252939a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 253039a53e0cSJaegeuk Kim 253139a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 253239a53e0cSJaegeuk Kim { 253345590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 2534cac5a3d8SDongOh Shin 253539a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 253639a53e0cSJaegeuk Kim } 253739a53e0cSJaegeuk Kim 25387a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 25397a2af766SChao Yu { 25407a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 25417a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 25427a2af766SChao Yu } 25437a2af766SChao Yu 254439a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 254539a53e0cSJaegeuk Kim { 254639a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 254739a53e0cSJaegeuk Kim } 254839a53e0cSJaegeuk Kim 25497a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 2550a2ced1ceSChao Yu static inline block_t data_blkaddr(struct inode *inode, 25517a2af766SChao Yu struct page *node_page, unsigned int offset) 255239a53e0cSJaegeuk Kim { 255339a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 255439a53e0cSJaegeuk Kim __le32 *addr_array; 25557a2af766SChao Yu int base = 0; 25567a2af766SChao Yu bool is_inode = IS_INODE(node_page); 2557cac5a3d8SDongOh Shin 255845590710SGu Zheng raw_node = F2FS_NODE(node_page); 25597a2af766SChao Yu 2560979f492fSLiFan if (is_inode) { 2561979f492fSLiFan if (!inode) 25627a88ddb5SChao Yu /* from GC path only */ 25637a2af766SChao Yu base = offset_in_addr(&raw_node->i); 2564979f492fSLiFan else if (f2fs_has_extra_attr(inode)) 25657a2af766SChao Yu base = get_extra_isize(inode); 25667a2af766SChao Yu } 25677a2af766SChao Yu 256839a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 25697a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 257039a53e0cSJaegeuk Kim } 257139a53e0cSJaegeuk Kim 2572a2ced1ceSChao Yu static inline block_t f2fs_data_blkaddr(struct dnode_of_data *dn) 2573a2ced1ceSChao Yu { 2574a2ced1ceSChao Yu return data_blkaddr(dn->inode, dn->node_page, dn->ofs_in_node); 2575a2ced1ceSChao Yu } 2576a2ced1ceSChao Yu 257739a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 257839a53e0cSJaegeuk Kim { 257939a53e0cSJaegeuk Kim int mask; 258039a53e0cSJaegeuk Kim 258139a53e0cSJaegeuk Kim addr += (nr >> 3); 258239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 258339a53e0cSJaegeuk Kim return mask & *addr; 258439a53e0cSJaegeuk Kim } 258539a53e0cSJaegeuk Kim 2586a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 2587a66cdd98SJaegeuk Kim { 2588a66cdd98SJaegeuk Kim int mask; 2589a66cdd98SJaegeuk Kim 2590a66cdd98SJaegeuk Kim addr += (nr >> 3); 2591a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2592a66cdd98SJaegeuk Kim *addr |= mask; 2593a66cdd98SJaegeuk Kim } 2594a66cdd98SJaegeuk Kim 2595a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 2596a66cdd98SJaegeuk Kim { 2597a66cdd98SJaegeuk Kim int mask; 2598a66cdd98SJaegeuk Kim 2599a66cdd98SJaegeuk Kim addr += (nr >> 3); 2600a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2601a66cdd98SJaegeuk Kim *addr &= ~mask; 2602a66cdd98SJaegeuk Kim } 2603a66cdd98SJaegeuk Kim 260452aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 260539a53e0cSJaegeuk Kim { 260639a53e0cSJaegeuk Kim int mask; 260739a53e0cSJaegeuk Kim int ret; 260839a53e0cSJaegeuk Kim 260939a53e0cSJaegeuk Kim addr += (nr >> 3); 261039a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 261139a53e0cSJaegeuk Kim ret = mask & *addr; 261239a53e0cSJaegeuk Kim *addr |= mask; 261339a53e0cSJaegeuk Kim return ret; 261439a53e0cSJaegeuk Kim } 261539a53e0cSJaegeuk Kim 261652aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 261739a53e0cSJaegeuk Kim { 261839a53e0cSJaegeuk Kim int mask; 261939a53e0cSJaegeuk Kim int ret; 262039a53e0cSJaegeuk Kim 262139a53e0cSJaegeuk Kim addr += (nr >> 3); 262239a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 262339a53e0cSJaegeuk Kim ret = mask & *addr; 262439a53e0cSJaegeuk Kim *addr &= ~mask; 262539a53e0cSJaegeuk Kim return ret; 262639a53e0cSJaegeuk Kim } 262739a53e0cSJaegeuk Kim 2628c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 2629c6ac4c0eSGu Zheng { 2630c6ac4c0eSGu Zheng int mask; 2631c6ac4c0eSGu Zheng 2632c6ac4c0eSGu Zheng addr += (nr >> 3); 2633c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 2634c6ac4c0eSGu Zheng *addr ^= mask; 2635c6ac4c0eSGu Zheng } 2636c6ac4c0eSGu Zheng 263759c84408SChao Yu /* 263836098557SEric Biggers * On-disk inode flags (f2fs_inode::i_flags) 263959c84408SChao Yu */ 26404c8ff709SChao Yu #define F2FS_COMPR_FL 0x00000004 /* Compress file */ 264159c84408SChao Yu #define F2FS_SYNC_FL 0x00000008 /* Synchronous updates */ 264259c84408SChao Yu #define F2FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ 264359c84408SChao Yu #define F2FS_APPEND_FL 0x00000020 /* writes to file may only append */ 264459c84408SChao Yu #define F2FS_NODUMP_FL 0x00000040 /* do not dump file */ 264559c84408SChao Yu #define F2FS_NOATIME_FL 0x00000080 /* do not update atime */ 26464c8ff709SChao Yu #define F2FS_NOCOMP_FL 0x00000400 /* Don't compress */ 264759c84408SChao Yu #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ 264859c84408SChao Yu #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 264959c84408SChao Yu #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 26502c2eb7a3SDaniel Rosenberg #define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */ 265159c84408SChao Yu 265259c84408SChao Yu /* Flags that should be inherited by new inodes from their parent. */ 265336098557SEric Biggers #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \ 26542c2eb7a3SDaniel Rosenberg F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 26554c8ff709SChao Yu F2FS_CASEFOLD_FL | F2FS_COMPR_FL | F2FS_NOCOMP_FL) 265659c84408SChao Yu 265759c84408SChao Yu /* Flags that are appropriate for regular files (all but dir-specific ones). */ 26582c2eb7a3SDaniel Rosenberg #define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 26592c2eb7a3SDaniel Rosenberg F2FS_CASEFOLD_FL)) 266059c84408SChao Yu 266159c84408SChao Yu /* Flags that are appropriate for non-directories/regular files. */ 266259c84408SChao Yu #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL) 26635c57132eSChao Yu 26645c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 26655c57132eSChao Yu { 26665c57132eSChao Yu if (S_ISDIR(mode)) 26675c57132eSChao Yu return flags; 26685c57132eSChao Yu else if (S_ISREG(mode)) 26695c57132eSChao Yu return flags & F2FS_REG_FLMASK; 26705c57132eSChao Yu else 26715c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 26725c57132eSChao Yu } 26735c57132eSChao Yu 2674205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2675205b9822SJaegeuk Kim int flag, bool set) 267639a53e0cSJaegeuk Kim { 2677205b9822SJaegeuk Kim switch (flag) { 2678205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2679205b9822SJaegeuk Kim case FI_INLINE_DATA: 2680205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 26819ac1e2d8SDaeho Jeong case FI_NEW_INODE: 2682205b9822SJaegeuk Kim if (set) 2683205b9822SJaegeuk Kim return; 2684df561f66SGustavo A. R. Silva fallthrough; 2685205b9822SJaegeuk Kim case FI_DATA_EXIST: 2686205b9822SJaegeuk Kim case FI_INLINE_DOTS: 26871ad71a27SJaegeuk Kim case FI_PIN_FILE: 26887c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2689205b9822SJaegeuk Kim } 269039a53e0cSJaegeuk Kim } 269139a53e0cSJaegeuk Kim 269291942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 269339a53e0cSJaegeuk Kim { 269458f7e00fSYufen Yu set_bit(flag, F2FS_I(inode)->flags); 2695205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 269639a53e0cSJaegeuk Kim } 269739a53e0cSJaegeuk Kim 269891942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 269939a53e0cSJaegeuk Kim { 27007653b9d8SChao Yu return test_bit(flag, F2FS_I(inode)->flags); 270139a53e0cSJaegeuk Kim } 270239a53e0cSJaegeuk Kim 270391942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 270439a53e0cSJaegeuk Kim { 270558f7e00fSYufen Yu clear_bit(flag, F2FS_I(inode)->flags); 2706205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 270739a53e0cSJaegeuk Kim } 270839a53e0cSJaegeuk Kim 270995ae251fSEric Biggers static inline bool f2fs_verity_in_progress(struct inode *inode) 271095ae251fSEric Biggers { 271195ae251fSEric Biggers return IS_ENABLED(CONFIG_FS_VERITY) && 271295ae251fSEric Biggers is_inode_flag_set(inode, FI_VERITY_IN_PROGRESS); 271395ae251fSEric Biggers } 271495ae251fSEric Biggers 271591942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2716444c580fSJaegeuk Kim { 271791942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 271891942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 27197c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 272039a53e0cSJaegeuk Kim } 272139a53e0cSJaegeuk Kim 2722a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2723a1961246SJaegeuk Kim { 2724a1961246SJaegeuk Kim if (inc) 2725a1961246SJaegeuk Kim inc_nlink(inode); 2726a1961246SJaegeuk Kim else 2727a1961246SJaegeuk Kim drop_nlink(inode); 27287c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2729a1961246SJaegeuk Kim } 2730a1961246SJaegeuk Kim 27318edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 27320abd675eSChao Yu block_t diff, bool add, bool claim) 27338edd03c8SJaegeuk Kim { 273426de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 273526de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 273626de9b11SJaegeuk Kim 27370abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 27380abd675eSChao Yu if (add) { 27390abd675eSChao Yu if (claim) 27400abd675eSChao Yu dquot_claim_block(inode, diff); 27410abd675eSChao Yu else 27420abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 27430abd675eSChao Yu } else { 27440abd675eSChao Yu dquot_free_block(inode, diff); 27450abd675eSChao Yu } 27460abd675eSChao Yu 27477c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 274826de9b11SJaegeuk Kim if (clean || recover) 274926de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 27508edd03c8SJaegeuk Kim } 27518edd03c8SJaegeuk Kim 2752fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2753fc9581c8SJaegeuk Kim { 275426de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 275526de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 275626de9b11SJaegeuk Kim 2757fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2758fc9581c8SJaegeuk Kim return; 2759fc9581c8SJaegeuk Kim 2760fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 27617c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 276226de9b11SJaegeuk Kim if (clean || recover) 276326de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 276426de9b11SJaegeuk Kim } 276526de9b11SJaegeuk Kim 2766205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2767205b9822SJaegeuk Kim { 2768205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 27697c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2770205b9822SJaegeuk Kim } 2771205b9822SJaegeuk Kim 27721ad71a27SJaegeuk Kim static inline void f2fs_i_gc_failures_write(struct inode *inode, 27731ad71a27SJaegeuk Kim unsigned int count) 27741ad71a27SJaegeuk Kim { 27752ef79ecbSChao Yu F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count; 27761ad71a27SJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 27771ad71a27SJaegeuk Kim } 27781ad71a27SJaegeuk Kim 2779205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2780205b9822SJaegeuk Kim { 2781205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 27827c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2783205b9822SJaegeuk Kim } 2784205b9822SJaegeuk Kim 2785205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2786205b9822SJaegeuk Kim { 2787205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 27887c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2789205b9822SJaegeuk Kim } 2790205b9822SJaegeuk Kim 279191942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2792444c580fSJaegeuk Kim { 2793205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2794205b9822SJaegeuk Kim 2795444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 27967653b9d8SChao Yu set_bit(FI_INLINE_XATTR, fi->flags); 27971001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 27987653b9d8SChao Yu set_bit(FI_INLINE_DATA, fi->flags); 279934d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 28007653b9d8SChao Yu set_bit(FI_INLINE_DENTRY, fi->flags); 2801b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 28027653b9d8SChao Yu set_bit(FI_DATA_EXIST, fi->flags); 2803510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 28047653b9d8SChao Yu set_bit(FI_INLINE_DOTS, fi->flags); 28057a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 28067653b9d8SChao Yu set_bit(FI_EXTRA_ATTR, fi->flags); 28071ad71a27SJaegeuk Kim if (ri->i_inline & F2FS_PIN_FILE) 28087653b9d8SChao Yu set_bit(FI_PIN_FILE, fi->flags); 2809444c580fSJaegeuk Kim } 2810444c580fSJaegeuk Kim 281191942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2812444c580fSJaegeuk Kim { 2813444c580fSJaegeuk Kim ri->i_inline = 0; 2814444c580fSJaegeuk Kim 281591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2816444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 281791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 28181001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 281991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 282034d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 282191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2822b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 282391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2824510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 28257a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 28267a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 28271ad71a27SJaegeuk Kim if (is_inode_flag_set(inode, FI_PIN_FILE)) 28281ad71a27SJaegeuk Kim ri->i_inline |= F2FS_PIN_FILE; 28297a2af766SChao Yu } 28307a2af766SChao Yu 28317a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 28327a2af766SChao Yu { 28337a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2834444c580fSJaegeuk Kim } 2835444c580fSJaegeuk Kim 2836987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2837987c7c31SChao Yu { 283891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2839987c7c31SChao Yu } 2840987c7c31SChao Yu 28414c8ff709SChao Yu static inline int f2fs_compressed_file(struct inode *inode) 28424c8ff709SChao Yu { 28434c8ff709SChao Yu return S_ISREG(inode->i_mode) && 28444c8ff709SChao Yu is_inode_flag_set(inode, FI_COMPRESSED_FILE); 28454c8ff709SChao Yu } 28464c8ff709SChao Yu 2847602a16d5SDaeho Jeong static inline bool f2fs_need_compress_data(struct inode *inode) 2848602a16d5SDaeho Jeong { 2849602a16d5SDaeho Jeong int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; 2850602a16d5SDaeho Jeong 2851602a16d5SDaeho Jeong if (!f2fs_compressed_file(inode)) 2852602a16d5SDaeho Jeong return false; 2853602a16d5SDaeho Jeong 2854602a16d5SDaeho Jeong if (compress_mode == COMPR_MODE_FS) 2855602a16d5SDaeho Jeong return true; 2856602a16d5SDaeho Jeong else if (compress_mode == COMPR_MODE_USER && 2857602a16d5SDaeho Jeong is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) 2858602a16d5SDaeho Jeong return true; 2859602a16d5SDaeho Jeong 2860602a16d5SDaeho Jeong return false; 2861602a16d5SDaeho Jeong } 2862602a16d5SDaeho Jeong 286381ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2864de93653fSJaegeuk Kim { 2865d02a6e61SChao Yu unsigned int addrs = CUR_ADDRS_PER_INODE(inode) - 2866d02a6e61SChao Yu get_inline_xattr_addrs(inode); 28674c8ff709SChao Yu 28684c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 28694c8ff709SChao Yu return addrs; 28704c8ff709SChao Yu return ALIGN_DOWN(addrs, F2FS_I(inode)->i_cluster_size); 2871d02a6e61SChao Yu } 2872d02a6e61SChao Yu 2873d02a6e61SChao Yu static inline unsigned int addrs_per_block(struct inode *inode) 2874d02a6e61SChao Yu { 28754c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 28764c8ff709SChao Yu return DEF_ADDRS_PER_BLOCK; 28774c8ff709SChao Yu return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, F2FS_I(inode)->i_cluster_size); 2878de93653fSJaegeuk Kim } 2879de93653fSJaegeuk Kim 28806afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page) 288165985d93SJaegeuk Kim { 2882695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2883cac5a3d8SDongOh Shin 288465985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 2885b323fd28SChao Yu get_inline_xattr_addrs(inode)]); 288665985d93SJaegeuk Kim } 288765985d93SJaegeuk Kim 288865985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 288965985d93SJaegeuk Kim { 2890622927f3SChao Yu if (f2fs_has_inline_xattr(inode)) 28916afc662eSChao Yu return get_inline_xattr_addrs(inode) * sizeof(__le32); 2892622927f3SChao Yu return 0; 289365985d93SJaegeuk Kim } 289465985d93SJaegeuk Kim 28950dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 28960dbdc2aeSJaegeuk Kim { 289791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 28980dbdc2aeSJaegeuk Kim } 28990dbdc2aeSJaegeuk Kim 2900b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2901b3d208f9SJaegeuk Kim { 290291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2903b3d208f9SJaegeuk Kim } 2904b3d208f9SJaegeuk Kim 2905510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2906510022a8SJaegeuk Kim { 290791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2908510022a8SJaegeuk Kim } 2909510022a8SJaegeuk Kim 29104c8ff709SChao Yu static inline int f2fs_is_mmap_file(struct inode *inode) 29114c8ff709SChao Yu { 29124c8ff709SChao Yu return is_inode_flag_set(inode, FI_MMAP_FILE); 29134c8ff709SChao Yu } 29144c8ff709SChao Yu 29151ad71a27SJaegeuk Kim static inline bool f2fs_is_pinned_file(struct inode *inode) 29161ad71a27SJaegeuk Kim { 29171ad71a27SJaegeuk Kim return is_inode_flag_set(inode, FI_PIN_FILE); 29181ad71a27SJaegeuk Kim } 29191ad71a27SJaegeuk Kim 292088b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 292188b88a66SJaegeuk Kim { 292291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 292388b88a66SJaegeuk Kim } 292488b88a66SJaegeuk Kim 29255fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 29265fe45743SChao Yu { 29275fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 29285fe45743SChao Yu } 29295fe45743SChao Yu 293002a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 293102a1335fSJaegeuk Kim { 293291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 293302a1335fSJaegeuk Kim } 293402a1335fSJaegeuk Kim 29353c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 29363c6c2bebSJaegeuk Kim { 293791942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 29383c6c2bebSJaegeuk Kim } 29393c6c2bebSJaegeuk Kim 29401e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 29411e84371fSJaegeuk Kim { 294291942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 29431e84371fSJaegeuk Kim } 29441e84371fSJaegeuk Kim 2945f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 29461001b347SHuajun Li { 2947695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 29487a2af766SChao Yu int extra_size = get_extra_isize(inode); 2949cac5a3d8SDongOh Shin 29507a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 29511001b347SHuajun Li } 29521001b347SHuajun Li 295334d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 295434d67debSChao Yu { 295591942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 295634d67debSChao Yu } 295734d67debSChao Yu 2958b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2959b5492af7SJaegeuk Kim { 2960b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2961b5492af7SJaegeuk Kim } 2962b5492af7SJaegeuk Kim 2963b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2964b5492af7SJaegeuk Kim { 2965b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 29667c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2967b5492af7SJaegeuk Kim } 2968b5492af7SJaegeuk Kim 2969b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2970b5492af7SJaegeuk Kim { 2971b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 29727c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2973b5492af7SJaegeuk Kim } 2974b5492af7SJaegeuk Kim 2975fe1897eaSChao Yu static inline bool f2fs_is_time_consistent(struct inode *inode) 2976fe1897eaSChao Yu { 2977fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime)) 2978fe1897eaSChao Yu return false; 2979fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime)) 2980fe1897eaSChao Yu return false; 2981fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime)) 2982fe1897eaSChao Yu return false; 2983fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3, 2984fe1897eaSChao Yu &F2FS_I(inode)->i_crtime)) 2985fe1897eaSChao Yu return false; 2986fe1897eaSChao Yu return true; 2987fe1897eaSChao Yu } 2988fe1897eaSChao Yu 298926787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 299026787236SJaegeuk Kim { 2991a0d00fadSChao Yu bool ret; 2992a0d00fadSChao Yu 299326787236SJaegeuk Kim if (dsync) { 299426787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 299526787236SJaegeuk Kim 299626787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 299726787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 299826787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 299926787236SJaegeuk Kim return ret; 300026787236SJaegeuk Kim } 300126787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 300226787236SJaegeuk Kim file_keep_isize(inode) || 3003235831d7SJunling Zheng i_size_read(inode) & ~PAGE_MASK) 300426787236SJaegeuk Kim return false; 3005a0d00fadSChao Yu 3006fe1897eaSChao Yu if (!f2fs_is_time_consistent(inode)) 3007214c2461SJaegeuk Kim return false; 3008214c2461SJaegeuk Kim 3009c10c9820SChao Yu spin_lock(&F2FS_I(inode)->i_size_lock); 3010a0d00fadSChao Yu ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 3011c10c9820SChao Yu spin_unlock(&F2FS_I(inode)->i_size_lock); 3012a0d00fadSChao Yu 3013a0d00fadSChao Yu return ret; 3014267378d4SChao Yu } 3015267378d4SChao Yu 3016deeedd71SChao Yu static inline bool f2fs_readonly(struct super_block *sb) 301777888c1eSJaegeuk Kim { 3018deeedd71SChao Yu return sb_rdonly(sb); 301977888c1eSJaegeuk Kim } 302077888c1eSJaegeuk Kim 3021744602cfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 3022744602cfSJaegeuk Kim { 3023aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 3024744602cfSJaegeuk Kim } 3025744602cfSJaegeuk Kim 302643c780baSEric Biggers static inline bool is_dot_dotdot(const u8 *name, size_t len) 3027eaa693f4SJaegeuk Kim { 302843c780baSEric Biggers if (len == 1 && name[0] == '.') 3029eaa693f4SJaegeuk Kim return true; 3030eaa693f4SJaegeuk Kim 303143c780baSEric Biggers if (len == 2 && name[0] == '.' && name[1] == '.') 3032eaa693f4SJaegeuk Kim return true; 3033eaa693f4SJaegeuk Kim 3034eaa693f4SJaegeuk Kim return false; 3035eaa693f4SJaegeuk Kim } 3036eaa693f4SJaegeuk Kim 30373e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 30383e72f721SJaegeuk Kim { 3039e4589fa5SSahitya Tummala struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 3040e4589fa5SSahitya Tummala 3041e4589fa5SSahitya Tummala if (!test_opt(sbi, EXTENT_CACHE) || 30424c8ff709SChao Yu is_inode_flag_set(inode, FI_NO_EXTENT) || 30434c8ff709SChao Yu is_inode_flag_set(inode, FI_COMPRESSED_FILE)) 30443e72f721SJaegeuk Kim return false; 30453e72f721SJaegeuk Kim 3046e4589fa5SSahitya Tummala /* 3047e4589fa5SSahitya Tummala * for recovered files during mount do not create extents 3048e4589fa5SSahitya Tummala * if shrinker is not registered. 3049e4589fa5SSahitya Tummala */ 3050e4589fa5SSahitya Tummala if (list_empty(&sbi->s_list)) 3051e4589fa5SSahitya Tummala return false; 3052e4589fa5SSahitya Tummala 3053886f56f9SAl Viro return S_ISREG(inode->i_mode); 30543e72f721SJaegeuk Kim } 30553e72f721SJaegeuk Kim 30561ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 30571ecc0c5cSChao Yu size_t size, gfp_t flags) 30580414b004SJaegeuk Kim { 305955523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 3060c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_KMALLOC); 30612c63feadSJaegeuk Kim return NULL; 306255523519SChao Yu } 30637fa750a1SArnd Bergmann 30640b6d4ca0SEric Biggers return kmalloc(size, flags); 30650414b004SJaegeuk Kim } 30660414b004SJaegeuk Kim 3067acbf054dSChao Yu static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, 3068acbf054dSChao Yu size_t size, gfp_t flags) 3069acbf054dSChao Yu { 3070acbf054dSChao Yu return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); 3071acbf054dSChao Yu } 3072acbf054dSChao Yu 3073628b3d14SChao Yu static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, 3074628b3d14SChao Yu size_t size, gfp_t flags) 3075628b3d14SChao Yu { 3076628b3d14SChao Yu if (time_to_inject(sbi, FAULT_KVMALLOC)) { 3077c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_KVMALLOC); 3078628b3d14SChao Yu return NULL; 3079628b3d14SChao Yu } 30807fa750a1SArnd Bergmann 3081628b3d14SChao Yu return kvmalloc(size, flags); 3082628b3d14SChao Yu } 3083628b3d14SChao Yu 3084628b3d14SChao Yu static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi, 3085628b3d14SChao Yu size_t size, gfp_t flags) 3086628b3d14SChao Yu { 3087628b3d14SChao Yu return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO); 3088628b3d14SChao Yu } 3089628b3d14SChao Yu 30907a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 3091f2470371SChao Yu { 30927a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 3093f2470371SChao Yu } 3094f2470371SChao Yu 30956afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode) 30966afc662eSChao Yu { 30976afc662eSChao Yu return F2FS_I(inode)->i_inline_xattr_size; 30986afc662eSChao Yu } 30996afc662eSChao Yu 31004d57b86dSChao Yu #define f2fs_get_inode_mode(i) \ 310191942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 3102a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 3103a6dda0e6SChristoph Hellwig 31047a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 31057a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 31067a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 31077a2af766SChao Yu 31085c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 31095c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 31102f84babfSSheng Yong ((offsetof(typeof(*(f2fs_inode)), field) + \ 31115c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 31122f84babfSSheng Yong <= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize))) \ 31135c57132eSChao Yu 31142bc4bea3SDaeho Jeong #define DEFAULT_IOSTAT_PERIOD_MS 3000 31152bc4bea3SDaeho Jeong #define MIN_IOSTAT_PERIOD_MS 100 31162bc4bea3SDaeho Jeong /* maximum period of iostat tracing is 1 day */ 31172bc4bea3SDaeho Jeong #define MAX_IOSTAT_PERIOD_MS 8640000 31182bc4bea3SDaeho Jeong 3119b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 3120b0af6d49SChao Yu { 3121b0af6d49SChao Yu int i; 3122b0af6d49SChao Yu 3123b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 31242bc4bea3SDaeho Jeong for (i = 0; i < NR_IO_TYPE; i++) { 31258b83ac81SChao Yu sbi->rw_iostat[i] = 0; 31268b83ac81SChao Yu sbi->prev_rw_iostat[i] = 0; 31272bc4bea3SDaeho Jeong } 3128b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 3129b0af6d49SChao Yu } 3130b0af6d49SChao Yu 31312bc4bea3SDaeho Jeong extern void f2fs_record_iostat(struct f2fs_sb_info *sbi); 31322bc4bea3SDaeho Jeong 3133b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 3134b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 3135b0af6d49SChao Yu { 3136b0af6d49SChao Yu if (!sbi->iostat_enable) 3137b0af6d49SChao Yu return; 3138b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 31398b83ac81SChao Yu sbi->rw_iostat[type] += io_bytes; 3140b0af6d49SChao Yu 3141b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 31428b83ac81SChao Yu sbi->rw_iostat[APP_BUFFERED_IO] = 31438b83ac81SChao Yu sbi->rw_iostat[APP_WRITE_IO] - 31448b83ac81SChao Yu sbi->rw_iostat[APP_DIRECT_IO]; 31458b83ac81SChao Yu 31468b83ac81SChao Yu if (type == APP_READ_IO || type == APP_DIRECT_READ_IO) 31478b83ac81SChao Yu sbi->rw_iostat[APP_BUFFERED_READ_IO] = 31488b83ac81SChao Yu sbi->rw_iostat[APP_READ_IO] - 31498b83ac81SChao Yu sbi->rw_iostat[APP_DIRECT_READ_IO]; 3150b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 31512bc4bea3SDaeho Jeong 31522bc4bea3SDaeho Jeong f2fs_record_iostat(sbi); 3153b0af6d49SChao Yu } 3154b0af6d49SChao Yu 31552c70c5e3SChao Yu #define __is_large_section(sbi) ((sbi)->segs_per_sec > 1) 31562c70c5e3SChao Yu 31576dc3a126SChao Yu #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META) 3158c9b60788SChao Yu 3159e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 3160e1da7872SChao Yu block_t blkaddr, int type); 3161e1da7872SChao Yu static inline void verify_blkaddr(struct f2fs_sb_info *sbi, 3162e1da7872SChao Yu block_t blkaddr, int type) 3163e1da7872SChao Yu { 3164e1da7872SChao Yu if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) { 3165dcbb4c10SJoe Perches f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.", 3166e1da7872SChao Yu blkaddr, type); 3167e1da7872SChao Yu f2fs_bug_on(sbi, 1); 3168e1da7872SChao Yu } 3169e1da7872SChao Yu } 3170e1da7872SChao Yu 3171e1da7872SChao Yu static inline bool __is_valid_data_blkaddr(block_t blkaddr) 31727b525dd0SChao Yu { 31734c8ff709SChao Yu if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR || 31744c8ff709SChao Yu blkaddr == COMPRESS_ADDR) 31757b525dd0SChao Yu return false; 31767b525dd0SChao Yu return true; 31777b525dd0SChao Yu } 31787b525dd0SChao Yu 3179240a5915SChao Yu static inline void f2fs_set_page_private(struct page *page, 3180240a5915SChao Yu unsigned long data) 3181240a5915SChao Yu { 3182240a5915SChao Yu if (PagePrivate(page)) 3183240a5915SChao Yu return; 3184240a5915SChao Yu 31857128cf9aSGuoqing Jiang attach_page_private(page, (void *)data); 3186240a5915SChao Yu } 3187240a5915SChao Yu 3188240a5915SChao Yu static inline void f2fs_clear_page_private(struct page *page) 3189240a5915SChao Yu { 31907128cf9aSGuoqing Jiang detach_page_private(page); 3191240a5915SChao Yu } 3192240a5915SChao Yu 319339a53e0cSJaegeuk Kim /* 319439a53e0cSJaegeuk Kim * file.c 319539a53e0cSJaegeuk Kim */ 3196cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 31974d57b86dSChao Yu void f2fs_truncate_data_blocks(struct dnode_of_data *dn); 31983265d3dbSChao Yu int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock); 3199c42d28ceSChao Yu int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock); 3200cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 3201549c7297SChristian Brauner int f2fs_getattr(struct user_namespace *mnt_userns, const struct path *path, 3202549c7297SChristian Brauner struct kstat *stat, u32 request_mask, unsigned int flags); 3203549c7297SChristian Brauner int f2fs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, 3204549c7297SChristian Brauner struct iattr *attr); 32054d57b86dSChao Yu int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 32064d57b86dSChao Yu void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); 3207c4020b2dSChao Yu int f2fs_precache_extents(struct inode *inode); 3208cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 3209cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 321078130819SChao Yu int f2fs_transfer_project_quota(struct inode *inode, kprojid_t kprojid); 32111ad71a27SJaegeuk Kim int f2fs_pin_file_control(struct inode *inode, bool inc); 321239a53e0cSJaegeuk Kim 321339a53e0cSJaegeuk Kim /* 321439a53e0cSJaegeuk Kim * inode.c 321539a53e0cSJaegeuk Kim */ 3216cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 3217704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 3218704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 3219cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 3220cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 32214d57b86dSChao Yu int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 32224d57b86dSChao Yu void f2fs_update_inode(struct inode *inode, struct page *node_page); 32234d57b86dSChao Yu void f2fs_update_inode_page(struct inode *inode); 3224cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 3225cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 32264d57b86dSChao Yu void f2fs_handle_failed_inode(struct inode *inode); 322739a53e0cSJaegeuk Kim 322839a53e0cSJaegeuk Kim /* 322939a53e0cSJaegeuk Kim * namei.c 323039a53e0cSJaegeuk Kim */ 32314d57b86dSChao Yu int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, 3232b6a06cbbSChao Yu bool hot, bool set); 323339a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 323439a53e0cSJaegeuk Kim 323539a53e0cSJaegeuk Kim /* 323639a53e0cSJaegeuk Kim * dir.c 323739a53e0cSJaegeuk Kim */ 32384d57b86dSChao Yu unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de); 323943c780baSEric Biggers int f2fs_init_casefolded_name(const struct inode *dir, 324043c780baSEric Biggers struct f2fs_filename *fname); 324143c780baSEric Biggers int f2fs_setup_filename(struct inode *dir, const struct qstr *iname, 324243c780baSEric Biggers int lookup, struct f2fs_filename *fname); 324343c780baSEric Biggers int f2fs_prepare_lookup(struct inode *dir, struct dentry *dentry, 324443c780baSEric Biggers struct f2fs_filename *fname); 324543c780baSEric Biggers void f2fs_free_filename(struct f2fs_filename *fname); 324643c780baSEric Biggers struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_ptr *d, 324743c780baSEric Biggers const struct f2fs_filename *fname, int *max_slots); 3248cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 3249cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 32504d57b86dSChao Yu void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent, 3251cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 32524d57b86dSChao Yu struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir, 325343c780baSEric Biggers const struct f2fs_filename *fname, struct page *dpage); 32544d57b86dSChao Yu void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode, 3255cac5a3d8SDongOh Shin unsigned int current_depth); 32564d57b86dSChao Yu int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots); 3257cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 3258cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 325943c780baSEric Biggers const struct f2fs_filename *fname, 326043c780baSEric Biggers struct page **res_page); 3261cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 3262cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 3263cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 3264cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 3265cac5a3d8SDongOh Shin struct page **page); 3266cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 3267cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 3268b06af2afSJaegeuk Kim bool f2fs_has_enough_room(struct inode *dir, struct page *ipage, 326943c780baSEric Biggers const struct f2fs_filename *fname); 3270cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 327143c780baSEric Biggers const struct fscrypt_str *name, f2fs_hash_t name_hash, 3272cac5a3d8SDongOh Shin unsigned int bit_pos); 327343c780baSEric Biggers int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname, 3274cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 327543c780baSEric Biggers int f2fs_add_dentry(struct inode *dir, const struct f2fs_filename *fname, 3276cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 32774d57b86dSChao Yu int f2fs_do_add_link(struct inode *dir, const struct qstr *name, 3278cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 3279cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 3280cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 3281cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 3282cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 328339a53e0cSJaegeuk Kim 3284b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 3285b7f7a5e0SAl Viro { 3286bfc2b7e8SEric Biggers if (fscrypt_is_nokey_name(dentry)) 3287bfc2b7e8SEric Biggers return -ENOKEY; 32884d57b86dSChao Yu return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name, 3289510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 3290b7f7a5e0SAl Viro } 3291b7f7a5e0SAl Viro 329239a53e0cSJaegeuk Kim /* 329339a53e0cSJaegeuk Kim * super.c 329439a53e0cSJaegeuk Kim */ 3295cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 3296cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 3297ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); 3298af033b2aSChao Yu int f2fs_quota_sync(struct super_block *sb, int type); 32996d1451bfSChengguang Xu loff_t max_file_blocks(struct inode *inode); 33004b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 3301cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 3302cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 33034d57b86dSChao Yu int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); 330439a53e0cSJaegeuk Kim 330539a53e0cSJaegeuk Kim /* 330639a53e0cSJaegeuk Kim * hash.c 330739a53e0cSJaegeuk Kim */ 330843c780baSEric Biggers void f2fs_hash_filename(const struct inode *dir, struct f2fs_filename *fname); 330939a53e0cSJaegeuk Kim 331039a53e0cSJaegeuk Kim /* 331139a53e0cSJaegeuk Kim * node.c 331239a53e0cSJaegeuk Kim */ 331339a53e0cSJaegeuk Kim struct dnode_of_data; 331439a53e0cSJaegeuk Kim struct node_info; 331539a53e0cSJaegeuk Kim 33164d57b86dSChao Yu int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid); 33174d57b86dSChao Yu bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type); 331850fa53ecSChao Yu bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page); 331950fa53ecSChao Yu void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi); 332050fa53ecSChao Yu void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page); 332150fa53ecSChao Yu void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi); 33224d57b86dSChao Yu int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 33234d57b86dSChao Yu bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 33244d57b86dSChao Yu bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 33257735730dSChao Yu int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, 33264d57b86dSChao Yu struct node_info *ni); 33274d57b86dSChao Yu pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 33284d57b86dSChao Yu int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 33294d57b86dSChao Yu int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from); 33304d57b86dSChao Yu int f2fs_truncate_xattr_node(struct inode *inode); 333150fa53ecSChao Yu int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, 333250fa53ecSChao Yu unsigned int seq_id); 33334d57b86dSChao Yu int f2fs_remove_inode_page(struct inode *inode); 33344d57b86dSChao Yu struct page *f2fs_new_inode_page(struct inode *inode); 33354d57b86dSChao Yu struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs); 33364d57b86dSChao Yu void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 33374d57b86dSChao Yu struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 33384d57b86dSChao Yu struct page *f2fs_get_node_page_ra(struct page *parent, int start); 333948018b4cSChao Yu int f2fs_move_node_page(struct page *node_page, int gc_type); 334068e79bafSJia Yang void f2fs_flush_inline_data(struct f2fs_sb_info *sbi); 33414d57b86dSChao Yu int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 334250fa53ecSChao Yu struct writeback_control *wbc, bool atomic, 334350fa53ecSChao Yu unsigned int *seq_id); 33444d57b86dSChao Yu int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, 33454d57b86dSChao Yu struct writeback_control *wbc, 3346b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 3347e2374015SChao Yu int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 33484d57b86dSChao Yu bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 33494d57b86dSChao Yu void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 33504d57b86dSChao Yu void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 33514d57b86dSChao Yu int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 33529627a7b3SChao Yu int f2fs_recover_inline_xattr(struct inode *inode, struct page *page); 33534d57b86dSChao Yu int f2fs_recover_xattr_data(struct inode *inode, struct page *page); 33544d57b86dSChao Yu int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 33557735730dSChao Yu int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, 3356cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 3357edc55aafSJaegeuk Kim int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 33584d57b86dSChao Yu int f2fs_build_node_manager(struct f2fs_sb_info *sbi); 33594d57b86dSChao Yu void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi); 33604d57b86dSChao Yu int __init f2fs_create_node_manager_caches(void); 33614d57b86dSChao Yu void f2fs_destroy_node_manager_caches(void); 336239a53e0cSJaegeuk Kim 336339a53e0cSJaegeuk Kim /* 336439a53e0cSJaegeuk Kim * segment.c 336539a53e0cSJaegeuk Kim */ 33664d57b86dSChao Yu bool f2fs_need_SSR(struct f2fs_sb_info *sbi); 33674d57b86dSChao Yu void f2fs_register_inmem_page(struct inode *inode, struct page *page); 33684d57b86dSChao Yu void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure); 33694d57b86dSChao Yu void f2fs_drop_inmem_pages(struct inode *inode); 33704d57b86dSChao Yu void f2fs_drop_inmem_page(struct inode *inode, struct page *page); 33714d57b86dSChao Yu int f2fs_commit_inmem_pages(struct inode *inode); 3372cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 33737bcd0cfaSChao Yu void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg); 337439d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 33754d57b86dSChao Yu int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi); 33761228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); 33774d57b86dSChao Yu void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 33784d57b86dSChao Yu void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 33794d57b86dSChao Yu bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 33804d57b86dSChao Yu void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi); 33814d57b86dSChao Yu void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi); 338203f2c02dSJaegeuk Kim bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi); 33834d57b86dSChao Yu void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, 33844d57b86dSChao Yu struct cp_control *cpc); 33854354994fSDaniel Rosenberg void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi); 33864d3aed70SDaniel Rosenberg block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi); 33874d3aed70SDaniel Rosenberg int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable); 33884d57b86dSChao Yu void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi); 33894d57b86dSChao Yu int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 3390*61461fc9SChao Yu bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno); 3391093749e2SChao Yu void f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi); 3392093749e2SChao Yu void f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi); 3393093749e2SChao Yu void f2fs_restore_inmem_curseg(struct f2fs_sb_info *sbi); 3394093749e2SChao Yu void f2fs_get_new_segment(struct f2fs_sb_info *sbi, 3395093749e2SChao Yu unsigned int *newseg, bool new_sec, int dir); 33960ef81833SChao Yu void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, 339704f0b2eaSQiuyang Sun unsigned int start, unsigned int end); 3398e1175f02SChao Yu void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type); 3399901d745fSChao Yu void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi); 3400cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 34014d57b86dSChao Yu bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, 34024d57b86dSChao Yu struct cp_control *cpc); 34034d57b86dSChao Yu struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 34044d57b86dSChao Yu void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src, 34054d57b86dSChao Yu block_t blk_addr); 34064d57b86dSChao Yu void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 3407b0af6d49SChao Yu enum iostat_type io_type); 34084d57b86dSChao Yu void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio); 34094d57b86dSChao Yu void f2fs_outplace_write_data(struct dnode_of_data *dn, 34104d57b86dSChao Yu struct f2fs_io_info *fio); 34114d57b86dSChao Yu int f2fs_inplace_write_data(struct f2fs_io_info *fio); 34124d57b86dSChao Yu void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 3413cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 3414c5d02785SChao Yu bool recover_curseg, bool recover_newaddr, 3415c5d02785SChao Yu bool from_gc); 3416cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 3417cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 3418cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 3419cac5a3d8SDongOh Shin bool recover_newaddr); 34204d57b86dSChao Yu void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 3421cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 3422fb830fc5SChao Yu struct f2fs_summary *sum, int type, 3423f608c38cSChao Yu struct f2fs_io_info *fio); 3424cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 3425bae0ee7aSChao Yu enum page_type type, bool ordered, bool locked); 34260ded69f6SJaegeuk Kim void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr); 34271e78e8bdSSahitya Tummala void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr, 34281e78e8bdSSahitya Tummala block_t len); 34294d57b86dSChao Yu void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 34304d57b86dSChao Yu void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 34314d57b86dSChao Yu int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 3432cac5a3d8SDongOh Shin unsigned int val, int alloc); 34334d57b86dSChao Yu void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 3434c426d991SShin'ichiro Kawasaki int f2fs_fix_curseg_write_pointer(struct f2fs_sb_info *sbi); 3435d508c94eSShin'ichiro Kawasaki int f2fs_check_write_pointer(struct f2fs_sb_info *sbi); 34364d57b86dSChao Yu int f2fs_build_segment_manager(struct f2fs_sb_info *sbi); 34374d57b86dSChao Yu void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi); 34384d57b86dSChao Yu int __init f2fs_create_segment_manager_caches(void); 34394d57b86dSChao Yu void f2fs_destroy_segment_manager_caches(void); 34404d57b86dSChao Yu int f2fs_rw_hint_to_seg_type(enum rw_hint hint); 34414d57b86dSChao Yu enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, 34424d57b86dSChao Yu enum page_type type, enum temp_type temp); 3443de881df9SAravind Ramesh unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi, 3444de881df9SAravind Ramesh unsigned int segno); 3445de881df9SAravind Ramesh unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi, 3446de881df9SAravind Ramesh unsigned int segno); 344739a53e0cSJaegeuk Kim 344839a53e0cSJaegeuk Kim /* 344939a53e0cSJaegeuk Kim * checkpoint.c 345039a53e0cSJaegeuk Kim */ 3451cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 34524d57b86dSChao Yu struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 34534d57b86dSChao Yu struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 345486f33603SJaegeuk Kim struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index); 34554d57b86dSChao Yu struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 3456e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 34574d57b86dSChao Yu block_t blkaddr, int type); 34584d57b86dSChao Yu int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 3459cac5a3d8SDongOh Shin int type, bool sync); 34604d57b86dSChao Yu void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 34614d57b86dSChao Yu long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 3462b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 34634d57b86dSChao Yu void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 34644d57b86dSChao Yu void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 34654d57b86dSChao Yu void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all); 34664d57b86dSChao Yu bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 34674d57b86dSChao Yu void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 346839d787beSChao Yu unsigned int devidx, int type); 34694d57b86dSChao Yu bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 347039d787beSChao Yu unsigned int devidx, int type); 3471cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 34724d57b86dSChao Yu int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi); 34734d57b86dSChao Yu void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi); 34744d57b86dSChao Yu void f2fs_add_orphan_inode(struct inode *inode); 34754d57b86dSChao Yu void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 34764d57b86dSChao Yu int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi); 34774d57b86dSChao Yu int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi); 34784d57b86dSChao Yu void f2fs_update_dirty_page(struct inode *inode, struct page *page); 34794d57b86dSChao Yu void f2fs_remove_dirty_inode(struct inode *inode); 34804d57b86dSChao Yu int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 3481bf22c3ccSSahitya Tummala void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type); 34823a0a9cbcSChao Yu u64 f2fs_get_sectors_written(struct f2fs_sb_info *sbi); 34834d57b86dSChao Yu int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 34844d57b86dSChao Yu void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi); 34854d57b86dSChao Yu int __init f2fs_create_checkpoint_caches(void); 34864d57b86dSChao Yu void f2fs_destroy_checkpoint_caches(void); 3487261eeb9cSDaeho Jeong int f2fs_issue_checkpoint(struct f2fs_sb_info *sbi); 3488261eeb9cSDaeho Jeong int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi); 3489261eeb9cSDaeho Jeong void f2fs_stop_ckpt_thread(struct f2fs_sb_info *sbi); 3490261eeb9cSDaeho Jeong void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi); 349139a53e0cSJaegeuk Kim 349239a53e0cSJaegeuk Kim /* 349339a53e0cSJaegeuk Kim * data.c 349439a53e0cSJaegeuk Kim */ 3495f543805fSChao Yu int __init f2fs_init_bioset(void); 3496f543805fSChao Yu void f2fs_destroy_bioset(void); 34970b20fcecSChao Yu int f2fs_init_bio_entry_cache(void); 34980b20fcecSChao Yu void f2fs_destroy_bio_entry_cache(void); 34994c8ff709SChao Yu void f2fs_submit_bio(struct f2fs_sb_info *sbi, 35004c8ff709SChao Yu struct bio *bio, enum page_type type); 3501b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 3502b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 3503bab475c5SChao Yu struct inode *inode, struct page *page, 3504bab475c5SChao Yu nid_t ino, enum page_type type); 35050b20fcecSChao Yu void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi, 35060b20fcecSChao Yu struct bio **bio, struct page *page); 3507b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 3508cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 35098648de2cSChao Yu int f2fs_merge_page_bio(struct f2fs_io_info *fio); 3510fe16efe6SChao Yu void f2fs_submit_page_write(struct f2fs_io_info *fio); 3511cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 3512cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 3513cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 35144d57b86dSChao Yu void f2fs_set_data_blkaddr(struct dnode_of_data *dn); 3515cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 35164d57b86dSChao Yu int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 35174d57b86dSChao Yu int f2fs_reserve_new_block(struct dnode_of_data *dn); 3518cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 3519cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 3520cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 35214d57b86dSChao Yu struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, 3522cac5a3d8SDongOh Shin int op_flags, bool for_write); 35234d57b86dSChao Yu struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index); 35244d57b86dSChao Yu struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index, 3525cac5a3d8SDongOh Shin bool for_write); 35264d57b86dSChao Yu struct page *f2fs_get_new_data_page(struct inode *inode, 3527cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 35284d57b86dSChao Yu int f2fs_do_write_data_page(struct f2fs_io_info *fio); 35290ef81833SChao Yu void f2fs_do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock); 3530cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 3531cac5a3d8SDongOh Shin int create, int flag); 3532cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 3533cac5a3d8SDongOh Shin u64 start, u64 len); 35344c8ff709SChao Yu int f2fs_encrypt_one_page(struct f2fs_io_info *fio); 35354d57b86dSChao Yu bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); 35364d57b86dSChao Yu bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); 35374c8ff709SChao Yu int f2fs_write_single_data_page(struct page *page, int *submitted, 35384c8ff709SChao Yu struct bio **bio, sector_t *last_block, 35394c8ff709SChao Yu struct writeback_control *wbc, 35404c8ff709SChao Yu enum iostat_type io_type, 35413afae09fSChao Yu int compr_blocks, bool allow_balance); 3542cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 3543cac5a3d8SDongOh Shin unsigned int length); 3544cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 35455b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 3546cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 3547cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 35485b7a487cSWeichao Guo #endif 3549b91050a8SHyunchul Lee bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len); 35505ec2d99dSMatthew Wilcox void f2fs_clear_page_cache_dirty_tag(struct page *page); 35514c8ff709SChao Yu int f2fs_init_post_read_processing(void); 35524c8ff709SChao Yu void f2fs_destroy_post_read_processing(void); 35534c8ff709SChao Yu int f2fs_init_post_read_wq(struct f2fs_sb_info *sbi); 35544c8ff709SChao Yu void f2fs_destroy_post_read_wq(struct f2fs_sb_info *sbi); 355539a53e0cSJaegeuk Kim 355639a53e0cSJaegeuk Kim /* 355739a53e0cSJaegeuk Kim * gc.c 355839a53e0cSJaegeuk Kim */ 35594d57b86dSChao Yu int f2fs_start_gc_thread(struct f2fs_sb_info *sbi); 35604d57b86dSChao Yu void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi); 35614d57b86dSChao Yu block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 35627dede886SChao Yu int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, bool force, 3563e066b83cSJaegeuk Kim unsigned int segno); 35644d57b86dSChao Yu void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); 356504f0b2eaSQiuyang Sun int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count); 3566093749e2SChao Yu int __init f2fs_create_garbage_collection_cache(void); 3567093749e2SChao Yu void f2fs_destroy_garbage_collection_cache(void); 356839a53e0cSJaegeuk Kim 356939a53e0cSJaegeuk Kim /* 357039a53e0cSJaegeuk Kim * recovery.c 357139a53e0cSJaegeuk Kim */ 35724d57b86dSChao Yu int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 35734d57b86dSChao Yu bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi); 357439a53e0cSJaegeuk Kim 357539a53e0cSJaegeuk Kim /* 357639a53e0cSJaegeuk Kim * debug.c 357739a53e0cSJaegeuk Kim */ 357839a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 357939a53e0cSJaegeuk Kim struct f2fs_stat_info { 358039a53e0cSJaegeuk Kim struct list_head stat_list; 358139a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 358239a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 358339a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 35845b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 35855b7ee374SChao Yu unsigned long long hit_total, total_ext; 3586c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 35872c8a4a28SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; 35882c8a4a28SJaegeuk Kim int ndirty_data, ndirty_qdata; 358935782b23SJaegeuk Kim int inmem_pages; 35902c8a4a28SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; 35915b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 35925b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 359339a53e0cSJaegeuk Kim int total_count, utilization; 35948b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 35955f9abab4SJaegeuk Kim int nr_rd_data, nr_rd_node, nr_rd_meta; 359602b16d0aSChao Yu int nr_dio_read, nr_dio_write; 3597274bd9baSChao Yu unsigned int io_skip_bggc, other_skip_bggc; 359814d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 359914d8d5f7SChao Yu int nr_discarding, nr_discarded; 36005f32366aSChao Yu int nr_discard_cmd; 3601d84d1cbdSChao Yu unsigned int undiscard_blks; 3602261eeb9cSDaeho Jeong int nr_issued_ckpt, nr_total_ckpt, nr_queued_ckpt; 3603261eeb9cSDaeho Jeong unsigned int cur_ckpt_time, peak_ckpt_time; 3604a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 3605ae999bb9SDaeho Jeong int compr_inode; 3606ae999bb9SDaeho Jeong unsigned long long compr_blocks; 3607648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 3608f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 360939a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 361039a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 361139a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 361239a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 361342190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 361439a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 3615e1235983SChangman Lee int bg_node_segs, bg_data_segs; 361639a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 3617e1235983SChangman Lee int bg_data_blks, bg_node_blks; 36182ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; 361939a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 362039a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 362139a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 36220759e2c1SChao Yu unsigned int dirty_seg[NR_CURSEG_TYPE]; 36230759e2c1SChao Yu unsigned int full_seg[NR_CURSEG_TYPE]; 36240759e2c1SChao Yu unsigned int valid_blks[NR_CURSEG_TYPE]; 362539a53e0cSJaegeuk Kim 3626b63e7be5SChao Yu unsigned int meta_count[META_MAX]; 362739a53e0cSJaegeuk Kim unsigned int segment_count[2]; 362839a53e0cSJaegeuk Kim unsigned int block_count[2]; 3629b9a2c252SChangman Lee unsigned int inplace_count; 36309edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 363139a53e0cSJaegeuk Kim }; 363239a53e0cSJaegeuk Kim 3633963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 3634963d4f7dSGu Zheng { 3635963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 3636963d4f7dSGu Zheng } 3637963d4f7dSGu Zheng 3638942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 363942190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 364039a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 3641fc7100eaSHridya Valsaraju #define stat_inc_bggc_count(si) ((si)->bg_gc++) 3642274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) ((sbi)->io_skip_bggc++) 3643274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) ((sbi)->other_skip_bggc++) 364433fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 364533fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 36465b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 36475b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 36485b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 36495b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 3650d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 3651d5e8f6c9SChao Yu do { \ 3652d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3653d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 3654d5e8f6c9SChao Yu } while (0) 3655d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 3656d5e8f6c9SChao Yu do { \ 3657d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3658d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 3659d5e8f6c9SChao Yu } while (0) 36600dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 36610dbdc2aeSJaegeuk Kim do { \ 36620dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 366303e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 36640dbdc2aeSJaegeuk Kim } while (0) 36650dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 36660dbdc2aeSJaegeuk Kim do { \ 36670dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 366803e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 36690dbdc2aeSJaegeuk Kim } while (0) 36703289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 36713289c061SJaegeuk Kim do { \ 36723289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 367303e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 36743289c061SJaegeuk Kim } while (0) 36753289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 36763289c061SJaegeuk Kim do { \ 36773289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 367803e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 36793289c061SJaegeuk Kim } while (0) 36804c8ff709SChao Yu #define stat_inc_compr_inode(inode) \ 36814c8ff709SChao Yu do { \ 36824c8ff709SChao Yu if (f2fs_compressed_file(inode)) \ 36834c8ff709SChao Yu (atomic_inc(&F2FS_I_SB(inode)->compr_inode)); \ 36844c8ff709SChao Yu } while (0) 36854c8ff709SChao Yu #define stat_dec_compr_inode(inode) \ 36864c8ff709SChao Yu do { \ 36874c8ff709SChao Yu if (f2fs_compressed_file(inode)) \ 36884c8ff709SChao Yu (atomic_dec(&F2FS_I_SB(inode)->compr_inode)); \ 36894c8ff709SChao Yu } while (0) 36904c8ff709SChao Yu #define stat_add_compr_blocks(inode, blocks) \ 3691ae999bb9SDaeho Jeong (atomic64_add(blocks, &F2FS_I_SB(inode)->compr_blocks)) 36924c8ff709SChao Yu #define stat_sub_compr_blocks(inode, blocks) \ 3693ae999bb9SDaeho Jeong (atomic64_sub(blocks, &F2FS_I_SB(inode)->compr_blocks)) 3694b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) \ 3695b63e7be5SChao Yu do { \ 3696b63e7be5SChao Yu if (blkaddr < SIT_I(sbi)->sit_base_addr) \ 3697b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_CP]); \ 3698b63e7be5SChao Yu else if (blkaddr < NM_I(sbi)->nat_blkaddr) \ 3699b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SIT]); \ 3700b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->ssa_blkaddr) \ 3701b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_NAT]); \ 3702b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->main_blkaddr) \ 3703b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SSA]); \ 3704b63e7be5SChao Yu } while (0) 3705dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 3706dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 3707dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 3708dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 3709b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 3710b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 371126a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 371226a28a0cSJaegeuk Kim do { \ 37130e6d0164SSahitya Tummala int cur = F2FS_I_SB(inode)->atomic_files; \ 371426a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 371526a28a0cSJaegeuk Kim if (cur > max) \ 371626a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 371726a28a0cSJaegeuk Kim } while (0) 3718648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 3719648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 3720648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 3721648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 3722648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 3723648d50baSChao Yu do { \ 3724648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 3725648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 3726648d50baSChao Yu if (cur > max) \ 3727648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 3728648d50baSChao Yu } while (0) 3729e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 373039a53e0cSJaegeuk Kim do { \ 3731963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 373268afcf2dSTomohiro Kusumi si->tot_segs++; \ 373368afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 373439a53e0cSJaegeuk Kim si->data_segs++; \ 3735e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 3736e1235983SChangman Lee } else { \ 373739a53e0cSJaegeuk Kim si->node_segs++; \ 3738e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 3739e1235983SChangman Lee } \ 374039a53e0cSJaegeuk Kim } while (0) 374139a53e0cSJaegeuk Kim 374239a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 374368afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 374439a53e0cSJaegeuk Kim 3745e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 374639a53e0cSJaegeuk Kim do { \ 3747963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 374839a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 374939a53e0cSJaegeuk Kim si->data_blks += (blks); \ 375068afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 375139a53e0cSJaegeuk Kim } while (0) 375239a53e0cSJaegeuk Kim 3753e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 375439a53e0cSJaegeuk Kim do { \ 3755963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 375639a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 375739a53e0cSJaegeuk Kim si->node_blks += (blks); \ 375868afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 375939a53e0cSJaegeuk Kim } while (0) 376039a53e0cSJaegeuk Kim 3761cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 3762cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 376321acc07dSGreg Kroah-Hartman void __init f2fs_create_root_stats(void); 37644589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 3765fc7100eaSHridya Valsaraju void f2fs_update_sit_info(struct f2fs_sb_info *sbi); 376639a53e0cSJaegeuk Kim #else 3767d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 3768d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 3769d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 3770d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 3771274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) do { } while (0) 3772274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) do { } while (0) 3773d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 3774d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 3775fc7100eaSHridya Valsaraju #define stat_inc_total_hit(sbi) do { } while (0) 3776fc7100eaSHridya Valsaraju #define stat_inc_rbtree_node_hit(sbi) do { } while (0) 3777d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 3778d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 3779d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 3780d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 3781d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 3782d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 3783d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 3784d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 37854c8ff709SChao Yu #define stat_inc_compr_inode(inode) do { } while (0) 37864c8ff709SChao Yu #define stat_dec_compr_inode(inode) do { } while (0) 37874c8ff709SChao Yu #define stat_add_compr_blocks(inode, blocks) do { } while (0) 37884c8ff709SChao Yu #define stat_sub_compr_blocks(inode, blocks) do { } while (0) 3789d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 3790d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 3791d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 3792d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 3793b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) do { } while (0) 3794d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 3795d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 3796d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 3797d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 3798d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 3799d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 3800d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 380139a53e0cSJaegeuk Kim 380239a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 380339a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 380421acc07dSGreg Kroah-Hartman static inline void __init f2fs_create_root_stats(void) { } 38054589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 380648abe91aSYueHaibing static inline void f2fs_update_sit_info(struct f2fs_sb_info *sbi) {} 380739a53e0cSJaegeuk Kim #endif 380839a53e0cSJaegeuk Kim 380939a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 381039a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 381139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 381239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 381339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 381439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 381539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 381639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 3817cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 381839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 38194d57b86dSChao Yu extern struct kmem_cache *f2fs_inode_entry_slab; 38201001b347SHuajun Li 3821e18c65b2SHuajun Li /* 3822e18c65b2SHuajun Li * inline.c 3823e18c65b2SHuajun Li */ 3824cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 3825cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 38264d57b86dSChao Yu void f2fs_do_read_inline_data(struct page *page, struct page *ipage); 38274d57b86dSChao Yu void f2fs_truncate_inline_inode(struct inode *inode, 38284d57b86dSChao Yu struct page *ipage, u64 from); 3829cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 3830cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 3831cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 3832b06af2afSJaegeuk Kim int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry); 3833cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 38349627a7b3SChao Yu int f2fs_recover_inline_data(struct inode *inode, struct page *npage); 38354d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, 383643c780baSEric Biggers const struct f2fs_filename *fname, 383743c780baSEric Biggers struct page **res_page); 38384d57b86dSChao Yu int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 3839cac5a3d8SDongOh Shin struct page *ipage); 384043c780baSEric Biggers int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname, 3841cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 38424d57b86dSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, 38434d57b86dSChao Yu struct page *page, struct inode *dir, 38444d57b86dSChao Yu struct inode *inode); 3845cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 3846cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 3847cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 3848cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 3849cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 3850cac5a3d8SDongOh Shin __u64 start, __u64 len); 3851cde4de12SJaegeuk Kim 3852cde4de12SJaegeuk Kim /* 38532658e50dSJaegeuk Kim * shrinker.c 38542658e50dSJaegeuk Kim */ 3855cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 3856cac5a3d8SDongOh Shin struct shrink_control *sc); 3857cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 3858cac5a3d8SDongOh Shin struct shrink_control *sc); 3859cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 3860cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 38612658e50dSJaegeuk Kim 38622658e50dSJaegeuk Kim /* 3863a28ef1f5SChao Yu * extent_cache.c 3864a28ef1f5SChao Yu */ 38654dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree(struct rb_root_cached *root, 3866004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 38672e9b2bb2SChao Yu struct rb_node **f2fs_lookup_rb_tree_ext(struct f2fs_sb_info *sbi, 38682e9b2bb2SChao Yu struct rb_root_cached *root, 38692e9b2bb2SChao Yu struct rb_node **parent, 38702e9b2bb2SChao Yu unsigned long long key, bool *left_most); 38714d57b86dSChao Yu struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 38724dada3fdSChao Yu struct rb_root_cached *root, 38734dada3fdSChao Yu struct rb_node **parent, 38744dada3fdSChao Yu unsigned int ofs, bool *leftmost); 38754dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root, 3876004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 3877004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 3878004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 38794dada3fdSChao Yu bool force, bool *leftmost); 38804d57b86dSChao Yu bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi, 38812e9b2bb2SChao Yu struct rb_root_cached *root, bool check_key); 3882cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 3883a6d601f3SChao Yu void f2fs_init_extent_tree(struct inode *inode, struct page *ipage); 3884cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 3885cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 3886cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 3887cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 3888cac5a3d8SDongOh Shin struct extent_info *ei); 3889cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 389019b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 3891cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 38924d57b86dSChao Yu void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi); 38934d57b86dSChao Yu int __init f2fs_create_extent_cache(void); 38944d57b86dSChao Yu void f2fs_destroy_extent_cache(void); 3895a28ef1f5SChao Yu 3896a28ef1f5SChao Yu /* 38978ceffcb2SChao Yu * sysfs.c 38988ceffcb2SChao Yu */ 3899dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 3900dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 3901dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 3902dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 39038ceffcb2SChao Yu 390495ae251fSEric Biggers /* verity.c */ 390595ae251fSEric Biggers extern const struct fsverity_operations f2fs_verityops; 390695ae251fSEric Biggers 39078ceffcb2SChao Yu /* 3908cde4de12SJaegeuk Kim * crypto support 3909cde4de12SJaegeuk Kim */ 39101958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 39111958593eSJaegeuk Kim { 391262230e0dSChandan Rajendra return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); 39131958593eSJaegeuk Kim } 39141958593eSJaegeuk Kim 3915cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 3916cde4de12SJaegeuk Kim { 3917643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 3918cde4de12SJaegeuk Kim file_set_encrypt(inode); 39199149a5ebSChao Yu f2fs_set_inode_flags(inode); 3920cde4de12SJaegeuk Kim #endif 3921cde4de12SJaegeuk Kim } 3922cde4de12SJaegeuk Kim 39236dbb1796SEric Biggers /* 39246dbb1796SEric Biggers * Returns true if the reads of the inode's data need to undergo some 39256dbb1796SEric Biggers * postprocessing step, like decryption or authenticity verification. 39266dbb1796SEric Biggers */ 39276dbb1796SEric Biggers static inline bool f2fs_post_read_required(struct inode *inode) 3928cde4de12SJaegeuk Kim { 39294c8ff709SChao Yu return f2fs_encrypted_file(inode) || fsverity_active(inode) || 39304c8ff709SChao Yu f2fs_compressed_file(inode); 39314c8ff709SChao Yu } 39324c8ff709SChao Yu 39334c8ff709SChao Yu /* 39344c8ff709SChao Yu * compress.c 39354c8ff709SChao Yu */ 39364c8ff709SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 39374c8ff709SChao Yu bool f2fs_is_compressed_page(struct page *page); 39384c8ff709SChao Yu struct page *f2fs_compress_control_page(struct page *page); 39394c8ff709SChao Yu int f2fs_prepare_compress_overwrite(struct inode *inode, 39404c8ff709SChao Yu struct page **pagep, pgoff_t index, void **fsdata); 39414c8ff709SChao Yu bool f2fs_compress_write_end(struct inode *inode, void *fsdata, 39424c8ff709SChao Yu pgoff_t index, unsigned copied); 39433265d3dbSChao Yu int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock); 39444c8ff709SChao Yu void f2fs_compress_write_end_io(struct bio *bio, struct page *page); 39454c8ff709SChao Yu bool f2fs_is_compress_backend_ready(struct inode *inode); 39465e6bbde9SChao Yu int f2fs_init_compress_mempool(void); 39475e6bbde9SChao Yu void f2fs_destroy_compress_mempool(void); 39487f59b277SEric Biggers void f2fs_end_read_compressed_page(struct page *page, bool failed); 39494c8ff709SChao Yu bool f2fs_cluster_is_empty(struct compress_ctx *cc); 39504c8ff709SChao Yu bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index); 39514c8ff709SChao Yu void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page); 39524c8ff709SChao Yu int f2fs_write_multi_pages(struct compress_ctx *cc, 39534c8ff709SChao Yu int *submitted, 39544c8ff709SChao Yu struct writeback_control *wbc, 39554c8ff709SChao Yu enum iostat_type io_type); 39564c8ff709SChao Yu int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index); 39574c8ff709SChao Yu int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, 39584c8ff709SChao Yu unsigned nr_pages, sector_t *last_block_in_bio, 39590683728aSChao Yu bool is_readahead, bool for_write); 39604c8ff709SChao Yu struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc); 39617f59b277SEric Biggers void f2fs_decompress_end_io(struct decompress_io_ctx *dic, bool failed); 39627f59b277SEric Biggers void f2fs_put_page_dic(struct page *page); 39634c8ff709SChao Yu int f2fs_init_compress_ctx(struct compress_ctx *cc); 39644c8ff709SChao Yu void f2fs_destroy_compress_ctx(struct compress_ctx *cc); 39654c8ff709SChao Yu void f2fs_init_compress_info(struct f2fs_sb_info *sbi); 396631083031SChao Yu int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi); 396731083031SChao Yu void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi); 3968c68d6c88SChao Yu int __init f2fs_init_compress_cache(void); 3969c68d6c88SChao Yu void f2fs_destroy_compress_cache(void); 39705ac443e2SDaeho Jeong #define inc_compr_inode_stat(inode) \ 39715ac443e2SDaeho Jeong do { \ 39725ac443e2SDaeho Jeong struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ 39735ac443e2SDaeho Jeong sbi->compr_new_inode++; \ 39745ac443e2SDaeho Jeong } while (0) 39755ac443e2SDaeho Jeong #define add_compr_block_stat(inode, blocks) \ 39765ac443e2SDaeho Jeong do { \ 39775ac443e2SDaeho Jeong struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ 39785ac443e2SDaeho Jeong int diff = F2FS_I(inode)->i_cluster_size - blocks; \ 39795ac443e2SDaeho Jeong sbi->compr_written_block += blocks; \ 39805ac443e2SDaeho Jeong sbi->compr_saved_block += diff; \ 39815ac443e2SDaeho Jeong } while (0) 39824c8ff709SChao Yu #else 39834c8ff709SChao Yu static inline bool f2fs_is_compressed_page(struct page *page) { return false; } 39844c8ff709SChao Yu static inline bool f2fs_is_compress_backend_ready(struct inode *inode) 39854c8ff709SChao Yu { 39864c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 39874c8ff709SChao Yu return true; 39884c8ff709SChao Yu /* not support compression */ 39894c8ff709SChao Yu return false; 39904c8ff709SChao Yu } 39914c8ff709SChao Yu static inline struct page *f2fs_compress_control_page(struct page *page) 39924c8ff709SChao Yu { 39934c8ff709SChao Yu WARN_ON_ONCE(1); 39944c8ff709SChao Yu return ERR_PTR(-EINVAL); 39954c8ff709SChao Yu } 39965e6bbde9SChao Yu static inline int f2fs_init_compress_mempool(void) { return 0; } 39975e6bbde9SChao Yu static inline void f2fs_destroy_compress_mempool(void) { } 39987f59b277SEric Biggers static inline void f2fs_end_read_compressed_page(struct page *page, bool failed) 39997f59b277SEric Biggers { 40007f59b277SEric Biggers WARN_ON_ONCE(1); 40017f59b277SEric Biggers } 40027f59b277SEric Biggers static inline void f2fs_put_page_dic(struct page *page) 40037f59b277SEric Biggers { 40047f59b277SEric Biggers WARN_ON_ONCE(1); 40057f59b277SEric Biggers } 400631083031SChao Yu static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { return 0; } 400731083031SChao Yu static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) { } 4008c68d6c88SChao Yu static inline int __init f2fs_init_compress_cache(void) { return 0; } 4009c68d6c88SChao Yu static inline void f2fs_destroy_compress_cache(void) { } 40105ac443e2SDaeho Jeong #define inc_compr_inode_stat(inode) do { } while (0) 40114c8ff709SChao Yu #endif 40124c8ff709SChao Yu 40134c8ff709SChao Yu static inline void set_compress_context(struct inode *inode) 40144c8ff709SChao Yu { 40154c8ff709SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 40164c8ff709SChao Yu 40174c8ff709SChao Yu F2FS_I(inode)->i_compress_algorithm = 40184c8ff709SChao Yu F2FS_OPTION(sbi).compress_algorithm; 40194c8ff709SChao Yu F2FS_I(inode)->i_log_cluster_size = 40204c8ff709SChao Yu F2FS_OPTION(sbi).compress_log_size; 4021b28f047bSChao Yu F2FS_I(inode)->i_compress_flag = 4022b28f047bSChao Yu F2FS_OPTION(sbi).compress_chksum ? 4023b28f047bSChao Yu 1 << COMPRESS_CHKSUM : 0; 40244c8ff709SChao Yu F2FS_I(inode)->i_cluster_size = 40254c8ff709SChao Yu 1 << F2FS_I(inode)->i_log_cluster_size; 40263fde13f8SChao Yu if (F2FS_I(inode)->i_compress_algorithm == COMPRESS_LZ4 && 40273fde13f8SChao Yu F2FS_OPTION(sbi).compress_level) 40283fde13f8SChao Yu F2FS_I(inode)->i_compress_flag |= 40293fde13f8SChao Yu F2FS_OPTION(sbi).compress_level << 40303fde13f8SChao Yu COMPRESS_LEVEL_OFFSET; 40314c8ff709SChao Yu F2FS_I(inode)->i_flags |= F2FS_COMPR_FL; 40324c8ff709SChao Yu set_inode_flag(inode, FI_COMPRESSED_FILE); 40334c8ff709SChao Yu stat_inc_compr_inode(inode); 40345ac443e2SDaeho Jeong inc_compr_inode_stat(inode); 4035530e0704SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 40364c8ff709SChao Yu } 40374c8ff709SChao Yu 403878134d03SDaeho Jeong static inline bool f2fs_disable_compressed_file(struct inode *inode) 40394c8ff709SChao Yu { 40404c8ff709SChao Yu struct f2fs_inode_info *fi = F2FS_I(inode); 40414c8ff709SChao Yu 40424c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 404378134d03SDaeho Jeong return true; 404478134d03SDaeho Jeong if (S_ISREG(inode->i_mode) && 404578134d03SDaeho Jeong (get_dirty_pages(inode) || atomic_read(&fi->i_compr_blocks))) 404678134d03SDaeho Jeong return false; 40474c8ff709SChao Yu 40484c8ff709SChao Yu fi->i_flags &= ~F2FS_COMPR_FL; 40494c8ff709SChao Yu stat_dec_compr_inode(inode); 405096f5b4faSChao Yu clear_inode_flag(inode, FI_COMPRESSED_FILE); 4051530e0704SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 405278134d03SDaeho Jeong return true; 4053cde4de12SJaegeuk Kim } 4054cde4de12SJaegeuk Kim 4055ccd31cb2SSheng Yong #define F2FS_FEATURE_FUNCS(name, flagname) \ 40567beb01f7SChao Yu static inline int f2fs_sb_has_##name(struct f2fs_sb_info *sbi) \ 4057ccd31cb2SSheng Yong { \ 40587beb01f7SChao Yu return F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_##flagname); \ 4059cde4de12SJaegeuk Kim } 4060f424f664SJaegeuk Kim 4061ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(encrypt, ENCRYPT); 4062ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(blkzoned, BLKZONED); 4063ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR); 4064ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA); 4065ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM); 4066ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); 4067ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); 4068ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); 4069b7c409deSSheng Yong F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); 407095ae251fSEric Biggers F2FS_FEATURE_FUNCS(verity, VERITY); 4071d440c52dSJunling Zheng F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); 40725aba5430SDaniel Rosenberg F2FS_FEATURE_FUNCS(casefold, CASEFOLD); 40734c8ff709SChao Yu F2FS_FEATURE_FUNCS(compression, COMPRESSION); 40741c1d35dfSChao Yu 4075178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 407695175dafSDamien Le Moal static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, 407795175dafSDamien Le Moal block_t blkaddr) 4078178053e2SDamien Le Moal { 4079178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 4080178053e2SDamien Le Moal 408195175dafSDamien Le Moal return test_bit(zno, FDEV(devi).blkz_seq); 4082178053e2SDamien Le Moal } 4083178053e2SDamien Le Moal #endif 4084178053e2SDamien Le Moal 40857d20c8abSChao Yu static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi) 408696ba2decSDamien Le Moal { 40877beb01f7SChao Yu return f2fs_sb_has_blkzoned(sbi); 40887d20c8abSChao Yu } 408996ba2decSDamien Le Moal 40907f3d7719SDamien Le Moal static inline bool f2fs_bdev_support_discard(struct block_device *bdev) 40917f3d7719SDamien Le Moal { 40927f3d7719SDamien Le Moal return blk_queue_discard(bdev_get_queue(bdev)) || 40937f3d7719SDamien Le Moal bdev_is_zoned(bdev); 40947f3d7719SDamien Le Moal } 40957f3d7719SDamien Le Moal 40967d20c8abSChao Yu static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi) 40977d20c8abSChao Yu { 40987f3d7719SDamien Le Moal int i; 40997f3d7719SDamien Le Moal 41007f3d7719SDamien Le Moal if (!f2fs_is_multi_device(sbi)) 41017f3d7719SDamien Le Moal return f2fs_bdev_support_discard(sbi->sb->s_bdev); 41027f3d7719SDamien Le Moal 41037f3d7719SDamien Le Moal for (i = 0; i < sbi->s_ndevs; i++) 41047f3d7719SDamien Le Moal if (f2fs_bdev_support_discard(FDEV(i).bdev)) 41057f3d7719SDamien Le Moal return true; 41067f3d7719SDamien Le Moal return false; 41077d20c8abSChao Yu } 41087d20c8abSChao Yu 41097d20c8abSChao Yu static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) 41107d20c8abSChao Yu { 41117d20c8abSChao Yu return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) || 41127d20c8abSChao Yu f2fs_hw_should_discard(sbi); 411352763a4bSJaegeuk Kim } 411452763a4bSJaegeuk Kim 4115f824deb5SChao Yu static inline bool f2fs_hw_is_readonly(struct f2fs_sb_info *sbi) 4116f824deb5SChao Yu { 4117f824deb5SChao Yu int i; 4118f824deb5SChao Yu 4119f824deb5SChao Yu if (!f2fs_is_multi_device(sbi)) 4120f824deb5SChao Yu return bdev_read_only(sbi->sb->s_bdev); 4121f824deb5SChao Yu 4122f824deb5SChao Yu for (i = 0; i < sbi->s_ndevs; i++) 4123f824deb5SChao Yu if (bdev_read_only(FDEV(i).bdev)) 4124f824deb5SChao Yu return true; 4125f824deb5SChao Yu return false; 4126f824deb5SChao Yu } 4127f824deb5SChao Yu 4128b0332a0fSChao Yu static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi) 412952763a4bSJaegeuk Kim { 4130b0332a0fSChao Yu return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS; 413152763a4bSJaegeuk Kim } 413252763a4bSJaegeuk Kim 41334c8ff709SChao Yu static inline bool f2fs_may_compress(struct inode *inode) 41344c8ff709SChao Yu { 41354c8ff709SChao Yu if (IS_SWAPFILE(inode) || f2fs_is_pinned_file(inode) || 41364c8ff709SChao Yu f2fs_is_atomic_file(inode) || 41374c8ff709SChao Yu f2fs_is_volatile_file(inode)) 41384c8ff709SChao Yu return false; 41394c8ff709SChao Yu return S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode); 41404c8ff709SChao Yu } 41414c8ff709SChao Yu 41424c8ff709SChao Yu static inline void f2fs_i_compr_blocks_update(struct inode *inode, 41434c8ff709SChao Yu u64 blocks, bool add) 41444c8ff709SChao Yu { 41454c8ff709SChao Yu int diff = F2FS_I(inode)->i_cluster_size - blocks; 4146c2759ebaSDaeho Jeong struct f2fs_inode_info *fi = F2FS_I(inode); 41474c8ff709SChao Yu 4148ef8d563fSChao Yu /* don't update i_compr_blocks if saved blocks were released */ 4149c2759ebaSDaeho Jeong if (!add && !atomic_read(&fi->i_compr_blocks)) 4150ef8d563fSChao Yu return; 4151ef8d563fSChao Yu 41524c8ff709SChao Yu if (add) { 4153c2759ebaSDaeho Jeong atomic_add(diff, &fi->i_compr_blocks); 41544c8ff709SChao Yu stat_add_compr_blocks(inode, diff); 41554c8ff709SChao Yu } else { 4156c2759ebaSDaeho Jeong atomic_sub(diff, &fi->i_compr_blocks); 41574c8ff709SChao Yu stat_sub_compr_blocks(inode, diff); 41584c8ff709SChao Yu } 41594c8ff709SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 41604c8ff709SChao Yu } 41614c8ff709SChao Yu 4162f847c699SChao Yu static inline int block_unaligned_IO(struct inode *inode, 4163f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4164b91050a8SHyunchul Lee { 4165f847c699SChao Yu unsigned int i_blkbits = READ_ONCE(inode->i_blkbits); 4166f847c699SChao Yu unsigned int blocksize_mask = (1 << i_blkbits) - 1; 4167f847c699SChao Yu loff_t offset = iocb->ki_pos; 4168f847c699SChao Yu unsigned long align = offset | iov_iter_alignment(iter); 4169f847c699SChao Yu 4170f847c699SChao Yu return align & blocksize_mask; 4171f847c699SChao Yu } 4172f847c699SChao Yu 4173f847c699SChao Yu static inline int allow_outplace_dio(struct inode *inode, 4174f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4175f847c699SChao Yu { 4176f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4177f847c699SChao Yu int rw = iov_iter_rw(iter); 4178f847c699SChao Yu 4179b0332a0fSChao Yu return (f2fs_lfs_mode(sbi) && (rw == WRITE) && 4180f847c699SChao Yu !block_unaligned_IO(inode, iocb, iter)); 4181f847c699SChao Yu } 4182f847c699SChao Yu 4183f847c699SChao Yu static inline bool f2fs_force_buffered_io(struct inode *inode, 4184f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4185f847c699SChao Yu { 4186f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4187f847c699SChao Yu int rw = iov_iter_rw(iter); 4188f847c699SChao Yu 4189f847c699SChao Yu if (f2fs_post_read_required(inode)) 4190f847c699SChao Yu return true; 41910916878dSDamien Le Moal if (f2fs_is_multi_device(sbi)) 4192f847c699SChao Yu return true; 4193f847c699SChao Yu /* 4194f847c699SChao Yu * for blkzoned device, fallback direct IO to buffered IO, so 4195f847c699SChao Yu * all IOs can be serialized by log-structured write. 4196f847c699SChao Yu */ 41977beb01f7SChao Yu if (f2fs_sb_has_blkzoned(sbi)) 4198f847c699SChao Yu return true; 4199b0332a0fSChao Yu if (f2fs_lfs_mode(sbi) && (rw == WRITE)) { 42009720ee80SChao Yu if (block_unaligned_IO(inode, iocb, iter)) 4201f847c699SChao Yu return true; 42029720ee80SChao Yu if (F2FS_IO_ALIGNED(sbi)) 42039720ee80SChao Yu return true; 42049720ee80SChao Yu } 4205ebc29b62Shuangjianan@oppo.com if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED)) 42064354994fSDaniel Rosenberg return true; 42074354994fSDaniel Rosenberg 4208f847c699SChao Yu return false; 4209b91050a8SHyunchul Lee } 4210b91050a8SHyunchul Lee 42117f59b277SEric Biggers static inline bool f2fs_need_verity(const struct inode *inode, pgoff_t idx) 42127f59b277SEric Biggers { 42137f59b277SEric Biggers return fsverity_active(inode) && 42147f59b277SEric Biggers idx < DIV_ROUND_UP(inode->i_size, PAGE_SIZE); 42157f59b277SEric Biggers } 42167f59b277SEric Biggers 421783a3bfdbSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 4218d494500aSChao Yu extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, 4219d494500aSChao Yu unsigned int type); 422083a3bfdbSJaegeuk Kim #else 4221d494500aSChao Yu #define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) 422283a3bfdbSJaegeuk Kim #endif 422383a3bfdbSJaegeuk Kim 4224af033b2aSChao Yu static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) 4225af033b2aSChao Yu { 4226af033b2aSChao Yu #ifdef CONFIG_QUOTA 42277beb01f7SChao Yu if (f2fs_sb_has_quota_ino(sbi)) 4228af033b2aSChao Yu return true; 4229af033b2aSChao Yu if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || 4230af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || 4231af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) 4232af033b2aSChao Yu return true; 4233af033b2aSChao Yu #endif 4234af033b2aSChao Yu return false; 4235af033b2aSChao Yu } 42360af725fcSJaegeuk Kim 423710f966bbSChao Yu #define EFSBADCRC EBADMSG /* Bad CRC detected */ 423810f966bbSChao Yu #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 423910f966bbSChao Yu 4240e1074d4bSChao Yu #endif /* _LINUX_F2FS_H */ 4241