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, 46b96d9b3bSChao Yu FAULT_ALLOC_BIO, /* it's obsolete due to bio_alloc() will never fail */ 47cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 48cb78942bSJaegeuk Kim FAULT_ORPHAN, 49cb78942bSJaegeuk Kim FAULT_BLOCK, 50cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5153aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 5214b44d23SJaegeuk Kim FAULT_TRUNCATE, 536f5c2ed0SChao Yu FAULT_READ_IO, 540f348028SChao Yu FAULT_CHECKPOINT, 55b83dcfe6SChao Yu FAULT_DISCARD, 566f5c2ed0SChao Yu FAULT_WRITE_IO, 5732410577SChao Yu FAULT_SLAB_ALLOC, 5810a26878SChao Yu FAULT_DQUOT_INIT, 592c63feadSJaegeuk Kim FAULT_MAX, 602c63feadSJaegeuk Kim }; 612c63feadSJaegeuk Kim 627fa750a1SArnd Bergmann #ifdef CONFIG_F2FS_FAULT_INJECTION 63d494500aSChao Yu #define F2FS_ALL_FAULT_TYPE ((1 << FAULT_MAX) - 1) 64d494500aSChao Yu 6508796897SSheng Yong struct f2fs_fault_info { 6608796897SSheng Yong atomic_t inject_ops; 6708796897SSheng Yong unsigned int inject_rate; 6808796897SSheng Yong unsigned int inject_type; 6908796897SSheng Yong }; 7008796897SSheng Yong 7119880e6eSAlexey Dobriyan extern const char *f2fs_fault_name[FAULT_MAX]; 7268afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 732c63feadSJaegeuk Kim #endif 742c63feadSJaegeuk Kim 7539a53e0cSJaegeuk Kim /* 7639a53e0cSJaegeuk Kim * For mount options 7739a53e0cSJaegeuk Kim */ 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 8039a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 8139a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 8239a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 8339a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 84444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 851001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8634d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8734d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8834d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 89d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 9089672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 91343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 9273faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 930abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA 0x00080000 940abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA 0x00100000 955c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA 0x00200000 964b2414d0SChao Yu #define F2FS_MOUNT_QUOTA 0x00400000 976afc662eSChao Yu #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 987e65be49SJaegeuk Kim #define F2FS_MOUNT_RESERVE_ROOT 0x01000000 994354994fSDaniel Rosenberg #define F2FS_MOUNT_DISABLE_CHECKPOINT 0x02000000 100a9117ecaSChao Yu #define F2FS_MOUNT_NORECOVERY 0x04000000 101093749e2SChao Yu #define F2FS_MOUNT_ATGC 0x08000000 102261eeb9cSDaeho Jeong #define F2FS_MOUNT_MERGE_CHECKPOINT 0x10000000 1035911d2d1SChao Yu #define F2FS_MOUNT_GC_MERGE 0x20000000 1046ce19affSChao Yu #define F2FS_MOUNT_COMPRESS_CACHE 0x40000000 10539a53e0cSJaegeuk Kim 10663189b78SChao Yu #define F2FS_OPTION(sbi) ((sbi)->mount_opt) 10763189b78SChao Yu #define clear_opt(sbi, option) (F2FS_OPTION(sbi).opt &= ~F2FS_MOUNT_##option) 10863189b78SChao Yu #define set_opt(sbi, option) (F2FS_OPTION(sbi).opt |= F2FS_MOUNT_##option) 10963189b78SChao Yu #define test_opt(sbi, option) (F2FS_OPTION(sbi).opt & F2FS_MOUNT_##option) 11039a53e0cSJaegeuk Kim 11139a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 11239a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 11339a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 11439a53e0cSJaegeuk Kim 115a9841c4dSJaegeuk Kim typedef u32 block_t; /* 116a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 117a9841c4dSJaegeuk Kim * address format, __le32. 118a9841c4dSJaegeuk Kim */ 11939a53e0cSJaegeuk Kim typedef u32 nid_t; 12039a53e0cSJaegeuk Kim 1214c8ff709SChao Yu #define COMPRESS_EXT_NUM 16 1224c8ff709SChao Yu 12339a53e0cSJaegeuk Kim struct f2fs_mount_info { 12439a53e0cSJaegeuk Kim unsigned int opt; 12563189b78SChao Yu int write_io_size_bits; /* Write IO size bits */ 12663189b78SChao Yu block_t root_reserved_blocks; /* root reserved blocks */ 12763189b78SChao Yu kuid_t s_resuid; /* reserved blocks for uid */ 12863189b78SChao Yu kgid_t s_resgid; /* reserved blocks for gid */ 12963189b78SChao Yu int active_logs; /* # of active logs */ 13063189b78SChao Yu int inline_xattr_size; /* inline xattr size */ 13163189b78SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 13263189b78SChao Yu struct f2fs_fault_info fault_info; /* For fault injection */ 13363189b78SChao Yu #endif 13463189b78SChao Yu #ifdef CONFIG_QUOTA 13563189b78SChao Yu /* Names of quota files with journalled quota */ 13663189b78SChao Yu char *s_qf_names[MAXQUOTAS]; 13763189b78SChao Yu int s_jquota_fmt; /* Format of quota to use */ 13863189b78SChao Yu #endif 13963189b78SChao Yu /* For which write hints are passed down to block layer */ 14063189b78SChao Yu int whint_mode; 14163189b78SChao Yu int alloc_mode; /* segment allocation policy */ 14263189b78SChao Yu int fsync_mode; /* fsync policy */ 143b0332a0fSChao Yu int fs_mode; /* fs mode: LFS or ADAPTIVE */ 144bbbc34fdSChao Yu int bggc_mode; /* bggc mode: off, on or sync */ 1454f993264SChao Yu int discard_unit; /* 1464f993264SChao Yu * discard command's offset/size should 1474f993264SChao Yu * be aligned to this unit: block, 1484f993264SChao Yu * segment or section 1494f993264SChao Yu */ 150ac4acb1fSEric Biggers struct fscrypt_dummy_policy dummy_enc_policy; /* test dummy encryption */ 1511ae18f71SJaegeuk Kim block_t unusable_cap_perc; /* percentage for cap */ 1524d3aed70SDaniel Rosenberg block_t unusable_cap; /* Amount of space allowed to be 1534d3aed70SDaniel Rosenberg * unusable when disabling checkpoint 1544d3aed70SDaniel Rosenberg */ 1554c8ff709SChao Yu 1564c8ff709SChao Yu /* For compression */ 1574c8ff709SChao Yu unsigned char compress_algorithm; /* algorithm type */ 158b28f047bSChao Yu unsigned char compress_log_size; /* cluster log size */ 1593fde13f8SChao Yu unsigned char compress_level; /* compress level */ 160b28f047bSChao Yu bool compress_chksum; /* compressed data chksum */ 1614c8ff709SChao Yu unsigned char compress_ext_cnt; /* extension count */ 162151b1982SFengnan Chang unsigned char nocompress_ext_cnt; /* nocompress extension count */ 163602a16d5SDaeho Jeong int compress_mode; /* compression mode */ 1644c8ff709SChao Yu unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ 165151b1982SFengnan Chang unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /* extensions */ 16639a53e0cSJaegeuk Kim }; 16739a53e0cSJaegeuk Kim 168cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1690bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 170e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1717a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1725c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 173704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 1746afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 175234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO 0x0080 1761c1d35dfSChao Yu #define F2FS_FEATURE_INODE_CRTIME 0x0100 177b7c409deSSheng Yong #define F2FS_FEATURE_LOST_FOUND 0x0200 17895ae251fSEric Biggers #define F2FS_FEATURE_VERITY 0x0400 179d440c52dSJunling Zheng #define F2FS_FEATURE_SB_CHKSUM 0x0800 1805aba5430SDaniel Rosenberg #define F2FS_FEATURE_CASEFOLD 0x1000 1814c8ff709SChao Yu #define F2FS_FEATURE_COMPRESSION 0x2000 182a7d9fe3cSJaegeuk Kim #define F2FS_FEATURE_RO 0x4000 183cde4de12SJaegeuk Kim 1847beb01f7SChao Yu #define __F2FS_HAS_FEATURE(raw_super, mask) \ 1857beb01f7SChao Yu ((raw_super->feature & cpu_to_le32(mask)) != 0) 1867beb01f7SChao Yu #define F2FS_HAS_FEATURE(sbi, mask) __F2FS_HAS_FEATURE(sbi->raw_super, mask) 1877beb01f7SChao Yu #define F2FS_SET_FEATURE(sbi, mask) \ 1887beb01f7SChao Yu (sbi->raw_super->feature |= cpu_to_le32(mask)) 1897beb01f7SChao Yu #define F2FS_CLEAR_FEATURE(sbi, mask) \ 1907beb01f7SChao Yu (sbi->raw_super->feature &= ~cpu_to_le32(mask)) 19176f105a2SJaegeuk Kim 19239a53e0cSJaegeuk Kim /* 1937c2e5963SJaegeuk Kim * Default values for user and/or group using reserved blocks 1947c2e5963SJaegeuk Kim */ 1957c2e5963SJaegeuk Kim #define F2FS_DEF_RESUID 0 1967c2e5963SJaegeuk Kim #define F2FS_DEF_RESGID 0 1977c2e5963SJaegeuk Kim 1987c2e5963SJaegeuk Kim /* 19939a53e0cSJaegeuk Kim * For checkpoint manager 20039a53e0cSJaegeuk Kim */ 20139a53e0cSJaegeuk Kim enum { 20239a53e0cSJaegeuk Kim NAT_BITMAP, 20339a53e0cSJaegeuk Kim SIT_BITMAP 20439a53e0cSJaegeuk Kim }; 20539a53e0cSJaegeuk Kim 206c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 207c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 208c473f1a9SChao Yu #define CP_SYNC 0x00000004 209c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 210c473f1a9SChao Yu #define CP_DISCARD 0x00000010 2111f43e2adSChao Yu #define CP_TRIMMED 0x00000020 2124354994fSDaniel Rosenberg #define CP_PAUSE 0x00000040 213b4b10061SJaegeuk Kim #define CP_RESIZE 0x00000080 21475ab4cb8SJaegeuk Kim 2154ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 216ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 217969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 218f9d1dcedSYunlei He #define DEF_MID_DISCARD_ISSUE_TIME 500 /* 500 ms, if device busy */ 219969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 2208bb4f253SJaegeuk Kim #define DEF_DISCARD_URGENT_UTIL 80 /* do more discard over 80% */ 22160b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 222dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 2234354994fSDaniel Rosenberg #define DEF_DISABLE_INTERVAL 5 /* 5 secs */ 224db610a64SJaegeuk Kim #define DEF_DISABLE_QUICK_INTERVAL 1 /* 1 secs */ 22503f2c02dSJaegeuk Kim #define DEF_UMOUNT_DISCARD_TIMEOUT 5 /* 5 secs */ 226bba681cbSJaegeuk Kim 22775ab4cb8SJaegeuk Kim struct cp_control { 22875ab4cb8SJaegeuk Kim int reason; 2294b2fecc8SJaegeuk Kim __u64 trim_start; 2304b2fecc8SJaegeuk Kim __u64 trim_end; 2314b2fecc8SJaegeuk Kim __u64 trim_minlen; 23275ab4cb8SJaegeuk Kim }; 23375ab4cb8SJaegeuk Kim 234662befdaSChao Yu /* 235e1da7872SChao Yu * indicate meta/data type 236662befdaSChao Yu */ 237662befdaSChao Yu enum { 238662befdaSChao Yu META_CP, 239662befdaSChao Yu META_NAT, 24081c1a0f1SChao Yu META_SIT, 2414c521f49SJaegeuk Kim META_SSA, 242b63e7be5SChao Yu META_MAX, 2434c521f49SJaegeuk Kim META_POR, 24493770ab7SChao Yu DATA_GENERIC, /* check range only */ 24593770ab7SChao Yu DATA_GENERIC_ENHANCE, /* strong check on range and segment bitmap */ 24693770ab7SChao Yu DATA_GENERIC_ENHANCE_READ, /* 24793770ab7SChao Yu * strong check on range and segment 24893770ab7SChao Yu * bitmap but no warning due to race 24993770ab7SChao Yu * condition of read on truncated area 25093770ab7SChao Yu * by extent_cache 25193770ab7SChao Yu */ 252e1da7872SChao Yu META_GENERIC, 253662befdaSChao Yu }; 254662befdaSChao Yu 2556451e041SJaegeuk Kim /* for the list of ino */ 2566451e041SJaegeuk Kim enum { 2576451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 258fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 259fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 2600a007b97SJaegeuk Kim TRANS_DIR_INO, /* for trasactions dir ino list */ 26139d787beSChao Yu FLUSH_INO, /* for multiple device flushing */ 2626451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 2636451e041SJaegeuk Kim }; 2646451e041SJaegeuk Kim 2656451e041SJaegeuk Kim struct ino_entry { 26639a53e0cSJaegeuk Kim struct list_head list; /* list head */ 26739a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 26839d787beSChao Yu unsigned int dirty_device; /* dirty device bitmap */ 26939a53e0cSJaegeuk Kim }; 27039a53e0cSJaegeuk Kim 2712710fd7eSChao Yu /* for the list of inodes to be GCed */ 27206292073SChao Yu struct inode_entry { 27339a53e0cSJaegeuk Kim struct list_head list; /* list head */ 27439a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 27539a53e0cSJaegeuk Kim }; 27639a53e0cSJaegeuk Kim 27750fa53ecSChao Yu struct fsync_node_entry { 27850fa53ecSChao Yu struct list_head list; /* list head */ 27950fa53ecSChao Yu struct page *page; /* warm node page pointer */ 28050fa53ecSChao Yu unsigned int seq_id; /* sequence id */ 28150fa53ecSChao Yu }; 28250fa53ecSChao Yu 283261eeb9cSDaeho Jeong struct ckpt_req { 284261eeb9cSDaeho Jeong struct completion wait; /* completion for checkpoint done */ 285261eeb9cSDaeho Jeong struct llist_node llnode; /* llist_node to be linked in wait queue */ 286261eeb9cSDaeho Jeong int ret; /* return code of checkpoint */ 287261eeb9cSDaeho Jeong ktime_t queue_time; /* request queued time */ 288261eeb9cSDaeho Jeong }; 289261eeb9cSDaeho Jeong 290261eeb9cSDaeho Jeong struct ckpt_req_control { 291261eeb9cSDaeho Jeong struct task_struct *f2fs_issue_ckpt; /* checkpoint task */ 292e6592066SDaeho Jeong int ckpt_thread_ioprio; /* checkpoint merge thread ioprio */ 293261eeb9cSDaeho Jeong wait_queue_head_t ckpt_wait_queue; /* waiting queue for wake-up */ 294261eeb9cSDaeho Jeong atomic_t issued_ckpt; /* # of actually issued ckpts */ 295261eeb9cSDaeho Jeong atomic_t total_ckpt; /* # of total ckpts */ 296261eeb9cSDaeho Jeong atomic_t queued_ckpt; /* # of queued ckpts */ 297261eeb9cSDaeho Jeong struct llist_head issue_list; /* list for command issue */ 298261eeb9cSDaeho Jeong spinlock_t stat_lock; /* lock for below checkpoint time stats */ 299261eeb9cSDaeho Jeong unsigned int cur_time; /* cur wait time in msec for currently issued checkpoint */ 300261eeb9cSDaeho Jeong unsigned int peak_time; /* peak wait time in msec until now */ 301261eeb9cSDaeho Jeong }; 302261eeb9cSDaeho Jeong 303a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 3047fd9e544SJaegeuk Kim struct discard_entry { 3057fd9e544SJaegeuk Kim struct list_head list; /* list head */ 306a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 307a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 3087fd9e544SJaegeuk Kim }; 3097fd9e544SJaegeuk Kim 310969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 311969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 312969d1b18SChao Yu 313ba48a33eSChao Yu /* max discard pend list number */ 314ba48a33eSChao Yu #define MAX_PLIST_NUM 512 315ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 3162f84babfSSheng Yong (MAX_PLIST_NUM - 1) : ((blk_num) - 1)) 317ba48a33eSChao Yu 31815469963SJaegeuk Kim enum { 31935ec7d57SChao Yu D_PREP, /* initial */ 32035ec7d57SChao Yu D_PARTIAL, /* partially submitted */ 32135ec7d57SChao Yu D_SUBMIT, /* all submitted */ 32235ec7d57SChao Yu D_DONE, /* finished */ 32315469963SJaegeuk Kim }; 32415469963SJaegeuk Kim 325004b6862SChao Yu struct discard_info { 326b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 327b01a9201SJaegeuk Kim block_t len; /* length */ 328004b6862SChao Yu block_t start; /* actual start address in dev */ 329004b6862SChao Yu }; 330004b6862SChao Yu 331b01a9201SJaegeuk Kim struct discard_cmd { 332004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 333004b6862SChao Yu union { 334004b6862SChao Yu struct { 335004b6862SChao Yu block_t lstart; /* logical start address */ 336004b6862SChao Yu block_t len; /* length */ 337004b6862SChao Yu block_t start; /* actual start address in dev */ 338004b6862SChao Yu }; 339004b6862SChao Yu struct discard_info di; /* discard info */ 340004b6862SChao Yu 341004b6862SChao Yu }; 342b01a9201SJaegeuk Kim struct list_head list; /* command list */ 343b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 344c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 345ec9895adSChao Yu unsigned short ref; /* reference count */ 3469a744b92SChao Yu unsigned char state; /* state */ 34772691af6SJaegeuk Kim unsigned char queued; /* queued discard */ 348c81abe34SJaegeuk Kim int error; /* bio error */ 34935ec7d57SChao Yu spinlock_t lock; /* for state/bio_ref updating */ 35035ec7d57SChao Yu unsigned short bio_ref; /* bio reference count */ 351275b66b0SChao Yu }; 352275b66b0SChao Yu 35378997b56SChao Yu enum { 35478997b56SChao Yu DPOLICY_BG, 35578997b56SChao Yu DPOLICY_FORCE, 35678997b56SChao Yu DPOLICY_FSTRIM, 35778997b56SChao Yu DPOLICY_UMOUNT, 35878997b56SChao Yu MAX_DPOLICY, 35978997b56SChao Yu }; 36078997b56SChao Yu 361ecc9aa00SChao Yu struct discard_policy { 36278997b56SChao Yu int type; /* type of discard */ 363ecc9aa00SChao Yu unsigned int min_interval; /* used for candidates exist */ 364f9d1dcedSYunlei He unsigned int mid_interval; /* used for device busy */ 365ecc9aa00SChao Yu unsigned int max_interval; /* used for candidates not exist */ 366ecc9aa00SChao Yu unsigned int max_requests; /* # of discards issued per round */ 367ecc9aa00SChao Yu unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ 368ecc9aa00SChao Yu bool io_aware; /* issue discard in idle time */ 369ecc9aa00SChao Yu bool sync; /* submit discard with REQ_SYNC flag */ 37020ee4382SChao Yu bool ordered; /* issue discard by lba order */ 3716ce48b0cSChao Yu bool timeout; /* discard timeout for put_super */ 37278997b56SChao Yu unsigned int granularity; /* discard granularity */ 373ecc9aa00SChao Yu }; 374ecc9aa00SChao Yu 3750b54fb84SJaegeuk Kim struct discard_cmd_control { 37615469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 37746f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 378ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 37946f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 3808412663dSChao Yu struct list_head fstrim_list; /* in-flight discard from fstrim */ 38115469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 382969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 38315469963SJaegeuk Kim struct mutex cmd_lock; 384d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 385d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 386969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 387d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 38820ee4382SChao Yu unsigned int next_pos; /* next discard position */ 3898b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 39072691af6SJaegeuk Kim atomic_t queued_discard; /* # of queued discard */ 3915f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 3924dada3fdSChao Yu struct rb_root_cached root; /* root of discard rb-tree */ 39367fce70bSChao Yu bool rbtree_check; /* config for consistence check */ 39439a53e0cSJaegeuk Kim }; 39539a53e0cSJaegeuk Kim 39639a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 39739a53e0cSJaegeuk Kim struct fsync_inode_entry { 39839a53e0cSJaegeuk Kim struct list_head list; /* list head */ 39939a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 400c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 401c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 40239a53e0cSJaegeuk Kim }; 40339a53e0cSJaegeuk Kim 40468afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 40568afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 40639a53e0cSJaegeuk Kim 40768afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 40868afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 40968afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 41068afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 41139a53e0cSJaegeuk Kim 412dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 413dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 414309cc2b6SJaegeuk Kim 415dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 41639a53e0cSJaegeuk Kim { 417dfc08a12SChao Yu int before = nats_in_cursum(journal); 418cac5a3d8SDongOh Shin 419dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 42039a53e0cSJaegeuk Kim return before; 42139a53e0cSJaegeuk Kim } 42239a53e0cSJaegeuk Kim 423dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 42439a53e0cSJaegeuk Kim { 425dfc08a12SChao Yu int before = sits_in_cursum(journal); 426cac5a3d8SDongOh Shin 427dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 42839a53e0cSJaegeuk Kim return before; 42939a53e0cSJaegeuk Kim } 43039a53e0cSJaegeuk Kim 431dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 432dfc08a12SChao Yu int size, int type) 433184a5cd2SChao Yu { 434184a5cd2SChao Yu if (type == NAT_JOURNAL) 435dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 436dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 437184a5cd2SChao Yu } 438184a5cd2SChao Yu 439f2470371SChao Yu /* for inline stuff */ 440f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 4417a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 4426afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode); 4437a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 4447a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 445b323fd28SChao Yu get_inline_xattr_addrs(inode) - \ 4466afc662eSChao Yu DEF_INLINE_RESERVED_SIZE)) 447f2470371SChao Yu 448f2470371SChao Yu /* for inline dir */ 449f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 450f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 451f2470371SChao Yu BITS_PER_BYTE + 1)) 452f91108b8SGeert Uytterhoeven #define INLINE_DENTRY_BITMAP_SIZE(inode) \ 453f91108b8SGeert Uytterhoeven DIV_ROUND_UP(NR_INLINE_DENTRY(inode), BITS_PER_BYTE) 454f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 455f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 456f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 457f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 458f2470371SChao Yu 459e9750824SNamjae Jeon /* 46039a53e0cSJaegeuk Kim * For INODE and NODE manager 46139a53e0cSJaegeuk Kim */ 4627b3cd7d6SJaegeuk Kim /* for directory operations */ 46343c780baSEric Biggers 46443c780baSEric Biggers struct f2fs_filename { 46543c780baSEric Biggers /* 46643c780baSEric Biggers * The filename the user specified. This is NULL for some 46743c780baSEric Biggers * filesystem-internal operations, e.g. converting an inline directory 46843c780baSEric Biggers * to a non-inline one, or roll-forward recovering an encrypted dentry. 46943c780baSEric Biggers */ 47043c780baSEric Biggers const struct qstr *usr_fname; 47143c780baSEric Biggers 47243c780baSEric Biggers /* 47343c780baSEric Biggers * The on-disk filename. For encrypted directories, this is encrypted. 47443c780baSEric Biggers * This may be NULL for lookups in an encrypted dir without the key. 47543c780baSEric Biggers */ 47643c780baSEric Biggers struct fscrypt_str disk_name; 47743c780baSEric Biggers 47843c780baSEric Biggers /* The dirhash of this filename */ 47943c780baSEric Biggers f2fs_hash_t hash; 48043c780baSEric Biggers 48143c780baSEric Biggers #ifdef CONFIG_FS_ENCRYPTION 48243c780baSEric Biggers /* 48343c780baSEric Biggers * For lookups in encrypted directories: either the buffer backing 48443c780baSEric Biggers * disk_name, or a buffer that holds the decoded no-key name. 48543c780baSEric Biggers */ 48643c780baSEric Biggers struct fscrypt_str crypto_buf; 48743c780baSEric Biggers #endif 48843c780baSEric Biggers #ifdef CONFIG_UNICODE 48943c780baSEric Biggers /* 49043c780baSEric Biggers * For casefolded directories: the casefolded name, but it's left NULL 4917ad08a58SDaniel Rosenberg * if the original name is not valid Unicode, if the directory is both 4927ad08a58SDaniel Rosenberg * casefolded and encrypted and its encryption key is unavailable, or if 4937ad08a58SDaniel Rosenberg * the filesystem is doing an internal operation where usr_fname is also 4947ad08a58SDaniel Rosenberg * NULL. In all these cases we fall back to treating the name as an 4957ad08a58SDaniel Rosenberg * opaque byte sequence. 49643c780baSEric Biggers */ 49743c780baSEric Biggers struct fscrypt_str cf_name; 49843c780baSEric Biggers #endif 49943c780baSEric Biggers }; 50043c780baSEric Biggers 5017b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 502d8c6822aSJaegeuk Kim struct inode *inode; 50376a9dd85SChao Yu void *bitmap; 5047b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 5057b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 5067b3cd7d6SJaegeuk Kim int max; 50776a9dd85SChao Yu int nr_bitmap; 5087b3cd7d6SJaegeuk Kim }; 5097b3cd7d6SJaegeuk Kim 51064c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 51164c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 5127b3cd7d6SJaegeuk Kim { 513d8c6822aSJaegeuk Kim d->inode = inode; 5147b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 51576a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 516c79d1520SYunlong Song d->bitmap = t->dentry_bitmap; 5177b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 5187b3cd7d6SJaegeuk Kim d->filename = t->filename; 51964c24ecbSTomohiro Kusumi } 520cac5a3d8SDongOh Shin 52164c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 522f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 52364c24ecbSTomohiro Kusumi { 524f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 525f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 526f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 527f2470371SChao Yu 52864c24ecbSTomohiro Kusumi d->inode = inode; 529f2470371SChao Yu d->max = entry_cnt; 530f2470371SChao Yu d->nr_bitmap = bitmap_size; 531f2470371SChao Yu d->bitmap = t; 532f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 533f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 534f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 5357b3cd7d6SJaegeuk Kim } 5367b3cd7d6SJaegeuk Kim 537dbe6a5ffSJaegeuk Kim /* 538dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 539dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 540dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 54139a53e0cSJaegeuk Kim */ 542dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 543dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 544266e97a8SJaegeuk Kim enum { 545266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 546266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 547266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 548266e97a8SJaegeuk Kim * look up a node with readahead called 5494f4124d0SChao Yu * by get_data_block. 55039a53e0cSJaegeuk Kim */ 551266e97a8SJaegeuk Kim }; 552266e97a8SJaegeuk Kim 55391803392SChao Yu #define DEFAULT_RETRY_IO_COUNT 8 /* maximum retry read IO or flush count */ 5547735730dSChao Yu 5555df7731fSChao Yu /* congestion wait timeout value, default: 20ms */ 5565df7731fSChao Yu #define DEFAULT_IO_TIMEOUT (msecs_to_jiffies(20)) 5575df7731fSChao Yu 558af033b2aSChao Yu /* maximum retry quota flush count */ 559af033b2aSChao Yu #define DEFAULT_RETRY_QUOTA_FLUSH_COUNT 8 560af033b2aSChao Yu 561a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 56239a53e0cSJaegeuk Kim 563817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 564817202d9SChao Yu 565287b1406SChao Yu /* dirty segments threshold for triggering CP */ 566287b1406SChao Yu #define DEFAULT_DIRTY_THRESHOLD 4 567287b1406SChao Yu 56839a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 56913054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 57013054c54SChao Yu 57113054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 57213054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 573c11abd1aSJaegeuk Kim 57454c2258cSChao Yu struct rb_entry { 57554c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 5762e9b2bb2SChao Yu union { 5772e9b2bb2SChao Yu struct { 57854c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 57954c2258cSChao Yu unsigned int len; /* length of the entry */ 58054c2258cSChao Yu }; 5812e9b2bb2SChao Yu unsigned long long key; /* 64-bits key */ 58248046cb5SJaegeuk Kim } __packed; 5832e9b2bb2SChao Yu }; 58454c2258cSChao Yu 58539a53e0cSJaegeuk Kim struct extent_info { 58639a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 587111d2495SMasanari Iida unsigned int len; /* length of the extent */ 58854c2258cSChao Yu u32 blk; /* start block address of the extent */ 58994afd6d6SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 59094afd6d6SChao Yu unsigned int c_len; /* physical extent length of compressed blocks */ 59194afd6d6SChao Yu #endif 59239a53e0cSJaegeuk Kim }; 59339a53e0cSJaegeuk Kim 59413054c54SChao Yu struct extent_node { 595c0362117SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 59613054c54SChao Yu struct extent_info ei; /* extent info */ 59754c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 598201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 59913054c54SChao Yu }; 60013054c54SChao Yu 60113054c54SChao Yu struct extent_tree { 60213054c54SChao Yu nid_t ino; /* inode number */ 6034dada3fdSChao Yu struct rb_root_cached root; /* root of extent info rb-tree */ 60462c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 6053e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 606137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 60713054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 60868e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 609b430f726SZhikang Zhang bool largest_updated; /* largest extent updated */ 61013054c54SChao Yu }; 61113054c54SChao Yu 61239a53e0cSJaegeuk Kim /* 613003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 614003a3e1dSJaegeuk Kim * 615003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 616003a3e1dSJaegeuk Kim */ 617003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 618003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 6197f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 6207f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 6217f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 622003a3e1dSJaegeuk Kim 623003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 62471f2c820SChao Yu struct block_device *m_bdev; /* for multi-device dio */ 625003a3e1dSJaegeuk Kim block_t m_pblk; 626003a3e1dSJaegeuk Kim block_t m_lblk; 627003a3e1dSJaegeuk Kim unsigned int m_len; 628003a3e1dSJaegeuk Kim unsigned int m_flags; 629da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 630c4020b2dSChao Yu pgoff_t *m_next_extent; /* point to next possible extent */ 631d5097be5SHyunchul Lee int m_seg_type; 632f9d6d059SChao Yu bool m_may_create; /* indicate it is from write path */ 63371f2c820SChao Yu bool m_multidev_dio; /* indicate it allows multi-device dio */ 634003a3e1dSJaegeuk Kim }; 635003a3e1dSJaegeuk Kim 636e2b4e2bcSChao Yu /* for flag in get_data_block */ 637f2220c7fSQiuyang Sun enum { 638f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 639f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 640f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 6410a4daae5SJaegeuk Kim F2FS_GET_BLOCK_DIO, 642f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 643f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 644c4020b2dSChao Yu F2FS_GET_BLOCK_PRECACHE, 645f2220c7fSQiuyang Sun }; 646e2b4e2bcSChao Yu 647003a3e1dSJaegeuk Kim /* 64839a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 64939a53e0cSJaegeuk Kim */ 65039a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 651354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 652cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 653e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 65426787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 655b6a06cbbSChao Yu #define FADVISE_HOT_BIT 0x20 65695ae251fSEric Biggers #define FADVISE_VERITY_BIT 0x40 657d4dd19ecSJaegeuk Kim #define FADVISE_TRUNC_BIT 0x80 65839a53e0cSJaegeuk Kim 659797c1cb5SChao Yu #define FADVISE_MODIFIABLE_BITS (FADVISE_COLD_BIT | FADVISE_HOT_BIT) 660797c1cb5SChao Yu 661b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 662b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 663b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 6641153db09SChao Yu 6651153db09SChao Yu #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 6661153db09SChao Yu #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 667b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 6681153db09SChao Yu 669cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 670cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 6711153db09SChao Yu 672e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 673e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 6741153db09SChao Yu 67526787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 67626787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 6771153db09SChao Yu 678b6a06cbbSChao Yu #define file_is_hot(inode) is_file(inode, FADVISE_HOT_BIT) 679b6a06cbbSChao Yu #define file_set_hot(inode) set_file(inode, FADVISE_HOT_BIT) 680b6a06cbbSChao Yu #define file_clear_hot(inode) clear_file(inode, FADVISE_HOT_BIT) 6811153db09SChao Yu 68295ae251fSEric Biggers #define file_is_verity(inode) is_file(inode, FADVISE_VERITY_BIT) 68395ae251fSEric Biggers #define file_set_verity(inode) set_file(inode, FADVISE_VERITY_BIT) 684cde4de12SJaegeuk Kim 685d4dd19ecSJaegeuk Kim #define file_should_truncate(inode) is_file(inode, FADVISE_TRUNC_BIT) 686d4dd19ecSJaegeuk Kim #define file_need_truncate(inode) set_file(inode, FADVISE_TRUNC_BIT) 687d4dd19ecSJaegeuk Kim #define file_dont_truncate(inode) clear_file(inode, FADVISE_TRUNC_BIT) 688d4dd19ecSJaegeuk Kim 689ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 690ab9fa662SJaegeuk Kim 6912ef79ecbSChao Yu enum { 6922ef79ecbSChao Yu GC_FAILURE_PIN, 6932ef79ecbSChao Yu GC_FAILURE_ATOMIC, 6942ef79ecbSChao Yu MAX_GC_FAILURE 6952ef79ecbSChao Yu }; 6962ef79ecbSChao Yu 6977653b9d8SChao Yu /* used for f2fs_inode_info->flags */ 6987653b9d8SChao Yu enum { 6997653b9d8SChao Yu FI_NEW_INODE, /* indicate newly allocated inode */ 7007653b9d8SChao Yu FI_DIRTY_INODE, /* indicate inode is dirty or not */ 7017653b9d8SChao Yu FI_AUTO_RECOVER, /* indicate inode is recoverable */ 7027653b9d8SChao Yu FI_DIRTY_DIR, /* indicate directory has dirty pages */ 7037653b9d8SChao Yu FI_INC_LINK, /* need to increment i_nlink */ 7047653b9d8SChao Yu FI_ACL_MODE, /* indicate acl mode */ 7057653b9d8SChao Yu FI_NO_ALLOC, /* should not allocate any blocks */ 7067653b9d8SChao Yu FI_FREE_NID, /* free allocated nide */ 7077653b9d8SChao Yu FI_NO_EXTENT, /* not to use the extent cache */ 7087653b9d8SChao Yu FI_INLINE_XATTR, /* used for inline xattr */ 7097653b9d8SChao Yu FI_INLINE_DATA, /* used for inline data*/ 7107653b9d8SChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 7117653b9d8SChao Yu FI_APPEND_WRITE, /* inode has appended data */ 7127653b9d8SChao Yu FI_UPDATE_WRITE, /* inode has in-place-update data */ 7137653b9d8SChao Yu FI_NEED_IPU, /* used for ipu per file */ 7147653b9d8SChao Yu FI_ATOMIC_FILE, /* indicate atomic file */ 7157653b9d8SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 7167653b9d8SChao Yu FI_VOLATILE_FILE, /* indicate volatile file */ 7177653b9d8SChao Yu FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 7187653b9d8SChao Yu FI_DROP_CACHE, /* drop dirty page cache */ 7197653b9d8SChao Yu FI_DATA_EXIST, /* indicate data exists */ 7207653b9d8SChao Yu FI_INLINE_DOTS, /* indicate inline dot dentries */ 7217653b9d8SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 7227653b9d8SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 7233d697a4aSEric Biggers FI_PREALLOCATED_ALL, /* all blocks for write were preallocated */ 7247653b9d8SChao Yu FI_HOT_DATA, /* indicate file is hot */ 7257653b9d8SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 7267653b9d8SChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 7277653b9d8SChao Yu FI_PIN_FILE, /* indicate file should not be gced */ 7287653b9d8SChao Yu FI_ATOMIC_REVOKE_REQUEST, /* request to drop atomic data */ 7297653b9d8SChao Yu FI_VERITY_IN_PROGRESS, /* building fs-verity Merkle tree */ 7307653b9d8SChao Yu FI_COMPRESSED_FILE, /* indicate file's data can be compressed */ 731b28f047bSChao Yu FI_COMPRESS_CORRUPT, /* indicate compressed cluster is corrupted */ 7327653b9d8SChao Yu FI_MMAP_FILE, /* indicate file was mmapped */ 733602a16d5SDaeho Jeong FI_ENABLE_COMPRESS, /* enable compression in "user" compression mode */ 734c6140415SJaegeuk Kim FI_COMPRESS_RELEASED, /* compressed blocks were released */ 735859fca6bSChao Yu FI_ALIGNED_WRITE, /* enable aligned write */ 7367653b9d8SChao Yu FI_MAX, /* max flag, never be used */ 7377653b9d8SChao Yu }; 7387653b9d8SChao Yu 73939a53e0cSJaegeuk Kim struct f2fs_inode_info { 74039a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 74139a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 74239a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 74338431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 7441ad71a27SJaegeuk Kim unsigned int i_current_depth; /* only for directory depth */ 7452ef79ecbSChao Yu /* for gc failure statistic */ 7462ef79ecbSChao Yu unsigned int i_gc_failures[MAX_GC_FAILURE]; 7476666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 74839a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 74939a53e0cSJaegeuk Kim 75039a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 7517653b9d8SChao Yu unsigned long flags[BITS_TO_LONGS(FI_MAX)]; /* use to pass per-file flags */ 752d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 753204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 75439a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 75539a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 75688c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 757b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 75839a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 75926de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 760c10c9820SChao Yu spinlock_t i_size_lock; /* protect last_disk_size */ 76188b88a66SJaegeuk Kim 7620abd675eSChao Yu #ifdef CONFIG_QUOTA 7630abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 7640abd675eSChao Yu 7650abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 7660abd675eSChao Yu qsize_t i_reserved_quota; 7670abd675eSChao Yu #endif 7680f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 7690f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 77057864ae5SJaegeuk Kim struct list_head inmem_ilist; /* list for inmem inodes */ 77188b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 7727a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 77388b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 7743e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 775b2532c69SChao Yu 776b2532c69SChao Yu /* avoid racing between foreground op and gc */ 777b2532c69SChao Yu struct rw_semaphore i_gc_rwsem[2]; 77827161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 779f2470371SChao Yu 7807a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 7815c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 7826afc662eSChao Yu int i_inline_xattr_size; /* inline xattr size */ 78324b81dfcSArnd Bergmann struct timespec64 i_crtime; /* inode creation time */ 78424b81dfcSArnd Bergmann struct timespec64 i_disk_time[4];/* inode disk times */ 7854c8ff709SChao Yu 7864c8ff709SChao Yu /* for file compress */ 787c2759ebaSDaeho Jeong atomic_t i_compr_blocks; /* # of compressed blocks */ 7884c8ff709SChao Yu unsigned char i_compress_algorithm; /* algorithm type */ 7894c8ff709SChao Yu unsigned char i_log_cluster_size; /* log of cluster size */ 7903fde13f8SChao Yu unsigned char i_compress_level; /* compress level (lz4hc,zstd) */ 791b28f047bSChao Yu unsigned short i_compress_flag; /* compress flag */ 7924c8ff709SChao Yu unsigned int i_cluster_size; /* cluster size */ 79339a53e0cSJaegeuk Kim }; 79439a53e0cSJaegeuk Kim 79539a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 796bd933d4fSChao Yu struct f2fs_extent *i_ext) 79739a53e0cSJaegeuk Kim { 798bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 799bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 800bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 80139a53e0cSJaegeuk Kim } 80239a53e0cSJaegeuk Kim 80339a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 80439a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 80539a53e0cSJaegeuk Kim { 80639a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 8074d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 80839a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 80939a53e0cSJaegeuk Kim } 81039a53e0cSJaegeuk Kim 811429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 812429511cdSChao Yu u32 blk, unsigned int len) 813429511cdSChao Yu { 814429511cdSChao Yu ei->fofs = fofs; 815429511cdSChao Yu ei->blk = blk; 816429511cdSChao Yu ei->len = len; 81794afd6d6SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 81894afd6d6SChao Yu ei->c_len = 0; 81994afd6d6SChao Yu #endif 820429511cdSChao Yu } 821429511cdSChao Yu 822004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 82335ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 824004b6862SChao Yu { 8259a997188SJaegeuk Kim return (back->lstart + back->len == front->lstart) && 82635ec7d57SChao Yu (back->len + front->len <= max_len); 827004b6862SChao Yu } 828004b6862SChao Yu 829004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 83035ec7d57SChao Yu struct discard_info *back, unsigned int max_len) 831004b6862SChao Yu { 83235ec7d57SChao Yu return __is_discard_mergeable(back, cur, max_len); 833004b6862SChao Yu } 834004b6862SChao Yu 835004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 83635ec7d57SChao Yu struct discard_info *front, unsigned int max_len) 837004b6862SChao Yu { 83835ec7d57SChao Yu return __is_discard_mergeable(cur, front, max_len); 839004b6862SChao Yu } 840004b6862SChao Yu 841429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 842429511cdSChao Yu struct extent_info *front) 843429511cdSChao Yu { 84494afd6d6SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 84594afd6d6SChao Yu if (back->c_len && back->len != back->c_len) 84694afd6d6SChao Yu return false; 84794afd6d6SChao Yu if (front->c_len && front->len != front->c_len) 84894afd6d6SChao Yu return false; 84994afd6d6SChao Yu #endif 850429511cdSChao Yu return (back->fofs + back->len == front->fofs && 851429511cdSChao Yu back->blk + back->len == front->blk); 852429511cdSChao Yu } 853429511cdSChao Yu 854429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 855429511cdSChao Yu struct extent_info *back) 856429511cdSChao Yu { 857429511cdSChao Yu return __is_extent_mergeable(back, cur); 858429511cdSChao Yu } 859429511cdSChao Yu 860429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 861429511cdSChao Yu struct extent_info *front) 862429511cdSChao Yu { 863429511cdSChao Yu return __is_extent_mergeable(cur, front); 864429511cdSChao Yu } 865429511cdSChao Yu 866cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 867b430f726SZhikang Zhang static inline void __try_update_largest_extent(struct extent_tree *et, 868b430f726SZhikang Zhang struct extent_node *en) 8694abd3f5aSChao Yu { 870205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 8714abd3f5aSChao Yu et->largest = en->ei; 872b430f726SZhikang Zhang et->largest_updated = true; 873205b9822SJaegeuk Kim } 8744abd3f5aSChao Yu } 8754abd3f5aSChao Yu 8769a4ffdf5SChao Yu /* 8779a4ffdf5SChao Yu * For free nid management 8789a4ffdf5SChao Yu */ 8799a4ffdf5SChao Yu enum nid_state { 8809a4ffdf5SChao Yu FREE_NID, /* newly added to free nid list */ 8819a4ffdf5SChao Yu PREALLOC_NID, /* it is preallocated */ 8829a4ffdf5SChao Yu MAX_NID_STATE, 883b8559dc2SChao Yu }; 884b8559dc2SChao Yu 885a95ba66aSJaegeuk Kim enum nat_state { 886a95ba66aSJaegeuk Kim TOTAL_NAT, 887a95ba66aSJaegeuk Kim DIRTY_NAT, 888a95ba66aSJaegeuk Kim RECLAIMABLE_NAT, 889a95ba66aSJaegeuk Kim MAX_NAT_STATE, 890a95ba66aSJaegeuk Kim }; 891a95ba66aSJaegeuk Kim 89239a53e0cSJaegeuk Kim struct f2fs_nm_info { 89339a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 89439a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 89504d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 89639a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 897cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 898ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 8992304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 90039a53e0cSJaegeuk Kim 90139a53e0cSJaegeuk Kim /* NAT cache management */ 90239a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 903309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 904f3e367d4Sqiulaibin struct rw_semaphore nat_tree_lock; /* protect nat entry tree */ 90539a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 90622969158SChao Yu spinlock_t nat_list_lock; /* protect clean nat entry list */ 907a95ba66aSJaegeuk Kim unsigned int nat_cnt[MAX_NAT_STATE]; /* the # of cached nat entries */ 90822ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 90939a53e0cSJaegeuk Kim 91039a53e0cSJaegeuk Kim /* free node ids management */ 9118a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 9129a4ffdf5SChao Yu struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ 9139a4ffdf5SChao Yu unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 914b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 91539a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 916bb1105e4SJaegeuk Kim unsigned char **free_nid_bitmap; 9174ac91242SChao Yu unsigned char *nat_block_bitmap; 918586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 91939a53e0cSJaegeuk Kim 92039a53e0cSJaegeuk Kim /* for checkpoint */ 92139a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 92222ad0b6aSJaegeuk Kim 92322ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 92422ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 92522ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 92622ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 927599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 928599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 929599a09b2SChao Yu #endif 93039a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 93139a53e0cSJaegeuk Kim }; 93239a53e0cSJaegeuk Kim 93339a53e0cSJaegeuk Kim /* 93439a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 93539a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 93639a53e0cSJaegeuk Kim * by the data offset in a file. 93739a53e0cSJaegeuk Kim */ 93839a53e0cSJaegeuk Kim struct dnode_of_data { 93939a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 94039a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 94139a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 94239a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 94339a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 94439a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 94593bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 9463cf45747SChao Yu char cur_level; /* level of hole node page */ 9473cf45747SChao Yu char max_level; /* level of current page located */ 94839a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 94939a53e0cSJaegeuk Kim }; 95039a53e0cSJaegeuk Kim 95139a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 95239a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 95339a53e0cSJaegeuk Kim { 954d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 95539a53e0cSJaegeuk Kim dn->inode = inode; 95639a53e0cSJaegeuk Kim dn->inode_page = ipage; 95739a53e0cSJaegeuk Kim dn->node_page = npage; 95839a53e0cSJaegeuk Kim dn->nid = nid; 95939a53e0cSJaegeuk Kim } 96039a53e0cSJaegeuk Kim 96139a53e0cSJaegeuk Kim /* 96239a53e0cSJaegeuk Kim * For SIT manager 96339a53e0cSJaegeuk Kim * 96439a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 96539a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 96639a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 96739a53e0cSJaegeuk Kim * respectively. 96839a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 96939a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 97039a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 97139a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 97239a53e0cSJaegeuk Kim * data and 8 for node logs. 97339a53e0cSJaegeuk Kim */ 97439a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 97539a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 976093749e2SChao Yu #define NR_CURSEG_INMEM_TYPE (2) 977a7d9fe3cSJaegeuk Kim #define NR_CURSEG_RO_TYPE (2) 978d0b9e42aSChao Yu #define NR_CURSEG_PERSIST_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 979d0b9e42aSChao Yu #define NR_CURSEG_TYPE (NR_CURSEG_INMEM_TYPE + NR_CURSEG_PERSIST_TYPE) 98039a53e0cSJaegeuk Kim 98139a53e0cSJaegeuk Kim enum { 98239a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 98339a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 98439a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 98539a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 98639a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 98739a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 988d0b9e42aSChao Yu NR_PERSISTENT_LOG, /* number of persistent log */ 989d0b9e42aSChao Yu CURSEG_COLD_DATA_PINNED = NR_PERSISTENT_LOG, 990d0b9e42aSChao Yu /* pinned file that needs consecutive block address */ 991093749e2SChao Yu CURSEG_ALL_DATA_ATGC, /* SSR alloctor in hot/warm/cold data area */ 992d0b9e42aSChao Yu NO_CHECK_TYPE, /* number of persistent & inmem log */ 99339a53e0cSJaegeuk Kim }; 99439a53e0cSJaegeuk Kim 9956b4afdd7SJaegeuk Kim struct flush_cmd { 9966b4afdd7SJaegeuk Kim struct completion wait; 997721bd4d5SGu Zheng struct llist_node llnode; 99839d787beSChao Yu nid_t ino; 9996b4afdd7SJaegeuk Kim int ret; 10006b4afdd7SJaegeuk Kim }; 10016b4afdd7SJaegeuk Kim 1002a688b9d9SGu Zheng struct flush_cmd_control { 1003a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 1004a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 10058b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 100672691af6SJaegeuk Kim atomic_t queued_flush; /* # of queued flushes */ 1007721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 1008721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 1009a688b9d9SGu Zheng }; 1010a688b9d9SGu Zheng 101139a53e0cSJaegeuk Kim struct f2fs_sm_info { 101239a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 101339a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 101439a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 101539a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 101639a53e0cSJaegeuk Kim 10172b60311dSChao Yu struct rw_semaphore curseg_lock; /* for preventing curseg change */ 10182b60311dSChao Yu 101939a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 102039a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 102139a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 102239a53e0cSJaegeuk Kim 102339a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 102439a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 102539a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 102639a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 102781eb8d6eSJaegeuk Kim 102881eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 102981eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 10307fd9e544SJaegeuk Kim 1031bba681cbSJaegeuk Kim /* for batched trimming */ 1032bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 1033bba681cbSJaegeuk Kim 1034184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 1035184a5cd2SChao Yu 1036216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 1037216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 1038c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 1039853137ceSJaegeuk Kim unsigned int min_seq_blocks; /* threshold for sequential blocks */ 1040ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 1041a2a12b67SChao Yu unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ 10426b4afdd7SJaegeuk Kim 10436b4afdd7SJaegeuk Kim /* for flush command control */ 1044b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 1045a688b9d9SGu Zheng 10460b54fb84SJaegeuk Kim /* for discard command control */ 10470b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 104839a53e0cSJaegeuk Kim }; 104939a53e0cSJaegeuk Kim 105039a53e0cSJaegeuk Kim /* 105139a53e0cSJaegeuk Kim * For superblock 105239a53e0cSJaegeuk Kim */ 105339a53e0cSJaegeuk Kim /* 105439a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 105539a53e0cSJaegeuk Kim * 105639a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 105739a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 105839a53e0cSJaegeuk Kim */ 105936951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 106039a53e0cSJaegeuk Kim enum count_type { 106139a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 1062c227f912SChao Yu F2FS_DIRTY_DATA, 10632c8a4a28SJaegeuk Kim F2FS_DIRTY_QDATA, 106439a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 106539a53e0cSJaegeuk Kim F2FS_DIRTY_META, 10668dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 10670f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 106836951b38SChao Yu F2FS_WB_CP_DATA, 106936951b38SChao Yu F2FS_WB_DATA, 10705f9abab4SJaegeuk Kim F2FS_RD_DATA, 10715f9abab4SJaegeuk Kim F2FS_RD_NODE, 10725f9abab4SJaegeuk Kim F2FS_RD_META, 107302b16d0aSChao Yu F2FS_DIO_WRITE, 107402b16d0aSChao Yu F2FS_DIO_READ, 107539a53e0cSJaegeuk Kim NR_COUNT_TYPE, 107639a53e0cSJaegeuk Kim }; 107739a53e0cSJaegeuk Kim 107839a53e0cSJaegeuk Kim /* 1079e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 108039a53e0cSJaegeuk Kim * The available types are: 108139a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 108239a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 108339a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 108439a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 108539a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 108639a53e0cSJaegeuk Kim * with waiting the bio's completion 108739a53e0cSJaegeuk Kim * ... Only can be used with META. 108839a53e0cSJaegeuk Kim */ 10897d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 109039a53e0cSJaegeuk Kim enum page_type { 109139a53e0cSJaegeuk Kim DATA, 109239a53e0cSJaegeuk Kim NODE, 109339a53e0cSJaegeuk Kim META, 109439a53e0cSJaegeuk Kim NR_PAGE_TYPE, 109539a53e0cSJaegeuk Kim META_FLUSH, 10968ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 10978ce67cb0SJaegeuk Kim INMEM_DROP, 10988c242db9SJaegeuk Kim INMEM_INVALIDATE, 109928bc106bSChao Yu INMEM_REVOKE, 11008ce67cb0SJaegeuk Kim IPU, 11018ce67cb0SJaegeuk Kim OPU, 110239a53e0cSJaegeuk Kim }; 110339a53e0cSJaegeuk Kim 1104a912b54dSJaegeuk Kim enum temp_type { 1105a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 1106a912b54dSJaegeuk Kim WARM, 1107a912b54dSJaegeuk Kim COLD, 1108a912b54dSJaegeuk Kim NR_TEMP_TYPE, 1109a912b54dSJaegeuk Kim }; 1110a912b54dSJaegeuk Kim 1111cc15620bSJaegeuk Kim enum need_lock_type { 1112cc15620bSJaegeuk Kim LOCK_REQ = 0, 1113cc15620bSJaegeuk Kim LOCK_DONE, 1114cc15620bSJaegeuk Kim LOCK_RETRY, 1115cc15620bSJaegeuk Kim }; 1116cc15620bSJaegeuk Kim 1117a5fd5050SChao Yu enum cp_reason_type { 1118a5fd5050SChao Yu CP_NO_NEEDED, 1119a5fd5050SChao Yu CP_NON_REGULAR, 11204c8ff709SChao Yu CP_COMPRESSED, 1121a5fd5050SChao Yu CP_HARDLINK, 1122a5fd5050SChao Yu CP_SB_NEED_CP, 1123a5fd5050SChao Yu CP_WRONG_PINO, 1124a5fd5050SChao Yu CP_NO_SPC_ROLL, 1125a5fd5050SChao Yu CP_NODE_NEED_CP, 1126a5fd5050SChao Yu CP_FASTBOOT_MODE, 1127a5fd5050SChao Yu CP_SPEC_LOG_NUM, 11280a007b97SJaegeuk Kim CP_RECOVER_DIR, 1129a5fd5050SChao Yu }; 1130a5fd5050SChao Yu 1131b0af6d49SChao Yu enum iostat_type { 11328b83ac81SChao Yu /* WRITE IO */ 11338b83ac81SChao Yu APP_DIRECT_IO, /* app direct write IOs */ 11348b83ac81SChao Yu APP_BUFFERED_IO, /* app buffered write IOs */ 1135b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 1136b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 1137b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 1138b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 1139b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 1140b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 1141b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 1142b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 1143b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 1144b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 11458b83ac81SChao Yu 11468b83ac81SChao Yu /* READ IO */ 11478b83ac81SChao Yu APP_DIRECT_READ_IO, /* app direct read IOs */ 11488b83ac81SChao Yu APP_BUFFERED_READ_IO, /* app buffered read IOs */ 11498b83ac81SChao Yu APP_READ_IO, /* app read IOs */ 11508b83ac81SChao Yu APP_MAPPED_READ_IO, /* app mapped read IOs */ 11518b83ac81SChao Yu FS_DATA_READ_IO, /* data read IOs */ 11529c122384SChao Yu FS_GDATA_READ_IO, /* data read IOs from background gc */ 11539c122384SChao Yu FS_CDATA_READ_IO, /* compressed data read IOs */ 11548b83ac81SChao Yu FS_NODE_READ_IO, /* node read IOs */ 11558b83ac81SChao Yu FS_META_READ_IO, /* meta read IOs */ 11568b83ac81SChao Yu 11578b83ac81SChao Yu /* other */ 1158b0af6d49SChao Yu FS_DISCARD, /* discard */ 1159b0af6d49SChao Yu NR_IO_TYPE, 1160b0af6d49SChao Yu }; 1161b0af6d49SChao Yu 1162458e6197SJaegeuk Kim struct f2fs_io_info { 116305ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 116439d787beSChao Yu nid_t ino; /* inode number */ 1165458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 1166a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 116704d328deSMike Christie int op; /* contains REQ_OP_ */ 1168ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 11697a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 117028bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 117105ca3632SJaegeuk Kim struct page *page; /* page to be written */ 11724375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 11734c8ff709SChao Yu struct page *compressed_page; /* compressed page */ 1174fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 1175d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 1176cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 1177fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 11786dc3a126SChao Yu bool is_por; /* indicate IO is from recovery or not */ 1179fe16efe6SChao Yu bool retry; /* need to reallocate block address */ 11804c8ff709SChao Yu int compr_blocks; /* # of compressed block addresses */ 11814c8ff709SChao Yu bool encrypted; /* indicate file is encrypted */ 1182b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 1183578c6478SYufen Yu struct writeback_control *io_wbc; /* writeback control */ 11848648de2cSChao Yu struct bio **bio; /* bio for ipu */ 11858648de2cSChao Yu sector_t *last_block; /* last block number in bio */ 11867735730dSChao Yu unsigned char version; /* version of the node */ 1187458e6197SJaegeuk Kim }; 1188458e6197SJaegeuk Kim 11890b20fcecSChao Yu struct bio_entry { 11900b20fcecSChao Yu struct bio *bio; 11910b20fcecSChao Yu struct list_head list; 11920b20fcecSChao Yu }; 11930b20fcecSChao Yu 119468afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 11951ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 1196458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 11971ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 11981ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 1199458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 1200df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 1201fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 1202fb830fc5SChao Yu struct list_head io_list; /* track fios */ 12030b20fcecSChao Yu struct list_head bio_list; /* bio entry list head */ 12040b20fcecSChao Yu struct rw_semaphore bio_list_lock; /* lock to protect bio entry list */ 12051ff7bd3bSJaegeuk Kim }; 12061ff7bd3bSJaegeuk Kim 12073c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 12083c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 12093c62be17SJaegeuk Kim struct f2fs_dev_info { 12103c62be17SJaegeuk Kim struct block_device *bdev; 12113c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 12123c62be17SJaegeuk Kim unsigned int total_segments; 12133c62be17SJaegeuk Kim block_t start_blk; 12143c62be17SJaegeuk Kim block_t end_blk; 12153c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 12163c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 121795175dafSDamien Le Moal unsigned long *blkz_seq; /* Bitmap indicating sequential zones */ 1218de881df9SAravind Ramesh block_t *zone_capacity_blocks; /* Array of zone capacity in blks */ 12193c62be17SJaegeuk Kim #endif 12203c62be17SJaegeuk Kim }; 12213c62be17SJaegeuk Kim 1222c227f912SChao Yu enum inode_type { 1223c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 1224c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 12250f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 122657864ae5SJaegeuk Kim ATOMIC_FILE, /* for all atomic files */ 1227c227f912SChao Yu NR_INODE_TYPE, 1228c227f912SChao Yu }; 1229c227f912SChao Yu 123067298804SChao Yu /* for inner inode cache management */ 123167298804SChao Yu struct inode_management { 123267298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 123367298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 123467298804SChao Yu struct list_head ino_list; /* inode list head */ 123567298804SChao Yu unsigned long ino_num; /* number of entries */ 123667298804SChao Yu }; 123767298804SChao Yu 1238093749e2SChao Yu /* for GC_AT */ 1239093749e2SChao Yu struct atgc_management { 1240093749e2SChao Yu bool atgc_enabled; /* ATGC is enabled or not */ 1241093749e2SChao Yu struct rb_root_cached root; /* root of victim rb-tree */ 1242093749e2SChao Yu struct list_head victim_list; /* linked with all victim entries */ 1243093749e2SChao Yu unsigned int victim_count; /* victim count in rb-tree */ 1244093749e2SChao Yu unsigned int candidate_ratio; /* candidate ratio */ 1245093749e2SChao Yu unsigned int max_candidate_count; /* max candidate count */ 1246093749e2SChao Yu unsigned int age_weight; /* age weight, vblock_weight = 100 - age_weight */ 1247093749e2SChao Yu unsigned long long age_threshold; /* age threshold */ 1248093749e2SChao Yu }; 1249093749e2SChao Yu 1250caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 1251caf0047eSChao Yu enum { 1252caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 1253caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 1254caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 1255caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 1256df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 1257bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 125883a3bfdbSJaegeuk Kim SBI_IS_SHUTDOWN, /* shutdown by ioctl */ 12591378752bSChao Yu SBI_IS_RECOVERED, /* recovered orphan/data */ 12604354994fSDaniel Rosenberg SBI_CP_DISABLED, /* CP was disabled last mount */ 1261db610a64SJaegeuk Kim SBI_CP_DISABLED_QUICK, /* CP was disabled quickly */ 1262af033b2aSChao Yu SBI_QUOTA_NEED_FLUSH, /* need to flush quota info in CP */ 1263af033b2aSChao Yu SBI_QUOTA_SKIP_FLUSH, /* skip flushing quota in current CP */ 1264af033b2aSChao Yu SBI_QUOTA_NEED_REPAIR, /* quota file may be corrupted */ 126504f0b2eaSQiuyang Sun SBI_IS_RESIZEFS, /* resizefs is in process */ 1266caf0047eSChao Yu }; 1267caf0047eSChao Yu 12686beceb54SJaegeuk Kim enum { 12696beceb54SJaegeuk Kim CP_TIME, 1270d0239e1bSJaegeuk Kim REQ_TIME, 1271a7d10cf3SSahitya Tummala DISCARD_TIME, 1272a7d10cf3SSahitya Tummala GC_TIME, 12734354994fSDaniel Rosenberg DISABLE_TIME, 127403f2c02dSJaegeuk Kim UMOUNT_DISCARD_TIMEOUT, 12756beceb54SJaegeuk Kim MAX_TIME, 12766beceb54SJaegeuk Kim }; 12776beceb54SJaegeuk Kim 12780cdd3195SHyunchul Lee enum { 12795b0e9539SJaegeuk Kim GC_NORMAL, 12805b0e9539SJaegeuk Kim GC_IDLE_CB, 12815b0e9539SJaegeuk Kim GC_IDLE_GREEDY, 1282093749e2SChao Yu GC_IDLE_AT, 12830e5e8111SDaeho Jeong GC_URGENT_HIGH, 12840e5e8111SDaeho Jeong GC_URGENT_LOW, 128507c6b593SDaeho Jeong MAX_GC_MODE, 12865b0e9539SJaegeuk Kim }; 12875b0e9539SJaegeuk Kim 12885b0e9539SJaegeuk Kim enum { 1289bbbc34fdSChao Yu BGGC_MODE_ON, /* background gc is on */ 1290bbbc34fdSChao Yu BGGC_MODE_OFF, /* background gc is off */ 1291bbbc34fdSChao Yu BGGC_MODE_SYNC, /* 1292bbbc34fdSChao Yu * background gc is on, migrating blocks 1293bbbc34fdSChao Yu * like foreground gc 1294bbbc34fdSChao Yu */ 1295bbbc34fdSChao Yu }; 1296bbbc34fdSChao Yu 1297bbbc34fdSChao Yu enum { 1298b0332a0fSChao Yu FS_MODE_ADAPTIVE, /* use both lfs/ssr allocation */ 1299b0332a0fSChao Yu FS_MODE_LFS, /* use lfs allocation only */ 13006691d940SDaeho Jeong FS_MODE_FRAGMENT_SEG, /* segment fragmentation mode */ 13016691d940SDaeho Jeong FS_MODE_FRAGMENT_BLK, /* block fragmentation mode */ 1302b0332a0fSChao Yu }; 1303b0332a0fSChao Yu 1304b0332a0fSChao Yu enum { 13050cdd3195SHyunchul Lee WHINT_MODE_OFF, /* not pass down write hints */ 13060cdd3195SHyunchul Lee WHINT_MODE_USER, /* try to pass down hints given by users */ 1307f2e703f9SHyunchul Lee WHINT_MODE_FS, /* pass down hints with F2FS policy */ 13080cdd3195SHyunchul Lee }; 13090cdd3195SHyunchul Lee 131007939627SJaegeuk Kim enum { 131107939627SJaegeuk Kim ALLOC_MODE_DEFAULT, /* stay default */ 131207939627SJaegeuk Kim ALLOC_MODE_REUSE, /* reuse segments as much as possible */ 131307939627SJaegeuk Kim }; 131407939627SJaegeuk Kim 131593cf93f1SJunling Zheng enum fsync_mode { 131693cf93f1SJunling Zheng FSYNC_MODE_POSIX, /* fsync follows posix semantics */ 131793cf93f1SJunling Zheng FSYNC_MODE_STRICT, /* fsync behaves in line with ext4 */ 1318d6290814SJaegeuk Kim FSYNC_MODE_NOBARRIER, /* fsync behaves nobarrier based on posix */ 131993cf93f1SJunling Zheng }; 132093cf93f1SJunling Zheng 1321602a16d5SDaeho Jeong enum { 1322602a16d5SDaeho Jeong COMPR_MODE_FS, /* 1323602a16d5SDaeho Jeong * automatically compress compression 1324602a16d5SDaeho Jeong * enabled files 1325602a16d5SDaeho Jeong */ 1326602a16d5SDaeho Jeong COMPR_MODE_USER, /* 1327602a16d5SDaeho Jeong * automatical compression is disabled. 1328602a16d5SDaeho Jeong * user can control the file compression 1329602a16d5SDaeho Jeong * using ioctls 1330602a16d5SDaeho Jeong */ 1331602a16d5SDaeho Jeong }; 1332602a16d5SDaeho Jeong 13334f993264SChao Yu enum { 13344f993264SChao Yu DISCARD_UNIT_BLOCK, /* basic discard unit is block */ 13354f993264SChao Yu DISCARD_UNIT_SEGMENT, /* basic discard unit is segment */ 13364f993264SChao Yu DISCARD_UNIT_SECTION, /* basic discard unit is section */ 13374f993264SChao Yu }; 13384f993264SChao Yu 1339b763f3beSChao Yu static inline int f2fs_test_bit(unsigned int nr, char *addr); 1340b763f3beSChao Yu static inline void f2fs_set_bit(unsigned int nr, char *addr); 1341b763f3beSChao Yu static inline void f2fs_clear_bit(unsigned int nr, char *addr); 13424c8ff709SChao Yu 1343b763f3beSChao Yu /* 1344b763f3beSChao Yu * Layout of f2fs page.private: 1345b763f3beSChao Yu * 1346b763f3beSChao Yu * Layout A: lowest bit should be 1 1347b763f3beSChao Yu * | bit0 = 1 | bit1 | bit2 | ... | bit MAX | private data .... | 1348b763f3beSChao Yu * bit 0 PAGE_PRIVATE_NOT_POINTER 1349b763f3beSChao Yu * bit 1 PAGE_PRIVATE_ATOMIC_WRITE 1350b763f3beSChao Yu * bit 2 PAGE_PRIVATE_DUMMY_WRITE 1351b763f3beSChao Yu * bit 3 PAGE_PRIVATE_ONGOING_MIGRATION 1352b763f3beSChao Yu * bit 4 PAGE_PRIVATE_INLINE_INODE 1353b763f3beSChao Yu * bit 5 PAGE_PRIVATE_REF_RESOURCE 1354b763f3beSChao Yu * bit 6- f2fs private data 1355b763f3beSChao Yu * 1356b763f3beSChao Yu * Layout B: lowest bit should be 0 1357b763f3beSChao Yu * page.private is a wrapped pointer. 1358b763f3beSChao Yu */ 1359b763f3beSChao Yu enum { 1360b763f3beSChao Yu PAGE_PRIVATE_NOT_POINTER, /* private contains non-pointer data */ 1361b763f3beSChao Yu PAGE_PRIVATE_ATOMIC_WRITE, /* data page from atomic write path */ 1362b763f3beSChao Yu PAGE_PRIVATE_DUMMY_WRITE, /* data page for padding aligned IO */ 1363b763f3beSChao Yu PAGE_PRIVATE_ONGOING_MIGRATION, /* data page which is on-going migrating */ 1364b763f3beSChao Yu PAGE_PRIVATE_INLINE_INODE, /* inode page contains inline data */ 1365b763f3beSChao Yu PAGE_PRIVATE_REF_RESOURCE, /* dirty page has referenced resources */ 1366b763f3beSChao Yu PAGE_PRIVATE_MAX 1367b763f3beSChao Yu }; 1368b763f3beSChao Yu 1369b763f3beSChao Yu #define PAGE_PRIVATE_GET_FUNC(name, flagname) \ 1370b763f3beSChao Yu static inline bool page_private_##name(struct page *page) \ 1371b763f3beSChao Yu { \ 1372c9ebd3dfSJaegeuk Kim return PagePrivate(page) && \ 1373c9ebd3dfSJaegeuk Kim test_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)) && \ 1374b763f3beSChao Yu test_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \ 1375b763f3beSChao Yu } 1376b763f3beSChao Yu 1377b763f3beSChao Yu #define PAGE_PRIVATE_SET_FUNC(name, flagname) \ 1378b763f3beSChao Yu static inline void set_page_private_##name(struct page *page) \ 1379b763f3beSChao Yu { \ 1380b763f3beSChao Yu if (!PagePrivate(page)) { \ 1381b763f3beSChao Yu get_page(page); \ 1382b763f3beSChao Yu SetPagePrivate(page); \ 1383c9ebd3dfSJaegeuk Kim set_page_private(page, 0); \ 1384b763f3beSChao Yu } \ 1385b763f3beSChao Yu set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)); \ 1386b763f3beSChao Yu set_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \ 1387b763f3beSChao Yu } 1388b763f3beSChao Yu 1389b763f3beSChao Yu #define PAGE_PRIVATE_CLEAR_FUNC(name, flagname) \ 1390b763f3beSChao Yu static inline void clear_page_private_##name(struct page *page) \ 1391b763f3beSChao Yu { \ 1392b763f3beSChao Yu clear_bit(PAGE_PRIVATE_##flagname, &page_private(page)); \ 1393b763f3beSChao Yu if (page_private(page) == 1 << PAGE_PRIVATE_NOT_POINTER) { \ 1394b763f3beSChao Yu set_page_private(page, 0); \ 1395b763f3beSChao Yu if (PagePrivate(page)) { \ 1396b763f3beSChao Yu ClearPagePrivate(page); \ 1397b763f3beSChao Yu put_page(page); \ 1398b763f3beSChao Yu }\ 1399b763f3beSChao Yu } \ 1400b763f3beSChao Yu } 1401b763f3beSChao Yu 1402b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(nonpointer, NOT_POINTER); 1403b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(reference, REF_RESOURCE); 1404b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(inline, INLINE_INODE); 1405b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(gcing, ONGOING_MIGRATION); 1406b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(atomic, ATOMIC_WRITE); 1407b763f3beSChao Yu PAGE_PRIVATE_GET_FUNC(dummy, DUMMY_WRITE); 1408b763f3beSChao Yu 1409b763f3beSChao Yu PAGE_PRIVATE_SET_FUNC(reference, REF_RESOURCE); 1410b763f3beSChao Yu PAGE_PRIVATE_SET_FUNC(inline, INLINE_INODE); 1411b763f3beSChao Yu PAGE_PRIVATE_SET_FUNC(gcing, ONGOING_MIGRATION); 1412b763f3beSChao Yu PAGE_PRIVATE_SET_FUNC(atomic, ATOMIC_WRITE); 1413b763f3beSChao Yu PAGE_PRIVATE_SET_FUNC(dummy, DUMMY_WRITE); 1414b763f3beSChao Yu 1415b763f3beSChao Yu PAGE_PRIVATE_CLEAR_FUNC(reference, REF_RESOURCE); 1416b763f3beSChao Yu PAGE_PRIVATE_CLEAR_FUNC(inline, INLINE_INODE); 1417b763f3beSChao Yu PAGE_PRIVATE_CLEAR_FUNC(gcing, ONGOING_MIGRATION); 1418b763f3beSChao Yu PAGE_PRIVATE_CLEAR_FUNC(atomic, ATOMIC_WRITE); 1419b763f3beSChao Yu PAGE_PRIVATE_CLEAR_FUNC(dummy, DUMMY_WRITE); 14204c8ff709SChao Yu 14216ce19affSChao Yu static inline unsigned long get_page_private_data(struct page *page) 14226ce19affSChao Yu { 14236ce19affSChao Yu unsigned long data = page_private(page); 14246ce19affSChao Yu 14256ce19affSChao Yu if (!test_bit(PAGE_PRIVATE_NOT_POINTER, &data)) 14266ce19affSChao Yu return 0; 14276ce19affSChao Yu return data >> PAGE_PRIVATE_MAX; 14286ce19affSChao Yu } 14296ce19affSChao Yu 14306ce19affSChao Yu static inline void set_page_private_data(struct page *page, unsigned long data) 14316ce19affSChao Yu { 14326ce19affSChao Yu if (!PagePrivate(page)) { 14336ce19affSChao Yu get_page(page); 14346ce19affSChao Yu SetPagePrivate(page); 1435c9ebd3dfSJaegeuk Kim set_page_private(page, 0); 14366ce19affSChao Yu } 14376ce19affSChao Yu set_bit(PAGE_PRIVATE_NOT_POINTER, &page_private(page)); 14386ce19affSChao Yu page_private(page) |= data << PAGE_PRIVATE_MAX; 14396ce19affSChao Yu } 14406ce19affSChao Yu 14416ce19affSChao Yu static inline void clear_page_private_data(struct page *page) 14426ce19affSChao Yu { 14436ce19affSChao Yu page_private(page) &= (1 << PAGE_PRIVATE_MAX) - 1; 14446ce19affSChao Yu if (page_private(page) == 1 << PAGE_PRIVATE_NOT_POINTER) { 14456ce19affSChao Yu set_page_private(page, 0); 14466ce19affSChao Yu if (PagePrivate(page)) { 14476ce19affSChao Yu ClearPagePrivate(page); 14486ce19affSChao Yu put_page(page); 14496ce19affSChao Yu } 14506ce19affSChao Yu } 14516ce19affSChao Yu } 14526ce19affSChao Yu 14534c8ff709SChao Yu /* For compression */ 14544c8ff709SChao Yu enum compress_algorithm_type { 14554c8ff709SChao Yu COMPRESS_LZO, 14564c8ff709SChao Yu COMPRESS_LZ4, 145750cfa66fSChao Yu COMPRESS_ZSTD, 14586d92b201SChao Yu COMPRESS_LZORLE, 14594c8ff709SChao Yu COMPRESS_MAX, 14604c8ff709SChao Yu }; 14614c8ff709SChao Yu 1462b28f047bSChao Yu enum compress_flag { 1463b28f047bSChao Yu COMPRESS_CHKSUM, 1464b28f047bSChao Yu COMPRESS_MAX_FLAG, 1465b28f047bSChao Yu }; 1466b28f047bSChao Yu 14676ce19affSChao Yu #define COMPRESS_WATERMARK 20 14686ce19affSChao Yu #define COMPRESS_PERCENT 20 14696ce19affSChao Yu 1470b28f047bSChao Yu #define COMPRESS_DATA_RESERVED_SIZE 4 14714c8ff709SChao Yu struct compress_data { 14724c8ff709SChao Yu __le32 clen; /* compressed data size */ 1473b28f047bSChao Yu __le32 chksum; /* compressed data chksum */ 14744c8ff709SChao Yu __le32 reserved[COMPRESS_DATA_RESERVED_SIZE]; /* reserved */ 14754c8ff709SChao Yu u8 cdata[]; /* compressed data */ 14764c8ff709SChao Yu }; 14774c8ff709SChao Yu 14784c8ff709SChao Yu #define COMPRESS_HEADER_SIZE (sizeof(struct compress_data)) 14794c8ff709SChao Yu 14804c8ff709SChao Yu #define F2FS_COMPRESSED_PAGE_MAGIC 0xF5F2C000 14814c8ff709SChao Yu 14823fde13f8SChao Yu #define COMPRESS_LEVEL_OFFSET 8 14833fde13f8SChao Yu 14844c8ff709SChao Yu /* compress context */ 14854c8ff709SChao Yu struct compress_ctx { 14864c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 14874c8ff709SChao Yu pgoff_t cluster_idx; /* cluster index number */ 14884c8ff709SChao Yu unsigned int cluster_size; /* page count in cluster */ 14894c8ff709SChao Yu unsigned int log_cluster_size; /* log of cluster size */ 14904c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 14914c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 14924c8ff709SChao Yu struct page **cpages; /* pages store compressed data in cluster */ 14934c8ff709SChao Yu unsigned int nr_cpages; /* total page number in cpages */ 14943271d7ebSFengnan Chang unsigned int valid_nr_cpages; /* valid page number in cpages */ 14954c8ff709SChao Yu void *rbuf; /* virtual mapped address on rpages */ 14964c8ff709SChao Yu struct compress_data *cbuf; /* virtual mapped address on cpages */ 14974c8ff709SChao Yu size_t rlen; /* valid data length in rbuf */ 14984c8ff709SChao Yu size_t clen; /* valid data length in cbuf */ 14994c8ff709SChao Yu void *private; /* payload buffer for specified compression algorithm */ 150050cfa66fSChao Yu void *private2; /* extra payload buffer */ 15014c8ff709SChao Yu }; 15024c8ff709SChao Yu 15034c8ff709SChao Yu /* compress context for write IO path */ 15044c8ff709SChao Yu struct compress_io_ctx { 15054c8ff709SChao Yu u32 magic; /* magic number to indicate page is compressed */ 15064c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 15074c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 15084c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 1509e6c3948dSChao Yu atomic_t pending_pages; /* in-flight compressed page count */ 15104c8ff709SChao Yu }; 15114c8ff709SChao Yu 15127f59b277SEric Biggers /* Context for decompressing one cluster on the read IO path */ 15134c8ff709SChao Yu struct decompress_io_ctx { 15144c8ff709SChao Yu u32 magic; /* magic number to indicate page is compressed */ 15154c8ff709SChao Yu struct inode *inode; /* inode the context belong to */ 15164c8ff709SChao Yu pgoff_t cluster_idx; /* cluster index number */ 15174c8ff709SChao Yu unsigned int cluster_size; /* page count in cluster */ 15184c8ff709SChao Yu unsigned int log_cluster_size; /* log of cluster size */ 15194c8ff709SChao Yu struct page **rpages; /* pages store raw data in cluster */ 15204c8ff709SChao Yu unsigned int nr_rpages; /* total page number in rpages */ 15214c8ff709SChao Yu struct page **cpages; /* pages store compressed data in cluster */ 15224c8ff709SChao Yu unsigned int nr_cpages; /* total page number in cpages */ 15234c8ff709SChao Yu struct page **tpages; /* temp pages to pad holes in cluster */ 15244c8ff709SChao Yu void *rbuf; /* virtual mapped address on rpages */ 15254c8ff709SChao Yu struct compress_data *cbuf; /* virtual mapped address on cpages */ 15264c8ff709SChao Yu size_t rlen; /* valid data length in rbuf */ 15274c8ff709SChao Yu size_t clen; /* valid data length in cbuf */ 15287f59b277SEric Biggers 15297f59b277SEric Biggers /* 15307f59b277SEric Biggers * The number of compressed pages remaining to be read in this cluster. 15317f59b277SEric Biggers * This is initially nr_cpages. It is decremented by 1 each time a page 15327f59b277SEric Biggers * has been read (or failed to be read). When it reaches 0, the cluster 15337f59b277SEric Biggers * is decompressed (or an error is reported). 15347f59b277SEric Biggers * 15357f59b277SEric Biggers * If an error occurs before all the pages have been submitted for I/O, 15367f59b277SEric Biggers * then this will never reach 0. In this case the I/O submitter is 15377f59b277SEric Biggers * responsible for calling f2fs_decompress_end_io() instead. 15387f59b277SEric Biggers */ 15397f59b277SEric Biggers atomic_t remaining_pages; 15407f59b277SEric Biggers 15417f59b277SEric Biggers /* 15427f59b277SEric Biggers * Number of references to this decompress_io_ctx. 15437f59b277SEric Biggers * 15447f59b277SEric Biggers * One reference is held for I/O completion. This reference is dropped 15457f59b277SEric Biggers * after the pagecache pages are updated and unlocked -- either after 15467f59b277SEric Biggers * decompression (and verity if enabled), or after an error. 15477f59b277SEric Biggers * 15487f59b277SEric Biggers * In addition, each compressed page holds a reference while it is in a 15497f59b277SEric Biggers * bio. These references are necessary prevent compressed pages from 15507f59b277SEric Biggers * being freed while they are still in a bio. 15517f59b277SEric Biggers */ 15527f59b277SEric Biggers refcount_t refcnt; 15537f59b277SEric Biggers 15547f59b277SEric Biggers bool failed; /* IO error occurred before decompression? */ 15557f59b277SEric Biggers bool need_verity; /* need fs-verity verification after decompression? */ 155650cfa66fSChao Yu void *private; /* payload buffer for specified decompression algorithm */ 155750cfa66fSChao Yu void *private2; /* extra payload buffer */ 15587f59b277SEric Biggers struct work_struct verity_work; /* work to verify the decompressed pages */ 15594c8ff709SChao Yu }; 15604c8ff709SChao Yu 15614c8ff709SChao Yu #define NULL_CLUSTER ((unsigned int)(~0)) 15624c8ff709SChao Yu #define MIN_COMPRESS_LOG_SIZE 2 15634c8ff709SChao Yu #define MAX_COMPRESS_LOG_SIZE 8 15640e2b7385SChao Yu #define MAX_COMPRESS_WINDOW_SIZE(log_size) ((PAGE_SIZE) << (log_size)) 15654c8ff709SChao Yu 156639a53e0cSJaegeuk Kim struct f2fs_sb_info { 156739a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 15685e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 156939a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 1570846ae671SChao Yu struct rw_semaphore sb_lock; /* lock for raw super block */ 1571e8240f65SChao Yu int valid_super_block; /* valid super block no */ 1572fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 1573853137ceSJaegeuk Kim struct mutex writepages; /* mutex for writepages() */ 157439a53e0cSJaegeuk Kim 1575178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 1576178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1577178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 1578178053e2SDamien Le Moal #endif 1579178053e2SDamien Le Moal 158039a53e0cSJaegeuk Kim /* for node-related operations */ 158139a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 158239a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 158339a53e0cSJaegeuk Kim 158439a53e0cSJaegeuk Kim /* for segment-related operations */ 158539a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 15861ff7bd3bSJaegeuk Kim 15871ff7bd3bSJaegeuk Kim /* for bio operations */ 1588a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1589107a805dSChao Yu /* keep migration IO order for LFS mode */ 1590107a805dSChao Yu struct rw_semaphore io_order_lock; 15910a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 159239a53e0cSJaegeuk Kim 159339a53e0cSJaegeuk Kim /* for checkpoint */ 159439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 15958508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1596aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 159739a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 15988769918bSSahitya Tummala struct rw_semaphore cp_global_sem; /* checkpoint procedure lock */ 1599b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1600b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 160159c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1602fb51b5efSChangman Lee wait_queue_head_t cp_wait; 16036beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 16046beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 1605261eeb9cSDaeho Jeong struct ckpt_req_control cprc_info; /* for checkpoint request control */ 160639a53e0cSJaegeuk Kim 160767298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 16086451e041SJaegeuk Kim 160950fa53ecSChao Yu spinlock_t fsync_node_lock; /* for node entry lock */ 161050fa53ecSChao Yu struct list_head fsync_node_list; /* node list head */ 161150fa53ecSChao Yu unsigned int fsync_seg_id; /* sequence id */ 161250fa53ecSChao Yu unsigned int fsync_node_num; /* number of node entries */ 161350fa53ecSChao Yu 16146451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 16150d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 161639a53e0cSJaegeuk Kim 1617c227f912SChao Yu /* for inode management */ 1618c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1619c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 1620040d2bb3SChao Yu struct mutex flush_lock; /* for flush exclusion */ 162139a53e0cSJaegeuk Kim 162213054c54SChao Yu /* for extent tree cache */ 162313054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 16245e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 162513054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 162613054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 16277441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1628137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 162974fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 163013054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 163113054c54SChao Yu 163239a53e0cSJaegeuk Kim /* basic filesystem units */ 163339a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 163439a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 163539a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 163639a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 163739a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 163839a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 163939a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 164039a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 164139a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 164239a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 164339a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 164439a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 164539a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1646ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 1647f6df8f23SSheng Yong int readdir_ra; /* readahead inode in readdir */ 164810208567SJaegeuk Kim u64 max_io_bytes; /* max io bytes to merge IOs */ 164939a53e0cSJaegeuk Kim 165039a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 165139a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1652a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 165339a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1654daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 165580d42145SYunlong Song block_t current_reserved_blocks; /* current reserved blocks */ 1656daeb433eSChao Yu 16574354994fSDaniel Rosenberg /* Additional tracking for no checkpoint mode */ 16584354994fSDaniel Rosenberg block_t unusable_block_count; /* # of blocks saved by last cp */ 16594354994fSDaniel Rosenberg 1660292c196aSChao Yu unsigned int nquota_files; /* # of quota sysfile */ 1661db6ec53bSJaegeuk Kim struct rw_semaphore quota_sem; /* blocking cp for flags */ 1662292c196aSChao Yu 1663523be8a6SJaegeuk Kim /* # of pages, see count_type */ 166435782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 166541382ec4SJaegeuk Kim /* # of allocated blocks */ 166641382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 166739a53e0cSJaegeuk Kim 1668687de7f1SJaegeuk Kim /* writeback control */ 1669c29fd0c0SChao Yu atomic_t wb_sync_req[META]; /* count # of WB_SYNC threads */ 1670687de7f1SJaegeuk Kim 1671513c5f37SJaegeuk Kim /* valid inode count */ 1672513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1673513c5f37SJaegeuk Kim 167439a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 167539a53e0cSJaegeuk Kim 167639a53e0cSJaegeuk Kim /* for cleaning operations */ 1677fb24fea7SChao Yu struct rw_semaphore gc_lock; /* 1678fb24fea7SChao Yu * semaphore for GC, avoid 1679fb24fea7SChao Yu * race between GC and GC or CP 1680fb24fea7SChao Yu */ 168139a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 1682093749e2SChao Yu struct atgc_management am; /* atgc management */ 16835ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 16845b0e9539SJaegeuk Kim unsigned int gc_mode; /* current GC state */ 1685e3080b01SChao Yu unsigned int next_victim_seg[2]; /* next segment in victim section */ 1686*325163e9SDaeho Jeong spinlock_t gc_urgent_high_lock; 1687*325163e9SDaeho Jeong bool gc_urgent_high_limited; /* indicates having limited trial count */ 1688*325163e9SDaeho Jeong unsigned int gc_urgent_high_remaining; /* remaining trial count for GC_URGENT_HIGH */ 16890e5e8111SDaeho Jeong 16902ef79ecbSChao Yu /* for skip statistic */ 1691677017d1SSahitya Tummala unsigned int atomic_files; /* # of opened atomic file */ 16922ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */ 16936f8d4455SJaegeuk Kim unsigned long long skipped_gc_rwsem; /* FG_GC only */ 169439a53e0cSJaegeuk Kim 16951ad71a27SJaegeuk Kim /* threshold for gc trials on pinned files */ 16961ad71a27SJaegeuk Kim u64 gc_pin_file_threshold; 1697f5a53edcSJaegeuk Kim struct rw_semaphore pin_sem; 16981ad71a27SJaegeuk Kim 1699b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1700b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1701e3080b01SChao Yu /* migration granularity of garbage collection, unit: segment */ 1702e3080b01SChao Yu unsigned int migration_granularity; 1703b1c57c1cSJaegeuk Kim 170439a53e0cSJaegeuk Kim /* 170539a53e0cSJaegeuk Kim * for stat information. 170639a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 170739a53e0cSJaegeuk Kim */ 170835b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 170939a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 1710b63e7be5SChao Yu atomic_t meta_count[META_MAX]; /* # of meta blocks */ 171139a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 171239a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1713b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 17145b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 17155b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 17165b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 17175b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1718d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 171903e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 172003e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 17214c8ff709SChao Yu atomic_t compr_inode; /* # of compressed inodes */ 1722ae999bb9SDaeho Jeong atomic64_t compr_blocks; /* # of compressed blocks */ 1723648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 172426a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1725648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 1726274bd9baSChao Yu unsigned int io_skip_bggc; /* skip background gc for in-flight IO */ 1727274bd9baSChao Yu unsigned int other_skip_bggc; /* skip background gc for other reasons */ 172833fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 172935b09d82SNamjae Jeon #endif 173039a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1731b59d0baeSNamjae Jeon 1732da9953b7SJaegeuk Kim /* to attach REQ_META|REQ_FUA flags */ 1733da9953b7SJaegeuk Kim unsigned int data_io_flag; 173432b6aba8SJaegeuk Kim unsigned int node_io_flag; 1735b0af6d49SChao Yu 1736b59d0baeSNamjae Jeon /* For sysfs suppport */ 17375d4daa57SChao Yu struct kobject s_kobj; /* /sys/fs/f2fs/<devname> */ 1738b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 17392658e50dSJaegeuk Kim 17405d4daa57SChao Yu struct kobject s_stat_kobj; /* /sys/fs/f2fs/<devname>/stat */ 17415d4daa57SChao Yu struct completion s_stat_kobj_unregister; 17425d4daa57SChao Yu 17434c89b53dSJaegeuk Kim struct kobject s_feature_list_kobj; /* /sys/fs/f2fs/<devname>/feature_list */ 17444c89b53dSJaegeuk Kim struct completion s_feature_list_kobj_unregister; 17454c89b53dSJaegeuk Kim 17462658e50dSJaegeuk Kim /* For shrinker support */ 17472658e50dSJaegeuk Kim struct list_head s_list; 174871f2c820SChao Yu struct mutex umount_mutex; 174971f2c820SChao Yu unsigned int shrinker_run_no; 175071f2c820SChao Yu 175171f2c820SChao Yu /* For multi devices */ 17523c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 17533c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 17541228b482SChao Yu unsigned int dirty_device; /* for checkpoint data flush */ 17551228b482SChao Yu spinlock_t dev_lock; /* protect dirty_device */ 175671f2c820SChao Yu bool aligned_blksize; /* all devices has the same logical blksize */ 17578f1dbbbbSShuoran Liu 17588f1dbbbbSShuoran Liu /* For write statistics */ 17598f1dbbbbSShuoran Liu u64 sectors_written_start; 17608f1dbbbbSShuoran Liu u64 kbytes_written; 176143b6573bSKeith Mok 176243b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 176343b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 17641ecc0c5cSChao Yu 1765704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1766704956ecSChao Yu __u32 s_chksum_seed; 17674c8ff709SChao Yu 17684c8ff709SChao Yu struct workqueue_struct *post_read_wq; /* post read workqueue */ 1769a999150fSChao Yu 1770a999150fSChao Yu struct kmem_cache *inline_xattr_slab; /* inline xattr entry */ 1771a999150fSChao Yu unsigned int inline_xattr_slab_size; /* default inline xattr slab size */ 177231083031SChao Yu 177307c6b593SDaeho Jeong /* For reclaimed segs statistics per each GC mode */ 177407c6b593SDaeho Jeong unsigned int gc_segment_mode; /* GC state for reclaimed segments */ 177507c6b593SDaeho Jeong unsigned int gc_reclaimed_segs[MAX_GC_MODE]; /* Reclaimed segs for each mode */ 177607c6b593SDaeho Jeong 17770f6b56ecSDaeho Jeong unsigned long seq_file_ra_mul; /* multiplier for ra_pages of seq. files in fadvise */ 17780f6b56ecSDaeho Jeong 17796691d940SDaeho Jeong int max_fragment_chunk; /* max chunk size for block fragmentation mode */ 17806691d940SDaeho Jeong int max_fragment_hole; /* max hole size for block fragmentation mode */ 17816691d940SDaeho Jeong 178231083031SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 178331083031SChao Yu struct kmem_cache *page_array_slab; /* page array entry */ 178431083031SChao Yu unsigned int page_array_slab_size; /* default page array slab size */ 17855ac443e2SDaeho Jeong 17865ac443e2SDaeho Jeong /* For runtime compression statistics */ 17875ac443e2SDaeho Jeong u64 compr_written_block; 17885ac443e2SDaeho Jeong u64 compr_saved_block; 17895ac443e2SDaeho Jeong u32 compr_new_inode; 17906ce19affSChao Yu 17916ce19affSChao Yu /* For compressed block cache */ 17926ce19affSChao Yu struct inode *compress_inode; /* cache compressed blocks */ 17936ce19affSChao Yu unsigned int compress_percent; /* cache page percentage */ 17946ce19affSChao Yu unsigned int compress_watermark; /* cache page watermark */ 17956ce19affSChao Yu atomic_t compress_page_hit; /* cache hit count */ 179631083031SChao Yu #endif 179752118743SDaeho Jeong 179852118743SDaeho Jeong #ifdef CONFIG_F2FS_IOSTAT 179952118743SDaeho Jeong /* For app/fs IO statistics */ 180052118743SDaeho Jeong spinlock_t iostat_lock; 180152118743SDaeho Jeong unsigned long long rw_iostat[NR_IO_TYPE]; 180252118743SDaeho Jeong unsigned long long prev_rw_iostat[NR_IO_TYPE]; 180352118743SDaeho Jeong bool iostat_enable; 180452118743SDaeho Jeong unsigned long iostat_next_period; 180552118743SDaeho Jeong unsigned int iostat_period_ms; 1806a4b68176SDaeho Jeong 1807a4b68176SDaeho Jeong /* For io latency related statistics info in one iostat period */ 1808a4b68176SDaeho Jeong spinlock_t iostat_lat_lock; 1809a4b68176SDaeho Jeong struct iostat_lat_info *iostat_io_lat; 181052118743SDaeho Jeong #endif 181139a53e0cSJaegeuk Kim }; 181239a53e0cSJaegeuk Kim 18131ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 1814c45d6002SChao Yu #define f2fs_show_injection_info(sbi, type) \ 1815c45d6002SChao Yu printk_ratelimited("%sF2FS-fs (%s) : inject %s in %s of %pS\n", \ 1816c45d6002SChao Yu KERN_INFO, sbi->sb->s_id, \ 1817c45d6002SChao Yu f2fs_fault_name[type], \ 181855523519SChao Yu __func__, __builtin_return_address(0)) 18191ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 18201ecc0c5cSChao Yu { 182163189b78SChao Yu struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info; 18221ecc0c5cSChao Yu 18231ecc0c5cSChao Yu if (!ffi->inject_rate) 18241ecc0c5cSChao Yu return false; 18251ecc0c5cSChao Yu 18261ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 18271ecc0c5cSChao Yu return false; 18281ecc0c5cSChao Yu 18291ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 18301ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 18311ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 18321ecc0c5cSChao Yu return true; 18331ecc0c5cSChao Yu } 18341ecc0c5cSChao Yu return false; 18351ecc0c5cSChao Yu } 18367fa750a1SArnd Bergmann #else 1837c45d6002SChao Yu #define f2fs_show_injection_info(sbi, type) do { } while (0) 18387fa750a1SArnd Bergmann static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 18397fa750a1SArnd Bergmann { 18407fa750a1SArnd Bergmann return false; 18417fa750a1SArnd Bergmann } 18421ecc0c5cSChao Yu #endif 18431ecc0c5cSChao Yu 18440916878dSDamien Le Moal /* 18450916878dSDamien Le Moal * Test if the mounted volume is a multi-device volume. 18460916878dSDamien Le Moal * - For a single regular disk volume, sbi->s_ndevs is 0. 18470916878dSDamien Le Moal * - For a single zoned disk volume, sbi->s_ndevs is 1. 18480916878dSDamien Le Moal * - For a multi-device volume, sbi->s_ndevs is always 2 or more. 18490916878dSDamien Le Moal */ 18500916878dSDamien Le Moal static inline bool f2fs_is_multi_device(struct f2fs_sb_info *sbi) 18510916878dSDamien Le Moal { 18520916878dSDamien Le Moal return sbi->s_ndevs > 1; 18530916878dSDamien Le Moal } 18540916878dSDamien Le Moal 18556beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 18566beceb54SJaegeuk Kim { 1857a7d10cf3SSahitya Tummala unsigned long now = jiffies; 1858a7d10cf3SSahitya Tummala 1859a7d10cf3SSahitya Tummala sbi->last_time[type] = now; 1860a7d10cf3SSahitya Tummala 1861a7d10cf3SSahitya Tummala /* DISCARD_TIME and GC_TIME are based on REQ_TIME */ 1862a7d10cf3SSahitya Tummala if (type == REQ_TIME) { 1863a7d10cf3SSahitya Tummala sbi->last_time[DISCARD_TIME] = now; 1864a7d10cf3SSahitya Tummala sbi->last_time[GC_TIME] = now; 1865a7d10cf3SSahitya Tummala } 18666beceb54SJaegeuk Kim } 18676beceb54SJaegeuk Kim 18686beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 18696beceb54SJaegeuk Kim { 18706bccfa19SArnd Bergmann unsigned long interval = sbi->interval_time[type] * HZ; 18716beceb54SJaegeuk Kim 18726beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 18736beceb54SJaegeuk Kim } 18746beceb54SJaegeuk Kim 1875a7d10cf3SSahitya Tummala static inline unsigned int f2fs_time_to_wait(struct f2fs_sb_info *sbi, 1876a7d10cf3SSahitya Tummala int type) 1877a7d10cf3SSahitya Tummala { 1878a7d10cf3SSahitya Tummala unsigned long interval = sbi->interval_time[type] * HZ; 1879a7d10cf3SSahitya Tummala unsigned int wait_ms = 0; 1880a7d10cf3SSahitya Tummala long delta; 1881a7d10cf3SSahitya Tummala 1882a7d10cf3SSahitya Tummala delta = (sbi->last_time[type] + interval) - jiffies; 1883a7d10cf3SSahitya Tummala if (delta > 0) 1884a7d10cf3SSahitya Tummala wait_ms = jiffies_to_msecs(delta); 1885a7d10cf3SSahitya Tummala 1886a7d10cf3SSahitya Tummala return wait_ms; 1887a7d10cf3SSahitya Tummala } 1888a7d10cf3SSahitya Tummala 188939a53e0cSJaegeuk Kim /* 189039a53e0cSJaegeuk Kim * Inline functions 189139a53e0cSJaegeuk Kim */ 1892416d2dbbSChao Yu static inline u32 __f2fs_crc32(struct f2fs_sb_info *sbi, u32 crc, 1893704956ecSChao Yu const void *address, unsigned int length) 1894704956ecSChao Yu { 1895704956ecSChao Yu struct { 1896704956ecSChao Yu struct shash_desc shash; 1897704956ecSChao Yu char ctx[4]; 1898704956ecSChao Yu } desc; 1899704956ecSChao Yu int err; 1900704956ecSChao Yu 1901704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1902704956ecSChao Yu 1903704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1904704956ecSChao Yu *(u32 *)desc.ctx = crc; 1905704956ecSChao Yu 1906704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1907704956ecSChao Yu BUG_ON(err); 1908704956ecSChao Yu 1909704956ecSChao Yu return *(u32 *)desc.ctx; 1910704956ecSChao Yu } 1911704956ecSChao Yu 1912416d2dbbSChao Yu static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 1913416d2dbbSChao Yu unsigned int length) 1914416d2dbbSChao Yu { 1915416d2dbbSChao Yu return __f2fs_crc32(sbi, F2FS_SUPER_MAGIC, address, length); 1916416d2dbbSChao Yu } 1917416d2dbbSChao Yu 1918416d2dbbSChao Yu static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 1919416d2dbbSChao Yu void *buf, size_t buf_size) 1920416d2dbbSChao Yu { 1921416d2dbbSChao Yu return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 1922416d2dbbSChao Yu } 1923416d2dbbSChao Yu 1924416d2dbbSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1925416d2dbbSChao Yu const void *address, unsigned int length) 1926416d2dbbSChao Yu { 1927416d2dbbSChao Yu return __f2fs_crc32(sbi, crc, address, length); 1928416d2dbbSChao Yu } 1929416d2dbbSChao Yu 193039a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 193139a53e0cSJaegeuk Kim { 193239a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 193339a53e0cSJaegeuk Kim } 193439a53e0cSJaegeuk Kim 193539a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 193639a53e0cSJaegeuk Kim { 193739a53e0cSJaegeuk Kim return sb->s_fs_info; 193839a53e0cSJaegeuk Kim } 193939a53e0cSJaegeuk Kim 19404081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 19414081363fSJaegeuk Kim { 19424081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 19434081363fSJaegeuk Kim } 19444081363fSJaegeuk Kim 19454081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 19464081363fSJaegeuk Kim { 19474081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 19484081363fSJaegeuk Kim } 19494081363fSJaegeuk Kim 19504081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 19514081363fSJaegeuk Kim { 19524969c06aSJaegeuk Kim return F2FS_M_SB(page_file_mapping(page)); 19534081363fSJaegeuk Kim } 19544081363fSJaegeuk Kim 195539a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 195639a53e0cSJaegeuk Kim { 195739a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 195839a53e0cSJaegeuk Kim } 195939a53e0cSJaegeuk Kim 196039a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 196139a53e0cSJaegeuk Kim { 196239a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 196339a53e0cSJaegeuk Kim } 196439a53e0cSJaegeuk Kim 196545590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 196645590710SGu Zheng { 196745590710SGu Zheng return (struct f2fs_node *)page_address(page); 196845590710SGu Zheng } 196945590710SGu Zheng 197058bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 197158bfaf44SJaegeuk Kim { 197258bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 197358bfaf44SJaegeuk Kim } 197458bfaf44SJaegeuk Kim 197539a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 197639a53e0cSJaegeuk Kim { 197739a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 197839a53e0cSJaegeuk Kim } 197939a53e0cSJaegeuk Kim 198039a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 198139a53e0cSJaegeuk Kim { 198239a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 198339a53e0cSJaegeuk Kim } 198439a53e0cSJaegeuk Kim 198539a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 198639a53e0cSJaegeuk Kim { 198739a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 198839a53e0cSJaegeuk Kim } 198939a53e0cSJaegeuk Kim 199039a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 199139a53e0cSJaegeuk Kim { 199239a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 199339a53e0cSJaegeuk Kim } 199439a53e0cSJaegeuk Kim 199539a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 199639a53e0cSJaegeuk Kim { 199739a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 199839a53e0cSJaegeuk Kim } 199939a53e0cSJaegeuk Kim 20009df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 20019df27d98SGu Zheng { 20029df27d98SGu Zheng return sbi->meta_inode->i_mapping; 20039df27d98SGu Zheng } 20049df27d98SGu Zheng 20054ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 20064ef51a8fSJaegeuk Kim { 20074ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 20084ef51a8fSJaegeuk Kim } 20094ef51a8fSJaegeuk Kim 2010caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 201139a53e0cSJaegeuk Kim { 2012fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 201339a53e0cSJaegeuk Kim } 201439a53e0cSJaegeuk Kim 2015caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 201639a53e0cSJaegeuk Kim { 2017fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 2018caf0047eSChao Yu } 2019caf0047eSChao Yu 2020caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 2021caf0047eSChao Yu { 2022fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 202339a53e0cSJaegeuk Kim } 202439a53e0cSJaegeuk Kim 2025d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 2026d71b5564SJaegeuk Kim { 2027d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 2028d71b5564SJaegeuk Kim } 2029d71b5564SJaegeuk Kim 2030ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) 2031ea676733SJaegeuk Kim { 2032ea676733SJaegeuk Kim if (type < F2FS_MAX_QUOTAS) 2033ea676733SJaegeuk Kim return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); 2034ea676733SJaegeuk Kim return 0; 2035ea676733SJaegeuk Kim } 2036ea676733SJaegeuk Kim 2037ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 2038ced2c7eaSKinglong Mee { 2039ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 2040ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 2041ced2c7eaSKinglong Mee } 2042ced2c7eaSKinglong Mee 2043aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 204425ca923bSJaegeuk Kim { 204525ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 2046aaec2b1dSChao Yu 204725ca923bSJaegeuk Kim return ckpt_flags & f; 204825ca923bSJaegeuk Kim } 204925ca923bSJaegeuk Kim 2050aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 205125ca923bSJaegeuk Kim { 2052aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 2053aaec2b1dSChao Yu } 2054aaec2b1dSChao Yu 2055aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 2056aaec2b1dSChao Yu { 2057aaec2b1dSChao Yu unsigned int ckpt_flags; 2058aaec2b1dSChao Yu 2059aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 206025ca923bSJaegeuk Kim ckpt_flags |= f; 206125ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 206225ca923bSJaegeuk Kim } 206325ca923bSJaegeuk Kim 2064aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 206525ca923bSJaegeuk Kim { 2066d1aa2453SChao Yu unsigned long flags; 2067d1aa2453SChao Yu 2068d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 2069aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 2070d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 2071aaec2b1dSChao Yu } 2072aaec2b1dSChao Yu 2073aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 2074aaec2b1dSChao Yu { 2075aaec2b1dSChao Yu unsigned int ckpt_flags; 2076aaec2b1dSChao Yu 2077aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 207825ca923bSJaegeuk Kim ckpt_flags &= (~f); 207925ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 208025ca923bSJaegeuk Kim } 208125ca923bSJaegeuk Kim 2082aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 2083aaec2b1dSChao Yu { 2084d1aa2453SChao Yu unsigned long flags; 2085d1aa2453SChao Yu 2086d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 2087aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 2088d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 2089aaec2b1dSChao Yu } 2090aaec2b1dSChao Yu 2091e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 209239a53e0cSJaegeuk Kim { 2093b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 209439a53e0cSJaegeuk Kim } 209539a53e0cSJaegeuk Kim 2096cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 2097cc15620bSJaegeuk Kim { 2098cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 2099cc15620bSJaegeuk Kim } 2100cc15620bSJaegeuk Kim 2101e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 210239a53e0cSJaegeuk Kim { 2103b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 210439936837SJaegeuk Kim } 210539936837SJaegeuk Kim 2106e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 210739936837SJaegeuk Kim { 2108b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 210939936837SJaegeuk Kim } 211039936837SJaegeuk Kim 2111e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 211239936837SJaegeuk Kim { 2113b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 211439a53e0cSJaegeuk Kim } 211539a53e0cSJaegeuk Kim 2116119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 2117119ee914SJaegeuk Kim { 2118119ee914SJaegeuk Kim int reason = CP_SYNC; 2119119ee914SJaegeuk Kim 2120119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 2121119ee914SJaegeuk Kim reason = CP_FASTBOOT; 2122119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 2123119ee914SJaegeuk Kim reason = CP_UMOUNT; 2124119ee914SJaegeuk Kim return reason; 2125119ee914SJaegeuk Kim } 2126119ee914SJaegeuk Kim 2127119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 2128119ee914SJaegeuk Kim { 2129c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 2130119ee914SJaegeuk Kim } 2131119ee914SJaegeuk Kim 2132119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 2133119ee914SJaegeuk Kim { 2134aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 2135aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 2136119ee914SJaegeuk Kim } 2137119ee914SJaegeuk Kim 213839a53e0cSJaegeuk Kim /* 213939a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 214039a53e0cSJaegeuk Kim */ 214139a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 214239a53e0cSJaegeuk Kim { 21430eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 21440eb0adadSChao Yu 2145000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 214639a53e0cSJaegeuk Kim } 214739a53e0cSJaegeuk Kim 21484bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 21494bc8e9bcSChao Yu { 21504bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 21514bc8e9bcSChao Yu } 21524bc8e9bcSChao Yu 2153d8a9a229SJaegeuk Kim static inline bool __allow_reserved_blocks(struct f2fs_sb_info *sbi, 2154a90a0884SJaegeuk Kim struct inode *inode, bool cap) 21557c2e5963SJaegeuk Kim { 2156d8a9a229SJaegeuk Kim if (!inode) 2157d8a9a229SJaegeuk Kim return true; 21587c2e5963SJaegeuk Kim if (!test_opt(sbi, RESERVE_ROOT)) 21597c2e5963SJaegeuk Kim return false; 2160d8a9a229SJaegeuk Kim if (IS_NOQUOTA(inode)) 2161d8a9a229SJaegeuk Kim return true; 216263189b78SChao Yu if (uid_eq(F2FS_OPTION(sbi).s_resuid, current_fsuid())) 21637c2e5963SJaegeuk Kim return true; 216463189b78SChao Yu if (!gid_eq(F2FS_OPTION(sbi).s_resgid, GLOBAL_ROOT_GID) && 216563189b78SChao Yu in_group_p(F2FS_OPTION(sbi).s_resgid)) 21667c2e5963SJaegeuk Kim return true; 2167a90a0884SJaegeuk Kim if (cap && capable(CAP_SYS_RESOURCE)) 2168162b27aeSJaegeuk Kim return true; 21697c2e5963SJaegeuk Kim return false; 21707c2e5963SJaegeuk Kim } 21717c2e5963SJaegeuk Kim 21720abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 21730abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 217446008c6dSChao Yu struct inode *inode, blkcnt_t *count) 217539a53e0cSJaegeuk Kim { 21760abd675eSChao Yu blkcnt_t diff = 0, release = 0; 2177daeb433eSChao Yu block_t avail_user_block_count; 21780abd675eSChao Yu int ret; 21790abd675eSChao Yu 21800abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 21810abd675eSChao Yu if (ret) 21820abd675eSChao Yu return ret; 2183dd11a5dfSJaegeuk Kim 218455523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 2185c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_BLOCK); 21860abd675eSChao Yu release = *count; 21879ea2f0beSChao Yu goto release_quota; 218855523519SChao Yu } 21897fa750a1SArnd Bergmann 2190dd11a5dfSJaegeuk Kim /* 2191dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 2192dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 2193dd11a5dfSJaegeuk Kim */ 2194dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 219539a53e0cSJaegeuk Kim 219639a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 21972555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 219880d42145SYunlong Song avail_user_block_count = sbi->user_block_count - 219980d42145SYunlong Song sbi->current_reserved_blocks; 22007e65be49SJaegeuk Kim 2201a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, true)) 220263189b78SChao Yu avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; 2203a4c3ecaaSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { 2204a4c3ecaaSDaniel Rosenberg if (avail_user_block_count > sbi->unusable_block_count) 22054354994fSDaniel Rosenberg avail_user_block_count -= sbi->unusable_block_count; 2206a4c3ecaaSDaniel Rosenberg else 2207a4c3ecaaSDaniel Rosenberg avail_user_block_count = 0; 2208a4c3ecaaSDaniel Rosenberg } 2209daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 2210daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 22117e65be49SJaegeuk Kim if (diff > *count) 22127e65be49SJaegeuk Kim diff = *count; 2213dd11a5dfSJaegeuk Kim *count -= diff; 22140abd675eSChao Yu release = diff; 22157e65be49SJaegeuk Kim sbi->total_valid_block_count -= diff; 221646008c6dSChao Yu if (!*count) { 221739a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 22180abd675eSChao Yu goto enospc; 221939a53e0cSJaegeuk Kim } 222046008c6dSChao Yu } 222139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 222241382ec4SJaegeuk Kim 222336b877afSDaniel Rosenberg if (unlikely(release)) { 222436b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 22250abd675eSChao Yu dquot_release_reservation_block(inode, release); 222636b877afSDaniel Rosenberg } 22270abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 22280abd675eSChao Yu return 0; 22290abd675eSChao Yu 22300abd675eSChao Yu enospc: 223136b877afSDaniel Rosenberg percpu_counter_sub(&sbi->alloc_valid_block_count, release); 22329ea2f0beSChao Yu release_quota: 22330abd675eSChao Yu dquot_release_reservation_block(inode, release); 22340abd675eSChao Yu return -ENOSPC; 223539a53e0cSJaegeuk Kim } 223639a53e0cSJaegeuk Kim 2237dcbb4c10SJoe Perches __printf(2, 3) 2238dcbb4c10SJoe Perches void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...); 2239dcbb4c10SJoe Perches 2240dcbb4c10SJoe Perches #define f2fs_err(sbi, fmt, ...) \ 2241dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_ERR fmt, ##__VA_ARGS__) 2242dcbb4c10SJoe Perches #define f2fs_warn(sbi, fmt, ...) \ 2243dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_WARNING fmt, ##__VA_ARGS__) 2244dcbb4c10SJoe Perches #define f2fs_notice(sbi, fmt, ...) \ 2245dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_NOTICE fmt, ##__VA_ARGS__) 2246dcbb4c10SJoe Perches #define f2fs_info(sbi, fmt, ...) \ 2247dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_INFO fmt, ##__VA_ARGS__) 2248dcbb4c10SJoe Perches #define f2fs_debug(sbi, fmt, ...) \ 2249dcbb4c10SJoe Perches f2fs_printk(sbi, KERN_DEBUG fmt, ##__VA_ARGS__) 2250dcbb4c10SJoe Perches 2251da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 225239a53e0cSJaegeuk Kim struct inode *inode, 22530eb0adadSChao Yu block_t count) 225439a53e0cSJaegeuk Kim { 22550eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 22560eb0adadSChao Yu 225739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 22589850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 225939a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 226080d42145SYunlong Song if (sbi->reserved_blocks && 226180d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 226280d42145SYunlong Song sbi->current_reserved_blocks = min(sbi->reserved_blocks, 226380d42145SYunlong Song sbi->current_reserved_blocks + count); 226439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 22655e159cd3SChao Yu if (unlikely(inode->i_blocks < sectors)) { 2266dcbb4c10SJoe Perches f2fs_warn(sbi, "Inconsistent i_blocks, ino:%lu, iblocks:%llu, sectors:%llu", 22675e159cd3SChao Yu inode->i_ino, 22685e159cd3SChao Yu (unsigned long long)inode->i_blocks, 22695e159cd3SChao Yu (unsigned long long)sectors); 22705e159cd3SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 22715e159cd3SChao Yu return; 22725e159cd3SChao Yu } 22730abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 227439a53e0cSJaegeuk Kim } 227539a53e0cSJaegeuk Kim 227639a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 227739a53e0cSJaegeuk Kim { 227835782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 22797c4abcbeSChao Yu 228020109873SChao Yu if (count_type == F2FS_DIRTY_DENTS || 228120109873SChao Yu count_type == F2FS_DIRTY_NODES || 228220109873SChao Yu count_type == F2FS_DIRTY_META || 228320109873SChao Yu count_type == F2FS_DIRTY_QDATA || 228420109873SChao Yu count_type == F2FS_DIRTY_IMETA) 2285caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 228639a53e0cSJaegeuk Kim } 228739a53e0cSJaegeuk Kim 2288a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 228939a53e0cSJaegeuk Kim { 2290204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 2291c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 2292c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 22932c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 22942c8a4a28SJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 229539a53e0cSJaegeuk Kim } 229639a53e0cSJaegeuk Kim 229739a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 229839a53e0cSJaegeuk Kim { 229935782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 230039a53e0cSJaegeuk Kim } 230139a53e0cSJaegeuk Kim 2302a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 230339a53e0cSJaegeuk Kim { 23045ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 23055ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 23061fe54f9dSJaegeuk Kim return; 23071fe54f9dSJaegeuk Kim 2308204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 2309c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 2310c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 23112c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 23122c8a4a28SJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 231339a53e0cSJaegeuk Kim } 231439a53e0cSJaegeuk Kim 2315523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 231639a53e0cSJaegeuk Kim { 231735782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 231839a53e0cSJaegeuk Kim } 231939a53e0cSJaegeuk Kim 2320204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 2321f8b2c1f9SJaegeuk Kim { 2322204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 2323f8b2c1f9SJaegeuk Kim } 2324f8b2c1f9SJaegeuk Kim 23255ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 23265ac206cfSNamjae Jeon { 23273519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 2328523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 2329523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 2330523be8a6SJaegeuk Kim 2331523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 23325ac206cfSNamjae Jeon } 23335ac206cfSNamjae Jeon 233439a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 233539a53e0cSJaegeuk Kim { 23368b8343faSJaegeuk Kim return sbi->total_valid_block_count; 233739a53e0cSJaegeuk Kim } 233839a53e0cSJaegeuk Kim 2339f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 2340f83a2584SYunlei He { 2341f83a2584SYunlei He return sbi->discard_blks; 2342f83a2584SYunlei He } 2343f83a2584SYunlei He 234439a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 234539a53e0cSJaegeuk Kim { 234639a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 234739a53e0cSJaegeuk Kim 234839a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 234939a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 235039a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 235139a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 235239a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 235339a53e0cSJaegeuk Kim 235439a53e0cSJaegeuk Kim return 0; 235539a53e0cSJaegeuk Kim } 235639a53e0cSJaegeuk Kim 235755141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 235855141486SWanpeng Li { 235955141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 236055141486SWanpeng Li } 236155141486SWanpeng Li 236239a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 236339a53e0cSJaegeuk Kim { 236439a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 23654260c406SGustavo A. R. Silva void *tmp_ptr = &ckpt->sit_nat_version_bitmap; 23661dbe4152SChangman Lee int offset; 23671dbe4152SChangman Lee 2368199bc3feSChao Yu if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { 2369199bc3feSChao Yu offset = (flag == SIT_BITMAP) ? 2370199bc3feSChao Yu le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; 2371b471eb99SChao Yu /* 2372b471eb99SChao Yu * if large_nat_bitmap feature is enabled, leave checksum 2373b471eb99SChao Yu * protection for all nat/sit bitmaps. 2374b471eb99SChao Yu */ 23754260c406SGustavo A. R. Silva return tmp_ptr + offset + sizeof(__le32); 2376199bc3feSChao Yu } 2377199bc3feSChao Yu 237855141486SWanpeng Li if (__cp_payload(sbi) > 0) { 23791dbe4152SChangman Lee if (flag == NAT_BITMAP) 23801dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 23811dbe4152SChangman Lee else 238265b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 23831dbe4152SChangman Lee } else { 23841dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 238525ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 23864260c406SGustavo A. R. Silva return tmp_ptr + offset; 238739a53e0cSJaegeuk Kim } 23881dbe4152SChangman Lee } 238939a53e0cSJaegeuk Kim 239039a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 239139a53e0cSJaegeuk Kim { 23928508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 239339a53e0cSJaegeuk Kim 23948508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 239539a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 239639a53e0cSJaegeuk Kim return start_addr; 239739a53e0cSJaegeuk Kim } 239839a53e0cSJaegeuk Kim 23998508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 24008508e44aSJaegeuk Kim { 24018508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 24028508e44aSJaegeuk Kim 24038508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 24048508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 24058508e44aSJaegeuk Kim return start_addr; 24068508e44aSJaegeuk Kim } 24078508e44aSJaegeuk Kim 24088508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 24098508e44aSJaegeuk Kim { 24108508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 24118508e44aSJaegeuk Kim } 24128508e44aSJaegeuk Kim 241339a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 241439a53e0cSJaegeuk Kim { 241539a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 241639a53e0cSJaegeuk Kim } 241739a53e0cSJaegeuk Kim 24180abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 2419000519f2SChao Yu struct inode *inode, bool is_inode) 242039a53e0cSJaegeuk Kim { 242139a53e0cSJaegeuk Kim block_t valid_block_count; 2422a4c3ecaaSDaniel Rosenberg unsigned int valid_node_count, user_block_count; 2423af033b2aSChao Yu int err; 24240abd675eSChao Yu 2425af033b2aSChao Yu if (is_inode) { 2426af033b2aSChao Yu if (inode) { 2427af033b2aSChao Yu err = dquot_alloc_inode(inode); 2428af033b2aSChao Yu if (err) 2429af033b2aSChao Yu return err; 2430af033b2aSChao Yu } 2431af033b2aSChao Yu } else { 2432af033b2aSChao Yu err = dquot_reserve_block(inode, 1); 2433af033b2aSChao Yu if (err) 2434af033b2aSChao Yu return err; 24350abd675eSChao Yu } 243639a53e0cSJaegeuk Kim 2437812c6056SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 2438c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_BLOCK); 2439812c6056SChao Yu goto enospc; 2440812c6056SChao Yu } 2441812c6056SChao Yu 244239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 244339a53e0cSJaegeuk Kim 24447e65be49SJaegeuk Kim valid_block_count = sbi->total_valid_block_count + 24457e65be49SJaegeuk Kim sbi->current_reserved_blocks + 1; 24467e65be49SJaegeuk Kim 2447a90a0884SJaegeuk Kim if (!__allow_reserved_blocks(sbi, inode, false)) 244863189b78SChao Yu valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; 2449a4c3ecaaSDaniel Rosenberg user_block_count = sbi->user_block_count; 24504354994fSDaniel Rosenberg if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) 2451a4c3ecaaSDaniel Rosenberg user_block_count -= sbi->unusable_block_count; 24527e65be49SJaegeuk Kim 2453a4c3ecaaSDaniel Rosenberg if (unlikely(valid_block_count > user_block_count)) { 245439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 24550abd675eSChao Yu goto enospc; 245639a53e0cSJaegeuk Kim } 245739a53e0cSJaegeuk Kim 2458ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 2459cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 246039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 24610abd675eSChao Yu goto enospc; 246239a53e0cSJaegeuk Kim } 246339a53e0cSJaegeuk Kim 2464ef86d709SGu Zheng sbi->total_valid_node_count++; 2465ef86d709SGu Zheng sbi->total_valid_block_count++; 246639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 246739a53e0cSJaegeuk Kim 24680abd675eSChao Yu if (inode) { 24690abd675eSChao Yu if (is_inode) 24700abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 24710abd675eSChao Yu else 24720abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 24730abd675eSChao Yu } 24740abd675eSChao Yu 247541382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 24760abd675eSChao Yu return 0; 24770abd675eSChao Yu 24780abd675eSChao Yu enospc: 2479af033b2aSChao Yu if (is_inode) { 2480af033b2aSChao Yu if (inode) 2481af033b2aSChao Yu dquot_free_inode(inode); 2482af033b2aSChao Yu } else { 24830abd675eSChao Yu dquot_release_reservation_block(inode, 1); 2484af033b2aSChao Yu } 24850abd675eSChao Yu return -ENOSPC; 248639a53e0cSJaegeuk Kim } 248739a53e0cSJaegeuk Kim 248839a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 2489000519f2SChao Yu struct inode *inode, bool is_inode) 249039a53e0cSJaegeuk Kim { 249139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 249239a53e0cSJaegeuk Kim 24939850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 24949850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 249539a53e0cSJaegeuk Kim 2496ef86d709SGu Zheng sbi->total_valid_node_count--; 2497ef86d709SGu Zheng sbi->total_valid_block_count--; 249880d42145SYunlong Song if (sbi->reserved_blocks && 249980d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 250080d42145SYunlong Song sbi->current_reserved_blocks++; 250139a53e0cSJaegeuk Kim 250239a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 25030abd675eSChao Yu 2504ea6d7e72SChao Yu if (is_inode) { 2505af033b2aSChao Yu dquot_free_inode(inode); 2506ea6d7e72SChao Yu } else { 2507ea6d7e72SChao Yu if (unlikely(inode->i_blocks == 0)) { 2508097a7686SChao Yu f2fs_warn(sbi, "dec_valid_node_count: inconsistent i_blocks, ino:%lu, iblocks:%llu", 2509ea6d7e72SChao Yu inode->i_ino, 2510ea6d7e72SChao Yu (unsigned long long)inode->i_blocks); 2511ea6d7e72SChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); 2512ea6d7e72SChao Yu return; 2513ea6d7e72SChao Yu } 25140abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 251539a53e0cSJaegeuk Kim } 2516ea6d7e72SChao Yu } 251739a53e0cSJaegeuk Kim 251839a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 251939a53e0cSJaegeuk Kim { 25208b8343faSJaegeuk Kim return sbi->total_valid_node_count; 252139a53e0cSJaegeuk Kim } 252239a53e0cSJaegeuk Kim 252339a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 252439a53e0cSJaegeuk Kim { 2525513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 252639a53e0cSJaegeuk Kim } 252739a53e0cSJaegeuk Kim 25280e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 252939a53e0cSJaegeuk Kim { 2530513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 253139a53e0cSJaegeuk Kim } 253239a53e0cSJaegeuk Kim 2533513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 253439a53e0cSJaegeuk Kim { 2535513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 253639a53e0cSJaegeuk Kim } 253739a53e0cSJaegeuk Kim 2538a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 2539a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 2540a56c7c6fSJaegeuk Kim { 254182cf4f13SChao Yu struct page *page; 2542cac5a3d8SDongOh Shin 25437fa750a1SArnd Bergmann if (IS_ENABLED(CONFIG_F2FS_FAULT_INJECTION)) { 254482cf4f13SChao Yu if (!for_write) 254582cf4f13SChao Yu page = find_get_page_flags(mapping, index, 254682cf4f13SChao Yu FGP_LOCK | FGP_ACCESSED); 254782cf4f13SChao Yu else 254882cf4f13SChao Yu page = find_lock_page(mapping, index); 2549c41f3cc3SJaegeuk Kim if (page) 2550c41f3cc3SJaegeuk Kim return page; 2551c41f3cc3SJaegeuk Kim 255255523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 2553c45d6002SChao Yu f2fs_show_injection_info(F2FS_M_SB(mapping), 2554c45d6002SChao Yu FAULT_PAGE_ALLOC); 2555c41f3cc3SJaegeuk Kim return NULL; 255655523519SChao Yu } 25577fa750a1SArnd Bergmann } 25587fa750a1SArnd Bergmann 2559a56c7c6fSJaegeuk Kim if (!for_write) 2560a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 2561a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 2562a56c7c6fSJaegeuk Kim } 2563a56c7c6fSJaegeuk Kim 256401eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page( 256501eccef7SChao Yu struct address_space *mapping, pgoff_t index, 256601eccef7SChao Yu int fgp_flags, gfp_t gfp_mask) 256701eccef7SChao Yu { 256801eccef7SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { 2569c45d6002SChao Yu f2fs_show_injection_info(F2FS_M_SB(mapping), FAULT_PAGE_GET); 257001eccef7SChao Yu return NULL; 257101eccef7SChao Yu } 25727fa750a1SArnd Bergmann 257301eccef7SChao Yu return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); 257401eccef7SChao Yu } 257501eccef7SChao Yu 25766e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 25776e2c64adSJaegeuk Kim { 25786e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 25796e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 25806e2c64adSJaegeuk Kim 25816e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 25826e2c64adSJaegeuk Kim kunmap(dst); 25836e2c64adSJaegeuk Kim kunmap(src); 25846e2c64adSJaegeuk Kim } 25856e2c64adSJaegeuk Kim 258639a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 258739a53e0cSJaegeuk Kim { 2588031fa8ccSJaegeuk Kim if (!page) 258939a53e0cSJaegeuk Kim return; 259039a53e0cSJaegeuk Kim 259139a53e0cSJaegeuk Kim if (unlock) { 25929850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 259339a53e0cSJaegeuk Kim unlock_page(page); 259439a53e0cSJaegeuk Kim } 259509cbfeafSKirill A. Shutemov put_page(page); 259639a53e0cSJaegeuk Kim } 259739a53e0cSJaegeuk Kim 259839a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 259939a53e0cSJaegeuk Kim { 260039a53e0cSJaegeuk Kim if (dn->node_page) 260139a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 260239a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 260339a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 260439a53e0cSJaegeuk Kim dn->node_page = NULL; 260539a53e0cSJaegeuk Kim dn->inode_page = NULL; 260639a53e0cSJaegeuk Kim } 260739a53e0cSJaegeuk Kim 260839a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 2609e8512d2eSGu Zheng size_t size) 261039a53e0cSJaegeuk Kim { 2611e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 261239a53e0cSJaegeuk Kim } 261339a53e0cSJaegeuk Kim 261432410577SChao Yu static inline void *f2fs_kmem_cache_alloc_nofail(struct kmem_cache *cachep, 26157bd59381SGu Zheng gfp_t flags) 26167bd59381SGu Zheng { 26177bd59381SGu Zheng void *entry; 26187bd59381SGu Zheng 261980c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 262080c54505SJaegeuk Kim if (!entry) 262180c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 26227bd59381SGu Zheng return entry; 26237bd59381SGu Zheng } 26247bd59381SGu Zheng 262532410577SChao Yu static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 262632410577SChao Yu gfp_t flags, bool nofail, struct f2fs_sb_info *sbi) 262732410577SChao Yu { 262832410577SChao Yu if (nofail) 262932410577SChao Yu return f2fs_kmem_cache_alloc_nofail(cachep, flags); 263032410577SChao Yu 263132410577SChao Yu if (time_to_inject(sbi, FAULT_SLAB_ALLOC)) { 263232410577SChao Yu f2fs_show_injection_info(sbi, FAULT_SLAB_ALLOC); 263332410577SChao Yu return NULL; 263432410577SChao Yu } 263532410577SChao Yu 263632410577SChao Yu return kmem_cache_alloc(cachep, flags); 263732410577SChao Yu } 263832410577SChao Yu 2639493720a4SChao Yu static inline bool is_inflight_io(struct f2fs_sb_info *sbi, int type) 26405f9abab4SJaegeuk Kim { 26415f9abab4SJaegeuk Kim if (get_pages(sbi, F2FS_RD_DATA) || get_pages(sbi, F2FS_RD_NODE) || 26425f9abab4SJaegeuk Kim get_pages(sbi, F2FS_RD_META) || get_pages(sbi, F2FS_WB_DATA) || 2643fef4129eSChao Yu get_pages(sbi, F2FS_WB_CP_DATA) || 2644fef4129eSChao Yu get_pages(sbi, F2FS_DIO_READ) || 264511ac8ef8SJaegeuk Kim get_pages(sbi, F2FS_DIO_WRITE)) 2646493720a4SChao Yu return true; 264711ac8ef8SJaegeuk Kim 264856659ce8SSahitya Tummala if (type != DISCARD_TIME && SM_I(sbi) && SM_I(sbi)->dcc_info && 264911ac8ef8SJaegeuk Kim atomic_read(&SM_I(sbi)->dcc_info->queued_discard)) 2650493720a4SChao Yu return true; 265111ac8ef8SJaegeuk Kim 265211ac8ef8SJaegeuk Kim if (SM_I(sbi) && SM_I(sbi)->fcc_info && 265372691af6SJaegeuk Kim atomic_read(&SM_I(sbi)->fcc_info->queued_flush)) 2654493720a4SChao Yu return true; 2655493720a4SChao Yu return false; 2656493720a4SChao Yu } 2657493720a4SChao Yu 2658493720a4SChao Yu static inline bool is_idle(struct f2fs_sb_info *sbi, int type) 2659493720a4SChao Yu { 2660493720a4SChao Yu if (sbi->gc_mode == GC_URGENT_HIGH) 2661493720a4SChao Yu return true; 2662493720a4SChao Yu 2663493720a4SChao Yu if (is_inflight_io(sbi, type)) 26645f9abab4SJaegeuk Kim return false; 266511ac8ef8SJaegeuk Kim 26660e5e8111SDaeho Jeong if (sbi->gc_mode == GC_URGENT_LOW && 26670e5e8111SDaeho Jeong (type == DISCARD_TIME || type == GC_TIME)) 26680e5e8111SDaeho Jeong return true; 26690e5e8111SDaeho Jeong 26705f9abab4SJaegeuk Kim return f2fs_time_over(sbi, type); 26715f9abab4SJaegeuk Kim } 26725f9abab4SJaegeuk Kim 26739be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 26749be32d72SJaegeuk Kim unsigned long index, void *item) 26759be32d72SJaegeuk Kim { 26769be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 26779be32d72SJaegeuk Kim cond_resched(); 26789be32d72SJaegeuk Kim } 26799be32d72SJaegeuk Kim 268039a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 268139a53e0cSJaegeuk Kim 268239a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 268339a53e0cSJaegeuk Kim { 268445590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 2685cac5a3d8SDongOh Shin 268639a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 268739a53e0cSJaegeuk Kim } 268839a53e0cSJaegeuk Kim 26897a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 26907a2af766SChao Yu { 26917a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 26927a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 26937a2af766SChao Yu } 26947a2af766SChao Yu 269539a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 269639a53e0cSJaegeuk Kim { 269739a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 269839a53e0cSJaegeuk Kim } 269939a53e0cSJaegeuk Kim 27007a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 2701a2ced1ceSChao Yu static inline block_t data_blkaddr(struct inode *inode, 27027a2af766SChao Yu struct page *node_page, unsigned int offset) 270339a53e0cSJaegeuk Kim { 270439a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 270539a53e0cSJaegeuk Kim __le32 *addr_array; 27067a2af766SChao Yu int base = 0; 27077a2af766SChao Yu bool is_inode = IS_INODE(node_page); 2708cac5a3d8SDongOh Shin 270945590710SGu Zheng raw_node = F2FS_NODE(node_page); 27107a2af766SChao Yu 2711979f492fSLiFan if (is_inode) { 2712979f492fSLiFan if (!inode) 27137a88ddb5SChao Yu /* from GC path only */ 27147a2af766SChao Yu base = offset_in_addr(&raw_node->i); 2715979f492fSLiFan else if (f2fs_has_extra_attr(inode)) 27167a2af766SChao Yu base = get_extra_isize(inode); 27177a2af766SChao Yu } 27187a2af766SChao Yu 271939a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 27207a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 272139a53e0cSJaegeuk Kim } 272239a53e0cSJaegeuk Kim 2723a2ced1ceSChao Yu static inline block_t f2fs_data_blkaddr(struct dnode_of_data *dn) 2724a2ced1ceSChao Yu { 2725a2ced1ceSChao Yu return data_blkaddr(dn->inode, dn->node_page, dn->ofs_in_node); 2726a2ced1ceSChao Yu } 2727a2ced1ceSChao Yu 272839a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 272939a53e0cSJaegeuk Kim { 273039a53e0cSJaegeuk Kim int mask; 273139a53e0cSJaegeuk Kim 273239a53e0cSJaegeuk Kim addr += (nr >> 3); 273339a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 273439a53e0cSJaegeuk Kim return mask & *addr; 273539a53e0cSJaegeuk Kim } 273639a53e0cSJaegeuk Kim 2737a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 2738a66cdd98SJaegeuk Kim { 2739a66cdd98SJaegeuk Kim int mask; 2740a66cdd98SJaegeuk Kim 2741a66cdd98SJaegeuk Kim addr += (nr >> 3); 2742a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2743a66cdd98SJaegeuk Kim *addr |= mask; 2744a66cdd98SJaegeuk Kim } 2745a66cdd98SJaegeuk Kim 2746a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 2747a66cdd98SJaegeuk Kim { 2748a66cdd98SJaegeuk Kim int mask; 2749a66cdd98SJaegeuk Kim 2750a66cdd98SJaegeuk Kim addr += (nr >> 3); 2751a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2752a66cdd98SJaegeuk Kim *addr &= ~mask; 2753a66cdd98SJaegeuk Kim } 2754a66cdd98SJaegeuk Kim 275552aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 275639a53e0cSJaegeuk Kim { 275739a53e0cSJaegeuk Kim int mask; 275839a53e0cSJaegeuk Kim int ret; 275939a53e0cSJaegeuk Kim 276039a53e0cSJaegeuk Kim addr += (nr >> 3); 276139a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 276239a53e0cSJaegeuk Kim ret = mask & *addr; 276339a53e0cSJaegeuk Kim *addr |= mask; 276439a53e0cSJaegeuk Kim return ret; 276539a53e0cSJaegeuk Kim } 276639a53e0cSJaegeuk Kim 276752aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 276839a53e0cSJaegeuk Kim { 276939a53e0cSJaegeuk Kim int mask; 277039a53e0cSJaegeuk Kim int ret; 277139a53e0cSJaegeuk Kim 277239a53e0cSJaegeuk Kim addr += (nr >> 3); 277339a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 277439a53e0cSJaegeuk Kim ret = mask & *addr; 277539a53e0cSJaegeuk Kim *addr &= ~mask; 277639a53e0cSJaegeuk Kim return ret; 277739a53e0cSJaegeuk Kim } 277839a53e0cSJaegeuk Kim 2779c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 2780c6ac4c0eSGu Zheng { 2781c6ac4c0eSGu Zheng int mask; 2782c6ac4c0eSGu Zheng 2783c6ac4c0eSGu Zheng addr += (nr >> 3); 2784c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 2785c6ac4c0eSGu Zheng *addr ^= mask; 2786c6ac4c0eSGu Zheng } 2787c6ac4c0eSGu Zheng 278859c84408SChao Yu /* 278936098557SEric Biggers * On-disk inode flags (f2fs_inode::i_flags) 279059c84408SChao Yu */ 27914c8ff709SChao Yu #define F2FS_COMPR_FL 0x00000004 /* Compress file */ 279259c84408SChao Yu #define F2FS_SYNC_FL 0x00000008 /* Synchronous updates */ 279359c84408SChao Yu #define F2FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ 279459c84408SChao Yu #define F2FS_APPEND_FL 0x00000020 /* writes to file may only append */ 279559c84408SChao Yu #define F2FS_NODUMP_FL 0x00000040 /* do not dump file */ 279659c84408SChao Yu #define F2FS_NOATIME_FL 0x00000080 /* do not update atime */ 27974c8ff709SChao Yu #define F2FS_NOCOMP_FL 0x00000400 /* Don't compress */ 279859c84408SChao Yu #define F2FS_INDEX_FL 0x00001000 /* hash-indexed directory */ 279959c84408SChao Yu #define F2FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 280059c84408SChao Yu #define F2FS_PROJINHERIT_FL 0x20000000 /* Create with parents projid */ 28012c2eb7a3SDaniel Rosenberg #define F2FS_CASEFOLD_FL 0x40000000 /* Casefolded file */ 280259c84408SChao Yu 280359c84408SChao Yu /* Flags that should be inherited by new inodes from their parent. */ 280436098557SEric Biggers #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \ 28052c2eb7a3SDaniel Rosenberg F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 28064c8ff709SChao Yu F2FS_CASEFOLD_FL | F2FS_COMPR_FL | F2FS_NOCOMP_FL) 280759c84408SChao Yu 280859c84408SChao Yu /* Flags that are appropriate for regular files (all but dir-specific ones). */ 28092c2eb7a3SDaniel Rosenberg #define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \ 28102c2eb7a3SDaniel Rosenberg F2FS_CASEFOLD_FL)) 281159c84408SChao Yu 281259c84408SChao Yu /* Flags that are appropriate for non-directories/regular files. */ 281359c84408SChao Yu #define F2FS_OTHER_FLMASK (F2FS_NODUMP_FL | F2FS_NOATIME_FL) 28145c57132eSChao Yu 28155c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 28165c57132eSChao Yu { 28175c57132eSChao Yu if (S_ISDIR(mode)) 28185c57132eSChao Yu return flags; 28195c57132eSChao Yu else if (S_ISREG(mode)) 28205c57132eSChao Yu return flags & F2FS_REG_FLMASK; 28215c57132eSChao Yu else 28225c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 28235c57132eSChao Yu } 28245c57132eSChao Yu 2825205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2826205b9822SJaegeuk Kim int flag, bool set) 282739a53e0cSJaegeuk Kim { 2828205b9822SJaegeuk Kim switch (flag) { 2829205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2830205b9822SJaegeuk Kim case FI_INLINE_DATA: 2831205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 28329ac1e2d8SDaeho Jeong case FI_NEW_INODE: 2833205b9822SJaegeuk Kim if (set) 2834205b9822SJaegeuk Kim return; 2835df561f66SGustavo A. R. Silva fallthrough; 2836205b9822SJaegeuk Kim case FI_DATA_EXIST: 2837205b9822SJaegeuk Kim case FI_INLINE_DOTS: 28381ad71a27SJaegeuk Kim case FI_PIN_FILE: 2839c6140415SJaegeuk Kim case FI_COMPRESS_RELEASED: 28407c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2841205b9822SJaegeuk Kim } 284239a53e0cSJaegeuk Kim } 284339a53e0cSJaegeuk Kim 284491942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 284539a53e0cSJaegeuk Kim { 284658f7e00fSYufen Yu set_bit(flag, F2FS_I(inode)->flags); 2847205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 284839a53e0cSJaegeuk Kim } 284939a53e0cSJaegeuk Kim 285091942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 285139a53e0cSJaegeuk Kim { 28527653b9d8SChao Yu return test_bit(flag, F2FS_I(inode)->flags); 285339a53e0cSJaegeuk Kim } 285439a53e0cSJaegeuk Kim 285591942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 285639a53e0cSJaegeuk Kim { 285758f7e00fSYufen Yu clear_bit(flag, F2FS_I(inode)->flags); 2858205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 285939a53e0cSJaegeuk Kim } 286039a53e0cSJaegeuk Kim 286195ae251fSEric Biggers static inline bool f2fs_verity_in_progress(struct inode *inode) 286295ae251fSEric Biggers { 286395ae251fSEric Biggers return IS_ENABLED(CONFIG_FS_VERITY) && 286495ae251fSEric Biggers is_inode_flag_set(inode, FI_VERITY_IN_PROGRESS); 286595ae251fSEric Biggers } 286695ae251fSEric Biggers 286791942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2868444c580fSJaegeuk Kim { 286991942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 287091942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 28717c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 287239a53e0cSJaegeuk Kim } 287339a53e0cSJaegeuk Kim 2874a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2875a1961246SJaegeuk Kim { 2876a1961246SJaegeuk Kim if (inc) 2877a1961246SJaegeuk Kim inc_nlink(inode); 2878a1961246SJaegeuk Kim else 2879a1961246SJaegeuk Kim drop_nlink(inode); 28807c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2881a1961246SJaegeuk Kim } 2882a1961246SJaegeuk Kim 28838edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 28840abd675eSChao Yu block_t diff, bool add, bool claim) 28858edd03c8SJaegeuk Kim { 288626de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 288726de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 288826de9b11SJaegeuk Kim 28890abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 28900abd675eSChao Yu if (add) { 28910abd675eSChao Yu if (claim) 28920abd675eSChao Yu dquot_claim_block(inode, diff); 28930abd675eSChao Yu else 28940abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 28950abd675eSChao Yu } else { 28960abd675eSChao Yu dquot_free_block(inode, diff); 28970abd675eSChao Yu } 28980abd675eSChao Yu 28997c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 290026de9b11SJaegeuk Kim if (clean || recover) 290126de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 29028edd03c8SJaegeuk Kim } 29038edd03c8SJaegeuk Kim 2904fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2905fc9581c8SJaegeuk Kim { 290626de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 290726de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 290826de9b11SJaegeuk Kim 2909fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2910fc9581c8SJaegeuk Kim return; 2911fc9581c8SJaegeuk Kim 2912fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 29137c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 291426de9b11SJaegeuk Kim if (clean || recover) 291526de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 291626de9b11SJaegeuk Kim } 291726de9b11SJaegeuk Kim 2918205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2919205b9822SJaegeuk Kim { 2920205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 29217c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2922205b9822SJaegeuk Kim } 2923205b9822SJaegeuk Kim 29241ad71a27SJaegeuk Kim static inline void f2fs_i_gc_failures_write(struct inode *inode, 29251ad71a27SJaegeuk Kim unsigned int count) 29261ad71a27SJaegeuk Kim { 29272ef79ecbSChao Yu F2FS_I(inode)->i_gc_failures[GC_FAILURE_PIN] = count; 29281ad71a27SJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 29291ad71a27SJaegeuk Kim } 29301ad71a27SJaegeuk Kim 2931205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2932205b9822SJaegeuk Kim { 2933205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 29347c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2935205b9822SJaegeuk Kim } 2936205b9822SJaegeuk Kim 2937205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2938205b9822SJaegeuk Kim { 2939205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 29407c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2941205b9822SJaegeuk Kim } 2942205b9822SJaegeuk Kim 294391942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2944444c580fSJaegeuk Kim { 2945205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2946205b9822SJaegeuk Kim 2947444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 29487653b9d8SChao Yu set_bit(FI_INLINE_XATTR, fi->flags); 29491001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 29507653b9d8SChao Yu set_bit(FI_INLINE_DATA, fi->flags); 295134d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 29527653b9d8SChao Yu set_bit(FI_INLINE_DENTRY, fi->flags); 2953b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 29547653b9d8SChao Yu set_bit(FI_DATA_EXIST, fi->flags); 2955510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 29567653b9d8SChao Yu set_bit(FI_INLINE_DOTS, fi->flags); 29577a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 29587653b9d8SChao Yu set_bit(FI_EXTRA_ATTR, fi->flags); 29591ad71a27SJaegeuk Kim if (ri->i_inline & F2FS_PIN_FILE) 29607653b9d8SChao Yu set_bit(FI_PIN_FILE, fi->flags); 2961c6140415SJaegeuk Kim if (ri->i_inline & F2FS_COMPRESS_RELEASED) 2962c6140415SJaegeuk Kim set_bit(FI_COMPRESS_RELEASED, fi->flags); 2963444c580fSJaegeuk Kim } 2964444c580fSJaegeuk Kim 296591942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2966444c580fSJaegeuk Kim { 2967444c580fSJaegeuk Kim ri->i_inline = 0; 2968444c580fSJaegeuk Kim 296991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2970444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 297191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 29721001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 297391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 297434d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 297591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2976b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 297791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2978510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 29797a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 29807a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 29811ad71a27SJaegeuk Kim if (is_inode_flag_set(inode, FI_PIN_FILE)) 29821ad71a27SJaegeuk Kim ri->i_inline |= F2FS_PIN_FILE; 2983c6140415SJaegeuk Kim if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) 2984c6140415SJaegeuk Kim ri->i_inline |= F2FS_COMPRESS_RELEASED; 29857a2af766SChao Yu } 29867a2af766SChao Yu 29877a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 29887a2af766SChao Yu { 29897a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2990444c580fSJaegeuk Kim } 2991444c580fSJaegeuk Kim 2992987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2993987c7c31SChao Yu { 299491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2995987c7c31SChao Yu } 2996987c7c31SChao Yu 29974c8ff709SChao Yu static inline int f2fs_compressed_file(struct inode *inode) 29984c8ff709SChao Yu { 29994c8ff709SChao Yu return S_ISREG(inode->i_mode) && 30004c8ff709SChao Yu is_inode_flag_set(inode, FI_COMPRESSED_FILE); 30014c8ff709SChao Yu } 30024c8ff709SChao Yu 3003602a16d5SDaeho Jeong static inline bool f2fs_need_compress_data(struct inode *inode) 3004602a16d5SDaeho Jeong { 3005602a16d5SDaeho Jeong int compress_mode = F2FS_OPTION(F2FS_I_SB(inode)).compress_mode; 3006602a16d5SDaeho Jeong 3007602a16d5SDaeho Jeong if (!f2fs_compressed_file(inode)) 3008602a16d5SDaeho Jeong return false; 3009602a16d5SDaeho Jeong 3010602a16d5SDaeho Jeong if (compress_mode == COMPR_MODE_FS) 3011602a16d5SDaeho Jeong return true; 3012602a16d5SDaeho Jeong else if (compress_mode == COMPR_MODE_USER && 3013602a16d5SDaeho Jeong is_inode_flag_set(inode, FI_ENABLE_COMPRESS)) 3014602a16d5SDaeho Jeong return true; 3015602a16d5SDaeho Jeong 3016602a16d5SDaeho Jeong return false; 3017602a16d5SDaeho Jeong } 3018602a16d5SDaeho Jeong 301981ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 3020de93653fSJaegeuk Kim { 3021d02a6e61SChao Yu unsigned int addrs = CUR_ADDRS_PER_INODE(inode) - 3022d02a6e61SChao Yu get_inline_xattr_addrs(inode); 30234c8ff709SChao Yu 30244c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 30254c8ff709SChao Yu return addrs; 30264c8ff709SChao Yu return ALIGN_DOWN(addrs, F2FS_I(inode)->i_cluster_size); 3027d02a6e61SChao Yu } 3028d02a6e61SChao Yu 3029d02a6e61SChao Yu static inline unsigned int addrs_per_block(struct inode *inode) 3030d02a6e61SChao Yu { 30314c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 30324c8ff709SChao Yu return DEF_ADDRS_PER_BLOCK; 30334c8ff709SChao Yu return ALIGN_DOWN(DEF_ADDRS_PER_BLOCK, F2FS_I(inode)->i_cluster_size); 3034de93653fSJaegeuk Kim } 3035de93653fSJaegeuk Kim 30366afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page) 303765985d93SJaegeuk Kim { 3038695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 3039cac5a3d8SDongOh Shin 304065985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 3041b323fd28SChao Yu get_inline_xattr_addrs(inode)]); 304265985d93SJaegeuk Kim } 304365985d93SJaegeuk Kim 304465985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 304565985d93SJaegeuk Kim { 3046622927f3SChao Yu if (f2fs_has_inline_xattr(inode)) 30476afc662eSChao Yu return get_inline_xattr_addrs(inode) * sizeof(__le32); 3048622927f3SChao Yu return 0; 304965985d93SJaegeuk Kim } 305065985d93SJaegeuk Kim 30510dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 30520dbdc2aeSJaegeuk Kim { 305391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 30540dbdc2aeSJaegeuk Kim } 30550dbdc2aeSJaegeuk Kim 3056b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 3057b3d208f9SJaegeuk Kim { 305891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 3059b3d208f9SJaegeuk Kim } 3060b3d208f9SJaegeuk Kim 3061510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 3062510022a8SJaegeuk Kim { 306391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 3064510022a8SJaegeuk Kim } 3065510022a8SJaegeuk Kim 30664c8ff709SChao Yu static inline int f2fs_is_mmap_file(struct inode *inode) 30674c8ff709SChao Yu { 30684c8ff709SChao Yu return is_inode_flag_set(inode, FI_MMAP_FILE); 30694c8ff709SChao Yu } 30704c8ff709SChao Yu 30711ad71a27SJaegeuk Kim static inline bool f2fs_is_pinned_file(struct inode *inode) 30721ad71a27SJaegeuk Kim { 30731ad71a27SJaegeuk Kim return is_inode_flag_set(inode, FI_PIN_FILE); 30741ad71a27SJaegeuk Kim } 30751ad71a27SJaegeuk Kim 307688b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 307788b88a66SJaegeuk Kim { 307891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 307988b88a66SJaegeuk Kim } 308088b88a66SJaegeuk Kim 30815fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 30825fe45743SChao Yu { 30835fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 30845fe45743SChao Yu } 30855fe45743SChao Yu 308602a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 308702a1335fSJaegeuk Kim { 308891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 308902a1335fSJaegeuk Kim } 309002a1335fSJaegeuk Kim 30913c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 30923c6c2bebSJaegeuk Kim { 309391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 30943c6c2bebSJaegeuk Kim } 30953c6c2bebSJaegeuk Kim 30961e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 30971e84371fSJaegeuk Kim { 309891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 30991e84371fSJaegeuk Kim } 31001e84371fSJaegeuk Kim 3101f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 31021001b347SHuajun Li { 3103695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 31047a2af766SChao Yu int extra_size = get_extra_isize(inode); 3105cac5a3d8SDongOh Shin 31067a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 31071001b347SHuajun Li } 31081001b347SHuajun Li 310934d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 311034d67debSChao Yu { 311191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 311234d67debSChao Yu } 311334d67debSChao Yu 3114b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 3115b5492af7SJaegeuk Kim { 3116b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 3117b5492af7SJaegeuk Kim } 3118b5492af7SJaegeuk Kim 3119b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 3120b5492af7SJaegeuk Kim { 3121766c6639SJaegeuk Kim if (is_file(inode, type)) 3122766c6639SJaegeuk Kim return; 3123b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 31247c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 3125b5492af7SJaegeuk Kim } 3126b5492af7SJaegeuk Kim 3127b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 3128b5492af7SJaegeuk Kim { 3129766c6639SJaegeuk Kim if (!is_file(inode, type)) 3130766c6639SJaegeuk Kim return; 3131b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 31327c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 3133b5492af7SJaegeuk Kim } 3134b5492af7SJaegeuk Kim 3135fe1897eaSChao Yu static inline bool f2fs_is_time_consistent(struct inode *inode) 3136fe1897eaSChao Yu { 3137fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time, &inode->i_atime)) 3138fe1897eaSChao Yu return false; 3139fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 1, &inode->i_ctime)) 3140fe1897eaSChao Yu return false; 3141fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 2, &inode->i_mtime)) 3142fe1897eaSChao Yu return false; 3143fe1897eaSChao Yu if (!timespec64_equal(F2FS_I(inode)->i_disk_time + 3, 3144fe1897eaSChao Yu &F2FS_I(inode)->i_crtime)) 3145fe1897eaSChao Yu return false; 3146fe1897eaSChao Yu return true; 3147fe1897eaSChao Yu } 3148fe1897eaSChao Yu 314926787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 315026787236SJaegeuk Kim { 3151a0d00fadSChao Yu bool ret; 3152a0d00fadSChao Yu 315326787236SJaegeuk Kim if (dsync) { 315426787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 315526787236SJaegeuk Kim 315626787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 315726787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 315826787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 315926787236SJaegeuk Kim return ret; 316026787236SJaegeuk Kim } 316126787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 316226787236SJaegeuk Kim file_keep_isize(inode) || 3163235831d7SJunling Zheng i_size_read(inode) & ~PAGE_MASK) 316426787236SJaegeuk Kim return false; 3165a0d00fadSChao Yu 3166fe1897eaSChao Yu if (!f2fs_is_time_consistent(inode)) 3167214c2461SJaegeuk Kim return false; 3168214c2461SJaegeuk Kim 3169c10c9820SChao Yu spin_lock(&F2FS_I(inode)->i_size_lock); 3170a0d00fadSChao Yu ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 3171c10c9820SChao Yu spin_unlock(&F2FS_I(inode)->i_size_lock); 3172a0d00fadSChao Yu 3173a0d00fadSChao Yu return ret; 3174267378d4SChao Yu } 3175267378d4SChao Yu 3176deeedd71SChao Yu static inline bool f2fs_readonly(struct super_block *sb) 317777888c1eSJaegeuk Kim { 3178deeedd71SChao Yu return sb_rdonly(sb); 317977888c1eSJaegeuk Kim } 318077888c1eSJaegeuk Kim 3181744602cfSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 3182744602cfSJaegeuk Kim { 3183aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 3184744602cfSJaegeuk Kim } 3185744602cfSJaegeuk Kim 318643c780baSEric Biggers static inline bool is_dot_dotdot(const u8 *name, size_t len) 3187eaa693f4SJaegeuk Kim { 318843c780baSEric Biggers if (len == 1 && name[0] == '.') 3189eaa693f4SJaegeuk Kim return true; 3190eaa693f4SJaegeuk Kim 319143c780baSEric Biggers if (len == 2 && name[0] == '.' && name[1] == '.') 3192eaa693f4SJaegeuk Kim return true; 3193eaa693f4SJaegeuk Kim 3194eaa693f4SJaegeuk Kim return false; 3195eaa693f4SJaegeuk Kim } 3196eaa693f4SJaegeuk Kim 31971ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 31981ecc0c5cSChao Yu size_t size, gfp_t flags) 31990414b004SJaegeuk Kim { 320055523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 3201c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_KMALLOC); 32022c63feadSJaegeuk Kim return NULL; 320355523519SChao Yu } 32047fa750a1SArnd Bergmann 32050b6d4ca0SEric Biggers return kmalloc(size, flags); 32060414b004SJaegeuk Kim } 32070414b004SJaegeuk Kim 3208acbf054dSChao Yu static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, 3209acbf054dSChao Yu size_t size, gfp_t flags) 3210acbf054dSChao Yu { 3211acbf054dSChao Yu return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); 3212acbf054dSChao Yu } 3213acbf054dSChao Yu 3214628b3d14SChao Yu static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi, 3215628b3d14SChao Yu size_t size, gfp_t flags) 3216628b3d14SChao Yu { 3217628b3d14SChao Yu if (time_to_inject(sbi, FAULT_KVMALLOC)) { 3218c45d6002SChao Yu f2fs_show_injection_info(sbi, FAULT_KVMALLOC); 3219628b3d14SChao Yu return NULL; 3220628b3d14SChao Yu } 32217fa750a1SArnd Bergmann 3222628b3d14SChao Yu return kvmalloc(size, flags); 3223628b3d14SChao Yu } 3224628b3d14SChao Yu 3225628b3d14SChao Yu static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi, 3226628b3d14SChao Yu size_t size, gfp_t flags) 3227628b3d14SChao Yu { 3228628b3d14SChao Yu return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO); 3229628b3d14SChao Yu } 3230628b3d14SChao Yu 32317a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 3232f2470371SChao Yu { 32337a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 3234f2470371SChao Yu } 3235f2470371SChao Yu 32366afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode) 32376afc662eSChao Yu { 32386afc662eSChao Yu return F2FS_I(inode)->i_inline_xattr_size; 32396afc662eSChao Yu } 32406afc662eSChao Yu 32414d57b86dSChao Yu #define f2fs_get_inode_mode(i) \ 324291942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 3243a6dda0e6SChristoph Hellwig (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 3244a6dda0e6SChristoph Hellwig 32457a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 32467a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 32477a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 32487a2af766SChao Yu 32495c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 32505c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 32512f84babfSSheng Yong ((offsetof(typeof(*(f2fs_inode)), field) + \ 32525c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 32532f84babfSSheng Yong <= (F2FS_OLD_ATTRIBUTE_SIZE + (extra_isize))) \ 32545c57132eSChao Yu 32552c70c5e3SChao Yu #define __is_large_section(sbi) ((sbi)->segs_per_sec > 1) 32562c70c5e3SChao Yu 32576dc3a126SChao Yu #define __is_meta_io(fio) (PAGE_TYPE_OF_BIO((fio)->type) == META) 3258c9b60788SChao Yu 3259e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 3260e1da7872SChao Yu block_t blkaddr, int type); 3261e1da7872SChao Yu static inline void verify_blkaddr(struct f2fs_sb_info *sbi, 3262e1da7872SChao Yu block_t blkaddr, int type) 3263e1da7872SChao Yu { 3264e1da7872SChao Yu if (!f2fs_is_valid_blkaddr(sbi, blkaddr, type)) { 3265dcbb4c10SJoe Perches f2fs_err(sbi, "invalid blkaddr: %u, type: %d, run fsck to fix.", 3266e1da7872SChao Yu blkaddr, type); 3267e1da7872SChao Yu f2fs_bug_on(sbi, 1); 3268e1da7872SChao Yu } 3269e1da7872SChao Yu } 3270e1da7872SChao Yu 3271e1da7872SChao Yu static inline bool __is_valid_data_blkaddr(block_t blkaddr) 32727b525dd0SChao Yu { 32734c8ff709SChao Yu if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR || 32744c8ff709SChao Yu blkaddr == COMPRESS_ADDR) 32757b525dd0SChao Yu return false; 32767b525dd0SChao Yu return true; 32777b525dd0SChao Yu } 32787b525dd0SChao Yu 327939a53e0cSJaegeuk Kim /* 328039a53e0cSJaegeuk Kim * file.c 328139a53e0cSJaegeuk Kim */ 3282cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 32834d57b86dSChao Yu void f2fs_truncate_data_blocks(struct dnode_of_data *dn); 32843265d3dbSChao Yu int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock); 3285c42d28ceSChao Yu int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock); 3286cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 3287549c7297SChristian Brauner int f2fs_getattr(struct user_namespace *mnt_userns, const struct path *path, 3288549c7297SChristian Brauner struct kstat *stat, u32 request_mask, unsigned int flags); 3289549c7297SChristian Brauner int f2fs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, 3290549c7297SChristian Brauner struct iattr *attr); 32914d57b86dSChao Yu int f2fs_truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 32924d57b86dSChao Yu void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count); 3293c4020b2dSChao Yu int f2fs_precache_extents(struct inode *inode); 32949b1bb01cSMiklos Szeredi int f2fs_fileattr_get(struct dentry *dentry, struct fileattr *fa); 32959b1bb01cSMiklos Szeredi int f2fs_fileattr_set(struct user_namespace *mnt_userns, 32969b1bb01cSMiklos Szeredi struct dentry *dentry, struct fileattr *fa); 3297cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 3298cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 329978130819SChao Yu int f2fs_transfer_project_quota(struct inode *inode, kprojid_t kprojid); 33001ad71a27SJaegeuk Kim int f2fs_pin_file_control(struct inode *inode, bool inc); 330139a53e0cSJaegeuk Kim 330239a53e0cSJaegeuk Kim /* 330339a53e0cSJaegeuk Kim * inode.c 330439a53e0cSJaegeuk Kim */ 3305cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 3306704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 3307704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 3308cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 3309cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 33104d57b86dSChao Yu int f2fs_try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 33114d57b86dSChao Yu void f2fs_update_inode(struct inode *inode, struct page *node_page); 33124d57b86dSChao Yu void f2fs_update_inode_page(struct inode *inode); 3313cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 3314cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 33154d57b86dSChao Yu void f2fs_handle_failed_inode(struct inode *inode); 331639a53e0cSJaegeuk Kim 331739a53e0cSJaegeuk Kim /* 331839a53e0cSJaegeuk Kim * namei.c 331939a53e0cSJaegeuk Kim */ 33204d57b86dSChao Yu int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name, 3321b6a06cbbSChao Yu bool hot, bool set); 332239a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 332339a53e0cSJaegeuk Kim 332439a53e0cSJaegeuk Kim /* 332539a53e0cSJaegeuk Kim * dir.c 332639a53e0cSJaegeuk Kim */ 33274d57b86dSChao Yu unsigned char f2fs_get_de_type(struct f2fs_dir_entry *de); 332843c780baSEric Biggers int f2fs_init_casefolded_name(const struct inode *dir, 332943c780baSEric Biggers struct f2fs_filename *fname); 333043c780baSEric Biggers int f2fs_setup_filename(struct inode *dir, const struct qstr *iname, 333143c780baSEric Biggers int lookup, struct f2fs_filename *fname); 333243c780baSEric Biggers int f2fs_prepare_lookup(struct inode *dir, struct dentry *dentry, 333343c780baSEric Biggers struct f2fs_filename *fname); 333443c780baSEric Biggers void f2fs_free_filename(struct f2fs_filename *fname); 333543c780baSEric Biggers struct f2fs_dir_entry *f2fs_find_target_dentry(const struct f2fs_dentry_ptr *d, 333643c780baSEric Biggers const struct f2fs_filename *fname, int *max_slots); 3337cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 3338cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 33394d57b86dSChao Yu void f2fs_do_make_empty_dir(struct inode *inode, struct inode *parent, 3340cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 33414d57b86dSChao Yu struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir, 334243c780baSEric Biggers const struct f2fs_filename *fname, struct page *dpage); 33434d57b86dSChao Yu void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode, 3344cac5a3d8SDongOh Shin unsigned int current_depth); 33454d57b86dSChao Yu int f2fs_room_for_filename(const void *bitmap, int slots, int max_slots); 3346cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 3347cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 334843c780baSEric Biggers const struct f2fs_filename *fname, 334943c780baSEric Biggers struct page **res_page); 3350cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 3351cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 3352cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 3353cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 3354cac5a3d8SDongOh Shin struct page **page); 3355cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 3356cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 3357b06af2afSJaegeuk Kim bool f2fs_has_enough_room(struct inode *dir, struct page *ipage, 335843c780baSEric Biggers const struct f2fs_filename *fname); 3359cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 336043c780baSEric Biggers const struct fscrypt_str *name, f2fs_hash_t name_hash, 3361cac5a3d8SDongOh Shin unsigned int bit_pos); 336243c780baSEric Biggers int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname, 3363cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 336443c780baSEric Biggers int f2fs_add_dentry(struct inode *dir, const struct f2fs_filename *fname, 3365cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 33664d57b86dSChao Yu int f2fs_do_add_link(struct inode *dir, const struct qstr *name, 3367cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 3368cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 3369cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 3370cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 3371cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 337239a53e0cSJaegeuk Kim 3373b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 3374b7f7a5e0SAl Viro { 3375bfc2b7e8SEric Biggers if (fscrypt_is_nokey_name(dentry)) 3376bfc2b7e8SEric Biggers return -ENOKEY; 33774d57b86dSChao Yu return f2fs_do_add_link(d_inode(dentry->d_parent), &dentry->d_name, 3378510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 3379b7f7a5e0SAl Viro } 3380b7f7a5e0SAl Viro 338139a53e0cSJaegeuk Kim /* 338239a53e0cSJaegeuk Kim * super.c 338339a53e0cSJaegeuk Kim */ 3384cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 3385cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 338610a26878SChao Yu int f2fs_dquot_initialize(struct inode *inode); 3387ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); 3388af033b2aSChao Yu int f2fs_quota_sync(struct super_block *sb, int type); 33896d1451bfSChengguang Xu loff_t max_file_blocks(struct inode *inode); 33904b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 3391cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 3392cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 33934d57b86dSChao Yu int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi); 339439a53e0cSJaegeuk Kim 339539a53e0cSJaegeuk Kim /* 339639a53e0cSJaegeuk Kim * hash.c 339739a53e0cSJaegeuk Kim */ 339843c780baSEric Biggers void f2fs_hash_filename(const struct inode *dir, struct f2fs_filename *fname); 339939a53e0cSJaegeuk Kim 340039a53e0cSJaegeuk Kim /* 340139a53e0cSJaegeuk Kim * node.c 340239a53e0cSJaegeuk Kim */ 340339a53e0cSJaegeuk Kim struct node_info; 340439a53e0cSJaegeuk Kim 34054d57b86dSChao Yu int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid); 34064d57b86dSChao Yu bool f2fs_available_free_memory(struct f2fs_sb_info *sbi, int type); 340750fa53ecSChao Yu bool f2fs_in_warm_node_list(struct f2fs_sb_info *sbi, struct page *page); 340850fa53ecSChao Yu void f2fs_init_fsync_node_info(struct f2fs_sb_info *sbi); 340950fa53ecSChao Yu void f2fs_del_fsync_node_entry(struct f2fs_sb_info *sbi, struct page *page); 341050fa53ecSChao Yu void f2fs_reset_fsync_node_info(struct f2fs_sb_info *sbi); 34114d57b86dSChao Yu int f2fs_need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 34124d57b86dSChao Yu bool f2fs_is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 34134d57b86dSChao Yu bool f2fs_need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 34147735730dSChao Yu int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t nid, 34154d57b86dSChao Yu struct node_info *ni); 34164d57b86dSChao Yu pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 34174d57b86dSChao Yu int f2fs_get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 34184d57b86dSChao Yu int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from); 34194d57b86dSChao Yu int f2fs_truncate_xattr_node(struct inode *inode); 342050fa53ecSChao Yu int f2fs_wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, 342150fa53ecSChao Yu unsigned int seq_id); 342294c821fbSChao Yu bool f2fs_nat_bitmap_enabled(struct f2fs_sb_info *sbi); 34234d57b86dSChao Yu int f2fs_remove_inode_page(struct inode *inode); 34244d57b86dSChao Yu struct page *f2fs_new_inode_page(struct inode *inode); 34254d57b86dSChao Yu struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs); 34264d57b86dSChao Yu void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 34274d57b86dSChao Yu struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 34284d57b86dSChao Yu struct page *f2fs_get_node_page_ra(struct page *parent, int start); 342948018b4cSChao Yu int f2fs_move_node_page(struct page *node_page, int gc_type); 343068e79bafSJia Yang void f2fs_flush_inline_data(struct f2fs_sb_info *sbi); 34314d57b86dSChao Yu int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 343250fa53ecSChao Yu struct writeback_control *wbc, bool atomic, 343350fa53ecSChao Yu unsigned int *seq_id); 34344d57b86dSChao Yu int f2fs_sync_node_pages(struct f2fs_sb_info *sbi, 34354d57b86dSChao Yu struct writeback_control *wbc, 3436b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 3437e2374015SChao Yu int f2fs_build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 34384d57b86dSChao Yu bool f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 34394d57b86dSChao Yu void f2fs_alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 34404d57b86dSChao Yu void f2fs_alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 34414d57b86dSChao Yu int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 34429627a7b3SChao Yu int f2fs_recover_inline_xattr(struct inode *inode, struct page *page); 34434d57b86dSChao Yu int f2fs_recover_xattr_data(struct inode *inode, struct page *page); 34444d57b86dSChao Yu int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 34457735730dSChao Yu int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, 3446cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 344794c821fbSChao Yu void f2fs_enable_nat_bits(struct f2fs_sb_info *sbi); 3448edc55aafSJaegeuk Kim int f2fs_flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 34494d57b86dSChao Yu int f2fs_build_node_manager(struct f2fs_sb_info *sbi); 34504d57b86dSChao Yu void f2fs_destroy_node_manager(struct f2fs_sb_info *sbi); 34514d57b86dSChao Yu int __init f2fs_create_node_manager_caches(void); 34524d57b86dSChao Yu void f2fs_destroy_node_manager_caches(void); 345339a53e0cSJaegeuk Kim 345439a53e0cSJaegeuk Kim /* 345539a53e0cSJaegeuk Kim * segment.c 345639a53e0cSJaegeuk Kim */ 34574d57b86dSChao Yu bool f2fs_need_SSR(struct f2fs_sb_info *sbi); 34584d57b86dSChao Yu void f2fs_register_inmem_page(struct inode *inode, struct page *page); 34594d57b86dSChao Yu void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure); 34604d57b86dSChao Yu void f2fs_drop_inmem_pages(struct inode *inode); 34614d57b86dSChao Yu void f2fs_drop_inmem_page(struct inode *inode, struct page *page); 34624d57b86dSChao Yu int f2fs_commit_inmem_pages(struct inode *inode); 3463cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 34647bcd0cfaSChao Yu void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg); 346539d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 34664d57b86dSChao Yu int f2fs_create_flush_cmd_control(struct f2fs_sb_info *sbi); 34671228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); 34684d57b86dSChao Yu void f2fs_destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 34694d57b86dSChao Yu void f2fs_invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 34704d57b86dSChao Yu bool f2fs_is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 34714d674904SFengnan Chang int f2fs_start_discard_thread(struct f2fs_sb_info *sbi); 34724d57b86dSChao Yu void f2fs_drop_discard_cmd(struct f2fs_sb_info *sbi); 34734d57b86dSChao Yu void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi); 347403f2c02dSJaegeuk Kim bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi); 34754d57b86dSChao Yu void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, 34764d57b86dSChao Yu struct cp_control *cpc); 34774354994fSDaniel Rosenberg void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi); 34784d3aed70SDaniel Rosenberg block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi); 34794d3aed70SDaniel Rosenberg int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable); 34804d57b86dSChao Yu void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi); 34814d57b86dSChao Yu int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 348261461fc9SChao Yu bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno); 3483093749e2SChao Yu void f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi); 3484093749e2SChao Yu void f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi); 3485093749e2SChao Yu void f2fs_restore_inmem_curseg(struct f2fs_sb_info *sbi); 3486093749e2SChao Yu void f2fs_get_new_segment(struct f2fs_sb_info *sbi, 3487093749e2SChao Yu unsigned int *newseg, bool new_sec, int dir); 34880ef81833SChao Yu void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, 348904f0b2eaSQiuyang Sun unsigned int start, unsigned int end); 3490509f1010SChao Yu void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force); 3491901d745fSChao Yu void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi); 3492cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 34934d57b86dSChao Yu bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, 34944d57b86dSChao Yu struct cp_control *cpc); 34954d57b86dSChao Yu struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 34964d57b86dSChao Yu void f2fs_update_meta_page(struct f2fs_sb_info *sbi, void *src, 34974d57b86dSChao Yu block_t blk_addr); 34984d57b86dSChao Yu void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 3499b0af6d49SChao Yu enum iostat_type io_type); 35004d57b86dSChao Yu void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio); 35014d57b86dSChao Yu void f2fs_outplace_write_data(struct dnode_of_data *dn, 35024d57b86dSChao Yu struct f2fs_io_info *fio); 35034d57b86dSChao Yu int f2fs_inplace_write_data(struct f2fs_io_info *fio); 35044d57b86dSChao Yu void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 3505cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 3506c5d02785SChao Yu bool recover_curseg, bool recover_newaddr, 3507c5d02785SChao Yu bool from_gc); 3508cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 3509cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 3510cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 3511cac5a3d8SDongOh Shin bool recover_newaddr); 35124d57b86dSChao Yu void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 3513cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 3514fb830fc5SChao Yu struct f2fs_summary *sum, int type, 3515f608c38cSChao Yu struct f2fs_io_info *fio); 351671f2c820SChao Yu void f2fs_update_device_state(struct f2fs_sb_info *sbi, nid_t ino, 351771f2c820SChao Yu block_t blkaddr, unsigned int blkcnt); 3518cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 3519bae0ee7aSChao Yu enum page_type type, bool ordered, bool locked); 35200ded69f6SJaegeuk Kim void f2fs_wait_on_block_writeback(struct inode *inode, block_t blkaddr); 35211e78e8bdSSahitya Tummala void f2fs_wait_on_block_writeback_range(struct inode *inode, block_t blkaddr, 35221e78e8bdSSahitya Tummala block_t len); 35234d57b86dSChao Yu void f2fs_write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 35244d57b86dSChao Yu void f2fs_write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 35254d57b86dSChao Yu int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 3526cac5a3d8SDongOh Shin unsigned int val, int alloc); 35274d57b86dSChao Yu void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 3528c426d991SShin'ichiro Kawasaki int f2fs_fix_curseg_write_pointer(struct f2fs_sb_info *sbi); 3529d508c94eSShin'ichiro Kawasaki int f2fs_check_write_pointer(struct f2fs_sb_info *sbi); 35304d57b86dSChao Yu int f2fs_build_segment_manager(struct f2fs_sb_info *sbi); 35314d57b86dSChao Yu void f2fs_destroy_segment_manager(struct f2fs_sb_info *sbi); 35324d57b86dSChao Yu int __init f2fs_create_segment_manager_caches(void); 35334d57b86dSChao Yu void f2fs_destroy_segment_manager_caches(void); 35344d57b86dSChao Yu int f2fs_rw_hint_to_seg_type(enum rw_hint hint); 35354d57b86dSChao Yu enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi, 35364d57b86dSChao Yu enum page_type type, enum temp_type temp); 3537de881df9SAravind Ramesh unsigned int f2fs_usable_segs_in_sec(struct f2fs_sb_info *sbi, 3538de881df9SAravind Ramesh unsigned int segno); 3539de881df9SAravind Ramesh unsigned int f2fs_usable_blks_in_seg(struct f2fs_sb_info *sbi, 3540de881df9SAravind Ramesh unsigned int segno); 354139a53e0cSJaegeuk Kim 35426691d940SDaeho Jeong #define DEF_FRAGMENT_SIZE 4 35436691d940SDaeho Jeong #define MIN_FRAGMENT_SIZE 1 35446691d940SDaeho Jeong #define MAX_FRAGMENT_SIZE 512 35456691d940SDaeho Jeong 35466691d940SDaeho Jeong static inline bool f2fs_need_rand_seg(struct f2fs_sb_info *sbi) 35476691d940SDaeho Jeong { 35486691d940SDaeho Jeong return F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_SEG || 35496691d940SDaeho Jeong F2FS_OPTION(sbi).fs_mode == FS_MODE_FRAGMENT_BLK; 35506691d940SDaeho Jeong } 35516691d940SDaeho Jeong 355239a53e0cSJaegeuk Kim /* 355339a53e0cSJaegeuk Kim * checkpoint.c 355439a53e0cSJaegeuk Kim */ 3555cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 35564d57b86dSChao Yu struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 35574d57b86dSChao Yu struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 355886f33603SJaegeuk Kim struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index); 35594d57b86dSChao Yu struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 3560e1da7872SChao Yu bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi, 35614d57b86dSChao Yu block_t blkaddr, int type); 35624d57b86dSChao Yu int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 3563cac5a3d8SDongOh Shin int type, bool sync); 35644d57b86dSChao Yu void f2fs_ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 35654d57b86dSChao Yu long f2fs_sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 3566b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 35674d57b86dSChao Yu void f2fs_add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 35684d57b86dSChao Yu void f2fs_remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 35694d57b86dSChao Yu void f2fs_release_ino_entry(struct f2fs_sb_info *sbi, bool all); 35704d57b86dSChao Yu bool f2fs_exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 35714d57b86dSChao Yu void f2fs_set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 357239d787beSChao Yu unsigned int devidx, int type); 35734d57b86dSChao Yu bool f2fs_is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 357439d787beSChao Yu unsigned int devidx, int type); 3575cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 35764d57b86dSChao Yu int f2fs_acquire_orphan_inode(struct f2fs_sb_info *sbi); 35774d57b86dSChao Yu void f2fs_release_orphan_inode(struct f2fs_sb_info *sbi); 35784d57b86dSChao Yu void f2fs_add_orphan_inode(struct inode *inode); 35794d57b86dSChao Yu void f2fs_remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 35804d57b86dSChao Yu int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi); 35814d57b86dSChao Yu int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi); 35824d57b86dSChao Yu void f2fs_update_dirty_page(struct inode *inode, struct page *page); 35834d57b86dSChao Yu void f2fs_remove_dirty_inode(struct inode *inode); 35844d57b86dSChao Yu int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 3585bf22c3ccSSahitya Tummala void f2fs_wait_on_all_pages(struct f2fs_sb_info *sbi, int type); 35863a0a9cbcSChao Yu u64 f2fs_get_sectors_written(struct f2fs_sb_info *sbi); 35874d57b86dSChao Yu int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 35884d57b86dSChao Yu void f2fs_init_ino_entry_info(struct f2fs_sb_info *sbi); 35894d57b86dSChao Yu int __init f2fs_create_checkpoint_caches(void); 35904d57b86dSChao Yu void f2fs_destroy_checkpoint_caches(void); 3591261eeb9cSDaeho Jeong int f2fs_issue_checkpoint(struct f2fs_sb_info *sbi); 3592261eeb9cSDaeho Jeong int f2fs_start_ckpt_thread(struct f2fs_sb_info *sbi); 3593261eeb9cSDaeho Jeong void f2fs_stop_ckpt_thread(struct f2fs_sb_info *sbi); 3594261eeb9cSDaeho Jeong void f2fs_init_ckpt_req_control(struct f2fs_sb_info *sbi); 359539a53e0cSJaegeuk Kim 359639a53e0cSJaegeuk Kim /* 359739a53e0cSJaegeuk Kim * data.c 359839a53e0cSJaegeuk Kim */ 3599f543805fSChao Yu int __init f2fs_init_bioset(void); 3600f543805fSChao Yu void f2fs_destroy_bioset(void); 36010b20fcecSChao Yu int f2fs_init_bio_entry_cache(void); 36020b20fcecSChao Yu void f2fs_destroy_bio_entry_cache(void); 36034c8ff709SChao Yu void f2fs_submit_bio(struct f2fs_sb_info *sbi, 36044c8ff709SChao Yu struct bio *bio, enum page_type type); 3605b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 3606b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 3607bab475c5SChao Yu struct inode *inode, struct page *page, 3608bab475c5SChao Yu nid_t ino, enum page_type type); 36090b20fcecSChao Yu void f2fs_submit_merged_ipu_write(struct f2fs_sb_info *sbi, 36100b20fcecSChao Yu struct bio **bio, struct page *page); 3611b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 3612cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 36138648de2cSChao Yu int f2fs_merge_page_bio(struct f2fs_io_info *fio); 3614fe16efe6SChao Yu void f2fs_submit_page_write(struct f2fs_io_info *fio); 3615cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 3616cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 3617cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 36184d57b86dSChao Yu void f2fs_set_data_blkaddr(struct dnode_of_data *dn); 3619cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 36204d57b86dSChao Yu int f2fs_reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 36214d57b86dSChao Yu int f2fs_reserve_new_block(struct dnode_of_data *dn); 3622cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 3623cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 36244d57b86dSChao Yu struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, 3625cac5a3d8SDongOh Shin int op_flags, bool for_write); 36264d57b86dSChao Yu struct page *f2fs_find_data_page(struct inode *inode, pgoff_t index); 36274d57b86dSChao Yu struct page *f2fs_get_lock_data_page(struct inode *inode, pgoff_t index, 3628cac5a3d8SDongOh Shin bool for_write); 36294d57b86dSChao Yu struct page *f2fs_get_new_data_page(struct inode *inode, 3630cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 36314d57b86dSChao Yu int f2fs_do_write_data_page(struct f2fs_io_info *fio); 36320ef81833SChao Yu void f2fs_do_map_lock(struct f2fs_sb_info *sbi, int flag, bool lock); 3633cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 3634cac5a3d8SDongOh Shin int create, int flag); 3635cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 3636cac5a3d8SDongOh Shin u64 start, u64 len); 36374c8ff709SChao Yu int f2fs_encrypt_one_page(struct f2fs_io_info *fio); 36384d57b86dSChao Yu bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio); 36394d57b86dSChao Yu bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio); 36404c8ff709SChao Yu int f2fs_write_single_data_page(struct page *page, int *submitted, 36414c8ff709SChao Yu struct bio **bio, sector_t *last_block, 36424c8ff709SChao Yu struct writeback_control *wbc, 36434c8ff709SChao Yu enum iostat_type io_type, 36443afae09fSChao Yu int compr_blocks, bool allow_balance); 3645a1e09b03SEric Biggers void f2fs_write_failed(struct inode *inode, loff_t to); 3646cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 3647cac5a3d8SDongOh Shin unsigned int length); 3648cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 36495b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 3650cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 3651cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 36525b7a487cSWeichao Guo #endif 3653b91050a8SHyunchul Lee bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len); 36545ec2d99dSMatthew Wilcox void f2fs_clear_page_cache_dirty_tag(struct page *page); 36554c8ff709SChao Yu int f2fs_init_post_read_processing(void); 36564c8ff709SChao Yu void f2fs_destroy_post_read_processing(void); 36574c8ff709SChao Yu int f2fs_init_post_read_wq(struct f2fs_sb_info *sbi); 36584c8ff709SChao Yu void f2fs_destroy_post_read_wq(struct f2fs_sb_info *sbi); 36591517c1a7SEric Biggers extern const struct iomap_ops f2fs_iomap_ops; 366039a53e0cSJaegeuk Kim 366139a53e0cSJaegeuk Kim /* 366239a53e0cSJaegeuk Kim * gc.c 366339a53e0cSJaegeuk Kim */ 36644d57b86dSChao Yu int f2fs_start_gc_thread(struct f2fs_sb_info *sbi); 36654d57b86dSChao Yu void f2fs_stop_gc_thread(struct f2fs_sb_info *sbi); 36664d57b86dSChao Yu block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 36677dede886SChao Yu int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, bool force, 3668e066b83cSJaegeuk Kim unsigned int segno); 36694d57b86dSChao Yu void f2fs_build_gc_manager(struct f2fs_sb_info *sbi); 367004f0b2eaSQiuyang Sun int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count); 3671093749e2SChao Yu int __init f2fs_create_garbage_collection_cache(void); 3672093749e2SChao Yu void f2fs_destroy_garbage_collection_cache(void); 367339a53e0cSJaegeuk Kim 367439a53e0cSJaegeuk Kim /* 367539a53e0cSJaegeuk Kim * recovery.c 367639a53e0cSJaegeuk Kim */ 36774d57b86dSChao Yu int f2fs_recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 36784d57b86dSChao Yu bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi); 3679cad83c96SChao Yu int __init f2fs_create_recovery_cache(void); 3680cad83c96SChao Yu void f2fs_destroy_recovery_cache(void); 368139a53e0cSJaegeuk Kim 368239a53e0cSJaegeuk Kim /* 368339a53e0cSJaegeuk Kim * debug.c 368439a53e0cSJaegeuk Kim */ 368539a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 368639a53e0cSJaegeuk Kim struct f2fs_stat_info { 368739a53e0cSJaegeuk Kim struct list_head stat_list; 368839a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 368939a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 369039a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 36915b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 36925b7ee374SChao Yu unsigned long long hit_total, total_ext; 3693c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 36942c8a4a28SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; 36952c8a4a28SJaegeuk Kim int ndirty_data, ndirty_qdata; 369635782b23SJaegeuk Kim int inmem_pages; 36972c8a4a28SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; 36985b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 36995b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 370039a53e0cSJaegeuk Kim int total_count, utilization; 37018b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 37025f9abab4SJaegeuk Kim int nr_rd_data, nr_rd_node, nr_rd_meta; 370302b16d0aSChao Yu int nr_dio_read, nr_dio_write; 3704274bd9baSChao Yu unsigned int io_skip_bggc, other_skip_bggc; 370514d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 370614d8d5f7SChao Yu int nr_discarding, nr_discarded; 37075f32366aSChao Yu int nr_discard_cmd; 3708d84d1cbdSChao Yu unsigned int undiscard_blks; 3709261eeb9cSDaeho Jeong int nr_issued_ckpt, nr_total_ckpt, nr_queued_ckpt; 3710261eeb9cSDaeho Jeong unsigned int cur_ckpt_time, peak_ckpt_time; 3711a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 3712ae999bb9SDaeho Jeong int compr_inode; 3713ae999bb9SDaeho Jeong unsigned long long compr_blocks; 3714648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 3715f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 371639a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 371739a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 371839a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 37196ce19affSChao Yu int dirty_count, node_pages, meta_pages, compress_pages; 37206ce19affSChao Yu int compress_page_hit; 372142190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 372239a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 3723e1235983SChangman Lee int bg_node_segs, bg_data_segs; 372439a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 3725e1235983SChangman Lee int bg_data_blks, bg_node_blks; 37262ef79ecbSChao Yu unsigned long long skipped_atomic_files[2]; 372739a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 372839a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 372939a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 37300759e2c1SChao Yu unsigned int dirty_seg[NR_CURSEG_TYPE]; 37310759e2c1SChao Yu unsigned int full_seg[NR_CURSEG_TYPE]; 37320759e2c1SChao Yu unsigned int valid_blks[NR_CURSEG_TYPE]; 373339a53e0cSJaegeuk Kim 3734b63e7be5SChao Yu unsigned int meta_count[META_MAX]; 373539a53e0cSJaegeuk Kim unsigned int segment_count[2]; 373639a53e0cSJaegeuk Kim unsigned int block_count[2]; 3737b9a2c252SChangman Lee unsigned int inplace_count; 37389edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 373939a53e0cSJaegeuk Kim }; 374039a53e0cSJaegeuk Kim 3741963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 3742963d4f7dSGu Zheng { 3743963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 3744963d4f7dSGu Zheng } 3745963d4f7dSGu Zheng 3746942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 374742190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 374839a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 3749fc7100eaSHridya Valsaraju #define stat_inc_bggc_count(si) ((si)->bg_gc++) 3750274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) ((sbi)->io_skip_bggc++) 3751274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) ((sbi)->other_skip_bggc++) 375233fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 375333fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 37545b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 37555b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 37565b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 37575b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 3758d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 3759d5e8f6c9SChao Yu do { \ 3760d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3761d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 3762d5e8f6c9SChao Yu } while (0) 3763d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 3764d5e8f6c9SChao Yu do { \ 3765d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 3766d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 3767d5e8f6c9SChao Yu } while (0) 37680dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 37690dbdc2aeSJaegeuk Kim do { \ 37700dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 377103e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 37720dbdc2aeSJaegeuk Kim } while (0) 37730dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 37740dbdc2aeSJaegeuk Kim do { \ 37750dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 377603e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 37770dbdc2aeSJaegeuk Kim } while (0) 37783289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 37793289c061SJaegeuk Kim do { \ 37803289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 378103e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 37823289c061SJaegeuk Kim } while (0) 37833289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 37843289c061SJaegeuk Kim do { \ 37853289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 378603e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 37873289c061SJaegeuk Kim } while (0) 37884c8ff709SChao Yu #define stat_inc_compr_inode(inode) \ 37894c8ff709SChao Yu do { \ 37904c8ff709SChao Yu if (f2fs_compressed_file(inode)) \ 37914c8ff709SChao Yu (atomic_inc(&F2FS_I_SB(inode)->compr_inode)); \ 37924c8ff709SChao Yu } while (0) 37934c8ff709SChao Yu #define stat_dec_compr_inode(inode) \ 37944c8ff709SChao Yu do { \ 37954c8ff709SChao Yu if (f2fs_compressed_file(inode)) \ 37964c8ff709SChao Yu (atomic_dec(&F2FS_I_SB(inode)->compr_inode)); \ 37974c8ff709SChao Yu } while (0) 37984c8ff709SChao Yu #define stat_add_compr_blocks(inode, blocks) \ 3799ae999bb9SDaeho Jeong (atomic64_add(blocks, &F2FS_I_SB(inode)->compr_blocks)) 38004c8ff709SChao Yu #define stat_sub_compr_blocks(inode, blocks) \ 3801ae999bb9SDaeho Jeong (atomic64_sub(blocks, &F2FS_I_SB(inode)->compr_blocks)) 3802b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) \ 3803b63e7be5SChao Yu do { \ 3804b63e7be5SChao Yu if (blkaddr < SIT_I(sbi)->sit_base_addr) \ 3805b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_CP]); \ 3806b63e7be5SChao Yu else if (blkaddr < NM_I(sbi)->nat_blkaddr) \ 3807b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SIT]); \ 3808b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->ssa_blkaddr) \ 3809b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_NAT]); \ 3810b63e7be5SChao Yu else if (blkaddr < SM_I(sbi)->main_blkaddr) \ 3811b63e7be5SChao Yu atomic_inc(&(sbi)->meta_count[META_SSA]); \ 3812b63e7be5SChao Yu } while (0) 3813dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 3814dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 3815dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 3816dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 3817b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 3818b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 381926a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 382026a28a0cSJaegeuk Kim do { \ 38210e6d0164SSahitya Tummala int cur = F2FS_I_SB(inode)->atomic_files; \ 382226a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 382326a28a0cSJaegeuk Kim if (cur > max) \ 382426a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 382526a28a0cSJaegeuk Kim } while (0) 3826648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 3827648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 3828648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 3829648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 3830648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 3831648d50baSChao Yu do { \ 3832648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 3833648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 3834648d50baSChao Yu if (cur > max) \ 3835648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 3836648d50baSChao Yu } while (0) 3837e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 383839a53e0cSJaegeuk Kim do { \ 3839963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 384068afcf2dSTomohiro Kusumi si->tot_segs++; \ 384168afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 384239a53e0cSJaegeuk Kim si->data_segs++; \ 3843e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 3844e1235983SChangman Lee } else { \ 384539a53e0cSJaegeuk Kim si->node_segs++; \ 3846e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 3847e1235983SChangman Lee } \ 384839a53e0cSJaegeuk Kim } while (0) 384939a53e0cSJaegeuk Kim 385039a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 385168afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 385239a53e0cSJaegeuk Kim 3853e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 385439a53e0cSJaegeuk Kim do { \ 3855963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 385639a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 385739a53e0cSJaegeuk Kim si->data_blks += (blks); \ 385868afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 385939a53e0cSJaegeuk Kim } while (0) 386039a53e0cSJaegeuk Kim 3861e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 386239a53e0cSJaegeuk Kim do { \ 3863963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 386439a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 386539a53e0cSJaegeuk Kim si->node_blks += (blks); \ 386668afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 386739a53e0cSJaegeuk Kim } while (0) 386839a53e0cSJaegeuk Kim 3869cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 3870cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 387121acc07dSGreg Kroah-Hartman void __init f2fs_create_root_stats(void); 38724589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 3873fc7100eaSHridya Valsaraju void f2fs_update_sit_info(struct f2fs_sb_info *sbi); 387439a53e0cSJaegeuk Kim #else 3875d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 3876d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 3877d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 3878d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 3879274bd9baSChao Yu #define stat_io_skip_bggc_count(sbi) do { } while (0) 3880274bd9baSChao Yu #define stat_other_skip_bggc_count(sbi) do { } while (0) 3881d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 3882d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 3883fc7100eaSHridya Valsaraju #define stat_inc_total_hit(sbi) do { } while (0) 3884fc7100eaSHridya Valsaraju #define stat_inc_rbtree_node_hit(sbi) do { } while (0) 3885d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 3886d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 3887d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 3888d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 3889d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 3890d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 3891d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 3892d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 38934c8ff709SChao Yu #define stat_inc_compr_inode(inode) do { } while (0) 38944c8ff709SChao Yu #define stat_dec_compr_inode(inode) do { } while (0) 38954c8ff709SChao Yu #define stat_add_compr_blocks(inode, blocks) do { } while (0) 38964c8ff709SChao Yu #define stat_sub_compr_blocks(inode, blocks) do { } while (0) 3897d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 3898d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 3899d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 3900d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 3901b63e7be5SChao Yu #define stat_inc_meta_count(sbi, blkaddr) do { } while (0) 3902d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 3903d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 3904d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 3905d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 3906d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 3907d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 3908d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 390939a53e0cSJaegeuk Kim 391039a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 391139a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 391221acc07dSGreg Kroah-Hartman static inline void __init f2fs_create_root_stats(void) { } 39134589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 391448abe91aSYueHaibing static inline void f2fs_update_sit_info(struct f2fs_sb_info *sbi) {} 391539a53e0cSJaegeuk Kim #endif 391639a53e0cSJaegeuk Kim 391739a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 391839a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 391939a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 392039a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 392139a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 392239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 392339a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 392439a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 3925cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 392639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 39274d57b86dSChao Yu extern struct kmem_cache *f2fs_inode_entry_slab; 39281001b347SHuajun Li 3929e18c65b2SHuajun Li /* 3930e18c65b2SHuajun Li * inline.c 3931e18c65b2SHuajun Li */ 3932cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 3933cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 39344d57b86dSChao Yu void f2fs_do_read_inline_data(struct page *page, struct page *ipage); 39354d57b86dSChao Yu void f2fs_truncate_inline_inode(struct inode *inode, 39364d57b86dSChao Yu struct page *ipage, u64 from); 3937cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 3938cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 3939cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 3940b06af2afSJaegeuk Kim int f2fs_try_convert_inline_dir(struct inode *dir, struct dentry *dentry); 3941cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 39429627a7b3SChao Yu int f2fs_recover_inline_data(struct inode *inode, struct page *npage); 39434d57b86dSChao Yu struct f2fs_dir_entry *f2fs_find_in_inline_dir(struct inode *dir, 394443c780baSEric Biggers const struct f2fs_filename *fname, 394543c780baSEric Biggers struct page **res_page); 39464d57b86dSChao Yu int f2fs_make_empty_inline_dir(struct inode *inode, struct inode *parent, 3947cac5a3d8SDongOh Shin struct page *ipage); 394843c780baSEric Biggers int f2fs_add_inline_entry(struct inode *dir, const struct f2fs_filename *fname, 3949cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 39504d57b86dSChao Yu void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, 39514d57b86dSChao Yu struct page *page, struct inode *dir, 39524d57b86dSChao Yu struct inode *inode); 3953cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 3954cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 3955cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 3956cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 3957cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 3958cac5a3d8SDongOh Shin __u64 start, __u64 len); 3959cde4de12SJaegeuk Kim 3960cde4de12SJaegeuk Kim /* 39612658e50dSJaegeuk Kim * shrinker.c 39622658e50dSJaegeuk Kim */ 3963cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 3964cac5a3d8SDongOh Shin struct shrink_control *sc); 3965cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 3966cac5a3d8SDongOh Shin struct shrink_control *sc); 3967cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 3968cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 39692658e50dSJaegeuk Kim 39702658e50dSJaegeuk Kim /* 3971a28ef1f5SChao Yu * extent_cache.c 3972a28ef1f5SChao Yu */ 39734dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree(struct rb_root_cached *root, 3974004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 39752e9b2bb2SChao Yu struct rb_node **f2fs_lookup_rb_tree_ext(struct f2fs_sb_info *sbi, 39762e9b2bb2SChao Yu struct rb_root_cached *root, 39772e9b2bb2SChao Yu struct rb_node **parent, 39782e9b2bb2SChao Yu unsigned long long key, bool *left_most); 39794d57b86dSChao Yu struct rb_node **f2fs_lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 39804dada3fdSChao Yu struct rb_root_cached *root, 39814dada3fdSChao Yu struct rb_node **parent, 39824dada3fdSChao Yu unsigned int ofs, bool *leftmost); 39834dada3fdSChao Yu struct rb_entry *f2fs_lookup_rb_tree_ret(struct rb_root_cached *root, 3984004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 3985004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 3986004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 39874dada3fdSChao Yu bool force, bool *leftmost); 39884d57b86dSChao Yu bool f2fs_check_rb_tree_consistence(struct f2fs_sb_info *sbi, 39892e9b2bb2SChao Yu struct rb_root_cached *root, bool check_key); 3990cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 3991a6d601f3SChao Yu void f2fs_init_extent_tree(struct inode *inode, struct page *ipage); 3992cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 3993cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 3994cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 3995cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 3996cac5a3d8SDongOh Shin struct extent_info *ei); 3997cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 399819b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 3999cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 40004d57b86dSChao Yu void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi); 40014d57b86dSChao Yu int __init f2fs_create_extent_cache(void); 40024d57b86dSChao Yu void f2fs_destroy_extent_cache(void); 4003a28ef1f5SChao Yu 4004a28ef1f5SChao Yu /* 40058ceffcb2SChao Yu * sysfs.c 40068ceffcb2SChao Yu */ 40070f6b56ecSDaeho Jeong #define MIN_RA_MUL 2 40080f6b56ecSDaeho Jeong #define MAX_RA_MUL 256 40090f6b56ecSDaeho Jeong 4010dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 4011dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 4012dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 4013dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 40148ceffcb2SChao Yu 401595ae251fSEric Biggers /* verity.c */ 401695ae251fSEric Biggers extern const struct fsverity_operations f2fs_verityops; 401795ae251fSEric Biggers 40188ceffcb2SChao Yu /* 4019cde4de12SJaegeuk Kim * crypto support 4020cde4de12SJaegeuk Kim */ 40211958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 40221958593eSJaegeuk Kim { 402362230e0dSChandan Rajendra return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); 40241958593eSJaegeuk Kim } 40251958593eSJaegeuk Kim 4026cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 4027cde4de12SJaegeuk Kim { 4028643fa961SChandan Rajendra #ifdef CONFIG_FS_ENCRYPTION 4029cde4de12SJaegeuk Kim file_set_encrypt(inode); 40309149a5ebSChao Yu f2fs_set_inode_flags(inode); 4031cde4de12SJaegeuk Kim #endif 4032cde4de12SJaegeuk Kim } 4033cde4de12SJaegeuk Kim 40346dbb1796SEric Biggers /* 40356dbb1796SEric Biggers * Returns true if the reads of the inode's data need to undergo some 40366dbb1796SEric Biggers * postprocessing step, like decryption or authenticity verification. 40376dbb1796SEric Biggers */ 40386dbb1796SEric Biggers static inline bool f2fs_post_read_required(struct inode *inode) 4039cde4de12SJaegeuk Kim { 40404c8ff709SChao Yu return f2fs_encrypted_file(inode) || fsverity_active(inode) || 40414c8ff709SChao Yu f2fs_compressed_file(inode); 40424c8ff709SChao Yu } 40434c8ff709SChao Yu 40444c8ff709SChao Yu /* 40454c8ff709SChao Yu * compress.c 40464c8ff709SChao Yu */ 40474c8ff709SChao Yu #ifdef CONFIG_F2FS_FS_COMPRESSION 40484c8ff709SChao Yu bool f2fs_is_compressed_page(struct page *page); 40494c8ff709SChao Yu struct page *f2fs_compress_control_page(struct page *page); 40504c8ff709SChao Yu int f2fs_prepare_compress_overwrite(struct inode *inode, 40514c8ff709SChao Yu struct page **pagep, pgoff_t index, void **fsdata); 40524c8ff709SChao Yu bool f2fs_compress_write_end(struct inode *inode, void *fsdata, 40534c8ff709SChao Yu pgoff_t index, unsigned copied); 40543265d3dbSChao Yu int f2fs_truncate_partial_cluster(struct inode *inode, u64 from, bool lock); 40554c8ff709SChao Yu void f2fs_compress_write_end_io(struct bio *bio, struct page *page); 40564c8ff709SChao Yu bool f2fs_is_compress_backend_ready(struct inode *inode); 40575e6bbde9SChao Yu int f2fs_init_compress_mempool(void); 40585e6bbde9SChao Yu void f2fs_destroy_compress_mempool(void); 40596ce19affSChao Yu void f2fs_decompress_cluster(struct decompress_io_ctx *dic); 40606ce19affSChao Yu void f2fs_end_read_compressed_page(struct page *page, bool failed, 40616ce19affSChao Yu block_t blkaddr); 40624c8ff709SChao Yu bool f2fs_cluster_is_empty(struct compress_ctx *cc); 40634c8ff709SChao Yu bool f2fs_cluster_can_merge_page(struct compress_ctx *cc, pgoff_t index); 4064b368cc5eSFengnan Chang bool f2fs_all_cluster_page_loaded(struct compress_ctx *cc, struct pagevec *pvec, 4065b368cc5eSFengnan Chang int index, int nr_pages); 4066bbe1da7eSChao Yu bool f2fs_sanity_check_cluster(struct dnode_of_data *dn); 40674c8ff709SChao Yu void f2fs_compress_ctx_add_page(struct compress_ctx *cc, struct page *page); 40684c8ff709SChao Yu int f2fs_write_multi_pages(struct compress_ctx *cc, 40694c8ff709SChao Yu int *submitted, 40704c8ff709SChao Yu struct writeback_control *wbc, 40714c8ff709SChao Yu enum iostat_type io_type); 40724c8ff709SChao Yu int f2fs_is_compressed_cluster(struct inode *inode, pgoff_t index); 407394afd6d6SChao Yu void f2fs_update_extent_tree_range_compressed(struct inode *inode, 407494afd6d6SChao Yu pgoff_t fofs, block_t blkaddr, unsigned int llen, 407594afd6d6SChao Yu unsigned int c_len); 40764c8ff709SChao Yu int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, 40774c8ff709SChao Yu unsigned nr_pages, sector_t *last_block_in_bio, 40780683728aSChao Yu bool is_readahead, bool for_write); 40794c8ff709SChao Yu struct decompress_io_ctx *f2fs_alloc_dic(struct compress_ctx *cc); 40807f59b277SEric Biggers void f2fs_decompress_end_io(struct decompress_io_ctx *dic, bool failed); 40817f59b277SEric Biggers void f2fs_put_page_dic(struct page *page); 408294afd6d6SChao Yu unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn); 40834c8ff709SChao Yu int f2fs_init_compress_ctx(struct compress_ctx *cc); 40848bfbfb0dSChao Yu void f2fs_destroy_compress_ctx(struct compress_ctx *cc, bool reuse); 40854c8ff709SChao Yu void f2fs_init_compress_info(struct f2fs_sb_info *sbi); 40866ce19affSChao Yu int f2fs_init_compress_inode(struct f2fs_sb_info *sbi); 40876ce19affSChao Yu void f2fs_destroy_compress_inode(struct f2fs_sb_info *sbi); 408831083031SChao Yu int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi); 408931083031SChao Yu void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi); 4090c68d6c88SChao Yu int __init f2fs_init_compress_cache(void); 4091c68d6c88SChao Yu void f2fs_destroy_compress_cache(void); 40926ce19affSChao Yu struct address_space *COMPRESS_MAPPING(struct f2fs_sb_info *sbi); 40936ce19affSChao Yu void f2fs_invalidate_compress_page(struct f2fs_sb_info *sbi, block_t blkaddr); 40946ce19affSChao Yu void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, struct page *page, 40956ce19affSChao Yu nid_t ino, block_t blkaddr); 40966ce19affSChao Yu bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi, struct page *page, 40976ce19affSChao Yu block_t blkaddr); 40986ce19affSChao Yu void f2fs_invalidate_compress_pages(struct f2fs_sb_info *sbi, nid_t ino); 40995ac443e2SDaeho Jeong #define inc_compr_inode_stat(inode) \ 41005ac443e2SDaeho Jeong do { \ 41015ac443e2SDaeho Jeong struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ 41025ac443e2SDaeho Jeong sbi->compr_new_inode++; \ 41035ac443e2SDaeho Jeong } while (0) 41045ac443e2SDaeho Jeong #define add_compr_block_stat(inode, blocks) \ 41055ac443e2SDaeho Jeong do { \ 41065ac443e2SDaeho Jeong struct f2fs_sb_info *sbi = F2FS_I_SB(inode); \ 41075ac443e2SDaeho Jeong int diff = F2FS_I(inode)->i_cluster_size - blocks; \ 41085ac443e2SDaeho Jeong sbi->compr_written_block += blocks; \ 41095ac443e2SDaeho Jeong sbi->compr_saved_block += diff; \ 41105ac443e2SDaeho Jeong } while (0) 41114c8ff709SChao Yu #else 41124c8ff709SChao Yu static inline bool f2fs_is_compressed_page(struct page *page) { return false; } 41134c8ff709SChao Yu static inline bool f2fs_is_compress_backend_ready(struct inode *inode) 41144c8ff709SChao Yu { 41154c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 41164c8ff709SChao Yu return true; 41174c8ff709SChao Yu /* not support compression */ 41184c8ff709SChao Yu return false; 41194c8ff709SChao Yu } 41204c8ff709SChao Yu static inline struct page *f2fs_compress_control_page(struct page *page) 41214c8ff709SChao Yu { 41224c8ff709SChao Yu WARN_ON_ONCE(1); 41234c8ff709SChao Yu return ERR_PTR(-EINVAL); 41244c8ff709SChao Yu } 41255e6bbde9SChao Yu static inline int f2fs_init_compress_mempool(void) { return 0; } 41265e6bbde9SChao Yu static inline void f2fs_destroy_compress_mempool(void) { } 41276ce19affSChao Yu static inline void f2fs_decompress_cluster(struct decompress_io_ctx *dic) { } 41286ce19affSChao Yu static inline void f2fs_end_read_compressed_page(struct page *page, 41296ce19affSChao Yu bool failed, block_t blkaddr) 41307f59b277SEric Biggers { 41317f59b277SEric Biggers WARN_ON_ONCE(1); 41327f59b277SEric Biggers } 41337f59b277SEric Biggers static inline void f2fs_put_page_dic(struct page *page) 41347f59b277SEric Biggers { 41357f59b277SEric Biggers WARN_ON_ONCE(1); 41367f59b277SEric Biggers } 413794afd6d6SChao Yu static inline unsigned int f2fs_cluster_blocks_are_contiguous(struct dnode_of_data *dn) { return 0; } 4138bbe1da7eSChao Yu static inline bool f2fs_sanity_check_cluster(struct dnode_of_data *dn) { return false; } 41396ce19affSChao Yu static inline int f2fs_init_compress_inode(struct f2fs_sb_info *sbi) { return 0; } 41406ce19affSChao Yu static inline void f2fs_destroy_compress_inode(struct f2fs_sb_info *sbi) { } 414131083031SChao Yu static inline int f2fs_init_page_array_cache(struct f2fs_sb_info *sbi) { return 0; } 414231083031SChao Yu static inline void f2fs_destroy_page_array_cache(struct f2fs_sb_info *sbi) { } 4143c68d6c88SChao Yu static inline int __init f2fs_init_compress_cache(void) { return 0; } 4144c68d6c88SChao Yu static inline void f2fs_destroy_compress_cache(void) { } 41456ce19affSChao Yu static inline void f2fs_invalidate_compress_page(struct f2fs_sb_info *sbi, 41466ce19affSChao Yu block_t blkaddr) { } 41476ce19affSChao Yu static inline void f2fs_cache_compressed_page(struct f2fs_sb_info *sbi, 41486ce19affSChao Yu struct page *page, nid_t ino, block_t blkaddr) { } 41496ce19affSChao Yu static inline bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi, 41506ce19affSChao Yu struct page *page, block_t blkaddr) { return false; } 41516ce19affSChao Yu static inline void f2fs_invalidate_compress_pages(struct f2fs_sb_info *sbi, 41526ce19affSChao Yu nid_t ino) { } 41535ac443e2SDaeho Jeong #define inc_compr_inode_stat(inode) do { } while (0) 415494afd6d6SChao Yu static inline void f2fs_update_extent_tree_range_compressed(struct inode *inode, 415594afd6d6SChao Yu pgoff_t fofs, block_t blkaddr, unsigned int llen, 415694afd6d6SChao Yu unsigned int c_len) { } 41574c8ff709SChao Yu #endif 41584c8ff709SChao Yu 41594c8ff709SChao Yu static inline void set_compress_context(struct inode *inode) 41604c8ff709SChao Yu { 41614c8ff709SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 41624c8ff709SChao Yu 41634c8ff709SChao Yu F2FS_I(inode)->i_compress_algorithm = 41644c8ff709SChao Yu F2FS_OPTION(sbi).compress_algorithm; 41654c8ff709SChao Yu F2FS_I(inode)->i_log_cluster_size = 41664c8ff709SChao Yu F2FS_OPTION(sbi).compress_log_size; 4167b28f047bSChao Yu F2FS_I(inode)->i_compress_flag = 4168b28f047bSChao Yu F2FS_OPTION(sbi).compress_chksum ? 4169b28f047bSChao Yu 1 << COMPRESS_CHKSUM : 0; 41704c8ff709SChao Yu F2FS_I(inode)->i_cluster_size = 41714c8ff709SChao Yu 1 << F2FS_I(inode)->i_log_cluster_size; 417201f6afd0SChao Yu if ((F2FS_I(inode)->i_compress_algorithm == COMPRESS_LZ4 || 417301f6afd0SChao Yu F2FS_I(inode)->i_compress_algorithm == COMPRESS_ZSTD) && 41743fde13f8SChao Yu F2FS_OPTION(sbi).compress_level) 41753fde13f8SChao Yu F2FS_I(inode)->i_compress_flag |= 41763fde13f8SChao Yu F2FS_OPTION(sbi).compress_level << 41773fde13f8SChao Yu COMPRESS_LEVEL_OFFSET; 41784c8ff709SChao Yu F2FS_I(inode)->i_flags |= F2FS_COMPR_FL; 41794c8ff709SChao Yu set_inode_flag(inode, FI_COMPRESSED_FILE); 41804c8ff709SChao Yu stat_inc_compr_inode(inode); 41815ac443e2SDaeho Jeong inc_compr_inode_stat(inode); 4182530e0704SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 41834c8ff709SChao Yu } 41844c8ff709SChao Yu 418578134d03SDaeho Jeong static inline bool f2fs_disable_compressed_file(struct inode *inode) 41864c8ff709SChao Yu { 41874c8ff709SChao Yu struct f2fs_inode_info *fi = F2FS_I(inode); 41884c8ff709SChao Yu 41894c8ff709SChao Yu if (!f2fs_compressed_file(inode)) 419078134d03SDaeho Jeong return true; 419102d58cd2SHyeong-Jun Kim if (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode)) 419278134d03SDaeho Jeong return false; 41934c8ff709SChao Yu 41944c8ff709SChao Yu fi->i_flags &= ~F2FS_COMPR_FL; 41954c8ff709SChao Yu stat_dec_compr_inode(inode); 419696f5b4faSChao Yu clear_inode_flag(inode, FI_COMPRESSED_FILE); 4197530e0704SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 419878134d03SDaeho Jeong return true; 4199cde4de12SJaegeuk Kim } 4200cde4de12SJaegeuk Kim 4201ccd31cb2SSheng Yong #define F2FS_FEATURE_FUNCS(name, flagname) \ 42027beb01f7SChao Yu static inline int f2fs_sb_has_##name(struct f2fs_sb_info *sbi) \ 4203ccd31cb2SSheng Yong { \ 42047beb01f7SChao Yu return F2FS_HAS_FEATURE(sbi, F2FS_FEATURE_##flagname); \ 4205cde4de12SJaegeuk Kim } 4206f424f664SJaegeuk Kim 4207ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(encrypt, ENCRYPT); 4208ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(blkzoned, BLKZONED); 4209ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(extra_attr, EXTRA_ATTR); 4210ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(project_quota, PRJQUOTA); 4211ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_chksum, INODE_CHKSUM); 4212ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(flexible_inline_xattr, FLEXIBLE_INLINE_XATTR); 4213ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); 4214ccd31cb2SSheng Yong F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); 4215b7c409deSSheng Yong F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); 421695ae251fSEric Biggers F2FS_FEATURE_FUNCS(verity, VERITY); 4217d440c52dSJunling Zheng F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); 42185aba5430SDaniel Rosenberg F2FS_FEATURE_FUNCS(casefold, CASEFOLD); 42194c8ff709SChao Yu F2FS_FEATURE_FUNCS(compression, COMPRESSION); 4220a7d9fe3cSJaegeuk Kim F2FS_FEATURE_FUNCS(readonly, RO); 42211c1d35dfSChao Yu 42224215d054SDaeho Jeong static inline bool f2fs_may_extent_tree(struct inode *inode) 42234215d054SDaeho Jeong { 42244215d054SDaeho Jeong struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 42254215d054SDaeho Jeong 42264215d054SDaeho Jeong if (!test_opt(sbi, EXTENT_CACHE) || 42274215d054SDaeho Jeong is_inode_flag_set(inode, FI_NO_EXTENT) || 42284215d054SDaeho Jeong (is_inode_flag_set(inode, FI_COMPRESSED_FILE) && 42294215d054SDaeho Jeong !f2fs_sb_has_readonly(sbi))) 42304215d054SDaeho Jeong return false; 42314215d054SDaeho Jeong 42324215d054SDaeho Jeong /* 42334215d054SDaeho Jeong * for recovered files during mount do not create extents 42344215d054SDaeho Jeong * if shrinker is not registered. 42354215d054SDaeho Jeong */ 42364215d054SDaeho Jeong if (list_empty(&sbi->s_list)) 42374215d054SDaeho Jeong return false; 42384215d054SDaeho Jeong 42394215d054SDaeho Jeong return S_ISREG(inode->i_mode); 42404215d054SDaeho Jeong } 42414215d054SDaeho Jeong 4242178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 424395175dafSDamien Le Moal static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, 424495175dafSDamien Le Moal block_t blkaddr) 4245178053e2SDamien Le Moal { 4246178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 4247178053e2SDamien Le Moal 424895175dafSDamien Le Moal return test_bit(zno, FDEV(devi).blkz_seq); 4249178053e2SDamien Le Moal } 4250178053e2SDamien Le Moal #endif 4251178053e2SDamien Le Moal 42527d20c8abSChao Yu static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi) 425396ba2decSDamien Le Moal { 42547beb01f7SChao Yu return f2fs_sb_has_blkzoned(sbi); 42557d20c8abSChao Yu } 425696ba2decSDamien Le Moal 42577f3d7719SDamien Le Moal static inline bool f2fs_bdev_support_discard(struct block_device *bdev) 42587f3d7719SDamien Le Moal { 42597f3d7719SDamien Le Moal return blk_queue_discard(bdev_get_queue(bdev)) || 42607f3d7719SDamien Le Moal bdev_is_zoned(bdev); 42617f3d7719SDamien Le Moal } 42627f3d7719SDamien Le Moal 42637d20c8abSChao Yu static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi) 42647d20c8abSChao Yu { 42657f3d7719SDamien Le Moal int i; 42667f3d7719SDamien Le Moal 42677f3d7719SDamien Le Moal if (!f2fs_is_multi_device(sbi)) 42687f3d7719SDamien Le Moal return f2fs_bdev_support_discard(sbi->sb->s_bdev); 42697f3d7719SDamien Le Moal 42707f3d7719SDamien Le Moal for (i = 0; i < sbi->s_ndevs; i++) 42717f3d7719SDamien Le Moal if (f2fs_bdev_support_discard(FDEV(i).bdev)) 42727f3d7719SDamien Le Moal return true; 42737f3d7719SDamien Le Moal return false; 42747d20c8abSChao Yu } 42757d20c8abSChao Yu 42767d20c8abSChao Yu static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi) 42777d20c8abSChao Yu { 42787d20c8abSChao Yu return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) || 42797d20c8abSChao Yu f2fs_hw_should_discard(sbi); 428052763a4bSJaegeuk Kim } 428152763a4bSJaegeuk Kim 4282f824deb5SChao Yu static inline bool f2fs_hw_is_readonly(struct f2fs_sb_info *sbi) 4283f824deb5SChao Yu { 4284f824deb5SChao Yu int i; 4285f824deb5SChao Yu 4286f824deb5SChao Yu if (!f2fs_is_multi_device(sbi)) 4287f824deb5SChao Yu return bdev_read_only(sbi->sb->s_bdev); 4288f824deb5SChao Yu 4289f824deb5SChao Yu for (i = 0; i < sbi->s_ndevs; i++) 4290f824deb5SChao Yu if (bdev_read_only(FDEV(i).bdev)) 4291f824deb5SChao Yu return true; 4292f824deb5SChao Yu return false; 4293f824deb5SChao Yu } 4294f824deb5SChao Yu 4295b0332a0fSChao Yu static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi) 429652763a4bSJaegeuk Kim { 4297b0332a0fSChao Yu return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS; 429852763a4bSJaegeuk Kim } 429952763a4bSJaegeuk Kim 43004c8ff709SChao Yu static inline bool f2fs_may_compress(struct inode *inode) 43014c8ff709SChao Yu { 43024c8ff709SChao Yu if (IS_SWAPFILE(inode) || f2fs_is_pinned_file(inode) || 43034c8ff709SChao Yu f2fs_is_atomic_file(inode) || 43044c8ff709SChao Yu f2fs_is_volatile_file(inode)) 43054c8ff709SChao Yu return false; 43064c8ff709SChao Yu return S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode); 43074c8ff709SChao Yu } 43084c8ff709SChao Yu 43094c8ff709SChao Yu static inline void f2fs_i_compr_blocks_update(struct inode *inode, 43104c8ff709SChao Yu u64 blocks, bool add) 43114c8ff709SChao Yu { 43124c8ff709SChao Yu int diff = F2FS_I(inode)->i_cluster_size - blocks; 4313c2759ebaSDaeho Jeong struct f2fs_inode_info *fi = F2FS_I(inode); 43144c8ff709SChao Yu 4315ef8d563fSChao Yu /* don't update i_compr_blocks if saved blocks were released */ 4316c2759ebaSDaeho Jeong if (!add && !atomic_read(&fi->i_compr_blocks)) 4317ef8d563fSChao Yu return; 4318ef8d563fSChao Yu 43194c8ff709SChao Yu if (add) { 4320c2759ebaSDaeho Jeong atomic_add(diff, &fi->i_compr_blocks); 43214c8ff709SChao Yu stat_add_compr_blocks(inode, diff); 43224c8ff709SChao Yu } else { 4323c2759ebaSDaeho Jeong atomic_sub(diff, &fi->i_compr_blocks); 43244c8ff709SChao Yu stat_sub_compr_blocks(inode, diff); 43254c8ff709SChao Yu } 43264c8ff709SChao Yu f2fs_mark_inode_dirty_sync(inode, true); 43274c8ff709SChao Yu } 43284c8ff709SChao Yu 4329f847c699SChao Yu static inline int block_unaligned_IO(struct inode *inode, 4330f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4331b91050a8SHyunchul Lee { 4332f847c699SChao Yu unsigned int i_blkbits = READ_ONCE(inode->i_blkbits); 4333f847c699SChao Yu unsigned int blocksize_mask = (1 << i_blkbits) - 1; 4334f847c699SChao Yu loff_t offset = iocb->ki_pos; 4335f847c699SChao Yu unsigned long align = offset | iov_iter_alignment(iter); 4336f847c699SChao Yu 4337f847c699SChao Yu return align & blocksize_mask; 4338f847c699SChao Yu } 4339f847c699SChao Yu 434071f2c820SChao Yu static inline bool f2fs_allow_multi_device_dio(struct f2fs_sb_info *sbi, 434171f2c820SChao Yu int flag) 434271f2c820SChao Yu { 434371f2c820SChao Yu if (!f2fs_is_multi_device(sbi)) 434471f2c820SChao Yu return false; 434571f2c820SChao Yu if (flag != F2FS_GET_BLOCK_DIO) 434671f2c820SChao Yu return false; 434771f2c820SChao Yu return sbi->aligned_blksize; 434871f2c820SChao Yu } 434971f2c820SChao Yu 4350f847c699SChao Yu static inline bool f2fs_force_buffered_io(struct inode *inode, 4351f847c699SChao Yu struct kiocb *iocb, struct iov_iter *iter) 4352f847c699SChao Yu { 4353f847c699SChao Yu struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 4354f847c699SChao Yu int rw = iov_iter_rw(iter); 4355f847c699SChao Yu 4356f847c699SChao Yu if (f2fs_post_read_required(inode)) 4357f847c699SChao Yu return true; 435871f2c820SChao Yu 435971f2c820SChao Yu /* disallow direct IO if any of devices has unaligned blksize */ 436071f2c820SChao Yu if (f2fs_is_multi_device(sbi) && !sbi->aligned_blksize) 4361f847c699SChao Yu return true; 4362f847c699SChao Yu /* 4363f847c699SChao Yu * for blkzoned device, fallback direct IO to buffered IO, so 4364f847c699SChao Yu * all IOs can be serialized by log-structured write. 4365f847c699SChao Yu */ 43667beb01f7SChao Yu if (f2fs_sb_has_blkzoned(sbi)) 4367f847c699SChao Yu return true; 4368b0332a0fSChao Yu if (f2fs_lfs_mode(sbi) && (rw == WRITE)) { 43699720ee80SChao Yu if (block_unaligned_IO(inode, iocb, iter)) 4370f847c699SChao Yu return true; 43719720ee80SChao Yu if (F2FS_IO_ALIGNED(sbi)) 43729720ee80SChao Yu return true; 43739720ee80SChao Yu } 4374ebc29b62Shuangjianan@oppo.com if (is_sbi_flag_set(F2FS_I_SB(inode), SBI_CP_DISABLED)) 43754354994fSDaniel Rosenberg return true; 43764354994fSDaniel Rosenberg 4377f847c699SChao Yu return false; 4378b91050a8SHyunchul Lee } 4379b91050a8SHyunchul Lee 43807f59b277SEric Biggers static inline bool f2fs_need_verity(const struct inode *inode, pgoff_t idx) 43817f59b277SEric Biggers { 43827f59b277SEric Biggers return fsverity_active(inode) && 43837f59b277SEric Biggers idx < DIV_ROUND_UP(inode->i_size, PAGE_SIZE); 43847f59b277SEric Biggers } 43857f59b277SEric Biggers 438683a3bfdbSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 4387d494500aSChao Yu extern void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, 4388d494500aSChao Yu unsigned int type); 438983a3bfdbSJaegeuk Kim #else 4390d494500aSChao Yu #define f2fs_build_fault_attr(sbi, rate, type) do { } while (0) 439183a3bfdbSJaegeuk Kim #endif 439283a3bfdbSJaegeuk Kim 4393af033b2aSChao Yu static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) 4394af033b2aSChao Yu { 4395af033b2aSChao Yu #ifdef CONFIG_QUOTA 43967beb01f7SChao Yu if (f2fs_sb_has_quota_ino(sbi)) 4397af033b2aSChao Yu return true; 4398af033b2aSChao Yu if (F2FS_OPTION(sbi).s_qf_names[USRQUOTA] || 4399af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[GRPQUOTA] || 4400af033b2aSChao Yu F2FS_OPTION(sbi).s_qf_names[PRJQUOTA]) 4401af033b2aSChao Yu return true; 4402af033b2aSChao Yu #endif 4403af033b2aSChao Yu return false; 4404af033b2aSChao Yu } 44050af725fcSJaegeuk Kim 44064f993264SChao Yu static inline bool f2fs_block_unit_discard(struct f2fs_sb_info *sbi) 44074f993264SChao Yu { 44084f993264SChao Yu return F2FS_OPTION(sbi).discard_unit == DISCARD_UNIT_BLOCK; 44094f993264SChao Yu } 44104f993264SChao Yu 441110f966bbSChao Yu #define EFSBADCRC EBADMSG /* Bad CRC detected */ 441210f966bbSChao Yu #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ 441310f966bbSChao Yu 4414e1074d4bSChao Yu #endif /* _LINUX_F2FS_H */ 4415