10a8165d7SJaegeuk Kim /* 239a53e0cSJaegeuk Kim * fs/f2fs/f2fs.h 339a53e0cSJaegeuk Kim * 439a53e0cSJaegeuk Kim * Copyright (c) 2012 Samsung Electronics Co., Ltd. 539a53e0cSJaegeuk Kim * http://www.samsung.com/ 639a53e0cSJaegeuk Kim * 739a53e0cSJaegeuk Kim * This program is free software; you can redistribute it and/or modify 839a53e0cSJaegeuk Kim * it under the terms of the GNU General Public License version 2 as 939a53e0cSJaegeuk Kim * published by the Free Software Foundation. 1039a53e0cSJaegeuk Kim */ 1139a53e0cSJaegeuk Kim #ifndef _LINUX_F2FS_H 1239a53e0cSJaegeuk Kim #define _LINUX_F2FS_H 1339a53e0cSJaegeuk Kim 1439a53e0cSJaegeuk Kim #include <linux/types.h> 1539a53e0cSJaegeuk Kim #include <linux/page-flags.h> 1639a53e0cSJaegeuk Kim #include <linux/buffer_head.h> 1739a53e0cSJaegeuk Kim #include <linux/slab.h> 1839a53e0cSJaegeuk Kim #include <linux/crc32.h> 1939a53e0cSJaegeuk Kim #include <linux/magic.h> 20c2d715d1SJaegeuk Kim #include <linux/kobject.h> 217bd59381SGu Zheng #include <linux/sched.h> 2239307a8eSJaegeuk Kim #include <linux/vmalloc.h> 23740432f8SJaegeuk Kim #include <linux/bio.h> 24d0239e1bSJaegeuk Kim #include <linux/blkdev.h> 250abd675eSChao Yu #include <linux/quotaops.h> 2646f47e48SEric Biggers #ifdef CONFIG_F2FS_FS_ENCRYPTION 2746f47e48SEric Biggers #include <linux/fscrypt_supp.h> 2846f47e48SEric Biggers #else 2946f47e48SEric Biggers #include <linux/fscrypt_notsupp.h> 3046f47e48SEric Biggers #endif 3143b6573bSKeith Mok #include <crypto/hash.h> 3239a53e0cSJaegeuk Kim 335d56b671SJaegeuk Kim #ifdef CONFIG_F2FS_CHECK_FS 349850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) BUG_ON(condition) 355d56b671SJaegeuk Kim #else 369850cf4aSJaegeuk Kim #define f2fs_bug_on(sbi, condition) \ 379850cf4aSJaegeuk Kim do { \ 389850cf4aSJaegeuk Kim if (unlikely(condition)) { \ 399850cf4aSJaegeuk Kim WARN_ON(1); \ 40caf0047eSChao Yu set_sbi_flag(sbi, SBI_NEED_FSCK); \ 419850cf4aSJaegeuk Kim } \ 429850cf4aSJaegeuk Kim } while (0) 435d56b671SJaegeuk Kim #endif 445d56b671SJaegeuk Kim 452c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 462c63feadSJaegeuk Kim enum { 472c63feadSJaegeuk Kim FAULT_KMALLOC, 48c41f3cc3SJaegeuk Kim FAULT_PAGE_ALLOC, 49cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 50cb78942bSJaegeuk Kim FAULT_ORPHAN, 51cb78942bSJaegeuk Kim FAULT_BLOCK, 52cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5353aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 5414b44d23SJaegeuk Kim FAULT_TRUNCATE, 558b038c70SChao Yu FAULT_IO, 560f348028SChao Yu FAULT_CHECKPOINT, 572c63feadSJaegeuk Kim FAULT_MAX, 582c63feadSJaegeuk Kim }; 592c63feadSJaegeuk Kim 6008796897SSheng Yong struct f2fs_fault_info { 6108796897SSheng Yong atomic_t inject_ops; 6208796897SSheng Yong unsigned int inject_rate; 6308796897SSheng Yong unsigned int inject_type; 6408796897SSheng Yong }; 6508796897SSheng Yong 662c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX]; 6768afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 682c63feadSJaegeuk Kim #endif 692c63feadSJaegeuk Kim 7039a53e0cSJaegeuk Kim /* 7139a53e0cSJaegeuk Kim * For mount options 7239a53e0cSJaegeuk Kim */ 7339a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 7439a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7539a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 80444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 811001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8234d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8334d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8434d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 85d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8689672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 876aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 88343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 8973faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 9036abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 9136abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 920abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA 0x00080000 930abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA 0x00100000 945c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA 0x00200000 954b2414d0SChao Yu #define F2FS_MOUNT_QUOTA 0x00400000 9639a53e0cSJaegeuk Kim 9768afcf2dSTomohiro Kusumi #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) 9868afcf2dSTomohiro Kusumi #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) 9968afcf2dSTomohiro Kusumi #define test_opt(sbi, option) ((sbi)->mount_opt.opt & F2FS_MOUNT_##option) 10039a53e0cSJaegeuk Kim 10139a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 10239a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 10339a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 10439a53e0cSJaegeuk Kim 105a9841c4dSJaegeuk Kim typedef u32 block_t; /* 106a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 107a9841c4dSJaegeuk Kim * address format, __le32. 108a9841c4dSJaegeuk Kim */ 10939a53e0cSJaegeuk Kim typedef u32 nid_t; 11039a53e0cSJaegeuk Kim 11139a53e0cSJaegeuk Kim struct f2fs_mount_info { 11239a53e0cSJaegeuk Kim unsigned int opt; 11339a53e0cSJaegeuk Kim }; 11439a53e0cSJaegeuk Kim 115cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1160bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 117e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1187a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1195c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 120704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 121cde4de12SJaegeuk Kim 12276f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 12376f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 12476f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 125c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 12676f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 127c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 12876f105a2SJaegeuk Kim 12939a53e0cSJaegeuk Kim /* 13039a53e0cSJaegeuk Kim * For checkpoint manager 13139a53e0cSJaegeuk Kim */ 13239a53e0cSJaegeuk Kim enum { 13339a53e0cSJaegeuk Kim NAT_BITMAP, 13439a53e0cSJaegeuk Kim SIT_BITMAP 13539a53e0cSJaegeuk Kim }; 13639a53e0cSJaegeuk Kim 137c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 138c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 139c473f1a9SChao Yu #define CP_SYNC 0x00000004 140c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 141c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1421f43e2adSChao Yu #define CP_TRIMMED 0x00000020 14375ab4cb8SJaegeuk Kim 14447b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 145bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 1464ddb1a4dSJaegeuk Kim (GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections)) 147a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 148a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 1494ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 15015469963SJaegeuk Kim #define DISCARD_ISSUE_RATE 8 151969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 152969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 15360b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 154dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 155bba681cbSJaegeuk Kim 15675ab4cb8SJaegeuk Kim struct cp_control { 15775ab4cb8SJaegeuk Kim int reason; 1584b2fecc8SJaegeuk Kim __u64 trim_start; 1594b2fecc8SJaegeuk Kim __u64 trim_end; 1604b2fecc8SJaegeuk Kim __u64 trim_minlen; 1614b2fecc8SJaegeuk Kim __u64 trimmed; 16275ab4cb8SJaegeuk Kim }; 16375ab4cb8SJaegeuk Kim 164662befdaSChao Yu /* 16581c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 166662befdaSChao Yu */ 167662befdaSChao Yu enum { 168662befdaSChao Yu META_CP, 169662befdaSChao Yu META_NAT, 17081c1a0f1SChao Yu META_SIT, 1714c521f49SJaegeuk Kim META_SSA, 1724c521f49SJaegeuk Kim META_POR, 173662befdaSChao Yu }; 174662befdaSChao Yu 1756451e041SJaegeuk Kim /* for the list of ino */ 1766451e041SJaegeuk Kim enum { 1776451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 178fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 179fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 1806451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1816451e041SJaegeuk Kim }; 1826451e041SJaegeuk Kim 1836451e041SJaegeuk Kim struct ino_entry { 18439a53e0cSJaegeuk Kim struct list_head list; /* list head */ 18539a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 18639a53e0cSJaegeuk Kim }; 18739a53e0cSJaegeuk Kim 1882710fd7eSChao Yu /* for the list of inodes to be GCed */ 18906292073SChao Yu struct inode_entry { 19039a53e0cSJaegeuk Kim struct list_head list; /* list head */ 19139a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 19239a53e0cSJaegeuk Kim }; 19339a53e0cSJaegeuk Kim 194a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 1957fd9e544SJaegeuk Kim struct discard_entry { 1967fd9e544SJaegeuk Kim struct list_head list; /* list head */ 197a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 198a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 1997fd9e544SJaegeuk Kim }; 2007fd9e544SJaegeuk Kim 201969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 202969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 203969d1b18SChao Yu 204ba48a33eSChao Yu /* max discard pend list number */ 205ba48a33eSChao Yu #define MAX_PLIST_NUM 512 206ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 207ba48a33eSChao Yu (MAX_PLIST_NUM - 1) : (blk_num - 1)) 208ba48a33eSChao Yu 209969d1b18SChao Yu #define P_ACTIVE 0x01 210969d1b18SChao Yu #define P_TRIM 0x02 211969d1b18SChao Yu #define plist_issue(tag) (((tag) & P_ACTIVE) || ((tag) & P_TRIM)) 212969d1b18SChao Yu 21315469963SJaegeuk Kim enum { 21415469963SJaegeuk Kim D_PREP, 21515469963SJaegeuk Kim D_SUBMIT, 21615469963SJaegeuk Kim D_DONE, 21715469963SJaegeuk Kim }; 21815469963SJaegeuk Kim 219004b6862SChao Yu struct discard_info { 220b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 221b01a9201SJaegeuk Kim block_t len; /* length */ 222004b6862SChao Yu block_t start; /* actual start address in dev */ 223004b6862SChao Yu }; 224004b6862SChao Yu 225b01a9201SJaegeuk Kim struct discard_cmd { 226004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 227004b6862SChao Yu union { 228004b6862SChao Yu struct { 229004b6862SChao Yu block_t lstart; /* logical start address */ 230004b6862SChao Yu block_t len; /* length */ 231004b6862SChao Yu block_t start; /* actual start address in dev */ 232004b6862SChao Yu }; 233004b6862SChao Yu struct discard_info di; /* discard info */ 234004b6862SChao Yu 235004b6862SChao Yu }; 236b01a9201SJaegeuk Kim struct list_head list; /* command list */ 237b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 238c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 239ec9895adSChao Yu unsigned short ref; /* reference count */ 2409a744b92SChao Yu unsigned char state; /* state */ 241c81abe34SJaegeuk Kim int error; /* bio error */ 242275b66b0SChao Yu }; 243275b66b0SChao Yu 2440b54fb84SJaegeuk Kim struct discard_cmd_control { 24515469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 24646f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 247ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 248969d1b18SChao Yu unsigned char pend_list_tag[MAX_PLIST_NUM];/* tag for pending entries */ 24946f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 25015469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 251969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 25215469963SJaegeuk Kim struct mutex cmd_lock; 253d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 254d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 255969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 256d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 2578b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 2588b8dd65fSChao Yu atomic_t issing_discard; /* # of issing discard */ 2595f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 260004b6862SChao Yu struct rb_root root; /* root of discard rb-tree */ 26139a53e0cSJaegeuk Kim }; 26239a53e0cSJaegeuk Kim 26339a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 26439a53e0cSJaegeuk Kim struct fsync_inode_entry { 26539a53e0cSJaegeuk Kim struct list_head list; /* list head */ 26639a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 267c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 268c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 26939a53e0cSJaegeuk Kim }; 27039a53e0cSJaegeuk Kim 27168afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 27268afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 27339a53e0cSJaegeuk Kim 27468afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 27568afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 27668afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 27768afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 27839a53e0cSJaegeuk Kim 279dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 280dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 281309cc2b6SJaegeuk Kim 282dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 28339a53e0cSJaegeuk Kim { 284dfc08a12SChao Yu int before = nats_in_cursum(journal); 285cac5a3d8SDongOh Shin 286dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 28739a53e0cSJaegeuk Kim return before; 28839a53e0cSJaegeuk Kim } 28939a53e0cSJaegeuk Kim 290dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 29139a53e0cSJaegeuk Kim { 292dfc08a12SChao Yu int before = sits_in_cursum(journal); 293cac5a3d8SDongOh Shin 294dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 29539a53e0cSJaegeuk Kim return before; 29639a53e0cSJaegeuk Kim } 29739a53e0cSJaegeuk Kim 298dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 299dfc08a12SChao Yu int size, int type) 300184a5cd2SChao Yu { 301184a5cd2SChao Yu if (type == NAT_JOURNAL) 302dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 303dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 304184a5cd2SChao Yu } 305184a5cd2SChao Yu 30639a53e0cSJaegeuk Kim /* 307e9750824SNamjae Jeon * ioctl commands 308e9750824SNamjae Jeon */ 309e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 310e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 311d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 312e9750824SNamjae Jeon 31388b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 31488b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 31588b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 31602a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 3171e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 3181e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 319d07efb50SJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32) 320456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 321d07efb50SJaegeuk Kim #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \ 322d07efb50SJaegeuk Kim struct f2fs_defragment) 3234dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 3244dd6f977SJaegeuk Kim struct f2fs_move_range) 325e066b83cSJaegeuk Kim #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ 326e066b83cSJaegeuk Kim struct f2fs_flush_device) 32734dc77adSJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ 32834dc77adSJaegeuk Kim struct f2fs_gc_range) 329e65ef207SJaegeuk Kim #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) 33088b88a66SJaegeuk Kim 3310b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 3320b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 3330b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 334f424f664SJaegeuk Kim 3351abff93dSJaegeuk Kim /* 3361abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 3371abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 3381abff93dSJaegeuk Kim */ 3391abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 3401abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 3411abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 3421abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 343c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 3441abff93dSJaegeuk Kim 345e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 346e9750824SNamjae Jeon /* 347e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 348e9750824SNamjae Jeon */ 349e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 350e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 35104ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 352e9750824SNamjae Jeon #endif 353e9750824SNamjae Jeon 3542c1d0305SChao Yu #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR 3552c1d0305SChao Yu #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR 3562c1d0305SChao Yu 35734dc77adSJaegeuk Kim struct f2fs_gc_range { 35834dc77adSJaegeuk Kim u32 sync; 35934dc77adSJaegeuk Kim u64 start; 36034dc77adSJaegeuk Kim u64 len; 36134dc77adSJaegeuk Kim }; 36234dc77adSJaegeuk Kim 363d323d005SChao Yu struct f2fs_defragment { 364d323d005SChao Yu u64 start; 365d323d005SChao Yu u64 len; 366d323d005SChao Yu }; 367d323d005SChao Yu 3684dd6f977SJaegeuk Kim struct f2fs_move_range { 3694dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3704dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3714dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3724dd6f977SJaegeuk Kim u64 len; /* size to move */ 3734dd6f977SJaegeuk Kim }; 3744dd6f977SJaegeuk Kim 375e066b83cSJaegeuk Kim struct f2fs_flush_device { 376e066b83cSJaegeuk Kim u32 dev_num; /* device number to flush */ 377e066b83cSJaegeuk Kim u32 segments; /* # of segments to flush */ 378e066b83cSJaegeuk Kim }; 379e066b83cSJaegeuk Kim 380f2470371SChao Yu /* for inline stuff */ 381f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 3827a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 3837a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 3847a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 3857a2af766SChao Yu DEF_INLINE_RESERVED_SIZE - \ 386f2470371SChao Yu F2FS_INLINE_XATTR_ADDRS)) 387f2470371SChao Yu 388f2470371SChao Yu /* for inline dir */ 389f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 390f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 391f2470371SChao Yu BITS_PER_BYTE + 1)) 392f2470371SChao Yu #define INLINE_DENTRY_BITMAP_SIZE(inode) ((NR_INLINE_DENTRY(inode) + \ 393f2470371SChao Yu BITS_PER_BYTE - 1) / BITS_PER_BYTE) 394f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 395f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 396f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 397f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 398f2470371SChao Yu 399e9750824SNamjae Jeon /* 40039a53e0cSJaegeuk Kim * For INODE and NODE manager 40139a53e0cSJaegeuk Kim */ 4027b3cd7d6SJaegeuk Kim /* for directory operations */ 4037b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 404d8c6822aSJaegeuk Kim struct inode *inode; 40576a9dd85SChao Yu void *bitmap; 4067b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 4077b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 4087b3cd7d6SJaegeuk Kim int max; 40976a9dd85SChao Yu int nr_bitmap; 4107b3cd7d6SJaegeuk Kim }; 4117b3cd7d6SJaegeuk Kim 41264c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 41364c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 4147b3cd7d6SJaegeuk Kim { 415d8c6822aSJaegeuk Kim d->inode = inode; 4167b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 41776a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 4187b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 4197b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 4207b3cd7d6SJaegeuk Kim d->filename = t->filename; 42164c24ecbSTomohiro Kusumi } 422cac5a3d8SDongOh Shin 42364c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 424f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 42564c24ecbSTomohiro Kusumi { 426f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 427f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 428f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 429f2470371SChao Yu 43064c24ecbSTomohiro Kusumi d->inode = inode; 431f2470371SChao Yu d->max = entry_cnt; 432f2470371SChao Yu d->nr_bitmap = bitmap_size; 433f2470371SChao Yu d->bitmap = t; 434f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 435f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 436f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 4377b3cd7d6SJaegeuk Kim } 4387b3cd7d6SJaegeuk Kim 439dbe6a5ffSJaegeuk Kim /* 440dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 441dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 442dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 44339a53e0cSJaegeuk Kim */ 444dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 445dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 446266e97a8SJaegeuk Kim enum { 447266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 448266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 449266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 450266e97a8SJaegeuk Kim * look up a node with readahead called 4514f4124d0SChao Yu * by get_data_block. 45239a53e0cSJaegeuk Kim */ 453266e97a8SJaegeuk Kim }; 454266e97a8SJaegeuk Kim 455a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 45639a53e0cSJaegeuk Kim 457817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 458817202d9SChao Yu 45913054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 46013054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 46113054c54SChao Yu 46239a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 46313054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 46413054c54SChao Yu 46513054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 46613054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 467c11abd1aSJaegeuk Kim 46854c2258cSChao Yu struct rb_entry { 46954c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 47054c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 47154c2258cSChao Yu unsigned int len; /* length of the entry */ 47254c2258cSChao Yu }; 47354c2258cSChao Yu 47439a53e0cSJaegeuk Kim struct extent_info { 47539a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 476111d2495SMasanari Iida unsigned int len; /* length of the extent */ 47754c2258cSChao Yu u32 blk; /* start block address of the extent */ 47839a53e0cSJaegeuk Kim }; 47939a53e0cSJaegeuk Kim 48013054c54SChao Yu struct extent_node { 48154c2258cSChao Yu struct rb_node rb_node; 48254c2258cSChao Yu union { 48354c2258cSChao Yu struct { 48454c2258cSChao Yu unsigned int fofs; 48554c2258cSChao Yu unsigned int len; 48654c2258cSChao Yu u32 blk; 48754c2258cSChao Yu }; 48813054c54SChao Yu struct extent_info ei; /* extent info */ 48954c2258cSChao Yu 49054c2258cSChao Yu }; 49154c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 492201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 49313054c54SChao Yu }; 49413054c54SChao Yu 49513054c54SChao Yu struct extent_tree { 49613054c54SChao Yu nid_t ino; /* inode number */ 49713054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 49862c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 4993e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 500137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 50113054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 50268e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 50313054c54SChao Yu }; 50413054c54SChao Yu 50539a53e0cSJaegeuk Kim /* 506003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 507003a3e1dSJaegeuk Kim * 508003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 509003a3e1dSJaegeuk Kim */ 510003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 511003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 5127f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 5137f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 5147f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 515003a3e1dSJaegeuk Kim 516003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 517003a3e1dSJaegeuk Kim block_t m_pblk; 518003a3e1dSJaegeuk Kim block_t m_lblk; 519003a3e1dSJaegeuk Kim unsigned int m_len; 520003a3e1dSJaegeuk Kim unsigned int m_flags; 521da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 522003a3e1dSJaegeuk Kim }; 523003a3e1dSJaegeuk Kim 524e2b4e2bcSChao Yu /* for flag in get_data_block */ 525f2220c7fSQiuyang Sun enum { 526f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 527f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 528f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 529f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 530f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 531f2220c7fSQiuyang Sun }; 532e2b4e2bcSChao Yu 533003a3e1dSJaegeuk Kim /* 53439a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 53539a53e0cSJaegeuk Kim */ 53639a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 537354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 538cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 539e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 54026787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 54139a53e0cSJaegeuk Kim 542b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 543b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 544b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 545b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 546b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 547b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 548cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 549cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 550cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 551e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 552e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 55326787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 55426787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 555cde4de12SJaegeuk Kim 556ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 557ab9fa662SJaegeuk Kim 55839a53e0cSJaegeuk Kim struct f2fs_inode_info { 55939a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 56039a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 56139a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 56238431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 56339a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 5646666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 56539a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 56639a53e0cSJaegeuk Kim 56739a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 56839a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 569d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 570204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 57139a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 57239a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 57388c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 574b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 57539a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 57626de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 57788b88a66SJaegeuk Kim 5780abd675eSChao Yu #ifdef CONFIG_QUOTA 5790abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 5800abd675eSChao Yu 5810abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 5820abd675eSChao Yu qsize_t i_reserved_quota; 5830abd675eSChao Yu #endif 5840f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 5850f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 58688b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 5877a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 58888b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 5893e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 59082e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 5915a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 59227161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 593f2470371SChao Yu 5947a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 5955c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 59639a53e0cSJaegeuk Kim }; 59739a53e0cSJaegeuk Kim 59839a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 599bd933d4fSChao Yu struct f2fs_extent *i_ext) 60039a53e0cSJaegeuk Kim { 601bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 602bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 603bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 60439a53e0cSJaegeuk Kim } 60539a53e0cSJaegeuk Kim 60639a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 60739a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 60839a53e0cSJaegeuk Kim { 60939a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 6104d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 61139a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 61239a53e0cSJaegeuk Kim } 61339a53e0cSJaegeuk Kim 614429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 615429511cdSChao Yu u32 blk, unsigned int len) 616429511cdSChao Yu { 617429511cdSChao Yu ei->fofs = fofs; 618429511cdSChao Yu ei->blk = blk; 619429511cdSChao Yu ei->len = len; 620429511cdSChao Yu } 621429511cdSChao Yu 622004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 623004b6862SChao Yu struct discard_info *front) 624004b6862SChao Yu { 625004b6862SChao Yu return back->lstart + back->len == front->lstart; 626004b6862SChao Yu } 627004b6862SChao Yu 628004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 629004b6862SChao Yu struct discard_info *back) 630004b6862SChao Yu { 631004b6862SChao Yu return __is_discard_mergeable(back, cur); 632004b6862SChao Yu } 633004b6862SChao Yu 634004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 635004b6862SChao Yu struct discard_info *front) 636004b6862SChao Yu { 637004b6862SChao Yu return __is_discard_mergeable(cur, front); 638004b6862SChao Yu } 639004b6862SChao Yu 640429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 641429511cdSChao Yu struct extent_info *front) 642429511cdSChao Yu { 643429511cdSChao Yu return (back->fofs + back->len == front->fofs && 644429511cdSChao Yu back->blk + back->len == front->blk); 645429511cdSChao Yu } 646429511cdSChao Yu 647429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 648429511cdSChao Yu struct extent_info *back) 649429511cdSChao Yu { 650429511cdSChao Yu return __is_extent_mergeable(back, cur); 651429511cdSChao Yu } 652429511cdSChao Yu 653429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 654429511cdSChao Yu struct extent_info *front) 655429511cdSChao Yu { 656429511cdSChao Yu return __is_extent_mergeable(cur, front); 657429511cdSChao Yu } 658429511cdSChao Yu 659cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 660205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 661205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 6624abd3f5aSChao Yu { 663205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 6644abd3f5aSChao Yu et->largest = en->ei; 6657c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 666205b9822SJaegeuk Kim } 6674abd3f5aSChao Yu } 6684abd3f5aSChao Yu 669b8559dc2SChao Yu enum nid_list { 670b8559dc2SChao Yu FREE_NID_LIST, 671b8559dc2SChao Yu ALLOC_NID_LIST, 672b8559dc2SChao Yu MAX_NID_LIST, 673b8559dc2SChao Yu }; 674b8559dc2SChao Yu 67539a53e0cSJaegeuk Kim struct f2fs_nm_info { 67639a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 67739a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 67804d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 67939a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 680cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 681ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 6822304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 68339a53e0cSJaegeuk Kim 68439a53e0cSJaegeuk Kim /* NAT cache management */ 68539a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 686309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 687b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 68839a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 689309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 690aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 69122ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 69239a53e0cSJaegeuk Kim 69339a53e0cSJaegeuk Kim /* free node ids management */ 6948a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 695b8559dc2SChao Yu struct list_head nid_list[MAX_NID_LIST];/* lists for free nids */ 696b8559dc2SChao Yu unsigned int nid_cnt[MAX_NID_LIST]; /* the number of free node id */ 697b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 69839a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 6994ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 7004ac91242SChao Yu unsigned char *nat_block_bitmap; 701586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 70239a53e0cSJaegeuk Kim 70339a53e0cSJaegeuk Kim /* for checkpoint */ 70439a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 70522ad0b6aSJaegeuk Kim 70622ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 70722ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 70822ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 70922ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 710599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 711599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 712599a09b2SChao Yu #endif 71339a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 71439a53e0cSJaegeuk Kim }; 71539a53e0cSJaegeuk Kim 71639a53e0cSJaegeuk Kim /* 71739a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 71839a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 71939a53e0cSJaegeuk Kim * by the data offset in a file. 72039a53e0cSJaegeuk Kim */ 72139a53e0cSJaegeuk Kim struct dnode_of_data { 72239a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 72339a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 72439a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 72539a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 72639a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 72739a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 72893bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 7293cf45747SChao Yu char cur_level; /* level of hole node page */ 7303cf45747SChao Yu char max_level; /* level of current page located */ 73139a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 73239a53e0cSJaegeuk Kim }; 73339a53e0cSJaegeuk Kim 73439a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 73539a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 73639a53e0cSJaegeuk Kim { 737d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 73839a53e0cSJaegeuk Kim dn->inode = inode; 73939a53e0cSJaegeuk Kim dn->inode_page = ipage; 74039a53e0cSJaegeuk Kim dn->node_page = npage; 74139a53e0cSJaegeuk Kim dn->nid = nid; 74239a53e0cSJaegeuk Kim } 74339a53e0cSJaegeuk Kim 74439a53e0cSJaegeuk Kim /* 74539a53e0cSJaegeuk Kim * For SIT manager 74639a53e0cSJaegeuk Kim * 74739a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 74839a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 74939a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 75039a53e0cSJaegeuk Kim * respectively. 75139a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 75239a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 75339a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 75439a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 75539a53e0cSJaegeuk Kim * data and 8 for node logs. 75639a53e0cSJaegeuk Kim */ 75739a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 75839a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 75939a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 76039a53e0cSJaegeuk Kim 76139a53e0cSJaegeuk Kim enum { 76239a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 76339a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 76439a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 76539a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 76639a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 76739a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 76838aa0889SJaegeuk Kim NO_CHECK_TYPE, 76939a53e0cSJaegeuk Kim }; 77039a53e0cSJaegeuk Kim 7716b4afdd7SJaegeuk Kim struct flush_cmd { 7726b4afdd7SJaegeuk Kim struct completion wait; 773721bd4d5SGu Zheng struct llist_node llnode; 7746b4afdd7SJaegeuk Kim int ret; 7756b4afdd7SJaegeuk Kim }; 7766b4afdd7SJaegeuk Kim 777a688b9d9SGu Zheng struct flush_cmd_control { 778a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 779a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 7808b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 7818b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 782721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 783721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 784a688b9d9SGu Zheng }; 785a688b9d9SGu Zheng 78639a53e0cSJaegeuk Kim struct f2fs_sm_info { 78739a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 78839a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 78939a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 79039a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 79139a53e0cSJaegeuk Kim 79239a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 79339a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 79439a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 79539a53e0cSJaegeuk Kim 79639a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 79739a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 79839a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 79939a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 80081eb8d6eSJaegeuk Kim 80181eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 80281eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 8037fd9e544SJaegeuk Kim 804bba681cbSJaegeuk Kim /* for batched trimming */ 805bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 806bba681cbSJaegeuk Kim 807184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 808184a5cd2SChao Yu 809216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 810216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 811c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 812ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 8136b4afdd7SJaegeuk Kim 8146b4afdd7SJaegeuk Kim /* for flush command control */ 815b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 816a688b9d9SGu Zheng 8170b54fb84SJaegeuk Kim /* for discard command control */ 8180b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 81939a53e0cSJaegeuk Kim }; 82039a53e0cSJaegeuk Kim 82139a53e0cSJaegeuk Kim /* 82239a53e0cSJaegeuk Kim * For superblock 82339a53e0cSJaegeuk Kim */ 82439a53e0cSJaegeuk Kim /* 82539a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 82639a53e0cSJaegeuk Kim * 82739a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 82839a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 82939a53e0cSJaegeuk Kim */ 83036951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 83139a53e0cSJaegeuk Kim enum count_type { 83239a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 833c227f912SChao Yu F2FS_DIRTY_DATA, 83439a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 83539a53e0cSJaegeuk Kim F2FS_DIRTY_META, 8368dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 8370f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 83836951b38SChao Yu F2FS_WB_CP_DATA, 83936951b38SChao Yu F2FS_WB_DATA, 84039a53e0cSJaegeuk Kim NR_COUNT_TYPE, 84139a53e0cSJaegeuk Kim }; 84239a53e0cSJaegeuk Kim 84339a53e0cSJaegeuk Kim /* 844e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 84539a53e0cSJaegeuk Kim * The available types are: 84639a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 84739a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 84839a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 84939a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 85039a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 85139a53e0cSJaegeuk Kim * with waiting the bio's completion 85239a53e0cSJaegeuk Kim * ... Only can be used with META. 85339a53e0cSJaegeuk Kim */ 8547d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 85539a53e0cSJaegeuk Kim enum page_type { 85639a53e0cSJaegeuk Kim DATA, 85739a53e0cSJaegeuk Kim NODE, 85839a53e0cSJaegeuk Kim META, 85939a53e0cSJaegeuk Kim NR_PAGE_TYPE, 86039a53e0cSJaegeuk Kim META_FLUSH, 8618ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 8628ce67cb0SJaegeuk Kim INMEM_DROP, 8638c242db9SJaegeuk Kim INMEM_INVALIDATE, 86428bc106bSChao Yu INMEM_REVOKE, 8658ce67cb0SJaegeuk Kim IPU, 8668ce67cb0SJaegeuk Kim OPU, 86739a53e0cSJaegeuk Kim }; 86839a53e0cSJaegeuk Kim 869a912b54dSJaegeuk Kim enum temp_type { 870a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 871a912b54dSJaegeuk Kim WARM, 872a912b54dSJaegeuk Kim COLD, 873a912b54dSJaegeuk Kim NR_TEMP_TYPE, 874a912b54dSJaegeuk Kim }; 875a912b54dSJaegeuk Kim 876cc15620bSJaegeuk Kim enum need_lock_type { 877cc15620bSJaegeuk Kim LOCK_REQ = 0, 878cc15620bSJaegeuk Kim LOCK_DONE, 879cc15620bSJaegeuk Kim LOCK_RETRY, 880cc15620bSJaegeuk Kim }; 881cc15620bSJaegeuk Kim 882b0af6d49SChao Yu enum iostat_type { 883b0af6d49SChao Yu APP_DIRECT_IO, /* app direct IOs */ 884b0af6d49SChao Yu APP_BUFFERED_IO, /* app buffered IOs */ 885b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 886b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 887b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 888b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 889b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 890b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 891b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 892b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 893b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 894b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 895b0af6d49SChao Yu FS_DISCARD, /* discard */ 896b0af6d49SChao Yu NR_IO_TYPE, 897b0af6d49SChao Yu }; 898b0af6d49SChao Yu 899458e6197SJaegeuk Kim struct f2fs_io_info { 90005ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 901458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 902a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 90304d328deSMike Christie int op; /* contains REQ_OP_ */ 904ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 9057a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 90628bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 90705ca3632SJaegeuk Kim struct page *page; /* page to be written */ 9084375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 909fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 910d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 911cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 912fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 913b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 914458e6197SJaegeuk Kim }; 915458e6197SJaegeuk Kim 91668afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 9171ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 918458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 9191ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 9201ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 921458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 922df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 923fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 924fb830fc5SChao Yu struct list_head io_list; /* track fios */ 9251ff7bd3bSJaegeuk Kim }; 9261ff7bd3bSJaegeuk Kim 9273c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 9283c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 9293c62be17SJaegeuk Kim struct f2fs_dev_info { 9303c62be17SJaegeuk Kim struct block_device *bdev; 9313c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 9323c62be17SJaegeuk Kim unsigned int total_segments; 9333c62be17SJaegeuk Kim block_t start_blk; 9343c62be17SJaegeuk Kim block_t end_blk; 9353c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 9363c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 9373c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 9383c62be17SJaegeuk Kim #endif 9393c62be17SJaegeuk Kim }; 9403c62be17SJaegeuk Kim 941c227f912SChao Yu enum inode_type { 942c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 943c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 9440f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 945c227f912SChao Yu NR_INODE_TYPE, 946c227f912SChao Yu }; 947c227f912SChao Yu 94867298804SChao Yu /* for inner inode cache management */ 94967298804SChao Yu struct inode_management { 95067298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 95167298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 95267298804SChao Yu struct list_head ino_list; /* inode list head */ 95367298804SChao Yu unsigned long ino_num; /* number of entries */ 95467298804SChao Yu }; 95567298804SChao Yu 956caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 957caf0047eSChao Yu enum { 958caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 959caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 960caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 961caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 962df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 963bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 964caf0047eSChao Yu }; 965caf0047eSChao Yu 9666beceb54SJaegeuk Kim enum { 9676beceb54SJaegeuk Kim CP_TIME, 968d0239e1bSJaegeuk Kim REQ_TIME, 9696beceb54SJaegeuk Kim MAX_TIME, 9706beceb54SJaegeuk Kim }; 9716beceb54SJaegeuk Kim 97239a53e0cSJaegeuk Kim struct f2fs_sb_info { 97339a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 9745e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 97539a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 976e8240f65SChao Yu int valid_super_block; /* valid super block no */ 977fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 97839a53e0cSJaegeuk Kim 979178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 980178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 981178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 982178053e2SDamien Le Moal #endif 983178053e2SDamien Le Moal 98439a53e0cSJaegeuk Kim /* for node-related operations */ 98539a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 98639a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 98739a53e0cSJaegeuk Kim 98839a53e0cSJaegeuk Kim /* for segment-related operations */ 98939a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 9901ff7bd3bSJaegeuk Kim 9911ff7bd3bSJaegeuk Kim /* for bio operations */ 992a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 993e41e6d75SChao Yu struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 994e41e6d75SChao Yu /* bio ordering for NODE/DATA */ 9950a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 9960a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 99739a53e0cSJaegeuk Kim 99839a53e0cSJaegeuk Kim /* for checkpoint */ 99939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 10008508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1001aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 100239a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 100339936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 1004b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1005b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 100659c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1007fb51b5efSChangman Lee wait_queue_head_t cp_wait; 10086beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 10096beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 101039a53e0cSJaegeuk Kim 101167298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 10126451e041SJaegeuk Kim 10136451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 10140d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 101539a53e0cSJaegeuk Kim 1016c227f912SChao Yu /* for inode management */ 1017c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1018c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 101939a53e0cSJaegeuk Kim 102013054c54SChao Yu /* for extent tree cache */ 102113054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 10225e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 102313054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 102413054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 10257441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1026137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 102774fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 102813054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 102913054c54SChao Yu 103039a53e0cSJaegeuk Kim /* basic filesystem units */ 103139a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 103239a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 103339a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 103439a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 103539a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 103639a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 103739a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 103839a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 103939a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 104039a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 104139a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 104239a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 104339a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1044e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 104539a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 1046ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 104739a53e0cSJaegeuk Kim 104839a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 104939a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1050a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 105139a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1052daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 1053daeb433eSChao Yu 105439a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 1055523be8a6SJaegeuk Kim 1056523be8a6SJaegeuk Kim /* # of pages, see count_type */ 105735782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 105841382ec4SJaegeuk Kim /* # of allocated blocks */ 105941382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 106039a53e0cSJaegeuk Kim 1061687de7f1SJaegeuk Kim /* writeback control */ 1062687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 1063687de7f1SJaegeuk Kim 1064513c5f37SJaegeuk Kim /* valid inode count */ 1065513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1066513c5f37SJaegeuk Kim 106739a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 106839a53e0cSJaegeuk Kim 106939a53e0cSJaegeuk Kim /* for cleaning operations */ 107039a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 107139a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 10725ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 107339a53e0cSJaegeuk Kim 1074e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 1075e93b9865SHou Pengyang u64 fggc_threshold; 1076e93b9865SHou Pengyang 1077b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1078b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1079b1c57c1cSJaegeuk Kim 108039a53e0cSJaegeuk Kim /* 108139a53e0cSJaegeuk Kim * for stat information. 108239a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 108339a53e0cSJaegeuk Kim */ 108435b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 108539a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 108639a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 108739a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1088b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 10895b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 10905b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 10915b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 10925b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1093d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 109403e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 109503e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 109626a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 1097648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 109826a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1099648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 110039a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 110133fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 110235b09d82SNamjae Jeon #endif 110339a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1104b59d0baeSNamjae Jeon 1105b0af6d49SChao Yu /* For app/fs IO statistics */ 1106b0af6d49SChao Yu spinlock_t iostat_lock; 1107b0af6d49SChao Yu unsigned long long write_iostat[NR_IO_TYPE]; 1108b0af6d49SChao Yu bool iostat_enable; 1109b0af6d49SChao Yu 1110b59d0baeSNamjae Jeon /* For sysfs suppport */ 1111b59d0baeSNamjae Jeon struct kobject s_kobj; 1112b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 11132658e50dSJaegeuk Kim 11142658e50dSJaegeuk Kim /* For shrinker support */ 11152658e50dSJaegeuk Kim struct list_head s_list; 11163c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 11173c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 11182658e50dSJaegeuk Kim struct mutex umount_mutex; 11192658e50dSJaegeuk Kim unsigned int shrinker_run_no; 11208f1dbbbbSShuoran Liu 11218f1dbbbbSShuoran Liu /* For write statistics */ 11228f1dbbbbSShuoran Liu u64 sectors_written_start; 11238f1dbbbbSShuoran Liu u64 kbytes_written; 112443b6573bSKeith Mok 112543b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 112643b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 11271ecc0c5cSChao Yu 1128704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1129704956ecSChao Yu __u32 s_chksum_seed; 1130704956ecSChao Yu 11311ecc0c5cSChao Yu /* For fault injection */ 11321ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 11331ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 11341ecc0c5cSChao Yu #endif 11354b2414d0SChao Yu 11364b2414d0SChao Yu #ifdef CONFIG_QUOTA 11374b2414d0SChao Yu /* Names of quota files with journalled quota */ 11384b2414d0SChao Yu char *s_qf_names[MAXQUOTAS]; 11394b2414d0SChao Yu int s_jquota_fmt; /* Format of quota to use */ 11404b2414d0SChao Yu #endif 114139a53e0cSJaegeuk Kim }; 114239a53e0cSJaegeuk Kim 11431ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 114455523519SChao Yu #define f2fs_show_injection_info(type) \ 114555523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 114655523519SChao Yu KERN_INFO, fault_name[type], \ 114755523519SChao Yu __func__, __builtin_return_address(0)) 11481ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 11491ecc0c5cSChao Yu { 11501ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 11511ecc0c5cSChao Yu 11521ecc0c5cSChao Yu if (!ffi->inject_rate) 11531ecc0c5cSChao Yu return false; 11541ecc0c5cSChao Yu 11551ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 11561ecc0c5cSChao Yu return false; 11571ecc0c5cSChao Yu 11581ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 11591ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 11601ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 11611ecc0c5cSChao Yu return true; 11621ecc0c5cSChao Yu } 11631ecc0c5cSChao Yu return false; 11641ecc0c5cSChao Yu } 11651ecc0c5cSChao Yu #endif 11661ecc0c5cSChao Yu 11678f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 11688f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 11698f1dbbbbSShuoran Liu */ 11708f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 117168afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 117268afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 11738f1dbbbbSShuoran Liu 11746beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 11756beceb54SJaegeuk Kim { 11766beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 11776beceb54SJaegeuk Kim } 11786beceb54SJaegeuk Kim 11796beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 11806beceb54SJaegeuk Kim { 11816beceb54SJaegeuk Kim struct timespec ts = {sbi->interval_time[type], 0}; 11826beceb54SJaegeuk Kim unsigned long interval = timespec_to_jiffies(&ts); 11836beceb54SJaegeuk Kim 11846beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 11856beceb54SJaegeuk Kim } 11866beceb54SJaegeuk Kim 1187d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1188d0239e1bSJaegeuk Kim { 1189d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1190d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1191d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1192d0239e1bSJaegeuk Kim 1193d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1194d0239e1bSJaegeuk Kim return 0; 1195d0239e1bSJaegeuk Kim 1196d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1197d0239e1bSJaegeuk Kim } 1198d0239e1bSJaegeuk Kim 119939a53e0cSJaegeuk Kim /* 120039a53e0cSJaegeuk Kim * Inline functions 120139a53e0cSJaegeuk Kim */ 120243b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 120343b6573bSKeith Mok unsigned int length) 120443b6573bSKeith Mok { 120543b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 120643b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 1207d41519a6SDavid Miller u32 retval; 120843b6573bSKeith Mok int err; 120943b6573bSKeith Mok 121043b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 121143b6573bSKeith Mok shash->flags = 0; 121243b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 121343b6573bSKeith Mok 121443b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 121543b6573bSKeith Mok BUG_ON(err); 121643b6573bSKeith Mok 1217d41519a6SDavid Miller retval = *ctx; 1218d41519a6SDavid Miller barrier_data(ctx); 1219d41519a6SDavid Miller return retval; 122043b6573bSKeith Mok } 122143b6573bSKeith Mok 122243b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 122343b6573bSKeith Mok void *buf, size_t buf_size) 122443b6573bSKeith Mok { 122543b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 122643b6573bSKeith Mok } 122743b6573bSKeith Mok 1228704956ecSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1229704956ecSChao Yu const void *address, unsigned int length) 1230704956ecSChao Yu { 1231704956ecSChao Yu struct { 1232704956ecSChao Yu struct shash_desc shash; 1233704956ecSChao Yu char ctx[4]; 1234704956ecSChao Yu } desc; 1235704956ecSChao Yu int err; 1236704956ecSChao Yu 1237704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1238704956ecSChao Yu 1239704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1240704956ecSChao Yu desc.shash.flags = 0; 1241704956ecSChao Yu *(u32 *)desc.ctx = crc; 1242704956ecSChao Yu 1243704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1244704956ecSChao Yu BUG_ON(err); 1245704956ecSChao Yu 1246704956ecSChao Yu return *(u32 *)desc.ctx; 1247704956ecSChao Yu } 1248704956ecSChao Yu 124939a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 125039a53e0cSJaegeuk Kim { 125139a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 125239a53e0cSJaegeuk Kim } 125339a53e0cSJaegeuk Kim 125439a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 125539a53e0cSJaegeuk Kim { 125639a53e0cSJaegeuk Kim return sb->s_fs_info; 125739a53e0cSJaegeuk Kim } 125839a53e0cSJaegeuk Kim 12594081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 12604081363fSJaegeuk Kim { 12614081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 12624081363fSJaegeuk Kim } 12634081363fSJaegeuk Kim 12644081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 12654081363fSJaegeuk Kim { 12664081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 12674081363fSJaegeuk Kim } 12684081363fSJaegeuk Kim 12694081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 12704081363fSJaegeuk Kim { 12714081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 12724081363fSJaegeuk Kim } 12734081363fSJaegeuk Kim 127439a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 127539a53e0cSJaegeuk Kim { 127639a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 127739a53e0cSJaegeuk Kim } 127839a53e0cSJaegeuk Kim 127939a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 128039a53e0cSJaegeuk Kim { 128139a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 128239a53e0cSJaegeuk Kim } 128339a53e0cSJaegeuk Kim 128445590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 128545590710SGu Zheng { 128645590710SGu Zheng return (struct f2fs_node *)page_address(page); 128745590710SGu Zheng } 128845590710SGu Zheng 128958bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 129058bfaf44SJaegeuk Kim { 129158bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 129258bfaf44SJaegeuk Kim } 129358bfaf44SJaegeuk Kim 129439a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 129539a53e0cSJaegeuk Kim { 129639a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 129739a53e0cSJaegeuk Kim } 129839a53e0cSJaegeuk Kim 129939a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 130039a53e0cSJaegeuk Kim { 130139a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 130239a53e0cSJaegeuk Kim } 130339a53e0cSJaegeuk Kim 130439a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 130539a53e0cSJaegeuk Kim { 130639a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 130739a53e0cSJaegeuk Kim } 130839a53e0cSJaegeuk Kim 130939a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 131039a53e0cSJaegeuk Kim { 131139a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 131239a53e0cSJaegeuk Kim } 131339a53e0cSJaegeuk Kim 131439a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 131539a53e0cSJaegeuk Kim { 131639a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 131739a53e0cSJaegeuk Kim } 131839a53e0cSJaegeuk Kim 13199df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 13209df27d98SGu Zheng { 13219df27d98SGu Zheng return sbi->meta_inode->i_mapping; 13229df27d98SGu Zheng } 13239df27d98SGu Zheng 13244ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 13254ef51a8fSJaegeuk Kim { 13264ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 13274ef51a8fSJaegeuk Kim } 13284ef51a8fSJaegeuk Kim 1329caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 133039a53e0cSJaegeuk Kim { 1331fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 133239a53e0cSJaegeuk Kim } 133339a53e0cSJaegeuk Kim 1334caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 133539a53e0cSJaegeuk Kim { 1336fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1337caf0047eSChao Yu } 1338caf0047eSChao Yu 1339caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1340caf0047eSChao Yu { 1341fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 134239a53e0cSJaegeuk Kim } 134339a53e0cSJaegeuk Kim 1344d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1345d71b5564SJaegeuk Kim { 1346d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1347d71b5564SJaegeuk Kim } 1348d71b5564SJaegeuk Kim 1349ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1350ced2c7eaSKinglong Mee { 1351ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1352ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1353ced2c7eaSKinglong Mee } 1354ced2c7eaSKinglong Mee 1355aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 135625ca923bSJaegeuk Kim { 135725ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1358aaec2b1dSChao Yu 135925ca923bSJaegeuk Kim return ckpt_flags & f; 136025ca923bSJaegeuk Kim } 136125ca923bSJaegeuk Kim 1362aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 136325ca923bSJaegeuk Kim { 1364aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1365aaec2b1dSChao Yu } 1366aaec2b1dSChao Yu 1367aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1368aaec2b1dSChao Yu { 1369aaec2b1dSChao Yu unsigned int ckpt_flags; 1370aaec2b1dSChao Yu 1371aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 137225ca923bSJaegeuk Kim ckpt_flags |= f; 137325ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 137425ca923bSJaegeuk Kim } 137525ca923bSJaegeuk Kim 1376aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 137725ca923bSJaegeuk Kim { 1378d1aa2453SChao Yu unsigned long flags; 1379d1aa2453SChao Yu 1380d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1381aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1382d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1383aaec2b1dSChao Yu } 1384aaec2b1dSChao Yu 1385aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1386aaec2b1dSChao Yu { 1387aaec2b1dSChao Yu unsigned int ckpt_flags; 1388aaec2b1dSChao Yu 1389aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 139025ca923bSJaegeuk Kim ckpt_flags &= (~f); 139125ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 139225ca923bSJaegeuk Kim } 139325ca923bSJaegeuk Kim 1394aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1395aaec2b1dSChao Yu { 1396d1aa2453SChao Yu unsigned long flags; 1397d1aa2453SChao Yu 1398d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1399aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1400d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1401aaec2b1dSChao Yu } 1402aaec2b1dSChao Yu 140322ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 140422ad0b6aSJaegeuk Kim { 1405d1aa2453SChao Yu unsigned long flags; 1406d1aa2453SChao Yu 140722ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 140822ad0b6aSJaegeuk Kim 140922ad0b6aSJaegeuk Kim if (lock) 1410d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 141122ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 141222ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 141322ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 141422ad0b6aSJaegeuk Kim if (lock) 1415d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 141622ad0b6aSJaegeuk Kim } 141722ad0b6aSJaegeuk Kim 141822ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 141922ad0b6aSJaegeuk Kim struct cp_control *cpc) 142022ad0b6aSJaegeuk Kim { 142122ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 142222ad0b6aSJaegeuk Kim 1423c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 142422ad0b6aSJaegeuk Kim } 142522ad0b6aSJaegeuk Kim 1426e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 142739a53e0cSJaegeuk Kim { 1428b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 142939a53e0cSJaegeuk Kim } 143039a53e0cSJaegeuk Kim 1431cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1432cc15620bSJaegeuk Kim { 1433cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1434cc15620bSJaegeuk Kim } 1435cc15620bSJaegeuk Kim 1436e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 143739a53e0cSJaegeuk Kim { 1438b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 143939936837SJaegeuk Kim } 144039936837SJaegeuk Kim 1441e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 144239936837SJaegeuk Kim { 1443b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 144439936837SJaegeuk Kim } 144539936837SJaegeuk Kim 1446e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 144739936837SJaegeuk Kim { 1448b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 144939a53e0cSJaegeuk Kim } 145039a53e0cSJaegeuk Kim 1451119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1452119ee914SJaegeuk Kim { 1453119ee914SJaegeuk Kim int reason = CP_SYNC; 1454119ee914SJaegeuk Kim 1455119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1456119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1457119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1458119ee914SJaegeuk Kim reason = CP_UMOUNT; 1459119ee914SJaegeuk Kim return reason; 1460119ee914SJaegeuk Kim } 1461119ee914SJaegeuk Kim 1462119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1463119ee914SJaegeuk Kim { 1464c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1465119ee914SJaegeuk Kim } 1466119ee914SJaegeuk Kim 1467119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1468119ee914SJaegeuk Kim { 1469aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1470aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1471119ee914SJaegeuk Kim } 1472119ee914SJaegeuk Kim 147339a53e0cSJaegeuk Kim /* 147439a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 147539a53e0cSJaegeuk Kim */ 1476064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 147739a53e0cSJaegeuk Kim { 1478d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1479d6b7d4b3SChao Yu return -EINVAL; 1480cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1481064e0823SNamjae Jeon return -EINVAL; 1482064e0823SNamjae Jeon return 0; 148339a53e0cSJaegeuk Kim } 148439a53e0cSJaegeuk Kim 148539a53e0cSJaegeuk Kim /* 148639a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 148739a53e0cSJaegeuk Kim */ 148839a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 148939a53e0cSJaegeuk Kim { 14900eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 14910eb0adadSChao Yu 1492000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 149339a53e0cSJaegeuk Kim } 149439a53e0cSJaegeuk Kim 14954bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 14964bc8e9bcSChao Yu { 14974bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 14984bc8e9bcSChao Yu } 14994bc8e9bcSChao Yu 15000abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 15010abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 150246008c6dSChao Yu struct inode *inode, blkcnt_t *count) 150339a53e0cSJaegeuk Kim { 15040abd675eSChao Yu blkcnt_t diff = 0, release = 0; 1505daeb433eSChao Yu block_t avail_user_block_count; 15060abd675eSChao Yu int ret; 15070abd675eSChao Yu 15080abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 15090abd675eSChao Yu if (ret) 15100abd675eSChao Yu return ret; 1511dd11a5dfSJaegeuk Kim 1512cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 151355523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 151455523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 15150abd675eSChao Yu release = *count; 15160abd675eSChao Yu goto enospc; 151755523519SChao Yu } 1518cb78942bSJaegeuk Kim #endif 1519dd11a5dfSJaegeuk Kim /* 1520dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1521dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1522dd11a5dfSJaegeuk Kim */ 1523dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1524cfb271d4SChao Yu 152539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 15262555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 1527daeb433eSChao Yu avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks; 1528daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1529daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 1530dd11a5dfSJaegeuk Kim *count -= diff; 15310abd675eSChao Yu release = diff; 1532daeb433eSChao Yu sbi->total_valid_block_count = avail_user_block_count; 153346008c6dSChao Yu if (!*count) { 153439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1535dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 15360abd675eSChao Yu goto enospc; 153739a53e0cSJaegeuk Kim } 153846008c6dSChao Yu } 153939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 154041382ec4SJaegeuk Kim 15410abd675eSChao Yu if (release) 15420abd675eSChao Yu dquot_release_reservation_block(inode, release); 15430abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 15440abd675eSChao Yu return 0; 15450abd675eSChao Yu 15460abd675eSChao Yu enospc: 15470abd675eSChao Yu dquot_release_reservation_block(inode, release); 15480abd675eSChao Yu return -ENOSPC; 154939a53e0cSJaegeuk Kim } 155039a53e0cSJaegeuk Kim 1551da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 155239a53e0cSJaegeuk Kim struct inode *inode, 15530eb0adadSChao Yu block_t count) 155439a53e0cSJaegeuk Kim { 15550eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 15560eb0adadSChao Yu 155739a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 15589850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 15590eb0adadSChao Yu f2fs_bug_on(sbi, inode->i_blocks < sectors); 156039a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 156139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 15620abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 156339a53e0cSJaegeuk Kim } 156439a53e0cSJaegeuk Kim 156539a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 156639a53e0cSJaegeuk Kim { 156735782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 15687c4abcbeSChao Yu 156936951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 157036951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 15717c4abcbeSChao Yu return; 15727c4abcbeSChao Yu 1573caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 157439a53e0cSJaegeuk Kim } 157539a53e0cSJaegeuk Kim 1576a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 157739a53e0cSJaegeuk Kim { 1578204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1579c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1580c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 158139a53e0cSJaegeuk Kim } 158239a53e0cSJaegeuk Kim 158339a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 158439a53e0cSJaegeuk Kim { 158535782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 158639a53e0cSJaegeuk Kim } 158739a53e0cSJaegeuk Kim 1588a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 158939a53e0cSJaegeuk Kim { 15905ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 15915ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 15921fe54f9dSJaegeuk Kim return; 15931fe54f9dSJaegeuk Kim 1594204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1595c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1596c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 159739a53e0cSJaegeuk Kim } 159839a53e0cSJaegeuk Kim 1599523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 160039a53e0cSJaegeuk Kim { 160135782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 160239a53e0cSJaegeuk Kim } 160339a53e0cSJaegeuk Kim 1604204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1605f8b2c1f9SJaegeuk Kim { 1606204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1607f8b2c1f9SJaegeuk Kim } 1608f8b2c1f9SJaegeuk Kim 16095ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 16105ac206cfSNamjae Jeon { 16113519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1612523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1613523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1614523be8a6SJaegeuk Kim 1615523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 16165ac206cfSNamjae Jeon } 16175ac206cfSNamjae Jeon 161839a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 161939a53e0cSJaegeuk Kim { 16208b8343faSJaegeuk Kim return sbi->total_valid_block_count; 162139a53e0cSJaegeuk Kim } 162239a53e0cSJaegeuk Kim 1623f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1624f83a2584SYunlei He { 1625f83a2584SYunlei He return sbi->discard_blks; 1626f83a2584SYunlei He } 1627f83a2584SYunlei He 162839a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 162939a53e0cSJaegeuk Kim { 163039a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 163139a53e0cSJaegeuk Kim 163239a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 163339a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 163439a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 163539a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 163639a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 163739a53e0cSJaegeuk Kim 163839a53e0cSJaegeuk Kim return 0; 163939a53e0cSJaegeuk Kim } 164039a53e0cSJaegeuk Kim 164155141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 164255141486SWanpeng Li { 164355141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 164455141486SWanpeng Li } 164555141486SWanpeng Li 164639a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 164739a53e0cSJaegeuk Kim { 164839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 16491dbe4152SChangman Lee int offset; 16501dbe4152SChangman Lee 165155141486SWanpeng Li if (__cp_payload(sbi) > 0) { 16521dbe4152SChangman Lee if (flag == NAT_BITMAP) 16531dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 16541dbe4152SChangman Lee else 165565b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 16561dbe4152SChangman Lee } else { 16571dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 165825ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 165939a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 166039a53e0cSJaegeuk Kim } 16611dbe4152SChangman Lee } 166239a53e0cSJaegeuk Kim 166339a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 166439a53e0cSJaegeuk Kim { 16658508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 166639a53e0cSJaegeuk Kim 16678508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 166839a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 166939a53e0cSJaegeuk Kim return start_addr; 167039a53e0cSJaegeuk Kim } 167139a53e0cSJaegeuk Kim 16728508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 16738508e44aSJaegeuk Kim { 16748508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 16758508e44aSJaegeuk Kim 16768508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 16778508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 16788508e44aSJaegeuk Kim return start_addr; 16798508e44aSJaegeuk Kim } 16808508e44aSJaegeuk Kim 16818508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 16828508e44aSJaegeuk Kim { 16838508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 16848508e44aSJaegeuk Kim } 16858508e44aSJaegeuk Kim 168639a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 168739a53e0cSJaegeuk Kim { 168839a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 168939a53e0cSJaegeuk Kim } 169039a53e0cSJaegeuk Kim 16910abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 1692000519f2SChao Yu struct inode *inode, bool is_inode) 169339a53e0cSJaegeuk Kim { 169439a53e0cSJaegeuk Kim block_t valid_block_count; 169539a53e0cSJaegeuk Kim unsigned int valid_node_count; 16960abd675eSChao Yu bool quota = inode && !is_inode; 16970abd675eSChao Yu 16980abd675eSChao Yu if (quota) { 16990abd675eSChao Yu int ret = dquot_reserve_block(inode, 1); 17000abd675eSChao Yu if (ret) 17010abd675eSChao Yu return ret; 17020abd675eSChao Yu } 170339a53e0cSJaegeuk Kim 170439a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 170539a53e0cSJaegeuk Kim 1706ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 1707daeb433eSChao Yu if (unlikely(valid_block_count + sbi->reserved_blocks > 1708daeb433eSChao Yu sbi->user_block_count)) { 170939a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17100abd675eSChao Yu goto enospc; 171139a53e0cSJaegeuk Kim } 171239a53e0cSJaegeuk Kim 1713ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1714cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 171539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17160abd675eSChao Yu goto enospc; 171739a53e0cSJaegeuk Kim } 171839a53e0cSJaegeuk Kim 1719ef86d709SGu Zheng sbi->total_valid_node_count++; 1720ef86d709SGu Zheng sbi->total_valid_block_count++; 172139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 172239a53e0cSJaegeuk Kim 17230abd675eSChao Yu if (inode) { 17240abd675eSChao Yu if (is_inode) 17250abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 17260abd675eSChao Yu else 17270abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 17280abd675eSChao Yu } 17290abd675eSChao Yu 173041382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 17310abd675eSChao Yu return 0; 17320abd675eSChao Yu 17330abd675eSChao Yu enospc: 17340abd675eSChao Yu if (quota) 17350abd675eSChao Yu dquot_release_reservation_block(inode, 1); 17360abd675eSChao Yu return -ENOSPC; 173739a53e0cSJaegeuk Kim } 173839a53e0cSJaegeuk Kim 173939a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1740000519f2SChao Yu struct inode *inode, bool is_inode) 174139a53e0cSJaegeuk Kim { 174239a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 174339a53e0cSJaegeuk Kim 17449850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 17459850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 1746000519f2SChao Yu f2fs_bug_on(sbi, !is_inode && !inode->i_blocks); 174739a53e0cSJaegeuk Kim 1748ef86d709SGu Zheng sbi->total_valid_node_count--; 1749ef86d709SGu Zheng sbi->total_valid_block_count--; 175039a53e0cSJaegeuk Kim 175139a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17520abd675eSChao Yu 17530abd675eSChao Yu if (!is_inode) 17540abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 175539a53e0cSJaegeuk Kim } 175639a53e0cSJaegeuk Kim 175739a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 175839a53e0cSJaegeuk Kim { 17598b8343faSJaegeuk Kim return sbi->total_valid_node_count; 176039a53e0cSJaegeuk Kim } 176139a53e0cSJaegeuk Kim 176239a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 176339a53e0cSJaegeuk Kim { 1764513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 176539a53e0cSJaegeuk Kim } 176639a53e0cSJaegeuk Kim 17670e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 176839a53e0cSJaegeuk Kim { 1769513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 177039a53e0cSJaegeuk Kim } 177139a53e0cSJaegeuk Kim 1772513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 177339a53e0cSJaegeuk Kim { 1774513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 177539a53e0cSJaegeuk Kim } 177639a53e0cSJaegeuk Kim 1777a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1778a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1779a56c7c6fSJaegeuk Kim { 1780c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1781c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1782cac5a3d8SDongOh Shin 1783c41f3cc3SJaegeuk Kim if (page) 1784c41f3cc3SJaegeuk Kim return page; 1785c41f3cc3SJaegeuk Kim 178655523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 178755523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1788c41f3cc3SJaegeuk Kim return NULL; 178955523519SChao Yu } 1790c41f3cc3SJaegeuk Kim #endif 1791a56c7c6fSJaegeuk Kim if (!for_write) 1792a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1793a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1794a56c7c6fSJaegeuk Kim } 1795a56c7c6fSJaegeuk Kim 17966e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 17976e2c64adSJaegeuk Kim { 17986e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 17996e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 18006e2c64adSJaegeuk Kim 18016e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 18026e2c64adSJaegeuk Kim kunmap(dst); 18036e2c64adSJaegeuk Kim kunmap(src); 18046e2c64adSJaegeuk Kim } 18056e2c64adSJaegeuk Kim 180639a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 180739a53e0cSJaegeuk Kim { 1808031fa8ccSJaegeuk Kim if (!page) 180939a53e0cSJaegeuk Kim return; 181039a53e0cSJaegeuk Kim 181139a53e0cSJaegeuk Kim if (unlock) { 18129850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 181339a53e0cSJaegeuk Kim unlock_page(page); 181439a53e0cSJaegeuk Kim } 181509cbfeafSKirill A. Shutemov put_page(page); 181639a53e0cSJaegeuk Kim } 181739a53e0cSJaegeuk Kim 181839a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 181939a53e0cSJaegeuk Kim { 182039a53e0cSJaegeuk Kim if (dn->node_page) 182139a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 182239a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 182339a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 182439a53e0cSJaegeuk Kim dn->node_page = NULL; 182539a53e0cSJaegeuk Kim dn->inode_page = NULL; 182639a53e0cSJaegeuk Kim } 182739a53e0cSJaegeuk Kim 182839a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1829e8512d2eSGu Zheng size_t size) 183039a53e0cSJaegeuk Kim { 1831e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 183239a53e0cSJaegeuk Kim } 183339a53e0cSJaegeuk Kim 18347bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 18357bd59381SGu Zheng gfp_t flags) 18367bd59381SGu Zheng { 18377bd59381SGu Zheng void *entry; 18387bd59381SGu Zheng 183980c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 184080c54505SJaegeuk Kim if (!entry) 184180c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 18427bd59381SGu Zheng return entry; 18437bd59381SGu Zheng } 18447bd59381SGu Zheng 1845740432f8SJaegeuk Kim static inline struct bio *f2fs_bio_alloc(int npages) 1846740432f8SJaegeuk Kim { 1847740432f8SJaegeuk Kim struct bio *bio; 1848740432f8SJaegeuk Kim 1849740432f8SJaegeuk Kim /* No failure on bio allocation */ 1850740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 185180c54505SJaegeuk Kim if (!bio) 185280c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1853740432f8SJaegeuk Kim return bio; 1854740432f8SJaegeuk Kim } 1855740432f8SJaegeuk Kim 18569be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 18579be32d72SJaegeuk Kim unsigned long index, void *item) 18589be32d72SJaegeuk Kim { 18599be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 18609be32d72SJaegeuk Kim cond_resched(); 18619be32d72SJaegeuk Kim } 18629be32d72SJaegeuk Kim 186339a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 186439a53e0cSJaegeuk Kim 186539a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 186639a53e0cSJaegeuk Kim { 186745590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1868cac5a3d8SDongOh Shin 186939a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 187039a53e0cSJaegeuk Kim } 187139a53e0cSJaegeuk Kim 18727a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 18737a2af766SChao Yu { 18747a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 18757a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 18767a2af766SChao Yu } 18777a2af766SChao Yu 187839a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 187939a53e0cSJaegeuk Kim { 188039a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 188139a53e0cSJaegeuk Kim } 188239a53e0cSJaegeuk Kim 18837a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 18847a2af766SChao Yu static inline block_t datablock_addr(struct inode *inode, 18857a2af766SChao Yu struct page *node_page, unsigned int offset) 188639a53e0cSJaegeuk Kim { 188739a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 188839a53e0cSJaegeuk Kim __le32 *addr_array; 18897a2af766SChao Yu int base = 0; 18907a2af766SChao Yu bool is_inode = IS_INODE(node_page); 1891cac5a3d8SDongOh Shin 189245590710SGu Zheng raw_node = F2FS_NODE(node_page); 18937a2af766SChao Yu 18947a2af766SChao Yu /* from GC path only */ 18957a2af766SChao Yu if (!inode) { 18967a2af766SChao Yu if (is_inode) 18977a2af766SChao Yu base = offset_in_addr(&raw_node->i); 18987a2af766SChao Yu } else if (f2fs_has_extra_attr(inode) && is_inode) { 18997a2af766SChao Yu base = get_extra_isize(inode); 19007a2af766SChao Yu } 19017a2af766SChao Yu 190239a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 19037a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 190439a53e0cSJaegeuk Kim } 190539a53e0cSJaegeuk Kim 190639a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 190739a53e0cSJaegeuk Kim { 190839a53e0cSJaegeuk Kim int mask; 190939a53e0cSJaegeuk Kim 191039a53e0cSJaegeuk Kim addr += (nr >> 3); 191139a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 191239a53e0cSJaegeuk Kim return mask & *addr; 191339a53e0cSJaegeuk Kim } 191439a53e0cSJaegeuk Kim 1915a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 1916a66cdd98SJaegeuk Kim { 1917a66cdd98SJaegeuk Kim int mask; 1918a66cdd98SJaegeuk Kim 1919a66cdd98SJaegeuk Kim addr += (nr >> 3); 1920a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1921a66cdd98SJaegeuk Kim *addr |= mask; 1922a66cdd98SJaegeuk Kim } 1923a66cdd98SJaegeuk Kim 1924a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 1925a66cdd98SJaegeuk Kim { 1926a66cdd98SJaegeuk Kim int mask; 1927a66cdd98SJaegeuk Kim 1928a66cdd98SJaegeuk Kim addr += (nr >> 3); 1929a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 1930a66cdd98SJaegeuk Kim *addr &= ~mask; 1931a66cdd98SJaegeuk Kim } 1932a66cdd98SJaegeuk Kim 193352aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 193439a53e0cSJaegeuk Kim { 193539a53e0cSJaegeuk Kim int mask; 193639a53e0cSJaegeuk Kim int ret; 193739a53e0cSJaegeuk Kim 193839a53e0cSJaegeuk Kim addr += (nr >> 3); 193939a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 194039a53e0cSJaegeuk Kim ret = mask & *addr; 194139a53e0cSJaegeuk Kim *addr |= mask; 194239a53e0cSJaegeuk Kim return ret; 194339a53e0cSJaegeuk Kim } 194439a53e0cSJaegeuk Kim 194552aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 194639a53e0cSJaegeuk Kim { 194739a53e0cSJaegeuk Kim int mask; 194839a53e0cSJaegeuk Kim int ret; 194939a53e0cSJaegeuk Kim 195039a53e0cSJaegeuk Kim addr += (nr >> 3); 195139a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 195239a53e0cSJaegeuk Kim ret = mask & *addr; 195339a53e0cSJaegeuk Kim *addr &= ~mask; 195439a53e0cSJaegeuk Kim return ret; 195539a53e0cSJaegeuk Kim } 195639a53e0cSJaegeuk Kim 1957c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 1958c6ac4c0eSGu Zheng { 1959c6ac4c0eSGu Zheng int mask; 1960c6ac4c0eSGu Zheng 1961c6ac4c0eSGu Zheng addr += (nr >> 3); 1962c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 1963c6ac4c0eSGu Zheng *addr ^= mask; 1964c6ac4c0eSGu Zheng } 1965c6ac4c0eSGu Zheng 19665c57132eSChao Yu #define F2FS_REG_FLMASK (~(FS_DIRSYNC_FL | FS_TOPDIR_FL)) 19675c57132eSChao Yu #define F2FS_OTHER_FLMASK (FS_NODUMP_FL | FS_NOATIME_FL) 19685c57132eSChao Yu #define F2FS_FL_INHERITED (FS_PROJINHERIT_FL) 19695c57132eSChao Yu 19705c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 19715c57132eSChao Yu { 19725c57132eSChao Yu if (S_ISDIR(mode)) 19735c57132eSChao Yu return flags; 19745c57132eSChao Yu else if (S_ISREG(mode)) 19755c57132eSChao Yu return flags & F2FS_REG_FLMASK; 19765c57132eSChao Yu else 19775c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 19785c57132eSChao Yu } 19795c57132eSChao Yu 198039a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 198139a53e0cSJaegeuk Kim enum { 198239a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 1983b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 198426de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 1985ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 198639a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 198739a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 198839a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 1989c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 1990c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 1991444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 19921001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 199334d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 1994fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 1995fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 199688b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 199788b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 19985fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 199902a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 20003c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 20011e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 2002b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 2003510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 2004d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 2005c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 2006dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 2007ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 20087a2af766SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 20095c57132eSChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 201039a53e0cSJaegeuk Kim }; 201139a53e0cSJaegeuk Kim 2012205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2013205b9822SJaegeuk Kim int flag, bool set) 201439a53e0cSJaegeuk Kim { 2015205b9822SJaegeuk Kim switch (flag) { 2016205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2017205b9822SJaegeuk Kim case FI_INLINE_DATA: 2018205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 2019205b9822SJaegeuk Kim if (set) 2020205b9822SJaegeuk Kim return; 2021205b9822SJaegeuk Kim case FI_DATA_EXIST: 2022205b9822SJaegeuk Kim case FI_INLINE_DOTS: 20237c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2024205b9822SJaegeuk Kim } 202539a53e0cSJaegeuk Kim } 202639a53e0cSJaegeuk Kim 202791942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 202839a53e0cSJaegeuk Kim { 202991942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 203091942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 2031205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 203239a53e0cSJaegeuk Kim } 203339a53e0cSJaegeuk Kim 203491942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 203539a53e0cSJaegeuk Kim { 203691942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 203739a53e0cSJaegeuk Kim } 203839a53e0cSJaegeuk Kim 203991942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 204039a53e0cSJaegeuk Kim { 204191942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 204291942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 2043205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 204439a53e0cSJaegeuk Kim } 204539a53e0cSJaegeuk Kim 204691942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2047444c580fSJaegeuk Kim { 204891942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 204991942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 20507c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 205139a53e0cSJaegeuk Kim } 205239a53e0cSJaegeuk Kim 2053a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2054a1961246SJaegeuk Kim { 2055a1961246SJaegeuk Kim if (inc) 2056a1961246SJaegeuk Kim inc_nlink(inode); 2057a1961246SJaegeuk Kim else 2058a1961246SJaegeuk Kim drop_nlink(inode); 20597c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2060a1961246SJaegeuk Kim } 2061a1961246SJaegeuk Kim 20628edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 20630abd675eSChao Yu block_t diff, bool add, bool claim) 20648edd03c8SJaegeuk Kim { 206526de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 206626de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 206726de9b11SJaegeuk Kim 20680abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 20690abd675eSChao Yu if (add) { 20700abd675eSChao Yu if (claim) 20710abd675eSChao Yu dquot_claim_block(inode, diff); 20720abd675eSChao Yu else 20730abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 20740abd675eSChao Yu } else { 20750abd675eSChao Yu dquot_free_block(inode, diff); 20760abd675eSChao Yu } 20770abd675eSChao Yu 20787c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 207926de9b11SJaegeuk Kim if (clean || recover) 208026de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 20818edd03c8SJaegeuk Kim } 20828edd03c8SJaegeuk Kim 2083fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2084fc9581c8SJaegeuk Kim { 208526de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 208626de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 208726de9b11SJaegeuk Kim 2088fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2089fc9581c8SJaegeuk Kim return; 2090fc9581c8SJaegeuk Kim 2091fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 20927c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 209326de9b11SJaegeuk Kim if (clean || recover) 209426de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 209526de9b11SJaegeuk Kim } 209626de9b11SJaegeuk Kim 2097205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2098205b9822SJaegeuk Kim { 2099205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 21007c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2101205b9822SJaegeuk Kim } 2102205b9822SJaegeuk Kim 2103205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2104205b9822SJaegeuk Kim { 2105205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 21067c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2107205b9822SJaegeuk Kim } 2108205b9822SJaegeuk Kim 2109205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2110205b9822SJaegeuk Kim { 2111205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 21127c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2113205b9822SJaegeuk Kim } 2114205b9822SJaegeuk Kim 211591942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2116444c580fSJaegeuk Kim { 2117205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2118205b9822SJaegeuk Kim 2119444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 2120205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 21211001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 2122205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 212334d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 2124205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 2125b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 2126205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 2127510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 2128205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 21297a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 21307a2af766SChao Yu set_bit(FI_EXTRA_ATTR, &fi->flags); 2131444c580fSJaegeuk Kim } 2132444c580fSJaegeuk Kim 213391942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2134444c580fSJaegeuk Kim { 2135444c580fSJaegeuk Kim ri->i_inline = 0; 2136444c580fSJaegeuk Kim 213791942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2138444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 213991942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 21401001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 214191942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 214234d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 214391942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2144b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 214591942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2146510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 21477a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 21487a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 21497a2af766SChao Yu } 21507a2af766SChao Yu 21517a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 21527a2af766SChao Yu { 21537a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2154444c580fSJaegeuk Kim } 2155444c580fSJaegeuk Kim 2156987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2157987c7c31SChao Yu { 215891942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2159987c7c31SChao Yu } 2160987c7c31SChao Yu 216181ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2162de93653fSJaegeuk Kim { 216381ca7350SChao Yu if (f2fs_has_inline_xattr(inode)) 21647a2af766SChao Yu return CUR_ADDRS_PER_INODE(inode) - F2FS_INLINE_XATTR_ADDRS; 21657a2af766SChao Yu return CUR_ADDRS_PER_INODE(inode); 2166de93653fSJaegeuk Kim } 2167de93653fSJaegeuk Kim 216865985d93SJaegeuk Kim static inline void *inline_xattr_addr(struct page *page) 216965985d93SJaegeuk Kim { 2170695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2171cac5a3d8SDongOh Shin 217265985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 217365985d93SJaegeuk Kim F2FS_INLINE_XATTR_ADDRS]); 217465985d93SJaegeuk Kim } 217565985d93SJaegeuk Kim 217665985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 217765985d93SJaegeuk Kim { 2178987c7c31SChao Yu if (f2fs_has_inline_xattr(inode)) 217965985d93SJaegeuk Kim return F2FS_INLINE_XATTR_ADDRS << 2; 218065985d93SJaegeuk Kim else 218165985d93SJaegeuk Kim return 0; 218265985d93SJaegeuk Kim } 218365985d93SJaegeuk Kim 21840dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 21850dbdc2aeSJaegeuk Kim { 218691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 21870dbdc2aeSJaegeuk Kim } 21880dbdc2aeSJaegeuk Kim 2189b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2190b3d208f9SJaegeuk Kim { 219191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2192b3d208f9SJaegeuk Kim } 2193b3d208f9SJaegeuk Kim 2194510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2195510022a8SJaegeuk Kim { 219691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2197510022a8SJaegeuk Kim } 2198510022a8SJaegeuk Kim 219988b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 220088b88a66SJaegeuk Kim { 220191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 220288b88a66SJaegeuk Kim } 220388b88a66SJaegeuk Kim 22045fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 22055fe45743SChao Yu { 22065fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 22075fe45743SChao Yu } 22085fe45743SChao Yu 220902a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 221002a1335fSJaegeuk Kim { 221191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 221202a1335fSJaegeuk Kim } 221302a1335fSJaegeuk Kim 22143c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 22153c6c2bebSJaegeuk Kim { 221691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 22173c6c2bebSJaegeuk Kim } 22183c6c2bebSJaegeuk Kim 22191e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 22201e84371fSJaegeuk Kim { 222191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 22221e84371fSJaegeuk Kim } 22231e84371fSJaegeuk Kim 2224f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 22251001b347SHuajun Li { 2226695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 22277a2af766SChao Yu int extra_size = get_extra_isize(inode); 2228cac5a3d8SDongOh Shin 22297a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 22301001b347SHuajun Li } 22311001b347SHuajun Li 223234d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 223334d67debSChao Yu { 223491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 223534d67debSChao Yu } 223634d67debSChao Yu 22379486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 22389486ba44SJaegeuk Kim { 22399486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 22409486ba44SJaegeuk Kim kunmap(page); 22419486ba44SJaegeuk Kim } 22429486ba44SJaegeuk Kim 2243b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2244b5492af7SJaegeuk Kim { 2245b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2246b5492af7SJaegeuk Kim } 2247b5492af7SJaegeuk Kim 2248b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2249b5492af7SJaegeuk Kim { 2250b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 22517c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2252b5492af7SJaegeuk Kim } 2253b5492af7SJaegeuk Kim 2254b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2255b5492af7SJaegeuk Kim { 2256b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 22577c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2258b5492af7SJaegeuk Kim } 2259b5492af7SJaegeuk Kim 226026787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 226126787236SJaegeuk Kim { 226226787236SJaegeuk Kim if (dsync) { 226326787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 226426787236SJaegeuk Kim bool ret; 226526787236SJaegeuk Kim 226626787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 226726787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 226826787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 226926787236SJaegeuk Kim return ret; 227026787236SJaegeuk Kim } 227126787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 227226787236SJaegeuk Kim file_keep_isize(inode) || 227326787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 227426787236SJaegeuk Kim return false; 227526787236SJaegeuk Kim return F2FS_I(inode)->last_disk_size == i_size_read(inode); 2276267378d4SChao Yu } 2277267378d4SChao Yu 2278267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 2279267378d4SChao Yu { 2280267378d4SChao Yu return sb->s_flags & MS_RDONLY; 2281267378d4SChao Yu } 228239a53e0cSJaegeuk Kim 228339a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 228439a53e0cSJaegeuk Kim { 2285aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 228639a53e0cSJaegeuk Kim } 228739a53e0cSJaegeuk Kim 2288eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2289eaa693f4SJaegeuk Kim { 2290eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2291eaa693f4SJaegeuk Kim return true; 2292eaa693f4SJaegeuk Kim 2293eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2294eaa693f4SJaegeuk Kim return true; 2295eaa693f4SJaegeuk Kim 2296eaa693f4SJaegeuk Kim return false; 2297eaa693f4SJaegeuk Kim } 2298eaa693f4SJaegeuk Kim 22993e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 23003e72f721SJaegeuk Kim { 23013e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 230291942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 23033e72f721SJaegeuk Kim return false; 23043e72f721SJaegeuk Kim 2305886f56f9SAl Viro return S_ISREG(inode->i_mode); 23063e72f721SJaegeuk Kim } 23073e72f721SJaegeuk Kim 23081ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 23091ecc0c5cSChao Yu size_t size, gfp_t flags) 23100414b004SJaegeuk Kim { 23112c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 231255523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 231355523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 23142c63feadSJaegeuk Kim return NULL; 231555523519SChao Yu } 23162c63feadSJaegeuk Kim #endif 23170414b004SJaegeuk Kim return kmalloc(size, flags); 23180414b004SJaegeuk Kim } 23190414b004SJaegeuk Kim 23207a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 2321f2470371SChao Yu { 23227a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 2323f2470371SChao Yu } 2324f2470371SChao Yu 232539a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 232691942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 232739a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 232839a53e0cSJaegeuk Kim 23297a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 23307a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 23317a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 23327a2af766SChao Yu 23335c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 23345c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 23355c57132eSChao Yu ((offsetof(typeof(*f2fs_inode), field) + \ 23365c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 23375c57132eSChao Yu <= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize)) \ 23385c57132eSChao Yu 2339b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 2340b0af6d49SChao Yu { 2341b0af6d49SChao Yu int i; 2342b0af6d49SChao Yu 2343b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2344b0af6d49SChao Yu for (i = 0; i < NR_IO_TYPE; i++) 2345b0af6d49SChao Yu sbi->write_iostat[i] = 0; 2346b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2347b0af6d49SChao Yu } 2348b0af6d49SChao Yu 2349b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 2350b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 2351b0af6d49SChao Yu { 2352b0af6d49SChao Yu if (!sbi->iostat_enable) 2353b0af6d49SChao Yu return; 2354b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2355b0af6d49SChao Yu sbi->write_iostat[type] += io_bytes; 2356b0af6d49SChao Yu 2357b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 2358b0af6d49SChao Yu sbi->write_iostat[APP_BUFFERED_IO] = 2359b0af6d49SChao Yu sbi->write_iostat[APP_WRITE_IO] - 2360b0af6d49SChao Yu sbi->write_iostat[APP_DIRECT_IO]; 2361b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2362b0af6d49SChao Yu } 2363b0af6d49SChao Yu 236439a53e0cSJaegeuk Kim /* 236539a53e0cSJaegeuk Kim * file.c 236639a53e0cSJaegeuk Kim */ 2367cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2368cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2369cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2370cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2371a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2372a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2373cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2374cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2375cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2376cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2377cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 237839a53e0cSJaegeuk Kim 237939a53e0cSJaegeuk Kim /* 238039a53e0cSJaegeuk Kim * inode.c 238139a53e0cSJaegeuk Kim */ 2382cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2383704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 2384704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 2385cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2386cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2387cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2388cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2389cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2390cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2391cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2392cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 239339a53e0cSJaegeuk Kim 239439a53e0cSJaegeuk Kim /* 239539a53e0cSJaegeuk Kim * namei.c 239639a53e0cSJaegeuk Kim */ 239739a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 239839a53e0cSJaegeuk Kim 239939a53e0cSJaegeuk Kim /* 240039a53e0cSJaegeuk Kim * dir.c 240139a53e0cSJaegeuk Kim */ 2402cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2403cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2404cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2405cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2406cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2407cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2408cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2409cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2410cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2411cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2412cac5a3d8SDongOh Shin const struct qstr *new_name, 2413cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2414cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2415cac5a3d8SDongOh Shin unsigned int current_depth); 2416cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2417cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2418cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2419cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2420cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2421cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2422cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2423cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2424cac5a3d8SDongOh Shin struct page **page); 2425cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2426cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2427cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2428cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2429cac5a3d8SDongOh Shin unsigned int bit_pos); 2430cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2431cac5a3d8SDongOh Shin const struct qstr *orig_name, 2432cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2433cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2434cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2435cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2436cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2437cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2438cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2439cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2440cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 244139a53e0cSJaegeuk Kim 2442b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2443b7f7a5e0SAl Viro { 24442b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2445510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2446b7f7a5e0SAl Viro } 2447b7f7a5e0SAl Viro 244839a53e0cSJaegeuk Kim /* 244939a53e0cSJaegeuk Kim * super.c 245039a53e0cSJaegeuk Kim */ 2451cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2452cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 24534b2414d0SChao Yu void f2fs_enable_quota_files(struct f2fs_sb_info *sbi); 24544b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 2455cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2456cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2457a07ef784SNamjae Jeon extern __printf(3, 4) 2458cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2459984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 246039a53e0cSJaegeuk Kim 246139a53e0cSJaegeuk Kim /* 246239a53e0cSJaegeuk Kim * hash.c 246339a53e0cSJaegeuk Kim */ 24646332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, 24656332cd32SJaegeuk Kim struct fscrypt_name *fname); 246639a53e0cSJaegeuk Kim 246739a53e0cSJaegeuk Kim /* 246839a53e0cSJaegeuk Kim * node.c 246939a53e0cSJaegeuk Kim */ 247039a53e0cSJaegeuk Kim struct dnode_of_data; 247139a53e0cSJaegeuk Kim struct node_info; 247239a53e0cSJaegeuk Kim 2473cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2474cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2475cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2476cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2477cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2478cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2479cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2480cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 2481cac5a3d8SDongOh Shin int truncate_xattr_node(struct inode *inode, struct page *page); 2482cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2483cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2484cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 24855f4ce6abSYunlei He struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs); 2486cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2487cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2488cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2489cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2490cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2491cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2492401db79fSYunlong Song int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc, 2493b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 249422ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2495cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2496cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2497cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2498cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2499cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2500d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2501cac5a3d8SDongOh Shin block_t blkaddr); 2502cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2503cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2504cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 250522ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2506cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2507cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 25086e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 250939a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 251039a53e0cSJaegeuk Kim 251139a53e0cSJaegeuk Kim /* 251239a53e0cSJaegeuk Kim * segment.c 251339a53e0cSJaegeuk Kim */ 2514b3a97a2aSJaegeuk Kim bool need_SSR(struct f2fs_sb_info *sbi); 2515cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 2516cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 25178c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2518cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2519cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2520cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 2521cac5a3d8SDongOh Shin int f2fs_issue_flush(struct f2fs_sb_info *sbi); 2522cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 2523cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2524cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2525cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2526cac5a3d8SDongOh Shin void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2527cce13252SChao Yu void stop_discard_thread(struct f2fs_sb_info *sbi); 2528638164a2SChao Yu void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi, bool umount); 2529cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2530cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2531cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2532cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2533cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2534cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2535cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2536cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2537b0af6d49SChao Yu void write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 2538b0af6d49SChao Yu enum iostat_type io_type); 2539cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2540cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2541d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2542cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2543cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2544cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2545cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2546cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2547cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2548cac5a3d8SDongOh Shin bool recover_newaddr); 2549cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2550cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2551fb830fc5SChao Yu struct f2fs_summary *sum, int type, 2552fb830fc5SChao Yu struct f2fs_io_info *fio, bool add_list); 2553cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2554cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2555d4c759eeSJaegeuk Kim void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr); 2556cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2557cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2558cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2559cac5a3d8SDongOh Shin unsigned int val, int alloc); 2560cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2561cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2562cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 25637fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 25647fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 256539a53e0cSJaegeuk Kim 256639a53e0cSJaegeuk Kim /* 256739a53e0cSJaegeuk Kim * checkpoint.c 256839a53e0cSJaegeuk Kim */ 2569cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2570cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2571cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2572cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2573cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2574cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2575cac5a3d8SDongOh Shin int type, bool sync); 2576cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2577cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2578b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 2579cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2580cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2581cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2582cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 2583cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2584cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2585cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2586cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2587cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2588cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2589cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2590cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2591cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2592cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2593cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2594cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 25956e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 259639a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 259739a53e0cSJaegeuk Kim 259839a53e0cSJaegeuk Kim /* 259939a53e0cSJaegeuk Kim * data.c 260039a53e0cSJaegeuk Kim */ 2601b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 2602b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 2603942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2604b9109b0eSJaegeuk Kim enum page_type type); 2605b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 2606cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2607b9109b0eSJaegeuk Kim int f2fs_submit_page_write(struct f2fs_io_info *fio); 2608cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2609cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2610cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2611cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2612cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2613cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2614cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2615cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2616cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2617cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2618cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2619cac5a3d8SDongOh Shin int op_flags, bool for_write); 2620cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2621cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2622cac5a3d8SDongOh Shin bool for_write); 2623cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2624cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2625cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2626cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2627cac5a3d8SDongOh Shin int create, int flag); 2628cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2629cac5a3d8SDongOh Shin u64 start, u64 len); 2630cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2631b0af6d49SChao Yu int __f2fs_write_data_pages(struct address_space *mapping, 2632b0af6d49SChao Yu struct writeback_control *wbc, 2633b0af6d49SChao Yu enum iostat_type io_type); 2634cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2635cac5a3d8SDongOh Shin unsigned int length); 2636cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 26375b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2638cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2639cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 26405b7a487cSWeichao Guo #endif 264139a53e0cSJaegeuk Kim 264239a53e0cSJaegeuk Kim /* 264339a53e0cSJaegeuk Kim * gc.c 264439a53e0cSJaegeuk Kim */ 2645cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2646cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2647cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2648e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 2649e066b83cSJaegeuk Kim unsigned int segno); 2650cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 265139a53e0cSJaegeuk Kim 265239a53e0cSJaegeuk Kim /* 265339a53e0cSJaegeuk Kim * recovery.c 265439a53e0cSJaegeuk Kim */ 2655cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2656cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 265739a53e0cSJaegeuk Kim 265839a53e0cSJaegeuk Kim /* 265939a53e0cSJaegeuk Kim * debug.c 266039a53e0cSJaegeuk Kim */ 266139a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 266239a53e0cSJaegeuk Kim struct f2fs_stat_info { 266339a53e0cSJaegeuk Kim struct list_head stat_list; 266439a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 266539a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 266639a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 26675b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 26685b7ee374SChao Yu unsigned long long hit_total, total_ext; 2669c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 267035782b23SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_data, ndirty_imeta; 267135782b23SJaegeuk Kim int inmem_pages; 26720f18b462SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, ndirty_all; 26735b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 26745b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 267539a53e0cSJaegeuk Kim int total_count, utilization; 26768b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 2677*14d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 2678*14d8d5f7SChao Yu int nr_discarding, nr_discarded; 26795f32366aSChao Yu int nr_discard_cmd; 2680d84d1cbdSChao Yu unsigned int undiscard_blks; 2681a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2682648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2683f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 268439a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 268539a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 268639a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 268739a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 268842190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 268939a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2690e1235983SChangman Lee int bg_node_segs, bg_data_segs; 269139a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2692e1235983SChangman Lee int bg_data_blks, bg_node_blks; 269339a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 269439a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 269539a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 269639a53e0cSJaegeuk Kim 269739a53e0cSJaegeuk Kim unsigned int segment_count[2]; 269839a53e0cSJaegeuk Kim unsigned int block_count[2]; 2699b9a2c252SChangman Lee unsigned int inplace_count; 27009edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 270139a53e0cSJaegeuk Kim }; 270239a53e0cSJaegeuk Kim 2703963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2704963d4f7dSGu Zheng { 2705963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2706963d4f7dSGu Zheng } 2707963d4f7dSGu Zheng 2708942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 270942190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 271039a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2711dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 271233fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 271333fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 27145b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 27155b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 27165b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 27175b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2718d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2719d5e8f6c9SChao Yu do { \ 2720d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2721d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2722d5e8f6c9SChao Yu } while (0) 2723d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2724d5e8f6c9SChao Yu do { \ 2725d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2726d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2727d5e8f6c9SChao Yu } while (0) 27280dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 27290dbdc2aeSJaegeuk Kim do { \ 27300dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 273103e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 27320dbdc2aeSJaegeuk Kim } while (0) 27330dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 27340dbdc2aeSJaegeuk Kim do { \ 27350dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 273603e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 27370dbdc2aeSJaegeuk Kim } while (0) 27383289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 27393289c061SJaegeuk Kim do { \ 27403289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 274103e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 27423289c061SJaegeuk Kim } while (0) 27433289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 27443289c061SJaegeuk Kim do { \ 27453289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 274603e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 27473289c061SJaegeuk Kim } while (0) 2748dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2749dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2750dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2751dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2752b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2753b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 275426a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2755cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 275626a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2757cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 275826a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 275926a28a0cSJaegeuk Kim do { \ 276026a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 276126a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 276226a28a0cSJaegeuk Kim if (cur > max) \ 276326a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 276426a28a0cSJaegeuk Kim } while (0) 2765648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2766648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2767648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2768648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2769648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2770648d50baSChao Yu do { \ 2771648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2772648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2773648d50baSChao Yu if (cur > max) \ 2774648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2775648d50baSChao Yu } while (0) 2776e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 277739a53e0cSJaegeuk Kim do { \ 2778963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 277968afcf2dSTomohiro Kusumi si->tot_segs++; \ 278068afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 278139a53e0cSJaegeuk Kim si->data_segs++; \ 2782e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2783e1235983SChangman Lee } else { \ 278439a53e0cSJaegeuk Kim si->node_segs++; \ 2785e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2786e1235983SChangman Lee } \ 278739a53e0cSJaegeuk Kim } while (0) 278839a53e0cSJaegeuk Kim 278939a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 279068afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 279139a53e0cSJaegeuk Kim 2792e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 279339a53e0cSJaegeuk Kim do { \ 2794963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 279539a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 279639a53e0cSJaegeuk Kim si->data_blks += (blks); \ 279768afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 279839a53e0cSJaegeuk Kim } while (0) 279939a53e0cSJaegeuk Kim 2800e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 280139a53e0cSJaegeuk Kim do { \ 2802963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 280339a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 280439a53e0cSJaegeuk Kim si->node_blks += (blks); \ 280568afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 280639a53e0cSJaegeuk Kim } while (0) 280739a53e0cSJaegeuk Kim 2808cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2809cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2810787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 28114589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 281239a53e0cSJaegeuk Kim #else 2813d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 2814d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 2815d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 2816d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 2817d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 2818d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 2819d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 2820d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 2821d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 2822d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 2823d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 2824d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 2825d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 2826d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 2827d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 2828d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 2829d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 2830d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 2831d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 2832d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 2833d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 2834d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 2835d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 2836d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 2837d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 2838d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 2839d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 2840d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 2841d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 284239a53e0cSJaegeuk Kim 284339a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 284439a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2845787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 28464589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 284739a53e0cSJaegeuk Kim #endif 284839a53e0cSJaegeuk Kim 284939a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 285039a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 285139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 285239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 285339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 285439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 285539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 285639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2857cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 285839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 285929e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 28601001b347SHuajun Li 2861e18c65b2SHuajun Li /* 2862e18c65b2SHuajun Li * inline.c 2863e18c65b2SHuajun Li */ 2864cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2865cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2866cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2867bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2868cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2869cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2870cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2871cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2872cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2873cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2874cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2875cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2876cac5a3d8SDongOh Shin struct page *ipage); 2877cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2878cac5a3d8SDongOh Shin const struct qstr *orig_name, 2879cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2880cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2881cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2882cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2883cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2884cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2885cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2886cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2887cac5a3d8SDongOh Shin __u64 start, __u64 len); 2888cde4de12SJaegeuk Kim 2889cde4de12SJaegeuk Kim /* 28902658e50dSJaegeuk Kim * shrinker.c 28912658e50dSJaegeuk Kim */ 2892cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 2893cac5a3d8SDongOh Shin struct shrink_control *sc); 2894cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 2895cac5a3d8SDongOh Shin struct shrink_control *sc); 2896cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 2897cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 28982658e50dSJaegeuk Kim 28992658e50dSJaegeuk Kim /* 2900a28ef1f5SChao Yu * extent_cache.c 2901a28ef1f5SChao Yu */ 2902004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 2903004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 2904004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 2905004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 2906004b6862SChao Yu unsigned int ofs); 2907004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 2908004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 2909004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 2910004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 2911004b6862SChao Yu bool force); 2912df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi, 2913df0f6b44SChao Yu struct rb_root *root); 2914cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 2915cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 2916cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 2917cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 2918cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 2919cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 2920cac5a3d8SDongOh Shin struct extent_info *ei); 2921cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 292219b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 2923cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 2924cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 2925a28ef1f5SChao Yu int __init create_extent_cache(void); 2926a28ef1f5SChao Yu void destroy_extent_cache(void); 2927a28ef1f5SChao Yu 2928a28ef1f5SChao Yu /* 29298ceffcb2SChao Yu * sysfs.c 29308ceffcb2SChao Yu */ 2931dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 2932dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 2933dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 2934dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 29358ceffcb2SChao Yu 29368ceffcb2SChao Yu /* 2937cde4de12SJaegeuk Kim * crypto support 2938cde4de12SJaegeuk Kim */ 29390b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 2940cde4de12SJaegeuk Kim { 2941cde4de12SJaegeuk Kim return file_is_encrypt(inode); 2942cde4de12SJaegeuk Kim } 2943cde4de12SJaegeuk Kim 29441958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 29451958593eSJaegeuk Kim { 29461958593eSJaegeuk Kim return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode); 29471958593eSJaegeuk Kim } 29481958593eSJaegeuk Kim 2949cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 2950cde4de12SJaegeuk Kim { 2951cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 2952cde4de12SJaegeuk Kim file_set_encrypt(inode); 2953cde4de12SJaegeuk Kim #endif 2954cde4de12SJaegeuk Kim } 2955cde4de12SJaegeuk Kim 2956cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 2957cde4de12SJaegeuk Kim { 29580b81d077SJaegeuk Kim return bio->bi_private != NULL; 2959cde4de12SJaegeuk Kim } 2960cde4de12SJaegeuk Kim 2961cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 2962cde4de12SJaegeuk Kim { 2963cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 2964cde4de12SJaegeuk Kim } 2965f424f664SJaegeuk Kim 29660bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 296752763a4bSJaegeuk Kim { 29680bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 296952763a4bSJaegeuk Kim } 297052763a4bSJaegeuk Kim 29717a2af766SChao Yu static inline int f2fs_sb_has_extra_attr(struct super_block *sb) 29727a2af766SChao Yu { 29737a2af766SChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_EXTRA_ATTR); 29747a2af766SChao Yu } 29757a2af766SChao Yu 29765c57132eSChao Yu static inline int f2fs_sb_has_project_quota(struct super_block *sb) 29775c57132eSChao Yu { 29785c57132eSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_PRJQUOTA); 29795c57132eSChao Yu } 29805c57132eSChao Yu 2981704956ecSChao Yu static inline int f2fs_sb_has_inode_chksum(struct super_block *sb) 2982704956ecSChao Yu { 2983704956ecSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CHKSUM); 2984704956ecSChao Yu } 2985704956ecSChao Yu 2986178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 2987178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 29883c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 2989178053e2SDamien Le Moal { 2990178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 29913c62be17SJaegeuk Kim int i; 2992178053e2SDamien Le Moal 29933c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 29943c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 29953c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 29963c62be17SJaegeuk Kim return -EINVAL; 2997178053e2SDamien Le Moal } 2998178053e2SDamien Le Moal #endif 2999178053e2SDamien Le Moal 300096ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 300196ba2decSDamien Le Moal { 300296ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 300396ba2decSDamien Le Moal 300496ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 300552763a4bSJaegeuk Kim } 300652763a4bSJaegeuk Kim 300752763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 300852763a4bSJaegeuk Kim { 300952763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 301052763a4bSJaegeuk Kim clear_opt(sbi, LFS); 301152763a4bSJaegeuk Kim 301252763a4bSJaegeuk Kim switch (mt) { 301352763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 301452763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 301552763a4bSJaegeuk Kim break; 301652763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 301752763a4bSJaegeuk Kim set_opt(sbi, LFS); 301852763a4bSJaegeuk Kim break; 301952763a4bSJaegeuk Kim } 302052763a4bSJaegeuk Kim } 302152763a4bSJaegeuk Kim 3022fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 3023fcc85a4dSJaegeuk Kim { 3024fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 3025886f56f9SAl Viro umode_t mode = inode->i_mode; 3026fcc85a4dSJaegeuk Kim 3027fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 3028fcc85a4dSJaegeuk Kim #else 3029fcc85a4dSJaegeuk Kim return 0; 3030fcc85a4dSJaegeuk Kim #endif 3031fcc85a4dSJaegeuk Kim } 3032fcc85a4dSJaegeuk Kim 303339a53e0cSJaegeuk Kim #endif 3034