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, 4901eccef7SChao Yu FAULT_PAGE_GET, 50d62fe971SChao Yu FAULT_ALLOC_BIO, 51cb78942bSJaegeuk Kim FAULT_ALLOC_NID, 52cb78942bSJaegeuk Kim FAULT_ORPHAN, 53cb78942bSJaegeuk Kim FAULT_BLOCK, 54cb78942bSJaegeuk Kim FAULT_DIR_DEPTH, 5553aa6bbfSJaegeuk Kim FAULT_EVICT_INODE, 5614b44d23SJaegeuk Kim FAULT_TRUNCATE, 578b038c70SChao Yu FAULT_IO, 580f348028SChao Yu FAULT_CHECKPOINT, 592c63feadSJaegeuk Kim FAULT_MAX, 602c63feadSJaegeuk Kim }; 612c63feadSJaegeuk Kim 6208796897SSheng Yong struct f2fs_fault_info { 6308796897SSheng Yong atomic_t inject_ops; 6408796897SSheng Yong unsigned int inject_rate; 6508796897SSheng Yong unsigned int inject_type; 6608796897SSheng Yong }; 6708796897SSheng Yong 682c63feadSJaegeuk Kim extern char *fault_name[FAULT_MAX]; 6968afcf2dSTomohiro Kusumi #define IS_FAULT_SET(fi, type) ((fi)->inject_type & (1 << (type))) 702c63feadSJaegeuk Kim #endif 712c63feadSJaegeuk Kim 7239a53e0cSJaegeuk Kim /* 7339a53e0cSJaegeuk Kim * For mount options 7439a53e0cSJaegeuk Kim */ 7539a53e0cSJaegeuk Kim #define F2FS_MOUNT_BG_GC 0x00000001 7639a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_ROLL_FORWARD 0x00000002 7739a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISCARD 0x00000004 7839a53e0cSJaegeuk Kim #define F2FS_MOUNT_NOHEAP 0x00000008 7939a53e0cSJaegeuk Kim #define F2FS_MOUNT_XATTR_USER 0x00000010 8039a53e0cSJaegeuk Kim #define F2FS_MOUNT_POSIX_ACL 0x00000020 8139a53e0cSJaegeuk Kim #define F2FS_MOUNT_DISABLE_EXT_IDENTIFY 0x00000040 82444c580fSJaegeuk Kim #define F2FS_MOUNT_INLINE_XATTR 0x00000080 831001b347SHuajun Li #define F2FS_MOUNT_INLINE_DATA 0x00000100 8434d67debSChao Yu #define F2FS_MOUNT_INLINE_DENTRY 0x00000200 8534d67debSChao Yu #define F2FS_MOUNT_FLUSH_MERGE 0x00000400 8634d67debSChao Yu #define F2FS_MOUNT_NOBARRIER 0x00000800 87d5053a34SJaegeuk Kim #define F2FS_MOUNT_FASTBOOT 0x00001000 8889672159SChao Yu #define F2FS_MOUNT_EXTENT_CACHE 0x00002000 896aefd93bSJaegeuk Kim #define F2FS_MOUNT_FORCE_FG_GC 0x00004000 90343f40f0SChao Yu #define F2FS_MOUNT_DATA_FLUSH 0x00008000 9173faec4dSJaegeuk Kim #define F2FS_MOUNT_FAULT_INJECTION 0x00010000 9236abef4eSJaegeuk Kim #define F2FS_MOUNT_ADAPTIVE 0x00020000 9336abef4eSJaegeuk Kim #define F2FS_MOUNT_LFS 0x00040000 940abd675eSChao Yu #define F2FS_MOUNT_USRQUOTA 0x00080000 950abd675eSChao Yu #define F2FS_MOUNT_GRPQUOTA 0x00100000 965c57132eSChao Yu #define F2FS_MOUNT_PRJQUOTA 0x00200000 974b2414d0SChao Yu #define F2FS_MOUNT_QUOTA 0x00400000 986afc662eSChao Yu #define F2FS_MOUNT_INLINE_XATTR_SIZE 0x00800000 9939a53e0cSJaegeuk Kim 10068afcf2dSTomohiro Kusumi #define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) 10168afcf2dSTomohiro Kusumi #define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) 10268afcf2dSTomohiro Kusumi #define test_opt(sbi, option) ((sbi)->mount_opt.opt & F2FS_MOUNT_##option) 10339a53e0cSJaegeuk Kim 10439a53e0cSJaegeuk Kim #define ver_after(a, b) (typecheck(unsigned long long, a) && \ 10539a53e0cSJaegeuk Kim typecheck(unsigned long long, b) && \ 10639a53e0cSJaegeuk Kim ((long long)((a) - (b)) > 0)) 10739a53e0cSJaegeuk Kim 108a9841c4dSJaegeuk Kim typedef u32 block_t; /* 109a9841c4dSJaegeuk Kim * should not change u32, since it is the on-disk block 110a9841c4dSJaegeuk Kim * address format, __le32. 111a9841c4dSJaegeuk Kim */ 11239a53e0cSJaegeuk Kim typedef u32 nid_t; 11339a53e0cSJaegeuk Kim 11439a53e0cSJaegeuk Kim struct f2fs_mount_info { 11539a53e0cSJaegeuk Kim unsigned int opt; 11639a53e0cSJaegeuk Kim }; 11739a53e0cSJaegeuk Kim 118cde4de12SJaegeuk Kim #define F2FS_FEATURE_ENCRYPT 0x0001 1190bfd7a09SDamien Le Moal #define F2FS_FEATURE_BLKZONED 0x0002 120e65ef207SJaegeuk Kim #define F2FS_FEATURE_ATOMIC_WRITE 0x0004 1217a2af766SChao Yu #define F2FS_FEATURE_EXTRA_ATTR 0x0008 1225c57132eSChao Yu #define F2FS_FEATURE_PRJQUOTA 0x0010 123704956ecSChao Yu #define F2FS_FEATURE_INODE_CHKSUM 0x0020 1246afc662eSChao Yu #define F2FS_FEATURE_FLEXIBLE_INLINE_XATTR 0x0040 125234a9689SJaegeuk Kim #define F2FS_FEATURE_QUOTA_INO 0x0080 126cde4de12SJaegeuk Kim 12776f105a2SJaegeuk Kim #define F2FS_HAS_FEATURE(sb, mask) \ 12876f105a2SJaegeuk Kim ((F2FS_SB(sb)->raw_super->feature & cpu_to_le32(mask)) != 0) 12976f105a2SJaegeuk Kim #define F2FS_SET_FEATURE(sb, mask) \ 130c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature |= cpu_to_le32(mask)) 13176f105a2SJaegeuk Kim #define F2FS_CLEAR_FEATURE(sb, mask) \ 132c64ab12eSDongOh Shin (F2FS_SB(sb)->raw_super->feature &= ~cpu_to_le32(mask)) 13376f105a2SJaegeuk Kim 13439a53e0cSJaegeuk Kim /* 13539a53e0cSJaegeuk Kim * For checkpoint manager 13639a53e0cSJaegeuk Kim */ 13739a53e0cSJaegeuk Kim enum { 13839a53e0cSJaegeuk Kim NAT_BITMAP, 13939a53e0cSJaegeuk Kim SIT_BITMAP 14039a53e0cSJaegeuk Kim }; 14139a53e0cSJaegeuk Kim 142c473f1a9SChao Yu #define CP_UMOUNT 0x00000001 143c473f1a9SChao Yu #define CP_FASTBOOT 0x00000002 144c473f1a9SChao Yu #define CP_SYNC 0x00000004 145c473f1a9SChao Yu #define CP_RECOVERY 0x00000008 146c473f1a9SChao Yu #define CP_DISCARD 0x00000010 1471f43e2adSChao Yu #define CP_TRIMMED 0x00000020 14875ab4cb8SJaegeuk Kim 14947b89808SJaegeuk Kim #define DEF_BATCHED_TRIM_SECTIONS 2048 150bba681cbSJaegeuk Kim #define BATCHED_TRIM_SEGMENTS(sbi) \ 1514ddb1a4dSJaegeuk Kim (GET_SEG_FROM_SEC(sbi, SM_I(sbi)->trim_sections)) 152a66cdd98SJaegeuk Kim #define BATCHED_TRIM_BLOCKS(sbi) \ 153a66cdd98SJaegeuk Kim (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg) 1544ddb1a4dSJaegeuk Kim #define MAX_DISCARD_BLOCKS(sbi) BLKS_PER_SEC(sbi) 155ecc9aa00SChao Yu #define DEF_MAX_DISCARD_REQUEST 8 /* issue 8 discards per round */ 156969d1b18SChao Yu #define DEF_MIN_DISCARD_ISSUE_TIME 50 /* 50 ms, if exists */ 157969d1b18SChao Yu #define DEF_MAX_DISCARD_ISSUE_TIME 60000 /* 60 s, if no candidates */ 15860b99b48SJaegeuk Kim #define DEF_CP_INTERVAL 60 /* 60 secs */ 159dcf25fe8SChao Yu #define DEF_IDLE_INTERVAL 5 /* 5 secs */ 160bba681cbSJaegeuk Kim 16175ab4cb8SJaegeuk Kim struct cp_control { 16275ab4cb8SJaegeuk Kim int reason; 1634b2fecc8SJaegeuk Kim __u64 trim_start; 1644b2fecc8SJaegeuk Kim __u64 trim_end; 1654b2fecc8SJaegeuk Kim __u64 trim_minlen; 16675ab4cb8SJaegeuk Kim }; 16775ab4cb8SJaegeuk Kim 168662befdaSChao Yu /* 16981c1a0f1SChao Yu * For CP/NAT/SIT/SSA readahead 170662befdaSChao Yu */ 171662befdaSChao Yu enum { 172662befdaSChao Yu META_CP, 173662befdaSChao Yu META_NAT, 17481c1a0f1SChao Yu META_SIT, 1754c521f49SJaegeuk Kim META_SSA, 1764c521f49SJaegeuk Kim META_POR, 177662befdaSChao Yu }; 178662befdaSChao Yu 1796451e041SJaegeuk Kim /* for the list of ino */ 1806451e041SJaegeuk Kim enum { 1816451e041SJaegeuk Kim ORPHAN_INO, /* for orphan ino list */ 182fff04f90SJaegeuk Kim APPEND_INO, /* for append ino list */ 183fff04f90SJaegeuk Kim UPDATE_INO, /* for update ino list */ 18439d787beSChao Yu FLUSH_INO, /* for multiple device flushing */ 1856451e041SJaegeuk Kim MAX_INO_ENTRY, /* max. list */ 1866451e041SJaegeuk Kim }; 1876451e041SJaegeuk Kim 1886451e041SJaegeuk Kim struct ino_entry { 18939a53e0cSJaegeuk Kim struct list_head list; /* list head */ 19039a53e0cSJaegeuk Kim nid_t ino; /* inode number */ 19139d787beSChao Yu unsigned int dirty_device; /* dirty device bitmap */ 19239a53e0cSJaegeuk Kim }; 19339a53e0cSJaegeuk Kim 1942710fd7eSChao Yu /* for the list of inodes to be GCed */ 19506292073SChao Yu struct inode_entry { 19639a53e0cSJaegeuk Kim struct list_head list; /* list head */ 19739a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 19839a53e0cSJaegeuk Kim }; 19939a53e0cSJaegeuk Kim 200a7eeb823SChao Yu /* for the bitmap indicate blocks to be discarded */ 2017fd9e544SJaegeuk Kim struct discard_entry { 2027fd9e544SJaegeuk Kim struct list_head list; /* list head */ 203a7eeb823SChao Yu block_t start_blkaddr; /* start blockaddr of current segment */ 204a7eeb823SChao Yu unsigned char discard_map[SIT_VBLOCK_MAP_SIZE]; /* segment discard bitmap */ 2057fd9e544SJaegeuk Kim }; 2067fd9e544SJaegeuk Kim 207969d1b18SChao Yu /* default discard granularity of inner discard thread, unit: block count */ 208969d1b18SChao Yu #define DEFAULT_DISCARD_GRANULARITY 16 209969d1b18SChao Yu 210ba48a33eSChao Yu /* max discard pend list number */ 211ba48a33eSChao Yu #define MAX_PLIST_NUM 512 212ba48a33eSChao Yu #define plist_idx(blk_num) ((blk_num) >= MAX_PLIST_NUM ? \ 213ba48a33eSChao Yu (MAX_PLIST_NUM - 1) : (blk_num - 1)) 214ba48a33eSChao Yu 21515469963SJaegeuk Kim enum { 21615469963SJaegeuk Kim D_PREP, 21715469963SJaegeuk Kim D_SUBMIT, 21815469963SJaegeuk Kim D_DONE, 21915469963SJaegeuk Kim }; 22015469963SJaegeuk Kim 221004b6862SChao Yu struct discard_info { 222b01a9201SJaegeuk Kim block_t lstart; /* logical start address */ 223b01a9201SJaegeuk Kim block_t len; /* length */ 224004b6862SChao Yu block_t start; /* actual start address in dev */ 225004b6862SChao Yu }; 226004b6862SChao Yu 227b01a9201SJaegeuk Kim struct discard_cmd { 228004b6862SChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 229004b6862SChao Yu union { 230004b6862SChao Yu struct { 231004b6862SChao Yu block_t lstart; /* logical start address */ 232004b6862SChao Yu block_t len; /* length */ 233004b6862SChao Yu block_t start; /* actual start address in dev */ 234004b6862SChao Yu }; 235004b6862SChao Yu struct discard_info di; /* discard info */ 236004b6862SChao Yu 237004b6862SChao Yu }; 238b01a9201SJaegeuk Kim struct list_head list; /* command list */ 239b01a9201SJaegeuk Kim struct completion wait; /* compleation */ 240c81abe34SJaegeuk Kim struct block_device *bdev; /* bdev */ 241ec9895adSChao Yu unsigned short ref; /* reference count */ 2429a744b92SChao Yu unsigned char state; /* state */ 243c81abe34SJaegeuk Kim int error; /* bio error */ 244275b66b0SChao Yu }; 245275b66b0SChao Yu 24678997b56SChao Yu enum { 24778997b56SChao Yu DPOLICY_BG, 24878997b56SChao Yu DPOLICY_FORCE, 24978997b56SChao Yu DPOLICY_FSTRIM, 25078997b56SChao Yu DPOLICY_UMOUNT, 25178997b56SChao Yu MAX_DPOLICY, 25278997b56SChao Yu }; 25378997b56SChao Yu 254ecc9aa00SChao Yu struct discard_policy { 25578997b56SChao Yu int type; /* type of discard */ 256ecc9aa00SChao Yu unsigned int min_interval; /* used for candidates exist */ 257ecc9aa00SChao Yu unsigned int max_interval; /* used for candidates not exist */ 258ecc9aa00SChao Yu unsigned int max_requests; /* # of discards issued per round */ 259ecc9aa00SChao Yu unsigned int io_aware_gran; /* minimum granularity discard not be aware of I/O */ 260ecc9aa00SChao Yu bool io_aware; /* issue discard in idle time */ 261ecc9aa00SChao Yu bool sync; /* submit discard with REQ_SYNC flag */ 26278997b56SChao Yu unsigned int granularity; /* discard granularity */ 263ecc9aa00SChao Yu }; 264ecc9aa00SChao Yu 2650b54fb84SJaegeuk Kim struct discard_cmd_control { 26615469963SJaegeuk Kim struct task_struct *f2fs_issue_discard; /* discard thread */ 26746f84c2cSChao Yu struct list_head entry_list; /* 4KB discard entry list */ 268ba48a33eSChao Yu struct list_head pend_list[MAX_PLIST_NUM];/* store pending entries */ 269969d1b18SChao Yu unsigned char pend_list_tag[MAX_PLIST_NUM];/* tag for pending entries */ 27046f84c2cSChao Yu struct list_head wait_list; /* store on-flushing entries */ 2718412663dSChao Yu struct list_head fstrim_list; /* in-flight discard from fstrim */ 27215469963SJaegeuk Kim wait_queue_head_t discard_wait_queue; /* waiting queue for wake-up */ 273969d1b18SChao Yu unsigned int discard_wake; /* to wake up discard thread */ 27415469963SJaegeuk Kim struct mutex cmd_lock; 275d618ebafSChao Yu unsigned int nr_discards; /* # of discards in the list */ 276d618ebafSChao Yu unsigned int max_discards; /* max. discards to be issued */ 277969d1b18SChao Yu unsigned int discard_granularity; /* discard granularity */ 278d84d1cbdSChao Yu unsigned int undiscard_blks; /* # of undiscard blocks */ 2798b8dd65fSChao Yu atomic_t issued_discard; /* # of issued discard */ 2808b8dd65fSChao Yu atomic_t issing_discard; /* # of issing discard */ 2815f32366aSChao Yu atomic_t discard_cmd_cnt; /* # of cached cmd count */ 282004b6862SChao Yu struct rb_root root; /* root of discard rb-tree */ 28339a53e0cSJaegeuk Kim }; 28439a53e0cSJaegeuk Kim 28539a53e0cSJaegeuk Kim /* for the list of fsync inodes, used only during recovery */ 28639a53e0cSJaegeuk Kim struct fsync_inode_entry { 28739a53e0cSJaegeuk Kim struct list_head list; /* list head */ 28839a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 289c52e1b10SJaegeuk Kim block_t blkaddr; /* block address locating the last fsync */ 290c52e1b10SJaegeuk Kim block_t last_dentry; /* block address locating the last dentry */ 29139a53e0cSJaegeuk Kim }; 29239a53e0cSJaegeuk Kim 29368afcf2dSTomohiro Kusumi #define nats_in_cursum(jnl) (le16_to_cpu((jnl)->n_nats)) 29468afcf2dSTomohiro Kusumi #define sits_in_cursum(jnl) (le16_to_cpu((jnl)->n_sits)) 29539a53e0cSJaegeuk Kim 29668afcf2dSTomohiro Kusumi #define nat_in_journal(jnl, i) ((jnl)->nat_j.entries[i].ne) 29768afcf2dSTomohiro Kusumi #define nid_in_journal(jnl, i) ((jnl)->nat_j.entries[i].nid) 29868afcf2dSTomohiro Kusumi #define sit_in_journal(jnl, i) ((jnl)->sit_j.entries[i].se) 29968afcf2dSTomohiro Kusumi #define segno_in_journal(jnl, i) ((jnl)->sit_j.entries[i].segno) 30039a53e0cSJaegeuk Kim 301dfc08a12SChao Yu #define MAX_NAT_JENTRIES(jnl) (NAT_JOURNAL_ENTRIES - nats_in_cursum(jnl)) 302dfc08a12SChao Yu #define MAX_SIT_JENTRIES(jnl) (SIT_JOURNAL_ENTRIES - sits_in_cursum(jnl)) 303309cc2b6SJaegeuk Kim 304dfc08a12SChao Yu static inline int update_nats_in_cursum(struct f2fs_journal *journal, int i) 30539a53e0cSJaegeuk Kim { 306dfc08a12SChao Yu int before = nats_in_cursum(journal); 307cac5a3d8SDongOh Shin 308dfc08a12SChao Yu journal->n_nats = cpu_to_le16(before + i); 30939a53e0cSJaegeuk Kim return before; 31039a53e0cSJaegeuk Kim } 31139a53e0cSJaegeuk Kim 312dfc08a12SChao Yu static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) 31339a53e0cSJaegeuk Kim { 314dfc08a12SChao Yu int before = sits_in_cursum(journal); 315cac5a3d8SDongOh Shin 316dfc08a12SChao Yu journal->n_sits = cpu_to_le16(before + i); 31739a53e0cSJaegeuk Kim return before; 31839a53e0cSJaegeuk Kim } 31939a53e0cSJaegeuk Kim 320dfc08a12SChao Yu static inline bool __has_cursum_space(struct f2fs_journal *journal, 321dfc08a12SChao Yu int size, int type) 322184a5cd2SChao Yu { 323184a5cd2SChao Yu if (type == NAT_JOURNAL) 324dfc08a12SChao Yu return size <= MAX_NAT_JENTRIES(journal); 325dfc08a12SChao Yu return size <= MAX_SIT_JENTRIES(journal); 326184a5cd2SChao Yu } 327184a5cd2SChao Yu 32839a53e0cSJaegeuk Kim /* 329e9750824SNamjae Jeon * ioctl commands 330e9750824SNamjae Jeon */ 331e9750824SNamjae Jeon #define F2FS_IOC_GETFLAGS FS_IOC_GETFLAGS 332e9750824SNamjae Jeon #define F2FS_IOC_SETFLAGS FS_IOC_SETFLAGS 333d49f3e89SChao Yu #define F2FS_IOC_GETVERSION FS_IOC_GETVERSION 334e9750824SNamjae Jeon 33588b88a66SJaegeuk Kim #define F2FS_IOCTL_MAGIC 0xf5 33688b88a66SJaegeuk Kim #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1) 33788b88a66SJaegeuk Kim #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2) 33802a1335fSJaegeuk Kim #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3) 3391e84371fSJaegeuk Kim #define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4) 3401e84371fSJaegeuk Kim #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5) 341d07efb50SJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT _IOW(F2FS_IOCTL_MAGIC, 6, __u32) 342456b88e4SChao Yu #define F2FS_IOC_WRITE_CHECKPOINT _IO(F2FS_IOCTL_MAGIC, 7) 343d07efb50SJaegeuk Kim #define F2FS_IOC_DEFRAGMENT _IOWR(F2FS_IOCTL_MAGIC, 8, \ 344d07efb50SJaegeuk Kim struct f2fs_defragment) 3454dd6f977SJaegeuk Kim #define F2FS_IOC_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ 3464dd6f977SJaegeuk Kim struct f2fs_move_range) 347e066b83cSJaegeuk Kim #define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ 348e066b83cSJaegeuk Kim struct f2fs_flush_device) 34934dc77adSJaegeuk Kim #define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \ 35034dc77adSJaegeuk Kim struct f2fs_gc_range) 351e65ef207SJaegeuk Kim #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, __u32) 35288b88a66SJaegeuk Kim 3530b81d077SJaegeuk Kim #define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 3540b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 3550b81d077SJaegeuk Kim #define F2FS_IOC_GET_ENCRYPTION_PWSALT FS_IOC_GET_ENCRYPTION_PWSALT 356f424f664SJaegeuk Kim 3571abff93dSJaegeuk Kim /* 3581abff93dSJaegeuk Kim * should be same as XFS_IOC_GOINGDOWN. 3591abff93dSJaegeuk Kim * Flags for going down operation used by FS_IOC_GOINGDOWN 3601abff93dSJaegeuk Kim */ 3611abff93dSJaegeuk Kim #define F2FS_IOC_SHUTDOWN _IOR('X', 125, __u32) /* Shutdown */ 3621abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_FULLSYNC 0x0 /* going down with full sync */ 3631abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_METASYNC 0x1 /* going down with metadata */ 3641abff93dSJaegeuk Kim #define F2FS_GOING_DOWN_NOSYNC 0x2 /* going down */ 365c912a829SJaegeuk Kim #define F2FS_GOING_DOWN_METAFLUSH 0x3 /* going down with meta flush */ 3661abff93dSJaegeuk Kim 367e9750824SNamjae Jeon #if defined(__KERNEL__) && defined(CONFIG_COMPAT) 368e9750824SNamjae Jeon /* 369e9750824SNamjae Jeon * ioctl commands in 32 bit emulation 370e9750824SNamjae Jeon */ 371e9750824SNamjae Jeon #define F2FS_IOC32_GETFLAGS FS_IOC32_GETFLAGS 372e9750824SNamjae Jeon #define F2FS_IOC32_SETFLAGS FS_IOC32_SETFLAGS 37304ef4b62SChao Yu #define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 374e9750824SNamjae Jeon #endif 375e9750824SNamjae Jeon 3762c1d0305SChao Yu #define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR 3772c1d0305SChao Yu #define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR 3782c1d0305SChao Yu 37934dc77adSJaegeuk Kim struct f2fs_gc_range { 38034dc77adSJaegeuk Kim u32 sync; 38134dc77adSJaegeuk Kim u64 start; 38234dc77adSJaegeuk Kim u64 len; 38334dc77adSJaegeuk Kim }; 38434dc77adSJaegeuk Kim 385d323d005SChao Yu struct f2fs_defragment { 386d323d005SChao Yu u64 start; 387d323d005SChao Yu u64 len; 388d323d005SChao Yu }; 389d323d005SChao Yu 3904dd6f977SJaegeuk Kim struct f2fs_move_range { 3914dd6f977SJaegeuk Kim u32 dst_fd; /* destination fd */ 3924dd6f977SJaegeuk Kim u64 pos_in; /* start position in src_fd */ 3934dd6f977SJaegeuk Kim u64 pos_out; /* start position in dst_fd */ 3944dd6f977SJaegeuk Kim u64 len; /* size to move */ 3954dd6f977SJaegeuk Kim }; 3964dd6f977SJaegeuk Kim 397e066b83cSJaegeuk Kim struct f2fs_flush_device { 398e066b83cSJaegeuk Kim u32 dev_num; /* device number to flush */ 399e066b83cSJaegeuk Kim u32 segments; /* # of segments to flush */ 400e066b83cSJaegeuk Kim }; 401e066b83cSJaegeuk Kim 402f2470371SChao Yu /* for inline stuff */ 403f2470371SChao Yu #define DEF_INLINE_RESERVED_SIZE 1 4046afc662eSChao Yu #define DEF_MIN_INLINE_SIZE 1 4057a2af766SChao Yu static inline int get_extra_isize(struct inode *inode); 4066afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode); 4076afc662eSChao Yu #define F2FS_INLINE_XATTR_ADDRS(inode) get_inline_xattr_addrs(inode) 4087a2af766SChao Yu #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ 4097a2af766SChao Yu (CUR_ADDRS_PER_INODE(inode) - \ 4106afc662eSChao Yu F2FS_INLINE_XATTR_ADDRS(inode) - \ 4116afc662eSChao Yu DEF_INLINE_RESERVED_SIZE)) 412f2470371SChao Yu 413f2470371SChao Yu /* for inline dir */ 414f2470371SChao Yu #define NR_INLINE_DENTRY(inode) (MAX_INLINE_DATA(inode) * BITS_PER_BYTE / \ 415f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 416f2470371SChao Yu BITS_PER_BYTE + 1)) 417f2470371SChao Yu #define INLINE_DENTRY_BITMAP_SIZE(inode) ((NR_INLINE_DENTRY(inode) + \ 418f2470371SChao Yu BITS_PER_BYTE - 1) / BITS_PER_BYTE) 419f2470371SChao Yu #define INLINE_RESERVED_SIZE(inode) (MAX_INLINE_DATA(inode) - \ 420f2470371SChao Yu ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * \ 421f2470371SChao Yu NR_INLINE_DENTRY(inode) + \ 422f2470371SChao Yu INLINE_DENTRY_BITMAP_SIZE(inode))) 423f2470371SChao Yu 424e9750824SNamjae Jeon /* 42539a53e0cSJaegeuk Kim * For INODE and NODE manager 42639a53e0cSJaegeuk Kim */ 4277b3cd7d6SJaegeuk Kim /* for directory operations */ 4287b3cd7d6SJaegeuk Kim struct f2fs_dentry_ptr { 429d8c6822aSJaegeuk Kim struct inode *inode; 43076a9dd85SChao Yu void *bitmap; 4317b3cd7d6SJaegeuk Kim struct f2fs_dir_entry *dentry; 4327b3cd7d6SJaegeuk Kim __u8 (*filename)[F2FS_SLOT_LEN]; 4337b3cd7d6SJaegeuk Kim int max; 43476a9dd85SChao Yu int nr_bitmap; 4357b3cd7d6SJaegeuk Kim }; 4367b3cd7d6SJaegeuk Kim 43764c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_block(struct inode *inode, 43864c24ecbSTomohiro Kusumi struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) 4397b3cd7d6SJaegeuk Kim { 440d8c6822aSJaegeuk Kim d->inode = inode; 4417b3cd7d6SJaegeuk Kim d->max = NR_DENTRY_IN_BLOCK; 44276a9dd85SChao Yu d->nr_bitmap = SIZE_OF_DENTRY_BITMAP; 4437b3cd7d6SJaegeuk Kim d->bitmap = &t->dentry_bitmap; 4447b3cd7d6SJaegeuk Kim d->dentry = t->dentry; 4457b3cd7d6SJaegeuk Kim d->filename = t->filename; 44664c24ecbSTomohiro Kusumi } 447cac5a3d8SDongOh Shin 44864c24ecbSTomohiro Kusumi static inline void make_dentry_ptr_inline(struct inode *inode, 449f2470371SChao Yu struct f2fs_dentry_ptr *d, void *t) 45064c24ecbSTomohiro Kusumi { 451f2470371SChao Yu int entry_cnt = NR_INLINE_DENTRY(inode); 452f2470371SChao Yu int bitmap_size = INLINE_DENTRY_BITMAP_SIZE(inode); 453f2470371SChao Yu int reserved_size = INLINE_RESERVED_SIZE(inode); 454f2470371SChao Yu 45564c24ecbSTomohiro Kusumi d->inode = inode; 456f2470371SChao Yu d->max = entry_cnt; 457f2470371SChao Yu d->nr_bitmap = bitmap_size; 458f2470371SChao Yu d->bitmap = t; 459f2470371SChao Yu d->dentry = t + bitmap_size + reserved_size; 460f2470371SChao Yu d->filename = t + bitmap_size + reserved_size + 461f2470371SChao Yu SIZE_OF_DIR_ENTRY * entry_cnt; 4627b3cd7d6SJaegeuk Kim } 4637b3cd7d6SJaegeuk Kim 464dbe6a5ffSJaegeuk Kim /* 465dbe6a5ffSJaegeuk Kim * XATTR_NODE_OFFSET stores xattrs to one node block per file keeping -1 466dbe6a5ffSJaegeuk Kim * as its node offset to distinguish from index node blocks. 467dbe6a5ffSJaegeuk Kim * But some bits are used to mark the node block. 46839a53e0cSJaegeuk Kim */ 469dbe6a5ffSJaegeuk Kim #define XATTR_NODE_OFFSET ((((unsigned int)-1) << OFFSET_BIT_SHIFT) \ 470dbe6a5ffSJaegeuk Kim >> OFFSET_BIT_SHIFT) 471266e97a8SJaegeuk Kim enum { 472266e97a8SJaegeuk Kim ALLOC_NODE, /* allocate a new node page if needed */ 473266e97a8SJaegeuk Kim LOOKUP_NODE, /* look up a node without readahead */ 474266e97a8SJaegeuk Kim LOOKUP_NODE_RA, /* 475266e97a8SJaegeuk Kim * look up a node with readahead called 4764f4124d0SChao Yu * by get_data_block. 47739a53e0cSJaegeuk Kim */ 478266e97a8SJaegeuk Kim }; 479266e97a8SJaegeuk Kim 480a6db67f0SJaegeuk Kim #define F2FS_LINK_MAX 0xffffffff /* maximum link count per file */ 48139a53e0cSJaegeuk Kim 482817202d9SChao Yu #define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */ 483817202d9SChao Yu 48413054c54SChao Yu /* vector size for gang look-up from extent cache that consists of radix tree */ 48513054c54SChao Yu #define EXT_TREE_VEC_SIZE 64 48613054c54SChao Yu 48739a53e0cSJaegeuk Kim /* for in-memory extent cache entry */ 48813054c54SChao Yu #define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */ 48913054c54SChao Yu 49013054c54SChao Yu /* number of extent info in extent cache we try to shrink */ 49113054c54SChao Yu #define EXTENT_CACHE_SHRINK_NUMBER 128 492c11abd1aSJaegeuk Kim 49354c2258cSChao Yu struct rb_entry { 49454c2258cSChao Yu struct rb_node rb_node; /* rb node located in rb-tree */ 49554c2258cSChao Yu unsigned int ofs; /* start offset of the entry */ 49654c2258cSChao Yu unsigned int len; /* length of the entry */ 49754c2258cSChao Yu }; 49854c2258cSChao Yu 49939a53e0cSJaegeuk Kim struct extent_info { 50039a53e0cSJaegeuk Kim unsigned int fofs; /* start offset in a file */ 501111d2495SMasanari Iida unsigned int len; /* length of the extent */ 50254c2258cSChao Yu u32 blk; /* start block address of the extent */ 50339a53e0cSJaegeuk Kim }; 50439a53e0cSJaegeuk Kim 50513054c54SChao Yu struct extent_node { 50654c2258cSChao Yu struct rb_node rb_node; 50754c2258cSChao Yu union { 50854c2258cSChao Yu struct { 50954c2258cSChao Yu unsigned int fofs; 51054c2258cSChao Yu unsigned int len; 51154c2258cSChao Yu u32 blk; 51254c2258cSChao Yu }; 51313054c54SChao Yu struct extent_info ei; /* extent info */ 51454c2258cSChao Yu 51554c2258cSChao Yu }; 51654c2258cSChao Yu struct list_head list; /* node in global extent list of sbi */ 517201ef5e0SHou Pengyang struct extent_tree *et; /* extent tree pointer */ 51813054c54SChao Yu }; 51913054c54SChao Yu 52013054c54SChao Yu struct extent_tree { 52113054c54SChao Yu nid_t ino; /* inode number */ 52213054c54SChao Yu struct rb_root root; /* root of extent info rb-tree */ 52362c8af65SChao Yu struct extent_node *cached_en; /* recently accessed extent node */ 5243e72f721SJaegeuk Kim struct extent_info largest; /* largested extent info */ 525137d09f0SJaegeuk Kim struct list_head list; /* to be used by sbi->zombie_list */ 52613054c54SChao Yu rwlock_t lock; /* protect extent info rb-tree */ 52768e35385SChao Yu atomic_t node_cnt; /* # of extent node in rb-tree*/ 52813054c54SChao Yu }; 52913054c54SChao Yu 53039a53e0cSJaegeuk Kim /* 531003a3e1dSJaegeuk Kim * This structure is taken from ext4_map_blocks. 532003a3e1dSJaegeuk Kim * 533003a3e1dSJaegeuk Kim * Note that, however, f2fs uses NEW and MAPPED flags for f2fs_map_blocks(). 534003a3e1dSJaegeuk Kim */ 535003a3e1dSJaegeuk Kim #define F2FS_MAP_NEW (1 << BH_New) 536003a3e1dSJaegeuk Kim #define F2FS_MAP_MAPPED (1 << BH_Mapped) 5377f63eb77SJaegeuk Kim #define F2FS_MAP_UNWRITTEN (1 << BH_Unwritten) 5387f63eb77SJaegeuk Kim #define F2FS_MAP_FLAGS (F2FS_MAP_NEW | F2FS_MAP_MAPPED |\ 5397f63eb77SJaegeuk Kim F2FS_MAP_UNWRITTEN) 540003a3e1dSJaegeuk Kim 541003a3e1dSJaegeuk Kim struct f2fs_map_blocks { 542003a3e1dSJaegeuk Kim block_t m_pblk; 543003a3e1dSJaegeuk Kim block_t m_lblk; 544003a3e1dSJaegeuk Kim unsigned int m_len; 545003a3e1dSJaegeuk Kim unsigned int m_flags; 546da85985cSChao Yu pgoff_t *m_next_pgofs; /* point next possible non-hole pgofs */ 547003a3e1dSJaegeuk Kim }; 548003a3e1dSJaegeuk Kim 549e2b4e2bcSChao Yu /* for flag in get_data_block */ 550f2220c7fSQiuyang Sun enum { 551f2220c7fSQiuyang Sun F2FS_GET_BLOCK_DEFAULT, 552f2220c7fSQiuyang Sun F2FS_GET_BLOCK_FIEMAP, 553f2220c7fSQiuyang Sun F2FS_GET_BLOCK_BMAP, 554f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_DIO, 555f2220c7fSQiuyang Sun F2FS_GET_BLOCK_PRE_AIO, 556f2220c7fSQiuyang Sun }; 557e2b4e2bcSChao Yu 558003a3e1dSJaegeuk Kim /* 55939a53e0cSJaegeuk Kim * i_advise uses FADVISE_XXX_BIT. We can add additional hints later. 56039a53e0cSJaegeuk Kim */ 56139a53e0cSJaegeuk Kim #define FADVISE_COLD_BIT 0x01 562354a3399SJaegeuk Kim #define FADVISE_LOST_PINO_BIT 0x02 563cde4de12SJaegeuk Kim #define FADVISE_ENCRYPT_BIT 0x04 564e7d55452SJaegeuk Kim #define FADVISE_ENC_NAME_BIT 0x08 56526787236SJaegeuk Kim #define FADVISE_KEEP_SIZE_BIT 0x10 56639a53e0cSJaegeuk Kim 567b5492af7SJaegeuk Kim #define file_is_cold(inode) is_file(inode, FADVISE_COLD_BIT) 568b5492af7SJaegeuk Kim #define file_wrong_pino(inode) is_file(inode, FADVISE_LOST_PINO_BIT) 569b5492af7SJaegeuk Kim #define file_set_cold(inode) set_file(inode, FADVISE_COLD_BIT) 570b5492af7SJaegeuk Kim #define file_lost_pino(inode) set_file(inode, FADVISE_LOST_PINO_BIT) 571b5492af7SJaegeuk Kim #define file_clear_cold(inode) clear_file(inode, FADVISE_COLD_BIT) 572b5492af7SJaegeuk Kim #define file_got_pino(inode) clear_file(inode, FADVISE_LOST_PINO_BIT) 573cde4de12SJaegeuk Kim #define file_is_encrypt(inode) is_file(inode, FADVISE_ENCRYPT_BIT) 574cde4de12SJaegeuk Kim #define file_set_encrypt(inode) set_file(inode, FADVISE_ENCRYPT_BIT) 575cde4de12SJaegeuk Kim #define file_clear_encrypt(inode) clear_file(inode, FADVISE_ENCRYPT_BIT) 576e7d55452SJaegeuk Kim #define file_enc_name(inode) is_file(inode, FADVISE_ENC_NAME_BIT) 577e7d55452SJaegeuk Kim #define file_set_enc_name(inode) set_file(inode, FADVISE_ENC_NAME_BIT) 57826787236SJaegeuk Kim #define file_keep_isize(inode) is_file(inode, FADVISE_KEEP_SIZE_BIT) 57926787236SJaegeuk Kim #define file_set_keep_isize(inode) set_file(inode, FADVISE_KEEP_SIZE_BIT) 580cde4de12SJaegeuk Kim 581ab9fa662SJaegeuk Kim #define DEF_DIR_LEVEL 0 582ab9fa662SJaegeuk Kim 58339a53e0cSJaegeuk Kim struct f2fs_inode_info { 58439a53e0cSJaegeuk Kim struct inode vfs_inode; /* serve a vfs inode */ 58539a53e0cSJaegeuk Kim unsigned long i_flags; /* keep an inode flags for ioctl */ 58639a53e0cSJaegeuk Kim unsigned char i_advise; /* use to give file attribute hints */ 58738431545SJaegeuk Kim unsigned char i_dir_level; /* use for dentry level for large dir */ 58839a53e0cSJaegeuk Kim unsigned int i_current_depth; /* use only in directory structure */ 5896666e6aaSJaegeuk Kim unsigned int i_pino; /* parent inode number */ 59039a53e0cSJaegeuk Kim umode_t i_acl_mode; /* keep file acl mode temporarily */ 59139a53e0cSJaegeuk Kim 59239a53e0cSJaegeuk Kim /* Use below internally in f2fs*/ 59339a53e0cSJaegeuk Kim unsigned long flags; /* use to pass per-file flags */ 594d928bfbfSJaegeuk Kim struct rw_semaphore i_sem; /* protect fi info */ 595204706c7SJaegeuk Kim atomic_t dirty_pages; /* # of dirty pages */ 59639a53e0cSJaegeuk Kim f2fs_hash_t chash; /* hash value of given file name */ 59739a53e0cSJaegeuk Kim unsigned int clevel; /* maximum level of given file name */ 59888c5c13aSJaegeuk Kim struct task_struct *task; /* lookup and create consistency */ 599b0af6d49SChao Yu struct task_struct *cp_task; /* separate cp/wb IO stats*/ 60039a53e0cSJaegeuk Kim nid_t i_xattr_nid; /* node id that contains xattrs */ 60126de9b11SJaegeuk Kim loff_t last_disk_size; /* lastly written file size */ 60288b88a66SJaegeuk Kim 6030abd675eSChao Yu #ifdef CONFIG_QUOTA 6040abd675eSChao Yu struct dquot *i_dquot[MAXQUOTAS]; 6050abd675eSChao Yu 6060abd675eSChao Yu /* quota space reservation, managed internally by quota code */ 6070abd675eSChao Yu qsize_t i_reserved_quota; 6080abd675eSChao Yu #endif 6090f18b462SJaegeuk Kim struct list_head dirty_list; /* dirty list for dirs and files */ 6100f18b462SJaegeuk Kim struct list_head gdirty_list; /* linked in global dirty list */ 61157864ae5SJaegeuk Kim struct list_head inmem_ilist; /* list for inmem inodes */ 61288b88a66SJaegeuk Kim struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 6137a10f017SJaegeuk Kim struct task_struct *inmem_task; /* store inmemory task */ 61488b88a66SJaegeuk Kim struct mutex inmem_lock; /* lock for inmemory pages */ 6153e72f721SJaegeuk Kim struct extent_tree *extent_tree; /* cached extent_tree entry */ 61682e0a5aaSChao Yu struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 6175a3a2d83SQiuyang Sun struct rw_semaphore i_mmap_sem; 61827161f13SYunlei He struct rw_semaphore i_xattr_sem; /* avoid racing between reading and changing EAs */ 619f2470371SChao Yu 6207a2af766SChao Yu int i_extra_isize; /* size of extra space located in i_addr */ 6215c57132eSChao Yu kprojid_t i_projid; /* id for project quota */ 6226afc662eSChao Yu int i_inline_xattr_size; /* inline xattr size */ 62339a53e0cSJaegeuk Kim }; 62439a53e0cSJaegeuk Kim 62539a53e0cSJaegeuk Kim static inline void get_extent_info(struct extent_info *ext, 626bd933d4fSChao Yu struct f2fs_extent *i_ext) 62739a53e0cSJaegeuk Kim { 628bd933d4fSChao Yu ext->fofs = le32_to_cpu(i_ext->fofs); 629bd933d4fSChao Yu ext->blk = le32_to_cpu(i_ext->blk); 630bd933d4fSChao Yu ext->len = le32_to_cpu(i_ext->len); 63139a53e0cSJaegeuk Kim } 63239a53e0cSJaegeuk Kim 63339a53e0cSJaegeuk Kim static inline void set_raw_extent(struct extent_info *ext, 63439a53e0cSJaegeuk Kim struct f2fs_extent *i_ext) 63539a53e0cSJaegeuk Kim { 63639a53e0cSJaegeuk Kim i_ext->fofs = cpu_to_le32(ext->fofs); 6374d0b0bd4SChao Yu i_ext->blk = cpu_to_le32(ext->blk); 63839a53e0cSJaegeuk Kim i_ext->len = cpu_to_le32(ext->len); 63939a53e0cSJaegeuk Kim } 64039a53e0cSJaegeuk Kim 641429511cdSChao Yu static inline void set_extent_info(struct extent_info *ei, unsigned int fofs, 642429511cdSChao Yu u32 blk, unsigned int len) 643429511cdSChao Yu { 644429511cdSChao Yu ei->fofs = fofs; 645429511cdSChao Yu ei->blk = blk; 646429511cdSChao Yu ei->len = len; 647429511cdSChao Yu } 648429511cdSChao Yu 649004b6862SChao Yu static inline bool __is_discard_mergeable(struct discard_info *back, 650004b6862SChao Yu struct discard_info *front) 651004b6862SChao Yu { 652004b6862SChao Yu return back->lstart + back->len == front->lstart; 653004b6862SChao Yu } 654004b6862SChao Yu 655004b6862SChao Yu static inline bool __is_discard_back_mergeable(struct discard_info *cur, 656004b6862SChao Yu struct discard_info *back) 657004b6862SChao Yu { 658004b6862SChao Yu return __is_discard_mergeable(back, cur); 659004b6862SChao Yu } 660004b6862SChao Yu 661004b6862SChao Yu static inline bool __is_discard_front_mergeable(struct discard_info *cur, 662004b6862SChao Yu struct discard_info *front) 663004b6862SChao Yu { 664004b6862SChao Yu return __is_discard_mergeable(cur, front); 665004b6862SChao Yu } 666004b6862SChao Yu 667429511cdSChao Yu static inline bool __is_extent_mergeable(struct extent_info *back, 668429511cdSChao Yu struct extent_info *front) 669429511cdSChao Yu { 670429511cdSChao Yu return (back->fofs + back->len == front->fofs && 671429511cdSChao Yu back->blk + back->len == front->blk); 672429511cdSChao Yu } 673429511cdSChao Yu 674429511cdSChao Yu static inline bool __is_back_mergeable(struct extent_info *cur, 675429511cdSChao Yu struct extent_info *back) 676429511cdSChao Yu { 677429511cdSChao Yu return __is_extent_mergeable(back, cur); 678429511cdSChao Yu } 679429511cdSChao Yu 680429511cdSChao Yu static inline bool __is_front_mergeable(struct extent_info *cur, 681429511cdSChao Yu struct extent_info *front) 682429511cdSChao Yu { 683429511cdSChao Yu return __is_extent_mergeable(cur, front); 684429511cdSChao Yu } 685429511cdSChao Yu 686cac5a3d8SDongOh Shin extern void f2fs_mark_inode_dirty_sync(struct inode *inode, bool sync); 687205b9822SJaegeuk Kim static inline void __try_update_largest_extent(struct inode *inode, 688205b9822SJaegeuk Kim struct extent_tree *et, struct extent_node *en) 6894abd3f5aSChao Yu { 690205b9822SJaegeuk Kim if (en->ei.len > et->largest.len) { 6914abd3f5aSChao Yu et->largest = en->ei; 6927c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 693205b9822SJaegeuk Kim } 6944abd3f5aSChao Yu } 6954abd3f5aSChao Yu 6969a4ffdf5SChao Yu /* 6979a4ffdf5SChao Yu * For free nid management 6989a4ffdf5SChao Yu */ 6999a4ffdf5SChao Yu enum nid_state { 7009a4ffdf5SChao Yu FREE_NID, /* newly added to free nid list */ 7019a4ffdf5SChao Yu PREALLOC_NID, /* it is preallocated */ 7029a4ffdf5SChao Yu MAX_NID_STATE, 703b8559dc2SChao Yu }; 704b8559dc2SChao Yu 70539a53e0cSJaegeuk Kim struct f2fs_nm_info { 70639a53e0cSJaegeuk Kim block_t nat_blkaddr; /* base disk address of NAT */ 70739a53e0cSJaegeuk Kim nid_t max_nid; /* maximum possible node ids */ 70804d47e67SChao Yu nid_t available_nids; /* # of available node ids */ 70939a53e0cSJaegeuk Kim nid_t next_scan_nid; /* the next nid to be scanned */ 710cdfc41c1SJaegeuk Kim unsigned int ram_thresh; /* control the memory footprint */ 711ea1a29a0SChao Yu unsigned int ra_nid_pages; /* # of nid pages to be readaheaded */ 7122304cb0cSChao Yu unsigned int dirty_nats_ratio; /* control dirty nats ratio threshold */ 71339a53e0cSJaegeuk Kim 71439a53e0cSJaegeuk Kim /* NAT cache management */ 71539a53e0cSJaegeuk Kim struct radix_tree_root nat_root;/* root of the nat entry cache */ 716309cc2b6SJaegeuk Kim struct radix_tree_root nat_set_root;/* root of the nat set cache */ 717b873b798SJaegeuk Kim struct rw_semaphore nat_tree_lock; /* protect nat_tree_lock */ 71839a53e0cSJaegeuk Kim struct list_head nat_entries; /* cached nat entry list (clean) */ 719309cc2b6SJaegeuk Kim unsigned int nat_cnt; /* the # of cached nat entries */ 720aec71382SChao Yu unsigned int dirty_nat_cnt; /* total num of nat entries in set */ 72122ad0b6aSJaegeuk Kim unsigned int nat_blocks; /* # of nat blocks */ 72239a53e0cSJaegeuk Kim 72339a53e0cSJaegeuk Kim /* free node ids management */ 7248a7ed66aSJaegeuk Kim struct radix_tree_root free_nid_root;/* root of the free_nid cache */ 7259a4ffdf5SChao Yu struct list_head free_nid_list; /* list for free nids excluding preallocated nids */ 7269a4ffdf5SChao Yu unsigned int nid_cnt[MAX_NID_STATE]; /* the number of free node id */ 727b8559dc2SChao Yu spinlock_t nid_list_lock; /* protect nid lists ops */ 72839a53e0cSJaegeuk Kim struct mutex build_lock; /* lock for build free nids */ 7294ac91242SChao Yu unsigned char (*free_nid_bitmap)[NAT_ENTRY_BITMAP_SIZE]; 7304ac91242SChao Yu unsigned char *nat_block_bitmap; 731586d1492SChao Yu unsigned short *free_nid_count; /* free nid count of NAT block */ 73239a53e0cSJaegeuk Kim 73339a53e0cSJaegeuk Kim /* for checkpoint */ 73439a53e0cSJaegeuk Kim char *nat_bitmap; /* NAT bitmap pointer */ 73522ad0b6aSJaegeuk Kim 73622ad0b6aSJaegeuk Kim unsigned int nat_bits_blocks; /* # of nat bits blocks */ 73722ad0b6aSJaegeuk Kim unsigned char *nat_bits; /* NAT bits blocks */ 73822ad0b6aSJaegeuk Kim unsigned char *full_nat_bits; /* full NAT pages */ 73922ad0b6aSJaegeuk Kim unsigned char *empty_nat_bits; /* empty NAT pages */ 740599a09b2SChao Yu #ifdef CONFIG_F2FS_CHECK_FS 741599a09b2SChao Yu char *nat_bitmap_mir; /* NAT bitmap mirror */ 742599a09b2SChao Yu #endif 74339a53e0cSJaegeuk Kim int bitmap_size; /* bitmap size */ 74439a53e0cSJaegeuk Kim }; 74539a53e0cSJaegeuk Kim 74639a53e0cSJaegeuk Kim /* 74739a53e0cSJaegeuk Kim * this structure is used as one of function parameters. 74839a53e0cSJaegeuk Kim * all the information are dedicated to a given direct node block determined 74939a53e0cSJaegeuk Kim * by the data offset in a file. 75039a53e0cSJaegeuk Kim */ 75139a53e0cSJaegeuk Kim struct dnode_of_data { 75239a53e0cSJaegeuk Kim struct inode *inode; /* vfs inode pointer */ 75339a53e0cSJaegeuk Kim struct page *inode_page; /* its inode page, NULL is possible */ 75439a53e0cSJaegeuk Kim struct page *node_page; /* cached direct node page */ 75539a53e0cSJaegeuk Kim nid_t nid; /* node id of the direct node block */ 75639a53e0cSJaegeuk Kim unsigned int ofs_in_node; /* data offset in the node page */ 75739a53e0cSJaegeuk Kim bool inode_page_locked; /* inode page is locked or not */ 75893bae099SJaegeuk Kim bool node_changed; /* is node block changed */ 7593cf45747SChao Yu char cur_level; /* level of hole node page */ 7603cf45747SChao Yu char max_level; /* level of current page located */ 76139a53e0cSJaegeuk Kim block_t data_blkaddr; /* block address of the node block */ 76239a53e0cSJaegeuk Kim }; 76339a53e0cSJaegeuk Kim 76439a53e0cSJaegeuk Kim static inline void set_new_dnode(struct dnode_of_data *dn, struct inode *inode, 76539a53e0cSJaegeuk Kim struct page *ipage, struct page *npage, nid_t nid) 76639a53e0cSJaegeuk Kim { 767d66d1f76SJaegeuk Kim memset(dn, 0, sizeof(*dn)); 76839a53e0cSJaegeuk Kim dn->inode = inode; 76939a53e0cSJaegeuk Kim dn->inode_page = ipage; 77039a53e0cSJaegeuk Kim dn->node_page = npage; 77139a53e0cSJaegeuk Kim dn->nid = nid; 77239a53e0cSJaegeuk Kim } 77339a53e0cSJaegeuk Kim 77439a53e0cSJaegeuk Kim /* 77539a53e0cSJaegeuk Kim * For SIT manager 77639a53e0cSJaegeuk Kim * 77739a53e0cSJaegeuk Kim * By default, there are 6 active log areas across the whole main area. 77839a53e0cSJaegeuk Kim * When considering hot and cold data separation to reduce cleaning overhead, 77939a53e0cSJaegeuk Kim * we split 3 for data logs and 3 for node logs as hot, warm, and cold types, 78039a53e0cSJaegeuk Kim * respectively. 78139a53e0cSJaegeuk Kim * In the current design, you should not change the numbers intentionally. 78239a53e0cSJaegeuk Kim * Instead, as a mount option such as active_logs=x, you can use 2, 4, and 6 78339a53e0cSJaegeuk Kim * logs individually according to the underlying devices. (default: 6) 78439a53e0cSJaegeuk Kim * Just in case, on-disk layout covers maximum 16 logs that consist of 8 for 78539a53e0cSJaegeuk Kim * data and 8 for node logs. 78639a53e0cSJaegeuk Kim */ 78739a53e0cSJaegeuk Kim #define NR_CURSEG_DATA_TYPE (3) 78839a53e0cSJaegeuk Kim #define NR_CURSEG_NODE_TYPE (3) 78939a53e0cSJaegeuk Kim #define NR_CURSEG_TYPE (NR_CURSEG_DATA_TYPE + NR_CURSEG_NODE_TYPE) 79039a53e0cSJaegeuk Kim 79139a53e0cSJaegeuk Kim enum { 79239a53e0cSJaegeuk Kim CURSEG_HOT_DATA = 0, /* directory entry blocks */ 79339a53e0cSJaegeuk Kim CURSEG_WARM_DATA, /* data blocks */ 79439a53e0cSJaegeuk Kim CURSEG_COLD_DATA, /* multimedia or GCed data blocks */ 79539a53e0cSJaegeuk Kim CURSEG_HOT_NODE, /* direct node blocks of directory files */ 79639a53e0cSJaegeuk Kim CURSEG_WARM_NODE, /* direct node blocks of normal files */ 79739a53e0cSJaegeuk Kim CURSEG_COLD_NODE, /* indirect node blocks */ 79838aa0889SJaegeuk Kim NO_CHECK_TYPE, 79939a53e0cSJaegeuk Kim }; 80039a53e0cSJaegeuk Kim 8016b4afdd7SJaegeuk Kim struct flush_cmd { 8026b4afdd7SJaegeuk Kim struct completion wait; 803721bd4d5SGu Zheng struct llist_node llnode; 80439d787beSChao Yu nid_t ino; 8056b4afdd7SJaegeuk Kim int ret; 8066b4afdd7SJaegeuk Kim }; 8076b4afdd7SJaegeuk Kim 808a688b9d9SGu Zheng struct flush_cmd_control { 809a688b9d9SGu Zheng struct task_struct *f2fs_issue_flush; /* flush thread */ 810a688b9d9SGu Zheng wait_queue_head_t flush_wait_queue; /* waiting queue for wake-up */ 8118b8dd65fSChao Yu atomic_t issued_flush; /* # of issued flushes */ 8128b8dd65fSChao Yu atomic_t issing_flush; /* # of issing flushes */ 813721bd4d5SGu Zheng struct llist_head issue_list; /* list for command issue */ 814721bd4d5SGu Zheng struct llist_node *dispatch_list; /* list for command dispatch */ 815a688b9d9SGu Zheng }; 816a688b9d9SGu Zheng 81739a53e0cSJaegeuk Kim struct f2fs_sm_info { 81839a53e0cSJaegeuk Kim struct sit_info *sit_info; /* whole segment information */ 81939a53e0cSJaegeuk Kim struct free_segmap_info *free_info; /* free segment information */ 82039a53e0cSJaegeuk Kim struct dirty_seglist_info *dirty_info; /* dirty segment information */ 82139a53e0cSJaegeuk Kim struct curseg_info *curseg_array; /* active segment information */ 82239a53e0cSJaegeuk Kim 8232b60311dSChao Yu struct rw_semaphore curseg_lock; /* for preventing curseg change */ 8242b60311dSChao Yu 82539a53e0cSJaegeuk Kim block_t seg0_blkaddr; /* block address of 0'th segment */ 82639a53e0cSJaegeuk Kim block_t main_blkaddr; /* start block address of main area */ 82739a53e0cSJaegeuk Kim block_t ssa_blkaddr; /* start block address of SSA area */ 82839a53e0cSJaegeuk Kim 82939a53e0cSJaegeuk Kim unsigned int segment_count; /* total # of segments */ 83039a53e0cSJaegeuk Kim unsigned int main_segments; /* # of segments in main area */ 83139a53e0cSJaegeuk Kim unsigned int reserved_segments; /* # of reserved segments */ 83239a53e0cSJaegeuk Kim unsigned int ovp_segments; /* # of overprovision segments */ 83381eb8d6eSJaegeuk Kim 83481eb8d6eSJaegeuk Kim /* a threshold to reclaim prefree segments */ 83581eb8d6eSJaegeuk Kim unsigned int rec_prefree_segments; 8367fd9e544SJaegeuk Kim 837bba681cbSJaegeuk Kim /* for batched trimming */ 838bba681cbSJaegeuk Kim unsigned int trim_sections; /* # of sections to trim */ 839bba681cbSJaegeuk Kim 840184a5cd2SChao Yu struct list_head sit_entry_set; /* sit entry set list */ 841184a5cd2SChao Yu 842216fbd64SJaegeuk Kim unsigned int ipu_policy; /* in-place-update policy */ 843216fbd64SJaegeuk Kim unsigned int min_ipu_util; /* in-place-update threshold */ 844c1ce1b02SJaegeuk Kim unsigned int min_fsync_blocks; /* threshold for fsync */ 845ef095d19SJaegeuk Kim unsigned int min_hot_blocks; /* threshold for hot block allocation */ 846a2a12b67SChao Yu unsigned int min_ssr_sections; /* threshold to trigger SSR allocation */ 8476b4afdd7SJaegeuk Kim 8486b4afdd7SJaegeuk Kim /* for flush command control */ 849b01a9201SJaegeuk Kim struct flush_cmd_control *fcc_info; 850a688b9d9SGu Zheng 8510b54fb84SJaegeuk Kim /* for discard command control */ 8520b54fb84SJaegeuk Kim struct discard_cmd_control *dcc_info; 85339a53e0cSJaegeuk Kim }; 85439a53e0cSJaegeuk Kim 85539a53e0cSJaegeuk Kim /* 85639a53e0cSJaegeuk Kim * For superblock 85739a53e0cSJaegeuk Kim */ 85839a53e0cSJaegeuk Kim /* 85939a53e0cSJaegeuk Kim * COUNT_TYPE for monitoring 86039a53e0cSJaegeuk Kim * 86139a53e0cSJaegeuk Kim * f2fs monitors the number of several block types such as on-writeback, 86239a53e0cSJaegeuk Kim * dirty dentry blocks, dirty node blocks, and dirty meta blocks. 86339a53e0cSJaegeuk Kim */ 86436951b38SChao Yu #define WB_DATA_TYPE(p) (__is_cp_guaranteed(p) ? F2FS_WB_CP_DATA : F2FS_WB_DATA) 86539a53e0cSJaegeuk Kim enum count_type { 86639a53e0cSJaegeuk Kim F2FS_DIRTY_DENTS, 867c227f912SChao Yu F2FS_DIRTY_DATA, 868*2c8a4a28SJaegeuk Kim F2FS_DIRTY_QDATA, 86939a53e0cSJaegeuk Kim F2FS_DIRTY_NODES, 87039a53e0cSJaegeuk Kim F2FS_DIRTY_META, 8718dcf2ff7SJaegeuk Kim F2FS_INMEM_PAGES, 8720f18b462SJaegeuk Kim F2FS_DIRTY_IMETA, 87336951b38SChao Yu F2FS_WB_CP_DATA, 87436951b38SChao Yu F2FS_WB_DATA, 87539a53e0cSJaegeuk Kim NR_COUNT_TYPE, 87639a53e0cSJaegeuk Kim }; 87739a53e0cSJaegeuk Kim 87839a53e0cSJaegeuk Kim /* 879e1c42045Sarter97 * The below are the page types of bios used in submit_bio(). 88039a53e0cSJaegeuk Kim * The available types are: 88139a53e0cSJaegeuk Kim * DATA User data pages. It operates as async mode. 88239a53e0cSJaegeuk Kim * NODE Node pages. It operates as async mode. 88339a53e0cSJaegeuk Kim * META FS metadata pages such as SIT, NAT, CP. 88439a53e0cSJaegeuk Kim * NR_PAGE_TYPE The number of page types. 88539a53e0cSJaegeuk Kim * META_FLUSH Make sure the previous pages are written 88639a53e0cSJaegeuk Kim * with waiting the bio's completion 88739a53e0cSJaegeuk Kim * ... Only can be used with META. 88839a53e0cSJaegeuk Kim */ 8897d5e5109SJaegeuk Kim #define PAGE_TYPE_OF_BIO(type) ((type) > META ? META : (type)) 89039a53e0cSJaegeuk Kim enum page_type { 89139a53e0cSJaegeuk Kim DATA, 89239a53e0cSJaegeuk Kim NODE, 89339a53e0cSJaegeuk Kim META, 89439a53e0cSJaegeuk Kim NR_PAGE_TYPE, 89539a53e0cSJaegeuk Kim META_FLUSH, 8968ce67cb0SJaegeuk Kim INMEM, /* the below types are used by tracepoints only. */ 8978ce67cb0SJaegeuk Kim INMEM_DROP, 8988c242db9SJaegeuk Kim INMEM_INVALIDATE, 89928bc106bSChao Yu INMEM_REVOKE, 9008ce67cb0SJaegeuk Kim IPU, 9018ce67cb0SJaegeuk Kim OPU, 90239a53e0cSJaegeuk Kim }; 90339a53e0cSJaegeuk Kim 904a912b54dSJaegeuk Kim enum temp_type { 905a912b54dSJaegeuk Kim HOT = 0, /* must be zero for meta bio */ 906a912b54dSJaegeuk Kim WARM, 907a912b54dSJaegeuk Kim COLD, 908a912b54dSJaegeuk Kim NR_TEMP_TYPE, 909a912b54dSJaegeuk Kim }; 910a912b54dSJaegeuk Kim 911cc15620bSJaegeuk Kim enum need_lock_type { 912cc15620bSJaegeuk Kim LOCK_REQ = 0, 913cc15620bSJaegeuk Kim LOCK_DONE, 914cc15620bSJaegeuk Kim LOCK_RETRY, 915cc15620bSJaegeuk Kim }; 916cc15620bSJaegeuk Kim 917a5fd5050SChao Yu enum cp_reason_type { 918a5fd5050SChao Yu CP_NO_NEEDED, 919a5fd5050SChao Yu CP_NON_REGULAR, 920a5fd5050SChao Yu CP_HARDLINK, 921a5fd5050SChao Yu CP_SB_NEED_CP, 922a5fd5050SChao Yu CP_WRONG_PINO, 923a5fd5050SChao Yu CP_NO_SPC_ROLL, 924a5fd5050SChao Yu CP_NODE_NEED_CP, 925a5fd5050SChao Yu CP_FASTBOOT_MODE, 926a5fd5050SChao Yu CP_SPEC_LOG_NUM, 927a5fd5050SChao Yu }; 928a5fd5050SChao Yu 929b0af6d49SChao Yu enum iostat_type { 930b0af6d49SChao Yu APP_DIRECT_IO, /* app direct IOs */ 931b0af6d49SChao Yu APP_BUFFERED_IO, /* app buffered IOs */ 932b0af6d49SChao Yu APP_WRITE_IO, /* app write IOs */ 933b0af6d49SChao Yu APP_MAPPED_IO, /* app mapped IOs */ 934b0af6d49SChao Yu FS_DATA_IO, /* data IOs from kworker/fsync/reclaimer */ 935b0af6d49SChao Yu FS_NODE_IO, /* node IOs from kworker/fsync/reclaimer */ 936b0af6d49SChao Yu FS_META_IO, /* meta IOs from kworker/reclaimer */ 937b0af6d49SChao Yu FS_GC_DATA_IO, /* data IOs from forground gc */ 938b0af6d49SChao Yu FS_GC_NODE_IO, /* node IOs from forground gc */ 939b0af6d49SChao Yu FS_CP_DATA_IO, /* data IOs from checkpoint */ 940b0af6d49SChao Yu FS_CP_NODE_IO, /* node IOs from checkpoint */ 941b0af6d49SChao Yu FS_CP_META_IO, /* meta IOs from checkpoint */ 942b0af6d49SChao Yu FS_DISCARD, /* discard */ 943b0af6d49SChao Yu NR_IO_TYPE, 944b0af6d49SChao Yu }; 945b0af6d49SChao Yu 946458e6197SJaegeuk Kim struct f2fs_io_info { 94705ca3632SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 94839d787beSChao Yu nid_t ino; /* inode number */ 949458e6197SJaegeuk Kim enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 950a912b54dSJaegeuk Kim enum temp_type temp; /* contains HOT/WARM/COLD */ 95104d328deSMike Christie int op; /* contains REQ_OP_ */ 952ef295ecfSChristoph Hellwig int op_flags; /* req_flag_bits */ 9537a9d7548SChao Yu block_t new_blkaddr; /* new block address to be written */ 95428bc106bSChao Yu block_t old_blkaddr; /* old block address before Cow */ 95505ca3632SJaegeuk Kim struct page *page; /* page to be written */ 9564375a336SJaegeuk Kim struct page *encrypted_page; /* encrypted page */ 957fb830fc5SChao Yu struct list_head list; /* serialize IOs */ 958d68f735bSJaegeuk Kim bool submitted; /* indicate IO submission */ 959cc15620bSJaegeuk Kim int need_lock; /* indicate we need to lock cp_rwsem */ 960fb830fc5SChao Yu bool in_list; /* indicate fio is in io_list */ 961b0af6d49SChao Yu enum iostat_type io_type; /* io type */ 962458e6197SJaegeuk Kim }; 963458e6197SJaegeuk Kim 96468afcf2dSTomohiro Kusumi #define is_read_io(rw) ((rw) == READ) 9651ff7bd3bSJaegeuk Kim struct f2fs_bio_info { 966458e6197SJaegeuk Kim struct f2fs_sb_info *sbi; /* f2fs superblock */ 9671ff7bd3bSJaegeuk Kim struct bio *bio; /* bios to merge */ 9681ff7bd3bSJaegeuk Kim sector_t last_block_in_bio; /* last block number */ 969458e6197SJaegeuk Kim struct f2fs_io_info fio; /* store buffered io info. */ 970df0f8dc0SChao Yu struct rw_semaphore io_rwsem; /* blocking op for bio */ 971fb830fc5SChao Yu spinlock_t io_lock; /* serialize DATA/NODE IOs */ 972fb830fc5SChao Yu struct list_head io_list; /* track fios */ 9731ff7bd3bSJaegeuk Kim }; 9741ff7bd3bSJaegeuk Kim 9753c62be17SJaegeuk Kim #define FDEV(i) (sbi->devs[i]) 9763c62be17SJaegeuk Kim #define RDEV(i) (raw_super->devs[i]) 9773c62be17SJaegeuk Kim struct f2fs_dev_info { 9783c62be17SJaegeuk Kim struct block_device *bdev; 9793c62be17SJaegeuk Kim char path[MAX_PATH_LEN]; 9803c62be17SJaegeuk Kim unsigned int total_segments; 9813c62be17SJaegeuk Kim block_t start_blk; 9823c62be17SJaegeuk Kim block_t end_blk; 9833c62be17SJaegeuk Kim #ifdef CONFIG_BLK_DEV_ZONED 9843c62be17SJaegeuk Kim unsigned int nr_blkz; /* Total number of zones */ 9853c62be17SJaegeuk Kim u8 *blkz_type; /* Array of zones type */ 9863c62be17SJaegeuk Kim #endif 9873c62be17SJaegeuk Kim }; 9883c62be17SJaegeuk Kim 989c227f912SChao Yu enum inode_type { 990c227f912SChao Yu DIR_INODE, /* for dirty dir inode */ 991c227f912SChao Yu FILE_INODE, /* for dirty regular/symlink inode */ 9920f18b462SJaegeuk Kim DIRTY_META, /* for all dirtied inode metadata */ 99357864ae5SJaegeuk Kim ATOMIC_FILE, /* for all atomic files */ 994c227f912SChao Yu NR_INODE_TYPE, 995c227f912SChao Yu }; 996c227f912SChao Yu 99767298804SChao Yu /* for inner inode cache management */ 99867298804SChao Yu struct inode_management { 99967298804SChao Yu struct radix_tree_root ino_root; /* ino entry array */ 100067298804SChao Yu spinlock_t ino_lock; /* for ino entry lock */ 100167298804SChao Yu struct list_head ino_list; /* inode list head */ 100267298804SChao Yu unsigned long ino_num; /* number of entries */ 100367298804SChao Yu }; 100467298804SChao Yu 1005caf0047eSChao Yu /* For s_flag in struct f2fs_sb_info */ 1006caf0047eSChao Yu enum { 1007caf0047eSChao Yu SBI_IS_DIRTY, /* dirty flag for checkpoint */ 1008caf0047eSChao Yu SBI_IS_CLOSE, /* specify unmounting */ 1009caf0047eSChao Yu SBI_NEED_FSCK, /* need fsck.f2fs to fix */ 1010caf0047eSChao Yu SBI_POR_DOING, /* recovery is doing or not */ 1011df728b0fSJaegeuk Kim SBI_NEED_SB_WRITE, /* need to recover superblock */ 1012bbf156f7SJaegeuk Kim SBI_NEED_CP, /* need to checkpoint */ 1013caf0047eSChao Yu }; 1014caf0047eSChao Yu 10156beceb54SJaegeuk Kim enum { 10166beceb54SJaegeuk Kim CP_TIME, 1017d0239e1bSJaegeuk Kim REQ_TIME, 10186beceb54SJaegeuk Kim MAX_TIME, 10196beceb54SJaegeuk Kim }; 10206beceb54SJaegeuk Kim 102139a53e0cSJaegeuk Kim struct f2fs_sb_info { 102239a53e0cSJaegeuk Kim struct super_block *sb; /* pointer to VFS super block */ 10235e176d54SJaegeuk Kim struct proc_dir_entry *s_proc; /* proc entry */ 102439a53e0cSJaegeuk Kim struct f2fs_super_block *raw_super; /* raw super block pointer */ 1025e8240f65SChao Yu int valid_super_block; /* valid super block no */ 1026fadb2fb8SChao Yu unsigned long s_flag; /* flags for sbi */ 102739a53e0cSJaegeuk Kim 1028178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 1029178053e2SDamien Le Moal unsigned int blocks_per_blkz; /* F2FS blocks per zone */ 1030178053e2SDamien Le Moal unsigned int log_blocks_per_blkz; /* log2 F2FS blocks per zone */ 1031178053e2SDamien Le Moal #endif 1032178053e2SDamien Le Moal 103339a53e0cSJaegeuk Kim /* for node-related operations */ 103439a53e0cSJaegeuk Kim struct f2fs_nm_info *nm_info; /* node manager */ 103539a53e0cSJaegeuk Kim struct inode *node_inode; /* cache node blocks */ 103639a53e0cSJaegeuk Kim 103739a53e0cSJaegeuk Kim /* for segment-related operations */ 103839a53e0cSJaegeuk Kim struct f2fs_sm_info *sm_info; /* segment manager */ 10391ff7bd3bSJaegeuk Kim 10401ff7bd3bSJaegeuk Kim /* for bio operations */ 1041a912b54dSJaegeuk Kim struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */ 1042e41e6d75SChao Yu struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE]; 1043e41e6d75SChao Yu /* bio ordering for NODE/DATA */ 10440a595ebaSJaegeuk Kim int write_io_size_bits; /* Write IO size bits */ 10450a595ebaSJaegeuk Kim mempool_t *write_io_dummy; /* Dummy pages */ 104639a53e0cSJaegeuk Kim 104739a53e0cSJaegeuk Kim /* for checkpoint */ 104839a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt; /* raw checkpoint pointer */ 10498508e44aSJaegeuk Kim int cur_cp_pack; /* remain current cp pack */ 1050aaec2b1dSChao Yu spinlock_t cp_lock; /* for flag in ckpt */ 105139a53e0cSJaegeuk Kim struct inode *meta_inode; /* cache meta blocks */ 105239936837SJaegeuk Kim struct mutex cp_mutex; /* checkpoint procedure lock */ 1053b873b798SJaegeuk Kim struct rw_semaphore cp_rwsem; /* blocking FS operations */ 1054b3582c68SChao Yu struct rw_semaphore node_write; /* locking node writes */ 105559c9081bSYunlei He struct rw_semaphore node_change; /* locking node change */ 1056fb51b5efSChangman Lee wait_queue_head_t cp_wait; 10576beceb54SJaegeuk Kim unsigned long last_time[MAX_TIME]; /* to store time in jiffies */ 10586beceb54SJaegeuk Kim long interval_time[MAX_TIME]; /* to store thresholds */ 105939a53e0cSJaegeuk Kim 106067298804SChao Yu struct inode_management im[MAX_INO_ENTRY]; /* manage inode cache */ 10616451e041SJaegeuk Kim 10626451e041SJaegeuk Kim /* for orphan inode, use 0'th array */ 10630d47c1adSGu Zheng unsigned int max_orphans; /* max orphan inodes */ 106439a53e0cSJaegeuk Kim 1065c227f912SChao Yu /* for inode management */ 1066c227f912SChao Yu struct list_head inode_list[NR_INODE_TYPE]; /* dirty inode list */ 1067c227f912SChao Yu spinlock_t inode_lock[NR_INODE_TYPE]; /* for dirty inode list lock */ 106839a53e0cSJaegeuk Kim 106913054c54SChao Yu /* for extent tree cache */ 107013054c54SChao Yu struct radix_tree_root extent_tree_root;/* cache extent cache entries */ 10715e8256acSYunlei He struct mutex extent_tree_lock; /* locking extent radix tree */ 107213054c54SChao Yu struct list_head extent_list; /* lru list for shrinker */ 107313054c54SChao Yu spinlock_t extent_lock; /* locking extent lru list */ 10747441ccefSJaegeuk Kim atomic_t total_ext_tree; /* extent tree count */ 1075137d09f0SJaegeuk Kim struct list_head zombie_list; /* extent zombie tree list */ 107674fd8d99SJaegeuk Kim atomic_t total_zombie_tree; /* extent zombie tree count */ 107713054c54SChao Yu atomic_t total_ext_node; /* extent info count */ 107813054c54SChao Yu 107939a53e0cSJaegeuk Kim /* basic filesystem units */ 108039a53e0cSJaegeuk Kim unsigned int log_sectors_per_block; /* log2 sectors per block */ 108139a53e0cSJaegeuk Kim unsigned int log_blocksize; /* log2 block size */ 108239a53e0cSJaegeuk Kim unsigned int blocksize; /* block size */ 108339a53e0cSJaegeuk Kim unsigned int root_ino_num; /* root inode number*/ 108439a53e0cSJaegeuk Kim unsigned int node_ino_num; /* node inode number*/ 108539a53e0cSJaegeuk Kim unsigned int meta_ino_num; /* meta inode number*/ 108639a53e0cSJaegeuk Kim unsigned int log_blocks_per_seg; /* log2 blocks per segment */ 108739a53e0cSJaegeuk Kim unsigned int blocks_per_seg; /* blocks per segment */ 108839a53e0cSJaegeuk Kim unsigned int segs_per_sec; /* segments per section */ 108939a53e0cSJaegeuk Kim unsigned int secs_per_zone; /* sections per zone */ 109039a53e0cSJaegeuk Kim unsigned int total_sections; /* total section count */ 109139a53e0cSJaegeuk Kim unsigned int total_node_count; /* total node block count */ 109239a53e0cSJaegeuk Kim unsigned int total_valid_node_count; /* valid node block count */ 1093e0afc4d6SChao Yu loff_t max_file_blocks; /* max block index of file */ 109439a53e0cSJaegeuk Kim int active_logs; /* # of active logs */ 1095ab9fa662SJaegeuk Kim int dir_level; /* directory level */ 10966afc662eSChao Yu int inline_xattr_size; /* inline xattr size */ 1097a2a12b67SChao Yu unsigned int trigger_ssr_threshold; /* threshold to trigger ssr */ 109839a53e0cSJaegeuk Kim 109939a53e0cSJaegeuk Kim block_t user_block_count; /* # of user blocks */ 110039a53e0cSJaegeuk Kim block_t total_valid_block_count; /* # of valid blocks */ 1101a66cdd98SJaegeuk Kim block_t discard_blks; /* discard command candidats */ 110239a53e0cSJaegeuk Kim block_t last_valid_block_count; /* for recovery */ 1103daeb433eSChao Yu block_t reserved_blocks; /* configurable reserved blocks */ 110480d42145SYunlong Song block_t current_reserved_blocks; /* current reserved blocks */ 1105daeb433eSChao Yu 110639a53e0cSJaegeuk Kim u32 s_next_generation; /* for NFS support */ 1107523be8a6SJaegeuk Kim 1108523be8a6SJaegeuk Kim /* # of pages, see count_type */ 110935782b23SJaegeuk Kim atomic_t nr_pages[NR_COUNT_TYPE]; 111041382ec4SJaegeuk Kim /* # of allocated blocks */ 111141382ec4SJaegeuk Kim struct percpu_counter alloc_valid_block_count; 111239a53e0cSJaegeuk Kim 1113687de7f1SJaegeuk Kim /* writeback control */ 1114687de7f1SJaegeuk Kim atomic_t wb_sync_req; /* count # of WB_SYNC threads */ 1115687de7f1SJaegeuk Kim 1116513c5f37SJaegeuk Kim /* valid inode count */ 1117513c5f37SJaegeuk Kim struct percpu_counter total_valid_inode_count; 1118513c5f37SJaegeuk Kim 111939a53e0cSJaegeuk Kim struct f2fs_mount_info mount_opt; /* mount options */ 112039a53e0cSJaegeuk Kim 112139a53e0cSJaegeuk Kim /* for cleaning operations */ 112239a53e0cSJaegeuk Kim struct mutex gc_mutex; /* mutex for GC */ 112339a53e0cSJaegeuk Kim struct f2fs_gc_kthread *gc_thread; /* GC thread */ 11245ec4e49fSJaegeuk Kim unsigned int cur_victim_sec; /* current victim section num */ 112539a53e0cSJaegeuk Kim 1126e93b9865SHou Pengyang /* threshold for converting bg victims for fg */ 1127e93b9865SHou Pengyang u64 fggc_threshold; 1128e93b9865SHou Pengyang 1129b1c57c1cSJaegeuk Kim /* maximum # of trials to find a victim segment for SSR and GC */ 1130b1c57c1cSJaegeuk Kim unsigned int max_victim_search; 1131b1c57c1cSJaegeuk Kim 113239a53e0cSJaegeuk Kim /* 113339a53e0cSJaegeuk Kim * for stat information. 113439a53e0cSJaegeuk Kim * one is for the LFS mode, and the other is for the SSR mode. 113539a53e0cSJaegeuk Kim */ 113635b09d82SNamjae Jeon #ifdef CONFIG_F2FS_STAT_FS 113739a53e0cSJaegeuk Kim struct f2fs_stat_info *stat_info; /* FS status information */ 113839a53e0cSJaegeuk Kim unsigned int segment_count[2]; /* # of allocated segments */ 113939a53e0cSJaegeuk Kim unsigned int block_count[2]; /* # of allocated blocks */ 1140b9a2c252SChangman Lee atomic_t inplace_count; /* # of inplace update */ 11415b7ee374SChao Yu atomic64_t total_hit_ext; /* # of lookup extent cache */ 11425b7ee374SChao Yu atomic64_t read_hit_rbtree; /* # of hit rbtree extent node */ 11435b7ee374SChao Yu atomic64_t read_hit_largest; /* # of hit largest extent node */ 11445b7ee374SChao Yu atomic64_t read_hit_cached; /* # of hit cached extent node */ 1145d5e8f6c9SChao Yu atomic_t inline_xattr; /* # of inline_xattr inodes */ 114603e14d52SChao Yu atomic_t inline_inode; /* # of inline_data inodes */ 114703e14d52SChao Yu atomic_t inline_dir; /* # of inline_dentry inodes */ 114826a28a0cSJaegeuk Kim atomic_t aw_cnt; /* # of atomic writes */ 1149648d50baSChao Yu atomic_t vw_cnt; /* # of volatile writes */ 115026a28a0cSJaegeuk Kim atomic_t max_aw_cnt; /* max # of atomic writes */ 1151648d50baSChao Yu atomic_t max_vw_cnt; /* max # of volatile writes */ 115239a53e0cSJaegeuk Kim int bg_gc; /* background gc calls */ 115333fbd510SChao Yu unsigned int ndirty_inode[NR_INODE_TYPE]; /* # of dirty inodes */ 115435b09d82SNamjae Jeon #endif 115539a53e0cSJaegeuk Kim spinlock_t stat_lock; /* lock for stat operations */ 1156b59d0baeSNamjae Jeon 1157b0af6d49SChao Yu /* For app/fs IO statistics */ 1158b0af6d49SChao Yu spinlock_t iostat_lock; 1159b0af6d49SChao Yu unsigned long long write_iostat[NR_IO_TYPE]; 1160b0af6d49SChao Yu bool iostat_enable; 1161b0af6d49SChao Yu 1162b59d0baeSNamjae Jeon /* For sysfs suppport */ 1163b59d0baeSNamjae Jeon struct kobject s_kobj; 1164b59d0baeSNamjae Jeon struct completion s_kobj_unregister; 11652658e50dSJaegeuk Kim 11662658e50dSJaegeuk Kim /* For shrinker support */ 11672658e50dSJaegeuk Kim struct list_head s_list; 11683c62be17SJaegeuk Kim int s_ndevs; /* number of devices */ 11693c62be17SJaegeuk Kim struct f2fs_dev_info *devs; /* for device list */ 11701228b482SChao Yu unsigned int dirty_device; /* for checkpoint data flush */ 11711228b482SChao Yu spinlock_t dev_lock; /* protect dirty_device */ 11722658e50dSJaegeuk Kim struct mutex umount_mutex; 11732658e50dSJaegeuk Kim unsigned int shrinker_run_no; 11748f1dbbbbSShuoran Liu 11758f1dbbbbSShuoran Liu /* For write statistics */ 11768f1dbbbbSShuoran Liu u64 sectors_written_start; 11778f1dbbbbSShuoran Liu u64 kbytes_written; 117843b6573bSKeith Mok 117943b6573bSKeith Mok /* Reference to checksum algorithm driver via cryptoapi */ 118043b6573bSKeith Mok struct crypto_shash *s_chksum_driver; 11811ecc0c5cSChao Yu 1182704956ecSChao Yu /* Precomputed FS UUID checksum for seeding other checksums */ 1183704956ecSChao Yu __u32 s_chksum_seed; 1184704956ecSChao Yu 11851ecc0c5cSChao Yu /* For fault injection */ 11861ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 11871ecc0c5cSChao Yu struct f2fs_fault_info fault_info; 11881ecc0c5cSChao Yu #endif 11894b2414d0SChao Yu 11904b2414d0SChao Yu #ifdef CONFIG_QUOTA 11914b2414d0SChao Yu /* Names of quota files with journalled quota */ 11924b2414d0SChao Yu char *s_qf_names[MAXQUOTAS]; 11934b2414d0SChao Yu int s_jquota_fmt; /* Format of quota to use */ 11944b2414d0SChao Yu #endif 119539a53e0cSJaegeuk Kim }; 119639a53e0cSJaegeuk Kim 11971ecc0c5cSChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 119855523519SChao Yu #define f2fs_show_injection_info(type) \ 119955523519SChao Yu printk("%sF2FS-fs : inject %s in %s of %pF\n", \ 120055523519SChao Yu KERN_INFO, fault_name[type], \ 120155523519SChao Yu __func__, __builtin_return_address(0)) 12021ecc0c5cSChao Yu static inline bool time_to_inject(struct f2fs_sb_info *sbi, int type) 12031ecc0c5cSChao Yu { 12041ecc0c5cSChao Yu struct f2fs_fault_info *ffi = &sbi->fault_info; 12051ecc0c5cSChao Yu 12061ecc0c5cSChao Yu if (!ffi->inject_rate) 12071ecc0c5cSChao Yu return false; 12081ecc0c5cSChao Yu 12091ecc0c5cSChao Yu if (!IS_FAULT_SET(ffi, type)) 12101ecc0c5cSChao Yu return false; 12111ecc0c5cSChao Yu 12121ecc0c5cSChao Yu atomic_inc(&ffi->inject_ops); 12131ecc0c5cSChao Yu if (atomic_read(&ffi->inject_ops) >= ffi->inject_rate) { 12141ecc0c5cSChao Yu atomic_set(&ffi->inject_ops, 0); 12151ecc0c5cSChao Yu return true; 12161ecc0c5cSChao Yu } 12171ecc0c5cSChao Yu return false; 12181ecc0c5cSChao Yu } 12191ecc0c5cSChao Yu #endif 12201ecc0c5cSChao Yu 12218f1dbbbbSShuoran Liu /* For write statistics. Suppose sector size is 512 bytes, 12228f1dbbbbSShuoran Liu * and the return value is in kbytes. s is of struct f2fs_sb_info. 12238f1dbbbbSShuoran Liu */ 12248f1dbbbbSShuoran Liu #define BD_PART_WRITTEN(s) \ 122568afcf2dSTomohiro Kusumi (((u64)part_stat_read((s)->sb->s_bdev->bd_part, sectors[1]) - \ 122668afcf2dSTomohiro Kusumi (s)->sectors_written_start) >> 1) 12278f1dbbbbSShuoran Liu 12286beceb54SJaegeuk Kim static inline void f2fs_update_time(struct f2fs_sb_info *sbi, int type) 12296beceb54SJaegeuk Kim { 12306beceb54SJaegeuk Kim sbi->last_time[type] = jiffies; 12316beceb54SJaegeuk Kim } 12326beceb54SJaegeuk Kim 12336beceb54SJaegeuk Kim static inline bool f2fs_time_over(struct f2fs_sb_info *sbi, int type) 12346beceb54SJaegeuk Kim { 12356bccfa19SArnd Bergmann unsigned long interval = sbi->interval_time[type] * HZ; 12366beceb54SJaegeuk Kim 12376beceb54SJaegeuk Kim return time_after(jiffies, sbi->last_time[type] + interval); 12386beceb54SJaegeuk Kim } 12396beceb54SJaegeuk Kim 1240d0239e1bSJaegeuk Kim static inline bool is_idle(struct f2fs_sb_info *sbi) 1241d0239e1bSJaegeuk Kim { 1242d0239e1bSJaegeuk Kim struct block_device *bdev = sbi->sb->s_bdev; 1243d0239e1bSJaegeuk Kim struct request_queue *q = bdev_get_queue(bdev); 1244d0239e1bSJaegeuk Kim struct request_list *rl = &q->root_rl; 1245d0239e1bSJaegeuk Kim 1246d0239e1bSJaegeuk Kim if (rl->count[BLK_RW_SYNC] || rl->count[BLK_RW_ASYNC]) 1247d0239e1bSJaegeuk Kim return 0; 1248d0239e1bSJaegeuk Kim 1249d0239e1bSJaegeuk Kim return f2fs_time_over(sbi, REQ_TIME); 1250d0239e1bSJaegeuk Kim } 1251d0239e1bSJaegeuk Kim 125239a53e0cSJaegeuk Kim /* 125339a53e0cSJaegeuk Kim * Inline functions 125439a53e0cSJaegeuk Kim */ 125543b6573bSKeith Mok static inline u32 f2fs_crc32(struct f2fs_sb_info *sbi, const void *address, 125643b6573bSKeith Mok unsigned int length) 125743b6573bSKeith Mok { 125843b6573bSKeith Mok SHASH_DESC_ON_STACK(shash, sbi->s_chksum_driver); 125943b6573bSKeith Mok u32 *ctx = (u32 *)shash_desc_ctx(shash); 1260d41519a6SDavid Miller u32 retval; 126143b6573bSKeith Mok int err; 126243b6573bSKeith Mok 126343b6573bSKeith Mok shash->tfm = sbi->s_chksum_driver; 126443b6573bSKeith Mok shash->flags = 0; 126543b6573bSKeith Mok *ctx = F2FS_SUPER_MAGIC; 126643b6573bSKeith Mok 126743b6573bSKeith Mok err = crypto_shash_update(shash, address, length); 126843b6573bSKeith Mok BUG_ON(err); 126943b6573bSKeith Mok 1270d41519a6SDavid Miller retval = *ctx; 1271d41519a6SDavid Miller barrier_data(ctx); 1272d41519a6SDavid Miller return retval; 127343b6573bSKeith Mok } 127443b6573bSKeith Mok 127543b6573bSKeith Mok static inline bool f2fs_crc_valid(struct f2fs_sb_info *sbi, __u32 blk_crc, 127643b6573bSKeith Mok void *buf, size_t buf_size) 127743b6573bSKeith Mok { 127843b6573bSKeith Mok return f2fs_crc32(sbi, buf, buf_size) == blk_crc; 127943b6573bSKeith Mok } 128043b6573bSKeith Mok 1281704956ecSChao Yu static inline u32 f2fs_chksum(struct f2fs_sb_info *sbi, u32 crc, 1282704956ecSChao Yu const void *address, unsigned int length) 1283704956ecSChao Yu { 1284704956ecSChao Yu struct { 1285704956ecSChao Yu struct shash_desc shash; 1286704956ecSChao Yu char ctx[4]; 1287704956ecSChao Yu } desc; 1288704956ecSChao Yu int err; 1289704956ecSChao Yu 1290704956ecSChao Yu BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver) != sizeof(desc.ctx)); 1291704956ecSChao Yu 1292704956ecSChao Yu desc.shash.tfm = sbi->s_chksum_driver; 1293704956ecSChao Yu desc.shash.flags = 0; 1294704956ecSChao Yu *(u32 *)desc.ctx = crc; 1295704956ecSChao Yu 1296704956ecSChao Yu err = crypto_shash_update(&desc.shash, address, length); 1297704956ecSChao Yu BUG_ON(err); 1298704956ecSChao Yu 1299704956ecSChao Yu return *(u32 *)desc.ctx; 1300704956ecSChao Yu } 1301704956ecSChao Yu 130239a53e0cSJaegeuk Kim static inline struct f2fs_inode_info *F2FS_I(struct inode *inode) 130339a53e0cSJaegeuk Kim { 130439a53e0cSJaegeuk Kim return container_of(inode, struct f2fs_inode_info, vfs_inode); 130539a53e0cSJaegeuk Kim } 130639a53e0cSJaegeuk Kim 130739a53e0cSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) 130839a53e0cSJaegeuk Kim { 130939a53e0cSJaegeuk Kim return sb->s_fs_info; 131039a53e0cSJaegeuk Kim } 131139a53e0cSJaegeuk Kim 13124081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) 13134081363fSJaegeuk Kim { 13144081363fSJaegeuk Kim return F2FS_SB(inode->i_sb); 13154081363fSJaegeuk Kim } 13164081363fSJaegeuk Kim 13174081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_M_SB(struct address_space *mapping) 13184081363fSJaegeuk Kim { 13194081363fSJaegeuk Kim return F2FS_I_SB(mapping->host); 13204081363fSJaegeuk Kim } 13214081363fSJaegeuk Kim 13224081363fSJaegeuk Kim static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) 13234081363fSJaegeuk Kim { 13244081363fSJaegeuk Kim return F2FS_M_SB(page->mapping); 13254081363fSJaegeuk Kim } 13264081363fSJaegeuk Kim 132739a53e0cSJaegeuk Kim static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info *sbi) 132839a53e0cSJaegeuk Kim { 132939a53e0cSJaegeuk Kim return (struct f2fs_super_block *)(sbi->raw_super); 133039a53e0cSJaegeuk Kim } 133139a53e0cSJaegeuk Kim 133239a53e0cSJaegeuk Kim static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) 133339a53e0cSJaegeuk Kim { 133439a53e0cSJaegeuk Kim return (struct f2fs_checkpoint *)(sbi->ckpt); 133539a53e0cSJaegeuk Kim } 133639a53e0cSJaegeuk Kim 133745590710SGu Zheng static inline struct f2fs_node *F2FS_NODE(struct page *page) 133845590710SGu Zheng { 133945590710SGu Zheng return (struct f2fs_node *)page_address(page); 134045590710SGu Zheng } 134145590710SGu Zheng 134258bfaf44SJaegeuk Kim static inline struct f2fs_inode *F2FS_INODE(struct page *page) 134358bfaf44SJaegeuk Kim { 134458bfaf44SJaegeuk Kim return &((struct f2fs_node *)page_address(page))->i; 134558bfaf44SJaegeuk Kim } 134658bfaf44SJaegeuk Kim 134739a53e0cSJaegeuk Kim static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) 134839a53e0cSJaegeuk Kim { 134939a53e0cSJaegeuk Kim return (struct f2fs_nm_info *)(sbi->nm_info); 135039a53e0cSJaegeuk Kim } 135139a53e0cSJaegeuk Kim 135239a53e0cSJaegeuk Kim static inline struct f2fs_sm_info *SM_I(struct f2fs_sb_info *sbi) 135339a53e0cSJaegeuk Kim { 135439a53e0cSJaegeuk Kim return (struct f2fs_sm_info *)(sbi->sm_info); 135539a53e0cSJaegeuk Kim } 135639a53e0cSJaegeuk Kim 135739a53e0cSJaegeuk Kim static inline struct sit_info *SIT_I(struct f2fs_sb_info *sbi) 135839a53e0cSJaegeuk Kim { 135939a53e0cSJaegeuk Kim return (struct sit_info *)(SM_I(sbi)->sit_info); 136039a53e0cSJaegeuk Kim } 136139a53e0cSJaegeuk Kim 136239a53e0cSJaegeuk Kim static inline struct free_segmap_info *FREE_I(struct f2fs_sb_info *sbi) 136339a53e0cSJaegeuk Kim { 136439a53e0cSJaegeuk Kim return (struct free_segmap_info *)(SM_I(sbi)->free_info); 136539a53e0cSJaegeuk Kim } 136639a53e0cSJaegeuk Kim 136739a53e0cSJaegeuk Kim static inline struct dirty_seglist_info *DIRTY_I(struct f2fs_sb_info *sbi) 136839a53e0cSJaegeuk Kim { 136939a53e0cSJaegeuk Kim return (struct dirty_seglist_info *)(SM_I(sbi)->dirty_info); 137039a53e0cSJaegeuk Kim } 137139a53e0cSJaegeuk Kim 13729df27d98SGu Zheng static inline struct address_space *META_MAPPING(struct f2fs_sb_info *sbi) 13739df27d98SGu Zheng { 13749df27d98SGu Zheng return sbi->meta_inode->i_mapping; 13759df27d98SGu Zheng } 13769df27d98SGu Zheng 13774ef51a8fSJaegeuk Kim static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi) 13784ef51a8fSJaegeuk Kim { 13794ef51a8fSJaegeuk Kim return sbi->node_inode->i_mapping; 13804ef51a8fSJaegeuk Kim } 13814ef51a8fSJaegeuk Kim 1382caf0047eSChao Yu static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type) 138339a53e0cSJaegeuk Kim { 1384fadb2fb8SChao Yu return test_bit(type, &sbi->s_flag); 138539a53e0cSJaegeuk Kim } 138639a53e0cSJaegeuk Kim 1387caf0047eSChao Yu static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 138839a53e0cSJaegeuk Kim { 1389fadb2fb8SChao Yu set_bit(type, &sbi->s_flag); 1390caf0047eSChao Yu } 1391caf0047eSChao Yu 1392caf0047eSChao Yu static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type) 1393caf0047eSChao Yu { 1394fadb2fb8SChao Yu clear_bit(type, &sbi->s_flag); 139539a53e0cSJaegeuk Kim } 139639a53e0cSJaegeuk Kim 1397d71b5564SJaegeuk Kim static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp) 1398d71b5564SJaegeuk Kim { 1399d71b5564SJaegeuk Kim return le64_to_cpu(cp->checkpoint_ver); 1400d71b5564SJaegeuk Kim } 1401d71b5564SJaegeuk Kim 1402ea676733SJaegeuk Kim static inline unsigned long f2fs_qf_ino(struct super_block *sb, int type) 1403ea676733SJaegeuk Kim { 1404ea676733SJaegeuk Kim if (type < F2FS_MAX_QUOTAS) 1405ea676733SJaegeuk Kim return le32_to_cpu(F2FS_SB(sb)->raw_super->qf_ino[type]); 1406ea676733SJaegeuk Kim return 0; 1407ea676733SJaegeuk Kim } 1408ea676733SJaegeuk Kim 1409ced2c7eaSKinglong Mee static inline __u64 cur_cp_crc(struct f2fs_checkpoint *cp) 1410ced2c7eaSKinglong Mee { 1411ced2c7eaSKinglong Mee size_t crc_offset = le32_to_cpu(cp->checksum_offset); 1412ced2c7eaSKinglong Mee return le32_to_cpu(*((__le32 *)((unsigned char *)cp + crc_offset))); 1413ced2c7eaSKinglong Mee } 1414ced2c7eaSKinglong Mee 1415aaec2b1dSChao Yu static inline bool __is_set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 141625ca923bSJaegeuk Kim { 141725ca923bSJaegeuk Kim unsigned int ckpt_flags = le32_to_cpu(cp->ckpt_flags); 1418aaec2b1dSChao Yu 141925ca923bSJaegeuk Kim return ckpt_flags & f; 142025ca923bSJaegeuk Kim } 142125ca923bSJaegeuk Kim 1422aaec2b1dSChao Yu static inline bool is_set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 142325ca923bSJaegeuk Kim { 1424aaec2b1dSChao Yu return __is_set_ckpt_flags(F2FS_CKPT(sbi), f); 1425aaec2b1dSChao Yu } 1426aaec2b1dSChao Yu 1427aaec2b1dSChao Yu static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1428aaec2b1dSChao Yu { 1429aaec2b1dSChao Yu unsigned int ckpt_flags; 1430aaec2b1dSChao Yu 1431aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 143225ca923bSJaegeuk Kim ckpt_flags |= f; 143325ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 143425ca923bSJaegeuk Kim } 143525ca923bSJaegeuk Kim 1436aaec2b1dSChao Yu static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 143725ca923bSJaegeuk Kim { 1438d1aa2453SChao Yu unsigned long flags; 1439d1aa2453SChao Yu 1440d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1441aaec2b1dSChao Yu __set_ckpt_flags(F2FS_CKPT(sbi), f); 1442d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1443aaec2b1dSChao Yu } 1444aaec2b1dSChao Yu 1445aaec2b1dSChao Yu static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1446aaec2b1dSChao Yu { 1447aaec2b1dSChao Yu unsigned int ckpt_flags; 1448aaec2b1dSChao Yu 1449aaec2b1dSChao Yu ckpt_flags = le32_to_cpu(cp->ckpt_flags); 145025ca923bSJaegeuk Kim ckpt_flags &= (~f); 145125ca923bSJaegeuk Kim cp->ckpt_flags = cpu_to_le32(ckpt_flags); 145225ca923bSJaegeuk Kim } 145325ca923bSJaegeuk Kim 1454aaec2b1dSChao Yu static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1455aaec2b1dSChao Yu { 1456d1aa2453SChao Yu unsigned long flags; 1457d1aa2453SChao Yu 1458d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 1459aaec2b1dSChao Yu __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1460d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 1461aaec2b1dSChao Yu } 1462aaec2b1dSChao Yu 146322ad0b6aSJaegeuk Kim static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 146422ad0b6aSJaegeuk Kim { 1465d1aa2453SChao Yu unsigned long flags; 1466d1aa2453SChao Yu 146722ad0b6aSJaegeuk Kim set_sbi_flag(sbi, SBI_NEED_FSCK); 146822ad0b6aSJaegeuk Kim 146922ad0b6aSJaegeuk Kim if (lock) 1470d1aa2453SChao Yu spin_lock_irqsave(&sbi->cp_lock, flags); 147122ad0b6aSJaegeuk Kim __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 147222ad0b6aSJaegeuk Kim kfree(NM_I(sbi)->nat_bits); 147322ad0b6aSJaegeuk Kim NM_I(sbi)->nat_bits = NULL; 147422ad0b6aSJaegeuk Kim if (lock) 1475d1aa2453SChao Yu spin_unlock_irqrestore(&sbi->cp_lock, flags); 147622ad0b6aSJaegeuk Kim } 147722ad0b6aSJaegeuk Kim 147822ad0b6aSJaegeuk Kim static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 147922ad0b6aSJaegeuk Kim struct cp_control *cpc) 148022ad0b6aSJaegeuk Kim { 148122ad0b6aSJaegeuk Kim bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG); 148222ad0b6aSJaegeuk Kim 1483c473f1a9SChao Yu return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set; 148422ad0b6aSJaegeuk Kim } 148522ad0b6aSJaegeuk Kim 1486e479556bSGu Zheng static inline void f2fs_lock_op(struct f2fs_sb_info *sbi) 148739a53e0cSJaegeuk Kim { 1488b873b798SJaegeuk Kim down_read(&sbi->cp_rwsem); 148939a53e0cSJaegeuk Kim } 149039a53e0cSJaegeuk Kim 1491cc15620bSJaegeuk Kim static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi) 1492cc15620bSJaegeuk Kim { 1493cc15620bSJaegeuk Kim return down_read_trylock(&sbi->cp_rwsem); 1494cc15620bSJaegeuk Kim } 1495cc15620bSJaegeuk Kim 1496e479556bSGu Zheng static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 149739a53e0cSJaegeuk Kim { 1498b873b798SJaegeuk Kim up_read(&sbi->cp_rwsem); 149939936837SJaegeuk Kim } 150039936837SJaegeuk Kim 1501e479556bSGu Zheng static inline void f2fs_lock_all(struct f2fs_sb_info *sbi) 150239936837SJaegeuk Kim { 1503b873b798SJaegeuk Kim down_write(&sbi->cp_rwsem); 150439936837SJaegeuk Kim } 150539936837SJaegeuk Kim 1506e479556bSGu Zheng static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi) 150739936837SJaegeuk Kim { 1508b873b798SJaegeuk Kim up_write(&sbi->cp_rwsem); 150939a53e0cSJaegeuk Kim } 151039a53e0cSJaegeuk Kim 1511119ee914SJaegeuk Kim static inline int __get_cp_reason(struct f2fs_sb_info *sbi) 1512119ee914SJaegeuk Kim { 1513119ee914SJaegeuk Kim int reason = CP_SYNC; 1514119ee914SJaegeuk Kim 1515119ee914SJaegeuk Kim if (test_opt(sbi, FASTBOOT)) 1516119ee914SJaegeuk Kim reason = CP_FASTBOOT; 1517119ee914SJaegeuk Kim if (is_sbi_flag_set(sbi, SBI_IS_CLOSE)) 1518119ee914SJaegeuk Kim reason = CP_UMOUNT; 1519119ee914SJaegeuk Kim return reason; 1520119ee914SJaegeuk Kim } 1521119ee914SJaegeuk Kim 1522119ee914SJaegeuk Kim static inline bool __remain_node_summaries(int reason) 1523119ee914SJaegeuk Kim { 1524c473f1a9SChao Yu return (reason & (CP_UMOUNT | CP_FASTBOOT)); 1525119ee914SJaegeuk Kim } 1526119ee914SJaegeuk Kim 1527119ee914SJaegeuk Kim static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi) 1528119ee914SJaegeuk Kim { 1529aaec2b1dSChao Yu return (is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG) || 1530aaec2b1dSChao Yu is_set_ckpt_flags(sbi, CP_FASTBOOT_FLAG)); 1531119ee914SJaegeuk Kim } 1532119ee914SJaegeuk Kim 153339a53e0cSJaegeuk Kim /* 153439a53e0cSJaegeuk Kim * Check whether the given nid is within node id range. 153539a53e0cSJaegeuk Kim */ 1536064e0823SNamjae Jeon static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 153739a53e0cSJaegeuk Kim { 1538d6b7d4b3SChao Yu if (unlikely(nid < F2FS_ROOT_INO(sbi))) 1539d6b7d4b3SChao Yu return -EINVAL; 1540cfb271d4SChao Yu if (unlikely(nid >= NM_I(sbi)->max_nid)) 1541064e0823SNamjae Jeon return -EINVAL; 1542064e0823SNamjae Jeon return 0; 154339a53e0cSJaegeuk Kim } 154439a53e0cSJaegeuk Kim 154539a53e0cSJaegeuk Kim /* 154639a53e0cSJaegeuk Kim * Check whether the inode has blocks or not 154739a53e0cSJaegeuk Kim */ 154839a53e0cSJaegeuk Kim static inline int F2FS_HAS_BLOCKS(struct inode *inode) 154939a53e0cSJaegeuk Kim { 15500eb0adadSChao Yu block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0; 15510eb0adadSChao Yu 1552000519f2SChao Yu return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; 155339a53e0cSJaegeuk Kim } 155439a53e0cSJaegeuk Kim 15554bc8e9bcSChao Yu static inline bool f2fs_has_xattr_block(unsigned int ofs) 15564bc8e9bcSChao Yu { 15574bc8e9bcSChao Yu return ofs == XATTR_NODE_OFFSET; 15584bc8e9bcSChao Yu } 15594bc8e9bcSChao Yu 15600abd675eSChao Yu static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool); 15610abd675eSChao Yu static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, 156246008c6dSChao Yu struct inode *inode, blkcnt_t *count) 156339a53e0cSJaegeuk Kim { 15640abd675eSChao Yu blkcnt_t diff = 0, release = 0; 1565daeb433eSChao Yu block_t avail_user_block_count; 15660abd675eSChao Yu int ret; 15670abd675eSChao Yu 15680abd675eSChao Yu ret = dquot_reserve_block(inode, *count); 15690abd675eSChao Yu if (ret) 15700abd675eSChao Yu return ret; 1571dd11a5dfSJaegeuk Kim 1572cb78942bSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 157355523519SChao Yu if (time_to_inject(sbi, FAULT_BLOCK)) { 157455523519SChao Yu f2fs_show_injection_info(FAULT_BLOCK); 15750abd675eSChao Yu release = *count; 15760abd675eSChao Yu goto enospc; 157755523519SChao Yu } 1578cb78942bSJaegeuk Kim #endif 1579dd11a5dfSJaegeuk Kim /* 1580dd11a5dfSJaegeuk Kim * let's increase this in prior to actual block count change in order 1581dd11a5dfSJaegeuk Kim * for f2fs_sync_file to avoid data races when deciding checkpoint. 1582dd11a5dfSJaegeuk Kim */ 1583dd11a5dfSJaegeuk Kim percpu_counter_add(&sbi->alloc_valid_block_count, (*count)); 1584cfb271d4SChao Yu 158539a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 15862555a2d5SJaegeuk Kim sbi->total_valid_block_count += (block_t)(*count); 158780d42145SYunlong Song avail_user_block_count = sbi->user_block_count - 158880d42145SYunlong Song sbi->current_reserved_blocks; 1589daeb433eSChao Yu if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { 1590daeb433eSChao Yu diff = sbi->total_valid_block_count - avail_user_block_count; 1591dd11a5dfSJaegeuk Kim *count -= diff; 15920abd675eSChao Yu release = diff; 1593daeb433eSChao Yu sbi->total_valid_block_count = avail_user_block_count; 159446008c6dSChao Yu if (!*count) { 159539a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 1596dd11a5dfSJaegeuk Kim percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 15970abd675eSChao Yu goto enospc; 159839a53e0cSJaegeuk Kim } 159946008c6dSChao Yu } 160039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 160141382ec4SJaegeuk Kim 16020abd675eSChao Yu if (release) 16030abd675eSChao Yu dquot_release_reservation_block(inode, release); 16040abd675eSChao Yu f2fs_i_blocks_write(inode, *count, true, true); 16050abd675eSChao Yu return 0; 16060abd675eSChao Yu 16070abd675eSChao Yu enospc: 16080abd675eSChao Yu dquot_release_reservation_block(inode, release); 16090abd675eSChao Yu return -ENOSPC; 161039a53e0cSJaegeuk Kim } 161139a53e0cSJaegeuk Kim 1612da19b0dcSGu Zheng static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 161339a53e0cSJaegeuk Kim struct inode *inode, 16140eb0adadSChao Yu block_t count) 161539a53e0cSJaegeuk Kim { 16160eb0adadSChao Yu blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK; 16170eb0adadSChao Yu 161839a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 16199850cf4aSJaegeuk Kim f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 16200eb0adadSChao Yu f2fs_bug_on(sbi, inode->i_blocks < sectors); 162139a53e0cSJaegeuk Kim sbi->total_valid_block_count -= (block_t)count; 162280d42145SYunlong Song if (sbi->reserved_blocks && 162380d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 162480d42145SYunlong Song sbi->current_reserved_blocks = min(sbi->reserved_blocks, 162580d42145SYunlong Song sbi->current_reserved_blocks + count); 162639a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 16270abd675eSChao Yu f2fs_i_blocks_write(inode, count, false, true); 162839a53e0cSJaegeuk Kim } 162939a53e0cSJaegeuk Kim 163039a53e0cSJaegeuk Kim static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 163139a53e0cSJaegeuk Kim { 163235782b23SJaegeuk Kim atomic_inc(&sbi->nr_pages[count_type]); 16337c4abcbeSChao Yu 163436951b38SChao Yu if (count_type == F2FS_DIRTY_DATA || count_type == F2FS_INMEM_PAGES || 163536951b38SChao Yu count_type == F2FS_WB_CP_DATA || count_type == F2FS_WB_DATA) 16367c4abcbeSChao Yu return; 16377c4abcbeSChao Yu 1638caf0047eSChao Yu set_sbi_flag(sbi, SBI_IS_DIRTY); 163939a53e0cSJaegeuk Kim } 164039a53e0cSJaegeuk Kim 1641a7ffdbe2SJaegeuk Kim static inline void inode_inc_dirty_pages(struct inode *inode) 164239a53e0cSJaegeuk Kim { 1643204706c7SJaegeuk Kim atomic_inc(&F2FS_I(inode)->dirty_pages); 1644c227f912SChao Yu inc_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1645c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 1646*2c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 1647*2c8a4a28SJaegeuk Kim inc_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 164839a53e0cSJaegeuk Kim } 164939a53e0cSJaegeuk Kim 165039a53e0cSJaegeuk Kim static inline void dec_page_count(struct f2fs_sb_info *sbi, int count_type) 165139a53e0cSJaegeuk Kim { 165235782b23SJaegeuk Kim atomic_dec(&sbi->nr_pages[count_type]); 165339a53e0cSJaegeuk Kim } 165439a53e0cSJaegeuk Kim 1655a7ffdbe2SJaegeuk Kim static inline void inode_dec_dirty_pages(struct inode *inode) 165639a53e0cSJaegeuk Kim { 16575ac9f36fSChao Yu if (!S_ISDIR(inode->i_mode) && !S_ISREG(inode->i_mode) && 16585ac9f36fSChao Yu !S_ISLNK(inode->i_mode)) 16591fe54f9dSJaegeuk Kim return; 16601fe54f9dSJaegeuk Kim 1661204706c7SJaegeuk Kim atomic_dec(&F2FS_I(inode)->dirty_pages); 1662c227f912SChao Yu dec_page_count(F2FS_I_SB(inode), S_ISDIR(inode->i_mode) ? 1663c227f912SChao Yu F2FS_DIRTY_DENTS : F2FS_DIRTY_DATA); 1664*2c8a4a28SJaegeuk Kim if (IS_NOQUOTA(inode)) 1665*2c8a4a28SJaegeuk Kim dec_page_count(F2FS_I_SB(inode), F2FS_DIRTY_QDATA); 166639a53e0cSJaegeuk Kim } 166739a53e0cSJaegeuk Kim 1668523be8a6SJaegeuk Kim static inline s64 get_pages(struct f2fs_sb_info *sbi, int count_type) 166939a53e0cSJaegeuk Kim { 167035782b23SJaegeuk Kim return atomic_read(&sbi->nr_pages[count_type]); 167139a53e0cSJaegeuk Kim } 167239a53e0cSJaegeuk Kim 1673204706c7SJaegeuk Kim static inline int get_dirty_pages(struct inode *inode) 1674f8b2c1f9SJaegeuk Kim { 1675204706c7SJaegeuk Kim return atomic_read(&F2FS_I(inode)->dirty_pages); 1676f8b2c1f9SJaegeuk Kim } 1677f8b2c1f9SJaegeuk Kim 16785ac206cfSNamjae Jeon static inline int get_blocktype_secs(struct f2fs_sb_info *sbi, int block_type) 16795ac206cfSNamjae Jeon { 16803519e3f9SChao Yu unsigned int pages_per_sec = sbi->segs_per_sec * sbi->blocks_per_seg; 1681523be8a6SJaegeuk Kim unsigned int segs = (get_pages(sbi, block_type) + pages_per_sec - 1) >> 1682523be8a6SJaegeuk Kim sbi->log_blocks_per_seg; 1683523be8a6SJaegeuk Kim 1684523be8a6SJaegeuk Kim return segs / sbi->segs_per_sec; 16855ac206cfSNamjae Jeon } 16865ac206cfSNamjae Jeon 168739a53e0cSJaegeuk Kim static inline block_t valid_user_blocks(struct f2fs_sb_info *sbi) 168839a53e0cSJaegeuk Kim { 16898b8343faSJaegeuk Kim return sbi->total_valid_block_count; 169039a53e0cSJaegeuk Kim } 169139a53e0cSJaegeuk Kim 1692f83a2584SYunlei He static inline block_t discard_blocks(struct f2fs_sb_info *sbi) 1693f83a2584SYunlei He { 1694f83a2584SYunlei He return sbi->discard_blks; 1695f83a2584SYunlei He } 1696f83a2584SYunlei He 169739a53e0cSJaegeuk Kim static inline unsigned long __bitmap_size(struct f2fs_sb_info *sbi, int flag) 169839a53e0cSJaegeuk Kim { 169939a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 170039a53e0cSJaegeuk Kim 170139a53e0cSJaegeuk Kim /* return NAT or SIT bitmap */ 170239a53e0cSJaegeuk Kim if (flag == NAT_BITMAP) 170339a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->nat_ver_bitmap_bytesize); 170439a53e0cSJaegeuk Kim else if (flag == SIT_BITMAP) 170539a53e0cSJaegeuk Kim return le32_to_cpu(ckpt->sit_ver_bitmap_bytesize); 170639a53e0cSJaegeuk Kim 170739a53e0cSJaegeuk Kim return 0; 170839a53e0cSJaegeuk Kim } 170939a53e0cSJaegeuk Kim 171055141486SWanpeng Li static inline block_t __cp_payload(struct f2fs_sb_info *sbi) 171155141486SWanpeng Li { 171255141486SWanpeng Li return le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_payload); 171355141486SWanpeng Li } 171455141486SWanpeng Li 171539a53e0cSJaegeuk Kim static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) 171639a53e0cSJaegeuk Kim { 171739a53e0cSJaegeuk Kim struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 17181dbe4152SChangman Lee int offset; 17191dbe4152SChangman Lee 172055141486SWanpeng Li if (__cp_payload(sbi) > 0) { 17211dbe4152SChangman Lee if (flag == NAT_BITMAP) 17221dbe4152SChangman Lee return &ckpt->sit_nat_version_bitmap; 17231dbe4152SChangman Lee else 172465b85cccSJaegeuk Kim return (unsigned char *)ckpt + F2FS_BLKSIZE; 17251dbe4152SChangman Lee } else { 17261dbe4152SChangman Lee offset = (flag == NAT_BITMAP) ? 172725ca923bSJaegeuk Kim le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; 172839a53e0cSJaegeuk Kim return &ckpt->sit_nat_version_bitmap + offset; 172939a53e0cSJaegeuk Kim } 17301dbe4152SChangman Lee } 173139a53e0cSJaegeuk Kim 173239a53e0cSJaegeuk Kim static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) 173339a53e0cSJaegeuk Kim { 17348508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 173539a53e0cSJaegeuk Kim 17368508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 2) 173739a53e0cSJaegeuk Kim start_addr += sbi->blocks_per_seg; 173839a53e0cSJaegeuk Kim return start_addr; 173939a53e0cSJaegeuk Kim } 174039a53e0cSJaegeuk Kim 17418508e44aSJaegeuk Kim static inline block_t __start_cp_next_addr(struct f2fs_sb_info *sbi) 17428508e44aSJaegeuk Kim { 17438508e44aSJaegeuk Kim block_t start_addr = le32_to_cpu(F2FS_RAW_SUPER(sbi)->cp_blkaddr); 17448508e44aSJaegeuk Kim 17458508e44aSJaegeuk Kim if (sbi->cur_cp_pack == 1) 17468508e44aSJaegeuk Kim start_addr += sbi->blocks_per_seg; 17478508e44aSJaegeuk Kim return start_addr; 17488508e44aSJaegeuk Kim } 17498508e44aSJaegeuk Kim 17508508e44aSJaegeuk Kim static inline void __set_cp_next_pack(struct f2fs_sb_info *sbi) 17518508e44aSJaegeuk Kim { 17528508e44aSJaegeuk Kim sbi->cur_cp_pack = (sbi->cur_cp_pack == 1) ? 2 : 1; 17538508e44aSJaegeuk Kim } 17548508e44aSJaegeuk Kim 175539a53e0cSJaegeuk Kim static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi) 175639a53e0cSJaegeuk Kim { 175739a53e0cSJaegeuk Kim return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 175839a53e0cSJaegeuk Kim } 175939a53e0cSJaegeuk Kim 17600abd675eSChao Yu static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, 1761000519f2SChao Yu struct inode *inode, bool is_inode) 176239a53e0cSJaegeuk Kim { 176339a53e0cSJaegeuk Kim block_t valid_block_count; 176439a53e0cSJaegeuk Kim unsigned int valid_node_count; 17650abd675eSChao Yu bool quota = inode && !is_inode; 17660abd675eSChao Yu 17670abd675eSChao Yu if (quota) { 17680abd675eSChao Yu int ret = dquot_reserve_block(inode, 1); 17690abd675eSChao Yu if (ret) 17700abd675eSChao Yu return ret; 17710abd675eSChao Yu } 177239a53e0cSJaegeuk Kim 177339a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 177439a53e0cSJaegeuk Kim 1775ef86d709SGu Zheng valid_block_count = sbi->total_valid_block_count + 1; 177680d42145SYunlong Song if (unlikely(valid_block_count + sbi->current_reserved_blocks > 1777daeb433eSChao Yu sbi->user_block_count)) { 177839a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17790abd675eSChao Yu goto enospc; 178039a53e0cSJaegeuk Kim } 178139a53e0cSJaegeuk Kim 1782ef86d709SGu Zheng valid_node_count = sbi->total_valid_node_count + 1; 1783cfb271d4SChao Yu if (unlikely(valid_node_count > sbi->total_node_count)) { 178439a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 17850abd675eSChao Yu goto enospc; 178639a53e0cSJaegeuk Kim } 178739a53e0cSJaegeuk Kim 1788ef86d709SGu Zheng sbi->total_valid_node_count++; 1789ef86d709SGu Zheng sbi->total_valid_block_count++; 179039a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 179139a53e0cSJaegeuk Kim 17920abd675eSChao Yu if (inode) { 17930abd675eSChao Yu if (is_inode) 17940abd675eSChao Yu f2fs_mark_inode_dirty_sync(inode, true); 17950abd675eSChao Yu else 17960abd675eSChao Yu f2fs_i_blocks_write(inode, 1, true, true); 17970abd675eSChao Yu } 17980abd675eSChao Yu 179941382ec4SJaegeuk Kim percpu_counter_inc(&sbi->alloc_valid_block_count); 18000abd675eSChao Yu return 0; 18010abd675eSChao Yu 18020abd675eSChao Yu enospc: 18030abd675eSChao Yu if (quota) 18040abd675eSChao Yu dquot_release_reservation_block(inode, 1); 18050abd675eSChao Yu return -ENOSPC; 180639a53e0cSJaegeuk Kim } 180739a53e0cSJaegeuk Kim 180839a53e0cSJaegeuk Kim static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1809000519f2SChao Yu struct inode *inode, bool is_inode) 181039a53e0cSJaegeuk Kim { 181139a53e0cSJaegeuk Kim spin_lock(&sbi->stat_lock); 181239a53e0cSJaegeuk Kim 18139850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_block_count); 18149850cf4aSJaegeuk Kim f2fs_bug_on(sbi, !sbi->total_valid_node_count); 1815000519f2SChao Yu f2fs_bug_on(sbi, !is_inode && !inode->i_blocks); 181639a53e0cSJaegeuk Kim 1817ef86d709SGu Zheng sbi->total_valid_node_count--; 1818ef86d709SGu Zheng sbi->total_valid_block_count--; 181980d42145SYunlong Song if (sbi->reserved_blocks && 182080d42145SYunlong Song sbi->current_reserved_blocks < sbi->reserved_blocks) 182180d42145SYunlong Song sbi->current_reserved_blocks++; 182239a53e0cSJaegeuk Kim 182339a53e0cSJaegeuk Kim spin_unlock(&sbi->stat_lock); 18240abd675eSChao Yu 18250abd675eSChao Yu if (!is_inode) 18260abd675eSChao Yu f2fs_i_blocks_write(inode, 1, false, true); 182739a53e0cSJaegeuk Kim } 182839a53e0cSJaegeuk Kim 182939a53e0cSJaegeuk Kim static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 183039a53e0cSJaegeuk Kim { 18318b8343faSJaegeuk Kim return sbi->total_valid_node_count; 183239a53e0cSJaegeuk Kim } 183339a53e0cSJaegeuk Kim 183439a53e0cSJaegeuk Kim static inline void inc_valid_inode_count(struct f2fs_sb_info *sbi) 183539a53e0cSJaegeuk Kim { 1836513c5f37SJaegeuk Kim percpu_counter_inc(&sbi->total_valid_inode_count); 183739a53e0cSJaegeuk Kim } 183839a53e0cSJaegeuk Kim 18390e80220aSJaegeuk Kim static inline void dec_valid_inode_count(struct f2fs_sb_info *sbi) 184039a53e0cSJaegeuk Kim { 1841513c5f37SJaegeuk Kim percpu_counter_dec(&sbi->total_valid_inode_count); 184239a53e0cSJaegeuk Kim } 184339a53e0cSJaegeuk Kim 1844513c5f37SJaegeuk Kim static inline s64 valid_inode_count(struct f2fs_sb_info *sbi) 184539a53e0cSJaegeuk Kim { 1846513c5f37SJaegeuk Kim return percpu_counter_sum_positive(&sbi->total_valid_inode_count); 184739a53e0cSJaegeuk Kim } 184839a53e0cSJaegeuk Kim 1849a56c7c6fSJaegeuk Kim static inline struct page *f2fs_grab_cache_page(struct address_space *mapping, 1850a56c7c6fSJaegeuk Kim pgoff_t index, bool for_write) 1851a56c7c6fSJaegeuk Kim { 1852c41f3cc3SJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 1853c41f3cc3SJaegeuk Kim struct page *page = find_lock_page(mapping, index); 1854cac5a3d8SDongOh Shin 1855c41f3cc3SJaegeuk Kim if (page) 1856c41f3cc3SJaegeuk Kim return page; 1857c41f3cc3SJaegeuk Kim 185855523519SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_ALLOC)) { 185955523519SChao Yu f2fs_show_injection_info(FAULT_PAGE_ALLOC); 1860c41f3cc3SJaegeuk Kim return NULL; 186155523519SChao Yu } 1862c41f3cc3SJaegeuk Kim #endif 1863a56c7c6fSJaegeuk Kim if (!for_write) 1864a56c7c6fSJaegeuk Kim return grab_cache_page(mapping, index); 1865a56c7c6fSJaegeuk Kim return grab_cache_page_write_begin(mapping, index, AOP_FLAG_NOFS); 1866a56c7c6fSJaegeuk Kim } 1867a56c7c6fSJaegeuk Kim 186801eccef7SChao Yu static inline struct page *f2fs_pagecache_get_page( 186901eccef7SChao Yu struct address_space *mapping, pgoff_t index, 187001eccef7SChao Yu int fgp_flags, gfp_t gfp_mask) 187101eccef7SChao Yu { 187201eccef7SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 187301eccef7SChao Yu if (time_to_inject(F2FS_M_SB(mapping), FAULT_PAGE_GET)) { 187401eccef7SChao Yu f2fs_show_injection_info(FAULT_PAGE_GET); 187501eccef7SChao Yu return NULL; 187601eccef7SChao Yu } 187701eccef7SChao Yu #endif 187801eccef7SChao Yu return pagecache_get_page(mapping, index, fgp_flags, gfp_mask); 187901eccef7SChao Yu } 188001eccef7SChao Yu 18816e2c64adSJaegeuk Kim static inline void f2fs_copy_page(struct page *src, struct page *dst) 18826e2c64adSJaegeuk Kim { 18836e2c64adSJaegeuk Kim char *src_kaddr = kmap(src); 18846e2c64adSJaegeuk Kim char *dst_kaddr = kmap(dst); 18856e2c64adSJaegeuk Kim 18866e2c64adSJaegeuk Kim memcpy(dst_kaddr, src_kaddr, PAGE_SIZE); 18876e2c64adSJaegeuk Kim kunmap(dst); 18886e2c64adSJaegeuk Kim kunmap(src); 18896e2c64adSJaegeuk Kim } 18906e2c64adSJaegeuk Kim 189139a53e0cSJaegeuk Kim static inline void f2fs_put_page(struct page *page, int unlock) 189239a53e0cSJaegeuk Kim { 1893031fa8ccSJaegeuk Kim if (!page) 189439a53e0cSJaegeuk Kim return; 189539a53e0cSJaegeuk Kim 189639a53e0cSJaegeuk Kim if (unlock) { 18979850cf4aSJaegeuk Kim f2fs_bug_on(F2FS_P_SB(page), !PageLocked(page)); 189839a53e0cSJaegeuk Kim unlock_page(page); 189939a53e0cSJaegeuk Kim } 190009cbfeafSKirill A. Shutemov put_page(page); 190139a53e0cSJaegeuk Kim } 190239a53e0cSJaegeuk Kim 190339a53e0cSJaegeuk Kim static inline void f2fs_put_dnode(struct dnode_of_data *dn) 190439a53e0cSJaegeuk Kim { 190539a53e0cSJaegeuk Kim if (dn->node_page) 190639a53e0cSJaegeuk Kim f2fs_put_page(dn->node_page, 1); 190739a53e0cSJaegeuk Kim if (dn->inode_page && dn->node_page != dn->inode_page) 190839a53e0cSJaegeuk Kim f2fs_put_page(dn->inode_page, 0); 190939a53e0cSJaegeuk Kim dn->node_page = NULL; 191039a53e0cSJaegeuk Kim dn->inode_page = NULL; 191139a53e0cSJaegeuk Kim } 191239a53e0cSJaegeuk Kim 191339a53e0cSJaegeuk Kim static inline struct kmem_cache *f2fs_kmem_cache_create(const char *name, 1914e8512d2eSGu Zheng size_t size) 191539a53e0cSJaegeuk Kim { 1916e8512d2eSGu Zheng return kmem_cache_create(name, size, 0, SLAB_RECLAIM_ACCOUNT, NULL); 191739a53e0cSJaegeuk Kim } 191839a53e0cSJaegeuk Kim 19197bd59381SGu Zheng static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep, 19207bd59381SGu Zheng gfp_t flags) 19217bd59381SGu Zheng { 19227bd59381SGu Zheng void *entry; 19237bd59381SGu Zheng 192480c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags); 192580c54505SJaegeuk Kim if (!entry) 192680c54505SJaegeuk Kim entry = kmem_cache_alloc(cachep, flags | __GFP_NOFAIL); 19277bd59381SGu Zheng return entry; 19287bd59381SGu Zheng } 19297bd59381SGu Zheng 1930d62fe971SChao Yu static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi, 1931d62fe971SChao Yu int npages, bool no_fail) 1932740432f8SJaegeuk Kim { 1933740432f8SJaegeuk Kim struct bio *bio; 1934740432f8SJaegeuk Kim 1935d62fe971SChao Yu if (no_fail) { 1936740432f8SJaegeuk Kim /* No failure on bio allocation */ 1937740432f8SJaegeuk Kim bio = bio_alloc(GFP_NOIO, npages); 193880c54505SJaegeuk Kim if (!bio) 193980c54505SJaegeuk Kim bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages); 1940740432f8SJaegeuk Kim return bio; 1941740432f8SJaegeuk Kim } 1942d62fe971SChao Yu #ifdef CONFIG_F2FS_FAULT_INJECTION 1943d62fe971SChao Yu if (time_to_inject(sbi, FAULT_ALLOC_BIO)) { 1944d62fe971SChao Yu f2fs_show_injection_info(FAULT_ALLOC_BIO); 1945d62fe971SChao Yu return NULL; 1946d62fe971SChao Yu } 1947d62fe971SChao Yu #endif 1948d62fe971SChao Yu return bio_alloc(GFP_KERNEL, npages); 1949d62fe971SChao Yu } 1950740432f8SJaegeuk Kim 19519be32d72SJaegeuk Kim static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, 19529be32d72SJaegeuk Kim unsigned long index, void *item) 19539be32d72SJaegeuk Kim { 19549be32d72SJaegeuk Kim while (radix_tree_insert(root, index, item)) 19559be32d72SJaegeuk Kim cond_resched(); 19569be32d72SJaegeuk Kim } 19579be32d72SJaegeuk Kim 195839a53e0cSJaegeuk Kim #define RAW_IS_INODE(p) ((p)->footer.nid == (p)->footer.ino) 195939a53e0cSJaegeuk Kim 196039a53e0cSJaegeuk Kim static inline bool IS_INODE(struct page *page) 196139a53e0cSJaegeuk Kim { 196245590710SGu Zheng struct f2fs_node *p = F2FS_NODE(page); 1963cac5a3d8SDongOh Shin 196439a53e0cSJaegeuk Kim return RAW_IS_INODE(p); 196539a53e0cSJaegeuk Kim } 196639a53e0cSJaegeuk Kim 19677a2af766SChao Yu static inline int offset_in_addr(struct f2fs_inode *i) 19687a2af766SChao Yu { 19697a2af766SChao Yu return (i->i_inline & F2FS_EXTRA_ATTR) ? 19707a2af766SChao Yu (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; 19717a2af766SChao Yu } 19727a2af766SChao Yu 197339a53e0cSJaegeuk Kim static inline __le32 *blkaddr_in_node(struct f2fs_node *node) 197439a53e0cSJaegeuk Kim { 197539a53e0cSJaegeuk Kim return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; 197639a53e0cSJaegeuk Kim } 197739a53e0cSJaegeuk Kim 19787a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode); 19797a2af766SChao Yu static inline block_t datablock_addr(struct inode *inode, 19807a2af766SChao Yu struct page *node_page, unsigned int offset) 198139a53e0cSJaegeuk Kim { 198239a53e0cSJaegeuk Kim struct f2fs_node *raw_node; 198339a53e0cSJaegeuk Kim __le32 *addr_array; 19847a2af766SChao Yu int base = 0; 19857a2af766SChao Yu bool is_inode = IS_INODE(node_page); 1986cac5a3d8SDongOh Shin 198745590710SGu Zheng raw_node = F2FS_NODE(node_page); 19887a2af766SChao Yu 19897a2af766SChao Yu /* from GC path only */ 19907a2af766SChao Yu if (!inode) { 19917a2af766SChao Yu if (is_inode) 19927a2af766SChao Yu base = offset_in_addr(&raw_node->i); 19937a2af766SChao Yu } else if (f2fs_has_extra_attr(inode) && is_inode) { 19947a2af766SChao Yu base = get_extra_isize(inode); 19957a2af766SChao Yu } 19967a2af766SChao Yu 199739a53e0cSJaegeuk Kim addr_array = blkaddr_in_node(raw_node); 19987a2af766SChao Yu return le32_to_cpu(addr_array[base + offset]); 199939a53e0cSJaegeuk Kim } 200039a53e0cSJaegeuk Kim 200139a53e0cSJaegeuk Kim static inline int f2fs_test_bit(unsigned int nr, char *addr) 200239a53e0cSJaegeuk Kim { 200339a53e0cSJaegeuk Kim int mask; 200439a53e0cSJaegeuk Kim 200539a53e0cSJaegeuk Kim addr += (nr >> 3); 200639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 200739a53e0cSJaegeuk Kim return mask & *addr; 200839a53e0cSJaegeuk Kim } 200939a53e0cSJaegeuk Kim 2010a66cdd98SJaegeuk Kim static inline void f2fs_set_bit(unsigned int nr, char *addr) 2011a66cdd98SJaegeuk Kim { 2012a66cdd98SJaegeuk Kim int mask; 2013a66cdd98SJaegeuk Kim 2014a66cdd98SJaegeuk Kim addr += (nr >> 3); 2015a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2016a66cdd98SJaegeuk Kim *addr |= mask; 2017a66cdd98SJaegeuk Kim } 2018a66cdd98SJaegeuk Kim 2019a66cdd98SJaegeuk Kim static inline void f2fs_clear_bit(unsigned int nr, char *addr) 2020a66cdd98SJaegeuk Kim { 2021a66cdd98SJaegeuk Kim int mask; 2022a66cdd98SJaegeuk Kim 2023a66cdd98SJaegeuk Kim addr += (nr >> 3); 2024a66cdd98SJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 2025a66cdd98SJaegeuk Kim *addr &= ~mask; 2026a66cdd98SJaegeuk Kim } 2027a66cdd98SJaegeuk Kim 202852aca074SGu Zheng static inline int f2fs_test_and_set_bit(unsigned int nr, char *addr) 202939a53e0cSJaegeuk Kim { 203039a53e0cSJaegeuk Kim int mask; 203139a53e0cSJaegeuk Kim int ret; 203239a53e0cSJaegeuk Kim 203339a53e0cSJaegeuk Kim addr += (nr >> 3); 203439a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 203539a53e0cSJaegeuk Kim ret = mask & *addr; 203639a53e0cSJaegeuk Kim *addr |= mask; 203739a53e0cSJaegeuk Kim return ret; 203839a53e0cSJaegeuk Kim } 203939a53e0cSJaegeuk Kim 204052aca074SGu Zheng static inline int f2fs_test_and_clear_bit(unsigned int nr, char *addr) 204139a53e0cSJaegeuk Kim { 204239a53e0cSJaegeuk Kim int mask; 204339a53e0cSJaegeuk Kim int ret; 204439a53e0cSJaegeuk Kim 204539a53e0cSJaegeuk Kim addr += (nr >> 3); 204639a53e0cSJaegeuk Kim mask = 1 << (7 - (nr & 0x07)); 204739a53e0cSJaegeuk Kim ret = mask & *addr; 204839a53e0cSJaegeuk Kim *addr &= ~mask; 204939a53e0cSJaegeuk Kim return ret; 205039a53e0cSJaegeuk Kim } 205139a53e0cSJaegeuk Kim 2052c6ac4c0eSGu Zheng static inline void f2fs_change_bit(unsigned int nr, char *addr) 2053c6ac4c0eSGu Zheng { 2054c6ac4c0eSGu Zheng int mask; 2055c6ac4c0eSGu Zheng 2056c6ac4c0eSGu Zheng addr += (nr >> 3); 2057c6ac4c0eSGu Zheng mask = 1 << (7 - (nr & 0x07)); 2058c6ac4c0eSGu Zheng *addr ^= mask; 2059c6ac4c0eSGu Zheng } 2060c6ac4c0eSGu Zheng 20615c57132eSChao Yu #define F2FS_REG_FLMASK (~(FS_DIRSYNC_FL | FS_TOPDIR_FL)) 20625c57132eSChao Yu #define F2FS_OTHER_FLMASK (FS_NODUMP_FL | FS_NOATIME_FL) 20635c57132eSChao Yu #define F2FS_FL_INHERITED (FS_PROJINHERIT_FL) 20645c57132eSChao Yu 20655c57132eSChao Yu static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) 20665c57132eSChao Yu { 20675c57132eSChao Yu if (S_ISDIR(mode)) 20685c57132eSChao Yu return flags; 20695c57132eSChao Yu else if (S_ISREG(mode)) 20705c57132eSChao Yu return flags & F2FS_REG_FLMASK; 20715c57132eSChao Yu else 20725c57132eSChao Yu return flags & F2FS_OTHER_FLMASK; 20735c57132eSChao Yu } 20745c57132eSChao Yu 207539a53e0cSJaegeuk Kim /* used for f2fs_inode_info->flags */ 207639a53e0cSJaegeuk Kim enum { 207739a53e0cSJaegeuk Kim FI_NEW_INODE, /* indicate newly allocated inode */ 2078b3783873SJaegeuk Kim FI_DIRTY_INODE, /* indicate inode is dirty or not */ 207926de9b11SJaegeuk Kim FI_AUTO_RECOVER, /* indicate inode is recoverable */ 2080ed57c27fSJaegeuk Kim FI_DIRTY_DIR, /* indicate directory has dirty pages */ 208139a53e0cSJaegeuk Kim FI_INC_LINK, /* need to increment i_nlink */ 208239a53e0cSJaegeuk Kim FI_ACL_MODE, /* indicate acl mode */ 208339a53e0cSJaegeuk Kim FI_NO_ALLOC, /* should not allocate any blocks */ 2084c9b63bd0SJaegeuk Kim FI_FREE_NID, /* free allocated nide */ 2085c11abd1aSJaegeuk Kim FI_NO_EXTENT, /* not to use the extent cache */ 2086444c580fSJaegeuk Kim FI_INLINE_XATTR, /* used for inline xattr */ 20871001b347SHuajun Li FI_INLINE_DATA, /* used for inline data*/ 208834d67debSChao Yu FI_INLINE_DENTRY, /* used for inline dentry */ 2089fff04f90SJaegeuk Kim FI_APPEND_WRITE, /* inode has appended data */ 2090fff04f90SJaegeuk Kim FI_UPDATE_WRITE, /* inode has in-place-update data */ 209188b88a66SJaegeuk Kim FI_NEED_IPU, /* used for ipu per file */ 209288b88a66SJaegeuk Kim FI_ATOMIC_FILE, /* indicate atomic file */ 20935fe45743SChao Yu FI_ATOMIC_COMMIT, /* indicate the state of atomical committing */ 209402a1335fSJaegeuk Kim FI_VOLATILE_FILE, /* indicate volatile file */ 20953c6c2bebSJaegeuk Kim FI_FIRST_BLOCK_WRITTEN, /* indicate #0 data block was written */ 20961e84371fSJaegeuk Kim FI_DROP_CACHE, /* drop dirty page cache */ 2097b3d208f9SJaegeuk Kim FI_DATA_EXIST, /* indicate data exists */ 2098510022a8SJaegeuk Kim FI_INLINE_DOTS, /* indicate inline dot dentries */ 2099d323d005SChao Yu FI_DO_DEFRAG, /* indicate defragment is running */ 2100c227f912SChao Yu FI_DIRTY_FILE, /* indicate regular/symlink has dirty pages */ 2101dc91de78SJaegeuk Kim FI_NO_PREALLOC, /* indicate skipped preallocated blocks */ 2102ef095d19SJaegeuk Kim FI_HOT_DATA, /* indicate file is hot */ 21037a2af766SChao Yu FI_EXTRA_ATTR, /* indicate file has extra attribute */ 21045c57132eSChao Yu FI_PROJ_INHERIT, /* indicate file inherits projectid */ 210539a53e0cSJaegeuk Kim }; 210639a53e0cSJaegeuk Kim 2107205b9822SJaegeuk Kim static inline void __mark_inode_dirty_flag(struct inode *inode, 2108205b9822SJaegeuk Kim int flag, bool set) 210939a53e0cSJaegeuk Kim { 2110205b9822SJaegeuk Kim switch (flag) { 2111205b9822SJaegeuk Kim case FI_INLINE_XATTR: 2112205b9822SJaegeuk Kim case FI_INLINE_DATA: 2113205b9822SJaegeuk Kim case FI_INLINE_DENTRY: 2114205b9822SJaegeuk Kim if (set) 2115205b9822SJaegeuk Kim return; 2116205b9822SJaegeuk Kim case FI_DATA_EXIST: 2117205b9822SJaegeuk Kim case FI_INLINE_DOTS: 21187c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2119205b9822SJaegeuk Kim } 212039a53e0cSJaegeuk Kim } 212139a53e0cSJaegeuk Kim 212291942321SJaegeuk Kim static inline void set_inode_flag(struct inode *inode, int flag) 212339a53e0cSJaegeuk Kim { 212491942321SJaegeuk Kim if (!test_bit(flag, &F2FS_I(inode)->flags)) 212591942321SJaegeuk Kim set_bit(flag, &F2FS_I(inode)->flags); 2126205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, true); 212739a53e0cSJaegeuk Kim } 212839a53e0cSJaegeuk Kim 212991942321SJaegeuk Kim static inline int is_inode_flag_set(struct inode *inode, int flag) 213039a53e0cSJaegeuk Kim { 213191942321SJaegeuk Kim return test_bit(flag, &F2FS_I(inode)->flags); 213239a53e0cSJaegeuk Kim } 213339a53e0cSJaegeuk Kim 213491942321SJaegeuk Kim static inline void clear_inode_flag(struct inode *inode, int flag) 213539a53e0cSJaegeuk Kim { 213691942321SJaegeuk Kim if (test_bit(flag, &F2FS_I(inode)->flags)) 213791942321SJaegeuk Kim clear_bit(flag, &F2FS_I(inode)->flags); 2138205b9822SJaegeuk Kim __mark_inode_dirty_flag(inode, flag, false); 213939a53e0cSJaegeuk Kim } 214039a53e0cSJaegeuk Kim 214191942321SJaegeuk Kim static inline void set_acl_inode(struct inode *inode, umode_t mode) 2142444c580fSJaegeuk Kim { 214391942321SJaegeuk Kim F2FS_I(inode)->i_acl_mode = mode; 214491942321SJaegeuk Kim set_inode_flag(inode, FI_ACL_MODE); 21457c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, false); 214639a53e0cSJaegeuk Kim } 214739a53e0cSJaegeuk Kim 2148a1961246SJaegeuk Kim static inline void f2fs_i_links_write(struct inode *inode, bool inc) 2149a1961246SJaegeuk Kim { 2150a1961246SJaegeuk Kim if (inc) 2151a1961246SJaegeuk Kim inc_nlink(inode); 2152a1961246SJaegeuk Kim else 2153a1961246SJaegeuk Kim drop_nlink(inode); 21547c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2155a1961246SJaegeuk Kim } 2156a1961246SJaegeuk Kim 21578edd03c8SJaegeuk Kim static inline void f2fs_i_blocks_write(struct inode *inode, 21580abd675eSChao Yu block_t diff, bool add, bool claim) 21598edd03c8SJaegeuk Kim { 216026de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 216126de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 216226de9b11SJaegeuk Kim 21630abd675eSChao Yu /* add = 1, claim = 1 should be dquot_reserve_block in pair */ 21640abd675eSChao Yu if (add) { 21650abd675eSChao Yu if (claim) 21660abd675eSChao Yu dquot_claim_block(inode, diff); 21670abd675eSChao Yu else 21680abd675eSChao Yu dquot_alloc_block_nofail(inode, diff); 21690abd675eSChao Yu } else { 21700abd675eSChao Yu dquot_free_block(inode, diff); 21710abd675eSChao Yu } 21720abd675eSChao Yu 21737c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 217426de9b11SJaegeuk Kim if (clean || recover) 217526de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 21768edd03c8SJaegeuk Kim } 21778edd03c8SJaegeuk Kim 2178fc9581c8SJaegeuk Kim static inline void f2fs_i_size_write(struct inode *inode, loff_t i_size) 2179fc9581c8SJaegeuk Kim { 218026de9b11SJaegeuk Kim bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 218126de9b11SJaegeuk Kim bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 218226de9b11SJaegeuk Kim 2183fc9581c8SJaegeuk Kim if (i_size_read(inode) == i_size) 2184fc9581c8SJaegeuk Kim return; 2185fc9581c8SJaegeuk Kim 2186fc9581c8SJaegeuk Kim i_size_write(inode, i_size); 21877c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 218826de9b11SJaegeuk Kim if (clean || recover) 218926de9b11SJaegeuk Kim set_inode_flag(inode, FI_AUTO_RECOVER); 219026de9b11SJaegeuk Kim } 219126de9b11SJaegeuk Kim 2192205b9822SJaegeuk Kim static inline void f2fs_i_depth_write(struct inode *inode, unsigned int depth) 2193205b9822SJaegeuk Kim { 2194205b9822SJaegeuk Kim F2FS_I(inode)->i_current_depth = depth; 21957c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2196205b9822SJaegeuk Kim } 2197205b9822SJaegeuk Kim 2198205b9822SJaegeuk Kim static inline void f2fs_i_xnid_write(struct inode *inode, nid_t xnid) 2199205b9822SJaegeuk Kim { 2200205b9822SJaegeuk Kim F2FS_I(inode)->i_xattr_nid = xnid; 22017c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2202205b9822SJaegeuk Kim } 2203205b9822SJaegeuk Kim 2204205b9822SJaegeuk Kim static inline void f2fs_i_pino_write(struct inode *inode, nid_t pino) 2205205b9822SJaegeuk Kim { 2206205b9822SJaegeuk Kim F2FS_I(inode)->i_pino = pino; 22077c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2208205b9822SJaegeuk Kim } 2209205b9822SJaegeuk Kim 221091942321SJaegeuk Kim static inline void get_inline_info(struct inode *inode, struct f2fs_inode *ri) 2211444c580fSJaegeuk Kim { 2212205b9822SJaegeuk Kim struct f2fs_inode_info *fi = F2FS_I(inode); 2213205b9822SJaegeuk Kim 2214444c580fSJaegeuk Kim if (ri->i_inline & F2FS_INLINE_XATTR) 2215205b9822SJaegeuk Kim set_bit(FI_INLINE_XATTR, &fi->flags); 22161001b347SHuajun Li if (ri->i_inline & F2FS_INLINE_DATA) 2217205b9822SJaegeuk Kim set_bit(FI_INLINE_DATA, &fi->flags); 221834d67debSChao Yu if (ri->i_inline & F2FS_INLINE_DENTRY) 2219205b9822SJaegeuk Kim set_bit(FI_INLINE_DENTRY, &fi->flags); 2220b3d208f9SJaegeuk Kim if (ri->i_inline & F2FS_DATA_EXIST) 2221205b9822SJaegeuk Kim set_bit(FI_DATA_EXIST, &fi->flags); 2222510022a8SJaegeuk Kim if (ri->i_inline & F2FS_INLINE_DOTS) 2223205b9822SJaegeuk Kim set_bit(FI_INLINE_DOTS, &fi->flags); 22247a2af766SChao Yu if (ri->i_inline & F2FS_EXTRA_ATTR) 22257a2af766SChao Yu set_bit(FI_EXTRA_ATTR, &fi->flags); 2226444c580fSJaegeuk Kim } 2227444c580fSJaegeuk Kim 222891942321SJaegeuk Kim static inline void set_raw_inline(struct inode *inode, struct f2fs_inode *ri) 2229444c580fSJaegeuk Kim { 2230444c580fSJaegeuk Kim ri->i_inline = 0; 2231444c580fSJaegeuk Kim 223291942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_XATTR)) 2233444c580fSJaegeuk Kim ri->i_inline |= F2FS_INLINE_XATTR; 223491942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DATA)) 22351001b347SHuajun Li ri->i_inline |= F2FS_INLINE_DATA; 223691942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DENTRY)) 223734d67debSChao Yu ri->i_inline |= F2FS_INLINE_DENTRY; 223891942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_DATA_EXIST)) 2239b3d208f9SJaegeuk Kim ri->i_inline |= F2FS_DATA_EXIST; 224091942321SJaegeuk Kim if (is_inode_flag_set(inode, FI_INLINE_DOTS)) 2241510022a8SJaegeuk Kim ri->i_inline |= F2FS_INLINE_DOTS; 22427a2af766SChao Yu if (is_inode_flag_set(inode, FI_EXTRA_ATTR)) 22437a2af766SChao Yu ri->i_inline |= F2FS_EXTRA_ATTR; 22447a2af766SChao Yu } 22457a2af766SChao Yu 22467a2af766SChao Yu static inline int f2fs_has_extra_attr(struct inode *inode) 22477a2af766SChao Yu { 22487a2af766SChao Yu return is_inode_flag_set(inode, FI_EXTRA_ATTR); 2249444c580fSJaegeuk Kim } 2250444c580fSJaegeuk Kim 2251987c7c31SChao Yu static inline int f2fs_has_inline_xattr(struct inode *inode) 2252987c7c31SChao Yu { 225391942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_XATTR); 2254987c7c31SChao Yu } 2255987c7c31SChao Yu 225681ca7350SChao Yu static inline unsigned int addrs_per_inode(struct inode *inode) 2257de93653fSJaegeuk Kim { 22586afc662eSChao Yu return CUR_ADDRS_PER_INODE(inode) - F2FS_INLINE_XATTR_ADDRS(inode); 2259de93653fSJaegeuk Kim } 2260de93653fSJaegeuk Kim 22616afc662eSChao Yu static inline void *inline_xattr_addr(struct inode *inode, struct page *page) 226265985d93SJaegeuk Kim { 2263695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 2264cac5a3d8SDongOh Shin 226565985d93SJaegeuk Kim return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - 22666afc662eSChao Yu F2FS_INLINE_XATTR_ADDRS(inode)]); 226765985d93SJaegeuk Kim } 226865985d93SJaegeuk Kim 226965985d93SJaegeuk Kim static inline int inline_xattr_size(struct inode *inode) 227065985d93SJaegeuk Kim { 22716afc662eSChao Yu return get_inline_xattr_addrs(inode) * sizeof(__le32); 227265985d93SJaegeuk Kim } 227365985d93SJaegeuk Kim 22740dbdc2aeSJaegeuk Kim static inline int f2fs_has_inline_data(struct inode *inode) 22750dbdc2aeSJaegeuk Kim { 227691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DATA); 22770dbdc2aeSJaegeuk Kim } 22780dbdc2aeSJaegeuk Kim 2279b3d208f9SJaegeuk Kim static inline int f2fs_exist_data(struct inode *inode) 2280b3d208f9SJaegeuk Kim { 228191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DATA_EXIST); 2282b3d208f9SJaegeuk Kim } 2283b3d208f9SJaegeuk Kim 2284510022a8SJaegeuk Kim static inline int f2fs_has_inline_dots(struct inode *inode) 2285510022a8SJaegeuk Kim { 228691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DOTS); 2287510022a8SJaegeuk Kim } 2288510022a8SJaegeuk Kim 228988b88a66SJaegeuk Kim static inline bool f2fs_is_atomic_file(struct inode *inode) 229088b88a66SJaegeuk Kim { 229191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_ATOMIC_FILE); 229288b88a66SJaegeuk Kim } 229388b88a66SJaegeuk Kim 22945fe45743SChao Yu static inline bool f2fs_is_commit_atomic_write(struct inode *inode) 22955fe45743SChao Yu { 22965fe45743SChao Yu return is_inode_flag_set(inode, FI_ATOMIC_COMMIT); 22975fe45743SChao Yu } 22985fe45743SChao Yu 229902a1335fSJaegeuk Kim static inline bool f2fs_is_volatile_file(struct inode *inode) 230002a1335fSJaegeuk Kim { 230191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_VOLATILE_FILE); 230202a1335fSJaegeuk Kim } 230302a1335fSJaegeuk Kim 23043c6c2bebSJaegeuk Kim static inline bool f2fs_is_first_block_written(struct inode *inode) 23053c6c2bebSJaegeuk Kim { 230691942321SJaegeuk Kim return is_inode_flag_set(inode, FI_FIRST_BLOCK_WRITTEN); 23073c6c2bebSJaegeuk Kim } 23083c6c2bebSJaegeuk Kim 23091e84371fSJaegeuk Kim static inline bool f2fs_is_drop_cache(struct inode *inode) 23101e84371fSJaegeuk Kim { 231191942321SJaegeuk Kim return is_inode_flag_set(inode, FI_DROP_CACHE); 23121e84371fSJaegeuk Kim } 23131e84371fSJaegeuk Kim 2314f2470371SChao Yu static inline void *inline_data_addr(struct inode *inode, struct page *page) 23151001b347SHuajun Li { 2316695fd1edSChao Yu struct f2fs_inode *ri = F2FS_INODE(page); 23177a2af766SChao Yu int extra_size = get_extra_isize(inode); 2318cac5a3d8SDongOh Shin 23197a2af766SChao Yu return (void *)&(ri->i_addr[extra_size + DEF_INLINE_RESERVED_SIZE]); 23201001b347SHuajun Li } 23211001b347SHuajun Li 232234d67debSChao Yu static inline int f2fs_has_inline_dentry(struct inode *inode) 232334d67debSChao Yu { 232491942321SJaegeuk Kim return is_inode_flag_set(inode, FI_INLINE_DENTRY); 232534d67debSChao Yu } 232634d67debSChao Yu 23279486ba44SJaegeuk Kim static inline void f2fs_dentry_kunmap(struct inode *dir, struct page *page) 23289486ba44SJaegeuk Kim { 23299486ba44SJaegeuk Kim if (!f2fs_has_inline_dentry(dir)) 23309486ba44SJaegeuk Kim kunmap(page); 23319486ba44SJaegeuk Kim } 23329486ba44SJaegeuk Kim 2333b5492af7SJaegeuk Kim static inline int is_file(struct inode *inode, int type) 2334b5492af7SJaegeuk Kim { 2335b5492af7SJaegeuk Kim return F2FS_I(inode)->i_advise & type; 2336b5492af7SJaegeuk Kim } 2337b5492af7SJaegeuk Kim 2338b5492af7SJaegeuk Kim static inline void set_file(struct inode *inode, int type) 2339b5492af7SJaegeuk Kim { 2340b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise |= type; 23417c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2342b5492af7SJaegeuk Kim } 2343b5492af7SJaegeuk Kim 2344b5492af7SJaegeuk Kim static inline void clear_file(struct inode *inode, int type) 2345b5492af7SJaegeuk Kim { 2346b5492af7SJaegeuk Kim F2FS_I(inode)->i_advise &= ~type; 23477c45729aSJaegeuk Kim f2fs_mark_inode_dirty_sync(inode, true); 2348b5492af7SJaegeuk Kim } 2349b5492af7SJaegeuk Kim 235026787236SJaegeuk Kim static inline bool f2fs_skip_inode_update(struct inode *inode, int dsync) 235126787236SJaegeuk Kim { 2352a0d00fadSChao Yu bool ret; 2353a0d00fadSChao Yu 235426787236SJaegeuk Kim if (dsync) { 235526787236SJaegeuk Kim struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 235626787236SJaegeuk Kim 235726787236SJaegeuk Kim spin_lock(&sbi->inode_lock[DIRTY_META]); 235826787236SJaegeuk Kim ret = list_empty(&F2FS_I(inode)->gdirty_list); 235926787236SJaegeuk Kim spin_unlock(&sbi->inode_lock[DIRTY_META]); 236026787236SJaegeuk Kim return ret; 236126787236SJaegeuk Kim } 236226787236SJaegeuk Kim if (!is_inode_flag_set(inode, FI_AUTO_RECOVER) || 236326787236SJaegeuk Kim file_keep_isize(inode) || 236426787236SJaegeuk Kim i_size_read(inode) & PAGE_MASK) 236526787236SJaegeuk Kim return false; 2366a0d00fadSChao Yu 2367a0d00fadSChao Yu down_read(&F2FS_I(inode)->i_sem); 2368a0d00fadSChao Yu ret = F2FS_I(inode)->last_disk_size == i_size_read(inode); 2369a0d00fadSChao Yu up_read(&F2FS_I(inode)->i_sem); 2370a0d00fadSChao Yu 2371a0d00fadSChao Yu return ret; 2372267378d4SChao Yu } 2373267378d4SChao Yu 2374267378d4SChao Yu static inline int f2fs_readonly(struct super_block *sb) 2375267378d4SChao Yu { 2376267378d4SChao Yu return sb->s_flags & MS_RDONLY; 2377267378d4SChao Yu } 237839a53e0cSJaegeuk Kim 237939a53e0cSJaegeuk Kim static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) 238039a53e0cSJaegeuk Kim { 2381aaec2b1dSChao Yu return is_set_ckpt_flags(sbi, CP_ERROR_FLAG); 238239a53e0cSJaegeuk Kim } 238339a53e0cSJaegeuk Kim 2384eaa693f4SJaegeuk Kim static inline bool is_dot_dotdot(const struct qstr *str) 2385eaa693f4SJaegeuk Kim { 2386eaa693f4SJaegeuk Kim if (str->len == 1 && str->name[0] == '.') 2387eaa693f4SJaegeuk Kim return true; 2388eaa693f4SJaegeuk Kim 2389eaa693f4SJaegeuk Kim if (str->len == 2 && str->name[0] == '.' && str->name[1] == '.') 2390eaa693f4SJaegeuk Kim return true; 2391eaa693f4SJaegeuk Kim 2392eaa693f4SJaegeuk Kim return false; 2393eaa693f4SJaegeuk Kim } 2394eaa693f4SJaegeuk Kim 23953e72f721SJaegeuk Kim static inline bool f2fs_may_extent_tree(struct inode *inode) 23963e72f721SJaegeuk Kim { 23973e72f721SJaegeuk Kim if (!test_opt(F2FS_I_SB(inode), EXTENT_CACHE) || 239891942321SJaegeuk Kim is_inode_flag_set(inode, FI_NO_EXTENT)) 23993e72f721SJaegeuk Kim return false; 24003e72f721SJaegeuk Kim 2401886f56f9SAl Viro return S_ISREG(inode->i_mode); 24023e72f721SJaegeuk Kim } 24033e72f721SJaegeuk Kim 24041ecc0c5cSChao Yu static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, 24051ecc0c5cSChao Yu size_t size, gfp_t flags) 24060414b004SJaegeuk Kim { 24072c63feadSJaegeuk Kim #ifdef CONFIG_F2FS_FAULT_INJECTION 240855523519SChao Yu if (time_to_inject(sbi, FAULT_KMALLOC)) { 240955523519SChao Yu f2fs_show_injection_info(FAULT_KMALLOC); 24102c63feadSJaegeuk Kim return NULL; 241155523519SChao Yu } 24122c63feadSJaegeuk Kim #endif 24130414b004SJaegeuk Kim return kmalloc(size, flags); 24140414b004SJaegeuk Kim } 24150414b004SJaegeuk Kim 24167a2af766SChao Yu static inline int get_extra_isize(struct inode *inode) 2417f2470371SChao Yu { 24187a2af766SChao Yu return F2FS_I(inode)->i_extra_isize / sizeof(__le32); 2419f2470371SChao Yu } 2420f2470371SChao Yu 24216afc662eSChao Yu static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb); 24226afc662eSChao Yu static inline int get_inline_xattr_addrs(struct inode *inode) 24236afc662eSChao Yu { 24246afc662eSChao Yu return F2FS_I(inode)->i_inline_xattr_size; 24256afc662eSChao Yu } 24266afc662eSChao Yu 242739a53e0cSJaegeuk Kim #define get_inode_mode(i) \ 242891942321SJaegeuk Kim ((is_inode_flag_set(i, FI_ACL_MODE)) ? \ 242939a53e0cSJaegeuk Kim (F2FS_I(i)->i_acl_mode) : ((i)->i_mode)) 243039a53e0cSJaegeuk Kim 24317a2af766SChao Yu #define F2FS_TOTAL_EXTRA_ATTR_SIZE \ 24327a2af766SChao Yu (offsetof(struct f2fs_inode, i_extra_end) - \ 24337a2af766SChao Yu offsetof(struct f2fs_inode, i_extra_isize)) \ 24347a2af766SChao Yu 24355c57132eSChao Yu #define F2FS_OLD_ATTRIBUTE_SIZE (offsetof(struct f2fs_inode, i_addr)) 24365c57132eSChao Yu #define F2FS_FITS_IN_INODE(f2fs_inode, extra_isize, field) \ 24375c57132eSChao Yu ((offsetof(typeof(*f2fs_inode), field) + \ 24385c57132eSChao Yu sizeof((f2fs_inode)->field)) \ 24395c57132eSChao Yu <= (F2FS_OLD_ATTRIBUTE_SIZE + extra_isize)) \ 24405c57132eSChao Yu 2441b0af6d49SChao Yu static inline void f2fs_reset_iostat(struct f2fs_sb_info *sbi) 2442b0af6d49SChao Yu { 2443b0af6d49SChao Yu int i; 2444b0af6d49SChao Yu 2445b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2446b0af6d49SChao Yu for (i = 0; i < NR_IO_TYPE; i++) 2447b0af6d49SChao Yu sbi->write_iostat[i] = 0; 2448b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2449b0af6d49SChao Yu } 2450b0af6d49SChao Yu 2451b0af6d49SChao Yu static inline void f2fs_update_iostat(struct f2fs_sb_info *sbi, 2452b0af6d49SChao Yu enum iostat_type type, unsigned long long io_bytes) 2453b0af6d49SChao Yu { 2454b0af6d49SChao Yu if (!sbi->iostat_enable) 2455b0af6d49SChao Yu return; 2456b0af6d49SChao Yu spin_lock(&sbi->iostat_lock); 2457b0af6d49SChao Yu sbi->write_iostat[type] += io_bytes; 2458b0af6d49SChao Yu 2459b0af6d49SChao Yu if (type == APP_WRITE_IO || type == APP_DIRECT_IO) 2460b0af6d49SChao Yu sbi->write_iostat[APP_BUFFERED_IO] = 2461b0af6d49SChao Yu sbi->write_iostat[APP_WRITE_IO] - 2462b0af6d49SChao Yu sbi->write_iostat[APP_DIRECT_IO]; 2463b0af6d49SChao Yu spin_unlock(&sbi->iostat_lock); 2464b0af6d49SChao Yu } 2465b0af6d49SChao Yu 246639a53e0cSJaegeuk Kim /* 246739a53e0cSJaegeuk Kim * file.c 246839a53e0cSJaegeuk Kim */ 2469cac5a3d8SDongOh Shin int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync); 2470cac5a3d8SDongOh Shin void truncate_data_blocks(struct dnode_of_data *dn); 2471cac5a3d8SDongOh Shin int truncate_blocks(struct inode *inode, u64 from, bool lock); 2472cac5a3d8SDongOh Shin int f2fs_truncate(struct inode *inode); 2473a528d35eSDavid Howells int f2fs_getattr(const struct path *path, struct kstat *stat, 2474a528d35eSDavid Howells u32 request_mask, unsigned int flags); 2475cac5a3d8SDongOh Shin int f2fs_setattr(struct dentry *dentry, struct iattr *attr); 2476cac5a3d8SDongOh Shin int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end); 2477cac5a3d8SDongOh Shin int truncate_data_blocks_range(struct dnode_of_data *dn, int count); 2478cac5a3d8SDongOh Shin long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 2479cac5a3d8SDongOh Shin long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 248039a53e0cSJaegeuk Kim 248139a53e0cSJaegeuk Kim /* 248239a53e0cSJaegeuk Kim * inode.c 248339a53e0cSJaegeuk Kim */ 2484cac5a3d8SDongOh Shin void f2fs_set_inode_flags(struct inode *inode); 2485704956ecSChao Yu bool f2fs_inode_chksum_verify(struct f2fs_sb_info *sbi, struct page *page); 2486704956ecSChao Yu void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page); 2487cac5a3d8SDongOh Shin struct inode *f2fs_iget(struct super_block *sb, unsigned long ino); 2488cac5a3d8SDongOh Shin struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino); 2489cac5a3d8SDongOh Shin int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink); 2490cac5a3d8SDongOh Shin int update_inode(struct inode *inode, struct page *node_page); 2491cac5a3d8SDongOh Shin int update_inode_page(struct inode *inode); 2492cac5a3d8SDongOh Shin int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc); 2493cac5a3d8SDongOh Shin void f2fs_evict_inode(struct inode *inode); 2494cac5a3d8SDongOh Shin void handle_failed_inode(struct inode *inode); 249539a53e0cSJaegeuk Kim 249639a53e0cSJaegeuk Kim /* 249739a53e0cSJaegeuk Kim * namei.c 249839a53e0cSJaegeuk Kim */ 249939a53e0cSJaegeuk Kim struct dentry *f2fs_get_parent(struct dentry *child); 250039a53e0cSJaegeuk Kim 250139a53e0cSJaegeuk Kim /* 250239a53e0cSJaegeuk Kim * dir.c 250339a53e0cSJaegeuk Kim */ 2504cac5a3d8SDongOh Shin void set_de_type(struct f2fs_dir_entry *de, umode_t mode); 2505cac5a3d8SDongOh Shin unsigned char get_de_type(struct f2fs_dir_entry *de); 2506cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *fname, 2507cac5a3d8SDongOh Shin f2fs_hash_t namehash, int *max_slots, 2508cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2509cac5a3d8SDongOh Shin int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, 2510cac5a3d8SDongOh Shin unsigned int start_pos, struct fscrypt_str *fstr); 2511cac5a3d8SDongOh Shin void do_make_empty_dir(struct inode *inode, struct inode *parent, 2512cac5a3d8SDongOh Shin struct f2fs_dentry_ptr *d); 2513cac5a3d8SDongOh Shin struct page *init_inode_metadata(struct inode *inode, struct inode *dir, 2514cac5a3d8SDongOh Shin const struct qstr *new_name, 2515cac5a3d8SDongOh Shin const struct qstr *orig_name, struct page *dpage); 2516cac5a3d8SDongOh Shin void update_parent_metadata(struct inode *dir, struct inode *inode, 2517cac5a3d8SDongOh Shin unsigned int current_depth); 2518cac5a3d8SDongOh Shin int room_for_filename(const void *bitmap, int slots, int max_slots); 2519cac5a3d8SDongOh Shin void f2fs_drop_nlink(struct inode *dir, struct inode *inode); 2520cac5a3d8SDongOh Shin struct f2fs_dir_entry *__f2fs_find_entry(struct inode *dir, 2521cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2522cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_find_entry(struct inode *dir, 2523cac5a3d8SDongOh Shin const struct qstr *child, struct page **res_page); 2524cac5a3d8SDongOh Shin struct f2fs_dir_entry *f2fs_parent_dir(struct inode *dir, struct page **p); 2525cac5a3d8SDongOh Shin ino_t f2fs_inode_by_name(struct inode *dir, const struct qstr *qstr, 2526cac5a3d8SDongOh Shin struct page **page); 2527cac5a3d8SDongOh Shin void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de, 2528cac5a3d8SDongOh Shin struct page *page, struct inode *inode); 2529cac5a3d8SDongOh Shin void f2fs_update_dentry(nid_t ino, umode_t mode, struct f2fs_dentry_ptr *d, 2530cac5a3d8SDongOh Shin const struct qstr *name, f2fs_hash_t name_hash, 2531cac5a3d8SDongOh Shin unsigned int bit_pos); 2532cac5a3d8SDongOh Shin int f2fs_add_regular_entry(struct inode *dir, const struct qstr *new_name, 2533cac5a3d8SDongOh Shin const struct qstr *orig_name, 2534cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2535cac5a3d8SDongOh Shin int __f2fs_do_add_link(struct inode *dir, struct fscrypt_name *fname, 2536cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2537cac5a3d8SDongOh Shin int __f2fs_add_link(struct inode *dir, const struct qstr *name, 2538cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2539cac5a3d8SDongOh Shin void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, 2540cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2541cac5a3d8SDongOh Shin int f2fs_do_tmpfile(struct inode *inode, struct inode *dir); 2542cac5a3d8SDongOh Shin bool f2fs_empty_dir(struct inode *dir); 254339a53e0cSJaegeuk Kim 2544b7f7a5e0SAl Viro static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode) 2545b7f7a5e0SAl Viro { 25462b0143b5SDavid Howells return __f2fs_add_link(d_inode(dentry->d_parent), &dentry->d_name, 2547510022a8SJaegeuk Kim inode, inode->i_ino, inode->i_mode); 2548b7f7a5e0SAl Viro } 2549b7f7a5e0SAl Viro 255039a53e0cSJaegeuk Kim /* 255139a53e0cSJaegeuk Kim * super.c 255239a53e0cSJaegeuk Kim */ 2553cac5a3d8SDongOh Shin int f2fs_inode_dirtied(struct inode *inode, bool sync); 2554cac5a3d8SDongOh Shin void f2fs_inode_synced(struct inode *inode); 2555ea676733SJaegeuk Kim int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); 25564b2414d0SChao Yu void f2fs_quota_off_umount(struct super_block *sb); 2557cac5a3d8SDongOh Shin int f2fs_commit_super(struct f2fs_sb_info *sbi, bool recover); 2558cac5a3d8SDongOh Shin int f2fs_sync_fs(struct super_block *sb, int sync); 2559a07ef784SNamjae Jeon extern __printf(3, 4) 2560cac5a3d8SDongOh Shin void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...); 2561984ec63cSShawn Lin int sanity_check_ckpt(struct f2fs_sb_info *sbi); 256239a53e0cSJaegeuk Kim 256339a53e0cSJaegeuk Kim /* 256439a53e0cSJaegeuk Kim * hash.c 256539a53e0cSJaegeuk Kim */ 25666332cd32SJaegeuk Kim f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info, 25676332cd32SJaegeuk Kim struct fscrypt_name *fname); 256839a53e0cSJaegeuk Kim 256939a53e0cSJaegeuk Kim /* 257039a53e0cSJaegeuk Kim * node.c 257139a53e0cSJaegeuk Kim */ 257239a53e0cSJaegeuk Kim struct dnode_of_data; 257339a53e0cSJaegeuk Kim struct node_info; 257439a53e0cSJaegeuk Kim 2575cac5a3d8SDongOh Shin bool available_free_memory(struct f2fs_sb_info *sbi, int type); 2576cac5a3d8SDongOh Shin int need_dentry_mark(struct f2fs_sb_info *sbi, nid_t nid); 2577cac5a3d8SDongOh Shin bool is_checkpointed_node(struct f2fs_sb_info *sbi, nid_t nid); 2578cac5a3d8SDongOh Shin bool need_inode_block_update(struct f2fs_sb_info *sbi, nid_t ino); 2579cac5a3d8SDongOh Shin void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni); 2580cac5a3d8SDongOh Shin pgoff_t get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs); 2581cac5a3d8SDongOh Shin int get_dnode_of_data(struct dnode_of_data *dn, pgoff_t index, int mode); 2582cac5a3d8SDongOh Shin int truncate_inode_blocks(struct inode *inode, pgoff_t from); 25839c77f754SJaegeuk Kim int truncate_xattr_node(struct inode *inode); 2584cac5a3d8SDongOh Shin int wait_on_node_pages_writeback(struct f2fs_sb_info *sbi, nid_t ino); 2585cac5a3d8SDongOh Shin int remove_inode_page(struct inode *inode); 2586cac5a3d8SDongOh Shin struct page *new_inode_page(struct inode *inode); 25875f4ce6abSYunlei He struct page *new_node_page(struct dnode_of_data *dn, unsigned int ofs); 2588cac5a3d8SDongOh Shin void ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2589cac5a3d8SDongOh Shin struct page *get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2590cac5a3d8SDongOh Shin struct page *get_node_page_ra(struct page *parent, int start); 2591cac5a3d8SDongOh Shin void move_node_page(struct page *node_page, int gc_type); 2592cac5a3d8SDongOh Shin int fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2593cac5a3d8SDongOh Shin struct writeback_control *wbc, bool atomic); 2594401db79fSYunlong Song int sync_node_pages(struct f2fs_sb_info *sbi, struct writeback_control *wbc, 2595b0af6d49SChao Yu bool do_balance, enum iostat_type io_type); 259622ad0b6aSJaegeuk Kim void build_free_nids(struct f2fs_sb_info *sbi, bool sync, bool mount); 2597cac5a3d8SDongOh Shin bool alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid); 2598cac5a3d8SDongOh Shin void alloc_nid_done(struct f2fs_sb_info *sbi, nid_t nid); 2599cac5a3d8SDongOh Shin void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid); 2600cac5a3d8SDongOh Shin int try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink); 2601cac5a3d8SDongOh Shin void recover_inline_xattr(struct inode *inode, struct page *page); 2602d260081cSChao Yu int recover_xattr_data(struct inode *inode, struct page *page, 2603cac5a3d8SDongOh Shin block_t blkaddr); 2604cac5a3d8SDongOh Shin int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page); 2605cac5a3d8SDongOh Shin int restore_node_summary(struct f2fs_sb_info *sbi, 2606cac5a3d8SDongOh Shin unsigned int segno, struct f2fs_summary_block *sum); 260722ad0b6aSJaegeuk Kim void flush_nat_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2608cac5a3d8SDongOh Shin int build_node_manager(struct f2fs_sb_info *sbi); 2609cac5a3d8SDongOh Shin void destroy_node_manager(struct f2fs_sb_info *sbi); 26106e6093a8SNamjae Jeon int __init create_node_manager_caches(void); 261139a53e0cSJaegeuk Kim void destroy_node_manager_caches(void); 261239a53e0cSJaegeuk Kim 261339a53e0cSJaegeuk Kim /* 261439a53e0cSJaegeuk Kim * segment.c 261539a53e0cSJaegeuk Kim */ 2616b3a97a2aSJaegeuk Kim bool need_SSR(struct f2fs_sb_info *sbi); 2617cac5a3d8SDongOh Shin void register_inmem_page(struct inode *inode, struct page *page); 261857864ae5SJaegeuk Kim void drop_inmem_pages_all(struct f2fs_sb_info *sbi); 2619cac5a3d8SDongOh Shin void drop_inmem_pages(struct inode *inode); 26208c242db9SJaegeuk Kim void drop_inmem_page(struct inode *inode, struct page *page); 2621cac5a3d8SDongOh Shin int commit_inmem_pages(struct inode *inode); 2622cac5a3d8SDongOh Shin void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need); 2623cac5a3d8SDongOh Shin void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi); 262439d787beSChao Yu int f2fs_issue_flush(struct f2fs_sb_info *sbi, nid_t ino); 2625cac5a3d8SDongOh Shin int create_flush_cmd_control(struct f2fs_sb_info *sbi); 26261228b482SChao Yu int f2fs_flush_device_cache(struct f2fs_sb_info *sbi); 2627cac5a3d8SDongOh Shin void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free); 2628cac5a3d8SDongOh Shin void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2629cac5a3d8SDongOh Shin bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 263078997b56SChao Yu void init_discard_policy(struct discard_policy *dpolicy, int discard_type, 263178997b56SChao Yu unsigned int granularity); 2632cce13252SChao Yu void stop_discard_thread(struct f2fs_sb_info *sbi); 2633cf5c759fSChao Yu bool f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2634cac5a3d8SDongOh Shin void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2635cac5a3d8SDongOh Shin void release_discard_addrs(struct f2fs_sb_info *sbi); 2636cac5a3d8SDongOh Shin int npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra); 2637cac5a3d8SDongOh Shin void allocate_new_segments(struct f2fs_sb_info *sbi); 2638cac5a3d8SDongOh Shin int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); 2639cac5a3d8SDongOh Shin bool exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2640cac5a3d8SDongOh Shin struct page *get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno); 2641cac5a3d8SDongOh Shin void update_meta_page(struct f2fs_sb_info *sbi, void *src, block_t blk_addr); 2642b0af6d49SChao Yu void write_meta_page(struct f2fs_sb_info *sbi, struct page *page, 2643b0af6d49SChao Yu enum iostat_type io_type); 2644cac5a3d8SDongOh Shin void write_node_page(unsigned int nid, struct f2fs_io_info *fio); 2645cac5a3d8SDongOh Shin void write_data_page(struct dnode_of_data *dn, struct f2fs_io_info *fio); 2646d1b3e72dSJaegeuk Kim int rewrite_data_page(struct f2fs_io_info *fio); 2647cac5a3d8SDongOh Shin void __f2fs_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 2648cac5a3d8SDongOh Shin block_t old_blkaddr, block_t new_blkaddr, 2649cac5a3d8SDongOh Shin bool recover_curseg, bool recover_newaddr); 2650cac5a3d8SDongOh Shin void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, 2651cac5a3d8SDongOh Shin block_t old_addr, block_t new_addr, 2652cac5a3d8SDongOh Shin unsigned char version, bool recover_curseg, 2653cac5a3d8SDongOh Shin bool recover_newaddr); 2654cac5a3d8SDongOh Shin void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2655cac5a3d8SDongOh Shin block_t old_blkaddr, block_t *new_blkaddr, 2656fb830fc5SChao Yu struct f2fs_summary *sum, int type, 2657fb830fc5SChao Yu struct f2fs_io_info *fio, bool add_list); 2658cac5a3d8SDongOh Shin void f2fs_wait_on_page_writeback(struct page *page, 2659cac5a3d8SDongOh Shin enum page_type type, bool ordered); 2660d4c759eeSJaegeuk Kim void f2fs_wait_on_block_writeback(struct f2fs_sb_info *sbi, block_t blkaddr); 2661cac5a3d8SDongOh Shin void write_data_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2662cac5a3d8SDongOh Shin void write_node_summaries(struct f2fs_sb_info *sbi, block_t start_blk); 2663cac5a3d8SDongOh Shin int lookup_journal_in_cursum(struct f2fs_journal *journal, int type, 2664cac5a3d8SDongOh Shin unsigned int val, int alloc); 2665cac5a3d8SDongOh Shin void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2666cac5a3d8SDongOh Shin int build_segment_manager(struct f2fs_sb_info *sbi); 2667cac5a3d8SDongOh Shin void destroy_segment_manager(struct f2fs_sb_info *sbi); 26687fd9e544SJaegeuk Kim int __init create_segment_manager_caches(void); 26697fd9e544SJaegeuk Kim void destroy_segment_manager_caches(void); 267039a53e0cSJaegeuk Kim 267139a53e0cSJaegeuk Kim /* 267239a53e0cSJaegeuk Kim * checkpoint.c 267339a53e0cSJaegeuk Kim */ 2674cac5a3d8SDongOh Shin void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io); 2675cac5a3d8SDongOh Shin struct page *grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2676cac5a3d8SDongOh Shin struct page *get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index); 2677cac5a3d8SDongOh Shin struct page *get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index); 2678cac5a3d8SDongOh Shin bool is_valid_blkaddr(struct f2fs_sb_info *sbi, block_t blkaddr, int type); 2679cac5a3d8SDongOh Shin int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, 2680cac5a3d8SDongOh Shin int type, bool sync); 2681cac5a3d8SDongOh Shin void ra_meta_pages_cond(struct f2fs_sb_info *sbi, pgoff_t index); 2682cac5a3d8SDongOh Shin long sync_meta_pages(struct f2fs_sb_info *sbi, enum page_type type, 2683b0af6d49SChao Yu long nr_to_write, enum iostat_type io_type); 2684cac5a3d8SDongOh Shin void add_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2685cac5a3d8SDongOh Shin void remove_ino_entry(struct f2fs_sb_info *sbi, nid_t ino, int type); 2686cac5a3d8SDongOh Shin void release_ino_entry(struct f2fs_sb_info *sbi, bool all); 2687cac5a3d8SDongOh Shin bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode); 268839d787beSChao Yu void set_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 268939d787beSChao Yu unsigned int devidx, int type); 269039d787beSChao Yu bool is_dirty_device(struct f2fs_sb_info *sbi, nid_t ino, 269139d787beSChao Yu unsigned int devidx, int type); 2692cac5a3d8SDongOh Shin int f2fs_sync_inode_meta(struct f2fs_sb_info *sbi); 2693cac5a3d8SDongOh Shin int acquire_orphan_inode(struct f2fs_sb_info *sbi); 2694cac5a3d8SDongOh Shin void release_orphan_inode(struct f2fs_sb_info *sbi); 2695cac5a3d8SDongOh Shin void add_orphan_inode(struct inode *inode); 2696cac5a3d8SDongOh Shin void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino); 2697cac5a3d8SDongOh Shin int recover_orphan_inodes(struct f2fs_sb_info *sbi); 2698cac5a3d8SDongOh Shin int get_valid_checkpoint(struct f2fs_sb_info *sbi); 2699cac5a3d8SDongOh Shin void update_dirty_page(struct inode *inode, struct page *page); 2700cac5a3d8SDongOh Shin void remove_dirty_inode(struct inode *inode); 2701cac5a3d8SDongOh Shin int sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type); 2702cac5a3d8SDongOh Shin int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2703cac5a3d8SDongOh Shin void init_ino_entry_info(struct f2fs_sb_info *sbi); 27046e6093a8SNamjae Jeon int __init create_checkpoint_caches(void); 270539a53e0cSJaegeuk Kim void destroy_checkpoint_caches(void); 270639a53e0cSJaegeuk Kim 270739a53e0cSJaegeuk Kim /* 270839a53e0cSJaegeuk Kim * data.c 270939a53e0cSJaegeuk Kim */ 2710b9109b0eSJaegeuk Kim void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type); 2711b9109b0eSJaegeuk Kim void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi, 2712942fd319SJaegeuk Kim struct inode *inode, nid_t ino, pgoff_t idx, 2713b9109b0eSJaegeuk Kim enum page_type type); 2714b9109b0eSJaegeuk Kim void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi); 2715cac5a3d8SDongOh Shin int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2716b9109b0eSJaegeuk Kim int f2fs_submit_page_write(struct f2fs_io_info *fio); 2717cac5a3d8SDongOh Shin struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2718cac5a3d8SDongOh Shin block_t blk_addr, struct bio *bio); 2719cac5a3d8SDongOh Shin int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2720cac5a3d8SDongOh Shin void set_data_blkaddr(struct dnode_of_data *dn); 2721cac5a3d8SDongOh Shin void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr); 2722cac5a3d8SDongOh Shin int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count); 2723cac5a3d8SDongOh Shin int reserve_new_block(struct dnode_of_data *dn); 2724cac5a3d8SDongOh Shin int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index); 2725cac5a3d8SDongOh Shin int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from); 2726cac5a3d8SDongOh Shin int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index); 2727cac5a3d8SDongOh Shin struct page *get_read_data_page(struct inode *inode, pgoff_t index, 2728cac5a3d8SDongOh Shin int op_flags, bool for_write); 2729cac5a3d8SDongOh Shin struct page *find_data_page(struct inode *inode, pgoff_t index); 2730cac5a3d8SDongOh Shin struct page *get_lock_data_page(struct inode *inode, pgoff_t index, 2731cac5a3d8SDongOh Shin bool for_write); 2732cac5a3d8SDongOh Shin struct page *get_new_data_page(struct inode *inode, 2733cac5a3d8SDongOh Shin struct page *ipage, pgoff_t index, bool new_i_size); 2734cac5a3d8SDongOh Shin int do_write_data_page(struct f2fs_io_info *fio); 2735cac5a3d8SDongOh Shin int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, 2736cac5a3d8SDongOh Shin int create, int flag); 2737cac5a3d8SDongOh Shin int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 2738cac5a3d8SDongOh Shin u64 start, u64 len); 2739cac5a3d8SDongOh Shin void f2fs_set_page_dirty_nobuffers(struct page *page); 2740b0af6d49SChao Yu int __f2fs_write_data_pages(struct address_space *mapping, 2741b0af6d49SChao Yu struct writeback_control *wbc, 2742b0af6d49SChao Yu enum iostat_type io_type); 2743cac5a3d8SDongOh Shin void f2fs_invalidate_page(struct page *page, unsigned int offset, 2744cac5a3d8SDongOh Shin unsigned int length); 2745cac5a3d8SDongOh Shin int f2fs_release_page(struct page *page, gfp_t wait); 27465b7a487cSWeichao Guo #ifdef CONFIG_MIGRATION 2747cac5a3d8SDongOh Shin int f2fs_migrate_page(struct address_space *mapping, struct page *newpage, 2748cac5a3d8SDongOh Shin struct page *page, enum migrate_mode mode); 27495b7a487cSWeichao Guo #endif 275039a53e0cSJaegeuk Kim 275139a53e0cSJaegeuk Kim /* 275239a53e0cSJaegeuk Kim * gc.c 275339a53e0cSJaegeuk Kim */ 2754cac5a3d8SDongOh Shin int start_gc_thread(struct f2fs_sb_info *sbi); 2755cac5a3d8SDongOh Shin void stop_gc_thread(struct f2fs_sb_info *sbi); 2756cac5a3d8SDongOh Shin block_t start_bidx_of_node(unsigned int node_ofs, struct inode *inode); 2757e066b83cSJaegeuk Kim int f2fs_gc(struct f2fs_sb_info *sbi, bool sync, bool background, 2758e066b83cSJaegeuk Kim unsigned int segno); 2759cac5a3d8SDongOh Shin void build_gc_manager(struct f2fs_sb_info *sbi); 276039a53e0cSJaegeuk Kim 276139a53e0cSJaegeuk Kim /* 276239a53e0cSJaegeuk Kim * recovery.c 276339a53e0cSJaegeuk Kim */ 2764cac5a3d8SDongOh Shin int recover_fsync_data(struct f2fs_sb_info *sbi, bool check_only); 2765cac5a3d8SDongOh Shin bool space_for_roll_forward(struct f2fs_sb_info *sbi); 276639a53e0cSJaegeuk Kim 276739a53e0cSJaegeuk Kim /* 276839a53e0cSJaegeuk Kim * debug.c 276939a53e0cSJaegeuk Kim */ 277039a53e0cSJaegeuk Kim #ifdef CONFIG_F2FS_STAT_FS 277139a53e0cSJaegeuk Kim struct f2fs_stat_info { 277239a53e0cSJaegeuk Kim struct list_head stat_list; 277339a53e0cSJaegeuk Kim struct f2fs_sb_info *sbi; 277439a53e0cSJaegeuk Kim int all_area_segs, sit_area_segs, nat_area_segs, ssa_area_segs; 277539a53e0cSJaegeuk Kim int main_area_segs, main_area_sections, main_area_zones; 27765b7ee374SChao Yu unsigned long long hit_largest, hit_cached, hit_rbtree; 27775b7ee374SChao Yu unsigned long long hit_total, total_ext; 2778c00ba554SJaegeuk Kim int ext_tree, zombie_tree, ext_node; 2779*2c8a4a28SJaegeuk Kim int ndirty_node, ndirty_dent, ndirty_meta, ndirty_imeta; 2780*2c8a4a28SJaegeuk Kim int ndirty_data, ndirty_qdata; 278135782b23SJaegeuk Kim int inmem_pages; 2782*2c8a4a28SJaegeuk Kim unsigned int ndirty_dirs, ndirty_files, nquota_files, ndirty_all; 27835b0ef73cSJaegeuk Kim int nats, dirty_nats, sits, dirty_sits; 27845b0ef73cSJaegeuk Kim int free_nids, avail_nids, alloc_nids; 278539a53e0cSJaegeuk Kim int total_count, utilization; 27868b8dd65fSChao Yu int bg_gc, nr_wb_cp_data, nr_wb_data; 278714d8d5f7SChao Yu int nr_flushing, nr_flushed, flush_list_empty; 278814d8d5f7SChao Yu int nr_discarding, nr_discarded; 27895f32366aSChao Yu int nr_discard_cmd; 2790d84d1cbdSChao Yu unsigned int undiscard_blks; 2791a00861dbSJaegeuk Kim int inline_xattr, inline_inode, inline_dir, append, update, orphans; 2792648d50baSChao Yu int aw_cnt, max_aw_cnt, vw_cnt, max_vw_cnt; 2793f83a2584SYunlei He unsigned int valid_count, valid_node_count, valid_inode_count, discard_blks; 279439a53e0cSJaegeuk Kim unsigned int bimodal, avg_vblocks; 279539a53e0cSJaegeuk Kim int util_free, util_valid, util_invalid; 279639a53e0cSJaegeuk Kim int rsvd_segs, overp_segs; 279739a53e0cSJaegeuk Kim int dirty_count, node_pages, meta_pages; 279842190d2aSJaegeuk Kim int prefree_count, call_count, cp_count, bg_cp_count; 279939a53e0cSJaegeuk Kim int tot_segs, node_segs, data_segs, free_segs, free_secs; 2800e1235983SChangman Lee int bg_node_segs, bg_data_segs; 280139a53e0cSJaegeuk Kim int tot_blks, data_blks, node_blks; 2802e1235983SChangman Lee int bg_data_blks, bg_node_blks; 280339a53e0cSJaegeuk Kim int curseg[NR_CURSEG_TYPE]; 280439a53e0cSJaegeuk Kim int cursec[NR_CURSEG_TYPE]; 280539a53e0cSJaegeuk Kim int curzone[NR_CURSEG_TYPE]; 280639a53e0cSJaegeuk Kim 280739a53e0cSJaegeuk Kim unsigned int segment_count[2]; 280839a53e0cSJaegeuk Kim unsigned int block_count[2]; 2809b9a2c252SChangman Lee unsigned int inplace_count; 28109edcdabfSChao Yu unsigned long long base_mem, cache_mem, page_mem; 281139a53e0cSJaegeuk Kim }; 281239a53e0cSJaegeuk Kim 2813963d4f7dSGu Zheng static inline struct f2fs_stat_info *F2FS_STAT(struct f2fs_sb_info *sbi) 2814963d4f7dSGu Zheng { 2815963d4f7dSGu Zheng return (struct f2fs_stat_info *)sbi->stat_info; 2816963d4f7dSGu Zheng } 2817963d4f7dSGu Zheng 2818942e0be6SChangman Lee #define stat_inc_cp_count(si) ((si)->cp_count++) 281942190d2aSJaegeuk Kim #define stat_inc_bg_cp_count(si) ((si)->bg_cp_count++) 282039a53e0cSJaegeuk Kim #define stat_inc_call_count(si) ((si)->call_count++) 2821dcdfff65SJaegeuk Kim #define stat_inc_bggc_count(sbi) ((sbi)->bg_gc++) 282233fbd510SChao Yu #define stat_inc_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]++) 282333fbd510SChao Yu #define stat_dec_dirty_inode(sbi, type) ((sbi)->ndirty_inode[type]--) 28245b7ee374SChao Yu #define stat_inc_total_hit(sbi) (atomic64_inc(&(sbi)->total_hit_ext)) 28255b7ee374SChao Yu #define stat_inc_rbtree_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_rbtree)) 28265b7ee374SChao Yu #define stat_inc_largest_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_largest)) 28275b7ee374SChao Yu #define stat_inc_cached_node_hit(sbi) (atomic64_inc(&(sbi)->read_hit_cached)) 2828d5e8f6c9SChao Yu #define stat_inc_inline_xattr(inode) \ 2829d5e8f6c9SChao Yu do { \ 2830d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2831d5e8f6c9SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_xattr)); \ 2832d5e8f6c9SChao Yu } while (0) 2833d5e8f6c9SChao Yu #define stat_dec_inline_xattr(inode) \ 2834d5e8f6c9SChao Yu do { \ 2835d5e8f6c9SChao Yu if (f2fs_has_inline_xattr(inode)) \ 2836d5e8f6c9SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_xattr)); \ 2837d5e8f6c9SChao Yu } while (0) 28380dbdc2aeSJaegeuk Kim #define stat_inc_inline_inode(inode) \ 28390dbdc2aeSJaegeuk Kim do { \ 28400dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 284103e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_inode)); \ 28420dbdc2aeSJaegeuk Kim } while (0) 28430dbdc2aeSJaegeuk Kim #define stat_dec_inline_inode(inode) \ 28440dbdc2aeSJaegeuk Kim do { \ 28450dbdc2aeSJaegeuk Kim if (f2fs_has_inline_data(inode)) \ 284603e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_inode)); \ 28470dbdc2aeSJaegeuk Kim } while (0) 28483289c061SJaegeuk Kim #define stat_inc_inline_dir(inode) \ 28493289c061SJaegeuk Kim do { \ 28503289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 285103e14d52SChao Yu (atomic_inc(&F2FS_I_SB(inode)->inline_dir)); \ 28523289c061SJaegeuk Kim } while (0) 28533289c061SJaegeuk Kim #define stat_dec_inline_dir(inode) \ 28543289c061SJaegeuk Kim do { \ 28553289c061SJaegeuk Kim if (f2fs_has_inline_dentry(inode)) \ 285603e14d52SChao Yu (atomic_dec(&F2FS_I_SB(inode)->inline_dir)); \ 28573289c061SJaegeuk Kim } while (0) 2858dcdfff65SJaegeuk Kim #define stat_inc_seg_type(sbi, curseg) \ 2859dcdfff65SJaegeuk Kim ((sbi)->segment_count[(curseg)->alloc_type]++) 2860dcdfff65SJaegeuk Kim #define stat_inc_block_count(sbi, curseg) \ 2861dcdfff65SJaegeuk Kim ((sbi)->block_count[(curseg)->alloc_type]++) 2862b9a2c252SChangman Lee #define stat_inc_inplace_blocks(sbi) \ 2863b9a2c252SChangman Lee (atomic_inc(&(sbi)->inplace_count)) 286426a28a0cSJaegeuk Kim #define stat_inc_atomic_write(inode) \ 2865cac5a3d8SDongOh Shin (atomic_inc(&F2FS_I_SB(inode)->aw_cnt)) 286626a28a0cSJaegeuk Kim #define stat_dec_atomic_write(inode) \ 2867cac5a3d8SDongOh Shin (atomic_dec(&F2FS_I_SB(inode)->aw_cnt)) 286826a28a0cSJaegeuk Kim #define stat_update_max_atomic_write(inode) \ 286926a28a0cSJaegeuk Kim do { \ 287026a28a0cSJaegeuk Kim int cur = atomic_read(&F2FS_I_SB(inode)->aw_cnt); \ 287126a28a0cSJaegeuk Kim int max = atomic_read(&F2FS_I_SB(inode)->max_aw_cnt); \ 287226a28a0cSJaegeuk Kim if (cur > max) \ 287326a28a0cSJaegeuk Kim atomic_set(&F2FS_I_SB(inode)->max_aw_cnt, cur); \ 287426a28a0cSJaegeuk Kim } while (0) 2875648d50baSChao Yu #define stat_inc_volatile_write(inode) \ 2876648d50baSChao Yu (atomic_inc(&F2FS_I_SB(inode)->vw_cnt)) 2877648d50baSChao Yu #define stat_dec_volatile_write(inode) \ 2878648d50baSChao Yu (atomic_dec(&F2FS_I_SB(inode)->vw_cnt)) 2879648d50baSChao Yu #define stat_update_max_volatile_write(inode) \ 2880648d50baSChao Yu do { \ 2881648d50baSChao Yu int cur = atomic_read(&F2FS_I_SB(inode)->vw_cnt); \ 2882648d50baSChao Yu int max = atomic_read(&F2FS_I_SB(inode)->max_vw_cnt); \ 2883648d50baSChao Yu if (cur > max) \ 2884648d50baSChao Yu atomic_set(&F2FS_I_SB(inode)->max_vw_cnt, cur); \ 2885648d50baSChao Yu } while (0) 2886e1235983SChangman Lee #define stat_inc_seg_count(sbi, type, gc_type) \ 288739a53e0cSJaegeuk Kim do { \ 2888963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 288968afcf2dSTomohiro Kusumi si->tot_segs++; \ 289068afcf2dSTomohiro Kusumi if ((type) == SUM_TYPE_DATA) { \ 289139a53e0cSJaegeuk Kim si->data_segs++; \ 2892e1235983SChangman Lee si->bg_data_segs += (gc_type == BG_GC) ? 1 : 0; \ 2893e1235983SChangman Lee } else { \ 289439a53e0cSJaegeuk Kim si->node_segs++; \ 2895e1235983SChangman Lee si->bg_node_segs += (gc_type == BG_GC) ? 1 : 0; \ 2896e1235983SChangman Lee } \ 289739a53e0cSJaegeuk Kim } while (0) 289839a53e0cSJaegeuk Kim 289939a53e0cSJaegeuk Kim #define stat_inc_tot_blk_count(si, blks) \ 290068afcf2dSTomohiro Kusumi ((si)->tot_blks += (blks)) 290139a53e0cSJaegeuk Kim 2902e1235983SChangman Lee #define stat_inc_data_blk_count(sbi, blks, gc_type) \ 290339a53e0cSJaegeuk Kim do { \ 2904963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 290539a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 290639a53e0cSJaegeuk Kim si->data_blks += (blks); \ 290768afcf2dSTomohiro Kusumi si->bg_data_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 290839a53e0cSJaegeuk Kim } while (0) 290939a53e0cSJaegeuk Kim 2910e1235983SChangman Lee #define stat_inc_node_blk_count(sbi, blks, gc_type) \ 291139a53e0cSJaegeuk Kim do { \ 2912963d4f7dSGu Zheng struct f2fs_stat_info *si = F2FS_STAT(sbi); \ 291339a53e0cSJaegeuk Kim stat_inc_tot_blk_count(si, blks); \ 291439a53e0cSJaegeuk Kim si->node_blks += (blks); \ 291568afcf2dSTomohiro Kusumi si->bg_node_blks += ((gc_type) == BG_GC) ? (blks) : 0; \ 291639a53e0cSJaegeuk Kim } while (0) 291739a53e0cSJaegeuk Kim 2918cac5a3d8SDongOh Shin int f2fs_build_stats(struct f2fs_sb_info *sbi); 2919cac5a3d8SDongOh Shin void f2fs_destroy_stats(struct f2fs_sb_info *sbi); 2920787c7b8cSChao Yu int __init f2fs_create_root_stats(void); 29214589d25dSNamjae Jeon void f2fs_destroy_root_stats(void); 292239a53e0cSJaegeuk Kim #else 2923d66450e7SArnd Bergmann #define stat_inc_cp_count(si) do { } while (0) 2924d66450e7SArnd Bergmann #define stat_inc_bg_cp_count(si) do { } while (0) 2925d66450e7SArnd Bergmann #define stat_inc_call_count(si) do { } while (0) 2926d66450e7SArnd Bergmann #define stat_inc_bggc_count(si) do { } while (0) 2927d66450e7SArnd Bergmann #define stat_inc_dirty_inode(sbi, type) do { } while (0) 2928d66450e7SArnd Bergmann #define stat_dec_dirty_inode(sbi, type) do { } while (0) 2929d66450e7SArnd Bergmann #define stat_inc_total_hit(sb) do { } while (0) 2930d66450e7SArnd Bergmann #define stat_inc_rbtree_node_hit(sb) do { } while (0) 2931d66450e7SArnd Bergmann #define stat_inc_largest_node_hit(sbi) do { } while (0) 2932d66450e7SArnd Bergmann #define stat_inc_cached_node_hit(sbi) do { } while (0) 2933d66450e7SArnd Bergmann #define stat_inc_inline_xattr(inode) do { } while (0) 2934d66450e7SArnd Bergmann #define stat_dec_inline_xattr(inode) do { } while (0) 2935d66450e7SArnd Bergmann #define stat_inc_inline_inode(inode) do { } while (0) 2936d66450e7SArnd Bergmann #define stat_dec_inline_inode(inode) do { } while (0) 2937d66450e7SArnd Bergmann #define stat_inc_inline_dir(inode) do { } while (0) 2938d66450e7SArnd Bergmann #define stat_dec_inline_dir(inode) do { } while (0) 2939d66450e7SArnd Bergmann #define stat_inc_atomic_write(inode) do { } while (0) 2940d66450e7SArnd Bergmann #define stat_dec_atomic_write(inode) do { } while (0) 2941d66450e7SArnd Bergmann #define stat_update_max_atomic_write(inode) do { } while (0) 2942d66450e7SArnd Bergmann #define stat_inc_volatile_write(inode) do { } while (0) 2943d66450e7SArnd Bergmann #define stat_dec_volatile_write(inode) do { } while (0) 2944d66450e7SArnd Bergmann #define stat_update_max_volatile_write(inode) do { } while (0) 2945d66450e7SArnd Bergmann #define stat_inc_seg_type(sbi, curseg) do { } while (0) 2946d66450e7SArnd Bergmann #define stat_inc_block_count(sbi, curseg) do { } while (0) 2947d66450e7SArnd Bergmann #define stat_inc_inplace_blocks(sbi) do { } while (0) 2948d66450e7SArnd Bergmann #define stat_inc_seg_count(sbi, type, gc_type) do { } while (0) 2949d66450e7SArnd Bergmann #define stat_inc_tot_blk_count(si, blks) do { } while (0) 2950d66450e7SArnd Bergmann #define stat_inc_data_blk_count(sbi, blks, gc_type) do { } while (0) 2951d66450e7SArnd Bergmann #define stat_inc_node_blk_count(sbi, blks, gc_type) do { } while (0) 295239a53e0cSJaegeuk Kim 295339a53e0cSJaegeuk Kim static inline int f2fs_build_stats(struct f2fs_sb_info *sbi) { return 0; } 295439a53e0cSJaegeuk Kim static inline void f2fs_destroy_stats(struct f2fs_sb_info *sbi) { } 2955787c7b8cSChao Yu static inline int __init f2fs_create_root_stats(void) { return 0; } 29564589d25dSNamjae Jeon static inline void f2fs_destroy_root_stats(void) { } 295739a53e0cSJaegeuk Kim #endif 295839a53e0cSJaegeuk Kim 295939a53e0cSJaegeuk Kim extern const struct file_operations f2fs_dir_operations; 296039a53e0cSJaegeuk Kim extern const struct file_operations f2fs_file_operations; 296139a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_file_inode_operations; 296239a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_dblock_aops; 296339a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_node_aops; 296439a53e0cSJaegeuk Kim extern const struct address_space_operations f2fs_meta_aops; 296539a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_dir_inode_operations; 296639a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_symlink_inode_operations; 2967cbaf042aSJaegeuk Kim extern const struct inode_operations f2fs_encrypted_symlink_inode_operations; 296839a53e0cSJaegeuk Kim extern const struct inode_operations f2fs_special_inode_operations; 296929e7043fSJaegeuk Kim extern struct kmem_cache *inode_entry_slab; 29701001b347SHuajun Li 2971e18c65b2SHuajun Li /* 2972e18c65b2SHuajun Li * inline.c 2973e18c65b2SHuajun Li */ 2974cac5a3d8SDongOh Shin bool f2fs_may_inline_data(struct inode *inode); 2975cac5a3d8SDongOh Shin bool f2fs_may_inline_dentry(struct inode *inode); 2976cac5a3d8SDongOh Shin void read_inline_data(struct page *page, struct page *ipage); 2977bd4667cbSKinglong Mee void truncate_inline_inode(struct inode *inode, struct page *ipage, u64 from); 2978cac5a3d8SDongOh Shin int f2fs_read_inline_data(struct inode *inode, struct page *page); 2979cac5a3d8SDongOh Shin int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page); 2980cac5a3d8SDongOh Shin int f2fs_convert_inline_inode(struct inode *inode); 2981cac5a3d8SDongOh Shin int f2fs_write_inline_data(struct inode *inode, struct page *page); 2982cac5a3d8SDongOh Shin bool recover_inline_data(struct inode *inode, struct page *npage); 2983cac5a3d8SDongOh Shin struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir, 2984cac5a3d8SDongOh Shin struct fscrypt_name *fname, struct page **res_page); 2985cac5a3d8SDongOh Shin int make_empty_inline_dir(struct inode *inode, struct inode *parent, 2986cac5a3d8SDongOh Shin struct page *ipage); 2987cac5a3d8SDongOh Shin int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name, 2988cac5a3d8SDongOh Shin const struct qstr *orig_name, 2989cac5a3d8SDongOh Shin struct inode *inode, nid_t ino, umode_t mode); 2990cac5a3d8SDongOh Shin void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page, 2991cac5a3d8SDongOh Shin struct inode *dir, struct inode *inode); 2992cac5a3d8SDongOh Shin bool f2fs_empty_inline_dir(struct inode *dir); 2993cac5a3d8SDongOh Shin int f2fs_read_inline_dir(struct file *file, struct dir_context *ctx, 2994cac5a3d8SDongOh Shin struct fscrypt_str *fstr); 2995cac5a3d8SDongOh Shin int f2fs_inline_data_fiemap(struct inode *inode, 2996cac5a3d8SDongOh Shin struct fiemap_extent_info *fieinfo, 2997cac5a3d8SDongOh Shin __u64 start, __u64 len); 2998cde4de12SJaegeuk Kim 2999cde4de12SJaegeuk Kim /* 30002658e50dSJaegeuk Kim * shrinker.c 30012658e50dSJaegeuk Kim */ 3002cac5a3d8SDongOh Shin unsigned long f2fs_shrink_count(struct shrinker *shrink, 3003cac5a3d8SDongOh Shin struct shrink_control *sc); 3004cac5a3d8SDongOh Shin unsigned long f2fs_shrink_scan(struct shrinker *shrink, 3005cac5a3d8SDongOh Shin struct shrink_control *sc); 3006cac5a3d8SDongOh Shin void f2fs_join_shrinker(struct f2fs_sb_info *sbi); 3007cac5a3d8SDongOh Shin void f2fs_leave_shrinker(struct f2fs_sb_info *sbi); 30082658e50dSJaegeuk Kim 30092658e50dSJaegeuk Kim /* 3010a28ef1f5SChao Yu * extent_cache.c 3011a28ef1f5SChao Yu */ 3012004b6862SChao Yu struct rb_entry *__lookup_rb_tree(struct rb_root *root, 3013004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs); 3014004b6862SChao Yu struct rb_node **__lookup_rb_tree_for_insert(struct f2fs_sb_info *sbi, 3015004b6862SChao Yu struct rb_root *root, struct rb_node **parent, 3016004b6862SChao Yu unsigned int ofs); 3017004b6862SChao Yu struct rb_entry *__lookup_rb_tree_ret(struct rb_root *root, 3018004b6862SChao Yu struct rb_entry *cached_re, unsigned int ofs, 3019004b6862SChao Yu struct rb_entry **prev_entry, struct rb_entry **next_entry, 3020004b6862SChao Yu struct rb_node ***insert_p, struct rb_node **insert_parent, 3021004b6862SChao Yu bool force); 3022df0f6b44SChao Yu bool __check_rb_tree_consistence(struct f2fs_sb_info *sbi, 3023df0f6b44SChao Yu struct rb_root *root); 3024cac5a3d8SDongOh Shin unsigned int f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink); 3025cac5a3d8SDongOh Shin bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext); 3026cac5a3d8SDongOh Shin void f2fs_drop_extent_tree(struct inode *inode); 3027cac5a3d8SDongOh Shin unsigned int f2fs_destroy_extent_node(struct inode *inode); 3028cac5a3d8SDongOh Shin void f2fs_destroy_extent_tree(struct inode *inode); 3029cac5a3d8SDongOh Shin bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs, 3030cac5a3d8SDongOh Shin struct extent_info *ei); 3031cac5a3d8SDongOh Shin void f2fs_update_extent_cache(struct dnode_of_data *dn); 303219b2c30dSChao Yu void f2fs_update_extent_cache_range(struct dnode_of_data *dn, 3033cac5a3d8SDongOh Shin pgoff_t fofs, block_t blkaddr, unsigned int len); 3034cac5a3d8SDongOh Shin void init_extent_cache_info(struct f2fs_sb_info *sbi); 3035a28ef1f5SChao Yu int __init create_extent_cache(void); 3036a28ef1f5SChao Yu void destroy_extent_cache(void); 3037a28ef1f5SChao Yu 3038a28ef1f5SChao Yu /* 30398ceffcb2SChao Yu * sysfs.c 30408ceffcb2SChao Yu */ 3041dc6b2055SJaegeuk Kim int __init f2fs_init_sysfs(void); 3042dc6b2055SJaegeuk Kim void f2fs_exit_sysfs(void); 3043dc6b2055SJaegeuk Kim int f2fs_register_sysfs(struct f2fs_sb_info *sbi); 3044dc6b2055SJaegeuk Kim void f2fs_unregister_sysfs(struct f2fs_sb_info *sbi); 30458ceffcb2SChao Yu 30468ceffcb2SChao Yu /* 3047cde4de12SJaegeuk Kim * crypto support 3048cde4de12SJaegeuk Kim */ 30490b81d077SJaegeuk Kim static inline bool f2fs_encrypted_inode(struct inode *inode) 3050cde4de12SJaegeuk Kim { 3051cde4de12SJaegeuk Kim return file_is_encrypt(inode); 3052cde4de12SJaegeuk Kim } 3053cde4de12SJaegeuk Kim 30541958593eSJaegeuk Kim static inline bool f2fs_encrypted_file(struct inode *inode) 30551958593eSJaegeuk Kim { 30561958593eSJaegeuk Kim return f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode); 30571958593eSJaegeuk Kim } 30581958593eSJaegeuk Kim 3059cde4de12SJaegeuk Kim static inline void f2fs_set_encrypted_inode(struct inode *inode) 3060cde4de12SJaegeuk Kim { 3061cde4de12SJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 3062cde4de12SJaegeuk Kim file_set_encrypt(inode); 3063cde4de12SJaegeuk Kim #endif 3064cde4de12SJaegeuk Kim } 3065cde4de12SJaegeuk Kim 3066cde4de12SJaegeuk Kim static inline bool f2fs_bio_encrypted(struct bio *bio) 3067cde4de12SJaegeuk Kim { 30680b81d077SJaegeuk Kim return bio->bi_private != NULL; 3069cde4de12SJaegeuk Kim } 3070cde4de12SJaegeuk Kim 3071cde4de12SJaegeuk Kim static inline int f2fs_sb_has_crypto(struct super_block *sb) 3072cde4de12SJaegeuk Kim { 3073cde4de12SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_ENCRYPT); 3074cde4de12SJaegeuk Kim } 3075f424f664SJaegeuk Kim 30760bfd7a09SDamien Le Moal static inline int f2fs_sb_mounted_blkzoned(struct super_block *sb) 307752763a4bSJaegeuk Kim { 30780bfd7a09SDamien Le Moal return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_BLKZONED); 307952763a4bSJaegeuk Kim } 308052763a4bSJaegeuk Kim 30817a2af766SChao Yu static inline int f2fs_sb_has_extra_attr(struct super_block *sb) 30827a2af766SChao Yu { 30837a2af766SChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_EXTRA_ATTR); 30847a2af766SChao Yu } 30857a2af766SChao Yu 30865c57132eSChao Yu static inline int f2fs_sb_has_project_quota(struct super_block *sb) 30875c57132eSChao Yu { 30885c57132eSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_PRJQUOTA); 30895c57132eSChao Yu } 30905c57132eSChao Yu 3091704956ecSChao Yu static inline int f2fs_sb_has_inode_chksum(struct super_block *sb) 3092704956ecSChao Yu { 3093704956ecSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_INODE_CHKSUM); 3094704956ecSChao Yu } 3095704956ecSChao Yu 30966afc662eSChao Yu static inline int f2fs_sb_has_flexible_inline_xattr(struct super_block *sb) 30976afc662eSChao Yu { 30986afc662eSChao Yu return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_FLEXIBLE_INLINE_XATTR); 30996afc662eSChao Yu } 31006afc662eSChao Yu 3101234a9689SJaegeuk Kim static inline int f2fs_sb_has_quota_ino(struct super_block *sb) 3102234a9689SJaegeuk Kim { 3103234a9689SJaegeuk Kim return F2FS_HAS_FEATURE(sb, F2FS_FEATURE_QUOTA_INO); 3104234a9689SJaegeuk Kim } 3105234a9689SJaegeuk Kim 3106178053e2SDamien Le Moal #ifdef CONFIG_BLK_DEV_ZONED 3107178053e2SDamien Le Moal static inline int get_blkz_type(struct f2fs_sb_info *sbi, 31083c62be17SJaegeuk Kim struct block_device *bdev, block_t blkaddr) 3109178053e2SDamien Le Moal { 3110178053e2SDamien Le Moal unsigned int zno = blkaddr >> sbi->log_blocks_per_blkz; 31113c62be17SJaegeuk Kim int i; 3112178053e2SDamien Le Moal 31133c62be17SJaegeuk Kim for (i = 0; i < sbi->s_ndevs; i++) 31143c62be17SJaegeuk Kim if (FDEV(i).bdev == bdev) 31153c62be17SJaegeuk Kim return FDEV(i).blkz_type[zno]; 31163c62be17SJaegeuk Kim return -EINVAL; 3117178053e2SDamien Le Moal } 3118178053e2SDamien Le Moal #endif 3119178053e2SDamien Le Moal 312096ba2decSDamien Le Moal static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi) 312196ba2decSDamien Le Moal { 312296ba2decSDamien Le Moal struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev); 312396ba2decSDamien Le Moal 312496ba2decSDamien Le Moal return blk_queue_discard(q) || f2fs_sb_mounted_blkzoned(sbi->sb); 312552763a4bSJaegeuk Kim } 312652763a4bSJaegeuk Kim 312752763a4bSJaegeuk Kim static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt) 312852763a4bSJaegeuk Kim { 312952763a4bSJaegeuk Kim clear_opt(sbi, ADAPTIVE); 313052763a4bSJaegeuk Kim clear_opt(sbi, LFS); 313152763a4bSJaegeuk Kim 313252763a4bSJaegeuk Kim switch (mt) { 313352763a4bSJaegeuk Kim case F2FS_MOUNT_ADAPTIVE: 313452763a4bSJaegeuk Kim set_opt(sbi, ADAPTIVE); 313552763a4bSJaegeuk Kim break; 313652763a4bSJaegeuk Kim case F2FS_MOUNT_LFS: 313752763a4bSJaegeuk Kim set_opt(sbi, LFS); 313852763a4bSJaegeuk Kim break; 313952763a4bSJaegeuk Kim } 314052763a4bSJaegeuk Kim } 314152763a4bSJaegeuk Kim 3142fcc85a4dSJaegeuk Kim static inline bool f2fs_may_encrypt(struct inode *inode) 3143fcc85a4dSJaegeuk Kim { 3144fcc85a4dSJaegeuk Kim #ifdef CONFIG_F2FS_FS_ENCRYPTION 3145886f56f9SAl Viro umode_t mode = inode->i_mode; 3146fcc85a4dSJaegeuk Kim 3147fcc85a4dSJaegeuk Kim return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)); 3148fcc85a4dSJaegeuk Kim #else 3149fcc85a4dSJaegeuk Kim return 0; 3150fcc85a4dSJaegeuk Kim #endif 3151fcc85a4dSJaegeuk Kim } 3152fcc85a4dSJaegeuk Kim 315339a53e0cSJaegeuk Kim #endif 3154